From 7768e1209d857e2b609a0b2c252ba1768751af2c Mon Sep 17 00:00:00 2001 From: Daniel Covington Date: Fri, 4 Dec 2026 09:41:22 -0500 Subject: [PATCH] M7.1-M7.3: 1-255 people, + and - while running, people keep their speed - M7.1: people tables as one 256-byte page per field in free video-bank RAM - M7.2: people drawn only into the hidden buffer and flipped in - M7.3: + adds and - removes people (repeat when held); status P001/016; raster IRQ frame count lets people catch up when frames drop - Checks: check-keys +/- scenarios, check-people -People N, check-paths reads buffer variables by label Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- docs/manual-tests.md | 26 +++ docs/milestones.md | 14 ++ docs/spec.md | 34 ++-- docs/verification-status.md | 11 + project.json | 97 +++++++-- src/keys.inc | 61 +++++- src/main.s | 16 +- src/paths.inc | 22 +- src/people.inc | 388 ++++++++++++++++++++++-------------- src/scroll.inc | 8 +- src/status.inc | 77 ++++--- tools/check-keys.ps1 | 60 ++++-- tools/check-paths.ps1 | 23 ++- tools/check-people.ps1 | 70 ++++--- tools/check-scroll.ps1 | 13 +- tools/check-split.ps1 | 8 +- 17 files changed, 625 insertions(+), 305 deletions(-) diff --git a/README.md b/README.md index e564fdd..7c1cf51 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Land Map 64 -A C64 program written in 6502 assembly that procedurally generates a 2x2-screen landscape world (light brown land, grey stone, green grass and trees, blue water) shown as a multicolour bitmap. The cursor keys scroll the view smoothly across the world. 16 people, drawn as white dots, wander the world but are blocked by water and stone. Where they walk often they wear dark brown paths into the land, which fade again when they are no longer used. Each person has a random name, a sex (M or F) and six D&D-style scores (3d6); P steps through the people, showing the chosen one below the map and making their dot blink. Two bitmap buffers are flipped each update, and only the spots where people move are redrawn. +A C64 program written in 6502 assembly that procedurally generates a 2x2-screen landscape world (light brown land, grey stone, green grass and trees, blue water) shown as a multicolour bitmap. The cursor keys scroll the view smoothly across the world. 16 people at first, drawn as white dots, wander the world but are blocked by water and stone. Where they walk often they wear dark brown paths into the land, which fade again when they are no longer used. Each person has a random name, a sex (M or F) and six D&D-style scores (3d6); P steps through the people, showing the chosen one below the map and making their dot blink. + adds a person and - removes the last one (1 to 255 people; with many, the picture updates less often but people keep their speed). Two bitmap buffers are flipped each update, and only the spots where people move are redrawn. - Targets: `c64` (details in [docs/spec.md](docs/spec.md)) - Language/toolchain: 6502 assembly (ca65) - Windows cross-development with cc65 (C, ca65 assembly or mixed) and VICE ([docs/toolchain.md](docs/toolchain.md)) diff --git a/docs/manual-tests.md b/docs/manual-tests.md index e207053..da85dad 100644 --- a/docs/manual-tests.md +++ b/docs/manual-tests.md @@ -377,3 +377,29 @@ Expected: - Cursor keys, SPACE and P still work; SPACE gives new names, sexes and scores and shows P01. Verifies: R8, R6 + +## M7 - A changing number of people + +### MT7.1: Adding and removing people (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-keys.ps1` and `pwsh -File tools/check-people.ps1 -People 255` +should end with `[PASS]`. + +Steps: +1. Wait for the map and read status line 1. +2. Press + a few times, then hold + until the count passes 100. +3. Hold + until it stops, then scroll around. +4. Press P a few times, then hold - until it stops. +5. Press SPACE. + +Expected: +- Line 1 reads like `P001/016 ALDRIC M` +- Each + press adds one to the count and a new dot appears somewhere in the world; held, the count climbs about 12 a second +- The count stops at 255; the map gets less smooth, but people walk at the same speed and no trails or broken terrain appear +- The - key removes people down to `P001/001`; the shown person changes to the last one when they are removed +- SPACE gives a new world with 16 people: `P001/016` + +Verifies: R2, R3, R8 diff --git a/docs/milestones.md b/docs/milestones.md index fc92c9e..a6aa63e 100644 --- a/docs/milestones.md +++ b/docs/milestones.md @@ -94,3 +94,17 @@ Requirements: R8, R6, R2, R3 | M6.2 | Status area shows only the chosen person, who gets a random name and sex: sex 50/50 (people_sex), name from a start syllable, half the time a middle one, and a male or female end syllable (people_name, 10 letters, space padded), rolled with the scores. Row 20 'Pnn' + name + M/F, row 21 the scores, rows 22-24 blank; the title, view position, people-in-view count and key help (and the per-frame status update and people-in-view count) are removed. All keys still work. | R8, R6 | Status area shows the chosen person's name, sex and scores only | `pwsh -File tools/check-keys.ps1` (names 3-10 letters, sex 0/1, rows 20-21 match the shown person), `tools/check-split.ps1` (rows 20-21 lit, 22-24 blank, person 01 in both banks), `tools/smoke.ps1`; manual test MT6.2 | Manual verification: see docs/manual-tests.md section M6. + +## M7 - A changing number of people + +Goal: 1 to 255 people, 16 in a new world; + and - change the number while the program runs; people keep their speed. + +Requirements: R2, R3, R8 + +| Task | Description | Requirements | Buildable outcome | Completion check | +|---|---|---|---|---| +| M7.1 | Memory layout that grows: every people table becomes one 256-byte page per field, indexed by person 0-254 (positions $4C00-$4FFF; direction, sex and the six scores $5800-$5FFF; saved bytes under the dots of both buffers $8C00-$91FF; the ten name letters $9200-$9BFF), so no table moves when the number changes. people_count (1-255) replaces the fixed 16 everywhere: placing, moving (every 8th person per frame), drawing, P, the status line. | R2, R8 | Same program with 16 people, its tables ready for up to 255 | `pwsh -File tools/smoke.ps1`, `tools/check-world.ps1`, `tools/check-keys.ps1`, `tools/check-people.ps1`, `tools/check-split.ps1`, `tools/check-paths.ps1` | +| M7.2 | People are drawn only into the hidden buffer (people_update in the main loop, once the hidden buffer is complete; buf_dots marks it) and flipped in at the next vertical blank, which now does no people work. A scroll step that crosses a cell waits until the rebuilt buffer has its people too. | R3, R5 | Vertical blank work no longer grows with the number of people | `pwsh -File tools/check-people.ps1` (both buffers hold the clean map plus the right dots), `tools/check-scroll.ps1 -Long and -Long -PathTest` | +| M7.3 | + adds a person at a random walkable spot with a new name, sex and scores (up to 255); - removes the last one (down to 1; if they were shown, the new last person is shown). Held, both repeat after 30 frames, then every 5th frame. Status line 1 shows P001/016 (person / number of people). The raster IRQ counts frames, so when the main loop takes longer than a frame the people catch up on the missed frames (up to 4) and keep their speed. | R2, R8, R3 | + and - change the number of people while it runs | `pwsh -File tools/check-keys.ps1` (+ held: the count climbs past 40, `- held: stops at 1`, `status shows P001/nnn)`, `tools/check-people.ps1 -People 255`, `tools/smoke.ps1`, manual test MT7.1 | + +Manual verification: see docs/manual-tests.md section M7. diff --git a/docs/spec.md b/docs/spec.md index ba1e513..4baca33 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -12,10 +12,11 @@ Changes approved by the user since then: - 2026-12-03: Worn paths instead of roads ("keep track of where the people walk and when the counter hits 128 then it is a path/road but the number can be reduced by one every certain number of cycles"; "remove their creation"): the generator makes no roads (R1 text, R1.2, R1.3); new R7 worn paths (dark brown patches, appear at 128, fade below 64, counts go down by one every 60 seconds, all chosen by the user); new milestone M5. - 2026-12-03: People's attributes ("now we need to give each person attributes like D&D"): new R8. Each person has six scores (strength, dexterity, constitution, intelligence, wisdom, charisma), rolled 3d6 when a world is made and stored one byte each; shown only, they do not change behaviour. P (a letter key, chosen by the user instead of Tab, which the C64 does not have) steps through the people; status line 4 (the spare line, R6) shows the chosen person's number and scores, and that person's dot blinks on the map. New milestone M6. - 2026-12-04: Status area shows only the chosen person, who also gets a name and a sex ("we dont need land map 64 text, view, or people in view or the directions on how to move the screen or new world or person; we do want the person's attributes; also every person needs a random name and needs to be male or female"): the title, view position, people-in-view count and key help are removed from the status area (R6); the keys all still work. R8 adds a random sex (50/50, shown as M or F) and a random name of 2-3 syllables from male or female syllable lists (up to 10 letters); line 1 shows number, name and sex, line 2 the scores, lines 3-5 are blank (layout chosen by the user). New task M6.2. +- 2026-12-04: A changing number of people ("if I make the people count 32 it messes up memory location and attributes dont show correctly"; "# of people can be dynamic so the memory needs to place in a way that it can expand or contract"): R2 now has 1-255 people, 16 in a new world; + adds a person and - removes the last one while the program runs (keys, maximum and change-while-running chosen by the user). The people's tables move to one 256-byte page per field in free RAM inside the video banks. R3: people are drawn only into the hidden buffer and flipped in; with many people the main loop may take more than a frame, and then the picture (and the scroll) updates less often while every person keeps walking at the same speed ("keep speed, drop frames", chosen by the user). R8: status line 1 shows `P001/016`: the person's number and the number of people. New milestone M7. ## Summary -A C64 program written in 6502 assembly that procedurally generates a 2x2-screen landscape world (light brown land, grey stone, green grass and trees, blue water) shown as a multicolour bitmap. The cursor keys scroll the view smoothly across the world. 16 people, drawn as white dots, wander the world but are blocked by water and stone. Where they walk often they wear dark brown paths into the land, which fade again when they are no longer used. Two bitmap buffers are flipped each update, and only the spots where people move are redrawn. +A C64 program written in 6502 assembly that procedurally generates a 2x2-screen landscape world (light brown land, grey stone, green grass and trees, blue water) shown as a multicolour bitmap. The cursor keys scroll the view smoothly across the world. 16 people at first (1-255, + and - change the number), drawn as white dots, wander the world but are blocked by water and stone. Where they walk often they wear dark brown paths into the land, which fade again when they are no longer used. Two bitmap buffers are flipped each update, and only the spots where people move are redrawn. Original idea, as given: @@ -25,14 +26,14 @@ Smallest useful version: A 2x2-screen world generated from a seed at start-up, s ## First release -A generated 2x2-screen world in multicolour bitmap mode with pixel-smooth cursor-key scrolling, a 5-line status area below the map showing the chosen person, 16 moving people blocked by water and stone, double-buffered partial redraw, and SPACE for a new world. +A generated 2x2-screen world in multicolour bitmap mode with pixel-smooth cursor-key scrolling, a 5-line status area below the map showing the chosen person, 16 moving people (1-255 with + and -) blocked by water and stone, double-buffered partial redraw, and SPACE for a new world. ### In scope - Procedural generation of a 2x2-screen world (80x50 cells of 4x8 multicolour pixels) from a seed - Terrain colours: light brown land (background), grey stone, green grass and trees, blue water, dark brown paths worn in by the people - Pixel-smooth scrolling of the view with the cursor keys, using the VIC-II fine-scroll registers and a double-buffered coarse shift -- 16 people as white dots (one multicolour pixel each), spread over the world, blocked by water and stone; only those in view are drawn +- 16 people as white dots (one multicolour pixel each), spread over the world, blocked by water and stone; only those in view are drawn (since M7: 1-255 people, + and - while running) - Two bitmap buffers flipped once per update; only the bytes under people are restored and redrawn between scroll steps - SPACE generates a new world - A 5-line text status area below a 20-row map, using a raster split: the chosen person's number, name, sex and scores @@ -88,31 +89,32 @@ Acceptance criteria: Capabilities: smooth-animation -### R2 - 16 moving people (must) +### R2 - Moving people, 1 to 255 (must) -16 people, each a single white multicolour pixel, are spread over the world and move on their own. Water and stone block them: they walk only on land, grass, trees and paths. People inside the view are drawn; others keep moving unseen. +A new world starts with 16 people, each a single white multicolour pixel, spread over the world; they move on their own. Water and stone block them: they walk only on land, grass, trees and paths. People inside the view are drawn; others keep moving unseen. While the program runs, + adds a person (a new name, sex and scores, on a random walkable spot) and - removes the last one; there are always 1 to 255 people. Held, + and - repeat. Each person steps every 8 frames however many people there are; with many people the picture updates less often instead (R3). Acceptance criteria: -- [R2.1] Scrolling around the world shows 16 white dots in total -- [R2.2] Each visible dot moves at least once per second +- [R2.1] Scrolling around a new world shows 16 white dots in total +- [R2.2] Each visible dot moves at least once per second, also with 255 people - [R2.3] No dot ever enters a blue (water) or grey (stone) pixel +- [R2.4] + adds one person (up to 255) and - removes the last one (down to 1); held, they repeat; the status line shows the new number of people (R8.2) and the new person's dot appears and moves Capabilities: smooth-animation ### R3 - Flicker-free double buffering, partial redraw (must) -While the view is still, people are drawn into the hidden bitmap buffer, which is then flipped into view during vertical blank. While the view scrolls, the hidden buffer is being rebuilt for the next scroll step, so people are restored and drawn in the shown buffer during vertical blank, before the first map line, and the rebuilt buffer is flipped in at the scroll step. Each update restores only the bitmap bytes under people at their previous positions in that buffer and draws them at their new positions; apart from the scroll rebuild, the rest of the map is never redrawn. +People are drawn only into the hidden bitmap buffer, never into the shown one, and the hidden buffer is flipped into view during vertical blank. While the view scrolls, the hidden buffer is rebuilt for the next scroll step; once it is complete the people are drawn into it, and it is flipped in at the scroll step. Each update restores only the bitmap bytes under people at their previous positions in that buffer and draws them at their new positions; apart from the scroll rebuild and changed path cells, the rest of the map is never redrawn. (Since M7; before, people were drawn into the shown buffer during vertical blank while a rebuild ran, which does not scale beyond about 16 people.) With up to about 64 people every frame is a new picture; with more, the main loop takes longer than a frame and the picture and the scroll update every 2nd to 4th frame, while people keep their walking speed. Acceptance criteria: - [R3.1] No flicker or tearing of the dots is visible in VICE at normal speed - [R3.2] After 5 minutes of running and scrolling, the map has no leftover white trails or damaged terrain -- [R3.3] A people update (restore, draw, flip) completes within one NTSC frame +- [R3.3] With 16 people a people update (restore, draw, flip) completes within one NTSC frame; with more people the vertical blank work still ends before the first map line, and people keep their speed Capabilities: smooth-animation, raster-interrupts ### R4 - New world on SPACE (must) -Pressing SPACE generates and shows a different world, with the 16 people placed on it. +Pressing SPACE generates and shows a different world, with 16 people placed on it (however many there were before). Acceptance criteria: - [R4.1] Pressing SPACE replaces the world with a visibly different one @@ -158,12 +160,12 @@ Capabilities: smooth-animation ### R8 - People's attributes (must) -Each of the 16 people is male or female (at random, 50/50) and has a random name of two or three syllables from a male or female syllable list (up to 10 letters), and six scores, as in D&D: strength, dexterity, constitution, intelligence, wisdom and charisma. Each score is rolled with three six-sided dice (3-18) when a world is made, and stored as one byte. For now the scores are only shown; they do not change how people move. The status lines show one person at a time: `P01 ALDRIC M` and `STR12 DEX09 CON15 INT10 WIS08 CHA13`. Each press of P shows the next person (after 16 comes 1); holding P does not repeat. The chosen person's dot blinks on the map (left out for 16 of every 32 frames) so it can be found. SPACE rolls new names, sexes and scores for the new world and shows person 1. +Each person is male or female (at random, 50/50) and has a random name of two or three syllables from a male or female syllable list (up to 10 letters), and six scores, as in D&D: strength, dexterity, constitution, intelligence, wisdom and charisma. Each score is rolled with three six-sided dice (3-18) when a world is made, and stored as one byte. For now the scores are only shown; they do not change how people move. The status lines show one person at a time: `P001/016 ALDRIC M` (person number / number of people, since M7) and `STR12 DEX09 CON15 INT10 WIS08 CHA13`. Each press of P shows the next person (after the last comes 1); holding P does not repeat. If the shown person is removed with -, the new last person is shown. The chosen person's dot blinks on the map (left out for 16 of every 32 frames) so it can be found. SPACE rolls new names, sexes and scores for the new world and shows person 1. Acceptance criteria: - [R8.1] Every person has six scores from 3 to 18, rolled 3d6 when a world is made; SPACE rolls new ones -- [R8.2] Status line 1 shows the chosen person's number (1-16), name and M or F; line 2 their six scores, labelled STR, DEX, CON, INT, WIS and CHA; person 1 is shown after a new world -- [R8.3] Each press of P shows the next person, after 16 comes 1; a held P counts once +- [R8.2] Status line 1 shows the chosen person's number and the number of people (`P001/016`), name and M or F; line 2 their six scores, labelled STR, DEX, CON, INT, WIS and CHA; person 1 is shown after a new world +- [R8.3] Each press of P shows the next person, after the last comes 1; a held P counts once - [R8.4] The chosen person's dot blinks about twice a second, wherever they are in the view, without disturbing the map or the other dots - [R8.5] The scores do not change how people move - [R8.6] Every person is male or female at random and has a random name of 2-3 syllables (up to 10 letters) from the male or female syllable list; SPACE gives new ones @@ -176,14 +178,14 @@ Capabilities: keyboard-input | Topic | Decision | Source | |---|---|---| -| Controls | Cursor keys scroll the view. On a real C64 these are CRSR down/right, plus SHIFT for up/left; the keyboard matrix is read directly so a key held down scrolls continuously. VICE maps the PC arrow keys to them. SPACE generates a new world. P shows the next person's scores (R8; a letter key, chosen by the user: the C64 has no Tab key). Known limitation (accepted by the user, 2026-12-03): SHIFT applies to both cursor keys, so only the Right + Down and Left + Up diagonals work; Up + Right and Down + Left come out as Up + Left (VICE sends the PC Up and Left arrows as SHIFT + CRSR). | decided by user | +| Controls | Cursor keys scroll the view. On a real C64 these are CRSR down/right, plus SHIFT for up/left; the keyboard matrix is read directly so a key held down scrolls continuously. VICE maps the PC arrow keys to them. SPACE generates a new world. P shows the next person's scores (R8; a letter key, chosen by the user: the C64 has no Tab key). + adds a person and - removes the last one (R2, M7; held, they repeat after half a second, about 12 times a second). Known limitation (accepted by the user, 2026-12-03): SHIFT applies to both cursor keys, so only the Right + Down and Left + Up diagonals work; Up + Right and Down + Left come out as Up + Left (VICE sends the PC Up and Left arrows as SHIFT + CRSR). | decided by user | | Visuals | Multicolour bitmap mode (160x200, double-wide pixels) for a 38-column map area 20 cell rows high, smooth-scrolled; below it a raster split to a fixed 5-row, 40-column text status area in the upper-case ROM font, white on light brown. 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) is the shared background colour; white is the colour-RAM colour in every cell, so people can be drawn anywhere without colour clash and colour RAM never needs scrolling. The two screen-RAM colours of each 4x8 cell come from grey (stone), green (grass and trees), blue (water) and dark brown (paths). The world is stored as one tile byte per 4x8 cell; each tile is drawn from a small set of 8-byte pixel patterns (including edge and corner patterns) so shorelines look natural. | decided by user | | Sound | None in the first release. | practical default | | 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 (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 (white), which is also the status text colour. Program, tables and variables (world tiles, people and their scores) lie below $4000; the 4,000 walk counts (R7) use the free RAM at $C000-$CF9F. | 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 with up to about 64 people (measured in M7: 128 people take 2 frames per main-loop pass, 255 take 4; people keep their speed, M7). 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 (white), which is also the status text colour. Program, tables and variables (world tiles) lie below $4000; the 4,000 walk counts (R7) use the free RAM at $C000-$CF9F. The people's tables (since M7) are one 256-byte page per field, indexed by person 0-254, in the RAM the video banks leave free: positions $4C00-$4FFF, direction, sex and the six scores $5800-$5FFF, the saved bytes under the dots of both buffers $8C00-$91FF, and the ten name letters $9200-$9BFF (the VIC sees the character ROM at $9000-$9FFF in bank 2, so the CPU RAM there is free). | 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 | diff --git a/docs/verification-status.md b/docs/verification-status.md index dea0425..f4dc12c 100644 --- a/docs/verification-status.md +++ b/docs/verification-status.md @@ -23,9 +23,20 @@ manual = `pending`, `confirmed by user ()`, `problem reported ():