# E01-S01: execute the platform proof and verify entry, completion, and result. [CmdletBinding()] param( [int]$RemotePort = 6510 ) $ErrorActionPreference = "Stop" $project = Split-Path $PSScriptRoot -Parent $build = Join-Path $project "build" $program = Join-Path $build "minimal.prg" $traceCommands = Join-Path $project "monitor\minimal-trace.txt" $monitorLog = Join-Path $build "minimal-monitor.log" $x128 = "C:\Program Files\GTK3VICE-3.10-win64\bin\x128.exe" & (Join-Path $PSScriptRoot "build-minimal.ps1") if ($LASTEXITCODE -ne 0) { throw "minimal build failed" } if (-not (Test-Path -LiteralPath $x128)) { throw "x128.exe not found at $x128" } if (Test-Path -LiteralPath $monitorLog) { Remove-Item -LiteralPath $monitorLog -Force } $arguments = @( "-autostart", ('"' + $program + '"'), "-autostart-warp", "-warp", "-sounddev", "dummy", "-moncommands", ('"' + $traceCommands + '"'), "-monlog", "-monlogname", ('"' + $monitorLog + '"'), "-remotemonitor", "-remotemonitoraddress", ("ip4://127.0.0.1:{0}" -f $RemotePort) ) -join ' ' $psi = [Diagnostics.ProcessStartInfo]::new() $psi.FileName = $x128 $psi.Arguments = $arguments $psi.UseShellExecute = $true $psi.WindowStyle = [Diagnostics.ProcessWindowStyle]::Hidden $process = [Diagnostics.Process]::Start($psi) $client = $null try { $deadline = [DateTime]::UtcNow.AddSeconds(10) while ([DateTime]::UtcNow -lt $deadline) { if ($process.HasExited) { throw "x128 exited before remote verification" } try { $client = [Net.Sockets.TcpClient]::new() $client.Connect("127.0.0.1", $RemotePort) break } catch { if ($client) { $client.Dispose(); $client = $null } Start-Sleep -Milliseconds 200 } } if (-not $client -or -not $client.Connected) { throw "could not connect to the VICE remote monitor" } # Autostart runs in warp. Give BASIC enough wall time to load, RUN, execute # the message loop, and return before inspecting the result byte. Start-Sleep -Seconds 3 $stream = $client.GetStream() $stream.ReadTimeout = 2000 $writer = [IO.StreamWriter]::new($stream, [Text.Encoding]::ASCII, 1024, $true) $writer.NewLine = "`n" $writer.AutoFlush = $true $writer.WriteLine('m $1c3e $1c3e') Start-Sleep -Milliseconds 300 $buffer = New-Object byte[] 8192 $response = "" while ($stream.DataAvailable) { $count = $stream.Read($buffer, 0, $buffer.Length) if ($count -le 0) { break } $response += [Text.Encoding]::ASCII.GetString($buffer, 0, $count) Start-Sleep -Milliseconds 50 } if ($response -notmatch '(?i)C:1c3e\s+a5\b') { throw "minimal_result was not `$A5; monitor response: $response" } $writer.WriteLine("q") $writer.Dispose() $client.Dispose() $client = $null if (-not $process.WaitForExit(5000)) { throw "x128 did not exit after remote-monitor quit" } if (-not (Test-Path -LiteralPath $monitorLog)) { throw "VICE did not create the monitor trace log" } $trace = Get-Content -Raw -LiteralPath $monitorLog if ($trace -notmatch '(?i)1c0d') { throw "monitor trace did not record minimal_entry at `$1C0D" } if ($trace -notmatch '(?i)1c24') { throw "monitor trace did not record minimal_done at `$1C24" } Write-Host "verified x128 entry `$1C0D, done `$1C24, result `$A5" Write-Host ("monitor log: {0}" -f $monitorLog) } finally { if ($client) { $client.Dispose() } if ($process -and -not $process.HasExited) { $process.Kill() $process.WaitForExit() } }