You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 line
2.3KB

  1. <#
  2. .SYNOPSIS
  3. Copy work saved on the Commodore back into the repository (on-Commodore workflow).
  4. .DESCRIPTION
  5. After you SAVE the program onto the transfer disk image (or a real disk imaged back to a
  6. .d64), this script reads it with c1541:
  7. - BASIC projects: reads the PRG and detokenizes it with petcat into src/main.bas.
  8. - Other projects: copies the files in resolved.onCommodore.returnFiles into the repo.
  9. Review the change with "git diff" before committing.
  10. .EXAMPLE
  11. pwsh -File tools/from-commodore.ps1
  12. pwsh -File tools/from-commodore.ps1 -Image "D:\disks\my work.d64"
  13. #>
  14. [CmdletBinding()]
  15. param([string]$Image)
  16. . (Join-Path $PSScriptRoot 'lib.ps1')
  17. try {
  18. $project = Get-ProjectConfig
  19. $oc = $project.resolved.onCommodore
  20. if (-not $oc) { throw 'This project does not use the on-Commodore workflow.' }
  21. $c1541 = Get-ToolPath $project 'c1541'
  22. $img = if ($Image) { (Resolve-Path -LiteralPath $Image).ProviderPath } else { Get-RepoPath $oc.image }
  23. if (-not (Test-Path -LiteralPath $img)) { throw "Disk image not found: $img (run tools/to-commodore.ps1 first, then SAVE your work onto it)." }
  24. $stage = Get-RepoPath 'build/transfer/returned'
  25. New-Item -ItemType Directory -Force -Path $stage | Out-Null
  26. if ($oc.kind -eq 'basic') {
  27. $petcat = Get-ToolPath $project 'petcat'
  28. $prg = Join-Path $stage "$($oc.programName).prg"
  29. if (Test-Path -LiteralPath $prg) { Remove-Item -LiteralPath $prg }
  30. Invoke-Tool $c1541 @('-attach', $img, '-read', $oc.programName, $prg)
  31. if (-not (Test-Path -LiteralPath $prg)) { throw "c1541 did not find '$($oc.programName)' on $img." }
  32. Invoke-Tool $petcat @('-nh', "-$($oc.dialect)", '-f', '-o', (Get-RepoPath $oc.source), '--', $prg)
  33. Write-Host "Updated $($oc.source) from the Commodore."
  34. }
  35. foreach ($f in @($oc.returnFiles)) {
  36. if (-not $f) { continue }
  37. $name = if ($f.type -eq 'seq') { "$($f.name),s" } else { $f.name }
  38. Invoke-Tool $c1541 @('-attach', $img, '-read', $name, (Get-RepoPath $f.dest))
  39. Write-Host "Copied $name -> $($f.dest)"
  40. }
  41. Write-Host 'Review with: git diff'
  42. } catch [MissingToolException] {
  43. Write-Host $_.Exception.Message -ForegroundColor Yellow
  44. exit 2
  45. } catch {
  46. Write-Host "FAILED: $($_.Exception.Message)" -ForegroundColor Red
  47. exit 1
  48. }

Powered by TurnKey Linux.