Skip to content

Latest commit

 

History

History
413 lines (308 loc) · 12.9 KB

HOWTO.md

File metadata and controls

413 lines (308 loc) · 12.9 KB

How to use the PSG AY-3-8910 BF MSX SDCC Library


Index



1 Description

Library functions for access to internal or external MSX PSG AY-3-8910.

It does not use the BIOS so it can be used to program both ROMs or MSX-DOS executables.

This library is similar to the PSG AY-3-8910 RT, but instead of writing directly to the registers, it does so to a buffer that should be dumped to the AY in each VBLANK frame.

It is designed to work together with the PT3player and/or ayFXplayer libraries, but you can also use it for your own or third-party player.

In this same repository you will find a short version (AY38910BF_S) with the essentials to work with player libraries.

It incorporates the SOUND function with the same behavior as the command included in MSX BASIC, as well as specific functions to modify the different sound parameters of the AY.

Controls the I/O bits of register 7 (Mixer), of the internal AY.

It allows to use the internal PSG of the MSX or an external one (like the one incorporated in the MEGAFLASHROM SCC+ or the Flashjacks).

In the header file there is a definition of SWITCHER type, needed for the functions. This type uses the values "ON" or "OFF", which equals 1 and 0 respectively.

Include definitions to improve the readability of your programs.

Use them for developing MSX applications using Small Device C Compiler (SDCC).

This project is an Open Source library. You can add part or all of this code in your application development or include it in other libraries/engines.

This library is part of the MSX fR3eL Project.

Enjoy it!



2 Requirements



3 AY Sound System

The AY38910BF, PT3player and ayFXplayer libraries are designed to work together, so you will have a system to provide music and effects in game development.

AY Sound System



4 Definitions

4.1 SWITCHER Type

Data type definition to be used in switches (same as boolean type).

Label Value
OFF 0
ON 1

4.2 AY Type

Label Value
AY_INTERNAL 0
AY_EXTERNAL 1

4.3 AY Registers

Label Value Description
AY_ToneA 0 Channel A Tone Period (12 bits)
AY_ToneB 2 Channel B Tone Period (12 bits)
AY_ToneC 4 Channel C Tone Period (12 bits)
AY_Noise 6 Noise Period (5 bits)
AY_Mixer 7 Mixer
AY_AmpA 8 Channel Volume A (4 bits + B5 active Envelope)
AY_AmpB 9 Channel Volume B (4 bits + B5 active Envelope)
AY_AmpC 10 Channel Volume C (4 bits + B5 active Envelope)
AY_EnvPeriod 11 Envelope Period (16 bits)
AY_EnvShape 13 Envelope Shape

4.4 Envelope shapes

The header file defines envelope shapes in case you prefer to use it instead of the numerical form:

Label Value
AY_ENV_LowerBeat 1
AY_ENV_Upper 4
AY_ENV_LeftSaw 8
AY_ENV_LowerTriangle 10
AY_ENV_LowerHold 11
AY_ENV_RightSaw 12
AY_ENV_UpperHold 13
AY_ENV_UpperTriangle 14

Attention! The LowerBeat shape may be produced with the values: 0, 1, 2, 3 and 9. The value 1 has been assigned to LowerBeat as 0 can be useful in case you need to control when the envelope is triggered. In this case 0 can act as a "don't write the envelop" event. Remember that, every time the register 13 is written, the sound with the assigned shape is started.

The Upper shape may be produced with the values: 4, 5, 6, 7 and 15.

4.5 AY channels

You can use it in the functions: SetTonePeriod, SetVolume and SetChannel

Label Value
AY_Channel_A 0
AY_Channel_B 1
AY_Channel_C 2


5 Functions

5.1 AY_Init

AY_Init
Initialize the AY buffer.
FunctionAY_Init()
Input ---
Output ---
Examples:
AY_Init();

5.2 SOUND

SOUND
Write into a register of PSG
FunctionSOUND(register, value)
register[char] register number (0 to 13)
value[char] value
Output ---
Examples:
Sound(8,16); //channel A envelope on

