浏览代码

M5.2: worn paths from walk counts

Every cell counts the steps people take into it; at 128 land, grass or
trees become a dark brown path tile, below 64 it turns back, and every
count loses one each 60 seconds. Changed cells are redrawn in the hidden
buffer only, keeping the people's dots. A rebuild in progress restarts
only when a cell is new to it (restarting every frame stalled the scroll).

Checks: new tools/check-paths.ps1 (PATH_TEST build); check-scroll compares
buffers with the world saved at each snapshot and has -PathTest;
check-world tile IDs updated for the path tiles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main
父节点
当前提交
dcb213e821
共有 13 个文件被更改,包括 719 次插入 和 35 次删除
  1. +1
    -1
      docs/manual-tests.md
  2. +1
    -1
      docs/milestones.md
  3. +7
    -1
      docs/verification-status.md
  4. +3
    -3
      project.json
  5. +4
    -0
      src/main.s
  6. +379
    -0
      src/paths.inc
  7. +1
    -9
      src/people.inc
  8. +11
    -0
      src/tiles.inc
  9. +237
    -0
      tools/check-paths.ps1
  10. +51
    -7
      tools/check-scroll.ps1
  11. +6
    -5
      tools/check-world.ps1
  12. +10
    -0
      tools/lib.ps1
  13. +8
    -8
      tools/run.ps1

+ 1
- 1
docs/manual-tests.md 查看文件

@@ -301,7 +301,7 @@ Verifies: R1 (R1.2, R1.3)
### MT5.2: Worn paths (c64)

Setup: VICE x64sc, NTSC (-ntsc), pepto-pal palette, warp off.
Start (test build: a path at 8 steps, gone again below 4, counts drop quickly):
Start (test build: a path at 4 steps, gone again below 2, every count one less each 400 frames):
`pwsh -File tools/run.ps1 -Target c64 -PathTest`
The normal build (`pwsh -File tools/run.ps1 -Target c64`) uses 128 and 64 with one count less
every 60 seconds, so paths there take many minutes of walking to appear.


+ 1
- 1
docs/milestones.md 查看文件

