FieldWindowInstruction.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 window instruction.
  22. */
  23. class FieldWindowInstruction : public KernelCallInstruction{
  24. public:
  25. /**
  26. * Processes the instruction.
  27. *
  28. * @param[in] func Function to process.
  29. * @param[out] stack Function stack. Unused.
  30. * @param[in] engine Engine.
  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. /**
  38. * Processes a STTIM opcode.
  39. *
  40. * Opcode: 0x38
  41. * Short name: STTIM
  42. * Long name: Set Timer
  43. *
  44. * Memory layout (6 bytes)
  45. * |0x38|B1/B2|0/B3|H|M|S|
  46. *
  47. * Arguments
  48. * - const Bit[4] B1: Bank to find hours value, or zero if hours (B1) is passed as a value.
  49. * - const Bit[4] B2: Bank to find minutes value, or zero if minutes (B2) is passed as a
  50. * value.
  51. * - const Bit[4] 0: Zero.
  52. * - const Bit[4] B3: Bank to find seconds value, or zero if seconds (B3) is passed as a
  53. * value.
  54. * - const UByte H: Hours, or address to find hours value, if B1 is non-zero.
  55. * - const UByte M: Minutes, or address to find minutes value, if B2 is non-zero.
  56. * - const UByte S: Seconds, or address to find seconds value, if B3 is non-zero.
  57. *
  58. * Sets the clock, as found in the WSPCL opcode. If the hours, minutes or seconds are
  59. * specified in the argument, the corresponding B nybble is zero. Otherwise, the value for
  60. * the time component is retrieved from the bank and address specified. The separate time
  61. * components can be retrieved from memory or specified as a value, in the same argument
  62. * list. Hours are not directly visible on the clock, as it only displays minutes and
  63. * seconds. Hours are translated into minutes.
  64. *
  65. * @param[in,out] code_gen Code generator to append lines.
  66. */
  67. void ProcessSTTIM(CodeGenerator* code_gen);
  68. void ProcessMESSAGE(CodeGenerator* code_gen, const std::string& script_name);
  69. /**
  70. * Processes an ASK opcode.
  71. *
  72. * Opcode: 0x48
  73. * Short name: ASK
  74. * Long name: Ask Question
  75. *
  76. * Memory layout (7 bytes)
  77. * |0x48|Bank|Win|Mess|First|Last|Addr|
  78. *
  79. * Arguments
  80. *
  81. * const UByte Bank: Bank to put line number selected.
  82. * const UByte Win: Window ID to place the question in. (Initialized with WINDOW)
  83. * const UByte Mess: Which dialog to display from dialog table.
  84. * const UByte First: Line from dialog where the first question is.
  85. * const UByte Last: Line from dialog where the last question is.
  86. * const UByte Addr: Address in bank where line selected is written.
  87. *
  88. * The ASK command opens a window with a set of choices to be picked with the "selector
  89. * finger". If ASK is called on an open window ID, the window will shrink closed and
  90. * re-open with the new data.
  91. */
  92. void ProcessASK(CodeGenerator* code_gen, const std::string& script_name);
  93. void ProcessMPNAM(CodeGenerator* code_gen, const std::string& script_name);
  94. /**
  95. * Processes a MENU opcode.
  96. *
  97. * Opcode: 0x49
  98. * Short name: MENU
  99. * Long name: Menu
  100. *
  101. * Memory layout (4 bytes)
  102. * |0x49|B|T|E|
  103. *
  104. * Arguments
  105. * - const UByte B: Bank for parameter, or zero if P is specified as a literal value.
  106. * - const UByte T: Type of menu, or special event.
  107. * - const UByte P: Parameter to the menu, or address of parameter value, if B is non-zero.
  108. *
  109. * MENU has two uses. Its primary function is to display a menu or other special screen.
  110. * These menus range from the character name entry screen, to a shop, and even the staff
  111. * credit display. The other function is to provide a set of special events that would
  112. * normally be accomplished through a set of opcodes, but are instead coded directly into a
  113. * MENU call. Some types of menu are erroneous or produce erratic behaviour, and were most
  114. * likely used for testing. As such, they are not listed here.
  115. *
  116. * Standard Menu Types
  117. *
  118. * ID Menu Type
  119. * 5 FF7 Credits
  120. * 6 Character Name Entry
  121. * 7 Party Select
  122. * 8 Shop
  123. * 9 Main Menu
  124. * E Save Screen
  125. *
  126. * Special Event Types
  127. * ID Event Type
  128. * F Yuffie's Materia Steal (Remove All Materia)
  129. * 12 Remove Cloud's Materia
  130. * 13 Restore Cloud's Materia
  131. *
  132. * Parameters
  133. *
  134. * Character Name Entry: Parameter indicates the name of the character to edit, and follows
  135. * the standard Character IDs, as well as 0x64 to indicate the Chocobo naming screen.
  136. *
  137. * @param[in,out] code_gen Code generator to append lines.
  138. */
  139. void ProcessMENU(CodeGenerator* code_gen);
  140. void ProcessMENU2(CodeGenerator* code_gen);
  141. void ProcessWINDOW(CodeGenerator* code_gen);
  142. void ProcessWCLSE(CodeGenerator* code_gen);
  143. /**
  144. * Processes a WSPCL opcode.
  145. *
  146. * Opcode: 0x36
  147. * Short name: WSPCL
  148. * Long name: Window Special (Numerical Display)
  149. *
  150. * Memory layout (5 bytes.)
  151. * |0x36|W|T|X|Y|
  152. *
  153. * Arguments
  154. *
  155. * - const UByte W: WINDOW ID to apply the change to.
  156. * - const UByte T: Type of display.
  157. * - const UByte X: X-coordinate of the numerical display, relative to the top-left of the
  158. * window.
  159. * - const UByte Y: Y-coordinate of the numerical display, relative to the top-left of the
  160. * window.
  161. *
  162. * Creates a numerical display inside the given window. The display can be either in the
  163. * form of a clock, or a scoreboard with six digits. This only creates the numerical
  164. * display; to actually show it, a MESSAGE or ASK command needs to be issued. Using a blank
  165. * line of dialog will allow you to create a numerical display in the top-left of the
  166. * window without field dialog hidden behind it. Alternatively, dialog can be shown along
  167. * with the display by placing the display in an appropriate area of the window. To set the
  168. * time for the clock variant, STTIM is used. To set the number for the numerical display,
  169. * WNUMB is used.
  170. *
  171. * @param[in,out] code_gen Code generator to append lines.
  172. */
  173. void ProcessWSPCL(CodeGenerator* code_gen);
  174. /**
  175. * Processes a WMODE opcode.
  176. *
  177. * Opcode: 0x52
  178. * Short name: WMODE
  179. * Long name: Window Mode
  180. *
  181. * Memory layout (4 bytes)
  182. * |0x52|N|M|C|
  183. *
  184. * Arguments
  185. *
  186. * - const UByte N: The ID of the window whose mode will be set.
  187. * - const UByte M: Mode of the window.
  188. * - const UByte C: Window permanency.
  189. *
  190. * Changes properties associated with the WINDOW whose ID is specified. The mode byte sets
  191. * the style of the window, as detailed below. If the final byte is set to 1, the window
  192. * cannot be closed by the player pushing [OK]. The mode of the window should be changed
  193. * before it is displayed with MESSAGE or ASK, or the changes will not be visible unless
  194. * the window is closed and reopened.
  195. *
  196. * @param[in,out] code_gen Code generator to append lines.
  197. */
  198. void ProcessWMODE(CodeGenerator* code_gen);
  199. };