Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

142 rindas
6.7KB

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

Powered by TurnKey Linux.