You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
6.4KB

  1. <#
  2. .SYNOPSIS
  3. Run the C64 build headless in VICE and check that the 16 people move and never
  4. stand on water or stone.
  5. .DESCRIPTION
  6. Starts x64sc (NTSC, warp, private config) like tools/smoke.ps1. Monitor tracepoints:
  7. - at smoke_ready: save the world tiles (world.bin);
  8. - at people_moved (once per frame): print the people table to the monitor log.
  9. VICE quits after -Cycles cycles. The script then checks every logged frame:
  10. 16 people inside the 80x50 world, every one on a walkable tile (not water or stone),
  11. every step at most one pixel, and every person moving during the run.
  12. Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.
  13. .EXAMPLE
  14. pwsh -File tools/check-people.ps1
  15. #>
  16. [CmdletBinding()]
  17. param(
  18. [int]$Cycles = 40000000,
  19. [switch]$NoBuild,
  20. [int]$TimeoutSeconds = 180
  21. )
  22. . (Join-Path $PSScriptRoot 'lib.ps1')
  23. $count = 16
  24. $width = 80
  25. $height = 50
  26. $blocking = 3..12 # STONE..WATER_SE in src/tiles.inc
  27. function Get-Label([hashtable]$Target, [string]$Symbol) {
  28. foreach ($line in Get-Content -LiteralPath (Get-RepoPath $Target.build.labels)) {
  29. $parts = $line -split '\s+'
  30. if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol) { return [Convert]::ToInt32($parts[1], 16) }
  31. }
  32. throw "Symbol '$Symbol' not found in $($Target.build.labels)."
  33. }
  34. try {
  35. $project = Get-ProjectConfig
  36. $target = Get-ProjectTargets $project 'c64'
  37. if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} }
  38. $emu = Get-ToolPath $project $target.emulator.binary
  39. } catch [MissingToolException] {
  40. Write-Host $_.Exception.Message -ForegroundColor Yellow
  41. exit 2
  42. }
  43. $dir = Get-RepoPath 'build/check-people'
  44. if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force }
  45. New-Item -ItemType Directory -Force -Path $dir | Out-Null
  46. $ready = Get-Label $target 'smoke_ready'
  47. $moved = Get-Label $target 'people_moved'
  48. $world = Get-Label $target 'world_tiles'
  49. $people = Get-Label $target 'people_cx'
  50. $tableEnd = $people + 5 * $count - 1
  51. Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value @(
  52. 'logname "monitor.log"'
  53. 'log on'
  54. ('trace exec ${0:x4}' -f $ready)
  55. ('command 1 "bsave \"world.bin\" 0 {0:x4} {1:x4}"' -f $world, ($world + $width * $height - 1))
  56. ('trace exec ${0:x4}' -f $moved)
  57. ('command 2 "m {0:x4} {1:x4}"' -f $people, $tableEnd)
  58. )
  59. Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
  60. $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
  61. $vargs += @('-limitcycles', [string]$Cycles, '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
  62. $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } }
  63. Write-Host "[c64] running x64sc headless for $Cycles cycles"
  64. $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
  65. -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
  66. if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true); Write-Host '[FAIL] VICE did not exit in time.' -ForegroundColor Red; exit 1 }
  67. $failures = [System.Collections.Generic.List[string]]::new()
  68. $worldFile = Join-Path $dir 'world.bin'
  69. if (-not (Test-Path -LiteralPath $worldFile)) { Write-Host '[FAIL] Program never reached smoke_ready.' -ForegroundColor Red; exit 1 }
  70. $tiles = [IO.File]::ReadAllBytes($worldFile)
  71. # Monitor memory dumps look like ">C:1e4c 00 01 02 ... text". Collect bytes per dump.
  72. $logFile = @('monitor.log', 'vice.log') | ForEach-Object { Join-Path $dir $_ } |
  73. Where-Object { (Test-Path -LiteralPath $_) -and (Select-String -LiteralPath $_ -Pattern '^>C:' -Quiet) } | Select-Object -First 1
  74. if (-not $logFile) { Write-Host '[FAIL] No people table was logged (people_moved never reached?).' -ForegroundColor Red; exit 1 }
  75. $frames = [System.Collections.Generic.List[byte[]]]::new()
  76. $current = [System.Collections.Generic.List[byte]]::new()
  77. foreach ($line in Get-Content -LiteralPath $logFile) {
  78. if ($line -notmatch '^>C:([0-9a-fA-F]{4})\s+(.*)$') { continue }
  79. $addr = [Convert]::ToInt32($Matches[1], 16)
  80. if ($addr -eq $people) { $current.Clear() }
  81. foreach ($hex in ($Matches[2] -split '\s+')) {
  82. if ($hex -notmatch '^[0-9a-fA-F]{2}$') { break }
  83. if ($current.Count -lt 5 * $count) { $current.Add([Convert]::ToByte($hex, 16)) }
  84. }
  85. if ($current.Count -eq 5 * $count) { $frames.Add($current.ToArray()); $current.Clear() }
  86. }
  87. if ($frames.Count -lt 60) { Write-Host "[FAIL] Only $($frames.Count) frames logged." -ForegroundColor Red; exit 1 }
  88. $first = $frames[0]
  89. $moves = [int[]]::new($count)
  90. $previous = $null
  91. foreach ($f in $frames) {
  92. for ($i = 0; $i -lt $count; $i++) {
  93. $cx = $f[$i]; $sx = $f[16 + $i]; $cy = $f[32 + $i]; $sy = $f[48 + $i]; $dir = $f[64 + $i]
  94. if ($cx -ge $width -or $cy -ge $height -or $sx -gt 3 -or $sy -gt 7 -or $dir -gt 3) {
  95. $failures.Add("person $i out of range: cell ($cx,$cy) pixel ($sx,$sy) dir $dir"); continue
  96. }
  97. $tile = $tiles[$cy * $width + $cx]
  98. if ($tile -in $blocking) { $failures.Add("person $i on blocking tile $tile at cell ($cx,$cy)") }
  99. if ($previous) {
  100. $x0 = $previous[$i] * 4 + $previous[16 + $i]; $y0 = $previous[32 + $i] * 8 + $previous[48 + $i]
  101. $dx = [Math]::Abs($cx * 4 + $sx - $x0); $dy = [Math]::Abs($cy * 8 + $sy - $y0)
  102. if ($dx + $dy -gt 1) { $failures.Add("person $i jumped $dx,$dy pixels") }
  103. if ($dx + $dy -eq 1) { $moves[$i]++ }
  104. }
  105. }
  106. $previous = $f
  107. if ($failures.Count -gt 10) { break }
  108. }
  109. for ($i = 0; $i -lt $count; $i++) {
  110. if ($moves[$i] -eq 0) { $failures.Add("person $i never moved") }
  111. }
  112. $sectors = @(0..($count - 1) | ForEach-Object { [int]($first[$_] -ge 40) + 2 * [int]($first[32 + $_] -ge 25) } | Sort-Object -Unique)
  113. if ($sectors.Count -ne 4) { $failures.Add("people start in only $($sectors.Count) of 4 screens") }
  114. $seconds = [Math]::Round($frames.Count / 60.0, 1)
  115. Write-Host ("Logged {0} movement frames (~{1} s NTSC). Steps per person: {2}" -f $frames.Count, $seconds, ($moves -join ' '))
  116. if ($failures.Count -gt 0) {
  117. $failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" }
  118. Write-Host '[FAIL] people check' -ForegroundColor Red
  119. exit 1
  120. }
  121. Write-Host '[PASS] 16 people spread over 4 screens move one pixel at a time and never stand on water or stone.' -ForegroundColor Green
  122. exit 0

Powered by TurnKey Linux.