# E04-S03: run the scalar emitter fixture, check results, capture golden bytes, # disassemble them with da65, and compare committed expectations when present. [CmdletBinding()] param( [int]$Port = 6530, [int]$TimeoutSeconds = 90 ) $ErrorActionPreference = "Stop" $project = Split-Path $PSScriptRoot -Parent Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force & (Join-Path $PSScriptRoot "build-scalar-test.ps1") $out = Join-Path $project "build\scalar-test" $prg = Join-Path $out "scalar-test.prg" $labels = Join-Path $out "scalar-test.lbl" $session = Start-Nova128X128 -Autostart $prg -Port $Port ` -Screenshot (Join-Path $out "scalar-test-vicii.png") try { $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds $lenAddr = Get-Nova128Label -Labels $labels -Name "golden_len" $copyAddr = Get-Nova128Label -Labels $labels -Name "golden_copy" $lenBytes = Read-Nova128Memory -Session $session -Address $lenAddr -Count 1 $goldenLen = [int]$lenBytes[0] if ($goldenLen -eq 0) { throw "golden_len is zero" } $golden = Read-Nova128Memory -Session $session -Address $copyAddr -Count $goldenLen } finally { Stop-Nova128X128 $session } Write-Host ('mailbox: ' + (($mb | ForEach-Object { $_.ToString('X2') }) -join ' ')) Write-Host ("results: byte={0:X2} cmp={1:X2} add={2:X2}{3:X2} sub={4:X2}{5:X2} mul={6:X2} fault={7}" -f ` $mb[8], $mb[9], $mb[11], $mb[10], $mb[13], $mb[12], $mb[14], $mb[15]) $failures = @() if ($mb[2] -ne 0x03) { $failures += "producer $($mb[2]) is not a generated program" } if ($mb[3] -ne 0xA5) { $failures += "fixture status is not PASS" } if ($mb[4] -ne 0 -or $mb[5] -ne 0) { $failures += "code is $($mb[4] + 256 * $mb[5])" } $want = [ordered]@{ byte = 0x5A cmp = 0x0E addLow = 0x21; addHigh = 0x22 subLow = 0xBB; subHigh = 0xEC mulLow = 0xE0 fault = 1 } if ($mb[8] -ne $want.byte) { $failures += ('byte assignment is {0:X2}, expected {1:X2}' -f $mb[8], $want.byte) } if ($mb[9] -ne $want.cmp) { $failures += ('comparisons are {0:X2}, expected {1:X2}' -f $mb[9], $want.cmp) } if ($mb[10] -ne $want.addLow -or $mb[11] -ne $want.addHigh) { $failures += ('add is {0:X2}{1:X2}, expected {2:X2}{3:X2}' -f $mb[11], $mb[10], $want.addHigh, $want.addLow) } if ($mb[12] -ne $want.subLow -or $mb[13] -ne $want.subHigh) { $failures += ('sub is {0:X2}{1:X2}, expected {2:X2}{3:X2}' -f $mb[13], $mb[12], $want.subHigh, $want.subLow) } if ($mb[14] -ne $want.mulLow) { $failures += ('mul low is {0:X2}, expected {1:X2}' -f $mb[14], $want.mulLow) } if ($mb[15] -ne $want.fault) { $failures += "fault byte is $($mb[15]), expected 1" } $binPath = Join-Path $out "scalar.golden.bin" [IO.File]::WriteAllBytes($binPath, $golden) $disPath = Join-Path $out "scalar.golden.dis" $da65 = (Get-Command da65 -ErrorAction Stop).Source & $da65 --cpu 6502 --start-addr 0000 -o $disPath $binPath 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { throw "da65 failed on $binPath" } # Remove da65's timestamp/path header so the committed listing is stable. $disLines = Get-Content -LiteralPath $disPath | Where-Object { $_.Trim() -ne "" -and -not $_.StartsWith(";") } [IO.File]::WriteAllText($disPath, (($disLines -join "`n") + "`n")) $hex = (($golden | ForEach-Object { $_.ToString("X2") }) -join " ") + "`n" $actualHex = Join-Path $out "scalar.golden.hex" [IO.File]::WriteAllText($actualHex, $hex) Write-Host "golden bytes: $goldenLen" Write-Host "hex: $actualHex" Write-Host "disassembly: $disPath" $expectedHexPath = Join-Path $project "tests\codegen\scalar.expected.hex" if (Test-Path -LiteralPath $expectedHexPath) { $expectedHex = ([IO.File]::ReadAllText($expectedHexPath)).Trim() if ($hex.Trim() -ne $expectedHex) { $failures += "golden bytes differ from tests/codegen/scalar.expected.hex" } } else { Write-Host "no tests/codegen/scalar.expected.hex yet" } $expectedDisPath = Join-Path $project "tests\codegen\scalar.expected.dis" if (Test-Path -LiteralPath $expectedDisPath) { $expectedDis = ([IO.File]::ReadAllText($expectedDisPath)).Replace("`r`n", "`n").TrimEnd() $actualDis = ([IO.File]::ReadAllText($disPath)).Replace("`r`n", "`n").TrimEnd() if ($actualDis -ne $expectedDis) { $failures += "golden disassembly differs from tests/codegen/scalar.expected.dis" } } else { Write-Host "no tests/codegen/scalar.expected.dis yet" } if ($failures) { throw ("scalar verification failed:`n " + ($failures -join "`n ")) } Write-Host "verified scalar assignments, comparisons, short-circuit, arithmetic, and divide-by-zero"