Difference between revisions of "PSG"

From MegaDrive Wiki
Jump to: navigation, search
(Created page.)
 
m (Added to MD Category)
Line 142: Line 142:
 
* '''A3 to A0:''' Sets the attenuation value, with 0000 being 0 db, and 1111 being off.
 
* '''A3 to A0:''' Sets the attenuation value, with 0000 being 0 db, and 1111 being off.
  
[[Category:Hardware]]
+
[[Category:Hardware]] [[Category:MegaDrive]]

Revision as of 15:48, 11 August 2012

A 1 kHz square wave under ideal conditions

The Mega Drive contains a SN76489 as it's PSG chip, integrated into the VDP. This chip is capable of producing three square wave channels at a variating volume and frequency, as well as one noise channel. Even though square waves should look like perfect squares, they don't rise and fall from full to ground potential immediately so some slanting will be visible, but this will be disregarded in examples in this article. The PSG chip is mapped into Motorola 68000 address space at $C00011, and at $7F11 on the Zilog Z80.

Registers

The SN76489 is programmed through the use of various registers. Frequencies are set in 10 bit registers and counted down until they reach 0, at which point the output waveform for that channel will toggle and the counter gets reloaded. This counter is ran at 3.58MHz, the same clock as the Z80. Higher values in these registers produce lower frequencies. The noise channel can be set as either a periodic or white noise mode. The noise channel's clock source can be chosen between the main clock divided by 2, 4 or 8, or the third tone channel. Attenuation can also be set, which allow variations in the volumes of the various channels, in 2 db steps down from 0 db to 28 db, with each step dividing the volume by two.

Setting Frequency

File:1kSquareWave.ogg
A 1 kHz square wave.

Setting the frequency of a PSG channel can be accomplished by writing two bytes to the PSG's memory area:

Setting PSG frequency
128 64 32 16 8 4 2 1 Byte 2 128 64 32 16 8 4 2 1
1 R2 R1 R0 d3 d2 d1 d0 0 0 d9 d8 d7 d6 d5 d4
  • R2 through R0: These bits specify the tone channel to write to. See the table below.
  • d9 through d0: The 10 bit frequency counter value to write.
Tone Channel Map
R2 R1 R0 Tone Channel
0 0 0 Channel 1
0 1 0 Channel 2
1 0 0 Channel 3

Configuring Noise Channel

The noise channel can be used to create percussion effects. This trick is often used when the PSG chip is the only one available, although it may also be used to complement other percussion sounds created by the YM2612. The noise channel can be configured in two modes: A periodic type noise, and white noise. The frequency of the noise can be selected from four modes:

NF1 NF0 Clock Source
0 0 Clock/2 (higher pitch, less coarse)
0 1 Clock/4
1 0 Clock/8 (lower pitch, more coarse)
1 1 Tone Generator 3

With the clock source set to Tone Generator 3, it's output square wave will be used as the clock source for the noise. The register is set like so:

Setting Noise
128 64 32 16 8 4 2 1
1 1 1 0 0 FB NF1 NF0
  • FB: WHen set, the noise will be white noise, periodic noise if clear.
  • NF1 and NF0: Set the clock source for the noise as described above.

Attenuators

Each channel has an attenuator, which can be used to attenuate, or change the output level to make the channel quieter or louder. Each step down, for example from 0 db to 2 db halves the volume. The attenuator can be set in steps from 2 db, starting at 0 db (full volume) down to 28 db, after which the next step will completely disable sound. The attenuator can be set as follows:

Setting Attenuator
128 64 32 16 8 4 2 1
R2 R1 R0 1 A3 A2 A1 A0
  • R2 to R0: Sets the channel to write to, as indicated in the table in the above section.
  • A3 to A0: Sets the attenuation value, with 0000 being 0 db, and 1111 being off.