PSG - Programmable Sound Generator

Overview

The AY-3-8910 is a register oriented Programmable Sound Generator. Control commands are issued to the PSG by writing to 16 registers. Each of the 16 registers is also readable so that the microprocessor can determine present states or stored data values. All functions of the PSG are controlled through the 16 registers which once programmed, generate and sustain the sounds, thus freeing the system processor for other tasks.

The basic blocks in the PSG which produce the programmed sounds include:

  • Tone Generators, produce the basic square wave tone frequencies for each channel (A,B,C)
  • Noise Generator, produces a frequency modulated pseudo random pulse width square wave output
  • Mixers, combine the outputs of the Tone Generators and the Noise Generator. One for each channel (A,B,C)
  • Amplitude Control, provides the D/A converters with either fixed or variable amplitude pattern. The fixed amplitude is under direct CPU control; the variable amplitude is accomplished by using the output of the Envelope Generator.
  • Envelope Generator produces an envelope pattern which can be used to amplitude modulate the output of each mixer D/A Converters the three D/A converters each produce up to a 16 level output signal as determined by the Amplitude Control

In addition, there are two two eight bit data I/O ports, called A and B, through which it interfaces the joysticks, etc. 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 following I/O ports are used to communicate with the PSG.

SVI MSX Read/Write Description
88H A0H W Data write
8CH A1H W Adress latch
90H A2H R Data read

The PSG has an 1.79MHz clock frequency.
 

Address 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.
 

Data Write Port

This port is used to write to any register once it has been selected by the Address Port.
 

Data Read Port

This port is used to read any register once it has been selected by the Address Port.
 

Registers 0

Bit Name Description
0-7 FTUNEA Channel A Frequency, LSB (fine tune)

Registers 1

Bit Name Description
0-3 CTUNEA Channel A Frequency, MSB (coarse tune)
4-7   Not used

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 0 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.

NOTE: For a tone to be heard, the channel on which it is to be played must have a volume (greater than 0), and its associated tone disable flag must be set to 0 (i.e. the tone is enabled) in the mixer control register.
 

Registers 2 and 3

These two registers control the Channel B Tone Generator as for Channel A.
 

Registers 4 and 5

These two registers control the Channel C Tone Generator as for Channel A.
 

Register 6

Bit Name Description
0-4 PERIOD Noise Frequency (5 bit period control)
5-7   Not used

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,861 Hz as before. Low values produce hissing, while large values produce grating noises.
 

Register 7

Bit Name Description
0 TA Tone Genrator A enable/disable
1 TB Tone Genrator B enable/disable
2 TC Tone Genrator C enable/disable
3 NA Noise Generator A enable/disable
4 NB Noise Generator B enable/disable
5 NC Noise Generator C enable/disable
6 IOA Port A input/output control
7 IOB Port B input/output control

This register enables or disables the Tone Generator and Noise Generator for each of the three channels: 0=Enable 1=Disable. 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.
 

Register 8

Bit Name Description
0-3 AMPL Channel A Amplitude (volume)
4 MODUL Volume controlled by Envelope enable/disable
5-7   Not used

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.

If bit 4 is set to 1, the volume is controlled by hardware enveloping (selected with registers 11-13), and bits 3-0 are ignored.

If bit 4 is set to 0, bits 3-0 hold the volume to be used. The volume is in the range 0-15, where 0 is no volume and 15 which is maximum volume.
 

Register 9

This register controls the amplitude of Channel B as for Channel A.
 

Register 10

This register controls the amplitude of Channel C as for Channel A.
 

Registers 11

Bit Name Description
0-7 FTUNEE Envelope Frequency, LSB (period fine tune)

Registers 12

Bit Name Description
0-7 CTUNEE Envelope Frequency, MSB (period coarse tune)

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).

Period = (3579545/256*frequency)
Register 11 = Period AND 255
Register 12 = Period / 256
 

Register 13

Bit Name Description
0 SHAPE Envelope shape, Hold
1 SHAPE Envelope shape, Alternate
2 SHAPE Envelope shape, Attack
3 SHAPE Envelope shape, Continue
4-7   Not used

The four Envelope Shape bits determine the shape of the amplitude modulation envelope produced by the Envelope Generator. Enveloping is used to produce special effects. It works by modifying the volume output on the channel which is enabled.

