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 60: Interrupt Vector Table Management (IM 2 Dynamic Handlers)

The Interrupt Vector Table (IVT) The Interrupt Vector Table (IVT) is a critical data structure used exclusively when the Z80 is operating in Interrupt Mode 2 (IM 2). It is a simple array of 16-bit addresses that tells the CPU exactly where to jump when a specific hardware device signals an interrupt. How the IVT Address is Calculated: Base Address: The OS sets the Interrupt Vector Register (I) to point to the base (high byte) of the IVT. Hardware Vector: The interrupting hardware places an 8-bit value (the low byte of the address) on the data bus. Final Address: The Z80 combines the I register (High Byte) with the Hardware Vector (Low Byte) to form the 16-bit address of the IVT entry. Jump: The CPU reads the 16-bit address stored at the IVT entry and jumps to the device’s specific Interrupt Service Routine (ISR). Structuring the IVT The IVT must be aligned to a 256-byte boundary (e.g., C000H′, D000H′) and consists of 128 consecutive 16-bit addresses (256 bytes). ...

September 27, 2025

Z80 Assembly 58: Interrupt-Driven Keyboard Handling

The Drawback of Main Loop Polling In simple programs, checking the keyboard (`IN′ instruction) is done within the main program loop. This is inefficient because the CPU spends valuable time polling the keyboard even when no key is pressed, slowing down the main application. The Solution: Timer-Driven Interrupts A robust operating system uses a fixed-rate timer interrupt (e.g., 50 or 60 times per second) to trigger the keyboard scan routine. This ensures the keyboard is checked reliably without interfering with the main application’s logic. ...

September 27, 2025

Z80 Assembly 48: Interrupt Prioritization and the Daisy Chain

The Challenge of Multiple Devices In a complex Z80 system, you might have several devices that need to interrupt the CPU (e.g., a timer, a keyboard controller, and a disk controller). If two devices signal an interrupt at the exact same time, the CPU needs a clear way to decide which one to service first. This is called priority resolution. The Daisy Chain Protocol The Z80 uses a hardware architecture called a Daisy Chain to resolve interrupt priority. ...

September 27, 2025

Z80 Assembly 41: Interrupt-Driven Serial Input (The Receiver)

The Challenge of Reliable Input In receiving serial data, the Z80 must wait for the exact moment the Start Bit arrives and then sample the input line precisely at the center of each of the next eight data bits. If the CPU misses the timing, the data is corrupted. The Solution: Interrupt-Driven Sampling The CPU cannot wait in a tight timing loop for data to arrive. Instead, we use a timer interrupt to tell the CPU exactly when to check the input line. ...

September 27, 2025

Z80 Assembly 10: Interrupt Modes and Handling External Events

What is an Interrupt? An interrupt is an external signal from a hardware device (like a timer or keyboard controller) that tells the CPU to immediately stop what it’s doing and execute a specific routine to handle the event. This is how the system maintains responsiveness. The Two Key Commands: Instruction Action Purpose EI Enable Interrupts Allows the CPU to listen for and respond to external interrupt requests. DI Disable Interrupts Prevents the CPU from responding to external requests (used for critical code sections). The routine that handles the interrupt must end with RETI (Return from Interrupt) or RETN (Return from Non-Maskable Interrupt) instead of a simple RET. ...

September 27, 2025

Z80 Assembly 09: BCD Arithmetic and the RST (Restart) Interrupts

BCD Arithmetic: The DAA Instruction Binary-Coded Decimal (BCD) is a way to store numbers where each byte holds two decimal digits (0-9). This is vital for financial or numerical applications where decimal accuracy is required, as standard binary math can introduce rounding errors when converting to decimal. The Problem: If you add 9 and 1 in binary, the result is 10 (0A Hex). In BCD, the result should be 10 (10 Hex). ...

September 27, 2025