]> Joshua Wise's Git repositories - fpgaboy.git/blame - rom.asm
Test interrupts. They work!
[fpgaboy.git] / rom.asm
CommitLineData
616eebe0 1 SECTION "a",HOME
20204e79 2
616eebe0 3main:
20204e79 4 ld c, $51 ; Note that we are alive.
616eebe0
JW
5 ld a, $FF
6 ld [c],a
62940da0 7
20204e79
JW
8 ld sp, $DFFF
9
10 ld hl, signon
616eebe0 11 call puts
31833112
JW
12
13 ld c, $07
14 ld a, $04 ;start timer, 4.096KHz
15 ld [c], a
16 ei
616eebe0
JW
17
18 call memtest
20204e79
JW
19
20 call insntest
21
616eebe0 22 call waitsw
31833112 23 di
20204e79 24
9a5394d1 25 jr main
616eebe0 26
31833112
JW
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
20204e79 44signon:
97d31911 45 db $0D,$0A,$1B,"[1mFPGABoy Diagnostic ROM",$1B,"[0m",$0D,$0A,0
616eebe0 46
20204e79 47; Memory tester: writes h ^ l to all addresses from C000 to DF80.
616eebe0
JW
48memtest:
49 ld hl,memteststr
50 call puts
51
20204e79 52 ld hl, $C000 ; Write loop
616eebe0
JW
53.wr:
54 ld a,h
55 xor l
56 ld [hli],a
57 ld a, $DF
58 cp h
9a5394d1 59 jr nz, .wr
616eebe0
JW
60 ld a, $80
61 cp l
9a5394d1 62 jr nz, .wr
616eebe0 63
20204e79 64 ld hl, $C000 ; Read loop
616eebe0
JW
65.rd:
66 ld a,h
67 xor l
68 ld b,a
69 ld a, [hli]
70 cp b
9a5394d1 71 jr nz, .memfail
616eebe0
JW
72
73 ld a, $DF
74 cp h
9a5394d1 75 jr nz, .rd
616eebe0
JW
76 ld a, $80
77 cp l
9a5394d1 78 jr nz, .rd
616eebe0 79
20204e79 80 ld hl, testokstr ; Say we're OK
616eebe0
JW
81 call puts
82 ret
20204e79
JW
83.memfail: ; Say we failed (sadface)
84 ; decrement hl the easy way
616eebe0
JW
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
616eebe0
JW
99memteststr:
100 db "Testing memory from $C000 to $DF80...",0
101testokstr:
102 db " OK!",$0D,$0A,0
103failatstr:
104 db " Test failed at $",0
20204e79
JW
105
106puthex: ; Put two hex nibbles to the serial console.
616eebe0
JW
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
20204e79 125; Wait for switches to be flipped on and off again.
616eebe0
JW
126waitsw:
127 ld hl,waitswstr
128 call puts
31833112 129
616eebe0 130 ld c, $51
31833112 131 xor a
616eebe0
JW
132 ld [c],a
133
616eebe0 134 ld b, $0
31833112 135.loop1:
616eebe0
JW
136 ld a,[c]
137 cp b
9a5394d1 138 jr z,.loop1
616eebe0
JW
139.loop2:
140 ld a,[c]
141 cp b
9a5394d1 142 jr nz,.loop2
616eebe0
JW
143 ret
144
145waitswstr:
06ad3a30
JW
146 db "Diagnostic ROM complete; flip switches to nonzero and then to zero to reset. Expect A.",$0D,$0A,0
147
20204e79
JW
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
9a5394d1 163 jr nz,.fail
20204e79
JW
164 ld a, e
165 cp c
9a5394d1 166 jr nz,.fail
20204e79
JW
167
168 ; Test ALU (HL).
169 ld hl, .ff
170 ld a, $FF
171 xor [hl]
172 ld hl, .xorhlfail
9a5394d1 173 jr nz, .fail
20204e79 174
722e486a
JW
175 ; Test JP (HL)
176 ld hl, .jphl
177 jp [hl]
178 ld hl, .jphlfail
9a5394d1 179 jr .fail
722e486a
JW
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
9a5394d1 189 jr .fail
722e486a
JW
190 rst $00
191.jr:
dadf7990
JW
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
722e486a 204
20204e79
JW
205 ; Test CP.
206 ld hl, .cpfail
207 ld a, $10
208 ld b, $20
209 cp b
9a5394d1 210 jr nc,.fail
20204e79
JW
211 ld a, $20
212 ld b, $10
213 cp b
9a5394d1 214 jr c,.fail
20204e79
JW
215
216 ; Test CPL
217 ld hl, .cplfail
218 ld a, $55
219 ld b, $AA
220 cpl
221 cp b
9a5394d1 222 jr nz,.fail
20204e79
JW
223
224 ld hl, .ok
225 call puts
226 ret
227.fail:
611e4a90
JW
228 call puts
229 ld hl, .testfailed
20204e79
JW
230 call puts
231 ret
232.insnteststr:
611e4a90 233 db "Testing instructions... ",0
20204e79 234.pushpopfail:
611e4a90 235 db "PUSH/POP",0
20204e79
JW
236.ff:
237 db $FF
238.xorhlfail:
611e4a90 239 db "XOR [HL]",0
722e486a 240.jphlfail:
611e4a90 241 db "JP [HL]",0
722e486a 242.jrfail:
611e4a90 243 db "JR",0
20204e79 244.cpfail:
611e4a90 245 db "CP",0
20204e79 246.cplfail:
611e4a90 247 db "CPL",0
dadf7990
JW
248.inc16fail:
249 db "INC16",0
611e4a90 250.testfailed:
f26748f7 251 db " test failed.",$0D,$0A,0
20204e79
JW
252.ok:
253 db "OK!",$0D,$0A,0
254
255; Serial port manipulation functions.
616eebe0 256putc:
616eebe0
JW
257 ld b, 0
258 ld c, $50
62940da0 259 push af
616eebe0
JW
260.waitport:
261 ld a,[c]
262 cp b
9a5394d1 263 jr nz,.waitport
62940da0 264 pop af
616eebe0
JW
265 ld [c],a
266 ret
267
268puts:
269 ld a, [hli]
270 ld b, $00
271 cp b
62940da0 272 jr z, .done
616eebe0 273 call putc
9a5394d1 274 jr puts
62940da0
JW
275.done:
276 ret
This page took 0.053205 seconds and 4 git commands to generate.