As well as controlling three sound channels the 8910 PSG contains two eight bit data ports, called A and B, through which it interfaces the joysticks and the cassette input. The PSG appears to the Z80 as three I/O ports called the Address Port, the Data Write Port and the Data Read Port.
The PSG contains sixteen internal registers which completely define its operation. A specific register is selected by writing its number, from 0 to 15, to this port. Once selected, repeated accesses to that register may be made via the two data ports.
This port is used to write to any register once it has been selected by the Address Port.
This port is used to read any register once it has been selected by the Address Port.
The following table summarizes all PSG registers:
Register Bits | |||||||||
Reg. | Function | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
R0 | Channel A Period | pa7 | pa6 | pa5 | pa4 | pa3 | pa2 | pa1 | pa0 |
R1 | - | - | - | - | paB | paA | pa9 | pa8 | |
R2 | Channel B Period | pb7 | pb6 | pb5 | pb4 | pb3 | pb2 | pb1 | pb0 |
R3 | - | - | - | - | pbB | pbA | pb9 | pb8 | |
R4 | Channel C Period | pc7 | pc6 | pc5 | pc4 | pc3 | pc2 | pc1 | pc0 |
R5 | - | - | - | - | pcB | pcA | pc9 | pc8 | |
R6 | Noise Tone | - | - | - | n4 | n3 | n2 | n1 | n0 |
R7 | /Enable | Port B Dir. | Port A Dir. | C Noise | B Noise | A Noise | C Tone | B Tone | A Tone |
R8 | Channel A Volume | - | - | - | A Mode | va3 | va2 | va1 | va0 |
R9 | Channel B Volume | - | - | - | B Mode | vb3 | vb2 | vb1 | vb0 |
R10 | Channel C Volume | - | - | - | C Mode | vc3 | vc2 | vc1 | vc0 |
R11 | Envelope Period | ep7 | ep6 | ep5 | ep4 | ep3 | ep2 | ep1 | ep0 |
R12 | epF | epE | epD | epC | epB | epA | ep9 | ep8 | |
R13 | Envelope Wave Shape | - | - | - | - | es3 | es2 | es1 | es0 |
R14 | I/O Port A | Cas Input | Kbd Mode | Joy Trg.B | Joy Trg.A | Joy Right | Joy Left | Joy Back | Joy Fwd |
R15 | I/O Port B | Kana LED | Joy Sel | Pulse 2 | Pulse 1 | 1 | 1 | 1 | 1 |
Important note: the PSG registers R14 and R15 can be programmed for input or output. On MSX, R14 must be ever programmed for input and, R15, for output. Thus, bit 6 of R7 must ever be set to "0" (input) and, bit 7, to "1" (output). Programming them otherwise may cause severe damage to the machine, putting active coupling circuitry connected to R14 and R15 in short-circuit. More details on PSG register 7 section.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
Channel A Frequency (LSB) | R0 | ||||||||
x | x | x | x | Channel A Frequency (MSB) | R1 |
Figure 2: channel A period control registers.
These two registers are used to define the frequency of the Tone Generator for Channel A. Variable frequencies are produced by dividing a fixed master frequency with the number held in Registers 0 and 1, this number can be in the range 1 to 4095. Register 0 holds the least significant eight bits and Register 1 the most significant four. The PSG divides an external 1.7897725 MHz frequency by sixteen to produce a Tone Generator master frequency of 111,861 Hz. The output of the Tone Generator can therefore range from 111,861 Hz (divide by 1) down to 27.3 Hz (divide by 4095). As an example to produce a middle "A" (440 Hz) the divider value in Registers 0 and 1 would be 254.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
Channel B Frequency (LSB) | R2 | ||||||||
x | x | x | x | Channel B Frequency (MSB) | R3 |
Figure 3: channel B period control registers.
These two registers control the Channel B Tone Generator as for Channel A.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
Channel C Frequency (LSB) | R4 | ||||||||
x | x | x | x | Channel C Frequency (MSB) | R5 |
Figure 4: channel C period control registers.
These two registers control the Channel C Tone Generator as for Channel A.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
x | x | x | Noise Frequency |
Figure 5.
In addition to three square wave Tone Generators the PSG contains a single Noise Generator. The fundamental frequency of the noise source can be controlled in a similar fashion to the Tone Generators. The five least significant bits of Register 6 hold a divider value from 1 to 31. The Noise Generator master frequency is 111,861Hz as before, used on a Linear Feedback Shift Register (LFSR) with the equation:
17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ← | ┐ |
│ | ↓ | │ | |||||||||||||||||
└ | ─ | ─ | ─ | ─ | ─ | ─ | ─ | ─ | ─ | → | ⊕ | ─ | ─ | ─ | ─ | ─ | ─ | ─ | ┘ |
Figure 6: PSG Noise Generator block diagram, implementing LFSR function X0' = X17 ⊕ X6 ⊕ X0. Because all registers of the LFSR are set to 1 (one) at start, the X0 term is supressed (X0 = 1, so it would just invert the state of X0', and once all registers are already inverted at start, it must be removed to assure an initial zero to the pseudo-random sequence). The noise output is extracted from register 0.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Port B Direction | Port A Direction | Channel C Noise | Channel B Noise | Channel A Noise | Channel C Tone | Channel B Tone | Channel A Tone |
Figure 7: PSG Control Register 1.
This register enables or disables the Tone Generator and Noise Generator for each of the three channels. Notice that it uses inverse logic, that is, 0=Enable and 1=Disable. Also notice that PSG has three different tone generators, each attached to its corresponding channel, but only one noise generator, attached to the three channels at the same time.
Channel A Tone Generator | Channel B Tone Generator | Channel C Tone Generator | Noise Generator | |||
Figure 8: PSG mixer.
It also controls the direction of interface ports A and B, to which the joysticks and cassette are attached: 0=Input, 1=Output. Register 7 must always contain 10xxxxxx or possible damage could result to the PSG, there are active devices connected to its I/O pins. The BASIC "SOUND" statement will force these bits to the correct value for Register 7 but there is no protection at the machine code level.
7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----------------------+ | x | x | x |Mode | Channel A Amplitude | +-----+-----+-----+-----+-----------------------+
Figure 28.
The four Amplitude bits determine the amplitude of Channel A from a minimum of 0 to a maximum of 15. The Mode bit selects either fixed or modulated amplitude: 0=Fixed, 1=Modulated. When modulated amplitude is selected the fixed amplitude value is ignored and the channel is modulated by the output from the Envelope Generator.
This register controls the amplitude of Channel B as for Channel A.
This register controls the amplitude of Channel C as for Channel A.
7 6 5 4 3 2 1 0 +------------------------+ |Envelope Frequency (LSB)| R11 +------------------------+ |Envelope Frequency (MSB)| R12 +------------------------+
Figure 29.
These two registers control the frequency of the single Envelope Generator used for amplitude modulation. As for the Tone Generators this frequency is determined by placing a divider count in the registers. The divider value may range from 1 to 65535 with Register 11 holding the least significant eight bits and Register 12 the most significant. The master frequency for the Envelope Generator is 6991 Hz so the envelope frequency may range from 6991 Hz (divide by 1) to 0.11 Hz (divide by 65535).
7 6 5 4 3 2 1 0 +---+---+---+---+---------------+ | x | x | x | x |Envelope Shape | +---+---+---+---+---------------+
Figure 30.
The four Envelope Shape bits determine the shape of the amplitude modulation envelope produced by the Envelope Generator:
3 2 1 0 Modulation Envelope 0 0 x x |\_________________ 0 1 x x /|_________________ 1 0 0 0 |\|\|\|\|\|\|\|\|\| 1 0 0 1 |\_________________ 1 0 1 0 \/\/\/\/\/\/\/\/\/\ _________________ 1 0 1 1 \| 1 1 0 0 /|/|/|/|/|/|/|/|/|/ __________________ 1 1 0 1 / 1 1 1 0 /\/\/\/\/\/\/\/\/\/ 1 1 1 1 /|_________________
Figure 31.
7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----+-----+-----+-----+ | Cas | Kbd | Joy | Joy | Joy | Joy | Joy | Joy | |Input|Mode |Trg.B|Trg.A|Right|Left |Back | Fwd | +-----+-----+-----+-----+-----+-----+-----+-----+
Figure 32.
This register is used to read in PSG Port A. The six joystick bits reflect the state of the four direction switches and two trigger buttons on a joystick: 0=Pressed, 1=Not pressed. Alternatively up to six Paddles may be connected instead of one joystick. Although most MSX machines have two 9 pin joystick connectors only one can be read at a time. The one to be selected for reading is determined by the Joystick Select bit in PSG Register 15.
The Keyboard Mode bit is unused on UK machines. On Japanese machines it is tied to a jumper link to determine the keyboard's character set.
The Cassette Input is used to read the signal from the cassette EAR output. This is passed through a comparator to clean the edges and to convert to digital levels but is otherwise unprocessed.
7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----+-----+-----+-----+ |Kana | Joy |Pulse|Pulse| 1 | 1 | 1 | 1 | | LED | Sel | 2 | 1 | | | | | +-----+-----+-----+-----+-----+-----+-----+-----+
Figure 33.
This register is used to output to PSG Port B. The four least significant bits are connected via TTL open-collector buffers to pins 6 and 7 of each joystick connector. They are normally set to a 1, when a paddle or joystick is connected, so that the pins can function as inputs. When a touchpad is connected they are used as handshaking outputs.
The two Pulse bits are used to generate a short positive- going pulse to any paddles attached to joystick connectors 1 or 2. Each paddle contains a monostable timer with a variable resistor controlling its pulse length. Once the timer is triggered the position of the variable resistor can be determined by counting until the monostable times out.
The Joystick Select bit determines which joystick connector is connected to PSG Port A for input: 0=Connector 1, 1=Connector 2.
The Kana LED output is unused on UK machines. On Japanese machines it is used to drive a keyboard mode indicator.