diff --git a/src/main/scala/millfork/compiler/z80/ZBuiltIns.scala b/src/main/scala/millfork/compiler/z80/ZBuiltIns.scala index a99b1acd..4cfe75e7 100644 --- a/src/main/scala/millfork/compiler/z80/ZBuiltIns.scala +++ b/src/main/scala/millfork/compiler/z80/ZBuiltIns.scala @@ -177,6 +177,8 @@ object ZBuiltIns { } case NumericConstant(n, _) if n < 0 && !decimal => result += ZLine.imm8(SUB, (-n.toInt) & 0xff) + case NumericConstant(0, _) => + // nothing case _ => result += ZLine.imm8(ADD, const.loByte) if (decimal) { diff --git a/src/main/scala/millfork/env/Environment.scala b/src/main/scala/millfork/env/Environment.scala index 5edcae02..712eb2d4 100644 --- a/src/main/scala/millfork/env/Environment.scala +++ b/src/main/scala/millfork/env/Environment.scala @@ -1480,7 +1480,10 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa stmt.assemblyParamPassingConvention match { case ByVariable(name) => val zp = pointies(name) // TODO - val allocationMethod = if (pointies(name)) VariableAllocationMethod.Zeropage else if (typ.isPointy) VariableAllocationMethod.Register else VariableAllocationMethod.Auto + val allocationMethod = + if (pointies(name)) VariableAllocationMethod.Zeropage + else if (typ.isPointy && options.platform.cpuFamily == CpuFamily.M6502) VariableAllocationMethod.Register + else VariableAllocationMethod.Auto val v = UninitializedMemoryVariable(prefix + name, typ, allocationMethod, None, defaultVariableAlignment(options, 2), isVolatile = false) addThing(v, stmt.position) registerAddressConstant(v, stmt.position, options, Some(typ)) diff --git a/src/main/scala/millfork/output/AbstractAssembler.scala b/src/main/scala/millfork/output/AbstractAssembler.scala index 4940bba3..015d034b 100644 --- a/src/main/scala/millfork/output/AbstractAssembler.scala +++ b/src/main/scala/millfork/output/AbstractAssembler.scala @@ -730,6 +730,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program inlinedFunctions, options.jobContext)) unoptimizedCodeSize += unoptimized.map(_.sizeInBytes).sum + // unoptimized.foreach(l => log.trace(l.toString)) val code = optimizations.foldLeft(quickSimplify(unoptimized)) { (c, opt) => val code = opt.optimize(f, c, OptimizationContext(options, labelMap, env.maybeGet[ThingInMemory]("__reg"), niceFunctionProperties)) if (code eq c) code else quickSimplify(code)