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