From d86e481f0e904ecf8b03c73f1d577ef889348656 Mon Sep 17 00:00:00 2001 From: Federico Berti Date: Tue, 25 Oct 2022 14:36:07 +0100 Subject: [PATCH] 68k: fix abcd/sbcd -(aN),-(aN) --- src/m68k/cpu/instructions/ABCD.java | 2 +- src/m68k/cpu/instructions/SBCD.java | 2 +- test/miggy/cpu/instructions/bcd/ABCDTest.java | 18 ++++++++++++++++++ test/miggy/cpu/instructions/bcd/SBCDTest.java | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/m68k/cpu/instructions/ABCD.java b/src/m68k/cpu/instructions/ABCD.java index de293f7..54485ff 100644 --- a/src/m68k/cpu/instructions/ABCD.java +++ b/src/m68k/cpu/instructions/ABCD.java @@ -100,8 +100,8 @@ protected final int abcd_ar(int opcode) { int sreg = (opcode & 0x07); int dreg = (opcode >> 9) & 0x07; cpu.decrementAddrRegister(sreg, 1); - cpu.decrementAddrRegister(dreg, 1); int s = cpu.readMemoryByte(cpu.getAddrRegisterLong(sreg)); + cpu.decrementAddrRegister(dreg, 1); int d = cpu.readMemoryByte(cpu.getAddrRegisterLong(dreg)); int result = calc(cpu, s, d); diff --git a/src/m68k/cpu/instructions/SBCD.java b/src/m68k/cpu/instructions/SBCD.java index 3c59c4e..f9712dd 100644 --- a/src/m68k/cpu/instructions/SBCD.java +++ b/src/m68k/cpu/instructions/SBCD.java @@ -100,8 +100,8 @@ protected final int sbcd_ar(int opcode) { int sreg = (opcode & 0x07); int dreg = (opcode >> 9) & 0x07; cpu.decrementAddrRegister(sreg, 1); - cpu.decrementAddrRegister(dreg, 1); int s = cpu.readMemoryByte(cpu.getAddrRegisterLong(sreg)); + cpu.decrementAddrRegister(dreg, 1); int d = cpu.readMemoryByte(cpu.getAddrRegisterLong(dreg)); int result = calc(cpu, s, d); diff --git a/test/miggy/cpu/instructions/bcd/ABCDTest.java b/test/miggy/cpu/instructions/bcd/ABCDTest.java index c97dc8c..54e995e 100644 --- a/test/miggy/cpu/instructions/bcd/ABCDTest.java +++ b/test/miggy/cpu/instructions/bcd/ABCDTest.java @@ -54,4 +54,22 @@ public void testMem() { assertFalse("Check V 2", SystemModel.CPU.isSet(CpuFlag.V)); assertFalse("Check C 2", SystemModel.CPU.isSet(CpuFlag.C)); } + + public void testMem2() { + setInstruction(0xc108); //abcd -(a0),-(a0) + SystemModel.CPU.setAddrRegister(0, codebase + 100); + SystemModel.MEM.poke(codebase + 98, 0x2316, Size.Word); + + SystemModel.CPU.setCCR((byte) 0); + + int time = SystemModel.CPU.execute(); + + //23+16 = 39 + assertEquals("Check result", 0x3916, SystemModel.MEM.peek(codebase + 98, Size.Word)); + assertFalse("Check X", SystemModel.CPU.isSet(CpuFlag.X)); + assertFalse("Check N", SystemModel.CPU.isSet(CpuFlag.N)); + assertFalse("Check Z", SystemModel.CPU.isSet(CpuFlag.Z)); + assertFalse("Check V", SystemModel.CPU.isSet(CpuFlag.V)); + assertFalse("Check C", SystemModel.CPU.isSet(CpuFlag.C)); + } } diff --git a/test/miggy/cpu/instructions/bcd/SBCDTest.java b/test/miggy/cpu/instructions/bcd/SBCDTest.java index 95f534c..2066e8a 100644 --- a/test/miggy/cpu/instructions/bcd/SBCDTest.java +++ b/test/miggy/cpu/instructions/bcd/SBCDTest.java @@ -53,4 +53,21 @@ public void testMem() { assertFalse("Check V 2", SystemModel.CPU.isSet(CpuFlag.V)); assertFalse("Check C 2", SystemModel.CPU.isSet(CpuFlag.C)); } + + public void testMem2() { + setInstruction(0x8108); //sbcd -(a0),-(a0) + SystemModel.CPU.setAddrRegister(0, codebase + 100); + SystemModel.MEM.poke(codebase + 98, 0x3916, Size.Word); + SystemModel.CPU.setCCR((byte) 0); + + int time = SystemModel.CPU.execute(); + + //39-16 = 23 + assertEquals("Check result", 0x2316, SystemModel.MEM.peek(codebase + 98, Size.Word)); + assertFalse("Check X", SystemModel.CPU.isSet(CpuFlag.X)); + assertFalse("Check N", SystemModel.CPU.isSet(CpuFlag.N)); + assertFalse("Check Z", SystemModel.CPU.isSet(CpuFlag.Z)); + assertFalse("Check V", SystemModel.CPU.isSet(CpuFlag.V)); + assertFalse("Check C", SystemModel.CPU.isSet(CpuFlag.C)); + } }