From 1940c26bce9a78bcdbe08117049b9e3a1e970805 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Mon, 8 Apr 2024 20:54:05 -0600 Subject: [PATCH 1/2] Fixed vs --- src/engine/fox_hud.c | 11 +++---- src/engine/fox_radio.c | 6 ++-- src/engine/fox_versus.c | 57 +++++++------------------------------ src/engine/guPerspectiveF.c | 6 ++-- src/libultra/gu/mtxutil.c | 10 +++---- src/sys/sys_main.c | 16 +++++------ src/sys/sys_matrix.c | 2 +- 7 files changed, 34 insertions(+), 74 deletions(-) diff --git a/src/engine/fox_hud.c b/src/engine/fox_hud.c index 1b51f4aa..ae3245a4 100644 --- a/src/engine/fox_hud.c +++ b/src/engine/fox_hud.c @@ -586,7 +586,8 @@ void HUD_VenomTitleCard_Draw(void) { RCP_SetupDL(&gMasterDisp, SETUPDL_76); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - Lib_TextureRect_IA8(&gMasterDisp, D_800D1C9C[i], D_800D1CA4[i], 19, D_800D1CB4[i], D_800D1CBC[i] - 28.0f, 1.0f, 1.0f); + Lib_TextureRect_IA8(&gMasterDisp, D_800D1C9C[i], D_800D1CA4[i], 19, D_800D1CB4[i], D_800D1CBC[i] - 28.0f, 1.0f, + 1.0f); } } @@ -663,9 +664,8 @@ void HUD_TitleCard_Draw(f32 x, f32 y) { HUD_VenomTitleCard_Draw(); } - Lib_TextureRect_IA8(&gMasterDisp, - sLevelTitleCard[levelIdx].titleCardTex, - sLevelTitleCard[levelIdx].titleCardWidth, sLevelTitleCard[levelIdx].titleCardHeight, x2, y2, 1.0f, 1.0f); + Lib_TextureRect_IA8(&gMasterDisp, sLevelTitleCard[j].titleCardTex, sLevelTitleCard[j].titleCardWidth, sLevelTitleCard[j].titleCardHeight, x2, y2, 1.0f, + 1.0f); if ((gSavedObjectLoadIndex == 0) && (gAllRangeCheckpoint == 0) && (gCurrentLevel != LEVEL_VENOM_ANDROSS) && (gCurrentLevel != LEVEL_TRAINING)) { @@ -1614,7 +1614,8 @@ void HUD_PauseScreen_Update(void) { RCP_SetupDL(&gMasterDisp, SETUPDL_76); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - Lib_TextureRect_IA8(&gMasterDisp, sLevelTitleCard[j].titleCardTex, sLevelTitleCard[j].titleCardWidth, sLevelTitleCard[j].titleCardHeight, x2, y2 + i, 1.0f, 1.0f); + Lib_TextureRect_IA8(&gMasterDisp, sLevelTitleCard[j].titleCardTex, sLevelTitleCard[j].titleCardWidth, sLevelTitleCard[j].titleCardHeight, x2, + y2 + i, 1.0f, 1.0f); HUD_MsgWindowBg_Draw2(x1 - 10.0f, y0 - 4.0f, 4.7f, 2.8f); diff --git a/src/engine/fox_radio.c b/src/engine/fox_radio.c index 881dee6d..48ddb59e 100644 --- a/src/engine/fox_radio.c +++ b/src/engine/fox_radio.c @@ -428,12 +428,10 @@ void func_radio_800BAAE8(void) { if (mirror) { Lib_TextureRect_RGBA16_MirX(&gMasterDisp, radioPortraitTex, 44, 44, gRadioPortraitPosX, - gRadioPortraitPosY + 20.0f + sp38 + gRadioPortraitScaleY, 1.0f, - gRadioPortraitScaleY); + gRadioPortraitPosY + 20.0f + sp38 + gRadioPortraitScaleY, 1.0f, gRadioPortraitScaleY); } else { Lib_TextureRect_RGBA16(&gMasterDisp, radioPortraitTex, 44, 44, gRadioPortraitPosX, - gRadioPortraitPosY + 20.0f + sp38 + gRadioPortraitScaleY, 1.0f, - gRadioPortraitScaleY); + gRadioPortraitPosY + 20.0f + sp38 + gRadioPortraitScaleY, 1.0f, gRadioPortraitScaleY); } } } diff --git a/src/engine/fox_versus.c b/src/engine/fox_versus.c index 9b39e5ea..8ad870d2 100644 --- a/src/engine/fox_versus.c +++ b/src/engine/fox_versus.c @@ -88,72 +88,39 @@ void func_versus_800BC88C(f32 xPos, f32 yPos, f32 scale) { } void func_versus_800BC8D8(f32 xPos, f32 yPos, f32 scale) { - s32 i; - - for (i = 0; i < 2; i++) { - Lib_TextureRect_CI8(&gMasterDisp, D_versus_300A470 + (152 * 8 * i), D_versus_300B218, 152, 8, xPos, - yPos + (8 * i * scale), scale, scale); - } - - Lib_TextureRect_CI8(&gMasterDisp, D_versus_300A470 + (152 * 8 * i), D_versus_300B218, 152, 7, xPos, - yPos + (8 * i * scale), scale, scale); + Lib_TextureRect_CI8(&gMasterDisp, D_versus_300A470, D_versus_300B218, 152, 23, xPos, yPos, scale, scale); } void func_versus_800BC9DC(f32 xPos, f32 yPos, f32 scale, s32 yScale) { u16* D_800D4AA4[] = { D_versus_3008DE0, D_versus_30098C0, D_versus_300A390 }; u8* D_800D4ABC[] = { D_versus_30087A0, D_versus_3008EC0, D_versus_3009990 }; s32 D_800D4AB0[] = { 40, 64, 64 }; - s32 i; - for (i = 0; i < 5; i++) { - Lib_TextureRect_CI8(&gMasterDisp, D_800D4ABC[yScale] + (D_800D4AB0[yScale] * 8 * i), D_800D4AA4[yScale], - D_800D4AB0[yScale], 8, xPos, yPos + (8 * i * scale), scale, scale); - } + Lib_TextureRect_CI8(&gMasterDisp, D_800D4ABC[yScale], D_800D4AA4[yScale], D_800D4AB0[yScale], 40, xPos, yPos, scale, + scale); } void func_versus_800BCB44(f32 xPos, f32 yPos, f32 scale) { - s32 i; - - for (i = 0; i < 2; i++) { - Lib_TextureRect_CI8(&gMasterDisp, D_versus_3006C60 + (96 * 8 * i), D_versus_3007500, 96, 8, xPos, - yPos + (8 * i * scale), scale, scale); - } - Lib_TextureRect_CI8(&gMasterDisp, D_versus_3006C60 + (96 * 8 * i), D_versus_3007500, 96, 7, xPos, - yPos + (8 * i * scale), scale, scale); + Lib_TextureRect_CI8(&gMasterDisp, D_versus_3006C60, D_versus_3007500, 96, 23, xPos, yPos, scale, scale); } void func_versus_800BCC48(f32 xPos, f32 yPos, f32 xScale, f32 yScale, s32 arg4) { u16* D_800D4AC8[] = { D_versus_3006A68, D_versus_3008598, D_versus_300C458, D_versus_3005E38 }; u8* D_800D4AD8[] = { D_versus_3006040, D_versus_30076C0, D_versus_300B3F0, D_versus_3004F60 }; s32 D_800D4AE8[] = { 104, 152, 168, 152 }; - s32 i; - for (i = 0; i < 3; i++) { - Lib_TextureRect_CI8(&gMasterDisp, D_800D4AD8[arg4] + (D_800D4AE8[arg4] * 8 * i), D_800D4AC8[arg4], - D_800D4AE8[arg4], 8, xPos, yPos + (8 * i * yScale), xScale, yScale); - } - Lib_TextureRect_CI8(&gMasterDisp, D_800D4AD8[arg4] + (D_800D4AE8[arg4] * 8 * i), D_800D4AC8[arg4], D_800D4AE8[arg4], - 1, xPos, yPos + (8 * i * yScale), xScale, yScale); + Lib_TextureRect_CI8(&gMasterDisp, D_800D4AD8[arg4], D_800D4AC8[arg4], D_800D4AE8[arg4], 25, xPos, yPos, xScale, + yScale); } void func_versus_800BCE24(f32 xPos, f32 yPos, f32 xScale, f32 yScale) { - s32 i; - - for (i = 0; i < 6; i++) { - Lib_TextureRect_CI8(&gMasterDisp, D_versus_3001420 + (256 * 7 * i), D_versus_3003E20, 256, 7, xPos, - yPos + (7 * i * yScale), xScale, yScale); - } + Lib_TextureRect_CI8(&gMasterDisp, D_versus_3001420, D_versus_3003E20, 256, 42, xPos, yPos, xScale, yScale); } void func_versus_800BCEF8(f32 xPos, f32 yPos, f32 scale) { s32 i; - for (i = 0; i < 12; i++) { - Lib_TextureRect_CI8(&gMasterDisp, D_versus_3004010 + (136 * 2 * i), D_versus_3004D58, 136, 2, xPos, - yPos + (2 * i * scale), scale, scale); - } - Lib_TextureRect_CI8(&gMasterDisp, D_versus_3004010 + (136 * 2 * i), D_versus_3004D58, 136, 1, xPos, - yPos + (2 * i * scale), scale, scale); + Lib_TextureRect_CI8(&gMasterDisp, D_versus_3004010, D_versus_3004D58, 136, 25, xPos, yPos, scale, scale); } void func_versus_800BCFFC(f32 xPos, f32 yPos, f32 xScale, f32 yScale) { @@ -203,12 +170,8 @@ void func_versus_800BD350(f32 xPos, f32 yPos) { void func_versus_800BD3A8(f32 xPos, f32 yPos) { s32 i; - for (i = 0; i < 8; i++) { - Lib_TextureRect_CI4(&gMasterDisp, aVsHandicapFrameTex + ((80 * 8 * i) / 2), aVsHandicapFrameTLUT, 80, 8, xPos, - yPos + (i * 8), 1.0f, 1.0f); - } - Lib_TextureRect_CI4(&gMasterDisp, aVsHandicapFrameTex + ((80 * 8 * i) / 2), aVsHandicapFrameTLUT, 80, 7, xPos, - yPos + (i * 8), 1.0f, 1.0f); + Lib_TextureRect_CI4(&gMasterDisp, aVsHandicapFrameTex + ((80 * 8 * i) / 2), aVsHandicapFrameTLUT, 80, 71, xPos, yPos, 1.0f, + 1.0f); } void func_versus_800BD4D4(f32 xPos, f32 yPos, s32 arg2) { diff --git a/src/engine/guPerspectiveF.c b/src/engine/guPerspectiveF.c index c567194d..83fd923d 100644 --- a/src/engine/guPerspectiveF.c +++ b/src/engine/guPerspectiveF.c @@ -2,8 +2,7 @@ #include #include "libc/math.h" -void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far, - float scale) { +void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far, float scale) { float yscale; int row; int col; @@ -33,8 +32,7 @@ void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, fl } } -void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far, - float scale) { +void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale) { float mat[4][4]; guPerspectiveF(mat, perspNorm, fovy, aspect, near, far, scale); guMtxF2L(mat, m); diff --git a/src/libultra/gu/mtxutil.c b/src/libultra/gu/mtxutil.c index a89c46ec..e2da48e8 100644 --- a/src/libultra/gu/mtxutil.c +++ b/src/libultra/gu/mtxutil.c @@ -35,14 +35,14 @@ void guMtxL2F(float mf[4][4], Mtx* m) { u32* m1; u32* m2; s32 stmp1, stmp2; - m1 = (u32*)&m->m[0][0]; - m2 = (u32*)&m->m[2][0]; + m1 = (u32*) &m->m[0][0]; + m2 = (u32*) &m->m[2][0]; for (r = 0; r < 4; r++) { for (c = 0; c < 2; c++) { tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff); tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff); - stmp1 = *(s32*)&tmp1; - stmp2 = *(s32*)&tmp2; + stmp1 = *(s32*) &tmp1; + stmp2 = *(s32*) &tmp2; mf[r][c * 2 + 0] = stmp1 / 65536.0f; mf[r][c * 2 + 1] = stmp2 / 65536.0f; } @@ -68,4 +68,4 @@ void guMtxIdent(Mtx* m) { guMtxIdentF(mf); guMtxF2L(mf, m); -} \ No newline at end of file +} diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c index 31ca2913..ae3fcd75 100644 --- a/src/sys/sys_main.c +++ b/src/sys/sys_main.c @@ -247,7 +247,7 @@ void Graphics_ThreadEntry(void* arg0) { // } } -void Graphics_ThreadUpdate(){ +void Graphics_ThreadUpdate() { if (GfxDebuggerIsDebugging()) { Graphics_PushFrame(gGfxPool->masterDL); @@ -279,7 +279,7 @@ void Graphics_ThreadUpdate(){ osRecvMesg(&gGfxTaskMsgQueue, NULL, OS_MESG_BLOCK); Graphics_SetTask(); - if(GfxDebuggerIsDebuggingRequested()) { + if (GfxDebuggerIsDebuggingRequested()) { GfxDebuggerDebugDisplayList(gGfxPool->masterDL); } @@ -289,7 +289,6 @@ void Graphics_ThreadUpdate(){ osViSwapBuffer(&gFrameBuffers[(gSysFrameCount - 1) % 3]); } - // LTODO: FAULT_CRASH // func_80007FE4(&gFrameBuffers[(gSysFrameCount - 1) % 3], SCREEN_WIDTH, 16); @@ -450,7 +449,6 @@ void Main_ThreadEntry(void* arg0) { // LTODO: Implement timers // Timer_ThreadEntry(NULL); - // N64 Stuff should not be needed // Main_InitMesgQueues(); // while (true) { @@ -485,20 +483,22 @@ void Idle_ThreadEntry(void* arg0) { // Main_SetVIMode(); // Lib_FillScreen(1); // osCreatePiManager(OS_PRIORITY_PIMGR, &gPiMgrCmdQueue, sPiMgrCmdBuff, ARRAY_COUNT(sPiMgrCmdBuff)); - // osCreateThread(&gMainThread, THREAD_ID_MAIN, &Main_ThreadEntry, arg0, sMainThreadStack + sizeof(sMainThreadStack), + // osCreateThread(&gMainThread, THREAD_ID_MAIN, &Main_ThreadEntry, arg0, sMainThreadStack + + // sizeof(sMainThreadStack), // 100); // osStartThread(&gMainThread); // Fault_Init(); // osSetThreadPri(NULL, OS_PRIORITY_IDLE); -// loop_1: -// goto loop_1; + // loop_1: + // goto loop_1; } void bootproc(void) { // RdRam_CheckIPL3(); // osInitialize(); Main_Initialize(); - // osCreateThread(&sIdleThread, THREAD_ID_IDLE, &Idle_ThreadEntry, NULL, sIdleThreadStack + sizeof(sIdleThreadStack), + // osCreateThread(&sIdleThread, THREAD_ID_IDLE, &Idle_ThreadEntry, NULL, sIdleThreadStack + + // sizeof(sIdleThreadStack), // 255); // osStartThread(&sIdleThread); } diff --git a/src/sys/sys_matrix.c b/src/sys/sys_matrix.c index 5426b040..7fbd89ca 100644 --- a/src/sys/sys_matrix.c +++ b/src/sys/sys_matrix.c @@ -1,6 +1,6 @@ #include "sys.h" -#define qs1616(e) ((s32)((e)*0x00010000)) +#define qs1616(e) ((s32) ((e) * 0x00010000)) #define IPART(x) ((qs1616(x) >> 16) & 0xFFFF) #define FPART(x) (qs1616(x) & 0xFFFF) From af9c94351ef49fb9ea3bfa4a3cd92bb6f0adcc70 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Tue, 9 Apr 2024 12:49:20 -0600 Subject: [PATCH 2/2] Fixed switch compilation and other weird quirks with deps --- .gitignore | 1 + CMakeLists.txt | 85 +++++++++++++++++++ src/port/Engine.cpp | 6 +- .../importers/MessageLookupFactory.cpp | 4 +- 4 files changed, 91 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ce21454c..f5a9871b 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ torch.hash.yml cmake-build-*/ .idea/ .vs +build* diff --git a/CMakeLists.txt b/CMakeLists.txt index e7c30cee..cb5ea849 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,6 +250,74 @@ add_subdirectory(libultraship ${CMAKE_CURRENT_SOURCE_DIR}/libultraship) add_dependencies(${PROJECT_NAME} libultraship) target_link_libraries(${PROJECT_NAME} PRIVATE libultraship) +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + find_package(glfw3 REQUIRED) + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + "ZAPDLib;" + "glu32;" + "SDL2::SDL2;" + "SDL2::SDL2main;" + "$<$:SDL2_net::SDL2_net-static>" + "glfw;" + "winmm;" + "imm32;" + "version;" + "setupapi" + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + "ZAPDLib;" + "glu32;" + "SDL2::SDL2;" + "SDL2::SDL2main;" + "glfw;" + "winmm;" + "imm32;" + "version;" + "setupapi" + ) + endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") + find_package(SDL2) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + SDL2::SDL2 + -lglad + Threads::Threads + ) +elseif(CMAKE_SYSTEM_NAME STREQUAL "CafeOS") + find_package(SDL2 REQUIRED) + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + SDL2::SDL2-static + + "$<$:-Wl,--wrap=abort>" + ) + target_include_directories(${PROJECT_NAME} PRIVATE + ${DEVKITPRO}/portlibs/wiiu/include/ + ) +else() + find_package(SDL2) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + "ZAPDLib;" + SDL2::SDL2 + "$<$:SDL2_net::SDL2_net>" + ${CMAKE_DL_LIBS} + Threads::Threads + ) +endif() if(USE_NETWORKING) if(MSVC) @@ -261,6 +329,23 @@ if(USE_NETWORKING) target_compile_definitions(${PROJECT_NAME} PRIVATE USE_NETWORKING) endif() +target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}") + +if(CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch") + +nx_generate_nacp(Lylat.nacp + NAME "Lylat64" + AUTHOR "${PROJECT_TEAM}" + VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" +) + +nx_create_nro(${PROJECT_NAME} + NACP Lylat.nacp +) + +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lylat64.nro DESTINATION . COMPONENT ${PROJECT_NAME}) +endif() + ################################################################################ # Compile and link options ################################################################################ diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index c77bdb75..b8614a55 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -154,11 +154,11 @@ extern "C" uint8_t GameEngine_OTRSigCheck(const char* data) { } extern "C" float __cosf(float angle) { - return std::cosf(angle); + return cosf(angle); } extern "C" float __sinf(float angle) { - return std::sinf(angle); + return sinf(angle); } extern "C" float SIN_DEG(float angle) { @@ -183,7 +183,7 @@ uint64_t Timer_GetCurrentMillis() { return SDL_GetTicks(); } -extern "C" int32_t Timer_CreateTask(uint64_t time, TimerAction action, int32_t* address, int32_t value) { +extern "C" s32 Timer_CreateTask(u64 time, TimerAction action, s32* address, s32 value) { const auto millis = Timer_GetCurrentMillis(); TimedEntry entry = { .duration = millis + CYCLES_TO_MSEC_PC(time), diff --git a/src/port/resource/importers/MessageLookupFactory.cpp b/src/port/resource/importers/MessageLookupFactory.cpp index d1d20ac6..8eec7ffb 100644 --- a/src/port/resource/importers/MessageLookupFactory.cpp +++ b/src/port/resource/importers/MessageLookupFactory.cpp @@ -1,8 +1,8 @@ #include "MessageLookupFactory.h" #include "../type/Message.h" #include "spdlog/spdlog.h" - #include "resourcebridge.h" +#include "ResourceUtil.h" namespace SF64 { std::shared_ptr ResourceFactoryBinaryMessageLookupV0::ReadResource(std::shared_ptr file) { @@ -18,7 +18,7 @@ std::shared_ptr ResourceFactoryBinaryMessageLookupV0::ReadResour SPDLOG_INFO("Reading message lookup table entry {}", i); auto id = reader->ReadInt32(); - uint16_t* ptr = static_cast(ResourceGetDataByCrc(reader->ReadUInt64())); + uint16_t* ptr = LoadChild(reader->ReadUInt64()); table->mLookupTable.push_back({ id, ptr }); }