• Aucun résultat trouvé

The way you program the SID to produce sounds is by putting different values (expressed as numbers) into its sound control registers. The sound control registers are memory locations, which store the numbers used to produce sound on the 64.

Table 1-1 shows the name and function of each of the sound control registers, its location, and the bits that can be set to manipulate that register.

Table 1-1. The SID Sound Control Registers

Sound Control Register Function Voice 1 Pitch Value (lower value) Voice 1 Pitch Value (upper value) Voice 1 Pulse Width (lower value) Voice 1 Pulse Width (upper value) Voice 1 Waveform Output (gate bit) Voice 1 Sync Bit Enable

Voice 1 Ring Modulation Enable Voice ]

[ Test Bit Enable [ Triangle Wave Enable I Sawtooth Wave Enable [ Pulse Wave Enable [ Noise Enable [ Decay Value I Attack Value I Release Value I Sustain Value

Voice 2 Pitch Value (lower value) Voice 2 Pitch Value (upper value) Voice 2 Pulse Width (lower value) Voice 2 Pulse Width (upper value) Voice 2 Waveform Output (gate bit) Voice 2 Sync Bit Enable

Voice 2 Ring Modulation Enable Voice 2 Test Bit Enable

Voice 2 Triangle Wave Enable Voice:I Sawtooth Wave Enable

Memory Address

1

SID: The Sound Interface Device

Sound Control Register Function Voice 2 Pulse Wave Enable Voice 2 Noise Enable Voice 2 Decay Value Voice 2 Attack Value Voice 2 Release Value Voice 2 Sustain Value

Voice 3 Pitch Value (lower value) Voice 3 Pitch Value (upper value) Voice 3 Pulse Width (lower value) Voice 3 Pulse Width (upper value) Voice 3 Waveform Output (gate bit) Voice 3 Sync Bit Enable

Voice 3 Ring Modulation Enable Voice 3 Test Bit Enable

Voice 3 Triangle Wave Enable Voice 3 Sawtooth Wave Enable Voice 3 Pulse Wave Enable Voice 3 Noise Enable Voice 3 Decay Value Voice 3 Attack Value Voice 3 Release Value Voice 3 Sustain Value Cutoff Filter (lower value) Cutoff Filter (upper value) Voice 1 Filter Enable Voice 2 Filter Enable Voice 3 Filter Enable

External Audio Filter Enable Resonance Filter Value Volume Control Low Pass Filter Enable Band Pass Filter Enable High Pass Filter Enable Disable Voice 3

Voice 3 Numeric Output Envelope Generator

1

SID: The Sound Interface Device

U

If you were using voice 1, for example, and wanted to use a pulse waveform, you would set bit 6 of location 54276 (by placing a value of 64 in that address), as shown in the above table.

Bits, bytes, and nybbles. The control registers listed in Table 1-1 are used to access all of the sound functions on the 64. To operate all but the last two registers, you use the BASIC command POKE. This allows you to change the values in the registers. The format of a POKE command is:

POKE M,V

where M is a number representing a memory location between 0 and 65535, and V is the value to be stored in that location.

The number to be stored must be between 0 and 255.

To get a better idea of how this works, let's store a num ber in memory:

POKE 6000,76

Now the location 6000 contains the value 76. If you want to read that memory location—in other words, see what value is presently there—you'll need to use the BASIC counterpart of the POKE command, PEEK.

PRINT PEEK (6000)

PEEK is used to examine the contents of a memory loca tion. You have to use the PRINT command along with the PEEK command so the computer will display the value it found in location 6000. Without the PRINT command, the computer would not know what to do with the value it found.

When you press RETURN, the computer should display the value you stored, 76.

By using this method of placing values as well as looking to see what value is currently in a memory location, you can store any number in any memory address that is available, as long as you use values between 0 and 255.

The reason you're restricted to using numbers between 0 and 255 is that the Commodore 64 is an eight-bit computer. In other words, it can accept only numbers that are eight binary bits long.

While it is not the purpose of this book to explain how binary numbers and the 64's memory registers work, it is important that you be able to use them. If you need a more detailed explanation of binary numbers than what follows,

1

SID: The Sound Interface Device

you should consult a book on beginning BASIC.

Each memory location in the 64 can store one byte, which in turn is made up of eight bits (binary digifc). The eight bits in each byte are numbered, starting with 0 on the far right, and ending with bit 7 on the far left. A byte, then, would look something like this:

Figure VI. Byte's Bits

One Byte

Bit

1 0

Each bit in this sample byte has its own individual value.

If the bit is set (the bit has a 1 stored in it), that value is added to the rest of the on (another term for set) bits in the byte. If that bit has a 0 stored in it instead, it's said to be off, or not set. Then the value of that bit is 0. The bits' values in a byte are given in the following table:

Figure V2. Bit Values

Bit

Bit Value 128 6 64

5 32

4 16

Bit 0's value when it's set (a 1 is stored there) is 1. Bit l's value is 2 when it's set, bit 2's value is 4, and so on. You'll notice that each succeeding bit as you move to the left has a value exactly double that of the previous bit. As long as you can remember that, the values are easy to recall.

Earlier, we said that the numbers placed in the 64's mem ory locations had to be between 0 and 255. Remember, that is the range of possible values on an eight-bit computer like the Commodore 64. But how are those numbers created? With the

1

SID: The Sound Interface Device

bit values in a byte, by setting (placing a 1 in that bit) some bits, and leaving other bits off (by placing a 0 in that bit). The total value of all set bits becomes the value stored in that memory location's byte.

For example, let's look at the binary number 0:

00000000

This represents a single byte in the 64. All eight bits contain zeros. Not one of the bits has been set or is on. To show the binary number 1, all you'd have to do is set one bit, bit 0. Bit 0, you'll recall, had a value of 1 when it was set. Binary num ber 1 would look like this:

00000001

Setting both bit 0 and bit 1 would give us a different value. All you have to do is add the bit values (see Figure 1-2) together for all the bits that have been set. 1 (bit 0) + 2 (bit 1)

= 3. Binary number 3 would thus look like:

00000011

Now let's look at the number 255 (as it is stored internally in the computer):

11111111

All the bits have been set by storing l's in them. Adding together all the bit values gives you a total of 255

(128 + 64+32 + 16+8+4 + 2 + 1=255). If you tried to add anything to this number, the number would overflow, since all the bits are filled. That's why you cannot save a number greater than 255 in any single memory location.

(Of course, you can store larger numbers in the computer, but they are stored as several bytes which are then combined to make larger numbers.)

Clearing the registers. Clearing the sound registers should be the first step in every sound routine you write. You do this because there is no way to determine what values are stored in any of the sound registers. They are sometimes called write-only registers, for although you can write to (store numbers in) them, you cannot read them. In other words, PEEKing to these registers will not give you a correct value.

All you'll see displayed will be 0's. You can try this yourself by entering the following one-line program and then typing RUN.

8

1

_ SID: The Sound Interface Device

I i ————————————————————————————

10 FOR 1=54272 TO 54296:PRINT PEEK(I):NEXT

_ A column of 0's will show on the screen. Even if you enter a M value to one of the registers by POKEing a value into it (such

as POKE 54272,32), the above one-line program will still _ show that only 0 values are present.

M By clearing all of the registers (POKEing them with zeros), you make sure that you will not have any incorrect values in any of the sound registers. It's a good habit to get into when you're programming sound on the 64.