No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

71 líneas
2.3KB

  1. # build-ml.ps1 - assemble vml.s with cc65 and generate vml.c, the Power C unit
  2. # that carries the machine code as a byte array plus its C wrappers.
  3. #
  4. # powershell -NoProfile -File build-ml.ps1
  5. #
  6. # Run it whenever vml.s or vmlwrap.c changes, then build.ps1 as usual.
  7. # vml.c is generated: edit vml.s (the code) or vmlwrap.c (the C side).
  8. #
  9. # The code is assembled for $C000. At start-up mlinit() calls highmem($C000) so
  10. # Power C keeps below it, and copies the array up there. Entry addresses come
  11. # from ld65's label file and are written into vml.c as #defines.
  12. $ErrorActionPreference = "Stop"
  13. $here = $PSScriptRoot
  14. $ca65 = (Get-Command ca65 -ErrorAction SilentlyContinue).Source
  15. if (-not $ca65) { throw "ca65 not found on PATH (cc65 bin folder)" }
  16. $ld65 = Join-Path (Split-Path $ca65) "ld65.exe"
  17. $tmp = Join-Path $env:TEMP "vml-build"
  18. New-Item -ItemType Directory -Force -Path $tmp | Out-Null
  19. $cfg = Join-Path $tmp "vml.cfg"
  20. @"
  21. MEMORY { M: start = `$C000, size = `$0400, file = "%O"; }
  22. SEGMENTS { CODE: load = M, type = ro; }
  23. "@ | Set-Content $cfg -Encoding ascii
  24. $obj = Join-Path $tmp "vml.o"
  25. $lbl = Join-Path $tmp "vml.lbl"
  26. $out = Join-Path $here "vml.bin"
  27. & $ca65 (Join-Path $here "vml.s") -o $obj
  28. if ($LASTEXITCODE) { throw "ca65 failed" }
  29. & $ld65 -C $cfg -o $out -Ln $lbl $obj
  30. if ($LASTEXITCODE) { throw "ld65 failed" }
  31. # entry points: "al 00C000 .scrn"
  32. $defs = @()
  33. foreach ($ln in (Get-Content $lbl)) {
  34. if ($ln -match '^al\s+([0-9A-Fa-f]+)\s+\.(scrn|row|bmove|ladj|kpop)$') {
  35. $defs += ("#define ML{0} 0x{1}" -f $matches[2].ToUpper(), $matches[1].Substring(2).ToLower())
  36. }
  37. }
  38. if ($defs.Count -ne 5) { throw "expected 5 entry labels in $lbl, got $($defs.Count)" }
  39. $b = [IO.File]::ReadAllBytes($out)
  40. $rows = @()
  41. for ($i = 0; $i -lt $b.Length; $i += 12) {
  42. $n = [Math]::Min(12, $b.Length - $i)
  43. $rows += " " + (($b[$i..($i + $n - 1)] | ForEach-Object { "$_" }) -join ", ")
  44. }
  45. $arr = $rows -join ",`n"
  46. $wrap = Get-Content (Join-Path $here "vmlwrap.c") -Raw
  47. @"
  48. /* vml.c - GENERATED by build-ml.ps1 from vml.s and vmlwrap.c. Do not edit.
  49. *
  50. * The machine code helpers as a byte array. mlinit() copies them to `$C000.
  51. */
  52. $($defs -join "`n")
  53. #define MLSIZE $($b.Length)
  54. char mlcode[$($b.Length)] = {
  55. $arr
  56. };
  57. $wrap
  58. "@ | Set-Content (Join-Path $here "vml.c") -Encoding ascii
  59. Write-Host ("vml.bin {0} bytes -> vml.c ({1})" -f $b.Length, ($defs -join '; '))

Powered by TurnKey Linux.