選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

90 行
3.7KB

  1. # E07-S02: autostart the editor on a disposable disk copy (D151: the C128 Vim
  2. # in x128 80-column mode by default; -Emulator x64sc selects the C64 build).
  3. #
  4. # The session is strictly sequential: this launcher refuses to start while a
  5. # compiler session owns the same image, waits for the emulator to exit and for
  6. # the image to flush, and never writes the source disk it copies from.
  7. [CmdletBinding()]
  8. param(
  9. [string]$EditorPrg = "",
  10. [string]$SourceImage = "",
  11. [string]$DiskImage = "",
  12. [ValidateSet("x128", "x64sc")][string]$Emulator = "x128",
  13. [int]$LimitCycles = 0,
  14. [string]$Screenshot = "",
  15. [switch]$Warp
  16. )
  17. $ErrorActionPreference = "Stop"
  18. $project = Split-Path $PSScriptRoot -Parent
  19. $repository = Split-Path $project -Parent
  20. $build = Join-Path $project "build"
  21. Import-Module (Join-Path $PSScriptRoot "lib\Nova128Launcher.psm1") -Force
  22. if ($EditorPrg -eq "") {
  23. if ($Emulator -eq "x128") {
  24. $EditorPrg = Join-Path $repository "vim\vim128.prg"
  25. } else {
  26. throw "the C64 editor lives on ../vim/vim-improved.d81; extract 'vim' and pass -EditorPrg"
  27. }
  28. }
  29. if ($SourceImage -eq "") { $SourceImage = Join-Path $repository "vim\vim-improved.d81" }
  30. if ($DiskImage -eq "") { $DiskImage = Join-Path $build "newlang-edit.d81" }
  31. $EditorPrg = [IO.Path]::GetFullPath($EditorPrg)
  32. $DiskImage = [IO.Path]::GetFullPath($DiskImage)
  33. if ($SourceImage) { $SourceImage = [IO.Path]::GetFullPath($SourceImage) }
  34. if (-not (Test-Path -LiteralPath $EditorPrg -PathType Leaf)) {
  35. throw "editor program not found: $EditorPrg (build Vim or pass -EditorPrg)"
  36. }
  37. $null = Get-Nova128ViceTool $Emulator
  38. $sourceHash = $null
  39. New-Item -ItemType Directory -Force -Path (Split-Path $DiskImage -Parent) | Out-Null
  40. if ($SourceImage) {
  41. if (-not (Test-Path -LiteralPath $SourceImage -PathType Leaf)) {
  42. throw "source disk image not found: $SourceImage"
  43. }
  44. if ([string]::Equals($SourceImage, $DiskImage, [StringComparison]::OrdinalIgnoreCase)) {
  45. throw "the editor must never start on the source disk image"
  46. }
  47. $sourceHash = (Get-FileHash -LiteralPath $SourceImage -Algorithm SHA256).Hash
  48. if (Test-Path -LiteralPath $DiskImage) { Remove-Item -LiteralPath $DiskImage -Force }
  49. Copy-Item -LiteralPath $SourceImage -Destination $DiskImage
  50. Write-Host "fresh editor disk: $DiskImage"
  51. }
  52. # The session's own disk carries the editor, so the machine can reload it and
  53. # the source image stays untouched.
  54. if ($Emulator -eq "x128") {
  55. if (-not (Test-Path -LiteralPath $DiskImage)) {
  56. throw "the C128 editor needs a writable disk image: $DiskImage"
  57. }
  58. Add-Nova128DiskFile -Image $DiskImage -HostPath $EditorPrg -DiskName "vim128" -Type prg
  59. Write-Host "injected vim128 into $DiskImage"
  60. # The editor is then started from the disk copy, not from the host path:
  61. # a host-loaded program has no device number, and vim128's saves would
  62. # report success without reaching the image.
  63. $EditorPrg = "vim128"
  64. }
  65. $session = $null
  66. try {
  67. $session = Enter-Nova128ImageSession -Image $DiskImage -Kind "editor"
  68. $session = $session
  69. $null = Invoke-Nova128Emulator -Emulator $Emulator -Program $EditorPrg `
  70. -DiskImage $DiskImage -Screenshot $Screenshot -LimitCycles $LimitCycles `
  71. -Warp:$Warp -EightyColumn:($Emulator -eq "x128") `
  72. -ProgramOnDisk:($Emulator -eq "x128")
  73. } finally {
  74. if ($session) { Exit-Nova128ImageSession -Session $session }
  75. }
  76. if ($sourceHash) {
  77. $after = (Get-FileHash -LiteralPath $SourceImage -Algorithm SHA256).Hash
  78. if ($after -ne $sourceHash) { throw "the source disk image changed during the editor session" }
  79. Write-Host "source disk unchanged: $after"
  80. }
  81. Write-Host "editor session closed and the image is flushed"
  82. Write-Host "next: run scripts\launch-compiler.ps1; never attach two writable sessions"

Powered by TurnKey Linux.