選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

150 行
7.8KB

  1. <#
  2. .SYNOPSIS
  3. Check the map/status raster split of the C64 build headless in VICE.
  4. .DESCRIPTION
  5. Runs x64sc (NTSC, warp, private config) with monitor tracepoints:
  6. - at split_store (src/status.inc): logs the raster line and cycle where the three
  7. mode writes start, every frame;
  8. - at people_moved: logs the hidden buffer, both drawn counts and the people-in-view
  9. digits of both status text screens.
  10. Then checks:
  11. - every split starts between line 210 cycle 53 and line 210 cycle 64. This window
  12. was measured by sweeping the delay: starts at 210:40-51 damaged the last map
  13. line, 211:0-11 damaged the first text line, 210:50-211:1 were clean;
  14. - a split happens on every frame (no missed interrupt);
  15. - the status digits of the hidden buffer equal the number of people drawn into it;
  16. - in the exit screenshot, the 40 text lines (raster 211-250) contain only brown
  17. and light red, status rows 20, 21, 22 and 24 are lit and row 23 is empty, and
  18. the last map line (raster 210) uses no colour foreign to the map. This is a
  19. coarse check: in the delay sweep it caught damage from writes at 210:40-46 but
  20. not subtler damage, so the timing window above is the main guard.
  21. Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.
  22. .EXAMPLE
  23. pwsh -File tools/check-split.ps1
  24. #>
  25. [CmdletBinding()]
  26. param([int]$Cycles = 20000000, [switch]$NoBuild, [int]$TimeoutSeconds = 180)
  27. . (Join-Path $PSScriptRoot 'lib.ps1')
  28. function Get-Label([hashtable]$Target, [string]$Symbol) {
  29. foreach ($line in Get-Content -LiteralPath (Get-RepoPath $Target.build.labels)) {
  30. $parts = $line -split '\s+'
  31. if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol) { return [Convert]::ToInt32($parts[1], 16) }
  32. }
  33. throw "Symbol '$Symbol' not found in $($Target.build.labels)."
  34. }
  35. try {
  36. $project = Get-ProjectConfig
  37. $target = Get-ProjectTargets $project 'c64'
  38. if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} }
  39. $emu = Get-ToolPath $project $target.emulator.binary
  40. } catch [MissingToolException] {
  41. Write-Host $_.Exception.Message -ForegroundColor Yellow
  42. exit 2
  43. }
  44. $dir = Get-RepoPath 'build/check-split'
  45. if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force }
  46. New-Item -ItemType Directory -Force -Path $dir | Out-Null
  47. $store = Get-Label $target 'split_store'
  48. $moved = Get-Label $target 'people_moved'
  49. $hidden = Get-Label $target 'hidden'
  50. $drawn = Get-Label $target 'drawn_count'
  51. $digits = @(0x4400, 0x8400) | ForEach-Object { $_ + 22 * 40 + 15 } # row 22, after "PEOPLE IN VIEW "
  52. Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value @(
  53. 'logname "monitor.log"', 'log on'
  54. ('trace exec ${0:x4}' -f $store)
  55. ('trace exec ${0:x4}' -f $moved), ('command 2 "m {0:x4} {0:x4}"' -f $hidden)
  56. ('trace exec ${0:x4}' -f $moved), ('command 3 "m {0:x4} {1:x4}"' -f $drawn, ($drawn + 1))
  57. ('trace exec ${0:x4}' -f $moved), ('command 4 "m {0:x4} {1:x4}"' -f $digits[0], ($digits[0] + 1))
  58. ('trace exec ${0:x4}' -f $moved), ('command 5 "m {0:x4} {1:x4}"' -f $digits[1], ($digits[1] + 1))
  59. )
  60. Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
  61. $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
  62. $vargs += @('-limitcycles', [string]$Cycles, '-exitscreenshot', 'screen.png', '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
  63. $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } }
  64. Write-Host "[c64] running x64sc headless for $Cycles cycles"
  65. $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
  66. -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
  67. if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true); Write-Host '[FAIL] VICE did not exit in time.' -ForegroundColor Red; exit 1 }
  68. $failures = [System.Collections.Generic.List[string]]::new()
  69. $log = Join-Path $dir 'monitor.log'
  70. if (-not (Test-Path -LiteralPath $log)) { Write-Host '[FAIL] no monitor log' -ForegroundColor Red; exit 1 }
  71. # Split timing.
  72. $starts = [System.Collections.Generic.List[string]]::new()
  73. $splitFrames = 0; $moveFrames = 0; $badCounts = 0
  74. $values = @{}
  75. $lastCheckpoint = 0
  76. foreach ($line in Get-Content -LiteralPath $log) {
  77. if ($line -match '^#(\d+) \(Trace\s+exec [0-9a-fA-F]+\)\s+(\d+)/\$\w+,\s+(\d+)/') {
  78. $lastCheckpoint = [int]$Matches[1]
  79. if ($lastCheckpoint -eq 1) {
  80. $splitFrames++
  81. $rl = [int]$Matches[2]; $cy = [int]$Matches[3]
  82. $starts.Add("${rl}:$cy")
  83. 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)") }
  84. }
  85. continue
  86. }
  87. if ($line -match '^>C:[0-9a-fA-F]{4} ((?:[0-9a-fA-F]{2} )+)') {
  88. $bytes = @($Matches[1].Trim() -split ' ' | ForEach-Object { [Convert]::ToByte($_, 16) })
  89. $values[$lastCheckpoint] = $bytes
  90. if ($lastCheckpoint -eq 5) {
  91. $moveFrames++
  92. $h = $values[2][0]
  93. $count = $values[3][$h]
  94. $shown = $values[4 + $h]
  95. $number = ($shown[0] - 0x30) * 10 + ($shown[1] - 0x30)
  96. if ($number -ne $count) { $badCounts++ }
  97. }
  98. }
  99. if ($failures.Count -gt 10) { break }
  100. }
  101. if ($splitFrames -lt 100) { $failures.Add("only $splitFrames splits logged") }
  102. if ([Math]::Abs($splitFrames - $moveFrames) -gt 2) { $failures.Add("$splitFrames splits for $moveFrames frames: an interrupt was missed") }
  103. if ($badCounts -gt 0) { $failures.Add("people-in-view digits differed from the drawn count in $badCounts frames") }
  104. # Screenshot: raster line r is at y = r - 28 in x64sc's NTSC screenshot.
  105. Add-Type -AssemblyName System.Drawing
  106. $shot = Join-Path $dir 'screen.png'
  107. if (-not (Test-Path -LiteralPath $shot)) { $failures.Add('no exit screenshot') } else {
  108. $bmp = [System.Drawing.Bitmap]::new($shot)
  109. try {
  110. $brown = $bmp.GetPixel(2, 2).ToArgb()
  111. $textColours = @{}
  112. $textLit = @{}
  113. for ($y = 211 - 28; $y -le 250 - 28; $y++) {
  114. for ($x = 0; $x -lt $bmp.Width; $x++) {
  115. $c = $bmp.GetPixel($x, $y).ToArgb()
  116. if ($c -ne $brown) { $textColours[$c] = 1; $textLit[[int][Math]::Floor(($y - 183) / 8)] = 1 }
  117. }
  118. }
  119. if ($textColours.Count -gt 1) { $failures.Add("status area shows $($textColours.Count) colours besides brown (expected light red only)") }
  120. foreach ($row in 0, 1, 2, 4) { if (-not $textLit.ContainsKey($row)) { $failures.Add("status row $($row + 20) is empty in the screenshot") } }
  121. if ($textLit.ContainsKey(3)) { $failures.Add('the spare status row 23 is not empty') }
  122. # Map colours: brown, light red, grey, green, blue, black as rendered in the map area above.
  123. $mapColours = @{}
  124. for ($y = 51 - 28; $y -le 209 - 28; $y++) { for ($x = 0; $x -lt $bmp.Width; $x++) { $mapColours[$bmp.GetPixel($x, $y).ToArgb()] = 1 } }
  125. for ($x = 0; $x -lt $bmp.Width; $x++) {
  126. if (-not $mapColours.ContainsKey($bmp.GetPixel($x, 210 - 28).ToArgb())) { $failures.Add("last map line has a colour not used elsewhere in the map at x=$x"); break }
  127. }
  128. } finally { $bmp.Dispose() }
  129. }
  130. $distinct = ($starts | Group-Object | Sort-Object Name | ForEach-Object { "$($_.Name) x$($_.Count)" }) -join ', '
  131. Write-Host "Split starts (line:cycle): $distinct"
  132. Write-Host "Frames: $splitFrames splits, $moveFrames people updates; people-in-view digits wrong in $badCounts frames."
  133. if ($failures.Count -gt 0) {
  134. $failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" }
  135. Write-Host '[FAIL] split check' -ForegroundColor Red
  136. exit 1
  137. }
  138. Write-Host '[PASS] split writes land in the measured border window every frame; status digits match; no foreign colours at the boundary.' -ForegroundColor Green
  139. exit 0

Powered by TurnKey Linux.