Skip to content

Add MEGA65 (native C65) and Commander X16 targets - #1

Open
jhonnaker1 wants to merge 2 commits into
idolpx:masterfrom
jhonnaker1:add-mega65-x16-targets
Open

Add MEGA65 (native C65) and Commander X16 targets#1
jhonnaker1 wants to merge 2 commits into
idolpx:masterfrom
jhonnaker1:add-mega65-x16-targets

Conversation

@jhonnaker1

Copy link
Copy Markdown

Adds two new build targets to CBM-FileBrowser, plus one shared bug fix. Both new ports boot, browse directories, scroll, and launch programs, verified in their emulators (Xemu / x16emu). Existing targets are untouched and still build clean.

MEGA65 — native C65 mode (target = 65)

Runs in the MEGA65's native mode (not GO64): loads at $2001 with a BASIC-10 SYS stub, screen $0800, colour RAM $D800. The C65 KERNAL is C128-derived, so the portable $FFxx jump table is reused; the C128 VDC/MMU code is replaced with C65-appropriate init, and PRNSTR/PRNINT/CLEARSCREEN are provided locally (no C64 BASIC ROM). Two MEGA65-specific details were needed: zero the KERNAL's 32-bit LOAD destination bank bytes ($AF/$B0) so directory/program loads land in bank 0, and use an 80-column screen stride. Launch parses the SYS address out of the loaded program's $2001 stub and jumps to it (ROM-independent).
New: sources/mega65.def, sources/mega65.asm, programs/fb65, MEGA65.md.

Commander X16 (target = 216)

The X16 has a C64-derived KERNAL (standard $FFxx, BASIC $0801, 65C02) but VERA video — the text screen is not in CPU address space. So all drawing goes through the KERNAL screen editor (CHROUT/PLOT), fast-scroll is off, and clearlist is reimplemented with PLOT+CHROUT. The browser sets 40x30 text mode and ISO mode (so mixed-case SD-card/HostFS filenames render as letters). Launch uses the same ROM-independent SYS-stub parser (from $0805).
New: sources/x16.def, sources/x16.asm, programs/fbx16, X16.md.

Shared fix: parseext infinite loop

parseext's outer loop steps X by the 4-byte slot size and terminated only on X == extensions_max, but the extensions table isn't a whole multiple of 4 ("tcrt" is 5 bytes), so X could step past extensions_max and loop forever. It only triggers when a selected filename has an extension that matches nothing — which never happens with CBM disk names (no extension) but does on the X16's HostFS names like NAME.PRG. Fixed by terminating on X >= extensions_max (bcs instead of beq) — a safe hardening for every target.

Build

cd sources && make builds all targets including fb65.prg and fbx16.prg. Both new targets sit behind !if target = 65 / !if target = 216 guards.

🤖 Generated with Claude Code

- target=65: native MEGA65/C65 mode - screen $0800, BASIC $2001, C128-derived
  KERNAL, self-contained print helpers, ROM-independent SYS-stub launcher.
  New files mega65.def / mega65.asm.
- target=216: Commander X16 - VERA video (all drawing via CHROUT/PLOT, no direct
  screen RAM, fast-scroll off), ISO charset so mixed-case SD/HostFS filenames
  render as letters, SYS-stub launcher. New files x16.def / x16.asm.
- Both added to the shared CBM-FileBrowser.asm behind "!if target" guards, with
  Makefile rules and prebuilt binaries in programs/ (fb65, fbx16).
- Fix a latent parseext infinite loop: its outer loop steps X by the 4-byte
  slot size and stopped only on X == extensions_max, but the table is not a
  whole multiple of 4 ("tcrt" is 5 bytes), so X could step past it. Terminate
  on X >= extensions_max (bcs) instead of == (beq). Only bites when a filename
  has a non-matching extension (e.g. the X16's HostFS "NAME.PRG"); safe for all
  targets.
- Docs: MEGA65.md, X16.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The SYS-stub launcher runs machine-language programs (the bulk of the software)
but cannot RUN a pure BASIC program: no SYS token means it resets, and a stray
$9E byte can make the parse jump to a bad address. Document this shared
limitation in X16.md and MEGA65.md; a proper LOAD-then-RUN hand-off into BASIC
is future work.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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