# Land Map 64 - Toolchain ## Decision - Language: **6502 assembly (ca65)** - Recipe: **Windows cross-development with cc65 (C, ca65 assembly or mixed) and VICE** (`cc65`) - Build location: Windows cross-development - Foundry recommendation: `cc65` / `asm-ca65` (6502 assembly (ca65)) No user override. The recommended language is used. ### Why this language - The user asked for assembly, and the program is timing-critical: pixel-smooth bitmap scrolling plus a 9 KB buffer rebuild and people updates must fit in each 1/60 s NTSC frame. - ca65 (the cc65 suite assembler) on Windows with VICE x64sc is a verified Foundry combination with an automated smoke test. - Assembly gives exact control of VIC-II bank switching, fine-scroll registers and raster timing, which the flip and the scroll depend on. ### Alternatives considered | Alternative | Why not chosen | |---|---| | C (cc65) | Too slow for the per-frame buffer rebuild and smooth scrolling; it would need most hot paths in assembly anyway. | | Mixed C + ca65 | Possible for world generation, but nearly all the work is timing-critical, and the user asked for assembly. | | BASIC V2 | Far too slow for bitmap drawing, let alone smooth scrolling. | ## Tools | Tool | Purpose | Verified version | Install source | First command if missing | Override variable | |---|---|---|---|---|---| | `cl65` | cc65 compile/assemble/link driver (C and ca65 assembly) | cl65 V2.19 - Git cc3c40c | https://cc65.github.io/getting-started.html | Download https://sourceforge.net/projects/cc65/files/cc65-snapshot-win64.zip, unzip it (for example to C:\cc65), then run: [Environment]::SetEnvironmentVariable('CC65_HOME','C:\cc65','User') and open a new terminal. | `CC65_HOME` | | `x64sc` | VICE cycle-exact Commodore 64 emulator | VICE 3.10 | https://vice-emu.sourceforge.io/index.html#download | winget install --id VICE-Team.VICE.GTK3 -e (or unzip GTK3VICE-3.10-win64.zip and set VICE_HOME to the unzipped folder) | `VICE_HOME` | Check them with `pwsh -File tools/check-prereqs.ps1`. Lookup order for each tool: its environment variable (folder or folder\bin), then `PATH`, then common install folders. ## Commands | Purpose | Command | |---|---| | Check prerequisites | `pwsh -File tools/check-prereqs.ps1` | | Build all targets | `pwsh -File tools/build.ps1` | | Build one target | `pwsh -File tools/build.ps1 -Target ` | | Run in VICE | `pwsh -File tools/run.ps1 -Target ` (add `-Video ntsc` to try NTSC) | | Automated smoke test | `pwsh -File tools/smoke.ps1` (exit 0 pass, 1 fail, 2 missing tool, 3 manual only) | ## Target settings and verification status Starter configurations marked verified were exercised by the Foundry's automated checks on 2026-11-26 with cl65 V2.19 - Git cc3c40c (Windows x64 snapshot), VICE 3.10 GTK3 win64 (x64sc, x128, c1541, petcat), PowerShell 7.6.7 on Windows 11 Pro 10.0.26200. ### Target `c64` - Status: **verified** starter configuration (cc65, c64/vicii-40, asm-ca65) - Build (what tools/build.ps1 runs): `cl65 -t c64 -g -C c64-asm.cfg -u __EXEHDR__ -D FOUNDRY_TARGET_C64 -I src -o build/land-map-64.prg -Ln build/land-map-64.lbl -m build/land-map-64.map src/*.c src/*.s` - Emulator: `x64sc -ntsc -autostart build/land-map-64.prg` - Smoke test: `pwsh -File tools/smoke.ps1 -Target c64`. It runs VICE headless for 30000000 cycles, saves memory when the program reaches `smoke_ready`, and checks: - Title in the status mirror - World generation reached its ready point (`MAP READY`) - C64 KERNAL reset vector at $FFFC (machine is in C64 mode) - World check: `pwsh -File tools/check-world.ps1` validates the tile data saved by the smoke test. - People check: `pwsh -File tools/check-people.ps1` runs VICE headless (NTSC, warp) for 40,000,000 cycles, logs the people table at the `people_moved` hook every frame through the monitor, and checks that all 16 people stay inside the world, never stand on a water or stone tile, move at most one pixel per step, all move, and start spread over the four screens. Output: `build/check-people/`. ### How the smoke test works `tools/smoke.ps1` starts VICE with `-config -default -warp -minimized -sounddev dummy`, so your own VICE settings are never read or changed. It gives the monitor a command file (`-moncommands`) that sets non-stopping tracepoints on the program's ready point. When the program reaches it, VICE saves memory with `bsave` into `build/smoke//`. VICE exits after `-limitcycles` cycles and writes `-exitscreenshot`; that is the normal way the run ends, so VICE's own exit code is ignored. The script then compares the saved memory with the expected screen text (as VIC-II/VDC screen codes) and mode bytes. Smoke hooks in the source: - cc65 C programs: `smoke_capture()` and `smoke_ready()` in `src/smoke.c`. 80-column builds copy the first VDC rows into `smoke_probe[]`, because VDC memory is not visible to the CPU. - ca65 programs: the `smoke_ready` label. - BASIC programs: `POKE 679,1` (BASIC V2) or `POKE 3071,1` (BASIC 7.0) after the first screen is drawn. ## Assumptions still to verify - [ ] A3: buffer flip via $DD00 bank bits in vertical blank shows no tearing on NTSC in VICE. - [ ] A4: measure the per-frame cost of the rebuild slice plus the people update with a border-colour timing bar before M3 is finished. - [ ] A6: multicolour bitmap and bank switching behave as documented in Mapping the Commodore 64. ## Sources - https://cc65.github.io/doc/cl65.html - https://cc65.github.io/doc/c64.html#toc4.2 - https://cc65.github.io/doc/c128.html - https://cc65.github.io/doc/ca65.html - https://vice-emu.sourceforge.io/vice_2.html#SEC50 - https://vice-emu.sourceforge.io/vice_7.html#SEC194 - https://vice-emu.sourceforge.io/vice_12.html - https://cc65.github.io/getting-started.html - https://vice-emu.sourceforge.io/index.html#download