]> Joshua Wise's Git repositories - fpgaboy.git/blame_incremental - diag.asm
impact.cmd fix again
[fpgaboy.git] / diag.asm
... / ...
CommitLineData
1 section "end",HOME[1024]
2 nop
3
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
16
17main:
18 ld a, $FF
19 ld c, $51
20 ld [c], a
21
22 ld sp, $DFF0
23
24 ld a, $04 ;start timer, 4.096KHz
25 ld c, $07
26 ld [c], a
27
28 ld hl, $DF81
29 xor a
30 ld [hli], a
31 ld [hli], a
32
33 ld hl, signon
34 call puts
35
36 ei
37
38 call memtest
39
40 call insntest
41
42 call waitsw
43
44 di
45
46 jr main
47
48signon:
49 db $0D,$0A,$1B,"[1mFPGABoy Diagnostic ROM",$1B,"[0m",$0D,$0A,0
50
51vbl:
52 PUSH AF
53 PUSH BC
54 PUSH DE
55 PUSH HL
56
57 xor a
58 ld [$FF0F], a
59
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
72lcdc:
73 PUSH AF
74 PUSH BC
75
76 xor a
77 ld [$FF0F], a
78
79 POP BC
80 POP AF
81
82 reti
83
84tmro:
85 PUSH AF
86 PUSH BC
87 PUSH DE
88 PUSH HL
89
90 xor a
91 ld [$FF0F], a
92
93 ld c, $45 ; LYC
94 ld a, [c]
95 inc a
96 ld [c], a
97
98 ld a, [$DF82]
99 cp 0
100 jr z, .noprint
101 ld a, $41 ; print A
102 call putc
103.noprint:
104 ld a, [$DF81]
105 inc a
106 ld [$DF81], a
107 ld [$FF51], a
108
109 POP HL
110 POP DE
111 POP BC
112 POP AF
113 RETI
114
115; Memory tester: writes h ^ l to all addresses from C000 to DF80.
116memtest:
117 ld hl,memteststr
118 call puts
119
120 ld hl, $C000 ; Write loop
121.wr:
122 ld a,h
123 xor l
124 ld [hli],a
125 ld a, h
126 cp $DF
127 jr nz, .wr
128 ld a, l
129 cp $80
130 jr nz, .wr
131
132 ld hl, $C000 ; Read loop
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
141 ld a, h
142 cp $DF
143 jr nz, .rd
144 ld a, l
145 cp $80
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
153 dec [hl]
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
180 and $0F
181 add $30
182 call putc
183 pop af
184 and $0F
185 add $30
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
193
194 ld hl,$DF82
195 ld a, 1
196 ld [hl], a
197
198 ld c, $51
199 xor a
200 ld [c],a
201
202.loop1:
203 ld a,[c]
204 cp $0
205 jr z,.loop1
206.loop2:
207 ld a,[c]
208 cp $0
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
252 cp $0
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
274 cp $20
275 jr nc,.fail
276 ld a, $20
277 cp $10
278 jr c,.fail
279
280 ; Test CPL
281 ld hl, .cplfail
282 ld a, $55
283 cpl
284 cp $AA
285 jr nz,.fail
286
287 ; Test DI/EI delay
288 di
289 ld hl, .dinocausefail
290 ld c, $0F ; First, wait until an interrupt happens...
291.wait: ld a, [c]
292 and $04
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]
298 and $04
299 cp 0
300 jr z, .fail
301 ld hl, .dicausefail
302 ei ; Make sure that an IRQ does happen on EI/NOP/DI
303 nop
304 nop
305 di
306 ld a, [c]
307 and $04
308 cp 0
309 jr nz, .fail
310 ei
311
312 ld hl, .ok
313 call puts
314 ret
315.fail:
316 ei
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
339.dinocausefail:
340 db "DI/EI does not cause interrupt",0
341.dicausefail:
342 db "DI/NOP/EI cause interrupt",0
343.testfailed:
344 db " test failed.",$0D,$0A,0
345.ok:
346 db "OK!",$0D,$0A,0
347
348; Serial port manipulation functions.
349putc:
350 ld c, $50
351 push af
352.waitport:
353 ld a,[c]
354 cp $00
355 jr nz,.waitport
356 pop af
357 ld [c],a
358 ret
359
360puts:
361 ld a, [hli]
362 cp $00
363 ret z
364 call putc
365 jr puts
366
This page took 0.022029 seconds and 4 git commands to generate.