24 Commits
Author SHA1 Message Date
Stefan ArentzandClaude Opus 4.8 743f1f2d08 ROM catalog R4b: configs name the socketed character/video ROM by SKU (#342)
Add `machine.character_rom` — the socketed character (][) / video (//e) ROM,
a `builtin:<SKU>` catalog key. Unlike the system ROMs (R4a, which feed the
builders), the character ROM feeds the renderer: the frontend resolves the
config's character_rom and calls Scr::set_character_rom(rom, model), which
re-decodes the model's glyph set from that ROM — Chr::from_rom for the ][,
ChrE::from_rom(_, mousetext) for the //e — instead of the catalog default.

- config.rs: `Machine.character_rom: Option<String>` + validation (resolves).
- chr.rs: Chr::from_rom (new decodes from it); ChrE::from_rom made pub.
- scr.rs: Scr::set_character_rom rebuilds the model's set.
- two.rs: Options.character_rom + the config<->options mappings; the frontend
  (both the SDL and headless/RFB Scr sites) applies it via apply_character_rom.
- The four configs/apple2*.json carry character_rom (341-0036; the //e's
  342-0133-A / 342-0265-A); --print-config shows it.

Gate: set_character_rom_decodes_from_the_given_rom — re-applying a model's
default video ROM is byte-identical, and a swapped ROM re-decodes the glyphs
(the Enhanced-vs-original MouseText slot moves). Golden-BMP screenshots stay
byte-identical; schema regenerated. fmt/clippy clean; full suite green.

This completes the rom-catalog plan (R1-R4).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 19:59:12 -04:00
Stefan ArentzandClaude Opus 4.8 ace8d75da9 ROM catalog R4a: configs name the socketed motherboard system ROMs by SKU (#341)
Add a `machine.rom` array so each Apple II config lists its socketed
motherboard system-ROM chips by SKU — `{ "address": "0xd000", "path":
"builtin:341-0011" }` for the $D000-$FFFF chips (][ / ][+) or the two 8 KB //e
halves ($C000 CD, $E000 EF). This is the swappable-ROM part the owner asked
for; the language card's $D000-$FFFF is RAM (not a ROM) and is not listed, so
no "language card ROM" appears.

- config.rs: `RomChip { address, path }` + `Machine.rom` + per-chip validation
  (address parses, builtin: SKU resolves); the schema regenerates.
- two.rs: the builders receive the ROM. `new_with_slots_and_rom` takes the
  resolved `(address, bytes)` chips; `new_2plus` gets the assembled
  $D000-$FFFF image, `new_apple2` places each chip, `new_2e` the CD/EF halves.
  `new_with_slots` stays a 4-arg convenience that passes
  `default_rom_chips(model)`, so the ~15 existing callers and `Two::new` are
  unchanged and a bare `ewm two` == its builtin config. `build_machine`
  resolves the config's `machine.rom` (or the default). `IouE::internal_rom`
  became owned (was `&'static`) so the //e CD half can come from a config.
- The four configs/apple2*.json carry the rom array; --print-config shows the
  SKUs.

Gate: builtin_configs_build_the_default_system_rom proves each config's
explicit machine.rom builds a byte-identical $D000-$FFFF to its default
fallback; the golden-BMP screenshots (default path) stay byte-identical;
schema_matches_committed + readme_examples_parse pass. fmt/clippy clean; full
suite green.

R4b (the character/video ROM -> the renderer) is the remaining piece.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 19:47:39 -04:00
Stefan ArentzandClaude Opus 4.8 d3fa82493b ROM catalog R3: the builtin: resolver reads the catalog (any SKU mountable) (#339)
Fold the four SKU-less ROMs (WozMon, apple1-basic, Krusader-1.3-6502/65C02)
into ROM_CATALOG and delete config.rs's separate ROM_BUILTINS table.
rom_builtin now resolves against the catalog, so a memory region can name
`"path": "builtin:342-0304-A"` — any catalog key, a SKU or a product slug —
and the existing slug names keep working. The error message lists the catalog
keys.

Refresh the memory-region `path` schema description to advertise the SKU form
and regenerate both JSON schemas (EWM_UPDATE_SCHEMA=1 schema_matches_committed).

Gate: rom_builtins_resolve_and_list (the slugs resolve, builtin:342-0304-A
resolves, an unknown lists the keys); schema_matches_committed;
readme_examples_parse; the apple1/replica1 builtin configs still boot.
Verified: fmt/clippy clean; full suite green including the golden-BMP
screenshots.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 18:44:03 -04:00
Stefan ArentzandClaude Opus 4.8 bc7cda0d2a Mouse plan M2: the mouse card substrate (polled) (#326)
Phase M2 of plans/20260721-01: a working AppleMouse II card when polled —
config, the device, the firmware, and the machine wiring. No interrupts yet
(Phase M4) and no host input yet (Phase M3); a program that calls the entry
points and reads the screen holes sees a real mouse.

- `ewm/src/mouse.rs`: `mouse_rom(slot)` — synthetic 256-byte firmware
  implementing the eight documented entry points (found via the $Cn12 offset
  table), moving bytes between the caller's screen holes and the card's
  DEVSEL ports; and `Mou`, the `Device` + `Persist` holding position, per-axis
  clamp, button (now + last), the moved flag, mode, and the read stream. The
  DEVSEL protocol is ours (only our firmware touches it) — documented in the
  module header. Identification: Pascal 1.1 ($Cn05=$38/$Cn07=$18/$Cn0B=$01/
  $Cn0C=$20) + AppleMouse ($CnFB=$D6), with $Cn01≠$20 so the Autostart scan
  skips it.
- Config: `SlotCard::Mouse` ("mouse"), any slot 1–7 (slot 0 already rejects
  it), both families, at most one; no files, nothing to resolve. Schemas
  regenerated.
- Machine: `SlotDevice::Mouse` wired into new_2plus / new_apple2 / new_2e
  (DEVSEL device + $Cn00 firmware ROM); build_machine maps the card; `Two`
  holds the handle for M3/M4.

Gates: the golden `mouse_rom(4)` byte test + a moved-slot operand test; the
device driven directly over its ports (Init→Clamp→Pos→Read, clamping); and
`two_mouse.rs` — a ][+ with a slot-4 mouse runs real 6502 through the
firmware entry points and the clamped result lands in the screen holes.
cargo fmt / clippy -D warnings / cargo test (377 pass, golden-BMP intact —
no mouse in those configs).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 01:04:22 -04:00
Stefan ArentzandClaude Opus 4.8 f246e72fd5 Add the original (unenhanced) //e machine (//e original-plan E3) (#320)
* Rename the Enhanced //e identifiers (E3 prep)

Mechanical prep for the original //e: the Rust variants that name the
Enhanced machine become `TwoType::Apple2EEnhanced` / `Model::TwoEEnhanced`,
freeing the plain `Apple2E` / `TwoE` for the original //e that the next
commit adds. Kickoff decision (owner): the plain name is the *original*
machine, matching `Two` = original ][ and the config tokens (apple2e =
original, apple2enhanced = Enhanced).

Word-boundary-guarded rename across ewm/src + ewm/tests (86 Apple2E, 11
TwoE). No behavior change: the serde tokens are untouched (Model::TwoEEnhanced
keeps rename = "apple2enhanced"), so the schema is byte-unchanged, and the
golden-BMP //e screenshots are identical. cargo test 361 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Add the original (unenhanced) //e machine (//e original-plan E3)

`model: apple2e` is now a real machine: a 6502 //e with the unenhanced
342-0134/0135 system ROMs and the 342-0133 video ROM, alongside the
Enhanced //e (65C02, 342-0303/0304, MouseText). Kickoff naming (owner):
`Model::TwoE` / `TwoType::Apple2E` = the original (the plain name), the
Enhanced kept the `*Enhanced` names from the prep commit.

- config: `Model::TwoE` (token `apple2e`) joins the enum; family / token /
  two_type / the aux + slot-0 //e validation all cover both //e models.
- two.rs: `TwoType::Apple2E` + `TwoType::is_iie()`; `new_2e` takes the
  variant and selects (6502, unenhanced ROMs) or (65C02, Enhanced ROMs);
  `IouE::new` takes the CD/EF halves. The `Persist` INFO string and
  `--print-config` mapping gain the `apple2e` arm. Schemas regenerated.
- rendering: `Scr` holds both //e glyph sets and picks by variant; the
  five `== Apple2E` //e-detection sites become `is_iie()` (the original
  and Enhanced //e render identically apart from the character ROM).

The one real subtlety — the original //e is NOT a plain ROM swap. Its
video ROM stores plain upper case at `$40-$5F`, but the original //e
*displays* inverse upper case there (the glyphs Apple later replaced with
MouseText). So `alternate_index` gains a `mousetext` flag: the Enhanced
set reads MouseText straight from ROM, the original inverts the upper-case
glyph — the same steady inverse glyph the primary set flashes.
(`render_txt_row_80` also dropped its redundant `line_offset` arg, derived
from `row`, to stay under clippy's argument limit.)

Gates (all green): the Enhanced //e is byte-identical — the golden-BMP
screenshots don't move; a golden pins the composed original-//e $E000-$FFFF
to the unenhanced EF half (and different from the Enhanced); the bare
original //e cold-boots to `]` on the 6502; and a char test proves the
alternate $40-$5F is inverse upper case, distinct from Enhanced MouseText.
cargo fmt / clippy -D warnings / cargo test (364 pass).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 23:43:01 -04:00
Stefan ArentzandClaude Opus 4.8 869ba8175e Rename builtin:apple2e -> apple2enhanced (//e original-plan E1) (#316)
Our `apple2e` was really the Enhanced //e (65C02 + 342-0303/0304 system
ROMs + the 342-0265 MouseText video ROM). Rename the config-level token
to the honest `apple2enhanced`, freeing `apple2e` for the true original
(unenhanced) //e that E2-E4 add. Mechanical, mirroring the
`2plus`->`apple2plus` rename (#308); no ROM or machine changes.

What moved (the config surface only):
- `config::Model` serde token + `Model::token()`; `git mv
  configs/apple2e.json -> apple2enhanced.json` with model updated and
  title made honest ("Apple //e" -> "Enhanced Apple //e", reserving
  "Apple //e" for E4's original). BUILTINS re-sorts in place (apple2enhanced
  sorts before apple2plus, so no manual reorder).
- The `Persist` INFO model string mirrors the token by design
  (apple2/apple2plus/...), so it renames too, keeping save-states
  self-describing as `apple2enhanced`.
- Every `"apple2e"` config-token literal in tests/error strings; usage
  and `--config` help text; README, notes/JSON_CONFIG.md, notes/MAC_APP.md,
  examples/myiie.json. Both JSON schemas regenerated from source
  (EWM_UPDATE_SCHEMA=1), not hand-edited.
- `builtin:list` column widened 12->16 so the longer name still aligns.

Deliberately NOT touched (internal, renamed later by E3): the Rust
identifiers `TwoType::Apple2E` / `Model::TwoE`, the `two_e_*` test files,
and their "apple2e must construct" panic strings — they name the type,
which stays until E3 splits the two machines.

Verified: cargo fmt --all --check, cargo clippy --all-targets -D warnings,
and cargo test (359 pass, incl. the golden-BMP screenshots and
readme_examples_parse). Gate: `builtin:list` shows apple2enhanced; the old
`builtin:apple2e` errors "no built-in config ... (available: apple1,
apple2, apple2enhanced, apple2plus, replica1)".

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 22:58:41 -04:00
Stefan ArentzandClaude Fable 5 2a36ca634f Window title from the config: EWM, or EWM - <title> (#312)
The window bar was picked by matching options.model, so an apple2
machine fell into the ][+ arm and showed "Apple ][+". Replace it with a
config-driven title: a new top-level `title` field, window reads
"EWM - <title>" when set and plain "EWM" otherwise
(config::window_title, shared by both frontends). The five built-in
configs set it to the machine name: Apple 1, Replica 1, Apple ][,
Apple ][+, Apple //e. The old "EWM v0.1 / …" strings are gone; the
bootloader window aligns to "EWM - Bootloader".

Both `two` and `one` carry the title in Options (from apply_config, and
round-tripped by options_to_config so --print-config shows it). It
comes from the document only: a bare `ewm two`/`ewm one` stays "EWM"
even though one's normalize fills the board from a builtin — so the
title tracks what you asked for, not the machine underneath.

Tests: window_title formatting, and every built-in carries its
machine-name title. Schemas regenerated for the new field.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 20:51:06 -04:00
Stefan ArentzandClaude Fable 5 5512b9c56e The original Apple ][ machine: model apple2 + Two::new_apple2 (A2) (#310)
Phase A2 of plans/20260720-01-original-apple2.md. config::Model gains
Two (serde token "apple2"), apple2 family, two_type() ->
TwoType::Apple2; that arm of new_with_slots is now a real constructor
instead of "unsupported". Two::new_apple2 builds the 48K machine on the
same TwoIo motherboard as the ][+, mapping the Integer ROM set from A1:
Programmer's Aid at $D000-$D7FF, a hole at $D800-$DFFF (unmapped ->
$00), Integer BASIC at $E000-$F7FF, Original Monitor at $F800-$FFFF.

The Monitor is non-autostart, so no emulator code is needed for the
behavioral difference: reset lands at the `*` prompt and does NOT boot
the Disk ][ in slot 6 (a ][+ would). The A1 ROM statics lose their
#[allow(dead_code)]; options_to_config now maps Apple2 -> Model::Two
(so --print-config round-trips), and the state INFO tag is "apple2".

Slot 0 (the memory-expansion socket) is deferred: wiring a Language
Card / Saturn to bank the Integer ROM is future work, so apple2 is 48K
for now. An explicit slot-0 card fails validation with a clear message;
the default ][+ layout's Language Card (inherited by a bare
`--set machine:model=apple2`) is refused at build time, pointing at the
fix. builtin:apple2 (A3) is the clean no-slot-0 path.

Gate: apple2 resets to the Monitor `*` prompt (not an autostart disk
boot), Ctrl-B enters Integer BASIC and PRINT 2+2 answers 4; the slot-0
rejection is pinned at both the validation and build stages. Schemas
regenerated for the new Model token.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 20:10:40 -04:00
Stefan ArentzandClaude Fable 5 64dc24f7a5 Rename model tokens: 2plus -> apple2plus, 2e -> apple2e (#308)
Spell out the two-family model tokens so every machine reads the same
way — apple1, apple2e, apple2plus, replica1 — ahead of adding the
original Apple ][ as `apple2` (plans/20260720-01). Pre-1.0, so the old
terse tokens go outright: `--set machine:model=2plus` and
`--config builtin:2plus` are now apple2plus / apple2e, and an old name
errors with the available list.

Mechanical and wide: the config::Model serde tokens and Model::token(),
the BUILTINS table (renamed, re-sorted, include_str paths), configs/
files (git mv 2plus.json/2e.json -> apple2plus.json/apple2e.json) and
their model values, the ewm/tests/configs fixtures, every "2plus"/"2e"
string literal in tests and error messages, the examples, both schemas,
and the live docs (README, JSON_CONFIG, IDEAS, MAC_APP). Guarded
word-boundary replacement so e2e, new_2e and hex escaped it. The
builtin:list column widened to fit the 10-char "apple2plus".

Verified: fmt, clippy -D warnings, the full suite (37 binaries incl.
golden-BMP and the README example check) pass; builtin:list and the
old-token error checked against the real binary.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 19:49:15 -04:00
Stefan ArentzandClaude Fable 5 c9c1a75fb6 Disk images over HTTP, cached with ETag revalidation (#306)
* --tty-telnet: proactive echo negotiation (fix telnet double-echo)

The telnet echo suppression was reactive — the server only announced
WILL ECHO / WILL SGA after the client sent an IAC first. But a classic
telnet client sits in line-mode-with-local-echo and waits for the
server to negotiate, so the announcement never went out, the client
kept echoing locally, and every line appeared twice (its echo plus the
machine's own authentic echo).

A telnet server that wants remote echo has to offer it proactively on
connect. The new --tty-telnet flag (implies --tty) does exactly that:
it writes WILL ECHO + WILL SGA before the banner and marks the filter
active so the reactive path doesn't double-announce. Bare --tty stays
byte-clean for local terminals and nc (kickoff option B); the reactive
fallback still helps a plain --tty client that does negotiate first.
The systemd @.service switches its ExecStart to --tty-telnet.

The growing session-behavior params (throttle, banner, telnet) fold
into a TtyConfig struct. Tests: proactive announce leads the stream
(before the banner) and doesn't double-announce when the client then
sends its own IAC; the flag implies --tty and parses. Verified live:
`ewm one --tty-telnet | xxd` shows FF FB 01 FF FB 03 then the prompt.

Docs: scripts/systemd/README.md and notes/APPLE1.md explain proactive
--tty-telnet vs byte-clean --tty, with troubleshooting for the
double-echo and the nc negotiation bytes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Disk images over HTTP, downloaded once into a cache

A floppy, hard-drive or 3.5" image path may now be an http(s):// URL:

  ewm two --set 'machine:slots:6:drive1=https://example.com/Frogger.dsk'

ewm/src/fetch.rs downloads it into $XDG_CACHE_HOME/ewm (else
~/.cache/ewm) / <sha1 of the URL> / <file name from the URL>, beside a
meta.json holding the ETag and Last-Modified. The digest keys the
directory because URLs are not filesystem-safe; the file keeps its own
name so the cache is browsable and errors read normally. The hash is
the crate's own SHA-1 (ws::sha1) — no dependency for that.

Freshness is one *conditional* GET (If-None-Match / If-Modified-Since)
rather than HEAD-then-GET: a 304 costs a single round trip. If the
request fails and a copy is cached, the cached copy is used, so a
machine assembled from URLs still boots offline; a cold cache with no
server is a loud error instead.

A URL is a source, not a path: resolve_paths leaves it alone (like
builtin:), while referenced_files still counts it, so a built-in
config may not carry one — builtins must run offline.

Downloaded hard drives mount memory-only. This needed a real change,
not just leaving the file handle unopened: in hdd.rs an unopenable
file means WRITE PROTECTED, which is a different (and still supported)
state for a local image. Hdd now carries an explicit `writeback` flag
— false for downloads, so ProDOS writes update the in-memory image and
never reach the cached file, and revalidating a download cannot
destroy them. Floppies already behaved this way.

Dependency: ureq (blocking + rustls), owner's decision — the one place
the tiny-dependency budget gives way, because TLS is not something to
hand-roll. It brings ~25 transitive crates including ring, so the
headless server build now compiles native crypto too.

Tests: the cache round trip against a real local HTTP server (cold
download, conditional revalidation with a 304, offline fallback, and a
cold cache with nothing listening failing loudly); URL naming and
digest stability including degenerate URLs; memory-only vs write-back
block writes at the register level; URLs surviving path resolution;
and the wiring gate — a machine builds with DOS 3.3 served over HTTP
into drive 1, which only passes if the mount path really fetched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 21:48:11 -04:00
Stefan ArentzandClaude Fable 5 a8a91fc125 machine.cpu and RAM-bank regions (R2) (#296)
Phase R2 of plans/20260719-03-one-machine-components.md.

The document can now say what the Apple 1 family is made of:
machine.cpu ("6502" / "65C02"; absent = the model's CPU) and
generalized memory regions taking exactly one of path (an image — file
or builtin:) or size (an empty RAM bank, "4k"/"32k"/bytes, RAM only).
Structurally, a typo'd builtin: image now fails at parse time naming
the available ROMs, instead of at machine build.

Family rules extend: machine.cpu and size banks are Apple 1 family
keys (the ][+ / //e board is a model property), and one-family layouts
are checked — known extents (banks and builtin images) must fit 64K
and must not overlap each other or the PIA at $D010-$D013; file images
have unknown extents, so only identical starts are judged. The
reset-vector check is deferred to R3 (recorded in the plan): in R2,
document regions are still extras on top of the model's default ROMs,
so "nothing covers the vector" is not yet judgeable.

one wires the new keys: Options carries the cpu override
(One::new_with_cpu) and a MemorySource (Image or Bank); build_machine
mounts banks as zeroed RAM; options_to_config round-trips both (banks
print back as "4k"-style sizes). two defensively expects image paths
(family validation guarantees it). Schemas regenerated.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 16:05:13 -04:00
Stefan ArentzandClaude Fable 5 cdff8386f9 roms/: mountable ROM images, the embedded registry, builtin: paths (R1) (#295)
Phase R1 of plans/20260719-03-one-machine-components.md.

rom/ renames to roms/ wholesale (kickoff decision 4), and the four
mountable one-family images land under the name = stem = token
convention: WozMon.rom (the historical apple1.rom, pristine), the
already-extracted apple1-basic.rom, and the two Krusader 1.3 builds as
4KB $F000-$FFFF slices, each carrying its own modified monitor page.
The historical krusader.rom retires; provenance is pinned by SHA-1
(the crate's own, RFC-vector-tested): BASIC + the 6502 slice
reassemble it byte for byte, BASIC + the 65C02 slice reassemble the
65C02 distribution, and WozMon matches the historical apple1.rom.
One::new mounts the Replica 1 from BASIC + the 6502 slice — memory
byte-identical to the old single 8K mount, proven by the untouched
boot tests.

config.rs gains the embedded ROM_BUILTINS registry and
read_memory_image: a region path of builtin:<name> resolves against
the registry and never touches the filesystem (a literal file named
builtin:x is reachable through a directory component, the same escape
hatch --config has). resolve_paths treats builtin: as a scheme, not a
relative path, and referenced_files skips it — so built-in configs may
carry ROM references and stay self-contained. Both frontends load
memory regions through the shared reader; schemas regenerated for the
path doc.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 15:56:10 -04:00
Stefan ArentzandClaude Fable 5 0f67d4964b Model tokens apple1/replica1 + family cross-checks (O1) (#288)
Phase O1 of plans/20260719-02-one-config.md: one document type
describes any EWM machine. config::Model grows the apple1 and replica1
tokens plus a family() accessor (Apple2 vs Apple1), and two_type()
returns Option — None for the one family, which apply_config turns
into the cross-subcommand error: machine.model: "replica1" is an
`ewm one` machine (run: ewm one --config …).

The family cross-checks join C2's completeness pass, next to the
//e-only rules: on apple1/replica1 documents, machine.slots and
machine.aux are rejected (no slots, no aux socket), as are display.*,
cpu.speed, input, boot, remote, and state — rejected, not ignored,
each error naming the offending key and the model. machine.memory,
cpu.strict, and debug.trace stay valid everywhere. A one-family
document is a valid config (from_document accepts it); only two
refuses to run it.

Both schemas regenerated for the Model enumeration. Tests: family and
token mapping, minimal one-family configs (with memory/strict/trace
and path resolution), the eight rejected-key cases, and two's
rejection via both apply_config and the --set command line.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 13:11:15 -04:00
Stefan ArentzandClaude Fable 5 fc90fff5a8 Partial configs: relax the parse, split validation (C2) (#279)
Phase C2 of plans/20260718-02-config-sources.md — the enabling change
for --config-overlay (C3), landed separately so C3 stays small.

Config.machine and Machine.model become Option in the serde types, so
any partial fragment ({}, a slots-only overlay) parses. Validation
splits to match: validate() keeps every check a lone fragment can be
judged on (unknown keys, enum values, slot rules, multiplicity), while
the new validate_complete() runs only on the final layered document —
machine.model present, plus the model cross-checks (aux is //e-only,
the //e has no slot 0) that an overlay can't answer until the merged
document names the model.

The loader contract keeps configs and overlays distinct concepts:
load/load_source_document (the --config path) still require
completeness per file — a partial file fails early with "machine.model
is required (is this an overlay? use --config-overlay)" — while
load_document now runs only the structural pass (file named in errors,
relative paths resolved) and is the path overlays will load through.
from_document runs both passes on the merged document and points a
missing model at the fix: "start from --config, e.g. --config
builtin:2plus".

Schema: option (2) from the plan. The generated schema is now
overlay-shaped, so the golden test post-processes the requiredness
(machine, machine.model) back into schema/ewm-config.schema.json and
commits the relaxed variant as schema/ewm-config-overlay.schema.json
with its own title/description, giving overlay files editor support.
Round-tripping the generated schema through serde_json::Value would
lose schemars' canonical keyword ordering, so the test converts back
to schemars::Schema before serializing.

Verified: fmt, clippy -D warnings, and the full test suite (including
the golden-BMP screenshot tests) pass; new tests pin the fragment
round-trip through load_document, the per-path completeness messages,
and the model cross-checks moving to the final-document pass. Behavior
of every existing command line is unchanged.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 21:13:44 -04:00
Stefan ArentzandClaude aae19c97b8 Built-in machine configs: --config builtin:2plus / builtin:2e (C1) (#278)
Phase C1 of plans/20260718-02-config-sources.md. The configs/ files are
embedded at compile time (include_str!, a static table in config.rs), so
--config builtin:<name> works from any installed binary; names are the
schema's model tokens, matching the renamed files 1:1 (configs/2plus.json,
configs/2e.json). builtin:list prints names with descriptions and exits
like --help; an unknown name errors listing the available names.

Built-ins are self-contained by rule: load_builtin rejects any file
reference (there is no directory to resolve relative paths against) and
a test pins the property, along with every builtin carrying the new
top-level description field (schema regenerated) and the table staying
sorted.

Verified: builtin:2plus/2e produce the same machine as their committed
files (unit + integration tests), built-ins layer with --set like any
source, builtin:list and unknown-name exits exercised against the real
binary, and the full suite (306 tests, golden BMPs included) is green
with fmt and clippy clean.


Claude-Session: https://claude.ai/code/session_014tBgXL3aSDMgV2CoxTmBQ6

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-18 20:55:38 -04:00
Stefan ArentzandClaude Fable 5 40607df7a7 state S4: --state lifecycle - restore at startup, save at quit
The user-facing surface (notes/STATE.md §6). --state <path> on ewm two,
and a state.path config field (resolved relative to the config file,
schema regenerated; CLI overrides config). At startup the machine is
built from config exactly as before, then the state file - when it
exists - overlays it, replacing the initial reset; a missing file cold
boots, a bad file is fatal with a clear message (never run a
half-restored machine). At quit both frontends save: the SDL loop on its
quit event, the headless serve loop on SIGINT/SIGTERM via raw libc
signal() declarations (no new dependency; the handler stores one relaxed
atomic, async-signal-safe) polled once per frame. Saves are atomic, so a
failure leaves any previous state file intact.

As-built deviation from the plan, recorded there in S5: the S0 CLI stub
('not built yet') was pointless inside a single PR, so the CLI surface
lands here where it works.

Verified live, headless: boot DOS 3.3 under --serve, SIGTERM -> clean
shutdown, 297 KB state file (64 KB machine + nibblized disk, matching the
plan's estimate); restart -> '[STATE] restored', and the framebuffer
shows the fully booted DOS banner 1.5 s after process start (a cold boot
takes ~5 s); SIGINT saves again on the way out. Tests: the file-level
round trip parks X=42 in DOS, saves, restores into a twin, and PRINT X
answers 42; a corrupt file is rejected; flag parsing covered.

Part of plans/20260718-01-machine-state.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 14:56:01 -04:00
Stefan ArentzandClaude Fable 5 859309fdd9 Remote console Phase 5: embedded web console (vendored noVNC, optional web server) (#265)
* Vendor the noVNC engine v1.6.0 (core/ + vendor/pako) for the web console

The pinned noVNC client engine and its one dependency, copied unmodified
from the v1.6.0 release (MPL-2.0; LICENSE.txt vendored alongside), plus
EWM's own minimal console page (index.html) that loads core/rfb.js and
connects back to the host and port it was served from. The full app/ UI
chrome (~800 KB of settings panels, images, and locales) is deliberately
not vendored. See ewm/novnc/README.md for the update procedure.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Remote console Phase 5: embedded web console served from the binary

http://host:PORT/ is now a live Apple II in a browser tab with no external
tooling: a small built-in HTTP handler serves the vendored noVNC console on
the WebSocket port, and the page connects back to the same host:port with the
RFB WebSocket upgrade — one port carries both, the Proxmox shape.

Strictly opt-in tiers, per the design note: --serve vnc://... is native VNC
only; ?ws=PORT adds the raw RFB-over-WebSocket listener (bring-your-own
noVNC; plain HTTP still answers 426); ?web=PORT additionally serves the
embedded console (web=PORT is sugar for web&ws=PORT; bare ?web defaults the
port to 5701). Config equivalent: remote.websocket + remote.web. Bind stays
the single remote.bind for all listeners.

- build.rs: embeds the novnc/ tree as a generated (path, bytes) table of
  include_bytes! entries — no embed crate, no runtime filesystem access.
- web.rs: static-table asset lookup (literal keys only, so no traversal;
  query strings ignored; "/" -> index.html) and a minimal one-shot HTTP
  responder (200 with content-type/length, 404, Connection: close).
- ws.rs: upgrade() split into read_http_request / accept_upgrade /
  refuse_plain_http so the connection handler can branch.
- rfb.rs: the WebSocket listener's Transport carries the web flag; plain
  HTTP requests route to the console when enabled, 426 otherwise.

Verified in a real Chrome tab: http://127.0.0.1:5701/ served the console
from the binary, booted the DOS 3.3 System Master, and CATALOG typed at
browser speed listed the disk. fmt/clippy/test green (145 lib tests, up
from 140: 3 web unit tests + 2 console integration tests).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 12:45:54 -04:00
Stefan ArentzandClaude Fable 5 b48f635d85 Re-land Phase 4 (WebSocket transport + keyboard pacing) onto remote-console (#264)
* Remote console Phase 4: embedded WebSocket transport, noVNC connects directly

Browsers cannot open raw TCP, so noVNC speaks RFB-over-WebSocket. This adds an
optional second listener that serves the identical RFB byte stream inside
WebSocket binary frames — no websockify sidecar, no new dependencies.

- ws.rs: a hand-rolled WebSocket (RFC 6455) server transport in the des.rs
  spirit, instead of the plan's tungstenite (which would add ~9 transitive
  crates; kept as documented fallback). HTTP upgrade with from-scratch SHA-1 +
  base64 (RFC-vector-tested, incl. the RFC 6455 accept-key example), binary
  frame encode/decode across all three length encodings, client-mask
  enforcement, ping->pong, close echo, subprotocol echo for older noVNC.
  Exposed as io::Read/io::Write adapters (WsReader/WsWriter).
- rfb.rs: the connection handling is now generic over Read/Write, so the RFB
  state machine (handshake, VNC auth, input, framebuffer) is shared verbatim
  between plain TCP and WebSocket; Server::start takes an Options struct and
  binds both listeners, feeding one machine. noVNC's SetPixelFormat request
  (little-endian, shifts 0/8/16) is byte-identical on the wire to our
  advertised big-endian 24/16/8, so keeping our format remains safe.
- config/CLI: remote.websocket config field and ?ws=5701 on the --serve URL
  (bare ?ws defaults to 5701); validation rejects port 0 and a ws port equal
  to the RFB port; schema regenerated.

Verified: a from-scratch Python WebSocket client (accept key checked against
hashlib's reference SHA-1) booted DOS 3.3 through the WS port and computed
PRINT 640*1.6 -> 1024; plain TCP verified in parallel on the same machine.
New tests: 6 ws unit tests, a full WS-transport RFB session test, and
parse_serve URL tests. fmt/clippy/test green (139 lib tests).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Remote console: pace remote key input through the one-byte keyboard latch

The Phase 4 browser gate (stock noVNC in Chrome) caught a real bug: a browser
delivers a whole typed word within a single frame, and the serve loop latched
every pending key back-to-back with no CPU cycles in between. The Apple II
keyboard is a one-byte latch, so each byte overwrote the previous before the
ROM could read it — typing CATALOG arrived as just "G". Scripted clients had
masked this by sleeping between keystrokes.

Fix: translated key bytes now land in a queue (RemoteKeys), and the frame loop
pumps at most one byte per frame, only after the ROM has consumed the previous
one (keyboard strobe cleared via $C010). Reset and pointer buttons still apply
immediately; the queue is bounded against flooding. Free side effect: correct
type-ahead while the machine is busy booting.

Verified in a real Chrome tab via noVNC over the WebSocket transport: booted
DOS 3.3, typed PRINT "HELLO FROM CHROME" at browser speed, every character
arrived; a zero-delay scripted burst (PRINT 6*7 -> 42) passed as a second
concurrent viewer of the same machine. New unit test drives the latch/strobe
pacing against a real machine. fmt/clippy/test green (140 lib tests).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 12:09:04 -04:00
Stefan ArentzandClaude Fable 5 f2544dde19 Remote console: headless VNC server for the Apple ][+ / //e (prototype) (#262)
* Remote console prototype: headless VNC server for `two` (notes/REMOTE.md)

A first working prototype of the remote-console plan, collapsing Phases 0/2/3
so an EWM machine can be booted headless and reached with a native VNC client.

- config: new `remote` block (protocol/bind/port/view_only) with validation
  (rejects reserved "rdp" and port 0); schema regenerated.
- rfb.rs: hand-rolled RFB 3.8/3.7/3.3 server on std::net in the wozbug shape —
  security None, Raw encoding, one handler thread per client (several viewers
  of one machine), mpsc input back to the emulator, big-endian-RGBA frames via
  u32::to_be_bytes (no per-pixel conversion). Unit-tested: full handshake +
  first FramebufferUpdate decode, key/pointer delivery, view-only.
- two.rs: `--serve vnc://host:port` parsing and a headless `serve()` loop — the
  SDL frame loop's shape without SDL, reusing build_machine() and the pure Scr
  renderer. Keysym->byte translation mirrors the SDL keyboard table (printable,
  arrows, Return, ESC, Tab/Del, Ctrl-letter, Ctrl+F12 reset).

The SDL path is left byte-for-byte unchanged (a parallel headless path rather
than Phase 1's full Driver refactor, which is deferred — see the prototype note
in notes/REMOTE.md). Verified end-to-end: booted DOS 3.3 and bare Applesoft
over vnc://, typed PRINT 2+2 and saw 4. fmt/clippy/test all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Remote console: VNC authentication (DES challenge) so macOS clients connect

macOS Screen Sharing refuses the RFB "None" security type and always prompts
for a password, so the None-only prototype could not be used from the built-in
client. Add standard VNC authentication (the RFB DES challenge, RFC 6143
§7.2.2), gated on a password.

- des.rs: a small from-scratch DES (FIPS 46-3, ECB, encrypt-only) — the project
  hand-rolls its primitives and keeps deps tiny. Tested against the textbook and
  all-zero vectors, and cross-checked end-to-end against OpenSSL's DES (an
  OpenSSL-computed auth response is accepted by the server).
- rfb.rs: offer security type VNC (2) with the DES challenge when a password is
  set, else None (1) as before; SecurityResult handling per 3.3/3.7/3.8. New
  tests cover auth accept and reject.
- config/CLI: `remote.password` config field and a `?password=` (and
  `?view_only=`) query on the --serve URL; --serve now merges onto config-
  provided serve options so a config password survives an explicit --serve.

Verified: macOS-style VNC auth handshake accepted with the right password and
rejected with the wrong one, then booted Applesoft and typed PRINT 2+2 over an
authenticated session. fmt/clippy/test (129 lib tests) all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* REMOTE.md: record the actual branch layout (remote-console integration branch)

The integration branch is 'remote-console' (cut from main); work branches
like 'claude/remote-console' PR into it, and one final PR promotes it to
main. PR #262 is the first such sub-phase PR.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-18 11:04:13 -04:00
Stefan ArentzandClaude Fable 5 185f64895f Emulate the UniDisk 3.5 Controller (Liron) with .2mg images (liron.rs) (#259)
The SmartPort card that put 800K 3.5" drives on the Apple II, as
virtual hardware in the hdd.rs style: hand-assembled $Cn00 firmware
over magic DEVSEL ports, no IWM emulation. Two drives, .2mg images of
exactly 400K or 800K, ProDOS order; the 2IMG locked flag mounts
read-only and writes land back in the file at data_offset, header
preserved.

The firmware carries a real SmartPort identity - signature $Cn07=$00,
ID type at $CnFB, ProDOS entry via $CnFF with the SmartPort dispatch
at entry+3 - and implements both protocols: the ProDOS block driver
with the drive bit in $43, and a SmartPort dispatch (the full
JSR-with-inline-bytes convention, return address fixed up past the
command and parameter-list bytes) serving STATUS, READ_BLOCK and
WRITE_BLOCK, with block calls translated onto the ProDOS pump.
Squeezing two protocols into one 256-byte page took a tiny two-pass
assembler (Asm) instead of hdd_rom's hand-counted offsets, plus a few
documented economies: the third SmartPort block byte is ignored (800K
is 1600 blocks), $45 is not preserved across transfers, and empty
drives report 0 blocks from ProDOS STATUS.

The boot test settled the plan's open question: the Enhanced //e
Autostart scan accepts the SmartPort signature, so ProDOS 2.4.3 boots
to Bitsy Bye from an 800K .2mg in slot 5 through this firmware.

Config: {"card": "liron", "drive1": ..., "drive2": ...}, any slot 1-7;
configs/enhanced.json now carries one in slot 5. WozBug SLOTS shows
the drives: S5: UniDisk 3.5 (D1 800K, D2 -).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 00:20:57 -04:00
Stefan ArentzandClaude Fable 5 9fad92a5ed Emulate the Saturn Systems 128K RAM Board in slot 0 (saturn.rs) (#257)
The classic third-party alternative to the Apple Language Card, per
the Saturn Operations Manual ch. 9: 128K as eight 16K banks that all
live at $D000-$FFFF, each bank two 4K banks (A/B) at $D000 plus its
own 8K. Bank 1 speaks the exact Language Card protocol, which is the
card's compatibility story - DOS 3.3, Pascal and VisiCalc treat it as
a 16K card and never notice the other seven banks.

The $C08x decode: A2=0 is the Language Card state machine (A3 now the
4K bank, A0/A1 read/write enables, copied from alc.rs including the
read-twice write-enable - the manual's "PEEK or POKE" prose is looser,
but the LC-compatible semantics are what software relies on); A2=1
selects the 16K bank ($C084-7 are banks 1-4, $C08C-F banks 5-8), with
the board state persisting across switches. Power-up: ROM read, write
protect, bank 1.

The slot-0 plumbing grows from a language_card bool into two::Slot0
(Language / Saturn128 / Empty), mirroring how SlotDevice mirrors the
config cards. The config gains {"card": "saturn128"}, slot 0 only,
][+ only, same rules as the language card; WozBug's SLOTS shows
S0: Saturn 128K (bank n).

Tested: all sixteen $C08x offsets against the manual's table, eight
banks holding independent contents on the bus with the A/B split at
$D000 and the shared per-bank 8K, and the compatibility claim end to
end - DOS 3.3 boots, prints (LOADING INTEGER INTO LANGUAGE CARD),
and INT/FP swap between Integer BASIC in Saturn bank 1 and Applesoft
in ROM.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 22:21:09 -04:00
Stefan ArentzandClaude Fable 5 7ccd4b369d Model slot 0: the ][+ Language Card becomes a configurable card (#256)
The Alc was hardwired into Two::new_2plus, so every ][+ was a 64K
machine and configs/plus.json could not even mention the card it was
supposed to demonstrate. Slot 0 now lives in the machine.slots table
(owner's decision — hardware-faithful, keyed "0"), restricted to
"language" or "empty": the socket has no $Cn00 firmware space, so
nothing else can work there, and the //e rejects "0" outright — its
language card is soldered onto the motherboard.

The literal-table rule now covers slot 0, a deliberate breaking change:
a ][+ config whose slots table omits "0" is a stock 48K machine, with
the motherboard ROM directly at $D000-$FFFF and slot 0's DEVSEL range
as unmapped as any other empty slot's. The default table (and the
--set materialization) gains "0": {"card": "language"}, so bare
command lines keep the classic 64K build and

  --set machine:slots:0:card=empty

is the 48K opt-out. configs/plus.json now declares the card.

Slot 0 never becomes a SlotDevice: build_machine consumes it as a
language_card flag on Two::new_with_slots, and new_2plus either wires
the Alc as before or maps the ROM straight onto the bus.
Two::language_card() reports the socket and WozBug's SLOTS shows an
S0 line on the ][+. A guard catches the --set plus --model 2e path
that bypasses config validation.

Tested: the $C083/$C083 write-enable sequence changes $D000 with the
card and bounces off ROM without it, and DOS 3.3 boots to the prompt
on the 48K machine — it just skips loading Integer BASIC.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 21:30:10 -04:00
Stefan ArentzandClaude Fable 5 6a6fd790eb Make machine construction slot-table-driven (JSON_CONFIG Phase B) (#252)
* Make machine construction slot-table-driven (JSON_CONFIG Phase B)

The machine builders no longer hard-wire the card set — Two::new_*
constructs from a slot table, so a config can put any card in any slot:

- Dsk/Clk/Hdd decode only the DEVSEL low nibble, so one implementation
  serves any slot; the clock and hard-disk firmware are generated per
  slot (clk_rom/hdd_rom patch the unit byte, $Cn page, and port
  operands), with golden tests pinning the slot-1/slot-7 images
  byte-for-byte to the pre-generator statics. The IouE holds owned slot
  ROM copies so generated firmware can be installed.
- Two::new_with_slots builds up to three Disk ][ controllers (the
  classic maximum), one Thunderclock, any number of hard drives, and
  empty slots (reading $00, which the Autostart scan skips). new/
  new_with_aux delegate with the default table, so the whole existing
  suite runs unchanged. Boot stays the real Autostart ROM slot scan —
  highest populated slot wins, as on hardware; no config boot hint.
- The Phase A layout gate in config validation is replaced by
  multiplicity rules; machine.slots is now optional (absent = the
  default layout, present = literal). --drive1/--drive2/--hdd became
  slot 6/7 sugar merged into the table, preserving CLI-over-config
  precedence. Drive lights OR across controllers; drag-drop targets the
  boot controller.
- New ewm/tests/two_slots.rs: controller independence at the bus level,
  boot-scan order, empty slots falling through to BASIC, a clock in
  slot 2 surviving a full ProDOS 2.4.3 boot, and hard drives in two
  slots serving distinct images.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add ready-made machine configs for the classic setups

configs/plus.json is the Apple ][+ (language card built in): green
monitor, Disk ][ in slot 6, nothing else. configs/enhanced.json is the
Enhanced //e (65C02 inherent to the model): extended 80-column 64K card
in the aux slot, Disk ][ in slot 6, color monitor. Neither names a
disk — the --drive1/--drive2 flags merge into the config's slot 6 card.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Replace the drive flags with generic --set config overrides

--set <key>=<value> overrides any config value by colon-separated key
path (--set machine:slots:6:drive1=game.dsk, --set display:monitor=
amber); the --drive1/--drive2/--hdd sugar flags are removed.

Config sources now layer left-to-right into one JSON document:
--config files load through the typed path (per-file validation and
relative-path resolution intact) and serialize back to JSON — the
config types gained serde::Serialize, fronting Phase C — while --set
mutates the document directly; one typed conversion + validation runs
at the end. Deep-merge rules: objects recurse, null/empty-array
overlays are no-ops, and objects whose "card" discriminators differ
replace wholesale. A --set entering machine:slots on a slotless
document materializes the default table first, so a bare
--set machine:slots:6:drive1=x behaves exactly like the removed
--drive1. Values parse as JSON when they are JSON (numbers, booleans,
whole objects — the one-line --hdd replacement) and as plain strings
otherwise.

The boo-menu launcher speaks --set for dropped media; README and the
notes record the new syntax and the multi-file deep-merge semantic.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Fix CI: point the full.json fixture at a committed disk image

The disks directory is gitignored with only four images force-added;
"Total Replay v6.0.1.hdv" exists only in local working trees, so the
two_config.rs existence assertion failed on CI (and has kept main red
since #251 merged). The fixture's slot 7 hard drive now uses the
committed ProDOS_2_4_3.po block image instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 18:15:32 -04:00
Stefan ArentzandClaude Fable 5 e83139331e Add JSON machine configuration via --config (JSON_CONFIG Phase A)
A whole machine can now be described in one JSON file and started with
`ewm two --config myemulator.json`:

- ewm/src/config.rs: serde types mirroring the schema; load() parses,
  validates semantically (Phase A accepts only today's buildable layout:
  slot 1 thunderclock, slot 6 diskii, slot 7 harddrive, any aux card),
  and resolves relative paths against the config file's directory.
- --config in parse_options via a two-pass parse: pass 1 seeds Options
  from the file, pass 2 is the unchanged flag loop — so explicitly given
  CLI flags override config values structurally.
- Config-only settings cpu.speed and input.controller wire to the
  existing palette mechanisms at startup (including the audio
  cycle-to-sample pairing and a preferred-gamepad name scan).
- schema/ewm-config.schema.json: draft 2020-12, derived from the config
  structs by a golden-file test (schemars is a dev-dependency only;
  regenerate with EWM_UPDATE_SCHEMA=1 cargo test -p ewm).
- Tests: schema lockstep, parse/validation/rejection messages,
  relative-path resolution, CLI-overrides-config precedence, and a boot
  gate (a config naming the DOS 3.3 disk boots to the ] prompt exactly
  like --drive1 does).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 15:16:03 -04:00