# E04-S07: compile COUNTER.N8, check deterministic PRG/MAP output, and run the # generated PRG in x128. [CmdletBinding()] param([int]$Port = 6558, [int]$TimeoutSeconds = 180) $ErrorActionPreference = "Stop" $project = Split-Path $PSScriptRoot -Parent Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force & (Join-Path $PSScriptRoot "build-counter-test.ps1") $out = Join-Path $project "build\counter-test" $disk = Join-Path $out "counter-test.d81" $failures = @() $session = Start-Nova128X128 -Autostart $disk -Drive8Image $disk -Port $Port ` -Screenshot (Join-Path $out "counter-compile-vicii.png") try { $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds } finally { Stop-Nova128X128 $session } Write-Host ("mailbox: " + (($mb | ForEach-Object { $_.ToString('X2') }) -join ' ')) if ($mb[2] -ne 0x02) { $failures += ("producer $($mb[2]) expected 2 (compiler)") } if ($mb[3] -ne 0xA5) { $failures += ("compiler status {0:X2} failed at stage {1}" -f $mb[3], $mb[4]) } if ($mb[8] -ne 0) { $failures += "diagnostics present: $($mb[8])" } if ($mb[9] -ne 0) { $failures += "emitter bad: $($mb[9])" } if ($mb[10] -eq 0) { $failures += "no generated code" } if ($mb[11] -ne 0) { $failures += "codegen error: $($mb[11])" } if ($mb[12] -ne 0) { $failures += "flow error: $($mb[12])" } if ($mb[13] -ne 0) { $failures += "output error: $($mb[13])" } $c1541 = Get-ViceTool "c1541" $prg = Join-Path $out "counter.prg" $prg2 = Join-Path $out "countb.prg" $map = Join-Path $out "counter.map" foreach ($path in @($prg, $prg2, $map)) { if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path -Force } } & $c1541 -attach $disk -read "counter.prg" $prg 2>&1 | Out-Null & $c1541 -attach $disk -read "countb.prg" $prg2 2>&1 | Out-Null & $c1541 -attach $disk -read "counter.map,s" $map 2>&1 | Out-Null foreach ($path in @($prg, $prg2, $map)) { if (-not (Test-Path -LiteralPath $path)) { $failures += "missing $(Split-Path $path -Leaf)" } } if (-not (Test-Path -LiteralPath $prg) -or -not (Test-Path -LiteralPath $prg2)) { $failures += "cannot check deterministic output" } else { $a = [IO.File]::ReadAllBytes($prg) $b = [IO.File]::ReadAllBytes($prg2) if ($a.Length -ne $b.Length -or (Compare-Object $a $b)) { $failures += "two compilations are not byte-identical" } if ($a.Length -lt 14 -or $a[0] -ne 0x01 -or $a[1] -ne 0x1C) { $failures += "COUNTER.PRG does not load at `$1C01" } } $codeSize = ('{0:X4}' -f $mb[10]) $codeStart = '1C4F' if (Test-Path -LiteralPath $map) { $text = Get-Content -Raw -LiteralPath $map foreach ($want in @("ENTRY 1C0D", "SECTION STUB 1C01 000C", "SECTION START 1C0D 0042", "SECTION CODE $codeStart $codeSize")) { if ($text -notmatch [regex]::Escape($want)) { $failures += "MAP missing '$want'" } } } $result = -1 if (-not $failures) { $session = Start-Nova128X128 -Autostart $prg -Port ($Port + 1) ` -Screenshot (Join-Path $out "counter-run-vicii.png") try { $rmb = Wait-Nova128Mailbox $session -TimeoutSeconds 60 } finally { Stop-Nova128X128 $session } if ($rmb[2] -ne 0x03) { $failures += ("program producer $($rmb[2]) expected 3") } if ($rmb[3] -ne 0xA5) { $failures += ("program status {0:X2}" -f $rmb[3]) } $result = $rmb[8] if ($result -ne 15) { $failures += "program total $result, expected 15" } } if ($failures) { throw ("counter verification failed:`n " + ($failures -join "`n ")) } Write-Host ("compile: {0} code bytes, deterministic PRG, MAP ENTRY 1C0D / CODE {1}" -f $mb[10], $codeStart) Write-Host "run: generated COUNTER.PRG reported total=$result" Write-Host "verified counter.n8 compiles from source and runs in x128"