Z80 Assembly 77: Interrupt-Driven Printing (Spooling Data)

The Drawback of Polling Printers are extremely slow compared to the Z80 CPU. If the main program waits for the NOT BUSY status bit (Part 76) after sending every single character, the CPU spends most of its time sitting idle, waiting for the printer to finish. The Solution: Interrupt Spooling Spooling (Simultaneous Peripheral Operations On-Line) uses interrupts to feed the printer one byte at a time in the background, allowing the main program to continue executing tasks. ...

September 28, 2025

Z80 Assembly 76: Printer I/O and Parallel Data Transfer

The Challenge of Parallel Data Transfer Unlike serial communication (sending one bit at a time, Part 40), parallel communication sends an entire byte (8 bits) simultaneously across 8 dedicated data lines. This requires additional lines for handshaking to ensure the slow peripheral (the printer) is ready to receive the data. Printer Ports on the Spectrum The ZX Spectrum often uses an external interface (like the ZX Interface 1 or Kempston printer interface) to add parallel output capability. These interfaces typically map to two adjacent I/O ports: ...

September 28, 2025

Z80 Assembly 75: Low-Level Cassette Tape I/O (Saving and Loading Data)

The Cassette I/O Challenge The ZX Spectrum does not have a dedicated tape controller chip. All tape reading and writing is achieved through software routines that precisely control the timing of a single I/O line, which is one of the most demanding tasks for the Z80 CPU. The Principle: Data is encoded using Pulse Width Modulation (PWM), where the duration of the tone (the pulse width) determines whether the CPU sends a binary ‘0’ or a binary ‘1’. ...

September 28, 2025

Z80 Assembly 74: Displaying a Full Screen Image (Loading Graphics Data)

The Full Screen Data Load To display a custom image on the Spectrum (e.g., a title screen or game level background), you must copy two large blocks of data from your program’s memory into the Spectrum’s Display File RAM. The Two Blocks: Pixel Data: 6144 bytes of raw $256 \times 192$ pixel information (starts at `4000H′). Attribute Data: 768 bytes of color and flash information (starts at `5800H′). Routine 1: Loading the Pixel Data The Pixel Data is 6144 bytes long. Since the data layout is non-linear (Part 73), you generally copy the data block-by-block. However, if your source data is already arranged in the Spectrum’s non-linear format, you can use the fastest method: `LDIR′. ...

September 28, 2025

Z80 Assembly 73: The Non-Linear Screen Memory Calculation

The Challenge of the Spectrum Screen The ZX Spectrum screen memory is not linear. To save on hardware costs, the memory map was designed to simplify the display hardware’s access but complicate the CPU’s access. The Layout: The screen is divided into three major vertical bands, and within each band, the lines are interleaved. This means to find the address of the pixel at (X, Y), you must perform a complex, multi-step calculation. ...

September 28, 2025

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 71: I/O Ports and the Keyboard Matrix Scan

The Spectrum’s Key I/O Port The ZX Spectrum is minimalistic, relying on just a few I/O ports to manage all peripherals (keyboard, display, cassette, and beeper). The Main Port: The most crucial I/O address is `FEH′ (254 decimal), which is used for both input and output control. I/O Port Decoding (The Trick) The Spectrum simplifies hardware design by only connecting I/O logic to the lowest bit (A0) and the highest byte (A8-A15) of the Z80’s 16-bit address lines. ...

September 28, 2025

Z80 Assembly 70: The ZX Spectrum Memory Map and Entry Points

Introduction to the Spectrum’s Memory Map The ZX Spectrum is a 48KB machine with a simple, fixed memory map. Understanding this map is crucial because the Z80 must interact with the screen and system variables at hardcoded addresses. The 64KB address space is divided into four main 16KB blocks: Address Range Size (KB) Content Usage 0000H - 3FFFH 16 KB System ROM Holds the BASIC interpreter and operating system kernel. 4000H - 7FFFH 16 KB Low RAM Holds the Display File (Screen + Attributes) and user data. 8000H - BFFFH 16 KB High RAM 1 General purpose user program space. C000H - FFFFH 16 KB High RAM 2 Used for user programs and the CPU Stack (grows downwards). The Display File (Screen Memory) The most important fixed addresses are those related to the screen, which resides in the low RAM area. ...

September 28, 2025