diff --git a/.agents/skills/asm6502-coder/SKILL.md b/.agents/skills/asm6502-coder/SKILL.md index c359c9d0e..f308556a2 100644 --- a/.agents/skills/asm6502-coder/SKILL.md +++ b/.agents/skills/asm6502-coder/SKILL.md @@ -1,13 +1,12 @@ --- name: asm6502-coder -description: Write 6502/65C02 assembly code using 64tass syntax, for use within Prog8 programs -license: MIT -compatibility: opencode +description: Writing or understanding 6502/65C02 assembly code using 64tass syntax, for use as stand alone .asm or inline within Prog8 programs --- # 65(C)02 Assembly Coder Skill -You are writing **6502/65C02 assembly** using **64tass syntax**, in separate `*.asm` files or embedded in a Prog8 program (inside `%asm {{ }}` blocks or `asmsub` routines). Follow all rules below. +You are an expert MOS 6502 assembly development assistant. Keep responses concise and practical — prefer short, correct code examples over lengthy prose. +You are working with **6502/65C02 assembly** using **64tass syntax**, in separate `*.asm` files or embedded in a Prog8 program (inside `%asm {{ }}` blocks or `asmsub` routines). Follow all rules below. ## Assembler: 64tass Syntax ### Formatting Rules diff --git a/.agents/skills/prog8-coder/SKILL.md b/.agents/skills/prog8-coder/SKILL.md index b5766d42e..2e2d716ad 100644 --- a/.agents/skills/prog8-coder/SKILL.md +++ b/.agents/skills/prog8-coder/SKILL.md @@ -1,14 +1,12 @@ --- name: prog8-coder -description: Write Prog8 programs (6502-targeted language with 8-bit retro systems as targets) -license: MIT -compatibility: opencode +description: Writing or understanding Prog8 programs --- # Prog8 Coder Skill +You are an expert retro system development assistant, versed in the Prog8 programming language. Keep responses concise and practical — prefer short, correct code examples over lengthy prose. You are working with **Prog8** source code (`.p8` files) or its Intermediate Representation (`.p8ir` files). Prog8 targets 8-bit systems (C64, CX16, C128, PET32) with the 6502 CPU, plus a `virtual` target for testing. - Follow ALL the rules below carefully. ## General & Setup diff --git a/codeCore/src/prog8/code/target/zp/PETZeropage.kt b/codeCore/src/prog8/code/target/zp/PETZeropage.kt index 6538d2461..81a3da525 100644 --- a/codeCore/src/prog8/code/target/zp/PETZeropage.kt +++ b/codeCore/src/prog8/code/target/zp/PETZeropage.kt @@ -32,7 +32,10 @@ class PETZeropage(options: CompilationOptions) : Zeropage(options) { } ZeropageType.FLOATSAFE, ZeropageType.BASICSAFE -> { - free.addAll(0xb1u..0xbau) // TODO more? + // Only scratch register area is safe for transient use. + // $b5 and $ba are clobbered by PET BASIC/Kernal calls like CHROUT ($ffd2). + // User variables requiring persistent storage must NOT be placed here. + free.addAll(listOf(0xb1u, 0xb2u, 0xb3u, 0xb4u, 0xb6u, 0xb7u, 0xb8u, 0xb9u)) } ZeropageType.DONTUSE -> { free.clear() // don't use zeropage at all @@ -83,4 +86,4 @@ class PETZeropage(options: CompilationOptions) : Zeropage(options) { allocatedVariables["cx16.r12r13sl"] = VarAllocation((base+6*4).toUInt(), DataType.LONG, 4) allocatedVariables["cx16.r14r15sl"] = VarAllocation((base+7*4).toUInt(), DataType.LONG, 4) } -} \ No newline at end of file +} diff --git a/codeCore/test/prog8tests/codecore/TestZeropageFreeList.kt b/codeCore/test/prog8tests/codecore/TestZeropageFreeList.kt index 82b01cacd..3f2119f56 100644 --- a/codeCore/test/prog8tests/codecore/TestZeropageFreeList.kt +++ b/codeCore/test/prog8tests/codecore/TestZeropageFreeList.kt @@ -256,15 +256,13 @@ class TestZeropageFreeList: FunSpec({ zp.availableBytes() shouldBe 0 } - test("BASICSAFE should have minimal locations") { + test("BASICSAFE should have minimal or no free locations") { val options = createOptions(PETTarget(), ZeropageType.BASICSAFE) val zp = PETZeropage(options) - // BASICSAFE has minimal locations (0xB1-0xBA per code, minus scratch locations) - zp.free.isNotEmpty().shouldBeTrue() - // After scratch removal, some locations in 0xb1-0xba range should still be free - // Just verify the free list is small but non-empty - zp.free.size shouldBeGreaterThan 0 + // BASICSAFE only includes scratch register addresses ($b1-$b4, $b6-$b9). + // After scratch removal, no free addresses remain for user variables. + // (scratch registers are still available for transient use) zp.free.size shouldBeLessThan 20 verifyScratchLocationsReserved(zp) @@ -628,12 +626,12 @@ class TestZeropageFreeList: FunSpec({ } } - test("BASICSAFE - minimal locations around 0xB1-0xBA") { + test("BASICSAFE - no free locations after scratch removal") { val options = createOptions(PETTarget(), ZeropageType.BASICSAFE) val zp = PETZeropage(options) - // BASICSAFE has minimal locations (0xB1-0xBA minus scratch) - zp.free.size shouldBeGreaterThan 0 + // BASICSAFE includes only scratch register addresses ($b1-$b4, $b6-$b9). + // After removing scratch registers from the pool, no free addresses remain. zp.free.size shouldBeLessThan 15 } diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index e08e1afe8..d05e82cc2 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -371,9 +371,9 @@ class TestCompilerOnExamplesPET32: FunSpec({ val onlyPET32 = cartesianProduct( listOf( - ExampleSizes("boingball", pet32SizeOptimized=1514, pet32SizeUnoptimized=1570), + ExampleSizes("boingball", pet32SizeOptimized=1547, pet32SizeUnoptimized=1603), ExampleSizes("petswirl", pet32SizeOptimized=895, pet32SizeUnoptimized=961), - ExampleSizes("music", pet32SizeOptimized=888, pet32SizeUnoptimized=925), + ExampleSizes("music", pet32SizeOptimized=892, pet32SizeUnoptimized=931), ), listOf(false, true) ) diff --git a/examples/customtarget/targetconfigs/tinypet.properties b/examples/customtarget/targetconfigs/tinypet.properties index 8d25e708e..35ca011a0 100644 --- a/examples/customtarget/targetconfigs/tinypet.properties +++ b/examples/customtarget/targetconfigs/tinypet.properties @@ -27,7 +27,7 @@ zp_scratch_w2 = $b8 # zero or more zeropage address ranges (inclusive). zp_fullsafe = $00-$8c,$90-$96,$9c,$9d,$9f-$a6,$ab-$ff zp_kernalsafe = $00-$8c,$90-$96,$9c,$9d,$9f-$a6,$ab-$ff -zp_basicsafe = $b3-$ba +zp_basicsafe = $b3-$b4,$b6-$b9 # the start of the 32 bytes used by the R0-R15 virtual registers. Can be in Zeropage or elsewhere. virtual_registers = $7fe0