FieldModuleInstruction.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 ProcessBATTLE(CodeGenerator* code_gen);
  60. /**
  61. * Processes a BTLON opcode.
  62. *
  63. * Opcode: 0x71
  64. * Short name: BTLON
  65. * Long name: Battle switch
  66. *
  67. * Memory layout (2 bytes)
  68. * |0x71|S|
  69. *
  70. * Arguments
  71. * - const UByte S: Switch battles on/off (0/1, respectively).
  72. *
  73. * Turns random encounters on or off for this field. Note that if a
  74. * field does not have any Encounter Data set in its field file,
  75. * battles will not occur regardless of the argument passed with this
  76. * opcode.
  77. *
  78. * @param[in,out] code_gen Code generator to append lines.
  79. */
  80. void ProcessBTLON(CodeGenerator* code_gen);
  81. /**
  82. * Processes a MAPJUMP opcode.
  83. *
  84. * Opcode: 0x60
  85. * Short name: BTLON
  86. * Long name: Change Field
  87. *
  88. * Memory layout
  89. * |0x60|I|I|X|X|Y|Y|Z|Z|D|
  90. *
  91. * Arguments
  92. * - const UShort I: Field ID of the map to jump to.
  93. * - const Short X: X-coordinate of the player on the next field.
  94. * - const Short Y: Y-coordinate of the player on the next field.
  95. * - const Short Z: Z-coordinate of the player on the next field.
  96. * - const UByte D: Direction the character will be facing on the next
  97. * field, in the standard game format.
  98. *
  99. * Switches fields to the one indicated by I, and places the character
  100. * at the coordinates and direction specified. This is an alternative
  101. * to using a gateway, and can complement their usage as it allows for
  102. * more than 12 gateways by simulating their behavior through a LINE
  103. * which, when crossed, executes a MAPJUMP.
  104. *
  105. * @param[in,out] code_gen Code generator to append lines.
  106. * @param[in] func Function to get the spawn point from.
  107. */
  108. void ProcessMAPJUMP(CodeGenerator* code_gen, Function& func);
  109. };