; Sonic 2 Clone Driver
; --------------------
; with comments from the Sonic 1 SVN Disassembly
; and many fixes and mods by Valley Bell
; Updates:
; - fixed Modulation on rests
; - PSG Noise Type is now restored after 1-up
; - fixed PSGSetVolume sending volumes >= $10 (usually during fade in)
; - added Underwater Mode
; - added custom DAC driver
; - added PlayPCMSong
; - added DAC-features to existing coordination flags:
; -> volume change
; -> key displacement (for >= 5F sounds)
; -> frequency displacement (-> custom pitches)
; - added PlaySFX_DAC
; - made SFX play while fading
; - fixed SFX reading instrument pointer from A6 (FF00) instead of A5 (track RAM)
; - ported SetLFOData from Ristar
; - ported PSG envelope flags from Ristar and made a few custom ones
; - fixed fading to not ignore the current envelope value
; - made address pointers (track pos, modulation data pos) keep the unused bits 24-31
; - made 2 new Note Fill modes
; - moved DAC bit from GlobalRAM[008] to TrackRAM[01]
; - made FM6 and DAC turning off each other
; - fixed a bug where playing sounds with index >= E0 causes crashes
; - made a proper music index extenstion (music is 01-9F, SFX A0-F3, Special F4-FF)
; - Restructured UpdateDAC to work similar FMUpdateTrack and PSGUpdateTrack
; - DAC Frequency Modulation

; - added optimized PAL mode
; - replaced SpeedUp Mode with a better implementation
; - Improved 1-up-return routine, so that SFX are still processed in that frame
; - Made new coord. flag EE: send YM2612 command and FD: Set SSG-EG
; - wrote own fading routines with more balanced fading
; - made new fading ignore SFX
; - moved the addresses of some Global Variables around
; - made Drown-Timer jingle unaffected by PAL and SpeedUp
; - made multiple Music Layers for 1-up and Invincibility
; (Plan: e.g. 1-up ends, Invinc. fades in, Invinc. runs off, BGM fades in)
; - added background music loading (I.e. 1-up is playing and Invinc. gets loaded without stopping the 1-up)
; - added FadeToPrevious sound ID and support for custom fading data
; - added F7, which prevents fading back to Invinc. instead of main BGM
; - changed add to or in WriteFMIorII to fix some bugs with the new fade in routine
; - small speedup for SetFMVol by caching FMSlotMask instead of the feedback/algorithm