Search in sources :

Example 16 with Mos6502Compiler

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

the class Mos6502CompilerTest method testIndirectXInstructions.

@Property
public void testIndirectXInstructions(@InRange(min = "0", max = "255") int byteValue) {
    final String hexByte = Integer.toHexString(byteValue);
    OpCode.streamOf(AddressingMode.INDIRECT_X).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " (" + VALUE_PREFIX + hexByte + ",X)");
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        assertArrayEquals(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 17 with Mos6502Compiler

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

the class Mos6502CompilerTest method testIntegration.

@Test
public void testIntegration() {
    final Mos6502Compiler compiler = new Mos6502Compiler("LDA #$14 ADC #$5 STA $20");
    Program program = compiler.compileProgram();
    final int[] programByte = program.getProgramAsByteArray();
    Memory memory = new SimpleMemory();
    Mos6502 processor = new Mos6502(memory);
    processor.reset();
    memory.setBlock(0, programByte);
    processor.step(3);
    Registers registers = processor.getRegisters();
    assertEquals(0x19, registers.getRegister(Registers.Register.ACCUMULATOR));
    assertEquals(0x19, memory.getByte(0x20));
    assertEquals(programByte.length, registers.getPC());
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) SimpleMemory(com.rox.emu.mem.SimpleMemory) Memory(com.rox.emu.mem.Memory) SimpleMemory(com.rox.emu.mem.SimpleMemory) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 18 with Mos6502Compiler

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

the class Mos6502CompilerTest method opCode2JaCoCoCoverage.

@Test
public void opCode2JaCoCoCoverage() {
    final Mos6502Compiler compiler = new Mos6502Compiler("\0BRK");
    try {
        compiler.compileProgram();
        fail("Exception expected.  This should not pass a String switch statement");
    } catch (UnknownTokenException e) {
        assertTrue(e.getMessage().contains("\0BRK"));
        assertNotNull(e);
    }
}
Also used : UnknownTokenException(com.rox.emu.UnknownTokenException) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

Example 19 with Mos6502Compiler

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

the class DebuggerWindow method compile.

public void compile(String programText) {
    final Mos6502Compiler compiler = new Mos6502Compiler(programText);
    try {
        final Program program = compiler.compileProgram();
        final int[] programAsByteArray = program.getProgramAsByteArray();
        loadProgram(programAsByteArray);
    } catch (UnknownOpCodeException e) {
        JOptionPane.showMessageDialog(this, e.getMessage());
    }
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) UnknownOpCodeException(com.rox.emu.UnknownOpCodeException) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler)

Example 20 with Mos6502Compiler

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

the class Mos6502CompilerTest method testLabelExtractionInCompilation.

@Test
public void testLabelExtractionInCompilation() {
    final Mos6502Compiler compiler = new Mos6502Compiler("MyLabel: SEC");
    final Program program = compiler.compileProgram();
    assertEquals(1, program.getLabels().size());
    assertEquals(0, program.getLocationOf("MyLabel"));
}
Also used : Program(com.rox.emu.processor.mos6502.util.Program) Mos6502Compiler(com.rox.emu.processor.mos6502.util.Mos6502Compiler) Test(org.junit.Test)

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