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