# Debug runs and media interoperability Design recorded on 20 November 2026. The first scripted-debug and persistent-media milestone is implemented; see [the user guide](debug-media.md) and [v1 contract](debug-contract-v1.md). The numerical/library and physical-address/BSS-SAP milestone is now implemented and validated within [its documented limits](word-machine-validation.md). Native safe points, watches, breakpoints, steps and inspection checkpoints now run in both interpreters. Rich interactive/graphical frontends remain future work. Both FORTRAN 704 and GW-BASIC 2026 need variable watches, steps, checkpoints, and appropriate card, tape or drum views. Graphical frontends should provide richer views; a TUI should provide compact text views. This is also useful for the proposed learning arcade. ## Organisation Keep the two repositories and their native execution/storage engines separate. Share a small versioned command/event specification and interoperability fixtures when the first implementations establish their contents. This document is the initial coordination point; do not create a third runtime/library now. The GW-BASIC handoff is [here](https://github.com/evvaletov/gw-basic-2026/blob/main/docs/fortran-debug-media-handoff.md). | Owner | Responsibilities | | --- | --- | | `fortran-704` | 704 word arithmetic, physical addresses, FORTRAN statements, SAP instructions, BCD, card decks, record tapes and word drums | | `gw-basic-2026` | BASIC variables and statements, strings, file numbers, sequential/random byte files and FIELD buffers; researched cassette support later | | Common contract | Command names, stop/checkpoint identifiers, capability negotiation, presentation conventions and explicit interchange fixtures | | Frontends | Read-only inspection, controls and views; no independent copy of execution or device semantics | The initial implementation is local to each runtime. A host-side graphical adapter or IDE debug adapter can consume the same inspection events later. The DOS monitor can call its runtime directly and need not run JSON, sockets, a daemon or a graphical toolkit. Extract shared code only after both projects have a tested need for the same component and compatible build requirements. ## Storage compatibility FORTRAN currently owns in-memory BCD/binary tape records, tape marks, rewind/backspace and addressed drum words, with dialect-specific boundaries. The inspected GW-BASIC tree has sequential/random byte-file support and a silent `MOTOR` stub; a cassette-image or drum backend was not found. Useful common work is inspection, mounting metadata, explicit data conversion and fixtures. A BASIC cassette is not a 704 reel tape. A BASIC random file is not an IBM drum. Preserve native media formats, word sizes, record boundaries, marks and encodings. Before designing a new image format, evaluate existing emulator formats against those requirements. The initial private F704M01 bundle is now selected and documented in the [user guide](debug-media.md), alongside the SIMH/P7B evaluation. It is not an emulator tape image; adapters remain separate work. Start interoperability with BCD text exported as explicitly encoded records and consumed by BASIC `LINE INPUT#`. Add typed numeric interchange only with specified precision, signed-zero/range policy, byte order and conversion tests. Do not reinterpret 704 floats as BASIC binary numeric values or silently flatten tape marks. Cassette binary/waveform formats require original-source evidence. ## Design background (v1 implementation linked above) Keep three independent capability axes: execution engine (FORTRAN AST, SAP, BASIC interpreter, compiled BASIC), frontend (line/TUI/graphical), and the program's own text/graphics mode. A graphical inspector does not change the program's screen mode or imply hardware timing. Proposed commands: `capabilities`, `break`, `continue`, `step`, `next`, `finish`, `watch`, `unwatch`, `inspect`, `checkpoint`, and `snapshot`. Advertise only implemented commands. `step` enters a call, `next` stops at the next statement in the current frame, and `finish` stops after that frame returns. Introduce these independently with tests; do not silently make them synonyms. * A **statement step** advances one executable statement. BASIC colon-separated statements need distinct locations; a FORTRAN continuation card is not a separate executable step. Locations include unit/frame, source line and label when present. A stop is before the next statement executes. * A **machine step** is one SAP/704 instruction, available only inside an implemented machine execution path. AST statements must not masquerade as machine instructions. AOT BASIC source stepping waits for source maps and instrumentation; `TRON` output alone is not a debugger. * A **breakpoint** pauses execution and does not save state. * A **checkpoint** is a named inspection barrier, usable interactively or in a scripted run. It can emit a deterministic digest and an inspection snapshot. * A **snapshot** is an immutable export for inspection/diffing. Initially it is not restorable. Any later `restore` capability needs complete execution frames, bindings, loops, flags, memory, media contents/cursors and pending I/O, plus matching program/dialect/runtime versions. Host files, console input, timers, RNG and other external effects need recording or an explicit refusal. Never imply reverse stepping or repeat external writes during replay. Watches initially accept variable names and constant-index array elements. They must not evaluate user functions, allocate variables, perform I/O, consume input, advance RNG/time, change overflow flags, seek a file or move a media head. Inspection errors are debugger diagnostics, not program exceptions. 704 displays include defined/uninitialised status and raw 12-digit octal words; integer, floating and BCD views are labelled interpretations. Physical aliases through COMMON, EQUIVALENCE and dummy arguments have a shared storage identity. Do not claim a host pointer is a 704 address. BASIC displays retain native type, array bounds and string bytes; FIELD views identify file, record-buffer offset and length. Honour each runtime's own initialisation rules; BASIC's defined defaults must not be labelled uninitialised. ## Views | State | TUI/line monitor | Graphical frontend | | --- | --- | --- | | Source/watches | Current statement, stack and compact value table | Source highlighting, pinned watches and change highlighting | | 704 cards | 80-column text, column ruler and card number | Card image and punch holes only with a verified encoding; distinguish source cards from binary object cards | | 704 tape | Unit, record/mark, cursor, mode, bounded word/BCD dump | Record strip, marks, position and decoded payload | | 704 drum | Unit, word address and bounded octal grid | Address map, selected/changed words and last transfer range | | BASIC files | File number/mode, position, record and FIELD slices | Record-buffer/field map and byte/string views | Views describe logical state. Drum rotation, tape speed and mechanical timing must not be presented as simulated facts. BASIC gets card/drum views only if a real, explicitly named extension later supplies those devices. Cassette views wait for an implemented backend. On DOS, preserve the program's text/graphics screen, using a saved page or separate monitor display as supported. ## Delivery status, 20 November 2026 Delivered items 1–3 below: both scripted monitors, basic native views, persistent FORTRAN media, the tested ASCII interchange pair, and the copied v1 command/event specification. DOS16/32 monitors use separate command/output files and pass execution/screen checks. Checkpoints contain the watch set and bounded native summaries. They do not capture all state. Native file buffers and FIELD mappings are inspected without changing BASIC's copy semantics. Graphical/interactive panes, next/finish, SAP instruction stepping and execution restoration remain unimplemented. Validation is recorded in [the implementation record](debug-media-validation.md). ## Original delivery order and acceptance 1. FORTRAN: add native safe-point/inspection hooks after physical addressing; implement a scripted line monitor with statement step/continue, breakpoints, pure watches, bounded media dumps and named inspection checkpoints. 2. GW-BASIC: implement equivalent interpreter hooks, with colon-statement locations and file/FIELD inspection. Keep compiled debugging explicitly unavailable until instrumentation/source maps exist. Validate DOS screen preservation and a bounded memory budget. 3. Persist FORTRAN tape/drum images; test restart, modes/marks, boundary wrap, host-independent packing, truncated/corrupt images and atomic loading. Establish a BCD-text interchange fixture read by BASIC. 4. Publish a local versioned event schema from those working implementations; add TUI polish and graphical card/media views over the same state. 5. Add restorable checkpoints only after complete state and external-effect handling are demonstrated. Reuse persistent media storage where appropriate. Acceptance requires normal/debug runs to have identical program output, final words, flags and media contents/positions. Repeated watches/dumps must leave those unchanged. Test calls, DO/FOR loops, aliases, unset FORTRAN cells, BASIC defaults, FIELD buffers, empty media, marks and address boundaries. Scripted stops/checkpoints must be reproducible. Debug traffic must not consume program input or contaminate printer/stdout streams. Capabilities and unsupported operations must be explicit in each engine/frontend combination. ## Design review The design was reviewed on 20 November 2026. Grok 4.7, Fable 5.2 and Gemini Argon each completed independent, self-contained storage and debugger passes. All selected native engines with a small shared contract. The runtimes stay separate. They differed on where shared documentation should live and what "checkpoint" should mean. The decisions here keep the first contract with its active implementer and separate inspectable checkpoints from future restoration.