<# .SYNOPSIS Run the C64 build headless in VICE and check that the 16 people move and never stand on water or stone. .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. 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. Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing. .EXAMPLE pwsh -File tools/check-people.ps1 #> [CmdletBinding()] param( [int]$Cycles = 40000000, [switch]$NoBuild, [int]$TimeoutSeconds = 180 ) . (Join-Path $PSScriptRoot 'lib.ps1') $count = 16 $width = 80 $height = 50 $blocking = 3..12 # STONE..WATER_SE in src/tiles.inc function Get-Label([hashtable]$Target, [string]$Symbol) { foreach ($line in Get-Content -LiteralPath (Get-RepoPath $Target.build.labels)) { $parts = $line -split '\s+' if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol) { return [Convert]::ToInt32($parts[1], 16) } } throw "Symbol '$Symbol' not found in $($Target.build.labels)." } try { $project = Get-ProjectConfig $target = Get-ProjectTargets $project 'c64' if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} } $emu = Get-ToolPath $project $target.emulator.binary } catch [MissingToolException] { Write-Host $_.Exception.Message -ForegroundColor Yellow exit 2 } $dir = Get-RepoPath 'build/check-people' if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force } New-Item -ItemType Directory -Force -Path $dir | Out-Null $ready = Get-Label $target 'smoke_ready' $moved = Get-Label $target 'people_moved' $world = Get-Label $target 'world_tiles' $people = Get-Label $target 'people_cx' $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) ) Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value '' $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target) $vargs += @('-limitcycles', [string]$Cycles, '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target)) $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } } Write-Host "[c64] running x64sc headless for $Cycles cycles" $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru ` -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err') if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true); Write-Host '[FAIL] VICE did not exit in time.' -ForegroundColor Red; exit 1 } $failures = [System.Collections.Generic.List[string]]::new() $worldFile = Join-Path $dir 'world.bin' if (-not (Test-Path -LiteralPath $worldFile)) { Write-Host '[FAIL] Program never reached smoke_ready.' -ForegroundColor Red; exit 1 } $tiles = [IO.File]::ReadAllBytes($worldFile) # Monitor memory dumps look like ">C:1e4c 00 01 02 ... text". Collect bytes per dump. $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() $current = [System.Collections.Generic.List[byte]]::new() foreach ($line in Get-Content -LiteralPath $logFile) { if ($line -notmatch '^>C:([0-9a-fA-F]{4})\s+(.*)$') { continue } $addr = [Convert]::ToInt32($Matches[1], 16) if ($addr -eq $people) { $current.Clear() } foreach ($hex in ($Matches[2] -split '\s+')) { if ($hex -notmatch '^[0-9a-fA-F]{2}$') { break } if ($current.Count -lt 5 * $count) { $current.Add([Convert]::ToByte($hex, 16)) } } if ($current.Count -eq 5 * $count) { $frames.Add($current.ToArray()); $current.Clear() } } if ($frames.Count -lt 60) { Write-Host "[FAIL] Only $($frames.Count) frames logged." -ForegroundColor Red; exit 1 } $first = $frames[0] $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 } $tile = $tiles[$cy * $width + $cx] if ($tile -in $blocking) { $failures.Add("person $i on blocking tile $tile at cell ($cx,$cy)") } if ($previous) { $x0 = $previous[$i] * 4 + $previous[16 + $i]; $y0 = $previous[32 + $i] * 8 + $previous[48 + $i] $dx = [Math]::Abs($cx * 4 + $sx - $x0); $dy = [Math]::Abs($cy * 8 + $sy - $y0) if ($dx + $dy -gt 1) { $failures.Add("person $i jumped $dx,$dy pixels") } if ($dx + $dy -eq 1) { $moves[$i]++ } } } $previous = $f if ($failures.Count -gt 10) { break } } for ($i = 0; $i -lt $count; $i++) { if ($moves[$i] -eq 0) { $failures.Add("person $i never moved") } } $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 ("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 exit 0