|
- <#
- .SYNOPSIS
- One command for building, running, testing, and inspecting C64/C128 programs.
-
- .DESCRIPTION
- c64 doctor check that cc65 and VICE are installed
- c64 new <name> [-Template c|asm|basic]
- create projects/<name> from templates/
- c64 build <project|file> build to <dir>/build/<name>.prg (+ .lbl labels, .map)
- c64 run <project|file|prg|d64> [-Monitor] [-Warp] [-Keys "text\n"]
- build if needed, then autostart in VICE
- c64 test <project|file|prg> [-Expect TEXT ...] [-Until label] [-AfterJiffies n] [-Keys ...]
- headless run; prints the screen and PASS/FAIL; exit code 0/1
- c64 mon "<cmd>" ["<cmd>" ...] [-Stay]
- send commands to the VICE remote monitor started by run -Monitor
- c64 screen <test-dir> re-decode screen text from a test dump
-
- <project> is a directory with c64project.json. <file> is a single .c, .s, .asm, or .bas.
- Exit codes: 0 success/pass, 1 test failure, 2 usage or tool error.
- #>
- param(
- [Parameter(Position = 0)][string]$Verb = "help",
- [Parameter(Position = 1, ValueFromRemainingArguments = $true)][object[]]$Rest = @()
- )
-
- $ErrorActionPreference = "Stop"
- Import-Module (Join-Path $PSScriptRoot "C64Tools.psm1") -Force
-
- function Split-C64Args([object[]]$Items) {
- # Turns "-Name value" / "-Switch" pairs into a hashtable for splatting; bare words are positional.
- $named = @{}; $positional = @()
- $i = 0
- while ($i -lt $Items.Count) {
- $item = "$($Items[$i])"
- if ($item -match '^-([A-Za-z][A-Za-z0-9]*)$') {
- $key = $Matches[1]
- $next = if ($i + 1 -lt $Items.Count) { "$($Items[$i + 1])" } else { $null }
- if ($null -ne $next -and $next -notmatch '^-[A-Za-z]') {
- if ($named.ContainsKey($key)) { $named[$key] = @($named[$key]) + $next } else { $named[$key] = $next }
- $i += 2
- } else {
- $named[$key] = $true; $i += 1
- }
- } else {
- $positional += $item; $i += 1
- }
- }
- return @{ Named = $named; Positional = $positional }
- }
-
- function Use-Array($named, [string[]]$keys) {
- foreach ($k in $keys) { if ($named.ContainsKey($k)) { $named[$k] = [string[]]@($named[$k]) } }
- }
-
- try {
- $parsed = Split-C64Args $Rest
- $n = $parsed.Named
- $pos = $parsed.Positional
- switch ($Verb.ToLowerInvariant()) {
- "doctor" {
- $rows = Test-C64Environment
- $rows | Format-Table Tool, Status, Purpose, Path -AutoSize | Out-String -Width 200 | Write-Host
- $missing = @($rows | Where-Object { $_.Status -eq "missing" -and $_.Purpose -match "required" })
- if ($missing) { Write-Host "missing required tools: $($missing.Tool -join ', ')" -ForegroundColor Red; exit 2 }
- Write-Host "toolchain ready" -ForegroundColor Green
- }
- "new" {
- if (-not $pos) { throw "usage: c64 new <name> [-Template c|asm|basic] [-Destination dir]" }
- $n.Name = $pos[0]
- [void](New-C64Project @n)
- }
- "build" {
- if (-not $pos) { throw "usage: c64 build <project-dir|source-file>" }
- foreach ($p in $pos) { [void](Invoke-C64Build -Path $p) }
- }
- "run" {
- if (-not $pos) { throw "usage: c64 run <project|file|prg|d64> [-Monitor] [-Warp] [-Keys text]" }
- Use-Array $n @("ViceArgs")
- [void](Start-C64 -Path $pos[0] @n)
- }
- "test" {
- if (-not $pos) { throw "usage: c64 test <project|file|prg> [-Expect text] [-Until label] [-AfterJiffies n]" }
- Use-Array $n @("Expect", "ViceArgs")
- $failed = 0
- foreach ($p in $pos) {
- $r = Invoke-C64Test -Path $p @n
- if (-not $r.passed) { $failed++ }
- }
- if ($pos.Count -gt 1) { Write-Host "$($pos.Count - $failed)/$($pos.Count) passed" }
- exit $(if ($failed) { 1 } else { 0 })
- }
- "mon" {
- if (-not $pos) { throw "usage: c64 mon `"<monitor command>`" [...] [-Port 6510] [-Stay]" }
- Send-C64Monitor -Command $pos @n | ForEach-Object { Write-Output $_ }
- }
- "screen" {
- if (-not $pos) { throw "usage: c64 screen <test-output-dir>" }
- (Read-C64Screen -DumpDir $pos[0]).Text | Write-Output
- }
- { $_ -in "help", "-h", "--help", "/?" } {
- Get-Help $PSCommandPath -Detailed | Out-String | Write-Host
- }
- default { throw "unknown command '$Verb'. Try: c64 help" }
- }
- } catch {
- Write-Host "error: $($_.Exception.Message)" -ForegroundColor Red
- exit 2
- }
|