Переглянути джерело

M3.3: scrolling checks finished; split checked at every y-scroll

- tools/check-scroll.ps1: scenarios driven as phases (phase byte at $CFF0,
  VICE conditional checkpoints); direction, edge, register, timing and stall
  checks; byte-exact final check of both buffers including dots.
- tools/check-split.ps1: "no key" guard, scroll down and up so every y-scroll
  value 0-7 is split; digits compared with an independent in-view count.
- tools/check-keys.ps1: border indicator check removed (indicator gone).
- docs: MT3.1/MT3.3 steps, toolchain check descriptions, verification status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main
Daniel Covington 3 дні тому
джерело
коміт
19c07883d5
6 змінених файлів з 265 додано та 159 видалено
  1. +27
    -28
      docs/manual-tests.md
  2. +3
    -2
      docs/toolchain.md
  3. +7
    -7
      docs/verification-status.md
  4. +14
    -16
      tools/check-keys.ps1
  5. +130
    -75
      tools/check-scroll.ps1
  6. +84
    -31
      tools/check-split.ps1

+ 27
- 28
docs/manual-tests.md Переглянути файл

@@ -122,36 +122,33 @@ Verifies: R3
Setup: VICE x64sc, NTSC (-ntsc), warp off.
Start: `pwsh -File tools/run.ps1 -Target c64`

At M3.1 (keys only, no scrolling yet): run `pwsh -File tools/check-keys.ps1` and
expect `[PASS] all 8 key scenarios decode correctly`. Then start the program and,
while the map is shown, hold each key below for a second or two and release it.
Until M3.3 the border colour shows the direction that is held:

| Keys held (VICE PC key) | Border |
|---|---|
| nothing | brown (same as the background) |
| CRSR RIGHT (Right arrow) | light green |
| SHIFT + CRSR RIGHT (Left arrow) | cyan |
| CRSR DOWN (Down arrow) | yellow |
| SHIFT + CRSR DOWN (Up arrow) | white |
| CRSR RIGHT + CRSR DOWN (Right + Down arrows) | orange |
| SHIFT + both (Left + Up arrows) | light blue |

Expected at M3.1: the colour stays as long as the key is held and returns to
brown on release; both the left and the right SHIFT key work; the dots keep
moving smoothly. Tapping SPACE gives a new map; holding SPACE gives exactly one.
(Right + Up or Left + Down cannot be told apart on a real C64, because SHIFT
reverses both cursor keys; they show grey or one of the colours above.)

From M3.3:
Automated first: `pwsh -File tools/check-keys.ps1` should print
`[PASS] all 8 key scenarios decode correctly` and `pwsh -File tools/check-scroll.ps1`
should print `[PASS] all 3 scroll scenarios: ...`.

Keys (VICE maps the PC arrow keys to these): Right arrow = CRSR RIGHT, Down arrow =
CRSR DOWN, Left arrow = SHIFT + CRSR RIGHT, Up arrow = SHIFT + CRSR DOWN. On a real
C64 keyboard hold either SHIFT key with a cursor key to go left or up.

Steps:
1. Hold each cursor key (with SHIFT for up and left) until the view stops.
1. Wait for the map. Hold Right until the view stops, then Down until it stops.
2. Hold Left until the view stops, then Up until it stops.
3. Hold Right + Down together for a few seconds, then Left + Up together.
4. Tap Right a few times, then hold Right and switch to Left while still moving.
5. Release all keys and tap SPACE; then scroll again in the new world.

Expected:
- Smooth movement, no jumps or tearing
- The view stops at each world edge
- All five terrain colours seen across the world
- The map moves one pixel at a time in the direction held, with no jumps, tearing
or flashes of wrong terrain when it crosses a cell edge; it stops as soon as the
key is released. A very short hesitation right after a scroll starts is acceptable
(the hidden buffer is being prepared); note it if it is noticeable.
- Right stops at VIEW X 42 (the right world edge, column 79, at the right of the map);
Down stops at VIEW Y 30 (row 49 at the bottom); Left and Up stop at 0. Holding a key
against an edge does nothing.
- Diagonal scrolling moves smoothly on both axes.
- Across the whole world you see all five terrain colours (brown land, green grass and
trees, grey stone, blue water, black roads).
- SPACE still generates a new map, and the view starts again at the top-left (0, 0).

Verifies: R1, R5

@@ -179,14 +176,16 @@ Steps:
1. Wait for the map view and read the text below the map.
2. Watch the boundary between map and text for 30 seconds while the dots move.
3. Tap SPACE and watch the boundary while the new map is generated and shown.
4. From M3.3: hold each cursor key and watch the text and the boundary while the map scrolls.
4. Hold each cursor key (and Right + Down, Left + Up) and watch the text and the boundary while the map scrolls, especially while it scrolls up and down.

Expected:
- The map fills the top 20 cell rows; five lines of light red upper-case text on brown sit below it:
`LAND MAP 64`, `VIEW X 00 Y 00`, `PEOPLE IN VIEW nn OF 16`, an empty line, `CRSR SCROLL SPACE NEW WORLD`.
- The people-in-view number equals the number of dots you can count on the map.
- The boundary is a clean, steady horizontal line: no flicker, jitter, garbage characters or half-height rows.
- From M3.3: the text never moves while the map scrolls, and the VIEW X/Y values follow the scrolling.
- The text never moves while the map scrolls, and the boundary stays clean at every vertical scroll position.
- VIEW X/Y show the view's top-left cell (X 0-42, Y 0-30) and follow the scrolling.
- The people-in-view number follows dots entering and leaving the map (it updates 15 times a second; a dot cut by the map's edge counts).

Verifies: R6 (and the R1 view size)



+ 3
- 2
docs/toolchain.md Переглянути файл

@@ -57,8 +57,9 @@ Starter configurations marked verified were exercised by the Foundry's automated
- 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. It also checks that a split happens every frame, that the people-in-view digits match the drawn count, 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` and the border indicator 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/`.
- 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 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). 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


+ 7
- 7
docs/verification-status.md Переглянути файл

