1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-01 08:41:32 +00:00

Fix for GitHub Issue #9

This commit is contained in:
Seth Morabito 2014-08-11 13:36:08 -07:00
parent 7c2a007928
commit 22a9207dca
2 changed files with 20 additions and 1 deletions

View File

@ -872,7 +872,7 @@ public class Cpu implements InstructionTable {
*/
private int lsr(int m) {
setCarryFlag((m & 0x01) != 0);
return (m >>> 1) & 0xff;
return (m & 0xff) >>> 1;
}
/**

View File

@ -583,4 +583,23 @@ public class CpuTest extends TestCase {
cpu.setYRegister(0x95);
assertEquals(0x15, cpu.zpyAddress(0x80));
}
// Test for GitHub symon issue #9, "LSR can yield wrong result"
public void testRightShiftMasksBitsCorrectly() throws Exception {
// Illegal value, the accumulator should only care about the low 8 bytes.
// I'm a little uncomfortable with this test because really, setAccumulator should
// defensively mask the value, but does not. Is this relying on a bug to test another bug?
cpu.setAccumulator(0xff8);
// Sanity check, in case I ever change my mind on setAccumulator's behavior
assertEquals(0xff8, cpu.getAccumulator());
bus.loadProgram(0x4a, // LSR
0x4a); // LSR
cpu.step();
assertEquals(0x7C, cpu.getAccumulator());
cpu.step();
assertEquals(0x3E, cpu.getAccumulator());
}
}