1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-03 19:31:02 +00:00

Add constants for segment bounds

This commit is contained in:
Karol Stasiak 2019-09-02 23:22:07 +02:00
parent b3ca130299
commit 1f8ece007b
5 changed files with 53 additions and 4 deletions

View File

@ -22,6 +22,8 @@
* [Literals](lang/literals.md)
* [Predefined constants](lang/predefined_constants.md)
* [List of text encodings and escape sequences](lang/text.md)
* [Operators reference](lang/operators.md)

View File

@ -0,0 +1,19 @@
[< back to index](../doc_index.md)
# Predefined constants
* `byte nullchar` the null terminator for strings in the default encoding, equivalent to `""z[0]`
* `null$ nullptr` the invalid pointer value; the value of the `NULLPTR` feature
* `bool true`, `bool false` boolean constants
* `pointer segment.N.start` the value of `segment_N_start` from the platform definition
* `pointer segment.N.end` the value of `segment_N_end` from the platform definition
* `pointer segment.N.heapstart` the address of the first byte in the `N` segment that was not automatically allocated
* `word segment.N.length` the number of byte locations between `segment_N_start` and `segment_N_end`, inclusive
* `byte segment.N.bank` the value of `segment_N_bank` from the platform definition

View File

@ -439,18 +439,35 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
val __zeropage_usage = UnexpandedConstant("__zeropage_usage", 1)
addThing(ConstantThing("__zeropage_usage", __zeropage_usage, b), None)
def addUnexpandedWordConstant(name: String): Unit = {
val c = UnexpandedConstant(name, 2)
addThing(ConstantThing(name, c, w), None)
addThing(ConstantThing(name + ".hi", c.hiByte, b), None)
addThing(ConstantThing(name + ".lo", c.loByte, b), None)
}
def addUnexpandedByteConstant(name: String): Unit = {
val c = UnexpandedConstant(name, 1)
addThing(ConstantThing(name, c, b), None)
}
def addUnexpandedPointerConstant(name: String): Unit = {
val c = UnexpandedConstant(name, 2)
addThing(ConstantThing(name, c, p), None)
addThing(ConstantThing(name + ".hi", c.hiByte, b), None)
addThing(ConstantThing(name + ".lo", c.loByte, b), None)
}
addUnexpandedWordConstant("__rwdata_start")
addUnexpandedWordConstant("__rwdata_end")
addUnexpandedPointerConstant("__rwdata_start")
addUnexpandedPointerConstant("__rwdata_end")
if (options.platform.ramInitialValuesBank.isDefined) {
addUnexpandedWordConstant("__rwdata_init_start")
addUnexpandedWordConstant("__rwdata_init_end")
addUnexpandedPointerConstant("__rwdata_init_start")
addUnexpandedPointerConstant("__rwdata_init_end")
addUnexpandedWordConstant("__rwdata_size")
}
for(segment <- options.platform.bankNumbers.keys) {
addUnexpandedPointerConstant(s"segment.$segment.start")
addUnexpandedPointerConstant(s"segment.$segment.heapstart")
addUnexpandedPointerConstant(s"segment.$segment.end")
addUnexpandedWordConstant(s"segment.$segment.length")
addUnexpandedByteConstant(s"segment.$segment.bank")
}
addThing(ConstantThing("$0000", NumericConstant(0, 2), p), None)
addThing(FlagBooleanType("set_carry",
BranchingOpcodeMapping(Opcode.BCS, IfFlagSet(ZFlag.C), MOpcode.BCS),

View File

@ -541,6 +541,14 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
labelMap += "__rwdata_start" -> (defaultBank -> rwDataStart)
labelMap += "__rwdata_end" -> (defaultBank -> rwDataEnd)
labelMap += "__heap_start" -> (defaultBank -> variableAllocators("default").heapStart)
for (segment <- platform.bankNumbers.keys) {
val allocator = options.platform.variableAllocators(segment)
labelMap += s"segment.$segment.start" -> (defaultBank -> allocator.startAt)
labelMap += s"segment.$segment.end" -> (defaultBank -> (allocator.endBefore - 1))
labelMap += s"segment.$segment.heapstart" -> (defaultBank -> allocator.heapStart)
labelMap += s"segment.$segment.length" -> (defaultBank -> (allocator.endBefore - allocator.startAt))
labelMap += s"segment.$segment.bank" -> (defaultBank -> platform.bankNumbers(segment))
}
env = rootEnv.allThings

View File

@ -95,6 +95,9 @@ class AfterCodeByteAllocator(startIfNoCode: Int, val endBefore: Int) extends Byt
class VariableAllocator(zpBytes: List[Int], private val bytes: ByteAllocator) {
def startAt: Int = bytes.startAt
def endBefore: Int = bytes.endBefore
def totalHimemSize: Int = bytes.endBefore - bytes.startAt
val zeropage: ByteAllocator = new ZeropageAllocator(zpBytes)