5.3 GetSound

GetSound
Read PSG register value
FunctionGetSound(register)
register[char] register number (0 to 13)
Output[char] value
Examples:
char value;            
value = GetSound(7);  //read mixer register

5.4 SetTonePeriod

SetTonePeriod
Set Tone Period for any channel
FunctionSetTonePeriod(channel, period)
channel[char] channel (0, 1 or 2)
period[unsigned int] period (0 - 4095)
Output ---
Examples:
SetTonePeriod(AY_Channel_B,1100);  //set tone period for channel A

5.5 SetNoisePeriod

SetNoisePeriod
Set Noise Period
FunctionSetNoisePeriod(period)
period[char] Noise period (0 - 31)
Output ---
Examples:
SetNoisePeriod(10);

5.6 SetEnvelopePeriod

SetEnvelopePeriod
Set Envelope Period
FunctionSetEnvelopePeriod(period)
period[unsigned int] Envelope period (0 - 65535)
Output ---
Examples:
SetEnvelopePeriod(1000);

5.7 SetVolume

SetVolume
Set volume channel
FunctionSetVolume(channel, volume)
channel[char] channel (0, 1 or 2)
volume[char] volume, 0 to 15 or 16 for activate envelope
Output ---
Examples:
SetVolume(0,14);  // set 14 volume level for channel A
SetVolume(1,16);  // activate envelope for channel B

5.8 SetChannel

SetChannel
Mixer. Enable/disable Tone and Noise channels.
FunctionSetChannel(channel, isTone, isNoise)
channel[char] channel (0, 1 or 2)
isTone[SWITCHER] Tone channel state
isNoise[SWITCHER] Noise channel state
Output ---
Examples:
SetChannel(0,true,false);
SetChannel(1,true,true);
SetChannel(2,false,false);

5.9 PlayEnvelope

PlayEnvelope
Set envelope type.
Plays the sound on channels that have a volume of 16.
FunctionPlayEnvelope(shape)
shape[char] Envelope shape (0-15)
Output ---
Examples:
PlayEnvelope(0); //Play LowerBeat envelope shape
PlayEnvelope(ENV_LowerTriangle); //Play LowerTriangle envelope shape

5.10 PlayAY

PlayAY
Send data from AYREGS buffer to AY registers.
(Execute on each interruption of VBLANK).
FunctionPlayAY()
Input ---
Output ---
Examples:
PlayAY();


6 Set Internal or External AY

To indicate in which PSG the sounds are to be played, you have the AY_TYPE variable. To select an external AY (ports 10h to 12h), like the one included in the MegaFlashROM SCC+, Flashjacks or other, you have to set the variable to 1 (or AY_EXTERNAL).

  AY_TYPE = AY_EXTERNAL;

Attention! When you execute the AY_Init() function, it will be updated to the default value corresponding to the internal AY.



7 How to use

coming soon...



8 Appendices

8.1 AY-3-8910 Register Table

Register\bitB7B6B5B4B3B2B1B0
R0Channel A Tone Period8-Bit Fine Tune A
R14-Bit Coarse Tune A
R2Channel B Tone Period8-Bit Fine Tune B
R34-Bit Coarse Tune B
R4Channel C Tone Period8-Bit Fine Tune C
R54-Bit Coarse Tune C
R6Noise period5-Bit Period control
R7Enable (bit 0=on, 1=off)IN/OUTNoiseTone
IOBIOAC BAC BA
R8Channel A AmplitudeEnvAmplitude
R9Channel B AmplitudeEnvAmplitude
R10Channel C AmplitudeEnvAmplitude
R11Envelope Period8-Bit Fine Tune Envelope
R128-Bit Coarse Tune Envelope
R13Envelope Shape/CycleCONTATTALTHOLD
R14I/O Port A Data Store8-Bit Parallel I/O on Port A
R15I/O Port B Data Store8-Bit Parallel I/O on Port B


9 References



Creative Commons License
This document is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.