@@ -78,6 +78,6 @@ Requirements: R7, R1, R2, R3, R5
| Task | Description | Requirements | Buildable outcome | Completion check |
|---|---|---|---|---|
| M5.1 | Remove road generation: the world has land, grass and trees, stone and water only; tools/check-world.ps1 fails on any road or bridge tile. | R1 | Worlds without roads | `pwsh -File tools/check-world.ps1 -Runs 10`; manual test MT5.1 |
| M5.2 | Worn paths: a walk count per cell (4,000 bytes), +1 when a person steps into a cell, -1 for every cell every 60 seconds (10 cells every 9 frames); at 128 a land, grass or tree cell becomes a path tile (dark brown patch, one per terrain so it can turn back), below 64 it turns back. Changed cells are redrawn in each buffer while it is hidden (people's dots and saved bytes kept), so the shown map never tears; a buffer in the middle of a rebuild restarts it in full. A test build (PATH_TEST: path at 8, back below 4, fast decay) makes it checkable. | R7, R2, R3, R5 | Busy cells turn into paths, unused paths fade | `pwsh -File tools/check-paths.ps1`, `tools/check-scroll.ps1 -Long`; manual test MT5.2 |
| M5.2 | Worn paths: a walk count per cell (4,000 bytes), +1 when a person steps into a cell, -1 for every cell every 60 seconds (10 cells every 9 frames); at 128 a land, grass or tree cell becomes a path tile (dark brown patch, one per terrain so it can turn back), below 64 it turns back. Changed cells are redrawn in each buffer while it is hidden (people's dots and saved bytes kept), so the shown map never tears; a buffer in the middle of a rebuild restarts it in full. A test build (PATH_TEST: path at 4, back below 2, one count less every 400 frames) makes it checkable. | R7, R2, R3, R5 | Busy cells turn into paths, unused paths fade | `pwsh -File tools/check-paths.ps1`, `tools/check-scroll.ps1 -Long`, `tools/check-scroll.ps1 -Long -PathTest`; manual test MT5.2 |

Manual verification: see docs/manual-tests.md section M5.

+ 7
- 1
docs/verification-status.md 查看文件

@@ -20,10 +20,16 @@ manual = `pending`, `confirmed by user (<date>)`, `problem reported (<date>): <n
| M3.4 Check that people stay aligned with the terrain over long scrolling runs; measure the frame budget with a border-colour timing bar. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`: 2,130 frames, update done by line 21; `pwsh -File tools/check-keys.ps1`: 8 of 8; `pwsh -File tools/check-split.ps1`: 962 splits, digits 241/241; `pwsh -File tools/check-scroll.ps1 -Long`: 4 of 4, tour 23,195 frames (about 6.4 minutes NTSC) with 21 stops byte-exact, people update done by line 45 at the latest; timing build `--asm-define TIMING_BAR` built and screenshot in VICE) | confirmed by user (2026-12-03), with the light brown background (colour 8, pepto-pal palette); dots visible |
| 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. | passed (2026-12-03, `pwsh -File tools/build.ps1` (4,647 bytes); `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1 -Runs 10`: 10 of 10 worlds, every 40x20 view with 3+ terrain kinds, map ready 7.1-7.3 s after power-on (generation 4.0-4.1 s), mix spread land 14 / grass-trees 8 / water 13 / stone 16 percentage points; `pwsh -File tools/check-people.ps1`: 1,919 frames, 0 missed, update done by line 20; `pwsh -File tools/check-keys.ps1`: 8 of 8; `pwsh -File tools/check-split.ps1`: 734 splits, digits right after 183 of 183 updates; `pwsh -File tools/check-scroll.ps1 -Long`: 4 of 4, tour 22,966 frames with 21 stops byte-exact, 116 stall frames in 15,216 moving frames; fix for walking on bridge water, 2026-12-03: `pwsh -File tools/build.ps1` (4,683 bytes); `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1` and `-Runs 10`: 10 of 10; `pwsh -File tools/check-keys.ps1`: 8 of 8; `pwsh -File tools/check-split.ps1`; `pwsh -File tools/check-scroll.ps1`: 3 of 3; `pwsh -File tools/check-people.ps1 -Cycles 300000000`: 17,119 frames, 1,408 person-frames on bridges, no dot on a blue or grey pixel; the same check fails on the old code (person 9 on a blue pixel of bridge tile 20); fix for the scroll that did not start, 2026-12-03: `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-keys.ps1`: 8 of 8; `pwsh -File tools/check-split.ps1`; `pwsh -File tools/check-scroll.ps1`: 4 of 4, new restart scenario 12 stall frames over four starts from a cell edge (the same scenario fails on the old code: 1,166 frames held left without moving); `pwsh -File tools/check-people.ps1`: 1,899 frames, 816 person-frames on bridges, pass; `pwsh -File tools/check-scroll.ps1 -Long`: 5 of 5, tour 22,967 frames with 21 stops byte-exact, 111 stall frames in 15,216 moving frames) | confirmed by user (2026-12-03), after two fixes: people walked on the blue water pixels of bridges, and the scroll sometimes did not start from rest on a cell edge |
| M5.1 Remove road generation: the world has land, grass and trees, stone and water only; tools/check-world.ps1 fails on any road or bridge tile. | passed (2026-12-03, `pwsh -File tools/build.ps1` (4,581 bytes); `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1` and `-Runs 10`: 10 of 10 worlds, no road or bridge cells; `pwsh -File tools/check-people.ps1`; `pwsh -File tools/check-keys.ps1`: 8 of 8; `pwsh -File tools/check-split.ps1`; `pwsh -File tools/check-scroll.ps1`: 4 of 4) | pending |
| M5.2 Worn paths: walk count per cell, path at 128, back below 64, one count less every 60 seconds. | not run - in progress | pending |
| M5.2 Worn paths: walk count per cell, path at 128, back below 64, one count less every 60 seconds. | passed (2026-12-03, `pwsh -File tools/build.ps1` (5,257 bytes); `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`: 1,910 frames; `pwsh -File tools/check-keys.ps1`: 8 of 8; `pwsh -File tools/check-split.ps1`; `pwsh -File tools/check-paths.ps1` (test build): 27 paths appeared, 4 faded, both buffers match the current world plus dots; `pwsh -File tools/check-scroll.ps1 -Long`: 5 of 5, tour 22,967 frames, 21 stops byte-exact, 95 stall frames, 6 paths appeared in the normal build during the tour; `pwsh -File tools/check-scroll.ps1 -Long -PathTest`: 5 of 5, tour 70 paths appeared and 38 faded while scrolling, no store into the shown buffer while displayed, 472 stall frames in 15,216 moving frames) | pending |

## Notes

- 2026-12-03 (M5.2 worn paths):
- src/paths.inc: walk counts (4,000 bytes, below VIC bank 1), path tiles PATH_LAND/PATH_GRASS/PATH_TREE in src/tiles.inc (dark brown patch, colour 9), decay sweep, an 8-entry change queue, and redraw of a changed cell in the hidden buffer only (dots and saved bytes kept). A buffer in the middle of a rebuild restarts it in full.
- Found by `check-scroll.ps1 -Long`: the first version restarted that rebuild every frame while a queued cell still waited for the shown buffer, so the rebuild never finished and the scroll stopped (6,826 stall frames, 6,747 abandoned rebuilds in the tour). It now restarts only when a cell is new to that buffer.
- The test build (`tools/run.ps1 -PathTest`, `--asm-define PATH_TEST`) uses a path at 4 steps, back below 2, one count less every 400 frames; at 8 / 4 / 200 frames paths almost never appeared (1 in 90 s).
- tools/check-scroll.ps1 now saves the world and change queue with every buffer save and compares buffers with that world, skipping cells still queued for the buffer: paths appear in the normal build during the 6-minute tour (land and path share the colour byte $99, so only bitmap bytes differed). New -PathTest switch runs it on the test build. tools/check-world.ps1 tile IDs updated for the path tiles (TILE_COUNT 26). New tools/check-paths.ps1.

- 2026-12-03 (spec change, approved by the user: worn paths instead of roads, new milestone M5):
- The user asked to track where people walk and turn a cell into a path when its count reaches 128, with counts going down by one now and then. Choices made by the user: a dark brown worn patch (not black road pieces), a path turns back below 64, one count less every 60 seconds, and no generated roads ("remove their creation").
- The unfinished M4.2 work (random winding roads with short bridges) was dropped before it was committed. It passed every check except the 5-minute scroll tour, which logged only 8,173 frames (cause not investigated). Its diff was kept outside the repository as a patch file.


+ 3
- 3
project.json 查看文件

@@ -664,7 +664,7 @@
},
{
"id": "M5.2",
"text": "Worn paths: a walk count per cell (4,000 bytes), +1 when a person steps into a cell, -1 for every cell every 60 seconds (10 cells every 9 frames); at 128 a land, grass or tree cell becomes a path tile (dark brown patch, one per terrain so it can turn back), below 64 it turns back. Changed cells are redrawn in each buffer while it is hidden (people's dots and saved bytes kept), so the shown map never tears; a buffer in the middle of a rebuild restarts it in full. A test build (PATH_TEST: path at 8, back below 4, fast decay) makes it checkable.",
"text": "Worn paths: a walk count per cell (4,000 bytes), +1 when a person steps into a cell, -1 for every cell every 60 seconds (10 cells every 9 frames); at 128 a land, grass or tree cell becomes a path tile (dark brown patch, one per terrain so it can turn back), below 64 it turns back. Changed cells are redrawn in each buffer while it is hidden (people's dots and saved bytes kept), so the shown map never tears; a buffer in the middle of a rebuild restarts it in full. A test build (PATH_TEST: path at 4, back below 2, one count less every 400 frames) makes it checkable.",
"requirements": [
"R7",
"R2",
@@ -672,7 +672,7 @@
"R5"
],
"outcome": "Busy cells turn into paths, unused paths fade",
"check": "pwsh -File tools/check-paths.ps1; tools/check-scroll.ps1 -Long; manual test MT5.2"
"check": "pwsh -File tools/check-paths.ps1; tools/check-scroll.ps1 -Long; tools/check-scroll.ps1 -Long -PathTest; manual test MT5.2"
}
],
"manualTests": [
@@ -697,7 +697,7 @@
"id": "MT5.2",
"title": "Worn paths",
"target": "c64",
"setup": "VICE x64sc, NTSC (-ntsc), pepto-pal palette, warp off. The test build (pwsh -File tools/run.ps1 -PathTest) makes paths at 8 steps and fades them below 4 within seconds; the normal build needs minutes of walking.",
"setup": "VICE x64sc, NTSC (-ntsc), pepto-pal palette, warp off. The test build (pwsh -File tools/run.ps1 -PathTest) makes paths at 4 steps and fades them below 2 (one count less every 400 frames, about 7 seconds); the normal build needs minutes of walking.",
"steps": [
"Start the test build and watch the first view for a minute without keys.",
"Scroll around while paths appear and fade.",


+ 4
- 0
src/main.s 查看文件

@@ -116,6 +116,8 @@ keys_read: ; check hook: scroll_dx and scroll_dy are set
jsr update_status
@rebuild:
jsr move_people ; after the status count: it counts the drawn dots
jsr decay_counts ; worn paths: counts fade, paths turn back
jsr apply_changes ; changed cells into the hidden buffer
TIMING_BAR_COLOR BAR_REBUILD
jsr choose_rebuild_target
jsr restore_hidden_people
@@ -147,6 +149,7 @@ rebuild_map:
sta VIC_CTRL1

jsr generate_world_from_timer
jsr reset_paths
jsr place_people
lda #0
sta visible ; buffer A is shown first
@@ -254,3 +257,4 @@ hidden: .res 1 ; the other buffer: visible EOR 1
.include "keys.inc"
.include "status.inc"
.include "scroll.inc"
.include "paths.inc"

+ 379
- 0
src/paths.inc 查看文件

@@ -0,0 +1,379 @@
; Worn paths (M5.2, R7).
;
; Every world cell has a walk count (walk_counts, laid out like world_tiles).
; A person stepping into a cell adds one (up to 255); every count loses one
; each 60 seconds (DECAY_CELLS cells every DECAY_FRAMES frames: 4000 cells in
; 3600 frames). A land, grass or tree cell whose count reaches PATH_ON becomes
; the matching path tile; a path whose count falls below PATH_OFF turns back.
;
; A changed tile is written to world_tiles at once and queued. Each frame the
; main loop redraws queued cells in the hidden buffer only, so the shown map
; is never written while it is displayed; a cell waits in the queue until both
; buffers have it. The redraw keeps the people's dots in the cell (a dot is the
; only %11 pixel) and updates the saved bytes under them, so restoring a dot
; later puts back the new tile. If the hidden buffer is in the middle of a
; rebuild, the rebuild starts again and draws every cell (its skip test
; compares world tiles, which have changed underneath it).
;
; The test build (PATH_TEST, tools/run.ps1 -PathTest) uses small thresholds
; and fast decay so paths can be watched and checked within a minute.
.ifdef PATH_TEST
PATH_ON = 4
PATH_OFF = 2
DECAY_FRAMES = 1
DECAY_CELLS = 10 ; every count loses one each 400 frames
.else
PATH_ON = 128
PATH_OFF = 64
DECAY_FRAMES = 9
DECAY_CELLS = 10 ; every count loses one each 3600 frames
.endif
CHANGE_SLOTS = 8

cnt_ptr = $56 ; walk count row
ap_bmp = $58 ; cell being redrawn: bitmap
ap_scr = $5A ; screen RAM

.segment "CODE"
; New world: all counts 0, no queued changes, decay from the first cell.
reset_paths:
lda #<walk_counts
sta cnt_ptr
lda #>walk_counts
sta cnt_ptr+1
ldx #16 ; pages
lda #0
tay
@clear: sta (cnt_ptr),y ; clears whole pages: walk_counts is followed
iny ; by paths_pad so the last page is its own
bne @clear
inc cnt_ptr+1
dex
bne @clear
sta chg_count
sta decay_cx
sta decay_cy
lda #DECAY_FRAMES
sta decay_wait
rts

; X = world row. cnt_ptr = that row of walk_counts. Preserves X and Y.
point_counts:
lda world_row_low,x
clc
adc #<(walk_counts - world_tiles)
sta cnt_ptr
lda world_row_high,x
adc #>(walk_counts - world_tiles)
sta cnt_ptr+1
rts

; X = person: move it to the candidate position; a step into another cell
; counts for that cell.
store_step:
lda cand_cx
eor people_cx,x
sta new_cell
lda cand_cy
eor people_cy,x
ora new_cell
sta new_cell
lda cand_cx
sta people_cx,x
lda cand_sx
sta people_sx,x
lda cand_cy
sta people_cy,x
lda cand_sy
sta people_sy,x
lda new_cell
bne count_step
rts

; A person stepped into cell (cand_cx, cand_cy).
count_step:
ldx cand_cy
ldy cand_cx
jsr point_counts
lda (cnt_ptr),y
cmp #255
beq @full
clc
adc #1
sta (cnt_ptr),y
@full: cmp #PATH_ON
bcc @done
jsr point_world_row
lda (world_ptr),y
cmp #STONE ; land, grass or trees (paths are above STONE)
bcs @done
clc
adc #PATH_LAND - LAND
jmp change_tile
@done: rts

; Main loop, every frame: every DECAY_FRAMES frames, the next DECAY_CELLS
; counts lose one; a path whose count is below PATH_OFF turns back.
decay_counts:
dec decay_wait
bne @done
lda #DECAY_FRAMES
sta decay_wait
lda #DECAY_CELLS
sta decay_left
@cell: ldx decay_cy
ldy decay_cx
jsr point_counts
lda (cnt_ptr),y
beq @check
sec
sbc #1
sta (cnt_ptr),y
@check: cmp #PATH_OFF
bcs @next
jsr point_world_row
lda (world_ptr),y
cmp #PATH_LAND
bcc @next
cmp #PATH_TREE + 1
bcs @next
sec
sbc #PATH_LAND - LAND
jsr change_tile
@next: inc decay_cx
lda decay_cx
cmp #WORLD_WIDTH
bne @more
lda #0
sta decay_cx
inc decay_cy
lda decay_cy
cmp #WORLD_HEIGHT
bne @more
lda #0
sta decay_cy
@more: dec decay_left
bne @cell
@done: rts

; A = new tile for the cell at column Y of the world row world_ptr points
; to, X = its row. Store it and queue the cell for both buffers. If the
; queue is full nothing changes; the count is checked again next time.
change_tile:
sta chg_tile
stx chg_ty
ldx chg_count
cpx #CHANGE_SLOTS
bcs change_full
lda chg_tile
sta (world_ptr),y
path_changed: ; check hook: A = new tile, Y = column
tya
sta chg_cx,x
lda chg_ty
sta chg_cy,x
lda #0
sta chg_done,x
inc chg_count
change_full:
rts

; Main loop, before choose_rebuild_target: bring the hidden buffer up to
; date with the queued cells, then drop cells that both buffers have.
apply_changes:
lda chg_count
bne @some
rts
@some: ldx hidden
stx ap_buf
lda buffer_bit,x
sta ap_bit
lda buf_ready,x
bne @ready
lda #0 ; being rebuilt: if a cell is new to it, restart
sta ap_index ; the rebuild, drawing every cell (only then:
ldy chg_count ; restarting every frame would never finish it)
@mark: dey
bmi @marked
lda chg_done,y
and ap_bit
bne @mark
lda chg_done,y
ora ap_bit
sta chg_done,y
inc ap_index
bne @mark
@marked:
lda ap_index
beq @drop
lda buf_cx,x
sta rb_tx
lda buf_cy,x
sta rb_ty
jsr start_rebuild ; buf_ready = 0: no skipping, no saved bytes
jmp @drop
@ready: ldy #0
@entry: cpy chg_count
beq @drop
lda chg_done,y
and ap_bit
bne @have
sty ap_index
jsr redraw_cell
ldy ap_index
lda chg_done,y
ora ap_bit
sta chg_done,y
@have: iny
bne @entry
@drop: ldx #0 ; keep the entries one buffer still lacks
ldy #0
@keep: cpx chg_count
beq @kept
lda chg_done,x
cmp #3
beq @gone
lda chg_cx,x
sta chg_cx,y
lda chg_cy,x
sta chg_cy,y
lda chg_done,x
sta chg_done,y
iny
@gone: inx
bne @keep
@kept: sty chg_count
rts

; Redraw queued cell Y in buffer ap_buf (complete, hidden) if it lies inside
; the buffer: colour, eight bitmap bytes with the dots kept, and the saved
; bytes of the dots in the cell.
redraw_cell:
ldx ap_buf
lda chg_cx,y
sec
sbc buf_cx,x
cmp #MAP_COLS_DRAWN
bcs @out
sta ap_col
lda chg_cy,y
sec
sbc buf_cy,x
cmp buf_rows,x
bcc @in
@out: rts
@in: sta ap_row
lda chg_cx,y ; the cell's tile now
sta ap_wx
ldx chg_cy,y
ldy ap_wx
jsr point_world_row
lda (world_ptr),y
sta ap_tile
ldy ap_row ; screen RAM colour
ldx ap_buf
lda screen_row_low,y
clc
adc ap_col
sta ap_scr
lda screen_row_high,y
adc buffer_screen_high,x
sta ap_scr+1
ldx ap_tile
lda tile_colors,x
ldy #0
sta (ap_scr),y
lda tile_times8,x
sta ap_pat
lda #0 ; ap_bmp = row base + col * 8, in buffer ap_buf
sta ap_bmp+1
lda ap_col
asl a
rol ap_bmp+1
asl a
rol ap_bmp+1
asl a
rol ap_bmp+1
ldy ap_row
clc
adc bitmap_row_low,y
sta ap_bmp
lda ap_bmp+1
adc bitmap_row_high,y
ldx ap_buf
clc
adc buffer_bitmap_offsets,x
sta ap_bmp+1
ldy #7
@byte: lda (ap_bmp),y ; dots: the %11 pixels (no tile uses %11)
sta ap_cur
lsr a
and ap_cur
and #$55
sta ap_dots
asl a
ora ap_dots
sta ap_dots
tya
clc
adc ap_pat
tax
lda tile_patterns,x
ora ap_dots
sta (ap_bmp),y
dey
bpl @byte
ldx ap_buf ; saved bytes under dots in this cell
lda list_starts,x
sta ap_first
clc
adc drawn_count,x
tax
@saved: cpx ap_first
beq @done
dex
lda drawn_high,x
cmp ap_bmp+1
bne @saved
lda drawn_low,x
sec
sbc ap_bmp
cmp #8 ; cells never straddle a page
bcs @saved
clc
adc ap_pat
tay
lda tile_patterns,y
sta drawn_byte,x
jmp @saved
@done: rts

.segment "RODATA"
buffer_bit: .byte 1, 2

.segment "BSS"
chg_count: .res 1
new_cell: .res 1
chg_tile: .res 1
chg_ty: .res 1
chg_cx: .res CHANGE_SLOTS
chg_cy: .res CHANGE_SLOTS
chg_done: .res CHANGE_SLOTS ; bit 0: buffer A has it, bit 1: buffer B
decay_cx: .res 1
decay_cy: .res 1
decay_wait: .res 1
decay_left: .res 1
ap_buf: .res 1
ap_bit: .res 1
ap_index: .res 1
ap_col: .res 1
ap_row: .res 1
ap_wx: .res 1
ap_tile: .res 1
ap_pat: .res 1
ap_cur: .res 1
ap_dots: .res 1
ap_first: .res 1
walk_counts: .res WORLD_WIDTH * WORLD_HEIGHT
paths_pad: .res 16 * 256 - WORLD_WIDTH * WORLD_HEIGHT ; reset_paths clears whole pages
.assert * <= SCREEN_A, lderror, "Walk counts must fit below VIC bank 1"

+ 1
- 9
src/people.inc 查看文件

@@ -154,15 +154,7 @@ move_person:
@check: jsr candidate_blocked
bcs @blocked
ldx person
lda cand_cx
sta people_cx,x
lda cand_sx
sta people_sx,x
lda cand_cy
sta people_cy,x
lda cand_sy
sta people_sy,x
rts
jmp store_step ; paths.inc: also counts a step into a new cell
@blocked:
ldx person
lda tries


+ 11
- 0
src/tiles.inc 查看文件

@@ -22,6 +22,9 @@
ROAD_SE
ROAD_SW
ROAD_X
PATH_LAND ; worn paths (M5.2), one per terrain they replace
PATH_GRASS
PATH_TREE
BRIDGE_H
BRIDGE_V
BRIDGE_X
@@ -50,11 +53,16 @@ tile_patterns:
.byte $00,$00,$00,$15,$15,$14,$14,$14 ; south-east bend
.byte $00,$00,$00,$54,$54,$14,$14,$14 ; south-west bend
.byte $14,$14,$14,$55,$55,$14,$14,$14 ; crossing
.repeat 3 ; worn path: dark brown specks (colour 9)
.byte $15,$40,$51,$04,$45,$10,$54,$01
.endrepeat
.byte $55,$55,$55,$AA,$AA,$55,$55,$55 ; east-west bridge: water %01, road %10
.byte $69,$69,$69,$69,$69,$69,$69,$69 ; north-south bridge
.byte $69,$69,$69,$AA,$AA,$69,$69,$69 ; bridge crossing
.assert * - tile_patterns = TILE_COUNT * 8, error, "Tile bitmap table size"
.assert TILE_COUNT <= 32, error, "Tile bitmap offsets must fit in X"
.assert PATH_GRASS - PATH_LAND = GRASS - LAND, error, "Path tiles follow LAND, GRASS, TREE"
.assert PATH_TREE - PATH_LAND = TREE - LAND, error, "Path tiles follow LAND, GRASS, TREE"

; Tiles whose eight bitmap bytes are all the same: that byte, else $FF.
; The scroll rebuild stores these without reading the pattern table.
@@ -80,6 +88,9 @@ tile_colors:
.byte $09
.endrepeat
.repeat 3
.byte $99
.endrepeat
.repeat 3
.byte $60
.endrepeat
.assert * - tile_colors = TILE_COUNT, error, "Tile colour table size"

+ 237
- 0
tools/check-paths.ps1 查看文件

@@ -0,0 +1,237 @@
<#
.SYNOPSIS
Run the worn-paths test build headless in VICE and check walk counts, path tiles and
both bitmap buffers (R7, M5.2).

.DESCRIPTION
Builds the PATH_TEST variant (build/<name>-pathtest.prg: a path at 4 steps, back below 2,
every count one less each 400 frames; see src/paths.inc) and runs it in x64sc (NTSC, warp,
private config) with no keys held. Monitor tracepoints:
- at smoke_ready: save the generated world;
- at path_changed: log the new tile (register A), once per path that appears or fades;
- at people_moved when move_frame is 0 (every 256 frames, each save overwriting the
last): save the world, the walk counts, the change queue, both bitmaps and screens,
the buffer origins and the people's saved-byte lists.
Checks on the last save:
- tiles: every cell is its generated tile, or the path tile for it (land, grass, trees
only); water and stone have count 0 and never change
- counts and paths agree: no land, grass or tree cell has count PATH_ON or more, no path
has count below PATH_OFF (unless the change queue was full)
- both buffers: every drawn cell (39 columns, 20 rows) has the colour and bitmap of its
current tile, except cells still queued for that buffer; the only other pixels are
people's dots (%11) in bytes listed in the buffer's saved-byte list, whose oldest entry
holds the clean tile byte
- paths appeared and faded during the run (path_changed hits with a path tile and with a
terrain tile)
Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.

.EXAMPLE
pwsh -File tools/check-paths.ps1
#>
[CmdletBinding()]
param(
[int]$Cycles = 90000000,
[switch]$NoBuild,
[int]$TimeoutSeconds = 400
)
. (Join-Path $PSScriptRoot 'lib.ps1')

$width = 80; $height = 50
# PATH_TEST thresholds: the first PATH_ON / PATH_OFF in src/paths.inc (the .ifdef PATH_TEST branch)
$pathsSrc = Get-Content -LiteralPath (Get-RepoPath 'src/paths.inc') -Raw
$PATH_ON = [int]([regex]::Match($pathsSrc, '(?m)^PATH_ON\s*=\s*(\d+)').Groups[1].Value)
$PATH_OFF = [int]([regex]::Match($pathsSrc, '(?m)^PATH_OFF\s*=\s*(\d+)').Groups[1].Value)
if ($PATH_ON -le 0 -or $PATH_OFF -le 0) { throw 'PATH_ON / PATH_OFF not found in src/paths.inc' }
$LAND = 0; $TREE = 2; $STONE = 3; $WATER_SE = 12
$CHANGE_SLOTS = 8

function Get-TileData {
$src = Get-Content -LiteralPath (Get-RepoPath 'src/tiles.inc') -Raw
$block = $src.Substring($src.IndexOf('tile_patterns:'))
$block = $block.Substring(0, $block.IndexOf('.assert * - tile_patterns'))
$patterns = [System.Collections.Generic.List[object]]::new()
$repeat = 1
foreach ($line in $block -split "`n") {
if ($line -match '^\s*\.repeat\s+(\d+)') { $repeat = [int]$Matches[1]; continue }
if ($line -match '^\s*\.endrepeat') { $repeat = 1; continue }
if ($line -match '^\s*\.byte\s+([^;\r\n]+)') {
$vals = @($Matches[1] -split ',' | ForEach-Object { [Convert]::ToByte($_.Trim().TrimStart('$'), 16) })
for ($r = 0; $r -lt $repeat; $r++) { $patterns.Add($vals) }
}
}
$colors = [System.Collections.Generic.List[byte]]::new()
$cblock = $src.Substring($src.IndexOf('tile_colors:'))
$cblock = $cblock.Substring(0, $cblock.IndexOf('.assert * - tile_colors'))
$repeat = 1
foreach ($line in $cblock -split "`n") {
if ($line -match '\.repeat\s+(\d+)') { $repeat = [int]$Matches[1]; continue }
if ($line -match '\.endrepeat') { $repeat = 1; continue }
if ($line -match '\.byte\s+([^;\r\n]+)') {
$vals = $Matches[1] -split ',' | ForEach-Object { [Convert]::ToByte($_.Trim().TrimStart('$'), 16) }
for ($r = 0; $r -lt $repeat; $r++) { foreach ($v in $vals) { $colors.Add($v) } }
}
}
$names = @([regex]::Matches(($src.Substring($src.IndexOf('.enum'), $src.IndexOf('.endenum') - $src.IndexOf('.enum'))), '(?m)^\s+([A-Z_]+)') | ForEach-Object { $_.Groups[1].Value })
@{ patterns = $patterns.ToArray(); colors = $colors.ToArray(); ids = @{} + (& { $h = @{}; for ($i = 0; $i -lt $names.Count; $i++) { $h[$names[$i]] = $i }; $h }) }
}

try {
$project = Get-ProjectConfig
$target = Get-ProjectTargets $project 'c64'
Set-TargetVariant $target 'PATH_TEST' 'pathtest'
if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} }
$emu = Get-ToolPath $project $target.emulator.binary
} catch [MissingToolException] {
Write-Host $_.Exception.Message -ForegroundColor Yellow
exit 2
}
$L = @{}
foreach ($line in Get-Content -LiteralPath (Get-RepoPath $target.build.labels)) {
$parts = $line -split '\s+'
if ($parts.Count -ge 3) { $L[$parts[2].TrimStart('.')] = [Convert]::ToInt32($parts[1], 16) }
}
foreach ($s in 'smoke_ready', 'people_moved', 'path_changed', 'world_tiles', 'walk_counts', 'chg_count', 'chg_done', 'move_frame',
'buf_cx', 'buf_rows', 'drawn_count', 'drawn_low', 'drawn_high', 'drawn_byte', 'list_starts') {
if (-not $L.ContainsKey($s)) { Write-Host "[FAIL] label $s not found" -ForegroundColor Red; exit 1 }
}
$tileData = Get-TileData
$ids = $tileData.ids
$PATH_LAND = $ids['PATH_LAND']; $PATH_TREE = $ids['PATH_TREE']

