; fixed_0000_syms.txt - semantic names for the M-ROM fixed region (z80dasm -S format)
; name: equ 0xADDR
; Naming follows the P-ROM conventions: <Subsystem>_<What>_<ADDR> for routines,
; <What>Table_<ADDR> / <What>_<ADDR> for data.  Names marked (?) are provisional.

; ---- vectors / RST -----------------------------------------------------------
Reset_0000:                 equ 0x0000
YM_Write_RST8_0008:         equ 0x0008   ; c=port (4/6), d=reg, e=val -> waits busy, writes
Ch_ClearActive_RST30_0030:  equ 0x0030   ; (ix+0)=(ix+0d)=0
IRQ_Vector_0038:            equ 0x0038
NMI_Vector_0066:            equ 0x0066
BankPtrTable_0080:          equ 0x0080   ; 18 x 24-bit linear pointers (lo,hi,bank,0)

; ---- page-aligned lookup tables 0100-1DFF (ld h,PAGE ; ld l,idx) -------------
; 01..10: eight 16-bit tables split lo/hi (page n = low byte, n+1 = high byte), each
; 256 steps of 1/256 semitone descending one octave (period = 15289 -> 7665 ...);
; SSG period for octave k = (Pg(1+2k), Pg(2+2k)), read by SSG_Update_* with
; h = 2*(oct&7)+1 ; oct >= 8 -> high byte only (tone below 1/16 of the range).
SsgPeriodOct0Lo_0100:       equ 0x0100   ; octave 0 period low  (hi in 0200)
SsgPeriodOct0Hi_0200:       equ 0x0200
SsgPeriodOct1Lo_0300:       equ 0x0300
SsgPeriodOct1Hi_0400:       equ 0x0400
SsgPeriodOct2Lo_0500:       equ 0x0500
SsgPeriodOct2Hi_0600:       equ 0x0600
SsgPeriodOct3Lo_0700:       equ 0x0700
SsgPeriodOct3Hi_0800:       equ 0x0800
SsgPeriodOct4Lo_0900:       equ 0x0900
SsgPeriodOct4Hi_0A00:       equ 0x0a00
SsgPeriodOct5Lo_0B00:       equ 0x0b00
SsgPeriodOct5Hi_0C00:       equ 0x0c00
SsgPeriodOct6Lo_0D00:       equ 0x0d00
SsgPeriodOct6Hi_0E00:       equ 0x0e00   ; all 0 (period < 256)
SsgPeriodOct7Lo_0F00:       equ 0x0f00
SsgPeriodOct7Hi_1000:       equ 0x1000   ; all 0
NotePitch_1100:             equ 0x1100   ; note n -> pitch word: lo 1100+n, hi 1180+n (= n*256/12, 1/256 semitone units);
                                         ; Pitch_SetNote_23F6, SSG/FM/ADPCMB_SetPitch, Seq_NoteEvent_56EA
FmFnumHi_1200:              equ 0x1200   ; FM F-number for 1/256-octave step: hi byte 1200+x, lo 1300+x (308 -> 615 = one octave);
FmFnumLo_1300:              equ 0x1300   ; read by FM_Update_* (ld h,12h ; ld d,(hl) ; inc h ; ld e,(hl))
LogTable_1400:              equ 0x1400   ; log2 curve (0 -> 0, ff -> ff); a*b = Exp[Log a + Log b - C0h] (Util_TableLookup_1F54,
ExpTable_1500:              equ 0x1500   ; Seq_ScaleByCurve_4F69, Env_*, Seq_SetVolumeLevel_4F88, ADPCMA/FM/SSG volume)
UnusedTable_1600:           equ 0x1600   ; not referenced by the driver
AdpcmbVolCurve_1700:        equ 0x1700   ; ADPCMB_Update_4024: volume -> level (ld h,17h ; ld l,c)
SsgVolume_1800:             equ 0x1800   ; SSG_Update_*: attenuation 0..7F -> SSG level 0..F (ld h,18h)
AdpcmaVolume_1900:          equ 0x1900   ; ADPCMA_Update_379C: volume -> ADPCM-A channel level
PortamentoRate_1A00:        equ 0x1a00   ; Seq_TrackPortamento_52EA: 128 words 16384/n^2-like divisor table (idx*2)
SquareLo_1B00:              equ 0x1b00   ; n^2: lo 1B00+n, hi 1C00+n (Seq_LoadOpPtrs_21A0..: ld h,1Bh ; inc h)
SquareHi_1C00:              equ 0x1c00
UnusedZero_1D00:            equ 0x1d00   ; 256 x 00, not referenced

