25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.7KB

  1. # E07-S02: autostart the Vim editor in x64sc on a disposable disk copy.
  2. #
  3. # The session is strictly sequential: this launcher refuses to start while a
  4. # compiler session owns the same image, waits for x64sc to exit and for the
  5. # image to flush, and never writes the source disk it copies from.
  6. [CmdletBinding()]
  7. param(
  8. [string]$EditorPrg = "",
  9. [string]$SourceImage = "",
  10. [string]$DiskImage = "",
  11. [int]$LimitCycles = 0,
  12. [string]$Screenshot = "",
  13. [switch]$Warp
  14. )
  15. $ErrorActionPreference = "Stop"
  16. $project = Split-Path $PSScriptRoot -Parent
  17. $repository = Split-Path $project -Parent
  18. $build = Join-Path $project "build"
  19. Import-Module (Join-Path $PSScriptRoot "lib\Nova128Launcher.psm1") -Force
  20. if ($EditorPrg -eq "") { $EditorPrg = Join-Path $repository "vim\vim128.prg" }
  21. if ($SourceImage -eq "") { $SourceImage = Join-Path $repository "vim\vim-improved.d81" }
  22. if ($DiskImage -eq "") { $DiskImage = Join-Path $build "newlang-edit.d81" }
  23. $EditorPrg = [IO.Path]::GetFullPath($EditorPrg)
  24. $DiskImage = [IO.Path]::GetFullPath($DiskImage)
  25. if ($SourceImage) { $SourceImage = [IO.Path]::GetFullPath($SourceImage) }
  26. if (-not (Test-Path -LiteralPath $EditorPrg -PathType Leaf)) {
  27. throw "editor program not found: $EditorPrg (build Vim or pass -EditorPrg)"
  28. }
  29. $null = Get-Nova128ViceTool "x64sc"
  30. $sourceHash = $null
  31. New-Item -ItemType Directory -Force -Path (Split-Path $DiskImage -Parent) | Out-Null
  32. if ($SourceImage) {
  33. if (-not (Test-Path -LiteralPath $SourceImage -PathType Leaf)) {
  34. throw "source disk image not found: $SourceImage"
  35. }
  36. if ([string]::Equals($SourceImage, $DiskImage, [StringComparison]::OrdinalIgnoreCase)) {
  37. throw "the editor must never start on the source disk image"
  38. }
  39. $sourceHash = (Get-FileHash -LiteralPath $SourceImage -Algorithm SHA256).Hash
  40. if (Test-Path -LiteralPath $DiskImage) { Remove-Item -LiteralPath $DiskImage -Force }
  41. Copy-Item -LiteralPath $SourceImage -Destination $DiskImage
  42. Write-Host "fresh editor disk: $DiskImage"
  43. }
  44. $session = $null
  45. try {
  46. $session = Enter-Nova128ImageSession -Image $DiskImage -Kind "editor"
  47. $null = Invoke-Nova128Emulator -Emulator "x64sc" -Program $EditorPrg `
  48. -DiskImage $DiskImage -Screenshot $Screenshot -LimitCycles $LimitCycles -Warp:$Warp
  49. } finally {
  50. if ($session) { Exit-Nova128ImageSession -Session $session }
  51. }
  52. if ($sourceHash) {
  53. $after = (Get-FileHash -LiteralPath $SourceImage -Algorithm SHA256).Hash
  54. if ($after -ne $sourceHash) { throw "the source disk image changed during the editor session" }
  55. Write-Host "source disk unchanged: $after"
  56. }
  57. Write-Host "editor session closed and the image is flushed"
  58. Write-Host "next: run scripts\launch-compiler.ps1; never attach two writable sessions"

Powered by TurnKey Linux.