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