Index: src/OFStdIOStream.h ================================================================== --- src/OFStdIOStream.h +++ src/OFStdIOStream.h @@ -69,10 +69,28 @@ /** * @brief The number of rows, or -1 if there is no underlying terminal or the * number of rows could not be queried. */ @property (readonly, nonatomic) int rows; + +#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) || \ + defined(DOXYGEN) +/** + * @brief Sets up a console for @ref OFStdOut / @ref OFStdErr output on systems + * that don't have a console by default. + * + * @note This method is only available on Wii, Nintendo DS and Nintendo 3DS. + */ ++ (void)setUpConsole; + +/** + * @brief Waits for the vertical blank of the console. + * + * @note This method is only available on Wii, Nintendo DS and Nintendo 3DS. + */ ++ (void)waitForConsoleVBlank; +#endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Sets the foreground color on the underlying terminal. Does nothing if Index: src/OFStdIOStream.m ================================================================== --- src/OFStdIOStream.m +++ src/OFStdIOStream.m @@ -59,16 +59,35 @@ #endif #ifdef OF_MSDOS # include #endif + +#ifdef OF_WII +# define asm __asm__ +# include +# undef asm +#endif #ifdef OF_WII_U # define BOOL WUT_BOOL # include # undef BOOL #endif + +#ifdef OF_NINTENDO_DS +# define asm __asm__ +# include +# undef asm +#endif + +#ifdef OF_NINTENDO_3DS +/* Newer versions of libctru started using id as a parameter name. */ +# define id id_3ds +# include <3ds.h> +# undef id +#endif /* References for static linking */ #ifdef OF_WINDOWS void _reference_to_OFWin32ConsoleStdIOStream(void) @@ -259,10 +278,62 @@ OFStdErr = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; # endif } #endif + +#if defined(OF_WII) ++ (void)setUpConsole +{ + GXRModeObj *mode; + void *nextFB; + + VIDEO_Init(); + + mode = VIDEO_GetPreferredMode(NULL); + nextFB = MEM_K0_TO_K1(SYS_AllocateFramebuffer(mode)); + VIDEO_Configure(mode); + VIDEO_SetNextFramebuffer(nextFB); + VIDEO_SetBlack(FALSE); + VIDEO_Flush(); + + VIDEO_WaitVSync(); + if (mode->viTVMode & VI_NON_INTERLACE) + VIDEO_WaitVSync(); + + CON_InitEx(mode, 2, 2, mode->fbWidth - 4, mode->xfbHeight - 4); + VIDEO_ClearFrameBuffer(mode, nextFB, COLOR_BLACK); +} + ++ (void)waitForConsoleVBlank +{ + VIDEO_WaitVSync(); +} +#elif defined(OF_NINTENDO_DS) ++ (void)setUpConsole +{ + consoleDemoInit(); +} + ++ (void)waitForConsoleVBlank +{ + swiWaitForVBlank(); +} +#elif defined(OF_NINTENDO_3DS) ++ (void)setUpConsole +{ + gfxInitDefault(); + atexit(gfxExit); + + consoleInit(GFX_TOP, NULL); +} + ++ (void)waitForConsoleVBlank +{ + gspWaitForVBlank(); +} +#endif - (instancetype)init { OF_INVALID_INIT_METHOD } Index: src/test/OTAppDelegate.m ================================================================== --- src/test/OTAppDelegate.m +++ src/test/OTAppDelegate.m @@ -36,29 +36,10 @@ #ifdef OF_IOS # include #endif -#ifdef OF_WII -# define asm __asm__ -# include -# undef asm -#endif - -#ifdef OF_NINTENDO_DS -# define asm __asm__ -# include -# undef asm -#endif - -#ifdef OF_NINTENDO_3DS -/* Newer versions of libctru started using id as a parameter name. */ -# define id id_3ds -# include <3ds.h> -# undef id -#endif - #ifdef OF_NINTENDO_SWITCH # define id nx_id # include # undef id @@ -116,36 +97,12 @@ [[OFFileManager defaultManager] changeCurrentDirectoryPath: [OFString stringWithUTF8String: (const char *)resourcesPath]]; CFRelease(resourcesURL); -#elif defined(OF_WII) - GXRModeObj *mode; - void *nextFB; - - VIDEO_Init(); - - mode = VIDEO_GetPreferredMode(NULL); - nextFB = MEM_K0_TO_K1(SYS_AllocateFramebuffer(mode)); - VIDEO_Configure(mode); - VIDEO_SetNextFramebuffer(nextFB); - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - - VIDEO_WaitVSync(); - if (mode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync(); - - CON_InitEx(mode, 2, 2, mode->fbWidth - 4, mode->xfbHeight - 4); - VIDEO_ClearFrameBuffer(mode, nextFB, COLOR_BLACK); -#elif defined(OF_NINTENDO_DS) - consoleDemoInit(); -#elif defined(OF_NINTENDO_3DS) - gfxInitDefault(); - atexit(gfxExit); - - consoleInit(GFX_TOP, NULL); +#elif defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) + [OFStdIOStream setUpConsole]; #elif defined(OF_NINTENDO_SWITCH) consoleInit(NULL); padConfigureInput(1, HidNpadStyleSet_NpadStandard); updateConsole(true); #endif @@ -324,17 +281,12 @@ if ([controller.pressedButtons containsObject: OFGameControllerEastButton]) break; -# if defined(OF_WII) - VIDEO_WaitVSync(); -# elif defined(OF_NINTENDO_DS) - swiWaitForVBlank(); -# elif defined(OF_NINTENDO_3DS) - gspWaitForVBlank(); -# endif + [OFStdIOStream waitForConsoleVBlank]; + objc_autoreleasePoolPop(pool); } #elif defined(OF_NINTENDO_SWITCH) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; @@ -610,17 +562,12 @@ if ([controller.pressedButtons containsObject: OFGameControllerStartButton]) # endif break; -# if defined(OF_WII) - VIDEO_WaitVSync(); -# elif defined(OF_NINTENDO_DS) - swiWaitForVBlank(); -# elif defined(OF_NINTENDO_3DS) - gspWaitForVBlank(); -# endif + [OFStdIOStream waitForConsoleVBlank]; + objc_autoreleasePoolPop(pool); } #elif defined(OF_NINTENDO_SWITCH) while (appletMainLoop()) updateConsole(true); Index: tests/gamecontroller/GameControllerTests.m ================================================================== --- tests/gamecontroller/GameControllerTests.m +++ tests/gamecontroller/GameControllerTests.m @@ -27,33 +27,17 @@ #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFThread.h" -#ifdef OF_WII -# define asm __asm__ -# include -# undef asm -#endif - -#ifdef OF_NINTENDO_DS -# define asm __asm__ -# include -# undef asm -# define BUTTONS_PER_LINE 2 -#endif - -#ifdef OF_NINTENDO_3DS -/* Newer versions of libctru started using id as a parameter name. */ -# define id id_3ds -# include <3ds.h> -# undef id -# define BUTTONS_PER_LINE 3 -#endif - -#ifndef BUTTONS_PER_LINE -# define BUTTONS_PER_LINE 5 + +#if defined(OF_NINTENDO_DS) +static size_t buttonsPerLine = 2; +#elif defined(OF_NINTENDO_3DS) +static size_t buttonsPerLine = 3; +#else +static size_t buttonsPerLine = 5; #endif #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) # define red maroon # define yellow olive @@ -70,36 +54,12 @@ OF_APPLICATION_DELEGATE(GameControllerTests) @implementation GameControllerTests - (void)applicationDidFinishLaunching: (OFNotification *)notification { -#if defined(OF_WII) - GXRModeObj *mode; - void *nextFB; - - VIDEO_Init(); - - mode = VIDEO_GetPreferredMode(NULL); - nextFB = MEM_K0_TO_K1(SYS_AllocateFramebuffer(mode)); - VIDEO_Configure(mode); - VIDEO_SetNextFramebuffer(nextFB); - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - - VIDEO_WaitVSync(); - if (mode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync(); - - CON_InitEx(mode, 2, 2, mode->fbWidth - 4, mode->xfbHeight - 4); - VIDEO_ClearFrameBuffer(mode, nextFB, COLOR_BLACK); -#elif defined(OF_NINTENDO_DS) - consoleDemoInit(); -#elif defined(OF_NINTENDO_3DS) - gfxInitDefault(); - atexit(gfxExit); - - consoleInit(GFX_TOP, NULL); +#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) + [OFStdIOStream setUpConsole]; #endif for (;;) { void *pool = objc_autoreleasePoolPush(); @@ -148,11 +108,11 @@ [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeFormat: @"[%@]", button]; - if (++i == BUTTONS_PER_LINE) { + if (++i == buttonsPerLine) { i = 0; } else [OFStdOut writeString: @" "]; } [OFStdOut setForegroundColor: [OFColor gray]]; @@ -171,11 +131,15 @@ position.x, position.y]; } [OFStdOut writeString: @"\n"]; } +#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) + [OFStdIOStream waitForConsoleVBlank]; +#else [OFThread sleepForTimeInterval: 1.f / 60.f]; +#endif objc_autoreleasePoolPop(pool); } } @end