PSG

image image

Channels

Pulse

Ramp

Noise

The noise channel doesn’t have a pulse width

Envelope

Tip

By default, the envelope does nothing. You can safely ignore it, if you don’t want to use it.

Each channel has an envelope generator. This allows automated control for some parameters, such as volume and pitch. It has two memory mapped registers: mask, and length. Mask is a bitmask for envelope settings, and length controls the length of the envelope.

Envelope Mask

Flag nameBitDescription
FLAG_VOL0Controls Volume (Manual volume control still applies over this).
FLAG_PW1Controls Pulse Width / Duty Cycle (Overrides manual control).
FLAG_FREQ2Controls Pitch (sweep effect).
FLAG_GATE3Enable Gate: Mute when timer runs out. Independent from volume flag.
FLAG_FALLING4Falling instead of rising: Envelope goes from 100% to 0% instead of 0% to 100%.
5unused
FLAG_LOOP6Envelope loops. Envelope starts over if it runs out.
FLAG_LOOP_MIRROR7If looping, every other cycle is reversed (rise-fall-rise-fall…).

Default value for mask is 0, meaning that no bits are set.

Memory Map

AddrGlobalAccessNameDescription
0x00todoWch0_freqPulse 0 Frequency in Hz
0x010x01Wch0_volPulse 0 Volume
0x020x02Wch0_pwPulse 0 Pulse width
0x030x03Wch0_env_maskPulse 0 Envelope mask
0x040x04Wch0_env_lengthPulse 0 Envelope length in milliseconds
0x100x10Wch1_freqPulse 1 Frequency in Hz
0x110x11Wch1_volPulse 1 Volume
0x120x12Wch1_pwPulse 1 Pulse width
0x130x13Wch1_env_maskPulse 1 Envelope mask
0x140x14Wch1_env_lengthPulse 1 Envelope length in milliseconds
0x200x20Wch2_freqRamp Frequency in Hz
0x210x21Wch2_volRamp Volume
0x220x22Wch2_dcRamp Duty cycle
0x230x23Wch2_env_maskRamp Envelope mask
0x240x24Wch2_env_lengthRamp Envelope length in milliseconds
0x300x30Wch3_freqNoise Frequency in Hz
0x310x31Wch3_volNoise Volume
0x330x33Wch3_env_maskNoise Envelope mask
0x340x34Wch3_env_lengthNoise Envelope length in milliseconds

Examples

Todo