Search in sources :

Example 1 with OpCode

use of com.rox.emu.processor.mos6502.op.OpCode in project emuRox by rossdrew.

the class Mos6502CompilerTest method testImmediateInstructions.

@Property
public void testImmediateInstructions(@InRange(min = "0", max = "255") int byteValue) {
    final String hexByte = Integer.toHexString(byteValue);
    OpCode.streamOf(AddressingMode.IMMEDIATE).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + IMMEDIATE_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)

Example 2 with OpCode

use of com.rox.emu.processor.mos6502.op.OpCode in project emuRox by rossdrew.

the class Mos6502CompilerTest method testTripleDigitArgument.

@Test
public void testTripleDigitArgument() {
    OpCode.streamOf(AddressingMode.ABSOLUTE).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + VALUE_PREFIX + "ABC");
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        assertArrayEquals("Output for '" + opcode.toString() + "' was wrong.", new int[] { opcode.getByteValue(), 0xA, 0xBC }, bytes);
    });
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 3 with OpCode

use of com.rox.emu.processor.mos6502.op.OpCode in project emuRox by rossdrew.

the class Mos6502CompilerTest method testZeroPageXInstructions.

@Property
public void testZeroPageXInstructions(@InRange(min = "0", max = "255") int byteValue) {
    final String hexByte = Integer.toHexString(byteValue);
    OpCode.streamOf(AddressingMode.ZERO_PAGE_X).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + VALUE_PREFIX + hexByte + ",X");
        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 4 with OpCode

use of com.rox.emu.processor.mos6502.op.OpCode 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 5 with OpCode

use of com.rox.emu.processor.mos6502.op.OpCode 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)

Aggregations

Mos6502Compiler (com.rox.emu.processor.mos6502.util.Mos6502Compiler)16 Program (com.rox.emu.processor.mos6502.util.Program)16 Property (com.pholser.junit.quickcheck.Property)10 Test (org.junit.Test)7 OpCode (com.rox.emu.processor.mos6502.op.OpCode)2 UnknownOpCodeException (com.rox.emu.UnknownOpCodeException)1 UnknownTokenException (com.rox.emu.UnknownTokenException)1 RoxWord (com.rox.emu.env.RoxWord)1 AddressingMode (com.rox.emu.processor.mos6502.op.AddressingMode)1