Changes

Jump to: navigation, search

PSG

3,787 bytes added, 14 May
/* Other Variants */
The Programmable Sound Generator (PSG) is a sound chip designed by General Instrument (GI) in 1978. The specific model used in the CPC is the AY-3-8912 chip.
The PSG is quite primitive. It is able to output a square wave and/or white noise in three separate sound channels (named Channel A, B and C). Each channel can be used to output tones and/or white noise.
== PSG Part numbers Some other 8-bit systems used in more sophisticated soundchips such as the CPC during its lifetime ==[https://youtu.be/7pONRbIHT_w C64 SID], the [https://youtu.be/BANwL2sQ0DM NES APU] and the [https://youtu.be/-mdjiWBYIqU Gameboy soundchip].
* GI AY-3-8912 [https:== I//www.cpcwiki.eu/imgs/c/cc/CPC464_PCB_Top_%28Z70378_MC0046A%29.jpg Source]* GI AY-3-8912A [https://www.cpcwiki.eu/imgs/f/f1/CPC6128_PCB_Top_%28Z70290_MC0020B%29.jpg Source]* Microchip AY-3-8912 [https://www.cpcwiki.eu/imgs/c/cf/AmstradCPC464_Z70375_MC0044D_GA40010_PCB_Top.jpg Source]* Microchip AY38912/P [https://www.cpcwiki.eu/imgs/5/5e/CPC464Plus_MC0122B_2700-016P-3_PCB_Top.jpg Source]O Access ==
<br> == The PSG Registers ==has 16 read/writeable data registers, and a write-only index register.
The PSG has While there are only 16 read/writeable data registers, and a write-only the index registeris 8-bit, not 4-bit. Only the The higher 4 least significant -bits of the selected index register number are consideredused as chip select.
Both the index and data registers are accessed through [[8255|PPI Port A]], depending on the current setting of the BC1 and BDIR bits in [[8255|PPI Port C]]. The four possible combinations are:
# set BC1/BDIR to Write Data
# and back to Inactive.
 
You must use 3 OUTs to send a value to an AY register, even if you don't change registers in the meantime. [https://www.cpcwiki.eu/forum/programming/interesting-walkthrough-video-coding-a-pet-to-play-samples-at-60khz/msg250874/#msg250874 Source]
 
So you have to enter the data on F4. Then on F6, select the type of data (bdir/bc1>>#10) and validate everything (bdir/bc1>>00). Otherwise, the data in other AY registers becomes corrupted quite quickly.
Consult this article for more information: [[How to access the PSG via PPI]]
 
<br>
 
== PSG Registers ==
===00h - Channel A Tone Frequency Low (8bit)===
=== 0Dh - Volume Envelope Shape (4bit) ===
Writing to this register (re-)starts the envelope. Both components of the envelope's phase are reset. The first step of the envelope has full duration every time. It is never shorted. [https://forums.nesdev.org/viewtopic.php?p=236672#p236672 Source]
 
The written value specifies the envelope shape, the four bits have the following meaning:
The possible combinations and resulting shapes are:
{| class="wikitable"|-! Binary !! Hex !! Shape!! Comment |-| 00XX || 00h-03h || <code>\_________ (</code> || same as 09h) |-| 01XX || 04h-07h || <code>/_________ (</code> || same as 0Fh) |-| 1000 || 08h || <code>\\\\\\\\\\</code> || |-| 1001 || 09h || <code>\_________ (</code> || volume remains quiet) |-| 1010 || 0Ah || <code>\/\/\/\/\/</code> || |-| 1011 || 0Bh || <code>\""""""""" (¯¯¯¯¯¯¯¯¯</code> || volume remains high) |-| 1100 || 0Ch || <code>//////////</code> || |-| 1101 || 0Dh || <code>/""""""""" (¯¯¯¯¯¯¯¯¯</code> || volume remains high) |-| 1110 || 0Eh || <code>/\/\/\/\/\</code> || |- | 1111 || 0Fh || <code>/_________ (</code> || volume remains quiet) We can observe that there are only 8 resulting shapes even though they are selected by using a 4-bit value.|}
When using the volume envelope generator, the volume is always increased from 00h to 0Fh (or vice versa), it is not possible to specify a starting/ending point (like from 00h to 07h).
Writing to this register ==== Bit 2 (re-Attack)starts ==== This bit is only responsible for the starting point of the envelopeand the direction.We have: volume = 0 if attack else 15 # Start at 0 for attack, 15 for decay direction = 1 if attack else -1 # Upward for attack, downward for decay ==== Bit 3 (Continue), Bit 1 (Alternate) and Bit 0 (Hold) ==== When bit3 = 0, volume and direction at the end of a period are always 0. When bit3 = 1, bit1 and bit0 determine what happens to volume and direction at the end of a period. ==== Algorithm ====  def envelope_step(volume, direction, shape): volume += direction if volume > 15 or volume < 0: match shape: case 8 | 12: volume &= 0x0f # direction is unchanged case 10 | 14: direction *= -1 volume += direction case 11 | 13: direction = 0 volume = 15 case _: direction = 0 volume = 0 return volume, direction
=== 0Eh - External Dataregister Port A ===
This register receives data from the CPC keyboard (or joystick), for more information read the chapter about the [[Programming:Keyboard_scanning|CPC Keyboard Matrix]].  This register can be also used as output port by setting bit 6 of the PSG control register to 1 (that would allow to use the six data pins of the joystick connector to output data to external hardware).
=== 0Fh - External Dataregister Port B ===
This register is not used in CPC computers. In detail, a AY-3-8910 sound chip would have external connectors for this register, so that it could be used as a further IO port, but the CPC's sound chip (AY-3-8912, in 28 pin package) doesn't have such connectors, even though the register still does exist internally.
 The [[Aleste 520EX]] (russian CPC clone) is a special case: does have it has a 8910 Yamaha YM2149F chip, with PSG SSG Port B being used as 8bit printer port data.
<br>
== Noise Generator ==
The noise generator uses a [https://en.wikipedia.org/wiki/Linear-feedback_shift_register Linear-Feedback Shift Register] algorithm. It is described in detail in the [[Media:Microchip ay8930.pdf|AY-8930 datasheet]].
The noise generator uses a [https://en.wikipedia.org/wiki/Linear-feedback_shift_register Linear-Feedback Shift Register] algorithm. The random number generator of the 8910 is a 17-bit shift register.  According to [https://github.com/mamedev/mame/blob/master/src/devices/sound/ay8910.h MAME]: The input to the shift register is bit0 XOR bit3. Bit0 is the output. This was verified on AY-3-8910 and YM2149 chips. However, the algorithm is described in detail in the [[Media:Microchip ay8930.pdf|AY-8930 datasheet]]. And it disagrees with MAME, the input to the shift register is bit0 XOR bit2. And it seems bit1 is the output. [[File:AY38910A noise block diagram.png]]
<br>
== Chip Variants ==
The PSG chip family is composed of 3 variants: the AY-3-8910 with two 8-bit I/O ports, the AY-3-8912 with one 8-bit I/O port and the AY-3-8913 with no I/O port. In addition to the CPC, these chips were also === IC models used in the [[ZX Spectrum]], [[MSX]], [[Oric]], [[Vectrex]], [[Intellivision]] and in the Mockingboard expansion for the [[Apple II]].CPC ===
The PSG chip competed with These are the DCSG (Digital Complex Sound Generator) chip family (SN76489, SN94624, TMS9919) ones known to be used in the CPC by Texas Instrumentslooking at pictures of CPC mainboards. The DCSG has similar sounding features except that it does not have any envelope control and that its noise generator has its own dedicated channelAll should operate almost identically.
Toshiba T7766A, Winbond WF19054, JFC 95101 and File KC89C72 are clones of the PSG* GI AY-3-8912 [https://www.cpcwiki.eu/imgs/c/cc/CPC464_PCB_Top_%28Z70378_MC0046A%29. jpg Source]* GI AY-3-8912A [https://wikiwww.agiricpcwiki.ninjaeu/sound_chip_clonesimgs/f/f1/CPC6128_PCB_Top_%28Z70290_MC0020B%29.jpg Source]* Microchip AY-3-8912 [https:index //www.cpcwiki.eu/imgs/c/cf/AmstradCPC464_Z70375_MC0044D_GA40010_PCB_Top.jpg Source]* Microchip AY38912/P [https://www.cpcwiki.eu/imgs/5/5e/CPC464Plus_MC0122B_2700-016P-3_PCB_Top.jpg Source]
Yamaha produced the SSG (Software-controlled Sound Generator) chip family (YM2149F, YM3439, YMZ294, YMZ284, YMZ285) which is a quasi-clone of the PSG. The main difference is that the envelope counter on the PSG has 16 steps. On the SSG it has twice the steps, happening twice as fast. This chip equips the [[Atari ST]], [[Aleste 520EX]] and some [[MSX]] computers. [https://www.cpcwiki.eu/imgs/a/ae/ALESTE_520EX_PCB_Top.jpg Source1] [https://www.msx.org/wiki/Yamaha_YM2149 Source2]=== Other Variants ===
The PSG chip family is composed of 3 variants:* the AY-3-8910, with two 8-bit I/O ports and a 40-pin package* the AY-3-8912, with one 8-bit I/O port and a 28-pin package* the AY-3-8913, with no I/O port and a 24-pin packageIn addition to the CPC, these chips were also used in the [[KC Compact]], [[ZX Spectrum]], [[MSX]], [[Oric-1/Atmos|Oric]], [[EG2000 Colour Genie]], [[Vectrex]], [[Intellivision]] and in the Mockingboard expansion for the [[Apple II]]. There are also PSG clones: Toshiba T7766A, Winbond WF19054, JFC 95101 and File KC89C72. [https://wiki.agiri.ninja/sound_chip_clones:index Source] Yamaha produced the SSG (Software-controlled Sound Generator) chip family (YM2149F, YM3439, YMZ294, YMZ284, YMZ285) which is a quasi-clone of the PSG. The main difference is that the envelope counter on the PSG has 16 steps. On the SSG it has twice the steps, happening twice as fast. This chip equips the [[Atari ST]], [[Aleste 520EX]] and [https://www.msx.org/wiki/Yamaha_YM2149 some MSX computers]. It is also used in the [[PlayCity]] expansion. The SSG has also been integrated as a component inside some of the arcade soundchips of the Yamaha OPN family. That's why you can find it in the [[Neo-Geo]] as a component inside the YM2610 soundchip. And the same is true for the OPN3 soundchip of the [[Play2CPC]] expansion. The chip is clocked differently depending on the computer: ZX Spectrum: 1773400 Hz ; Pentagon: 1750000 Hz ; MSX: 1789772 Hz ; CPC: 1000000 Hz ; Oric: 1000000 Hz ; Atari ST: 2000000 Hz.
The EPSG (AY-3-8930), used in the Covox Sound Master soundcard on PCs, is a register-compatible evolution of the AY-3-8910:
* The noise tone can be changed by applying an AND and OR mask to the output
<br>=== Competitors ===
The PSG chip competed with the DCSG (Digital Complex Sound Generator) chip family (SN76489, SN94624, TMS9919) by Texas Instruments. The DCSG has similar sounding features except that it does not have any envelope control and that its noise generator has its own dedicated channel. == Datasheet = Replacing the AY-3-8912 in the CPC with an AY-3-8910(A) ===* [[Media:Ay3In case that the AY-3-8912 needs to be replaced in the CPC it can become a hurdle these days to get a real AY-3-891x8912 especially for an acceptable price.pdf| Instead of the original AY-3-891x datasheet8912 it's possible to use an AY-3-8910(A) instead with the help of a small adapter board. An open source adapter board can be found here: https://github.com/etomuc/CPC-AY-3-8910-to-8912-adapter For tips regarding the desoldering of ICs see this Wiki page: [[IC Repair]] <br>
== Links ==
*[http://en.wikipedia.org/wiki/General_Instrument_AY-3-8910 Wikipedia on the PSG]
*[[Media:Ay3-891x.pdf|AY-3-891x datasheet]] [[Media:Ym2149 datasheet.pdf|YM2149 datasheet]]
*[http://quasar.cpcscene.net/doku.php?id=assem:psg Quasar PSG documentation (in french)]
*[https://youtu.be/C4ezcX1W2_Y Mix I] [https://youtu.be/gH57xU9c7dE Mix II] [https://youtu.be/e7V3EMXF97g Mix III] AMSTRAD CPC MUSIC 1 hour
*[https://youtu.be/AhgUwqv2yAE Space Debris - Amstrad CPC Soundtrakker cover] [https://youtu.be/E_plcHyOC_8 RUN! - SID emulation on Amstrad CPC] by [[BSC]]
*[https://nguillaumin.github.io/ym-jukebox/ YM Jukebox] [https://ym.mmcm.ru/ AY Music Collection]
 
<br>
[[Category:Hardware]]
[[Category:Music and sound| ]][[Category:Video contents]][[Category:CPC Internal Components]]
13,173
edits