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