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

Annotation of /public/oric/demos/AlchimieX/player.s

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26