Procházet zdrojové kódy

M3.3 fix: never show a half-rebuilt buffer when a scroll starts

User report: the top of the screen tore a little when scrolling left or
right. Starting a scroll from rest restarted the rebuild of the hidden
buffer in the frame people had been drawn into it with a flip pending, so
the next vertical blank showed it half rebuilt for up to 8 frames.
choose_rebuild_target now waits while people_flip_pending is set.

check-scroll.ps1 checks every frame that the shown buffer is complete and
built for the view's cell (fails on the old code in all three scenarios)
and that nothing is stored into the shown map during raster 55-210.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main
Daniel Covington před 2 dny
rodič
revize
a40ea04328
4 změnil soubory, kde provedl 42 přidání a 4 odebrání
  1. +1
    -1
      docs/toolchain.md
  2. +3
    -1
      docs/verification-status.md
  3. +7
    -1
      src/scroll.inc
  4. +31
    -1
      tools/check-scroll.ps1

+ 1
- 1
docs/toolchain.md Zobrazit soubor

@@ -59,7 +59,7 @@ Starter configurations marked verified were exercised by the Foundry's automated
- World check: `pwsh -File tools/check-world.ps1` validates the tile data saved by the smoke test.
- Split check: `pwsh -File tools/check-split.ps1` runs VICE headless for 20,000,000 cycles. It logs the raster line and cycle of the three mode writes at `split_store` (src/status.inc) every frame and requires them to start between line 210 cycle 53 and line 210 cycle 64. That window was measured by building with split delays 6-12 under `+autostart-delay-random`: starts at 210:40-51 damaged the last map line, starts at 211:0-11 damaged the first text line, and 210:50-211:1 were clean; the shipped delay starts at 210:55-61 at y-scroll 3. Tracepoints on the `key_row_*` instructions fake "no key" and then scroll down three cells and back up (phase byte at $CFF0, VICE conditional checkpoints), so every map y-scroll value 0-7 is split and checked against the same window (y-scroll 2, a bad line at line 210, uses a shorter delay; measured 2026-12-03: starts at 210:58-64). It also checks that a split happens every frame, that after each status update the people-in-view digits equal the number of people whose dot is at least partly in the visible window (computed by the script from the people table and view), and (coarsely) the screenshot colours at the boundary. Output: `build/check-split/`.
- Key check: `pwsh -File tools/check-keys.ps1` runs eight headless VICE scenarios. VICE's monitor cannot press keys, so tracepoints on the `key_row_*` instructions in `src/keys.inc` replace the port B row bits with those of held keys (`r a = <bits>`). It checks `scroll_dx`/`scroll_dy` for no key, right, left (right SHIFT), down, up (left SHIFT), down-right and up-left, and that SPACE held from frame 60 regenerates exactly once. Output: `build/check-keys/`.
- Scroll check: `pwsh -File tools/check-scroll.ps1` runs three headless VICE scenarios (edges, middle, reverse). Each is a list of phases: fake held keys (as in the key check) until a condition on the program state is met at `people_moved` (a `move_frame` value or a view position). The phase number is kept in free RAM at $CFF0 and moved on by VICE conditional checkpoints (`trace exec $addr if (@cpu:$addr == $nn) && (...)`: the parentheses are needed, and checkpoints at one address run in the order they were defined, so phase changes are defined latest first). Every frame it logs the phase, view, scroll registers, visible buffer, flip state and people table. It checks that the view moves at most one pixel per axis per frame and only in the direction of the keys read the frame before, stays inside 0-336 x 0-244 and stops at the edges, that $D011/$D016 match the fine scroll, that 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/`.
- Scroll check: `pwsh -File tools/check-scroll.ps1` runs three headless VICE scenarios (edges, middle, reverse). Each is a list of phases: fake held keys (as in the key check) until a condition on the program state is met at `people_moved` (a `move_frame` value or a view position). The phase number is kept in free RAM at $CFF0 and moved on by VICE conditional checkpoints (`trace exec $addr if (@cpu:$addr == $nn) && (...)`: the parentheses are needed, and checkpoints at one address run in the order they were defined, so phase changes are defined latest first). Every frame it logs the phase, view, scroll registers, visible buffer, flip state and people table. It checks that the view moves at most one pixel per axis per frame and only in the direction of the keys read the frame before, stays inside 0-336 x 0-244 and stops at the edges, that $D011/$D016 match the fine scroll, that in every frame the shown buffer is complete and built for the view's cell (a half-rebuilt buffer on screen tears the top of the map), that nothing is stored into the shown buffer's map screen RAM or bitmap during raster 55-210, that no frame is missed and the people update ends before raster 55, and reports frames where a held key did not move the view (stalls, allowed up to 40). At the end it compares the buffer about to be shown, byte for byte, with a fresh render of the world at the view plus the people's dots (and, when a flip is pending, the shown buffer with the previous frame's dots). 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


+ 3
- 1
docs/verification-status.md Zobrazit soubor

@@ -16,11 +16,13 @@ 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). | 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.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) | problem reported (2026-12-03): "the top of the screen tears a little when I go left or right"; fixed, re-test of MT3.1-MT3.3 pending |
| 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 (M3.3 fix): The user reported a small tear at the top of the screen when scrolling left or right. Cause: when a scroll started from rest, choose_rebuild_target restarted the rebuild of the hidden buffer in the same frame that people had been drawn into it with a flip pending; the next vertical blank showed that half-rebuilt buffer (top rows already one cell on) for up to 8 frames, until the next cell crossing. It happened for every direction, not only left and right. Fix (src/scroll.inc): no rebuild restart while people_flip_pending is set; the other buffer is rebuilt from the next frame. tools/check-scroll.ps1 now checks in every frame that the shown buffer is complete and built for the view's cell: on the old code it failed in all three scenarios (frames 30-37, ready 0, origin one cell on); it also checks that nothing is stored into the shown buffer's map while the map is displayed (no such store was found, before or after the fix).

- 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.


+ 7
- 1
src/scroll.inc Zobrazit soubor

@@ -310,8 +310,14 @@ frames_to_cross:
; After the keys are read: the hidden buffer should hold the origin of the
; next cell crossing in the held direction, or the current origin when the
; view is still (then people flip every frame again). Restart its rebuild
; when the target changes.
; when the target changes. Not while a people flip is pending: the hidden
; buffer is shown at the next vertical blank, so it must stay complete (the
; buffer it replaces becomes hidden then and is rebuilt from the next frame).
choose_rebuild_target:
lda people_flip_pending
beq @choose
rts
@choose:
lda view_cx
sta rb_tx
lda view_cy


+ 31
- 1
tools/check-scroll.ps1 Zobrazit soubor

@@ -24,7 +24,11 @@
vx 0-336, vy 0-244; the fine-scroll registers match the view
- 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
- in every frame the shown buffer is complete (buf_ready) and built for the view's
cell (buf_cx, buf_cy); a half-rebuilt buffer on screen tears the top of the map
- the main loop never misses a frame and the people update ends before raster 55
- nothing is stored into the shown buffer's map screen RAM or bitmap while the map
is displayed (raster 55-210): such a store tears the picture
- 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 buffer about to be shown (bitmap and screen RAM) equals a fresh
@@ -84,7 +88,7 @@ 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',
'move_frame', 'people_flip_pending', 'buf_cx', 'buf_cy', 'buf_ready', '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.
@@ -153,12 +157,25 @@ foreach ($sc in $scenarios) {
& $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} {1:x4}' -f $L.buf_cx, ($L.buf_cx + 1)) $null
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.buf_cy, ($L.buf_cy + 1)) $null
& $add $L.people_moved ('m {0:x4} {1:x4}' -f $L.buf_ready, ($L.buf_ready + 1)) $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))
}
# Stores into the shown buffer's map (screen RAM rows 0-20, bitmap) while the map is displayed
# (raster 55-210) would tear the picture. Armed at smoke_ready, so start-up is not counted.
$firstStore = $n + 1
foreach ($range in @(@(0, 0x4000, 0x4347), @(0, 0x6000, 0x7a3f), @(1, 0x8000, 0x8347), @(1, 0xa000, 0xba3f))) {
$n++
$mon.Add(('trace store ${0:x4} ${1:x4} if (@cpu:${2:x4} == ${3:x2}) && (RL > $36) && (RL < $d3)' -f $range[1], $range[2], $L.visible, $range[0]))
$mon.Add("disable $n")
}
$lastStore = $n
for ($c = $firstStore; $c -le $lastStore; $c++) { & $add $L.smoke_ready "enable $c" $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)
@@ -184,6 +201,9 @@ foreach ($sc in $scenarios) {
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 -eq $L.buf_cx) { $cur.bufcx = $bytes[0..1] }
elseif ($addr -eq $L.buf_cy) { $cur.bufcy = $bytes[0..1] }
elseif ($addr -eq $L.buf_ready) { $cur.ready = $bytes[0..1] }
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()
@@ -191,6 +211,12 @@ foreach ($sc in $scenarios) {
$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") }
$tears = @(Select-String -LiteralPath (Join-Path $dir 'monitor.log') -Pattern '^#(\d+) \(Trace\s+store ([0-9a-fA-F]{4})\)\s+(\d+)/' |
Where-Object { [int]$_.Matches[0].Groups[1].Value -ge $firstStore -and [int]$_.Matches[0].Groups[1].Value -lt $firstStore + 4 })
if ($tears.Count -gt 0) {
$t = $tears[0].Matches[0].Groups
$failures.Add("$($tears.Count) store(s) into the shown buffer while the map was displayed (first: `$$($t[2].Value) at raster line $($t[3].Value))")
}
$stalls = 0; $steps = 0; $late = 0; $lastLine = 0
$maxVx = 0; $maxVy = 0; $minAfterMaxVx = 999; $minAfterMaxVy = 999
$phaseFrames = @(0) * $sc.phases.Count
@@ -201,6 +227,10 @@ foreach ($sc in $scenarios) {
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)) }
$v = $f.visible
if (-not $f.ready[$v] -or $f.bufcx[$v] -ne $f.cx -or $f.bufcy[$v] -ne $f.cy) {
$failures.Add("frame ${i}: shown buffer $v is not a complete render at the view cell (ready $($f.ready[$v]), origin $($f.bufcx[$v]),$($f.bufcy[$v]), view cell $($f.cx),$($f.cy))")
}
if ($f.line -ge 55 -and $f.line -lt 251) { $failures.Add("frame ${i}: people update ended at raster line $($f.line)") }
elseif ($f.line -lt 55) { $lastLine = [Math]::Max($lastLine, $f.line) }
if ($i -gt 0) {


Načítá se…
Zrušit
Uložit

Powered by TurnKey Linux.