Skip to content

Commit

Permalink
68k: fix abcd/sbcd -(aN),-(aN)
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Berti committed Nov 1, 2022
1 parent c5e739c commit d86e481
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/m68k/cpu/instructions/ABCD.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/m68k/cpu/instructions/SBCD.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions test/miggy/cpu/instructions/bcd/ABCDTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
17 changes: 17 additions & 0 deletions test/miggy/cpu/instructions/bcd/SBCDTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit d86e481

Please sign in to comment.