; =============== S U B R O U T I N E =======================================
; Sets track volume.
;
; Has one parameter byte, the volume.
;
; For FM tracks, this is a 7-bit value from 0 (lowest volume) to 127 (highest
; volume). The value is XOR'ed with 7Fh before being sent, then stripped of the
; sign bit. The volume change takes effect immediatelly.
;
; For PSG tracks, this is a 4-bit value ranging from 8 (lowest volume) to 78h
; (highest volume). The value is shifted 3 bits to the right, XOR'ed with 0Fh
; and AND'ed with 0Fh before being uploaded, so the sign bit and the lower 3
; bits are discarded.
;
;loc_C85
cfSetVolume:
bit 7, (ix+zTrackVoiceControl) ; Is this a PSG channel?
jr z, + ; Branch if not
; The following code gets bits 3, 4, 5 and 6 from the parameter byte,
; puts them in positions 0 to 3 and inverts them, discarding all other
; bits in the parameter byte.
; Shift the parameter byte 3 bits to the right
srl a
srl a
srl a
xor 0Fh ; Invert lower nibble's bits
and 0Fh ; Clear out high nibble
jp zStoreTrackVolume
; ---------------------------------------------------------------------------
+
xor 7Fh ; Invert parameter byte (except irrelevant sign bit)
and 7Fh ; Strip sign bit
ld (ix+zTrackVolume), a ; Set as new track volume
jr zSendTL ; Begin using new volume immediately
Comments