Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

187 rindas
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, the people table with 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 + 1 } # row 20, after "P"
  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. if ($L.move_frame -ne $L.people_cx + 80) { throw 'move_frame must follow the five people tables (src/people.inc)' }
  61. # Checkpoints 1-5 keep their numbers: the parser below relies on them.
  62. $mon = @(
  63. 'logname "monitor.log"', 'log on'
  64. ('trace exec ${0:x4}' -f $L.split_store), ('command 1 "m {0:x4} {0:x4}"' -f $L.map_d011)
  65. ('trace exec ${0:x4}' -f $L.people_moved), ('command 2 "m {0:x4} {1:x4}"' -f $L.view_cx, ($L.view_cx + 3))
  66. ('trace exec ${0:x4}' -f $L.people_moved), ('command 3 "m {0:x4} {1:x4}"' -f $L.people_cx, ($L.people_cx + 80))
  67. ('trace exec ${0:x4}' -f $L.people_moved), ('command 4 "m {0:x4} {1:x4}"' -f $digits[0], ($digits[0] + 1))
  68. ('trace exec ${0:x4}' -f $L.people_moved), ('command 5 "m {0:x4} {1:x4}"' -f $digits[1], ($digits[1] + 1))
  69. ('trace exec ${0:x4}' -f $L.split_store), ('command 6 "m {0:x4} {0:x4}"' -f ($L.split_delay + 1))
  70. ('trace exec ${0:x4}' -f $L.smoke_ready), ('command 7 "> {0:x4} 00"' -f $PHASE)
  71. )
  72. $n = 7
  73. foreach ($row in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space', 'key_row_p') {
  74. $n++; $mon += ('trace exec ${0:x4}' -f $L[$row]); $mon += ('command {0} "r a = ff"' -f $n)
  75. }
  76. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_cursor, (& $cond @(, @($PHASE, 1)))); $mon += ('command {0} "r a = 7f"' -f $n)
  77. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_cursor, (& $cond @(, @($PHASE, 2)))); $mon += ('command {0} "r a = 7f"' -f $n)
  78. $n++; $mon += ('trace exec ${0:x4} if {1}' -f $L.key_row_lshift, (& $cond @(, @($PHASE, 2)))); $mon += ('command {0} "r a = 7f"' -f $n)
  79. # Phase changes, latest first so one frame moves on at most one phase.
  80. $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)
  81. $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)
  82. $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)
  83. Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
  84. Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
  85. $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
  86. $vargs += @('-limitcycles', [string]$Cycles, '-exitscreenshot', 'screen.png', '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
  87. $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } }
  88. Write-Host "[c64] running x64sc headless for $Cycles cycles"
  89. $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
  90. -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
  91. if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true); Write-Host '[FAIL] VICE did not exit in time.' -ForegroundColor Red; exit 1 }
  92. $failures = [System.Collections.Generic.List[string]]::new()
  93. $log = Join-Path $dir 'monitor.log'
  94. if (-not (Test-Path -LiteralPath $log)) { Write-Host '[FAIL] no monitor log' -ForegroundColor Red; exit 1 }
  95. # Split timing.
  96. $starts = [System.Collections.Generic.List[string]]::new()
  97. $splits = [System.Collections.Generic.List[hashtable]]::new()
  98. $split = $null
  99. $splitFrames = 0; $moveFrames = 0; $badCounts = 0; $checkedCounts = 0
  100. $lastCheckpoint = 0
  101. $frame = $null; $prev = $null
  102. foreach ($line in Get-Content -LiteralPath $log) {
  103. if ($line -match '^#(\d+) \(Trace\s+exec [0-9a-fA-F]+\)\s+(\d+)/\$\w+,\s+(\d+)/') {
  104. $lastCheckpoint = [int]$Matches[1]
  105. if ($lastCheckpoint -eq 1) {
  106. $splitFrames++
  107. $split = @{ line = [int]$Matches[2]; cycle = [int]$Matches[3] }
  108. $splits.Add($split)
  109. }
  110. if ($lastCheckpoint -eq 2) { $prev = $frame; $frame = @{ people = [System.Collections.Generic.List[byte]]::new(); digits = @() } }
  111. continue
  112. }
  113. if ($line -match '^>C:[0-9a-fA-F]{4} ((?:[0-9a-fA-F]{2} )+)') {
  114. $bytes = @($Matches[1].Trim() -split ' ' | ForEach-Object { [Convert]::ToByte($_, 16) })
  115. if ($lastCheckpoint -eq 1 -and $null -ne $split) { $split.y = $bytes[0] -band 7 }
  116. if ($lastCheckpoint -eq 6 -and $null -ne $split) { $split.delay = $bytes[0] }
  117. if ($null -eq $frame) { continue }
  118. if ($lastCheckpoint -eq 2) { $frame.cx = $bytes[0]; $frame.fx = $bytes[1]; $frame.cy = $bytes[2]; $frame.fy = $bytes[3] }
  119. if ($lastCheckpoint -eq 3) { foreach ($b in $bytes) { if ($frame.people.Count -lt 81) { $frame.people.Add($b) } } }
  120. if ($lastCheckpoint -eq 4 -or $lastCheckpoint -eq 5) { $frame.digits += , (($bytes[0] - 0x30) * 10 + ($bytes[1] - 0x30)) }
  121. if ($lastCheckpoint -eq 5) {
  122. $moveFrames++
  123. $checkedCounts++
  124. if ($frame.digits[0] -ne 1 -or $frame.digits[1] -ne 1) { $badCounts++ }
  125. }
  126. }
  127. if ($failures.Count -gt 10) { break }
  128. }
  129. $monErrors = @(Select-String -LiteralPath $log -Pattern '^ERROR|not a valid checkpoint' | Select-Object -First 3)
  130. foreach ($e in $monErrors) { $failures.Add("monitor script error: $($e.Line.Trim())") }
  131. foreach ($sp in $splits) {
  132. $starts.Add("y$($sp.y) d$($sp.delay) $($sp.line):$($sp.cycle)")
  133. 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)") }
  134. }
  135. $seenY = @($splits | ForEach-Object { $_.y } | Where-Object { $null -ne $_ } | Sort-Object -Unique)
  136. if ($seenY.Count -ne 8) { $failures.Add("splits seen only at y-scroll $($seenY -join ', ') (expected 0-7)") }
  137. if ($splitFrames -lt 100) { $failures.Add("only $splitFrames splits logged") }
  138. if ([Math]::Abs($splitFrames - $moveFrames) -gt 2) { $failures.Add("$splitFrames splits for $moveFrames frames: an interrupt was missed") }
  139. if ($checkedCounts -lt 50) { $failures.Add("only $checkedCounts status updates checked") }
  140. if ($badCounts -gt 0) { $failures.Add("status row 20 did not show person 01 in both banks in $badCounts of $checkedCounts frames") }
  141. # Screenshot: raster line r is at y = r - 28 in x64sc's NTSC screenshot.
  142. Add-Type -AssemblyName System.Drawing
  143. $shot = Join-Path $dir 'screen.png'
  144. if (-not (Test-Path -LiteralPath $shot)) { $failures.Add('no exit screenshot') } else {
  145. $bmp = [System.Drawing.Bitmap]::new($shot)
  146. try {
  147. $brown = $bmp.GetPixel(2, 2).ToArgb()
  148. $textColours = @{}
  149. $textLit = @{}
  150. for ($y = 211 - 28; $y -le 250 - 28; $y++) {
  151. for ($x = 0; $x -lt $bmp.Width; $x++) {
  152. $c = $bmp.GetPixel($x, $y).ToArgb()
  153. if ($c -ne $brown) { $textColours[$c] = 1; $textLit[[int][Math]::Floor(($y - 183) / 8)] = 1 }
  154. }
  155. }
  156. if ($textColours.Count -gt 1) { $failures.Add("status area shows $($textColours.Count) colours besides the background (expected white only)") }
  157. foreach ($row in 0, 1) { if (-not $textLit.ContainsKey($row)) { $failures.Add("status row $($row + 20) is empty in the screenshot") } }
  158. foreach ($row in 2, 3, 4) { if ($textLit.ContainsKey($row)) { $failures.Add("status row $($row + 20) should be blank") } }
  159. # Map colours: background, white, grey, green, blue, black as rendered in the map area above.
  160. $mapColours = @{}
  161. for ($y = 51 - 28; $y -le 209 - 28; $y++) { for ($x = 0; $x -lt $bmp.Width; $x++) { $mapColours[$bmp.GetPixel($x, $y).ToArgb()] = 1 } }
  162. for ($x = 0; $x -lt $bmp.Width; $x++) {
  163. 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 }
  164. }
  165. } finally { $bmp.Dispose() }
  166. }
  167. $distinct = ($starts | Group-Object | Sort-Object Name | ForEach-Object { "$($_.Name) x$($_.Count)" }) -join ', '
  168. Write-Host "Split starts (y-scroll, delay, line:cycle): $distinct"
  169. Write-Host "Frames: $splitFrames splits, $moveFrames people updates; shown person number wrong in $badCounts of $checkedCounts frames."
  170. if ($failures.Count -gt 0) {
  171. $failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" }
  172. Write-Host '[FAIL] split check' -ForegroundColor Red
  173. exit 1
  174. }
  175. 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
  176. exit 0

Powered by TurnKey Linux.