|
- # pc-compile.ps1 - compile C sources with the ORIGINAL Power C in VICE, on a throwaway
- # copy of reference/POWERc.d81 (the original image is never written).
- # pc-compile.ps1 -Src a.c,b.c -Out outdir [-Link name] [-Run keys]
- # Produces outdir\a.o ... ; with -Link, links all objects (+libs) into outdir\<name>.prg
- param([string[]]$Src, [string]$Out, [string]$Link = "", [int]$Delay = 700, [int]$Pad = 20)
- $ErrorActionPreference = "Continue"
- $vice = "C:\Program Files\GTK3VICE-3.10-win64\bin"
- $x64 = Join-Path $vice "x64sc.exe"; $c1541 = Join-Path $vice "c1541.exe"
- $Src = @($Src | % { $_ -split "," } | % { (Resolve-Path $_).Path })
- New-Item -ItemType Directory -Force -Path $Out | Out-Null
- $Out = (Resolve-Path $Out).Path
- $here = $PSScriptRoot
- $base = Join-Path $here "..\..\POWERc.d81"
- $wd = Join-Path $here "..\work"
- New-Item -ItemType Directory -Force -Path $wd, $Out | Out-Null
- Set-Location $wd
- $img = "t.d81"
- Copy-Item $base $img -Force
-
- function ConvertTo-Petscii([string]$in, [string]$out) {
- $bytes = [IO.File]::ReadAllBytes($in); $o = New-Object System.Collections.Generic.List[byte]
- foreach ($b in $bytes) {
- if ($b -eq 13) { continue }
- if ($b -eq 10) { $o.Add([byte]13); continue }
- if ($b -ge 0x61 -and $b -le 0x7A) { $o.Add([byte]($b - 0x20)); continue }
- if ($b -ge 0x41 -and $b -le 0x5A) { $o.Add([byte]($b + 0x80)); continue }
- if ($b -ge 0x7B -and $b -le 0x7F) { $o.Add([byte]($b + 0x60)); continue }
- $o.Add([byte]$b)
- }
- [IO.File]::WriteAllBytes($out, $o.ToArray())
- }
- function Quote-Arg([string]$a) {
- if ($a -ne "" -and $a -notmatch '[\s"]') { return $a }
- $e = $a -replace '(\\*)"', '$1$1\"'; $e = $e -replace '(\\+)$', '$1$1'; return '"' + $e + '"'
- }
- $kb = ""; $names = @()
- foreach ($s in $Src) {
- $n = [IO.Path]::GetFileNameWithoutExtension($s); $names += $n
- $pet = Join-Path $wd "$n.pet"
- ConvertTo-Petscii $s $pet
- $null = & $c1541 $img -delete "$n.c" "$n.o" 2>$null
- $null = & $c1541 $img -write $pet "$n.c,s" 2>$null
- $kb += "cc $n.c\n" + ("\n" * 3) + ("\n" * $Pad)
- }
- if ($Link -ne "") {
- $kb += "link -s\n"
- foreach ($n in $names) { $kb += "$n.o\n" }
- $kb += "^\n\n$Link\n" + ("\n" * 8)
- }
- $shot = "last.png"; if (Test-Path $shot) { Remove-Item $shot -Force }
- $cycles = [long](($kb.Length * $Delay / 1000.0 + 20) * 13000000); if ($cycles -gt 2000000000) { $cycles = 2000000000 }
- $argv = @("-8", $img, "-autostart", "${img}:shell", "-autostart-warp", "-warp", "-sounddev", "dummy",
- "-keybuf-delay", "$Delay", "-keybuf", $kb, "-limitcycles", "$cycles", "-exitscreenshot", $shot)
- $psi = New-Object System.Diagnostics.ProcessStartInfo
- $psi.WorkingDirectory = (Get-Location).Path; $psi.FileName = $x64; $psi.Arguments = ($argv | % { Quote-Arg $_ }) -join ' '; $psi.UseShellExecute = $false
- $p = [Diagnostics.Process]::Start($psi); $p.WaitForExit(); Start-Sleep -Milliseconds 900
- foreach ($n in $names) {
- & $c1541 $img -read "$n.o,s" (Join-Path $Out "$n.o") 2>$null | Out-Null
- if (Test-Path (Join-Path $Out "$n.o")) { Write-Host "ok $n.o" } else { Write-Host "FAIL $n.o (see work\last.png)" }
- }
- if ($Link -ne "") { & $c1541 $img -read $Link (Join-Path $Out "$Link.prg") 2>$null | Out-Null }
|