2024-09-08 14:03:57 +00:00
|
|
|
package prog8tests.compiler
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2022-01-15 11:29:29 +00:00
|
|
|
import com.github.michaelbull.result.expectError
|
2022-01-14 22:16:05 +00:00
|
|
|
import com.github.michaelbull.result.getOrElse
|
|
|
|
import com.github.michaelbull.result.onFailure
|
|
|
|
import io.kotest.assertions.fail
|
2021-11-07 23:16:58 +00:00
|
|
|
import io.kotest.assertions.throwables.shouldThrow
|
|
|
|
import io.kotest.assertions.withClue
|
|
|
|
import io.kotest.core.spec.style.FunSpec
|
|
|
|
import io.kotest.matchers.collections.shouldBeIn
|
|
|
|
import io.kotest.matchers.collections.shouldNotBeIn
|
2021-11-20 23:48:23 +00:00
|
|
|
import io.kotest.matchers.comparables.shouldBeGreaterThan
|
2021-11-07 23:16:58 +00:00
|
|
|
import io.kotest.matchers.shouldBe
|
2022-01-15 12:49:49 +00:00
|
|
|
import io.kotest.matchers.shouldNotBe
|
2022-03-10 22:08:41 +00:00
|
|
|
import prog8.code.core.*
|
2022-03-11 19:35:25 +00:00
|
|
|
import prog8.code.target.C64Target
|
|
|
|
import prog8.code.target.Cx16Target
|
|
|
|
import prog8.code.target.c64.C64Zeropage
|
|
|
|
import prog8.code.target.cx16.CX16Zeropage
|
2022-01-18 20:21:49 +00:00
|
|
|
import prog8tests.helpers.DummyCompilationTarget
|
2021-10-29 14:46:56 +00:00
|
|
|
import prog8tests.helpers.ErrorReporterForTests
|
2021-06-01 19:21:33 +00:00
|
|
|
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
class TestAbstractZeropage: FunSpec({
|
2021-10-29 21:46:51 +00:00
|
|
|
|
|
|
|
class DummyZeropage(options: CompilationOptions) : Zeropage(options) {
|
2021-11-20 23:48:23 +00:00
|
|
|
override val SCRATCH_B1 = 0x10u
|
|
|
|
override val SCRATCH_REG = 0x11u
|
|
|
|
override val SCRATCH_W1 = 0x20u
|
|
|
|
override val SCRATCH_W2 = 0x30u
|
2021-10-29 21:46:51 +00:00
|
|
|
|
|
|
|
init {
|
2021-11-20 23:48:23 +00:00
|
|
|
free.addAll(0u..255u)
|
2021-10-29 21:46:51 +00:00
|
|
|
|
|
|
|
removeReservedFromFreePool()
|
2023-11-02 22:45:10 +00:00
|
|
|
retainAllowed()
|
2021-10-29 21:46:51 +00:00
|
|
|
}
|
2022-07-28 16:55:47 +00:00
|
|
|
|
|
|
|
override fun allocateCx16VirtualRegisters() {
|
|
|
|
}
|
2021-10-29 21:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testAbstractZeropage") {
|
|
|
|
val zp = DummyZeropage(
|
|
|
|
CompilationOptions(
|
|
|
|
OutputType.RAW,
|
2022-02-26 14:36:22 +00:00
|
|
|
CbmPrgLauncherType.NONE,
|
2021-11-07 23:16:58 +00:00
|
|
|
ZeropageType.FULL,
|
2021-11-20 23:48:23 +00:00
|
|
|
listOf((0x50u..0x5fu)),
|
2023-11-02 22:45:10 +00:00
|
|
|
CompilationOptions.AllZeropageAllowed,
|
2022-03-13 11:52:12 +00:00
|
|
|
floats = false,
|
|
|
|
noSysInit = false,
|
|
|
|
compTarget = DummyCompilationTarget,
|
|
|
|
loadAddress = 999u
|
2021-11-07 23:16:58 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
zp.free.size shouldBe 256-6-16
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2021-10-29 21:46:51 +00:00
|
|
|
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
class TestC64Zeropage: FunSpec({
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
val errors = ErrorReporterForTests()
|
2022-02-06 20:29:06 +00:00
|
|
|
val c64target = C64Target()
|
2021-11-07 23:16:58 +00:00
|
|
|
|
|
|
|
test("testNames") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed,
|
2022-03-13 11:52:12 +00:00
|
|
|
floats = false,
|
|
|
|
noSysInit = false,
|
|
|
|
compTarget = c64target, loadAddress = 999u
|
|
|
|
))
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2024-09-04 19:49:47 +00:00
|
|
|
var result = zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-01-14 22:16:05 +00:00
|
|
|
result.onFailure { fail(it.toString()) }
|
2024-09-04 19:49:47 +00:00
|
|
|
result = zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-01-14 22:16:05 +00:00
|
|
|
result.onFailure { fail(it.toString()) }
|
2024-09-04 19:49:47 +00:00
|
|
|
result = zp.allocate("varname", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-01-14 22:16:05 +00:00
|
|
|
result.onFailure { fail(it.toString()) }
|
2024-09-04 19:49:47 +00:00
|
|
|
shouldThrow<IllegalArgumentException> { zp.allocate("varname", DataTypeFull.forDt(BaseDataType.UBYTE),null, null, errors) }
|
|
|
|
result = zp.allocate("varname2", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-01-14 22:16:05 +00:00
|
|
|
result.onFailure { fail(it.toString()) }
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testZpFloatEnable") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2024-09-04 19:49:47 +00:00
|
|
|
var result = zp.allocate("", DataTypeFull.forDt(BaseDataType.FLOAT), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "should be allocation error due to disabled floats" }
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.DONTUSE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2024-09-04 19:49:47 +00:00
|
|
|
result = zp2.allocate("", DataTypeFull.forDt(BaseDataType.FLOAT), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "should be allocation error due to disabled ZP use" }
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2024-09-04 19:49:47 +00:00
|
|
|
zp3.allocate("", DataTypeFull.forDt(BaseDataType.FLOAT), null, null, errors)
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testZpModesWithFloats") {
|
2023-11-02 22:45:10 +00:00
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2021-11-07 23:16:58 +00:00
|
|
|
shouldThrow<InternalCompilerException> {
|
2023-11-02 22:45:10 +00:00
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
2021-11-07 23:16:58 +00:00
|
|
|
shouldThrow<InternalCompilerException> {
|
2023-11-02 22:45:10 +00:00
|
|
|
C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testZpDontuse") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.DONTUSE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2021-06-01 19:21:33 +00:00
|
|
|
println(zp.free)
|
2021-11-07 23:16:58 +00:00
|
|
|
zp.availableBytes() shouldBe 0
|
2024-09-04 19:49:47 +00:00
|
|
|
val result = zp.allocate("", DataTypeFull.forDt(BaseDataType.BYTE), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "expected error due to disabled ZP use" }
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testFreeSpacesBytes") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2023-09-28 23:15:54 +00:00
|
|
|
zp1.availableBytes() shouldBe 17
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2023-09-28 23:15:54 +00:00
|
|
|
zp2.availableBytes() shouldBe 87
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2023-09-28 23:15:54 +00:00
|
|
|
zp3.availableBytes() shouldBe 96
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2022-07-28 16:55:47 +00:00
|
|
|
zp4.availableBytes() shouldBe 207
|
2024-09-04 19:49:47 +00:00
|
|
|
zp4.allocate("test", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-07-28 16:55:47 +00:00
|
|
|
zp4.availableBytes() shouldBe 206
|
2024-09-04 19:49:47 +00:00
|
|
|
zp4.allocate("test2", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-07-28 16:55:47 +00:00
|
|
|
zp4.availableBytes() shouldBe 205
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testReservedSpace") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2022-07-28 16:55:47 +00:00
|
|
|
zp1.availableBytes() shouldBe 207
|
|
|
|
4u shouldNotBeIn zp1.free
|
|
|
|
35u shouldNotBeIn zp1.free
|
2021-11-20 23:48:23 +00:00
|
|
|
50u shouldBeIn zp1.free
|
|
|
|
100u shouldBeIn zp1.free
|
|
|
|
49u shouldBeIn zp1.free
|
|
|
|
101u shouldBeIn zp1.free
|
|
|
|
200u shouldBeIn zp1.free
|
|
|
|
255u shouldBeIn zp1.free
|
|
|
|
199u shouldBeIn zp1.free
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, listOf(50u .. 100u, 200u..255u), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2022-07-28 16:55:47 +00:00
|
|
|
zp2.availableBytes() shouldBe 107
|
|
|
|
4u shouldNotBeIn zp2.free
|
|
|
|
35u shouldNotBeIn zp2.free
|
2021-11-20 23:48:23 +00:00
|
|
|
50u shouldNotBeIn zp2.free
|
|
|
|
100u shouldNotBeIn zp2.free
|
|
|
|
49u shouldBeIn zp2.free
|
|
|
|
101u shouldBeIn zp2.free
|
|
|
|
200u shouldNotBeIn zp2.free
|
|
|
|
255u shouldNotBeIn zp2.free
|
|
|
|
199u shouldBeIn zp2.free
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, listOf(50u .. 100u, 200u..255u), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2022-07-28 16:55:47 +00:00
|
|
|
zp2.availableBytes() shouldBe 107
|
|
|
|
4u shouldBeIn zp3.free
|
|
|
|
35u shouldNotBeIn zp3.free
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testBasicsafeAllocation") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2023-09-28 23:15:54 +00:00
|
|
|
zp.availableBytes() shouldBe 17
|
2021-11-07 23:16:58 +00:00
|
|
|
zp.hasByteAvailable() shouldBe true
|
|
|
|
zp.hasWordAvailable() shouldBe true
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2024-09-04 19:49:47 +00:00
|
|
|
var result = zp.allocate("", DataTypeFull.forDt(BaseDataType.FLOAT), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "expect allocation error: in regular zp there aren't 5 sequential bytes free" }
|
2021-06-01 19:21:33 +00:00
|
|
|
|
|
|
|
for (i in 0 until zp.availableBytes()) {
|
2024-09-04 19:49:47 +00:00
|
|
|
val alloc = zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-01-15 16:05:34 +00:00
|
|
|
alloc.getOrElse { throw it }
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
2021-11-07 23:16:58 +00:00
|
|
|
zp.availableBytes() shouldBe 0
|
|
|
|
zp.hasByteAvailable() shouldBe false
|
|
|
|
zp.hasWordAvailable() shouldBe false
|
2024-09-04 19:49:47 +00:00
|
|
|
result = zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "expected allocation error" }
|
2024-09-04 19:49:47 +00:00
|
|
|
result = zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "expected allocation error" }
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testFullAllocation") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2022-07-28 16:55:47 +00:00
|
|
|
zp.availableBytes() shouldBe 207
|
2021-11-07 23:16:58 +00:00
|
|
|
zp.hasByteAvailable() shouldBe true
|
|
|
|
zp.hasWordAvailable() shouldBe true
|
2024-09-04 19:49:47 +00:00
|
|
|
var result = zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
val loc = result.getOrElse { throw it } .address
|
2021-11-20 23:48:23 +00:00
|
|
|
loc shouldBeGreaterThan 3u
|
2021-11-07 23:16:58 +00:00
|
|
|
loc shouldNotBeIn zp.free
|
2021-06-01 19:21:33 +00:00
|
|
|
val num = zp.availableBytes() / 2
|
|
|
|
|
2021-12-21 18:08:33 +00:00
|
|
|
for(i in 0..num-3) {
|
2024-09-04 19:49:47 +00:00
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors)
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
2021-12-21 18:08:33 +00:00
|
|
|
zp.availableBytes() shouldBe 5
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2022-01-15 11:29:29 +00:00
|
|
|
// can't allocate because no more sequential bytes, only fragmented
|
2024-09-04 19:49:47 +00:00
|
|
|
result = zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "should give allocation error" }
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2021-12-21 18:08:33 +00:00
|
|
|
for(i in 0..4) {
|
2024-09-04 19:49:47 +00:00
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
zp.availableBytes() shouldBe 0
|
|
|
|
zp.hasByteAvailable() shouldBe false
|
|
|
|
zp.hasWordAvailable() shouldBe false
|
2024-09-04 19:49:47 +00:00
|
|
|
result = zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-01-15 11:29:29 +00:00
|
|
|
result.expectError { "should give allocation error" }
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testEfficientAllocation") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, c64target, 999u))
|
2023-09-28 23:15:54 +00:00
|
|
|
zp.availableBytes() shouldBe 17
|
2024-09-04 19:49:47 +00:00
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.WORD), null, null, errors).getOrElse{throw it}.address shouldBe 0x04u
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors).getOrElse{throw it}.address shouldBe 0x06u
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors).getOrElse{throw it}.address shouldBe 0x0au
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors).getOrElse{throw it}.address shouldBe 0x9bu
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors).getOrElse{throw it}.address shouldBe 0x9eu
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors).getOrElse{throw it}.address shouldBe 0xb0u
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UWORD), null, null, errors).getOrElse{throw it}.address shouldBe 0xbeu
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors).getOrElse{throw it}.address shouldBe 0x0eu
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors).getOrElse{throw it}.address shouldBe 0x92u
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors).getOrElse{throw it}.address shouldBe 0x96u
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors).getOrElse{throw it}.address shouldBe 0xa6u
|
|
|
|
zp.allocate("", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors).getOrElse{throw it}.address shouldBe 0xf9u
|
2021-11-07 23:16:58 +00:00
|
|
|
zp.availableBytes() shouldBe 0
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testReservedLocations") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, c64target, 999u))
|
2021-11-07 23:16:58 +00:00
|
|
|
withClue("zp _B1 and _REG must be next to each other to create a word") {
|
2021-11-20 23:48:23 +00:00
|
|
|
zp.SCRATCH_B1 + 1u shouldBe zp.SCRATCH_REG
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
2021-11-07 23:16:58 +00:00
|
|
|
})
|
2021-06-01 19:21:33 +00:00
|
|
|
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
class TestCx16Zeropage: FunSpec({
|
|
|
|
val errors = ErrorReporterForTests()
|
2022-02-06 20:29:06 +00:00
|
|
|
val cx16target = Cx16Target()
|
2021-06-01 19:21:33 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testReservedLocations") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, cx16target, 999u))
|
2021-11-07 23:16:58 +00:00
|
|
|
withClue("zp _B1 and _REG must be next to each other to create a word") {
|
2021-11-20 23:48:23 +00:00
|
|
|
zp.SCRATCH_B1 + 1u shouldBe zp.SCRATCH_REG
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testFreeSpacesBytes") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, true, false, cx16target, 999u))
|
2021-11-07 23:16:58 +00:00
|
|
|
zp1.availableBytes() shouldBe 88
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp2 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, cx16target, 999u))
|
2021-11-07 23:16:58 +00:00
|
|
|
zp2.availableBytes() shouldBe 175
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp3 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, cx16target, 999u))
|
2021-11-07 23:16:58 +00:00
|
|
|
zp3.availableBytes() shouldBe 216
|
2024-09-04 19:49:47 +00:00
|
|
|
zp3.allocate("test", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2021-11-07 23:16:58 +00:00
|
|
|
zp3.availableBytes() shouldBe 215
|
2024-09-04 19:49:47 +00:00
|
|
|
zp3.allocate("test2", DataTypeFull.forDt(BaseDataType.UBYTE), null, null, errors)
|
2021-11-07 23:16:58 +00:00
|
|
|
zp3.availableBytes() shouldBe 214
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testReservedSpace") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, cx16target, 999u))
|
2021-11-07 23:16:58 +00:00
|
|
|
zp1.availableBytes() shouldBe 216
|
2021-11-20 23:48:23 +00:00
|
|
|
0x22u shouldBeIn zp1.free
|
|
|
|
0x80u shouldBeIn zp1.free
|
|
|
|
0xffu shouldBeIn zp1.free
|
|
|
|
0x02u shouldNotBeIn zp1.free
|
|
|
|
0x21u shouldNotBeIn zp1.free
|
2021-06-01 19:21:33 +00:00
|
|
|
}
|
2022-01-15 12:49:49 +00:00
|
|
|
|
|
|
|
test("preallocated zp vars") {
|
2023-11-02 22:45:10 +00:00
|
|
|
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, false, cx16target, 999u))
|
2023-02-15 23:33:37 +00:00
|
|
|
zp1.allocatedVariables["test"] shouldBe null
|
|
|
|
zp1.allocatedVariables["cx16.r0"] shouldNotBe null
|
|
|
|
zp1.allocatedVariables["cx16.r15"] shouldNotBe null
|
|
|
|
zp1.allocatedVariables["cx16.r0L"] shouldNotBe null
|
|
|
|
zp1.allocatedVariables["cx16.r15L"] shouldNotBe null
|
|
|
|
zp1.allocatedVariables["cx16.r0sH"] shouldNotBe null
|
|
|
|
zp1.allocatedVariables["cx16.r15sH"] shouldNotBe null
|
2022-01-15 12:49:49 +00:00
|
|
|
}
|
2021-11-07 23:16:58 +00:00
|
|
|
})
|