summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknolax <1339802534.kk@gmail.com>2018-02-21 21:43:52 -0500
committerknolax <1339802534.kk@gmail.com>2018-02-21 21:43:52 -0500
commit61285392fa02c1acef39f75342d6dab20b672036 (patch)
treed711b2c918d01265fcda682e16a90ceac1539bc7
Initial Commit, braille graphics have been implemented.
-rw-r--r--Makefile2
-rwxr-xr-xwsimbin0 -> 8736 bytes
-rw-r--r--wsim.c145
3 files changed, 147 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2198cda
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+main:
+ gcc wsim.c -o wsim
diff --git a/wsim b/wsim
new file mode 100755
index 0000000..21147a6
--- /dev/null
+++ b/wsim
Binary files differ
diff --git a/wsim.c b/wsim.c
new file mode 100644
index 0000000..b369b9d
--- /dev/null
+++ b/wsim.c
@@ -0,0 +1,145 @@
+#include<stdio.h>
+#include<string.h>
+#include<stdint.h>
+/* map holding the pixels for a 200x200 pixel imagebuffer, [x][y]
+ * bits are in braille order within each byte
+ */
+uint8_t map[100][50];
+/* takes char storing the on/off positions of 8 points, in braille encoding
+ * order, and prints the corresponding braille char
+ */
+
+/* global state bit switch */
+uint8_t state = 1;
+#define STATE_LOOP 0x01
+void printbraille(uint8_t points) {
+ /* outputs braille characters, the encoding for braile is:
+ * 1 4
+ * 2 5
+ * 3 6
+ * 7 8
+ * with the block being in U+2800 to U+28FF
+ * in utf8 that's encoded
+ * 1110xxxx 10xxxxxx 10xxxxxx
+ * [1110](0010) [10](1000)87 [10]654321
+ */
+ printf("%c%c%c",
+ 0b11100010,
+ 0b10100000 | (points >> 6),
+ 0b10000000 | (points & 0b00111111));
+}
+/* prints the map, clears output before aswell*/
+void printmap() {
+ uint8_t xi = 0;
+ uint8_t yi = 0;
+ /*terminal escape code to move the cursor to beginning of screen or 1,1*/
+ printf("\033[1;1H");
+ while (yi < 50) {
+ xi = 0;
+ while (xi < 100) {
+ printbraille(map[xi][yi]);
+ xi++;
+ }
+ printf("\n");
+ yi++;
+ }
+}
+/* sets a pixel in the map, converts x,y coordinates to braille order
+ * if set is 0, then set it to 0
+ * if 1, set to 1
+ * if > 1, flip
+ * does not throw errors
+ */
+void setpixel(uint8_t x, uint8_t y,uint8_t set) {
+ /* anchor x and y coordinates, eg the index in map*/
+ uint8_t ax;
+ uint8_t ay;
+ /*bitmask in braille order of the byte in mask*/
+ uint8_t shift = 0x01;
+ /* check if out of bounds, since the arguments are unsigned, don't have
+ * to check below 0, doesn't throw errors
+ */
+ if ( (x >= 200 ) || (y >= 200) ) {
+ return;
+ }
+ /* integer division rounds down, therefore dividing will always get the
+ * index
+ */
+ ax = x/2;
+ ay = y/4;
+ /*
+ * maps to braille order based off of x and y offsets
+ * 1 4
+ * 2 5
+ * 3 6
+ * 7 8
+ */
+ switch(x % 2) {
+ case 0:
+ switch (y % 4) {
+ case 0:
+ shift = shift << 0;
+ break;
+ case 1:
+ shift = shift << 1;
+ break;
+ case 2:
+ shift = shift << 2;
+ break;
+ case 3:
+ shift = shift << 6;
+ break;
+ }
+ break;
+ case 1:
+ switch (y % 4) {
+ case 0:
+ shift = shift << 3;
+ break;
+ case 1:
+ shift = shift << 4;
+ break;
+ case 2:
+ shift = shift << 5;
+ break;
+ case 3:
+ shift = shift << 7;
+ break;
+ }
+ break;
+ }
+ /* sets the bit based on set*/
+ switch (set) {
+ case 0:
+ map[ax][ay] = map[ax][ay] & (~shift);
+ break;
+ case 1:
+ map[ax][ay] = map[ax][ay] | shift;
+ break;
+ default:
+ map[ax][ay] = ((~map[ax][ay]) & shift) |
+ ((~shift) & map[ax][ay]);
+ break;
+ }
+ return;
+}
+int main (int argc, char * argv[]) {
+ /*holds keypress*/
+ char input;
+ /*zeroing map*/
+ memset(map, 0, sizeof(map[0][0]) * 100 * 50);
+ printmap();
+ while (state & STATE_LOOP) {
+ setpixel(0,0,2);
+ printmap();
+ /* checks input*/
+ input = getc(stdin);
+ /*haven't set the terminal to raw mode so will still need
+ * space
+ */
+ if (input == 'q') {
+ state = state & (~STATE_LOOP);
+ }
+ }
+ return 0;
+}