<# .SYNOPSIS Copy work saved on the Commodore back into the repository (on-Commodore workflow). .DESCRIPTION After you SAVE the program onto the transfer disk image (or a real disk imaged back to a .d64), this script reads it with c1541: - BASIC projects: reads the PRG and detokenizes it with petcat into src/main.bas. - Other projects: copies the files in resolved.onCommodore.returnFiles into the repo. Review the change with "git diff" before committing. .EXAMPLE pwsh -File tools/from-commodore.ps1 pwsh -File tools/from-commodore.ps1 -Image "D:\disks\my work.d64" #> [CmdletBinding()] param([string]$Image) . (Join-Path $PSScriptRoot 'lib.ps1') try { $project = Get-ProjectConfig $oc = $project.resolved.onCommodore if (-not $oc) { throw 'This project does not use the on-Commodore workflow.' } $c1541 = Get-ToolPath $project 'c1541' $img = if ($Image) { (Resolve-Path -LiteralPath $Image).ProviderPath } else { Get-RepoPath $oc.image } if (-not (Test-Path -LiteralPath $img)) { throw "Disk image not found: $img (run tools/to-commodore.ps1 first, then SAVE your work onto it)." } $stage = Get-RepoPath 'build/transfer/returned' New-Item -ItemType Directory -Force -Path $stage | Out-Null if ($oc.kind -eq 'basic') { $petcat = Get-ToolPath $project 'petcat' $prg = Join-Path $stage "$($oc.programName).prg" if (Test-Path -LiteralPath $prg) { Remove-Item -LiteralPath $prg } Invoke-Tool $c1541 @('-attach', $img, '-read', $oc.programName, $prg) if (-not (Test-Path -LiteralPath $prg)) { throw "c1541 did not find '$($oc.programName)' on $img." } Invoke-Tool $petcat @('-nh', "-$($oc.dialect)", '-f', '-o', (Get-RepoPath $oc.source), '--', $prg) Write-Host "Updated $($oc.source) from the Commodore." } foreach ($f in @($oc.returnFiles)) { if (-not $f) { continue } $name = if ($f.type -eq 'seq') { "$($f.name),s" } else { $f.name } Invoke-Tool $c1541 @('-attach', $img, '-read', $name, (Get-RepoPath $f.dest)) Write-Host "Copied $name -> $($f.dest)" } Write-Host 'Review with: git diff' } catch [MissingToolException] { Write-Host $_.Exception.Message -ForegroundColor Yellow exit 2 } catch { Write-Host "FAILED: $($_.Exception.Message)" -ForegroundColor Red exit 1 }