ff7_field_disassembler.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. #include <vector>
  2. #include "ff7_field_disassembler.h"
  3. #include "ff7_field_engine.h"
  4. #include "decompiler_engine.h"
  5. #include <boost/format.hpp>
  6. #include "lzs.h"
  7. #include "make_unique.h"
  8. #include <boost/algorithm/string/split.hpp>
  9. #include <boost/algorithm/string.hpp>
  10. #include "ff7_field_codegen.h"
  11. FF7::FF7Disassembler::FF7Disassembler(SUDM::IScriptFormatter& formatter, FF7FieldEngine* engine, InstVec& insts, const std::vector<unsigned char>& rawScriptData)
  12. : SimpleDisassembler(insts),
  13. mEngine(engine),
  14. mFormatter(formatter)
  15. {
  16. mbFromRaw = true;
  17. kSectionPointersSize = 0; // If loading a raw section then we don't have a "sections header" to skip
  18. auto dataCopy = rawScriptData;
  19. mStream = std::make_unique<BinaryReader>(std::move(dataCopy));
  20. ReadHeader();
  21. }
  22. FF7::FF7Disassembler::FF7Disassembler(SUDM::IScriptFormatter& formatter, FF7FieldEngine *engine, InstVec &insts)
  23. : SimpleDisassembler(insts),
  24. mEngine(engine),
  25. mFormatter(formatter)
  26. {
  27. }
  28. FF7::FF7Disassembler::~FF7Disassembler()
  29. {
  30. }
  31. void FF7::FF7Disassembler::ReadHeader()
  32. {
  33. if (!mbFromRaw)
  34. {
  35. // First read the file section pointers
  36. for (int i = 0; i < kNumSections; i++)
  37. {
  38. mSections[i] = mStream->ReadU32();
  39. }
  40. // Now fix up from PSX RAM pointers to simple file offsets
  41. const uint32 basePtr = mSections[0];
  42. for (int i = 0; i < kNumSections; i++)
  43. {
  44. mSections[i] = (mSections[i] - basePtr) + kSectionPointersSize;
  45. }
  46. // Now seek to the script section
  47. mStream->Seek(mSections[eScript]);
  48. }
  49. // Read the script header
  50. mHeader.Read(*mStream);
  51. mScaleFactor = static_cast<float>(mHeader.mScale) / 512.0f;
  52. }
  53. void FF7::FF7Disassembler::open(const char *filename)
  54. {
  55. // Read all of the file, decompress it, then stuff it into a stream
  56. mStream = std::make_unique<BinaryReader>(Lzs::Decompress(BinaryReader::ReadAll(filename)));
  57. ReadHeader();
  58. }
  59. uint32 FF7::FF7Disassembler::GetEndOfScriptOffset(uint16 curEntryPoint, size_t entityIndex, size_t scriptIndex)
  60. {
  61. uint16 nextEntryPoint = curEntryPoint;
  62. do
  63. {
  64. if (scriptIndex + 1 >= 32)
  65. {
  66. if (entityIndex + 1 >= mHeader.mEntityScripts.size())
  67. {
  68. // This is the very last script, so use the end of its data which is the offset to strings
  69. return mHeader.mOffsetToStrings;
  70. }
  71. else
  72. {
  73. // Wrap around to the next entity
  74. entityIndex++;
  75. scriptIndex = 0;
  76. }
  77. }
  78. else
  79. {
  80. // Get the next script in the same entity
  81. scriptIndex++;
  82. }
  83. nextEntryPoint = mHeader.mEntityScripts[entityIndex][scriptIndex];
  84. } while (nextEntryPoint == curEntryPoint);
  85. return nextEntryPoint;
  86. }
  87. std::unique_ptr<Function> FF7::FF7Disassembler::StartFunction(size_t scriptIndex)
  88. {
  89. auto func = std::make_unique<Function>();
  90. func->_retVal = false;
  91. func->_args = 0;
  92. func->_name = "script_" + std::to_string(scriptIndex);
  93. func->mStartAddr = _address;
  94. return func;
  95. }
  96. struct ScriptInfo
  97. {
  98. uint16 mEntryPoint;
  99. uint32 mNextEntryPoint;
  100. size_t mIndex;
  101. };
  102. void FF7::FF7Disassembler::doDisassemble()
  103. {
  104. // Loop through the scripts for each entity
  105. for (size_t entityNumber = 0; entityNumber < mHeader.mEntityScripts.size(); entityNumber++)
  106. {
  107. std::string strOriginalName = mHeader.mFieldEntityNames[entityNumber].data();
  108. if (strOriginalName.empty())
  109. {
  110. // If the entity name was blank in the file then use a consistent generated name
  111. strOriginalName = "entity_" + std::to_string(entityNumber);
  112. }
  113. const std::string entityName = mFormatter.EntityName(strOriginalName);
  114. // Only parse each script one
  115. std::set<uint16> parsedScripts;
  116. std::vector<ScriptInfo> scriptInfo;
  117. // Collect the scripts to parse
  118. for (size_t scriptIndex = 0; scriptIndex < mHeader.mEntityScripts[entityNumber].size(); scriptIndex++)
  119. {
  120. uint16 scriptEntryPoint = mHeader.mEntityScripts[entityNumber][scriptIndex];
  121. if (parsedScripts.find(scriptEntryPoint) != std::end(parsedScripts))
  122. {
  123. // If we've already parsed this scripts entry point, then don't do it again as it means
  124. // two scripts have the same entry which only seems to be true for "empty" scripts
  125. continue;
  126. }
  127. parsedScripts.insert(scriptEntryPoint);
  128. const uint32 nextScriptEntryPoint = GetEndOfScriptOffset(scriptEntryPoint, entityNumber, scriptIndex);
  129. const uint32 scriptSize = nextScriptEntryPoint - scriptEntryPoint;
  130. if (scriptSize > 0)
  131. {
  132. ScriptInfo info = { scriptEntryPoint, nextScriptEntryPoint, scriptIndex };
  133. scriptInfo.push_back(info);
  134. }
  135. }
  136. for (auto it = scriptInfo.begin(); it != scriptInfo.end(); it++)
  137. {
  138. const bool isStart = it == scriptInfo.begin();
  139. const bool isEnd = it == (--scriptInfo.end());
  140. DisassembleIndivdualScript(entityName, entityNumber, it->mIndex, it->mEntryPoint, it->mNextEntryPoint, isStart, isEnd);
  141. }
  142. }
  143. }
  144. static int FindId(uint32 startAddr, uint32 endAddr, const InstVec& insts)
  145. {
  146. for (const InstPtr& instruction : insts)
  147. {
  148. if (instruction->_address >= startAddr && instruction->_address <= endAddr)
  149. {
  150. if (instruction->_opcode == FF7::eOpcodes::opCodeCHAR)
  151. {
  152. return instruction->_params[0]->getSigned();
  153. }
  154. }
  155. }
  156. return -1;
  157. }
  158. void FF7::FF7Disassembler::AddFunc(
  159. std::string entity_name, size_t entity_index, size_t script_index, uint32 next_script_entry_point,
  160. const bool is_start, bool is_end, bool to_return_only, std::string func_name
  161. ){
  162. bool is_line = false;
  163. std::vector<float> point_a = {0, 0, 0};
  164. std::vector<float> point_b = {0, 0, 0};
  165. const auto SCRIPT_ENTRY_POINT = mStream->Position();
  166. // Read each block of opcodes up to a return.
  167. const size_t old_num_instructions = _insts.size();
  168. // Initialize the function.
  169. std::unique_ptr<Function> func = StartFunction(script_index);
  170. // Read.
  171. if (to_return_only){
  172. // Read opcodes to the end or bail at the first return.
  173. is_line = ReadOpCodesToPositionOrReturn(
  174. next_script_entry_point + kSectionPointersSize, point_a, point_b
  175. );
  176. auto stream_pos = mStream->Position();
  177. const size_t endPos = next_script_entry_point + kSectionPointersSize;
  178. // Can't be the end if there is more data:
  179. if (stream_pos != endPos) is_end = false;
  180. }
  181. else{
  182. // Keep going till we have all of the script, i.e if we bail at a
  183. // return then call again till we have everything
  184. while (mStream->Position() != next_script_entry_point + kSectionPointersSize){
  185. is_line = ReadOpCodesToPositionOrReturn(
  186. next_script_entry_point + kSectionPointersSize, point_a, point_b
  187. );
  188. }
  189. }
  190. // Read metadata, mark start and/or end.
  191. std::string meta_data;
  192. if (is_start && is_end) meta_data = "start_end_";
  193. else if (is_start) meta_data = "start_";
  194. else if (is_end) meta_data = "end_";
  195. const size_t new_num_instructions = _insts.size();
  196. func->mNumInstructions = new_num_instructions - old_num_instructions;
  197. func->mEndAddr = _insts.back()->_address;
  198. if (!func_name.empty()) func->_name = func_name;
  199. if (mEngine->EntityIsLine(entity_index)){
  200. switch (script_index){
  201. // main - on_update
  202. case 0: break;
  203. // [OK] - on_interact
  204. case 1: break;
  205. // Move - on_enter_line
  206. case 2: func->_name = "on_enter_line"; break;
  207. // Move - on_move_to_line
  208. case 3: func->_name = "on_move_to_line"; break;
  209. // Go - on_cross_line
  210. case 4: func->_name = "on_cross_line"; break;
  211. // Go1x - on_cross_line
  212. case 5: func->_name = "on_cross_line_once"; break;
  213. // GoAway - on_leave_line
  214. case 6: func->_name = "on_leave_line"; break;
  215. }
  216. }
  217. int id = FindId(func->mStartAddr, func->mEndAddr, _insts);
  218. // If there is no ID check if there was an ID for this entity in any of
  219. // its other functions and use that instead.
  220. if (id == -1){
  221. for (auto& func : mEngine->_functions){
  222. FunctionMetaData func_meta_data(func.second._metadata);
  223. if (func_meta_data.EntityName() == entity_name && func_meta_data.CharacterId() != -1){
  224. id = func_meta_data.CharacterId();
  225. break;
  226. }
  227. }
  228. }
  229. meta_data += std::to_string(id) + "_" + entity_name;
  230. func->_metadata = meta_data;
  231. mEngine->_functions[SCRIPT_ENTRY_POINT] = *func;
  232. mEngine->AddEntityFunction(entity_name, entity_index, func->_name, script_index);
  233. // If the entity is a line, mark it as so.
  234. if (is_line) mEngine->MarkEntityAsLine(entity_index, true, point_a, point_b);
  235. }
  236. void FF7::FF7Disassembler::DisassembleIndivdualScript(std::string entityName,
  237. size_t entityIndex,
  238. size_t scriptIndex,
  239. size_t scriptEntryPoint,
  240. uint32 nextScriptEntryPoint,
  241. bool isStart,
  242. bool isEnd)
  243. {
  244. scriptEntryPoint += kSectionPointersSize;
  245. mStream->Seek(scriptEntryPoint);
  246. _addressBase = mStream->Position();
  247. _address = _addressBase;
  248. // "Normal" script
  249. if (scriptIndex > 0)
  250. {
  251. if (scriptIndex == 1)
  252. {
  253. AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, isStart, isEnd, false, "on_interact");
  254. }
  255. else
  256. {
  257. AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, isStart, isEnd, false, "");
  258. }
  259. }
  260. else
  261. {
  262. const size_t endPos = nextScriptEntryPoint + kSectionPointersSize;
  263. // Read the init script, which means stop at the first return
  264. AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, isStart, isEnd, true, "on_start");
  265. // Not at the end of this script? Then the remaining data is the "main" script
  266. auto streamPos = mStream->Position();
  267. if (streamPos != endPos)
  268. {
  269. // The "main" script can have more than one return statement
  270. AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, false, isEnd, false, "on_update");
  271. streamPos = mStream->Position();
  272. // But should end exactly on the end pos
  273. if (streamPos != endPos)
  274. {
  275. throw InternalDecompilerError();
  276. }
  277. }
  278. }
  279. }
  280. const FF7::TInstructRecord kOpcodes[] =
  281. {
  282. // Flow
  283. { 1, FF7::eOpcodes::RET, "RET", "", FF7::FF7ControlFlowInstruction::Create },
  284. { 1, FF7::eOpcodes::REQ, "REQ", "BU", FF7::FF7ControlFlowInstruction::Create },
  285. { 1, FF7::eOpcodes::REQSW, "REQSW", "BU", FF7::FF7ControlFlowInstruction::Create },
  286. { 1, FF7::eOpcodes::REQEW, "REQEW", "BU", FF7::FF7ControlFlowInstruction::Create },
  287. { 1, FF7::eOpcodes::NOP, "NOP", "", FF7::FF7NoOperationInstruction::Create },
  288. { 1, FF7::eOpcodes::IFUB, "IFUB", "NNBBBL", FF7::FF7NoOperationInstruction::Create }
  289. };
  290. std::map<std::string, const FF7::TInstructRecord*> FF7::FieldInstructions()
  291. {
  292. // Convert the array to a map that we can query on by mnemonic
  293. std::map<std::string, const TInstructRecord*> mnemonicToInstructionRecords;
  294. for (size_t i = 0; i < boost::size(kOpcodes); i++)
  295. {
  296. mnemonicToInstructionRecords[kOpcodes[i].mMnemonic] = &kOpcodes[i];
  297. }
  298. return mnemonicToInstructionRecords;
  299. }
  300. bool FF7::FF7Disassembler::ReadOpCodesToPositionOrReturn(
  301. size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
  302. ){
  303. bool is_line = false;
  304. std::vector<unsigned int> exitAddrs;
  305. while (mStream->Position() < end_pos){
  306. uint8 opcode = mStream->ReadU8();
  307. uint32 full_opcode = 0;
  308. std::string opcodePrefix;
  309. switch (opcode){
  310. // Flow
  311. OPCODE(eOpcodes::IFUB, "IFUB", FF7CondJumpInstruction, 0, "NBBBB");
  312. OPCODE(eOpcodes::RET, "RET", FF7ControlFlowInstruction, 0, "");
  313. OPCODE(eOpcodes::REQ, "REQ", FF7ControlFlowInstruction, 0, "BU");
  314. OPCODE(eOpcodes::REQSW, "REQSW", FF7ControlFlowInstruction, 0, "BU");
  315. OPCODE(eOpcodes::REQEW, "REQEW", FF7ControlFlowInstruction, 0, "BU");
  316. OPCODE(eOpcodes::PREQ, "PREQ", FF7ControlFlowInstruction, 0, "BU");
  317. OPCODE(eOpcodes::PRQSW, "PRQSW", FF7ControlFlowInstruction, 0, "BU");
  318. OPCODE(eOpcodes::PRQEW, "PRQEW", FF7ControlFlowInstruction, 0, "BU");
  319. OPCODE(eOpcodes::RETTO, "RETTO", FF7ControlFlowInstruction, 0, "U");
  320. OPCODE(eOpcodes::JMPF, "JMPF", FF7UncondJumpInstruction, 0, "B");
  321. OPCODE(eOpcodes::JMPFL, "JMPFL", FF7UncondJumpInstruction, 0, "w");
  322. OPCODE(eOpcodes::JMPB, "JMPB", FF7UncondJumpInstruction, 0, "B");
  323. OPCODE(eOpcodes::JMPBL, "JMPBL", FF7UncondJumpInstruction, 0, "w");
  324. OPCODE(eOpcodes::IFUBL, "IFUBL", FF7CondJumpInstruction, 0, "NBBBw");
  325. OPCODE(eOpcodes::IFSW, "IFSW", FF7CondJumpInstruction, 0, "NwwBB");
  326. OPCODE(eOpcodes::IFSWL, "IFSWL", FF7CondJumpInstruction, 0, "NwwBw");
  327. OPCODE(eOpcodes::IFUW, "IFUW", FF7CondJumpInstruction, 0, "NwwBB");
  328. OPCODE(eOpcodes::IFUWL, "IFUWL", FF7CondJumpInstruction, 0, "NwwBw");
  329. OPCODE(eOpcodes::WAIT, "WAIT", FF7ControlFlowInstruction, 0, "w");
  330. OPCODE(eOpcodes::IFKEY, "IFKEY", FF7CondJumpInstruction, 0, "wB");
  331. OPCODE(eOpcodes::IFKEYON, "IFKEYON", FF7CondJumpInstruction, 0, "wB");
  332. OPCODE(eOpcodes::IFKEYOFF, "IFKEYOFF", FF7CondJumpInstruction, 0, "wB");
  333. OPCODE(eOpcodes::NOP, "NOP", FF7NoOperationInstruction, 0, "");
  334. OPCODE(eOpcodes::IFPRTYQ, "IFPRTYQ", FF7CondJumpInstruction, 0, "BB");
  335. OPCODE(eOpcodes::IFMEMBQ, "IFMEMBQ", FF7CondJumpInstruction, 0, "BB");
  336. // Module
  337. OPCODE(eOpcodes::DSKCG, "DSKCG", FF7ModuleInstruction, 0, "B");
  338. START_SUBOPCODE(eOpcodes::SPECIAL)
  339. OPCODE(eSpecialOpcodes::ARROW, "ARROW", FF7ModuleInstruction, 0, "B");
  340. OPCODE(eSpecialOpcodes::PNAME, "PNAME", FF7ModuleInstruction, 0, "B");
  341. OPCODE(eSpecialOpcodes::GMSPD, "GMSPD", FF7ModuleInstruction, 0, "B");
  342. OPCODE(eSpecialOpcodes::SMSPD, "SMSPD", FF7ModuleInstruction, 0, "BB");
  343. OPCODE(eSpecialOpcodes::FLMAT, "FLMAT", FF7ModuleInstruction, 0, "");
  344. OPCODE(eSpecialOpcodes::FLITM, "FLITM", FF7ModuleInstruction, 0, "");
  345. OPCODE(eSpecialOpcodes::BTLCK, "BTLCK", FF7ModuleInstruction, 0, "B");
  346. OPCODE(eSpecialOpcodes::MVLCK, "MVLCK", FF7ModuleInstruction, 0, "B");
  347. OPCODE(eSpecialOpcodes::SPCNM, "SPCNM", FF7ModuleInstruction, 0, "BB");
  348. OPCODE(eSpecialOpcodes::RSGLB, "RSGLB", FF7ModuleInstruction, 0, "");
  349. OPCODE(eSpecialOpcodes::CLITM, "CLITM", FF7ModuleInstruction, 0, "");
  350. END_SUBOPCODE
  351. OPCODE(eOpcodes::MINIGAME, "MINIGAME", FF7ModuleInstruction, 0, "wsswBB");
  352. OPCODE(eOpcodes::BTMD2, "BTMD2", FF7ModuleInstruction, 0, "d");
  353. OPCODE(eOpcodes::BTRLD, "BTRLD", FF7ModuleInstruction, 0, "NB");
  354. OPCODE(eOpcodes::BTLTB, "BTLTB", FF7ModuleInstruction, 0, "B");
  355. OPCODE(eOpcodes::MAPJUMP, "MAPJUMP", FF7ModuleInstruction, 0, "wsswB");
  356. OPCODE(eOpcodes::LSTMP, "LSTMP", FF7ModuleInstruction, 0, "NB");
  357. OPCODE(eOpcodes::BATTLE, "BATTLE", FF7ModuleInstruction, 0, "Nw");
  358. OPCODE(eOpcodes::BTLON, "BTLON", FF7ModuleInstruction, 0, "B");
  359. OPCODE(eOpcodes::BTLMD, "BTLMD", FF7ModuleInstruction, 0, "w");
  360. OPCODE(eOpcodes::MPJPO, "MPJPO", FF7ModuleInstruction, 0, "B");
  361. OPCODE(eOpcodes::PMJMP, "PMJMP", FF7ModuleInstruction, 0, "w");
  362. OPCODE(eOpcodes::PMJMP2, "PMJMP2", FF7ModuleInstruction, 0, "");
  363. OPCODE(eOpcodes::GAMEOVER, "GAMEOVER", FF7ModuleInstruction, 0, "");
  364. // Math
  365. OPCODE(eOpcodes::PLUS_, "PLUS!", FF7MathInstruction, 0, "NBB");
  366. OPCODE(eOpcodes::PLUS2_, "PLUS2!", FF7MathInstruction, 0, "NBw");
  367. OPCODE(eOpcodes::MINUS_, "MINUS!", FF7MathInstruction, 0, "NBB");
  368. OPCODE(eOpcodes::MINUS2_, "MINUS2!", FF7MathInstruction, 0, "NBw");
  369. OPCODE(eOpcodes::INC_, "INC!", FF7MathInstruction, 0, "BB");
  370. OPCODE(eOpcodes::INC2_, "INC2!", FF7MathInstruction, 0, "BB");
  371. OPCODE(eOpcodes::DEC_, "DEC!", FF7MathInstruction, 0, "BB");
  372. OPCODE(eOpcodes::DEC2_, "DEC2!", FF7MathInstruction, 0, "BB");
  373. OPCODE(eOpcodes::RDMSD, "RDMSD", FF7MathInstruction, 0, "NB");
  374. OPCODE(eOpcodes::SETBYTE, "SETBYTE", FF7MathInstruction, 0, "NBB");
  375. OPCODE(eOpcodes::SETWORD, "SETWORD", FF7MathInstruction, 0, "NBw");
  376. OPCODE(eOpcodes::BITON, "BITON", FF7MathInstruction, 0, "NBB");
  377. OPCODE(eOpcodes::BITOFF, "BITOFF", FF7MathInstruction, 0, "NBB");
  378. OPCODE(eOpcodes::BITXOR, "BITXOR", FF7MathInstruction, 0, "NBB");
  379. OPCODE(eOpcodes::PLUS, "PLUS", FF7MathInstruction, 0, "NBB");
  380. OPCODE(eOpcodes::PLUS2, "PLUS2", FF7MathInstruction, 0, "NBw");
  381. OPCODE(eOpcodes::MINUS, "MINUS", FF7MathInstruction, 0, "NBB");
  382. OPCODE(eOpcodes::MINUS2, "MINUS2", FF7MathInstruction, 0, "NBw");
  383. OPCODE(eOpcodes::MUL, "MUL", FF7MathInstruction, 0, "NBB");
  384. OPCODE(eOpcodes::MUL2, "MUL2", FF7MathInstruction, 0, "NBw");
  385. OPCODE(eOpcodes::DIV, "DIV", FF7MathInstruction, 0, "NBB");
  386. OPCODE(eOpcodes::DIV2, "DIV2", FF7MathInstruction, 0, "NBw");
  387. OPCODE(eOpcodes::MOD, "MOD", FF7MathInstruction, 0, "NBB");
  388. OPCODE(eOpcodes::MOD2, "MOD2", FF7MathInstruction, 0, "NBw");
  389. OPCODE(eOpcodes::AND, "AND", FF7MathInstruction, 0, "NBB");
  390. OPCODE(eOpcodes::AND2, "AND2", FF7MathInstruction, 0, "NBw");
  391. OPCODE(eOpcodes::OR, "OR", FF7MathInstruction, 0, "NBB");
  392. OPCODE(eOpcodes::OR2, "OR2", FF7MathInstruction, 0, "NBw");
  393. OPCODE(eOpcodes::XOR, "XOR", FF7MathInstruction, 0, "NBB");
  394. OPCODE(eOpcodes::XOR2, "XOR2", FF7MathInstruction, 0, "NBw");
  395. OPCODE(eOpcodes::INC, "INC", FF7MathInstruction, 0, "BB");
  396. OPCODE(eOpcodes::INC2, "INC2", FF7MathInstruction, 0, "BB");
  397. OPCODE(eOpcodes::DEC, "DEC", FF7MathInstruction, 0, "BB");
  398. OPCODE(eOpcodes::DEC2, "DEC2", FF7MathInstruction, 0, "BB");
  399. OPCODE(eOpcodes::RANDOM, "RANDOM", FF7MathInstruction, 0, "BB");
  400. OPCODE(eOpcodes::LBYTE, "LBYTE", FF7MathInstruction, 0, "NBB");
  401. OPCODE(eOpcodes::HBYTE, "HBYTE", FF7MathInstruction, 0, "NBw");
  402. OPCODE(eOpcodes::TWOBYTE, "2BYTE", FF7MathInstruction, 0, "NNBBB");
  403. OPCODE(eOpcodes::SIN, "SIN", FF7MathInstruction, 0, "NNwwwB");
  404. OPCODE(eOpcodes::COS, "COS", FF7MathInstruction, 0, "NNwwwB");
  405. // Window
  406. OPCODE(eOpcodes::TUTOR, "TUTOR", FF7WindowInstruction, 0, "B");
  407. OPCODE(eOpcodes::WCLS, "WCLS", FF7WindowInstruction, 0, "B");
  408. OPCODE(eOpcodes::WSIZW, "WSIZW", FF7WindowInstruction, 0, "Bwwww");
  409. OPCODE(eOpcodes::WSPCL, "WSPCL", FF7WindowInstruction, 0, "BBBB");
  410. OPCODE(eOpcodes::WNUMB, "WNUMB", FF7WindowInstruction, 0, "NBwwB"); // NBdB when N == 0
  411. OPCODE(eOpcodes::STTIM, "STTIM", FF7WindowInstruction, 0, "NNBBB");
  412. OPCODE(eOpcodes::MESSAGE, "MESSAGE", FF7WindowInstruction, 0, "BB");
  413. OPCODE(eOpcodes::MPARA, "MPARA", FF7WindowInstruction, 0, "NBBB");
  414. OPCODE(eOpcodes::MPRA2, "MPRA2", FF7WindowInstruction, 0, "NBBw");
  415. OPCODE(eOpcodes::MPNAM, "MPNAM", FF7WindowInstruction, 0, "B");
  416. OPCODE(eOpcodes::ASK, "ASK", FF7WindowInstruction, 0, "NBBBBB");
  417. OPCODE(eOpcodes::MENU, "MENU", FF7WindowInstruction, 0, "NBB");
  418. OPCODE(eOpcodes::MENU2, "MENU2", FF7WindowInstruction, 0, "B");
  419. OPCODE(eOpcodes::WINDOW, "WINDOW", FF7WindowInstruction, 0, "Bwwww");
  420. OPCODE(eOpcodes::WMOVE, "WMOVE", FF7WindowInstruction, 0, "Bss");
  421. OPCODE(eOpcodes::WMODE, "WMODE", FF7WindowInstruction, 0, "BBB");
  422. OPCODE(eOpcodes::WREST, "WREST", FF7WindowInstruction, 0, "B");
  423. OPCODE(eOpcodes::WCLSE, "WCLSE", FF7WindowInstruction, 0, "B");
  424. OPCODE(eOpcodes::WROW, "WROW", FF7WindowInstruction, 0, "BB");
  425. OPCODE(eOpcodes::GWCOL, "GWCOL", FF7WindowInstruction, 0, "NNBBBB");
  426. OPCODE(eOpcodes::SWCOL, "SWCOL", FF7WindowInstruction, 0, "NNBBBB");
  427. // Party
  428. OPCODE(eOpcodes::SPTYE, "SPTYE", FF7PartyInstruction, 0, "NNBBB");
  429. OPCODE(eOpcodes::GTPYE, "GTPYE", FF7PartyInstruction, 0, "NNBBB");
  430. OPCODE(eOpcodes::GOLDU, "GOLDU", FF7PartyInstruction, 0, "Nww"); // Nd when N == 0
  431. OPCODE(eOpcodes::GOLDD, "GOLDD", FF7PartyInstruction, 0, "Nww"); // Nd when N == 0
  432. OPCODE(eOpcodes::CHGLD, "CHGLD", FF7PartyInstruction, 0, "NBB");
  433. OPCODE(eOpcodes::HMPMAX1, "HMPMAX1", FF7PartyInstruction, 0, "");
  434. OPCODE(eOpcodes::HMPMAX2, "HMPMAX2", FF7PartyInstruction, 0, "");
  435. OPCODE(eOpcodes::MHMMX, "MHMMX", FF7PartyInstruction, 0, "");
  436. OPCODE(eOpcodes::HMPMAX3, "HMPMAX3", FF7PartyInstruction, 0, "");
  437. OPCODE(eOpcodes::MPU, "MPU", FF7PartyInstruction, 0, "NBw");
  438. OPCODE(eOpcodes::MPD, "MPD", FF7PartyInstruction, 0, "NBw");
  439. OPCODE(eOpcodes::HPU, "HPU", FF7PartyInstruction, 0, "NBw");
  440. OPCODE(eOpcodes::HPD, "HPD", FF7PartyInstruction, 0, "NBw");
  441. OPCODE(eOpcodes::STITM, "STITM", FF7PartyInstruction, 0, "NwB");
  442. OPCODE(eOpcodes::DLITM, "DLITM", FF7PartyInstruction, 0, "NwB");
  443. OPCODE(eOpcodes::CKITM, "CKITM", FF7PartyInstruction, 0, "NwB");
  444. OPCODE(eOpcodes::SMTRA, "SMTRA", FF7PartyInstruction, 0, "NNBBBB");
  445. OPCODE(eOpcodes::DMTRA, "DMTRA", FF7PartyInstruction, 0, "NNBBBBB");
  446. OPCODE(eOpcodes::CMTRA, "CMTRA", FF7PartyInstruction, 0, "NNNBBBBBB");
  447. OPCODE(eOpcodes::GETPC, "GETPC", FF7PartyInstruction, 0, "NBB");
  448. OPCODE(eOpcodes::PRTYP, "PRTYP", FF7PartyInstruction, 0, "B");
  449. OPCODE(eOpcodes::PRTYM, "PRTYM", FF7PartyInstruction, 0, "B");
  450. OPCODE(eOpcodes::PRTYE, "PRTYE", FF7PartyInstruction, 0, "BBB");
  451. OPCODE(eOpcodes::MMBUD, "MMBUD", FF7PartyInstruction, 0, "BB");
  452. OPCODE(eOpcodes::MMBLK, "MMBLK", FF7PartyInstruction, 0, "B");
  453. OPCODE(eOpcodes::MMBUK, "MMBUK", FF7PartyInstruction, 0, "B");
  454. // Model
  455. OPCODE(eOpcodes::JOIN, "JOIN", FF7ModelInstruction, 0, "B");
  456. OPCODE(eOpcodes::SPLIT, "SPLIT", FF7ModelInstruction, 0, "NNNssBssBB");
  457. OPCODE(eOpcodes::BLINK, "BLINK", FF7ModelInstruction, 0, "B");
  458. OPCODE_BASE(eOpcodes::KAWAI)
  459. {
  460. int length = this->mStream->ReadU8();
  461. assert(length >= 3);
  462. std::ostringstream paramStream;
  463. for (int i = 3; i < length; ++i)
  464. {
  465. paramStream << "B";
  466. }
  467. auto parameters = paramStream.str();
  468. opcode = this->mStream->ReadU8();
  469. switch (opcode)
  470. {
  471. OPCODE(
  472. eKawaiOpcodes::EYETX, "EYETX", FF7ModelInstruction, 0, parameters.c_str()
  473. ); // was BBBB
  474. OPCODE(
  475. eKawaiOpcodes::TRNSP, "TRNSP", FF7ModelInstruction, 0, parameters.c_str()
  476. ); // was B
  477. OPCODE(
  478. eKawaiOpcodes::AMBNT, "AMBNT", FF7ModelInstruction, 0, parameters.c_str()
  479. ); // was BBBBBBB
  480. OPCODE(
  481. eKawaiOpcodes::Unknown03, "Unknown03",
  482. FF7ModelInstruction, 0, parameters.c_str()
  483. );
  484. OPCODE(
  485. eKawaiOpcodes::Unknown04, "Unknown04",
  486. FF7ModelInstruction, 0, parameters.c_str()
  487. );
  488. OPCODE(
  489. eKawaiOpcodes::Unknown05, "Unknown05",
  490. FF7ModelInstruction, 0, parameters.c_str()
  491. );
  492. OPCODE(
  493. eKawaiOpcodes::LIGHT, "LIGHT",FF7ModelInstruction, 0, parameters.c_str()
  494. );
  495. OPCODE(
  496. eKawaiOpcodes::Unknown07, "Unknown07",
  497. FF7ModelInstruction, 0, parameters.c_str()
  498. );
  499. OPCODE(
  500. eKawaiOpcodes::Unknown08, "Unknown08",
  501. FF7ModelInstruction, 0, parameters.c_str()
  502. );
  503. OPCODE(
  504. eKawaiOpcodes::Unknown09, "Unknown09",
  505. FF7ModelInstruction, 0, parameters.c_str()
  506. );
  507. OPCODE(
  508. eKawaiOpcodes::SBOBJ, "SBOBJ",
  509. FF7ModelInstruction, 0, parameters.c_str()
  510. );
  511. OPCODE(
  512. eKawaiOpcodes::Unknown0B, "Unknown0B",
  513. FF7ModelInstruction, 0, parameters.c_str()
  514. );
  515. OPCODE(
  516. eKawaiOpcodes::Unknown0C, "Unknown0C",
  517. FF7ModelInstruction, 0, parameters.c_str()
  518. );
  519. OPCODE(
  520. eKawaiOpcodes::SHINE, "SHINE", FF7ModelInstruction, 0, parameters.c_str()
  521. );
  522. OPCODE(
  523. eKawaiOpcodes::RESET, "RESET", FF7ModelInstruction, 0, parameters.c_str()
  524. );
  525. default:
  526. throw UnknownSubOpcodeException(this->_address, opcode);
  527. }
  528. INC_ADDR;
  529. INC_ADDR;
  530. }
  531. OPCODE_END
  532. OPCODE(eOpcodes::KAWIW, "KAWIW", FF7ModelInstruction, 0, "");
  533. OPCODE(eOpcodes::PMOVA, "PMOVA", FF7ModelInstruction, 0, "B");
  534. OPCODE(eOpcodes::PDIRA, "PDIRA", FF7ModelInstruction, 0, "B");
  535. OPCODE(eOpcodes::PTURA, "PTURA", FF7ModelInstruction, 0, "BBB");
  536. OPCODE(eOpcodes::PGTDR, "PGTDR", FF7ModelInstruction, 0, "NBB");
  537. OPCODE(eOpcodes::PXYZI, "PXYZI", FF7ModelInstruction, 0, "NNBBBBB");
  538. OPCODE(eOpcodes::TLKON, "TLKON", FF7ModelInstruction, 0, "B");
  539. OPCODE(eOpcodes::PC, "PC", FF7ModelInstruction, 0, "B");
  540. OPCODE(eOpcodes::opCodeCHAR, "CHAR", FF7ModelInstruction, 0, "B");
  541. OPCODE(eOpcodes::DFANM, "DFANM", FF7ModelInstruction, 0, "BB");
  542. OPCODE(eOpcodes::ANIME1, "ANIME1", FF7ModelInstruction, 0, "BB");
  543. OPCODE(eOpcodes::VISI, "VISI", FF7ModelInstruction, 0, "B");
  544. OPCODE(eOpcodes::XYZI, "XYZI", FF7ModelInstruction, 0, "NNsssw");
  545. OPCODE(eOpcodes::XYI, "XYI", FF7ModelInstruction, 0, "NNssw");
  546. OPCODE(eOpcodes::XYZ, "XYZ", FF7ModelInstruction, 0, "NNsss");
  547. OPCODE(eOpcodes::MOVE, "MOVE", FF7ModelInstruction, 0, "Nss");
  548. OPCODE(eOpcodes::CMOVE, "CMOVE", FF7ModelInstruction, 0, "Nss");
  549. OPCODE(eOpcodes::MOVA, "MOVA", FF7ModelInstruction, 0, "B");
  550. OPCODE(eOpcodes::TURA, "TURA", FF7ModelInstruction, 0, "BBB");
  551. OPCODE(eOpcodes::ANIMW, "ANIMW", FF7ModelInstruction, 0, "");
  552. OPCODE(eOpcodes::FMOVE, "FMOVE", FF7ModelInstruction, 0, "Nss");
  553. OPCODE(eOpcodes::ANIME2, "ANIME2", FF7ModelInstruction, 0, "BB");
  554. OPCODE(eOpcodes::ANIM_1, "ANIM!1", FF7ModelInstruction, 0, "BB");
  555. OPCODE(eOpcodes::CANIM1, "CANIM1", FF7ModelInstruction, 0, "BBBB");
  556. OPCODE(eOpcodes::CANM_1, "CANM!1", FF7ModelInstruction, 0, "BBBB");
  557. OPCODE(eOpcodes::MSPED, "MSPED", FF7ModelInstruction, 0, "Nw");
  558. OPCODE(eOpcodes::DIR, "DIR", FF7ModelInstruction, 0, "BB");
  559. OPCODE(eOpcodes::TURNGEN, "TURNGEN", FF7ModelInstruction, 0, "NBBBB");
  560. OPCODE(eOpcodes::TURN, "TURN", FF7ModelInstruction, 0, "NBBBB");
  561. OPCODE(eOpcodes::DIRA, "DIRA", FF7ModelInstruction, 0, "B");
  562. OPCODE(eOpcodes::GETDIR, "GETDIR", FF7ModelInstruction, 0, "NBB");
  563. OPCODE(eOpcodes::GETAXY, "GETAXY", FF7ModelInstruction, 0, "NBBB");
  564. OPCODE(eOpcodes::GETAI, "GETAI", FF7ModelInstruction, 0, "NBB");
  565. OPCODE(eOpcodes::ANIM_2, "ANIM!2", FF7ModelInstruction, 0, "BB");
  566. OPCODE(eOpcodes::CANIM2, "CANIM2", FF7ModelInstruction, 0, "BBBB");
  567. OPCODE(eOpcodes::CANM_2, "CANM!2", FF7ModelInstruction, 0, "BBBB");
  568. OPCODE(eOpcodes::ASPED, "ASPED", FF7ModelInstruction, 0, "Nw");
  569. OPCODE(eOpcodes::CC, "CC", FF7ModelInstruction, 0, "B");
  570. OPCODE(eOpcodes::JUMP, "JUMP", FF7ModelInstruction, 0, "NNssww");
  571. OPCODE(eOpcodes::AXYZI, "AXYZI", FF7ModelInstruction, 0, "NNBBBBB");
  572. OPCODE(eOpcodes::LADER, "LADER", FF7ModelInstruction, 0, "NNssswBBBB");
  573. OPCODE(eOpcodes::OFST, "OFST", FF7ModelInstruction, 0, "NNBsssw");
  574. OPCODE(eOpcodes::OFSTW, "OFSTW", FF7ModelInstruction, 0, "");
  575. OPCODE(eOpcodes::TALKR, "TALKR", FF7ModelInstruction, 0, "NB");
  576. OPCODE(eOpcodes::SLIDR, "SLIDR", FF7ModelInstruction, 0, "NB");
  577. OPCODE(eOpcodes::SOLID, "SOLID", FF7ModelInstruction, 0, "B");
  578. OPCODE(eOpcodes::TLKR2, "TLKR2", FF7ModelInstruction, 0, "Nw");
  579. OPCODE(eOpcodes::SLDR2, "SLDR2", FF7ModelInstruction, 0, "Nw");
  580. OPCODE(eOpcodes::CCANM, "CCANM", FF7ModelInstruction, 0, "BBB");
  581. OPCODE(eOpcodes::FCFIX, "FCFIX", FF7ModelInstruction, 0, "B");
  582. OPCODE(eOpcodes::ANIMB, "ANIMB", FF7ModelInstruction, 0, "");
  583. OPCODE(eOpcodes::TURNW, "TURNW", FF7ModelInstruction, 0, "");
  584. // Walkmesh
  585. OPCODE(eOpcodes::SLIP, "SLIP", FF7WalkmeshInstruction, 0, "B");
  586. OPCODE(eOpcodes::UC, "UC", FF7WalkmeshInstruction, 0, "B");
  587. OPCODE(eOpcodes::IDLCK, "IDLCK", FF7WalkmeshInstruction, 0, "wB");
  588. OPCODE(eOpcodes::LINON, "LINON", FF7WalkmeshInstruction, 0, "B");
  589. OPCODE(eOpcodes::SLINE, "SLINE", FF7WalkmeshInstruction, 0, "NNNssssss");
  590. //OPCODE(eOpcodes::LINE, "LINE", FF7WalkmeshInstruction, 0, "ssssss");
  591. // LINE is done like this to save opcode params to the function out params.
  592. case eOpcodes::LINE:
  593. is_line = true;
  594. full_opcode = (full_opcode << 8) + eOpcodes::LINE;
  595. this->_insts.push_back(new FF7WalkmeshInstruction());
  596. (this->_insts.back())->_opcode = full_opcode;
  597. (this->_insts.back())->_address = this->_address;
  598. (this->_insts.back())->_stackChange = 0;
  599. (this->_insts.back())->_name = opcodePrefix + std::string("LINE");
  600. (this->_insts.back())->_codeGenData = "";
  601. this->readParams((this->_insts.back()), "ssssss");
  602. point_a[0] = this->_insts.back()->_params[0]->getSigned();
  603. point_a[1] = this->_insts.back()->_params[1]->getSigned();
  604. point_a[2] = this->_insts.back()->_params[2]->getSigned();
  605. point_b[0] = this->_insts.back()->_params[3]->getSigned();
  606. point_b[1] = this->_insts.back()->_params[4]->getSigned();
  607. point_b[2] = this->_insts.back()->_params[5]->getSigned();
  608. break;
  609. // Backgnd
  610. OPCODE(eOpcodes::BGPDH, "BGPDH", FF7BackgroundInstruction, 0, "NBs");
  611. OPCODE(eOpcodes::BGSCR, "BGSCR", FF7BackgroundInstruction, 0, "NBss");
  612. OPCODE(eOpcodes::MPPAL, "MPPAL", FF7BackgroundInstruction, 0, "NNNBBBBBBB");
  613. OPCODE(eOpcodes::BGON, "BGON", FF7BackgroundInstruction, 0, "NBB");
  614. OPCODE(eOpcodes::BGOFF, "BGOFF", FF7BackgroundInstruction, 0, "NBB");
  615. OPCODE(eOpcodes::BGROL, "BGROL", FF7BackgroundInstruction, 0, "NB");
  616. OPCODE(eOpcodes::BGROL2, "BGROL2", FF7BackgroundInstruction, 0, "NB");
  617. OPCODE(eOpcodes::BGCLR, "BGCLR", FF7BackgroundInstruction, 0, "NB");
  618. OPCODE(eOpcodes::STPAL, "STPAL", FF7BackgroundInstruction, 0, "NBBB");
  619. OPCODE(eOpcodes::LDPAL, "LDPAL", FF7BackgroundInstruction, 0, "NBBB");
  620. OPCODE(eOpcodes::CPPAL, "CPPAL", FF7BackgroundInstruction, 0, "NBBB");
  621. OPCODE(eOpcodes::RTPAL, "RTPAL", FF7BackgroundInstruction, 0, "NNBBBB");
  622. OPCODE(eOpcodes::ADPAL, "ADPAL", FF7BackgroundInstruction, 0, "NNNBBBBBB");
  623. OPCODE(eOpcodes::MPPAL2, "MPPAL2", FF7BackgroundInstruction, 0, "NNNBBBBBB");
  624. OPCODE(eOpcodes::STPLS, "STPLS", FF7BackgroundInstruction, 0, "BBBB");
  625. OPCODE(eOpcodes::LDPLS, "LDPLS", FF7BackgroundInstruction, 0, "BBBB");
  626. OPCODE(eOpcodes::CPPAL2, "CPPAL2", FF7BackgroundInstruction, 0, "BBBBBBB");
  627. OPCODE(eOpcodes::RTPAL2, "RTPAL2", FF7BackgroundInstruction, 0, "BBBBBBB");
  628. OPCODE(eOpcodes::ADPAL2, "ADPAL2", FF7BackgroundInstruction, 0, "BBBBBBBBBB");
  629. // Camera
  630. OPCODE(eOpcodes::NFADE, "NFADE", FF7CameraInstruction, 0, "NNBBBBBB");
  631. OPCODE(eOpcodes::SHAKE, "SHAKE", FF7CameraInstruction, 0, "BBBBBBB");
  632. OPCODE(eOpcodes::SCRLO, "SCRLO", FF7CameraInstruction, 0, "B");
  633. OPCODE(eOpcodes::SCRLC, "SCRLC", FF7CameraInstruction, 0, "BBBB");
  634. OPCODE(eOpcodes::SCRLA, "SCRLA", FF7CameraInstruction, 0, "NwBB");
  635. OPCODE(eOpcodes::SCR2D, "SCR2D", FF7CameraInstruction, 0, "Nss");
  636. OPCODE(eOpcodes::SCRCC, "SCRCC", FF7CameraInstruction, 0, "");
  637. OPCODE(eOpcodes::SCR2DC, "SCR2DC", FF7CameraInstruction, 0, "NNssw");
  638. OPCODE(eOpcodes::SCRLW, "SCRLW", FF7CameraInstruction, 0, "");
  639. OPCODE(eOpcodes::SCR2DL, "SCR2DL", FF7CameraInstruction, 0, "NNssw");
  640. OPCODE(eOpcodes::VWOFT, "VWOFT", FF7CameraInstruction, 0, "NssB");
  641. OPCODE(eOpcodes::FADE, "FADE", FF7CameraInstruction, 0, "NNBBBBBB");
  642. OPCODE(eOpcodes::FADEW, "FADEW", FF7CameraInstruction, 0, "");
  643. OPCODE(eOpcodes::SCRLP, "SCRLP", FF7CameraInstruction, 0, "NwBB");
  644. OPCODE(eOpcodes::MVCAM, "MVCAM", FF7CameraInstruction, 0, "B");
  645. // AV
  646. OPCODE(eOpcodes::BGMOVIE, "BGMOVIE", FF7AudioVideoInstruction, 0, "B");
  647. OPCODE(eOpcodes::AKAO2, "AKAO2", FF7AudioVideoInstruction, 0, "NNNBwwwww");
  648. OPCODE(eOpcodes::MUSIC, "MUSIC", FF7AudioVideoInstruction, 0, "B");
  649. OPCODE(eOpcodes::SOUND, "SOUND", FF7AudioVideoInstruction, 0, "NwB");
  650. OPCODE(eOpcodes::AKAO, "AKAO", FF7AudioVideoInstruction, 0, "NNNBBwwww");
  651. OPCODE(eOpcodes::MUSVT, "MUSVT", FF7AudioVideoInstruction, 0, "B");
  652. OPCODE(eOpcodes::MUSVM, "MUSVM", FF7AudioVideoInstruction, 0, "B");
  653. OPCODE(eOpcodes::MULCK, "MULCK", FF7AudioVideoInstruction, 0, "B");
  654. OPCODE(eOpcodes::BMUSC, "BMUSC", FF7AudioVideoInstruction, 0, "B");
  655. OPCODE(eOpcodes::CHMPH, "CHMPH", FF7AudioVideoInstruction, 0, "BBB");
  656. OPCODE(eOpcodes::PMVIE, "PMVIE", FF7AudioVideoInstruction, 0, "B");
  657. OPCODE(eOpcodes::MOVIE, "MOVIE", FF7AudioVideoInstruction, 0, "");
  658. OPCODE(eOpcodes::MVIEF, "MVIEF", FF7AudioVideoInstruction, 0, "NB");
  659. OPCODE(eOpcodes::FMUSC, "FMUSC", FF7AudioVideoInstruction, 0, "B");
  660. OPCODE(eOpcodes::CMUSC, "CMUSC", FF7AudioVideoInstruction, 0, "BBBBBBB");
  661. OPCODE(eOpcodes::CHMST, "CHMST", FF7AudioVideoInstruction, 0, "NB");
  662. // Uncat
  663. OPCODE(eOpcodes::MPDSP, "MPDSP", FF7UncategorizedInstruction, 0, "B");
  664. OPCODE(eOpcodes::SETX, "SETX", FF7UncategorizedInstruction, 0, "BBBBBB");
  665. OPCODE(eOpcodes::GETX, "GETX", FF7UncategorizedInstruction, 0, "BBBBBB");
  666. OPCODE(eOpcodes::SEARCHX, "SEARCHX", FF7UncategorizedInstruction, 0, "BBBBBBBBBB");
  667. default:
  668. throw UnknownOpcodeException(this->_address, opcode);
  669. }
  670. INC_ADDR;
  671. // Is it within an "if" statement tracking?
  672. InstPtr i = this->_insts.back();
  673. if (i->isCondJump()) exitAddrs.push_back(i->getDestAddress());
  674. if (!exitAddrs.empty())
  675. if (i->_address == exitAddrs.back()) exitAddrs.pop_back();
  676. // Only bail if its the first RET that isn't within an "if" block.
  677. if (full_opcode == eOpcodes::RET && exitAddrs.empty()) return is_line;
  678. }
  679. return is_line;
  680. }