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