Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef inc_koei_vmdisasm
- #define inc_koei_vmdisasm
- #include <cstdint>
- #include <array>
- #include <map>
- #include <snes/assert.h>
- #include <snes/disasm.h>
- namespace snes
- {
- namespace koei
- {
- using u08 = std::uint8_t;
- using i16 = std::int16_t;
- using u16 = std::uint16_t;
- using u32 = std::uint32_t;
- enum class mode_t
- {
- null,
- quick_frame_relative,
- quick_immediate,
- near_frame_relative,
- far_frame_relative,
- immediate,
- immediate_byte,
- absolute,
- absolute_goto,
- branch_forward,
- branch_back,
- call,
- call_absolute,
- call_stack,
- switch_c,
- switch_nc,
- // 32-bit
- extended,
- };
- struct opcode_data_t
- {
- opcode_data_t() : short_name(nullptr), long_name(nullptr), mode(mode_t::null) {}
- opcode_data_t(const char *sn, const char *ln, mode_t _mode = mode_t::null) : short_name(sn), long_name(ln), mode(_mode) {}
- const char *short_name;
- const char *long_name;
- mode_t mode;
- };
- template <int N>
- struct opcode_database_t : std::array<opcode_data_t, N>
- {
- using db_populator_t = void(*)(opcode_database_t &db);
- opcode_database_t(db_populator_t populator)
- {
- if (populator) {
- populator(*this);
- }
- }
- void add_opcode_data(int index, const opcode_data_t &data)
- {
- ASSERT((*this)[index].short_name == nullptr);
- (*this)[index] = data;
- }
- void add_opcode_data(int start, int end, const opcode_data_t &data)
- {
- for (int i = start; i <= end; i++) {
- ASSERT((*this)[i].short_name == nullptr);
- (*this)[i] = data;
- }
- }
- };
- void vm_opcode_database_populate(koei::opcode_database_t<256> &db);
- void vm_opcode_database_long_populate(koei::opcode_database_t<48> &db);
- extern opcode_database_t<256> opcode_db;
- extern opcode_database_t<48> opcode_db_long;
- struct disasm_t
- {
- disasm_t() : zero(nullptr), opt(local_options), func_map(local_func_map), data_map(local_data_map)
- {
- }
- disasm_t(const disasm_options_t &_opt, const addr_map_t &_func_map, const addr_map_t &_data_map) :
- zero(nullptr), opt(_opt), func_map(_func_map), data_map(_data_map)
- {
- }
- void set_zero(const void *zero_ptr) { zero = (const u08 *)zero_ptr; }
- int disassemble(const u08 *mem, char *result);
- int disassemble_long(const u08 *mem, char *result);
- struct vm_registers_t
- {
- vm_registers_t()
- {
- clear();
- }
- void clear()
- {
- SPl = 0;
- FPl = 0;
- PCl = 0;
- ll = 0;
- rl = 0;
- }
- union
- {
- // stack pointer
- u32 SPl;
- u16 SP;
- };
- union
- {
- // frame pointer
- u32 FPl;
- u16 FP;
- };
- union
- {
- // program counter
- u32 PCl;
- u16 PC;
- };
- // 32 bit (low / high)
- union
- {
- u32 ll;
- u16 l;
- };
- union
- {
- u32 rl;
- u16 r;
- };
- };
- disasm_options_t local_options;
- const disasm_options_t &opt;
- addr_map_t local_func_map;
- const addr_map_t &func_map;
- addr_map_t local_data_map;
- const addr_map_t &data_map;
- addr_map_t line_label;
- vm_registers_t reg;
- // pointer to 0x000000 rom address
- const u08 *zero;
- int sval;
- int data;
- };
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement