FieldControlFlowInstruction.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #pragma once
  19. #include "decompiler/instruction.h"
  20. #include "decompiler/field/FieldEngine.h"
  21. namespace FF7{
  22. /**
  23. * A script flow control instruction.
  24. */
  25. class FF7ControlFlowInstruction : public KernelCallInstruction{
  26. public:
  27. /**
  28. * Create a FF7ControlFlowInstruction.
  29. *
  30. * @return Pointer to the newly created instruction.
  31. */
  32. static InstPtr Create(){return new FF7ControlFlowInstruction();}
  33. /**
  34. * Processes the instruction.
  35. *
  36. * @param func[in] Function to process.
  37. * @param stack[out] Function stack.
  38. * @param engine[in] Engine.
  39. * @param code_gen[in] Code generator.
  40. */
  41. virtual void ProcessInst(
  42. Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
  43. ) override;
  44. private:
  45. /**
  46. * Processes a REQ command.
  47. *
  48. * Opcode: 0x01
  49. * Short name: REQ
  50. * Long name: Request remote execution (asynchronous,
  51. * non-guaranteed)
  52. *
  53. * Memory layout (3 bytes)
  54. * |0x01|E|P/F|
  55. *
  56. * Arguments
  57. * - const UByte E: The ID of the target entity.
  58. * - const Bit[3] P: The priority at which we want to execute the
  59. * remote script (high 3 bits of byte).
  60. * - const Bit[5] F: The ID of the specific member function of E
  61. * to be executed (low 5 bits of byte).
  62. *
  63. * Requests that a remote entity executes one of its member
  64. * functions at a specified priority. The request is asynchronous
  65. * and returns immediately without waiting for the remote
  66. * execution to start or finish. If the specified priority is
  67. * already busy executing, the request will fail silently.
  68. *
  69. * @param codegen[in|out] Code generator to append lines.
  70. * @param engine[in] The engine.
  71. */
  72. void ProcessREQ(CodeGenerator* code_gen, const FieldEngine& engine);
  73. /**
  74. * Processes a REQSW command.
  75. *
  76. * Opcode: 0x02
  77. * Short name: REQSW
  78. * Long name: Request remote execution (asynchronous execution,
  79. * guaranteed)
  80. *
  81. * Memory layout (3 bytes)
  82. * |0x02|E|P/F|
  83. *
  84. * Arguments
  85. * - const UByte E: The ID of the target entity.
  86. * - const Bit[3] P: The priority at which we want to execute the
  87. * remote script (high 3 bits of byte).
  88. * - const Bit[5] F: The ID of the specific member function of E
  89. * tobe executed (low 5 bits of byte).
  90. *
  91. * Requests that a remote entity executes one of its member
  92. * functions at a specified priority. If the specified priority is
  93. * already busy executing, the request will block until it becomes
  94. * available and only then return. The remote execution is still
  95. * carried out asynchronously, with no notification of completion.
  96. *
  97. * @param codegen[in|out] Code generator to append lines.
  98. * @param engine[in] The engine.
  99. */
  100. void ProcessREQSW(CodeGenerator* code_gen, const FieldEngine& engine);
  101. /**
  102. * Processes a REQEW command.
  103. *
  104. * Opcode: 0x03
  105. * Short name: REQEW
  106. * Long name: Request remote execution (synchronous, guaranteed)
  107. *
  108. * Memory layout (3 bytes)
  109. * |0x03|E|P/F|
  110. *
  111. * Arguments
  112. * - const UByte E: The ID of the target entity.
  113. * - const Bit[3] P: The priority at which we want to execute the
  114. * remote script (high 3 bits of byte).
  115. * - const Bit[5] F: The ID of the specific member function of E
  116. * to be executed (low 5 bits of byte).
  117. *
  118. * Requests that a remote entity executes one of its member
  119. * functions at a specified priority. The request will block until
  120. * remote execution has finished before returning.
  121. *
  122. * @param codegen[in|out] Code generator to append lines.
  123. * @param engine[in] The engine.
  124. */
  125. void ProcessREQEW(CodeGenerator* code_gen, const FieldEngine& engine);
  126. /**
  127. * Processes a RETTO command.
  128. *
  129. * Opcode: 0x07
  130. * Short name: RETTO
  131. * Long name: Return To
  132. *
  133. * Memory layout (2 bytes)
  134. * |0x07|P/F|
  135. *
  136. * Arguments
  137. * - const Bit[3] P: The priority at which we want to execute the
  138. * remote script (high 3 bits of byte).
  139. * - const Bit[5] F: The ID of the specific member function of the
  140. * current entity to be executed to (low 5 bits of byte).
  141. *
  142. * Stops the active script loop for this entity and also any
  143. * script loops (except the main) that are queuing to be executed
  144. * after the current script. This is essentially the same as
  145. * adding a RET onto each of the active / queued scripts next
  146. * execution position and returning the current op index to index
  147. * for each script. Then the script control is passed to the
  148. * script F within the current entity with the priority P.
  149. *
  150. * @param codegen[in|out] Code generator to append lines.
  151. */
  152. void ProcessRETTO(CodeGenerator* code_gen);
  153. /**
  154. * Processes a WAIT command.
  155. *
  156. * Opcode: 0x24
  157. * Short name: WAIT
  158. * Long name: Wait
  159. *
  160. * Memory layout (2 bytes)
  161. * |0x24|A|
  162. *
  163. * Arguments
  164. * - const UShort A: Amount (number of frames) to wait.
  165. *
  166. * Pauses current script execution for a specific amount of time.
  167. * Rather than a specific time value in milliseconds/seconds,
  168. * the amount specifies the number of frames that must be drawn
  169. * before execution resumes. Since the game runs at 30fps,
  170. * WAIT(0x1E) (or WAIT(30) in decimal) will pause script execution
  171. * for 1 second, WAIT(0x96) will pause for 5 seconds, and so on.
  172. *
  173. * @param codegen[in|out] Code generator to append lines.
  174. */
  175. void ProcessWAIT(CodeGenerator* code_gen);
  176. };
  177. }