public void Append( CommandTree cmd ) { mMainExecutionPath += cmd.ToString(); }
public CommandTree GetPattern( int location, CommandTree cmdTree ) { byte command = MainForm.TheROM[location]; ArrayList list = Commands[command] as ArrayList; int lo, hi, offset=0, offset1=0; string currentCmd = ""; if( list != null ) { if( cmdTree.ToString() == "" ) { cmdTree.Append( string.Format("{0:x6};",location) ); } currentCmd += string.Format("{0:x2}:",command); // command hex currentCmd += list[0].ToString(); // name or command int args = Int32.Parse(list[1].ToString()); if( IsConditionalGotoCommand( command ) ) { lo = MainForm.TheROM[location+1]; hi = MainForm.TheROM[location+2]; offset1 = lo + (hi * 256) - 0x2000 + 0x10; CommandTree tree = new CommandTree(""); cmdTree.AddBranch( GetPattern( offset1, tree)); } else { switch( args ) { case 1: currentCmd += string.Format("({0:x2});",MainForm.TheROM[location+1]); break; case 2: if( list[2].ToString() == "lo") { lo = MainForm.TheROM[location+1]; hi = MainForm.TheROM[location+2]; offset = lo + (hi * 256) - 0x2000 + 0x10; //ret += string.Format("({0:x2}{1:x2});",hi,lo ); currentCmd += string.Format("({0:x4});",offset ); } else { currentCmd += string.Format("({0:x2},{1:x2});", MainForm.TheROM[location+1], MainForm.TheROM[location+2]); } break; case 3: if( list[2].ToString() == "lo") { lo = MainForm.TheROM[location+1]; hi = MainForm.TheROM[location+2]; offset = lo + (hi * 256) - 0x2000 + 0x10; //ret += string.Format("({0:x2}{1:x2}, {2:x2});", // hi, // lo, // MainForm.TheROM[location+2] ); currentCmd += string.Format("({0:x4}, {1:x2});", offset, MainForm.TheROM[location+2] ); } else { currentCmd += string.Format("({0:x2}, {1:x2}, {2:x2});", MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3] ); } break; case 4: lo = MainForm.TheROM[location+3]; hi = MainForm.TheROM[location+4]; offset1 = lo + (hi * 256) + 0x10; /* Calculate the offset */ /*ret = string.Format("{0:x2}-Pass({1:x2} {2:x2}) Branch-{3:x2}{4:x2}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3], MainForm.TheROM[location+4]);*/ currentCmd += string.Format("{0:x2}-Pass({1:x2} {2:x2}) Branch-{3:x4}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], offset); CommandTree t1 = new CommandTree(""); t1 = GetPattern(offset1, t1); cmdTree.AddBranch(t1); break; case 5: lo = MainForm.TheROM[location+4]; hi = MainForm.TheROM[location+5]; offset1 = lo + (hi * 256) + 0x10; /* Calculate the offset */ /*ret = string.Format("{0:x2}-Pass({1:x2} {2:x2} {3:x2} ) Branch-{4:x2}{5:x2}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3], MainForm.TheROM[location+4], MainForm.TheROM[location+5]);*/ currentCmd += string.Format("{0:x2}-Pass({1:x2} {2:x2} {3:x2} ) Branch-{4:x4}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3], offset); CommandTree t2 = new CommandTree(""); t2 = GetPattern(offset1, t2); cmdTree.AddBranch(t2); break; case 6: lo = MainForm.TheROM[location+5]; hi = MainForm.TheROM[location+6]; offset1 = lo + (hi * 256) + 0x10; /* Calculate the offset */ /*ret = string.Format("{0:x2}-Pass({1:x2} {2:x2} {3:x2} {4:x2} ) Branch-{5:x2}{6:x2}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3], MainForm.TheROM[location+4], MainForm.TheROM[location+5], MainForm.TheROM[location+6]);*/ currentCmd += string.Format("{0:x2}-Pass({1:x2} {2:x2} {3:x2} {4:x2} ) Branch-{5:x4}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3], MainForm.TheROM[location+4], offset); CommandTree t3 = new CommandTree(""); t3 = GetPattern(offset1, t3); cmdTree.AddBranch(t3); break; case 7: lo = MainForm.TheROM[location+6]; hi = MainForm.TheROM[location+7]; offset1 = lo + (hi * 0x100) + 0x10; /* Calculate the offset */ /*ret = string.Format("{0:x2}-Pass({1:x2} {2:x2} {3:x2} {4:x2} {5:x2}) Branch-{6:x2}{7:x2}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3], MainForm.TheROM[location+4], MainForm.TheROM[location+5], MainForm.TheROM[location+6], MainForm.TheROM[location+7]);*/ currentCmd += string.Format("{0:x2}-Pass({1:x2} {2:x2} {3:x2} {4:x2} {5:x2}) Branch-{6:x4}:", command, MainForm.TheROM[location+1], MainForm.TheROM[location+2], MainForm.TheROM[location+3], MainForm.TheROM[location+4], MainForm.TheROM[location+5], offset); CommandTree t4 = new CommandTree(""); t4 = GetPattern(offset1, t4); cmdTree.AddBranch(t4); break; } // end switch } if( command == 0xFE ) { byte arg = MainForm.TheROM[location+1]; if( arg >= 0x80 ) { //byte back = (byte)~arg; byte back = (byte)(0xFF - arg +1); currentCmd += string.Format("FE:LoopBack({0:x2});",back); offset = location - back; } else { // still needs work currentCmd += string.Format("FE:LoopForward({0:x2});",arg); offset = location+arg; } } int locNext = 0; if( offset == 0 ) locNext = 1 + location + args; else locNext = offset; // not a goto, not a loopback/loopforward if( command == 0xFE ) { cmdTree.Append(currentCmd); cmdTree = GetPattern( locNext, cmdTree ); } else if( !InfiniteLoop(cmdTree.MainExecutionPath , locNext) ) { cmdTree.Append(currentCmd); cmdTree = GetPattern(locNext, cmdTree ); } //return ret; } return cmdTree; }