User Tools

Site Tools


oric:hardware:faster_register_block_dump

The sending of a block of 14 registers to the sound chip can be accelerated by only sending values that have changed. This can be accomplished in two ways..

1 To read back the content of the register and compare with the value being sent

2 To use a reference table(block) to compare differences between value sent and last known value

We use the second method because it is much easier to program and has the advantage of protecting a write to Register 13 (The cycle register). Refer ? for details on the Cycle register.

To ease the identification of 6522 VIA Registers we use the the following Labels..

    #DEFINE ayc_Register $FF
    #DEFINE ayc_Write    $FD
    #DEFINE ayc_Inactive $DD
     
    #DEFINE via_pcr      $030C
    #DEFINE via_porta    $030F

Both reference and Register Block are 14 bytes long.

    RegisterBlockDump
         LDX #13

Fetch the Register Value and compare against last known value

    .(
    loop LDA RegisterBlock,X
         CMP ReferenceBlock,X

Avoid sending Register if values have not changed

         BEQ skip

Store the new value to the reference block

         STA ReferenceBlock,X

Store the Register Number in VIA Port A

         STX via_porta

Set AY control lines to AY Register

         LDY #ayc_Register
         STY via_pcr

Set AY control lines back to inactive

         LDY #ayc_Inactive
         STY via_pcr

Store the New Value for the register in VIA Port A

         STA via_porta

Set AY control lines to AY Register Value Write

         LDA #ayc_Write
         STA via_pcr

Set AY control lines back to inactive

         STY via_pcr

And process remaining 13 registers

    skip DEX
         BPL loop
    .)
         RTS
    RegisterBlock
     .dsb 7,0
     .byt %01111000
     .dsb 6,0
    ReferenceBlock
     .dsb 14,128

Code is repeated below in full without comments so that it may be pasted into your own source code.

    #DEFINE ayc_Register $FF
    #DEFINE ayc_Write    $FD
    #DEFINE ayc_Inactive $DD
     
    #DEFINE via_pcr      $030C
    #DEFINE via_porta    $030F
    RegisterBlockDump
         LDX #13
    .(
    loop LDA RegisterBlock,X
         CMP ReferenceBlock,X
         BEQ skip
         STA ReferenceBlock,X
         STX via_porta
         LDY #ayc_Register
         STY via_pcr
         LDY #ayc_Inactive
         STY via_pcr
         STA via_porta
         LDA #ayc_Write
         STA via_pcr
         STY via_pcr
    skip DEX
         BPL loop
    .)
         RTS
    RegisterBlock
     .dsb 7,0
     .byt %01111000
     .dsb 6,0
    ReferenceBlock
     .dsb 14,128
oric/hardware/faster_register_block_dump.txt · Last modified: 2009/11/08 22:09 by twilighte