; ---- main / interrupts / bank switching -------------------------------------
Main_Init_1E00:             equ 0x1e00
Main_Loop_1E3F:             equ 0x1e3f
Main_WaitTick_1E5B:         equ 0x1e5b
YM_InitTimers_1E6B:         equ 0x1e6b
IRQ_Timer_1E7A:             equ 0x1e7a   ; YM2610 timer A -> tick counter F801
NMI_RingReset_1EB3:         equ 0x1eb3
NMI_RingPop_1EBB:           equ 0x1ebb   ; cf=1, a=cmd if a command is queued
NMI_Command_1ED6:           equ 0x1ed6   ; 68k -> Z80 command latch (port 0)
NMI_SoftReset_1F0A:         equ 0x1f0a   ; cmd 01
NMI_HardReset_1F4B:         equ 0x1f4b   ; cmd 03
Util_TableLookup_1F54:      equ 0x1f54
Bank_SelectInit_1F7D:       equ 0x1f7d   ; select file bank 2 in the 8000 window
Bank_ResolvePtr24_1FA6:     equ 0x1fa6   ; (hl)=24-bit ptr -> switch bank, hl=8000|off
Bank_ReadWordBank2_1FDE:    equ 0x1fde
Ch_InitStruct_1FE5:         equ 0x1fe5
Ch_ResetStruct_201B:        equ 0x201b
Cmd_InitState_203F:         equ 0x203f
Cmd_Dispatch_2050:          equ 0x2050   ; pops NMI ring, cmds 00-0F via CmdJumpTable
CmdJumpTable_2076:          equ 0x2076
Cmd_DispatchHi_2096:        equ 0x2096   ; cmds >= 20: sound id = cmd-20, type via F81C
CmdHiJumpTable_20B3:        equ 0x20b3
Cmd_Nop_20D3:               equ 0x20d3
Cmd_PlayMusic_20D4:         equ 0x20d4
Cmd_StopMusic_2101:         equ 0x2101
Cmd_SetFlag_210F:           equ 0x210f
Cmd_PlaySfx_2115:           equ 0x2115
Cmd_StopSfx_2156:           equ 0x2156
Cmd_StopAll_215D:           equ 0x215d
Cmd_StopAll2_2163:          equ 0x2163
Cmd_StopSeq_2166:           equ 0x2166
Cmd_SetParam_2169:          equ 0x2169
Cmd_SetTempo_2170:          equ 0x2170
Cmd_SetFade_217E:           equ 0x217e
Cmd_FadeOutOn_2185:         equ 0x2185
Cmd_FadeOutOff_2190:        equ 0x2190

