]> Joshua Wise's Git repositories - fpgaboy.git/blame_incremental - rom.asm
Rework it all to use the new macros.
[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, $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
19
20 ld hl, signon
21 call puts
22
23
24 ei
25
26 call memtest
27
28 call insntest
29
30 call waitsw
31 di
32
33 jr main
34
35 section "fuq",HOME[$50]
36irqhand:
37 PUSH AF
38 PUSH BC
39 PUSH DE
40 PUSH HL
41
42; ld c, $51
43; ld a, $F0
44; ld [c], a
45
46 xor a
47 ld c, $0F ; ack the irq
48 ld [c], a
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
66 POP HL
67 POP DE
68 POP BC
69 POP AF
70 RETI
71
72signon:
73 db $0D,$0A,$1B,"[1mFPGABoy Diagnostic ROM",$1B,"[0m",$0D,$0A,0
74
75; Memory tester: writes h ^ l to all addresses from C000 to DF80.
76memtest:
77 ld hl,memteststr
78 call puts
79
80 ld hl, $C001 ; Write loop
81.wr:
82 ld a,h
83 xor l
84 ld [hli],a
85 ld a, $DF
86 cp h
87 jr nz, .wr
88 ld a, $80
89 cp l
90 jr nz, .wr
91
92 ld hl, $C001 ; Read loop
93.rd:
94 ld a,h
95 xor l
96 ld b,a
97 ld a, [hli]
98 cp b
99 jr nz, .memfail
100
101 ld a, $DF
102 cp h
103 jr nz, .rd
104 ld a, $80
105 cp l
106 jr nz, .rd
107
108 ld hl, testokstr ; Say we're OK
109 call puts
110 ret
111.memfail: ; Say we failed (sadface)
112 ; decrement hl the easy way
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
127memteststr:
128 db "Testing memory from $C000 to $DF80...",0
129testokstr:
130 db " OK!",$0D,$0A,0
131failatstr:
132 db " Test failed at $",0
133
134puthex: ; Put two hex nibbles to the serial console.
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
153; Wait for switches to be flipped on and off again.
154waitsw:
155 ld hl,waitswstr
156 call puts
157
158 ld c, $51
159 xor a
160 ld [c],a
161
162 ld b, $0
163.loop1:
164 ld a,[c]
165 cp b
166 ei
167 jr z,.loop1
168.loop2:
169 ld a,[c]
170 cp b
171 jr nz,.loop2
172 ret
173
174waitswstr:
175 db "Diagnostic ROM complete; flip switches to nonzero and then to zero to reset. Expect A.",$0D,$0A,0
176
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
192 jr nz,.fail
193 ld a, e
194 cp c
195 jr nz,.fail
196
197 ; Test ALU (HL).
198 ld hl, .ff
199 ld a, $FF
200 xor [hl]
201 ld hl, .xorhlfail
202 jr nz, .fail
203
204 ; Test JP (HL)
205 ld hl, .jphl
206 jp [hl]
207 ld hl, .jphlfail
208 jr .fail
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
218 jr .fail
219 rst $00
220.jr:
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
233
234 ; Test CP.
235 ld hl, .cpfail
236 ld a, $10
237 ld b, $20
238 cp b
239 jr nc,.fail
240 ld a, $20
241 ld b, $10
242 cp b
243 jr c,.fail
244
245 ; Test CPL
246 ld hl, .cplfail
247 ld a, $55
248 ld b, $AA
249 cpl
250 cp b
251 jr nz,.fail
252
253 ld hl, .ok
254 call puts
255 ret
256.fail:
257 call puts
258 ld hl, .testfailed
259 call puts
260 ret
261.insnteststr:
262 db "Testing instructions... ",0
263.pushpopfail:
264 db "PUSH/POP",0
265.ff:
266 db $FF
267.xorhlfail:
268 db "XOR [HL]",0
269.jphlfail:
270 db "JP [HL]",0
271.jrfail:
272 db "JR",0
273.cpfail:
274 db "CP",0
275.cplfail:
276 db "CPL",0
277.inc16fail:
278 db "INC16",0
279.testfailed:
280 db " test failed.",$0D,$0A,0
281.ok:
282 db "OK!",$0D,$0A,0
283
284; Serial port manipulation functions.
285putc:
286 ld b, 0
287 ld c, $50
288 push af
289.waitport:
290 ld a,[c]
291 cp b
292 jr nz,.waitport
293 pop af
294 ld [c],a
295 ret
296
297puts:
298 ld a, [hli]
299 ld b, $00
300 cp b
301 ret z
302 call putc
303 jr puts
This page took 0.020879 seconds and 4 git commands to generate.