--- story: E02-S01 owner: e02_source_reader status: done started: 2026-11-07 depends-on: [E01-S03, E01-S05] --- # E02-S01 Claim ## Intended change Add the compiler's source reader. `src_load` reads a PETSCII SEQ file from device 8 once into a bank-1 cache, enforcing the line, line-count, and file size limits with stable error codes and exact positions. `src_rewind` and `src_next_line` then replay the cached source identically for every pass, one logical line at a time. Disk access goes through new `diskio.s` KERNAL wrappers that always close their channels. ## File area - `src/compiler/source.s`, `src/compiler/diskio.s` - `src/common/source.inc` - `src/compiler/mmu.s` (bank-1 block copy only) - `cfg/compiler.cfg` (bank-1 source cache area) - `tests/platform/map-skeleton.s` (table-size constant only) - `tests/source/` - `scripts/build-source-test.ps1`, `scripts/verify-source-test.ps1`, `scripts/lib/` - `docs/memory-map.md`, `docs/architecture.md`, `docs/decisions.md` (D118) - `planning/claims/E02-S01.md` - generated files under `build/` ## Acceptance evidence - [x] Reads Vim-created SEQ source without host conversion: fixtures use Vim's exact save format (PETSCII, `$0D` lines, both letter ranges in `decls.n8`); the reader delivers the bytes unchanged, verified by a host Fletcher-16 match. A live Vim edit is E07-S03. - [x] Accepts `$0D` lines and a missing final `$0D`: `nofinal.n8` yields the same 50 lines and checksum as `decls.n8` with one byte fewer. - [x] Enforces line/file limits with stable errors: `edge.n8` (80-byte line, 599 lines, 18,999 bytes) loads; `longln.n8` -> code 3 at 3:81, `manyln.n8` -> code 4 at 600:1, `big.n8` -> code 2 at 500:38. - [x] Rewinds identically for all compiler passes: two replays per load give identical line counts and checksums, and `src_line_no` ends at the line count. - [x] Disk failure closes channels and leaves no partial output: `LDTND` is 0 after every load; after each failure `src_len` is 0 and `src_next_line` returns end of source at once; a later `decls.n8` load succeeds unchanged. ## Coordination notes Source error codes are reader return codes. E02-S04 maps them to stable `Exxx` diagnostics. A true Vim round trip (edit in x64sc, compile in x128) is E07-S03; this story proves the reader consumes Vim's exact byte format (`../vim/NOTES.md`, `vedit.c` save path) with no conversion. ## Work log - Confirmed Vim's save format in `../vim/NOTES.md` and `vedit.c` (raw buffer, `$0D` lines, final `$0D` appended, 80-column wrap on load). - Recorded D118: one disk read into a bank-1 cache (`$2000-$6AFF`), tables keep `$6B00-$BFFF` (21,760 bytes). Map skeleton re-verified with it. - Added `mmu_copy_to1` and `mmu_src` to `mmu.s`, `diskio.s` with a COMMON chunk reader run through `kcall`, `source.s`, and `diskio.inc`. - Added `scripts/lib/Nova128Test.psm1` (link, PETSCII conversion, disk images, remote monitor, mailbox polling). The monitor helper waits for the `(C:$xxxx)` prompt; a fixed delay returned empty replies with a 1581. - Negative control: allowing 81-byte lines makes the C128 report FAIL and the host flag `longln.n8` (code 0, position 0:0, 100 bytes kept). Restored. ## Completion - Tests run: `scripts/verify-source-test.ps1` (pass plus mutation run), `scripts/verify-map-skeleton.ps1`, `scripts/verify-kernal-probe.ps1`, `tests/grammar/validate.ps1`, `tests/disk/prepare-disk.tests.ps1`. - Results: all 8 fixture records match host expectations; screenshot shows each result code and `NOVA128 SOURCE TEST OK`; regressions pass. - Files changed: `src/compiler/source.s`, `src/compiler/diskio.s`, `src/compiler/mmu.s`, `src/common/source.inc`, `src/common/diskio.inc`, `cfg/compiler.cfg`, `tests/source/source-test.s`, `tests/platform/map-skeleton.s`, `scripts/build-source-test.ps1`, `scripts/verify-source-test.ps1`, `scripts/build-map-skeleton.ps1`, `scripts/lib/Nova128Test.psm1`, `docs/memory-map.md`, `docs/architecture.md`, `docs/decisions.md` (D118), this claim. - Remaining risks: device 8 is fixed; a read error part-way through a file (ST error other than EOI) is handled in code but not exercised, since VICE offers no simple way to inject one; only the 1581 (D81) was tested; error codes are reader codes until E02-S04 assigns user-facing `Exxx` IDs.