ObjFW  Check-in [5c70eba805]

Overview
Comment:ObjFWHID: Add gamepad for Nintendo DS
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5c70eba80531feaaec5d969e99fe30f3f99c4f8610e604d37450c568d33df290
User & Date: js on 2024-06-09 14:34:58
Other Links: manifest | tags
Context
2024-06-09
15:12
ObjFWHID: Make OHGameControllerProfile a protocol check-in: 8be13b6bc6 user: js tags: trunk
14:34
ObjFWHID: Add gamepad for Nintendo DS check-in: 5c70eba805 user: js tags: trunk
12:39
Try all profiles in game controller tests check-in: 2431754f9f user: js tags: trunk
Changes

Modified src/hid/Makefile from [14a7f00a36] to [9c2b6d39ae].

26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
	     OHEvdevDualShock4.m			\
	     OHEvdevExtendedGamepad.m			\
	     OHEvdevGameController.m			\
	     OHEvdevPlayStationExtendedGamepad.m	\
	     OHEvdevStadiaExtendedGamepad.m
SRCS_NINTENDO_3DS = OHNintendo3DSExtendedGamepad.m	\
		    OHNintendo3DSGameController.m
SRCS_NINTENDO_DS = OHNintendoDSGameController.m

SRCS_XINPUT = OHXInputExtendedGamepad.m	\
	      OHXInputGameController.m

INCLUDES := ${SRCS:.m=.h}	\
	    ObjFWHID.h

SRCS += OHGameControllerEmulatedAxis.m		\







|
>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	     OHEvdevDualShock4.m			\
	     OHEvdevExtendedGamepad.m			\
	     OHEvdevGameController.m			\
	     OHEvdevPlayStationExtendedGamepad.m	\
	     OHEvdevStadiaExtendedGamepad.m
SRCS_NINTENDO_3DS = OHNintendo3DSExtendedGamepad.m	\
		    OHNintendo3DSGameController.m
SRCS_NINTENDO_DS = OHNintendoDSGamepad.m	\
		   OHNintendoDSGameController.m
SRCS_XINPUT = OHXInputExtendedGamepad.m	\
	      OHXInputGameController.m

INCLUDES := ${SRCS:.m=.h}	\
	    ObjFWHID.h

SRCS += OHGameControllerEmulatedAxis.m		\

Modified src/hid/OHNintendoDSGameController.h from [ba9c705bcc] to [9aba480f1a].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * <https://www.gnu.org/licenses/>.
 */

#import "OHGameController.h"

OF_ASSUME_NONNULL_BEGIN

@class OHNintendoDSGameControllerProfile;

@interface OHNintendoDSGameController: OHGameController
{
	OHNintendoDSGameControllerProfile *_rawProfile;
}
@end

OF_ASSUME_NONNULL_END







|



|




17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * <https://www.gnu.org/licenses/>.
 */

#import "OHGameController.h"

OF_ASSUME_NONNULL_BEGIN

@class OHNintendoDSGamepad;

@interface OHNintendoDSGameController: OHGameController
{
	OHNintendoDSGamepad *_gamepad;
}
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHNintendoDSGameController.m from [18aa290f08] to [9d14fc6ff2].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

#import "OHNintendoDSGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerProfile.h"

#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"

#define asm __asm__
#include <nds.h>
#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;

+ (void)initialize
{
	void *pool;

	if (self != [OHNintendoDSGameController class])
		return;







|








<
<
<


<
<
<
<
<

|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36



37
38





39
40
41
42
43
44
45
46
47

#import "OHNintendoDSGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHNintendoDSGamepad.h"

#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"

#define asm __asm__
#include <nds.h>
#undef asm




static OFArray OF_GENERIC(OHGameController *) *controllers;






@implementation OHNintendoDSGameController
@synthesize gamepad = _gamepad;

+ (void)initialize
{
	void *pool;

	if (self != [OHNintendoDSGameController class])
		return;
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
}

- (instancetype)init
{
	self = [super init];

	@try {
		_rawProfile = [[OHNintendoDSGameControllerProfile alloc] init];

		[self retrieveState];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_rawProfile release];

	[super dealloc];
}

- (void)retrieveState
{
	OFDictionary *buttons = _rawProfile.buttons;
	OHGameControllerDirectionalPad *dPad =
	    [_rawProfile.directionalPads objectForKey: @"D-Pad"];
	u32 keys;

	scanKeys();
	keys = keysCurrent();

	[[buttons objectForKey: @"A"] setValue: !!(keys & KEY_A)];
	[[buttons objectForKey: @"B"] setValue: !!(keys & KEY_B)];







|












|






|

|







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
}

- (instancetype)init
{
	self = [super init];

	@try {
		_gamepad = [[OHNintendoDSGamepad alloc] init];

		[self retrieveState];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_gamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	OFDictionary *buttons = _gamepad.buttons;
	OHGameControllerDirectionalPad *dPad =
	    [_gamepad.directionalPads objectForKey: @"D-Pad"];
	u32 keys;

	scanKeys();
	keys = keysCurrent();

	[[buttons objectForKey: @"A"] setValue: !!(keys & KEY_A)];
	[[buttons objectForKey: @"B"] setValue: !!(keys & KEY_B)];
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	[dPad.right setValue: !!(keys & KEY_RIGHT)];
}

- (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;
}
@end







<

|
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|


105
106
107
108
109
110
111

112
113

114











































115
116
117
	[dPad.right setValue: !!(keys & KEY_RIGHT)];
}

- (OFString *)name
{
	return @"Nintendo DS";
}


- (OHGameControllerProfile *)rawProfile

{











































	return _gamepad;
}
@end

Added src/hid/OHNintendoDSGamepad.h version [2368a4d576].























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * 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
 * <https://www.gnu.org/licenses/>.
 */

#import "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHNintendoDSGamepad: OHGamepad
@end

OF_ASSUME_NONNULL_END

Added src/hid/OHNintendoDSGamepad.m version [38e3ed9f0f].































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * 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
 * <https://www.gnu.org/licenses/>.
 */

#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