Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

32 строки
1.3KB

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

Powered by TurnKey Linux.