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.

65 line
2.3KB

  1. # E01-S01: build the minimal native-mode C128 platform proof.
  2. [CmdletBinding()]
  3. param()
  4. $ErrorActionPreference = "Stop"
  5. $project = Split-Path $PSScriptRoot -Parent
  6. $build = Join-Path $project "build"
  7. $source = Join-Path $project "src\platform\minimal.s"
  8. $config = Join-Path $project "cfg\minimal-c128.cfg"
  9. $object = Join-Path $build "minimal.o"
  10. $program = Join-Path $build "minimal.prg"
  11. $map = Join-Path $build "minimal.map"
  12. $labels = Join-Path $build "minimal.lbl"
  13. $debug = Join-Path $build "minimal.dbg"
  14. $ca65 = (Get-Command ca65 -ErrorAction Stop).Source
  15. $ld65 = (Get-Command ld65 -ErrorAction Stop).Source
  16. New-Item -ItemType Directory -Force -Path $build | Out-Null
  17. foreach ($path in @($object, $program, $map, $labels, $debug)) {
  18. if (Test-Path -LiteralPath $path) {
  19. Remove-Item -LiteralPath $path -Force
  20. }
  21. }
  22. & $ca65 --cpu 6502 --debug-info -o $object $source
  23. if ($LASTEXITCODE -ne 0) { throw "ca65 failed with exit code $LASTEXITCODE" }
  24. & $ld65 -C $config -o $program -m $map -Ln $labels --dbgfile $debug $object
  25. if ($LASTEXITCODE -ne 0) { throw "ld65 failed with exit code $LASTEXITCODE" }
  26. $bytes = [IO.File]::ReadAllBytes($program)
  27. if ($bytes.Length -lt 16) { throw "minimal.prg is unexpectedly short" }
  28. if ($bytes[0] -ne 0x01 -or $bytes[1] -ne 0x1C) {
  29. throw "minimal.prg load address is not `$1C01"
  30. }
  31. # The first BASIC line must be SYS 7181, whose target is $1C0D.
  32. $expectedHeader = [byte[]](0x0B,0x1C,0x0A,0x00,0x9E,0x37,0x31,0x38,0x31,0x00,0x00,0x00)
  33. for ($i = 0; $i -lt $expectedHeader.Length; $i++) {
  34. if ($bytes[$i + 2] -ne $expectedHeader[$i]) {
  35. throw ("BASIC header differs at file offset {0}: expected {1:X2}, got {2:X2}" -f
  36. ($i + 2), $expectedHeader[$i], $bytes[$i + 2])
  37. }
  38. }
  39. $labelText = Get-Content -Raw -LiteralPath $labels
  40. $expectedLabels = @{
  41. minimal_entry = "001C0D"
  42. minimal_done = "001C24"
  43. minimal_result = "001C3E"
  44. }
  45. foreach ($item in $expectedLabels.GetEnumerator()) {
  46. $pattern = "(?im)^al\s+" + $item.Value + "\s+\." + [regex]::Escape($item.Key) + "\s*$"
  47. if ($labelText -notmatch $pattern) {
  48. throw ("linker label {0} did not resolve to `${1}" -f $item.Key, $item.Value.Substring(2))
  49. }
  50. }
  51. Write-Host ("built {0} ({1} bytes)" -f $program, $bytes.Length)
  52. Write-Host ("map {0}" -f $map)
  53. Write-Host ("labels {0}" -f $labels)

Powered by TurnKey Linux.