; ---- channel engine ---------------------------------------------------------
Seq_LoadOpPtrs_219B:        equ 0x219b
Env_Start_2208:             equ 0x2208
Env_Release_2219:           equ 0x2219
Env_Step_222D:              equ 0x222d
Lfo_Clear_229D:             equ 0x229d
Lfo_Load_22A8:              equ 0x22a8
Env_Init_22F4:              equ 0x22f4
Rng_Next_2300:              equ 0x2300   ; uses R register, state at F81D
Env_Update_231E:            equ 0x231e
Pitch_Clear_23EE:           equ 0x23ee
Pitch_SetNote_23F6:         equ 0x23f6
Pitch_SetFine_2420:         equ 0x2420
Pitch_Load_242E:            equ 0x242e
Pitch_Update_2461:          equ 0x2461
Vib_Update_248E:            equ 0x248e
CmdStruct_24DE:             equ 0x24de
CmdStruct_24F7:             equ 0x24f7
SSG_Init_2515:              equ 0x2515   ; channels at F81F / F86B / F8B7
SSG_InitChannel_255D:       equ 0x255d
SSG_Update_2593:            equ 0x2593
SSG_UpdateChB_2738:         equ 0x2738
SSG_UpdateChC_28DD:         equ 0x28dd
FM_Init_2B43:               equ 0x2b43
FM_Update_2C5F:             equ 0x2c5f
ADPCMA_Init_3740:           equ 0x3740
ADPCMA_Update_379C:         equ 0x379c
ADPCMB_Init_3FCA:           equ 0x3fca
ADPCMB_Update_4024:         equ 0x4024
ChTypeJumpTable0_4AA0:      equ 0x4aa0
ChTypeJumpTable1_4ABC:      equ 0x4abc
ChTypeJumpTable2_4AD8:      equ 0x4ad8
Ch_KeyOn_4AE2:              equ 0x4ae2
Ch_SetNote_4B0B:            equ 0x4b0b
Ch_SetNote2_4B26:           equ 0x4b26
Ch_SetNote3_4B41:           equ 0x4b41
Ch_SetNote4_4B4F:           equ 0x4b4f
NoteMapTable_4B84:          equ 0x4b84   ; 256-entry note/volume map used by Seq_StartMusic

; ---- sequence player (8 tracks of 0x23 bytes at FDF2) -----------------------
Seq_Init_4C84:              equ 0x4c84
Seq_Update_4CA6:            equ 0x4ca6
Seq_SetTempo_4F39:          equ 0x4f39
Seq_SetVolumeLevel_4F88:    equ 0x4f88
Seq_StartMusic_4FA3:        equ 0x4fa3   ; ix -> music header (5-byte track entries)
Seq_InitTracks_5025:        equ 0x5025
Seq_StopAllTracks_504E:     equ 0x504e
Seq_StartSfx_507B:          equ 0x507b
Seq_FindFreeTrack_50DB:     equ 0x50db
Seq_UpdateTracks_514F:      equ 0x514f
Seq_StopTrackById_5210:     equ 0x5210
Seq_TrackInit_5251:         equ 0x5251
Seq_TrackPortamento_52EA:   equ 0x52ea
Seq_TrackStep_532B:         equ 0x532b
Seq_TrackNextOp_533E:       equ 0x533e
Seq_TrackFetch_5362:        equ 0x5362   ; opcode >= DA -> stop, >= C0 -> SeqOpJumpTable, else note
SeqOpJumpTable_53A3:        equ 0x53a3   ; 26 x 'jp' for opcodes C0..D9
SeqOp_D9_Reply68k_53F4:     equ 0x53f4
SeqOp_DA_SetVolLevel_540F:  equ 0x540f
SeqOp_D3_Note_5420:         equ 0x5420
SeqOp_D4_Note2_5434:        equ 0x5434
SeqOp_D5_Note3_5448:        equ 0x5448
SeqOp_D6_Note4_545C:        equ 0x545c
SeqOp_D7_PitchDown_5470:    equ 0x5470
SeqOp_D8_PitchUp_5499:      equ 0x5499
SeqOp_D1_Portamento_54C5:   equ 0x54c5
SeqOp_D2_SetLfo_54F0:       equ 0x54f0
SeqOp_CE_SetTranspose_54FC: equ 0x54fc
SeqOp_CD_SetTempo_550F:     equ 0x550f
SeqOp_CC_SetLength_551D:    equ 0x551d
SeqOp_CB_SetWait_5535:      equ 0x5535
SeqOp_CA_SetDetune_5541:    equ 0x5541
SeqOp_C9_SetSustain_555C:   equ 0x555c
SeqOp_C6_SetVol_5574:       equ 0x5574
SeqOp_C7_SetPan_5582:       equ 0x5582
SeqOp_C8_SetParam_5590:     equ 0x5590
SeqOp_C5_Return_559E:       equ 0x559e
SeqOp_CF_LoopStart_55D4:    equ 0x55d4
SeqOp_D0_LoopEnd_5605:      equ 0x5605
SeqOp_C4_CallSub_565D:      equ 0x565d
SeqOp_C3_SetBit0_569A:      equ 0x569a
SeqOp_C0_SetInstrLo_56B1:   equ 0x56b1
SeqOp_C1_SetInstrLoHi_56BD: equ 0x56bd
SeqOp_C2_Jump_56CE:         equ 0x56ce
Seq_NoteEvent_56EA:         equ 0x56ea   ; opcodes 00..BF: note + optional wait/dur/vel bytes
Seq_TrackEndCheck_5786:     equ 0x5786
Seq_TrackStop_578D:         equ 0x578d
InstrPtrTable_57A1:         equ 0x57a1   ; 1024 x 24-bit pointers to instrument patches (8 groups x 128; idx = (iy+0B)*128+(iy+0A))

