FieldDisassembler.cpp 40 KB

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