;****************************************************************************
; ReadVolArg
;
; Reads a volume argument for SONA_VOLUME_* stream events, processes it and
; stores the new volume value.
;----------------------------------------------------------------------------
; input c ..... current stream bank
; input hl .... current stream address
; input de .... pointer to current volume
;----------------------------------------------------------------------------
; output c .... new stream bank
; output hl ... new stream address
; output de ... pointer to current volume (intact)
;----------------------------------------------------------------------------
; modifies .... a,bc,hl,a'
;****************************************************************************
ReadVolArg:
ReadArgByte ; Read value
ld a, b ; Absolute or relative attenuation?
or a ; $00~$7F = absolute
jp m, ReadRelVolArg ; $80~$FF = relative
ld (de), a ; Store absolute attenuation as-is
ret ; End of subroutine
;----------------------------------------------------------------------------
ReadRelVolArg:
cp $C0 ; Change up or down?
jr nc, ReadVolDownArg ; $80~$BF = increment
; $C0~$FF = decrement
;----------------------------------------------------------------------------
ReadVolUpArg:
PollPcm
ld (de), a ; Add value + $80 from original
add a, b ; attenuation
jr nc, ReadVolUpOk ; Did it overflow?
ld a, $FF
ReadVolUpOk:
sub $80 ; Remove that +$80 offset
ld (de), a ; Store new attenuation value
ret ; End of subroutine
;----------------------------------------------------------------------------
ReadVolDownArg:
PollPcm
ld a, b ; Isolate value
and $3F
ld b, a
ld a, (de) ; Substract value from original
sub b ; attenuation
jr nc, ReadVolDownOk ; Did it overflow?
xor a
ReadVolDownOk:
ld (de), a ; Store new attenuation value
ret ; End of subroutine