private static Dictionary<int, FXAppCmd> GetFXReverseAppCommands(XmlNode attributeNode) { Dictionary<int, FXAppCmd> reverseAppCmds = new Dictionary<int, FXAppCmd>(); XmlNodeList appCmdNodeList = attributeNode.SelectSingleNode("AppCmdList").ChildNodes; //获得应用指令集 foreach (XmlNode appCmdNode in appCmdNodeList) { if (appCmdNode.NodeType == XmlNodeType.Element) { FXAppCmd appCmd = new FXAppCmd(); appCmd.AppCmdType = FXAppCmdType.Normal; appCmd.Comment = appCmdNode.Attributes["comment"].Value; appCmd.FuncNO = Convert.ToInt32(appCmdNode.Attributes["funcNO"].Value); appCmd.Name = appCmdNode.Attributes["name"].Value; appCmd.Group = appCmdNode.Attributes["group"].Value; reverseAppCmds.Add(appCmd.FuncNO, appCmd); } } return reverseAppCmds; }
private static Dictionary<string, IFXCmd> GetFXCommands(XmlNode attributeNode) { Dictionary<string, IFXCmd> cmdList = new Dictionary<string, IFXCmd>(); XmlNodeList basicCmdNodeList = attributeNode.SelectSingleNode("BasicCmdList").ChildNodes; //获得基本指令集 foreach (XmlNode basicCmdNode in basicCmdNodeList) { if (basicCmdNode.NodeType == XmlNodeType.Element) { FXBasicCmd basicCmd = new FXBasicCmd(); basicCmd.Name = basicCmdNode.Attributes["name"].Value; basicCmd.Comment = basicCmdNode.Attributes["comment"].Value; XmlNodeList characterNodeList = basicCmdNode.ChildNodes; foreach (XmlNode characterNode in characterNodeList) { if (characterNode.NodeType == XmlNodeType.Element) { FXBasicCmdCharacter character = new FXBasicCmdCharacter(); character.BasicCmdType = (FXBasicCmdType)Convert.ToInt32(characterNode.Attributes["type"].Value); character.Value = characterNode.Attributes["value"].Value; character.Cmd = basicCmd.Name; if (characterNode.Attributes["adapterType"] != null) character.AdapterType = (FXBasicCmdAdapterType)Convert.ToInt32(characterNode.Attributes["adapterType"].Value); else character.AdapterType = FXBasicCmdAdapterType.NULL; if (characterNode.Attributes["adapter"] != null) character.Adapter = characterNode.Attributes["adapter"].Value; if (characterNode.Attributes["min"] != null) character.Min = Convert.ToInt32(characterNode.Attributes["min"].Value); if (characterNode.Attributes["max"] != null) character.Max = Convert.ToInt32(characterNode.Attributes["max"].Value); basicCmd.Characters.Add(character); } } cmdList.Add(basicCmd.Name, basicCmd); } } XmlNodeList appCmdNodeList = attributeNode.SelectSingleNode("AppCmdList").ChildNodes; //获得应用指令集 foreach (XmlNode appCmdNode in appCmdNodeList) { if (appCmdNode.NodeType == XmlNodeType.Element) { FXAppCmd appCmd = new FXAppCmd(); appCmd.AppCmdType = FXAppCmdType.Normal; appCmd.Comment = appCmdNode.Attributes["comment"].Value; appCmd.FuncNO = Convert.ToInt32(appCmdNode.Attributes["funcNO"].Value); appCmd.Name = appCmdNode.Attributes["name"].Value; appCmd.Group = appCmdNode.Attributes["group"].Value; cmdList.Add(appCmd.Name, appCmd); } } return cmdList; }
/// <summary>根据应用指令的类型生成对应的应用指令符号字符串 /// /// </summary> /// <param name="cmd"></param> /// <returns></returns> private static string GetAppCmdStrByCmdType(FXAppCmd cmd) { if (cmd.AppCmdType == FXAppCmdType.D) return "D" + cmd.Name; if (cmd.AppCmdType == FXAppCmdType.DP) return "D" + cmd.Name + "P"; if (cmd.AppCmdType == FXAppCmdType.P) return cmd.Name + "P"; return cmd.Name; }
private static string ComplieAppCmdStr(FXAppCmd cmd, OperandDetails[] detailsArray, Dictionary<string, FXRegister> registerList) { int funcValue = (cmd.FuncNO + 8) * 2; //命令的值 bool is32bit = false; if (cmd.AppCmdType == FXAppCmdType.D) { funcValue = funcValue + 1; is32bit = true; } if (cmd.AppCmdType == FXAppCmdType.P) { funcValue = funcValue + 0x1000; } if (cmd.AppCmdType == FXAppCmdType.DP) { funcValue = funcValue + 0x1001; is32bit = true; } string valueStr = Utils.FillStringWithChar(funcValue.ToString("X"), FXConfigReader.ZEROCHAR, 4, true); foreach (OperandDetails details in detailsArray) { int valueValue = 0; FXRegisterMN mn = GetRegisterMN(details, registerList, ref valueValue); if (!is32bit) //如果是16bit的 { int valueLow = 0x8000 + 0x100 * mn.M + (valueValue & 0xFF); int valueHigh = 0x8000 + 0x100 * mn.N + ((valueValue & 0xFF00) >> 8); valueStr = valueStr + " " + valueLow.ToString("X") + " " + valueHigh.ToString("X"); } else { int valueLowest = 0x8000 + 0x100 * mn.M + (valueValue & 0xFF); int valueLow = 0x8000 + 0x100 * mn.N + ((valueValue & 0xFF00) >> 8); int valueHigh = 0x8000 + ((valueValue & 0xFF0000) >> 16); int valueHighest = 0x8000 + (int)((valueValue & 0xFF000000) >> 24); valueStr = valueStr + " " + valueLowest.ToString("X") + " " + valueLow.ToString("X") + " " + valueHigh.ToString("X") + " " + valueHighest.ToString("X"); } } return valueStr; }
/// <summary>根据给定的机器码找到对应的应用指令 /// /// </summary> /// <param name="codeArray">机器码数组</param> /// <param name="index">当前的索引</param> /// <param name="reverseAppCmdDict">应用指令功能编号和应用指令对照表</param> /// <returns></returns> private static FXAppCmd GetAppCmd(string[] codeArray, ref int index, Dictionary<int, FXAppCmd> reverseAppCmdDict) { int cmdInt = Convert.ToInt32(codeArray[index], 16); FXAppCmdType cmdType = FXAppCmdType.Normal; if (cmdInt > 0x1000) //如果命令值大于0x1000,那么说明有脉冲成分 { cmdInt = cmdInt - 0x1000; if (cmdInt % 2 == 0) //如果是偶数,那么没有没有32位成分 cmdType = FXAppCmdType.P; else { cmdType = FXAppCmdType.DP; cmdInt--; } } else //没有脉冲成分 { if (cmdInt % 2 == 0) //如果是偶数,那么没有没有32位成分 cmdType = FXAppCmdType.Normal; else { cmdType = FXAppCmdType.D; cmdInt--; } } cmdInt = cmdInt / 2 - 8; if (reverseAppCmdDict.ContainsKey(cmdInt)) { FXAppCmd cmdInDict = reverseAppCmdDict[cmdInt]; FXAppCmd cmd = new FXAppCmd(); cmd.AppCmdType = cmdType; cmd.Comment = cmdInDict.Comment; cmd.FuncNO = cmdInDict.FuncNO; cmd.Group = cmdInDict.Group; cmd.Name = cmdInDict.Name; index++; return cmd; } else return null; }