diff --git a/.claude/skills/c64-workflow/SKILL.md b/.claude/skills/c64-workflow/SKILL.md index 23b316b..a6cfd70 100644 --- a/.claude/skills/c64-workflow/SKILL.md +++ b/.claude/skills/c64-workflow/SKILL.md @@ -125,7 +125,12 @@ with the stored value) if you need a bare-VICE check. | `ram.bin` | 64KB RAM, banking ignored (2-byte load-address header, then $0000-$FFFF) | | `io.bin` | $D000-$DFFF as the CPU sees I/O: VIC, SID, color RAM, CIAs (2-byte header) | | `monitor.log` | VICE monitor output. The `.;xxxx` line holds PC/A/X/Y at the trigger | -| `result.json` | `passed`, `reason`, `code`, `pc`, `missing`, `screen` | +| `vice.log`, `vice.stdout.log`, `vice.stderr.log` | VICE startup and runtime diagnostics, when emitted | +| `result.json` | `passed`, `reason`, `code`, `pc`, `missing`, `screen`, `emulatorExitCode` | + +On a native C128, `-Expect` checks the 40-column VIC-II screen. The 80-column +VDC screen is outside the text decoder's coverage. A native 40-column smoke +test runs in `tools/regress.ps1`. Inspect a variable: find it in `build/.lbl`, then read `ram.bin` at `2 + address`. For example, with pwsh: diff --git a/AGENTS.md b/AGENTS.md index 57a6200..cc6aecc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -43,7 +43,7 @@ c64 mon "r" "m .label .label+8" # talk to a run started with -Monito - **Free zero page** while BASIC and the Kernal are live: `$02`, `$FB-$FE`. cc65 C programs own `$02-$1B` for their runtime. - **Keep the suite green.** After changing `tools/`, `templates/`, `lib/`, or an example, - run `pwsh tools/regress.ps1` (about 2 minutes, 17 cases). + run `pwsh tools/regress.ps1` (about 2 minutes, including a native C128 smoke test). - **Respect sub-project rules.** `newLang/` has its own `AGENTS.md`; read it before changing anything there. diff --git a/README.md b/README.md index 71b32c5..6a3613a 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,16 @@ waits for a trigger: - **`-AfterJiffies `**: after n Kernal IRQs, for programs you don't want to modify. At the trigger it saves RAM, I/O, the decoded text screen, and a screenshot to -`build/test//`, then checks `-Expect` strings. BASIC errors fail immediately -with the error name and line number. +`build/test//`, then checks `-Expect` strings against the 40-column VIC-II +screen. On a native C128, use the 40-column display for text assertions. The runner +does not decode the 80-column VDC screen. The regression suite includes a native +C128 build and 40-column text assertion. C64 BASIC errors fail immediately with +the error name and line number. + +If VICE exits before the trigger, check `result.json` for `emulatorExitCode` and +look in `vice.log`, `vice.stdout.log`, and `vice.stderr.log` for startup details. +The redirected output files may be empty on Windows. Run VICE from a Windows +session that allows desktop applications if it exits immediately inside a sandbox. ## Sources diff --git a/tools/C64Tools.psm1 b/tools/C64Tools.psm1 index 27dd942..62348d0 100644 --- a/tools/C64Tools.psm1 +++ b/tools/C64Tools.psm1 @@ -480,7 +480,8 @@ function Invoke-C64Test { } elseif ($AfterJiffies -gt 0) { $mode = "jiffies" $tick = if ($TickAddress) { $TickAddress.TrimStart('$') } elseif ($t.Machine -eq "c128") { "fa65" } else { "ea31" } - $trigger = "break exec $tick`nignore 1 $AfterJiffies" + # The VICE monitor reads numbers as hex: pass the count in hex. + $trigger = "break exec $tick`nignore 1 {0:x}" -f $AfterJiffies } $onHit = @( @@ -504,11 +505,15 @@ function Invoke-C64Test { Set-Content -Encoding ascii -LiteralPath (Join-Path $out "setup.mon") -Value $setup $log = Join-Path $out "monitor.log" + $viceLog = Join-Path $out "vice.log" + $stdout = Join-Path $out "vice.stdout.log" + $stderr = Join-Path $out "vice.stderr.log" $shot = Join-Path $out "screenshot.png" # -refreshonbreak: warp mode skips rendering frames, so without it the exit # screenshot can be several frames older than the RAM dump. $argv = @("-default", "-sounddev", "dummy", "-minimized", "-warp", "-refreshonbreak", "-limitcycles", "$MaxCycles", + "-logfile", ('"' + $viceLog + '"'), "-moncommands", ('"' + (Join-Path $out "setup.mon") + '"'), "-monlog", "-monlogname", ('"' + $log + '"'), "-exitscreenshot", ('"' + $shot + '"')) @@ -522,25 +527,41 @@ function Invoke-C64Test { $emu = Get-C64Tool (Get-C64Emulator $t.Machine) Write-Host ("> {0} {1}" -f (Split-Path $emu -Leaf), ($argv -join ' ')) -ForegroundColor DarkGray $sw = [Diagnostics.Stopwatch]::StartNew() - $proc = Start-Process -FilePath $emu -ArgumentList $argv -PassThru $done = Join-Path $out "done.bin" - while (-not $proc.HasExited -and -not (Test-Path -LiteralPath $done) -and $sw.Elapsed.TotalSeconds -lt $TimeoutSeconds) { - Start-Sleep -Milliseconds 100 + $proc = $null + $launchError = $null + try { + $proc = Start-Process -FilePath $emu -ArgumentList $argv -PassThru -WindowStyle Hidden ` + -RedirectStandardOutput $stdout -RedirectStandardError $stderr -ErrorAction Stop + } catch { + $launchError = $_.Exception.Message } - $captured = Test-Path -LiteralPath $done - if (-not $proc.HasExited) { - # A clean close flushes the monitor log and writes the exit screenshot. - [void]$proc.CloseMainWindow() - if (-not $proc.WaitForExit(10000)) { $proc.Kill(); $proc.WaitForExit() } + $timedOut = $false + if ($proc) { + while (-not $proc.HasExited -and -not (Test-Path -LiteralPath $done) -and $sw.Elapsed.TotalSeconds -lt $TimeoutSeconds) { + Start-Sleep -Milliseconds 100 + } + $timedOut = -not $proc.HasExited -and -not (Test-Path -LiteralPath $done) + # Let monitor playback finish its quit command and flush the logs and screenshot. + if (-not $timedOut) { [void]$proc.WaitForExit(10000) } + if (-not $proc.HasExited) { + [void]$proc.CloseMainWindow() + if (-not $proc.WaitForExit(10000)) { $proc.Kill(); $proc.WaitForExit() } + } } + $captured = Test-Path -LiteralPath $done $seconds = [math]::Round($sw.Elapsed.TotalSeconds, 1) $result = [ordered]@{ program = $t.Program; mode = $mode; passed = $false; reason = ""; code = $null - seconds = $seconds; screen = $null; missing = @(); pc = $null } + seconds = $seconds; screen = $null; missing = @(); pc = $null + emulatorExitCode = $(if ($proc) { $proc.ExitCode }) } $reasons = @() - if (-not $captured) { - $why = if ($sw.Elapsed.TotalSeconds -ge $TimeoutSeconds) { "wall-clock timeout ($TimeoutSeconds s)" } else { "emulator stopped after $MaxCycles cycles" } - $reasons += "trigger never fired: $why" + if ($launchError) { + $reasons += "could not start VICE: $launchError" + } elseif ($timedOut) { + $reasons += "trigger never fired: wall-clock timeout ($TimeoutSeconds s)" + } elseif (-not $captured) { + $reasons += "trigger never fired: VICE exited with code $($result.emulatorExitCode); see vice.log and vice.stdout.log / vice.stderr.log" } else { $screen = Read-C64Screen -DumpDir $out Set-Content -LiteralPath (Join-Path $out "screen.txt") -Value $screen.Text -Encoding utf8 diff --git a/tools/regress.ps1 b/tools/regress.ps1 index 6e09545..7de0a35 100644 --- a/tools/regress.ps1 +++ b/tools/regress.ps1 @@ -21,6 +21,7 @@ $cases = @( @{ Path = "$scratch\t-c"; New = "c" }, @{ Path = "$scratch\t-asm"; New = "asm" }, @{ Path = "$scratch\t-basic"; New = "basic" }, + @{ Path = "$scratch\t-c128"; New = "c"; Machine = "c128" }, @{ Path = "skirmish-game" }, @{ Path = "samples/kernal-os-skeleton" }, @{ Path = "samples/kernal-os-skeleton"; Keys = "help\n"; AfterJiffies = 700; Expect = @("ABOUT EXIT") }, @@ -39,12 +40,21 @@ $cases = @( $results = foreach ($c in $cases) { $label = if ($c.New) { "template $($c.New)" } else { $c.Path } + if ($c.Machine) { $label += " ($($c.Machine) native)" } if ($c.ContainsKey("Keys")) { $label += " (keys)" } try { if ($c.New) { [void](New-C64Project -Name (Split-Path $c.Path -Leaf) -Template $c.New -Destination $c.Path) } + if ($c.Machine) { + $manifest = Join-Path $c.Path "c64project.json" + $project = Get-Content -Raw -LiteralPath $manifest | ConvertFrom-Json + $project.machine = $c.Machine + $project.disk = $false + $project | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath $manifest + } $testArgs = @{ Path = $c.Path } foreach ($k in "Until", "AfterJiffies", "Keys", "Disk", "Expect") { if ($c.ContainsKey($k)) { $testArgs[$k] = $c[$k] } } $r = Invoke-C64Test @testArgs 6>$null + if ($c.Machine -and $r.screen) { Write-Host $r.screen.TrimEnd() } [pscustomobject]@{ Case = $label; Passed = $r.passed; Reason = $r.reason; Seconds = $r.seconds } } catch { [pscustomobject]@{ Case = $label; Passed = $false; Reason = $_.Exception.Message; Seconds = 0 }