Skip to content

40 Best Machine Code Routines for the ZX Spectrum

John Hardman and Andrew Hewson’s collection of working parts

The 1982 book pairs an introduction to Spectrum machine code with forty routines for display and program manipulation. Its co-authors explain callable components rather than presenting a complete game.

John Hardman and Andrew Hewson’s 40 Best Machine Code Routines for the ZX Spectrum offers a set of parts a BASIC programmer can call and adapt. Published by Hewson Consultants in 1982, it first explains the processor and the machine, then supplies routines for work such as scrolling, character manipulation and editing stored programs.

The co-authorship matters. The original cover and title pages name both Hardman and Hewson. Its connection with Andrew Hewson and the later Hewson publishing company should not erase Hardman from the book’s credit.

The original wraparound cover names John Hardman and Andrew Hewson and lists the kinds of routines inside
The original cover promises routines with explanatory text and names both authors. Its examples include scrolling and program-text manipulation. Cover copyright Hewson Consultants, 1982; artist not identified in the consulted copy. Reproduced at low resolution for discussion of this book.

Learn enough to use the parts

Section A introduces machine code and the Spectrum’s internal organisation. Registers, the stack, memory and the display supply the context needed to understand the routines in Section B. The reader is expected to connect an operation to the bytes and addresses it uses.

That makes the book a bridge in the move from BASIC to machine code. A programmer can keep the main program in BASIC while giving a demanding operation to a machine-code routine. It is not necessary to begin by writing an entire game in assembly language.

A routine has an interface

The collection includes scrolling by pixels or characters, rotating and inverting characters, searching strings and renumbering program lines. These operations touch different representations. Moving the picture’s bits is not the same job as updating a game’s map; editing tokenised BASIC is not the same as editing a plain text file.

The surrounding explanations and memory discussion therefore matter as much as the byte listings. A routine needs the expected inputs, working area and return arrangement. Reusing a scratch area already occupied by another part of a program can break both, even when each routine works in isolation. (Original contents and memory sections.)

A Spectrum book, with a specific machine underneath

The Z80 instructions are one layer. Spectrum display memory and ROM conventions are another. A routine can rely on both, so recognising the CPU in another computer does not make the whole routine portable.

The title also needs its complete ending: there is separate Commodore 64 material with a similar name. This entry concerns the ZX Spectrum book. Its value is the combination of a documented machine, reusable operations and enough explanation to understand their limits.

Sources

  • John Hardman and Andrew Hewson, 40 Best Machine Code Routines for the ZX Spectrum, Hewson Consultants, first edition 1982, ISBN 0-907912-03-6: original cover, title pages, contents and text. This entry’s bibliographic and content claims rest on the book itself; the title’s “best” is not adopted as an independent ranking.

Checked. Verified against primary sources and signed off by a person.