summaryrefslogtreecommitdiff
path: root/ROMs/typewriter.c
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-28 14:44:51 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-28 14:44:51 +1000
commitcf7e621c104cb4aea801392585d2dcc9335bc013 (patch)
treeee4aef401c399995968afe217d06557587707c51 /ROMs/typewriter.c
parent7f96fc5e7f412a66d460dcaa82bbdbcaea08f360 (diff)
added preprocessor (wip)
Diffstat (limited to 'ROMs/typewriter.c')
-rw-r--r--ROMs/typewriter.c107
1 files changed, 107 insertions, 0 deletions
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