Init_Music ($F68D)

Init_Music_chk ($F687)

Init_Music_dft ($F692)

These routines are responsible for filling the music work buffer while a sound is being made. It should be called once during each refresh cycle. If you want to start a new sound, then you must set $C856 to 0x01, and point the U-register to the sound block. If no sound is in progress ($C856 = 0), then it returns immediately (unless you called Init_Music or Init_Music_dft, which do not make this check). When a sound is in progress, $C856 will be set to 0x80.

These routines process a single note at a time, and calculate the amplitude and course/fine tuning values for the 3 sound channels. The values calculated are stored in the music work buffer, at $C83F-$C84C.

Music data format:

header word -> $C84F 32 nibble ADSR table
header word -> $C851 8-byte "twang" table
data bytes

The ADSR table is simply 32 nibbles (16 bytes) of amplitude values.

The twang table is 8 signed bytes to modify the base frequency of each note being played. Each channel has a different limit to its twang table index (6-8) to keep them out of phase to each other.

Music data bytes:

Bits 0-5 = frequency
Bit 6 clear = tone
Bit 6 set = noise
Bit 7 set = next music data byte is for next channel
Bit 7 clear, play note with duration in next music data byte:
bits 0-5 = duration
bit 6 = unused
bit 7 set = end of music


DP = $C8

U-reg points to the start of the music data

$C84D points to frequency table (Init_Music_dft only)

$C856 may need to be set.



D-reg, X-reg, Y-reg, U-reg trashed