|
- # to-petscii.ps1 - convert an ASCII C source file into the PETSCII form
- # Power C expects on a C64 disk: uppercase letters shifted into $C1-$DA,
- # lowercase into $41-$5A, { } into $DB/$DD, and CR ($0D) line endings.
- #
- # Usage:
- # powershell -NoProfile -File to-petscii.ps1 vim.c vim.pet
-
- param(
- [Parameter(Mandatory = $true)][string]$InFile,
- [Parameter(Mandatory = $true)][string]$OutFile
- )
-
- $bytes = [System.IO.File]::ReadAllBytes($InFile)
- $start = 0
- if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
- $start = 3 # skip a UTF-8 BOM if an editor added one
- }
-
- $out = New-Object System.Collections.Generic.List[byte]
- for ($i = $start; $i -lt $bytes.Length; $i++) {
- $b = $bytes[$i]
- if ($b -eq 13) { continue } # CRLF -> single CR
- if ($b -eq 10) { $out.Add([byte]13); continue }
- if ($b -ge 0x61 -and $b -le 0x7A) { $out.Add([byte]($b - 0x20)); continue } # a-z
- if ($b -ge 0x41 -and $b -le 0x5A) { $out.Add([byte]($b + 0x80)); continue } # A-Z
- if ($b -ge 0x7B -and $b -le 0x7F) { $out.Add([byte]($b + 0x60)); continue } # { | } ~ -> $DB-$DF
- $out.Add([byte]$b)
- }
-
- [System.IO.File]::WriteAllBytes($OutFile, $out.ToArray())
- Write-Host ("wrote {0} PETSCII bytes to {1}" -f $out.Count, $OutFile)
|