FieldPartyInstruction.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 party instruction
  22. */
  23. class FieldPartyInstruction : 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 The 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. /**
  38. * Processes a GOLDU opcode.
  39. *
  40. * Opcode: 0x39
  41. * Short name: GOLDU
  42. * Long name: Gil Up
  43. * Memory layout (6 bytes)
  44. * |0x39|0|A|A|A|A| or |0x39|B/0|A|0|0|0|
  45. *
  46. * Arguments
  47. * - Increase by a constant amount:
  48. * - const UByte 0: Zero.
  49. * - const ULong A: Amount to increase.
  50. * - Increase by an amount found in memory:
  51. * - const Bit[4] B: Source bank.
  52. * - const UByte A: Source address.
  53. * - const UByte[3] 0: Three zero bytes.
  54. *
  55. * Increases the amount of gil by a constant amount, or by an amount found in the source
  56. * bank B and address A. The total gil is capped above by 0xFFFFFFFF; attempts to increment
  57. * further will fail.
  58. *
  59. * @param[in,out] code_gen Code generator to append lines.
  60. */
  61. void ProcessGOLDU(CodeGenerator* code_gen);
  62. /**
  63. * Processes a GOLDD opcode.
  64. *
  65. * Opcode: 0x40
  66. * Short name: GOLDD
  67. * Long name: Gil Down
  68. * Memory layout (6 bytes)
  69. * |0x39|0|A|A|A|A| or |0x39|B/0|A|0|0|0|
  70. *
  71. * Arguments
  72. * - Decrease by a constant amount:
  73. * - const UByte 0: Zero.
  74. * - const ULong A: Amount to increase.
  75. * - Decrease by an amount found in memory:
  76. * - const Bit[4] B: Source bank.
  77. * - const UByte A: Source address.
  78. * - const UByte[3] 0: Three zero bytes.
  79. *
  80. * Decreases the amount of gil by a constant amount, or by an amount found in the source
  81. * bank B and address A. The total gil can't get below 0.
  82. *
  83. * @param[in,out] code_gen Code generator to append lines.
  84. */
  85. void ProcessGOLDD(CodeGenerator* code_gen);
  86. /**
  87. * Processes a STITM opcode.
  88. *
  89. * Opcode: 0x58
  90. * Short name: STITM
  91. * Long name: Set item
  92. * Memory layout (4 bytes)
  93. * |0x58|B1/B2|T|T|A|
  94. *
  95. * Arguments
  96. * - const Bit[4] B1: Source bank 1, or zero if T is set as a constant value.
  97. * - const Bit[4] B2: Source bank 2, or zero if A is set as a constant value.
  98. * - const UShort T: Type of item to add, or source address to retrieve item type from.
  99. * - const UByte A: Amount of item to add, or source address to retrieve quantity from.
  100. *
  101. * Adds a new item to the inventory. Either the item is added explicitly with values, in
  102. * which case B1 and B2 are zero, or the item type and quantity are retrieved from memory.
  103. * In this case, bank B1 and address T retrieve the item type, whilst bank B2 and address A
  104. * retrieve the quantity to add.
  105. *
  106. * @param[in,out] code_gen Code generator to append lines.
  107. */
  108. void ProcessSTITM(CodeGenerator* code_gen);
  109. /**
  110. * Processes a DLITM opcode.
  111. *
  112. * Opcode: 0x59
  113. * Short name: STITM
  114. * Long name: Set item
  115. * Memory layout (4 bytes)
  116. * |0x59|B1/B2|T|T|A|
  117. *
  118. * Arguments
  119. * - const Bit[4] B1: Source bank 1, or zero if T is set as a constant value.
  120. * - const Bit[4] B2: Source bank 2, or zero if A is set as a constant value.
  121. * - const UShort T: Type of item to remove, or source address to retrieve item type from.
  122. * - const UByte A: Amount of item to remove, or source address to retrieve quantity from.
  123. *
  124. * Removes a quantity of an item from the inventory. Either the item is removed explicitly
  125. * with values, in which case B1 and B2 are zero, or the item type and quantity are
  126. * retrieved from memory. In this case, bank B1 and address T retrieve the item type,
  127. * whilst bank B2 and address A retrieve the quantity to remove.
  128. *
  129. * @param[in,out] code_gen Code generator to append lines.
  130. */
  131. void ProcessDLITM(CodeGenerator* code_gen);
  132. /**
  133. * Processes a CKITM opcode.
  134. *
  135. * Opcode: 0x5A
  136. * Short name: CKITM
  137. * Long name: Check item
  138. * Memory layout (3 bytes)
  139. * |0x5A|B|I|A|
  140. *
  141. * Arguments
  142. * - const UByte B: Bank to store result.
  143. * - const UShort I: Item ID to check.
  144. * - const UByte A: Address to store result.
  145. *
  146. * Copies the amount of item I the player has in their inventory, to the bank and address
  147. * specified.
  148. *
  149. * @param[in,out] code_gen Code generator to append lines.
  150. */
  151. void ProcessCKITM(CodeGenerator* code_gen);
  152. void ProcessPRTYE(CodeGenerator* code_gen);
  153. /**
  154. * Processes a CHGLD opcode.
  155. *
  156. * Opcode: 0x3B
  157. * Short name: CHGLD
  158. * Long name: Check gil
  159. * Memory layout (6 bytes)
  160. * |0x39|B1/B2|A1|A2|
  161. *
  162. * Arguments
  163. * - const Bit[4] B1: Destination bank 1.
  164. * - const Bit[4] B2: Destination bank 2.
  165. * - const UByte A1: Destination address 1.
  166. * - const UByte A2: Destination address 2.
  167. *
  168. * Copies the amount of gil the party has into the destination addresses. As the gil amount
  169. * is a four-byte value, the arguments require two destination addresses to place two
  170. * two-byte values into. Address 1 takes the lower two bytes of the gil amount, while
  171. * address 2 takes the higher two bytes.
  172. *
  173. * @param[in,out] code_gen Code generator to append lines.
  174. */
  175. void ProcessCHGLD(CodeGenerator* code_gen);
  176. };