summaryrefslogtreecommitdiff
path: root/ROMs/typewriter.c
diff options
context:
space:
mode:
Diffstat (limited to 'ROMs/typewriter.c')
-rw-r--r--ROMs/typewriter.c84
1 files changed, 25 insertions, 59 deletions
diff --git a/ROMs/typewriter.c b/ROMs/typewriter.c
index 0886532..a63a77d 100644
--- a/ROMs/typewriter.c
+++ b/ROMs/typewriter.c
@@ -1,4 +1,5 @@
#load "font.bin"
+#include "lib.c"
int drawChar(int ch, int x, int y, int color)
{
@@ -19,33 +20,6 @@ int drawChar(int ch, int x, int y, int color)
}
}
-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++)
@@ -59,49 +33,41 @@ int main()
{
int x = 0;
int y = 0;
- while (1)
+ while (true)
{
- 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)
+ if (x >= SCREEN_WIDTH)
{
x = 0;
y += 8;
}
- if (y >= 64)
+ if (y >= SCREEN_HEIGHT)
{
x = 0;
y = 0;
clear(8);
}
+
+ int sk = readKey();
+ while (getKeyState(sk)) { }
+
+ if (sk == SK_NL)
+ {
+ y += 8;
+ x = 0;
+ continue;
+ }
+
+ if (sk == SK_BS)
+ {
+ x -= 8;
+ if (x < 0)
+ x = 0;
+ drawChar(' ', x, y, 1);
+ continue;
+ }
+ drawChar(sk, x, y, 1);
+ x += 8;
}
} \ No newline at end of file