# pc-run.ps1 - link given object files with the ORIGINAL Power C linker (copy of POWERc.d81), # optionally run the program and type keys at it. The original disk image is never written. # pc-run.ps1 -Obj a.o,b.o -Name prog -Dir outdir [-Keys 'text\n'] [-Data file1,file2] param([string[]]$Obj, [string]$Name = "prog", [string]$Dir, [string]$Keys = "", [string[]]$Data = @(), [string[]]$LibObj = @(), [int]$Delay = 900, [int]$Tail = 8, [int]$Settle = 15, [string]$Shot = "run.png") $ErrorActionPreference = "Continue" $vice = "C:\Program Files\GTK3VICE-3.10-win64\bin" $x64 = Join-Path $vice "x64sc.exe"; $c1541 = Join-Path $vice "c1541.exe" $Obj = @($Obj | % { $_ -split "," } | % { (Resolve-Path $_).Path }) $LibObj = @($LibObj | ? { $_ } | % { $_ -split "," } | % { (Resolve-Path $_).Path }) $Data = @($Data | ? { $_ } | % { $_ -split "," } | % { (Resolve-Path $_).Path }) New-Item -ItemType Directory -Force -Path $Dir | Out-Null $Dir = (Resolve-Path $Dir).Path $here = $PSScriptRoot $base = (Resolve-Path (Join-Path $here "..\..\POWERc.d81")).Path $wd = Join-Path $here "..\work"; New-Item -ItemType Directory -Force -Path $wd | Out-Null; $wd = (Resolve-Path $wd).Path Set-Location $wd $img = "r.d81"; Copy-Item $base $img -Force $names = @() foreach ($o in $Obj) { $n = [IO.Path]::GetFileNameWithoutExtension($o); $names += $n $null = & $c1541 $img -delete "$n.o" 2>$null $null = & $c1541 $img -write $o "$n.o,s" 2>$null } foreach ($l in $LibObj) { $ln = [IO.Path]::GetFileName($l); $null = & $c1541 $img -delete $ln 2>$null; $null = & $c1541 $img -write $l "$ln,s" 2>$null } foreach ($d in $Data) { $null = & $c1541 $img -write $d ([IO.Path]::GetFileName($d) + ",s") 2>$null } 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 = "link -s\n" foreach ($n in $names) { $kb += "$n.o\n" } $kb += "^\n\n$Name\n" + ("\n" * $Tail) $haveKeys = $Keys -ne "" if ($haveKeys) { $kb += "bye\n" + ("\n" * 6) + 'load"' + $Name + '",8,1' + "\n" + ("\n" * 10) + "run\n" + $Keys } $shotp = Join-Path $Dir $Shot; if (Test-Path $shotp) { Remove-Item $shotp -Force } $cycles = [long](($kb.Length * $Delay / 1000.0 + $Settle) * 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", $shotp) $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.WorkingDirectory = $wd; $psi.FileName = $x64; $psi.Arguments = ($argv | % { Quote-Arg $_ }) -join ' '; $psi.UseShellExecute = $false $p = [Diagnostics.Process]::Start($psi); $p.WaitForExit(); Start-Sleep -Milliseconds 900 $prg = Join-Path $Dir "$Name.prg"; if (Test-Path $prg) { Remove-Item $prg -Force } & $c1541 $img -read $Name $prg 2>$null | Out-Null if (Test-Path $prg) { Write-Host ("linked {0}: {1} bytes" -f $Name, (Get-Item $prg).Length) } else { Write-Host "LINK FAILED" }