diff --git a/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala b/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala index 713d5c0c..8611c78a 100644 --- a/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala +++ b/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala @@ -268,6 +268,18 @@ object AbstractExpressionCompiler { case 3 => env.get[Type]("int24") case 4 => env.get[Type]("long") } + case ConstantArrayElementExpression(constant) => + (constant.quickSimplify match { + case SubbyteConstant(_, _) => false -> 1 + case NumericConstant(v, s) => (v < 0) -> s + case CompoundConstant(MathOperator.Minus, NumericConstant(_, ls), NumericConstant(_, rs)) => true -> (ls max rs) + }) match { + case (false, 1) => b + case (true, 1) => env.get[Type]("sbyte") + case (_, 2) => b + case (_, 3) => env.get[Type]("int24") + case (_, 4) => env.get[Type]("long") + } case GeneratedConstantExpression(_, typ) => typ case TextLiteralExpression(_) => env.get[Type]("pointer") case VariableExpression(name) => diff --git a/src/main/scala/millfork/compiler/z80/Z80Comparisons.scala b/src/main/scala/millfork/compiler/z80/Z80Comparisons.scala index e4c53677..0bd04cfb 100644 --- a/src/main/scala/millfork/compiler/z80/Z80Comparisons.scala +++ b/src/main/scala/millfork/compiler/z80/Z80Comparisons.scala @@ -137,6 +137,9 @@ object Z80Comparisons { import ZOpcode._ val calculateLeft = Z80ExpressionCompiler.compileToHL(ctx, l) val calculateRight = Z80ExpressionCompiler.compileToHL(ctx, r) + if (branches == NoBranching) { + return calculateLeft ++ calculateRight + } val fastEqualityComparison: Option[List[ZLine]] = (calculateLeft, calculateRight) match { case (List(ZLine0(LD_16, TwoRegisters(HL, IMM_16), NumericConstant(0, _))), _) => Some(calculateRight ++ List(ZLine.ld8(A, H), ZLine.register(OR, L))) diff --git a/src/main/scala/millfork/output/AbstractAssembler.scala b/src/main/scala/millfork/output/AbstractAssembler.scala index 999e0549..682d2f45 100644 --- a/src/main/scala/millfork/output/AbstractAssembler.scala +++ b/src/main/scala/millfork/output/AbstractAssembler.scala @@ -156,6 +156,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program case MathOperator.Shl => l << r case MathOperator.Shl9 => (l << r) & 0x1ff case MathOperator.Shr => l >>> r + case MathOperator.Shr9 => ((l & 0x1ff) >>> r) & 0xff case MathOperator.DecimalPlus => asDecimal(l, r, _ + _) case MathOperator.DecimalPlus9 => asDecimal(l, r, _ + _) & 0x1ff case MathOperator.DecimalMinus => asDecimal(l, r, _ - _)