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