; ---- work RAM F800-FFFF (z80dasm also substitutes these in operands) --------
; globals
wTick_F800:                 equ 0xf800   ; main loop counter
wTickPending_F801:          equ 0xf801   ; timer ticks not yet consumed (max 2)
wTickCount_F802:            equ 0xf802
wTickDiv_F803:              equ 0xf803
wSfxFlag_F804:              equ 0xf804
wMasterVolume_F805:         equ 0xf805   ; FF = full
wVolumeLevel_F806:          equ 0xf806   ; 16-bit scaled level set by Seq_SetVolumeLevel
wFadeFlag_F808:             equ 0xf808   ; 1 while fading out
wTempoStep_F809:            equ 0xf809   ; ticks per sequencer step
wYmStatus_F80A:             equ 0xf80a   ; last value read from port 6 (YM status 1)
wYmPortLatch_F80B:          equ 0xf80b   ; bc saved by RST8
wNmiRingRd_F80F:            equ 0xf80f
wNmiRingWr_F810:            equ 0xf810
wCurBank_F811:              equ 0xf811   ; file bank currently mapped at 8000
wTmpWord_F812:              equ 0xf812
wTmpByte_F814:              equ 0xf814
wSoundId_F815:              equ 0xf815   ; last command - 0x20
wSfxPending_F816:           equ 0xf816
wSoundParam_F817:           equ 0xf817
wMusicId_F818:              equ 0xf818
wCmdCounter_F819:           equ 0xf819   ; 16-bit, incremented per command (track age)
wSfxId_F81B:                equ 0xf81b
wCmdType_F81C:              equ 0xf81c   ; 0F = separator, <10 = type for next sound
wRngState_F81D:             equ 0xf81d
; SSG channels (3 x 0x4c bytes)
wSSG_ChA_F81F:              equ 0xf81f
wSSG_ChB_F86B:              equ 0xf86b
wSSG_ChC_F8B7:              equ 0xf8b7
wSSG_Mixer_F903:            equ 0xf903
wSSG_EnvShape_F905:         equ 0xf905
; FM channels (4 x 0x67 bytes)
wFM_Ch1_F907:               equ 0xf907
wFM_Ch2_F96E:               equ 0xf96e
wFM_Ch3_F9D5:               equ 0xf9d5
wFM_Ch4_FA3C:               equ 0xfa3c
wFM_Shared_FAA3:            equ 0xfaa3
; ADPCM-A channels (6 x 0x29 bytes)
wPCMA_Ch1_FAA5:             equ 0xfaa5
wPCMA_Ch2_FACE:             equ 0xface
wPCMA_Ch3_FAF7:             equ 0xfaf7
wPCMA_Ch4_FB20:             equ 0xfb20
wPCMA_Ch5_FB49:             equ 0xfb49
wPCMA_Ch6_FB72:             equ 0xfb72
; ADPCM-B channel
wPCMB_Ch_FB9B:              equ 0xfb9b
wPCMB_Shared_FBBA:          equ 0xfbba
wNoteTmp_FBF5:              equ 0xfbf5   ; note / len / vol / gate scratch for Seq_NoteEvent
wNoteLen_FBF6:              equ 0xfbf6
wNoteVol_FBF7:              equ 0xfbf7
wNoteGate_FBF8:             equ 0xfbf8
; music tracks (14 x 0x23 bytes, FBFC..FDF2) and sfx tracks (8 x 0x23, FDF2..FF0A)
wMusicTracks_FBFC:          equ 0xfbfc
wMusicHdr_FDE6:             equ 0xfde6   ; copied music header fields (volume, tempo…)
wSfxTracks_FDF2:            equ 0xfdf2
wCurTrack_FF0A:             equ 0xff0a   ; iy of the track being stepped
wReplyToggle_FF0C:          equ 0xff0c
wSeqPtr_FF0D:               equ 0xff0d   ; sequence read pointer of the current track
wStackTop_FFF0:             equ 0xfff0
wNmiRing_FFF0:              equ 0xfff0   ; 16-byte NMI command ring (also stack top)
Instr_ResolvePtr_4B5D:      equ 0x4b5d   ; (iy+0A/0B) -> hl = instrument patch in bank (FF = default CmdStruct_2509)
InstrDefault_2509:          equ 0x2509
; ---- channel-type entry points (ChTypeJumpTable0/1/2_4AA0: load patch / key-on / set pitch) ----
SSG_LoadPatch_2AA8:         equ 0x2aa8   ; type 0 patch -> channel (I_ENV, 2 x I_LFO, I_PITCH)
SSG_SetPitch_2B02:          equ 0x2b02   ; note (ix+08) -> period via pages 11xx/91xx
SSG_KeyOn_2B12:             equ 0x2b12   ; restart envelope + LFOs + pitch slide
FM_InitChannel_2BB7:        equ 0x2bb7   ; called for FM 1..4 at init
FM_WriteOpRegs_2C03:        equ 0x2c03   ; b = op mask, d = first reg, hl = 4 values (reg += 10h each)
FM_LoadPatch_3568:          equ 0x3568   ; type 1 patch: 4 x 7 operator bytes + FB/ALG, LFO, AMS/PMS
FM_SetPitch_3605:           equ 0x3605
FM_KeyOn_3615:              equ 0x3615   ; reg 28h key-on, global LFO, restart envelopes
FM_OpVolumeUp_3672:         equ 0x3672   ; TL+1 on the operators in mask c (Ch_SetNote_4B0B)
FM_OpVolumeDown_36AA:       equ 0x36aa   ; TL-1 (Ch_SetNote2_4B26)
FM_OpParam3_36E1:           equ 0x36e1   ; (Ch_SetNote3_4B41) (?)
FM_OpParam4_3711:           equ 0x3711   ; (Ch_SetNote4_4B4F) (?)
ADPCMA_InitChannel_3783:    equ 0x3783
ADPCMA_LoadPatch_3F41:      equ 0x3f41   ; type 2 patch: I_ENV, sample-map pointer
ADPCMA_SelectSample_3F60:   equ 0x3f60   ; note -> PcmaSampleTab entry -> channel +15 (5 B)
ADPCMA_KeyOn_3FBA:          equ 0x3fba
ADPCMB_InitChannel_3FE0:    equ 0x3fe0
ADPCMB_LoadPatch_427F:      equ 0x427f   ; type 3 patch: I_ENV, 2 x I_LFO, I_PITCH, key ranges
ADPCMB_SetPitch_42CA:       equ 0x42ca   ; delta-N from note - root (pages 11xx/91xx)
ADPCMB_KeyOn_42EF:          equ 0x42ef   ; pick PCMB_KEY range -> PcmbSample -> FBAF..FBB8
Ch_AllocByType_4389:        equ 0x4389   ; patch type -> find / steal a hardware channel of that type
Ch_NoteOn_4A03:             equ 0x4a03   ; resolve patch, allocate channel, copy note, run loader chain
Ch_DispatchKeyOn_4AA8:      equ 0x4aa8   ; ChTypeJumpTable1 (key-on), then ...
Ch_DispatchPitch_4AC4:      equ 0x4ac4   ; ChTypeJumpTable2 (pitch)
Ch_DispatchDone_4AE0:       equ 0x4ae0
Ch_IsFM_4B03:               equ 0x4b03   ; carry = channel type 1
Seq_ApplyTempo_4F40:        equ 0x4f40   ; FDEE (tempo target) vs FDE7 -> FDEC step
Seq_TempoCurve_4F5B:        equ 0x4f5b   ; Cmd_SetTempo_2170 tail
Seq_ScaleByCurve_4F69:      equ 0x4f69   ; a, l -> curve lookup in pages 14xx/15xx, clamped
