|
- # E07-S02: autostart the editor on a disposable disk copy (D151: the C128 Vim
- # in x128 80-column mode by default; -Emulator x64sc selects the C64 build).
- #
- # The session is strictly sequential: this launcher refuses to start while a
- # compiler session owns the same image, waits for the emulator 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 = "",
- [ValidateSet("x128", "x64sc")][string]$Emulator = "x128",
- [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 "") {
- if ($Emulator -eq "x128") {
- $EditorPrg = Join-Path $repository "vim\vim128.prg"
- } else {
- throw "the C64 editor lives on ../vim/vim-improved.d81; extract 'vim' and pass -EditorPrg"
- }
- }
- 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 $Emulator
-
- $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"
- }
-
- # The session's own disk carries the editor, so the machine can reload it and
- # the source image stays untouched.
- if ($Emulator -eq "x128") {
- if (-not (Test-Path -LiteralPath $DiskImage)) {
- throw "the C128 editor needs a writable disk image: $DiskImage"
- }
- Add-Nova128DiskFile -Image $DiskImage -HostPath $EditorPrg -DiskName "vim128" -Type prg
- Write-Host "injected vim128 into $DiskImage"
- # The editor is then started from the disk copy, not from the host path:
- # a host-loaded program has no device number, and vim128's saves would
- # report success without reaching the image.
- $EditorPrg = "vim128"
- }
-
- $session = $null
- try {
- $session = Enter-Nova128ImageSession -Image $DiskImage -Kind "editor"
- $session = $session
- $null = Invoke-Nova128Emulator -Emulator $Emulator -Program $EditorPrg `
- -DiskImage $DiskImage -Screenshot $Screenshot -LimitCycles $LimitCycles `
- -Warp:$Warp -EightyColumn:($Emulator -eq "x128") `
- -ProgramOnDisk:($Emulator -eq "x128")
- } 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"
|