diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-28 21:57:33 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-28 21:57:33 +1000 |
| commit | 76cea79a46d42f8f59503d3bb421f0d298da66cb (patch) | |
| tree | dc4310f667068f97ff6b8488d203b55202bc274a /ROMs/paint.asm | |
| parent | cf7e621c104cb4aea801392585d2dcc9335bc013 (diff) | |
implemented standard library
Diffstat (limited to 'ROMs/paint.asm')
| -rw-r--r-- | ROMs/paint.asm | 185 |
1 files changed, 129 insertions, 56 deletions
diff --git a/ROMs/paint.asm b/ROMs/paint.asm index 2f023b7..b4d454f 100644 --- a/ROMs/paint.asm +++ b/ROMs/paint.asm @@ -25,7 +25,7 @@ _setPixel_int_x__int_y__int_c:; int setPixel(int x, int y, int c) mov 0, V0 ; fallback return 0 ret -_setPixelIndex_int_i__int_c: ; int setPixelIndex(int i, int c) +_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 @@ -46,29 +46,28 @@ _clear_int_c: ; int clear(int c) pop [$720F] ; param int c push V0 ; restore function return address mov $402F, [$7211] ; int screenStart = $402F - push 64 ; left operand - mov 128, V1 ; right operand + 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, [$7213] ; int screenSize = AX - mov 0, [$7215] ; int i = 0 -_body_1: - push [$7215] ; left operand - mov [$7213], V1 ; right operand + 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 [$7215], V1 ; store indexer + 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 [$7215] ; i++ - inc [$7215] + push [$7213] ; i++ + inc [$7213] pop V0 jmp _body_1 _end_2: @@ -77,21 +76,21 @@ _end_2: _getKeyState_int_scanCode: ; int getKeyState(int scanCode) pop V0 ; preserve function return address - pop [$7217] ; param int scanCode + pop [$7215] ; param int scanCode push V0 ; restore function return address - mov $6033, [$7219] ; int hid = $6033 - push [$7217] ; left operand + mov $6033, [$7217] ; int hid = $6033 + push [$7215] ; left operand mov 8, V1 ; right operand pop V0 ; get left operand back div V0, V1 ; compute division - mov AX, [$721B] ; int index = AX - push [$7217] ; left operand + mov AX, [$7219] ; int index = AX + push [$7215] ; left operand mov 8, V1 ; right operand pop V0 ; get left operand back mod V0, V1 ; compute modulus - mov AX, [$721D] ; int bit = AX - push [$7219] ; store index obj - push [$721B] ; left operand + mov AX, [$721B] ; int bit = AX + push [$7217] ; store index obj + push [$7219] ; left operand mov 1, V1 ; right operand pop V0 ; get left operand back sub V0, V1 ; compute subtraction @@ -100,10 +99,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], [$721F] ; int val = [V0] - push [$721F] ; left operand + mov [V0], [$721D] ; int val = [V0] + push [$721D] ; left operand push 1 ; left operand - mov [$721D], V1 ; right operand + mov [$721B], V1 ; right operand pop V0 ; get left operand back shl V0, V1 ; compute left shift mov DX, V1 ; right operand @@ -119,35 +118,109 @@ _getKeyState_int_scanCode: ; int getKeyState(int scanCode) mov 0, V0 ; fallback return 0 ret -_main: ; int main() - mov 0, [$7221] ; int color = 0 +_getPressedKey: ; int getPressedKey() + mov 0, [$721F] ; int sk = 0 _body_3: + push [$721F] ; 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) + cmp V0, 0 ; logical and + not + bz + jmp _clause_5 + mov 0, V0 ; first operand failed, store 0 and skip second + jmp _end_6 +_clause_5: + push [$721F] ; left operand + mov 160, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute inequality check + not + cmp LX, 0 ; compare result from second operand to 0 + not + mov LX, V0 ; store second operand result +_end_6: + not V0 + bz ; check if condition + jmp _end_7 ; if succeeds, continue, else jump to end + mov [$721F], V0 ; return value + ret +_end_7: + push [$721F] ; i++ + inc [$721F] + pop V0 + jmp _body_3 +_end_4: + mov 0, V0 ; return value + ret + mov 0, V0 ; fallback return 0 + ret + +_readKey: ; int readKey() +_body_8: not 1 bz - jmp _end_4 ; if while condition fails, jump to end - mov $602F, [$7223] ; int hid = $602F - push [$7223] ; store index obj - mov 0, V1 ; store indexer - pop V0 ; restore index obj - mul V1, 2 ; multiply indexer by 2 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$7225] ; int mouseIndex = [V0] - push [$7223] ; store index obj - mov 1, V1 ; store indexer - pop V0 ; restore index obj - mul V1, 2 ; multiply indexer by 2 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$7227] ; int mouseState = [V0] + jmp _end_9 ; if while condition fails, jump to end + call _getPressedKey ; int getPressedKey() + mov V0, [$7221] ; int sk = V0 + push [$7221] ; 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 + ret +_end_10: + jmp _body_8 +_end_9: + mov 0, V0 ; fallback return 0 + ret + +_getMouseIndex: ; int 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() + push $602F ; left operand + mov 2, V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + mov AX, V0 ; move pointer into register for dereference + mov [V0], V0 ; return value + ret + 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() + mov V0, [$7225] ; int mouseIndex = V0 + call _getMouseState ; int getMouseState() + mov V0, [$7227] ; int mouseState = V0 push [$7227] ; left operand mov 1, V1 ; right operand pop V0 ; get left operand back and V0, V1 ; compute and not DX bz ; check if condition - jmp _end_5 ; if succeeds, continue, else jump to end - push [$7221] ; left operand + jmp _end_13 ; if succeeds, continue, else jump to end + push [$7223] ; left operand mov 3, V1 ; right operand pop V0 ; get left operand back mod V0, V1 ; compute modulus @@ -157,35 +230,35 @@ _body_3: add V0, V1 ; compute addition push AX ; arg int i push [$7225] ; arg int c - call _setPixelIndex_int_i__int_c; int setPixelIndex(int i, int c) -_end_5: + call _setPixel_int_i__int_c; int setPixel(int i, int c) +_end_13: push 67 ; arg int scanCode call _getKeyState_int_scanCode; int getKeyState(int scanCode) not V0 bz ; check if condition - jmp _end_6 ; if succeeds, continue, else jump to end + jmp _end_14 ; if succeeds, continue, else jump to end push 8 ; arg int c call _clear_int_c ; int clear(int c) -_end_6: +_end_14: push 65 ; arg int scanCode call _getKeyState_int_scanCode; int getKeyState(int scanCode) not V0 bz ; check if condition - jmp _end_7 ; if succeeds, continue, else jump to end - push [$7221] ; i++ - inc [$7221] + jmp _end_15 ; if succeeds, continue, else jump to end + push [$7223] ; i++ + inc [$7223] pop V0 -_body_8: +_body_16: push 65 ; arg int scanCode call _getKeyState_int_scanCode; int getKeyState(int scanCode) not V0 bz - jmp _end_9 ; if while condition fails, jump to end - jmp _body_8 -_end_9: -_end_7: - jmp _body_3 -_end_4: + jmp _end_17 ; if while condition fails, jump to end + jmp _body_16 +_end_17: +_end_15: + jmp _body_11 +_end_12: mov 0, V0 ; fallback return 0 ret |
