From cf7e621c104cb4aea801392585d2dcc9335bc013 Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Thu, 28 Aug 2025 14:44:51 +1000 Subject: added preprocessor (wip) --- ROMs/typewriter.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 ROMs/typewriter.c (limited to 'ROMs/typewriter.c') diff --git a/ROMs/typewriter.c b/ROMs/typewriter.c new file mode 100644 index 0000000..0886532 --- /dev/null +++ b/ROMs/typewriter.c @@ -0,0 +1,107 @@ +#load "font.bin" + +int drawChar(int ch, int x, int y, int color) +{ + // adjust for jmp instruction + char* fontStart = 0x1FFF + 2; + int charStart = ch * 8; + + for (int yOff = 0; yOff < 8; yOff++) + { + int row = fontStart[charStart + yOff]; + + for (int xOff = 0; xOff < 8; xOff++) + { + int bit = (row >> (7 - xOff)) & 1; + int pix = bit ? 8 : color; + setPixel(x + xOff, y + yOff, pix); + } + } +} + +int setPixel(int x, int y, int c) +{ + char* screenStart = 0x402F; + int i = (y * 128) + x; + screenStart[i] = c; +} + +int clear(int c) +{ + char* screenStart = 0x402F; + char screenSize = 64 * 128; + for (int i = 0; i < screenSize; i++) + { + screenStart[i] = c; + } +} + +int getKeyState(int scanCode) +{ + char* hid = 0x6033; + int index = scanCode / 8; + int bit = scanCode % 8; + + int val = hid[index - 1]; + return (val & (1 << bit)) != 0; +} + +int print(int* text, int len, int x, int y, int color) +{ + for (int i = 0; i < len; i++) + { + int ch = text[i]; + drawChar(ch, x + (i * 8), y, color); + } +} + +int main() +{ + int x = 0; + int y = 0; + while (1) + { + for (int sk = 0; sk < 256; sk++) + { + if (getKeyState(sk)) + { + while (getKeyState(sk)) { } + // Newline pressed + if (sk == 13) + { + y += 8; + x = 0; + continue; + } + // Backspace pressed + if (sk == 8) + { + x -= 8; + if (x < 0) + x = 0; + int* text = " "; + print(text, 1, x, y, 1); + continue; + } + + int* text = new int[] { sk }; + print(text, 1, x, y, 1); + x += 8; + } + } + + if (x >= 128) + { + x = 0; + y += 8; + } + + if (y >= 64) + { + x = 0; + y = 0; + clear(8); + } + + } +} \ No newline at end of file -- cgit v1.3.1