diff --git a/.gitmodules b/.gitmodules index cad9a047..e3599ada 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,6 @@ [submodule "external/capstone"] path = external/capstone url = https://github.com/capstone-engine/capstone/ - branch = next [submodule "external/nativefiledialog-extended"] path = external/nativefiledialog-extended url = https://github.com/btzy/nativefiledialog-extended/ diff --git a/external/capstone b/external/capstone index 0d0e6843..fee83fcc 160000 --- a/external/capstone +++ b/external/capstone @@ -1 +1 @@ -Subproject commit 0d0e684358afd0889b98deaf3941caa9c6855cae +Subproject commit fee83fcc1ad096c22d4f2066ccb58ad1a76a9886 diff --git a/external/nativefiledialog-extended b/external/nativefiledialog-extended index 33115928..31df8e30 160000 --- a/external/nativefiledialog-extended +++ b/external/nativefiledialog-extended @@ -1 +1 @@ -Subproject commit 33115928184cc3cc1b945a0f94bbc574d137224c +Subproject commit 31df8e30cc14c6929033152ffd61dd1c98b4f5b3 diff --git a/src/n64/core/Cpu.cpp b/src/n64/core/Cpu.cpp index 96b68366..57e34dbd 100644 --- a/src/n64/core/Cpu.cpp +++ b/src/n64/core/Cpu.cpp @@ -88,6 +88,27 @@ inline void HandleInterrupt(Registers& regs) { } } +inline void Cpu::disassembly(u32 instr) const { + size_t count; + cs_insn *insn; + + u8 code[4]; + //u32 temp = bswap_32(instr); + memcpy(code, &instr, 4); + + count = cs_disasm(handle, code, 4, regs.pc, 0, &insn); + + if (count > 0) { + size_t j; + for (j = 0; j < count; j++) { + fmt::print("0x{:016X}:\t{}\t\t{}\n", insn[j].address, insn[j].mnemonic, insn[j].op_str); + } + + cs_free(insn, count); + } else + printf("ERROR: Failed to disassemble given code!\n"); +} + void Cpu::Step(Mem& mem) { regs.gpr[0] = 0; @@ -96,6 +117,8 @@ void Cpu::Step(Mem& mem) { u32 instruction = mem.Read32(regs, regs.pc, regs.pc); + disassembly(instruction); + regs.oldPC = regs.pc; regs.pc = regs.nextPC; regs.nextPC += 4; diff --git a/src/n64/core/Cpu.hpp b/src/n64/core/Cpu.hpp index 25a3a4b2..efe24e25 100644 --- a/src/n64/core/Cpu.hpp +++ b/src/n64/core/Cpu.hpp @@ -7,23 +7,21 @@ namespace n64 { struct Cpu { Cpu() { - //log = fopen("disasm.txt", "w"); - //if(cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64, &handle) != CS_ERR_OK) { - // util::panic("Could not initialize capstone!\n"); - //} + if(cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64, &handle) != CS_ERR_OK) { + util::panic("Could not initialize capstone!\n"); + } Reset(); } ~Cpu() { - //fclose(log); - //cs_close(&handle); + cs_close(&handle); } void Reset(); void Step(Mem&); Registers regs; private: csh handle; - FILE* log; + void disassembly(u32 instr) const; friend struct Cop1; void special(Mem&, u32);