$dir = Get-RepoPath 'build/check-paths'
if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force }
New-Item -ItemType Directory -Force -Path $dir | Out-Null
$mon = [System.Collections.Generic.List[string]]::new()
$mon.Add('logname "monitor.log"'); $mon.Add('log on')
$n = 0
function Add-Trace([int]$Address, [string]$Command, [string]$Condition) {
$script:n++
$line = 'trace exec ${0:x4}' -f $Address
if ($Condition) { $line += " if $Condition" }
$mon.Add($line)
if ($Command) { $mon.Add(('command {0} "{1}"' -f $script:n, $Command)) }
}
$bsave = { param([string]$name, [int]$from, [int]$len) 'bsave \"{0}\" 0 {1:x4} {2:x4}' -f $name, $from, ($from + $len - 1) }
Add-Trace $L.smoke_ready (& $bsave 'start-world.bin' $L.world_tiles 4000) $null
Add-Trace $L.path_changed $null $null
$changeCheckpoint = $n
$every = '(@cpu:${0:x4} == $00)' -f $L.move_frame
Add-Trace $L.people_moved (& $bsave 'world.bin' $L.world_tiles 4000) $every
Add-Trace $L.people_moved (& $bsave 'counts.bin' $L.walk_counts 4000) $every
Add-Trace $L.people_moved (& $bsave 'queue.bin' $L.chg_count ($L.chg_done + $CHANGE_SLOTS - $L.chg_count)) $every
Add-Trace $L.people_moved (& $bsave 'bitmap-a.bin' 0x6000 6400) $every
Add-Trace $L.people_moved (& $bsave 'bitmap-b.bin' 0xA000 6400) $every
Add-Trace $L.people_moved (& $bsave 'screen-a.bin' 0x4000 800) $every
Add-Trace $L.people_moved (& $bsave 'screen-b.bin' 0x8000 800) $every
Add-Trace $L.people_moved (& $bsave 'bufs.bin' $L.buf_cx 8) $every
Add-Trace $L.people_moved (& $bsave 'counts2.bin' $L.drawn_count 2) $every
Add-Trace $L.people_moved (& $bsave 'lists.bin' $L.drawn_low 32) $every
Add-Trace $L.people_moved (& $bsave 'listh.bin' $L.drawn_high 32) $every
Add-Trace $L.people_moved (& $bsave 'listb.bin' $L.drawn_byte 32) $every
foreach ($row in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space') { Add-Trace $L[$row] 'r a = ff' $null }
Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''

$vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
$vargs += @('-limitcycles', [string]$Cycles, '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
$quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } }
Write-Host "[c64] running the PATH_TEST build headless for $Cycles cycles"
$p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
-RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true); Write-Host '[FAIL] VICE did not exit in time.' -ForegroundColor Red; exit 1 }

