Lua: Add Teak disassembler

This commit is contained in:
wheremyfoodat 2024-04-29 00:46:22 +03:00
parent eab1a12b07
commit 27828b1351

View file

@ -1,4 +1,6 @@
#ifdef PANDA3DS_ENABLE_LUA #ifdef PANDA3DS_ENABLE_LUA
#include <teakra/disassembler.h>
#include <array> #include <array>
#include "capstone.hpp" #include "capstone.hpp"
@ -227,6 +229,15 @@ static int disassembleARMThunk(lua_State* L) {
return 1; return 1;
} }
static int disassembleTeakThunk(lua_State* L) {
const u16 instruction = u16(lua_tonumber(L, 1));
const u16 expansion = u16(lua_tonumber(L, 2));
std::string disassembly = Teakra::Disassembler::Do(instruction, expansion);
lua_pushstring(L, disassembly.c_str());
return 1;
}
// clang-format off // clang-format off
static constexpr luaL_Reg functions[] = { static constexpr luaL_Reg functions[] = {
{ "__read8", read8Thunk }, { "__read8", read8Thunk },
@ -246,6 +257,7 @@ static constexpr luaL_Reg functions[] = {
{ "__getCirclepad", getCirclepadThunk }, { "__getCirclepad", getCirclepadThunk },
{ "__getButton", getButtonThunk }, { "__getButton", getButtonThunk },
{ "__disassembleARM", disassembleARMThunk }, { "__disassembleARM", disassembleARMThunk },
{ "__disassembleTeak", disassembleTeakThunk },
{ nullptr, nullptr }, { nullptr, nullptr },
}; };
// clang-format on // clang-format on
@ -280,6 +292,7 @@ void LuaManager::initializeThunks() {
getCirclepad = function() return GLOBALS.__getCirclepad() end, getCirclepad = function() return GLOBALS.__getCirclepad() end,
disassembleARM = function(pc, instruction) return GLOBALS.__disassembleARM(pc, instruction) end, disassembleARM = function(pc, instruction) return GLOBALS.__disassembleARM(pc, instruction) end,
disassembleTeak = function(opcode, exp) return GLOBALS.__disassembleTeak(opcode, exp or 0) end,
Frame = __Frame, Frame = __Frame,
ButtonA = __ButtonA, ButtonA = __ButtonA,