Skip to content

HALT2INT

Manuel Sainz de Baranda y Goñi edited this page Nov 28, 2026 · 28 revisions

Platform: ZX Spectrum
Author: Woodmass, Mark
License: GPLv2

Version Release date Links Download
v3 2022-01-04 Discord post zip (hosted) - zip (Discord post)
v2 2021-10-23 Discord post zip (hosted) - zip (Discord post)
v2 2021-09-26 Discord post zip (hosted) - zip (Discord post)
v1 2021-09-21 Discord post zip (hosted) - zip (original URL)
v1-pre 2021-09-21 Discord post zip (hosted) - zip (Discord post)
beta.2 2021-09-20 Discord post tap (hosted) - zip (Discord post)
beta.1 2021-09-20 Discord post zip (hosted) - zip (Discord post)
beta 2021-09-19 Discord post tap (hosted) - zip (Discord post)
alpha 2021-09-19 Discord post tap (hosted) - zip (Discord post)

Description

HALT2INT tests whether an emulator implements the halt instruction and the HALT state correctly. It was written to demonstrate, on real hardware, that Tony Brewer's description of HALT in his article on the special reset is accurate: after halt the program counter has already been incremented, so the CPU repeatedly reads the opcode that follows this instruction and, when an interrupt is accepted, the incremented PC is pushed onto the stack unchanged.

The test uses memory contention as a probe to reveal which opcode is actually fetched during the HALT state. The ZX Spectrum's ULA pauses the CPU while it reads contended memory during screen drawing, and each pause reduces the number of R-register increments. If halt simply decremented the program counter so that it re-executed itself, as was long believed, then a halt in contended memory would be stalled on every HALT cycle and R would advance far fewer times than a halt in uncontended memory. Since Brewer's description is correct, the CPU instead fetches the opcode after halt, so the contention follows that following address. The program places halt at addresses that straddle the contended and uncontended areas (16384, 32767, 32768, 49151, 49152 and 65535) and counts the R increments; the exact number of contended fetches shows which address is being read.

To carry this out it synchronizes to the frame start, sets R so that it is zero when the halt is reached, executes the halt at a precise point in the frame, and reads R after the interrupt. Repeating this at several points in the frame (12000, 14335, 14336, 14335+227 and 57239) also exposes the contended-memory (ULA) timings and distinguishes the "early" (first contended cycle T-state 14335) and "late" (14336) ZX Spectrum 48K ULA variants. A separate build covers the 128K and +2 machines.

Expected results

ZX Spectrum 48K

From v2 to v3 From beta.2 to v1
Early timings

Late timings

Early timings

Late timings

beta.1 beta
Early timings

Late timings

Early timings

Late timings

alpha

Results on real hardware

v3: SGS Z8400AB1 / ZX Spectrum 48K (Issue 6A, ULA 6C001E-7)

Tested by Matthew London

The machine was pre-cooled. The test is shown at the end of the video. It was used to confirm that BBG was run with late timings.

https://www.youtube.com/watch?v=b5GoVUWfksE

v3: ZX Spectrum +2 (ES)

Tested by Víctor Iborra

img

Tested by Víctor Iborra

img

Clone this wiki locally