Index: src/hid/Makefile ================================================================== --- src/hid/Makefile +++ src/hid/Makefile @@ -28,11 +28,12 @@ OHEvdevGameController.m \ OHEvdevPlayStationExtendedGamepad.m \ OHEvdevStadiaExtendedGamepad.m SRCS_NINTENDO_3DS = OHNintendo3DSExtendedGamepad.m \ OHNintendo3DSGameController.m -SRCS_NINTENDO_DS = OHNintendoDSGameController.m +SRCS_NINTENDO_DS = OHNintendoDSGamepad.m \ + OHNintendoDSGameController.m SRCS_XINPUT = OHXInputExtendedGamepad.m \ OHXInputGameController.m INCLUDES := ${SRCS:.m=.h} \ ObjFWHID.h Index: src/hid/OHNintendoDSGameController.h ================================================================== --- src/hid/OHNintendoDSGameController.h +++ src/hid/OHNintendoDSGameController.h @@ -19,14 +19,14 @@ #import "OHGameController.h" OF_ASSUME_NONNULL_BEGIN -@class OHNintendoDSGameControllerProfile; +@class OHNintendoDSGamepad; @interface OHNintendoDSGameController: OHGameController { - OHNintendoDSGameControllerProfile *_rawProfile; + OHNintendoDSGamepad *_gamepad; } @end OF_ASSUME_NONNULL_END Index: src/hid/OHNintendoDSGameController.m ================================================================== --- src/hid/OHNintendoDSGameController.m +++ src/hid/OHNintendoDSGameController.m @@ -23,31 +23,23 @@ #import "OFArray.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerProfile.h" +#import "OHNintendoDSGamepad.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #define asm __asm__ #include #undef asm -@interface OHNintendoDSGameControllerProfile: OHGameControllerProfile -@end - static OFArray OF_GENERIC(OHGameController *) *controllers; -static OFString *const buttonNames[] = { - @"A", @"B", @"X", @"Y", @"L", @"R", @"Start", @"Select" -}; -static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); - @implementation OHNintendoDSGameController -@synthesize rawProfile = _rawProfile; +@synthesize gamepad = _gamepad; + (void)initialize { void *pool; @@ -68,11 +60,11 @@ - (instancetype)init { self = [super init]; @try { - _rawProfile = [[OHNintendoDSGameControllerProfile alloc] init]; + _gamepad = [[OHNintendoDSGamepad alloc] init]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; @@ -81,20 +73,20 @@ return self; } - (void)dealloc { - [_rawProfile release]; + [_gamepad release]; [super dealloc]; } - (void)retrieveState { - OFDictionary *buttons = _rawProfile.buttons; + OFDictionary *buttons = _gamepad.buttons; OHGameControllerDirectionalPad *dPad = - [_rawProfile.directionalPads objectForKey: @"D-Pad"]; + [_gamepad.directionalPads objectForKey: @"D-Pad"]; u32 keys; scanKeys(); keys = keysCurrent(); @@ -115,56 +107,11 @@ - (OFString *)name { return @"Nintendo DS"; } -@end - -@implementation OHNintendoDSGameControllerProfile -- (instancetype)init -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - OFMutableDictionary *buttons = - [OFMutableDictionary dictionaryWithCapacity: numButtons]; - OHGameControllerButton *up, *down, *left, *right; - OHGameControllerDirectionalPad *dPad; - - for (size_t i = 0; i < numButtons; i++) { - OHGameControllerButton *button = - [[[OHGameControllerButton alloc] - initWithName: buttonNames[i]] autorelease]; - [buttons setObject: button forKey: buttonNames[i]]; - } - [buttons makeImmutable]; - _buttons = [buttons retain]; - - up = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Up"] autorelease]; - down = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Down"] autorelease]; - left = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Left"] autorelease]; - right = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Right"] autorelease]; - dPad = [[[OHGameControllerDirectionalPad alloc] - initWithName: @"D-Pad" - up: up - down: down - left: left - right: right] autorelease]; - - _directionalPads = [[OFDictionary alloc] - initWithObject: dPad - forKey: @"D-Pad"]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; + +- (OHGameControllerProfile *)rawProfile +{ + return _gamepad; } @end ADDED src/hid/OHNintendoDSGamepad.h Index: src/hid/OHNintendoDSGamepad.h ================================================================== --- /dev/null +++ src/hid/OHNintendoDSGamepad.h @@ -0,0 +1,27 @@ +/* + * 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 + * . + */ + +#import "OHGamepad.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OHNintendoDSGamepad: OHGamepad +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHNintendoDSGamepad.m Index: src/hid/OHNintendoDSGamepad.m ================================================================== --- /dev/null +++ src/hid/OHNintendoDSGamepad.m @@ -0,0 +1,127 @@ +/* + * 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 "OHNintendoDSGamepad.h" +#import "OFDictionary.h" +#import "OHGameControllerButton.h" +#import "OHGameControllerDirectionalPad.h" + +static OFString *const buttonNames[] = { + @"A", @"B", @"X", @"Y", @"L", @"R", @"Start", @"Select" +}; +static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); + +@implementation OHNintendoDSGamepad +- (instancetype)init +{ + self = [super init]; + + @try { + void *pool = objc_autoreleasePoolPush(); + OFMutableDictionary *buttons = + [OFMutableDictionary dictionaryWithCapacity: numButtons]; + OHGameControllerButton *up, *down, *left, *right; + OHGameControllerDirectionalPad *dPad; + + for (size_t i = 0; i < numButtons; i++) { + OHGameControllerButton *button = + [[[OHGameControllerButton alloc] + initWithName: buttonNames[i]] autorelease]; + [buttons setObject: button forKey: buttonNames[i]]; + } + [buttons makeImmutable]; + _buttons = [buttons retain]; + + _axes = [[OFMutableDictionary alloc] init]; + + up = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Up"] autorelease]; + down = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Down"] autorelease]; + left = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Left"] autorelease]; + right = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Right"] autorelease]; + dPad = [[[OHGameControllerDirectionalPad alloc] + initWithName: @"D-Pad" + up: up + down: down + left: left + right: right] autorelease]; + + _directionalPads = [[OFDictionary alloc] + initWithObject: dPad + forKey: @"D-Pad"]; + + objc_autoreleasePoolPop(pool); + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (OHGameControllerButton *)northButton +{ + return [_buttons objectForKey: @"X"]; +} + +- (OHGameControllerButton *)southButton +{ + return [_buttons objectForKey: @"B"]; +} + +- (OHGameControllerButton *)westButton +{ + return [_buttons objectForKey: @"Y"]; +} + +- (OHGameControllerButton *)eastButton +{ + return [_buttons objectForKey: @"A"]; +} + +- (OHGameControllerButton *)leftShoulderButton +{ + return [_buttons objectForKey: @"L"]; +} + +- (OHGameControllerButton *)rightShoulderButton +{ + return [_buttons objectForKey: @"R"]; +} + +- (OHGameControllerButton *)menuButton +{ + return [_buttons objectForKey: @"Start"]; +} + +- (OHGameControllerButton *)optionsButton +{ + return [_buttons objectForKey: @"Select"]; +} + +- (OHGameControllerDirectionalPad *)dPad +{ + return [_directionalPads objectForKey: @"D-Pad"]; +} +@end