# E07-S02: autostart the Vim editor in x64sc on a disposable disk copy. # # The session is strictly sequential: this launcher refuses to start while a # compiler session owns the same image, waits for x64sc to exit and for the # image to flush, and never writes the source disk it copies from. [CmdletBinding()] param( [string]$EditorPrg = "", [string]$SourceImage = "", [string]$DiskImage = "", [int]$LimitCycles = 0, [string]$Screenshot = "", [switch]$Warp ) $ErrorActionPreference = "Stop" $project = Split-Path $PSScriptRoot -Parent $repository = Split-Path $project -Parent $build = Join-Path $project "build" Import-Module (Join-Path $PSScriptRoot "lib\Nova128Launcher.psm1") -Force if ($EditorPrg -eq "") { $EditorPrg = Join-Path $repository "vim\vim128.prg" } if ($SourceImage -eq "") { $SourceImage = Join-Path $repository "vim\vim-improved.d81" } if ($DiskImage -eq "") { $DiskImage = Join-Path $build "newlang-edit.d81" } $EditorPrg = [IO.Path]::GetFullPath($EditorPrg) $DiskImage = [IO.Path]::GetFullPath($DiskImage) if ($SourceImage) { $SourceImage = [IO.Path]::GetFullPath($SourceImage) } if (-not (Test-Path -LiteralPath $EditorPrg -PathType Leaf)) { throw "editor program not found: $EditorPrg (build Vim or pass -EditorPrg)" } $null = Get-Nova128ViceTool "x64sc" $sourceHash = $null New-Item -ItemType Directory -Force -Path (Split-Path $DiskImage -Parent) | Out-Null if ($SourceImage) { if (-not (Test-Path -LiteralPath $SourceImage -PathType Leaf)) { throw "source disk image not found: $SourceImage" } if ([string]::Equals($SourceImage, $DiskImage, [StringComparison]::OrdinalIgnoreCase)) { throw "the editor must never start on the source disk image" } $sourceHash = (Get-FileHash -LiteralPath $SourceImage -Algorithm SHA256).Hash if (Test-Path -LiteralPath $DiskImage) { Remove-Item -LiteralPath $DiskImage -Force } Copy-Item -LiteralPath $SourceImage -Destination $DiskImage Write-Host "fresh editor disk: $DiskImage" } $session = $null try { $session = Enter-Nova128ImageSession -Image $DiskImage -Kind "editor" $null = Invoke-Nova128Emulator -Emulator "x64sc" -Program $EditorPrg ` -DiskImage $DiskImage -Screenshot $Screenshot -LimitCycles $LimitCycles -Warp:$Warp } finally { if ($session) { Exit-Nova128ImageSession -Session $session } } if ($sourceHash) { $after = (Get-FileHash -LiteralPath $SourceImage -Algorithm SHA256).Hash if ($after -ne $sourceHash) { throw "the source disk image changed during the editor session" } Write-Host "source disk unchanged: $after" } Write-Host "editor session closed and the image is flushed" Write-Host "next: run scripts\launch-compiler.ps1; never attach two writable sessions"