public AssemblableCommand(CommandTemplate selectedCommand, ApplicationContext context, DataType[] parmsDt, string[] parms) { this.selectedCommand = selectedCommand; this.Context = context; this.parmsDt = parmsDt; this.parms = parms; }
public static int GetCommandLength(ApplicationContext ctx, IMemorizable pointer) { int GetLenghtParms(CommandTemplate lenTemplate) { if (lenTemplate.OpCode.Count(c => c == '$') / 2 == 2) { return (int.Parse( lenTemplate.ParTypes[0].ToString() .Substring(lenTemplate.ParTypes[0].ToString().Length - 2, 2)) / 8 + int.Parse( lenTemplate.ParTypes[1].ToString() .Substring(lenTemplate.ParTypes[1].ToString().Length - 2, 2)) / 8); } if (lenTemplate.OpCode.Count(c => c == '$') / 2 == 0) { return(0); } int np = sbyte.Parse(lenTemplate.OpCode[lenTemplate.OpCode.IndexOf("$") + 3].ToString()) - 1; return (int.Parse( lenTemplate.ParTypes[np].ToString().Substring(lenTemplate.ParTypes[np].ToString().Length - 2, 2)) / 8); } CommandTemplate template = ctx.CommandTemplList.Find(c => c.OpCode.StartsWith(MySupport.ByteArrayToString(pointer.GetValues(0, 1)))); // Params are always attched. string commandNoParms = template.OpCode.Contains("$") ? template.OpCode.Remove(template.OpCode.IndexOf("$")) : template.OpCode; return(commandNoParms.Length / 2 + GetLenghtParms(template)); }
public AssemblableCommand(ApplicationContext ctx, string instruct) { Context = ctx; string cmd = instruct.Split((char)32)[0]; parms = instruct.Split((char)32)[1].Split(','); parmsDt = new DataType[2] { DataType.None, DataType.None }; for (var i = 0; i < parms.Length; i++) { parmsDt[i] = CommandTemplate.GetDTFromArgument(parms[i]); } var parmsDts = new string[2]; for (var i = 0; i < parms.Length; i++) { parmsDts[i] = CommandTemplate.DataTypeToString(parmsDt[i]); } selectedCommand = Context.CommandTemplList.Find( c => c.Name == cmd.Replace(" ", "") && c.ParTypes.SequenceEqual(parmsDt) && this.CheckParSpecific(c, parms)); if (selectedCommand == null) { throw new Exception("No Command matching criteria."); } }
public AssemblableCommand(CommandTemplate cmd, ApplicationContext ctx = null) { selectedCommand = cmd; Context = ctx; }
private bool CheckParSpecific(CommandTemplate c, string[] par) { return(!par.Where((t, i) => c.ParSpecific[i] != t && c.ParSpecific[i] != "any").Any()); }
public static AssemblableCommand Dissassemble(ApplicationContext ctx, IMemorizable pointer) { AssemblableCommand command; int inizioPar = -1; List <CommandTemplate> allcmds = ctx.CommandTemplList.Where(el => { var ret = true; for (var i = 0;; i += 2) { if (pointer.Length < i || el.OpCode.Length <= i || el.OpCode.Substring(i, 2).Contains('$') || !ret) { inizioPar = i; break; } ret = MySupport.ByteArrayToString(pointer.GetValues(i / 2, 1)) == el.OpCode.Substring(i, 2); } return(ret); }).ToList(); if (allcmds.Count > 1) { throw new Exception("Multple commands with a single opCode"); } CommandTemplate template = allcmds[0]; if (!template.OpCode.Contains("$")) { return(new AssemblableCommand(template)); } inizioPar = template.OpCode.IndexOf("$" /*, inizioPar*/); // TOLTO A CASO PERCHE NON ANDAVA int spar = -1; var parms = new string[2]; if (inizioPar != template.OpCode.Length / 2) { int np = sbyte.Parse(template.OpCode[inizioPar + 3].ToString()) - 1; sbyte p2size = sbyte.Parse(template.ParTypes[np].ToString().Substring(template.ParTypes[np].ToString().Length - 2)); p2size /= 8; parms[np] = template.OpCode.Substring(inizioPar + 5, 2) != "le" ? MySupport.ByteArrayToString(pointer.GetValues(inizioPar / 2, p2size)) : MySupport.ByteArrayToString(pointer.GetValues(inizioPar / 2, p2size).Reverse().ToArray()); inizioPar = template.OpCode.IndexOf("$", template.OpCode.IndexOf("$", inizioPar + 1) + 1); spar = inizioPar / 2 + p2size; } // Parameters are always attached. if (inizioPar != template.OpCode.Length / 2 && inizioPar != -1) { int np = sbyte.Parse(template.OpCode[inizioPar + 3].ToString()) - 1; sbyte p2size = sbyte.Parse(template.ParTypes[np].ToString().Substring(template.ParTypes[np].ToString().Length - 2)); p2size /= 8; parms[np] = template.OpCode.Substring(inizioPar + 5, 2) != "le" ? MySupport.ByteArrayToString(pointer.GetValues(spar / 2, p2size)) : MySupport.ByteArrayToString(pointer.GetValues(spar / 2, p2size).Reverse().ToArray()); } command = new AssemblableCommand(template, ctx, template.ParTypes, parms); return(command); }