Cleaned up a little.
[ymamoto.git] / playtest.s
blob1f488d2fbb63277b51c03092e868aebeb98fa3c8
2 * Simple ST application to playback YMamoto tunes.
3 * This is based on some simple code that Michael Bricout gave me.
4 *
5 * Julian Squires <tek@wiw.org> / 2004-2005
8 section text
9 global _main
10 _main: MOVE.L #super_main, -(SP)
11 MOVE.W #38, -(SP)
12 TRAP #14 ; XBIOS Supexec
13 ADDQ.L #6, SP
15 MOVE.W #0, -(SP)
16 TRAP #1
17 ;;; main end.
19 extern ymamoto_init, ymamoto_reset, ymamoto_update
20 extern sine, cosine, step_sine_oscillator, reset_sine_oscillator
23 ; Vector addresses.
24 hbl_vector = $68
25 vbl_vector = $70
26 timer_b_vector = $120
28 super_main:
29 MOVEM.L D0-D7/A0-A1, -(SP)
30 BSR init
31 .0: CMPI.B #$39, $FFFC02 ; The ol' hit-space-to-continue bit.
32 BNE .0
33 BSR shutdown
34 MOVEM.L (SP)+, D0-D7/A0-A1
35 RTS
38 init: BTST #1, $FFFC00 ; ACIA Tx buffer full?
39 BEQ init
40 MOVE.B #$12, $FFFC02 ; I *hate* mice.
41 MOVE.B #0, $FFFC00
43 ; Setup music playback routine.
44 LEA tune_data, A0
45 MOVEQ #1, D0
46 BSR ymamoto_init
48 ; Save system palette.
49 MOVEM.L $FF8240, D0-D7
50 MOVEM.L D0-D7, saved_system_palette
51 ; Save system res.
52 MOVE.B $FF8260, D0
53 LEA saved_system_res, A0
54 MOVE.B D0, (A0)
56 MOVE.W #$2700, SR ; Mask interrupts.
58 MOVE.B #0, $FF8260 ; Shifter resolution -- low res.
59 MOVEQ #0, D0
60 MOVE.B $FF8201, D0 ; Video RAM address.
61 LSL.W #8, D0
62 MOVE.B $FF8203, D0
63 LSL.L #8, D0
64 ; XXX One more byte available on the STe.
66 ; Clear VRAM.
67 MOVE.L D0, vram_address
68 MOVE.L D0, A0
69 MOVE.W #32000/4, D1
70 MOVEQ #0, D0
71 .0: MOVE.L D0, (A0)+
72 DBF D1, .0
74 ; Save TOS VBL, HBL vectors, interrupt settings.
75 LEA old_vectors, A0
76 MOVE.L hbl_vector, (A0)+
77 MOVE.L vbl_vector, (A0)+
78 MOVE.L timer_b_vector, (A0)+
79 MOVE.B $FFFA07, (A0)+ ; Timers.
80 MOVE.B $FFFA09, (A0)+
81 MOVE.B $FFFA15, (A0)+
82 MOVE.B $FFFA17, (A0)+
83 MOVE.B $FFFA19, (A0)+
84 MOVE.B $FFFA1b, (A0)+
85 MOVE.B $FFFA1f, (A0)+
86 MOVE.B $FFFA21, (A0)+
87 ; Setup our own vbl, hbl handlers (HBL not called by default).
88 MOVE.L #raster_bars_vbl, vbl_vector
89 MOVE.L #hbl_handler, hbl_vector
91 BSR reset_sine_oscillator
92 CLR.W scrolly_pos
94 MOVE.W #$2300, SR ; Unmask most interrupts.
95 RTS
98 shutdown:
99 MOVE.W #$2700, SR ; Mask interrupts.
101 MOVE.B saved_system_res, $FF8260 ; Restore shifter res.
102 MOVEM.L saved_system_palette, D0-D7 ; Restore palette.
103 MOVEM.L D0-D7, $FF8240
105 ; Restore TOS VBL, timer B vectors.
106 LEA old_vectors, A0
107 MOVE.L (A0)+, hbl_vector
108 MOVE.L (A0)+, vbl_vector
109 MOVE.L (A0)+, timer_b_vector
110 MOVE.B (A0)+, $FFFA07 ; Timers.
111 MOVE.B (A0)+, $FFFA09
112 MOVE.B (A0)+, $FFFA15
113 MOVE.B (A0)+, $FFFA17
114 MOVE.B (A0)+, $FFFA19
115 MOVE.B (A0)+, $FFFA1b
116 MOVE.B (A0)+, $FFFA1f
117 MOVE.B (A0)+, $FFFA21
119 MOVE.W #$2300, SR ; Unmask interrupts.
121 BSR ymamoto_reset ; Mute YM.
123 MOVE.B #%10010110, $FFFC00 ; Interrupts on, 8N1, clock/64.
124 .0: BTST #1, $FFFC00 ; ACIA Tx buffer full?
125 BEQ .0
126 MOVE.B #8, $FFFC02 ; I suppose we'd better restore the mouse.
130 * Called each vertical blank.
131 raster_bars_vbl:
132 MOVEM.L D0-D2/A0-A2, -(SP)
134 MOVE.W #0, $FF8240 ; Black by default.
135 MOVE.W #$FFFF, $FF8242 ; White text.
137 ; Update sine values.
138 BSR step_sine_oscillator
140 ; Update positions of bars.
141 MOVE.W sine, D0 ; Circular motion around X axis.
142 ASR.W #2, D0
143 MOVE.W D0, bar_a_z
144 MOVE.W cosine, D0
145 ASR.W #2, D0
146 ADD.W #80, D0
147 MOVE.W D0, bar_a_y
149 MOVE.W sine, D0 ; Circular motion around X axis.
150 ASR.W #2, D0
151 ADD.W #20, D0
152 MOVE.W D0, bar_b_z
153 MOVE.W cosine, D0
154 ASR.W #3, D0
155 ADD.W #40, D0
156 MOVE.W D0, bar_b_y
158 ; Setup scanline/hblank routine.
159 CLR.B $FFFA1B ; Disable timer B.
160 MOVE.B bar_a_y+1, $FFFA21
161 MOVE.L #scanline_bar_a, timer_b_vector
162 MOVE.B #$18, $FFFA1B ; Enable timer B (event mode).
163 BSET #0, $FFFA07 ; intA enable timer B.
164 BSET #0, $FFFA13 ; intA mask, unmask timer B.
166 MOVE.W bar_a_y, scanline
167 MOVE.W #$310, next_palette_value
169 ; Update scrolly.
170 BSR update_scrolly
172 ; Update music.
173 LEA tune_data, A0
174 BSR ymamoto_update
176 MOVEM.L (SP)+, D0-D2/A0-A2
180 hbl_handler:
181 MOVE.W #$2300, SR ; disable ourselves.
184 scanline_bar_a:
185 MOVE.W next_palette_value, $FF8240
186 MOVEM.L D0-D2/A0, -(SP)
187 .0: ; get delta of current scanline to initial y
188 MOVE.W scanline, D0
189 MOVE.W bar_a_y, D1
190 SUB.W D1, D0 ; D0 = scanline - y_a
191 MOVE.W bar_b_y, D1
192 SUB.W D0, D1
193 BLE .2
195 CMP.W #40, D0
196 BGE .1
197 ; check Z, etc...
198 BRA .2
200 .1: ;MOVE.L #scanline_bar_b, timer_b_vector
201 ;MOVE.B #0, $FFFA1B
202 ;MOVE.B D1, $FFFA21
203 ;MOVE.B #$18, $FFFA1B
204 ;ADD.W D1, scanline
205 ;BRA 3f
207 .2: MOVE.B #0, $FFFA1B
208 MOVE.B #4, $FFFA21
209 MOVE.B #$18, $FFFA1B
210 ADD.W #4, scanline
212 .3: ; get color according to delta
213 LSR.B #1, D0
214 ADDQ.B #2, D0
215 CMP.B #20, D0
216 BLS .4
217 MOVEQ #20, D0
218 .4: LEA .5, A0
219 MOVE.W (A0,D0), D1
220 BRA .6
221 .5: DC.W $310, $421, $421, $632, $632, $632, $632
222 DC.W $421, $421, $310, 0
223 .6: ; XXX modify by Z
224 MOVE.W D1, next_palette_value
226 MOVEM.L (SP)+, D0-D2/A0
227 BCLR #0, $FFFA0F ; Ack interrupt?
231 ; 1bpp scrolltext along middle of screen.
232 update_scrolly:
233 ; XXX Test
234 MOVE.L vram_address, A0
235 ADD.W #11520, A0
237 MOVE.W scrolly_pos, D0
238 CMP.W #(scroll_text_len<<3), D0
239 BLS .0
240 CLR.W D0
241 MOVE.W D0, scrolly_pos
242 .0 AND.B #$07, D0
243 BNE .2
245 MOVE.W scrolly_pos, D0
246 LSR.W #3, D0
247 LEA scroll_text, A1
248 MOVEQ #0, D1
249 MOVE.B (A1,D0), D1
250 LEA one_bpp_font, A1
251 LSL.W #3, D1
252 ADD.W D1, A1
253 MOVEQ #7, D0
254 LEA scrolly_buffer, A2
255 .1 MOVE.B (A1)+, (A2)+
256 ADDQ.L #1, A2
257 DBF D0, .1
259 .2: MOVEQ #7, D0
260 LEA scrolly_buffer, A1
261 .3: LSL (A1)+
262 ROXL.W 152(A0)
263 ROXL.W 144(A0)
264 ROXL.W 136(A0)
265 ROXL.W 128(A0)
266 ROXL.W 120(A0)
267 ROXL.W 112(A0)
268 ROXL.W 104(A0)
269 ROXL.W 96(A0)
270 ROXL.W 88(A0)
271 ROXL.W 80(A0)
272 ROXL.W 72(A0)
273 ROXL.W 64(A0)
274 ROXL.W 56(A0)
275 ROXL.W 48(A0)
276 ROXL.W 40(A0)
277 ROXL.W 32(A0)
278 ROXL.W 24(A0)
279 ROXL.W 16(A0)
280 ROXL.W 8(A0)
281 ROXL.W (A0)
282 ADD.W #160, A0
283 DBF D0, .3
285 ADD.W #1, scrolly_pos
288 GLOBAL plot_debug_dword
289 plot_debug_dword:
290 MOVEM.L D0-D2/A0-A2, -(SP)
291 LEA debug_string_buf, A2
293 LEA hex_xlat, A1
294 MOVEQ #8-1, D1
295 .0: ROL.L #4, D0
296 MOVE.B D0, D2
297 AND.L #$f, D2
298 MOVE.B (A1,D2), (A2)+
299 DBF D1, .0
300 MOVE.B #0, (A2)+
301 LEA debug_string_buf, A2
302 BSR plot_debug_string
303 MOVEM.L (SP)+, D0-D2/A0-A2
307 ; A2 = address of string, NUL terminated.
308 plot_debug_string:
309 MOVE.L vram_address, A0
310 .0: MOVEQ #0, D0
311 MOVE.B (A2)+, D0
312 BEQ .1
313 LEA one_bpp_font, A1
314 LSL.W #3, D0
315 ADD.W D0, A1
316 MOVEQ #7, D0
317 .2: MOVE.B (A1)+, (A0)
318 ADD.W #160, A0
319 DBF D0, .2
320 SUB.W #1280, A0
321 MOVE.L A0, D0
322 BTST #0, D0
323 BNE .3
324 ADDQ.L #1, A0
325 BRA .0
326 .3: ADDQ.L #7, A0
327 BRA .0
328 .1: RTS
331 section bss
332 align 4
333 vram_address: ds.b 4
334 old_vectors: ds.b 20
335 saved_system_palette: ds.b 32
336 saved_system_res: ds.b 1
337 even
338 scrolly_pos: ds.b 2
339 scrolly_buffer: ds.b 16
340 scanline: ds.w 1
341 bar_a_y: ds.w 1
342 bar_a_z: ds.w 1
343 bar_b_y: ds.w 1
344 bar_b_z: ds.w 1
345 next_palette_value: ds.w 1
346 debug_string_buf: ds.b 10
348 section data
349 align 4
350 tune_data: incbin "ch-1.bin"
351 one_bpp_font: incbin "readable.f08"
352 scroll_text: DC.B "The mandatory scrolltext... tek speaking. Yes, it's unbelievable that I'm so lazy that I didn't implement any cool effects in this scrolly. I've been struggling with these damned MiNT cross-targetted binutils for the past two weeks -- I can never be sure whether the bugs are in my code or in the tools, because each available version of the binutils produces different eccentric behavior. Next time, I'll have all this stuff fixed, and probably will have jettisoned these fucking binutils for a real assembler/linker. Greets? Of course. Greets go out to the lonely St. John's scene, such as it is -- Retsyn, Michael (you need a new handle)... uh, and how about all the people who were sceners in some sense but then disappeared... off the top of my head I'm thinking of mr. nemo, jason, flyer, rubix... Anyway. Write more code! "
353 scroll_text_len = (. - scroll_text)
354 hex_xlat: DC.B "0123456789abcdef"
355 * vim:syn=asm68k