Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

136 строки
6.3KB

  1. # DEMO: write a Nova128 program in the Vim clone (x64sc, C64 mode), then check
  2. # it on the C128 (x128) with the compiler front end as it exists today.
  3. #
  4. # pwsh -File scripts/demo-write-check.ps1 (good.n8 and bad.n8)
  5. # pwsh -File scripts/demo-write-check.ps1 -Programs good.n8
  6. #
  7. # For each demo/<name>.n8 (an ASCII mirror):
  8. # 1. x64sc autostarts VIM from a fresh copy of vim/work.d81 and the program
  9. # is TYPED into it through the keyboard buffer: file name, `y` to create,
  10. # `i`, the text, RUN/STOP, `:w`. Vim writes the PETSCII SEQ file and
  11. # stays on screen for the exit screenshot.
  12. # 2. The SEQ file is read back with c1541 and compared with the mirror.
  13. # 3. x128 autostarts N8CHECK from the same disk (after x64sc has exited),
  14. # the file name is typed at its prompt, and it parses the file.
  15. # 4. The screen and NAME.ERR, if any, are shown.
  16. # Screenshots go to build/demo/. No code is generated yet (epic E04).
  17. [CmdletBinding()]
  18. param([string[]]$Programs = @("good.n8", "bad.n8"), [int]$KeyDelay = 120)
  19. $ErrorActionPreference = "Stop"
  20. $project = Split-Path $PSScriptRoot -Parent
  21. $repository = Split-Path $project -Parent
  22. Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
  23. $out = Join-Path $project "build\demo"
  24. New-Item -ItemType Directory -Force -Path $out | Out-Null
  25. $c1541 = Get-ViceTool "c1541"
  26. $x64 = Get-ViceTool "x64sc"
  27. $x128 = Get-ViceTool "x128"
  28. # ------------------------------------------------------------- build
  29. $link = Invoke-Nova128Link -Name "n8check" -BuildDir $out `
  30. -Config (Join-Path $project "cfg\compiler.cfg") -Sources @(
  31. (Join-Path $project "src\compiler\mmu.s"),
  32. (Join-Path $project "src\compiler\diskio.s"),
  33. (Join-Path $project "src\compiler\source.s"),
  34. (Join-Path $project "src\compiler\lexer.s"),
  35. (Join-Path $project "src\compiler\names.s"),
  36. (Join-Path $project "src\compiler\diagnostics.s"),
  37. (Join-Path $project "src\compiler\parser.s"),
  38. (Join-Path $project "demo\n8check.s"))
  39. # A fresh copy: the Vim work disk itself is never written.
  40. $disk = Join-Path $out "demo.d81"
  41. if (Test-Path $disk) { Remove-Item $disk -Force }
  42. Copy-Item (Join-Path $repository "vim\work.d81") $disk
  43. & $c1541 $disk -write $link.Program "n8check" 2>&1 | Out-Null
  44. foreach ($p in $Programs) { # stale copies, if any
  45. & $c1541 $disk -delete $p ($p -replace '\.n8$', '.err') 2>&1 | Out-Null
  46. }
  47. function Quote-Arg([string]$a) {
  48. if ($a -ne "" -and $a -notmatch '[\s"]') { return $a }
  49. $e = $a -replace '(\\*)"', '$1$1\"'
  50. $e = $e -replace '(\\+)$', '$1$1'
  51. return '"' + $e + '"'
  52. }
  53. # One emulator at a time, run from build/demo so "demo.d81:prog" has no drive
  54. # letter colon, and waited for so nothing else touches the image.
  55. function Invoke-Vice([string]$exe, [string[]]$argv) {
  56. $psi = [Diagnostics.ProcessStartInfo]::new()
  57. $psi.FileName = $exe
  58. $psi.WorkingDirectory = $out
  59. $psi.Arguments = ($argv | ForEach-Object { Quote-Arg $_ }) -join ' '
  60. $psi.UseShellExecute = $false
  61. $psi.RedirectStandardOutput = $true # VICE's log is noise here
  62. $psi.RedirectStandardError = $true
  63. $proc = [Diagnostics.Process]::Start($psi)
  64. $stdout = $proc.StandardOutput.ReadToEndAsync()
  65. $stderr = $proc.StandardError.ReadToEndAsync()
  66. $proc.WaitForExit()
  67. [void]$stdout.Result; [void]$stderr.Result
  68. Start-Sleep -Milliseconds 900 # let the image write settle
  69. }
  70. function Get-Cycles([int]$keys, [int]$extraSeconds) {
  71. $wall = $keys * $KeyDelay / 1000.0 + $extraSeconds
  72. return [long][Math]::Min([Math]::Max($wall * 13000000, 150000000), 2000000000)
  73. }
  74. function ConvertFrom-PetsciiText([byte[]]$bytes) {
  75. return -join ($bytes | ForEach-Object {
  76. if ($_ -eq 13) { "`n" }
  77. elseif ($_ -ge 0x41 -and $_ -le 0x5A) { [char]($_ + 0x20) }
  78. elseif ($_ -ge 0xC1 -and $_ -le 0xDA) { [char]($_ - 0x80) }
  79. else { [char]$_ } })
  80. }
  81. foreach ($name in $Programs) {
  82. $base = $name -replace '\.n8$', ''
  83. $mirror = (Get-Content -Raw (Join-Path $project "demo\$name")) -replace "`r", ""
  84. $text = $mirror.TrimEnd("`n")
  85. if ($text -cmatch '[A-Z"\\]') { throw "$name must be lowercase without quotes or backslashes (typed via -keybuf)" }
  86. Write-Host ""
  87. Write-Host "=== $name"
  88. # 1. type it into Vim on the C64
  89. $keys = "$name\n" + "y" + "i" + ($text -replace "`n", "\n") + "\x03" + ":w\n"
  90. $shot = Join-Path $out "$base-vim.png"
  91. if (Test-Path $shot) { Remove-Item $shot -Force }
  92. Write-Host " x64sc: typing $($text.Length) characters into VIM..."
  93. Invoke-Vice $x64 @("-drive8type", "1581", "-8", "demo.d81", "-autostart", "demo.d81:vim",
  94. "-autostart-warp", "-warp", "-sounddev", "dummy",
  95. "-keybuf-delay", "$KeyDelay", "-keybuf", $keys,
  96. "-limitcycles", "$(Get-Cycles $keys.Length 25)", "-exitscreenshot", $shot)
  97. # 2. read back what Vim wrote
  98. $seq = Join-Path $out "$base.seq"
  99. if (Test-Path $seq) { Remove-Item $seq -Force }
  100. & $c1541 $disk -read "$name,s" $seq 2>&1 | Out-Null
  101. if (-not (Test-Path $seq)) { throw "VIM did not write $name (see $shot)" }
  102. $saved = (ConvertFrom-PetsciiText ([IO.File]::ReadAllBytes($seq))).TrimEnd("`n")
  103. if ($saved -ne $text) { throw "$name on disk differs from demo\$name (see $shot)" }
  104. Write-Host " VIM saved $name as a SEQ file: $(([IO.File]::ReadAllBytes($seq)).Length) PETSCII bytes, identical to the mirror"
  105. # 3. check it on the C128
  106. $shot128 = Join-Path $out "$base-check.png"
  107. if (Test-Path $shot128) { Remove-Item $shot128 -Force }
  108. Write-Host " x128: N8CHECK $name ..."
  109. Invoke-Vice $x128 @("-drive8type", "1581", "-8", "demo.d81", "-autostart", "demo.d81:n8check",
  110. "-autostart-warp", "-warp", "-sounddev", "dummy",
  111. "-keybuf-delay", "$KeyDelay", "-keybuf", "$name\n",
  112. "-limitcycles", "$(Get-Cycles 10 40)", "-exitscreenshotvicii", $shot128)
  113. # 4. results
  114. $err = Join-Path $out "$base.err.txt"
  115. if (Test-Path $err) { Remove-Item $err -Force }
  116. & $c1541 $disk -read "$base.err,s" $err 2>&1 | Out-Null
  117. if (Test-Path $err) {
  118. Write-Host " $base.err:"
  119. foreach ($line in ([Text.Encoding]::ASCII.GetString([IO.File]::ReadAllBytes($err)).TrimEnd("`r") -split "`r")) {
  120. Write-Host " $line"
  121. }
  122. } else {
  123. Write-Host " no $base.err: the program has no errors"
  124. }
  125. Write-Host " screenshots: $shot, $shot128"
  126. }

Powered by TurnKey Linux.