FieldCameraInstruction.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (C) 2022 V-Gears Team
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include "decompiler/instruction/KernelCallInstruction.h"
  19. #include "decompiler/field/FieldEngine.h"
  20. /**
  21. * A camera instruction.
  22. */
  23. class FieldCameraInstruction : public KernelCallInstruction{
  24. public:
  25. /**
  26. * Processes the instruction.
  27. *
  28. * @param[in] func Function to process.
  29. * @param[out] stack Function stack.
  30. * @param[in] engine Engine. Unused
  31. * @param[in,out] code_gen Code generator to append lines.
  32. */
  33. virtual void ProcessInst(
  34. Function& func, ValueStack &stack, Engine* engine, CodeGenerator* code_gen
  35. ) override;
  36. private:
  37. void ProcessNFADE(CodeGenerator* code_gen);
  38. /**
  39. * Prodesses a SCR2D opcode.
  40. *
  41. * Opcode: 0x64
  42. * Short name: SCR2D
  43. * Long name: Scroll 2D
  44. *
  45. * Memory layout (4 bytes)
  46. * |0x64|B1/B2|X|Y|
  47. *
  48. * Arguments
  49. *
  50. * - const Bit[4] B1: Source bank 1, or zero if X is set as a constant value.
  51. * - const Bit[4] B2: Source bank 2, or zero if Y is set as a constant value.
  52. * - const Short X: X-coordinate to scroll to, or address to find X if B1 is non-zero.
  53. * - const Short Y: Y-coordinate to scroll to, or address to find Y if B2 is non-zero.
  54. *
  55. * Instantaneously scrolls the current view to the coordinates found in the arguments (or
  56. * the values found at the addresses if memory banks and address are specified). The move
  57. * to the new coordinates is instant; variants exist for linear and smooth scrolling.
  58. *
  59. * @param[in,out] code_gen Code generator to append lines.
  60. */
  61. void ProcessSCR2D(CodeGenerator* code_gen);
  62. /**
  63. * Processes a SCRLC opcode.
  64. *
  65. * Opcode: 0x62
  66. * Short name: SCRLC
  67. * Long name: Scroll To Playable Character Stop Movement
  68. *
  69. * Memory layout (5 bytes)
  70. * |0x63|B|S|U|T|
  71. *
  72. * Arguments
  73. *
  74. * - const UByte B: PRESUME -> Bank for the scroll speed, or zero if it is specified as a
  75. * literal value. Always zero in game data
  76. * - const UShort S: Speed of the scroll, in frames, or the address to find the speed if B
  77. * is non-zero.
  78. * - const UByte U: Unknown -> Always zero in game data. Seems to affect the speed above.
  79. * - const UByte T: Type of scroll.
  80. *
  81. * Scrolls the current view so that the main playable character is in the center of the
  82. * view. The script executes asynchronously and does not block whilst the camera movement
  83. * is active but returns control to the next script operation. This is tweened over a
  84. * period of S frames. If the main playable character also moves during this time period,
  85. * the tween position is also updated to match the new playable character location. Once
  86. * the camera has completed its movement, the camera NO LONGER follows the main playable
  87. * character's movement. It stays in place.
  88. *
  89. * Scroll Types:
  90. * 2 - Linear.
  91. * 3 - Smooth (QuadraticInAndOut).
  92. */
  93. void ProcessSCRLC(CodeGenerator* code_gen);
  94. /**
  95. * Processes a SCRCC opcode.
  96. *
  97. * Opcode: 0x65
  98. * Short name: SCRCC
  99. * Long name: Scroll To Playable Character
  100. *
  101. * Memory layout (1 byte)
  102. * |0x65|
  103. *
  104. * Instantaneously scrolls the current view so that it is centered on the current playable
  105. * character.
  106. */
  107. void ProcessSCRCC(CodeGenerator* code_gen);
  108. /**
  109. * Processes a SCR2DC opcode.
  110. *
  111. * Opcode: 0x66
  112. * Short name: SCR2DC
  113. * Long name: Scroll to Coordinates (Smooth)
  114. *
  115. * Memory layout (6 bytes)
  116. * |0x66|B1/B2|0/B3|X|Y|S|
  117. *
  118. * Arguments
  119. *
  120. * - const Bit[4] B1: Source bank 1, or zero if X is set as a constant value.
  121. * - const Bit[4] B2: Source bank 2, or zero if Y is set as a constant value.
  122. * - const Bit[4] 0: Zero.
  123. * - const Bit[4] B4: Source bank 3, or zero if S is set as a constant value.
  124. * - const Short X: X-coordinate to scroll to.
  125. * - const Short Y: Y-coordinate to scroll to.
  126. * - const UShort S: Speed to scroll; higher values scroll more slowly.
  127. *
  128. * Similar to SCR2D, except the scroll is not instantaneous and is performed smoothly, with
  129. * a slower start and ending, with speed peaking in the center of the scroll. The overall
  130. * speed can be set with S.
  131. *
  132. * @param[in,out] code_gen Code generator to append lines.
  133. */
  134. void ProcessSCR2DC(CodeGenerator* code_gen);
  135. /**
  136. * Processes a SCR2DL opcode.
  137. *
  138. * Opcode: 0x68
  139. * Short name: SCR2DC
  140. * Long name: Scroll to Coordinates (Linear)
  141. *
  142. * Memory layout (6 bytes)
  143. * |0x68|B1/B2|0/B3|X|Y|S|
  144. *
  145. * Arguments
  146. *
  147. * - const Bit[4] B1: Source bank 1, or zero if X is set as a constant value.
  148. * - const Bit[4] B2: Source bank 2, or zero if Y is set as a constant value.
  149. * - const Bit[4] 0: Zero.
  150. * - const Bit[4] B4: Source bank 3, or zero if S is set as a constant value.
  151. * - const Short X: X-coordinate to scroll to.
  152. * - const Short Y: Y-coordinate to scroll to.
  153. * - const UShort S: Speed to scroll; higher values scroll more slowly.
  154. *
  155. * Similar to SCR2D, except the scroll to the coordinates is linear; that is, the speed is
  156. * constant throughout the duration of the screen scroll.
  157. *
  158. * @param[in,out] code_gen Code generator to append lines.
  159. */
  160. void ProcessSCR2DL(CodeGenerator* code_gen);
  161. /**
  162. * Processes a VWOFT opcode.
  163. *
  164. * Opcode: 0x6A
  165. * Short name: VWOFT
  166. * Long name: View Offset
  167. *
  168. * Memory layout (5 bytes)
  169. * |0x6A|B1/B2|Y|X|S|
  170. *
  171. * Arguments
  172. * - const Bit[4] B1: Bank to retrieve the destination Y offset amount from, or zero if it
  173. * is given as a literal value.
  174. * - const Bit[4]: Bank to retrieve the destination X offset amount from, or zero if it
  175. * is given as a literal value.
  176. * - const Short Y: Amount to offset the camera in the Y coordinate, or the address to
  177. * retrieve it if B1 is non-zero.
  178. * - const Short X: Amount to offset the camera in the X coordinate, or the address to
  179. * retrieve it if B2 is non-zero.
  180. * - const UShort S: Movement speed. Lower values move the camera faster.
  181. *
  182. * Scrolls the current view by the values supplied in X and Y coordinates, instantly.
  183. *
  184. * @param[in,out] code_gen Code generator to append lines.
  185. * @todo Y is the Y coordinate for sure, but I dont't know about X and S.
  186. */
  187. void ProcessVWOFT(CodeGenerator* code_gen);
  188. void ProcessFADE(CodeGenerator* code_gen);
  189. };