diff --git a/src/test/java/ca/craigthomas/yacoco3e/components/ByteInstructionTest.java b/src/test/java/ca/craigthomas/yacoco3e/components/ByteInstructionTest.java index d4637e9..c2fa424 100644 --- a/src/test/java/ca/craigthomas/yacoco3e/components/ByteInstructionTest.java +++ b/src/test/java/ca/craigthomas/yacoco3e/components/ByteInstructionTest.java @@ -797,330 +797,5 @@ public void testClearExtendedCorrect() throws MalformedInstructionException { // cpu.decimalAdditionAdjust(); // assertEquals(new UnsignedByte(0xD2), registerSet.getA()); // assertTrue(io.regs.cc.isMasked(CC_C)); -// } - - @Test - public void testGetDirectReadsAddressFromDPAndPC() { - Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); - io.writeByte(0x00BE, 0xCD); - io.writeByte(0xABCD, 0xFF); - regs.pc.set(0xBE); - regs.dp.set(0xAB); - instruction.getDirect(io); - assertEquals(1, instruction.numBytesRead); - assertEquals(0xABCD, instruction.addressRead.getInt()); - assertEquals(0xFF, io.readByte(0xABCD).getShort()); - } - - - @Test - public void testGetImmediateReadsAddressFromPC() { - Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); - io.writeByte(0xBEEE, 0xAB); - regs.pc.set(0xBEEE); - instruction.getImmediate(io); - assertEquals(1, instruction.numBytesRead); - assertEquals(0xAB, instruction.byteRead.getShort()); - assertEquals(0xBEEE, instruction.addressRead.getInt()); - } - - @Test - public void testGetImmediateWordReadsAddressFromPC() { - Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); - instruction.isByteSized = false; - io.writeWord(0xBEEE, 0xABCD); - regs.pc.set(0xBEEE); - instruction.getImmediate(io); - assertEquals(2, instruction.numBytesRead); - assertEquals(0xABCD, instruction.wordRead.getInt()); - assertEquals(0xBEEE, instruction.addressRead.getInt()); - } - - @Test - public void testGetExtendedWorksCorrectly() { - Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", EXTENDED, ByteInstruction::clear); - instruction.isByteSized = false; - io.writeWord(0xBEEE, 0xABCD); - io.writeWord(0xABCD, 0xDEAD); - regs.pc.set(0xBEEE); - instruction.getExtended(io); - assertEquals(2, instruction.numBytesRead); - assertEquals(0xDEAD, instruction.wordRead.getInt()); - assertEquals(0xABCD, instruction.addressRead.getInt()); - } - -// @Test -// public void testGetIndexedZeroOffset() throws MalformedInstructionException { -// Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); -// instruction.getIndexed(io); -// regs.x.set(0xB000); -// io.writeByte(0x0000, 0x84); -// assertEquals(0xB000, instruction.byteRead.getShort()); -// } -// -// @Test -// public void testGetIndexedZeroOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xB000), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x94)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed5BitPositiveOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x01)); -// assertEquals(new UnsignedWord(0xB001), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed5BitNegativeOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x1F)); -// assertEquals(new UnsignedWord(0xAFFF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRPostIncrement() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x80)); -// assertEquals(new UnsignedWord(0xB000), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xB001), regs.x); -// } -// -// @Test -// public void testGetIndexedRPostIncrementTwice() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x81)); -// assertEquals(new UnsignedWord(0xB000), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xB002), regs.x); -// } -// -// @Test -// public void testGetIndexedRPostIncrementTwiceIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xB000), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x91)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xB002), regs.x); -// } -// -// @Test -// public void testGetIndexedRDecrement() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x82)); -// assertEquals(new UnsignedWord(0xAFFF), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xAFFF), regs.x); -// } -// -// @Test -// public void testGetIndexedRDecrementTwice() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x83)); -// assertEquals(new UnsignedWord(0xAFFE), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xAFFE), regs.x); -// } -// -// @Test -// public void testGetIndexedRDecrementTwiceIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xAFFE), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x93)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xAFFE), regs.x); -// } -// -// @Test -// public void testGetIndexedRWithBOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.b.set(new UnsignedByte(0x0B)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x85)); -// assertEquals(new UnsignedWord(0xB00B), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithBOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.b.set(new UnsignedByte(0x0B)); -// io.writeWord(new UnsignedWord(0xB00B), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x95)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithAOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.a.set(new UnsignedByte(0x0A)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x86)); -// assertEquals(new UnsignedWord(0xB00A), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithAOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.a.set(new UnsignedByte(0x0A)); -// io.writeWord(new UnsignedWord(0xB00A), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x96)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitPositiveOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x8802)); -// assertEquals(new UnsignedWord(0xB002), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitNegativeOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x88FE)); -// assertEquals(new UnsignedWord(0xAFFE), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitPositiveOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xB002), new UnsignedWord(0xBEEF)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x9802)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitNegativeOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xAFFE), new UnsignedWord(0xBEEF)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x98FE)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitPositiveOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x89)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0xB200), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitNegativeOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x89)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xAE00), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitPositiveOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xB200), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x99)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitNegativeOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xAE00), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x99)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithDOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.setD(new UnsignedWord(0x0200)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x8B)); -// assertEquals(new UnsignedWord(0xB200), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithDOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.setD(new UnsignedWord(0x0200)); -// io.writeWord(new UnsignedWord(0xB200), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9B)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitPositiveOffset() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x8C0A)); -// assertEquals(new UnsignedWord(0x000C), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitNegativeOffset() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x8CFC)); -// assertEquals(new UnsignedWord(0xFFFE), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitPositiveOffsetIndexed() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x000C), new UnsignedWord(0xBEEF)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x9C0A)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitNegativeOffsetIndexed() throws MalformedInstructionException { -// memory.rom = new short [0x4000]; -// memory.rom[0x3FFC] = (short) 0xBE; -// memory.rom[0x3FFD] = (short) 0xEF; -// -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x9CFA)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitPositiveOffset() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x8D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0x0203), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitNegativeOffset() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x8D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xFE03), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitPositiveOffsetIndexed() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x0203), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitNegativeOffsetIndexed() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0xFE03), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedExtendedIndirect() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0xB000), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9F)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xB000)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test(expected = MalformedInstructionException.class) -// public void testGetIndexedIllegalPostByteExceptionOnRPostIncrement() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x90)); -// io.getIndexed(); -// } -// -// @Test(expected = MalformedInstructionException.class) -// public void testGetIndexedIllegalPostByteExceptionOnRPostDecrement() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x92)); -// io.getIndexed(); // } } diff --git a/src/test/java/ca/craigthomas/yacoco3e/components/InstructionTest.java b/src/test/java/ca/craigthomas/yacoco3e/components/InstructionTest.java index 975240d..19c1d18 100644 --- a/src/test/java/ca/craigthomas/yacoco3e/components/InstructionTest.java +++ b/src/test/java/ca/craigthomas/yacoco3e/components/InstructionTest.java @@ -9,25 +9,19 @@ import org.junit.Test; import static ca.craigthomas.yacoco3e.datatypes.AddressingMode.*; -import static ca.craigthomas.yacoco3e.datatypes.RegisterSet.*; import static org.junit.Assert.*; public class InstructionTest { private IOController io; private RegisterSet regs; - private CPU cpu; - private Memory memory; - private int extendedAddress; @Before public void setUp() { Screen screen = new Screen(1); Cassette cassette = new Cassette(); regs = new RegisterSet(); - memory = new Memory(); + Memory memory = new Memory(); io = new IOController(memory, regs, new EmulatedKeyboard(), screen, cassette); - cpu = new CPU(io); - extendedAddress = 0xC0A0; io.regs.pc.set(0); } @@ -101,276 +95,525 @@ public void testGetIndexedZeroOffset() throws MalformedInstructionException { assertEquals(0xB000, instruction.addressRead.getInt()); } -// @Test -// public void testGetIndexedZeroOffsetIndirect() throws MalformedInstructionException { -// Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(0xB000, 0xBEEF); -// io.writeByte(0x0000, 0x94); -// instruction.getIndexed(io); -// System.out.println(instruction.addressRead); -// assertEquals(1, instruction.numBytesRead); -//// assertEquals(0xB000, instruction.addressRead.getInt()); -// assertEquals(0xBE, instruction.byteRead.getShort()); -// assertEquals(0xBEEF, instruction.wordRead.getInt()); -// assertEquals(0x0001, regs.pc.getInt()); -// } - -// @Test -// public void testGetIndexed5BitPositiveOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x01)); -// assertEquals(new UnsignedWord(0xB001), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed5BitNegativeOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x1F)); -// assertEquals(new UnsignedWord(0xAFFF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRPostIncrement() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x80)); -// assertEquals(new UnsignedWord(0xB000), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xB001), regs.x); -// } -// -// @Test -// public void testGetIndexedRPostIncrementTwice() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x81)); -// assertEquals(new UnsignedWord(0xB000), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xB002), regs.x); -// } -// -// @Test -// public void testGetIndexedRPostIncrementTwiceIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xB000), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x91)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xB002), regs.x); -// } -// -// @Test -// public void testGetIndexedRDecrement() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x82)); -// assertEquals(new UnsignedWord(0xAFFF), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xAFFF), regs.x); -// } -// -// @Test -// public void testGetIndexedRDecrementTwice() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x83)); -// assertEquals(new UnsignedWord(0xAFFE), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xAFFE), regs.x); -// } -// -// @Test -// public void testGetIndexedRDecrementTwiceIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xAFFE), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x93)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// assertEquals(new UnsignedWord(0xAFFE), regs.x); -// } -// -// @Test -// public void testGetIndexedRWithBOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.b.set(new UnsignedByte(0x0B)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x85)); -// assertEquals(new UnsignedWord(0xB00B), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithBOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.b.set(new UnsignedByte(0x0B)); -// io.writeWord(new UnsignedWord(0xB00B), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x95)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithAOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.a.set(new UnsignedByte(0x0A)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x86)); -// assertEquals(new UnsignedWord(0xB00A), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithAOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.a.set(new UnsignedByte(0x0A)); -// io.writeWord(new UnsignedWord(0xB00A), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x96)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitPositiveOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x8802)); -// assertEquals(new UnsignedWord(0xB002), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitNegativeOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x88FE)); -// assertEquals(new UnsignedWord(0xAFFE), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitPositiveOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xB002), new UnsignedWord(0xBEEF)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x9802)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed8BitNegativeOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xAFFE), new UnsignedWord(0xBEEF)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x98FE)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitPositiveOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x89)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0xB200), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitNegativeOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x89)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xAE00), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitPositiveOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xB200), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x99)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexed16BitNegativeOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// io.writeWord(new UnsignedWord(0xAE00), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x99)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithDOffset() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.setD(new UnsignedWord(0x0200)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x8B)); -// assertEquals(new UnsignedWord(0xB200), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedRWithDOffsetIndirect() throws MalformedInstructionException { -// regs.x.set(new UnsignedWord(0xB000)); -// regs.setD(new UnsignedWord(0x0200)); -// io.writeWord(new UnsignedWord(0xB200), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9B)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitPositiveOffset() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x8C0A)); -// assertEquals(new UnsignedWord(0x000C), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitNegativeOffset() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x8CFC)); -// assertEquals(new UnsignedWord(0xFFFE), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitPositiveOffsetIndexed() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x000C), new UnsignedWord(0xBEEF)); -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x9C0A)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith8BitNegativeOffsetIndexed() throws MalformedInstructionException { -// memory.rom = new short [0x4000]; -// memory.rom[0x3FFC] = (short) 0xBE; -// memory.rom[0x3FFD] = (short) 0xEF; -// -// io.writeWord(new UnsignedWord(0x0000), new UnsignedWord(0x9CFA)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitPositiveOffset() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x8D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0x0203), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitNegativeOffset() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x8D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xFE03), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitPositiveOffsetIndexed() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0x0203), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0x0200)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedPCWith16BitNegativeOffsetIndexed() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0xFE03), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9D)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xFE00)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test -// public void testGetIndexedExtendedIndirect() throws MalformedInstructionException { -// io.writeWord(new UnsignedWord(0xB000), new UnsignedWord(0xBEEF)); -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x9F)); -// io.writeWord(new UnsignedWord(0x0001), new UnsignedWord(0xB000)); -// assertEquals(new UnsignedWord(0xBEEF), io.getIndexed().value); -// } -// -// @Test(expected = MalformedInstructionException.class) -// public void testGetIndexedIllegalPostByteExceptionOnRPostIncrement() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x90)); -// io.getIndexed(); -// } -// -// @Test(expected = MalformedInstructionException.class) -// public void testGetIndexedIllegalPostByteExceptionOnRPostDecrement() throws MalformedInstructionException { -// io.writeByte(new UnsignedWord(0x0000), new UnsignedByte(0x92)); -// io.getIndexed(); -// } + @Test + public void testGetIndexedZeroOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeWord(0xB000, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + io.writeByte(0x0000, 0x94); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + } + + @Test + public void testGetIndexed5BitPositiveOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeWord(0xB001, 0xDEAD); + io.writeByte(0x0000, 0x01); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xB001, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + } + + @Test + public void testGetIndexed5BitNegativeOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x1F); + io.writeWord(0xAFFF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xAFFF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + } + + @Test + public void testGetIndexedRPostIncrement() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x80); + io.writeWord(0xB000, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xB000, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB001, regs.x.getInt()); + } + + @Test + public void testGetIndexedRPostIncrementTwice() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x81); + io.writeWord(0xB000, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xB000, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB002, regs.x.getInt()); + } + + @Test + public void testGetIndexedRPostIncrementTwiceIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x91); + io.writeWord(0xB000, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB002, regs.x.getInt()); + } + + @Test + public void testGetIndexedRDecrement() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x82); + io.writeWord(0xAFFF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xAFFF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xAFFF, regs.x.getInt()); + } + + @Test + public void testGetIndexedRDecrementTwice() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x83); + io.writeWord(0xAFFE, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xAFFE, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xAFFE, regs.x.getInt()); + } + + @Test + public void testGetIndexedRDecrementTwiceIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x93); + io.writeWord(0xAFFE, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xAFFE, regs.x.getInt()); + } + + @Test + public void testGetIndexedROnly() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x84); + io.writeWord(0xB000, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xB000, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexedRWithBOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + regs.b.set(0x0B); + io.writeByte(0x0000, 0x85); + io.writeWord(0xB00B, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xB00B, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexedRWithBOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + regs.b.set(0x0B); + io.writeByte(0x0000, 0x95); + io.writeWord(0xB00B, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexedRWithAOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + regs.a.set(0x0A); + io.writeByte(0x0000, 0x86); + io.writeWord(0xB00A, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xB00A, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexedRWithAOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + regs.a.set(0x0A); + io.writeByte(0x0000, 0x96); + io.writeWord(0xB00A, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed8BitPositiveOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeWord(0x0000, 0x8802); + io.writeWord(0xB002, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0xB002, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0002, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed8BitNegativeOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeWord(0x0000, 0x88FE); + io.writeWord(0xAFFE, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0xAFFE, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0002, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed8BitPositiveOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeWord(0x0000, 0x9802); + io.writeWord(0xB002, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0002, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed8BitNegativeOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeWord(0x0000, 0x98FE); + io.writeWord(0xAFFE, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0002, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed16BitPositiveOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x89); + io.writeWord(0x0001, 0x0200); + io.writeWord(0xB200, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0xB200, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0003, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed16BitNegativeOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x89); + io.writeWord(0x0001, 0xFE00); + io.writeWord(0xAE00, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0xAE00, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0003, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed16BitPositiveOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x99); + io.writeWord(0x0001, 0x0200); + io.writeWord(0xB200, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0003, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexed16BitNegativeOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + io.writeByte(0x0000, 0x99); + io.writeWord(0x0001, 0xFE00); + io.writeWord(0xAE00, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0003, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexedRWithDOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + regs.setD(0x0200); + io.writeByte(0x0000, 0x8B); + io.writeWord(0xB200, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xB200, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexedRWithDOffsetIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.x.set(0xB000); + regs.setD(0x0200); + io.writeByte(0x0000, 0x9B); + io.writeWord(0xB200, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(1, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0001, regs.pc.getInt()); + assertEquals(0xB000, regs.x.getInt()); + } + + @Test + public void testGetIndexedPCWith8BitPositiveOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + io.writeWord(0x0000, 0x8C0A); + io.writeWord(0x000C, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0x000C, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0002, regs.pc.getInt()); + } + + @Test + public void testGetIndexedPCWith8BitNegativeOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.pc.set(0x000A); + io.writeWord(0x000A, 0x8CFC); + io.writeWord(0x0008, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0x0008, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x000C, regs.pc.getInt()); + } + + @Test + public void testGetIndexedPCWith8BitPositiveOffsetIndexed() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + io.writeWord(0x0000, 0x9C0A); + io.writeWord(0x000C, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0002, regs.pc.getInt()); + } + + @Test + public void testGetIndexedPCWith8BitNegativeOffsetIndexed() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.pc.set(0x000A); + io.writeWord(0x000A, 0x9CFC); + io.writeWord(0x0008, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(2, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x000C, regs.pc.getInt()); + } + + @Test + public void testGetIndexedPCWith16BitPositiveOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + io.writeByte(0x0000, 0x8D); + io.writeWord(0x0001, 0x0200); + io.writeWord(0x0203, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0x0203, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0003, regs.pc.getInt()); + } + + @Test + public void testGetIndexedPCWith16BitNegativeOffset() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.pc.set(0xA000); + io.writeByte(0xA000, 0x8D); + io.writeWord(0xA001, 0xFE00); + io.writeWord(0x9E03, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0x9E03, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0xA003, regs.pc.getInt()); + } + + @Test + public void testGetIndexedPCWith16BitPositiveOffsetIndexed() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + io.writeByte(0x0000, 0x9D); + io.writeWord(0x0001, 0x0200); + io.writeWord(0x0203, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0003, regs.pc.getInt()); + } + + @Test + public void testGetIndexedPCWith16BitNegativeOffsetIndexed() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + regs.pc.set(0xA000); + io.writeByte(0xA000, 0x9D); + io.writeWord(0xA001, 0xFE00); + io.writeWord(0x9E03, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0xA003, regs.pc.getInt()); + } + + @Test + public void testGetIndexedExtendedIndirect() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + io.writeByte(0x0000, 0x9F); + io.writeWord(0x0001, 0xB000); + io.writeWord(0xB000, 0xBEEF); + io.writeWord(0xBEEF, 0xDEAD); + instruction.getIndexed(io); + assertEquals(3, instruction.numBytesRead); + assertEquals(0xBEEF, instruction.addressRead.getInt()); + assertEquals(0xDE, instruction.byteRead.getShort()); + assertEquals(0xDEAD, instruction.wordRead.getInt()); + assertEquals(0x0003, regs.pc.getInt()); + } + + @Test(expected = MalformedInstructionException.class) + public void testGetIndexedIllegalPostByteExceptionOnRPostIncrement() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + io.writeByte(0x0000, 0x90); + instruction.getIndexed(io); + } + + @Test(expected = MalformedInstructionException.class) + public void testGetIndexedIllegalPostByteExceptionOnRPostDecrement() throws MalformedInstructionException { + Instruction instruction = new ByteInstruction(0x6F, 4, "CLRM", INDEXED, ByteInstruction::clear); + io.writeByte(0x0000, 0x92); + instruction.getIndexed(io); + } }