@@ -498,6 +498,10 @@ gsl_nextSongLine
498498 txa
499499 tay
500500 lda (ptrSongLines),y
501+ ;* Check for special song line commands. Track numbers >= $FE are not real
502+ ;* tracks, but control flow commands:
503+ ;* $FE = Jump to a new song line pointer.
504+ ;* $FF = Empty track line (handled in this 7800 port by setting a max pause).
501505 cmp #$fe ;* check for "goto line"
502506 bcs gsl_GotoOrEmpty ;* and handle it.
503507 ;* (A) = Real track #
@@ -573,11 +577,12 @@ gtl_loopTracks
573577
574578oo1i
575579 ldy trackn_idx,x
576- ;* Get a track data point
577- ;* 0 - 60 = Note, instr and volume data
578- ;* 61 - Volume only
579- ;* 62 = Pause/empty line
580- ;* 63 - Speed, go loop or end
580+ ;* Get a track data point. The track data stream is a sequence of commands
581+ ;* encoded by the first byte's value:
582+ ;* 0-60 ($00-$3C): A new note. The next byte contains instrument/volume.
583+ ;* 61 ($3D): Volume-only change for the current note.
584+ ;* 62 ($3E): Pause. The next byte specifies duration.
585+ ;* 63 ($3F): Control command (e.g., change speed, loop, or end track).
581586 lda (_ns),y
582587 sta rmtreg1
583588 iny
@@ -606,6 +611,10 @@ oo1i
606611 sta trackn_instrx2,x
607612
608613gtl_ProcessVolumeData
614+ ;* The note/instrument/volume data is packed into two bytes to save space.
615+ ;* Byte 1: [vvnnnnnn] (v=volume bits 3&2, n=note)
616+ ;* Byte 2: [iiiiii vv] (i=instrument, v=volume bits 1&0)
617+ ;* This sequence unpacks the 4-bit volume from the two bytes.
609618 lda rmtreg2
610619 lsr
611620 ror rmtreg1
@@ -671,6 +680,15 @@ p2x2
671680 bne p2x1
672681 rts
673682
683+ ;* rmt_play:
684+ ;* This is the main player entry point, intended to be called once per frame
685+ ;* It orchestrates all player state updates.
686+ ;* The timing is controlled by two counters:
687+ ;* 1. v_aspeed: Ticks per song line. When it reaches zero, a new line of
688+ ;* track data is read by GetTrackLine. This is the "song tempo".
689+ ;* 2. smc_silence_instrspeed: Ticks per instrument step. When it reaches
690+ ;* zero, the instrument envelopes/effects are processed.
691+ ;*
674692rmt_play
675693rmt_p0
676694 jsr SetPokey
@@ -759,6 +777,17 @@ returnfromInstrumentsEffects
759777 lda rmtreg2
760778 sta trackn_command,x
761779 and #$70
780+ ;* This is the main instrument command dispatcher. The command number (0-7)
781+ ;* is stored in the 3 bits of reg2 ($70 mask).
782+ ;* The original player used self-modifying code here (sta jmx+1) to jump
783+ ;* to the correct command handler.
784+ ;* For a ROM-based system like the 7800:
785+ ;* the jump has been changed to use a table of addresses (rts_tab). The code
786+ ;* pushes the correct handler's address-1 onto the stack and executes an RTS,
787+ ;* effectively performing a calculated JMP.
788+ ;* For a RAM-based system:
789+ ;* the jump uses self-modifying code to branch to the desired JMP
790+ ;* instruction.
762791 lsr
763792 lsr
764793 IF ROM_BASED
@@ -998,6 +1027,15 @@ qq0 ora trackn_audctl,x
9981027 dex
9991028 bpl qq0
10001029 sta v_audctl
1030+ ;* This section handles advanced audio effects that require multiple POKEY
1031+ ;* channels. The priority system:
1032+ ;* 1. Filters (highest priority): If a track enables a filter, it will
1033+ ;* override the channel it needs (e.g., track 0 filter uses channel 2),
1034+ ;* silencing whatever was playing there.
1035+ ;* 2. 16-bit Bass (medium priority): If a filter is not active on a needed
1036+ ;* channel, 16-bit bass can use it (e.g., track 1 bass uses channel 0).
1037+ ;* 3. Normal Track Playback (lowest priority).
1038+ ;* The code first checks for and applies filters, then checks for 16-bit bass.
10011039qq1
10021040 ldx v_audctl
10031041 ELSE
0 commit comments