$read = { param($name) $f = Join-Path $dir $name; if (Test-Path -LiteralPath $f) { , [IO.File]::ReadAllBytes($f) } else { $null } }
$start = & $read 'start-world.bin'; $world = & $read 'world.bin'; $counts = & $read 'counts.bin'; $queue = & $read 'queue.bin'
if (-not $start -or -not $world -or -not $counts -or -not $queue) { Write-Host '[FAIL] the program did not reach the save points (smoke_ready, people_moved at move_frame 0).' -ForegroundColor Red; exit 1 }
$bitmaps = @((& $read 'bitmap-a.bin'), (& $read 'bitmap-b.bin')); $screens = @((& $read 'screen-a.bin'), (& $read 'screen-b.bin'))
$bufs = & $read 'bufs.bin'; $drawnCount = & $read 'counts2.bin'
$listLow = & $read 'lists.bin'; $listHigh = & $read 'listh.bin'; $listByte = & $read 'listb.bin'
$failures = [System.Collections.Generic.List[string]]::new()

# Change events: the trace's register line gives A = the new tile.
$logFile = @('monitor.log', 'vice.log') | ForEach-Object { Join-Path $dir $_ } | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
$appeared = 0; $faded = 0; $want = $false
foreach ($line in Get-Content -LiteralPath $logFile) {
if ($line -match "^#$changeCheckpoint \(Trace\s+exec") { $want = $true; continue }
if ($want -and $line -match '^\.C:.*\bA:([0-9A-Fa-f]{2})') {
$a = [Convert]::ToInt32($Matches[1], 16)
if ($a -ge $PATH_LAND -and $a -le $PATH_TREE) { $appeared++ } else { $faded++ }
$want = $false
}
}
if ($appeared -eq 0) { $failures.Add('no path appeared during the run') }
if ($faded -eq 0) { $failures.Add('no path faded during the run') }