@@ -16,17 +16,17 @@ manual = `pending`, `confirmed by user (<date>)`, `problem reported (<date>): <n
| M2.2 Per-buffer saved-byte lists: restore the bytes under people from two frames ago, draw people in view, flip in vertical blank. | 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,117 frames, 0 missed flips, update done by raster line 26 at the latest, both final bitmaps byte-exact against clean map plus dots) | confirmed by user (2026-12-03) |
| M3.1 Keyboard matrix reading for the cursor keys with SHIFT, held-key repeat. | 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`; `pwsh -File tools/check-keys.ps1`: 8 of 8 scenarios, SPACE held = 1 regeneration) | confirmed by user (2026-12-03) |
| M3.2 Split screen: raster interrupts switch to text below a 20-row map and back at the top of the frame; status text screen and ROM font copy in both banks; status lines with the people-in-view count. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1` incl. status text in both banks; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`; `pwsh -File tools/check-keys.ps1`; `pwsh -File tools/check-split.ps1`: 955 splits in 955 frames, writes start at 210:55-61, digits right in every frame) | confirmed by user (2026-12-03) |
| M3.3 Fine scroll via $D016/$D011 in the 38-column, 20-row map area; rebuild the hidden buffer from tiles over 8 frames and flip on wrap; stop at world edges; show the view position in the status area; draw people relative to the view (in the shown buffer during vertical blank while a rebuild runs). | in progress (paused 2026-12-03); not verified | pending |
| M3.3 Fine scroll via $D016/$D011 in the 38-column, 20-row map area; rebuild the hidden buffer from tiles over 8 frames and flip on wrap; stop at world edges; show the view position in the status area; draw people relative to the view (in the shown buffer during vertical blank while a rebuild runs). | 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,127 frames, 0 missed, update done by line 36; `pwsh -File tools/check-keys.ps1`: 8 of 8; `pwsh -File tools/check-split.ps1`: 964 splits in 964 frames, all y-scroll values 0-7, starts 210:55-64, digits right after 240 of 240 status updates; `pwsh -File tools/check-scroll.ps1`: 3 of 3 scenarios, edges reached and held, 1-5 stall frames per scenario, both buffers byte-exact at the end) | pending (MT3.1, MT3.2, MT3.3) |
| M3.4 Check that people stay aligned with the terrain over long scrolling runs; measure the frame budget with a border-colour timing bar. | not run | pending |

## Notes

- 2026-12-03 PAUSED IN M3.3 (work in progress, committed as "M3.3 WIP"). State when paused:
- Code written and building: src/scroll.inc (view position, fine scroll, cell steps with flip, diagonal phase lock, edge stops, chunked hidden-buffer rebuild), people drawn relative to each buffer's origin (src/people.inc), status view position and people-in-view count, split choosing text screen 1 or 2 and the delay by y-scroll (src/status.inc), temporary M3.1 border indicator removed.
- Rebuild speed: after optimisation, straight scrolling stalls only at start-up (about 18 frames per scenario); diagonal down-right was smooth in the one run seen. Assumption A4 looks met but is not yet confirmed.
- tools/check-people.ps1 passes (now forces "no key" on the key rows: keys typed on the PC while a headless VICE has focus reached the program and scrolled the view).
- tools/check-scroll.ps1 (new) is not finished: its key schedule used VICE "ignore" counts, which do not count one per frame. Next step: drive scenarios with a phase byte at $CFF0 and conditional checkpoints (VICE 3.10 accepts "if @cpu:$addr == $nn"), one checkpoint per key row per phase.
- Still to do for M3.3: finish check-scroll; add the "no key" guard and a scrolling scenario to tools/check-split.ps1 so every y-scroll value is checked (split delay for y-scroll 2 is 1, not yet measured); run check-keys, smoke and all checks; update docs/manual-tests.md (MT3.1 still describes the removed border colours; MT3.3 step 4) and docs/toolchain.md; then ask for manual tests MT3.1-MT3.3.
- 2026-12-03 (M3.3, resumed and finished): tools/check-scroll.ps1 now drives each scenario as phases (phase byte at $CFF0, VICE conditional checkpoints on people_moved; frame counts with "ignore" did not work). VICE 3.10 needs parentheses around each comparison joined with && (without them the condition never fired), and runs checkpoints at one address in definition order in the same hit, so phase changes are defined latest first. A rejected checkpoint shifts the numbers of the later ones, so both new checks fail on any monitor "ERROR". The check found a mistake in itself, not in the program: while the view is still, people are drawn into the hidden buffer and shown at the next flip, so the shown buffer holds the previous frame's dots; the final comparison now checks both buffers byte for byte (dots included).
- Stalls (a held key that did not move the view): 5 in the edges run (1,546 frames), 1 in middle, 3 in reverse. A4 (rebuild over 8 frames within the frame budget, 1 pixel per frame) holds in VICE for these runs; the frame budget itself is measured in M3.4.
- A7 under vertical fine scroll: tools/check-split.ps1 now scrolls down three cells and back, so every map y-scroll value is split. All starts are inside the measured window 210:53-64. At y-scroll 2 (line 210 is a bad line, shorter delay) starts were 210:58-64, so the margin to the window's end is 0-6 cycles there. The window was measured at y-scroll 3 only; the user's MT3.3 boundary check while scrolling up and down is the confirmation.
- The digits check in tools/check-split.ps1 was changed: since M3.3 the status updates every 4th frame and people may be drawn into the shown buffer, so "digits = hidden buffer's drawn count" no longer applies. It now compares the digits after each update with the script's own count of dots at least partly inside the visible window.
- tools/check-keys.ps1 no longer checks the M3.1 border indicator (removed in M3.3). docs/manual-tests.md MT3.1 and MT3.3 and docs/toolchain.md updated.
- The knowledge system was not available (Docker/PostgreSQL not running), so nothing was recorded there.

- 2026-12-03: Spec change approved by the user: R3 reworded for scrolling (people drawn in the shown buffer during vertical blank while a scroll rebuild runs), and drawing people relative to the view moved from M3.4 to M3.3. Acceptance criteria unchanged.



+ 14
- 16
tools/check-keys.ps1 Переглянути файл

@@ -7,7 +7,8 @@
tracepoints on the instructions that store the port B row bits (key_row_cursor,
key_row_lshift, key_row_rshift, key_row_space in src/keys.inc) run "r a = <bits>",
as if those keys were held down. At keys_read the script logs scroll_dx, scroll_dy and
the border colour (the M3.1 direction indicator); it counts space_ready hits.
the frames that reached it; it counts space_ready hits. (The M3.1 border-colour
direction indicator was removed in M3.3, so the border is no longer checked.)

