|
- # E02-S04: run the diagnostics test in x128, then check the result block, the
- # 40-column screen, and the ERR files left on the disk image.
- [CmdletBinding()]
- param([int]$Port = 6534, [int]$TimeoutSeconds = 180)
-
- $ErrorActionPreference = "Stop"
- $project = Split-Path $PSScriptRoot -Parent
- Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
- & (Join-Path $PSScriptRoot "build-diag-test.ps1")
-
- $out = Join-Path $project "build\diag-test"
- $disk = Join-Path $out "diag-test.d81"
- $expected = Get-Content -Raw (Join-Path $out "expected.json") | ConvertFrom-Json
- $failures = @()
-
- $session = Start-Nova128X128 -Autostart $disk -Drive8Image $disk -Port $Port `
- -Screenshot (Join-Path $out "diag-test-vicii.png")
- try {
- $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds
- $results = Read-Nova128Memory $session ($mb[8] + 256 * $mb[9]) 34
- Invoke-Nova128Monitor $session "x" | Out-Null
- Start-Sleep -Seconds 2 # let the OK line print
- $screenRam = Read-Nova128Memory $session 0x0400 1000
- } finally {
- Stop-Nova128X128 $session -SettleSeconds 0
- }
-
- # ------------------------------------------------------------ results
- $want = [ordered]@{ "phase A count" = @(0, 6); "phase D count" = @(1, 2); "phase D file state (2=failed)" = @(2, 2)
- "phase B count" = @(3, 20); "phase C count" = @(4, 0) }
- foreach ($k in $want.Keys) {
- if ($results[$want[$k][0]] -ne $want[$k][1]) { $failures += "${k}: $($results[$want[$k][0]]) expected $($want[$k][1])" }
- }
- for ($i = 5; $i -le 8; $i++) { if ($results[$i] -ne 0) { $failures += "files left open after phase $($i - 4): $($results[$i])" } }
- $carries = $results[9..33]
- $wantCarries = @(0) * 20 + @(1) * 5
- if (($carries -join ',') -ne ($wantCarries -join ',')) {
- $failures += "phase B carries $($carries -join '') expected $($wantCarries -join '')"
- }
-
- # ------------------------------------------------------------- screen
- $rows = for ($r = 0; $r -lt 25; $r++) {
- $chars = for ($c = 0; $c -lt 40; $c++) {
- $code = $screenRam[$r * 40 + $c]
- if ($code -le 0x1F) { [char]($code + 0x40) } elseif ($code -le 0x3F) { [char]$code } else { '?' }
- }
- (-join $chars).TrimEnd()
- }
- for ($r = 0; $r -lt $expected.screen.Count; $r++) {
- $pattern = '^' + [regex]::Escape($expected.screen[$r]).Replace('\#\#', '\d\d').Replace('##', '\d\d') + '$'
- if ($rows[$r] -notmatch $pattern) { $failures += "screen row ${r}: '$($rows[$r])' expected '$($expected.screen[$r])'" }
- }
- $wide = @($rows | Where-Object { $_.Length -gt 39 })
- if ($wide) { $failures += "screen rows longer than 39: $($wide -join ' | ')" }
-
- # ---------------------------------------------------------- ERR files
- $c1541 = Get-ViceTool "c1541"
- $listing = (& $c1541 -attach $disk -list 2>&1) | Out-String
- function Read-SeqText([string]$name) {
- $dest = Join-Path $out ($name.Replace('*', '_') + ".bin")
- if (Test-Path $dest) { Remove-Item $dest -Force }
- & $c1541 -attach $disk -read "$name,s" $dest 2>&1 | Out-Null # SEQ needs ,s
- if (-not (Test-Path $dest)) { return $null }
- $bytes = [IO.File]::ReadAllBytes($dest)
- return @(([Text.Encoding]::ASCII.GetString($bytes).TrimEnd("`r")) -split "`r")
- }
- $diagLines = Read-SeqText "diag.err"
- if ($null -eq $diagLines) { $failures += "diag.err missing" }
- elseif (($diagLines -join "`n") -cne ($expected.diag -join "`n")) {
- $failures += "diag.err differs:`n got: " + ($diagLines -join "`n ") + "`n want: " + ($expected.diag -join "`n ")
- }
- $limitLines = Read-SeqText "limit.err"
- if ($null -eq $limitLines) { $failures += "limit.err missing" }
- elseif (($limitLines -join "`n") -cne ($expected.limit -join "`n")) {
- $failures += "limit.err differs ($($limitLines.Count) lines): first '$($limitLines[0])', last '$($limitLines[-1])'"
- }
- if ($listing -match '"clean\.err"') { $failures += "stale clean.err was not scratched" }
- if ($listing -match '"bad') { $failures += "a bad*.err file was created" }
-
- if ($failures) { throw ("diagnostics verification failed:`n " + ($failures -join "`n ")) }
- Write-Host "screen (rows 0-$($expected.screen.Count - 1)):"
- $rows[0..($expected.screen.Count - 1)] | ForEach-Object { Write-Host " |$_" }
- Write-Host ("diag.err: {0} lines, limit.err: {1} lines (20 + limit), clean.err scratched, no bad*.err" -f
- $diagLines.Count, $limitLines.Count)
- Write-Host "verified diagnostics: results, screen, and ERR files match"
|