FieldModuleInstruction.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 module instruction.
  24. */
  25. class FieldModuleInstruction : public KernelCallInstruction{
  26. public:
  27. /**
  28. * Processes the instruction.
  29. *
  30. * @param func[in] Function to process.
  31. * @param stack[out] Function stack.
  32. * @param engine[in] Engine. Unused.
  33. * @param code_gen[in] Code generator.
  34. */
  35. virtual void ProcessInst(
  36. Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
  37. ) override;
  38. private:
  39. /**
  40. * Processes a BATTLE opcode.
  41. *
  42. * Opcode: 0x70
  43. * Short name: BATTLE
  44. * Long name: Start battle
  45. *
  46. * Memory layout (4 bytes)
  47. * |0x70|B|N|N|
  48. *
  49. * Arguments
  50. * - const UByte B: Bank (16-bit) to retrieve the address of the
  51. * battle ID, or zero if it is given as a literal value.
  52. * - const UWord N: Battle ID, or address to find ID if B is
  53. * non-zero.
  54. *
  55. * This launches the battle module with whatever battle number is
  56. * used in the argument, or the value retrieved from memory
  57. * location N if B is non-zero. Battle 1, 2, and 999 (0x03E7) are
  58. * debug battles.
  59. *
  60. * @param codegen[in|out] Code generator to append lines.
  61. */
  62. void ProcessBATTLE(CodeGenerator* code_gen);
  63. /**
  64. * Processes a BTLON opcode.
  65. *
  66. * Opcode: 0x71
  67. * Short name: BTLON
  68. * Long name: Battle switch
  69. *
  70. * Memory layout (2 bytes)
  71. * |0x71|S|
  72. *
  73. * Arguments
  74. * - const UByte S: Switch battles on/off (0/1, respectively).
  75. *
  76. * Turns random encounters on or off for this field. Note that if
  77. * a field does not have any Encounter Data set in its field file,
  78. * battles will not occur regardless of the argument passed with
  79. * this opcode.
  80. *
  81. * @param codegen[in|out] Code generator to append lines.
  82. */
  83. void ProcessBTLON(CodeGenerator* code_gen);
  84. /**
  85. * Processes a MAPJUMP opcode.
  86. *
  87. * Opcode: 0x60
  88. * Short name: BTLON
  89. * Long name: Change Field
  90. *
  91. * Memory layout
  92. * |0x60|I|I|X|X|Y|Y|Z|Z|D|
  93. *
  94. * Arguments
  95. * - const UShort I: Field ID of the map to jump to.
  96. * - const Short X: X-coordinate of the player on the next field.
  97. * - const Short Y: Y-coordinate of the player on the next field.
  98. * - const Short Z: Z-coordinate of the player on the next field.
  99. * - const UByte D: Direction the character will be facing on the
  100. * next field, in the standard game format.
  101. *
  102. * Switches fields to the one indicated by I, and places the
  103. * character at the coordinates and direction specified. This is
  104. * an alternative to using a gateway, and can complement their
  105. * usage as it allows for more than 12 gateways by simulating
  106. * their behavior through a LINE which, when crossed, executes a
  107. * MAPJUMP.
  108. *
  109. * @param codegen[in|out] Code generator to append lines.
  110. * @param func[in] Function to get the spawn point from.
  111. */
  112. void ProcessMAPJUMP(CodeGenerator* code_gen, Function& func);
  113. };
  114. }