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