diff --git a/codeCore/src/prog8/code/core/IMachineDefinition.kt b/codeCore/src/prog8/code/core/IMachineDefinition.kt
index 178ce45c3..82e836cf2 100644
--- a/codeCore/src/prog8/code/core/IMachineDefinition.kt
+++ b/codeCore/src/prog8/code/core/IMachineDefinition.kt
@@ -14,7 +14,7 @@ interface IMachineDefinition {
val FLOAT_MAX_POSITIVE: Double
val FLOAT_MEM_SIZE: Int
val PROGRAM_LOAD_ADDRESS : UInt
- val PROGRAM_TOP_ADDRESS: UInt
+ val PROGRAM_MEMTOP_ADDRESS: UInt
val BSSHIGHRAM_START: UInt
val BSSHIGHRAM_END: UInt
val BSSGOLDENRAM_START: UInt
diff --git a/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt b/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt
index 3c4fd9288..2d32a2d22 100644
--- a/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt
+++ b/codeCore/src/prog8/code/target/atari/AtariMachineDefinition.kt
@@ -12,7 +12,7 @@ class AtariMachineDefinition: IMachineDefinition {
override val FLOAT_MAX_NEGATIVE = -9.999999999e97
override val FLOAT_MEM_SIZE = 6
override val PROGRAM_LOAD_ADDRESS = 0x2000u
- override val PROGRAM_TOP_ADDRESS = 0xffffu // TODO what's memtop
+ override val PROGRAM_MEMTOP_ADDRESS = 0xffffu // TODO what's memtop?
override val BSSHIGHRAM_START = 0u // TODO
override val BSSHIGHRAM_END = 0u // TODO
diff --git a/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt b/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt
index 8c4d3923b..8636d6733 100644
--- a/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt
+++ b/codeCore/src/prog8/code/target/c128/C128MachineDefinition.kt
@@ -14,7 +14,7 @@ class C128MachineDefinition: IMachineDefinition {
override val FLOAT_MAX_NEGATIVE = Mflpt5.FLOAT_MAX_NEGATIVE
override val FLOAT_MEM_SIZE = Mflpt5.FLOAT_MEM_SIZE
override val PROGRAM_LOAD_ADDRESS = 0x1c01u
- override val PROGRAM_TOP_ADDRESS = 0xfeffu
+ override val PROGRAM_MEMTOP_ADDRESS = 0xff00u
override val BSSHIGHRAM_START = 0u // TODO
override val BSSHIGHRAM_END = 0u // TODO
diff --git a/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt b/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt
index 6315ef379..83c08aa7c 100644
--- a/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt
+++ b/codeCore/src/prog8/code/target/c64/C64MachineDefinition.kt
@@ -15,7 +15,7 @@ class C64MachineDefinition: IMachineDefinition {
override val FLOAT_MAX_NEGATIVE = Mflpt5.FLOAT_MAX_NEGATIVE
override val FLOAT_MEM_SIZE = Mflpt5.FLOAT_MEM_SIZE
override val PROGRAM_LOAD_ADDRESS = 0x0801u
- override val PROGRAM_TOP_ADDRESS = 0xcfe0u // $9fff if floats are used
+ override val PROGRAM_MEMTOP_ADDRESS = 0xcfe0u // $a000 if floats are used
// note that at $cfe0-$cfff are the 16 'virtual registers' R0-R15
override val BSSHIGHRAM_START = 0xc000u
diff --git a/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt b/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt
index fa72e9099..3c58e6305 100644
--- a/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt
+++ b/codeCore/src/prog8/code/target/cx16/CX16MachineDefinition.kt
@@ -14,7 +14,7 @@ class CX16MachineDefinition: IMachineDefinition {
override val FLOAT_MAX_NEGATIVE = Mflpt5.FLOAT_MAX_NEGATIVE
override val FLOAT_MEM_SIZE = Mflpt5.FLOAT_MEM_SIZE
override val PROGRAM_LOAD_ADDRESS = 0x0801u
- override val PROGRAM_TOP_ADDRESS = 0x9effu
+ override val PROGRAM_MEMTOP_ADDRESS = 0x9f00u
override val BSSHIGHRAM_START = 0xa000u // hiram bank 1, 8Kb, assumed to be active
override val BSSHIGHRAM_END = 0xbfffu // Rom starts at $c000
diff --git a/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt b/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt
index 90b874ddf..b006968d1 100644
--- a/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt
+++ b/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt
@@ -12,7 +12,7 @@ class Neo6502MachineDefinition: IMachineDefinition {
override val FLOAT_MAX_NEGATIVE = -9.999999999e97
override val FLOAT_MEM_SIZE = 6
override val PROGRAM_LOAD_ADDRESS = 0x0800u
- override val PROGRAM_TOP_ADDRESS = 0xfbffu
+ override val PROGRAM_MEMTOP_ADDRESS = 0xfc00u // kernal starts here
override val BSSHIGHRAM_START = 0u // TODO
override val BSSHIGHRAM_END = 0u // TODO
diff --git a/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt b/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt
index b71cda9ef..09302d76d 100644
--- a/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt
+++ b/codeCore/src/prog8/code/target/pet/PETMachineDefinition.kt
@@ -14,7 +14,7 @@ class PETMachineDefinition: IMachineDefinition {
override val FLOAT_MAX_NEGATIVE = Mflpt5.FLOAT_MAX_NEGATIVE
override val FLOAT_MEM_SIZE = Mflpt5.FLOAT_MEM_SIZE
override val PROGRAM_LOAD_ADDRESS = 0x0401u
- override val PROGRAM_TOP_ADDRESS = 0x7fffu
+ override val PROGRAM_MEMTOP_ADDRESS = 0x8000u
override val BSSHIGHRAM_START = 0u
override val BSSHIGHRAM_END = 0u
diff --git a/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt b/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt
index 15cd7bc74..96de9c098 100644
--- a/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt
+++ b/codeCore/src/prog8/code/target/virtual/VirtualMachineDefinition.kt
@@ -14,7 +14,7 @@ class VirtualMachineDefinition: IMachineDefinition {
override val FLOAT_MAX_NEGATIVE = -Float.MAX_VALUE.toDouble()
override val FLOAT_MEM_SIZE = 8 // 64-bits double
override val PROGRAM_LOAD_ADDRESS = 0u // not actually used
- override val PROGRAM_TOP_ADDRESS = 0xffffu // not actually used
+ override val PROGRAM_MEMTOP_ADDRESS = 0xffffu // not actually used
override val BSSHIGHRAM_START = 0u // not actually used
override val BSSHIGHRAM_END = 0u // not actually used
diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt
index 1ae16c7b1..852a31fab 100644
--- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt
+++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt
@@ -287,7 +287,7 @@ internal class ProgramAndVarsGen(
}
}
asmgen.out(" ; memtop check")
- asmgen.out(" .cerror * > ${options.memtopAddress.toHex()}, \"Program too long by \", * - ${options.memtopAddress.toHex()}, \" bytes, memtop=${options.memtopAddress.toHex()}\"")
+ asmgen.out(" .cerror * >= ${options.memtopAddress.toHex()}, \"Program too long by \", * - ${(options.memtopAddress-1u).toHex()}, \" bytes, memtop=${options.memtopAddress.toHex()}\"")
}
private fun block2asm(block: PtBlock) {
diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt
index ab882c36a..820df9dcb 100644
--- a/compiler/src/prog8/compiler/Compiler.kt
+++ b/compiler/src/prog8/compiler/Compiler.kt
@@ -264,7 +264,7 @@ internal fun determineProgramLoadAddress(program: Program, options: CompilationO
}
options.loadAddress = loadAddress
- options.memtopAddress = program.toplevelModule.memtopAddress?.first ?: options.compTarget.machine.PROGRAM_TOP_ADDRESS
+ options.memtopAddress = program.toplevelModule.memtopAddress?.first ?: options.compTarget.machine.PROGRAM_MEMTOP_ADDRESS
}
diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst
index bf7dc9215..bd100e1ab 100644
--- a/docs/source/syntaxreference.rst
+++ b/docs/source/syntaxreference.rst
@@ -191,8 +191,8 @@ Directives
but with this you can change it to another value. This can be useful for example to 'reserve' a piece
of memory at the end of program space where other data such as external library files can be loaded into.
This memtop value is used for a check instruction for the assembler to see if the resulting program size
- exceeds the given memtop address. This value is inclusive, so $9eff means that the program can use up to
- and including the address $9eff and that $9f00 is the first address out of bounds.
+ exceeds the given memtop address. This value is exclusive, so $a000 means that $a000 is the first address
+ that program can no longer use. Everything up to and including $9fff is still usable.
.. data:: %option