diff --git a/CMakeLists.txt b/CMakeLists.txt index e0b689413..6a3844f17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,8 @@ include(cmake/Utils.cmake) if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND USE_AUTO_VCPKG) include(cmake/automate-vcpkg.cmake) - set(VCPKG_TRIPLET x64-windows-static) - set(VCPKG_TARGET_TRIPLET x64-windows-static) + set(VCPKG_TRIPLET x86-windows-static) + set(VCPKG_TARGET_TRIPLET x86-windows-static) vcpkg_bootstrap() vcpkg_install_packages(zlib bzip2 sdl2 glew) diff --git a/extern/ZAPDUtils/Utils/BitConverter.h b/extern/ZAPDUtils/Utils/BitConverter.h index 46845fe36..c90b3dfbd 100644 --- a/extern/ZAPDUtils/Utils/BitConverter.h +++ b/extern/ZAPDUtils/Utils/BitConverter.h @@ -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; diff --git a/extern/ZAPDUtils/Utils/DiskFile.h b/extern/ZAPDUtils/Utils/DiskFile.h index 74962a02a..51aefb44a 100644 --- a/extern/ZAPDUtils/Utils/DiskFile.h +++ b/extern/ZAPDUtils/Utils/DiskFile.h @@ -81,7 +81,19 @@ class DiskFile static void WriteAllText(const fs::path& filePath, const std::string& text) { + try { + std::filesystem::create_directories(filePath.parent_path().string()); + } catch (std::filesystem::filesystem_error const& ex) { + std::cout << "what(): " << ex.what() << '\n' + << "path1(): " << ex.path1() << '\n' + << "path2(): " << ex.path2() << '\n' + << "code().value(): " << ex.code().value() << '\n' + << "code().message(): " << ex.code().message() << '\n' + << "code().category(): " << ex.code().category().name() << '\n'; + } std::ofstream file(filePath, std::ios::out); + + file.write(text.c_str(), text.size()); } }; diff --git a/include/libultraship/bridge.h b/include/libultraship/bridge.h index 9d4f6dca7..668e6b63e 100644 --- a/include/libultraship/bridge.h +++ b/include/libultraship/bridge.h @@ -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 diff --git a/include/libultraship/libultra/abi.h b/include/libultraship/libultra/abi.h index 99d8ddf35..3b0912f72 100644 --- a/include/libultraship/libultra/abi.h +++ b/include/libultraship/libultra/abi.h @@ -37,6 +37,7 @@ typedef unsigned int u32; #define A_INIT 0x01 #define A_CONTINUE 0x00 #define A_LOOP 0x02 +#define A_ADPCM_SHORT 0x04 #define A_OUT 0x02 #define A_LEFT 0x02 #define A_RIGHT 0x00 @@ -446,13 +447,20 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (u32)(addr); \ } -#define aDuplicate(pkt, count, dmemi, dmemo, a4) \ - { \ - Acmd* _a = (Acmd*)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_DUPLICATE, 24, 8) | _SHIFTL(count, 16, 8) | _SHIFTL(dmemi, 0, 16)); \ - _a->words.w1 = _SHIFTL(dmemo, 16, 16) | _SHIFTL(a4, 0, 16); \ +#define aDuplicate(pkt, numCopies, dmemSrc, dmemDest) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_DUPLICATE, 24, 8) | _SHIFTL(numCopies, 16, 8) | _SHIFTL(dmemSrc, 0, 16)); \ + _a->words.w1 = _SHIFTL(dmemDest, 16, 16) | _SHIFTL(0x80, 0, 16); \ } +//#define aDuplicate(pkt, count, dmemi, dmemo, a4) \ +// { \ +// Acmd* _a = (Acmd*)pkt; \ +// \ +// _a->words.w0 = (_SHIFTL(A_DUPLICATE, 24, 8) | _SHIFTL(count, 16, 8) | _SHIFTL(dmemi, 0, 16)); \ +// _a->words.w1 = _SHIFTL(dmemo, 16, 16) | _SHIFTL(a4, 0, 16); \ +// } #define aAddMixer(pkt, count, dmemi, dmemo, a4) \ { \ diff --git a/include/libultraship/libultra/gbi.h b/include/libultraship/libultra/gbi.h index f72898d72..45e124b8b 100644 --- a/include/libultraship/libultra/gbi.h +++ b/include/libultraship/libultra/gbi.h @@ -343,6 +343,7 @@ #define G_TEXTURE_GEN 0x00040000 #define G_TEXTURE_GEN_LINEAR 0x00080000 #define G_LOD 0x00100000 /* NOT IMPLEMENTED */ +#define G_LIGHTING_POSITIONAL 0x00400000 #if (defined(F3DEX_GBI) || defined(F3DLP_GBI)) #define G_CLIPPING 0x00800000 #else @@ -1270,6 +1271,15 @@ typedef struct { char pad3; } Light_t; +typedef struct { + unsigned char col[3]; + unsigned char unk3; + unsigned char colc[3]; + unsigned char unk7; + short pos[3]; + unsigned char unkE; +} PointLight_t; + typedef struct { unsigned char col[3]; /* ambient light value (rgba) */ char pad1; @@ -1283,6 +1293,7 @@ typedef struct { typedef union { Light_t l; + PointLight_t p; long long int force_structure_alignment[2]; } Light; @@ -2271,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 @@ -2785,6 +2796,9 @@ typedef union { #define gsDPSetAlphaDither(mode) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) #endif +#define gDPSetDither(pkt, mode) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 4, mode) + + /* 'blendmask' is not supported anymore. * The bits are reserved for future use. * Fri May 26 13:45:55 PDT 1995 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de362932b..9044ed8e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,9 @@ add_library(libultraship STATIC) set_target_properties(libultraship PROPERTIES PREFIX "") set_property(TARGET libultraship PROPERTY CXX_STANDARD 20) +# Need to set C11 for libgfxd (_Alignas) +set_property(TARGET libultraship PROPERTY C_STANDARD 11) + set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include) if (CMAKE_SYSTEM_NAME STREQUAL "Windows") @@ -87,7 +90,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 @@ -97,6 +100,8 @@ 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 @@ -104,7 +109,7 @@ set(Source_Files__Public__Bridge ${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}) @@ -115,6 +120,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}) @@ -163,11 +170,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 @@ -349,7 +380,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 ) @@ -398,7 +429,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() diff --git a/src/Context.cpp b/src/Context.cpp index 6140e0458..cb08eb027 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -5,6 +5,7 @@ #include #include #include "install_config.h" +#include "debug/GfxDebugger.h" #ifdef __APPLE__ #include "utils/OSXFolderManager.h" @@ -82,6 +83,7 @@ void Context::Init(const std::vector& otrFiles, const std::unordere InitConsole(); InitWindow(); InitAudio(); + InitGfxDebugger(); } void Context::InitLogging() { @@ -237,6 +239,14 @@ void Context::InitAudio() { GetAudio()->Init(); } +void Context::InitGfxDebugger() { + if (GetGfxDebugger() != nullptr) { + return; + } + + mGfxDebugger = std::make_shared(); +} + void Context::InitConsole() { if (GetConsole() != nullptr) { return; @@ -291,6 +301,10 @@ std::shared_ptr