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