25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

144 satır
6.8KB

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

Powered by TurnKey Linux.