The shape of the envelope defines how the volume is affected. If the envelope slopes upwards the volume will be increased, and if the envelope slopes downwards the volume will be decreased. If the envelope repeatedly slopes up and down, the volume will repeatedly rise to a maximum and then drop a minimum.

The shapes of envelopes that can be produced is shown in the table below.

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	 /|_________________

x indicates bit with any value (either 1 or 0)
 

Register 14

Bit Name Description
0-7 PORTA I/O Port A

This register holds any data which is written to/read from port A of the PSG.

To read a value from this port, it must be put into input mode by setting bit 6 of register 7 (mixer control) of the PSG to 0. Usually, this is not necessary as port A always operates as input, unless it has been changed by the user.

To write a value to this port, it must be put into output mode by setting bit 6 of register 7 (mixer control) of the PSG to 1. The user can then write the byte into the register.

In the SVI-328/318, port A is used for a special function. It is used for INPUT of joystick direction status. It must ONLY be READ, writing values to this port may have an unpredicted result.

0 FWD1 Joystick 1, Forward
1 BACK1 Joystick 1, Back
2 LEFT1 Joystick 1, Left
3 RIGHT1 Joystick 1, Right
4 FWD2 Joystick 2, Forward
5 BACK2 Joystick 2, Back
6 LEFT2 Joystick 2, Left
7 RIGHT2 Joystick 2, Right


In the SVI-728/738, port A is used for a special function. It is used for INPUT of joystick status and cassette data. It must ONLY be READ, writing values to this port may have an unpredicted result.

0 FWD Joystick, Forward
1 BACK Joystick, Back
2 LEFT Joystick, Left
3 RIGHT Joystick, Right
4 TRGA Joystick, Trigger A (0=pressed, 1=not pressed)
5 TRGB Joystick, Trigger B (0=pressed, 1=not pressed)
6 KBDMOD Keyboard mode (japanese machines)
7 CASIN Cassette Input

 

Register 15

Bit Name Description
0-7 PORTB I/O Port B

This register holds any data which is written to/read from port B of the PSG.

To read a value from this port, it must be put into input mode by setting bit 7 of register 7 (mixer control) of the PSG to 0. Usually, this is not necessary as port A always operates as input, unless it has been changed by the user.

To write a value to this port, it must be put into output mode by setting bit 7 of register 7 (mixer control) of the PSG to 1. The user can then write the byte into the register.

In the SVI-328/318, port B is used for a special function. It is used for OUTPUT to select memory bank to be used.

0 CART ROM Bank 1 - Cartridge (0=Bank On, 1=Bank Off)
1 BK21 RAM Bank 21 (0=Bank On, 1=Bank Off)
2 BK22 RAM Bank 22 (0=Bank On, 1=Bank Off)
3 BK31 RAM Bank 31 (0=Bank On, 1=Bank Off)
4 BK32 RAM Bank 32 (0=Bank On, 1=Bank Off)
5 CAPS Caps Lock LED on/off
6 ROMEN0 ROM 0 enable (1=Disable, 0=Enable)
7 ROMEN1 ROM 1 enable (1=Disable, 0=Enable)


In the SVI-728/738, port B is used for a special function. It is used for OUTPUT to joystick.

0 1 (Used as handshaking output if touchpad)
1 1 (Used as handshaking output if touchpad)
2 1 (Used as handshaking output if touchpad)
3 1 (Used as handshaking output if touchpad)
4 PULSE Pulse 1 (for paddles)
5 PULSE Pulse 2 (for paddles)
6 JOYSEL Joystick select (0=Joystick 1, 1=Joystick 2)
7 KANLED LED output (japanese machines)

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.
 

Register Overview

Register Bits Description
0 8 Channel A Tone Period (fine tune)
1 4 Channel A Tone Perid (coarse tune)
2 8 Channel B Tone Period (fine tune)
3 4 Channel B Tone Period (coarse tune)
4 8 Channel C Tone Period (fine tune)
5 4 Channel C Tone Period (coarse tune)
6 5 Noise Generator control
7 8 Mixer control and I/O enable
8 5 Channel A amplitude (volume) and Envelope enable
9 5 Channel B amplitude (volume) and Envelope enable
10 5 Channel C amplitude (volume) and Envelope enable
11 8 Envelope period (fine tune)
12 8 Envelope period (coarse tune)
13 4 Envelope shape
14 8 I/O port A
15 8 I/O port B

NOTE:

fine tune = send low byte of the value required (bits 7-0)
coarse tune = send high byte of the value required. (bits 15-8)