# Queue: chg_count, new_cell, chg_tile, chg_ty, chg_cx[8], chg_cy[8], chg_done[8].
$qCount = $queue[0]; $qFull = $qCount -ge $CHANGE_SLOTS
$pending = @(@{}, @{})
for ($i = 0; $i -lt $qCount; $i++) {
$cx = $queue[4 + $i]; $cy = $queue[4 + $CHANGE_SLOTS + $i]; $done = $queue[4 + 2 * $CHANGE_SLOTS + $i]
for ($b = 0; $b -lt 2; $b++) { if (-not ($done -band (1 -shl $b))) { $pending[$b]["$cx,$cy"] = 1 } }
}

# Tiles and counts.
$paths = 0
for ($i = 0; $i -lt 4000; $i++) {
$t = $world[$i]; $o = $start[$i]; $c = $counts[$i]; $x = $i % $width; $y = [math]::Floor($i / $width)
if ($o -ge $STONE -and $o -le $WATER_SE) {
if ($t -ne $o) { $failures.Add("water or stone cell ($x,$y) changed from $o to $t") }
if ($c -ne 0) { $failures.Add("water or stone cell ($x,$y) has walk count $c") }
continue
}
if ($t -ge $PATH_LAND -and $t -le $PATH_TREE) {
$paths++
if ($t - $PATH_LAND + $LAND -ne $o) { $failures.Add("path tile $t at ($x,$y) over generated tile $o") }
if ($c -lt $PATH_OFF -and -not $qFull) { $failures.Add("path at ($x,$y) has count $c (below $PATH_OFF)") }
} elseif ($t -ne $o) {
$failures.Add("cell ($x,$y) changed from $o to $t")
} elseif ($c -ge $PATH_ON -and -not $qFull) {
$failures.Add("cell ($x,$y) has count $c but is not a path")
}
}

