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