Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -40,10 +40,15 @@ extern int _CRT_glob; extern void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*); #elif !defined(OF_IOS) extern char **environ; #endif + +#ifdef _PSP +# include +# include +#endif static OFApplication *app = nil; static void atexit_handler(void) @@ -135,11 +140,15 @@ exit(0); } + (void)terminateWithStatus: (int)status { +#ifdef _PSP + sceKernelExitGame(); +#else exit(status); +#endif } - init { self = [super init]; Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -30,10 +30,11 @@ #ifdef _PSP # include # include # include +# include PSP_MODULE_INFO("ObjFW Tests", 0, 0, 0); #endif #ifdef __wii__ # define BOOL OGC_BOOL @@ -47,13 +48,37 @@ RED, GREEN, YELLOW }; +#ifdef _PSP +static int +exit_cb(int arg1, int arg2, void *arg) +{ + sceKernelExitGame(); + + return 0; +} + +static int +callback_thread(SceSize args, void *argp) +{ + sceKernelRegisterExitCallback( + sceKernelCreateCallback("Exit Callback", exit_cb, NULL)); + sceKernelSleepThreadCB(); + + return 0; +} +#endif + int main(int argc, char *argv[]) { +#ifdef _PSP + int tid; +#endif + #if defined(OF_OBJFW_RUNTIME) && !defined(_WIN32) /* This does not work on Win32 if ObjFW is built as a DLL */ atexit(objc_exit); #endif @@ -82,10 +107,17 @@ VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK); #endif #ifdef _PSP pspDebugScreenInit(); + + sceCtrlSetSamplingCycle(0); + sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); + + if ((tid = sceKernelCreateThread("update_thread", callback_thread, + 0x11, 0xFA0, 0, 0)) >= 0) + sceKernelStartThread(tid, 0, 0); #endif #if defined(__wii__) || defined(_PSP) @try { return of_application_main(&argc, &argv, @@ -101,23 +133,27 @@ [delegate outputString: string inColor: RED]; [delegate outputString: backtrace inColor: RED]; +# if defined(__wii__) [delegate outputString: @"Press home button to exit!\n" inColor: NO_COLOR]; for (;;) { -# ifdef __wii__ WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) [OFApplication terminateWithStatus: 1]; VIDEO_WaitVSync(); -# endif } +# elif defined(_PSP) + sceKernelSleepThreadCB(); +# else + abort(); +# endif } #else return of_application_main(&argc, &argv, [TestsAppDelegate class]); #endif } @@ -216,10 +252,26 @@ return; VIDEO_WaitVSync(); } #endif +#ifdef _PSP + [self outputString: @"Press X to continue!\n" + inColor: NO_COLOR]; + for (;;) { + SceCtrlData pad; + + sceCtrlReadBufferPositive(&pad, 1); + if (pad.Buttons & PSP_CTRL_CROSS) { + for (;;) { + sceCtrlReadBufferPositive(&pad, 1); + if (!(pad.Buttons & PSP_CTRL_CROSS)) + return; + } + } + } +#endif } - (void)applicationDidFinishLaunching { #ifdef __wii__ @@ -262,11 +314,11 @@ [self forwardingTests]; #ifdef OF_HAVE_PROPERTIES [self propertiesTests]; #endif -#ifdef __wii__ +#if defined(__wii__) [self outputString: @"Press home button to exit!\n" inColor: NO_COLOR]; for (;;) { WPAD_ScanPads(); @@ -273,10 +325,15 @@ if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) [OFApplication terminateWithStatus: _fails]; VIDEO_WaitVSync(); } +#elif defined(_PSP) + [self outputString: [OFString stringWithFormat: @"%zd tests failed!", + _fails] + inColor: NO_COLOR]; + sceKernelSleepThreadCB(); #else [OFApplication terminateWithStatus: _fails]; #endif } @end