mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-26 20:33:02 +00:00
Fixed org option
This commit is contained in:
parent
34b827df38
commit
807a9df8ac
@ -17,8 +17,8 @@ class Platform(
|
||||
val flagOverrides: Map[CompilationFlag.Value, Boolean],
|
||||
val startingModules: List[String],
|
||||
val outputPackager: OutputPackager,
|
||||
val allocator: VariableAllocator,
|
||||
val org: Int,
|
||||
val codeAllocator: UpwardByteAllocator,
|
||||
val variableAllocator: VariableAllocator,
|
||||
val fileExtension: String,
|
||||
var defaultCodeBank: Int = 0,
|
||||
)
|
||||
@ -30,11 +30,11 @@ object Platform {
|
||||
Map(),
|
||||
List("c64_hardware", "c64_loader"),
|
||||
SequenceOutput(List(StartAddressOutput, AllocatedDataOutput)),
|
||||
new UpwardByteAllocator(0x80D, 0xA000),
|
||||
new VariableAllocator(
|
||||
List(0xC1, 0xC3, 0xFB, 0xFD, 0x39, 0x3B, 0x3D, 0x43, 0x4B),
|
||||
new AfterCodeByteAllocator(0xA000)
|
||||
),
|
||||
0x80D,
|
||||
".prg"
|
||||
)
|
||||
|
||||
@ -98,11 +98,14 @@ object Platform {
|
||||
case "all" => List.tabulate(128)(_ * 2)
|
||||
case xs => xs.split("[, ]+").map(parseNumber).toList
|
||||
}
|
||||
val byteAllocator = (as.get(classOf[String], "himem_start", ""), as.get(classOf[String], "himem_end", "")) match {
|
||||
case ("", _) => ErrorReporting.fatal(s"Undefined himem_start")
|
||||
case (_, "") => ErrorReporting.fatal(s"Undefined himem_end")
|
||||
case ("after_code", end) => new AfterCodeByteAllocator(parseNumber(end) + 1)
|
||||
case (start, end) => new UpwardByteAllocator(parseNumber(start), parseNumber(end) + 1)
|
||||
val himemEnd = as.get(classOf[String], "himem_end", "") match {
|
||||
case "" => ErrorReporting.fatal(s"Undefined himem_end")
|
||||
case end => 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")
|
||||
@ -120,7 +123,8 @@ object Platform {
|
||||
var fileExtension = os.get(classOf[String], "extension", ".bin")
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -236,15 +236,14 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
var justAfterCode = platform.org
|
||||
val allocator = platform.allocator
|
||||
allocator.notifyAboutEndOfCode(platform.org)
|
||||
val codeAllocator = new VariableAllocator(Nil, platform.codeAllocator)
|
||||
var justAfterCode = platform.codeAllocator.startAt
|
||||
env.allPreallocatables.foreach {
|
||||
case f: NormalFunction if f.address.isEmpty && f.name == "main" =>
|
||||
val code = compiledFunctions(f.name)
|
||||
if (code.nonEmpty) {
|
||||
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
|
||||
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)
|
||||
if (code.nonEmpty) {
|
||||
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
|
||||
justAfterCode = outputFunction(code, index, assembly, options)
|
||||
}
|
||||
@ -263,7 +262,7 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
|
||||
}
|
||||
env.allPreallocatables.foreach {
|
||||
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
|
||||
assembly.append("* = $" + index.toHexString)
|
||||
assembly.append(name)
|
||||
@ -275,7 +274,7 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
|
||||
initializedVariablesSize += items.length
|
||||
justAfterCode = index
|
||||
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
|
||||
val altName = m.name.stripPrefix(env.prefix) + "`"
|
||||
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
|
||||
case _ =>
|
||||
}
|
||||
allocator.notifyAboutEndOfCode(justAfterCode)
|
||||
env.allocateVariables(None, bank0, callGraph, allocator, options, labelMap.put)
|
||||
val variableAllocator = platform.variableAllocator
|
||||
variableAllocator.notifyAboutEndOfCode(justAfterCode)
|
||||
env.allocateVariables(None, bank0, callGraph, variableAllocator, options, labelMap.put)
|
||||
|
||||
env = rootEnv.allThings
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package millfork.test.emu
|
||||
|
||||
import millfork.output.{AfterCodeByteAllocator, CurrentBankFragmentOutput, VariableAllocator}
|
||||
import millfork.output.{AfterCodeByteAllocator, CurrentBankFragmentOutput, UpwardByteAllocator, VariableAllocator}
|
||||
import millfork.{Cpu, Platform}
|
||||
|
||||
/**
|
||||
@ -12,8 +12,8 @@ object EmuPlatform {
|
||||
Map(),
|
||||
Nil,
|
||||
CurrentBankFragmentOutput(0, 0xffff),
|
||||
new UpwardByteAllocator(0x200, 0xb000),
|
||||
new VariableAllocator((0 until 256 by 2).toList, new AfterCodeByteAllocator(0xff00)),
|
||||
0x200,
|
||||
".bin"
|
||||
)
|
||||
}
|
||||
|
@ -172,14 +172,14 @@ class EmuRun(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimization],
|
||||
}
|
||||
platform.cpu match {
|
||||
case millfork.Cpu.Cmos =>
|
||||
runViaSymon(memoryBank, platform.org, CpuBehavior.CMOS_6502)
|
||||
runViaSymon(memoryBank, platform.codeAllocator.startAt, CpuBehavior.CMOS_6502)
|
||||
case millfork.Cpu.Ricoh =>
|
||||
runViaHalfnes(memoryBank, platform.org)
|
||||
runViaHalfnes(memoryBank, platform.codeAllocator.startAt)
|
||||
case millfork.Cpu.Mos =>
|
||||
ErrorReporting.fatal("There's no NMOS emulator with decimal mode support")
|
||||
Timings(-1, -1) -> memoryBank
|
||||
case millfork.Cpu.StrictMos | millfork.Cpu.StrictRicoh =>
|
||||
runViaSymon(memoryBank, platform.org, CpuBehavior.NMOS_6502)
|
||||
runViaSymon(memoryBank, platform.codeAllocator.startAt, CpuBehavior.NMOS_6502)
|
||||
case _ =>
|
||||
ErrorReporting.trace("No emulation support for " + platform.cpu)
|
||||
Timings(-1, -1) -> memoryBank
|
||||
|
Loading…
x
Reference in New Issue
Block a user