Sona 0.50 Source

Sona 0.50/src-z80/fm_regwrite.z80

;****************************************************************************
; FmRegWrite [SONAOP_FMREG1..2]
; Processes the stream event for writing directly to YM2612 registers.
;----------------------------------------------------------------------------
; input b ..... YM2612 bank (bit 0 only)
; input c ..... current stream bank
; input hl .... current stream address
;----------------------------------------------------------------------------
; output c .... new stream bank
; output hl ... new stream address
;----------------------------------------------------------------------------
; breaks ...... a,b,de
;----------------------------------------------------------------------------
; format: 1111100z yyyyyyyy xxxxxxxx
;
; where:  xxxxxxxx = value to write
;         yyyyyyyy = register number
;                z = register bank
;****************************************************************************

FmRegWrite:
    PollPcm
    
    ld      a, b                        ; Retrieve bank number (stored in
    and     $01                         ; bit 0 of the stream opcode) and
    ld      e, a                        ; compute the port address to use
    ld      d, YmAddr1>>8               ; later
    
    ReadArgByte                         ; Read register number
    
    ld      a, b                        ; Save register number for later
    ex      af, af'                     ; and go read the register value
    ReadArgByte
    
    ex      af, af'                     ; Write YM2612 register
    ld      (de), a
    inc     e
    ld      a, b
    ld      (de), a
    
    ret                                 ; End of subroutine