# Buffers: origin (buf_cx[2], buf_cy[2], buf_ready[2], buf_rows[2]).
$dotsChecked = 0
for ($b = 0; $b -lt 2; $b++) {
$ox = $bufs[$b]; $oy = $bufs[2 + $b]; $ready = $bufs[4 + $b]; $rows = [math]::Min(20, $bufs[6 + $b])
if (-not $ready) { $failures.Add("buffer $b is not complete at the save"); continue }
$base = @(0x6000, 0xA000)[$b]
$listed = @{} # address offset -> oldest saved byte
for ($k = $drawnCount[$b] - 1; $k -ge 0; $k--) {
$e = 16 * $b + $k
$addr = $listLow[$e] + 256 * $listHigh[$e] - $base
$listed[$addr] = $listByte[$e] # ends with the oldest entry
}
$badCells = 0; $badDots = 0
for ($r = 0; $r -lt $rows; $r++) {
for ($col = 0; $col -lt 39; $col++) {
$wx = $ox + $col; $wy = $oy + $r
if ($wx -ge $width -or $wy -ge $height) { continue }
if ($pending[$b].ContainsKey("$wx,$wy")) { continue }
$t = $world[$wy * $width + $wx]
if ($screens[$b][$r * 40 + $col] -ne $tileData.colors[$t]) { $badCells++; continue }
for ($k = 0; $k -lt 8; $k++) {
$off = $r * 320 + $col * 8 + $k
$want = $tileData.patterns[$t][$k]; $have = $bitmaps[$b][$off]
if ($have -eq $want) { if ($listed.ContainsKey($off) -and $listed[$off] -ne $want) { $badDots++ }; continue }
# Pairs that differ must be dots (%11) in a listed byte whose oldest saved byte is clean.
for ($q = 0; $q -lt 4; $q++) {
$sh = 6 - 2 * $q
if ((($have -shr $sh) -band 3) -ne (($want -shr $sh) -band 3) -and (($have -shr $sh) -band 3) -ne 3) { $badCells++ }
}
if (-not $listed.ContainsKey($off) -or $listed[$off] -ne $want) { $badDots++ } else { $dotsChecked++ }
}
}
}
if ($badCells -gt 0) { $failures.Add("buffer $('AB'[$b]): $badCells cells or pixels differ from the current world") }
if ($badDots -gt 0) { $failures.Add("buffer $('AB'[$b]): $badDots dot bytes without a matching clean saved byte") }
}

Write-Host ("Paths appeared {0} times and faded {1} times; {2} path cells at the last save; change queue {3}/{4}; {5} dot bytes checked." -f $appeared, $faded, $paths, $qCount, $CHANGE_SLOTS, $dotsChecked)
if ($failures.Count -gt 0) {
$failures | Select-Object -First 12 | ForEach-Object { Write-Host " $_" }
Write-Host '[FAIL] paths check' -ForegroundColor Red
exit 1
}
Write-Host '[PASS] paths appear and fade with the walk counts, only on land, grass and trees; both buffers show the current world plus the dots.' -ForegroundColor Green
exit 0

+ 51
- 7
tools/check-scroll.ps1 查看文件

@@ -49,15 +49,23 @@
the main loop's busy and idle cycles, the interrupt cycles, and how many frames each
hidden-buffer rebuild took (assumption A4: 8 frames allow 1 pixel per frame).

Worn paths (R7) change the world while the view scrolls (in the normal build too, on a long
tour), so every buffer save also saves the world and the change queue, and buffers are
compared with that world, skipping cells still queued for that buffer (changed cells are
drawn only in the hidden one). -PathTest runs the same scenarios on the worn-paths test
build (PATH_TEST, src/paths.inc: paths appear and fade within seconds) and fails the tour
if no path appeared.

Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.

.EXAMPLE
pwsh -File tools/check-scroll.ps1
pwsh -File tools/check-scroll.ps1 -Long # also the 5-minute tour (several minutes)
pwsh -File tools/check-scroll.ps1 -Long -ParseOnly -NoBuild # re-check the last run's logs
pwsh -File tools/check-scroll.ps1 -Long -PathTest # with paths changing during the run
#>
[CmdletBinding()]
param([switch]$NoBuild, [switch]$Long, [switch]$ParseOnly, [int]$TimeoutSeconds = 300, [int]$MaxStallFrames = 40)
param([switch]$NoBuild, [switch]$Long, [switch]$ParseOnly, [switch]$PathTest, [int]$TimeoutSeconds = 300, [int]$MaxStallFrames = 40)
. (Join-Path $PSScriptRoot 'lib.ps1')

