Search in sources :

Example 91 with Program

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

the class Mos6502CompilerTest method testAbsoluteYInstructions.

@Property
public void testAbsoluteYInstructions(@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_Y).forEach((opcode) -> {
        final Mos6502Compiler compiler = new Mos6502Compiler(opcode.getOpCodeName() + " " + VALUE_PREFIX + hexWord + ",Y");
        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)

Example 92 with Program

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

the class Mos6502CompilerTest method testIndirectYInstructions.

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

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

the class Mos6502CompilerTest method testSingleDigitArgument.

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

Example 94 with Program

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

the class Mos6502CompilerTest method testProgram.

@Test
public void testProgram() {
    final Mos6502Compiler compiler = new Mos6502Compiler("LDA #$14 ADC #$5 STA $20");
    final Program program = compiler.compileProgram();
    int[] bytes = program.getProgramAsByteArray();
    int[] expected = new int[] { OpCode.LDA_I.getByteValue(), 0x14, OpCode.ADC_I.getByteValue(), 0x5, OpCode.STA_Z.getByteValue(), 0x20 };
    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 95 with Program

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

the class Mos6502CompilerTest method testOversizedValue.

@Test
public void testOversizedValue() {
    try {
        final Mos6502Compiler compiler = new Mos6502Compiler("ADC " + VALUE_PREFIX + "12345");
        Program program = compiler.compileProgram();
        int[] bytes = program.getProgramAsByteArray();
        fail("Argument size over " + 0xFFFF + " 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)

Aggregations

Program (com.rox.emu.processor.mos6502.util.Program)100 Test (org.junit.Test)86 Mos6502Compiler (com.rox.emu.processor.mos6502.util.Mos6502Compiler)32 Property (com.pholser.junit.quickcheck.Property)12 UnknownOpCodeException (com.rox.emu.UnknownOpCodeException)6 Memory (com.rox.emu.mem.Memory)2 SimpleMemory (com.rox.emu.mem.SimpleMemory)2 UnknownTokenException (com.rox.emu.UnknownTokenException)1 RoxWord (com.rox.emu.env.RoxWord)1 AddressingMode (com.rox.emu.processor.mos6502.op.AddressingMode)1 OpCode (com.rox.emu.processor.mos6502.op.OpCode)1 StringTokenizer (java.util.StringTokenizer)1