예제 #1
0
        public static OpcodeDefinition Find(OpcodeByte opcode,
                                            OpcodeByte ext1 = null, OpcodeByte ext2 = null)
        {
            var result = FindInternal(opcode, ext1, ext2);

            //if (result == null &&
            //    ext1 != null && ext1.Value != 0)
            //{
            //    // shift extensions
            //    result = FindInternal(opcode, ext2, OpcodeByte.Empty);
            //}

            return(result);
        }
예제 #2
0
 private static OpcodeDefinition FindInternal(OpcodeByte opcode, OpcodeByte ext1, OpcodeByte ext2)
 {
     if (ext1 != null && ext2 != null)
     {
         return(_twoExtensions[ext2.Value << 16 | ext1.Value << 8 | opcode.Value]);
     }
     else if (ext1 != null && ext2 == null)
     {
         return(_oneExtension[ext1.Value << 8 | opcode.Value]);
     }
     else
     {
         return(_noExtensions[opcode.Value]);
     }
 }
예제 #3
0
 public static UInt16 MakeUInt16(OpcodeByte lsb, OpcodeByte msb)
 {
     return((UInt16)((msb.Value << 8) | lsb.Value));
 }
예제 #4
0
        private bool Process(OpcodeByte opcodeByte)
        {
            if (_opcodeDef == null)
            {
                if (opcodeByte.IsExtension && !HasReversedOffsetParameterOrder)
                {
                    SetExtension(opcodeByte);
                }
                else if (HasReversedOffsetParameterOrder && _tmpOffset == null)
                {
                    _tmpOffset = opcodeByte;
                }
                else
                {
                    _opcodeDef = OpcodeDefinition.Find(opcodeByte, _ext1, _ext2);

                    if (_opcodeDef == null)
                    {
                        throw new NotSupportedException("Illegal opcode:" + opcodeByte.ToString());
                    }

                    if (!_opcodeDef.HasParameters)
                    {
                        Opcode = new SingleByteOpcode(_opcodeDef);
                        IsDone = true;
                    }
                    else
                    {
                        var mbo = new MultiByteOpcode(_opcodeDef);
                        Opcode = mbo;

                        if (_tmpOffset != null)
                        {
                            if (!_opcodeDef.d)
                            {
                                throw new InvalidOperationException(
                                          string.Format("Found a reversed d-offset parameter for opcode {0} but it does not have a d-parameter (true).", _opcodeDef.ToString()));
                            }

                            mbo.AddParameter(_tmpOffset);
                            IsDone = mbo.ParameterCount == _opcodeDef.ParameterCount;
                        }
                    }
                }
            }
            else // parameters
            {
                var mbo = Opcode as MultiByteOpcode;

                if (mbo == null)
                {
                    throw new InvalidOperationException("OpcodeBuilder already produced an Opcode -or- " +
                                                        "you are adding parameters to a SingleCycleOpcode. Did you forget to call Clear?");
                }

                int paramCount = _opcodeDef.ParameterCount;
                mbo.AddParameter(opcodeByte);

                if (mbo.ParameterCount > paramCount)
                {
                    throw new InvalidOperationException("Too many parameters.");
                }

                IsDone = mbo.ParameterCount == paramCount;
            }

            return(Opcode != null);
        }
예제 #5
0
 private static IEnumerable <OpcodeDefinition> FindInternal(OpcodeByte opcode, OpcodeByte ext1, OpcodeByte ext2)
 {
     return(from od in Defintions
            where (ext1 == null && od.Ext1 == 0) || ext1 != null && od.Ext1 == ext1.Value
            where (ext2 == null && od.Ext2 == 0) || ext2 != null && od.Ext2 == ext2.Value
            where od.IsEqualTo(opcode)
            select od);
 }
예제 #6
0
 public void AddParameter(OpcodeByte parameter)
 {
     _parameters.Add(parameter);
     FormatText();
 }