Commodore 128 Programmer's Reference Manual page 367

Hide thumbs Also See for 128:
Table of Contents

Advertisement

SOUND AND MUSIC ON THE COMMODORE 128
357
I I
( '
The program plays a series of notes in a single voice (voice 1). Here's a line by
line description of the instructions in the program.
H
The instructions stored in locations $1800 through $180A clear the SID registers
n
($D400-$D418) to zero. This is a recommended programming practice, so you can
assume that all the SID registers are initialized to zero.
The instructions stored in locations $180E through $1814 assign the attack/decay
values in the SID envelope generator. In this program, attack is set at (15:$0F) and the
decay is set at 5. This attack setting makes the sounds seem as if they are far away and
traveling closer, similar to the way a train sounds as it approaches from far away.
The instructions stored in locations $1818 through $181E select the sustain/release
values for the voice 1 envelope generator. In this case the sustain duration is set on 10
($0A) and the release rate is set to 3. For more information on the ADSR settings, see
the beginning of the chapter.
The next sequence of instructions ($1823-$ 1829) sets the volume to maximum
output (15:$0F). Notice that the last three instruction sequences loaded the X register
with the register number, loaded the accumulator with the appropriate value and stored
the value in the location of the start of the SID plus an offset in the X register. This
programming style is easy to follow and is standardized throughout the program.
The instructions stored in locations $182D through $183E get the low- and
high-byte frequency values for the musical note data, and place them into the low- and
high-byte frequency control registers for voice 1. First the X and Y registers are cleared
to zero. The Y register is used as an index to the musical note data in memory starting at
n
location $1890. To access successive bytes for frequency and duration, the Y index
| j
register is incremented. The X register is used as an index to access the low- and
high-byte frequency control registers at locations $D400 and $D401. In this program
_
segment, the X register can only have one of two values; 0 to access location $D400 and
J
1 to access location $D401.
'
The first time through the loop, the instruction starting at location $1831 (LDA
$1890,Y) loads the musical data value (low byte frequency) into the accumulator. The
j—J
next instruction (BEQ $1875) checks to see if this value is equal to zero. If it is, control
/ I
passes to location $1875, the volume is cleared to zero, and the program ends. This
suggests that to end the program, place a zero in the low byte data element. This
0
mechanism acts as a data terminator, since no additional data is read if the low-byte
]
value of a musical note equals zero. If the data value does not equal zero, it is stored in
the low byte frequency control register for voice 1.
rn
Both the X and Y registers are incremented, and the next musical data value, this
1 !
time at $1891, is loaded into the accumulator with the instruction beginning at location
' j
$183B. The next instruction (STA $D400,X) stores the data value in the high-byte
frequency control register ($D401) for voice 1.
P
The instruction at location $1844 increments the Y register. The next load
I
instruction starting at location $1845 loads the accumulator with the next data element in
memory, this time the low byte for the duration of the note. The duration note table is
f]
found on page 252. The low-byte duration is stored in zero page location $FA. The Y

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents