Search in sources :

Example 6 with Mos6502Compiler

use of com.rox.emu.processor.mos6502.util.Mos6502Compiler in project emuRox by rossdrew.

the class Mos6502CompilerTest method testRelativeNavigationBackwards.

@Test
public void testRelativeNavigationBackwards() {
    final Mos6502Compiler compiler = new Mos6502Compiler("MyLabel: SEC BCS MyLabel");
    final int[] expectedResult = new int[] { OpCode.SEC.getByteValue(), OpCode.BCS.getByteValue(), 0b11111101 };
    final Program program = compiler.compileProgram();
    final int[] actualResult = program.getProgramAsByteArray();
    assertTrue("Expected " + Arrays.toString(expectedResult) + ", got " + Arrays.toString(actualResult), Arrays.equals(actualResult, expectedResult));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 7 with Mos6502Compiler

use of com.rox.emu.processor.mos6502.util.Mos6502Compiler in project emuRox by rossdrew.

the class Mos6502CompilerTest method testAbsoluteInstructions.

@Property
public void testAbsoluteInstructions(@InRange(min = "256", max = "65535") int wordValue) {
    final String hexWord = Integer.toHexString(wordValue);
    final int highByte = (wordValue >> 8) & 0xFF;
    final int lowByte = wordValue & 0xFF;
    OpCode.streamOf(AddressingMode.ABSOLUTE).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + VALUE_PREFIX + hexWord);
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        assertArrayEquals("Output for '" + opcode.toString() + "' was wrong.", new int[] { opcode.getByteValue(), highByte, lowByte }, bytes);
    });
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Property(com.pholser.junit.quickcheck.Property)

Example 8 with Mos6502Compiler

use of com.rox.emu.processor.mos6502.util.Mos6502Compiler in project emuRox by rossdrew.

the class Mos6502CompilerTest method firstInvalidOpcode.

@Test
public void firstInvalidOpcode() {
    final Mos6502Compiler compiler = new Mos6502Compiler("ROX");
    try {
        compiler.compileProgram();
        fail("Exception expected, 'ROX' is an invalid OpCode");
    } catch (UnknownTokenException e) {
        assertTrue(e.getMessage().contains("ROX"));
        assertNotNull(e);
    }
}
Also used : UnknownTokenException(com.rox.emu.UnknownTokenException) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 9 with Mos6502Compiler

use of com.rox.emu.processor.mos6502.util.Mos6502Compiler in project emuRox by rossdrew.

the class Mos6502CompilerTest method testAccumulatorInstructions.

@Property
public void testAccumulatorInstructions(@InRange(min = "0", max = "255") int byteValue) {
    final String hexByte = Integer.toHexString(byteValue);
    OpCode.streamOf(AddressingMode.ACCUMULATOR).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + ACCUMULATOR_PREFIX + hexByte);
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        assertArrayEquals("Output for '" + opcode.toString() + "' was wrong.", new int[] { opcode.getByteValue(), byteValue }, bytes);
    });
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Property(com.pholser.junit.quickcheck.Property)

Example 10 with Mos6502Compiler

use of com.rox.emu.processor.mos6502.util.Mos6502Compiler in project emuRox by rossdrew.

the class Mos6502CompilerTest method testZeroPageInstructions.

@Property
public void testZeroPageInstructions(@InRange(min = "0", max = "255") int byteValue) {
    final String hexByte = Integer.toHexString(byteValue);
    OpCode.streamOf(AddressingMode.ZERO_PAGE).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + VALUE_PREFIX + hexByte);
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        assertArrayEquals("Output for '" + opcode.toString() + "' was wrong.", new int[] { opcode.getByteValue(), byteValue }, bytes);
    });
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Property(com.pholser.junit.quickcheck.Property)

Aggregations

Mos6502Compiler (com.rox.emu.processor.mos6502.util.Mos6502Compiler)36 Program (com.rox.emu.processor.mos6502.util.Program)32 Test (org.junit.Test)25 Property (com.pholser.junit.quickcheck.Property)10 UnknownOpCodeException (com.rox.emu.UnknownOpCodeException)5 UnknownTokenException (com.rox.emu.UnknownTokenException)3 Memory (com.rox.emu.mem.Memory)2 SimpleMemory (com.rox.emu.mem.SimpleMemory)2