Egghead.page Logo

Sinclair ZX Spectrum Vertical Blank Interrupt Handling

This article explores the technical mechanism behind vertical synchronization on the Sinclair ZX Spectrum. It details how the Uncommitted Logic Array triggers CPU interrupts, the default Interrupt Mode 1 configuration, and how developers utilized these frame-based signals for game logic and timing without dedicated hardware support.

The Sinclair ZX Spectrum relies on a partnership between the Z80 CPU and the custom Uncommitted Logic Array (ULA) to manage video timing. Unlike modern systems with dedicated graphics processors, the Spectrum generates video signals directly through the ULA, which also manages memory contention. The vertical blank interrupt is not a separate software event but is physically generated by the ULA at the start of every video frame. This signal is sent to the Z80’s interrupt pin, ensuring the processor is synchronized with the television’s refresh rate, typically 50Hz for PAL regions and 60Hz for NTSC units.

By default, the Spectrum’s ROM configures the Z80 CPU into Interrupt Mode 1 (IM 1). In this mode, when the ULA triggers an interrupt, the CPU automatically jumps to the fixed memory address 0x0038. This address contains a jump instruction to the actual Interrupt Service Routine (ISR) located elsewhere in the memory. This design simplifies hardware requirements but offers less flexibility than Interrupt Mode 2, which allows for a vector table. Consequently, all frame-based processing, including keyboard scanning, music playback, and game logic updates, typically occurs within this single ISR entry point.

Developers faced significant challenges because the interrupt marks the start of the frame rather than providing a specific window for rendering. There was no hardware sprite engine or dedicated vertical blanking memory buffer. To achieve smooth animation, programmers had to ensure their game logic completed within the 20 milliseconds available between interrupts. Advanced coders utilized precise timing loops within the interrupt routine to manipulate the border color or change display attributes mid-frame, creating raster effects that mimicked hardware features found in competing machines like the Commodore 64.

Ultimately, the ZX Spectrum’s handling of vertical blank interrupts was a testament to efficient software engineering over hardware complexity. The system leveraged the mandatory frame interrupt to maintain system stability and timing consistency. While the lack of advanced interrupt vectors limited some graphical capabilities, the straightforward IM 1 implementation allowed hobbyists and professionals alike to create complex games by mastering the precise timing of the Z80 CPU against the steady pulse of the ULA.