From d6c497731fabef3d620ccd7278b4decfcc6d5c82 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 9 Nov 2025 20:42:03 -0600 Subject: [PATCH] Fix PSP compiled --- CMakeLists.txt | 4 ++-- src/assert/assert.c | 5 +++-- src/asset/asset.c | 7 +++++-- src/asset/type/assetlanguage.c | 3 --- src/debug/debug.c | 32 ++++++++++---------------------- src/engine/engine.c | 3 +++ src/error/error.c | 3 ++- src/scene/scene/scenetest.c | 1 - src/util/string.c | 13 +++++++++++++ src/util/string.h | 11 ++++++++++- 10 files changed, 48 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a43a4c..df6e432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) if(NOT DEFINED DUSK_TARGET_SYSTEM) - #set(DUSK_TARGET_SYSTEM "linux") - set(DUSK_TARGET_SYSTEM "psp") + set(DUSK_TARGET_SYSTEM "linux") + #set(DUSK_TARGET_SYSTEM "psp") endif() # Prep cache diff --git a/src/assert/assert.c b/src/assert/assert.c index 2f02a16..0d8b02e 100644 --- a/src/assert/assert.c +++ b/src/assert/assert.c @@ -6,6 +6,7 @@ */ #include "assert.h" +#include "debug/debug.h" #ifndef ASSERTIONS_FAKED void assertTrueImpl( @@ -15,13 +16,13 @@ const char *message ) { if(x != true) { - fprintf( - stderr, + debugPrint( "Assertion Failed in %s:%i\n\n%s\n", file, line, message ); + abort(); } } diff --git a/src/asset/asset.c b/src/asset/asset.c index b381954..1c8be10 100644 --- a/src/asset/asset.c +++ b/src/asset/asset.c @@ -11,6 +11,7 @@ #include "assert/assert.h" #include "asset/assettype.h" #include "engine/engine.h" +#include "debug/debug.h" errorret_t assetInit(void) { memoryZero(&ASSET, sizeof(asset_t)); @@ -59,7 +60,10 @@ errorret_t assetInit(void) { assertTrue(ENGINE.argc >= 1, "PSP requires launch argument."); // PSP is given either host0:/Dusk.prx (debugging) OR the PBP file. - if(stringEndsWith(ENGINE.argv[0], ".pbp") || ASSET_PBP_READ_PBP_FROM_HOST) { + if( + stringEndsWithCaseInsensitive(ENGINE.argv[0], ".pbp") || + ASSET_PBP_READ_PBP_FROM_HOST + ) { const char_t *pbpPath = ( ASSET_PBP_READ_PBP_FROM_HOST ? "./EBOOT.PBP" : ENGINE.argv[0] ); @@ -152,7 +156,6 @@ errorret_t assetInit(void) { ); // Try open - printf("Trying to open asset at: %s\n", searchPath); ASSET.zip = zip_open(searchPath, ZIP_RDONLY, NULL); if(ASSET.zip == NULL) continue; break;// Found! diff --git a/src/asset/type/assetlanguage.c b/src/asset/type/assetlanguage.c index 40bc51d..e651702 100644 --- a/src/asset/type/assetlanguage.c +++ b/src/asset/type/assetlanguage.c @@ -30,7 +30,6 @@ errorret_t assetLanguageInit( // We now own the zip file handle. lang->zip = zipFile; - printf("Initialized language asset.\n"); // Read in the header. zip_int64_t bytesRead = zip_fread( @@ -108,6 +107,4 @@ void assetLanguageDispose(assetlanguage_t *lang) { if(lang->zip) { zip_fclose(lang->zip); } - - printf("Disposed language asset.\n"); } \ No newline at end of file diff --git a/src/debug/debug.c b/src/debug/debug.c index 3f5ac13..52c5b1b 100644 --- a/src/debug/debug.c +++ b/src/debug/debug.c @@ -8,28 +8,6 @@ #include "debug.h" void debugPrint(const char_t *message, ...) { - // char_t buffer[CONSOLE_LINE_MAX]; - - // va_list args; - // va_start(args, message); - // int32_t len = stringFormatVA(buffer, CONSOLE_LINE_MAX, message, args); - // va_end(args); - - // // Move all lines back - // memoryMove( - // CONSOLE.line[0], - // CONSOLE.line[1], - // (CONSOLE_HISTORY_MAX - 1) * CONSOLE_LINE_MAX - // ); - - // // Copy the new line - // memoryCopy( - // CONSOLE.line[CONSOLE_HISTORY_MAX - 1], - // buffer, - // len + 1 - // ); - // printf("%s\n", buffer); - va_list args; va_start(args, message); vprintf(message, args); @@ -37,4 +15,14 @@ void debugPrint(const char_t *message, ...) { // For the time being just use standard printing functions. printf(message, args); + + #if PSP + FILE *file = fopen("ms0:/PSP/GAME/Dusk/debug.log", "a"); + if(file) { + va_start(args, message); + vfprintf(file, message, args); + va_end(args); + fclose(file); + } + #endif } \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index 3aa60ec..2bd7a51 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -15,6 +15,7 @@ #include "asset/asset.h" #include "ui/ui.h" #include "rpg/rpg.h" +#include "debug/debug.h" engine_t ENGINE; @@ -24,6 +25,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { ENGINE.argc = argc; ENGINE.argv = argv; + // Init systems. Order is important. timeInit(); inputInit(); @@ -46,6 +48,7 @@ errorret_t engineUpdate(void) { sceneManagerUpdate(); errorChain(displayUpdate()); + if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false; errorOk(); diff --git a/src/error/error.c b/src/error/error.c index fe1b424..64d6132 100644 --- a/src/error/error.c +++ b/src/error/error.c @@ -9,6 +9,7 @@ #include "error.h" #include "util/memory.h" #include "util/string.h" +#include "debug/debug.h" errorret_t errorThrowImpl( errorstate_t *state, @@ -120,7 +121,7 @@ errorret_t errorPrint(const errorret_t retval) { assertNotNull(retval.state, "Error state cannot be NULL"); assertNotNull(retval.state->message, "Message cannot be NULL"); - printf( + debugPrint( ERROR_PRINT_FORMAT, retval.state->code, retval.state->message, diff --git a/src/scene/scene/scenetest.c b/src/scene/scene/scenetest.c index 03bfa4a..1fba899 100644 --- a/src/scene/scene/scenetest.c +++ b/src/scene/scene/scenetest.c @@ -9,7 +9,6 @@ #include "scene/scenedata.h" errorret_t sceneTestInit(scenedata_t *data) { - printf("Scene Test Init\n"); data->sceneTest.nothing = 0; errorOk(); } diff --git a/src/util/string.c b/src/util/string.c index 8b7b668..319cc5f 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -155,4 +155,17 @@ bool_t stringEndsWith(const char_t *str, const char_t *suffix) { size_t suffixLen = strlen(suffix); if(suffixLen > strLen) return false; return strcmp(str + strLen - suffixLen, suffix) == 0; +} + +bool_t stringEndsWithCaseInsensitive( + const char_t *str, + const char_t *suffix +) { + assertNotNull(str, "str must not be NULL"); + assertNotNull(suffix, "suffix must not be NULL"); + + size_t strLen = strlen(str); + size_t suffixLen = strlen(suffix); + if(suffixLen > strLen) return false; + return strcasecmp(str + strLen - suffixLen, suffix) == 0; } \ No newline at end of file diff --git a/src/util/string.h b/src/util/string.h index fda8d95..f269573 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -143,4 +143,13 @@ bool_t stringToF32(const char_t *str, float_t *out); * @param suffix The suffix to check for. * @return TRUE if the string ends with the suffix, FALSE otherwise. */ -bool_t stringEndsWith(const char_t *str, const char_t *suffix); \ No newline at end of file +bool_t stringEndsWith(const char_t *str, const char_t *suffix); + +/** + * Determines if a string ends with a specified suffix, ignoring case. + * + * @param str The string to check. + * @param suffix The suffix to check for. + * @return TRUE if the string ends with the suffix, FALSE otherwise. + */ +bool_t stringEndsWithCaseInsensitive(const char_t *str, const char_t *suffix); \ No newline at end of file