1 /*
2 SDL_psp_main.c, placed in the public domain by Sam Lantinga 3/13/14
3 */
4 #include "SDL_config.h"
5
6 #ifdef __PSP__
7
8 #include "SDL_main.h"
9 #include <pspkernel.h>
10 #include <pspdebug.h>
11 #include <pspsdk.h>
12 #include <pspthreadman.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15
16 /* If application's main() is redefined as SDL_main, and libSDLmain is
17 linked, then this file will create the standard exit callback,
18 define the PSP_MODULE_INFO macro, and exit back to the browser when
19 the program is finished.
20
21 You can still override other parameters in your own code if you
22 desire, such as PSP_HEAP_SIZE_KB, PSP_MAIN_THREAD_ATTR,
23 PSP_MAIN_THREAD_STACK_SIZE, etc.
24 */
25
26 PSP_MODULE_INFO("SDL App", 0, 1, 1);
27
sdl_psp_exit_callback(int arg1,int arg2,void * common)28 int sdl_psp_exit_callback(int arg1, int arg2, void *common)
29 {
30 exit(0);
31 return 0;
32 }
33
sdl_psp_callback_thread(SceSize args,void * argp)34 int sdl_psp_callback_thread(SceSize args, void *argp)
35 {
36 int cbid;
37 cbid = sceKernelCreateCallback("Exit Callback",
38 sdl_psp_exit_callback, NULL);
39 sceKernelRegisterExitCallback(cbid);
40 sceKernelSleepThreadCB();
41 return 0;
42 }
43
sdl_psp_setup_callbacks(void)44 int sdl_psp_setup_callbacks(void)
45 {
46 int thid = 0;
47 thid = sceKernelCreateThread("update_thread",
48 sdl_psp_callback_thread, 0x11, 0xFA0, 0, 0);
49 if(thid >= 0)
50 sceKernelStartThread(thid, 0, 0);
51 return thid;
52 }
53
main(int argc,char * argv[])54 int main(int argc, char *argv[])
55 {
56 pspDebugScreenInit();
57 sdl_psp_setup_callbacks();
58
59 /* Register sceKernelExitGame() to be called when we exit */
60 atexit(sceKernelExitGame);
61
62 SDL_SetMainReady();
63
64 (void)SDL_main(argc, argv);
65 return 0;
66 }
67
68 #endif /* __PSP__ */
69
70 /* vi: set ts=4 sw=4 expandtab: */
71