rev |
line source |
nuclear@0
|
1 ; vi:ft=rgbasm:
|
nuclear@4
|
2 ; -------- build options ----------
|
nuclear@4
|
3 BUILD_CHESS equ 1
|
nuclear@4
|
4 BUILD_LOGO equ 2
|
nuclear@4
|
5
|
nuclear@4
|
6 BUILD = BUILD_LOGO
|
nuclear@4
|
7 ; ---------------------------------
|
nuclear@4
|
8
|
nuclear@0
|
9 include "hw.inc"
|
nuclear@0
|
10
|
nuclear@0
|
11 xoffs_center equ 4
|
nuclear@0
|
12 yoffs_center equ 12
|
nuclear@0
|
13
|
nuclear@3
|
14 frame equ $ff80
|
nuclear@3
|
15 bnstate equ $ff81
|
nuclear@3
|
16 bnxor equ $ff82
|
nuclear@3
|
17 pause equ $ff83
|
nuclear@3
|
18
|
nuclear@3
|
19 BN_A equ $01
|
nuclear@3
|
20 BN_B equ $02
|
nuclear@3
|
21 BN_SELECT equ $04
|
nuclear@3
|
22 BN_START equ $08
|
nuclear@3
|
23 BN_RIGHT equ $10
|
nuclear@3
|
24 BN_LEFT equ $20
|
nuclear@3
|
25 BN_UP equ $40
|
nuclear@3
|
26 BN_DOWN equ $80
|
nuclear@0
|
27
|
nuclear@0
|
28 section "hdr", ROM0[$100]
|
nuclear@0
|
29 nop
|
nuclear@0
|
30 jp main
|
nuclear@0
|
31
|
nuclear@0
|
32 rept $150 - $104
|
nuclear@0
|
33 db 0
|
nuclear@0
|
34 endr
|
nuclear@0
|
35
|
nuclear@0
|
36 section "text", ROM0
|
nuclear@0
|
37
|
nuclear@0
|
38 main:
|
nuclear@0
|
39 call init
|
nuclear@0
|
40
|
nuclear@0
|
41 xor a, a
|
nuclear@3
|
42 ldh [frame], a
|
nuclear@3
|
43 ldh [bnstate], a
|
nuclear@3
|
44 ldh [bnxor], a
|
nuclear@3
|
45 ldh [pause], a
|
nuclear@3
|
46
|
nuclear@0
|
47 .mainloop:
|
nuclear@0
|
48 ldh a, [REG_LY]
|
nuclear@0
|
49 cp a, 144
|
nuclear@0
|
50 jr c, .wait_hsync
|
nuclear@0
|
51
|
nuclear@3
|
52 ; we're in vsync, increment frame counter, handle input,
|
nuclear@3
|
53 ; and wait for the next frame
|
nuclear@3
|
54 call read_input
|
nuclear@3
|
55
|
nuclear@3
|
56 ; swap palette if A is pressed
|
nuclear@3
|
57 ldh a, [bnxor]
|
nuclear@3
|
58 and a, BN_A
|
nuclear@3
|
59 jr z, .skip_akey ; skip if A haven't changed state since last frame
|
nuclear@3
|
60 ldh a, [bnstate]
|
nuclear@3
|
61 and a, BN_A
|
nuclear@3
|
62 jr z, .skip_akey ; skip if A is not pressed
|
nuclear@3
|
63 ldh a, [REG_BGP]
|
nuclear@3
|
64 cpl
|
nuclear@3
|
65 ldh [REG_BGP], a
|
nuclear@3
|
66 .skip_akey:
|
nuclear@3
|
67 ; toggle pause if start is pressed
|
nuclear@3
|
68 ldh a, [bnxor]
|
nuclear@3
|
69 and a, BN_START
|
nuclear@3
|
70 jr z, .skip_startkey ; skip if start haven't changed state since last frame
|
nuclear@3
|
71 ldh a, [bnstate]
|
nuclear@3
|
72 and a, BN_START
|
nuclear@3
|
73 jr z, .skip_startkey ; skip if start is not pressed
|
nuclear@3
|
74 ldh a, [pause]
|
nuclear@3
|
75 cpl
|
nuclear@3
|
76 ldh [pause], a
|
nuclear@3
|
77 .skip_startkey:
|
nuclear@3
|
78
|
nuclear@3
|
79 ; increment frame if we're not paused
|
nuclear@3
|
80 ldh a, [pause]
|
nuclear@3
|
81 bit 0, a
|
nuclear@3
|
82 jr nz, .skip_frameinc
|
nuclear@3
|
83 ldh a, [frame]
|
nuclear@0
|
84 inc a
|
nuclear@3
|
85 ldh [frame], a
|
nuclear@3
|
86 .skip_frameinc:
|
nuclear@3
|
87
|
nuclear@3
|
88
|
nuclear@0
|
89 .wait_newframe:
|
nuclear@0
|
90 ldh a, [REG_LY]
|
nuclear@0
|
91 cp a, 0
|
nuclear@0
|
92 jr nz, .wait_newframe
|
nuclear@0
|
93
|
nuclear@0
|
94 ; scanline code
|
nuclear@0
|
95 .wait_hsync:
|
nuclear@0
|
96 ldh a, [REG_STAT]
|
nuclear@0
|
97 and a, STAT_MODE_MASK
|
nuclear@0
|
98 jr nz, .wait_hsync
|
nuclear@0
|
99
|
nuclear@3
|
100 ldh a, [frame]
|
nuclear@0
|
101 ld d, a
|
nuclear@0
|
102
|
nuclear@0
|
103 xor a, a
|
nuclear@0
|
104 ld b, a
|
nuclear@1
|
105
|
nuclear@0
|
106 ldh a, [REG_LY]
|
nuclear@1
|
107 add a, d ; add frame number
|
nuclear@0
|
108 ld c, a
|
nuclear@0
|
109
|
nuclear@0
|
110 ld hl, sintab
|
nuclear@1
|
111 add hl, bc ; hl now points to the sine value
|
nuclear@0
|
112
|
nuclear@1
|
113 ld a, [hl]
|
nuclear@1
|
114
|
nuclear@1
|
115 ; add a half-octave sine
|
nuclear@1
|
116 ld e, a ; save first sine to e
|
nuclear@1
|
117 sla d
|
nuclear@1
|
118 ld a, [REG_LY]
|
nuclear@1
|
119 sla a
|
nuclear@1
|
120 add a, d
|
nuclear@1
|
121 ld c, a
|
nuclear@1
|
122 srl d
|
nuclear@1
|
123
|
nuclear@1
|
124 ld hl, sintab
|
nuclear@1
|
125 add hl, bc
|
nuclear@1
|
126 ld a, [hl]
|
nuclear@1
|
127 sra a
|
nuclear@1
|
128 add a, e ; add previously saved sine
|
nuclear@1
|
129
|
nuclear@1
|
130 add a, yoffs_center
|
nuclear@0
|
131 ldh [REG_SCY], a
|
nuclear@0
|
132
|
nuclear@1
|
133 ; do something for SCX too
|
nuclear@1
|
134 ld a, d
|
nuclear@1
|
135 sla a
|
nuclear@1
|
136 ld d, a
|
nuclear@1
|
137
|
nuclear@1
|
138 ldh a, [REG_LY]
|
nuclear@1
|
139 add a, 32
|
nuclear@1
|
140 add a, d ; add frame number
|
nuclear@1
|
141 ld c, a
|
nuclear@1
|
142
|
nuclear@1
|
143 ld hl, sintab
|
nuclear@1
|
144 add hl, bc
|
nuclear@1
|
145
|
nuclear@1
|
146 ld a, [hl]
|
nuclear@1
|
147 sra a
|
nuclear@1
|
148 add a, xoffs_center
|
nuclear@1
|
149 ldh [REG_SCX], a
|
nuclear@1
|
150
|
nuclear@0
|
151 ; done, wait until we're out of hsync
|
nuclear@0
|
152 .wait_endhsync:
|
nuclear@0
|
153 ldh a, [REG_STAT]
|
nuclear@0
|
154 and a, STAT_MODE_MASK
|
nuclear@0
|
155 jr z, .wait_endhsync
|
nuclear@0
|
156
|
nuclear@3
|
157 jp .mainloop
|
nuclear@0
|
158
|
nuclear@0
|
159
|
nuclear@0
|
160 di
|
nuclear@0
|
161 .end: halt
|
nuclear@0
|
162 nop
|
nuclear@0
|
163 jp .end
|
nuclear@0
|
164
|
nuclear@0
|
165 init:
|
nuclear@0
|
166 call wait_vsync
|
nuclear@0
|
167 xor a, a
|
nuclear@0
|
168 ldh [REG_LCDC], a
|
nuclear@0
|
169
|
nuclear@2
|
170 ; setup palette
|
nuclear@0
|
171 ld a, $1b
|
nuclear@0
|
172 ldh [REG_BGP], a
|
nuclear@0
|
173
|
nuclear@0
|
174 ; copy tiles
|
nuclear@0
|
175 ld hl, $8000
|
nuclear@0
|
176 ld de, tiles
|
nuclear@0
|
177 ld bc, tiles_end - tiles
|
nuclear@0
|
178 .copytiles:
|
nuclear@0
|
179 ld a, [de]
|
nuclear@0
|
180 ld [hl+], a
|
nuclear@0
|
181 inc de
|
nuclear@0
|
182 dec bc
|
nuclear@0
|
183 ld a, b
|
nuclear@0
|
184 or c
|
nuclear@0
|
185 jp nz, .copytiles
|
nuclear@0
|
186
|
nuclear@4
|
187 IF BUILD == BUILD_LOGO
|
nuclear@4
|
188 ; copy logo tilemap
|
nuclear@0
|
189 ld hl, $9800
|
nuclear@0
|
190 ld de, tilemap
|
nuclear@0
|
191 ld b, 21
|
nuclear@0
|
192 .copymap:
|
nuclear@0
|
193 ld c, 21
|
nuclear@0
|
194 .copymaprow:
|
nuclear@0
|
195 ld a, [de]
|
nuclear@0
|
196 inc de
|
nuclear@0
|
197 ld [hl+], a
|
nuclear@0
|
198 dec c
|
nuclear@0
|
199 jr nz, .copymaprow
|
nuclear@0
|
200
|
nuclear@0
|
201 push bc
|
nuclear@0
|
202 ld bc, 11
|
nuclear@0
|
203 add hl, bc
|
nuclear@0
|
204 pop bc
|
nuclear@0
|
205
|
nuclear@0
|
206 dec b
|
nuclear@0
|
207 jr nz, .copymap
|
nuclear@4
|
208 ELSE
|
nuclear@4
|
209 ; generate chessboard tilemap
|
nuclear@4
|
210 ld hl, $9800
|
nuclear@4
|
211 ld b, 32
|
nuclear@4
|
212 .fillscr:
|
nuclear@4
|
213 ld c, 32
|
nuclear@4
|
214 .fillrow:
|
nuclear@4
|
215 ld a, b
|
nuclear@4
|
216 add a, c
|
nuclear@4
|
217 and a, 1
|
nuclear@4
|
218
|
nuclear@4
|
219 ld [hl+], a
|
nuclear@4
|
220 dec c
|
nuclear@4
|
221 jr nz, .fillrow
|
nuclear@4
|
222
|
nuclear@4
|
223 dec b
|
nuclear@4
|
224 jr nz, .fillscr
|
nuclear@4
|
225 ENDC
|
nuclear@0
|
226
|
nuclear@0
|
227 ; center viewport
|
nuclear@0
|
228 ld a, yoffs_center
|
nuclear@0
|
229 ldh [REG_SCY], a
|
nuclear@0
|
230 ld a, xoffs_center
|
nuclear@0
|
231 ldh [REG_SCX], a
|
nuclear@0
|
232
|
nuclear@0
|
233 ; configure LCD
|
nuclear@0
|
234 ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON
|
nuclear@0
|
235 ldh [REG_LCDC], a
|
nuclear@0
|
236 ret
|
nuclear@0
|
237
|
nuclear@0
|
238 wait_vsync:
|
nuclear@0
|
239 ldh a, [REG_LY]
|
nuclear@0
|
240 cp a, 144
|
nuclear@0
|
241 jr c, wait_vsync
|
nuclear@0
|
242 ret
|
nuclear@0
|
243
|
nuclear@3
|
244 read_input:
|
nuclear@3
|
245 ; read D-pad
|
nuclear@3
|
246 ld a, P1_DPAD
|
nuclear@3
|
247 ld [REG_P1], a
|
nuclear@3
|
248 ld a, [REG_P1]
|
nuclear@3
|
249 ld a, [REG_P1]
|
nuclear@3
|
250 cpl
|
nuclear@3
|
251 and a, $0f
|
nuclear@3
|
252 swap a
|
nuclear@3
|
253 ld b, a
|
nuclear@3
|
254 ; read buttons
|
nuclear@3
|
255 ld a, P1_BUTTONS
|
nuclear@3
|
256 ld [REG_P1], a
|
nuclear@3
|
257 ld a, [REG_P1]
|
nuclear@3
|
258 ld a, [REG_P1]
|
nuclear@3
|
259 ld a, [REG_P1]
|
nuclear@3
|
260 ld a, [REG_P1]
|
nuclear@3
|
261 ld a, [REG_P1]
|
nuclear@3
|
262 ld a, [REG_P1]
|
nuclear@3
|
263 cpl
|
nuclear@3
|
264 and a, $0f
|
nuclear@3
|
265 or a, b
|
nuclear@3
|
266 ld b, a
|
nuclear@3
|
267 ; reset port
|
nuclear@3
|
268 ld a, P1_DPAD | P1_BUTTONS
|
nuclear@3
|
269 ldh [REG_P1], a
|
nuclear@3
|
270 ; calculate differences and save state variables
|
nuclear@3
|
271 ldh a, [bnstate]
|
nuclear@3
|
272 xor a, b
|
nuclear@3
|
273 ldh [bnxor], a
|
nuclear@3
|
274 ld a, b
|
nuclear@3
|
275 ldh [bnstate], a
|
nuclear@3
|
276 ret
|
nuclear@3
|
277
|
nuclear@0
|
278 section "data", ROM0, align[8]
|
nuclear@0
|
279 sintab:
|
nuclear@0
|
280 include "sin.inc"
|
nuclear@0
|
281
|
nuclear@4
|
282 IF BUILD == BUILD_LOGO
|
nuclear@0
|
283 tiles:
|
nuclear@0
|
284 incbin "logo.tiles"
|
nuclear@0
|
285 tiles_end:
|
nuclear@0
|
286 tilemap:
|
nuclear@0
|
287 incbin "logo.tilemap"
|
nuclear@0
|
288 tilemap_end:
|
nuclear@4
|
289
|
nuclear@4
|
290 ELSE
|
nuclear@4
|
291 ; chessboard tiles
|
nuclear@4
|
292 tiles:
|
nuclear@4
|
293 db $55,$00
|
nuclear@4
|
294 db $aa,$00
|
nuclear@4
|
295 db $55,$00
|
nuclear@4
|
296 db $aa,$00
|
nuclear@4
|
297 db $55,$00
|
nuclear@4
|
298 db $aa,$00
|
nuclear@4
|
299 db $55,$00
|
nuclear@4
|
300 db $aa,$00
|
nuclear@4
|
301
|
nuclear@4
|
302 db $ff,$aa
|
nuclear@4
|
303 db $ff,$55
|
nuclear@4
|
304 db $ff,$aa
|
nuclear@4
|
305 db $ff,$55
|
nuclear@4
|
306 db $ff,$aa
|
nuclear@4
|
307 db $ff,$55
|
nuclear@4
|
308 db $ff,$aa
|
nuclear@4
|
309 db $ff,$55
|
nuclear@4
|
310 tiles_end:
|
nuclear@4
|
311 ENDC
|