# AGENTS.md: Commodore 64 / 128 Development This repository is a workbench for writing Commodore 64 and C128 software with AI agents. It provides a toolchain that builds, runs, and **checks** programs in VICE without a human watching the screen; topic skills compiled from the classic reference books; register and ROM reference tables; and several working projects. ## Start here 1. Load `.claude/skills/c64-workflow/SKILL.md`. It covers the build/test/debug loop and the traps that cost the most time. 2. Run `c64 doctor` once per machine. It needs cc65 and VICE 3.x; `pwsh` runs the tools. 3. Load the topic skill for the domain (table below) before you write hardware code. 4. Finish only when `c64 test` passes and you have read the screen it prints. ``` c64 new -Template c|asm|basic # projects/ c64 build c64 test [-Expect TEXT] [-Until label] [-AfterJiffies n] [-Keys "x\n"] c64 run [-Monitor] [-FromDisk] c64 mon "r" "m .label .label+8" # talk to a run started with -Monitor ``` `c64` is `c64.cmd` at the repo root (from PowerShell: `.\c64.cmd`; from Git Bash: `./c64.cmd`). Exit codes: 0 ok, 1 test failed, 2 usage or tool error. ## Rules - **Verify on the emulator.** A program that compiles is not done. Use `c64 test` with `-Expect` for screen text, or report from code through `$D7FF` (`lib/c64test.h`, `lib/c64test.inc`). Use `build/test//screenshot.png` for graphics and sprites. - **Pick the toolchain the user asked for.** cc65 C and ca65 assembly are the defaults. Power C means on-machine K&R C: load `.claude/skills/powerc/SKILL.md`, and never write to `reference/POWERc.d81` (copy it first). - **Write addresses in hex with `$`**, adding decimal when they appear in BASIC `PEEK` or `POKE` (`$D020` = 53280). - **Check banking** before touching `$A000-$BFFF`, `$D000-$DFFF`, or `$E000-$FFFF`. The CPU sees ROM, RAM, I/O, or character ROM depending on `$01`. - **Prefer Kernal routines** (`$FFD2` CHROUT, `$FFE4` GETIN, `$FFBA`/`$FFBD`/`$FFC0` for files) over custom I/O unless speed or banking rules them out. - **State PAL or NTSC** for anything timing-sensitive (raster splits, SID pitch). VICE defaults to PAL. - **Free zero page** while BASIC and the Kernal are live: `$02`, `$FB-$FE`. cc65 C programs own `$02-$1B` for their runtime. - **Keep the suite green.** After changing `tools/`, `templates/`, `lib/`, or an example, run `pwsh tools/regress.ps1` (about 2 minutes, including a native C128 smoke test). - **Respect sub-project rules.** `newLang/` has its own `AGENTS.md`; read it before changing anything there. ## Skills (`.claude/skills/`) | Skill | Use for | |-------|---------| | `c64-workflow` | **Always**: c64 commands, c64project.json, testing, debugging, charset traps | | `6510-assembly` | Opcodes, addressing modes, ML idioms, calling ML from BASIC | | `memory-map` | Zero page, banking via `$01`, VIC banks, safe places for code and data | | `graphics-vic2` | Text/bitmap/multicolor modes, sprites, scrolling, raster tricks | | `sound-sid` | SID registers, ADSR, waveforms, filters, music drivers | | `interrupts` | IRQ/NMI, CIA timers, raster interrupts, stable raster | | `kernal-routines` | Kernal jump table, screen/serial/disk I/O from ML | | `disk-io-1541` | 1541 DOS commands, file types, direct access, error channel | | `basic-programming` | BASIC 2.0 internals, tokens, extending BASIC, FP routines | | `compiler-design` | Compilers and assemblers that run on or target the 64/128 | | `vice-emulator` | VICE options, monitor commands, checkpoints, snapshots | | `powerc` | Spinnaker Power C on the C64 (`reference/POWERc.d81`) | ## Reference (`reference/`) | File | Contents | |------|----------| | `memory-map-complete.md` | Complete zero page, pages 2-3, I/O map, `$01` banking | | `6510-opcodes.md` | All opcodes with modes, cycles, flags | | `kernal-jumplist.md` | Kernal jump table with inputs and outputs | | `vic-registers.md`, `sid-registers.md`, `cia-registers.md` | Chip register maps | | `disk-dos-commands.md` | 1541 DOS commands, error codes, disk layout | | `vice-usage.md` | VICE 3.10 command line and monitor quick reference | | `vice.pdf` | VICE 3.10 manual | | `POWERc.d81`, `Power_C_Instruction_Manual.pdf` | Power C system disk (read-only) and manual | | `powerc-re/` | Power C reverse engineering: patched compiler/runtime, smaller and faster output | ## Projects | Path | What | Build / check | |------|------|---------------| | `projects/` | New programs from `c64 new` | `c64 test projects/` | | `templates/{c,asm,basic}` | Skeletons with a passing self-test | used by `c64 new` | | `examples/` | Single-file examples (BASIC, ca65, cc65 C, Power C disks) | exact commands in `tools/regress.ps1` | | `skirmish-game/` | Tactical game in ca65 assembly | `c64 test skirmish-game` | | `samples/kernal-os-skeleton/` | Kernal-resident OS shell (+ `vim.asm` via `build_vim.bat`) | `c64 test samples/kernal-os-skeleton` | | `samples/cc65-mouse-driver-demo/` | cc65 1351 mouse driver demo | `c64 test samples/cc65-mouse-driver-demo` | | `vim/` | vi clone: ca65 assembly on the C64 (`src/vim.s`), plus the older Power C build and a cc65 C128 port (`vim128.c`) | `pwsh vim/test/test-vim.ps1`; see `vim/NOTES.md` | | `newLang/` | Nova128: an OO language and on-machine compiler for the C128 | see `newLang/AGENTS.md` | ## Platform summary ``` $0000-$00FF zero page $0100-$01FF stack $0200-$03FF OS work area, vectors $0400-$07E7 screen (default) $0801-$9FFF BASIC program $A000-$BFFF BASIC ROM / RAM $C000-$CFFF free RAM $D000-$DFFF I/O or char ROM / RAM $D000 VIC-II $D400 SID $D800 color RAM $DC00 CIA 1 (keyboard, joystick, IRQ) $DD00 CIA 2 (VIC bank, serial, NMI) $E000-$FFFF Kernal ROM / RAM $01 bits 2-0 (CHAREN HIRAM LORAM): %111 $37 default | %110 $36 BASIC out | %101 $35 all RAM + I/O | %100 $34 all RAM ``` CPU: 6510 at 0.985 MHz (PAL) or 1.023 MHz (NTSC). 16 colors, 8 hardware sprites (24×21), 40×25 text, 320×200 hi-res, 160×200 multicolor. Full details are in the skills and `reference/`. ## Sources Platform knowledge was compiled from: *The Anatomy of the Commodore 64*; *The Machine Language Book* and *The Advanced Machine Language Book for the Commodore 64* (Abacus); *COMPUTE!'s Mapping the Commodore 64*; *COMPUTE!'s VIC-20 and Commodore 64 Tool Kit* (BASIC and Kernal); *The Anatomy of the 1541 Disk Drive*; *The Complete Commodore 64 ROM Disassembly*; *Compiler Design and Implementation (64 and 128)*; *COMPUTE!'s SpeedScript*; and *Invaluable Utilities for the Commodore 64*. Emulator material comes from the VICE 3.10 manual. Toolchain behavior was verified on this repository.