Z80 Assembly 72: Beeper Sound and Color Control (The FEH Port)

The Combined I/O Port: FEH The ZX Spectrum uses the same I/O port address **FEH′** for multiple output functions. When you execute an OUT (FEH), A` instruction, every bit in the Accumulator (A) controls a different piece of hardware. The Output Byte Breakdown (OUT to `FEH′): Bit Function Value (If Set) Purpose 0-2 Border Color 000B - 111B Sets the color of the screen border (0=Black, 7=White). 3 Beeper Output `08H′ Toggles the speaker (0=Off, 1=On). 4 EAR Socket `10H′ Controls the tape recorder output (used for data saving/loading). 5-7 Unused N/A Ignored by the 48K Spectrum hardware. Controlling the Beeper To produce sound, you must create a fast timing loop (Part 28) that toggles Bit 3 of the output byte. ...

September 28, 2025

Z80 Assembly 39: Software Sound Synthesis (Beyond the Square Wave)

Limitations of the Beeper (Square Wave) The simple beeper (Part 28) can only produce a square wave (a harsh, buzzy tone) because it only switches the speaker ON or OFF. To create richer sounds, like music that sounds closer to a sine wave, or complex speech effects, we need to simulate varying amplitude (volume). Pulse-Width Modulation (PWM) Synthesis Since the Z80 cannot vary the voltage to the speaker, we simulate varying amplitude using Pulse-Width Modulation (PWM). ...

September 27, 2025

Z80 Assembly 38: Complex Music with the AY-3-8910 Sound Chip

The Limitation of the Beeper The simple beeper (Part 28) can only play one square wave tone at a time. The AY-3-8910 (or compatible) Programmable Sound Generator is a dedicated chip that provides three independent tone channels, a noise generator, and volume control. Communicating with the AY Chip The AY chip uses a few fixed I/O ports for communication. The Z80 talks to it using a two-step process: Select Register: Write the address (0-15) of the internal register you want to modify. Write Data: Write the actual data value to that register. Generic AY Port Example: ...

September 27, 2025

Z80 Assembly 28: Basic Sound Generation (The Beeper Port)

The Basics of Beeper Sound Many simple Z80 systems (like the ZX Spectrum) lack a dedicated sound chip and rely on a simple speaker connected to an I/O port. This speaker is known as the beeper. How Tones are Made: A tone is generated by rapidly toggling a single bit in the output port (switching the speaker ON and OFF) at a specific frequency. Frequency & Pitch: The speed of the toggling loop determines the tone’s frequency (pitch). ...

September 27, 2025