summaryrefslogtreecommitdiff
path: root/ROMs/paint.asm
blob: 9a853a4879cdd62285178360bc733e5eed7e7e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
    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

_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 _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                        ; 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                   ; arg 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 _screen_clear_int_c  ; int screen_clear(int c)
_end_14:
    push 65                   ; arg 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
    push [$7223]              ; i++
    inc [$7223]
    pop V0
_body_16:
    push 65                   ; arg 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
    jmp _body_16
_end_17:
_end_15:
    jmp _body_11
_end_12:
    mov 0, V0                 ; fallback return 0
    ret