Scenarios: no key, right, left (right SHIFT), down, up (left SHIFT), down-right,
up-left, and SPACE held from frame 60 on (must regenerate exactly once).
@@ -46,16 +47,15 @@ foreach ($s in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_sp

# Row bits are active low. Cursor column: RIGHT = bit 2, DOWN = bit 7.
# Left SHIFT = bit 7 of its column, right SHIFT and SPACE = bit 4 of theirs.
# Border colours from src/keys.inc direction_colors.
$scenarios = @(
@{ name = 'no key'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 0; border = 9 }
@{ name = 'CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 0; border = 13 }
@{ name = 'right SHIFT+CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ef'; dx = -1; dy = 0; border = 3 }
@{ name = 'CRSR DOWN'; cursor = '7f'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 1; border = 7 }
@{ name = 'left SHIFT+CRSR DOWN'; cursor = '7f'; lshift = '7f'; rshift = 'ff'; dx = 0; dy = -1; border = 1 }
@{ name = 'CRSR RIGHT+DOWN'; cursor = '7b'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 1; border = 8 }
@{ name = 'left SHIFT+RIGHT+DOWN'; cursor = '7b'; lshift = '7f'; rshift = 'ff'; dx = -1; dy = -1; border = 14 }
@{ name = 'SPACE held'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; space = 'ef'; spaceAfter = 60; dx = 0; dy = 0; border = 9; regenerations = 1 }
@{ name = 'no key'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 0 }
@{ name = 'CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 0 }
@{ name = 'right SHIFT+CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ef'; dx = -1; dy = 0 }
@{ name = 'CRSR DOWN'; cursor = '7f'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 1 }
@{ name = 'left SHIFT+CRSR DOWN'; cursor = '7f'; lshift = '7f'; rshift = 'ff'; dx = 0; dy = -1 }
@{ name = 'CRSR RIGHT+DOWN'; cursor = '7b'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 1 }
@{ name = 'left SHIFT+RIGHT+DOWN'; cursor = '7b'; lshift = '7f'; rshift = 'ff'; dx = -1; dy = -1 }
@{ name = 'SPACE held'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; space = 'ef'; spaceAfter = 60; dx = 0; dy = 0; regenerations = 1 }
)

$root = Get-RepoPath 'build/check-keys'
@@ -84,9 +84,8 @@ foreach ($sc in $scenarios) {
& $add $hooks.key_row_space 'r a = ff'
}
& $add $hooks.keys_read ('m {0:x4} {1:x4}' -f $hooks.scroll_dx, ($hooks.scroll_dx + 1))
& $add $hooks.keys_read 'm d020 d020'
$spaceCheckpoint = $n + 1
& $add $hooks.space_ready 'm d020 d020'
& $add $hooks.space_ready 'r'
Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''

@@ -99,19 +98,18 @@ foreach ($sc in $scenarios) {
if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true) }

$log = Join-Path $dir 'monitor.log'
$scroll = $null; $border = $null; $frames = 0; $regenerations = 0
$scroll = $null; $frames = 0; $regenerations = 0
if (Test-Path -LiteralPath $log) {
foreach ($line in Get-Content -LiteralPath $log) {
if ($line -match ('^#{0} \(Trace' -f $spaceCheckpoint)) { $regenerations++ }
elseif ($line -match ('^>C:{0:x4}\s+([0-9a-f]{{2}}) ([0-9a-f]{{2}})' -f $hooks.scroll_dx)) {
$scroll = @([Convert]::ToByte($Matches[1], 16), [Convert]::ToByte($Matches[2], 16)) | ForEach-Object { if ($_ -ge 128) { $_ - 256 } else { [int]$_ } }; $frames++
} elseif ($line -match '^>C:d020\s+([0-9a-f]{2})') { $border = [Convert]::ToByte($Matches[1], 16) -band 0x0F }
}
}
}
$problems = @()
if ($frames -lt 30) { $problems += "only $frames frames reached keys_read" }
elseif ($scroll[0] -ne $sc.dx -or $scroll[1] -ne $sc.dy) { $problems += "scroll ($($scroll[0]),$($scroll[1])), expected ($($sc.dx),$($sc.dy))" }
if ($null -ne $border -and $border -ne $sc.border) { $problems += "border colour $border, expected $($sc.border)" }
$wantRegen = if ($sc.regenerations) { $sc.regenerations } else { 0 }
if ($regenerations -ne $wantRegen) { $problems += "$regenerations regenerations, expected $wantRegen" }
if ($problems.Count -gt 0) {
@@ -119,7 +117,7 @@ foreach ($sc in $scenarios) {
Write-Host (" FAIL {0}: {1}" -f $sc.name, ($problems -join '; ')) -ForegroundColor Red
} else {
$extra = if ($sc.space) { ", $regenerations regeneration while held" } else { '' }
Write-Host (" ok {0}: scroll ({1},{2}), border {3}, {4} frames{5}" -f $sc.name, $scroll[0], $scroll[1], $border, $frames, $extra)
Write-Host (" ok {0}: scroll ({1},{2}), {3} frames{4}" -f $sc.name, $scroll[0], $scroll[1], $frames, $extra)
}
}
if ($failed -gt 0) { Write-Host "[FAIL] $failed of $($scenarios.Count) key scenarios" -ForegroundColor Red; exit 1 }


+ 130
- 75
tools/check-scroll.ps1 Переглянути файл

@@ -3,26 +3,33 @@
Check pixel-smooth scrolling of the C64 build headless in VICE.

.DESCRIPTION
Each scenario holds keys on a schedule (faked as in tools/check-keys.ps1: tracepoints
on the key_row_* instructions set the row bits; host key presses cannot interfere),
logs the view position, buffer state and scroll registers at people_moved every frame,
and saves both buffers (bitmap and screen RAM) each frame; the last save is checked.
Each scenario is a list of phases. A phase holds keys (faked as in tools/check-keys.ps1:
tracepoints on the key_row_* instructions set the row bits, so host key presses cannot
interfere) until a condition on the program state is met at people_moved (a frame
number or a view position); the phase number lives in free RAM at $CFF0 and VICE
conditional checkpoints move it on. Every frame the script logs the phase, view
position, buffer state and scroll registers at people_moved; in the last phase it
saves both buffers (bitmap and screen RAM), and the last save is checked.

Scenarios:
edges right+down until the bottom-right corner, then SHIFT (up+left) until
the top-left corner, then release
edges right+down to the bottom-right corner, hold there, then SHIFT (up+left)
to the top-left corner, hold there, then release
middle down, then right, then release in the middle of the world
reverse right for a while, reverse to left right after a cell step, release
reverse right, reverse to left in the frame after a cell step, right again;
then down, reverse to up right after a cell step; release

Checks, per scenario:
- the view moves at most one pixel per axis per frame and stays inside
- the view moves at most one pixel per axis per frame, only in the direction of the
keys read the frame before, and stays inside
vx 0-336, vy 0-244; the fine-scroll registers match the view
- edges: the view reaches vx 336 and vy 244, then 0 and 0, and stops there
- every scenario reaches its last phase; edges: the view reaches vx 336 and vy 244,
then 0 and 0, and does not move while the keys push against an edge
- the main loop never misses a frame and the people update ends before raster 55
- frames where a held key did not move the view although no edge was reached are
counted as stalls and reported (they happen while the hidden buffer is not ready)
- at the end, the shown buffer's bitmap and screen RAM equal a fresh render of the
world from the view's top-left cell (39 columns, 21 rows), except bytes with dots
- at the end, the buffer about to be shown (bitmap and screen RAM) equals a fresh
render of the world from the view's top-left cell (39 columns, 21 rows) with this
frame's dots ORed in; when a flip is pending, the shown buffer has last frame's dots

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

@@ -77,23 +84,41 @@ try {
$tiles = Get-TileData
$L = @{}
foreach ($s in 'smoke_ready', 'people_moved', 'world_tiles', 'people_cx', 'visible', 'view_cx', 'map_d011', 'map_d016',
'move_frame', 'people_flip_pending', 'view_fx', 'view_cy', 'view_fy',
'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space') { $L[$s] = Get-Label $target $s }

# Key bits (active low): cursor column RIGHT = bit 2, DOWN = bit 7; left SHIFT = bit 7.
$RIGHT_DOWN = '7b'; $DOWN = '7f'; $RIGHTK = 'fb'; $NONE = 'ff'; $SHIFT = '7f'
$PHASE = 0xCFF0 # free RAM (the program ends below $2700)
# Phase end conditions: frame = move_frame value (wraps every 256 frames); view = cell and fine.
function Frame([int]$n) { , (, @($L.move_frame, $n)) }
function View([int]$cx, [int]$fx, [int]$cy, [int]$fy) {
$c = @()
if ($cx -ge 0) { $c += , @($L.view_cx, $cx); $c += , @($L.view_fx, $fx) }
if ($cy -ge 0) { $c += , @($L.view_cy, $cy); $c += , @($L.view_fy, $fy) }
$c
}
$scenarios = @(
@{ name = 'edges'; cycles = 30000000; schedule = @(
@{ at = 30; cursor = $RIGHT_DOWN; lshift = $NONE }
@{ at = 520; cursor = $RIGHT_DOWN; lshift = $SHIFT }
@{ at = 1010; cursor = $NONE; lshift = $NONE }) }
@{ name = 'middle'; cycles = 12000000; schedule = @(
@{ at = 30; cursor = $DOWN; lshift = $NONE }
@{ at = 130; cursor = $RIGHTK; lshift = $NONE }
@{ at = 263; cursor = $NONE; lshift = $NONE }) }
@{ name = 'reverse'; cycles = 12000000; schedule = @(
@{ at = 30; cursor = $RIGHTK; lshift = $NONE }
@{ at = 104; cursor = $RIGHTK; lshift = $SHIFT }
@{ at = 200; cursor = $NONE; lshift = $NONE }) }
@{ name = 'edges'; cycles = 30000000; phases = @(
@{ cursor = $NONE; lshift = $NONE; until = (Frame 30) }
@{ cursor = $RIGHT_DOWN; lshift = $NONE; until = (View 42 0 30 4) } # vx 336, vy 244
@{ cursor = $RIGHT_DOWN; lshift = $NONE; until = (Frame 0); edge = $true }
@{ cursor = $RIGHT_DOWN; lshift = $SHIFT; until = (View 0 0 0 0) }
@{ cursor = $RIGHT_DOWN; lshift = $SHIFT; until = (Frame 128); edge = $true }
@{ cursor = $NONE; lshift = $NONE }) }
@{ name = 'middle'; cycles = 12000000; phases = @(
@{ cursor = $NONE; lshift = $NONE; until = (Frame 30) }
@{ cursor = $DOWN; lshift = $NONE; until = (View -1 0 12 3) } # vy 99
@{ cursor = $RIGHTK; lshift = $NONE; until = (View 16 5 -1 0) } # vx 133
@{ cursor = $NONE; lshift = $NONE }) }
@{ name = 'reverse'; cycles = 12000000; phases = @(
@{ cursor = $NONE; lshift = $NONE; until = (Frame 30) }
@{ cursor = $RIGHTK; lshift = $NONE; until = (View 9 0 -1 0) } # just stepped into cell 9
@{ cursor = $RIGHTK; lshift = $SHIFT; until = (View 3 2 -1 0) }
@{ cursor = $RIGHTK; lshift = $NONE; until = (View 5 0 -1 0) }
@{ cursor = $DOWN; lshift = $NONE; until = (View -1 0 6 0) } # just stepped into row 6
@{ cursor = $DOWN; lshift = $SHIFT; until = (View -1 0 2 1) }
@{ cursor = $NONE; lshift = $NONE }) }
)

$root = Get-RepoPath 'build/check-scroll'
@@ -105,29 +130,35 @@ foreach ($sc in $scenarios) {
$mon = [System.Collections.Generic.List[string]]::new()
$mon.Add('logname "monitor.log"'); $mon.Add('log on')
$n = 0
$add = { param($addr, $cmd, $ignore)
$add = { param($addr, $cmd, $cond)
$script:n++
$mon.Add(('trace exec ${0:x4}' -f $addr)); $mon.Add(('command {0} "{1}"' -f $script:n, $cmd))
if ($ignore) { $mon.Add(('ignore {0} {1}' -f $script:n, $ignore)) }
$line = 'trace exec ${0:x4}' -f $addr
if ($cond) { $line += ' if ' + (($cond | ForEach-Object { '(@cpu:${0:x4} == ${1:x2})' -f $_[0], $_[1] }) -join ' && ') }
$mon.Add($line); $mon.Add(('command {0} "{1}"' -f $script:n, $cmd))
}
$lastPhase = $sc.phases.Count - 1
& $add $L.smoke_ready ('bsave \"world.bin\" 0 {0:x4} {1:x4}' -f $L.world_tiles, ($L.world_tiles + 3999)) $null
& $add $L.smoke_ready ('> {0:x4} 00' -f $PHASE) $null
foreach ($row in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space') { & $add $L[$row] 'r a = ff' $null }
for ($ph = 0; $ph -le $lastPhase; $ph++) { # later checkpoints at one address run after earlier ones
$k = $sc.phases[$ph]
if ($k.cursor -ne $NONE) { & $add $L.key_row_cursor "r a = $($k.cursor)" @(, @($PHASE, $ph)) }
if ($k.lshift -ne $NONE) { & $add $L.key_row_lshift "r a = $($k.lshift)" @(, @($PHASE, $ph)) }
}
& $add $L.smoke_ready ('bsave \"world.bin\" 0 {0:x4} {1:x4}' -f $L.world_tiles, ($L.world_tiles + 3999)) 0
& $add $L.key_row_cursor 'r a = ff' 0
& $add $L.key_row_lshift 'r a = ff' 0
& $add $L.key_row_rshift 'r a = ff' 0
& $add $L.key_row_space 'r a = ff' 0
foreach ($step in $sc.schedule) { # later checkpoints run after earlier ones at the same address
& $add $L.key_row_cursor "r a = $($step.cursor)" $step.at
& $add $L.key_row_lshift "r a = $($step.lshift)" $step.at
for ($ph = $lastPhase - 1; $ph -ge 0; $ph--) { # descending, so one hit moves on at most one phase
& $add $L.people_moved ('> {0:x4} {1:x2}' -f $PHASE, ($ph + 1)) (@(, @($PHASE, $ph)) + $sc.phases[$ph].until)
}
$viewCheckpoint = $n + 1
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.view_cx, ($L.view_cx + 3)) 0
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.map_d011, ($L.map_d016)) 0
& $add $L.people_moved ('m {0:x4} {0:x4}' -f $L.visible) 0
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.people_cx, ($L.people_cx + 79)) 0
& $add $L.people_moved 'bsave \"bitmap-a.bin\" 0 6000 7a3f' 0
& $add $L.people_moved 'bsave \"bitmap-b.bin\" 0 a000 ba3f' 0
& $add $L.people_moved 'bsave \"screen-a.bin\" 0 4000 4347' 0
& $add $L.people_moved 'bsave \"screen-b.bin\" 0 8000 8347' 0
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.view_cx, ($L.view_cx + 3)) $null
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.map_d011, ($L.map_d016)) $null
& $add $L.people_moved ('m {0:x4} {0:x4}' -f $L.visible) $null
& $add $L.people_moved ('m {0:x4} {0:x4}' -f $L.people_flip_pending) $null
& $add $L.people_moved ('m {0:x4} {0:x4}' -f $PHASE) $null
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.people_cx, ($L.people_cx + 79)) $null
foreach ($save in @('bitmap-a.bin 6000 7a3f', 'bitmap-b.bin a000 ba3f', 'screen-a.bin 4000 4347', 'screen-b.bin 8000 8347')) {
$f = $save -split ' '
& $add $L.people_moved ('bsave \"{0}\" 0 {1} {2}' -f $f[0], $f[1], $f[2]) @(, @($PHASE, $lastPhase))
}
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)
@@ -151,17 +182,23 @@ foreach ($sc in $scenarios) {
if ($addr -eq $L.view_cx) { $cur.cx = $bytes[0]; $cur.fx = $bytes[1]; $cur.cy = $bytes[2]; $cur.fy = $bytes[3] }
elseif ($addr -eq $L.map_d011) { $cur.d011 = $bytes[0]; $cur.d016 = $bytes[1] }
elseif ($addr -eq $L.visible) { $cur.visible = $bytes[0] }
elseif ($addr -eq $PHASE) { $cur.phase = $bytes[0] }
elseif ($addr -eq $L.people_flip_pending) { $cur.pending = $bytes[0] }
elseif ($addr -ge $L.people_cx -and $addr -lt $L.people_cx + 80) { foreach ($b in $bytes) { if ($cur.people.Count -lt 80) { $cur.people.Add($b) } } }
}
$failures = [System.Collections.Generic.List[string]]::new()
# A rejected checkpoint shifts the numbers of the ones after it, so commands would land on the wrong ones.
$monErrors = @(Select-String -LiteralPath (Join-Path $dir 'monitor.log') -Pattern '^ERROR|not a valid checkpoint' | Select-Object -First 3)
foreach ($e in $monErrors) { $failures.Add("monitor script error: $($e.Line.Trim())") }
if ($frames.Count -lt 100) { $failures.Add("only $($frames.Count) frames logged") }
$stalls = 0; $steps = 0; $late = 0; $lastLine = 0
$maxVx = 0; $maxVy = 0; $minAfterMaxVx = 999; $minAfterMaxVy = 999
$keysFor = { param($i) $k = @{ cursor = $NONE; lshift = $NONE }; foreach ($s in $sc.schedule) { if ($i -ge $s.at) { $k = $s } }; $k }
$phaseFrames = @(0) * $sc.phases.Count
for ($i = 0; $i -lt $frames.Count; $i++) {
$f = $frames[$i]
$vx = 8 * $f.cx + $f.fx; $vy = 8 * $f.cy + $f.fy
$f.vx = $vx; $f.vy = $vy
if ($f.phase -lt $sc.phases.Count) { $phaseFrames[$f.phase]++ } else { $failures.Add("frame ${i}: phase $($f.phase) out of range") }
if ($vx -gt 336 -or $vy -gt 244 -or $f.fx -gt 7 -or $f.fy -gt 7) { $failures.Add("frame ${i}: view out of range ($vx,$vy)") }
if ($f.d016 -ne (0x10 -bor (7 - $f.fx)) -or $f.d011 -ne (0x30 -bor (7 - $f.fy))) { $failures.Add(("frame {0}: registers d011={1:x2} d016={2:x2} do not match view fine scroll ({3},{4})" -f $i, $f.d011, $f.d016, $f.fx, $f.fy)) }
if ($f.line -ge 55 -and $f.line -lt 251) { $failures.Add("frame ${i}: people update ended at raster line $($f.line)") }
@@ -169,19 +206,21 @@ foreach ($sc in $scenarios) {
if ($i -gt 0) {
$p = $frames[$i - 1]
$dx = $vx - $p.vx; $dy = $vy - $p.vy
if ([Math]::Abs($dx) -gt 1 -or [Math]::Abs($dy) -gt 1) { $failures.Add("frame ${i}: view jumped by ($dx,$dy)") }
if ($dx -ne 0 -or $dy -ne 0) { $steps++ }
if ($f.clock - $p.clock -gt 1.5 * 17095) { $late++ }
# Keys read in frame i-2 drive the step applied in frame i-1's vertical blank... the
# key row hooks count from the first read; allow two frames of latency.
$k = & $keysFor ($i - 2)
if ($i -ge 2 -and $k.cursor -ne $NONE) {
$wantX = if (([Convert]::ToByte($k.cursor, 16) -band 0x04) -eq 0) { if ($k.lshift -eq $SHIFT) { -1 } else { 1 } } else { 0 }
$wantY = if (([Convert]::ToByte($k.cursor, 16) -band 0x80) -eq 0) { if ($k.lshift -eq $SHIFT) { -1 } else { 1 } } else { 0 }
$canX = ($wantX -gt 0 -and $p.vx -lt 336) -or ($wantX -lt 0 -and $p.vx -gt 0)
$canY = ($wantY -gt 0 -and $p.vy -lt 244) -or ($wantY -lt 0 -and $p.vy -gt 0)
if (($canX -or $canY) -and $dx -eq 0 -and $dy -eq 0) { $stalls++ }
# The keys read after people_moved in frame i-1 (that frame's phase) give frame i's step.
$k = $sc.phases[[Math]::Min($p.phase, $lastPhase)]
$bits = [Convert]::ToByte($k.cursor, 16)
$sign = if ($k.lshift -eq $SHIFT) { -1 } else { 1 }
$wantX = if (($bits -band 0x04) -eq 0) { $sign } else { 0 }
$wantY = if (($bits -band 0x80) -eq 0) { $sign } else { 0 }
if (($dx -ne 0 -and $dx -ne $wantX) -or ($dy -ne 0 -and $dy -ne $wantY)) {
$failures.Add("frame ${i}: view moved by ($dx,$dy) with keys asking for ($wantX,$wantY)")
}
if ($k.edge -and $f.phase -eq $p.phase -and ($dx -ne 0 -or $dy -ne 0)) { $failures.Add("frame ${i}: view moved by ($dx,$dy) while held against an edge") }
$canX = ($wantX -gt 0 -and $p.vx -lt 336) -or ($wantX -lt 0 -and $p.vx -gt 0)
$canY = ($wantY -gt 0 -and $p.vy -lt 244) -or ($wantY -lt 0 -and $p.vy -gt 0)
if (($canX -or $canY) -and $dx -eq 0 -and $dy -eq 0) { $stalls++ }
}
if ($vx -gt $maxVx) { $maxVx = $vx; $minAfterMaxVx = $vx }
if ($vy -gt $maxVy) { $maxVy = $vy; $minAfterMaxVy = $vy }
@@ -189,39 +228,55 @@ foreach ($sc in $scenarios) {
if ($vy -lt $minAfterMaxVy) { $minAfterMaxVy = $vy }
}
if ($late -gt 0) { $failures.Add("the main loop missed $late frame(s)") }
if ($phaseFrames[$lastPhase] -lt 10) { $failures.Add("reached the last phase for only $($phaseFrames[$lastPhase]) frame(s) (frames per phase: $($phaseFrames -join ', '))") }
if ($sc.name -eq 'edges') {
if ($maxVx -ne 336 -or $maxVy -ne 244) { $failures.Add("did not reach the bottom-right edge (max vx $maxVx, vy $maxVy)") }
if ($minAfterMaxVx -ne 0 -or $minAfterMaxVy -ne 0) { $failures.Add("did not return to the top-left edge (min vx $minAfterMaxVx, vy $minAfterMaxVy)") }
}
if ($stalls -gt $MaxStallFrames) { $failures.Add("$stalls stall frames (allowed $MaxStallFrames)") }

# Final frame: shown buffer = fresh render at the view origin, except dot bytes.
$last = $frames[$frames.Count - 1]
$suffix = @('a', 'b')[$last.visible]
$bitmap = [IO.File]::ReadAllBytes((Join-Path $dir "bitmap-$suffix.bin"))
$screen = [IO.File]::ReadAllBytes((Join-Path $dir "screen-$suffix.bin"))
# 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'))
$dotBytes = @{}
for ($i = 0; $i -lt 16; $i++) {
$col = $last.people[$i] - $last.cx; $row = $last.people[32 + $i] - $last.cy
if ($col -ge 0 -and $col -lt 39 -and $row -ge 0 -and $row -lt 21) { $dotBytes[$row * 320 + $col * 8 + $last.people[48 + $i]] = 1 }
}
$badBitmap = 0; $badScreen = 0
$rows = [Math]::Min(21, 50 - $last.cy)
for ($r = 0; $r -lt $rows; $r++) {
for ($c = 0; $c -lt 39; $c++) {
$t = $world[($last.cy + $r) * 80 + $last.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
if ($bitmap[$o] -ne $tiles.patterns[$t][$k] -and -not $dotBytes.ContainsKey($o)) { $badBitmap++ }
$last = $frames[$frames.Count - 1]
$checkBuffer = {
param([int]$buf, $people, [string]$what)
$suffix = @('a', 'b')[$buf]
$bitmap = [IO.File]::ReadAllBytes((Join-Path $dir "bitmap-$suffix.bin"))
$screen = [IO.File]::ReadAllBytes((Join-Path $dir "screen-$suffix.bin"))
$dots = @{}
for ($i = 0; $i -lt 16; $i++) {
$col = $people[$i] - $last.cx; $row = $people[32 + $i] - $last.cy
if ($col -ge 0 -and $col -lt 39 -and $row -ge 0 -and $row -lt 21) {
$o = $row * 320 + $col * 8 + $people[48 + $i]
$dots[$o] = [int]$dots[$o] -bor (0xC0 -shr (2 * $people[16 + $i]))
}
}
$badBitmap = 0; $badScreen = 0
$rows = [Math]::Min(21, 50 - $last.cy)
for ($r = 0; $r -lt $rows; $r++) {
for ($c = 0; $c -lt 39; $c++) {
$t = $world[($last.cy + $r) * 80 + $last.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
if ($bitmap[$o] -ne ($tiles.patterns[$t][$k] -bor [int]$dots[$o])) { $badBitmap++ }
}
}
}
if ($badBitmap -gt 0 -or $badScreen -gt 0) { $failures.Add("buffer $suffix ($what) differs from the world plus dots: $badBitmap bitmap bytes, $badScreen colour bytes") }
}
if ($last.pending) {
& $checkBuffer (1 - $last.visible) $last.people 'shown next frame'
$prev = $frames[$frames.Count - 2]
if ($prev.cx -eq $last.cx -and $prev.cy -eq $last.cy) { & $checkBuffer $last.visible $prev.people 'shown, previous dots' }
} else {
& $checkBuffer $last.visible $last.people 'shown'
}
if ($badBitmap -gt 0 -or $badScreen -gt 0) { $failures.Add("final shown buffer differs from the world at the view: $badBitmap bitmap bytes, $badScreen colour bytes") }

$summary = "{0}: {1} frames, {2} moving, {3} stall frames, update done by line {4}, final view ({5},{6}) cell ({7},{8})" -f `
$sc.name, $frames.Count, $steps, $stalls, $lastLine, $last.vx, $last.vy, $last.cx, $last.cy
$summary = "{0}: {1} frames (per phase {9}), {2} moving, {3} stall frames, update done by line {4}, final view ({5},{6}) cell ({7},{8})" -f `
$sc.name, $frames.Count, $steps, $stalls, $lastLine, $last.vx, $last.vy, $last.cx, $last.cy, ($phaseFrames -join '/')
if ($failures.Count -gt 0) {
$failedScenarios++
Write-Host " FAIL $summary" -ForegroundColor Red


+ 84
- 31
tools/check-split.ps1 Переглянути файл

@@ -5,15 +5,25 @@
.DESCRIPTION
Runs x64sc (NTSC, warp, private config) with monitor tracepoints:
- at split_store (src/status.inc): logs the raster line and cycle where the three
mode writes start, every frame;
- at people_moved: logs the hidden buffer, both drawn counts and the people-in-view
digits of both status text screens.
mode writes start, the map's y-scroll (map_d011) and the patched split delay,
every frame;
- on the key_row_* instructions (src/keys.inc): fakes "no key" (keys typed on the PC
while a headless VICE has focus would otherwise reach the program), then holds
CRSR DOWN from frame 30 until the view is at cell row 3, then SHIFT+CRSR DOWN
until it is back at row 0, then no key, so every map y-scroll value (0-7) is split;
- at people_moved: logs the view position, the people table with move_frame, and the
people-in-view digits of text screen 1 in both banks.
Then checks:
- every split starts between line 210 cycle 53 and line 210 cycle 64. This window
was measured by sweeping the delay: starts at 210:40-51 damaged the last map
- every split starts between line 210 cycle 53 and line 210 cycle 64, for every
y-scroll value, and every y-scroll value 0-7 was seen. This window was measured
at y-scroll 3 by sweeping the delay: starts at 210:40-51 damaged the last map
line, 211:0-11 damaged the first text line, 210:50-211:1 were clean;
- a split happens on every frame (no missed interrupt);
- the status digits of the hidden buffer equal the number of people drawn into it;
- the status is updated every 4th frame (move_frame a multiple of 4, after
people_moved): in the frame after each update, the digits in both banks equal the
number of people whose dot is at least partly inside the visible map window
(24-row, 38-column display; buffer pixel rows fy..fy+155 and hires pixel columns
fx..fx+303), counted here from the people table and view of the updating frame;
- in the exit screenshot, the 40 text lines (raster 211-250) contain only brown
and light red, status rows 20, 21, 22 and 24 are lit and row 23 is empty, and
the last map line (raster 210) uses no colour foreign to the map. This is a
@@ -50,19 +60,36 @@ $dir = Get-RepoPath 'build/check-split'
if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force }
New-Item -ItemType Directory -Force -Path $dir | Out-Null

$store = Get-Label $target 'split_store'
$moved = Get-Label $target 'people_moved'
$hidden = Get-Label $target 'hidden'
$drawn = Get-Label $target 'drawn_count'
$L = @{}
foreach ($sym in 'split_store', 'split_delay', 'people_moved', 'smoke_ready', 'people_cx', 'map_d011', 'move_frame', 'view_cx', 'view_cy', 'view_fy',
'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space') { $L[$sym] = Get-Label $target $sym }
$digits = @(0x4400, 0x8400) | ForEach-Object { $_ + 22 * 40 + 15 } # row 22, after "PEOPLE IN VIEW "
Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value @(
$PHASE = 0xCFF0 # free RAM: scroll phase 0 still, 1 down, 2 up, 3 still
$cond = { param($pairs) ($pairs | ForEach-Object { '(@cpu:${0:x4} == ${1:x2})' -f $_[0], $_[1] }) -join ' && ' }
if ($L.move_frame -ne $L.people_cx + 80) { throw 'move_frame must follow the five people tables (src/people.inc)' }
# Checkpoints 1-5 keep their numbers: the parser below relies on them.
$mon = @(
'logname "monitor.log"', 'log on'
('trace exec ${0:x4}' -f $store)
('trace exec ${0:x4}' -f $moved), ('command 2 "m {0:x4} {0:x4}"' -f $hidden)
('trace exec ${0:x4}' -f $moved), ('command 3 "m {0:x4} {1:x4}"' -f $drawn, ($drawn + 1))
('trace exec ${0:x4}' -f $moved), ('command 4 "m {0:x4} {1:x4}"' -f $digits[0], ($digits[0] + 1))
('trace exec ${0:x4}' -f $moved), ('command 5 "m {0:x4} {1:x4}"' -f $digits[1], ($digits[1] + 1))
('trace exec ${0:x4}' -f $L.split_store), ('command 1 "m {0:x4} {0:x4}"' -f $L.map_d011)
('trace exec ${0:x4}' -f $L.people_moved), ('command 2 "m {0:x4} {1:x4}"' -f $L.view_cx, ($L.view_cx + 3))
('trace exec ${0:x4}' -f $L.people_moved), ('command 3 "m {0:x4} {1:x4}"' -f $L.people_cx, ($L.people_cx + 80))
('trace exec ${0:x4}' -f $L.people_moved), ('command 4 "m {0:x4} {1:x4}"' -f $digits[0], ($digits[0] + 1))
('trace exec ${0:x4}' -f $L.people_moved), ('command 5 "m {0:x4} {1:x4}"' -f $digits[1], ($digits[1] + 1))
('trace exec ${0:x4}' -f $L.split_store), ('command 6 "m {0:x4} {0:x4}"' -f ($L.split_delay + 1))
('trace exec ${0:x4}' -f $L.smoke_ready), ('command 7 "> {0:x4} 00"' -f $PHASE)
)
$n = 7
foreach ($row in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space') {
$n++; $mon += ('trace exec ${0:x4}' -f $L[$row]); $mon += ('command {0} "r a = ff"' -f $n)
}
$n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_cursor, (& $cond @(, @($PHASE, 1)))); $mon += ('command {0} "r a = 7f"' -f $n)
$n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_cursor, (& $cond @(, @($PHASE, 2)))); $mon += ('command {0} "r a = 7f"' -f $n)
$n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_lshift, (& $cond @(, @($PHASE, 2)))); $mon += ('command {0} "r a = 7f"' -f $n)
# Phase changes, latest first so one frame moves on at most one phase.
$n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.people_moved, (& $cond @(@($PHASE, 2), @($L.view_cy, 0), @($L.view_fy, 0)))); $mon += ('command {0} "> {1:x4} 03"' -f $n, $PHASE)
$n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.people_moved, (& $cond @(@($PHASE, 1), @($L.view_cy, 3), @($L.view_fy, 0)))); $mon += ('command {0} "> {1:x4} 02"' -f $n, $PHASE)
$n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.people_moved, (& $cond @(@($PHASE, 0), @($L.move_frame, 30)))); $mon += ('command {0} "> {1:x4} 01"' -f $n, $PHASE)
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, '-exitscreenshot', 'screen.png', '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
@@ -78,37 +105,63 @@ if (-not (Test-Path -LiteralPath $log)) { Write-Host '[FAIL] no monitor log' -Fo

# Split timing.
$starts = [System.Collections.Generic.List[string]]::new()
$splitFrames = 0; $moveFrames = 0; $badCounts = 0
$values = @{}
$splits = [System.Collections.Generic.List[hashtable]]::new()
$split = $null
$splitFrames = 0; $moveFrames = 0; $badCounts = 0; $checkedCounts = 0
$lastCheckpoint = 0
$frame = $null; $prev = $null
# Independent count: a person is in view if any part of their dot is in the visible window.
function Get-InView($f) {
$count = 0
for ($i = 0; $i -lt 16; $i++) {
$y = 8 * ($f.people[32 + $i] - $f.cy) + $f.people[48 + $i] - $f.fy
$x = 8 * ($f.people[$i] - $f.cx) + 2 * $f.people[16 + $i]
if ($y -ge 0 -and $y -le 155 -and $x + 1 -ge $f.fx -and $x -le $f.fx + 303) { $count++ }
}
$count
}
foreach ($line in Get-Content -LiteralPath $log) {
if ($line -match '^#(\d+) \(Trace\s+exec [0-9a-fA-F]+\)\s+(\d+)/\$\w+,\s+(\d+)/') {
$lastCheckpoint = [int]$Matches[1]
if ($lastCheckpoint -eq 1) {
$splitFrames++
$rl = [int]$Matches[2]; $cy = [int]$Matches[3]
$starts.Add("${rl}:$cy")
if ($rl -ne 210 -or $cy -lt 53 -or $cy -gt 64) { $failures.Add("split started at line $rl cycle $cy (allowed 210:53-210:64)") }
$split = @{ line = [int]$Matches[2]; cycle = [int]$Matches[3] }
$splits.Add($split)
}
if ($lastCheckpoint -eq 2) { $prev = $frame; $frame = @{ people = [System.Collections.Generic.List[byte]]::new(); digits = @() } }
continue
}
if ($line -match '^>C:[0-9a-fA-F]{4} ((?:[0-9a-fA-F]{2} )+)') {
$bytes = @($Matches[1].Trim() -split ' ' | ForEach-Object { [Convert]::ToByte($_, 16) })
$values[$lastCheckpoint] = $bytes
if ($lastCheckpoint -eq 1 -and $null -ne $split) { $split.y = $bytes[0] -band 7 }
if ($lastCheckpoint -eq 6 -and $null -ne $split) { $split.delay = $bytes[0] }
if ($null -eq $frame) { continue }
if ($lastCheckpoint -eq 2) { $frame.cx = $bytes[0]; $frame.fx = $bytes[1]; $frame.cy = $bytes[2]; $frame.fy = $bytes[3] }
if ($lastCheckpoint -eq 3) { foreach ($b in $bytes) { if ($frame.people.Count -lt 81) { $frame.people.Add($b) } } }
if ($lastCheckpoint -eq 4 -or $lastCheckpoint -eq 5) { $frame.digits += , (($bytes[0] - 0x30) * 10 + ($bytes[1] - 0x30)) }
if ($lastCheckpoint -eq 5) {
$moveFrames++
$h = $values[2][0]
$count = $values[3][$h]
$shown = $values[4 + $h]
$number = ($shown[0] - 0x30) * 10 + ($shown[1] - 0x30)
if ($number -ne $count) { $badCounts++ }
if ($null -ne $prev -and $prev.people.Count -eq 81 -and ($prev.people[80] -band 3) -eq 0) {
$checkedCounts++
$want = Get-InView $prev
if ($frame.digits[0] -ne $want -or $frame.digits[1] -ne $want) { $badCounts++ }
}
}
}
if ($failures.Count -gt 10) { break }
}
$monErrors = @(Select-String -LiteralPath $log -Pattern '^ERROR|not a valid checkpoint' | Select-Object -First 3)
foreach ($e in $monErrors) { $failures.Add("monitor script error: $($e.Line.Trim())") }
foreach ($sp in $splits) {
$starts.Add("y$($sp.y) d$($sp.delay) $($sp.line):$($sp.cycle)")
if ($sp.line -ne 210 -or $sp.cycle -lt 53 -or $sp.cycle -gt 64) { $failures.Add("split at y-scroll $($sp.y) started at line $($sp.line) cycle $($sp.cycle) (allowed 210:53-210:64)") }
}
$seenY = @($splits | ForEach-Object { $_.y } | Where-Object { $null -ne $_ } | Sort-Object -Unique)
if ($seenY.Count -ne 8) { $failures.Add("splits seen only at y-scroll $($seenY -join ', ') (expected 0-7)") }
if ($splitFrames -lt 100) { $failures.Add("only $splitFrames splits logged") }
if ([Math]::Abs($splitFrames - $moveFrames) -gt 2) { $failures.Add("$splitFrames splits for $moveFrames frames: an interrupt was missed") }
if ($badCounts -gt 0) { $failures.Add("people-in-view digits differed from the drawn count in $badCounts frames") }
if ($checkedCounts -lt 50) { $failures.Add("only $checkedCounts status updates checked") }
if ($badCounts -gt 0) { $failures.Add("people-in-view digits differed from the people in the visible window after $badCounts of $checkedCounts status updates") }

# Screenshot: raster line r is at y = r - 28 in x64sc's NTSC screenshot.
Add-Type -AssemblyName System.Drawing
@@ -138,12 +191,12 @@ if (-not (Test-Path -LiteralPath $shot)) { $failures.Add('no exit screenshot') }
}

$distinct = ($starts | Group-Object | Sort-Object Name | ForEach-Object { "$($_.Name) x$($_.Count)" }) -join ', '
Write-Host "Split starts (line:cycle): $distinct"
Write-Host "Frames: $splitFrames splits, $moveFrames people updates; people-in-view digits wrong in $badCounts frames."
Write-Host "Split starts (y-scroll, delay, line:cycle): $distinct"
Write-Host "Frames: $splitFrames splits, $moveFrames people updates; people-in-view digits wrong after $badCounts of $checkedCounts status updates."
if ($failures.Count -gt 0) {
$failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" }
Write-Host '[FAIL] split check' -ForegroundColor Red
exit 1
}
Write-Host '[PASS] split writes land in the measured border window every frame; status digits match; no foreign colours at the boundary.' -ForegroundColor Green
Write-Host '[PASS] split writes land in the measured border window every frame at every y-scroll; status digits match; no foreign colours at the boundary.' -ForegroundColor Green
exit 0

Завантаження…
Відмінити
Зберегти

Powered by TurnKey Linux.