/[projet1]/public/oric/demos/SlideShowDemo/code/player.s
Defence Force logotype

Contents of /public/oric/demos/SlideShowDemo/code/player.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1015 - (show annotations)
Thu Dec 12 20:53:08 2013 UTC (6 years, 1 month ago) by dbug
File size: 8769 byte(s)
Archived the latest version of the loader code.
It's still pretty much work in progress, but it would suck that my hard drive dies :p
1 ; To check: AYC
2 ; http://cpcwiki.eu/index.php/AYC
3
4 #include "floppy_description.h"
5
6 .zero
7
8 _DecodedByte .dsb 1 ; Byte being currently decoded from the MYM stream
9 _DecodeBitCounter .dsb 1 ; Number of bits we can read in the current byte
10 _DecodedResult .dsb 1 ; What is returned by the 'read bits' function
11
12 _CurrentAYRegister .dsb 1 ; Contains the number of the register being decoded
13
14 _RegisterBufferHigh .dsb 1 ; Points to the high byte of the decoded register buffer, increment to move to the next register
15 _BufferFrameOffset .dsb 1 ; From 0 to 127, used when filling the decoded register buffer
16
17 _MusicResetCounter .dsb 2 ; Contains the number of rows to play before reseting
18
19 _CurrentFrame .dsb 1 ; From 0 to 255 and then cycles... the index of the frame to play this vbl
20
21 _PlayerVbl .dsb 1
22 _MusicLooped .dsb 1
23
24 _FrameLoadBalancer .dsb 1 ; We depack a new frame every 9 VBLs, this way the 14 registers are evenly depacked over 128 frames
25
26
27 .text
28
29 #define VIA_1 $30f
30 #define VIA_2 $30c
31
32 #define _MusicData $c000
33
34 _PlayerCount .byt 0
35 ;_CurrentMusic .byt LOADER_FIRST_MUSIC
36
37
38 ;
39 ; Current PSG values during unpacking
40 ;
41 _PlayerRegValues
42 _RegisterChanAFrequency
43 ; Chanel A Frequency
44 .byt 8
45 .byt 4
46
47 _RegisterChanBFrequency
48 ; Chanel B Frequency
49 .byt 8
50 .byt 4
51
52 _RegisterChanCFrequency
53 ; Chanel C Frequency
54 .byt 8
55 .byt 4
56
57 _RegisterChanNoiseFrequency
58 ; Chanel sound generator
59 .byt 5
60
61 ; select
62 .byt 8
63
64 ; Volume A,B,C
65 _RegisterChanAVolume
66 .byt 5
67 _RegisterChanBVolume
68 .byt 5
69 _RegisterChanCVolume
70 .byt 5
71
72 ; Wave period
73 .byt 8
74 .byt 8
75
76 ; Wave form
77 .byt 8
78
79 _PlayerRegCurrentValue .byt 0
80
81
82 _Mym_ReInitialize
83 .(
84 sei
85 lda #0
86 sta _MusicLooped
87 jsr _Mym_Initialize
88 cli
89 rts
90 .)
91
92 _Mym_Initialize
93 .(
94 ; The two first bytes of the MYM music is the number of rows in the music
95 ; We decrement that at each frame, and when we reach zero, time to start again.
96 ldx _MusicData+0
97 stx _MusicResetCounter+0
98 ldx _MusicData+1
99 inx
100 stx _MusicResetCounter+1
101
102 .(
103 ; Initialize the read bit counter
104 lda #<(_MusicData+2)
105 sta __auto_music_ptr+1
106 lda #>(_MusicData+2)
107 sta __auto_music_ptr+2
108
109 lda #1
110 sta _DecodeBitCounter
111
112 ; Clear all data
113 lda #0
114 sta _DecodedResult
115 sta _DecodedByte
116 sta _PlayerVbl
117 sta _PlayerRegCurrentValue
118 sta _BufferFrameOffset
119 sta _PlayerCount
120 sta _CurrentAYRegister
121 sta _CurrentFrame
122
123 ldx #14
124 loop_init
125 dex
126 sta _PlayerRegValues,x
127 bne loop_init
128 .)
129
130 ;
131 ; Unpack the 128 first register frames
132 ;
133 .(
134 lda #>_PlayerBuffer
135 sta _RegisterBufferHigh
136
137 ldx #0
138 unpack_block_loop
139 stx _CurrentAYRegister
140
141 ; Unpack that register
142 jsr _PlayerUnpackRegister2
143
144 ; Next register
145 ldx _CurrentAYRegister
146 inx
147 cpx #14
148 bne unpack_block_loop
149 .)
150
151 lda #128
152 sta _PlayerVbl+0
153
154 lda #0
155 sta _PlayerCount
156 sta _CurrentAYRegister
157 sta _CurrentFrame
158
159 lda #9
160 sta _FrameLoadBalancer
161 rts
162 .)
163
164
165
166 _Mym_PlayFrame
167 .(
168 ;
169 ; Check for end of music
170 ; CountZero: $81,$0d
171 dec _MusicResetCounter+0
172 bne music_contines
173 dec _MusicResetCounter+1
174 bne music_contines
175 music_resets
176 lda #1
177 sta _MusicLooped
178 jsr _Mym_Initialize
179
180 music_contines
181
182 ;
183 ; Play a frame of 14 registers
184 ;
185 .(
186 lda _CurrentFrame
187 sta _auto_psg_play_read+1
188 lda #>_PlayerBuffer
189 sta _auto_psg_play_read+2
190
191 ldy #0
192 register_loop
193
194 _auto_psg_play_read
195 ldx _PlayerBuffer
196
197 sty VIA_1
198 txa
199
200 pha
201 lda VIA_2
202 ora #$EE ; $EE 238 11101110
203 sta VIA_2
204
205 and #$11 ; $11 17 00010001
206 ora #$CC ; $CC 204 11001100
207 sta VIA_2
208
209 tax
210 pla
211 sta VIA_1
212 txa
213 ora #$EC ; $EC 236 11101100
214 sta VIA_2
215
216 and #$11 ; $11 17 00010001
217 ora #$CC ; $CC 204 11001100
218 sta VIA_2
219
220 inc _auto_psg_play_read+2
221 iny
222 cpy #14
223 bne register_loop
224 .)
225
226
227 inc _CurrentFrame
228 inc _PlayerCount
229
230 lda _CurrentAYRegister
231 cmp #14
232 bcs end_reg
233
234 .(
235 dec _FrameLoadBalancer
236 bne end
237
238 jsr _PlayerUnpackRegister
239 inc _CurrentAYRegister
240 lda #9
241 sta _FrameLoadBalancer
242 end
243 rts
244 .)
245
246 end_reg
247 .(
248 lda _PlayerCount
249 cmp #128
250 bcc skip
251
252 lda #0
253 sta _CurrentAYRegister
254 sta _PlayerCount
255 lda #9
256 sta _FrameLoadBalancer
257
258 clc
259 lda _PlayerVbl+0
260 adc #128
261 sta _PlayerVbl+0
262 skip
263 .)
264
265 rts
266 .)
267
268
269
270
271 ;
272 ; Initialise X with the number of bits to read
273 ; Y is not modifier
274 ; A is saved and restored..
275 ;
276 _ReadBits
277 pha
278
279 lda #0
280 sta _DecodedResult
281
282 ; Will iterate X times (number of bits to read)
283 loop_read_bits
284
285 dec _DecodeBitCounter
286 bne end_reload
287
288 ; reset mask
289 lda #8
290 sta _DecodeBitCounter
291
292 ; fetch a new byte, and increment the adress.
293 __auto_music_ptr
294 lda _MusicData+2
295 sta _DecodedByte
296
297 inc __auto_music_ptr+1
298 bne end_reload
299 inc __auto_music_ptr+2
300 end_reload
301
302 asl _DecodedByte
303 rol _DecodedResult
304
305 dex
306 bne loop_read_bits
307
308 pla
309 rts
310
311
312
313
314
315 _PlayerUnpackRegister
316 lda #>_PlayerBuffer
317 clc
318 adc _CurrentAYRegister
319 sta _RegisterBufferHigh
320 _PlayerUnpackRegister2
321 ;
322 ; Init register bit count and current value
323 ;
324 ldx _CurrentAYRegister
325 lda _PlayerRegValues,x
326 sta _PlayerRegCurrentValue
327
328
329 ;
330 ; Check if it's packed or not
331 ; and call adequate routine...
332 ;
333 ldx #1
334 jsr _ReadBits
335 ldx _DecodedResult
336 bne DecompressFragment
337
338
339 UnchangedFragment
340 .(
341 ;
342 ; No change at all, just repeat '_PlayerRegCurrentValue' 128 times
343 ;
344 lda _RegisterBufferHigh ; highpart of buffer adress + register number
345 sta __auto_copy_unchanged_write+2
346
347 ldx #128 ; 128 iterations
348 lda _PlayerRegCurrentValue ; Value to write
349
350 ldy _PlayerVbl
351
352 repeat_loop
353 __auto_copy_unchanged_write
354 sta _PlayerBuffer,y
355 iny
356 dex
357 bne repeat_loop
358 .)
359
360 jmp player_main_return
361
362
363 player_main_return
364 ; Write back register current value
365 ldx _CurrentAYRegister
366 lda _PlayerRegCurrentValue
367 sta _PlayerRegValues,x
368
369 ; Move to the next register buffer
370 inc _RegisterBufferHigh
371 rts
372
373
374
375
376 DecompressFragment
377 lda _PlayerVbl ; Either 0 or 128 at this point else we have a problem...
378 sta _BufferFrameOffset
379
380 decompressFragmentLoop
381
382 player_copy_packed_loop
383 ; Check packing method
384 ldx #1
385 jsr _ReadBits
386
387 ldx _DecodedResult
388 bne PlayerNotCopyLast
389
390 UnchangedRegister
391 .(
392 ; We just copy the current value 128 times
393 lda _RegisterBufferHigh ; highpart of buffer adress + register number
394 sta player_copy_last+2
395
396 ldx _BufferFrameOffset ; Value between 00 and 7f
397 lda _PlayerRegCurrentValue ; Value to copy
398 player_copy_last
399 sta _PlayerBuffer,x
400
401 inc _BufferFrameOffset
402 .)
403
404
405 player_return
406
407 ; Check end of loop
408 lda _BufferFrameOffset
409 and #127
410 bne decompressFragmentLoop
411
412 jmp player_main_return
413
414
415 PlayerNotCopyLast
416 ; Check packing method
417 ldx #1
418 jsr _ReadBits
419
420 ldx _DecodedResult
421 beq DecompressWithOffset
422
423 ReadNewRegisterValue
424 ; Read new register value (variable bit count)
425 ldx _CurrentAYRegister
426 lda _PlayerRegBits,x
427 tax
428 jsr _ReadBits
429 ldx _DecodedResult
430 stx _PlayerRegCurrentValue
431
432 ; Copy to stream
433 lda _RegisterBufferHigh ; highpart of buffer adress + register number
434 sta player_read_new+2
435
436 ldx _BufferFrameOffset ; Value between 00 and 7f
437 lda _PlayerRegCurrentValue ; New value to write
438 player_read_new
439 sta _PlayerBuffer,x
440
441 inc _BufferFrameOffset
442 jmp player_return
443
444
445
446
447 DecompressWithOffset
448 .(
449 ; Read Offset (0 to 127)
450 ldx #7
451 jsr _ReadBits
452
453 lda _RegisterBufferHigh ; highpart of buffer adress + register number
454 sta __auto_write+2 ; Write adress
455 sta __auto_read+2 ; Read adress
456
457 ; Compute wrap around offset...
458 lda _BufferFrameOffset ; between 0 and 255
459 clc
460 adc _DecodedResult ; + Offset Between 00 and 7f
461 sec
462 sbc #128 ; -128
463 tay
464
465 ; Read count (7 bits)
466 ldx #7
467 jsr _ReadBits
468
469 inc _DecodedResult ; 1 to 129
470
471
472 ldx _BufferFrameOffset
473
474 player_copy_offset_loop
475
476 __auto_read
477 lda _PlayerBuffer,y ; Y for reading
478 iny
479
480 __auto_write
481 sta _PlayerBuffer,x ; X for writing
482
483 inc _BufferFrameOffset
484
485 inx
486 dec _DecodedResult
487 bne player_copy_offset_loop
488
489 sta _PlayerRegCurrentValue
490
491 jmp player_return
492 .)
493
494
495
496 ;
497 ; Size in bits of each PSG register
498 ;
499 _PlayerRegBits
500 ; Chanel A Frequency
501 .byt 8
502 .byt 4
503
504 ; Chanel B Frequency
505 .byt 8
506 .byt 4
507
508 ; Chanel C Frequency
509 .byt 8
510 .byt 4
511
512 ; Chanel sound generator
513 .byt 5
514
515 ; select
516 .byt 8
517
518 ; Volume A,B,C
519 .byt 5
520 .byt 5
521 .byt 5
522
523 ; Wave period
524 .byt 8
525 .byt 8
526
527 ; Wave form
528 .byt 8
529
530 .dsb 256-(*&255)
531
532 _PlayerBuffer .dsb 256*14 ; About 3.5 kilobytes somewhere in memory, we put the music file in overlay memory
533 _PlayerBufferEnd
534
535 .text
536
537

  ViewVC Help
Powered by ViewVC 1.1.26