ThomasSpeedrunner

cfSetVolume

Sep 21st, 2014
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. ; =============== S U B R O U T I N E =======================================
  2. ; Sets track volume.
  3. ;
  4. ; Has one parameter byte, the volume.
  5. ;
  6. ; For FM tracks, this is a 7-bit value from 0 (lowest volume) to 127 (highest
  7. ; volume). The value is XOR'ed with 7Fh before being sent, then stripped of the
  8. ; sign bit. The volume change takes effect immediatelly.
  9. ;
  10. ; For PSG tracks, this is a 4-bit value ranging from 8 (lowest volume) to 78h
  11. ; (highest volume). The value is shifted 3 bits to the right, XOR'ed with 0Fh
  12. ; and AND'ed with 0Fh before being uploaded, so the sign bit and the lower 3
  13. ; bits are discarded.
  14. ;
  15. ;loc_C85
  16. cfSetVolume:
  17. bit 7, (ix+zTrackVoiceControl) ; Is this a PSG channel?
  18. jr z, + ; Branch if not
  19. ; The following code gets bits 3, 4, 5 and 6 from the parameter byte,
  20. ; puts them in positions 0 to 3 and inverts them, discarding all other
  21. ; bits in the parameter byte.
  22. ; Shift the parameter byte 3 bits to the right
  23. srl a
  24. srl a
  25. srl a
  26. xor 0Fh ; Invert lower nibble's bits
  27. and 0Fh ; Clear out high nibble
  28. jp zStoreTrackVolume
  29. ; ---------------------------------------------------------------------------
  30. +
  31. xor 7Fh ; Invert parameter byte (except irrelevant sign bit)
  32. and 7Fh ; Strip sign bit
  33. ld (ix+zTrackVolume), a ; Set as new track volume
  34. jr zSendTL ; Begin using new volume immediately
Advertisement
Add Comment
Please, Sign In to add comment