Fix SDL2main on PSP (#5076) - Fix SDL2main on PSP SDL2main was not working for PSP, because it wasn't being activated and it wasn't unsetting the main. Besides that a debug screen being started was causing issues with joystick input and the sceKernelExitGame calli is no longer needed with the current PSPDEV SDK. - Clean up imports in PSP main - Set PSP GPU and user modes in main - Fix exit callback in PSP main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/include/SDL_main.h b/include/SDL_main.h
index ec78e41..43aac97 100644
--- a/include/SDL_main.h
+++ b/include/SDL_main.h
@@ -83,6 +83,15 @@
*/
#define SDL_MAIN_NEEDED
+#elif defined(__PSP__)
+/* On PSP SDL provides a main function that sets the module info,
+ activates the GPU and starts the thread required to be able to exit
+ the software.
+
+ If you provide this yourself, you may define SDL_MAIN_HANDLED
+ */
+#define SDL_MAIN_AVAILABLE
+
#endif
#endif /* SDL_MAIN_HANDLED */
diff --git a/src/main/psp/SDL_psp_main.c b/src/main/psp/SDL_psp_main.c
index 2ca8e44..fb3dd44 100644
--- a/src/main/psp/SDL_psp_main.c
+++ b/src/main/psp/SDL_psp_main.c
@@ -7,11 +7,12 @@
#include "SDL_main.h"
#include <pspkernel.h>
-#include <pspdebug.h>
-#include <pspsdk.h>
#include <pspthreadman.h>
#include <stdlib.h>
-#include <stdio.h>
+
+#ifdef main
+ #undef main
+#endif
/* If application's main() is redefined as SDL_main, and libSDLmain is
linked, then this file will create the standard exit callback,
@@ -23,11 +24,12 @@
PSP_MAIN_THREAD_STACK_SIZE, etc.
*/
-PSP_MODULE_INFO("SDL App", 0, 1, 1);
+PSP_MODULE_INFO("SDL App", 0, 1, 0);
+PSP_MAIN_THREAD_ATTR(THREAD_ATTR_VFPU | THREAD_ATTR_USER);
int sdl_psp_exit_callback(int arg1, int arg2, void *common)
{
- exit(0);
+ sceKernelExitGame();
return 0;
}
@@ -53,12 +55,8 @@ int sdl_psp_setup_callbacks(void)
int main(int argc, char *argv[])
{
- pspDebugScreenInit();
sdl_psp_setup_callbacks();
- /* Register sceKernelExitGame() to be called when we exit */
- atexit(sceKernelExitGame);
-
SDL_SetMainReady();
(void)SDL_main(argc, argv);