/[projet1]/users/dbug/tests/g0blinish_music/mymplayer.s
Defence Force logotype

Diff of /users/dbug/tests/g0blinish_music/mymplayer.s

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1237 by dbug, Sat Dec 6 21:25:54 2014 UTC revision 1238 by dbug, Sat Dec 6 21:50:17 2014 UTC
# Line 12  Line 12 
12  ;              465 bytes - Inlined the mym initialisation in the StartMusic code  ;              465 bytes - Inlined the mym initialisation in the StartMusic code
13  ;              455 bytes - Simplified the load balancer code by using the same frame counter for two different purpose.  ;              455 bytes - Simplified the load balancer code by using the same frame counter for two different purpose.
14  ;              449 bytes - Merged more initialization code all over the place  ;              449 bytes - Merged more initialization code all over the place
15    ;              442 bytes - Improved the logic in the mym depacking
16    ;              416 bytes - Used zero page addressing for the write buffers
17    
18  #define _PlayerBuffer           $5900           ; .dsb 256*14 (About 3.5 kilobytes)  #define _PlayerBuffer           $5900           ; .dsb 256*14 (About 3.5 kilobytes)
19  #define _MusicData                      $6700           ; Musics are loaded in $67B0, between the player buffer and the redefined character sets  #define _MusicData                      $6700           ; Musics are loaded in $67B0, between the player buffer and the redefined character sets
# Line 34  _DecodedResult         .dsb 1          ; What is return Line 36  _DecodedResult         .dsb 1          ; What is return
36    
37  _CurrentAYRegister      .dsb 1          ; Contains the number of the register being decoded      _CurrentAYRegister      .dsb 1          ; Contains the number of the register being decoded    
38    
39  _RegisterBufferHigh     .dsb 1          ; Points to the high byte of the decoded register buffer, increment to move to the next register          _ptr_register_buffer
40  _BufferFrameOffset      .dsb 1          ; From 0 to 127, used when filling the decoded register buffer  _ptr_register_buffer_low        .dsb 1          ; Points to the low byte of the decoded register buffer
41    _ptr_register_buffer_high       .dsb 1          ; Points to the high byte of the decoded register buffer, increment to move to the next register        
42    
43  _MusicResetCounter      .dsb 2          ; Contains the number of rows to play before reseting  _MusicResetCounter      .dsb 2          ; Contains the number of rows to play before reseting
44    
# Line 44  _CurrentFrame          .dsb 1          ; From 0 to 255 a Line 47  _CurrentFrame          .dsb 1          ; From 0 to 255 a
47  _PlayerVbl                      .dsb 1  _PlayerVbl                      .dsb 1
48    
49  _FrameLoadBalancer      .dsb 1          ; We depack a new frame every 9 VBLs, this way the 14 registers are evenly depacked over 128 frames  _FrameLoadBalancer      .dsb 1          ; We depack a new frame every 9 VBLs, this way the 14 registers are evenly depacked over 128 frames
50    temp_value                      .dsb 1      ; temp
51  _50hzFlipFlop                   .dsb 1  _50hzFlipFlop                   .dsb 1
52  _PlayerRegCurrentValue  .dsb 1          ; For depacking of data  _PlayerRegCurrentValue  .dsb 1          ; For depacking of data
53    
# Line 132  loop_clear Line 135  loop_clear
135          ;          ;
136          .(          .(
137          lda #>_PlayerBuffer          lda #>_PlayerBuffer
138          sta _RegisterBufferHigh          sta _ptr_register_buffer_high
139    
140          ldx #0          ldx #0
141            stx _ptr_register_buffer_low
142  unpack_block_loop  unpack_block_loop
143          stx _CurrentAYRegister          stx _CurrentAYRegister
144                    
# Line 262  NextFrameBlock Line 266  NextFrameBlock
266          sta _CurrentAYRegister          sta _CurrentAYRegister
267    
268          lda #>_PlayerBuffer          lda #>_PlayerBuffer
269          sta _RegisterBufferHigh          sta _ptr_register_buffer_high
270    
271          lda _PlayerVbl+0          lda _PlayerVbl+0
272          eor #128          eor #128
# Line 328  _PlayerUnpackRegister Line 332  _PlayerUnpackRegister
332          jsr _ReadOneBit          jsr _ReadOneBit
333          bne DecompressFragment          bne DecompressFragment
334                    
335    ; No change at all, just repeat '_PlayerRegCurrentValue' 128 times
336  UnchangedFragment        UnchangedFragment      
337  .(  .(
         ; No change at all, just repeat '_PlayerRegCurrentValue' 128 times  
         lda _RegisterBufferHigh                         ; highpart of buffer adress + register number  
         sta __auto_copy_unchanged_write+2  
   
         ldx #128                                                        ; 128 iterations  
338          lda _PlayerRegCurrentValue                      ; Value to write          lda _PlayerRegCurrentValue                      ; Value to write
339    
340          ldy _PlayerVbl          ldy _PlayerVbl
341            ldx #128                                                        ; 128 iterations
342  repeat_loop  repeat_loop
343  __auto_copy_unchanged_write          sta (_ptr_register_buffer),y
         sta _PlayerBuffer,y  
344          iny              iny    
345          dex          dex
346          bne repeat_loop          bne repeat_loop
# Line 352  player_main_return Line 352  player_main_return
352          sta _PlayerRegValues,x          sta _PlayerRegValues,x
353    
354          ; Move to the next register buffer          ; Move to the next register buffer
355          inc _RegisterBufferHigh          inc _ptr_register_buffer_high
356          rts          rts
357    
358    
359  DecompressFragment  DecompressFragment
360          lda _PlayerVbl                                          ; Either 0 or 128 at this point else we have a problem...          ldy _PlayerVbl                                          ; Either 0 or 128 at this point else we have a problem...
         sta _BufferFrameOffset  
361    
362  decompressFragmentLoop    decompressFragmentLoop  
363                    
# Line 367  player_copy_packed_loop Line 366  player_copy_packed_loop
366          jsr _ReadOneBit          jsr _ReadOneBit
367          bne PlayerNotCopyLast          bne PlayerNotCopyLast
368    
369    ; We just copy the current value 128 times
370  UnchangedRegister  UnchangedRegister
 .(        
         ; We just copy the current value 128 times  
         lda _RegisterBufferHigh                         ; highpart of buffer adress + register number  
         sta __auto_player_copy_last+2  
   
         ldx _BufferFrameOffset                          ; Value between 00 and 7f  
371          lda _PlayerRegCurrentValue                      ; Value to copy          lda _PlayerRegCurrentValue                      ; Value to copy
372  __auto_player_copy_last          sta (_ptr_register_buffer),y
373          sta _PlayerBuffer,x          iny
         inx  
 .)  
374    
375  player_return  player_return
376          sta _PlayerRegCurrentValue                      ; New value to write          sta _PlayerRegCurrentValue                      ; New value to write
         stx _BufferFrameOffset                          ; New buffer offset  
377    
378          ; Check end of loop          ; Check end of loop
379          txa          tya
380          and #127          and #127
381          bne decompressFragmentLoop          bne decompressFragmentLoop
382    
# Line 397  PlayerNotCopyLast Line 388  PlayerNotCopyLast
388          jsr _ReadOneBit          jsr _ReadOneBit
389          beq DecompressWithOffset          beq DecompressWithOffset
390    
391  ; New register value  ; New register value copied to the register stream
392  ReadNewRegisterValue  ReadNewRegisterValue
         ; Copy to stream  
         lda _RegisterBufferHigh                         ; highpart of buffer adress + register number  
         sta __auto_player_read_new+2  
   
393          ; Read new register value (variable bit count)          ; Read new register value (variable bit count)
394          ldx _CurrentAYRegister          ldx _CurrentAYRegister
395          lda _PlayerRegBits,x          lda _PlayerRegBits,x
396          jsr _ReadBits          jsr _ReadBits
397    
398          ldx _BufferFrameOffset                          ; Value between 00 and 7f          sta (_ptr_register_buffer),y
399  __auto_player_read_new          iny
         sta _PlayerBuffer,x  
         inx  
400          jmp player_return          jmp player_return
401    
402    
403  ; Offset depacking  ; Offset depacking
404  DecompressWithOffset  DecompressWithOffset
405  .(  .(
406            lda _ptr_register_buffer_high           ; highpart of buffer adress + register number
407            sta __auto_read+2                                       ; Read adress
408    
409          ; Read Offset (0 to 127)          ; Read Offset (0 to 127)
410          lda #7          lda #7
411          jsr _ReadBits                                            jsr _ReadBits                                  
412          ; Compute wrap around offset...          ; Compute wrap around offset...
413          clc          clc
414          adc _BufferFrameOffset                                  ; between 0 and 255          tya
415            adc _DecodedResult                                      ; between 0 and 255
416          sec          sec
417          sbc #128                                                        ; -128          sbc #128                                                        ; -128
418          tay          sta temp_value
419                    
         lda _RegisterBufferHigh                 ; highpart of buffer adress + register number  
         sta __auto_write+2                              ; Write adress  
         sta __auto_read+2                               ; Read adress  
   
420          ; Read count (7 bits)          ; Read count (7 bits)
421          lda #7          lda #7
422          jsr _ReadBits          jsr _ReadBits
423    
424          ldx _BufferFrameOffset          ldx temp_value
425  loop_copy_offset  loop_copy_offset
426  __auto_read  __auto_read
427          lda _PlayerBuffer,y                             ; Y for reading          lda _PlayerBuffer,x                             ; X for reading
         iny  
   
 __auto_write  
         sta _PlayerBuffer,x                             ; X for writing  
428          inx          inx
429    
430            sta (_ptr_register_buffer),y    ; Y for writing
431            iny
432          dec _DecodedResult          dec _DecodedResult
433          bpl loop_copy_offset          bpl loop_copy_offset
434    

Legend:
Removed from v.1237  
changed lines
  Added in v.1238

  ViewVC Help
Powered by ViewVC 1.1.26