FieldControlFlowInstruction.h 6.8 KB

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