-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsing me a song, you're the piano man
297 lines (267 loc) · 11 KB
/
sing me a song, you're the piano man
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
HWID_KEYBOARD equ 0x4
HWID_HOLO equ 0x9
HOLO_CLEAR equ 0
HOLO_DISPLAY_HEX equ 1
HOLO_DISPLAY_STRING equ 2
KEYBOARD_FETCH_KEY equ 1
.text
jmp __start
_main:
mov bp,sp
sub sp,2
mov [bp-1],0
mov [bp-2],0
push 0x3333
call _DebugText
add sp,1
push 0x2222
call _DebugText
add sp,1
push 0x1111
call _DebugText
add sp,1
_main_outerloop:
mov a,[bp-1]
push a
push data
push display
call _RenderTextWindow
add sp,3
mov [bp-2],a
_main_innerloop:
mov a,[bp-2]
test a,a
jz _main_doneinnerloop
sub a,1
mov [bp-2],a
call _ClearScreen
call _FinishTick
jmp _main_innerloop
_main_doneinnerloop:
mov a,[bp-1]
add a,1
mov [bp-1],a
add a,data
cmp a,data_end ; can't do assemble-time arithmetic :(
jnz _main_offsetgood
mov [bp-1],0
_main_offsetgood:
jmp _main_outerloop
; int RenderTextWindow(int * display, int * str, int offset);
; returns how many frames the window should be displayed
_RenderTextWindow:
push bp
mov bp,sp
sub sp,2
push x
mov [bp-1],0
mov x,[bp+3]
add x,[bp+4]
mov [bp-2],x
mov y,[bp+2]
mov c,8
_RenderTextWindow_l1:
test c,c
jz _RenderTextWindow_l1d
sub c,1
mov b,[x]
test b,b
jz _RenderTextWindow_end
mov [y],b
add x,1
add y,1
jmp _RenderTextWindow_l1
_RenderTextWindow_l1d:
mov a,[bp+4]
test a,a
jz _RenderTextWindow_longdelay
mov x,[bp-2]
mov a,[x-1] ; if we are starting a new line
test a,a
jz _RenderTextWindow_longdelay
mov a,[x+8] ; or ending a line, delay long
test a,a
jz _RenderTextWindow_longdelay
mov [bp-1],1
jmp _RenderTextWindow_end
_RenderTextWindow_longdelay:
mov [bp-1],3
_RenderTextWindow_end:
mov a,[bp-1]
pop x
mov sp,bp
pop bp
ret
; void FormatDoubleHexToString(int * display, int first, int second);
_FormatDoubleHexToString:
push bp
mov bp,sp
push [bp+3]
push [bp+2]
call _FormatHexToString
add sp,2
push [bp+4]
mov a,[bp+2]
add a,4
push a
call _FormatHexToString
add sp,2
mov sp,bp
pop bp
ret
; void FormatHexToString(int * display, int hex);
_FormatHexToString:
push bp
mov bp,sp
mov y,[bp+2]
mov b,[bp+3]
mov a,b
shr a,12
call _FormatHexToString_loop
mov a,b
shr a,8
call _FormatHexToString_loop
mov a,b
shr a,4
call _FormatHexToString_loop
mov a,b
call _FormatHexToString_loop
mov sp,bp
pop bp
ret
_FormatHexToString_loop:
and a,0xf
cmp a,10
jl _FormatHexToString_noadd1
add a,7
_FormatHexToString_noadd1:
add a,0x30
mov [y],a
add y,1
ret
; void ClearScreen(void);
_ClearScreen:
push bp
mov bp,sp
mov a,HOLO_CLEAR
hwi HWID_HOLO
mov sp,bp
pop bp
ret
; void DebugText(int hex);
_DebugText:
push bp
mov bp,sp
mov a,[bp+2]
push a
call _DrawHexOnScreen
add sp,1
call _WaitForNextTick
mov sp,bp
pop bp
ret
; void DrawHexOnScreen(int hex);
_DrawHexOnScreen:
push bp
mov bp,sp
mov b,[bp+2]
mov a,HOLO_DISPLAY_HEX
hwi HWID_HOLO
mov sp,bp
pop bp
ret
; void DrawStringOnScreen(int * str);
_DrawStringOnScreen:
push bp
mov bp,sp
push x
mov x,[bp+2]
mov a,HOLO_DISPLAY_STRING
hwi HWID_HOLO
pop x
mov sp,bp
pop bp
ret
; void FinishTick(void);
_FinishTick:
push bp
mov bp,sp
push display
call _DrawStringOnScreen
add sp,1
call _WaitForNextTick
mov sp,bp
pop bp
ret
__start:
mov a,[restore_valid]
test a,a
jnz RestorePrevTickState
mov a,[initialized]
test a,a
jnz _InvalidRestore
mov a,1
mov [initialized],a
jmp _main
; void WaitForNextTick(void);
_WaitForNextTick:
push bp
mov [restore_sp],sp
mov a,1
mov [restore_valid],a
brk
RestorePrevTickState:
xor a,a
mov [restore_valid],a
mov sp,[restore_sp]
pop bp
ret
; void CrashPrgm(void);
_CrashPrgm:
brk
; void InvalidRestore(void);
_InvalidRestore:
mov sp,0x8000
mov bp,sp
mov a,KEYBOARD_FETCH_KEY
hwi HWID_KEYBOARD
cmp b,0x25
jz _left
cmp b,0x26
jz _up
cmp b,0x27
jz _right
cmp b,0x28
jz _down
jmp _none
_left:
sub [restore_dbg_ptr],1
jmp _none
_right:
add [restore_dbg_ptr],1
jmp _none
_down:
sub [restore_dbg_ptr],0x100
jmp _none
_up:
add [restore_dbg_ptr],0x100
jmp _none
_none:
mov a,[restore_dbg_ptr]
push [a]
push a
push display
call _FormatDoubleHexToString
add sp,3
push display
call _DrawStringOnScreen
add sp,1
brk
.data
data: dw 40,83,99,114,111,108,108,105,110,103,32,116,105,99,107,101,114,32,99,111,100,101,32,98,121,32,99,111,111,112,114,111,99,107,115,49,50,51,101,33,41,0,87,101,39,114,101,32,110,111,32,115,116,114,97,110,103,101,114,115,32,116,111,32,108,111,118,101,0,89,111,117,32,107,110,111,119,32,116,104,101,32,114,117,108,101,115,32,97,110,100,32,115,111,32,100,111,32,73,0,65,32,102,117,108,108,32,99,111,109,109,105,116,109,101,110,116,39,115,32,119,104,97,116,32,73,39,109,32,116,104,105,110,107,105,110,103,32,111,102,0,89,111,117,32,119,111,117,108,100,110,39,116,32,103,101,116,32,116,104,105,115,32,102,114,111,109,32,97,110,121,32,111,116,104,101,114,32,103,117,121,0,73,32,106,117,115,116,32,119,97,110,110,97,32,116,101,108,108,32,121,111,117,32,104,111,119,32,73,39,109,32,102,101,101,108,105,110,103,0,71,111,116,116,97,32,109,97,107,101,32,121,111,117,32,117,110,100,101,114,115,116,97,110,100,0,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,32,121,111,117,32,117,112,0,78,101,118,101,114,32,103,111,110,110,97,32,108,101,116,32,121,111,117,32,100,111,119,110,0,78,101,118,101,114,32,103,111,110,110,97,32,114,117,110,32,97,114,111,117,110,100,32,97,110,100,32,100,101,115,101,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,109,97,107,101,32,121,111,117,32,99,114,121,0,78,101,118,101,114,32,103,111,110,110,97,32,115,97,121,32,103,111,111,100,98,121,101,0,78,101,118,101,114,32,103,111,110,110,97,32,116,101,108,108,32,97,32,108,105,101,32,97,110,100,32,104,117,114,116,32,121,111,117,0,87,101,39,118,101,32,107,110,111,119,110,32,101,97,99,104,32,111,116,104,101,114,32,102,111,114,32,115,111,32,108,111,110,103,0,89,111,117,114,32,104,101,97,114,116,39,115,32,98,101,101,110,32,97,99,104,105,110,103,32,98,117,116,32,121,111,117,39,114,101,32,116,111,111,32,115,104,121,32,116,111,32,115,97,121,32,105,116,0,73,110,115,105,100,101,32,119,101,32,98,111,116,104,32,107,110,111,119,32,119,104,97,116,39,115,32,98,101,101,110,32,103,111,105,110,103,32,111,110,0,87,101,32,107,110,111,119,32,116,104,101,32,103,97,109,101,32,97,110,100,32,119,101,39,114,101,32,103,111,110,110,97,32,112,108,97,121,32,105,116,0,65,110,100,32,105,102,32,121,111,117,32,97,115,107,32,109,101,32,104,111,119,32,73,39,109,32,102,101,101,108,105,110,103,0,68,111,110,39,116,32,116,101,108,108,32,109,101,32,121,111,117,39,114,101,32,116,111,111,32,98,108,105,110,100,32,116,111,32,115,101,101,0,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,32,121,111,117,32,117,112,0,78,101,118,101,114,32,103,111,110,110,97,32,108,101,116,32,121,111,117,32,100,111,119,110,0,78,101,118,101,114,32,103,111,110,110,97,32,114,117,110,32,97,114,111,117,110,100,32,97,110,100,32,100,101,115,101,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,109,97,107,101,32,121,111,117,32,99,114,121,0,78,101,118,101,114,32,103,111,110,110,97,32,115,97,121,32,103,111,111,100,98,121,101,0,78,101,118,101,114,32,103,111,110,110,97,32,116,101,108,108,32,97,32,108,105,101,32,97,110,100,32,104,117,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,32,121,111,117,32,117,112,0,78,101,118,101,114,32,103,111,110,110,97,32,108,101,116,32,121,111,117,32,100,111,119,110,0,78,101,118,101,114,32,103,111,110,110,97,32,114,117,110,32,97,114,111,117,110,100,32,97,110,100,32,100,101,115,101,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,109,97,107,101,32,121,111,117,32,99,114,121,0,78,101,118,101,114,32,103,111,110,110,97,32,115,97,121,32,103,111,111,100,98,121,101,0,78,101,118,101,114,32,103,111,110,110,97,32,116,101,108,108,32,97,32,108,105,101,32,97,110,100,32,104,117,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,44,32,110,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,0,40,71,105,118,101,32,121,111,117,32,117,112,41,0,40,79,111,104,41,32,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,44,32,110,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,0,40,71,105,118,101,32,121,111,117,32,117,112,41,0,87,101,39,118,101,32,107,110,111,119,110,32,101,97,99,104,32,111,116,104,101,114,32,102,111,114,32,115,111,32,108,111,110,103,0,89,111,117,114,32,104,101,97,114,116,39,115,32,98,101,101,110,32,97,99,104,105,110,103,32,98,117,116,32,121,111,117,39,114,101,32,116,111,111,32,115,104,121,32,116,111,32,115,97,121,32,105,116,0,73,110,115,105,100,101,32,119,101,32,98,111,116,104,32,107,110,111,119,32,119,104,97,116,39,115,32,98,101,101,110,32,103,111,105,110,103,32,111,110,0,87,101,32,107,110,111,119,32,116,104,101,32,103,97,109,101,32,97,110,100,32,119,101,39,114,101,32,103,111,110,110,97,32,112,108,97,121,32,105,116,0,73,32,106,117,115,116,32,119,97,110,110,97,32,116,101,108,108,32,121,111,117,32,104,111,119,32,73,39,109,32,102,101,101,108,105,110,103,0,71,111,116,116,97,32,109,97,107,101,32,121,111,117,32,117,110,100,101,114,115,116,97,110,100,0,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,32,121,111,117,32,117,112,0,78,101,118,101,114,32,103,111,110,110,97,32,108,101,116,32,121,111,117,32,100,111,119,110,0,78,101,118,101,114,32,103,111,110,110,97,32,114,117,110,32,97,114,111,117,110,100,32,97,110,100,32,100,101,115,101,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,109,97,107,101,32,121,111,117,32,99,114,121,0,78,101,118,101,114,32,103,111,110,110,97,32,115,97,121,32,103,111,111,100,98,121,101,0,78,101,118,101,114,32,103,111,110,110,97,32,116,101,108,108,32,97,32,108,105,101,32,97,110,100,32,104,117,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,32,121,111,117,32,117,112,0,78,101,118,101,114,32,103,111,110,110,97,32,108,101,116,32,121,111,117,32,100,111,119,110,0,78,101,118,101,114,32,103,111,110,110,97,32,114,117,110,32,97,114,111,117,110,100,32,97,110,100,32,100,101,115,101,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,109,97,107,101,32,121,111,117,32,99,114,121,0,78,101,118,101,114,32,103,111,110,110,97,32,115,97,121,32,103,111,111,100,98,121,101,0,78,101,118,101,114,32,103,111,110,110,97,32,116,101,108,108,32,97,32,108,105,101,32,97,110,100,32,104,117,114,116,32,121,111,117,0,78,101,118,101,114,32,103,111,110,110,97,32,103,105,118,101,32,121,111,117,32,117,112,0,84,104,97,110,107,115,32,102,111,114,32,108,105,115,116,101,110,105,110,103,33,0
data_end:
display: dw 0,0,0,0,0,0,0,0,0,0
initialized: dw 0
restore_valid: dw 0
restore_sp: dw 0
restore_dbg_ptr: dw 0