FieldMathInstruction.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.h"
  19. #include "decompiler/field/FieldEngine.h"
  20. namespace FF7{
  21. /**
  22. * A math instruction.
  23. */
  24. class FieldMathInstruction : public StoreInstruction{
  25. public:
  26. /**
  27. * Processes the instruction.
  28. *
  29. * @param func[in] Function to process.
  30. * @param stack[out] Function stack.
  31. * @param engine[in] Engine. Unused.
  32. * @param code_gen[in] Code generator.
  33. */
  34. virtual void ProcessInst(
  35. Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
  36. ) override;
  37. private:
  38. void ProcessSaturatedPLUS(CodeGenerator* code_gen);
  39. void ProcessSaturatedPLUS2(CodeGenerator* code_gen);
  40. void ProcessSaturatedMINUS(CodeGenerator* code_gen);
  41. void ProcessSaturatedMINUS2(CodeGenerator* code_gen);
  42. void ProcessSaturatedINC(CodeGenerator* code_gen);
  43. void ProcessSaturatedINC2(CodeGenerator* code_gen);
  44. void ProcessSaturatedDEC(CodeGenerator* code_gen);
  45. void ProcessSaturatedDEC2(CodeGenerator* code_gen);
  46. void ProcessRDMSD(CodeGenerator* code_gen);
  47. void ProcessSETBYTE_SETWORD(CodeGenerator* code_gen);
  48. /**
  49. * Processes a BITON opcode.
  50. *
  51. * Opcode: 0x82
  52. * Short name: BITON
  53. * Long name: Set Bit
  54. *
  55. * Memory layout (4 bytes)
  56. * |0x82|D/S|A|B|
  57. *
  58. * Arguments
  59. * - const Bit[4] D: Destination bank.
  60. * - const Bit[4] S: Source bank.
  61. * - const UByte A: Destination address.
  62. * - const UByte Bit: The number of the bit to turn on.
  63. *
  64. * Sets the nth bit in the "A" location, where n is a number
  65. * between 0-7 supplied in B. A value of zero in B will set the
  66. * least significant bit. If the Source Bank is 0 then the bit to
  67. * be set is taken from "Bit". If the Source Bank is an 8 bit
  68. * bank, then the bit is the address in that bank where the
  69. * operand is.
  70. *
  71. * @param codegen[in|out] Code generator to append lines.
  72. */
  73. void ProcessBITON(CodeGenerator* code_gen);
  74. /**
  75. * Processes a BITON opcode.
  76. *
  77. * Opcode: 0x83
  78. * Short name: BITOFF
  79. * Long name: Reset Bit
  80. *
  81. * Memory layout (4 bytes)
  82. * |0x83|D/S|A|B|
  83. *
  84. * Arguments
  85. * - const Bit[4] D: Destination bank.
  86. * - const Bit[4] S: Source bank.
  87. * - const UByte A: Destination address.
  88. * - const UByte Bit: The number of the bit to turn off.
  89. *
  90. * Sets the nth bit in the "A" location, where n is a number
  91. * between 0-7 supplied in B. A value of zero in B will reset the
  92. * least significant bit. If the Source Bank is 0 then the bit to
  93. * be set is taken from "Bit". If the Source Bank is an 8 bit
  94. * bank, then the bit is the address in that bank where the
  95. * operand is.
  96. *
  97. * @param codegen[in|out] Code generator to append lines.
  98. */
  99. void ProcessBITOFF(CodeGenerator* code_gen);
  100. void ProcessPLUSx_MINUSx(CodeGenerator* code_gen, const std::string& op);
  101. void ProcessINCx_DECx(CodeGenerator* code_gen, const std::string& op);
  102. void ProcessRANDOM(CodeGenerator* code_gen);
  103. };
  104. }