|
- <#
- .SYNOPSIS
- Check the map/status raster split of the C64 build headless in VICE.
-
- .DESCRIPTION
- Runs x64sc (NTSC, warp, private config) with monitor tracepoints:
- - at split_store (src/status.inc): logs the raster line and cycle where the three
- mode writes start, every frame;
- - at people_moved: logs the hidden buffer, both drawn counts and the people-in-view
- digits of both status text screens.
- Then checks:
- - every split starts between line 210 cycle 53 and line 210 cycle 64. This window
- was measured by sweeping the delay: starts at 210:40-51 damaged the last map
- line, 211:0-11 damaged the first text line, 210:50-211:1 were clean;
- - a split happens on every frame (no missed interrupt);
- - the status digits of the hidden buffer equal the number of people drawn into it;
- - in the exit screenshot, the 40 text lines (raster 211-250) contain only brown
- and light red, status rows 20, 21, 22 and 24 are lit and row 23 is empty, and
- the last map line (raster 210) uses no colour foreign to the map. This is a
- coarse check: in the delay sweep it caught damage from writes at 210:40-46 but
- not subtler damage, so the timing window above is the main guard.
- Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.
-
- .EXAMPLE
- pwsh -File tools/check-split.ps1
- #>
- [CmdletBinding()]
- param([int]$Cycles = 20000000, [switch]$NoBuild, [int]$TimeoutSeconds = 180)
- . (Join-Path $PSScriptRoot 'lib.ps1')
-
- 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-split'
- if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force }
- New-Item -ItemType Directory -Force -Path $dir | Out-Null
-
- $store = Get-Label $target 'split_store'
- $moved = Get-Label $target 'people_moved'
- $hidden = Get-Label $target 'hidden'
- $drawn = Get-Label $target 'drawn_count'
- $digits = @(0x4400, 0x8400) | ForEach-Object { $_ + 22 * 40 + 15 } # row 22, after "PEOPLE IN VIEW "
- Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value @(
- 'logname "monitor.log"', 'log on'
- ('trace exec ${0:x4}' -f $store)
- ('trace exec ${0:x4}' -f $moved), ('command 2 "m {0:x4} {0:x4}"' -f $hidden)
- ('trace exec ${0:x4}' -f $moved), ('command 3 "m {0:x4} {1:x4}"' -f $drawn, ($drawn + 1))
- ('trace exec ${0:x4}' -f $moved), ('command 4 "m {0:x4} {1:x4}"' -f $digits[0], ($digits[0] + 1))
- ('trace exec ${0:x4}' -f $moved), ('command 5 "m {0:x4} {1:x4}"' -f $digits[1], ($digits[1] + 1))
- )
- Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
- $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
- $vargs += @('-limitcycles', [string]$Cycles, '-exitscreenshot', 'screen.png', '-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()
- $log = Join-Path $dir 'monitor.log'
- if (-not (Test-Path -LiteralPath $log)) { Write-Host '[FAIL] no monitor log' -ForegroundColor Red; exit 1 }
-
- # Split timing.
- $starts = [System.Collections.Generic.List[string]]::new()
- $splitFrames = 0; $moveFrames = 0; $badCounts = 0
- $values = @{}
- $lastCheckpoint = 0
- foreach ($line in Get-Content -LiteralPath $log) {
- if ($line -match '^#(\d+) \(Trace\s+exec [0-9a-fA-F]+\)\s+(\d+)/\$\w+,\s+(\d+)/') {
- $lastCheckpoint = [int]$Matches[1]
- if ($lastCheckpoint -eq 1) {
- $splitFrames++
- $rl = [int]$Matches[2]; $cy = [int]$Matches[3]
- $starts.Add("${rl}:$cy")
- 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)") }
- }
- continue
- }
- if ($line -match '^>C:[0-9a-fA-F]{4} ((?:[0-9a-fA-F]{2} )+)') {
- $bytes = @($Matches[1].Trim() -split ' ' | ForEach-Object { [Convert]::ToByte($_, 16) })
- $values[$lastCheckpoint] = $bytes
- if ($lastCheckpoint -eq 5) {
- $moveFrames++
- $h = $values[2][0]
- $count = $values[3][$h]
- $shown = $values[4 + $h]
- $number = ($shown[0] - 0x30) * 10 + ($shown[1] - 0x30)
- if ($number -ne $count) { $badCounts++ }
- }
- }
- if ($failures.Count -gt 10) { break }
- }
- if ($splitFrames -lt 100) { $failures.Add("only $splitFrames splits logged") }
- if ([Math]::Abs($splitFrames - $moveFrames) -gt 2) { $failures.Add("$splitFrames splits for $moveFrames frames: an interrupt was missed") }
- if ($badCounts -gt 0) { $failures.Add("people-in-view digits differed from the drawn count in $badCounts frames") }
-
- # Screenshot: raster line r is at y = r - 28 in x64sc's NTSC screenshot.
- Add-Type -AssemblyName System.Drawing
- $shot = Join-Path $dir 'screen.png'
- if (-not (Test-Path -LiteralPath $shot)) { $failures.Add('no exit screenshot') } else {
- $bmp = [System.Drawing.Bitmap]::new($shot)
- try {
- $brown = $bmp.GetPixel(2, 2).ToArgb()
- $textColours = @{}
- $textLit = @{}
- for ($y = 211 - 28; $y -le 250 - 28; $y++) {
- for ($x = 0; $x -lt $bmp.Width; $x++) {
- $c = $bmp.GetPixel($x, $y).ToArgb()
- if ($c -ne $brown) { $textColours[$c] = 1; $textLit[[int][Math]::Floor(($y - 183) / 8)] = 1 }
- }
- }
- if ($textColours.Count -gt 1) { $failures.Add("status area shows $($textColours.Count) colours besides brown (expected light red only)") }
- foreach ($row in 0, 1, 2, 4) { if (-not $textLit.ContainsKey($row)) { $failures.Add("status row $($row + 20) is empty in the screenshot") } }
- if ($textLit.ContainsKey(3)) { $failures.Add('the spare status row 23 is not empty') }
- # Map colours: brown, light red, grey, green, blue, black as rendered in the map area above.
- $mapColours = @{}
- for ($y = 51 - 28; $y -le 209 - 28; $y++) { for ($x = 0; $x -lt $bmp.Width; $x++) { $mapColours[$bmp.GetPixel($x, $y).ToArgb()] = 1 } }
- for ($x = 0; $x -lt $bmp.Width; $x++) {
- 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 }
- }
- } finally { $bmp.Dispose() }
- }
-
- $distinct = ($starts | Group-Object | Sort-Object Name | ForEach-Object { "$($_.Name) x$($_.Count)" }) -join ', '
- Write-Host "Split starts (line:cycle): $distinct"
- Write-Host "Frames: $splitFrames splits, $moveFrames people updates; people-in-view digits wrong in $badCounts frames."
- if ($failures.Count -gt 0) {
- $failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" }
- Write-Host '[FAIL] split check' -ForegroundColor Red
- exit 1
- }
- Write-Host '[PASS] split writes land in the measured border window every frame; status digits match; no foreign colours at the boundary.' -ForegroundColor Green
- exit 0
|