Skip to content

Commit

Permalink
Merge pull request #18 from fedex81/bcd-fixes
Browse files Browse the repository at this point in the history
68k: fix abcd/sbcd -(aN),-(aN)
  • Loading branch information
tonyheadford authored Nov 1, 2022
2 parents c5e739c + d86e481 commit e6b6f3a
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 e6b6f3a

Please sign in to comment.