Skip to content

Commit

Permalink
Debugger: Lua - Added getCdlData API
Browse files Browse the repository at this point in the history
  • Loading branch information
SourMesen committed Dec 1, 2024
1 parent 04062de commit 355ca16
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Core/Debugger/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 },

Expand Down Expand Up @@ -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<uint8_t> 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);
Expand Down
2 changes: 2 additions & 0 deletions Core/Debugger/LuaApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class LuaApi
static int GetAccessCounters(lua_State *lua);
static int ResetAccessCounters(lua_State *lua);

static int GetCdlData(lua_State* lua);

private:
static FrameInfo InternalGetScreenSize();

Expand Down
10 changes: 10 additions & 0 deletions UI/Debugger/Documentation/LuaDocumentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions UI/Debugger/Utilities/CodeCompletionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public enum DocEntryCategory
public enum DocEntrySubcategory
{
AccessCounters,
Cdl,
Cheats,
SaveStates,
Others
Expand Down
1 change: 1 addition & 0 deletions UI/Localization/resources.en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,7 @@ E
</Enum>
<Enum ID="DocEntrySubcategory">
<Value ID="AccessCounters">Access Counters</Value>
<Value ID="Cdl">Code/Data Log</Value>
<Value ID="Cheats">Cheats</Value>
<Value ID="SaveStates">Save States</Value>
<Value ID="Others">Others</Value>
Expand Down

0 comments on commit 355ca16

Please sign in to comment.