From ff84ce2b043cef9b0ef42da09ba565115db50014 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 17 Apr 2026 15:28:03 -0500 Subject: [PATCH] Added PSP Accept/Cance --- assets/init.lua | 4 +-- src/dusk/engine/engine.c | 2 ++ src/dusk/system/system.c | 8 ++++++ src/dusk/system/system.h | 10 ++++++- src/dusklinux/system/systemlinux.c | 4 +++ src/dusklinux/system/systemlinux.h | 5 ++++ src/dusklinux/system/systemplatform.h | 1 + src/duskpsp/input/inputpsp.c | 7 +++++ src/duskpsp/network/networkpsp.h | 2 +- src/duskpsp/system/systemplatform.h | 1 + src/duskpsp/system/systempsp.c | 39 +++++++++++++++++++++++++-- src/duskpsp/system/systempsp.h | 7 +++++ src/dusksdl2/input/inputsdl2.c | 5 ++++ 13 files changed, 89 insertions(+), 6 deletions(-) diff --git a/assets/init.lua b/assets/init.lua index 37945756..d7875417 100644 --- a/assets/init.lua +++ b/assets/init.lua @@ -9,8 +9,8 @@ if PSP then inputBind("down", INPUT_ACTION_DOWN) inputBind("left", INPUT_ACTION_LEFT) inputBind("right", INPUT_ACTION_RIGHT) - inputBind("circle", INPUT_ACTION_CANCEL) - inputBind("cross", INPUT_ACTION_ACCEPT) + inputBind("accept", INPUT_ACTION_ACCEPT) + inputBind("cancel", INPUT_ACTION_CANCEL) inputBind("select", INPUT_ACTION_RAGEQUIT) inputBind("lstick_up", INPUT_ACTION_UP) inputBind("lstick_down", INPUT_ACTION_DOWN) diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index 0e0a2715..18c66817 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -21,6 +21,7 @@ #include "game/game.h" #include "physics/physicsmanager.h" #include "network/network.h" +#include "system/system.h" #include "display/mesh/cube.h" #include "display/mesh/plane.h" @@ -62,6 +63,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { ENGINE.argv = argv; // Init systems. Order is important. + errorChain(systemInit()); timeInit(); errorChain(inputInit()); errorChain(assetInit()); diff --git a/src/dusk/system/system.c b/src/dusk/system/system.c index 94287825..7c872a43 100644 --- a/src/dusk/system/system.c +++ b/src/dusk/system/system.c @@ -12,6 +12,14 @@ #error "systemGetActiveDialogTypePlatform is not defined" #endif +#ifndef systemInitPlatform + #error "systemInitPlatform is not defined" +#endif + +errorret_t systemInit() { + return systemInitPlatform(); +} + systemdialogtype_t systemGetActiveDialogType() { return systemGetActiveDialogTypePlatform(); } \ No newline at end of file diff --git a/src/dusk/system/system.h b/src/dusk/system/system.h index 7479b360..e009c7b0 100644 --- a/src/dusk/system/system.h +++ b/src/dusk/system/system.h @@ -6,7 +6,7 @@ */ #pragma once -#include "dusk.h" +#include "error/error.h" typedef enum { SYSTEM_DIALOG_TYPE_NONE, @@ -14,6 +14,14 @@ typedef enum { SYSTEM_DIALOG_TYPE_TICK_BLOCKING } systemdialogtype_t; +/** + * Initializes the system module. This is called really early in the init + * process of the engine. + * + * @return Error code indicating success or failure. + */ +errorret_t systemInit(void); + /** * Basically this is only used on a few system types, it is to ask the plaform, * e.g. PSP "What dialog is currently open?" and then the engine will change the diff --git a/src/dusklinux/system/systemlinux.c b/src/dusklinux/system/systemlinux.c index 30987b5b..cec2f252 100644 --- a/src/dusklinux/system/systemlinux.c +++ b/src/dusklinux/system/systemlinux.c @@ -7,6 +7,10 @@ #include "systemlinux.h" +errorret_t systemInitLinux() { + errorOk(); +} + systemdialogtype_t systemGetActiveDialogTypeLinux() { return SYSTEM_DIALOG_TYPE_NONE; } \ No newline at end of file diff --git a/src/dusklinux/system/systemlinux.h b/src/dusklinux/system/systemlinux.h index 7e8bf508..6bb739be 100644 --- a/src/dusklinux/system/systemlinux.h +++ b/src/dusklinux/system/systemlinux.h @@ -8,6 +8,11 @@ #pragma once #include "system/system.h" +/** + * Initializes the Linux system module. + */ +errorret_t systemInitLinux(void); + /** * Currently just returns SYSTEM_DIALOG_TYPE_NONE. * diff --git a/src/dusklinux/system/systemplatform.h b/src/dusklinux/system/systemplatform.h index 732db4d0..42e34dbe 100644 --- a/src/dusklinux/system/systemplatform.h +++ b/src/dusklinux/system/systemplatform.h @@ -8,4 +8,5 @@ #pragma once #include "system/systemlinux.h" +#define systemInitPlatform systemInitLinux #define systemGetActiveDialogTypePlatform systemGetActiveDialogTypeLinux \ No newline at end of file diff --git a/src/duskpsp/input/inputpsp.c b/src/duskpsp/input/inputpsp.c index 7b1d70c0..df9cc89f 100644 --- a/src/duskpsp/input/inputpsp.c +++ b/src/duskpsp/input/inputpsp.c @@ -7,6 +7,9 @@ #include "input/input.h" +// #define INPUT_PSP_GAMEPAD_BUTTON_ACCEPT INPUT_SDL2_GAMEPAD_BUTTON_CUSTOM +// #define INPUT_PSP_GAMEPAD_BUTTON_CANCEL INPUT_SDL2_GAMEPAD_BUTTON_CUSTOM + inputbuttondata_t INPUT_BUTTON_DATA[] = { { .name = "triangle", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_Y } }, { .name = "cross", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } }, @@ -21,6 +24,10 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = { { .name = "l", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER } }, { .name = "r", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } }, + // Refer to systempsp.c for some extra info. + { .name = "accept", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } }, + { .name = "cancel", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_B } }, + { .name = "lstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } }, { .name = "lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } }, { .name = "lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = true } } }, diff --git a/src/duskpsp/network/networkpsp.h b/src/duskpsp/network/networkpsp.h index 78ff487c..5c527159 100644 --- a/src/duskpsp/network/networkpsp.h +++ b/src/duskpsp/network/networkpsp.h @@ -36,7 +36,7 @@ typedef struct { void (*onFailed)(errorret_t error, void *user); // Used during disconnecting - void *onCompelteUser; + void *onCompleteUser; void (*onComplete)(void *user); } networkpsp_t; diff --git a/src/duskpsp/system/systemplatform.h b/src/duskpsp/system/systemplatform.h index 1f4f8f4e..65a350c7 100644 --- a/src/duskpsp/system/systemplatform.h +++ b/src/duskpsp/system/systemplatform.h @@ -8,4 +8,5 @@ #pragma once #include "system/systempsp.h" +#define systemInitPlatform systemInitPSP #define systemGetActiveDialogTypePlatform systemGetActiveDialogTypePSP \ No newline at end of file diff --git a/src/duskpsp/system/systempsp.c b/src/duskpsp/system/systempsp.c index dbe9c2bb..416da9c1 100644 --- a/src/duskpsp/system/systempsp.c +++ b/src/duskpsp/system/systempsp.c @@ -6,10 +6,45 @@ */ #include "systempsp.h" +#include "input/input.h" +#include "util/string.h" +#include "assert/assert.h" + +errorret_t systemInitPSP() { + // Bind ACCEPT and CANCEL binds. + inputbuttondata_t *buttonCross, *buttonCircle, *buttonAccept, *buttonCancel; + + inputbuttondata_t *i = INPUT_BUTTON_DATA; + while(i->name) { + if(stringCompare(i->name, "cross")) { + buttonCross = i; + } else if(stringCompare(i->name, "circle")) { + buttonCircle = i; + } else if(stringCompare(i->name, "accept")) { + buttonAccept = i; + } else if(stringCompare(i->name, "cancel")) { + buttonCancel = i; + } + i++; + } + + assertNotNull(buttonCross, "Cross button not found!"); + assertNotNull(buttonCircle, "Circle button not found!"); + assertNotNull(buttonAccept, "Accept button not found!"); + assertNotNull(buttonCancel, "Cancel button not found!"); + + if(systemPSPGetCrossButtonSetting() == PSP_UTILITY_ACCEPT_CROSS) { + buttonAccept->button.gpButton = buttonCross->button.gpButton; + buttonCancel->button.gpButton = buttonCircle->button.gpButton; + } else { + buttonAccept->button.gpButton = buttonCircle->button.gpButton; + buttonCancel->button.gpButton = buttonCross->button.gpButton; + } + + errorOk(); +} systemdialogtype_t systemGetActiveDialogTypePSP() { - - return SYSTEM_DIALOG_TYPE_NONE; } diff --git a/src/duskpsp/system/systempsp.h b/src/duskpsp/system/systempsp.h index 50805980..e858db38 100644 --- a/src/duskpsp/system/systempsp.h +++ b/src/duskpsp/system/systempsp.h @@ -9,6 +9,13 @@ #include "system/system.h" #include +/** + * Initializes the PSP system module. + * + * @return Error code indicating success or failure. + */ +errorret_t systemInitPSP(void); + /** * Returns which PSP system dialog is currently open (if any). * diff --git a/src/dusksdl2/input/inputsdl2.c b/src/dusksdl2/input/inputsdl2.c index e1ac5b7d..6972eb0c 100644 --- a/src/dusksdl2/input/inputsdl2.c +++ b/src/dusksdl2/input/inputsdl2.c @@ -73,6 +73,11 @@ float_t inputButtonGetValueSDL2(const inputbutton_t button) { #ifdef DUSK_INPUT_GAMEPAD case INPUT_BUTTON_TYPE_GAMEPAD: { + assertTrue( + button.gpButton < SDL_CONTROLLER_BUTTON_MAX, + "Gamepad button out of range" + ); + if(SDL_GameControllerGetButton( INPUT.platform.controller, button.gpButton )) {