From 39b07a8bae4df9cd7686ff410329f838f6f1bc7d Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Fri, 28 Jun 2019 16:44:41 +0200 Subject: [PATCH] Fix init_rw_memory on Atari 2600 --- docs/lang/preprocessor.md | 2 +- examples/vcs/colors.mfk | 1 + src/main/scala/millfork/Platform.scala | 10 +++------- src/main/scala/millfork/output/VariableAllocator.scala | 4 ++-- src/test/scala/millfork/test/emu/EmuPlatform.scala | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/lang/preprocessor.md b/docs/lang/preprocessor.md index dffb4fc4..8e334640 100644 --- a/docs/lang/preprocessor.md +++ b/docs/lang/preprocessor.md @@ -66,7 +66,7 @@ See [the ROM vs RAM guide](../api/rom-vs-ram.md) for more information. * `ZPREG_SIZE` – size of the pseudoregister in bytes, or 0 on platforms that don't use it -* `TINY_MAIN_RAM` – 1 if the main ram is 256 bytes or less, 0 otherwise +* `TINY_RW_MEMORY` – 1 if the main ram is 256 bytes or less, 0 otherwise * `USES_IX_STACK`, `USES_IY_STACK` – 1 if given index register is used as a base pointer for stack-allocated variables, 0 otherwise diff --git a/examples/vcs/colors.mfk b/examples/vcs/colors.mfk index 5c29987a..2944627a 100644 --- a/examples/vcs/colors.mfk +++ b/examples/vcs/colors.mfk @@ -1,4 +1,5 @@ void main() { + init_rw_memory() byte y while true { start_frame() diff --git a/src/main/scala/millfork/Platform.scala b/src/main/scala/millfork/Platform.scala index 98f60711..c2aeb2c9 100644 --- a/src/main/scala/millfork/Platform.scala +++ b/src/main/scala/millfork/Platform.scala @@ -157,16 +157,12 @@ object Platform { case "default" => log.error("Cannot use default as ram_init_segment") None - case x if banks.contains(x) => - if (CpuFamily.forType(cpu) == CpuFamily.M6502 && zpRegisterSize < 4) { - log.error("Using ram_init_segment requires zeropage register of size at least 4") - } - Some(x) + case x if banks.contains(x) => Some(x) case x => log.error("Invalid ram_init_segment: " + x) None } - // used by 65816: + // used by 65816 and in NES debugging: val bankNumbers = banks.map(b => b -> (as.get(classOf[String], s"segment_${b}_bank", "00") match { case "" => 0 case x => parseNumber(x) @@ -204,7 +200,7 @@ object Platform { val codeAllocators = banks.map(b => b -> new UpwardByteAllocator(bankStarts(b), bankCodeEnds(b))) val variableAllocators = banks.map(b => b -> new VariableAllocator( if (b == "default" && CpuFamily.forType(cpu) == CpuFamily.M6502) freeZpBytes else Nil, bankDataStarts(b) match { - case None => new AfterCodeByteAllocator(bankEnds(b)) + case None => new AfterCodeByteAllocator(bankStarts(b), bankEnds(b)) case Some(start) => new UpwardByteAllocator(start, bankEnds(b)) })) diff --git a/src/main/scala/millfork/output/VariableAllocator.scala b/src/main/scala/millfork/output/VariableAllocator.scala index 783e686a..cc341f0b 100644 --- a/src/main/scala/millfork/output/VariableAllocator.scala +++ b/src/main/scala/millfork/output/VariableAllocator.scala @@ -84,8 +84,8 @@ class ZeropageAllocator(val freeZpBytes: List[Int]) extends ByteAllocator { override def heapStart: Int = 0 } -class AfterCodeByteAllocator(val endBefore: Int) extends ByteAllocator { - var startAt = 0x200 +class AfterCodeByteAllocator(startIfNoCode: Int, val endBefore: Int) extends ByteAllocator { + var startAt = startIfNoCode def notifyAboutEndOfCode(org: Int): Unit = startAt = org override def preferredOrder: Option[List[Int]] = None diff --git a/src/test/scala/millfork/test/emu/EmuPlatform.scala b/src/test/scala/millfork/test/emu/EmuPlatform.scala index a64b5c2a..5d4acb98 100644 --- a/src/test/scala/millfork/test/emu/EmuPlatform.scala +++ b/src/test/scala/millfork/test/emu/EmuPlatform.scala @@ -21,7 +21,7 @@ object EmuPlatform { Map("default" -> (if (cpu == Cpu.Intel8086) new UpwardByteAllocator(0x100, 0xb000) else new UpwardByteAllocator(0x200, 0xb000))), Map("default" -> new VariableAllocator( if (CpuFamily.forType(cpu) == CpuFamily.M6502) pointers else Nil, - new AfterCodeByteAllocator(0xff00))), + new AfterCodeByteAllocator(0x200, 0xff00))), if (CpuFamily.forType(cpu) == CpuFamily.M6502) 4 else 0, pointers, ".bin",