zxdream¶
A ZX81-BASIC interpreter in C99 with a 32x24 character screen and swappable UI backends.
Quick start¶
make test # unit tests, ASan/UBSan clean
# TTY backend — plain text terminal or pipe
make ui=tty
./bin/zxdream-tty examples/house.bas
# NCURSES backend — full-screen terminal UI
make ui=ncurses
./bin/zxdream-ncurses examples/house.bas
# SDL3 backend — graphical window (X11/Wayland/KMSDRM)
make ui=sdl3
./bin/zxdream-sdl3 examples/house.bas
The raw backend (teletype mode, PRINT straight to stdout) builds as
bin/zxdream-raw via make backends; see SPEC.md section 9.
Status¶
- M1 complete: full ZX81 BASIC per the BNF grammar (33 statements). 173/173 Unity unit tests, ASan/UBSan clean, PTY key tests pass (verified 2026-12-01). Corpus contract (retrocomputing runner): 179/179 against ROM-truth expectations, oracle-verified via ZEsarUX on 2026-11-30 — triage fixed 15 stale ASCII-era expectations and two real zxdream bugs (RND now uses the ROM LCG, undefined variables report 2 instead of reading as 0).
- Hardware-near memory:
PEEK/POKEwork on the sysvar window ($4009–$407C), RAMTOP (16388/16389, stored without side effects) and the FRAMES cells (16436/16437, the counter continues from the poked value);RAND nstores its seed in the SEED cell; the display file (fromD_FILE, 24 × 33 bytes) is a live translator between ZX81 display codes and the screen —PRINT,PEEKandPOKEall see the same screen, so byte-wise screen walkers like DOOLHOF or ZOMAARWA run. Program-area/VARS access is deliberately not implemented. See "Support for SYSVARS" below. - UI backends:
tty(pipe + terminal),sdl3(X11/Wayland/KMSDRM),ncurses,raw(teletype: streams PRINT output straight to stdout, no screen size/border/centering — AT/PLOT/CLS/SCROLL are null functions; see SPEC.md section 9). FAST/SLOW timing is implemented (SLOW runs at the calibrated ZX81 tempo, ~22 stmt/s; commits4691461,8663a34). SAVE/LOAD and the editor (embedding zxedit as a library) are still pending.
Support for SYSVARS¶
A loaded .P image carries the 116-byte system-variable window
$4009–$407C. zxdream maps PEEK/POKE onto it; the window
survives CLEAR and NEW (on the real ZX81 these keep the sysvars).
Programs fed as .bas text have no sysvar block — PEEK/POKE
report "not supported" there.
Read-only cells (pointers into the image — poking them would
separate the interpreter from its own data structures; VERSN is the
identity byte):
| Addr | Name | Meaning |
|---|---|---|
| $4009 | VERSN | ROM version (0) |
| $400C | D_FILE | start of display file |
| $400E | DF_CC | display-file cursor |
| $4010 | VARS | start of variables |
| $4012 | DEST | assignment destination |
| $4014 | E_LINE | edit line; defines the file end |
| $4016 | CH_ADD | character address |
| $4018 | X_PTR | syntax-marker address |
| $401A | STKBOT | calculator stack bottom |
| $401C | STKEND | calculator stack end |
| $401F | MEM | calculator memory pointer |
| $4029 | NXTLIN | next program line to run |
| $4030 | T_ADDR | syntax-table address |
Writable content cells:
| Addr | Name | Meaning |
|---|---|---|
| $400A | E_PPC | line being edited |
| $401E | BREG | calculator B register |
| $4021 | (unused) | — |
| $4022 | DF_SZ | lower screen lines |
| $4023 | S_TOP | top line for auto-listings |
| $4025 | LAST_K | last key pressed |
| $4027 | DEBOUNCE | key debounce |
| $4028 | MARGIN | border lines − 1 |
| $402B | OLDPPC | line CONT jumps to |
| $402D | FLAGX | command flags |
| $402E | STRLEN | string-assignment length |
| $4036 | COORDS | last PLOT position (x, y) |
| $4038 | PR_CC | printer buffer position |
| $4039 | S_POSN | PRINT position (column, line) |
| $403B | CDFLAG | display mode flags (bit 6 = SLOW) |
| $403C | PRBUFF | printer buffer (33 bytes) |
| $405D | MEMBOT | calculator memory cells |
| $407B | (unused) | — |
Live and special cells:
- FRAMES ($4034/$4035, 16436/16437) — the 16-bit frame counter,
ticking at 50 Hz.
PEEK 16436+PEEK 16437*256works like on the real machine. POKEs are accepted and the counter continues from the poked value. - SEED ($4032/$4033, 16434/16435) —
RAND nstores its seed here (verified against ZEsarUX:RAND 17408→PEEK 16434=0,PEEK 16435=68), so programs can copy it.
Below the window — RAMTOP ($4004/$4005, 16388/16389): peekable and pokable. Stored values have no effect on execution (by design). Defaults, verified against a fresh ZEsarUX boot: 32768 ($8000) with a 16K RAM pack, 17408 ($4400) with 1K internal RAM — the first byte above the BASIC RAM area.
The display file (screen area) — live translator: the region from
D_FILE ($400C) over 24 rows × 33 bytes (expanded layout: 32 display
codes + 0x76 per row) is a bidirectional translator between ZX81
display codes and the Unicode screen model. PEEK reads the current
screen as display codes (inverse cells carry bit 7, row ends are
0x76); POKE writes through to the screen (text, inverse text,
block graphics; 0x76/row-end pokes are accepted without visible
effect). The archive programs that walk the screen byte-wise
(DOOLHOF, ZOMAARWA, CRASH-, BOMBER-, …) use exactly this
33-byte stride.
Out of scope — the program area: PEEK/POKE into the program
bytes and VARS (e.g. 16513+, 16514, computed addresses into the
listing) is deliberately not implemented (Martin, 2026-12-01). Such
programs still abort with a PEEK/POKE error.
Not supported¶
Consciously excluded:
- Program-area and VARS access.
PEEK/POKEinto the listing bytes and the variables area is not implemented (see above); nine difftest programs (3D-TICTA, COMPUT, COMPUTER, CRASH-, DAMMEN, DAMMEN-2, DENKSPEL, SKETCHPA, WERELDHA) still abort there. - A full Z80 memory model. zxdream interprets BASIC, it does not
emulate the machine: no ROM image, no CPU stack, no machine-code
execution —
USR(addr)reports "not supported".PEEK/POKEbelow$4009(beyond RAMTOP) and inside the ROM area fail like any address outside the windows above. - READ / DATA / RESTORE. Correctly absent — the ZX81 does not have them (no such tokens exist in the ROM).
Approximations (work, but not byte-exact):
- FRAMES is wall-clock based (50 Hz ticks), not cycle-accurate; SLOW mode runs at the calibrated ZX81 tempo (~22 stmt/s), FAST at full speed.
- Display-file POKEs of token-range bytes (0x40–0x7F) store an inverse space — the closest cell the screen model can represent; no archive program uses them.
- Half-dither graphics codes (0x08–0x0A) share one glyph — the documented lossy mapping from pfile2bas FORMAT.md §5.
- The display file covers the 24 main screen rows only; the lower (input) screen area is not mapped.
.bastext input has no sysvar block —PEEK/POKEreport "not supported" there (load a.Pimage to get a live window).
Pending (planned, not excluded):
- SAVE/LOAD and the editor inside zxdream — waiting on the zxedit embedding as a library (the byte-stable saver already exists in zxedit).
- Seven archive RAM-dump exotics still fail to load (MUNCHER, YAHTZEE, HEXLOADE, LA-PULGA, PIT, TEKSTEDI, EEUWKALE) — their sysvar/layout conventions differ structurally.
- The ten difftest "Variable not found" aborts are not a gap — they are oracle-verified ROM behaviour (the same programs stop with report 2 on a real ZX81).
Native Linux console¶
To run zxdream-sdl3 (or zxdream-tty) directly on a framebuffer
console without X/Wayland:
SDL_VIDEODRIVER=kmsdrm ./bin/zxdream-sdl3 examples/house.bas
Requirements:
- Group membership in
video(DRM master) andrender(GPU buffers); addinputas well, or SDL cannot open the keyboard and keys will silently not work. Apply withsudo usermod -aG video,render,input $USERand log in again. XDG_RUNTIME_DIRmust point at the session's runtime dir (/run/user/$(id -u)). A normal local console login sets this via systemd; if you SSH'd orsu'd in, export it by hand.- Keyboard and mouse need
inputgroup access; without it SDL printsCouldn't open /dev/input/event*: Permission deniedand input is dead. - For the authentic ZX81 look, load a generated PSF2 console font (24 rows of 5x-scaled 8x8 cells plus border on a 1920x1080 console):
make fonts
sudo cp fonts/zxdream-40x40.psf /usr/share/consolefonts/
setfont zxdream-40x40
F11 toggles fullscreen; ESC breaks a running program (and closes the
window afterwards), Ctrl+C does the same via a graceful shutdown that
restores the text console.
Docs¶
SPEC.md— the binding specificationdocs/ARCHITECTURE.md— how the pieces fitdocs/zx81-basic-ebnf.md— the grammardocs/charset.md— character repertoire and block graphicsdocs/learning-basic.md— a beginner's textbook
Website & Download¶
- Website: https://zxdream.retro-dev.de/
- Download:
zxdream-2026-12-03.zip(Versionsnummer = Release-Datum) - Release Notes: https://zxdream.retro-dev.de/releasenotes/