function Get-Label([hashtable]$Target, [string]$Symbol) {
@@ -73,9 +81,16 @@ function Get-TileData {
$src = Get-Content -LiteralPath (Get-RepoPath 'src/tiles.inc') -Raw
$block = $src.Substring($src.IndexOf('tile_patterns:'))
$block = $block.Substring(0, $block.IndexOf('.assert * - tile_patterns'))
$patterns = @(foreach ($m in [regex]::Matches($block, '(?m)^\s*\.byte\s+([^;\r\n]+)')) {
, @($m.Groups[1].Value -split ',' | ForEach-Object { [Convert]::ToByte($_.Trim().TrimStart('$'), 16) })
})
$patterns = [System.Collections.Generic.List[object]]::new()
$repeat = 1; $body = [System.Collections.Generic.List[object]]::new()
foreach ($line in $block -split "`n") {
if ($line -match '\.repeat\s+(\d+)') { $repeat = [int]$Matches[1]; $body.Clear(); continue }
if ($line -match '\.endrepeat') { for ($r = 0; $r -lt $repeat; $r++) { foreach ($b in $body) { $patterns.Add($b) } }; $repeat = 1; continue }
if ($line -match '^\s*\.byte\s+([^;\r\n]+)') {
$row = @($Matches[1] -split ',' | ForEach-Object { [Convert]::ToByte($_.Trim().TrimStart('$'), 16) })
if ($repeat -gt 1) { $body.Add($row) } else { $patterns.Add($row) }
}
}
$colors = [System.Collections.Generic.List[byte]]::new()
$cblock = $src.Substring($src.IndexOf('tile_colors:'))
$cblock = $cblock.Substring(0, $cblock.IndexOf('.assert * - tile_colors'))
@@ -88,12 +103,17 @@ function Get-TileData {
for ($r = 0; $r -lt $repeat; $r++) { foreach ($v in $vals) { $colors.Add($v) } }
}
}
@{ patterns = $patterns; colors = $colors.ToArray() }
# Tile IDs: the .enum at the top of the file (PATH_LAND, PATH_GRASS, PATH_TREE are consecutive).
$enum = $src.Substring($src.IndexOf('.enum'), $src.IndexOf('.endenum') - $src.IndexOf('.enum'))
$names = @([regex]::Matches($enum, '(?m)^\s+([A-Z_]+)') | ForEach-Object { $_.Groups[1].Value })
if ($patterns.Count -ne $names.IndexOf('TILE_COUNT')) { throw "tiles.inc: $($patterns.Count) patterns for $($names.IndexOf('TILE_COUNT')) tiles" }
@{ patterns = $patterns.ToArray(); colors = $colors.ToArray(); pathLand = $names.IndexOf('PATH_LAND') }
}

