-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAUDIO3_TEST.s
462 lines (420 loc) · 7.65 KB
/
AUDIO3_TEST.s
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
.org 0 ; entry point
jmpf Start
.org $03 ; External int. (INT0) - I01CR
reti
.org $0B ; External int. (INT1) - I01CR
reti
.org $13 ; External int. (INT2) and Timer 0 low - I23CR and T0CNT
reti
.org $1B ; External int. (INT3) and base timer - I23CR and BTCR
reti
.org $23 ; Timer 0 high - T0CNT
reti
.org $2B ; Timer 1 Low and High - T1CNT
reti
.org $33 ; Serial IO 1 - SCON0
reti
.org $3B ; Serial IO 2 - SCON1
reti
.org $43 ; Maple - 160 and 161
reti
.org $4B ; Port 3 interrupt - P3INT
reti
.org $1F0 ; exit app mode
goodbye:
not1 EXT, 0
jmpf goodbye
.org $200
.byte "T1 MODE 3 TEST " ; ................... 16-byte Title
.byte "by https://github.com/jvsTSX " ; ... 32-byte Description
.org $240 ; >>> ICON HEADER
.org $260 ; >>> PALETTE TABLE
.org $280 ; >>> ICON DATA
; /////////////////////////////////////////////////////////////
; /// GAME CODE ///
; /////////////////////////////////////////////////////////////
.include "sfr.i"
LastKeys = $4
RegSel = $5
KeyRepCntLow = $6
KeyRepCntHigh = $7
TimerRelHigh = $8
TimerComHigh = $9
TimerRelLow = $A
TimerComLow = $B
Timer1Enables = $C
Start: ; setup
mov #0, IE
mov #%00000000, OCR
; setup RAM variables
mov #$FF, LastKeys
mov #0, RegSel
mov #$10, KeyRepCntLow
mov #$08, KeyRepCntHigh
mov #0, TimerRelHigh
mov #$80, TimerComHigh
mov #0, TimerRelLow
mov #$80, TimerComLow
mov #%11000000, Timer1Enables
mov #<Numbers, TRL
mov #>Numbers, TRH
; enable port 1 to output to buzzer
mov #$80, P1FCR
clr1 P1, 7
mov #$80, P1DDR
; initialize screen
mov #$80, 2
mov #0, XBNK
.Loop:
mov #0, @r2 ; line 1
inc 2
mov #0, @r2
inc 2
mov #0, @r2
inc 2
mov #0, @r2
inc 2
mov #0, @r2
inc 2
mov #0, @r2
inc 2
mov #0, @r2 ; line 2
inc 2
mov #0, @r2
inc 2
mov #0, @r2
inc 2
mov #0, @r2
inc 2
mov #0, @r2
inc 2
mov #0, @r2
ld 2
add #5
st 2
bnz .Loop
bp XBNK, 0, .LoopDone
inc XBNK
mov #80, 2
br .Loop
.LoopDone:
Main: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ld P3
st C
be LastKeys, NoButtonKeys ; check SMBA keys
st LastKeys
bp C, 4, .NoAkey ; increment register selector
inc RegSel
ld RegSel
and #%00000011
st RegSel
.NoAkey:
bp C, 5, .NoBkey ; apply register data
; disable T1 output
ld Timer1Enables
or #%00100000
st T1CNT
; update registers
ld TimerComHigh
st T1HC
ld TimerRelHigh
st T1HR
ld TimerComLow
st T1LC
ld TimerRelLow
st T1LR
; re-enable T1 output
ld Timer1Enables
or #%00110000
st T1CNT
.NoBkey:
bp C, 6, .NoMode ; go back to BIOS
jmpf goodbye
.NoMode:
bp C, 7, .NoSleep ; cycle timer speed
ld Timer1Enables
add #%01000000
st Timer1Enables
.NoSleep:
NoButtonKeys:
ld C ; check DPAD keys
or #%11110000
be #$FF, .NoDPADKeys
; repeat counter
dec KeyRepCntLow
ld KeyRepCntLow
bnz .NoDPADKeys
mov #$10, KeyRepCntLow
; configure indirect pointer
ld RegSel
add #8
st 0
bp C, 0, .NoUp ; increment high nibble
ld @r0
add #$10
st @r0
.NoUp:
bp C, 1, .NoDown ; decrement high nibble
ld @r0
sub #$10
st @r0
.NoDown:
bp C, 2, .NoLeft ; decrement low nibble
dec @r0
.NoLeft:
bp C, 3, .NoRight ; increment low nibble
inc @r0
.NoRight:
.NoDPADKeys:
; update register values
mov #0, XBNK
mov #$80, 2
ld TimerRelHigh
call DrawNumbers
mov #$C0, 2
ld TimerComHigh
call DrawNumbers
inc XBNK
mov #$80, 2
ld TimerRelLow
call DrawNumbers
mov #$C0, 2
ld TimerComLow
call DrawNumbers
; draw timer 1 enable states (tiny numbers)
mov #0, XBNK
ld Timer1Enables
ror
ror
ror
ror
add #$80 ; skip the big numbers, this way i don't need to reload TR
st C
ldc
st $185
inc C
ld C
ldc
st $18B
inc C
ld C
ldc
st $195
inc C
ld C
ldc
st $19B
; update cursor
clr1 $182, 7 ; clear all other cursor states
clr1 $1C2, 7
inc XBNK
clr1 $182, 7
clr1 $1C2, 7
dec XBNK
ld RegSel ; draw current cursor position
bne #0, .Not0 ; this looks stupid but it's faster
set1 $182, 7 ; for this case in specific
.Not0:
bne #1, .Not1
set1 $1C2, 7
.Not1:
inc XBNK
bne #2, .Not2
set1 $182, 7
.Not2:
bne #3, .Not3
set1 $1C2, 7
.Not3:
jmp Main
DrawNumbers: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; r0 = number rows to copy
; r1 = loop watch number (will exit when it hits 2)
; r2 = loop TR lookup index
; B = Number to display
; C = Nibble being displayed
mov #0, 1
mov #3, 0
st B
ror
ror
ror
ror
.NextNum:
rol
rol
rol
and #%01111000
st C
.Loop:
ld C
ldc
st @r2
inc C
ld 2
add #$6
st 2
ld C
ldc
st @r2
inc C
ld 2
add #$A
st 2
dbnz 0, .Loop
mov #3, 0
sub #$2F ; back to first line + next row
st 2
inc 1
ld 1
be #2, .Exit ; this will only allow the loop to run once again
ld B
br .NextNum
.Exit:
ret
Numbers: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.byte %01111100 ; 0
.byte %10001010
.byte %10010010
.byte %10010010
.byte %10100010
.byte %01111100
.byte $00
.byte $00
.byte %00010000 ; 1
.byte %00110000
.byte %01010000
.byte %00010000
.byte %00010000
.byte %11111110
.byte $00
.byte $00
.byte %01111100 ; 2
.byte %10000010
.byte %00000010
.byte %00011100
.byte %01100000
.byte %11111110
.byte $00
.byte $00
.byte %01111100 ; 3
.byte %10000010
.byte %00011100
.byte %00000010
.byte %10000010
.byte %01111100
.byte $00
.byte $00
.byte %00100100 ; 4
.byte %01000100
.byte %10000100
.byte %11111110
.byte %00000100
.byte %00000100
.byte $00
.byte $00
.byte %11111110 ; 5
.byte %10000000
.byte %11111100
.byte %00000010
.byte %10000010
.byte %01111100
.byte $00
.byte $00
.byte %00111100 ; 6
.byte %01000000
.byte %10000000
.byte %11111100
.byte %10000010
.byte %01111100
.byte $00
.byte $00
.byte %11111110 ; 7
.byte %00000010
.byte %00000100
.byte %00001000
.byte %00010000
.byte %00100000
.byte $00
.byte $00
.byte %00111100 ; 8
.byte %01000010
.byte %00111100
.byte %11000010
.byte %10000010
.byte %01111100
.byte $00
.byte $00
.byte %01111100 ; 9
.byte %10000010
.byte %01111110
.byte %00000010
.byte %00000100
.byte %01111000
.byte $00
.byte $00
.byte %00000110 ; A
.byte %00001010
.byte %00010010
.byte %00111110
.byte %01000010
.byte %10000010
.byte $00
.byte $00
.byte %11111100 ; B
.byte %10000010
.byte %11111100
.byte %10000010
.byte %10000010
.byte %11111100
.byte $00
.byte $00
.byte %01111100 ; C
.byte %10000010
.byte %10000000
.byte %10000000
.byte %10000010
.byte %01111100
.byte $00
.byte $00
.byte %11111000 ; D
.byte %10000110
.byte %10000010
.byte %10000010
.byte %10000110
.byte %11111000
.byte $00
.byte $00
.byte %11111110 ; E
.byte %10000000
.byte %11111000
.byte %10000000
.byte %10000000
.byte %11111110
.byte $00
.byte $00
.byte %11111110 ; F
.byte %10000000
.byte %11111000
.byte %10000000
.byte %10000000
.byte %10000000
.byte $00
.byte $00
NumbersTiny:
.byte %00000010 ; 1
.byte %00000110
.byte %00000010
.byte %00001111
.byte %00001110 ; 2
.byte %00000001
.byte %00000110
.byte %00001111
.byte %00001111 ; 3
.byte %00000111
.byte %00000001
.byte %00001111
.byte %00001010 ; 4
.byte %00001010
.byte %00001111
.byte %00000010
.cnop 0, $200