You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10KB

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 <id>
Run in VICE pwsh -File tools/run.ps1 -Target <id> (add -Video ntsc to try NTSC)
Run with the timing bar pwsh -File tools/run.ps1 -Target c64 -TimingBar (assembles with --asm-define TIMING_BAR into build/land-map-64-timing.prg; cl65's -D only defines C symbols, so assembler symbols go in the build's asmDefines)
Long scrolling run pwsh -File tools/check-scroll.ps1 -Long (adds the 5-minute tour; about 10 minutes; -ParseOnly -NoBuild re-checks the last run's logs)
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)
    • Status rows 20, 21, 22 and 24 in buffer A's text screen ($4720) and rows 20 and 24 in buffer B's ($8720)
    • 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.
  • Split check: pwsh -File tools/check-split.ps1 runs VICE headless for 20,000,000 cycles. It logs the raster line and cycle of the three mode writes at split_store (src/status.inc) every frame and requires them to start between line 210 cycle 53 and line 210 cycle 64. That window was measured by building with split delays 6-12 under +autostart-delay-random: starts at 210:40-51 damaged the last map line, starts at 211:0-11 damaged the first text line, and 210:50-211:1 were clean; the shipped delay starts at 210:55-61 at y-scroll 3. Tracepoints on the key_row_* instructions fake “no key” and then scroll down three cells and back up (phase byte at $CFF0, VICE conditional checkpoints), so every map y-scroll value 0-7 is split and checked against the same window (y-scroll 2, a bad line at line 210, uses a shorter delay; measured 2026-12-03: starts at 210:58-64). It also checks that a split happens every frame, that after each status update the people-in-view digits equal the number of people whose dot is at least partly in the visible window (computed by the script from the people table and view), and (coarsely) the screenshot colours at the boundary. Output: build/check-split/.
  • Key check: pwsh -File tools/check-keys.ps1 runs eight headless VICE scenarios. VICE's monitor cannot press keys, so tracepoints on the key_row_* instructions in src/keys.inc replace the port B row bits with those of held keys (r a = <bits>). It checks scroll_dx/scroll_dy for no key, right, left (right SHIFT), down, up (left SHIFT), down-right and up-left, and that SPACE held from frame 60 regenerates exactly once. Output: build/check-keys/.
  • Scroll check: pwsh -File tools/check-scroll.ps1 runs three headless VICE scenarios (edges, middle, reverse). Each is a list of phases: fake held keys (as in the key check) until a condition on the program state is met at people_moved (a move_frame value or a view position). The phase number is kept in free RAM at $CFF0 and moved on by VICE conditional checkpoints (trace exec $addr if (@cpu:$addr == $nn) && (...): the parentheses are needed, and checkpoints at one address run in the order they were defined, so phase changes are defined latest first). Every frame it logs the phase, view, scroll registers, visible buffer, flip state and people table. It checks that the view moves at most one pixel per axis per frame and only in the direction of the keys read the frame before, stays inside 0-336 x 0-244 and stops at the edges, that $D011/$D016 match the fine scroll, that in every frame the shown buffer is complete and built for the view's cell (a half-rebuilt buffer on screen tears the top of the map), that nothing is stored into the shown buffer's map screen RAM or bitmap during raster 55-210, that no frame is missed and the people update ends before raster 55, and reports frames where a held key did not move the view (stalls, allowed up to 40). At the end it compares the buffer about to be shown, byte for byte, with a fresh render of the world at the view plus the people's dots (and, when a flip is pending, the shown buffer with the previous frame's dots). It also logs the CPU clock at frame_start, people_moved, frame_done, the KERNAL interrupt entry ($FF48) and exit ($EA81), start_rebuild and rebuild_ready, and prints a budget line per scenario: frame period, vertical blank work, main loop busy and idle cycles, interrupt cycles, and how many frames each hidden-buffer rebuild took. With -Long it adds a tour scenario (about 23,000 frames, six laps over the whole world by rows and by columns, 21 stops) that saves and checks both buffers byte for byte at the end of every stop. Any monitor script error fails the check. Output: build/check-scroll/.
  • 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. It also saves both bitmap buffers before people are drawn and at the last frame, and checks byte for byte that the hidden buffer is the clean map plus the current dots and the visible buffer is the clean map plus the previous frame's dots (no trails, no damaged terrain). It checks that the main loop never misses a frame (x64sc NTSC frame: 263 lines x 65 = 17,095 cycles) and that each people update ends before raster line 51, the first visible line. Output: build/check-people/.

How the smoke test works

tools/smoke.ps1 starts VICE with -config <temp file> -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/<target>/. 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

Powered by TurnKey Linux.