From 355ca16074d77c55796f84849fbdf1721e706d8c Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 1 Dec 2024 15:27:46 +0900 Subject: [PATCH] Debugger: Lua - Added getCdlData API --- Core/Debugger/LuaApi.cpp | 28 +++++++++++++++++++ Core/Debugger/LuaApi.h | 2 ++ .../Documentation/LuaDocumentation.json | 10 +++++++ UI/Debugger/Utilities/CodeCompletionHelper.cs | 1 + UI/Localization/resources.en.xml | 1 + 5 files changed, 42 insertions(+) diff --git a/Core/Debugger/LuaApi.cpp b/Core/Debugger/LuaApi.cpp index 3c626b42..77568d37 100644 --- a/Core/Debugger/LuaApi.cpp +++ b/Core/Debugger/LuaApi.cpp @@ -6,6 +6,7 @@ #include "Debugger/MemoryDumper.h" #include "Debugger/ScriptingContext.h" #include "Debugger/MemoryAccessCounter.h" +#include "Debugger/CdlManager.h" #include "Debugger/LabelManager.h" #include "Shared/SystemActionManager.h" #include "Shared/Video/DebugHud.h" @@ -141,6 +142,8 @@ int LuaApi::GetLibrary(lua_State *lua) { "getAccessCounters", LuaApi::GetAccessCounters }, { "resetAccessCounters", LuaApi::ResetAccessCounters }, + { "getCdlData", LuaApi::GetCdlData}, + { "addCheat", LuaApi::AddCheat }, { "clearCheats", LuaApi::ClearCheats }, @@ -949,6 +952,31 @@ int LuaApi::ResetAccessCounters(lua_State *lua) return l.ReturnCount(); } +int LuaApi::GetCdlData(lua_State* lua) +{ + LuaCallHelper l(lua); + MemoryType memoryType = (MemoryType)l.ReadInteger(); + checkEnum(MemoryType, memoryType, "Invalid memory type"); + checkparams(); + + if(!_debugger->GetCdlManager()->GetCodeDataLogger(memoryType)) { + error("This memory type does not support CDL data (only some ROM memory types support it)"); + } + + uint32_t size = _memoryDumper->GetMemorySize(memoryType); + vector cdlData; + cdlData.resize(size, {}); + _debugger->GetCdlManager()->GetCdlData(0, size, memoryType, cdlData.data()); + + lua_newtable(lua); + for(uint32_t i = 0; i < size; i++) { + lua_pushinteger(lua, cdlData[i]); + lua_rawseti(lua, -2, i); + } + + return 1; +} + int LuaApi::GetScriptDataFolder(lua_State *lua) { LuaCallHelper l(lua); diff --git a/Core/Debugger/LuaApi.h b/Core/Debugger/LuaApi.h index 842f3c0a..9a052abe 100644 --- a/Core/Debugger/LuaApi.h +++ b/Core/Debugger/LuaApi.h @@ -90,6 +90,8 @@ public: static int GetAccessCounters(lua_State *lua); static int ResetAccessCounters(lua_State *lua); + static int GetCdlData(lua_State* lua); + private: static FrameInfo InternalGetScreenSize(); diff --git a/UI/Debugger/Documentation/LuaDocumentation.json b/UI/Debugger/Documentation/LuaDocumentation.json index 8cca9b67..b8f55c6d 100644 --- a/UI/Debugger/Documentation/LuaDocumentation.json +++ b/UI/Debugger/Documentation/LuaDocumentation.json @@ -143,6 +143,16 @@ ], "returnValue": { "type": "Array", "description": "Array of ints" } }, +{ + "name": "getCdlData", + "category": "Miscellaneous", + "subcategory": "Cdl", + "description": "Returns the current state of the CDL (code/data log) for the specified memory type. This can only be used for (some) ROM memory types.", + "parameters": [ + { "name": "memoryType", "type": "Enum", "enumName": "memType", "description": "Memory type" } + ], + "returnValue": { "type": "Array", "description": "Array of bytes" } +}, { "name": "getDrawSurfaceSize", "category": "Drawing", diff --git a/UI/Debugger/Utilities/CodeCompletionHelper.cs b/UI/Debugger/Utilities/CodeCompletionHelper.cs index 186b5b10..b9778a1f 100644 --- a/UI/Debugger/Utilities/CodeCompletionHelper.cs +++ b/UI/Debugger/Utilities/CodeCompletionHelper.cs @@ -315,6 +315,7 @@ namespace Mesen.Debugger.Utilities public enum DocEntrySubcategory { AccessCounters, + Cdl, Cheats, SaveStates, Others diff --git a/UI/Localization/resources.en.xml b/UI/Localization/resources.en.xml index 59ab840b..d27c5010 100644 --- a/UI/Localization/resources.en.xml +++ b/UI/Localization/resources.en.xml @@ -3022,6 +3022,7 @@ E Access Counters + Code/Data Log Cheats Save States Others