Egghead.page Logo

How Sinclair ZX Spectrum Keyboard Scanning Works

The Sinclair ZX Spectrum utilized a unique keyboard matrix system managed by its Uncommitted Logic Array (ULA) to detect key presses efficiently. This article explores the technical mechanics behind the scanning process, detailing how the Z80 CPU interacts with the hardware to register input without dedicated keyboard controller chips. Readers will gain insight into the row and column architecture that defined the typing experience on this iconic 8-bit computer.

Unlike modern computers that rely on dedicated microcontrollers to handle input, the ZX Spectrum integrated keyboard scanning directly into its core logic. The keyboard was arranged in a matrix consisting of five rows and eight columns, creating a grid where each key sat at a specific intersection. When a key was pressed, it physically connected a specific row line to a specific column line, completing an electrical circuit that the system could detect. This design minimized component count and cost, which was essential for the machine’s budget-friendly market positioning.

The scanning process was driven by the Z80 CPU in conjunction with the ULA. To read the keyboard, the CPU would output a specific value to the I/O ports, effectively selecting one of the five rows by pulling it low electrically. The ULA would then read the state of the eight column lines. If a key on the selected row was pressed, the corresponding column line would also read as low. By cycling through each of the five rows rapidly, the system could determine the state of every key on the board in a matter of milliseconds.

This scanning routine was handled by the computer’s ROM, specifically through a subroutine often referred to as KSCAN. The ROM routine ensured that key presses were registered consistently across different software applications without requiring developers to write their own hardware-level input code. The system typically scanned the keyboard during the vertical blanking interval or within the main execution loop to ensure responsiveness without interfering with video display generation.

However, this matrix design introduced a well-known limitation known as key ghosting or key clash. Because the keys were simple electrical contacts without diodes to isolate them, pressing certain combinations of three or more keys could create false connections within the matrix. This meant that some key combinations would not register correctly if pressed simultaneously, a constraint that particularly affected gaming controls where multiple inputs were often required at once. Despite this limitation, the scanning method remained a testament to the efficient hardware engineering that characterized the Sinclair ZX Spectrum era.