Search in sources :

Example 6 with UnknownOpCodeException

use of com.rox.emu.UnknownOpCodeException 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)

Example 7 with UnknownOpCodeException

use of com.rox.emu.UnknownOpCodeException in project emuRox by rossdrew.

the class OpCodeConverter method getAddressingMode.

/**
 * Extract the {@link Mos6502} {@link AddressingMode} from the {@link String} representation of an {@link OpCode}.
 *
 * @param internalOpCodeName the {@link String} representation of an {@link OpCode}
 * @return An {@link AddressingMode} object that represents the intended addressing mode of the {@link OpCode} in question
 */
public static AddressingMode getAddressingMode(String internalOpCodeName) {
    final String[] tokens = internalOpCodeName.split(OpCode.TOKEN_SEPARATOR);
    if (tokens.length <= OpCode.ADDR_I) {
        // XXX Write this less ugly
        if (EnumSet.of(Operation.JSR, Operation.BPL, Operation.BMI, Operation.BVC, Operation.BVS, Operation.BCC, Operation.BCS, Operation.BNE, Operation.BEQ).contains(getOperation(internalOpCodeName)))
            return AddressingMode.RELATIVE;
        return AddressingMode.IMPLIED;
    }
    final String addressingModeDescriptor = tokens[OpCode.ADDR_I];
    // XXX Not pretty but necessary for proper test coverage - update if JaCoCo ever learns to deal with it
    final String indexToken = (tokens.length <= OpCode.INDX_I) ? "" : tokens[OpCode.INDX_I];
    if ("I".equals(addressingModeDescriptor))
        return AddressingMode.IMMEDIATE;
    else if ("A".equals(addressingModeDescriptor))
        return AddressingMode.ACCUMULATOR;
    else if ("Z".equals(addressingModeDescriptor))
        return withIndexing(AddressingMode.ZERO_PAGE, indexToken);
    else if ("ABS".equals(addressingModeDescriptor))
        return withIndexing(AddressingMode.ABSOLUTE, indexToken);
    else if ("IND".equals(addressingModeDescriptor))
        return withIndexing(AddressingMode.INDIRECT, indexToken);
    else
        throw new UnknownOpCodeException("Unrecognised addressing mode " + addressingModeDescriptor, internalOpCodeName);
}
Also used : UnknownOpCodeException(com.rox.emu.UnknownOpCodeException)

Aggregations

UnknownOpCodeException (com.rox.emu.UnknownOpCodeException)7 Program (com.rox.emu.processor.mos6502.util.Program)6 Mos6502Compiler (com.rox.emu.processor.mos6502.util.Mos6502Compiler)5 Test (org.junit.Test)5