Skip to content

Commit

Permalink
Gfx Debugger (#2)
Browse files Browse the repository at this point in the history
* BitConverter: fix type correcteness in loop

* gbi: get rid of LoadUcode macros

* Gui: add ability to make a GuiImage out of a LUS::Texture

* Add GfxDebugger

* GfxDebugger: add C Bridge

* gfx_pc: expose internal state + intergrate debugger

* Add GfxDebuggerWindow

* Context: integrate GfxDebuggerWindow

* update CMakeLists.txt

* GfxDebugger: move inline code from header to cpp file
  • Loading branch information
Random06457 authored and louist103 committed Jan 10, 2024
1 parent 9f05a1f commit 4b0486f
Show file tree
Hide file tree
Showing 16 changed files with 2,000 additions and 1,054 deletions.
4 changes: 2 additions & 2 deletions extern/ZAPDUtils/Utils/BitConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ class BitConverter

switch (firstByte) {
case 0x37: // v64
for (int32_t pos = 0; pos < (romSize / 2); pos++) {
for (size_t pos = 0; pos < (romSize / 2); pos++) {
((uint16_t*)rom)[pos] = ToUInt16BE(rom, pos * 2);
}
break;
case 0x40: // n64
for (int32_t pos = 0; pos < (romSize / 4); pos++) {
for (size_t pos = 0; pos < (romSize / 4); pos++) {
((uint32_t*)rom)[pos] = ToUInt32BE(rom, pos * 4);
}
break;
Expand Down
1 change: 1 addition & 0 deletions include/libultraship/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
#include "public/bridge/windowbridge.h"
#include "public/bridge/consolevariablebridge.h"
#include "public/bridge/crashhandlerbridge.h"
#include "public/bridge/gfxdebuggerbridge.h"

#endif
4 changes: 2 additions & 2 deletions include/libultraship/libultra/gbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2282,9 +2282,9 @@ typedef union {
#define gsSPLoadUcode(uc_start, uc_dstart) gsSPLoadUcodeEx((uc_start), (uc_dstart), SP_UCODE_DATA_SIZE)

#define gSPLoadUcodeL(pkt, ucode) \
gSPLoadUcode((pkt), OS_K0_TO_PHYSICAL(&##ucode##TextStart), OS_K0_TO_PHYSICAL(&##ucode##DataStart))
// gSPLoadUcode((pkt), OS_K0_TO_PHYSICAL(&##ucode##TextStart), OS_K0_TO_PHYSICAL(&##ucode##DataStart))
#define gsSPLoadUcodeL(ucode) \
gsSPLoadUcode(OS_K0_TO_PHYSICAL(&##ucode##TextStart), OS_K0_TO_PHYSICAL(&##ucode##DataStart))
// gsSPLoadUcode(OS_K0_TO_PHYSICAL(&##ucode##TextStart), OS_K0_TO_PHYSICAL(&##ucode##DataStart))
#endif

#ifdef F3DEX_GBI_2
Expand Down
36 changes: 32 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ set(Source_Files__Public__Libultra
${CMAKE_CURRENT_SOURCE_DIR}/public/libultra/os.h
${CMAKE_CURRENT_SOURCE_DIR}/public/libultra/os.cpp
)

source_group("public/libultra" FILES ${Source_Files__Public__Libultra})

set(Source_Files__Public__Bridge
Expand All @@ -183,14 +183,16 @@ set(Source_Files__Public__Bridge
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/windowbridge.cpp
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/audiobridge.h
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/audiobridge.cpp
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/gfxdebuggerbridge.h
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/gfxdebuggerbridge.cpp
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/controllerbridge.h
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/controllerbridge.cpp
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/consolevariablebridge.h
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/consolevariablebridge.cpp
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/crashhandlerbridge.h
${CMAKE_CURRENT_SOURCE_DIR}/public/bridge/crashhandlerbridge.cpp
)

source_group("public/bridge" FILES ${Source_Files__Public__Bridge})
target_sources(libultraship PRIVATE ${Source_Files__Public__Libultra} ${Source_Files__Public__Bridge})

Expand All @@ -201,6 +203,8 @@ set(Source_Files__Debug
${CMAKE_CURRENT_SOURCE_DIR}/debug/CrashHandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug/Console.h
${CMAKE_CURRENT_SOURCE_DIR}/debug/Console.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug/GfxDebugger.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug/GfxDebugger.h
)

source_group("debug" FILES ${Source_Files__Debug})
Expand Down Expand Up @@ -249,11 +253,35 @@ set(Source_Files__Window__Gui
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GuiElement.cpp
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GuiMenuBar.h
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GuiMenuBar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GfxDebuggerWindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GfxDebuggerWindow.h
)

source_group("window/gui" FILES ${Source_Files__Window__Gui})
target_sources(libultraship PRIVATE ${Source_Files__Window__Gui})


set(Header_Files__Libraries__libgfxd
"../../ZAPDTR/lib/libgfxd/gbi.h"
"../../ZAPDTR/lib/libgfxd/gfxd.h"
"../../ZAPDTR/lib/libgfxd/priv.h"
)
source_group("Header Files\\Libraries\\libgfxd" FILES ${Header_Files__Libraries__libgfxd})

set(Source_Files__Libraries__libgfxd
"../../ZAPDTR/lib/libgfxd/gfxd.c"
"../../ZAPDTR/lib/libgfxd/uc.c"
"../../ZAPDTR/lib/libgfxd/uc_f3d.c"
"../../ZAPDTR/lib/libgfxd/uc_f3db.c"
"../../ZAPDTR/lib/libgfxd/uc_f3dex.c"
"../../ZAPDTR/lib/libgfxd/uc_f3dex2.c"
"../../ZAPDTR/lib/libgfxd/uc_f3dexb.c"
)
source_group("Source Files\\Libraries\\libgfxd" FILES ${Source_Files__Libraries__libgfxd})


target_sources(libultraship PRIVATE ${Header_Files__Libraries__libgfxd} ${Source_Files__Libraries__libgfxd})

#=================== Utils ===================

set(Source_Files__Utils
Expand Down Expand Up @@ -436,7 +464,7 @@ endif()
#=================== Packages & Includes ===================

target_include_directories(libultraship
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern ${CMAKE_CURRENT_BINARY_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/lib/libgfxd
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb
)

Expand Down Expand Up @@ -490,7 +518,7 @@ endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
)
endif()

Expand Down
14 changes: 14 additions & 0 deletions src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include "install_config.h"
#include "debug/GfxDebugger.h"

#ifdef __APPLE__
#include "utils/OSXFolderManager.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ void Context::Init(const std::vector<std::string>& otrFiles, const std::unordere
InitConsole();
InitWindow();
InitAudio();
InitGfxDebugger();
}

void Context::InitLogging() {
Expand Down Expand Up @@ -237,6 +239,14 @@ void Context::InitAudio() {
GetAudio()->Init();
}

void Context::InitGfxDebugger() {
if (GetGfxDebugger() != nullptr) {
return;
}

mGfxDebugger = std::make_shared<GfxDebugger>();
}

void Context::InitConsole() {
if (GetConsole() != nullptr) {
return;
Expand Down Expand Up @@ -291,6 +301,10 @@ std::shared_ptr<Audio> Context::GetAudio() {
return mAudio;
}

std::shared_ptr<GfxDebugger> Context::GetGfxDebugger() {
return mGfxDebugger;
}

std::string Context::GetConfigFilePath() {
return mConfigFilePath;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "debug/Console.h"

namespace LUS {
class GfxDebugger;

class Context {
public:
Expand Down Expand Up @@ -47,6 +48,7 @@ class Context {
std::shared_ptr<Window> GetWindow();
std::shared_ptr<Console> GetConsole();
std::shared_ptr<Audio> GetAudio();
std::shared_ptr<GfxDebugger> GetGfxDebugger();

std::string GetConfigFilePath();
std::string GetName();
Expand All @@ -60,6 +62,7 @@ class Context {
void InitControlDeck(std::vector<uint16_t> additionalBitmasks = {});
void InitCrashHandler();
void InitAudio();
void InitGfxDebugger();
void InitConsole();
void InitWindow(std::shared_ptr<GuiWindow> customInputEditorWindow = nullptr);

Expand All @@ -78,6 +81,7 @@ class Context {
std::shared_ptr<Window> mWindow;
std::shared_ptr<Console> mConsole;
std::shared_ptr<Audio> mAudio;
std::shared_ptr<GfxDebugger> mGfxDebugger;

std::string mConfigFilePath;
std::string mMainPath;
Expand Down
54 changes: 54 additions & 0 deletions src/debug/GfxDebugger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "GfxDebugger.h"
#include <spdlog/fmt/fmt.h>

namespace LUS {

void GfxDebugger::ResumeGame() {
mIsDebugging = false;
mIsDebuggingRequested = false;
mDlist = nullptr;
}

const Gfx* GfxDebugger::GetDisplayList() const {
return mDlist;
}

const std::vector<const Gfx*>& GfxDebugger::GetBreakPoint() const {
return mBreakPoint;
}

void GfxDebugger::SetBreakPoint(const std::vector<const Gfx*>& bp) {
mBreakPoint = bp;
}

void GfxDebugger::RequestDebugging() {
mIsDebuggingRequested = true;
}
bool GfxDebugger::IsDebugging() const {
return mIsDebugging;
}
bool GfxDebugger::IsDebuggingRequested() const {
return mIsDebuggingRequested;
}

void GfxDebugger::DebugDisplayList(Gfx* cmds) {
mDlist = cmds;
mIsDebuggingRequested = false;
mIsDebugging = true;
mBreakPoint = { cmds };
}

bool GfxDebugger::HasBreakPoint(const std::vector<const Gfx*>& path) const {
if (path.size() != mBreakPoint.size())
return false;

for (size_t i = 0; i < path.size(); i++) {
if (path[i] != mBreakPoint[i]) {
return false;
}
}

return true;
}

} // namespace LUS
34 changes: 34 additions & 0 deletions src/debug/GfxDebugger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "libultraship/libultra/gbi.h"
#include <string>
#include <vector>

namespace LUS {

class GfxDebugger {
public:
void RequestDebugging();
bool IsDebugging() const;
bool IsDebuggingRequested() const;

void DebugDisplayList(Gfx* cmds);

void ResumeGame();

const Gfx* GetDisplayList() const;

const std::vector<const Gfx*>& GetBreakPoint() const;

bool HasBreakPoint(const std::vector<const Gfx*>& path) const;

void SetBreakPoint(const std::vector<const Gfx*>& bp);

private:
bool mIsDebugging = false;
bool mIsDebuggingRequested = false;
Gfx* mDlist = nullptr;
std::vector<const Gfx*> mBreakPoint = {};
};

} // namespace LUS
Loading

0 comments on commit 4b0486f

Please sign in to comment.