From 9e8ba6e00dc4a4137a5187dbe5fe5b1394219735 Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:20:03 +1000 Subject: stuff --- ROMs/life.asm | 404 ++++++++++++++++++++++++++++++ ROMs/life.c | 62 +++++ ROMs/life.q1 | Bin 0 -> 1376 bytes ROMs/logictest.asm | 140 +++++++++++ ROMs/logictest.c | 37 +++ ROMs/logictest.q1 | Bin 0 -> 477 bytes ROMs/paint.asm | 376 ++++++++++++++-------------- ROMs/typewriter.asm | 688 ++++++++++++++++++++++++++-------------------------- 8 files changed, 1175 insertions(+), 532 deletions(-) create mode 100644 ROMs/life.asm create mode 100644 ROMs/life.c create mode 100644 ROMs/life.q1 create mode 100644 ROMs/logictest.asm create mode 100644 ROMs/logictest.c create mode 100644 ROMs/logictest.q1 (limited to 'ROMs') diff --git a/ROMs/life.asm b/ROMs/life.asm new file mode 100644 index 0000000..d5250a0 --- /dev/null +++ b/ROMs/life.asm @@ -0,0 +1,404 @@ + jmp _main +_hid_getKeyState_int_scanCode:; int hid_getKeyState(int scanCode) + pop V0 ; preserve function return address + pop [$71FF] ; param int scanCode + push V0 ; restore function return address + 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, [$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, [$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 + mov AX, 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 + mov [V0], [$7207] ; int val = [V0] + push [$7207] ; left operand + push 1 ; left operand + mov [$7205], V1 ; right operand + pop V0 ; get left operand back + shl V0, V1 ; compute left shift + mov DX, V1 ; right operand + pop V0 ; get left operand back + and V0, V1 ; compute and + push DX ; left operand + mov 0, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute inequality check + not + mov LX, V0 ; return value + ret + mov 0, V0 ; fallback return 0 + ret + +_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_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_3 + mov 0, V0 ; first operand failed, store 0 and skip second + 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 + not + cmp LX, 0 ; compare result from second operand to 0 + not + mov LX, V0 ; store second operand result +_end_4: + not V0 + bz ; check if condition + jmp _end_5 ; if succeeds, continue, else jump to end + mov [$7209], V0 ; return value + ret +_end_5: + push [$7209] ; i++ + inc [$7209] + pop V0 + jmp _body_1 +_end_2: + mov 0, V0 ; return value + ret + mov 0, V0 ; fallback return 0 + ret + +_hid_waitForPressedKey: ; int hid_waitForPressedKey() +_body_6: + not 1 + bz + 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_8 ; if succeeds, continue, else jump to end + mov [$720B], V0 ; return value + ret +_end_8: + jmp _body_6 +_end_7: + mov 0, V0 ; fallback return 0 + ret + +_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 + +_hid_getMouseState: ; int hid_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 + +_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 + +_getState_char*_grid__int_index:; char getState(char* grid, int index) + pop V0 ; preserve function return address + pop [$7223] ; param char* grid + pop [$7225] ; param int index + push V0 ; restore function return address + push [$7225] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + div V0, V1 ; compute division + mov AX, [$7227] ; int byteIndex = AX + push [$7225] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + mod V0, V1 ; compute modulus + mov AX, [$7229] ; int bitIndex = AX + push [$7223] ; store index obj + mov [$7227], 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 + mov [V0], [$722B] ; int byte = [V0] + push [$722B] ; left operand + mov [$7229], V1 ; right operand + pop V0 ; get left operand back + shr V0, V1 ; compute right shift + push DX ; left operand + mov 1, V1 ; right operand + pop V0 ; get left operand back + and V0, V1 ; compute and + push DX ; left operand + mov 0, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute inequality check + not + mov LX, V0 ; return value + ret + mov 0, V0 ; fallback return 0 + ret + +_setState_char*_grid__int_index__int_state:; int setState(char* grid, int index, int state) + pop V0 ; preserve function return address + pop [$722D] ; param char* grid + pop [$722F] ; param int index + pop [$7231] ; param int state + push V0 ; restore function return address + push [$722F] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + div V0, V1 ; compute division + mov AX, [$7233] ; int byteIndex = AX + push [$722F] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + mod V0, V1 ; compute modulus + mov AX, [$7235] ; int bitIndex = AX + push [$722D] ; store index obj + mov [$7233], 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 + mov [V0], [$7237] ; int byte = [V0] + bz [$7231] ; check if condition + jmp _then_12 + ; if failed + push [$7237] ; left operand + push 1 ; left operand + mov [$7235], V1 ; right operand + pop V0 ; get left operand back + shl V0, V1 ; compute left shift + inv DX + mov DX, V1 ; right operand + pop V0 ; get left operand back + and V0, V1 ; compute and + push DX ; computation results + pop V1 ; get computation results back + mov V1, [$7237] ; store back into left param + jmp _end_11 +_then_12: ; if succeeded + push [$7237] ; left operand + push 1 ; left operand + mov [$7235], V1 ; right operand + pop V0 ; get left operand back + shl V0, V1 ; compute left shift + mov DX, V1 ; right operand + pop V0 ; get left operand back + or V0, V1 ; compute or + push DX ; computation results + pop V1 ; get computation results back + mov V1, [$7237] ; store back into left param +_end_11: + push [$722D] ; store index obj + mov [$7233], 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 [$7237], [V0] ; [V0] = [$7237] + mov 0, V0 ; fallback return 0 + ret + +_drawGrid_char*_grid: ; int drawGrid(char* grid) + pop V0 ; preserve function return address + pop [$7239] ; param char* grid + push V0 ; restore function return address + push 8 ; arg int c + call _screen_clear_int_c ; int screen_clear(int c) + mov 0, [$723B] ; int y = 0 +_body_13: + push [$723B] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check + not LX + bz + jmp _end_14 ; if for condition fails, jump to end + mov 0, [$723D] ; int x = 0 +_body_15: + push [$723D] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check + not LX + bz + jmp _end_16 ; if for condition fails, jump to end + push [$723B] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + mul V0, V1 ; compute multiplication + push AX ; left operand + mov [$723D], V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + mov AX, [$723F] ; int index = AX + push [$723F] ; arg int index + push [$7239] ; arg char* grid + call _getState_char*_grid__int_index; char getState(char* grid, int index) + not V0 + bz ; check if condition + jmp _end_17 ; if succeeds, continue, else jump to end + push 7 ; arg int c + push [$723B] ; arg int y + push [$723D] ; arg int x + call _screen_setPixel_int_x__int_y__int_c; int screen_setPixel(int x, int y, int c) +_end_17: + push [$723D] ; i++ + inc [$723D] + pop V0 + jmp _body_15 +_end_16: + push [$723B] ; i++ + inc [$723B] + pop V0 + jmp _body_13 +_end_14: + mov 0, V0 ; fallback return 0 + ret + +_main: ; int main() + mov $7243, [$7241] ; int grid = $7243 + ; clear memory + mov 0, [$724B] ; int i = 0 +_body_18: + push [$724B] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check + not LX + bz + jmp _end_19 ; if for condition fails, jump to end + push [$7241] ; store index obj + mov [$724B], 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 0, [V0] ; [V0] = 0 + push [$724B] ; i++ + inc [$724B] + pop V0 + jmp _body_18 +_end_19: + ; turn on pixel at (0,0) + push 1 ; arg int state + push 0 ; arg int index + push [$7241] ; arg char* grid + call _setState_char*_grid__int_index__int_state; int setState(char* grid, int index, int state) + push [$7241] ; arg char* grid + call _drawGrid_char*_grid ; int drawGrid(char* grid) +_body_20: + not 1 + bz + jmp _end_21 ; if while condition fails, jump to end + jmp _body_20 +_end_21: + mov 0, V0 ; fallback return 0 + ret + diff --git a/ROMs/life.c b/ROMs/life.c new file mode 100644 index 0000000..f35f9d0 --- /dev/null +++ b/ROMs/life.c @@ -0,0 +1,62 @@ +#include "std.c" +#include "hid.c" +#include "screen.c" + +#define GRID_SIZE 64 +#define GRID_BYTES 8 +#define GRID_WIDTH 8 +#define GRID_HEIGHT 8 + +char getState(char* grid, int index) +{ + int byteIndex = index / 8; + int bitIndex = index % 8; + int byte = grid[byteIndex]; + + return ((byte >> bitIndex) & 1) != 0; +} + +int setState(char* grid, int index, int state) +{ + int byteIndex = index / 8; + int bitIndex = index % 8; + int byte = grid[byteIndex]; + + if (state) + byte |= (1 << bitIndex); + else + byte &= ~(1 << bitIndex); + + grid[byteIndex] = byte; +} + +int drawGrid(char* grid) +{ + screen_clear(COLOR_BLACK); + + for (int y = 0; y < GRID_HEIGHT; y++) + { + for (int x = 0; x < GRID_WIDTH; x++) + { + int index = (y * GRID_WIDTH) + x; + if (getState(grid, index)) + screen_setPixel(x, y, COLOR_WHITE); + } + } +} + +int main() +{ + char* grid = new char[GRID_BYTES]; + + // clear memory + for (int i = 0; i < GRID_BYTES; i++) + grid[i] = 0; + + // turn on pixel at (0,0) + setState(grid, 0, 1); + + drawGrid(grid); + + while (1) { } +} \ No newline at end of file diff --git a/ROMs/life.q1 b/ROMs/life.q1 new file mode 100644 index 0000000..47e3f95 Binary files /dev/null and b/ROMs/life.q1 differ diff --git a/ROMs/logictest.asm b/ROMs/logictest.asm new file mode 100644 index 0000000..6a2aac1 --- /dev/null +++ b/ROMs/logictest.asm @@ -0,0 +1,140 @@ + jmp _main +_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 + pop [$7203] ; param int c + 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 + +_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 + 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 + +_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 + 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 + +_main: ; int main() + ; Test values + mov 0, [$7215] ; int a = 0 + ; 170 + mov 0, [$7217] ; int b = 0 + ; 204 + mov 0, [$7219] ; int c = 0 + ; AND + movb [$7215], [$7219] ; [$7219] = [$7215] + push [$7219] ; left operand + mov [$7217], V1 ; right operand + pop V0 ; get left operand back + and V0, V1 ; compute and + ; expect 0b10001000 = 136 + mov $7100, V0 ; move pointer into register for dereference + mov [V0], V0 ; move pointer into register for dereference + ; OR + movb [$7215], [$7219] ; [$7219] = [$7215] + push [$7219] ; left operand + mov [$7217], V1 ; right operand + pop V0 ; get left operand back + or V0, V1 ; compute or + ; expect 0b11101110 = 238 + mov $7101, V0 ; move pointer into register for dereference + mov [V0], V0 ; move pointer into register for dereference + ; XOR + movb [$7215], [$7219] ; [$7219] = [$7215] + push [$7219] ; left operand + mov [$7217], V1 ; right operand + pop V0 ; get left operand back + xor V0, V1 ; compute exclusive or + ; expect 0b01100110 = 102 + mov $7102, V0 ; move pointer into register for dereference + mov [V0], V0 ; move pointer into register for dereference + ; NOT + inv [$7215] + movb DX, [$7219] ; [$7219] = DX + ; expect 0b01010101 = 85 + mov $7103, V0 ; move pointer into register for dereference + mov [V0], V0 ; move pointer into register for dereference + ; SHL + movb [$7215], [$7219] ; [$7219] = [$7215] + push [$7219] ; left operand + mov 2, V1 ; right operand + pop V0 ; get left operand back + shl V0, V1 ; compute left shift + ; expect 0b10101000 = 168 + mov $7104, V0 ; move pointer into register for dereference + mov [V0], V0 ; move pointer into register for dereference + ; SHR + movb [$7215], [$7219] ; [$7219] = [$7215] + push [$7219] ; left operand + mov 2, V1 ; right operand + pop V0 ; get left operand back + shr V0, V1 ; compute right shift + ; expect 0b00101010 = 42 + mov $7105, V0 ; move pointer into register for dereference + mov [V0], V0 ; move pointer into register for dereference + ; Program ends cleanly + mov 0, V0 ; return value + ret + mov 0, V0 ; fallback return 0 + ret + diff --git a/ROMs/logictest.c b/ROMs/logictest.c new file mode 100644 index 0000000..f2ef6d9 --- /dev/null +++ b/ROMs/logictest.c @@ -0,0 +1,37 @@ +#include "std.c" +#include "screen.c" + +int main() +{ + // Test values + char a = 0b10101010; // 170 + char b = 0b11001100; // 204 + char c; + + // AND + c = a & b; // expect 0b10001000 = 136 + *((char*)0x7100) = c; + + // OR + c = a | b; // expect 0b11101110 = 238 + *((char*)0x7101) = c; + + // XOR + c = a ^ b; // expect 0b01100110 = 102 + *((char*)0x7102) = c; + + // NOT + c = ~a; // expect 0b01010101 = 85 + *((char*)0x7103) = c; + + // SHL + c = a << 2; // expect 0b10101000 = 168 + *((char*)0x7104) = c; + + // SHR + c = a >> 2; // expect 0b00101010 = 42 + *((char*)0x7105) = c; + + // Program ends cleanly + return 0; +} \ No newline at end of file diff --git a/ROMs/logictest.q1 b/ROMs/logictest.q1 new file mode 100644 index 0000000..f68eb77 Binary files /dev/null and b/ROMs/logictest.q1 differ diff --git a/ROMs/paint.asm b/ROMs/paint.asm index c5bfe14..9a853a4 100644 --- a/ROMs/paint.asm +++ b/ROMs/paint.asm @@ -1,264 +1,264 @@ jmp _main -_hid_getKeyState_int_scanCode: - pop V0 - pop [$71FF] - push V0 - mov $6033, [$7201] - push [$71FF] - mov 8, V1 - pop V0 - div V0, V1 - mov AX, [$7203] - push [$71FF] - mov 8, V1 - pop V0 - mod V0, V1 - mov AX, [$7205] - push [$7201] - push [$7203] - mov 1, V1 - pop V0 - sub V0, V1 - mov AX, V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - mov [V0], [$7207] - push [$7207] - push 1 - mov [$7205], V1 - pop V0 - shl V0, V1 - mov DX, V1 - pop V0 - and V0, V1 - push DX - mov 0, V1 - pop V0 - cmp V0, V1 +_hid_getKeyState_int_scanCode:; int hid_getKeyState(int scanCode) + pop V0 ; preserve function return address + pop [$71FF] ; param int scanCode + push V0 ; restore function return address + 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, [$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, [$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 + mov AX, 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 + mov [V0], [$7207] ; int val = [V0] + push [$7207] ; left operand + push 1 ; left operand + mov [$7205], V1 ; right operand + pop V0 ; get left operand back + shl V0, V1 ; compute left shift + mov DX, V1 ; right operand + pop V0 ; get left operand back + and V0, V1 ; compute and + push DX ; left operand + mov 0, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute inequality check not - mov LX, V0 + mov LX, V0 ; return value ret - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_hid_getPressedKey: - mov 0, [$7209] +_hid_getPressedKey: ; int hid_getPressedKey() + mov 0, [$7209] ; int sk = 0 _body_1: - push [$7209] - mov 256, V1 - pop V0 - lt V0, V1 + 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_2 - push [$7209] - call _hid_getKeyState_int_scanCode - cmp V0, 0 + 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_3 - mov 0, V0 + mov 0, V0 ; first operand failed, store 0 and skip second jmp _end_4 _clause_3: - push [$7209] - mov 160, V1 - pop V0 - cmp V0, V1 + push [$7209] ; left operand + mov 160, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute inequality check not - cmp LX, 0 + cmp LX, 0 ; compare result from second operand to 0 not - mov LX, V0 + mov LX, V0 ; store second operand result _end_4: not V0 - bz - jmp _end_5 - mov [$7209], V0 + bz ; check if condition + jmp _end_5 ; if succeeds, continue, else jump to end + mov [$7209], V0 ; return value ret _end_5: - push [$7209] + push [$7209] ; i++ inc [$7209] pop V0 jmp _body_1 _end_2: - mov 0, V0 + mov 0, V0 ; return value ret - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_hid_waitForPressedKey: +_hid_waitForPressedKey: ; int hid_waitForPressedKey() _body_6: not 1 bz - jmp _end_7 - call _hid_getPressedKey - mov V0, [$720B] - push [$720B] - mov 0, V1 - pop V0 - cmp V0, V1 + 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 - jmp _end_8 - mov [$720B], V0 + bz ; check if condition + jmp _end_8 ; if succeeds, continue, else jump to end + mov [$720B], V0 ; return value ret _end_8: jmp _body_6 _end_7: - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_hid_getMouseIndex: - mov $602F, V0 - mov [V0], V0 +_hid_getMouseIndex: ; int hid_getMouseIndex() + mov $602F, V0 ; move pointer into register for dereference + mov [V0], V0 ; return value ret - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_hid_getMouseState: - push $602F - mov 2, V1 - pop V0 - add V0, V1 - mov AX, V0 - mov [V0], V0 +_hid_getMouseState: ; int hid_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 + mov 0, V0 ; fallback return 0 ret -_screen_setPixel_int_x__int_y__int_c: - pop V0 - pop [$720D] - pop [$720F] - pop [$7211] - push V0 - mov $402F, [$7213] - push [$720F] - mov 128, V1 - pop V0 - mul V0, V1 - push AX - mov [$720D], V1 - pop V0 - add V0, V1 - mov AX, [$7215] - push [$7213] - mov [$7215], V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - movb [$7211], [V0] - mov 0, V0 +_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: - pop V0 - pop [$7217] - pop [$7219] - push V0 - mov $402F, [$721B] - push [$721B] - mov [$7217], V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - movb [$7219], [V0] - mov 0, V0 +_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: - pop V0 - pop [$721D] - push V0 - mov $402F, [$721F] - mov 0, [$7221] +_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] - push 128 - mov 64, V1 - pop V0 - mul V0, V1 - mov AX, V1 - pop V0 - lt V0, V1 + 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 - push [$721F] - mov [$7221], V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - movb [$721D], [V0] - push [$7221] + 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 + mov 0, V0 ; fallback return 0 ret -_main: - mov 0, [$7223] +_main: ; int main() + mov 0, [$7223] ; int color = 0 _body_11: not 1 bz - jmp _end_12 - call _hid_getMouseIndex - mov V0, [$7225] - call _hid_getMouseState - mov V0, [$7227] - push [$7227] - mov 1, V1 - pop V0 - and V0, V1 + jmp _end_12 ; if while condition fails, jump to end + call _hid_getMouseIndex ; int hid_getMouseIndex() + mov V0, [$7225] ; int mouseIndex = V0 + call _hid_getMouseState ; int hid_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 - jmp _end_13 - push [$7223] - mov 3, V1 - pop V0 - mod V0, V1 - push AX - mov 1, V1 - pop V0 - add V0, V1 - push AX - push [$7225] - call _screen_setPixel_int_i__int_c + bz ; check if condition + 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 + push AX ; left operand + mov 1, V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + push AX ; arg int i + push [$7225] ; arg int c + call _screen_setPixel_int_i__int_c; int screen_setPixel(int i, int c) _end_13: - push 67 - call _hid_getKeyState_int_scanCode + push 67 ; arg int scanCode + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 - bz - jmp _end_14 - push 8 - call _screen_clear_int_c + bz ; check if condition + jmp _end_14 ; if succeeds, continue, else jump to end + push 8 ; arg int c + call _screen_clear_int_c ; int screen_clear(int c) _end_14: - push 65 - call _hid_getKeyState_int_scanCode + push 65 ; arg int scanCode + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 - bz - jmp _end_15 - push [$7223] + bz ; check if condition + jmp _end_15 ; if succeeds, continue, else jump to end + push [$7223] ; i++ inc [$7223] pop V0 _body_16: - push 65 - call _hid_getKeyState_int_scanCode + push 65 ; arg int scanCode + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 bz - jmp _end_17 + 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 + mov 0, V0 ; fallback return 0 ret diff --git a/ROMs/typewriter.asm b/ROMs/typewriter.asm index a2369c3..a9379d9 100644 --- a/ROMs/typewriter.asm +++ b/ROMs/typewriter.asm @@ -1,461 +1,461 @@ jmp _main .include "font.bin" -_screen_setPixel_int_x__int_y__int_c: - pop V0 - pop [$71FF] - pop [$7201] - pop [$7203] - push V0 - mov $402F, [$7205] - push [$7201] - mov 128, V1 - pop V0 - mul V0, V1 - push AX - mov [$71FF], V1 - pop V0 - add V0, V1 - mov AX, [$7207] - push [$7205] - mov [$7207], V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - movb [$7203], [V0] - mov 0, V0 +_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 + pop [$7203] ; param int c + 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 -_screen_setPixel_int_i__int_c: - pop V0 - pop [$7209] - pop [$720B] - push V0 - mov $402F, [$720D] - push [$720D] - mov [$7209], V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - movb [$720B], [V0] - mov 0, V0 +_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 + 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 -_screen_clear_int_c: - pop V0 - pop [$720F] - push V0 - mov $402F, [$7211] - mov 0, [$7213] +_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 + mov $402F, [$7211] ; int screenStart = $402F + mov 0, [$7213] ; int i = 0 _body_1: - push [$7213] - push 128 - mov 64, V1 - pop V0 - mul V0, V1 - mov AX, V1 - pop V0 - lt V0, V1 + 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 - push [$7211] - mov [$7213], V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - movb [$720F], [V0] - push [$7213] + 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 + mov 0, V0 ; fallback return 0 ret -_hid_getKeyState_int_scanCode: - pop V0 - pop [$7215] - push V0 - mov $6033, [$7217] - push [$7215] - mov 8, V1 - pop V0 - div V0, V1 - mov AX, [$7219] - push [$7215] - mov 8, V1 - pop V0 - mod V0, V1 - mov AX, [$721B] - push [$7217] - push [$7219] - mov 1, V1 - pop V0 - sub V0, V1 - mov AX, V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - mov [V0], [$721D] - push [$721D] - push 1 - mov [$721B], V1 - pop V0 - shl V0, V1 - mov DX, V1 - pop V0 - and V0, V1 - push DX - mov 0, V1 - pop V0 - cmp V0, V1 +_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 sk_table = $6033 + push [$7215] ; 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 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 1, V1 ; right operand + pop V0 ; get left operand back + sub V0, V1 ; compute subtraction + mov AX, 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 + mov [V0], [$721D] ; int val = [V0] + push [$721D] ; left operand + push 1 ; left operand + mov [$721B], V1 ; right operand + pop V0 ; get left operand back + shl V0, V1 ; compute left shift + mov DX, V1 ; right operand + pop V0 ; get left operand back + and V0, V1 ; compute and + push DX ; left operand + mov 0, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute inequality check not - mov LX, V0 + mov LX, V0 ; return value ret - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_hid_getPressedKey: - mov 0, [$721F] +_hid_getPressedKey: ; int hid_getPressedKey() + mov 0, [$721F] ; int sk = 0 _body_3: - push [$721F] - mov 256, V1 - pop V0 - lt V0, V1 + 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 - push [$721F] - call _hid_getKeyState_int_scanCode - cmp V0, 0 + jmp _end_4 ; if for condition fails, jump to end + push [$721F] ; arg int scanCode + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) + cmp V0, 0 ; logical and not bz jmp _clause_5 - mov 0, V0 + mov 0, V0 ; first operand failed, store 0 and skip second jmp _end_6 _clause_5: - push [$721F] - mov 160, V1 - pop V0 - cmp V0, V1 + 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 + cmp LX, 0 ; compare result from second operand to 0 not - mov LX, V0 + mov LX, V0 ; store second operand result _end_6: not V0 - bz - jmp _end_7 - mov [$721F], 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] + push [$721F] ; i++ inc [$721F] pop V0 jmp _body_3 _end_4: - mov 0, V0 + mov 0, V0 ; return value ret - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_hid_waitForPressedKey: +_hid_waitForPressedKey: ; int hid_waitForPressedKey() _body_8: not 1 bz - jmp _end_9 - call _hid_getPressedKey - mov V0, [$7221] - push [$7221] - mov 0, V1 - pop V0 - cmp V0, V1 + jmp _end_9 ; if while condition fails, jump to end + call _hid_getPressedKey ; int hid_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 - jmp _end_10 - mov [$7221], V0 + 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 + mov 0, V0 ; fallback return 0 ret -_hid_getMouseIndex: - mov $602F, V0 - mov [V0], V0 +_hid_getMouseIndex: ; int hid_getMouseIndex() + mov $602F, V0 ; move pointer into register for dereference + mov [V0], V0 ; return value ret - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_hid_getMouseState: - push $602F - mov 2, V1 - pop V0 - add V0, V1 - mov AX, V0 - mov [V0], V0 +_hid_getMouseState: ; int hid_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 + mov 0, V0 ; fallback return 0 ret -_drawChar_int_ch__int_x__int_y__int_color: - pop V0 - pop [$7223] - pop [$7225] - pop [$7227] - pop [$7229] - push V0 +_drawChar_int_ch__int_x__int_y__int_color:; int drawChar(int ch, int x, int y, int color) + pop V0 ; preserve function return address + pop [$7223] ; param int ch + pop [$7225] ; param int x + pop [$7227] ; param int y + pop [$7229] ; param int color + push V0 ; restore function return address ; adjust for jmp instruction - push $1FFF - mov 2, V1 - pop V0 - add V0, V1 - mov AX, [$722B] - push [$7223] - mov 8, V1 - pop V0 - mul V0, V1 - mov AX, [$722D] - mov 0, [$722F] + push $1FFF ; left operand + mov 2, V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + mov AX, [$722B] ; int fontStart = AX + push [$7223] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + mul V0, V1 ; compute multiplication + mov AX, [$722D] ; int charStart = AX + mov 0, [$722F] ; int yOff = 0 _body_11: - push [$722F] - mov 8, V1 - pop V0 - lt V0, V1 + push [$722F] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check not LX bz - jmp _end_12 - push [$722B] - push [$722D] - mov [$722F], V1 - pop V0 - add V0, V1 - mov AX, V1 - pop V0 - mul V1, 1 - add AX, V0 - mov AX, V0 - mov [V0], [$7231] - mov 0, [$7233] + jmp _end_12 ; if for condition fails, jump to end + push [$722B] ; store index obj + push [$722D] ; left operand + mov [$722F], V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + mov AX, 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 + mov [V0], [$7231] ; int row = [V0] + mov 0, [$7233] ; int xOff = 0 _body_13: - push [$7233] - mov 8, V1 - pop V0 - lt V0, V1 + push [$7233] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check not LX bz - jmp _end_14 - push [$7231] - push 7 - mov [$7233], V1 - pop V0 - sub V0, V1 - mov AX, V1 - pop V0 - shr V0, V1 - push DX - mov 1, V1 - pop V0 - and V0, V1 - mov DX, [$7235] - bz [$7235] + jmp _end_14 ; if for condition fails, jump to end + push [$7231] ; left operand + push 7 ; left operand + mov [$7233], 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 + shr V0, V1 ; compute right shift + push DX ; left operand + mov 1, V1 ; right operand + pop V0 ; get left operand back + and V0, V1 ; compute and + mov DX, [$7235] ; int bit = DX + bz [$7235] ; check ternary condition jmp _then_15 - mov [$7229], V0 + mov [$7229], V0 ; store ternary fail result jmp _end_16 _then_15: - mov 8, V0 + mov 8, V0 ; store ternary success result _end_16: - mov V0, [$7237] - push [$7237] - push [$7227] - mov [$722F], V1 - pop V0 - add V0, V1 - push AX - push [$7225] - mov [$7233], V1 - pop V0 - add V0, V1 - push AX - call _screen_setPixel_int_x__int_y__int_c - push [$7233] + mov V0, [$7237] ; int pix = V0 + push [$7237] ; arg int x + push [$7227] ; left operand + mov [$722F], V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + push AX ; arg int y + push [$7225] ; left operand + mov [$7233], V1 ; right operand + pop V0 ; get left operand back + add V0, V1 ; compute addition + push AX ; arg 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 jmp _body_13 _end_14: - push [$722F] + push [$722F] ; i++ inc [$722F] pop V0 jmp _body_11 _end_12: - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_print_int*_text__int_len__int_x__int_y__int_color: - pop V0 - pop [$7239] - pop [$723B] - pop [$723D] - pop [$723F] - pop [$7241] - push V0 - mov 0, [$7243] +_print_int*_text__int_len__int_x__int_y__int_color:; int print(int* text, int len, int x, int y, int color) + pop V0 ; preserve function return address + pop [$7239] ; param int* text + pop [$723B] ; param int len + pop [$723D] ; param int x + pop [$723F] ; param int y + pop [$7241] ; param int color + push V0 ; restore function return address + mov 0, [$7243] ; int i = 0 _body_17: - push [$7243] - mov [$723B], V1 - pop V0 - lt V0, V1 + push [$7243] ; left operand + mov [$723B], V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check not LX bz - jmp _end_18 - push [$7239] - mov [$7243], V1 - pop V0 - mul V1, 2 - add AX, V0 - mov AX, V0 - mov [V0], [$7245] - push [$7241] - push [$723F] - push [$723D] - push [$7243] - mov 8, V1 - pop V0 - mul V0, V1 - mov AX, V1 - pop V0 - add V0, V1 - push AX - push [$7245] - call _drawChar_int_ch__int_x__int_y__int_color - push [$7243] + jmp _end_18 ; if for condition fails, jump to end + push [$7239] ; store index obj + mov [$7243], 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], [$7245] ; int ch = [V0] + push [$7241] ; arg int ch + push [$723F] ; arg int x + push [$723D] ; left operand + push [$7243] ; left operand + mov 8, 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 + add V0, V1 ; compute addition + push AX ; arg int y + push [$7245] ; arg int color + call _drawChar_int_ch__int_x__int_y__int_color; int drawChar(int ch, int x, int y, int color) + push [$7243] ; i++ inc [$7243] pop V0 jmp _body_17 _end_18: - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -_main: - mov 0, [$7247] - mov 0, [$7249] +_main: ; int main() + mov 0, [$7247] ; int x = 0 + mov 0, [$7249] ; int y = 0 _body_19: not 1 bz - jmp _end_20 - push [$7247] - mov 128, V1 - pop V0 - cmp V0, V1 + jmp _end_20 ; if while condition fails, jump to end + push [$7247] ; left operand + mov 128, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute equality check bz jmp _end_21 gt V0, V1 _end_21: not LX - bz - jmp _end_22 - mov 0, [$7247] - push [$7249] - mov 8, V1 - pop V0 - add V0, V1 - push AX - pop V1 - mov V1, [$7249] + bz ; check if condition + jmp _end_22 ; if succeeds, continue, else jump to end + mov 0, [$7247] ; [$7247] = 0 + push [$7249] ; left operand + mov 8, 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, [$7249] ; store back into left param _end_22: - push [$7249] - mov 64, V1 - pop V0 - cmp V0, V1 + push [$7249] ; left operand + mov 64, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute equality check bz jmp _end_23 gt V0, V1 _end_23: not LX - bz - jmp _end_24 - mov 0, [$7247] - mov 0, [$7249] - push 8 - call _screen_clear_int_c + bz ; check if condition + jmp _end_24 ; if succeeds, continue, else jump to end + mov 0, [$7247] ; [$7247] = 0 + mov 0, [$7249] ; [$7249] = 0 + push 8 ; arg int c + call _screen_clear_int_c ; int screen_clear(int c) _end_24: - call _hid_waitForPressedKey - mov V0, [$724B] + call _hid_waitForPressedKey; int hid_waitForPressedKey() + mov V0, [$724B] ; int sk = V0 _body_25: - push [$724B] - call _hid_getKeyState_int_scanCode + push [$724B] ; arg int scanCode + call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) not V0 bz - jmp _end_26 + jmp _end_26 ; if while condition fails, jump to end jmp _body_25 _end_26: - push [$724B] - mov 13, V1 - pop V0 - cmp V0, V1 + push [$724B] ; left operand + mov 13, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute equality check not LX - bz - jmp _end_27 - push [$7249] - mov 8, V1 - pop V0 - add V0, V1 - push AX - pop V1 - mov V1, [$7249] - mov 0, [$7247] - jmp _body_19 + bz ; check if condition + jmp _end_27 ; if succeeds, continue, else jump to end + push [$7249] ; left operand + mov 8, 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, [$7249] ; store back into left param + mov 0, [$7247] ; [$7247] = 0 + jmp _body_19 ; continue _end_27: - push [$724B] - mov 8, V1 - pop V0 - cmp V0, V1 + push [$724B] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + cmp V0, V1 ; compute equality check not LX - bz - jmp _end_28 - push [$7247] - mov 8, V1 - pop V0 - sub V0, V1 - push AX - pop V1 - mov V1, [$7247] - push [$7247] - mov 0, V1 - pop V0 - lt V0, V1 + bz ; check if condition + jmp _end_28 ; if succeeds, continue, else jump to end + push [$7247] ; left operand + mov 8, V1 ; right operand + pop V0 ; get left operand back + sub V0, V1 ; compute subtraction + push AX ; computation results + pop V1 ; get computation results back + mov V1, [$7247] ; store back into left param + push [$7247] ; left operand + mov 0, V1 ; right operand + pop V0 ; get left operand back + lt V0, V1 ; compute less than check not LX - bz - jmp _end_29 - mov 0, [$7247] + bz ; check if condition + jmp _end_29 ; if succeeds, continue, else jump to end + mov 0, [$7247] ; [$7247] = 0 _end_29: - push 1 - push [$7249] - push [$7247] - push 32 - call _drawChar_int_ch__int_x__int_y__int_color - jmp _body_19 + push 1 ; arg int ch + push [$7249] ; arg int x + push [$7247] ; arg int y + push 32 ; arg int color + 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 1 - push [$7249] - push [$7247] - push [$724B] - call _drawChar_int_ch__int_x__int_y__int_color - push [$7247] - mov 8, V1 - pop V0 - add V0, V1 - push AX - pop V1 - mov V1, [$7247] + push 1 ; arg int ch + push [$7249] ; arg int x + push [$7247] ; arg int y + push [$724B] ; arg int color + call _drawChar_int_ch__int_x__int_y__int_color; int drawChar(int ch, int x, int y, int color) + push [$7247] ; left operand + mov 8, 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, [$7247] ; store back into left param jmp _body_19 _end_20: - mov 0, V0 + mov 0, V0 ; fallback return 0 ret -- cgit v1.3.1