It works.
[fpgaboy.git] / diag.asm
CommitLineData
5bac4cf0
JW
1 SECTION "a",HOME
2
3main:
4 ld c, $51 ; Note that we are alive.
5 ld a, $FF
6 ld [c],a
7
8 ld sp, $DFF0
9
30ef1ae0
JW
10 ld c, $07
11 ld a, $04 ;start timer, 4.096KHz
12 ld [c], a
13
14 ld hl, $DF81
15 xor a
16 ld [hl], a
17
5bac4cf0
JW
18 ld hl, signon
19 call puts
30ef1ae0
JW
20
21 ei
5bac4cf0
JW
22
23 call memtest
24
25 call insntest
26
27 call waitsw
30ef1ae0
JW
28
29 di
5bac4cf0
JW
30
31 jr main
32
33signon:
34 db $0D,$0A,$1B,"[1mFPGABoy Diagnostic ROM",$1B,"[0m",$0D,$0A,0
35
30ef1ae0
JW
36 section "fuq",HOME[$100]
37irqhand:
38 PUSH AF
39 PUSH BC
40 PUSH DE
41 PUSH HL
42
43 xor a
44 ld c, $0F ; ack the irq
45 ld [c], a
46
47 ld a, $41 ; print A
48 call putc
49
50 ld hl, $DF81
51 ld a, [hl]
52 ld b, 1
53 add b
54 ld c, $51
55 ld [c], a
56 ld [hl], a
57
58
59 POP HL
60 POP DE
61 POP BC
62 POP AF
63 RETI
64 db $18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE
65 db $18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE
66 db $18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE,$18,$FE
67
5bac4cf0
JW
68; Memory tester: writes h ^ l to all addresses from C000 to DF80.
69memtest:
70 ld hl,memteststr
71 call puts
72
73 ld hl, $C001 ; Write loop
74.wr:
75 ld a,h
76 xor l
77 ld [hli],a
78 ld a, $DF
79 cp h
80 jr nz, .wr
81 ld a, $80
82 cp l
83 jr nz, .wr
84
85 ld hl, $C001 ; Read loop
86.rd:
87 ld a,h
88 xor l
89 ld b,a
90 ld a, [hli]
91 cp b
92 jr nz, .memfail
93
94 ld a, $DF
95 cp h
96 jr nz, .rd
97 ld a, $80
98 cp l
99 jr nz, .rd
100
101 ld hl, testokstr ; Say we're OK
102 call puts
103 ret
104.memfail: ; Say we failed (sadface)
105 ; decrement hl the easy way
106 ld a,[hld]
107 push hl
108 ld hl, failatstr
109 call puts
110 pop hl
111 ld a, h
112 call puthex
113 ld a, l
114 call puthex
115 ld a, $0A
116 call putc
117 ld a, $0D
118 call putc
119 ret
120memteststr:
121 db "Testing memory from $C000 to $DF80...",0
122testokstr:
123 db " OK!",$0D,$0A,0
124failatstr:
125 db " Test failed at $",0
126
127puthex: ; Put two hex nibbles to the serial console.
128 push af
129 rra
130 rra
131 rra
132 rra
133 ld b,$0F
134 and b
135 ld b,$30
136 add b
137 call putc
138 pop af
139 ld b,$0F
140 and b
141 ld b,$30
142 add b
143 call putc
144 ret
145
146; Wait for switches to be flipped on and off again.
147waitsw:
148 ld hl,waitswstr
149 call puts
150
151 ld c, $51
152 xor a
153 ld [c],a
154
155 ld b, $0
156.loop1:
157 ld a,[c]
158 cp b
159 jr z,.loop1
160.loop2:
161 ld a,[c]
162 cp b
163 jr nz,.loop2
164 ret
165
166waitswstr:
167 db "Diagnostic ROM complete; flip switches to nonzero and then to zero to reset. Expect A.",$0D,$0A,0
168
169; Core instruction basic acceptance tests.
170insntest:
171 ld hl, .insnteststr
172 call puts
173
174 ; Test PUSH and POP.
175 ld b, $12
176 ld c, $34
177 ld d, $56
178 ld e, $78
179 push bc
180 pop de
181 ld hl, .pushpopfail
182 ld a, d
183 cp b
184 jr nz,.fail
185 ld a, e
186 cp c
187 jr nz,.fail
188
189 ; Test ALU (HL).
190 ld hl, .ff
191 ld a, $FF
192 xor [hl]
193 ld hl, .xorhlfail
194 jr nz, .fail
195
196 ; Test JP (HL)
197 ld hl, .jphl
198 jp [hl]
199 ld hl, .jphlfail
200 jr .fail
201 rst $00
202.jphl:
203
204 ; Test JR
205 ld a, $FF
206 ld b, $00
207 cp b
208 jr nz,.jr
209 ld hl, .jrfail
210 jr .fail
211 rst $00
212.jr:
213
214 ; Test inc16
215 ld d, $12
216 ld e, $FF
217 ld hl, .inc16fail
218 inc de
219 ld a, $13
220 cp d
221 jr nz, .fail
222 ld a, $00
223 cp e
224 jr nz, .fail
225
226 ; Test CP.
227 ld hl, .cpfail
228 ld a, $10
229 ld b, $20
230 cp b
231 jr nc,.fail
232 ld a, $20
233 ld b, $10
234 cp b
235 jr c,.fail
236
237 ; Test CPL
238 ld hl, .cplfail
239 ld a, $55
240 ld b, $AA
241 cpl
242 cp b
243 jr nz,.fail
244
245 ld hl, .ok
246 call puts
247 ret
248.fail:
249 call puts
250 ld hl, .testfailed
251 call puts
252 ret
253.insnteststr:
254 db "Testing instructions... ",0
255.pushpopfail:
256 db "PUSH/POP",0
257.ff:
258 db $FF
259.xorhlfail:
260 db "XOR [HL]",0
261.jphlfail:
262 db "JP [HL]",0
263.jrfail:
264 db "JR",0
265.cpfail:
266 db "CP",0
267.cplfail:
268 db "CPL",0
269.inc16fail:
270 db "INC16",0
271.testfailed:
272 db " test failed.",$0D,$0A,0
273.ok:
274 db "OK!",$0D,$0A,0
275
276; Serial port manipulation functions.
277putc:
278 ld b, 0
279 ld c, $50
280 push af
281.waitport:
282 ld a,[c]
283 cp b
284 jr nz,.waitport
285 pop af
286 ld [c],a
287 ret
288
289puts:
290 ld a, [hli]
291 ld b, $00
292 cp b
293 ret z
294 call putc
295 jr puts
This page took 0.043217 seconds and 4 git commands to generate.