|
- # E04-S05: compile HELLO.N8 in x128, extract the generated PRG, and run it in
- # a second x128 session; the screen must show the source's string.
- [CmdletBinding()]
- param([int]$Port = 6548, [int]$TimeoutSeconds = 180)
-
- $ErrorActionPreference = "Stop"
- $project = Split-Path $PSScriptRoot -Parent
- Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
- & (Join-Path $PSScriptRoot "build-hello-test.ps1")
-
- $out = Join-Path $project "build\hello-test"
- $disk = Join-Path $out "hello-test.d81"
- $text = "HELLO FROM NOVA128"
- $failures = @()
-
- # ------------------------------------------------------- compile session
- $session = Start-Nova128X128 -Autostart $disk -Drive8Image $disk -Port $Port `
- -Screenshot (Join-Path $out "hello-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]) (see HELLO.ERR)" }
- if ($mb[9] -ne 1) { $failures += "captured $($mb[9]) string prints, expected 1" }
- if ($mb[10] -ne 0) { $failures += "unsupported print flag set" }
- if ($mb[11] -ne 18) { $failures += "captured $($mb[11]) string bytes, expected 18" }
- if ($mb[12] -ne 0) { $failures += "output error $($mb[12])" }
-
- # ------------------------------------------------- extract the generated PRG
- $c1541 = Get-ViceTool "c1541"
- $prg = Join-Path $out "hello.prg"
- if (Test-Path -LiteralPath $prg) { Remove-Item -LiteralPath $prg -Force }
- & $c1541 -attach $disk -read "hello.prg" $prg 2>&1 | Out-Null
- if (-not (Test-Path -LiteralPath $prg)) {
- $failures += "HELLO.PRG was not written to the compile disk"
- } else {
- $bytes = [IO.File]::ReadAllBytes($prg)
- if ($bytes.Length -lt 14 -or $bytes[0] -ne 0x01 -or $bytes[1] -ne 0x1C) {
- $failures += "HELLO.PRG does not load at `$1C01"
- }
- }
-
- # ----------------------------------------------------------- run the PRG
- $hitRow = -1
- if (-not $failures) {
- $session = Start-Nova128X128 -Autostart $prg -Port ($Port + 1) `
- -Screenshot (Join-Path $out "hello-run-vicii.png")
- try {
- $deadline = [DateTime]::UtcNow.AddSeconds(60)
- while ([DateTime]::UtcNow -lt $deadline) {
- Start-Sleep -Seconds 1
- try { $screenRam = Read-Nova128Memory $session 0x0400 1000 } catch { continue }
- 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 { '?' }
- }
- if ((-join $chars) -match [regex]::Escape($text)) { $hitRow = $r; break }
- }
- if ($hitRow -ge 0) { break }
- }
- } finally {
- Stop-Nova128X128 $session
- }
- if ($hitRow -lt 0) { $failures += "the generated PRG never displayed '$text'" }
- }
-
- if ($failures) { throw ("hello verification failed:`n " + ($failures -join "`n ")) }
- Write-Host ("compile: diagnostics 0, one 18-byte print, out_err 0; HELLO.PRG {0} bytes" -f (Get-Item $prg).Length)
- Write-Host ("run: '$text' displayed on screen row $hitRow")
- Write-Host "verified hello.n8 compiles to a PRG and the PRG runs in x128"
|