Skip to content

zxedit

A fullscreen, token-level editor for ZX81 BASIC programs stored as native .P files. It runs in the terminal (raw termios, no ncurses) and edits the programs the way the ZX81 ROM does — on the token bytes themselves, never on a de-tokenized text form. Keywords are entered like on the original machine (a committed keyword becomes one byte), but driven from a normal PC keyboard with a commit-on-unique matcher: a keyword is committed as soon as its letter prefix is unique (PRINT at PR, LIST at LI), remaining letters are absorbed, so every keyword stays typable despite prefix overlaps.

Features

  • Load, edit and save .P files; the byte format is treated with the same tolerance as the ZX81 ROM: anything ZEsarUX lists, zxedit loads (verified against a corpus of 832 real-world files).
  • ROM-faithful editing model, adapted to a PC keyboard:
  • four cursor modes (K, L, C, F) with mode colors,
  • token-wise editing in statement context, digit-wise editing inside numbers (the FP memo is re-derived live, like the ROM), byte-wise editing inside strings, REM bodies and variable names,
  • Ctrl+E = the ROM EDIT key: copies the selected line into the edit row with the cursor right after the line number (verified against the ZEsarUX emulator),
  • committing a line with a new line number inserts it sorted and keeps the old one — the renumbering flow described in the ZX81 literature.
  • Line commit is syntax-checked (Enter shows an English error message in the status line instead of committing).
  • Two keyword profiles: ROM (strict ZX81 set) and ZXDREAM (ROM plus FRAMES), switchable at runtime.

Prerequisites

  • A C compiler (C17) and GNU make; the Unity test framework is vendored in vendor/.
  • Python 3 for make test-pty (the terminal interaction test).

Build & install

make            # builds the test suite, runs it, builds bin/zxedit
make install    # root: /usr/local/bin, user: ~/.local/bin (PREFIX overridable)
make uninstall

Useful targets: make test (unit tests, ASan/UBSan), make test-pty (terminal interaction test driven over a PTY), make clean.

Usage

zxedit FILE.P

Start with the path of a .P file. If the file does not exist yet, it is created on the first explicit save (Ctrl+S). Changes are only written to disk on Ctrl+S — quitting with unsaved changes asks for confirmation.

Screen layout

The top area lists the program (sorted by line number, keywords in inverse video, strings quoted, numbers as digits). The > marker on a listing line is the selected line. Below the listing is the edit row: the selected line appears here as a preview; editing happens in this row. The bottom line is the status row: file name, line count, keyword profile, cursor mode, and save state; while an edit fails to commit, it shows the error message instead.

Cursor modes and colors

The cursor highlights the character at the cursor position with the color of the current mode; the same color is shown on the mode letter in the status line.

Mode Meaning Color
K statement start — a typed letter starts a keyword salmon
L literal context — inside strings, REM bodies, variable names soft green
C operand position after a statement keyword soft blue
F directly after a function keyword mauve

The cursor highlights the character at the cursor position (block-cursor semantics: Backspace deletes left of and Delete under the highlighted character; at the line end the last character is highlighted).

The edit row sits on a light gray strip that spans the terminal width; the listing and the edit row use a pastel syntax highlight palette (keywords soft blue, functions soft teal, numbers soft amber, strings soft green, REM bodies gray). The status line spans the full terminal width. Resizing the terminal repaints at the new size at once — also in the middle of an edit; the edit state survives.

In browse mode (the edit row is only a preview) the status line shows b without a color. Keyword entry is active in K; in the other modes letters are literal, and Ctrl+F toggles function mode (the ROM SHIFT+ENTER equivalent) so functions and operand words (AND OR NOT TO STEP THEN AT TAB) can be spelled out.

Key commands

Key Action
Up / Down move the > selection; the selected line is copied into the edit row as a preview
Left / Right enter edit mode for the selected line and move the cursor
Enter enter edit mode for the selected line
typing starts a new line (first digits become its line number, space commits the number)

Editing (edit row)

The cursor moves with the granularity of its context: token boundaries in statement context, digit-wise inside numbers, byte-wise inside strings, REM bodies and variable names. Typing always inserts at the cursor.

Key Action
Left / Right move the cursor (context granularity, never into a number's invisible memo)
Backspace delete left: one character in strings/REM/names, one digit in numbers, a whole token in statement context
Delete delete forward (mirror of Backspace)
letters / digits / punctuation insert at the cursor; keywords commit on unique prefix in K mode
Ctrl+F toggle function mode (spell out functions and operand words)
Ctrl+E ROM EDIT: re-copy the selected line, cursor right after the line number
Esc discard the edit, restore the committed line
Enter commit the line: same number replaces it, a new number inserts sorted (old line stays), a bare line number deletes the line

Program and session

Key Action
Ctrl+N start a new line (line number chosen between the neighbors)
Ctrl+D delete the selected program line
Ctrl+S save the program to the .P file
Ctrl+P switch keyword profile (ROM / ZXDREAM)
Ctrl+Q quit; with unsaved changes, press twice to confirm

Notes on the .P format

zxedit saves what the ZX81 ROM saves: the sysvar block from VERSN on, the token-byte program lines (line numbers big-endian, body lengths little-endian, bodies terminated by 0x76), the display-file area, the variables area and whatever bytes follow. Numbers are stored as digits plus the 5-byte floating-point form after 0x7E, re-derived live while editing. Files with damaged pointers or missing line terminators load (the ROM validates nothing either) and are silently repaired on save.

Development

The code is split into a UI-free core library (src/core/: file I/O, keyword matcher, cursor state machine, line commit, display decoding) and a thin terminal frontend (src/ui/, src/zxedit_tui.c), so other frontends can embed the core. Tests live in tests/ (Unity-based unit tests plus a PTY-driven interaction test); SPEC.md documents the accepted blackbox behavior.

License

MIT — see https://opensource.org/license/mit.

Contact

devel ät datenbrei.de

Download & Release Notes