1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-10-13 01:23:40 +00:00

Fixed org option

This commit is contained in:
Karol Stasiak 2018-03-09 00:07:05 +01:00
parent 34b827df38
commit 807a9df8ac
4 changed files with 27 additions and 23 deletions

View File

@ -17,8 +17,8 @@ class Platform(
val flagOverrides: Map[CompilationFlag.Value, Boolean], val flagOverrides: Map[CompilationFlag.Value, Boolean],
val startingModules: List[String], val startingModules: List[String],
val outputPackager: OutputPackager, val outputPackager: OutputPackager,
val allocator: VariableAllocator, val codeAllocator: UpwardByteAllocator,
val org: Int, val variableAllocator: VariableAllocator,
val fileExtension: String, val fileExtension: String,
var defaultCodeBank: Int = 0, var defaultCodeBank: Int = 0,
) )
@ -30,11 +30,11 @@ object Platform {
Map(), Map(),
List("c64_hardware", "c64_loader"), List("c64_hardware", "c64_loader"),
SequenceOutput(List(StartAddressOutput, AllocatedDataOutput)), SequenceOutput(List(StartAddressOutput, AllocatedDataOutput)),
new UpwardByteAllocator(0x80D, 0xA000),
new VariableAllocator( new VariableAllocator(
List(0xC1, 0xC3, 0xFB, 0xFD, 0x39, 0x3B, 0x3D, 0x43, 0x4B), List(0xC1, 0xC3, 0xFB, 0xFD, 0x39, 0x3B, 0x3D, 0x43, 0x4B),
new AfterCodeByteAllocator(0xA000) new AfterCodeByteAllocator(0xA000)
), ),
0x80D,
".prg" ".prg"
) )
@ -98,11 +98,14 @@ object Platform {
case "all" => List.tabulate(128)(_ * 2) case "all" => List.tabulate(128)(_ * 2)
case xs => xs.split("[, ]+").map(parseNumber).toList case xs => xs.split("[, ]+").map(parseNumber).toList
} }
val byteAllocator = (as.get(classOf[String], "himem_start", ""), as.get(classOf[String], "himem_end", "")) match { val himemEnd = as.get(classOf[String], "himem_end", "") match {
case ("", _) => ErrorReporting.fatal(s"Undefined himem_start") case "" => ErrorReporting.fatal(s"Undefined himem_end")
case (_, "") => ErrorReporting.fatal(s"Undefined himem_end") case end => parseNumber(end) + 1
case ("after_code", end) => new AfterCodeByteAllocator(parseNumber(end) + 1) }
case (start, end) => new UpwardByteAllocator(parseNumber(start), parseNumber(end) + 1) val byteAllocator = as.get(classOf[String], "himem_start", "") match {
case "" => ErrorReporting.fatal(s"Undefined himem_start")
case "after_code" => new AfterCodeByteAllocator(himemEnd)
case start => new UpwardByteAllocator(parseNumber(start), himemEnd)
} }
val os = conf.getSection("output") val os = conf.getSection("output")
@ -120,7 +123,8 @@ object Platform {
var fileExtension = os.get(classOf[String], "extension", ".bin") var fileExtension = os.get(classOf[String], "extension", ".bin")
new Platform(cpu, flagOverrides, startingModules, outputPackager, new Platform(cpu, flagOverrides, startingModules, outputPackager,
new VariableAllocator(freePointers, byteAllocator), org, new UpwardByteAllocator(org, 0xffff),
new VariableAllocator(freePointers, byteAllocator),
if (fileExtension.startsWith(".")) fileExtension else "." + fileExtension) if (fileExtension.startsWith(".")) fileExtension else "." + fileExtension)
} }

View File

