Ejemplo n.º 1
0
        public void WriteBinary(BinaryWriter bw)
        {
            OpCodeDef   ocd  = LangDef.LangDef.GetOpCode(OpCode);
            OperandMode mode = LangDef.LangDef.ModeStringToMode(GetModeText());

            byte[] bytes = ocd.GetBinary(mode);

            WriteBytes(bw, bytes);

            if (!writeFlipped)
            {
                if (LeftOperand != null)
                {
                    LeftOperand.WriteBinary(bw);

                    if (RightOperand != null)
                    {
                        RightOperand.WriteBinary(bw);
                    }
                }
            }
            else
            { //flipped bytes implies two operands
                RightOperand.WriteBinary(bw);
                LeftOperand.WriteBinary(bw);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes out the opcode as hex text along with their op codes
        /// </summary>
        /// <returns></returns>
        public override string AsHextText()
        {
            //write the opcode bytes
            string      s    = "";
            OpCodeDef   ocd  = LangDef.LangDef.GetOpCode(OpCode);
            OperandMode mode = LangDef.LangDef.ModeStringToMode(GetModeText());

            s += ocd.GetHextText(mode);

            if (!writeFlipped)
            {
                if (LeftOperand != null)
                {
                    s += LeftOperand.GetHexText();

                    if (RightOperand != null)
                    {
                        s += RightOperand.GetHexText();
                    }
                }
            }
            else
            { //flipped bytes implies two operands
                s += RightOperand.GetHexText();
                s += LeftOperand.GetHexText();
            }
            return(s);
        }
Ejemplo n.º 3
0
 //returns the bytes for the opcode in the specified mode
 public byte[] GetBinary(OperandMode om)
 {
     if (hexValues.ContainsKey(om))
     {
         return(hexValues[om]);
     }
     throw new Exception("Unable to get binary for opcode " + Name + " in mode " + om.ToString());
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds an addressing mode to an opcode
        /// </summary>
        /// <param name="mode"></param>
        public void AddMode(OperandMode mode, byte[] hexVals)
        {
            if (!modes.Contains(mode))
            {
                modes.Add(mode);
            }

            if (!hexValues.ContainsKey(mode))
            {
                hexValues.Add(mode, hexVals);
            }
        }
Ejemplo n.º 5
0
        static string ToOperandString(OperandMode operandMode, Register reg1, Register reg2, uint value)
        {
            StringBuilder builder = new StringBuilder(24);

            switch ((operandMode & ~OperandMode.ADDRESS))
            {
            case OperandMode.REG:
                builder.Append(ToString(reg1));
                break;

            case OperandMode.IMM:
                builder.Append(value);
                break;

            case OperandMode.IMM_REG:
                builder.Append(value).Append("+").Append(ToString(reg1));
                break;

            case OperandMode.IMM_NREG:
                builder.Append(value).Append("|").Append(ToString(reg1));
                break;

            case OperandMode.IMM_REG_REG:
                builder.Append(value).Append("+").Append(ToString(reg1))
                .Append("+").Append(ToString(reg2));
                break;

            case OperandMode.IMM_REG_NREG:
                builder.Append(value).Append("+").Append(ToString(reg1))
                .Append("|").Append(ToString(reg2));
                break;

            case OperandMode.IMM_NREG_REG:
                builder.Append(value).Append("|").Append(ToString(reg1))
                .Append("+").Append(ToString(reg2));
                break;

            case OperandMode.IMM_NREG_NREG:
                builder.Append(value).Append("|").Append(ToString(reg1))
                .Append("|").Append(ToString(reg2));
                break;

            default:
                throw new ArgumentOutOfRangeException($"Invalid value: {operandMode}");
            }

            if (operandMode.HasFlag(OperandMode.ADDRESS))
            {
                builder.Append("@");
            }

            return(builder.ToString());
Ejemplo n.º 6
0
        /// <summary>
        /// Returns whether or nor an opcode supports an addressing mode
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public bool SupportsMode(string modeStr)
        {
            try
            {
                OperandMode mode = LangDef.ModeStringToMode(modeStr);

                return(modes.Contains(mode));
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public string GetHextText(OperandMode mode)
        {
            string s = "";

            byte[] bytes = hexValues[mode];

            for (int i = 0; i < bytes.Length; i++)
            {
                s += String.Format("{0:X2}", bytes[i]);
            }

            return(s);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds a mode to the opcode def table
        /// </summary>
        /// <param name="opcode"></param>
        /// <param name="mode"></param>
        /// <param name="byte1"></param>
        /// <param name="byte2"></param>
        /// <param name="byte3"></param>
        private static void AddMode(string opcode, OperandMode mode, byte byte1, byte byte2 = 0, byte byte3 = 0)
        {
            byte[] codes;

            if (byte3 != 0 && byte2 != 0)
            {
                codes = new byte[]
                {
                    byte1, byte2, byte3
                };
            }
            else if (byte3 == 0 && byte2 != 0)
            {
                codes = new byte[]
                {
                    byte1, byte2
                };
            }
            else
            {
                codes = new byte[]
                {
                    byte1
                };
            }



            OpCodeDef op = opcodes.Find(
                (o) => { return(o.Name == opcode); }
                );

            if (op == null)
            {
                throw new Exception("Opcode " + opcode + " not found while trying to add mode" + mode.ToString());
            }

            op.AddMode(mode, codes);
        }