Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>main
| @@ -91,7 +91,7 @@ Expected: | |||
| - Dots move at least once per second (each takes about 7 small steps a second and sometimes changes direction). | |||
| - No dot enters blue or grey pixels. A dot that reaches water or stone turns away. | |||
| - After SPACE, dots appear on the new map and keep moving. | |||
| - At M2.1 the dots are drawn straight into the visible buffer during vertical blank; small flicker or a missed frame is not a failure until M2.2 adds the buffer flip (MT2.2). | |||
| - From M2.2 the dots are drawn into the hidden buffer, which is flipped into view each frame (see MT2.2). | |||
| Verifies: R2 | |||
| @@ -101,12 +101,17 @@ Setup: VICE x64sc, NTSC (-ntsc), warp off. | |||
| Start: `pwsh -File tools/run.ps1 -Target c64` | |||
| Steps: | |||
| 1. Let it run for 5 minutes. | |||
| 2. Inspect the map closely. | |||
| 1. Run `pwsh -File tools/check-people.ps1` and note the result. | |||
| 2. Start the program and let it run for 5 minutes at normal speed (warp off). | |||
| 3. Watch the dots closely during that time, especially where two dots pass close to each other. | |||
| 4. At the end, inspect the map closely, including the places dots walked over. | |||
| 5. Tap SPACE, let the new map run for a minute, and inspect it again. | |||
| Expected: | |||
| - No flicker | |||
| - No light red trails or damaged terrain | |||
| - `tools/check-people.ps1` prints `[PASS]`, with `0 missed` buffer flips. | |||
| - Dots step smoothly; they never flicker, blink out, or show doubled or half-drawn. | |||
| - The terrain does not flicker or shake (both buffers show the same map). | |||
| - No light red trails and no damaged terrain pixels where dots have been. | |||
| Verifies: R3 | |||
| @@ -56,7 +56,7 @@ Starter configurations marked verified were exercised by the Foundry's automated | |||
| - World generation reached its ready point (`MAP READY`) | |||
| - 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. | |||
| - 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. Output: `build/check-people/`. | |||
| - 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 | |||
| @@ -13,11 +13,14 @@ manual = `pending`, `confirmed by user (<date>)`, `problem reported (<date>): <n | |||
| | M1.2 Seeded generator: 80x50 tile world with water, stone, grass with trees, and connected roads; enforce the at-most-two-colours-per-cell rule. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`) | confirmed by user (2026-12-03) | | |||
| | M1.3 Render the top-left screen of the world into the visible buffer; SPACE regenerates. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; VICE monitor buffered SPACE and compared all 1,000 visible cells before and after) | confirmed by user (2026-12-03) | | |||
| | M2.1 People table (world x, y, direction) and movement rules; water and stone block. | 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,106 frames logged, every person stepped 263-264 times, none on water or stone) | confirmed by user (2026-12-03) | | |||
| | M2.2 Per-buffer saved-byte lists: restore the bytes under people from two frames ago, draw people in view, flip in vertical blank. | not run | pending | | |||
| | 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) | pending | | |||
| | M3.1 Keyboard matrix reading for the cursor keys with SHIFT, held-key repeat. | not run | pending | | |||
| | M3.2 Fine scroll via $D016/$D011 in 38x24 mode; rebuild the hidden buffer from tiles over 8 frames and flip on wrap; stop at world edges. | not run | pending | | |||
| | M3.3 Draw people relative to the view; measure the frame budget with a border-colour timing bar. | not run | pending | | |||
| ## Notes | |||
| - 2026-12-03 (M2.2): VICE x64sc NTSC runs 263 lines x 65 cycles = 17,095 cycles per frame (measured with tools/check-people.ps1). The spec's budget says 17,030 (the 262-line 6567R56A figure). The difference does not affect any acceptance criterion. Correcting the spec text needs the user's approval (AGENTS.md section 6). | |||
| - 2026-12-03 (M2.2): A3 checked in VICE only: flipping the two buffers with the $DD00 bank bits in vertical blank shows the same map in both banks and passes the byte-exact buffer check. The user's MT2.2 visual check is still pending. | |||
| - Generated 2026-12-03. Starter verification at generation time is reported by the Foundry; re-run `pwsh -File tools/smoke.ps1` on your machine and record the result in row M0.1. | |||
| @@ -16,7 +16,7 @@ | |||
| ; During generation VIC bank 0 displays the message at $0400. In bitmap mode | |||
| ; that text screen is hidden and holds the smoke test status mirror. | |||
| .export smoke_ready | |||
| .export smoke_ready, visible | |||
| ; ---------------------------------------------------------------- hardware | |||
| VIC_CTRL1 = $D011 ; bit 5 bitmap mode, bit 4 display on, bit 3 25 rows | |||
| @@ -36,11 +36,14 @@ TEXT_SCREEN = $0400 | |||
| SCREEN_A = $4000 | |||
| BITMAP_A = $6000 | |||
| SCREEN_B = $8000 | |||
| BITMAP_B = $A000 | |||
| VIEW_WIDTH = 40 | |||
| VIEW_HEIGHT = 25 | |||
| BANK_TEXT_BITS = %00000011 ; VIC bank 0 ($0000-$3FFF) | |||
| BANK_A_BITS = %00000010 ; VIC bank 1 ($4000-$7FFF) | |||
| BANK_B_BITS = %00000001 ; VIC bank 2 ($8000-$BFFF) | |||
| COL_BROWN = 9 | |||
| COL_LIGHT_RED = 10 | |||
| @@ -73,12 +76,22 @@ start: | |||
| smoke_ready: ; first generated world is on screen | |||
| nop | |||
| ; Each frame: in the hidden buffer, restore the bytes under the people drawn | |||
| ; there two frames ago, move the people, draw them, then flip that buffer into | |||
| ; view during vertical blank. | |||
| main_loop: | |||
| jsr wait_frame ; people are redrawn below the visible area | |||
| lda visible | |||
| eor #1 | |||
| sta hidden | |||
| jsr restore_people | |||
| jsr draw_people | |||
| jsr move_people | |||
| people_moved: ; smoke hook: one movement step done | |||
| jsr draw_people | |||
| people_moved: ; check hook: hidden buffer holds the new step | |||
| jsr wait_frame | |||
| ldx hidden | |||
| lda buffer_bank_bits,x | |||
| jsr set_bank | |||
| stx visible | |||
| jsr GETIN | |||
| cmp #PETSCII_SPACE | |||
| bne main_loop | |||
| @@ -105,7 +118,12 @@ rebuild_map: | |||
| jsr generate_world_from_timer | |||
| jsr place_people | |||
| lda #>SCREEN_A | |||
| jsr draw_world_view | |||
| lda #>SCREEN_B | |||
| jsr draw_world_view | |||
| lda #0 | |||
| sta visible ; buffer A is shown first | |||
| jsr wait_frame ; switch banks and modes below the visible area | |||
| lda #BANK_A_BITS | |||
| @@ -123,18 +141,22 @@ rebuild_map: | |||
| bpl @ready | |||
| rts | |||
| ; Wait until the raster reaches FLIP_RASTER, then until it has left that line, | |||
| ; so each call returns once per frame. | |||
| ; Wait until the raster is below the visible area (line FLIP_RASTER or later, | |||
| ; up to the last line 262). First wait to leave that range, so each call returns | |||
| ; once per frame. A range rather than one exact line: the KERNAL interrupt can | |||
| ; run across line FLIP_RASTER, and an exact-line poll would then miss a frame. | |||
| wait_frame: | |||
| @until: lda VIC_RASTER | |||
| @leave: bit VIC_CTRL1 ; bit 7 = raster bit 8: lines 256-262 | |||
| bmi @leave | |||
| lda VIC_RASTER | |||
| cmp #FLIP_RASTER | |||
| bne @until | |||
| bit VIC_CTRL1 ; bit 7 = raster bit 8; line 251, not 507 | |||
| bmi @until | |||
| @leave: lda VIC_RASTER | |||
| bcs @leave | |||
| @until: bit VIC_CTRL1 | |||
| bmi @done | |||
| lda VIC_RASTER | |||
| cmp #FLIP_RASTER | |||
| beq @leave | |||
| rts | |||
| bcc @until | |||
| @done: rts | |||
| ; A = bank bits for $DD00. Keeps the other bits. | |||
| set_bank: | |||
| @@ -145,16 +167,16 @@ set_bank: | |||
| sta CIA2_PRA | |||
| rts | |||
| ; Render the first 40 columns of each of the first 25 world rows. | |||
| ; Render the first 40 columns of each of the first 25 world rows into one | |||
| ; buffer. A = high byte of its screen RAM; its bitmap is $2000 above that. | |||
| draw_world_view: | |||
| lda #<BITMAP_A | |||
| sta bmp | |||
| lda #>BITMAP_A | |||
| sta scr+1 | |||
| clc | |||
| adc #>(BITMAP_A - SCREEN_A) | |||
| sta bmp+1 | |||
| lda #<SCREEN_A | |||
| lda #0 | |||
| sta bmp | |||
| sta scr | |||
| lda #>SCREEN_A | |||
| sta scr+1 | |||
| lda #0 | |||
| sta view_row | |||
| @row: ldx view_row | |||
| @@ -243,6 +265,7 @@ write_generating: | |||
| rts | |||
| .segment "RODATA" | |||
| buffer_bank_bits: .byte BANK_A_BITS, BANK_B_BITS | |||
| title_text: .byte "LAND MAP 64", 0 | |||
| generating_text: .byte "GENERATING..." | |||
| STATUS_LENGTH = * - generating_text | |||
| @@ -251,6 +274,8 @@ ready_text: .byte "MAP READY " | |||
| .segment "BSS" | |||
| bank_bits: .res 1 | |||
| visible: .res 1 ; buffer on screen: 0 = A, 1 = B | |||
| hidden: .res 1 ; buffer being drawn: visible EOR 1 | |||
| view_row: .res 1 | |||
| view_column: .res 1 | |||
| @@ -19,6 +19,7 @@ TURN_TRIES = 5 ; current direction, then all four from a random | |||
| place_people: | |||
| lda #0 | |||
| sta drawn_count | |||
| sta drawn_count+1 | |||
| sta move_frame | |||
| tax | |||
| @person: | |||
| @@ -186,10 +187,17 @@ candidate_blocked: | |||
| @open: clc | |||
| rts | |||
| ; Put back the bitmap bytes saved by draw_people, newest first, so people that | |||
| ; share a byte restore correctly. | |||
| ; Put back the bitmap bytes saved when people were last drawn into the hidden | |||
| ; buffer (two frames ago), newest first, so people that share a byte restore | |||
| ; correctly. Only those bytes change: the rest of the map is never redrawn. | |||
| restore_people: | |||
| ldx drawn_count | |||
| ldx hidden | |||
| lda list_starts,x | |||
| sta list_start | |||
| clc | |||
| adc drawn_count,x | |||
| tax ; X = one past the newest saved byte | |||
| cpx list_start | |||
| beq @done | |||
| @loop: dex | |||
| lda drawn_low,x | |||
| @@ -199,14 +207,23 @@ restore_people: | |||
| lda drawn_byte,x | |||
| ldy #0 | |||
| sta (bmp),y | |||
| txa | |||
| cpx list_start | |||
| bne @loop | |||
| stx drawn_count | |||
| @done: rts | |||
| @done: ldx hidden | |||
| lda #0 | |||
| sta drawn_count,x | |||
| rts | |||
| ; Draw every person inside the view (the top-left screen) into buffer A, | |||
| ; saving the byte under each one. Call restore_people first. | |||
| ; Draw every person inside the view (the top-left screen) into the hidden | |||
| ; buffer, saving the byte under each one in that buffer's list. | |||
| ; Call restore_people first. | |||
| draw_people: | |||
| ldx hidden | |||
| lda list_starts,x | |||
| sta list_start | |||
| sta list_pos | |||
| lda buffer_bitmap_offsets,x | |||
| sta bitmap_offset | |||
| ldx #0 | |||
| @person: | |||
| lda people_cy,x | |||
| @@ -231,10 +248,12 @@ draw_people: | |||
| sta bmp | |||
| lda bmp+1 | |||
| adc bitmap_row_high,y | |||
| clc | |||
| adc bitmap_offset ; buffer A or B | |||
| sta bmp+1 | |||
| ldy #0 | |||
| lda (bmp),y | |||
| ldy drawn_count | |||
| ldy list_pos | |||
| sta drawn_byte,y | |||
| lda bmp | |||
| sta drawn_low,y | |||
| @@ -245,14 +264,21 @@ draw_people: | |||
| ora pixel_masks,y ; pixel %11 = colour RAM = light red | |||
| ldy #0 | |||
| sta (bmp),y | |||
| inc drawn_count | |||
| inc list_pos | |||
| @next: inx | |||
| cpx #PEOPLE_COUNT | |||
| bne @person | |||
| lda list_pos | |||
| sec | |||
| sbc list_start | |||
| ldx hidden | |||
| sta drawn_count,x | |||
| rts | |||
| .segment "RODATA" | |||
| pixel_masks: .byte $C0, $30, $0C, $03 | |||
| list_starts: .byte 0, PEOPLE_COUNT | |||
| buffer_bitmap_offsets: .byte 0, >(BITMAP_B - BITMAP_A) | |||
| bitmap_row_low: | |||
| .repeat VIEW_HEIGHT, row | |||
| .byte <(BITMAP_A + 320 * row) | |||
| @@ -276,8 +302,12 @@ cand_cx: .res 1 | |||
| cand_sx: .res 1 | |||
| cand_cy: .res 1 | |||
| cand_sy: .res 1 | |||
| drawn_count: .res 1 | |||
| drawn_low: .res PEOPLE_COUNT | |||
| drawn_high: .res PEOPLE_COUNT | |||
| drawn_byte: .res PEOPLE_COUNT | |||
| ; Saved-byte lists: entries 0-15 belong to buffer A, 16-31 to buffer B. | |||
| drawn_count: .res 2 | |||
| drawn_low: .res 2 * PEOPLE_COUNT | |||
| drawn_high: .res 2 * PEOPLE_COUNT | |||
| drawn_byte: .res 2 * PEOPLE_COUNT | |||
| list_start: .res 1 | |||
| list_pos: .res 1 | |||
| bitmap_offset: .res 1 | |||
| .assert * <= SCREEN_A, lderror, "People data must fit below VIC bank 1" | |||
| @@ -1,15 +1,22 @@ | |||
| <# | |||
| .SYNOPSIS | |||
| Run the C64 build headless in VICE and check that the 16 people move and never | |||
| stand on water or stone. | |||
| Run the C64 build headless in VICE and check that the 16 people move, never | |||
| stand on water or stone, and are redrawn in both buffers without trails. | |||
| .DESCRIPTION | |||
| Starts x64sc (NTSC, warp, private config) like tools/smoke.ps1. Monitor tracepoints: | |||
| - at smoke_ready: save the world tiles (world.bin); | |||
| - at people_moved (once per frame): print the people table to the monitor log. | |||
| - at smoke_ready: save the world tiles and both clean bitmaps (no people yet); | |||
| - at people_moved (once per frame, after drawing into the hidden buffer and | |||
| before the flip): print the people table and the visible-buffer flag to the | |||
| monitor log, and save both bitmaps (each frame overwrites the last). | |||
| VICE quits after -Cycles cycles. The script then checks every logged frame: | |||
| 16 people inside the 80x50 world, every one on a walkable tile (not water or stone), | |||
| every step at most one pixel, and every person moving during the run. | |||
| every step at most one pixel, and every person moving during the run. It checks | |||
| that the main loop never misses a frame (x64sc NTSC frame = 263 lines x 65 = | |||
| 17,095 cycles; a gap over 1.5 frames fails), and that | |||
| in the final frame the hidden bitmap equals the clean map plus the people's current | |||
| dots and the visible bitmap equals the clean map plus the previous frame's dots: | |||
| no trails, no damaged terrain. | |||
| Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing. | |||
| @@ -55,15 +62,28 @@ $ready = Get-Label $target 'smoke_ready' | |||
| $moved = Get-Label $target 'people_moved' | |||
| $world = Get-Label $target 'world_tiles' | |||
| $people = Get-Label $target 'people_cx' | |||
| $visibleFlag = Get-Label $target 'visible' | |||
| $tableEnd = $people + 5 * $count - 1 | |||
| Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value @( | |||
| 'logname "monitor.log"' | |||
| 'log on' | |||
| ('trace exec ${0:x4}' -f $ready) | |||
| ('command 1 "bsave \"world.bin\" 0 {0:x4} {1:x4}"' -f $world, ($world + $width * $height - 1)) | |||
| ('trace exec ${0:x4}' -f $moved) | |||
| ('command 2 "m {0:x4} {1:x4}"' -f $people, $tableEnd) | |||
| ) | |||
| $bitmapSize = 8000 | |||
| $buffers = @(0x6000, 0xA000) # bitmaps of buffers A and B (src/main.s) | |||
| $monitor = [System.Collections.Generic.List[string]]::new() | |||
| $monitor.Add('logname "monitor.log"') | |||
| $monitor.Add('log on') | |||
| $n = 0 | |||
| function Add-Trace([int]$Address, [string]$Command) { | |||
| $script:n++ | |||
| $monitor.Add(('trace exec ${0:x4}' -f $Address)) | |||
| $monitor.Add(('command {0} "{1}"' -f $script:n, $Command)) | |||
| } | |||
| Add-Trace $ready ('bsave \"world.bin\" 0 {0:x4} {1:x4}' -f $world, ($world + $width * $height - 1)) | |||
| Add-Trace $ready ('bsave \"clean-a.bin\" 0 {0:x4} {1:x4}' -f $buffers[0], ($buffers[0] + $bitmapSize - 1)) | |||
| Add-Trace $ready ('bsave \"clean-b.bin\" 0 {0:x4} {1:x4}' -f $buffers[1], ($buffers[1] + $bitmapSize - 1)) | |||
| Add-Trace $moved ('m {0:x4} {1:x4}' -f $people, $tableEnd) | |||
| $peopleCheckpoint = $n | |||
| Add-Trace $moved ('m {0:x4} {0:x4}' -f $visibleFlag) | |||
| Add-Trace $moved ('bsave \"final-a.bin\" 0 {0:x4} {1:x4}' -f $buffers[0], ($buffers[0] + $bitmapSize - 1)) | |||
| Add-Trace $moved ('bsave \"final-b.bin\" 0 {0:x4} {1:x4}' -f $buffers[1], ($buffers[1] + $bitmapSize - 1)) | |||
| Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $monitor | |||
| Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value '' | |||
| $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target) | |||
| @@ -84,10 +104,17 @@ $logFile = @('monitor.log', 'vice.log') | ForEach-Object { Join-Path $dir $_ } | | |||
| Where-Object { (Test-Path -LiteralPath $_) -and (Select-String -LiteralPath $_ -Pattern '^>C:' -Quiet) } | Select-Object -First 1 | |||
| if (-not $logFile) { Write-Host '[FAIL] No people table was logged (people_moved never reached?).' -ForegroundColor Red; exit 1 } | |||
| $frames = [System.Collections.Generic.List[byte[]]]::new() | |||
| $visibleLog = [System.Collections.Generic.List[int]]::new() | |||
| $clocks = [System.Collections.Generic.List[long]]::new() | |||
| $current = [System.Collections.Generic.List[byte]]::new() | |||
| $wantClock = $false | |||
| $lines = [System.Collections.Generic.List[int]]::new() | |||
| foreach ($line in Get-Content -LiteralPath $logFile) { | |||
| if ($line -match "^#$peopleCheckpoint \(Trace\s+exec [0-9a-fA-F]+\)\s+(\d+)/") { $lines.Add([int]$Matches[1]); $wantClock = $true; continue } | |||
| if ($wantClock -and $line -match '^\.C:.*\s(\d+)\s*$') { $clocks.Add([long]$Matches[1]); $wantClock = $false; continue } | |||
| if ($line -notmatch '^>C:([0-9a-fA-F]{4})\s+(.*)$') { continue } | |||
| $addr = [Convert]::ToInt32($Matches[1], 16) | |||
| if ($addr -eq $visibleFlag) { $visibleLog.Add([Convert]::ToInt32(($Matches[2] -split '\s+')[0], 16)); continue } | |||
| if ($addr -eq $people) { $current.Clear() } | |||
| foreach ($hex in ($Matches[2] -split '\s+')) { | |||
| if ($hex -notmatch '^[0-9a-fA-F]{2}$') { break } | |||
| @@ -102,9 +129,9 @@ $moves = [int[]]::new($count) | |||
| $previous = $null | |||
| foreach ($f in $frames) { | |||
| for ($i = 0; $i -lt $count; $i++) { | |||
| $cx = $f[$i]; $sx = $f[16 + $i]; $cy = $f[32 + $i]; $sy = $f[48 + $i]; $dir = $f[64 + $i] | |||
| if ($cx -ge $width -or $cy -ge $height -or $sx -gt 3 -or $sy -gt 7 -or $dir -gt 3) { | |||
| $failures.Add("person $i out of range: cell ($cx,$cy) pixel ($sx,$sy) dir $dir"); continue | |||
| $cx = $f[$i]; $sx = $f[16 + $i]; $cy = $f[32 + $i]; $sy = $f[48 + $i]; $heading = $f[64 + $i] | |||
| if ($cx -ge $width -or $cy -ge $height -or $sx -gt 3 -or $sy -gt 7 -or $heading -gt 3) { | |||
| $failures.Add("person $i out of range: cell ($cx,$cy) pixel ($sx,$sy) dir $heading"); continue | |||
| } | |||
| $tile = $tiles[$cy * $width + $cx] | |||
| if ($tile -in $blocking) { $failures.Add("person $i on blocking tile $tile at cell ($cx,$cy)") } | |||
| @@ -121,15 +148,56 @@ foreach ($f in $frames) { | |||
| for ($i = 0; $i -lt $count; $i++) { | |||
| if ($moves[$i] -eq 0) { $failures.Add("person $i never moved") } | |||
| } | |||
| # Main loop timing: one hook per NTSC frame (65 cycles x 263 lines on x64sc). | |||
| # The hook comes after a variable amount of work, so gaps jitter around 17095. | |||
| $frameCycles = 17095 | |||
| $late = 0 | |||
| for ($k = 1; $k -lt $clocks.Count; $k++) { if ($clocks[$k] - $clocks[$k - 1] -gt 1.5 * $frameCycles) { $late++ } } | |||
| if ($clocks.Count -lt $frames.Count) { $failures.Add("only $($clocks.Count) hook clocks for $($frames.Count) frames") } | |||
| if ($late -gt 0) { $failures.Add("the main loop missed $late frame(s)") } | |||
| # The flip happens from line 251; the update must end before the visible area (line 51). | |||
| $lastLine = ($lines | Where-Object { $_ -lt 200 } | Measure-Object -Maximum).Maximum | |||
| if (@($lines | Where-Object { $_ -ge 51 }).Count -gt 0) { $failures.Add('a people update ran into the visible area (hook at raster line 51 or later)') } | |||
| # Final frame: hidden buffer = clean + current dots, visible buffer = clean + previous dots. | |||
| function Get-ExpectedBitmap([byte[]]$Clean, [byte[]]$Table) { | |||
| $bitmap = [byte[]]$Clean.Clone() | |||
| $masks = 0xC0, 0x30, 0x0C, 0x03 | |||
| for ($i = 0; $i -lt $count; $i++) { | |||
| $cx = $Table[$i]; $cy = $Table[32 + $i] | |||
| if ($cx -ge 40 -or $cy -ge 25) { continue } | |||
| $offset = $cy * 320 + $cx * 8 + $Table[48 + $i] | |||
| $bitmap[$offset] = $bitmap[$offset] -bor $masks[$Table[16 + $i]] | |||
| } | |||
| , $bitmap | |||
| } | |||
| $clean = 'clean-a.bin', 'clean-b.bin' | ForEach-Object { , [IO.File]::ReadAllBytes((Join-Path $dir $_)) } | |||
| $final = 'final-a.bin', 'final-b.bin' | ForEach-Object { , [IO.File]::ReadAllBytes((Join-Path $dir $_)) } | |||
| if ((Format-Hex $clean[0]) -ne (Format-Hex $clean[1])) { $failures.Add('buffers A and B differ before people are drawn') } | |||
| $shown = $visibleLog[$visibleLog.Count - 1] | |||
| $hiddenIndex = 1 - $shown | |||
| $expectHidden = Get-ExpectedBitmap $clean[$hiddenIndex] $frames[$frames.Count - 1] | |||
| $expectShown = Get-ExpectedBitmap $clean[$shown] $frames[$frames.Count - 2] | |||
| $dots = 0 | |||
| foreach ($pair in @(@($final[$hiddenIndex], $expectHidden, 'hidden'), @($final[$shown], $expectShown, 'visible'))) { | |||
| $bad = 0 | |||
| for ($b = 0; $b -lt $bitmapSize; $b++) { | |||
| if ($pair[0][$b] -ne $pair[1][$b]) { $bad++ } | |||
| } | |||
| if ($bad -gt 0) { $failures.Add("final $($pair[2]) bitmap has $bad bytes that differ from clean map plus people") } | |||
| } | |||
| for ($b = 0; $b -lt $bitmapSize; $b++) { if ($final[$hiddenIndex][$b] -ne $clean[$hiddenIndex][$b]) { $dots++ } } | |||
| $sectors = @(0..($count - 1) | ForEach-Object { [int]($first[$_] -ge 40) + 2 * [int]($first[32 + $_] -ge 25) } | Sort-Object -Unique) | |||
| if ($sectors.Count -ne 4) { $failures.Add("people start in only $($sectors.Count) of 4 screens") } | |||
| $seconds = [Math]::Round($frames.Count / 60.0, 1) | |||
| Write-Host ("Buffer flips: {0} frames, {1} missed; people update done by raster line {2} at the latest. Final hidden buffer: {3}, {4} bytes carry dots." -f $clocks.Count, $late, $lastLine, ('A', 'B')[$hiddenIndex], $dots) | |||
| Write-Host ("Logged {0} movement frames (~{1} s NTSC). Steps per person: {2}" -f $frames.Count, $seconds, ($moves -join ' ')) | |||
| if ($failures.Count -gt 0) { | |||
| $failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" } | |||
| Write-Host '[FAIL] people check' -ForegroundColor Red | |||
| exit 1 | |||
| } | |||
| Write-Host '[PASS] 16 people spread over 4 screens move one pixel at a time and never stand on water or stone.' -ForegroundColor Green | |||
| Write-Host '[PASS] 16 people spread over 4 screens move one pixel at a time, never stand on water or stone; both buffers hold only the clean map plus the right dots; one flip per frame.' -ForegroundColor Green | |||
| exit 0 | |||
Powered by TurnKey Linux.