diff --git a/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala b/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala index f52a5f4c..291a2576 100644 --- a/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala +++ b/src/main/scala/millfork/assembly/mos/opt/UndocumentedOptimizations.scala @@ -89,6 +89,11 @@ object UndocumentedOptimizations { val fragment2 = sax :: ctx.get[List[AssemblyLine]](12) List(fragment0, fragment1, fragment2).flatten }, + (Elidable & HasOpcode(TXA)) ~ + (Elidable & HasOpcode(AND)) ~ + (Elidable & HasOpcode(STA) & HasAddrModeIn(SaxModes) & DoesntMatterWhatItDoesWith(State.A, State.Z, State.N)) ~~> { code => + code(1).copy(opcode = LDA) :: code(2).copy(opcode = SAX) :: code.drop(3) + }, ) def andConstant(const: Constant, mask: Int): Option[Long] = const match { diff --git a/src/test/scala/millfork/test/IllegalSuite.scala b/src/test/scala/millfork/test/IllegalSuite.scala index b84a267e..d39ea709 100644 --- a/src/test/scala/millfork/test/IllegalSuite.scala +++ b/src/test/scala/millfork/test/IllegalSuite.scala @@ -140,6 +140,10 @@ class IllegalSuite extends FunSuite with Matchers { | byte c | b = five(a) | c = five(a) + | asm { + | iny + | inx + | } | a = c | five(a) | c = a & b @@ -156,9 +160,9 @@ class IllegalSuite extends FunSuite with Matchers { val m = EmuUndocumentedRun(""" | word output @$c000 | void main () { - | output = five(5) + | output = five(0, 5) | } - | word five (byte a) { + | word five (byte dummy, byte a) { | return a:a | } """.stripMargin) @@ -169,9 +173,9 @@ class IllegalSuite extends FunSuite with Matchers { val m = EmuUndocumentedRun(""" | byte output @$c000 | void main () { - | output = five(1) + | output = five(0, 1) | } - | byte five (byte a) { + | byte five (byte dummy, byte a) { | byte b | b = a | a += 4