Egghead.page Logo

ZX Spectrum CPU and ULA Memory Contention Mechanism

The Sinclair ZX Spectrum utilized a shared memory architecture where the Z80 CPU and the Uncommitted Logic Array (ULA) competed for access to dynamic RAM. This article explains the specific timing mechanisms used to resolve this contention, detailing how the ULA prioritized video display generation over processor instructions during specific scanline periods, ultimately affecting the computer’s overall processing speed and graphical capabilities.

Shared Memory Architecture

At the heart of the ZX Spectrum design was a cost-saving measure that required both the central processor and the video hardware to access the same pool of dynamic random-access memory (DRAM). The Z80 CPU operated at a clock speed of 3.5 MHz, while the ULA was responsible for generating the video signal, reading keyboard inputs, and handling the cassette interface. Because there was only one data bus connected to the RAM chips, both components could not read or write data simultaneously. This necessitated an arbitration system to prevent data corruption and ensure the video display remained stable.

The Contention Window

Memory contention occurred because the ULA required constant access to memory to fetch pixel data for the television screen. The video signal was generated based on a standard 6.5 microsecond scanline. During each scanline, there was a specific period known as the contention window where the ULA demanded priority access to the memory bus. This window typically lasted for 207 clock cycles out of the total available cycles per scanline. When the ULA needed to fetch pixel attributes or bitmap data, it would effectively halt the Z80 CPU by asserting a wait state.

CPU Wait States and Performance Impact

When the ULA accessed memory, the Z80 CPU was forced into a wait state, freezing its operation until the bus was released. This meant that while the CPU was rated at 3.5 MHz, its effective speed was significantly lower during video generation periods. The CPU could only access memory freely during the horizontal and vertical blanking intervals or during the non-contended portion of the scanline. This architecture resulted in variable instruction execution times, where code running during the contention window took longer to execute than code running during the blanking intervals.

Design Trade-offs and Legacy

This method of handling memory contention was a deliberate engineering trade-off to keep the manufacturing cost low. By avoiding dedicated video RAM, Sinclair Research could produce an affordable home computer, but it came at the cost of consistent processing power. Developers had to account for these timing discrepancies when writing precise code, particularly for games requiring smooth scrolling or accurate sound generation. Despite these limitations, the contention mechanism allowed the ZX Spectrum to become one of the most successful computers of the 1980s, defining a generation of computing through its unique hardware constraints.