From 101f0140787220d37dc0b5f29e192ba91a091d28 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Fri, 24 May 2024 18:10:55 -0400 Subject: [PATCH] cleanup and try to give unk vars a name (roughly based on DWARF) sMapBufMaxSize -> guess sMapBuf -> why is this split?? --- include/nw4r/db/db_assert.h | 14 ++++------- include/nw4r/db/db_console.h | 14 +++++++++++ include/nw4r/db/db_directPrint.h | 4 ++-- include/nw4r/db/db_mapFile.h | 8 +++---- src/nw4r/db/db_mapFile.cpp | 41 ++++++++++++++++---------------- 5 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 include/nw4r/db/db_console.h diff --git a/include/nw4r/db/db_assert.h b/include/nw4r/db/db_assert.h index a7ff8de5..ecc21922 100644 --- a/include/nw4r/db/db_assert.h +++ b/include/nw4r/db/db_assert.h @@ -1,16 +1,12 @@ -#ifndef DB_ASSERT_H -#define DB_ASSERT_H +#ifndef NW4R_DB_ASSERT_H +#define NW4R_DB_ASSERT_H + +#include namespace nw4r { namespace db { -namespace detail { - struct ConsoleHead { - - }; -} - -typedef detail::ConsoleHead* ConsoleHandle; +typedef detail::ConsoleHead *ConsoleHandle; ConsoleHandle Assertion_SetConsole(ConsoleHandle handle); diff --git a/include/nw4r/db/db_console.h b/include/nw4r/db/db_console.h new file mode 100644 index 00000000..90515fb2 --- /dev/null +++ b/include/nw4r/db/db_console.h @@ -0,0 +1,14 @@ +#ifndef NW4R_DB_CONSOLE_H +#define NW4R_DB_CONSOLE_H + +namespace nw4r { +namespace db { + +namespace detail { +struct ConsoleHead {}; +} // namespace detail + +} // namespace db +} // namespace nw4r + +#endif diff --git a/include/nw4r/db/db_directPrint.h b/include/nw4r/db/db_directPrint.h index c3e682ec..cd78ceac 100644 --- a/include/nw4r/db/db_directPrint.h +++ b/include/nw4r/db/db_directPrint.h @@ -1,5 +1,5 @@ -#ifndef DB_DIRECT_PRINT_H -#define DB_DIRECT_PRINT_H +#ifndef NW4R_DB_DIRECT_PRINT_H +#define NW4R_DB_DIRECT_PRINT_H #include #include diff --git a/include/nw4r/db/db_mapFile.h b/include/nw4r/db/db_mapFile.h index 2eb2aac6..1576109f 100644 --- a/include/nw4r/db/db_mapFile.h +++ b/include/nw4r/db/db_mapFile.h @@ -1,5 +1,5 @@ -#ifndef DB_MAPFILE_H -#define DB_MAPFILE_H +#ifndef NW4R_DB_MAPFILE_H +#define NW4R_DB_MAPFILE_H #include @@ -13,9 +13,9 @@ typedef struct MapFile { MapFile *next; } MapFile; -typedef MapFile* MapFileHandle; +typedef MapFile *MapFileHandle; -MapFileHandle MapFile_RegistOnDvd(void*, const char*, const OSModuleInfo*); +MapFileHandle MapFile_RegistOnDvd(void *, const char *, const OSModuleInfo *); void MapFile_Unregist(MapFileHandle); void MapFile_UnregistAll(); bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize); diff --git a/src/nw4r/db/db_mapFile.cpp b/src/nw4r/db/db_mapFile.cpp index d8e0e24b..ad52c4fa 100644 --- a/src/nw4r/db/db_mapFile.cpp +++ b/src/nw4r/db/db_mapFile.cpp @@ -13,9 +13,9 @@ static u8 (*GetCharPtr_)(const u8 *) = nullptr; static u8 dvdReadBuf[512] ALIGN(32); static DVDFileInfo sFileInfo; -s32 unk_80574e10 = 0x200; -u8 *dvdReadPtr = dvdReadBuf; -s32 unk_80574e18 = -1; +static s32 sMapBufMaxSize = 0x200; +static u8 *sMapBuf = dvdReadBuf; +static s32 sMapBufOffset = -1; static void MapFile_Append(MapFile *file) { if (sMapFileList == nullptr) { @@ -71,30 +71,30 @@ static u8 GetCharOnMem_(const u8 *arg) { } /** 80436b50 */ -static u8 GetCharOnDvd_(const u8 *arg) { - s32 cleared = (s32)arg & 0x7fffffff; - s32 unoffset = cleared - unk_80574e18; - if (cleared >= sFileLength) { +static u8 GetCharOnDvd_(const u8 *buf) { + s32 address = (u32)buf & 0x7fffffff; + s32 offset = address - sMapBufOffset; + if (address >= sFileLength) { return 0; } - if (unk_80574e18 < 0 || unoffset < 0 || unoffset >= unk_80574e10) { - unk_80574e18 = ROUND_DOWN(cleared, 32); - unoffset = cleared - unk_80574e18; - cleared = unk_80574e10; - if (unk_80574e18 + unk_80574e10 >= sFileLength) { - cleared = ROUND_UP(sFileLength - unk_80574e18, 32); + if (sMapBufOffset < 0 || offset < 0 || offset >= sMapBufMaxSize) { + sMapBufOffset = ROUND_DOWN(address, 32); + offset = address - sMapBufOffset; + address = sMapBufMaxSize; + if (sMapBufOffset + sMapBufMaxSize >= sFileLength) { + address = ROUND_UP(sFileLength - sMapBufOffset, 32); } - BOOL interrupts = OSEnableInterrupts(); - BOOL read = DVDReadAsyncPrio(&sFileInfo, dvdReadPtr, cleared, unk_80574e18, nullptr, 2); + BOOL enabled = OSEnableInterrupts(); + BOOL read = DVDReadAsyncPrio(&sFileInfo, sMapBuf, address, sMapBufOffset, nullptr, 2); while (DVDGetCommandBlockStatus(&sFileInfo.block)) {} - OSRestoreInterrupts(interrupts); + OSRestoreInterrupts(enabled); if (read <= 0) { return 0; } } - return *(dvdReadPtr + unoffset); + return *(sMapBuf + offset); } static u8 *SearchNextLine_(u8 *buf, s32 lines) { @@ -148,7 +148,7 @@ static u8 *SearchParam_(u8 *lineTop, u32 argNum, u8 splitter) { } inArg = true; } - buf += 1; + buf++; } } @@ -297,7 +297,7 @@ bool QuerySymbolToSingleMapFile_(MapFileHandle pMapFile, u32 address, u8 *strBuf if (!DVDFastOpen(pMapFile->fileEntry, &sFileInfo)) { goto err; } - unk_80574e18 = -1; + sMapBufOffset = -1; sFileLength = sFileInfo.size; GetCharPtr_ = GetCharOnDvd_; ret = QuerySymbolToMapFile_(buf, pMapFile->moduleInfo, address, strBuf, strBufSize); @@ -313,7 +313,6 @@ err: } bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize) { - MapFile *pMap = sMapFileList; if (sMapFileList == nullptr) { if (address < (u32)_stack_end) { snprintf((char *)strBuf, strBufSize, "[%p]", address); @@ -329,7 +328,7 @@ bool MapFile_QuerySymbol(u32 address, u8 *strBuf, u32 strBufSize) { return false; } } else { - for (; pMap != nullptr; pMap = pMap->next) { + for (MapFile *pMap = sMapFileList; pMap != nullptr; pMap = pMap->next) { if (QuerySymbolToSingleMapFile_(pMap, address, strBuf, strBufSize)) { return true; }