|
- # build-ml.ps1 - assemble vrow.s with cc65 and turn the result into vml.c, the
- # Power C unit that holds the machine code as a byte array and calls it.
- #
- # powershell -NoProfile -File build-ml.ps1
- #
- # Run it whenever vrow.s changes, then build.ps1 as usual. vml.c is generated:
- # edit vrow.s, not vml.c.
-
- $ErrorActionPreference = "Stop"
- $here = $PSScriptRoot
- $bin = "D:\Development\Commodore\cc65-snapshot-win32\bin"
- $ca65 = Join-Path $bin "ca65.exe"
- $ld65 = Join-Path $bin "ld65.exe"
- $addr = 0xC020 # where the routine lives; the parameter block is at $C000
-
- $cfg = Join-Path $env:TEMP "vrow.cfg"
- @"
- MEMORY { M: start = `$C020, size = `$0100, file = "%O"; }
- SEGMENTS { CODE: load = M, type = ro; }
- "@ | Set-Content $cfg -Encoding ascii
-
- $obj = Join-Path $env:TEMP "vrow.o"
- $out = Join-Path $here "vrow.bin"
- & $ca65 (Join-Path $here "vrow.s") -o $obj
- if ($LASTEXITCODE) { throw "ca65 failed" }
- & $ld65 -C $cfg -o $out $obj
- if ($LASTEXITCODE) { throw "ld65 failed" }
-
- $b = [IO.File]::ReadAllBytes($out)
- $rows = @()
- for ($i = 0; $i -lt $b.Length; $i += 12) {
- $n = [Math]::Min(12, $b.Length - $i)
- $rows += " " + (($b[$i..($i + $n - 1)] | ForEach-Object { "$_" }) -join ", ")
- }
- $arr = $rows -join ",`n"
-
- @"
- /* vml.c - GENERATED by build-ml.ps1 from vrow.s. Do not edit by hand.
- *
- * The machine code row painter, kept as a byte array and called in place
- * through sys(). It is position independent; its parameters go through zero
- * page scratch `$22-`$28, which Power C leaves to ML routines.
- */
-
- char mlcode[$($b.Length)] = {
- $arr
- };
-
- /* nothing to install: the code runs where the array sits */
- mlinit()
- {
- return 0;
- }
-
- /* paint the screen row at address dst: len bytes from src, cursor at column cur
- (255 = none), rev = 128 for an all reverse row */
- mlrow(src, len, dst, cur, rev)
- unsigned src, dst;
- int len, cur, rev;
- {
- char *p;
- char a, x, y;
-
- p = (char *) 0x22;
- p[0] = src & 255;
- p[1] = src >> 8;
- p[2] = len;
- p[3] = dst & 255;
- p[4] = dst >> 8;
- p[5] = cur;
- p[6] = rev;
- a = 0;
- x = 0;
- y = 0;
- sys((unsigned) mlcode, &a, &x, &y); /* c64 form: no bank argument */
- return 0;
- }
- "@ | Set-Content (Join-Path $here "vml.c") -Encoding utf8
-
- Write-Host ("vrow.bin {0} bytes -> vml.c" -f $b.Length)
|