diff --git a/COMPILING.md b/COMPILING.md index 3ceff6b7..4f61d575 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -56,7 +56,7 @@ Test suite is useful if you plan on modifying the compiler. Some test dependenci https://github.com/sethm/symon/tree/71905fdb1998ee4f142260879504bc46cf27648f https://github.com/andrew-hoffman/halfnes/tree/061 https://github.com/trekawek/coffee-gb/tree/coffee-gb-1.0.0 - https://github.com/sorenroug/osnine-java/tree/1b4e059c5886fe01e8901c70684f7eedefe65010 + https://github.com/sorenroug/osnine-java/tree/b77349a6c314e1362e69b7158c385ac6f89b7ab8 * for each of them, run `maven package` and `maven install` diff --git a/build.sbt b/build.sbt index 07e699db..1b404217 100644 --- a/build.sbt +++ b/build.sbt @@ -22,7 +22,7 @@ libraryDependencies += "NeatMonster" % "Intel8086" % "1.0" % "test" from "https: // https://github.com/sethm/symon/tree/71905fdb1998ee4f142260879504bc46cf27648f // https://github.com/andrew-hoffman/halfnes/tree/061 // https://github.com/trekawek/coffee-gb/tree/coffee-gb-1.0.0 -// https://github.com/sorenroug/osnine-java/tree/1b4e059c5886fe01e8901c70684f7eedefe65010 +// https://github.com/sorenroug/osnine-java/tree/b77349a6c314e1362e69b7158c385ac6f89b7ab8 libraryDependencies += "com.loomcom.symon" % "symon" % "1.3.0-SNAPSHOT" % "test" @@ -30,7 +30,7 @@ libraryDependencies += "com.grapeshot" % "halfnes" % "061" % "test" libraryDependencies += "eu.rekawek.coffeegb" % "coffee-gb" % "1.0.0" % "test" -libraryDependencies += "roug.org.osnine" % "osnine-core" % "1.0-SNAPSHOT" % "test" +libraryDependencies += "roug.org.osnine" % "osnine-core" % "2.0-SNAPSHOT" % "test" mainClass in Compile := Some("millfork.Main") diff --git a/src/main/scala/millfork/compiler/m6809/M6809LargeBuiltins.scala b/src/main/scala/millfork/compiler/m6809/M6809LargeBuiltins.scala index 4ee69260..c350d702 100644 --- a/src/main/scala/millfork/compiler/m6809/M6809LargeBuiltins.scala +++ b/src/main/scala/millfork/compiler/m6809/M6809LargeBuiltins.scala @@ -116,6 +116,7 @@ object M6809LargeBuiltins { } val sizeInBytes = AbstractExpressionCompiler.getExpressionType(ctx, target).size val byteLoads = M6809ExpressionCompiler.compileToByteReads(ctx, argument, sizeInBytes) + val needsAPreserved = byteLoads.tails.toList.tail.map(_.exists(_.exists(_.readsRegister(M6809Register.A)))) val result = new ListBuffer[MLine]() val targetAddr: Option[Constant] = M6809ExpressionCompiler.compileAddressToX(ctx, target) match { case List(MLine(LDX, Immediate, addr, _, _)) => Some(addr) @@ -152,17 +153,28 @@ object M6809LargeBuiltins { case (SUBA, _) => targetAddr match { case Some(addr) => - if (i == firstNonzeroByte) { - result ++= ldb - } else { - result ++= M6809ExpressionCompiler.stashCarryIfNeeded(ctx, ldb) + val stashCC = i != firstNonzeroByte + if (stashCC) result += MLine.pp(PSHS, M6809Register.CC) + result ++= ldb + if (needsAPreserved(i)) { + // TODO: optimize? + result += MLine.pp(PSHS, M6809Register.A) } result += MLine.pp(PSHS, M6809Register.B) result += MLine.immediate(LDA, if (i == firstNonzeroByte) 0x9a else 0x99) result += MLine.accessAndPullS(SUBA) + if (needsAPreserved(i)) { + // TODO: optimize? + result += MLine.pp(PULS, M6809Register.B) + } + if (stashCC) result += MLine.pp(PULS, M6809Register.CC) result += MLine.absolute(if (i == firstNonzeroByte) ADDA else ADCA, addr + (sizeInBytes - 1 - i)) result += MLine.inherent(DAA) result += MLine.absolute(STA, addr + (sizeInBytes - 1 - i)) + if (needsAPreserved(i)) { + // TODO: optimize? + result += MLine.tfr(M6809Register.B, M6809Register.A) + } case None => result ++= M6809ExpressionCompiler.stashXIfNeeded(ctx, ldb) result += MLine.pp(PSHS, M6809Register.B) diff --git a/src/test/scala/millfork/test/ByteDecimalMathSuite.scala b/src/test/scala/millfork/test/ByteDecimalMathSuite.scala index d9cf551e..aebc8bd1 100644 --- a/src/test/scala/millfork/test/ByteDecimalMathSuite.scala +++ b/src/test/scala/millfork/test/ByteDecimalMathSuite.scala @@ -152,8 +152,7 @@ class ByteDecimalMathSuite extends FunSuite with Matchers with AppendedClues { } test("In-place decimal word subtraction") { - // TODO: enable 6809 after the DAA bug in the emulator is fixed - EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086/*, Cpu.Motorola6809*/)( + EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086, Cpu.Motorola6809)( """ | word output @$c000 | word a @@ -167,8 +166,7 @@ class ByteDecimalMathSuite extends FunSuite with Matchers with AppendedClues { } test("In-place decimal long subtraction") { - // TODO: enable 6809 after the DAA bug in the emulator is fixed - EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086/*, Cpu.Motorola6809*/)( + EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086, Cpu.Motorola6809)( """ | long output @$c000 | word a @@ -245,8 +243,7 @@ class ByteDecimalMathSuite extends FunSuite with Matchers with AppendedClues { } test("Decimal left shift test 3") { - // TODO: enable 6809 after the DAA bug in the emulator is fixed - EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086/*, Cpu.Motorola6809*/)( + EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086, Cpu.Motorola6809)( """ | word output @$c000 | void main () { @@ -260,8 +257,7 @@ class ByteDecimalMathSuite extends FunSuite with Matchers with AppendedClues { } test("Decimal left shift test 4") { - // TODO: enable 6809 after the DAA bug in the emulator is fixed - EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086/*, Cpu.Motorola6809*/)( + EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Ricoh, Cpu.Intel8086, Cpu.Motorola6809)( """ | long output @$c000 | void main () { diff --git a/src/test/scala/millfork/test/emu/EmuM6809Run.scala b/src/test/scala/millfork/test/emu/EmuM6809Run.scala index 399d09b0..6fdda94a 100644 --- a/src/test/scala/millfork/test/emu/EmuM6809Run.scala +++ b/src/test/scala/millfork/test/emu/EmuM6809Run.scala @@ -15,8 +15,9 @@ import millfork.error.ConsoleLogger import millfork.node.opt.NodeOptimization import millfork.node.{Program, StandardCallGraph} import millfork.output.{M6809Assembler, MemoryBank} -import millfork.parser.{M6809Parser, MosParser, PreprocessingResult, Preprocessor, Z80Parser} -import org.roug.osnine.{BusStraight, MC6809} +import millfork.parser.{M6809Parser, PreprocessingResult, Preprocessor} +import org.roug.usim.mc6809.MC6809 +import org.roug.usim.BusStraight import org.scalatest.Matchers import scala.collection.JavaConverters._ diff --git a/src/test/scala/millfork/test/emu/M6809Memory.scala b/src/test/scala/millfork/test/emu/M6809Memory.scala index 31f7a1b2..552d807d 100644 --- a/src/test/scala/millfork/test/emu/M6809Memory.scala +++ b/src/test/scala/millfork/test/emu/M6809Memory.scala @@ -1,7 +1,7 @@ package millfork.test.emu import millfork.output.MemoryBank -import org.roug.osnine.{Bus8Motorola, MemorySegment} +import org.roug.usim.MemorySegment /** * @author Karol Stasiak