Search in sources :

Example 11 with Mos6502Compiler

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

the class Mos6502CompilerTest method testInvalidValuePrefix.

@Test
public void testInvalidValuePrefix() {
    try {
        final Mos6502Compiler compiler = new Mos6502Compiler("ADC @$10");
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        fail("Invalid value prefix should throw an exception but was " + Arrays.toString(bytes));
    } catch (UnknownOpCodeException e) {
        assertFalse(e.getMessage().isEmpty());
        assertFalse(e.getOpCode() == null);
    }
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) UnknownOpCodeException(com.rox.emu.UnknownOpCodeException) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 12 with Mos6502Compiler

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

the class Mos6502CompilerTest method testZeroPageYInstructions.

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

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

the class Mos6502CompilerTest method testChainedTwoByteInstructions.

@Test
public void testChainedTwoByteInstructions() {
    final Mos6502Compiler compiler = new Mos6502Compiler("LDA " + IMMEDIATE_VALUE_PREFIX + "47 CLC LDA " + IMMEDIATE_VALUE_PREFIX + "10 SEC");
    final Program program = compiler.compileProgram();
    int[] bytes = program.getProgramAsByteArray();
    int[] expected = new int[] { OpCode.LDA_I.getByteValue(), 0x47, OpCode.CLC.getByteValue(), OpCode.LDA_I.getByteValue(), 0x10, OpCode.SEC.getByteValue() };
    assertArrayEquals("Expected: " + Arrays.toString(expected) + ", Got: " + Arrays.toString(bytes), expected, bytes);
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 14 with Mos6502Compiler

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

the class Mos6502CompilerTest method testFullLineCommentRemoval.

@Test
public void testFullLineCommentRemoval() {
    final Mos6502Compiler compiler = new Mos6502Compiler("SEC \n;this should not be parsed\nCLC");
    Program program = compiler.compileProgram();
    int[] bytes = program.getProgramAsByteArray();
    assertEquals(2, bytes.length);
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 15 with Mos6502Compiler

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

the class Mos6502CompilerTest method testAbsoluteXInstructions.

@Property
public void testAbsoluteXInstructions(@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_X).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + VALUE_PREFIX + hexWord + ",X");
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        assertArrayEquals("Output for '" + opcode.toString() + " 0x" + hexWord + "' 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)

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