Index: src/OFGameController.m ================================================================== --- src/OFGameController.m +++ src/OFGameController.m @@ -21,12 +21,14 @@ #import "OFGameController.h" #import "OFOutOfRangeException.h" -#ifdef OF_NINTENDO_3DS -# include "platform/3DS/OFGameController.m" +#if defined(OF_NINTENDO_DS) +# include "platform/NintendoDS/OFGameController.m" +#elif defined(F_NINTENDO_3DS) +# include "platform/Nintendo3DS/OFGameController.m" #else @implementation OFGameController @dynamic buttons, pressedButtons, numAxes; + (size_t)numControllers DELETED src/platform/3DS/OFGameController.m Index: src/platform/3DS/OFGameController.m ================================================================== --- src/platform/3DS/OFGameController.m +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#include "config.h" - -#import "OFGameController.h" -#import "OFSet.h" - -#import "OFOutOfRangeException.h" - -#define id id_3ds -#include <3ds.h> -#undef id - -@interface OFGameController () -- (instancetype)of_init OF_METHOD_FAMILY(init); -@end - -static OFGameController *controller; - -static void -initController(void) -{ - controller = [[OFGameController alloc] of_init]; -} - -@implementation OFGameController -+ (size_t)numControllers -{ - return 1; -} - -+ (OFGameController *)controllerWithIndex: (size_t)index -{ - static OFOnceControl onceControl = OFOnceControlInitValue; - - if (index > 0) - @throw [OFOutOfRangeException exception]; - - OFOnce(&onceControl, initController); - - return [[controller retain] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)of_init -{ - return [super init]; -} - -- (OFSet *)buttons -{ - return [OFSet setWithObjects: @"A", @"B", @"Select", @"Start", - @"D-Pad Right", @"D-Pad Left", @"D-Pad Up", @"D-Pad Down", @"R", - @"L", @"X", @"Y", @"ZL", @"ZR", @"C-Stick Right", @"C-Stick Left", - @"C-Stick Up", @"C-Stick Down", nil]; -} - -- (OFSet *)pressedButtons -{ - OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 18]; - u32 keys; - - hidScanInput(); - keys = hidKeysHeld(); - - if (keys & KEY_A) - [pressedButtons addObject: @"A"]; - if (keys & KEY_B) - [pressedButtons addObject: @"A"]; - if (keys & KEY_SELECT) - [pressedButtons addObject: @"Select"]; - if (keys & KEY_START) - [pressedButtons addObject: @"Start"]; - if (keys & KEY_DRIGHT) - [pressedButtons addObject: @"D-Pad Right"]; - if (keys & KEY_DLEFT) - [pressedButtons addObject: @"D-Pad Left"]; - if (keys & KEY_DUP) - [pressedButtons addObject: @"D-Pad Up"]; - if (keys & KEY_DDOWN) - [pressedButtons addObject: @"D-Pad Down"]; - if (keys & KEY_R) - [pressedButtons addObject: @"R"]; - if (keys & KEY_L) - [pressedButtons addObject: @"L"]; - if (keys & KEY_X) - [pressedButtons addObject: @"X"]; - if (keys & KEY_Y) - [pressedButtons addObject: @"Y"]; - if (keys & KEY_ZL) - [pressedButtons addObject: @"ZL"]; - if (keys & KEY_ZR) - [pressedButtons addObject: @"ZR"]; - if (keys & KEY_CSTICK_RIGHT) - [pressedButtons addObject: @"C-Stick Right"]; - if (keys & KEY_CSTICK_LEFT) - [pressedButtons addObject: @"C-Stick Left"]; - if (keys & KEY_CSTICK_UP) - [pressedButtons addObject: @"C-Stick Up"]; - if (keys & KEY_CSTICK_DOWN) - [pressedButtons addObject: @"C-Stick Down"]; - - [pressedButtons makeImmutable]; - - return pressedButtons; -} - -- (size_t)numAxes -{ - return 1; -} - -- (OFPoint)positionOfAxisWithIndex: (size_t)index -{ - circlePosition pos; - - if (index > 0) - @throw [OFOutOfRangeException exception]; - - hidCircleRead(&pos); - - return OFMakePoint( - (float)pos.dx / (pos.dx < 0 ? INT16_MIN : INT16_MAX), - (float)pos.dy / (pos.dy < 0 ? INT16_MIN : INT16_MAX)); -} -@end ADDED src/platform/Nintendo3DS/OFGameController.m Index: src/platform/Nintendo3DS/OFGameController.m ================================================================== --- /dev/null +++ src/platform/Nintendo3DS/OFGameController.m @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OFGameController.h" +#import "OFSet.h" + +#import "OFOutOfRangeException.h" + +#define id id_3ds +#include <3ds.h> +#undef id + +@interface OFGameController () +- (instancetype)of_init OF_METHOD_FAMILY(init); +@end + +static OFGameController *controller; + +static void +initController(void) +{ + controller = [[OFGameController alloc] of_init]; +} + +@implementation OFGameController ++ (size_t)numControllers +{ + return 1; +} + ++ (OFGameController *)controllerWithIndex: (size_t)index +{ + static OFOnceControl onceControl = OFOnceControlInitValue; + + if (index > 0) + @throw [OFOutOfRangeException exception]; + + OFOnce(&onceControl, initController); + + return [[controller retain] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)of_init +{ + return [super init]; +} + +- (OFSet *)buttons +{ + return [OFSet setWithObjects: @"A", @"B", @"Select", @"Start", + @"D-Pad Right", @"D-Pad Left", @"D-Pad Up", @"D-Pad Down", @"R", + @"L", @"X", @"Y", @"ZL", @"ZR", @"C-Stick Right", @"C-Stick Left", + @"C-Stick Up", @"C-Stick Down", nil]; +} + +- (OFSet *)pressedButtons +{ + OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 18]; + u32 keys; + + hidScanInput(); + keys = hidKeysHeld(); + + if (keys & KEY_A) + [pressedButtons addObject: @"A"]; + if (keys & KEY_B) + [pressedButtons addObject: @"A"]; + if (keys & KEY_SELECT) + [pressedButtons addObject: @"Select"]; + if (keys & KEY_START) + [pressedButtons addObject: @"Start"]; + if (keys & KEY_DRIGHT) + [pressedButtons addObject: @"D-Pad Right"]; + if (keys & KEY_DLEFT) + [pressedButtons addObject: @"D-Pad Left"]; + if (keys & KEY_DUP) + [pressedButtons addObject: @"D-Pad Up"]; + if (keys & KEY_DDOWN) + [pressedButtons addObject: @"D-Pad Down"]; + if (keys & KEY_R) + [pressedButtons addObject: @"R"]; + if (keys & KEY_L) + [pressedButtons addObject: @"L"]; + if (keys & KEY_X) + [pressedButtons addObject: @"X"]; + if (keys & KEY_Y) + [pressedButtons addObject: @"Y"]; + if (keys & KEY_ZL) + [pressedButtons addObject: @"ZL"]; + if (keys & KEY_ZR) + [pressedButtons addObject: @"ZR"]; + if (keys & KEY_CSTICK_RIGHT) + [pressedButtons addObject: @"C-Stick Right"]; + if (keys & KEY_CSTICK_LEFT) + [pressedButtons addObject: @"C-Stick Left"]; + if (keys & KEY_CSTICK_UP) + [pressedButtons addObject: @"C-Stick Up"]; + if (keys & KEY_CSTICK_DOWN) + [pressedButtons addObject: @"C-Stick Down"]; + + [pressedButtons makeImmutable]; + + return pressedButtons; +} + +- (size_t)numAxes +{ + return 1; +} + +- (OFPoint)positionOfAxisWithIndex: (size_t)index +{ + circlePosition pos; + + if (index > 0) + @throw [OFOutOfRangeException exception]; + + hidCircleRead(&pos); + + return OFMakePoint( + (float)pos.dx / (pos.dx < 0 ? INT16_MIN : INT16_MAX), + (float)pos.dy / (pos.dy < 0 ? INT16_MIN : INT16_MAX)); +} +@end ADDED src/platform/NintendoDS/OFGameController.m Index: src/platform/NintendoDS/OFGameController.m ================================================================== --- /dev/null +++ src/platform/NintendoDS/OFGameController.m @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OFGameController.h" +#import "OFSet.h" + +#import "OFOutOfRangeException.h" + +#define asm __asm__ +#include +#undef asm + +@interface OFGameController () +- (instancetype)of_init OF_METHOD_FAMILY(init); +@end + +static OFGameController *controller; + +static void +initController(void) +{ + controller = [[OFGameController alloc] of_init]; +} + +@implementation OFGameController ++ (size_t)numControllers +{ + return 1; +} + ++ (OFGameController *)controllerWithIndex: (size_t)index +{ + static OFOnceControl onceControl = OFOnceControlInitValue; + + if (index > 0) + @throw [OFOutOfRangeException exception]; + + OFOnce(&onceControl, initController); + + return [[controller retain] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)of_init +{ + return [super init]; +} + +- (OFSet *)buttons +{ + return [OFSet setWithObjects: @"A", @"B", @"Select", @"Start", + @"D-Pad Right", @"D-Pad Left", @"D-Pad Up", @"D-Pad Down", @"R", + @"L", @"X", @"Y", nil]; +} + +- (OFSet *)pressedButtons +{ + OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 12]; + uint32 keys; + + scanKeys(); + keys = keysCurrent(); + + if (keys & KEY_A) + [pressedButtons addObject: @"A"]; + if (keys & KEY_B) + [pressedButtons addObject: @"A"]; + if (keys & KEY_SELECT) + [pressedButtons addObject: @"Select"]; + if (keys & KEY_START) + [pressedButtons addObject: @"Start"]; + if (keys & KEY_RIGHT) + [pressedButtons addObject: @"D-Pad Right"]; + if (keys & KEY_LEFT) + [pressedButtons addObject: @"D-Pad Left"]; + if (keys & KEY_UP) + [pressedButtons addObject: @"D-Pad Up"]; + if (keys & KEY_DOWN) + [pressedButtons addObject: @"D-Pad Down"]; + if (keys & KEY_R) + [pressedButtons addObject: @"R"]; + if (keys & KEY_L) + [pressedButtons addObject: @"L"]; + if (keys & KEY_X) + [pressedButtons addObject: @"X"]; + if (keys & KEY_Y) + [pressedButtons addObject: @"Y"]; + + [pressedButtons makeImmutable]; + + return pressedButtons; +} + +- (size_t)numAxes +{ + return 0; +} + +- (OFPoint)positionOfAxisWithIndex: (size_t)index +{ + @throw [OFOutOfRangeException exception]; +} +@end Index: src/test/OTAppDelegate.m ================================================================== --- src/test/OTAppDelegate.m +++ src/test/OTAppDelegate.m @@ -321,22 +321,11 @@ if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) break; VIDEO_WaitVSync(); } -#elif defined(OF_NINTENDO_DS) - [OFStdOut setForegroundColor: [OFColor silver]]; - [OFStdOut writeLine: @"Press A to continue"]; - - for (;;) { - swiWaitForVBlank(); - scanKeys(); - - if (keysDown() & KEY_A) - break; - } -#elif defined(OF_NINTENDO_3DS) +#elif defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); @@ -344,11 +333,15 @@ [OFGameController controllerWithIndex: 0]; if ([controller.pressedButtons containsObject: @"A"]) break; +# if defined(OF_NINTENDO_DS) + swiWaitForVBlank(); +# elif defined(OF_NINTENDO_3DS) gspWaitForVBlank(); +# endif objc_autoreleasePoolPop(pool); } #elif defined(OF_NINTENDO_SWITCH) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"];