FieldMathInstruction.h 4.0 KB

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