1
0
mirror of https://github.com/KarolS/millfork.git synced 2026-04-20 03:16:45 +00:00

6809: Update emulators and fix decimal subtraction

This commit is contained in:
Karol Stasiak
2020-06-22 01:17:42 +02:00
parent e77811c67c
commit b7a34457fb
6 changed files with 27 additions and 18 deletions
@@ -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)
@@ -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 () {
@@ -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._
@@ -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