@ -236,15 +236,14 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
case _ => case _ =>
} }
var justAfterCode = platform.org val codeAllocator = new VariableAllocator(Nil, platform.codeAllocator)
val allocator = platform.allocator var justAfterCode = platform.codeAllocator.startAt
allocator.notifyAboutEndOfCode(platform.org)
env.allPreallocatables.foreach { env.allPreallocatables.foreach {
case f: NormalFunction if f.address.isEmpty && f.name == "main" => case f: NormalFunction if f.address.isEmpty && f.name == "main" =>
val code = compiledFunctions(f.name) val code = compiledFunctions(f.name)
if (code.nonEmpty) { if (code.nonEmpty) {
val size = code.map(_.sizeInBytes).sum val size = code.map(_.sizeInBytes).sum
val index = allocator.allocateBytes(bank0, options, size, initialized = true, writeable = false) val index = codeAllocator.allocateBytes(bank0, options, size, initialized = true, writeable = false)
labelMap(f.name) = index labelMap(f.name) = index
justAfterCode = outputFunction(code, index, assembly, options) justAfterCode = outputFunction(code, index, assembly, options)
} }
@ -255,7 +254,7 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
val code = compiledFunctions(f.name) val code = compiledFunctions(f.name)
if (code.nonEmpty) { if (code.nonEmpty) {
val size = code.map(_.sizeInBytes).sum val size = code.map(_.sizeInBytes).sum
val index = allocator.allocateBytes(bank0, options, size, initialized = true, writeable = false) val index = codeAllocator.allocateBytes(bank0, options, size, initialized = true, writeable = false)
labelMap(f.name) = index labelMap(f.name) = index
justAfterCode = outputFunction(code, index, assembly, options) justAfterCode = outputFunction(code, index, assembly, options)
} }
@ -263,7 +262,7 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
} }
env.allPreallocatables.foreach { env.allPreallocatables.foreach {
case InitializedArray(name, None, items) => case InitializedArray(name, None, items) =>
var index = allocator.allocateBytes(bank0, options, items.size, initialized = true, writeable = true) var index = codeAllocator.allocateBytes(bank0, options, items.size, initialized = true, writeable = true)
labelMap(name) = index labelMap(name) = index
assembly.append("* = $" + index.toHexString) assembly.append("* = $" + index.toHexString)
assembly.append(name) assembly.append(name)
@ -275,7 +274,7 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
initializedVariablesSize += items.length initializedVariablesSize += items.length
justAfterCode = index justAfterCode = index
case m@InitializedMemoryVariable(name, None, typ, value) => case m@InitializedMemoryVariable(name, None, typ, value) =>
var index = allocator.allocateBytes(bank0, options, typ.size, initialized = true, writeable = true) var index = codeAllocator.allocateBytes(bank0, options, typ.size, initialized = true, writeable = true)
labelMap(name) = index labelMap(name) = index
val altName = m.name.stripPrefix(env.prefix) + "`" val altName = m.name.stripPrefix(env.prefix) + "`"
env.things += altName -> ConstantThing(altName, NumericConstant(index, 2), env.get[Type]("pointer")) env.things += altName -> ConstantThing(altName, NumericConstant(index, 2), env.get[Type]("pointer"))
@ -290,8 +289,9 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
justAfterCode = index justAfterCode = index
case _ => case _ =>
} }
allocator.notifyAboutEndOfCode(justAfterCode) val variableAllocator = platform.variableAllocator
env.allocateVariables(None, bank0, callGraph, allocator, options, labelMap.put) variableAllocator.notifyAboutEndOfCode(justAfterCode)
env.allocateVariables(None, bank0, callGraph, variableAllocator, options, labelMap.put)
env = rootEnv.allThings env = rootEnv.allThings

View File

@ -1,6 +1,6 @@
package millfork.test.emu package millfork.test.emu
import millfork.output.{AfterCodeByteAllocator, CurrentBankFragmentOutput, VariableAllocator} import millfork.output.{AfterCodeByteAllocator, CurrentBankFragmentOutput, UpwardByteAllocator, VariableAllocator}
import millfork.{Cpu, Platform} import millfork.{Cpu, Platform}
/** /**
@ -12,8 +12,8 @@ object EmuPlatform {
Map(), Map(),
Nil, Nil,
CurrentBankFragmentOutput(0, 0xffff), CurrentBankFragmentOutput(0, 0xffff),
new UpwardByteAllocator(0x200, 0xb000),
new VariableAllocator((0 until 256 by 2).toList, new AfterCodeByteAllocator(0xff00)), new VariableAllocator((0 until 256 by 2).toList, new AfterCodeByteAllocator(0xff00)),
0x200,
".bin" ".bin"
) )
} }

View File

@ -172,14 +172,14 @@ class EmuRun(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimization],
} }
platform.cpu match { platform.cpu match {
case millfork.Cpu.Cmos => case millfork.Cpu.Cmos =>
runViaSymon(memoryBank, platform.org, CpuBehavior.CMOS_6502) runViaSymon(memoryBank, platform.codeAllocator.startAt, CpuBehavior.CMOS_6502)
case millfork.Cpu.Ricoh => case millfork.Cpu.Ricoh =>
runViaHalfnes(memoryBank, platform.org) runViaHalfnes(memoryBank, platform.codeAllocator.startAt)
case millfork.Cpu.Mos => case millfork.Cpu.Mos =>
ErrorReporting.fatal("There's no NMOS emulator with decimal mode support") ErrorReporting.fatal("There's no NMOS emulator with decimal mode support")
Timings(-1, -1) -> memoryBank Timings(-1, -1) -> memoryBank
case millfork.Cpu.StrictMos | millfork.Cpu.StrictRicoh => case millfork.Cpu.StrictMos | millfork.Cpu.StrictRicoh =>
runViaSymon(memoryBank, platform.org, CpuBehavior.NMOS_6502) runViaSymon(memoryBank, platform.codeAllocator.startAt, CpuBehavior.NMOS_6502)
case _ => case _ =>
ErrorReporting.trace("No emulation support for " + platform.cpu) ErrorReporting.trace("No emulation support for " + platform.cpu)
Timings(-1, -1) -> memoryBank Timings(-1, -1) -> memoryBank