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

119 строки
5.2KB

  1. <#
  2. .SYNOPSIS
  3. One command for building, running, testing, and inspecting C64/C128 programs.
  4. .DESCRIPTION
  5. c64 doctor check that cc65 and VICE are installed
  6. c64 new <name> [-Template c|asm|basic]
  7. create projects/<name> from templates/
  8. c64 build <project|file> build to <dir>/build/<name>.prg (+ .lbl labels, .map)
  9. c64 run <project|file|prg|d64> [-Monitor] [-Warp] [-Keys "text\n"]
  10. build if needed, then autostart in VICE
  11. c64 test <project|file|prg> [-Expect TEXT ...] [-Until label] [-AfterJiffies n] [-Keys ...]
  12. headless run; prints the screen and PASS/FAIL; exit code 0/1
  13. c64 mon "<cmd>" ["<cmd>" ...] [-Stay]
  14. send commands to the VICE remote monitor started by run -Monitor
  15. c64 screen <test-dir> re-decode screen text from a test dump
  16. <project> is a directory with c64project.json. <file> is a single .c, .s, .asm, or .bas.
  17. Exit codes: 0 success/pass, 1 test failure, 2 usage or tool error.
  18. #>
  19. param(
  20. [Parameter(Position = 0)][string]$Verb = "help",
  21. [Parameter(Position = 1, ValueFromRemainingArguments = $true)][object[]]$Rest = @()
  22. )
  23. $ErrorActionPreference = "Stop"
  24. Import-Module (Join-Path $PSScriptRoot "C64Tools.psm1") -Force
  25. function Split-C64Args([object[]]$Items) {
  26. # Turns "-Name value" / "-Switch" pairs into a hashtable for splatting; bare words are positional.
  27. $named = @{}; $positional = @()
  28. $i = 0
  29. while ($i -lt $Items.Count) {
  30. $item = "$($Items[$i])"
  31. if ($item -match '^-([A-Za-z][A-Za-z0-9]*)$') {
  32. $key = $Matches[1]
  33. $next = if ($i + 1 -lt $Items.Count) { "$($Items[$i + 1])" } else { $null }
  34. # -ViceArgs always takes the next token verbatim ("-ViceArgs '-refresh 1'").
  35. if ($null -ne $next -and ($key -eq "ViceArgs" -or $next -notmatch '^-[A-Za-z]')) {
  36. if ($named.ContainsKey($key)) { $named[$key] = @($named[$key]) + $next } else { $named[$key] = $next }
  37. $i += 2
  38. } else {
  39. $named[$key] = $true; $i += 1
  40. }
  41. } else {
  42. $positional += $item; $i += 1
  43. }
  44. }
  45. return @{ Named = $named; Positional = $positional }
  46. }
  47. function Use-Array($named, [string[]]$keys) {
  48. foreach ($k in $keys) { if ($named.ContainsKey($k)) { $named[$k] = [string[]]@($named[$k]) } }
  49. if ($named.ContainsKey("ViceArgs")) {
  50. $named["ViceArgs"] = [string[]]@($named["ViceArgs"] | ForEach-Object { $_ -split '\s+' } | Where-Object { $_ })
  51. }
  52. }
  53. try {
  54. $parsed = Split-C64Args $Rest
  55. $n = $parsed.Named
  56. $pos = $parsed.Positional
  57. switch ($Verb.ToLowerInvariant()) {
  58. "doctor" {
  59. $rows = Test-C64Environment
  60. $rows | Format-Table Tool, Status, Purpose, Path -AutoSize | Out-String -Width 200 | Write-Host
  61. $missing = @($rows | Where-Object { $_.Status -eq "missing" -and $_.Purpose -match "required" })
  62. if ($missing) { Write-Host "missing required tools: $($missing.Tool -join ', ')" -ForegroundColor Red; exit 2 }
  63. Write-Host "toolchain ready" -ForegroundColor Green
  64. }
  65. "new" {
  66. if (-not $pos) { throw "usage: c64 new <name> [-Template c|asm|basic] [-Destination dir]" }
  67. $n.Name = $pos[0]
  68. [void](New-C64Project @n)
  69. }
  70. "build" {
  71. if (-not $pos) { throw "usage: c64 build <project-dir|source-file>" }
  72. foreach ($p in $pos) { [void](Invoke-C64Build -Path $p) }
  73. }
  74. "run" {
  75. if (-not $pos) { throw "usage: c64 run <project|file|prg|d64> [-Monitor] [-Warp] [-Keys text]" }
  76. Use-Array $n @("ViceArgs")
  77. [void](Start-C64 -Path $pos[0] @n)
  78. }
  79. "test" {
  80. if (-not $pos) { throw "usage: c64 test <project|file|prg> [-Expect text] [-Until label] [-AfterJiffies n]" }
  81. Use-Array $n @("Expect", "ViceArgs")
  82. $failed = 0
  83. foreach ($p in $pos) {
  84. try {
  85. $r = Invoke-C64Test -Path $p @n
  86. if (-not $r.passed) { $failed++ }
  87. } catch {
  88. # One broken target must not hide the results of the others.
  89. Write-Host "FAIL $p $($_.Exception.Message)" -ForegroundColor Red
  90. $failed++
  91. }
  92. }
  93. if ($pos.Count -gt 1) { Write-Host "$($pos.Count - $failed)/$($pos.Count) passed" }
  94. exit $(if ($failed) { 1 } else { 0 })
  95. }
  96. "mon" {
  97. if (-not $pos) { throw "usage: c64 mon `"<monitor command>`" [...] [-Port 6510] [-Stay]" }
  98. Send-C64Monitor -Command $pos @n | ForEach-Object { Write-Output $_ }
  99. }
  100. "screen" {
  101. if (-not $pos) { throw "usage: c64 screen <test-output-dir>" }
  102. (Read-C64Screen -DumpDir $pos[0]).Text | Write-Output
  103. }
  104. { $_ -in "help", "-h", "--help", "/?" } {
  105. Get-Help $PSCommandPath -Detailed | Out-String | Write-Host
  106. }
  107. default { throw "unknown command '$Verb'. Try: c64 help" }
  108. }
  109. } catch {
  110. Write-Host "error: $($_.Exception.Message)" -ForegroundColor Red
  111. exit 2
  112. }

Powered by TurnKey Linux.