Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

185 lines
12KB

  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, the map's y-scroll (map_d011) and the patched split delay,
  8. every frame;
  9. - on the key_row_* instructions (src/keys.inc): fakes "no key" (keys typed on the PC
  10. while a headless VICE has focus would otherwise reach the program), then holds
  11. CRSR DOWN from frame 30 until the view is at cell row 3, then SHIFT+CRSR DOWN
  12. until it is back at row 0, then no key, so every map y-scroll value (0-7) is split;
  13. - at people_moved: logs the view position, move_frame, and the
  14. shown person's number (status row 20) of text screen 1 in both banks.
  15. Then checks:
  16. - every split starts between line 210 cycle 53 and line 210 cycle 64, for every
  17. y-scroll value, and every y-scroll value 0-7 was seen. This window was measured
  18. at y-scroll 3 by sweeping the delay: starts at 210:40-51 damaged the last map
  19. line, 211:0-11 damaged the first text line, 210:50-211:1 were clean;
  20. - a split happens on every frame (no missed interrupt);
  21. - in every frame both banks show person 01 in status row 20 (no P is pressed; the
  22. status area shows only the chosen person since M6.2);
  23. - in the exit screenshot, the 40 text lines (raster 211-250) contain only the background colour
  24. and white, status rows 20 and 21 are lit (the chosen person, R8) and rows 22-24 are blank, and
  25. the last map line (raster 210) uses no colour foreign to the map. This is a
  26. coarse check: in the delay sweep it caught damage from writes at 210:40-46 but
  27. not subtler damage, so the timing window above is the main guard.
  28. Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.
  29. .EXAMPLE
  30. pwsh -File tools/check-split.ps1
  31. #>
  32. [CmdletBinding()]
  33. param([int]$Cycles = 20000000, [switch]$NoBuild, [int]$TimeoutSeconds = 180)
  34. . (Join-Path $PSScriptRoot 'lib.ps1')
  35. function Get-Label([hashtable]$Target, [string]$Symbol) {
  36. foreach ($line in Get-Content -LiteralPath (Get-RepoPath $Target.build.labels)) {
  37. $parts = $line -split '\s+'
  38. if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol) { return [Convert]::ToInt32($parts[1], 16) }
  39. }
  40. throw "Symbol '$Symbol' not found in $($Target.build.labels)."
  41. }
  42. try {
  43. $project = Get-ProjectConfig
  44. $target = Get-ProjectTargets $project 'c64'
  45. if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} }
  46. $emu = Get-ToolPath $project $target.emulator.binary
  47. } catch [MissingToolException] {
  48. Write-Host $_.Exception.Message -ForegroundColor Yellow
  49. exit 2
  50. }
  51. $dir = Get-RepoPath 'build/check-split'
  52. if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force }
  53. New-Item -ItemType Directory -Force -Path $dir | Out-Null
  54. $L = @{}
  55. foreach ($sym in 'split_store', 'split_delay', 'people_moved', 'smoke_ready', 'people_cx', 'map_d011', 'move_frame', 'view_cx', 'view_cy', 'view_fy',
  56. 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space', 'key_row_p') { $L[$sym] = Get-Label $target $sym }
  57. $digits = @(0x4400, 0x8400) | ForEach-Object { $_ + 20 * 40 + 2 } # row 20, last two digits of "P001"
  58. $PHASE = 0xCFF0 # free RAM: scroll phase 0 still, 1 down, 2 up, 3 still
  59. $cond = { param($pairs) ($pairs | ForEach-Object { '(@cpu:${0:x4} == ${1:x2})' -f $_[0], $_[1] }) -join ' && ' }
  60. # Checkpoints 1-5 keep their numbers: the parser below relies on them.
  61. $mon = @(
  62. 'logname "monitor.log"', 'log on'
  63. ('trace exec ${0:x4}' -f $L.split_store), ('command 1 "m {0:x4} {0:x4}"' -f $L.map_d011)
  64. ('trace exec ${0:x4}' -f $L.people_moved), ('command 2 "m {0:x4} {1:x4}"' -f $L.view_cx, ($L.view_cx + 3))
  65. ('trace exec ${0:x4}' -f $L.people_moved), ('command 3 "m {0:x4} {0:x4}"' -f $L.move_frame)
  66. ('trace exec ${0:x4}' -f $L.people_moved), ('command 4 "m {0:x4} {1:x4}"' -f $digits[0], ($digits[0] + 1))
  67. ('trace exec ${0:x4}' -f $L.people_moved), ('command 5 "m {0:x4} {1:x4}"' -f $digits[1], ($digits[1] + 1))
  68. ('trace exec ${0:x4}' -f $L.split_store), ('command 6 "m {0:x4} {0:x4}"' -f ($L.split_delay + 1))
  69. ('trace exec ${0:x4}' -f $L.smoke_ready), ('command 7 "> {0:x4} 00"' -f $PHASE)
  70. )
  71. $n = 7
  72. foreach ($row in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space', 'key_row_p') {
  73. $n++; $mon += ('trace exec ${0:x4}' -f $L[$row]); $mon += ('command {0} "r a = ff"' -f $n)
  74. }
  75. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_cursor, (& $cond @(, @($PHASE, 1)))); $mon += ('command {0} "r a = 7f"' -f $n)
  76. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_cursor, (& $cond @(, @($PHASE, 2)))); $mon += ('command {0} "r a = 7f"' -f $n)
  77. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_lshift, (& $cond @(, @($PHASE, 2)))); $mon += ('command {0} "r a = 7f"' -f $n)
  78. # Phase changes, latest first so one frame moves on at most one phase.
  79. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.people_moved, (& $cond @(@($PHASE, 2), @($L.view_cy, 0), @($L.view_fy, 0)))); $mon += ('command {0} "> {1:x4} 03"' -f $n, $PHASE)
  80. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.people_moved, (& $cond @(@($PHASE, 1), @($L.view_cy, 3), @($L.view_fy, 0)))); $mon += ('command {0} "> {1:x4} 02"' -f $n, $PHASE)
  81. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.people_moved, (& $cond @(@($PHASE, 0), @($L.move_frame, 30)))); $mon += ('command {0} "> {1:x4} 01"' -f $n, $PHASE)
  82. Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
  83. Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
  84. $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
  85. $vargs += @('-limitcycles', [string]$Cycles, '-exitscreenshot', 'screen.png', '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
  86. $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } }
  87. Write-Host "[c64] running x64sc headless for $Cycles cycles"
  88. $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
  89. -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
  90. if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true); Write-Host '[FAIL] VICE did not exit in time.' -ForegroundColor Red; exit 1 }
  91. $failures = [System.Collections.Generic.List[string]]::new()
  92. $log = Join-Path $dir 'monitor.log'
  93. if (-not (Test-Path -LiteralPath $log)) { Write-Host '[FAIL] no monitor log' -ForegroundColor Red; exit 1 }
  94. # Split timing.
  95. $starts = [System.Collections.Generic.List[string]]::new()
  96. $splits = [System.Collections.Generic.List[hashtable]]::new()
  97. $split = $null
  98. $splitFrames = 0; $moveFrames = 0; $badCounts = 0; $checkedCounts = 0
  99. $lastCheckpoint = 0
  100. $frame = $null; $prev = $null
  101. foreach ($line in Get-Content -LiteralPath $log) {
  102. if ($line -match '^#(\d+) \(Trace\s+exec [0-9a-fA-F]+\)\s+(\d+)/\$\w+,\s+(\d+)/') {
  103. $lastCheckpoint = [int]$Matches[1]
  104. if ($lastCheckpoint -eq 1) {
  105. $splitFrames++
  106. $split = @{ line = [int]$Matches[2]; cycle = [int]$Matches[3] }
  107. $splits.Add($split)
  108. }
  109. if ($lastCheckpoint -eq 2) { $prev = $frame; $frame = @{ people = [System.Collections.Generic.List[byte]]::new(); digits = @() } }
  110. continue
  111. }
  112. if ($line -match '^>C:[0-9a-fA-F]{4} ((?:[0-9a-fA-F]{2} )+)') {
  113. $bytes = @($Matches[1].Trim() -split ' ' | ForEach-Object { [Convert]::ToByte($_, 16) })
  114. if ($lastCheckpoint -eq 1 -and $null -ne $split) { $split.y = $bytes[0] -band 7 }
  115. if ($lastCheckpoint -eq 6 -and $null -ne $split) { $split.delay = $bytes[0] }
  116. if ($null -eq $frame) { continue }
  117. if ($lastCheckpoint -eq 2) { $frame.cx = $bytes[0]; $frame.fx = $bytes[1]; $frame.cy = $bytes[2]; $frame.fy = $bytes[3] }
  118. if ($lastCheckpoint -eq 4 -or $lastCheckpoint -eq 5) { $frame.digits += , (($bytes[0] - 0x30) * 10 + ($bytes[1] - 0x30)) }
  119. if ($lastCheckpoint -eq 5) {
  120. $moveFrames++
  121. $checkedCounts++
  122. if ($frame.digits[0] -ne 1 -or $frame.digits[1] -ne 1) { $badCounts++ }
  123. }
  124. }
  125. if ($failures.Count -gt 10) { break }
  126. }
  127. $monErrors = @(Select-String -LiteralPath $log -Pattern '^ERROR|not a valid checkpoint' | Select-Object -First 3)
  128. foreach ($e in $monErrors) { $failures.Add("monitor script error: $($e.Line.Trim())") }
  129. foreach ($sp in $splits) {
  130. $starts.Add("y$($sp.y) d$($sp.delay) $($sp.line):$($sp.cycle)")
  131. if ($sp.line -ne 210 -or $sp.cycle -lt 53 -or $sp.cycle -gt 64) { $failures.Add("split at y-scroll $($sp.y) started at line $($sp.line) cycle $($sp.cycle) (allowed 210:53-210:64)") }
  132. }
  133. $seenY = @($splits | ForEach-Object { $_.y } | Where-Object { $null -ne $_ } | Sort-Object -Unique)
  134. if ($seenY.Count -ne 8) { $failures.Add("splits seen only at y-scroll $($seenY -join ', ') (expected 0-7)") }
  135. if ($splitFrames -lt 100) { $failures.Add("only $splitFrames splits logged") }
  136. if ([Math]::Abs($splitFrames - $moveFrames) -gt 2) { $failures.Add("$splitFrames splits for $moveFrames frames: an interrupt was missed") }
  137. if ($checkedCounts -lt 50) { $failures.Add("only $checkedCounts status updates checked") }
  138. if ($badCounts -gt 0) { $failures.Add("status row 20 did not show person 01 in both banks in $badCounts of $checkedCounts frames") }
  139. # Screenshot: raster line r is at y = r - 28 in x64sc's NTSC screenshot.
  140. Add-Type -AssemblyName System.Drawing
  141. $shot = Join-Path $dir 'screen.png'
  142. if (-not (Test-Path -LiteralPath $shot)) { $failures.Add('no exit screenshot') } else {
  143. $bmp = [System.Drawing.Bitmap]::new($shot)
  144. try {
  145. $brown = $bmp.GetPixel(2, 2).ToArgb()
  146. $textColours = @{}
  147. $textLit = @{}
  148. for ($y = 211 - 28; $y -le 250 - 28; $y++) {
  149. for ($x = 0; $x -lt $bmp.Width; $x++) {
  150. $c = $bmp.GetPixel($x, $y).ToArgb()
  151. if ($c -ne $brown) { $textColours[$c] = 1; $textLit[[int][Math]::Floor(($y - 183) / 8)] = 1 }
  152. }
  153. }
  154. if ($textColours.Count -gt 1) { $failures.Add("status area shows $($textColours.Count) colours besides the background (expected white only)") }
  155. foreach ($row in 0, 1) { if (-not $textLit.ContainsKey($row)) { $failures.Add("status row $($row + 20) is empty in the screenshot") } }
  156. foreach ($row in 2, 3, 4) { if ($textLit.ContainsKey($row)) { $failures.Add("status row $($row + 20) should be blank") } }
  157. # Map colours: background, white, grey, green, blue, black as rendered in the map area above.
  158. $mapColours = @{}
  159. for ($y = 51 - 28; $y -le 209 - 28; $y++) { for ($x = 0; $x -lt $bmp.Width; $x++) { $mapColours[$bmp.GetPixel($x, $y).ToArgb()] = 1 } }
  160. for ($x = 0; $x -lt $bmp.Width; $x++) {
  161. 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 }
  162. }
  163. } finally { $bmp.Dispose() }
  164. }
  165. $distinct = ($starts | Group-Object | Sort-Object Name | ForEach-Object { "$($_.Name) x$($_.Count)" }) -join ', '
  166. Write-Host "Split starts (y-scroll, delay, line:cycle): $distinct"
  167. Write-Host "Frames: $splitFrames splits, $moveFrames people updates; shown person number wrong in $badCounts of $checkedCounts frames."
  168. if ($failures.Count -gt 0) {
  169. $failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" }
  170. Write-Host '[FAIL] split check' -ForegroundColor Red
  171. exit 1
  172. }
  173. Write-Host '[PASS] split writes land in the measured border window every frame at every y-scroll; status shows person 01 in both banks; no foreign colours at the boundary.' -ForegroundColor Green
  174. exit 0

Powered by TurnKey Linux.