FieldModuleInstruction.h 4.2 KB

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