User Tools

Site Tools


oric:hardware:advanced_ay_access

Advanced AY Access (How to perform faster transfers of Data to the AY)

There are currently two advanced methods of writing to a Sound Chip Register.

The AY register must be selected before the value may be written to it. The following code sets up the Volume register of channel A (Register 8).

        LDA #08
        STA via_porta
        LDA #ayc_Register
        STA via_pcr
        LDA #ayc_Inactive
        STA via_pcr

The standard way of writing the register value is as follows

        LDA RegisterValue
        STA via_porta
        LDA #ayc_Write
        STA via_pcr
        LDA #ayc_Inactive
        STA via_pcr

The following chapters describe technique to reduce these lines of code. The techniques are only useful when writing repeatedly to the same AY register, such as when playing a sample.

Setting ayc_Write

Under Euphoric and some Real Machines simply setting the AY Control state to ayc_Write will allow an infinite stream of register values to be placed on via_porta.

However roughly 50% of real Oric Machines crash as a consequence of keeping the control line high for too long.

Triggering Register Data

CA2 and CB2 are the VIA's control lines that tell the AY what the data is in via_porta. Internally to the VIA, CA2 is associated to Port A and CB2 to Port B. The following logic table defines the 4 states.

CA2CB2AY Data State
00Inactive
01Write AY Register Data
10Read AY Register Data
11Write AY Register Number

This says that when CB2 is high and CA2 is low, data placed on via_porta will be taken by the AY as data for the last register accessed.

Both CA2 and CB2's logic levels are set in via_pcr (VIA Peripheral Control Register).

The VIA 6522 Peripheral Control Register($030C)

BitsField
0CA1 Control
1-3CA2 Control
4CB1 Control
5-7CB2 Control

CA2/CB2 Field Values

Bit PatternOperationEffective Output
000Input Negative Active Edge1
001Independant Interrupt Input Negative Active Edge1
010Input Positive Active Edge1
011Independant Interrupt Input Positive Active Edge1
100Handshake Output-
101Pulse Output(Pulse Mode)-
110Low Output0
111High Output1

The Pulse Mode setting in via_pcr can be applied to CB2. This special mode means that whenever Port B is written to (or read from ) CB2 will be momentarily sent high.

We can therefore use this to optimise our code for sending data to the AY Register. However we will first need to set up the mode. We can do this as part of setting the register number.

        LDA #08
        STA via_porta
        LDA #ayc_Register
        STA via_pcr
        LDA #%10101100
        STA via_pcr

Then to write to the Volume Register of Channel A.

        LDA RegisterValue
        STA via_porta
        LDA via_portb

To disable this special mode.

        LDA #ayc_Inactive
        STA via_pcr

Virtual Memory address Register

With this technique it is possible to free the processor as much as just writing the value for the register to a single location. However this technique requires alot of extra lines of code to setup the system (in order to make it compatible with both the Euphoric Emulator and the real Machine).

Inside the VIA is a location called the Shift Register. This can shift out a series of bits onto CB2. The VIA's ACR (Auxilliary Control Register) or via_acr is used to control the behaviour of the Shift register.

The VIA 6522 Auxilliary Control Register ($030B)

BitsField
0Port A Latch
1Port B Latch
2-4Shift Register Control
5Timer 2 Control
6-7Timer 1 Control

Shift Register field values

Bit PatternOperation
000Disabled
001Shift in under control of T2
010Shift in under control of CPU clock
011Shift in under control of external Clock
100Shift out free running at T2 Rate
101Shift out under control of T2
110Shift out under control of CPU clock
111Shift out under control of external Clock

We can select mode 100 which will continuously shift out the pattern of bits held in the shift register. Each bit that is shifted out will be automatically fed back into the left of the register constantly rotating its contents.

If we write 10101010 to the Shift register then a constant stream of pulses can be generated onto CB2. This means that we now only have to write the value to via_porta and the hardware will continuelly send it to the AY register.

Unfortunately the Euphoric Emulator does not support the Shift Register.

However once the shifting has been initiated it will override any change to the logic state of CB2 set in via_pcr.

So we can simply set CB2 high in via_pcr after starting the shift register. This means this technique will now work for all machines.

So first we set up the technique (which we will do as part of setting up the register).

      ;Set the Register Number
      LDA #08
      STA via_porta
      LDA #ayc_Register
      STA via_pcr
      LDA #ayc_Inactive
      STA via_pcr
      ;Set Timer 2 very low
      LDA #1
      STA via_t2ll
      STA via_t2ch
      ;Store value in shift register
      LDA #%10101010
      STA via_sr
      ;Set ACR Shift mode to 100 (but don't upset other bits)
      LDA via_acr
      AND #%11100011
      ORA #%00010000
      STA via_acr
      ;Finally Set CB2 high in PCR
      LDA #ayc_Write
      STA via_pcr

And now we simply do the following to write the AY register value

      LDA RegisterValue
      STA via_porta

To disable this special mode we must first disable the Shift register then set the control lines low.

      LDA via_acr
      AND #%11100011
      STA via_acr
      LDA #ayc_Inactive
      STA via_pcr
oric/hardware/advanced_ay_access.txt · Last modified: 2008/03/28 18:18 by twilighte