diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-28 22:30:02 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-28 22:30:02 +1000 |
| commit | 5d012f16b2a0200087afe9dffc906046d258b3b8 (patch) | |
| tree | ad7a8cee368d1b83e08df13243678a34d34c6aae /ROMs | |
| parent | 76cea79a46d42f8f59503d3bb421f0d298da66cb (diff) | |
seperated modules out
Diffstat (limited to 'ROMs')
| -rw-r--r-- | ROMs/hid.c | 80 | ||||
| -rw-r--r-- | ROMs/lib.c | 88 | ||||
| -rw-r--r-- | ROMs/paint.asm | 252 | ||||
| -rw-r--r-- | ROMs/paint.c | 18 | ||||
| -rw-r--r-- | ROMs/paint.q1 | bin | 872 -> 872 bytes | |||
| -rw-r--r-- | ROMs/screen.c | 48 | ||||
| -rw-r--r-- | ROMs/std.c | 4 | ||||
| -rw-r--r-- | ROMs/typewriter.asm | 47 | ||||
| -rw-r--r-- | ROMs/typewriter.c | 23 | ||||
| -rw-r--r-- | ROMs/typewriter.q1 | bin | 3627 -> 3686 bytes |
10 files changed, 314 insertions, 246 deletions
diff --git a/ROMs/hid.c b/ROMs/hid.c new file mode 100644 index 0000000..11730e9 --- /dev/null +++ b/ROMs/hid.c @@ -0,0 +1,80 @@ +#include "std.c" + +#define BUS_HID_SK_START 0x6033 +#define BUS_HID_MS_INDEX 0x602F +#define BUS_HID_MS_STATE 0x602F + 2 + +#define SK_MAX 256 +#define SK_NEWLINE 13 +#define SK_BACKSPACE 8 +#define SK_SHIFT 160 +#define SK_A 65 +#define SK_B 66 +#define SK_C 67 +#define SK_D 68 +#define SK_E 69 +#define SK_F 70 +#define SK_G 71 +#define SK_H 72 +#define SK_I 73 +#define SK_J 74 +#define SK_K 75 +#define SK_L 76 +#define SK_M 77 +#define SK_N 78 +#define SK_O 79 +#define SK_P 80 +#define SK_Q 81 +#define SK_R 82 +#define SK_S 83 +#define SK_T 84 +#define SK_U 85 +#define SK_V 86 +#define SK_W 87 +#define SK_X 88 +#define SK_Y 89 +#define SK_Z 90 + +#define MS_LEFT 1 +#define MS_RIGHT 2 +#define MS_MIDDLE 4 + +int hid_getKeyState(int scanCode) +{ + char* sk_table = BUS_HID_SK_START; + int index = scanCode / 8; + int bit = scanCode % 8; + + int val = sk_table[index - 1]; + return (val & (1 << bit)) != 0; +} + +int hid_getPressedKey() +{ + for (int sk = 0; sk < SK_MAX; sk++) + { + if (hid_getKeyState(sk) && sk != SK_SHIFT) + return sk; + } + return 0; +} + +int hid_waitForPressedKey() +{ + while (true) + { + int sk = hid_getPressedKey(); + if (sk != 0) + return sk; + } +} + +int hid_getMouseIndex() +{ + return *(BUS_HID_MS_INDEX); +} + +int hid_getMouseState() +{ + return *(BUS_HID_MS_STATE); +}
\ No newline at end of file diff --git a/ROMs/lib.c b/ROMs/lib.c deleted file mode 100644 index cd666b9..0000000 --- a/ROMs/lib.c +++ /dev/null @@ -1,88 +0,0 @@ -#define SK_MAX 256 -#define SK_NL 13 -#define SK_BS 8 -#define SK_SHIFT 160 -#define SK_A 65 -#define SK_B 66 -#define SK_C 67 -#define SK_D 68 -#define SK_E 69 - -#define MS_LEFT 1 -#define MS_RIGHT 2 -#define MS_MIDDLE 4 - -#define SCREEN_WIDTH 128 -#define SCREEN_HEIGHT 64 -#define SCREEN_MAX 128 * 64 - -#define true 1 -#define false 0 - -#define COLOR_BLACK 8 -#define COLOR_RED 1 -#define COLOR_GREEN 2 -#define COLOR_BLUE 3 -#define COLOR_TRANSPARENT 0 - -int setPixel(int x, int y, int c) -{ - char* screenStart = 0x402F; - int i = (y * SCREEN_WIDTH) + x; - screenStart[i] = c; -} - -int setPixel(int i, int c) -{ - char* screenStart = 0x402F; - screenStart[i] = c; -} - -int clear(int c) -{ - char* screenStart = 0x402F; - for (int i = 0; i < SCREEN_MAX; 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 getPressedKey() -{ - for (int sk = 0; sk < SK_MAX; sk++) - { - if (getKeyState(sk) && sk != SK_SHIFT) - return sk; - } - return 0; -} - -int readKey() -{ - while (true) - { - int sk = getPressedKey(); - if (sk != 0) - return sk; - } -} - -int getMouseIndex() -{ - return *(0x602F); -} - -int getMouseState() -{ - return *(0x602F + 2); -}
\ No newline at end of file diff --git a/ROMs/paint.asm b/ROMs/paint.asm index b4d454f..9a853a4 100644 --- a/ROMs/paint.asm +++ b/ROMs/paint.asm @@ -1,96 +1,21 @@ jmp _main -_setPixel_int_x__int_y__int_c:; int setPixel(int x, int y, int c) +_hid_getKeyState_int_scanCode:; int hid_getKeyState(int scanCode) pop V0 ; preserve function return address - pop [$71FF] ; param int x - pop [$7201] ; param int y - pop [$7203] ; param int c + pop [$71FF] ; param int scanCode push V0 ; restore function return address - mov $402F, [$7205] ; int screenStart = $402F - push [$7201] ; left operand - mov 128, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - push AX ; left operand - mov [$71FF], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, [$7207] ; int i = AX - push [$7205] ; store index obj - mov [$7207], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$7203], [V0] ; [V0] = [$7203] - mov 0, V0 ; fallback return 0 - ret - -_setPixel_int_i__int_c: ; int setPixel(int i, int c) - pop V0 ; preserve function return address - pop [$7209] ; param int i - pop [$720B] ; param int c - push V0 ; restore function return address - mov $402F, [$720D] ; int screenStart = $402F - push [$720D] ; store index obj - mov [$7209], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$720B], [V0] ; [V0] = [$720B] - mov 0, V0 ; fallback return 0 - ret - -_clear_int_c: ; int clear(int c) - pop V0 ; preserve function return address - pop [$720F] ; param int c - push V0 ; restore function return address - mov $402F, [$7211] ; int screenStart = $402F - mov 0, [$7213] ; int i = 0 -_body_1: - push [$7213] ; left operand - push 128 ; left operand - mov 64, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_2 ; if for condition fails, jump to end - push [$7211] ; store index obj - mov [$7213], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$720F], [V0] ; [V0] = [$720F] - push [$7213] ; i++ - inc [$7213] - pop V0 - jmp _body_1 -_end_2: - mov 0, V0 ; fallback return 0 - ret - -_getKeyState_int_scanCode: ; int getKeyState(int scanCode) - pop V0 ; preserve function return address - pop [$7215] ; param int scanCode - push V0 ; restore function return address - mov $6033, [$7217] ; int hid = $6033 - push [$7215] ; left operand + mov $6033, [$7201] ; int sk_table = $6033 + push [$71FF] ; left operand mov 8, V1 ; right operand pop V0 ; get left operand back div V0, V1 ; compute division - mov AX, [$7219] ; int index = AX - push [$7215] ; left operand + mov AX, [$7203] ; int index = AX + push [$71FF] ; left operand mov 8, V1 ; right operand pop V0 ; get left operand back mod V0, V1 ; compute modulus - mov AX, [$721B] ; int bit = AX - push [$7217] ; store index obj - push [$7219] ; left operand + mov AX, [$7205] ; int bit = AX + push [$7201] ; store index obj + push [$7203] ; left operand mov 1, V1 ; right operand pop V0 ; get left operand back sub V0, V1 ; compute subtraction @@ -99,10 +24,10 @@ _getKeyState_int_scanCode: ; int getKeyState(int scanCode) mul V1, 1 ; multiply indexer by 1 add AX, V0 ; add indexer and index obj mov AX, V0 ; move to general purpose register - mov [V0], [$721D] ; int val = [V0] - push [$721D] ; left operand + mov [V0], [$7207] ; int val = [V0] + push [$7207] ; left operand push 1 ; left operand - mov [$721B], V1 ; right operand + mov [$7205], V1 ; right operand pop V0 ; get left operand back shl V0, V1 ; compute left shift mov DX, V1 ; right operand @@ -118,26 +43,26 @@ _getKeyState_int_scanCode: ; int getKeyState(int scanCode) mov 0, V0 ; fallback return 0 ret -_getPressedKey: ; int getPressedKey() - mov 0, [$721F] ; int sk = 0 -_body_3: - push [$721F] ; left operand +_hid_getPressedKey: ; int hid_getPressedKey() + mov 0, [$7209] ; int sk = 0 +_body_1: + push [$7209] ; left operand mov 256, V1 ; right operand pop V0 ; get left operand back lt V0, V1 ; compute less than check not LX bz - jmp _end_4 ; if for condition fails, jump to end - push [$721F] ; arg int scanCode - call _getKeyState_int_scanCode; int getKeyState(int scanCode) + jmp _end_2 ; if for condition fails, jump to end + push [$7209] ; arg int scanCode + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) cmp V0, 0 ; logical and not bz - jmp _clause_5 + jmp _clause_3 mov 0, V0 ; first operand failed, store 0 and skip second - jmp _end_6 -_clause_5: - push [$721F] ; left operand + jmp _end_4 +_clause_3: + push [$7209] ; left operand mov 160, V1 ; right operand pop V0 ; get left operand back cmp V0, V1 ; compute inequality check @@ -145,54 +70,54 @@ _clause_5: cmp LX, 0 ; compare result from second operand to 0 not mov LX, V0 ; store second operand result -_end_6: +_end_4: not V0 bz ; check if condition - jmp _end_7 ; if succeeds, continue, else jump to end - mov [$721F], V0 ; return value + jmp _end_5 ; if succeeds, continue, else jump to end + mov [$7209], V0 ; return value ret -_end_7: - push [$721F] ; i++ - inc [$721F] +_end_5: + push [$7209] ; i++ + inc [$7209] pop V0 - jmp _body_3 -_end_4: + jmp _body_1 +_end_2: mov 0, V0 ; return value ret mov 0, V0 ; fallback return 0 ret -_readKey: ; int readKey() -_body_8: +_hid_waitForPressedKey: ; int hid_waitForPressedKey() +_body_6: not 1 bz - jmp _end_9 ; if while condition fails, jump to end - call _getPressedKey ; int getPressedKey() - mov V0, [$7221] ; int sk = V0 - push [$7221] ; left operand + jmp _end_7 ; if while condition fails, jump to end + call _hid_getPressedKey ; int hid_getPressedKey() + mov V0, [$720B] ; int sk = V0 + push [$720B] ; left operand mov 0, V1 ; right operand pop V0 ; get left operand back cmp V0, V1 ; compute inequality check not not LX bz ; check if condition - jmp _end_10 ; if succeeds, continue, else jump to end - mov [$7221], V0 ; return value + jmp _end_8 ; if succeeds, continue, else jump to end + mov [$720B], V0 ; return value ret -_end_10: - jmp _body_8 -_end_9: +_end_8: + jmp _body_6 +_end_7: mov 0, V0 ; fallback return 0 ret -_getMouseIndex: ; int getMouseIndex() +_hid_getMouseIndex: ; int hid_getMouseIndex() mov $602F, V0 ; move pointer into register for dereference mov [V0], V0 ; return value ret mov 0, V0 ; fallback return 0 ret -_getMouseState: ; int getMouseState() +_hid_getMouseState: ; int hid_getMouseState() push $602F ; left operand mov 2, V1 ; right operand pop V0 ; get left operand back @@ -203,15 +128,90 @@ _getMouseState: ; int getMouseState() mov 0, V0 ; fallback return 0 ret +_screen_setPixel_int_x__int_y__int_c:; int screen_setPixel(int x, int y, int c) + pop V0 ; preserve function return address + pop [$720D] ; param int x + pop [$720F] ; param int y + pop [$7211] ; param int c + push V0 ; restore function return address + mov $402F, [$7213] ; int screenStart = $402F + push [$720F] ; left operand + mov 128, V1 ; right operand + pop V0 ; get left operand back + mul V0, V1 ; compute multiplication + push AX ; left operand + mov [$720D], V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + mov AX, [$7215] ; int i = AX + push [$7213] ; store index obj + mov [$7215], V1 ; store indexer + pop V0 ; restore index obj + mul V1, 1 ; multiply indexer by 1 + add AX, V0 ; add indexer and index obj + mov AX, V0 ; move to general purpose register + movb [$7211], [V0] ; [V0] = [$7211] + mov 0, V0 ; fallback return 0 + ret + +_screen_setPixel_int_i__int_c:; int screen_setPixel(int i, int c) + pop V0 ; preserve function return address + pop [$7217] ; param int i + pop [$7219] ; param int c + push V0 ; restore function return address + mov $402F, [$721B] ; int screenStart = $402F + push [$721B] ; store index obj + mov [$7217], V1 ; store indexer + pop V0 ; restore index obj + mul V1, 1 ; multiply indexer by 1 + add AX, V0 ; add indexer and index obj + mov AX, V0 ; move to general purpose register + movb [$7219], [V0] ; [V0] = [$7219] + mov 0, V0 ; fallback return 0 + ret + +_screen_clear_int_c: ; int screen_clear(int c) + pop V0 ; preserve function return address + pop [$721D] ; param int c + push V0 ; restore function return address + mov $402F, [$721F] ; int screenStart = $402F + mov 0, [$7221] ; int i = 0 +_body_9: + push [$7221] ; left operand + push 128 ; left operand + mov 64, V1 ; right operand + pop V0 ; get left operand back + mul V0, V1 ; compute multiplication + mov AX, V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check + not LX + bz + jmp _end_10 ; if for condition fails, jump to end + push [$721F] ; store index obj + mov [$7221], V1 ; store indexer + pop V0 ; restore index obj + mul V1, 1 ; multiply indexer by 1 + add AX, V0 ; add indexer and index obj + mov AX, V0 ; move to general purpose register + movb [$721D], [V0] ; [V0] = [$721D] + push [$7221] ; i++ + inc [$7221] + pop V0 + jmp _body_9 +_end_10: + mov 0, V0 ; fallback return 0 + ret + _main: ; int main() mov 0, [$7223] ; int color = 0 _body_11: not 1 bz jmp _end_12 ; if while condition fails, jump to end - call _getMouseIndex ; int getMouseIndex() + call _hid_getMouseIndex ; int hid_getMouseIndex() mov V0, [$7225] ; int mouseIndex = V0 - call _getMouseState ; int getMouseState() + call _hid_getMouseState ; int hid_getMouseState() mov V0, [$7227] ; int mouseState = V0 push [$7227] ; left operand mov 1, V1 ; right operand @@ -230,18 +230,18 @@ _body_11: add V0, V1 ; compute addition push AX ; arg int i push [$7225] ; arg int c - call _setPixel_int_i__int_c; int setPixel(int i, int c) + call _screen_setPixel_int_i__int_c; int screen_setPixel(int i, int c) _end_13: push 67 ; arg int scanCode - call _getKeyState_int_scanCode; int getKeyState(int scanCode) + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 bz ; check if condition jmp _end_14 ; if succeeds, continue, else jump to end push 8 ; arg int c - call _clear_int_c ; int clear(int c) + call _screen_clear_int_c ; int screen_clear(int c) _end_14: push 65 ; arg int scanCode - call _getKeyState_int_scanCode; int getKeyState(int scanCode) + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 bz ; check if condition jmp _end_15 ; if succeeds, continue, else jump to end @@ -250,7 +250,7 @@ _end_14: pop V0 _body_16: push 65 ; arg int scanCode - call _getKeyState_int_scanCode; int getKeyState(int scanCode) + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 bz jmp _end_17 ; if while condition fails, jump to end diff --git a/ROMs/paint.c b/ROMs/paint.c index 7e0427b..71c478e 100644 --- a/ROMs/paint.c +++ b/ROMs/paint.c @@ -1,23 +1,25 @@ -#include "lib.c" +#include "std.c" +#include "hid.c" +#include "screen.c" int main() { int color = 0; while (true) { - int mouseIndex = getMouseIndex(); - int mouseState = getMouseState(); + int mouseIndex = hid_getMouseIndex(); + int mouseState = hid_getMouseState(); if (mouseState & MS_LEFT) - setPixel(mouseIndex, (color % 3) + 1); + screen_setPixel(mouseIndex, (color % 3) + 1); - if (getKeyState(SK_C)) - clear(COLOR_BLACK); + if (hid_getKeyState(SK_C)) + screen_clear(COLOR_BLACK); - if (getKeyState(SK_A)) + if (hid_getKeyState(SK_A)) { color++; - while (getKeyState(SK_A)) { } + while (hid_getKeyState(SK_A)) { } } } }
\ No newline at end of file diff --git a/ROMs/paint.q1 b/ROMs/paint.q1 Binary files differindex 5105eb8..ecf446d 100644 --- a/ROMs/paint.q1 +++ b/ROMs/paint.q1 diff --git a/ROMs/screen.c b/ROMs/screen.c new file mode 100644 index 0000000..0eff8c7 --- /dev/null +++ b/ROMs/screen.c @@ -0,0 +1,48 @@ +#include "std.c" + +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 64 +#define SCREEN_MAX 128 * 64 + +#define COLOR_TRANSPARENT 0 +#define COLOR_RED 1 +#define COLOR_GREEN 2 +#define COLOR_BLUE 3 +#define COLOR_YELLOW 4 +#define COLOR_CYAN 5 +#define COLOR_MAGENTA 6 +#define COLOR_WHITE 7 +#define COLOR_BLACK 8 +#define COLOR_GRAY 9 +#define COLOR_ORANGE 10 +#define COLOR_PURPLE 11 +#define COLOR_BROWN 12 +#define COLOR_LIGHTGRAY 13 +#define COLOR_DARKGRAY 14 +#define COLOR_LIGHTBLUE 15 +#define COLOR_LIGHTGREEN 16 + +#define BUS_SCREEN_PALETTE_START 0x3FFF +#define BUS_SCREEN_PIXELS_START 0x402F + +int screen_setPixel(int x, int y, int c) +{ + char* screenStart = BUS_SCREEN_PIXELS_START; + int i = (y * SCREEN_WIDTH) + x; + screenStart[i] = c; +} + +int screen_setPixel(int i, int c) +{ + char* screenStart = BUS_SCREEN_PIXELS_START; + screenStart[i] = c; +} + +int screen_clear(int c) +{ + char* screenStart = BUS_SCREEN_PIXELS_START; + for (int i = 0; i < SCREEN_MAX; i++) + { + screenStart[i] = c; + } +}
\ No newline at end of file diff --git a/ROMs/std.c b/ROMs/std.c new file mode 100644 index 0000000..aa0b85f --- /dev/null +++ b/ROMs/std.c @@ -0,0 +1,4 @@ +#include "std.c" + +#define true 1 +#define false 0
\ No newline at end of file diff --git a/ROMs/typewriter.asm b/ROMs/typewriter.asm index 8a9017b..8b8338a 100644 --- a/ROMs/typewriter.asm +++ b/ROMs/typewriter.asm @@ -1,6 +1,6 @@ jmp _main .include "font.bin" -_setPixel_int_x__int_y__int_c:; int setPixel(int x, int y, int c) +_screen_setPixel_int_x__int_y__int_c:; int screen_setPixel(int x, int y, int c) pop V0 ; preserve function return address pop [$71FF] ; param int x pop [$7201] ; param int y @@ -26,7 +26,7 @@ _setPixel_int_x__int_y__int_c:; int setPixel(int x, int y, int c) mov 0, V0 ; fallback return 0 ret -_setPixel_int_i__int_c: ; int setPixel(int i, int c) +_screen_setPixel_int_i__int_c:; int screen_setPixel(int i, int c) pop V0 ; preserve function return address pop [$7209] ; param int i pop [$720B] ; param int c @@ -42,7 +42,7 @@ _setPixel_int_i__int_c: ; int setPixel(int i, int c) mov 0, V0 ; fallback return 0 ret -_clear_int_c: ; int clear(int c) +_screen_clear_int_c: ; int screen_clear(int c) pop V0 ; preserve function return address pop [$720F] ; param int c push V0 ; restore function return address @@ -75,11 +75,11 @@ _end_2: mov 0, V0 ; fallback return 0 ret -_getKeyState_int_scanCode: ; int getKeyState(int scanCode) +_hid_getKeyState_int_scanCode:; int hid_getKeyState(int scanCode) pop V0 ; preserve function return address pop [$7215] ; param int scanCode push V0 ; restore function return address - mov $6033, [$7217] ; int hid = $6033 + mov $6033, [$7217] ; int sk_table = $6033 push [$7215] ; left operand mov 8, V1 ; right operand pop V0 ; get left operand back @@ -119,7 +119,7 @@ _getKeyState_int_scanCode: ; int getKeyState(int scanCode) mov 0, V0 ; fallback return 0 ret -_getPressedKey: ; int getPressedKey() +_hid_getPressedKey: ; int hid_getPressedKey() mov 0, [$721F] ; int sk = 0 _body_3: push [$721F] ; left operand @@ -130,7 +130,7 @@ _body_3: bz jmp _end_4 ; if for condition fails, jump to end push [$721F] ; arg int scanCode - call _getKeyState_int_scanCode; int getKeyState(int scanCode) + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) cmp V0, 0 ; logical and not bz @@ -163,12 +163,12 @@ _end_4: mov 0, V0 ; fallback return 0 ret -_readKey: ; int readKey() +_hid_waitForPressedKey: ; int hid_waitForPressedKey() _body_8: not 1 bz jmp _end_9 ; if while condition fails, jump to end - call _getPressedKey ; int getPressedKey() + call _hid_getPressedKey ; int hid_getPressedKey() mov V0, [$7221] ; int sk = V0 push [$7221] ; left operand mov 0, V1 ; right operand @@ -186,14 +186,14 @@ _end_9: mov 0, V0 ; fallback return 0 ret -_getMouseIndex: ; int getMouseIndex() +_hid_getMouseIndex: ; int hid_getMouseIndex() mov $602F, V0 ; move pointer into register for dereference mov [V0], V0 ; return value ret mov 0, V0 ; fallback return 0 ret -_getMouseState: ; int getMouseState() +_hid_getMouseState: ; int hid_getMouseState() push $602F ; left operand mov 2, V1 ; right operand pop V0 ; get left operand back @@ -283,7 +283,7 @@ _end_16: pop V0 ; get left operand back add V0, V1 ; compute addition push AX ; arg int c - call _setPixel_int_x__int_y__int_c; int setPixel(int x, int y, int c) + call _screen_setPixel_int_x__int_y__int_c; int screen_setPixel(int x, int y, int c) push [$7233] ; i++ inc [$7233] pop V0 @@ -383,13 +383,13 @@ _end_23: mov 0, [$7247] ; [$7247] = 0 mov 0, [$7249] ; [$7249] = 0 push 8 ; arg int c - call _clear_int_c ; int clear(int c) + call _screen_clear_int_c ; int screen_clear(int c) _end_24: - call _readKey ; int readKey() + call _hid_waitForPressedKey; int hid_waitForPressedKey() mov V0, [$724B] ; int sk = V0 _body_25: push [$724B] ; arg int scanCode - call _getKeyState_int_scanCode; int getKeyState(int scanCode) + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 bz jmp _end_26 ; if while condition fails, jump to end @@ -442,6 +442,23 @@ _end_29: call _drawChar_int_ch__int_x__int_y__int_color; int drawChar(int ch, int x, int y, int color) jmp _body_19 ; continue _end_28: + push 160 ; arg int scanCode + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) + not V0 + bz ; check if condition + jmp _end_30 ; if succeeds, continue, else jump to end + push [$724B] ; left operand + push 97 ; left operand + mov 65, V1 ; right operand + pop V0 ; get left operand back + sub V0, V1 ; compute subtraction + mov AX, V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + push AX ; computation results + pop V1 ; get computation results back + mov V1, [$724B] ; store back into left param +_end_30: push 1 ; arg int ch push [$7249] ; arg int x push [$7247] ; arg int y diff --git a/ROMs/typewriter.c b/ROMs/typewriter.c index a63a77d..278e048 100644 --- a/ROMs/typewriter.c +++ b/ROMs/typewriter.c @@ -1,5 +1,7 @@ #load "font.bin" -#include "lib.c" +#include "std.c" +#include "screen.c" +#include "hid.c" int drawChar(int ch, int x, int y, int color) { @@ -14,8 +16,8 @@ int drawChar(int ch, int x, int y, int color) 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 pix = bit ? COLOR_BLACK : color; + screen_setPixel(x + xOff, y + yOff, pix); } } } @@ -45,20 +47,20 @@ int main() { x = 0; y = 0; - clear(8); + screen_clear(COLOR_BLACK); } - int sk = readKey(); - while (getKeyState(sk)) { } + int sk = hid_waitForPressedKey(); + while (hid_getKeyState(sk)) { } - if (sk == SK_NL) + if (sk == SK_NEWLINE) { y += 8; x = 0; continue; } - if (sk == SK_BS) + if (sk == SK_BACKSPACE) { x -= 8; if (x < 0) @@ -66,8 +68,11 @@ int main() drawChar(' ', x, y, 1); continue; } + + if (hid_getKeyState(SK_SHIFT)) + sk += ('a' - 'A'); - drawChar(sk, x, y, 1); + drawChar(sk, x, y, COLOR_RED); x += 8; } }
\ No newline at end of file diff --git a/ROMs/typewriter.q1 b/ROMs/typewriter.q1 Binary files differindex 163bb6f..82d8114 100644 --- a/ROMs/typewriter.q1 +++ b/ROMs/typewriter.q1 |
