FieldMediaInstruction.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * V-Gears
  3. * Copyright (C) 2022 V-Gears Team
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <iostream>
  19. #include <sstream>
  20. #include <boost/format.hpp>
  21. #include "decompiler/field/instruction/FieldMediaInstruction.h"
  22. #include "decompiler/field/FieldEngine.h"
  23. #include "decompiler/field/FieldCodeGenerator.h"
  24. #include "decompiler/field/FieldDisassembler.h"
  25. void FF7::FieldMediaInstruction::ProcessInst(
  26. Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
  27. ){
  28. FunctionMetaData md(func.metadata);
  29. switch (opcode_){
  30. case OPCODES::BGMOVIE: code_gen->WriteTodo(md.GetEntityName(), "BGMOVIE"); break;
  31. case OPCODES::AKAO2: ProcessAKAO2(code_gen); break;
  32. case OPCODES::MUSIC: ProcessMUSIC(code_gen); break;
  33. case OPCODES::SOUND: ProcessSOUND(code_gen); break;
  34. case OPCODES::AKAO: ProcessAKAO(code_gen); break;
  35. case OPCODES::MUSVT: code_gen->WriteTodo(md.GetEntityName(), "MUSVT"); break;
  36. case OPCODES::MUSVM: code_gen->WriteTodo(md.GetEntityName(), "MUSVM"); break;
  37. case OPCODES::MULCK: ProcessMULCK(code_gen); break;
  38. case OPCODES::BMUSC: code_gen->WriteTodo(md.GetEntityName(), "BMUSC"); break;
  39. case OPCODES::CHMPH: code_gen->WriteTodo(md.GetEntityName(), "CHMPH"); break;
  40. case OPCODES::PMVIE: ProcessPMVIE(code_gen); break;
  41. case OPCODES::MOVIE: ProcessMOVIE(code_gen); break;
  42. case OPCODES::MVIEF: ProcessMVIEF(code_gen); break;
  43. case OPCODES::FMUSC: code_gen->WriteTodo(md.GetEntityName(), "FMUSC"); break;
  44. case OPCODES::CMUSC: code_gen->WriteTodo(md.GetEntityName(), "CMUSC"); break;
  45. case OPCODES::CHMST: code_gen->WriteTodo(md.GetEntityName(), "CHMST"); break;
  46. default:
  47. code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
  48. md.GetEntityName(), address_, opcode_
  49. ));
  50. }
  51. }
  52. void FF7::FieldMediaInstruction::ProcessAKAO2(CodeGenerator* code_gen){
  53. FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
  54. const auto& param1 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  55. cg->GetFormatter(), params_[0]->getUnsigned(), params_[7]->getUnsigned()
  56. );
  57. const auto& param2 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  58. cg->GetFormatter(), params_[1]->getUnsigned(), params_[8]->getUnsigned()
  59. );
  60. const auto& param3 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  61. cg->GetFormatter(), params_[2]->getUnsigned(), params_[9]->getUnsigned()
  62. );
  63. const auto& param4 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  64. cg->GetFormatter(), params_[3]->getUnsigned(), params_[10]->getUnsigned()
  65. );
  66. const auto& param5 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  67. cg->GetFormatter(), params_[5]->getUnsigned(), params_[11]->getUnsigned()
  68. );
  69. auto op = params_[6]->getUnsigned();
  70. code_gen->AddOutputLine((
  71. boost::format("-- music:execute_akao(0x%6$02x, %1%, %2%, %3%, %4%, %5%)")
  72. % param1 % param2 % param3 % param4 % param5 % op
  73. ).str());
  74. }
  75. void FF7::FieldMediaInstruction::ProcessMUSIC(CodeGenerator* code_gen){
  76. code_gen->AddOutputLine((
  77. boost::format("-- music:execute_akao(0x10, pointer_to_field_AKAO_%1%)")
  78. % params_[0]->getUnsigned()
  79. ).str());
  80. }
  81. void FF7::FieldMediaInstruction::ProcessSOUND(CodeGenerator* code_gen){
  82. FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
  83. const auto& soundId = FF7::FieldCodeGenerator::FormatValueOrVariable(
  84. cg->GetFormatter(), params_[0]->getUnsigned(), params_[2]->getUnsigned()
  85. );
  86. const auto& panning = FF7::FieldCodeGenerator::FormatValueOrVariable(
  87. cg->GetFormatter(), params_[1]->getUnsigned(), params_[3]->getUnsigned()
  88. );
  89. code_gen->AddOutputLine(
  90. (boost::format("-- music:execute_akao(0x20, %1%, %2%)") % soundId % panning).str()
  91. );
  92. }
  93. void FF7::FieldMediaInstruction::ProcessAKAO(CodeGenerator* code_gen){
  94. FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
  95. const auto& param1 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  96. cg->GetFormatter(), params_[0]->getUnsigned(), params_[7]->getUnsigned()
  97. );
  98. const auto& param2 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  99. cg->GetFormatter(), params_[1]->getUnsigned(), params_[8]->getUnsigned()
  100. );
  101. const auto& param3 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  102. cg->GetFormatter(), params_[2]->getUnsigned(), params_[9]->getUnsigned()
  103. );
  104. const auto& param4 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  105. cg->GetFormatter(), params_[3]->getUnsigned(), params_[10]->getUnsigned()
  106. );
  107. const auto& param5 = FF7::FieldCodeGenerator::FormatValueOrVariable(
  108. cg->GetFormatter(), params_[5]->getUnsigned(), params_[11]->getUnsigned()
  109. );
  110. auto op = params_[6]->getUnsigned();
  111. code_gen->AddOutputLine((
  112. boost::format("-- music:execute_akao(0x%6$02x, %1%, %2%, %3%, %4%, %5%)")
  113. % param1 % param2 % param3 % param4 % param5 % op
  114. ).str());
  115. }
  116. void FF7::FieldMediaInstruction::ProcessMULCK(CodeGenerator* code_gen){
  117. code_gen->AddOutputLine((
  118. boost::format("-- music:lock(%1%)")
  119. % FF7::FieldCodeGenerator::FormatBool(params_[0]->getUnsigned())
  120. ).str());
  121. }
  122. void FF7::FieldMediaInstruction::ProcessPMVIE(CodeGenerator* code_gen){
  123. code_gen->AddOutputLine(
  124. (boost::format("-- field:movie_set(%1%)") % params_[0]->getUnsigned()
  125. ).str());
  126. }
  127. void FF7::FieldMediaInstruction::ProcessMOVIE(CodeGenerator* code_gen){
  128. code_gen->AddOutputLine("-- field:play_movie()");
  129. }
  130. void FF7::FieldMediaInstruction::ProcessMVIEF(CodeGenerator* code_gen){
  131. // TODO: Check for assignment to value.
  132. FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
  133. const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
  134. cg->GetFormatter(), params_[1]->getUnsigned(), params_[2]->getUnsigned());
  135. code_gen->AddOutputLine(
  136. (boost::format("-- %1% = field:get_movie_frame()") % destination).str()
  137. );
  138. }