示例#1
0
        private ushort GetOperand(ParsedInstruction currentLine, out Error error)
        {
            if (currentLine.operandExpression == null)
            {
                error = Error.None;
                return(currentLine.operandValue.Value);
            }
            if (currentLine.operandExpression != null)
            {
                StringSection expression = currentLine.operandExpression;

                var result = Assembler.Evaluator.EvaluateExpression(ref expression, currentLine.sourceLine, out error).Value;

                if (error.Code != ErrorCode.None)
                {
                    error = new Error(error, currentLine.sourceLine);
                    return(0);
                }
                else if (!expression.IsNullOrEmpty)
                {
                    error = new Error(ErrorCode.Invalid_Expression, Error.Msg_InvalidExpression, currentLine.sourceLine);
                    return(0);
                }
                return(result);
            }

            error = new Error(ErrorCode.Engine_Error, "Instruction required an operand, but none was present. Instruction may have been mis-parsed.", currentLine.sourceLine);
            return(0);
        }
示例#2
0
        // Todo: Move TryToConvertToZeroPage and FindOpcode to another class, probably assembler.
        // (The only reason they need to be instance methods is for AllowInvalidOpcodes, but this
        //  could also be specified as a parameter).
        public bool TryToConvertToZeroPage(ref ParsedInstruction instruction)
        {
            var op         = Opcode.allOps[instruction.opcode];
            var addressing = op.addressing;

            Opcode.addressing newAddressing = addressing;

            switch (addressing)
            {
            case Opcode.addressing.absolute:
                newAddressing = Opcode.addressing.zeropage;
                break;

            case Opcode.addressing.absoluteIndexedX:
                newAddressing = Opcode.addressing.zeropageIndexedX;
                break;

            case Opcode.addressing.absoluteIndexedY:
                newAddressing = Opcode.addressing.zeropageIndexedY;
                break;
            }

            if (addressing == newAddressing)
            {
                return(false);
            }

            int newOpcode = FindOpcode(op.name, newAddressing);

            if (newOpcode >= 0)
            {
                instruction = new ParsedInstruction(instruction, (byte)newOpcode);
                return(true);
            }
            return(false);
        }
示例#3
0
 static ParsedInstruction()
 {
     Empty = new ParsedInstruction(0xFF, null, -1);
 }
示例#4
0
 public ParsedInstruction(ParsedInstruction oldLine, byte newOpcode)
 {
     this        = oldLine; // Does this work?
     this.opcode = newOpcode;
 }