From 75b9f4677d8a81c29c5de8881fad3941b9509fce Mon Sep 17 00:00:00 2001 From: Daniel Covington Date: Thu, 3 Dec 2026 19:53:30 -0500 Subject: [PATCH] M4.1: terrain all over the world (random mix per world, bridges) Region generator with a per-world terrain mix: jittered seeds on a grid, noisy nearest-seed regions, smoothing, thin-water removal, shores and trees; the road grid crosses water on new bridge tiles. The scroll rebuild skips cells whose tile is already drawn, keeping rebuilds within 8 frames with textured terrain everywhere (chunk cutoffs 224/234). check-world checks the new rules over N VICE runs; check-keys and check-scroll allow for the slower start-up. Spec R1.5/R1.6, M4, MT4.1. Co-Authored-By: Claude Opus 5.5 --- docs/manual-tests.md | 32 ++ docs/milestones.md | 12 + docs/spec.md | 13 +- docs/verification-status.md | 8 + project.json | 60 ++- src/scroll.inc | 69 +++- src/tiles.inc | 9 + src/world.inc | 707 ++++++++++++++++++++++++++++-------- tools/check-keys.ps1 | 2 +- tools/check-scroll.ps1 | 10 +- tools/check-world.ps1 | 270 +++++++++++--- 11 files changed, 980 insertions(+), 212 deletions(-) diff --git a/docs/manual-tests.md b/docs/manual-tests.md index a250ba3..55cbb63 100644 --- a/docs/manual-tests.md +++ b/docs/manual-tests.md @@ -233,6 +233,38 @@ Expected: Verifies: R6 (and the R1 view size) +## M4 - Terrain all over the world + +### MT4.1: Terrain everywhere, a different mix per world (c64) + +Setup: VICE x64sc, NTSC (-ntsc), pepto-pal palette (tools/run.ps1 selects it), warp off. +Start: `pwsh -File tools/run.ps1 -Target c64` + +Automated first: `pwsh -File tools/check-world.ps1 -Runs 10` should end with +`[PASS] the terrain mix varies between worlds ...` and `[PASS] 10 world(s) checked.` +(add `-ShowMap` to print each world as a character map: `.` land, `g` grass, `T` trees, +`#` stone, `~` water, roads `-` `|` with `+` crossings, bridges `=` `!` with `*` crossings). + +Steps: +1. Wait for the map (the generating message shows for about 4 seconds). Look at the first view. +2. Scroll over the whole world: right to the edge, down, left, and up again. +3. Tap SPACE five or six times, waiting for each new map, and compare the first views. +4. In one world, scroll along a road that crosses a lake, and watch the dots near water and stone for a minute. +5. Scroll left, right, up and down across busy terrain. + +Expected: +- Every view shows a mixture of terrain: open light brown land, green meadows with trees, grey rock + outcrops and blue lakes with shores, spread over the whole world, not one big lake or a few patches. +- Each new world has a different mix: some clearly wetter, rockier or greener than others. +- Black roads (two across, two down) run the full width and height of the world; where one crosses + water it continues as a bridge (black over blue), with no gap. +- No colour clash, no stray pixels at shores, bridges or crossings. +- Dots walk on land, grass, trees, roads and bridges, and never step onto water or stone. +- Scrolling stays smooth over textured terrain (no regular stutter at each cell step). A short + hesitation when a scroll starts from rest is acceptable, as before. + +Verifies: R1 (R1.2-R1.6), R2.3, R5.1 + ## Real hardware Optional for this release. Use these steps when hardware is available. diff --git a/docs/milestones.md b/docs/milestones.md index 51fe95e..102aa66 100644 --- a/docs/milestones.md +++ b/docs/milestones.md @@ -56,3 +56,15 @@ Requirements: R5, R6, R3, R2 | M3.4 | Check that people stay aligned with the terrain over long scrolling runs; measure the frame budget with a border-colour timing bar. | R2, R3, R5, R6 | People stay aligned with terrain over long runs; budget measured | Manual tests MT3.2, MT3.3 and MT3.4 | Manual verification: see docs/manual-tests.md section M3. + +## M4 - Terrain all over the world + +Goal: Lakes, meadows with trees, rocky outcrops and open land are spread over the whole world, in a different mix for each world, with roads crossing water on bridges. + +Requirements: R1, R2, R5 + +| Task | Description | Requirements | Buildable outcome | Completion check | +|---|---|---|---|---| +| M4.1 | Region generator: each world rolls its own terrain mix; jittered seeds on a grid give every class areas all over the world, shaped by noisy distances, smoothing and removal of thin water; shores from the neighbours; trees on grass. Roads stay a grid of two rows and two columns and become bridges over water. The scroll rebuild skips cells whose tile is already drawn, to keep the 8-frame rebuild with textured terrain everywhere. | R1, R2, R5 | Varied terrain in every view; SPACE gives a different mix | `pwsh -File tools/check-world.ps1 -Runs 10`, `tools/check-scroll.ps1 -Long`; manual test MT4.1 | + +Manual verification: see docs/manual-tests.md section M4. \ No newline at end of file diff --git a/docs/spec.md b/docs/spec.md index 1a41eb2..691112d 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -8,6 +8,7 @@ Changes approved by the user since then: - 2026-12-03: R3 reworded for scrolling: while a scroll rebuild runs, people are drawn in the shown buffer during vertical blank; drawing people relative to the view moved from M3.4 to M3.3. - 2026-12-03: A4 status recorded from the M3.4 measurement as partly met; the user accepted the occasional one-frame scroll pause. - 2026-12-03: Background (land, border and status area) changed from brown (colour 9) to light brown: C64 colour 8 (named orange), which VICE's pepto-pal palette (measured from PAL C64s) shows as light brown; tools/run.ps1 starts VICE with that palette (new assumption A8). Tree trunks stay colour 9. +- 2026-12-03: Terrain all over the world ("the different land spaces need to be all over the map, not just here and there"): R1 reworded; new criteria R1.5 (every view shows at least three terrain kinds) and R1.6 (each world rolls its own random terrain mix). Roads stay a grid and cross water on bridges. New milestone M4. ## Summary @@ -71,13 +72,15 @@ Each criterion is observable. Criteria IDs (for example R1.2) are referenced by ### R1 - Generated 2x2-screen world (must) -At start-up the program generates a world of 2x2 screens (80x50 cells of 4x8 multicolour pixels) from a seed. The generator decides the layout, shapes and counts of features; every world contains light brown land, grey stone, green grass and trees, blue water and black roads that connect to each other. The view shows a 40x20-cell window of it in multicolour bitmap mode, above the status area (R6). +At start-up the program generates a world of 2x2 screens (80x50 cells of 4x8 multicolour pixels) from a seed. Terrain covers the whole world: lakes, meadows with trees, rocky outcrops and open light brown land are spread all over it, not gathered in a few places. Each world rolls its own mix of the four terrain kinds (land, grass and trees, water, stone), so one world may be wet and another rocky. A grid of black roads (two across, two down) connects to each other and crosses water on bridges. The view shows a 40x20-cell window of it in multicolour bitmap mode, above the status area (R6). Acceptance criteria: - [R1.1] After autostart in VICE (x64sc, NTSC) the map view appears within 15 seconds - [R1.2] Scrolling across the whole world shows all five terrain colours: light brown, grey, green, blue and black -- [R1.3] Roads are continuous black lines that connect to each other +- [R1.3] Roads are continuous black lines that connect to each other; where a road crosses water it is a bridge - [R1.4] No colour clash: every 4x8 cell shows only its intended colours +- [R1.5] Every 40x20-cell view of the world shows at least three of the four terrain kinds (land, grass and trees, water, stone), each covering at least 8 cells +- [R1.6] Different worlds have different terrain mixes: over several SPACE presses, some worlds are visibly wetter, rockier or greener than others Capabilities: smooth-animation @@ -148,9 +151,9 @@ Capabilities: raster-interrupts | Persistence (save/load) | None. Maps and seeds are not saved. | practical default | | File formats | None. A single PRG. | practical default | | Peripherals | Keyboard only. No disk access after loading, no joystick. | practical default | -| Timing and memory budgets | NTSC: 60 Hz, 17,095 cycles per frame (263 lines x 65 cycles, the NTSC VIC-II 6567R8 that x64sc emulates). Per frame: fine-scroll update, one slice of the hidden-buffer rebuild (about 7,600 bytes of bitmap and screen RAM, 20 map rows plus one partial row, spread over 8 frames), and restoring and redrawing visible people; together under one frame. World data about 4 KB; two bitmap buffers with their screen RAM about 18 KB. World generation may take several seconds. | practical default | +| Timing and memory budgets | NTSC: 60 Hz, 17,095 cycles per frame (263 lines x 65 cycles, the NTSC VIC-II 6567R8 that x64sc emulates). Per frame: fine-scroll update, one slice of the hidden-buffer rebuild (about 7,600 bytes of bitmap and screen RAM, 20 map rows plus one partial row, spread over 8 frames), and restoring and redrawing visible people; together under one frame. World data about 4 KB; two bitmap buffers with their screen RAM about 18 KB. World generation may take several seconds (since M4.1 about 4 seconds, behind the generating message; the map is ready about 7 seconds after power-on). | practical default | | Memory layout | Buffer A in VIC bank 1 and buffer B in VIC bank 2, each with its own 8 KB bitmap and 1 KB screen RAM; flipping switches bank bits in $DD00 during vertical blank. Each bank also holds a 1 KB status text screen (bank + $0400) and a 2 KB copy of the upper-case ROM font (bank + $0800), at the same offsets so a flip still changes only $DD00. Colour RAM is shared and constant (light red), which is also the status text colour. | practical default | -| Rebuild source | The hidden buffer is rebuilt from the tile world, never copied from the visible buffer, so people's dots are never copied into the new view. | practical default | +| Rebuild source | The hidden buffer is rebuilt from the tile world, never copied from the visible buffer, so people's dots are never copied into the new view. Since M4.1 the rebuild first puts back the bytes under the buffer's own people and then skips every cell whose tile is already drawn there (most cells, as terrain comes in areas), so textured terrain everywhere still rebuilds within 8 frames. | practical default | | Seed | The seed comes from the CIA timer at start-up and at each SPACE press. It is not shown or saved in the first release. | practical default | ## Required capabilities @@ -166,7 +169,7 @@ Capabilities: raster-interrupts | A1 | Light red (C64 colour 10) stands in for tan, as the C64 has no tan. | confirmed | | A2 | The map generator keeps every 4x8 cell to at most two of grey, green, blue and black (besides the light brown background). Where three would meet, for example a road along a shoreline next to grass, it changes the least-represented colour in that cell. | default | | A3 | Each buffer has its own bitmap and screen RAM in a separate VIC bank (banks 1 and 2), flipped via $DD00 in vertical blank; colour RAM is shared and constant. | unverified | -| A4 | Rebuilding the hidden buffer from tile patterns (about 7,600 bytes) can be spread over 8 frames alongside the people update within the NTSC frame budget, which allows 1 pixel per frame scrolling. | partly met (measured 2026-12-03 in VICE x64sc NTSC, accepted by the user): most rebuilds take 7-8 frames; about 6% take 9-10 when many people are in view, pausing the scroll for one frame (1.7% of scrolling frames); not noticeable in use | +| A4 | Rebuilding the hidden buffer from tile patterns (about 7,600 bytes) can be spread over 8 frames alongside the people update within the NTSC frame budget, which allows 1 pixel per frame scrolling. | partly met (measured 2026-12-03 in VICE x64sc NTSC, accepted by the user): since M4.1 the rebuild skips cells already drawn; in the long tour 99% of rebuilds take 6-8 frames, 13 of 1,928 take 9 or more, pausing the scroll for one frame in 0.8% of scrolling frames (M3.4, before terrain everywhere: 1.7%); not noticeable in use | | A5 | The smoke test cannot read a bitmap. The program writes a status mirror ("LAND MAP 64", "MAP READY") into the unused text screen at $0400 once the first view is shown; the smoke test checks that text, and the VICE screenshot shows the map. | default | | A6 | The catalog has no bitmap-graphics capability. Multicolour bitmap mode and VIC bank switching are documented in Mapping the Commodore 64 (53265 $D011, 53270 $D016, 53272 $D018, 56576 $DD00); a catalog update is proposed separately. | unverified | | A7 | Switching from the fine-scrolled multicolour bitmap to fixed text (and back at the top of the frame) with raster interrupts gives a steady split in VICE x64sc NTSC with no bad-line glitches at the boundary, whatever the map's vertical fine-scroll value. | unverified | diff --git a/docs/verification-status.md b/docs/verification-status.md index d37fe20..77c143e 100644 --- a/docs/verification-status.md +++ b/docs/verification-status.md @@ -18,9 +18,17 @@ manual = `pending`, `confirmed by user ()`, `problem reported ():