try {
$project = Get-ProjectConfig
$target = Get-ProjectTargets $project 'c64'
if ($PathTest) { Set-TargetVariant $target 'PATH_TEST' 'pathtest' }
if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} }
$emu = Get-ToolPath $project $target.emulator.binary
} catch [MissingToolException] {
@@ -107,6 +127,8 @@ foreach ($s in 'smoke_ready', 'people_moved', 'world_tiles', 'people_cx', 'visib
'move_frame', 'people_flip_pending', 'buf_cx', 'buf_cy', 'buf_ready', 'view_fx', 'view_cy', 'view_fy',
'frame_start', 'frame_done', 'start_rebuild', 'rebuild_ready',
'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space') { $L[$s] = Get-Label $target $s }
$CHANGE_SLOTS = 8 # src/paths.inc
foreach ($s in 'chg_count', 'chg_done', 'path_changed') { $L[$s] = Get-Label $target $s }
$IRQ_ENTRY = 0xFF48; $IRQ_EXIT = 0xEA81 # KERNAL IRQ entry and the exit our handler jumps to
$FRAME_CYCLES = 17095

@@ -214,6 +236,9 @@ foreach ($sc in $scenarios) {
}
# Snapshots at the end of each "snap" stop: before the phase changes, so they run in the same hit.
$saves = @('bitmap-a.bin 6000 7a3f', 'bitmap-b.bin a000 ba3f', 'screen-a.bin 4000 4347', 'screen-b.bin 8000 8347')
# With them, the world and change queue (chg_count .. chg_done) as they were at the save.
$saves += ('world-now.bin {0:x4} {1:x4}' -f $L.world_tiles, ($L.world_tiles + 3999))
$saves += ('queue.bin {0:x4} {1:x4}' -f $L.chg_count, ($L.chg_done + $CHANGE_SLOTS - 1))
for ($ph = 0; $ph -lt $lastPhase; $ph++) {
if (-not $sc.phases[$ph].snap) { continue }
foreach ($save in $saves) {
@@ -254,6 +279,8 @@ foreach ($sc in $scenarios) {
@('rbstart', $L.start_rebuild), @('rbready', $L.rebuild_ready))) {
$n++; $mon.Add(('trace exec ${0:x4}' -f $ev[1])); $events[$n] = $ev[0]
}
$n++; $mon.Add(('trace exec ${0:x4}' -f $L.path_changed)); $events[$n] = 'path' # A = new tile
$pathAppeared = 0; $pathFaded = 0; $script:pathCells = 0; $script:pendingSkipped = 0
if (-not $ParseOnly) {
Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
@@ -279,6 +306,10 @@ foreach ($sc in $scenarios) {
if ($events.ContainsKey($num)) { $want = $events[$num]; $wantLine = [int]$Matches[2] }
continue
}
if ($want -eq 'path' -and $line -match '^\.C:.*\sA:([0-9a-fA-F]{2})\s') {
if ([Convert]::ToInt32($Matches[1], 16) -ge $tiles.pathLand) { $pathAppeared++ } else { $pathFaded++ }
$want = $null; continue
}
if ($want -and $line -match '^\.C:.*\s(\d+)\s*$') {
if ($want -eq 'view') { $cur.clock = [long]$Matches[1]; $timeline.Add(@('view', $cur.clock, $cur.line)) }
else { $timeline.Add(@($want, [long]$Matches[1], $wantLine)) }
@@ -395,12 +426,20 @@ foreach ($sc in $scenarios) {
# Final frames: at people_moved, the buffer that will be shown (the hidden one when a flip is
# pending, otherwise the shown one) must equal a fresh render at the view origin plus this
# frame's dots; with a flip pending, the shown buffer must hold the previous frame's dots.
$world = [IO.File]::ReadAllBytes((Join-Path $dir 'world.bin'))
$last = $frames[$frames.Count - 1]
$checkBuffer = {
param([string]$prefix, [int]$buf, $at, $people, [string]$what)
$suffix = @('a', 'b')[$buf]
$bitmap = [IO.File]::ReadAllBytes((Join-Path $dir "${prefix}bitmap-$suffix.bin"))
# The world as it was at the save; cells still queued for this buffer are skipped.
$now = [IO.File]::ReadAllBytes((Join-Path $dir "${prefix}world-now.bin"))
$q = [IO.File]::ReadAllBytes((Join-Path $dir "${prefix}queue.bin"))
$pending = @{} # queue: chg_count, new_cell, chg_tile, chg_ty, chg_cx[8], chg_cy[8], chg_done[8]
for ($i = 0; $i -lt [Math]::Min($q[0], $CHANGE_SLOTS); $i++) {
if (($q[4 + 2 * $CHANGE_SLOTS + $i] -band (1 -shl $buf)) -eq 0) { $pending["$($q[4 + $i]),$($q[4 + $CHANGE_SLOTS + $i])"] = $true }
}
$script:pathCells += @($now | Where-Object { $_ -ge $tiles.pathLand -and $_ -le $tiles.pathLand + 2 }).Count
$script:pendingSkipped += $pending.Count
$screen = [IO.File]::ReadAllBytes((Join-Path $dir "${prefix}screen-$suffix.bin"))
$dots = @{}
for ($i = 0; $i -lt 16; $i++) {
@@ -416,7 +455,8 @@ foreach ($sc in $scenarios) {
$rows = [Math]::Min(21, 50 - $at.cy); $cols = [Math]::Min(39, 80 - $at.cx)
for ($r = 0; $r -lt $rows; $r++) {
for ($c = 0; $c -lt $cols; $c++) {
$t = $world[($at.cy + $r) * 80 + $at.cx + $c]
if ($pending.Count -and $pending["$($at.cx + $c),$($at.cy + $r)"]) { continue }
$t = $now[($at.cy + $r) * 80 + $at.cx + $c]
if ($screen[$r * 40 + $c] -ne $tiles.colors[$t]) { $badScreen++ }
for ($k = 0; $k -lt 8; $k++) {
$o = $r * 320 + $c * 8 + $k
@@ -450,6 +490,10 @@ foreach ($sc in $scenarios) {

$perPhase = if ($phaseFrames.Count -le 12) { $phaseFrames -join '/' } else { "$($phaseFrames.Count) phases" }
$snapText = if ($snaps) { ", $snaps stops checked byte for byte" } else { '' }
if ($PathTest -or $pathAppeared) {
$snapText += ", paths appeared $pathAppeared and faded $pathFaded times, $($script:pathCells) path cells in checked saves ($($script:pendingSkipped) queued cells skipped)"
if ($sc.name -eq 'tour' -and $pathAppeared -eq 0) { $failures.Add('no path appeared during the tour') }
}
$summary = "{0}: {1} frames ({9}), {2} moving, {3} stall frames, update done by line {4}, final view ({5},{6}) cell ({7},{8}){10}" -f `
$sc.name, $frames.Count, $steps, $stalls, $lastLine, $last.vx, $last.vy, $last.cx, $last.cy, $perPhase, $snapText
if ($failures.Count -gt 0) {


+ 6
- 5
tools/check-world.ps1 查看文件

@@ -37,9 +37,10 @@ $width = 80; $height = 50
$LAND = 0; $GRASS = 1; $TREE = 2; $STONE = 3; $WATER = 4
$WATER_N = 5; $WATER_S = 6; $WATER_W = 7; $WATER_E = 8
$WATER_NW = 9; $WATER_NE = 10; $WATER_SW = 11; $WATER_SE = 12
$ROAD_H = 13; $ROAD_V = 14; $ROAD_X = 19; $BRIDGE_H = 20; $BRIDGE_V = 21; $BRIDGE_X = 22
$TILE_COUNT = 23
$glyphs = '.gT#~~~~~~~~~-|+++++=!*'
$ROAD_H = 13; $ROAD_V = 14; $ROAD_X = 19; $PATH_LAND = 20; $PATH_TREE = 22
$BRIDGE_H = 23; $BRIDGE_V = 24; $BRIDGE_X = 25
$TILE_COUNT = 26 # src/tiles.inc enum; no road, path or bridge tile at generation
$glyphs = '.gT#~~~~~~~~~-|+++++:::=!*'
# Shore tile by [row part][column part]: row 0 = open to the north, 2 = open to the south.
$shore = @(@($WATER_NW, $WATER_N, $WATER_NE), @($WATER_W, $WATER, $WATER_E), @($WATER_SW, $WATER_S, $WATER_SE))
$NTSC_HZ = 1022727
@@ -68,9 +69,9 @@ function Test-World([byte[]]$tiles, [string]$name) {
if ($p[1] -eq 0) { $fail.Add("no $($p[0]) anywhere") }
}

# No roads or bridges at generation time.
# No roads, paths or bridges at generation time (paths are worn in later).
$roadCells = 0; for ($t = $ROAD_H; $t -lt $TILE_COUNT; $t++) { $roadCells += $counts[$t] }
if ($roadCells -gt 0) { $fail.Add("$roadCells road or bridge cells: the generator must not make roads") }
if ($roadCells -gt 0) { $fail.Add("$roadCells road, path or bridge cells: the generator makes none") }

# Water: neighbours count as water if water family, bridge, or outside the world.
$isWet = { param($x, $y)


+ 10
- 0
tools/lib.ps1 查看文件

@@ -239,6 +239,16 @@ function New-TargetDisk([hashtable]$Project, [hashtable]$Target, [hashtable]$Don
# Emulator
# ---------------------------------------------------------------------------

# Build variant: add an assembler symbol and give the program, labels and map a suffix
# (<name>-<Suffix>.prg), so the normal build is not touched. cc65 targets only.
function Set-TargetVariant([hashtable]$Target, [string]$Define, [string]$Suffix) {
if ($Target.build.kind -ne 'cc65') { throw "The $Define build needs a cc65 target." }
$Target.build.asmDefines = @(@($Target.build.asmDefines) + $Define | Where-Object { $_ })
foreach ($k in 'labels', 'map') { $Target.build[$k] = $Target.build[$k] -replace '(\.\w+)$', "-$Suffix`$1" }
$Target.artifact = $Target.artifact -replace '(\.\w+)$', "-$Suffix`$1"
$Target.disk = $null
}

function Get-AutostartFile([hashtable]$Target) {
if ($Target.emulator.autostart -eq 'disk') { return Get-RepoPath $Target.disk.image }
Get-RepoPath $Target.artifact


+ 8
- 8
tools/run.ps1 查看文件

@@ -11,29 +11,29 @@
pwsh -File tools/run.ps1
pwsh -File tools/run.ps1 -Target c128-80
pwsh -File tools/run.ps1 -Target c64 -TimingBar
pwsh -File tools/run.ps1 -Target c64 -PathTest
.PARAMETER TimingBar
Build with the assembler symbol TIMING_BAR into a separate program (<name>-timing.prg) whose border colour
shows the CPU's work in each frame (see src/main.s). The normal build is not touched.
.PARAMETER PathTest
Build with the assembler symbol PATH_TEST into <name>-pathtest.prg: worn paths appear after 8 steps
into a cell and fade below 4, with fast decay (see src/paths.inc), so they can be watched in minutes.
#>
[CmdletBinding()]
param(
[string]$Target,
[switch]$NoBuild,
[ValidateSet('pal', 'ntsc')][string]$Video,
[switch]$TimingBar
[switch]$TimingBar,
[switch]$PathTest
)
. (Join-Path $PSScriptRoot 'lib.ps1')

try {
$project = Get-ProjectConfig
$t = if ($Target) { Get-ProjectTargets $project $Target } else { @($project.resolved.targets)[0] }
if ($TimingBar) {
if ($t.build.kind -ne 'cc65') { throw "-TimingBar needs a cc65 target." }
$t.build.asmDefines = @(@($t.build.asmDefines) + 'TIMING_BAR' | Where-Object { $_ })
foreach ($k in 'labels', 'map') { $t.build[$k] = $t.build[$k] -replace '(\.\w+)$', '-timing$1' }
$t.artifact = $t.artifact -replace '(\.\w+)$', '-timing$1'
$t.disk = $null
}
if ($TimingBar) { Set-TargetVariant $t 'TIMING_BAR' 'timing' }
if ($PathTest) { Set-TargetVariant $t 'PATH_TEST' 'pathtest' }
if (-not $NoBuild) { Invoke-TargetBuild $project $t @{} }
if ($t.build.kind -eq 'none' -and -not $t.disk) { throw "Target $($t.id) is built on the Commodore; follow docs/toolchain.md to load it." }
$emu = Get-ToolPath $project $t.emulator.binary


正在加载...
取消
保存

Powered by TurnKey Linux.