Dictionary <string, AsmStruct> AsmStructs = new Dictionary <string, AsmStruct>(); //コメントデータ. void ASMMapLoadResource(string fullfilename, ROM rom) { if (!U.IsRequiredFileExist(fullfilename)) { return; } //ユーザが定義したmapファイル using (StreamReader reader = File.OpenText(fullfilename)) { string line; while ((line = reader.ReadLine()) != null) { if (U.IsComment(line) || U.OtherLangLine(line, rom)) { continue; } line = U.ClipComment(line); string[] sp = line.Split('\t'); if (sp.Length <= 1) { continue; } string op = sp[0]; if (op.Length <= 0) { continue; } if (op[0] == '@') {//struct定義 continue; } uint pointer = U.toPointer(U.atoh(op)); if (pointer < 0x02000000) { continue; } if (sp[1].Length <= 0) { continue; } if (sp[1][0] == '@') {//structを利用している if (sp.Length <= 2) { continue; } string[] types = sp[1].Split('@'); if (types.Length <= 1) { continue; } //配列指定. Cとは違い型の方につけます。 @STRUCT@[A] 値は16進数です. uint count = 0; if (types.Length >= 3) { if (types[2].Length <= 0 && types[2][0] != '[') { Debug.Assert(false); continue; } count = U.atoh(U.substr(types[2], 1)); if (count <= 0) { Debug.Assert(false); } } string structName = types[1]; if (!AsmStructs.ContainsKey(structName)) { Debug.Assert(false); continue; } AsmStruct asmSt = AsmStructs[structName]; if (count <= 1) { for (int i = 0; i < asmSt.Nodes.Count; i++) { AsmStructNode node = asmSt.Nodes[i]; AsmMapSt p = new AsmMapSt(); //p.Pointer = pointer; //keyに移動. string name; ParseFuncName(sp, out name); p.Name = structName + "@" + name + "." + node.Name; if (node.TypeName == "") { p.ResultAndArgs = node.Comment; p.TypeName = ""; } else { p.ResultAndArgs = "RET=@" + node.TypeName + " " + node.Comment; p.TypeName = node.TypeName; } AsmMap[pointer + node.Offset] = p; } } else { for (uint n = 0; n < count; n++) { for (int i = 0; i < asmSt.Nodes.Count; i++) { AsmStructNode node = asmSt.Nodes[i]; AsmMapSt p = new AsmMapSt(); string name; ParseFuncName(sp, out name); //p.Pointer = pointer; //keyに移動. p.Name = structName + "@" + name + "[" + n + "]" + "." + node.Name; p.ResultAndArgs = node.Comment; p.TypeName = node.TypeName; AsmMap[pointer + node.Offset] = p; } pointer += asmSt.SizeOf; } } } else if (sp[1][0] == ':') {//範囲指定 絶対指定 if (sp.Length <= 2) { continue; } uint endpointer = U.toPointer(U.atoh(sp[1].Substring(1))); if (endpointer == 0) { Debug.Assert(false); endpointer = pointer; } else if (pointer > endpointer) { Debug.Assert(false); U.Swap(ref pointer, ref endpointer); } AsmMapSt p = new AsmMapSt(); //p.Pointer = pointer; //keyに移動. ParseFuncNamePlus(sp, out p.Name, out p.ResultAndArgs, out p.TypeName); p.Length = endpointer - pointer; AsmMap[pointer] = p; } else {//structを利用していない 範囲してもしない AsmMapSt p = new AsmMapSt(); //p.Pointer = pointer; //keyに移動. ParseFuncNamePlus2(sp, out p.Name, out p.ResultAndArgs, out p.TypeName); TypeToLengthAndName(p, pointer, rom); AsmMap[pointer] = p; } } } }
//Formで作っていた型情報を追加. void ROMTypeLoadResource() { char[] skipTrim = new char[] { ' ', '_' }; Assembly assembly = Assembly.GetExecutingAssembly(); foreach (Type q in assembly.GetTypes()) { if (!q.IsClass) { continue; } if (q.Name.LastIndexOf("Form") == q.Name.Length - 4) { continue; } List <AsmStructNode> structSt = new List <AsmStructNode>(); const BindingFlags FINDS_FLAG = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; FieldInfo[] fields = q.GetFields(FINDS_FLAG); foreach (FieldInfo f in fields) { string name = f.Name; if (name.IndexOf("L_") >= 0 || name.IndexOf("J_") >= 0) { continue; } string prefix = InputFormRef.GetPrefixName(name); uint id = InputFormRef.GetStructID(prefix, name); if (id == U.NOT_FOUND) { continue; } AsmStruct aStruct; string key = q.Name + prefix; if (AsmStructs.ContainsKey(key)) { aStruct = AsmStructs[key]; } else { aStruct = new AsmStruct(); aStruct.Nodes = new List <AsmStructNode>(); AsmStructs[key] = aStruct; } AsmStructNode node; string a = InputFormRef.SkipPrefixName(name, prefix); if (a.Length <= 0) { continue; } else if (a[0] == 'b') { node = new AsmStructNode(); node.Type = AsmStructTypeEnum.b; aStruct.SizeOf = Math.Max(aStruct.SizeOf, id + 1); } else if (a[0] == 'B') { node = new AsmStructNode(); node.Type = AsmStructTypeEnum.B; aStruct.SizeOf = Math.Max(aStruct.SizeOf, id + 1); } else if (a[0] == 'W') { node = new AsmStructNode(); node.Type = AsmStructTypeEnum.W; aStruct.SizeOf = Math.Max(aStruct.SizeOf, id + 2); } else if (a[0] == 'D') { node = new AsmStructNode(); node.Type = AsmStructTypeEnum.D; aStruct.SizeOf = Math.Max(aStruct.SizeOf, id + 4); } else if (a[0] == 'P') { node = new AsmStructNode(); node.Type = AsmStructTypeEnum.P; aStruct.SizeOf = Math.Max(aStruct.SizeOf, id + 4); } else {//不明 continue; } node.Offset = id; node.Name = ""; node.Comment = ""; node.TypeName = ""; string find_jump_name = "J_" + id; string find_label_name = "L_" + id; foreach (FieldInfo ff in fields) { int p = ff.Name.IndexOf(find_jump_name); if (p >= 0) { uint lid = InputFormRef.GetStructID(prefix, name); if (lid != id) { continue; } node.Name = U.substr(ff.Name, p + find_jump_name.Length + 1).Trim(skipTrim); if (node.TypeName.Length < 0) { node.TypeName = node.Name; } continue; } p = ff.Name.IndexOf(find_label_name); if (p >= 0) { uint lid = InputFormRef.GetStructID(prefix, name); if (lid != id) { continue; } string label = U.substr(ff.Name, p + find_label_name.Length + 1).Trim(skipTrim); if (label == "COMBO") { continue; } node.TypeName = label; continue; } } aStruct.Nodes.Add(node); } } }
void ASMMapLoadStruct(string fullfilename, ROM rom) { //ユーザが定義したmapファイル if (!File.Exists(fullfilename)) { Debug.Assert(false); return; } using (StreamReader reader = File.OpenText(fullfilename)) { string line; while ((line = reader.ReadLine()) != null) { if (U.IsComment(line) || U.OtherLangLine(line, rom)) { continue; } line = U.ClipComment(line); string[] sp = line.Split('\t'); if (sp.Length <= 2) { continue; } string op = sp[0]; if (op.Length <= 0) { continue; } if (op[0] != '@') {//struct定義でなければ無視 continue; } string[] st = op.Split('@'); if (st.Length <= 2) { continue; } AsmStruct asmStrict; if (!AsmStructs.ContainsKey(st[1])) { asmStrict = new AsmStruct(); asmStrict.SizeOf = 0; asmStrict.Nodes = new List <AsmStructNode>(); AsmStructs[st[1]] = asmStrict; } else { asmStrict = AsmStructs[st[1]]; } AsmStructNode node = new AsmStructNode(); node.Offset = U.atoh(st[2]); string type = sp[1]; if (type == "short") { asmStrict.SizeOf = Math.Max(asmStrict.SizeOf, node.Offset + 2); node.Type = AsmStructTypeEnum.W; } else if (type == "sbyte") { asmStrict.SizeOf = Math.Max(asmStrict.SizeOf, node.Offset + 1); node.Type = AsmStructTypeEnum.b; } else if (type == "word" || type == "dword") { asmStrict.SizeOf = Math.Max(asmStrict.SizeOf, node.Offset + 4); node.Type = AsmStructTypeEnum.D; } else if (type == "pointer") { asmStrict.SizeOf = Math.Max(asmStrict.SizeOf, node.Offset + 4); node.Type = AsmStructTypeEnum.P; } else if (type.Length > 0 && type[0] == '&') { asmStrict.SizeOf = Math.Max(asmStrict.SizeOf, node.Offset + 4); node.Type = AsmStructTypeEnum.P; node.TypeName = type.Substring(1); } else { asmStrict.SizeOf = Math.Max(asmStrict.SizeOf, node.Offset + 1); node.Type = AsmStructTypeEnum.B; //不明 } node.Name = sp[2]; StringBuilder comment = new StringBuilder(); for (int i = 3; i < sp.Length; i++) { comment.Append(" "); comment.Append(sp[i]); } node.Comment = U.substr(comment.ToString(), 1); asmStrict.Nodes.Add(node); } } }