Say ABCD.
[fpgaboy.git] / diag.asm
CommitLineData
fe3dc890
JW
1 section "end",HOME[1024]
2 nop
3
00573fd5
JW
4 SECTION "a",HOME[$00]
5
6start: jp main
7
8 section "vbl",HOME[$40]
9 jp vbl
10
11 section "lcdc",HOME[$48]
12 jp lcdc
13
14 section "tmro",HOME[$50]
15 jp tmro
5bac4cf0
JW
16
17main:
5bac4cf0 18 ld a, $FF
fe3dc890
JW
19 ld c, $51
20 ld [c], a
00573fd5 21
5bac4cf0
JW
22 ld sp, $DFF0
23
30ef1ae0 24 ld a, $04 ;start timer, 4.096KHz
00573fd5
JW
25 ld c, $07
26 ld [c], a
03202f62 27
30ef1ae0
JW
28 ld hl, $DF81
29 xor a
7e4f4505
JW
30 ld [hli], a
31 ld [hli], a
30ef1ae0 32
5bac4cf0
JW
33 ld hl, signon
34 call puts
39a68cde
JW
35
36 call putscreen
30ef1ae0
JW
37
38 ei
5bac4cf0
JW
39
40 call memtest
41
42 call insntest
43
44 call waitsw
30ef1ae0
JW
45
46 di
5bac4cf0
JW
47
48 jr main
49
50signon:
51 db $0D,$0A,$1B,"[1mFPGABoy Diagnostic ROM",$1B,"[0m",$0D,$0A,0
52
0dea04d3 53tiles:
ec727403
JW
54 db %01111100
55 db %11000110
56 db %11000110
57 db %11111110
58 db %11000110
59 db %11000110
60 db %11000110
0dea04d3 61 db %00000000
ec727403
JW
62
63 db %11111100
64 db %11000110
65 db %11000110
66 db %11111100
67 db %11000110
68 db %11000110
69 db %11111100
0dea04d3
JW
70 db %00000000
71
14778cde
JW
72 db %01111100
73 db %11000110
74 db %11000010
75 db %11000000
76 db %11000010
77 db %11000110
78 db %01111100
79 db %00000000
80
81 db %11111100
82 db %11000110
83 db %11000110
84 db %11000110
85 db %11000110
86 db %11000110
87 db %11111100
88 db %00000000
89
39a68cde 90putscreen:
4d90f272 91 ; Wait for vblank
80ecd2fe 92 call .vblwait
4d90f272
JW
93
94 ld hl, $8000 ; Copy two tiles.
0dea04d3 95 ld de, tiles
14778cde 96 ld c, $20
0dea04d3
JW
97.cloop: push hl
98 ld h, d
99 ld l, e
100 ld a, [hl]
101 inc de
102 pop hl
39a68cde
JW
103 ld [hli], a
104 ld [hli], a
0dea04d3 105 dec c
39a68cde 106 xor a
0dea04d3
JW
107 cp c
108 jr nz, .cloop
39a68cde
JW
109
110 ld hl, $9800
80ecd2fe
JW
111.vloop: call .vblwait
112 ld c, $40
0dea04d3 113 ld b, 0
14778cde
JW
114.loop: ld a, b
115 inc b
116 and $03
39a68cde
JW
117 ld [hli], a
118 ld a, h
119 cp $9C
80ecd2fe
JW
120 ret z
121 dec c
122 xor a
123 cp c
124 jr nz,.loop
125 jr .vloop
126
127.vblwait:
128.stat1: ld a, [$FF41] ; STAT
129 and $03
130 cp $00
131 jp nz, .stat1
132.stat2: ld a, [$FF41]
133 and $03
134 cp $01
135 jr nz, .stat2
39a68cde
JW
136 ret
137
00573fd5 138vbl:
03202f62
JW
139 PUSH AF
140 PUSH BC
141 PUSH DE
142 PUSH HL
143
144 xor a
f6fa1d6e
JW
145 ld [$FF0F], a
146
80ecd2fe
JW
147 ld a, [$FF51]
148 ld b, a
149 and $80
150 cp $80
151 jr nz, .nothing
152 ld c, $0
153
154 ld a, b
155 and $1
156 cp c
157 call nz, .scyup
158
159 ld a, b
160 and $2
161 cp c
162 call nz, .scydown
163
164 ld a, b
165 and $4
166 cp c
167 call nz, .scxup
168
169 ld a, b
170 and $8
171 cp c
172 call nz, .scxdown
173
174.nothing:
03202f62
JW
175 POP HL
176 POP DE
177 POP BC
178 POP AF
179
180 RETI
181
80ecd2fe
JW
182.scyup: ld hl, $FF42
183 inc [hl]
184 ret
185
186.scydown: ld hl, $FF42
187 dec [hl]
188 ret
189
190.scxup: ld hl, $FF43
191 inc [hl]
192 ret
193
194.scxdown: ld hl, $FF43
195 dec [hl]
196 ret
197
198
00573fd5
JW
199lcdc:
200 PUSH AF
fe3dc890 201 PUSH BC
00573fd5
JW
202
203 xor a
f6fa1d6e 204 ld [$FF0F], a
00573fd5 205
fe3dc890 206 POP BC
00573fd5
JW
207 POP AF
208
209 reti
210
211tmro:
30ef1ae0
JW
212 PUSH AF
213 PUSH BC
214 PUSH DE
215 PUSH HL
216
217 xor a
f6fa1d6e 218 ld [$FF0F], a
30ef1ae0 219
03202f62
JW
220 ld c, $45 ; LYC
221 ld a, [c]
222 inc a
223 ld [c], a
224
f6fa1d6e 225 ld a, [$DF82]
7e4f4505
JW
226 cp 0
227 jr z, .noprint
30ef1ae0
JW
228 ld a, $41 ; print A
229 call putc
7e4f4505 230.noprint:
f6fa1d6e
JW
231 ld a, [$DF81]
232 inc a
233 ld [$DF81], a
234 ld [$FF51], a
30ef1ae0 235
30ef1ae0
JW
236 POP HL
237 POP DE
238 POP BC
239 POP AF
240 RETI
30ef1ae0 241
5bac4cf0
JW
242; Memory tester: writes h ^ l to all addresses from C000 to DF80.
243memtest:
244 ld hl,memteststr
245 call puts
246
f6fa1d6e 247 ld hl, $C000 ; Write loop
5bac4cf0
JW
248.wr:
249 ld a,h
250 xor l
251 ld [hli],a
f888201b
JW
252 ld a, h
253 cp $DF
5bac4cf0 254 jr nz, .wr
f888201b
JW
255 ld a, l
256 cp $80
5bac4cf0
JW
257 jr nz, .wr
258
f6fa1d6e 259 ld hl, $C000 ; Read loop
5bac4cf0
JW
260.rd:
261 ld a,h
262 xor l
263 ld b,a
264 ld a, [hli]
265 cp b
266 jr nz, .memfail
267
f888201b
JW
268 ld a, h
269 cp $DF
5bac4cf0 270 jr nz, .rd
f888201b
JW
271 ld a, l
272 cp $80
5bac4cf0
JW
273 jr nz, .rd
274
275 ld hl, testokstr ; Say we're OK
276 call puts
277 ret
278.memfail: ; Say we failed (sadface)
279 ; decrement hl the easy way
f6fa1d6e 280 dec [hl]
5bac4cf0
JW
281 push hl
282 ld hl, failatstr
283 call puts
284 pop hl
285 ld a, h
286 call puthex
287 ld a, l
288 call puthex
289 ld a, $0A
290 call putc
291 ld a, $0D
292 call putc
293 ret
294memteststr:
295 db "Testing memory from $C000 to $DF80...",0
296testokstr:
297 db " OK!",$0D,$0A,0
298failatstr:
299 db " Test failed at $",0
300
301puthex: ; Put two hex nibbles to the serial console.
302 push af
303 rra
304 rra
305 rra
306 rra
f888201b
JW
307 and $0F
308 add $30
5bac4cf0
JW
309 call putc
310 pop af
f888201b
JW
311 and $0F
312 add $30
5bac4cf0
JW
313 call putc
314 ret
315
316; Wait for switches to be flipped on and off again.
317waitsw:
318 ld hl,waitswstr
319 call puts
7e4f4505
JW
320
321 ld hl,$DF82
322 ld a, 1
323 ld [hl], a
5bac4cf0
JW
324
325 ld c, $51
326 xor a
327 ld [c],a
328
5bac4cf0
JW
329.loop1:
330 ld a,[c]
f888201b 331 cp $0
5bac4cf0
JW
332 jr z,.loop1
333.loop2:
334 ld a,[c]
f888201b 335 cp $0
5bac4cf0
JW
336 jr nz,.loop2
337 ret
338
339waitswstr:
340 db "Diagnostic ROM complete; flip switches to nonzero and then to zero to reset. Expect A.",$0D,$0A,0
341
342; Core instruction basic acceptance tests.
343insntest:
344 ld hl, .insnteststr
345 call puts
346
347 ; Test PUSH and POP.
348 ld b, $12
349 ld c, $34
350 ld d, $56
351 ld e, $78
352 push bc
353 pop de
354 ld hl, .pushpopfail
355 ld a, d
356 cp b
357 jr nz,.fail
358 ld a, e
359 cp c
360 jr nz,.fail
361
362 ; Test ALU (HL).
363 ld hl, .ff
364 ld a, $FF
365 xor [hl]
366 ld hl, .xorhlfail
367 jr nz, .fail
368
369 ; Test JP (HL)
370 ld hl, .jphl
371 jp [hl]
372 ld hl, .jphlfail
373 jr .fail
374 rst $00
375.jphl:
376
377 ; Test JR
378 ld a, $FF
f888201b 379 cp $0
5bac4cf0
JW
380 jr nz,.jr
381 ld hl, .jrfail
382 jr .fail
383 rst $00
384.jr:
385
386 ; Test inc16
387 ld d, $12
388 ld e, $FF
389 ld hl, .inc16fail
390 inc de
391 ld a, $13
392 cp d
393 jr nz, .fail
394 ld a, $00
395 cp e
396 jr nz, .fail
397
398 ; Test CP.
399 ld hl, .cpfail
400 ld a, $10
f888201b 401 cp $20
5bac4cf0
JW
402 jr nc,.fail
403 ld a, $20
f888201b 404 cp $10
5bac4cf0
JW
405 jr c,.fail
406
407 ; Test CPL
408 ld hl, .cplfail
409 ld a, $55
5bac4cf0 410 cpl
f888201b 411 cp $AA
5bac4cf0 412 jr nz,.fail
f9000d73
JW
413
414 ; Test DI/EI delay
415 di
00573fd5 416 ld hl, .dinocausefail
f9000d73
JW
417 ld c, $0F ; First, wait until an interrupt happens...
418.wait: ld a, [c]
00573fd5 419 and $04
f9000d73
JW
420 cp 0
421 jr z, .wait
422 ei ; Now make sure that an IRQ didn't happen on EI/DI
423 di
424 ld a, [c]
00573fd5 425 and $04
f9000d73
JW
426 cp 0
427 jr z, .fail
00573fd5 428 ld hl, .dicausefail
f9000d73
JW
429 ei ; Make sure that an IRQ does happen on EI/NOP/DI
430 nop
00573fd5 431 nop
f9000d73
JW
432 di
433 ld a, [c]
00573fd5 434 and $04
f9000d73
JW
435 cp 0
436 jr nz, .fail
437 ei
5bac4cf0
JW
438
439 ld hl, .ok
440 call puts
441 ret
442.fail:
f9000d73 443 ei
5bac4cf0
JW
444 call puts
445 ld hl, .testfailed
446 call puts
447 ret
448.insnteststr:
449 db "Testing instructions... ",0
450.pushpopfail:
451 db "PUSH/POP",0
452.ff:
453 db $FF
454.xorhlfail:
455 db "XOR [HL]",0
456.jphlfail:
457 db "JP [HL]",0
458.jrfail:
459 db "JR",0
460.cpfail:
461 db "CP",0
462.cplfail:
463 db "CPL",0
464.inc16fail:
465 db "INC16",0
00573fd5
JW
466.dinocausefail:
467 db "DI/EI does not cause interrupt",0
468.dicausefail:
469 db "DI/NOP/EI cause interrupt",0
5bac4cf0
JW
470.testfailed:
471 db " test failed.",$0D,$0A,0
472.ok:
473 db "OK!",$0D,$0A,0
474
475; Serial port manipulation functions.
476putc:
5bac4cf0
JW
477 ld c, $50
478 push af
479.waitport:
480 ld a,[c]
f888201b 481 cp $00
5bac4cf0
JW
482 jr nz,.waitport
483 pop af
484 ld [c],a
485 ret
486
487puts:
488 ld a, [hli]
f888201b 489 cp $00
5bac4cf0
JW
490 ret z
491 call putc
492 jr puts
fe3dc890 493
This page took 0.122813 seconds and 4 git commands to generate.