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