Skip to content

firmware: the TR menu loads and lists D64/D71/D81 images through the shared disk image engine - #91

Draft
wesbiggs wants to merge 5 commits into
SensoriumEmbedded:mainfrom
wesbiggs:shared-disk-menu
Draft

wesbiggs wants to merge 5 commits into
SensoriumEmbedded:mainfrom
wesbiggs:shared-disk-menu

Conversation

@wesbiggs

@wesbiggs wesbiggs commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

This is part 4 of a series of PRs to streamline and consolidate disk image (.d64/.d71/.d81) access, which will then be used to power the VDrive Special IO. It moves the TR menu's own D64/D71/D81 code, loading a file and listing a directory, onto the shared engine from #88. After it, the firmware has no disk image code of its own left, and the series stops here until the VDrive work proper.

Depends on #88, #89 and #90. Only the last two commits (b1010ded, 154ee102) are new here, so please review those. Once the others merge, I'll rebase this branch onto main and it will shrink to those two commits.

Rationale

D64.ino carried its own sector geometry, file-chain reader and directory walk: a fourth copy of what the engine does, and the least defended one. A file chain that loops or links off the image read until RAM ran out or seeked to a wrong offset, and the listing stopped a directory sector at its first empty slot.

State of affairs after this PR

  • Loading a file (b1010ded) goes through the engine via DiskImage/MenuDisk.h, which also holds the menu's size tolerance: short D64s down to 171520 bytes (Realm.d64 is one) still open, and a sector past the file's end fails to read rather than the image being refused. Valid files load the same bytes as before. A chain that loops or links off the image now fails with "File could not be read", and the size limit is the buffer's exact size rather than 254 bytes short of it.
  • Listing a directory (154ee102) goes through the engine's directory iterator, via MenuDiskList. This changes what the menu shows, to match a drive's own listing:
    • a deleted file (type byte 0, name still in the slot) is no longer listed;
    • an empty slot no longer ends its directory sector, so entries after a gap are listed.
  • The listing still starts at the first directory sector (18/1, or 40/3 on a D81) rather than the header's link, as the menu always has.
  • LoadDxxDirectory and LoadDxxFile keep their signatures, so every way into them (the menu, and DriveDirLoad.ino's callers) takes the new path.

Memory

  • New functions in D64.ino and MenuDisk.h are FLASHMEM, and the engine's are VD_COLD, which is FLASHMEM on the firmware. None of it is on the PHI2 path.
  • MenuDisk.h's size and track tables are PROGMEM, and the menu's two load-failure messages use PSTR().
  • No new RAM2 use. Directory entries are still allocated one per listed file, as before.
  • RAM, from the link report of the shipping builds (npm run build:tr, npm run build:tr-plus), at firmware: the GEOS installer and boot-file reader use the shared disk image engine #90's tip (81b2e06c) and at this branch's tip: no change. TR and TR+ main, MinimalBoot and the TR+ extension image report the same RAM1 free for local variables and padding and RAM2 variables before and after (TR main 122748 / 6008 / 17600, TR+ main 79836 / 25864 / 17600).

Docs

  • docs/Architecture/Disk-Images.md: MenuDisk.h, and the TR menu as the engine's third caller, with what its listing shows.

Testing

  • New host test Source/Teensy/tests/menu-disk.test.js lists directories and loads files the way the TR menu does, from each kind, short and odd-sized images, deleted entries, gaps, and chains that loop or link off the image.
  • npm test passes at this branch's tip.
  • Host build only, not hardware tested. Browsing into a D64, D71 or D81 from the TR menu and launching a program from it goes through this path.

Compatibility

The menu's listing of a disk image changes as described above: deleted files no longer show, and files after an empty directory slot now do. No change to the remote protocol (docs/ControlComms.md), the cartridge register map, the EEPROM settings or any timing.

License

My own work, MIT licensed like the rest of the repository.

🤖 Generated with Claude Code

wesbiggs and others added 5 commits November 3, 2026 22:06
…VDrive will share

The GEOS installer and the TR block device each carry their own image
geometry, BAM and directory code, and VDrive brings a third, more
complete engine (40-track D64s, error bytes, BAM and directory growth
for all three kinds, tested against c1541). Bring VDrive's engine in
under Source/Teensy/DiskImage so the other two can move onto it.

Nothing uses it yet. The copy differs from teensyrom-vdrive's d64/ only
in what the firmware needs: SPDX lines, the placement macros moving into
d64.h, and its three constant tables marked D64_FLASH so they land in
PROGMEM rather than DTCM. DiskImage.h includes the code once for the
single translation unit the firmware and the host harnesses build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5t9wWXadFkQgKaCnjreF7
… engine

TRBlockImage did its own track/sector arithmetic on top of GEOS's format
table, which knows only the three plain sizes. A D64 with the error
bytes copiers append, or a 40-track D64, therefore mounted as no image.

The backend now opens the image with d64_open_exact and reads and writes
through d64_block_read/d64_block_write, so those images mount and the
geometry is the one VDrive uses. The error table is left unread: the
driver has no status for a bad sector, so it gets the sector's bytes.
Files of any other size still mount as no image; the harness now reads
one byte past the largest image so an oversized file cannot pass as one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5t9wWXadFkQgKaCnjreF7
… image engine

GeosDiskPatch.h carried a second implementation of what the shared
engine does: BAM places, allocation, directory chains and growth, file
chains. It now asks the engine for all of it and keeps only what is
GEOS's own: the info block, the GEOS bytes of the directory entry, and
moving the TR driver ahead of the other input drivers. GeosBoot.h reads
the boot file, refreshes an old TR mouse driver and sets up CONFIGURE
through the engine too. The header goes from 596 lines to 362.

The driver now lands where 1541 DOS would put it (nearest the directory,
interleave 10) rather than first-free from track 1: one allocator in the
firmware, and GEOS does not care where its files are. trmouse.py models
the same allocator so the byte-for-byte test still holds, and
docs/Architecture/Disk-Images.md records the choice.

The room checks happen before the first write, now from the engine:
d64_blocks_allocatable counts exactly what the allocator can hand out,
so a BAM count below its bitmap is no longer refused and can no longer
run the write out of room partway. Images with error bytes and 40-track
D64s are accepted.

The engine gains d64_dir_check, d64_dir_room, d64_blocks_allocatable and
d64_alloc_next, which VDrive can use as well, and no longer grows a D81
directory into BAM sector 40/1 or 40/2 when a damaged BAM shows one free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5t9wWXadFkQgKaCnjreF7
… shared engine

D64.ino carried its own sector geometry and file-chain reader. Loading a
program from an image now goes through the shared engine via
DiskImage/MenuDisk.h, which also holds the menu's size tolerance: short
D64s down to 171520 bytes (Realm.d64) still open, and a sector past the
file's end fails to read rather than the image being refused.

Valid files load the same bytes as before. A chain that loops or links
off the image now fails with "File could not be read" instead of reading
until RAM runs out or seeking to a wrong offset, and the size limit is
the buffer's exact size rather than 254 bytes short of it.

The directory listing is unchanged here; it moves in the next commit,
which changes what the menu shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5t9wWXadFkQgKaCnjreF7
…d engine

The last disk image code of its own in the firmware was the menu's
directory walk. It now goes through the shared engine's iterator, via
MenuDiskList in DiskImage/MenuDisk.h, which is host-tested.

This changes what the menu shows, to match a drive's directory listing:
- a deleted file (type byte 0, name still in the slot) is no longer
  listed;
- an empty slot no longer ends its directory sector, so entries after a
  gap are listed.

The listing still starts at the first directory sector (18/1, or 40/3 on
a D81) rather than the header's link, as the menu always has.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5t9wWXadFkQgKaCnjreF7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant