WorldDisassembler.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears 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. #pragma once
  16. #include "decompiler/Disassembler.h"
  17. namespace FF7{
  18. class WorldEngine;
  19. class WorldDisassembler : public Disassembler{
  20. public:
  21. /**
  22. * CConstructor.
  23. *
  24. * @param engine[in] The engine to use to disassemble.
  25. * @param insts[in] The list of instructions.
  26. * @param script_number[in] The script number to process.
  27. */
  28. WorldDisassembler(WorldEngine* engine, InstVec& insts, int script_number);
  29. /**
  30. * Destructor.
  31. */
  32. ~WorldDisassembler();
  33. /**
  34. * Disassembles the instructions.
  35. */
  36. void DoDisassemble() override;
  37. private:
  38. /**
  39. * Parses an opcode.
  40. *
  41. * Adds properties to an instruction, and adds the instruction to
  42. * the list.
  43. *
  44. * @param opcode[in] The opcode code.
  45. * @param name[in] the opcode name.
  46. * @param instruction[in][out] A newly created instruction of the
  47. * type the opcode belongs to.
  48. * @param stack_change[in] Indicates how much the instruction
  49. * changes the stack pointer by.
  50. * @param argument_format[in] The opcode argument format.
  51. */
  52. template<typename T> void ParseOpcode(
  53. int opcode, std::string name, T instruction,
  54. int stack_change, const char* argument_format
  55. ){
  56. uint32 full_opcode = (full_opcode << 8) + opcode;
  57. this->insts_.push_back(instruction);
  58. this->insts_.back()->SetOpcode(full_opcode);
  59. this->insts_.back()->SetAddress(this->address_);
  60. this->insts_.back()->SetStackChange(0);
  61. this->insts_.back()->SetName(std::string(name));
  62. this->insts_.back()->SetCodeGenData("");
  63. this->ReadParams(this->insts_.back(), argument_format);
  64. }
  65. /**
  66. * The script number.
  67. */
  68. int script_number_ = 0;
  69. };
  70. }