Skip to content

Commit

Permalink
Add in unit tests for addressing modes
Browse files Browse the repository at this point in the history
  • Loading branch information
craigthomas committed Feb 21, 2025
1 parent e4643c4 commit 4970d3e
Show file tree
Hide file tree
Showing 2 changed files with 522 additions and 604 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// }
}
Loading

0 comments on commit 4970d3e

Please sign in to comment.