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