Search in sources :

Example 1 with Mos6502Compiler

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

the class Mos6502CompilerTest method testAbsoluteAddressing.

@Test
public void testAbsoluteAddressing() {
    final Mos6502Compiler compiler = new Mos6502Compiler("LDA #$1C STA $100 INC $100");
    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);
    assertEquals(0x1D, memory.getByte(0x100));
}
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 2 with Mos6502Compiler

use of com.rox.emu.processor.mos6502.util.Mos6502Compiler 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 3 with Mos6502Compiler

use of com.rox.emu.processor.mos6502.util.Mos6502Compiler 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 4 with Mos6502Compiler

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

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

the class Mos6502CompilerTest method testChainedTwoByteInstructionsWithLabel.

@Test
public void testChainedTwoByteInstructionsWithLabel() {
    final Mos6502Compiler compiler = new Mos6502Compiler("LDA " + IMMEDIATE_VALUE_PREFIX + "47 LABELA: 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);
    assertEquals(1, program.getLabels().size());
    assertEquals(2, program.getLocationOf("LABELA"));
}
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