--- name: c64-workflow description: > Start here for any task that creates, builds, runs, tests, or debugs a Commodore 64 or C128 program in this repository. Covers the `c64` command (doctor, new, build, run, test, mon), c64project.json, the $D7FF test-result protocol, reading test artifacts, choosing between cc65 C, ca65 assembly, BASIC, and Power C, and the PETSCII/charset traps that make text show up wrong. --- # C64 Development Workflow Use one loop for every program: **scaffold → build → headless test → inspect → fix**. Never call a change finished until `c64 test` passes. Its output shows the actual C64 screen, so you can check the result yourself instead of asking the user to look. ``` c64 doctor # once per machine: cc65 + VICE present? c64 new invaders -Template c # projects/invaders from templates/c c64 build projects/invaders # -> build/invaders.prg .lbl .map .d64 c64 test projects/invaders # headless; prints screen + PASS/FAIL c64 run projects/invaders # for the user to play (opens a window) ``` `c64` is `c64.cmd` at the repo root, which calls `pwsh tools/c64.ps1`. From PowerShell use `.\c64.cmd`; from Git Bash use `./c64.cmd` or `pwsh tools/c64.ps1 ...`. Exit codes: 0 = success/pass, 1 = test failed, 2 = usage or tool error. Any command also accepts a single source file (`c64 test examples/moonlander.c`). Output then goes to `build/` next to the file. ## Choose the toolchain | Need | Use | Template | |------|-----|----------| | Games, tools, most new programs | cc65 C (`cl65`), with asm for hot loops | `c` | | Raster effects, cycle timing, size-critical code, IRQ handlers | ca65 assembly | `asm` | | Small demos, teaching, a type-in listing | BASIC 2.0 (`petcat`) | `basic` | | C that must compile **on** the C64 | Power C: load `.claude/skills/powerc/SKILL.md` | none | | C128 native mode | any of the above with `"machine": "c128"` | `c` / `asm` | Mixed C + asm: put `.s` files in `src/`. The C template's manifest already includes `src/*.s`. cc65 calling convention: arguments on the C stack (`popa`/`popax`), the last argument in A/X when `__fastcall__` (the default). Return values go in A (8-bit) or A/X (16-bit). ## c64project.json ```json { "name": "invaders", // output name; disk filename (16 chars max) "machine": "c64", // c64 | c128 "language": "c", // c | asm | basic "sources": ["src/*.c", "src/*.s"], "config": "src/game.cfg", // optional ld65 config (asm default: c64-asm.cfg + BASIC stub) "flags": ["-Oirs"], // extra cl65 flags (-D NAME=1, --static-locals, ...) "disk": true, // also write build/.d64 (or a path: "build/x.d81") "diskFiles": [{ "path": "data/level1.bin", "name": "level1" }, { "path": "data/notes.txt", "name": "notes", "type": "seq" }], "basicCase": "lower", // BASIC only: "preserve" keeps case for shifted PETSCII "test": { // defaults for `c64 test`; CLI options override "expect": ["SCORE 0"], "until": "main_loop", // OR "afterJiffies": 300 (default: wait for $D7FF) "keys": "", // typed with VICE -keybuf; \n is RETURN "timeoutSeconds": 60, "maxCycles": 150000000 } } ``` (JSON has no comments; they are shown here only to explain the fields.) Builds always emit `build/.lbl` (VICE labels) and `build/.map`. Read the map when memory gets tight: it lists every segment's start, end, and size. ## Headless testing: `c64 test` The runner boots VICE minimized in warp mode and injects the PRG. When a **trigger** fires it dumps RAM and I/O, decodes the text screen, and closes VICE. | Trigger | Use when | |---------|----------| | default: first store to `$D7FF` | You control the code. Store 0 for pass, 1-255 for a failure code. | | `-Until