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.

109 satır
4.7KB

  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. if ($null -ne $next -and $next -notmatch '^-[A-Za-z]') {
  35. if ($named.ContainsKey($key)) { $named[$key] = @($named[$key]) + $next } else { $named[$key] = $next }
  36. $i += 2
  37. } else {
  38. $named[$key] = $true; $i += 1
  39. }
  40. } else {
  41. $positional += $item; $i += 1
  42. }
  43. }
  44. return @{ Named = $named; Positional = $positional }
  45. }
  46. function Use-Array($named, [string[]]$keys) {
  47. foreach ($k in $keys) { if ($named.ContainsKey($k)) { $named[$k] = [string[]]@($named[$k]) } }
  48. }
  49. try {
  50. $parsed = Split-C64Args $Rest
  51. $n = $parsed.Named
  52. $pos = $parsed.Positional
  53. switch ($Verb.ToLowerInvariant()) {
  54. "doctor" {
  55. $rows = Test-C64Environment
  56. $rows | Format-Table Tool, Status, Purpose, Path -AutoSize | Out-String -Width 200 | Write-Host
  57. $missing = @($rows | Where-Object { $_.Status -eq "missing" -and $_.Purpose -match "required" })
  58. if ($missing) { Write-Host "missing required tools: $($missing.Tool -join ', ')" -ForegroundColor Red; exit 2 }
  59. Write-Host "toolchain ready" -ForegroundColor Green
  60. }
  61. "new" {
  62. if (-not $pos) { throw "usage: c64 new <name> [-Template c|asm|basic] [-Destination dir]" }
  63. $n.Name = $pos[0]
  64. [void](New-C64Project @n)
  65. }
  66. "build" {
  67. if (-not $pos) { throw "usage: c64 build <project-dir|source-file>" }
  68. foreach ($p in $pos) { [void](Invoke-C64Build -Path $p) }
  69. }
  70. "run" {
  71. if (-not $pos) { throw "usage: c64 run <project|file|prg|d64> [-Monitor] [-Warp] [-Keys text]" }
  72. Use-Array $n @("ViceArgs")
  73. [void](Start-C64 -Path $pos[0] @n)
  74. }
  75. "test" {
  76. if (-not $pos) { throw "usage: c64 test <project|file|prg> [-Expect text] [-Until label] [-AfterJiffies n]" }
  77. Use-Array $n @("Expect", "ViceArgs")
  78. $failed = 0
  79. foreach ($p in $pos) {
  80. $r = Invoke-C64Test -Path $p @n
  81. if (-not $r.passed) { $failed++ }
  82. }
  83. if ($pos.Count -gt 1) { Write-Host "$($pos.Count - $failed)/$($pos.Count) passed" }
  84. exit $(if ($failed) { 1 } else { 0 })
  85. }
  86. "mon" {
  87. if (-not $pos) { throw "usage: c64 mon `"<monitor command>`" [...] [-Port 6510] [-Stay]" }
  88. Send-C64Monitor -Command $pos @n | ForEach-Object { Write-Output $_ }
  89. }
  90. "screen" {
  91. if (-not $pos) { throw "usage: c64 screen <test-output-dir>" }
  92. (Read-C64Screen -DumpDir $pos[0]).Text | Write-Output
  93. }
  94. { $_ -in "help", "-h", "--help", "/?" } {
  95. Get-Help $PSCommandPath -Detailed | Out-String | Write-Host
  96. }
  97. default { throw "unknown command '$Verb'. Try: c64 help" }
  98. }
  99. } catch {
  100. Write-Host "error: $($_.Exception.Message)" -ForegroundColor Red
  101. exit 2
  102. }

Powered by TurnKey Linux.