1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-11-17 16:05:31 +00:00

6502: Fix expressions like p[i] <<= 1

This commit is contained in:
Karol Stasiak 2019-07-08 18:51:49 +02:00
parent 767f0da703
commit d64d0b5f96

View File

@ -319,8 +319,13 @@ object BuiltIns {
case Some(NumericConstant(0, _)) =>
MosExpressionCompiler.compile(ctx, lhs, None, NoBranching)
case Some(NumericConstant(v, _)) if v > 0 =>
val result = simpleOperation(opcode, ctx, lhs, IndexChoice.RequireX, preserveA = true, commutative = false)
val result = simpleOperation(opcode, ctx, lhs, IndexChoice.PreferX, preserveA = true, commutative = false)
result.last.addrMode match {
case AbsoluteX | Absolute | ZeroPage | ZeroPageX | LongAbsoluteX | LongAbsolute =>
result ++ List.fill(v.toInt - 1)(result.last)
case IndexedY | AbsoluteY | IndexedZ | LongIndexedZ | IndexedSY =>
result.init ++ List(result.last.copy(opcode = LDA)) ++ List.fill(v.toInt)(AssemblyLine.implied(opcode)) ++ List(result.last.copy(opcode = STA))
}
case _ =>
compileShiftOps(opcode, ctx, lhs, rhs) ++ MosExpressionCompiler.compileByteStorage(ctx, MosRegister.A, lhs)
}