# E01-S01: build the minimal native-mode C128 platform proof. [CmdletBinding()] param() $ErrorActionPreference = "Stop" $project = Split-Path $PSScriptRoot -Parent $build = Join-Path $project "build" $source = Join-Path $project "src\platform\minimal.s" $config = Join-Path $project "cfg\minimal-c128.cfg" $object = Join-Path $build "minimal.o" $program = Join-Path $build "minimal.prg" $map = Join-Path $build "minimal.map" $labels = Join-Path $build "minimal.lbl" $debug = Join-Path $build "minimal.dbg" $ca65 = (Get-Command ca65 -ErrorAction Stop).Source $ld65 = (Get-Command ld65 -ErrorAction Stop).Source New-Item -ItemType Directory -Force -Path $build | Out-Null foreach ($path in @($object, $program, $map, $labels, $debug)) { if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path -Force } } & $ca65 --cpu 6502 --debug-info -o $object $source if ($LASTEXITCODE -ne 0) { throw "ca65 failed with exit code $LASTEXITCODE" } & $ld65 -C $config -o $program -m $map -Ln $labels --dbgfile $debug $object if ($LASTEXITCODE -ne 0) { throw "ld65 failed with exit code $LASTEXITCODE" } $bytes = [IO.File]::ReadAllBytes($program) if ($bytes.Length -lt 16) { throw "minimal.prg is unexpectedly short" } if ($bytes[0] -ne 0x01 -or $bytes[1] -ne 0x1C) { throw "minimal.prg load address is not `$1C01" } # The first BASIC line must be SYS 7181, whose target is $1C0D. $expectedHeader = [byte[]](0x0B,0x1C,0x0A,0x00,0x9E,0x37,0x31,0x38,0x31,0x00,0x00,0x00) for ($i = 0; $i -lt $expectedHeader.Length; $i++) { if ($bytes[$i + 2] -ne $expectedHeader[$i]) { throw ("BASIC header differs at file offset {0}: expected {1:X2}, got {2:X2}" -f ($i + 2), $expectedHeader[$i], $bytes[$i + 2]) } } $labelText = Get-Content -Raw -LiteralPath $labels $expectedLabels = @{ minimal_entry = "001C0D" minimal_done = "001C24" minimal_result = "001C3E" } foreach ($item in $expectedLabels.GetEnumerator()) { $pattern = "(?im)^al\s+" + $item.Value + "\s+\." + [regex]::Escape($item.Key) + "\s*$" if ($labelText -notmatch $pattern) { throw ("linker label {0} did not resolve to `${1}" -f $item.Key, $item.Value.Substring(2)) } } Write-Host ("built {0} ({1} bytes)" -f $program, $bytes.Length) Write-Host ("map {0}" -f $map) Write-Host ("labels {0}" -f $labels)