Search in sources :

Example 1 with AddressingMode

use of com.rox.emu.processor.mos6502.op.AddressingMode in project emuRox by rossdrew.

the class DebuggerWindow method getArgumentCount.

private int getArgumentCount(int instr) {
    final OpCode opCode = OpCode.from(instr);
    final AddressingMode addressingMode = opCode.getAddressingMode();
    return addressingMode.getInstructionBytes() - 1;
}
Also used : OpCode(com.rox.emu.processor.mos6502.op.OpCode) AddressingMode(com.rox.emu.processor.mos6502.op.AddressingMode)

Example 2 with AddressingMode

use of com.rox.emu.processor.mos6502.op.AddressingMode in project emuRox by rossdrew.

the class AddressingModeTest method testValues.

@Test
public void testValues() {
    for (AddressingMode addressingMode : AddressingMode.values()) {
        final String description = addressingMode.getDescription();
        final int bytes = addressingMode.getInstructionBytes();
        assertFalse(description == null || description.isEmpty());
        assertTrue(bytes > 0);
    }
}
Also used : AddressingMode(com.rox.emu.processor.mos6502.op.AddressingMode) Test(org.junit.Test)

Example 3 with AddressingMode

use of com.rox.emu.processor.mos6502.op.AddressingMode in project emuRox by rossdrew.

the class Mos6502Compiler method compileProgram.

/**
 * Extract a compiled {@link Program} from this compiler.
 * This will use the program text contained in this object and attempt to compile it
 *
 * @return A compiled {@link Program} object
 * @throws UnknownOpCodeException if during the course of compilation, we encounter an unknown where we expect an op-code to be
 */
public Program compileProgram() {
    Program workingProgram = new Program();
    final StringTokenizer tokenizer = new StringTokenizer(sanitize(programText));
    while (tokenizer.hasMoreTokens()) {
        final String opCodeToken = tokenizer.nextToken();
        if (LABEL_REGEX.matcher(opCodeToken).matches()) {
            workingProgram = workingProgram.with(opCodeToken.substring(0, opCodeToken.length() - 1));
            continue;
        }
        switch(opCodeToken) {
            // XXX Do these need to work with hard coded values as well
            case "BPL":
            case "BMI":
            case "BVC":
            case "BVS":
            case "BCC":
            case "BCS":
            case "BNE":
            case "BEQ":
            case "JSR":
                workingProgram = workingProgram.with(OpCode.from(opCodeToken).getByteValue());
                final String argToken = tokenizer.nextToken().trim();
                if (Character.isAlphabetic(argToken.charAt(0))) {
                    workingProgram = workingProgram.with(workingProgram.referenceBuilder(argToken));
                } else {
                    throw new UnknownTokenException("Invalid label ('" + argToken + "') specified for " + opCodeToken, opCodeToken);
                }
                break;
            // Opcodes with no arguments
            case "TAX":
            case "TAY":
            case "TYA":
            case "TXA":
            case "TXS":
            case "TXY":
            case "TSX":
            case "PHA":
            case "PLA":
            case "PHP":
            case "PLP":
            case "INY":
            case "DEY":
            case "INX":
            case "DEX":
            case "RTS":
            case "RTI":
            case "SEC":
            case "CLC":
            case "SEI":
            case "SED":
            case "CLD":
            case "CLI":
            case "CLV":
            case "BRK":
            case "NOP":
                workingProgram = workingProgram.with(OpCode.from(opCodeToken).getByteValue());
                break;
            // Opcodes with non label arguments
            case "ADC":
            case "SBC":
            case "LDA":
            case "LDY":
            case "LDX":
            case "AND":
            case "ORA":
            case "EOR":
            case "ASL":
            case "ROL":
            case "LSR":
            case "STY":
            case "STX":
            case "STA":
            case "CMP":
            case "CPX":
            case "CPY":
            case "INC":
            case "DEC":
            case "BIT":
            // Absolute only
            case "JMP":
            case // Accumulator only
            "ROR":
                final String valueToken = tokenizer.nextToken().trim();
                final String prefix = extractFirstOccurrence(ARG_PREFIX_REGEX, valueToken).trim();
                final String value = extractFirstOccurrence(ARG_VALUE_REGEX, valueToken).trim();
                final String postfix = extractFirstOccurrence(ARG_POSTFIX_REGEX, valueToken).trim();
                final AddressingMode addressingMode = getAddressingModeFrom(prefix, value, postfix);
                workingProgram = workingProgram.with(OpCode.from(opCodeToken, addressingMode).getByteValue());
                workingProgram = extractArgumentValue(workingProgram, value);
                break;
            default:
                throw new UnknownTokenException("Unknown token (\"" + opCodeToken + "\") while parsing program", opCodeToken);
        }
    }
    return workingProgram;
}
Also used : StringTokenizer(java.util.StringTokenizer) UnknownTokenException(com.rox.emu.UnknownTokenException) AddressingMode(com.rox.emu.processor.mos6502.op.AddressingMode)

Aggregations

AddressingMode (com.rox.emu.processor.mos6502.op.AddressingMode)3 UnknownTokenException (com.rox.emu.UnknownTokenException)1 OpCode (com.rox.emu.processor.mos6502.op.OpCode)1 StringTokenizer (java.util.StringTokenizer)1 Test (org.junit.Test)1