Skip to content

Commit fb469d1

Browse files
committed
Allow game controllers mapping from file
Fixed mapping for PS3-compatible controller
1 parent 20d73c7 commit fb469d1

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

SDL2/src/SDL.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ SDL_GetPlatform()
441441
return "iOS";
442442
#elif __PSP__
443443
return "PlayStation Portable";
444+
#elif defined(__RASPBERRY_PI__)
445+
return "RaspberryPi";
444446
#else
445447
return "Unknown (see SDL_platform.h)";
446448
#endif

SDL2/src/joystick/SDL_gamecontrollerdb.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ static const char *s_ControllerMappings [] =
7171
"030000005e0400009102000007010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
7272
#elif defined(__RASPBERRY_PI__)
7373
"4e45532047616d657061640000000000,NES Gamepad,a:b7,b:b6,dpdown:b2,dpleft:b1,dpright:b0,dpup:b3,guide:b5,start:b4,",
74-
"03000000b50700001302000001010000,Mega World USB 2-Axis 8-Button Gamepad,a:b2,b:b0,x:b3,y:b1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftx:a0,lefty:a1",
75-
"030000004c0500006802000000010000,MY-POWER CO.,LTD 2In1 USB Joystick,x:b7,a:b8,b:b9,y:b10,back:b11,start:b14,dpleft:b18,dpdown:b17,dpright:b16,dpup:b15,guide:b0,leftshoulder:b5,lefttrigger:b3,rightshoulder:b6,righttrigger:b4,leftx:a0,lefty:a1,rightx:a2,righty:a3",
74+
"030000004c0500006802000000010000,PS3 Controller,a:b9,b:b10,back:b7,dpdown:b1,dpleft:b0,dpright:b2,dpup:b3,guide:b18,leftshoulder:b13,leftstick:b6,lefttrigger:b15,leftx:a0,lefty:a1,rightshoulder:b12,rightstick:b5,righttrigger:b14,rightx:a2,righty:a3,start:b4,x:b8,y:b11,",
7675
#endif
7776
NULL
7877
};

abbaye/src/main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include "SDL_image.h"
1313
#include "SDL_mixer.h"
1414

15+
#include "emmc.h"
16+
#include "ff.h"
17+
18+
FATFS FatFs;
19+
1520
extern void startscreen(SDL_Window *screen,uint *state,uint *grapset,uint *fullscreen);
1621
extern void history(SDL_Window *screen,uint *state,uint *grapset,uint *fullscreen);
1722
extern void game(SDL_Window *screen,uint *state,uint *grapset,uint *fullscreen);
@@ -36,6 +41,10 @@ void main () {
3641
uint grapset = 1; /* 0-8bits, 1-16bits */
3742
uint fullscreen = 0; /* 0-Windowed,1-Fullscreen */
3843

44+
if (sd_card_init(NULL) == 0) {
45+
f_mount(&FatFs, "0:", 1);
46+
}
47+
3948
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
4049

4150
/* Creating window */
@@ -45,6 +54,14 @@ void main () {
4554
Mix_OpenAudio (22050,MIX_DEFAULT_FORMAT,2,4096);
4655
Mix_AllocateChannels(5);
4756

57+
/* Init game controllers */
58+
SDL_GameControllerAddMappingsFromFile("control.txt");
59+
for (int i = 0; i < SDL_NumJoysticks(); i++) {
60+
if (SDL_IsGameController(i)) {
61+
SDL_GameControllerOpen(i);
62+
}
63+
}
64+
4865
while (1) {
4966
switch (state) {
5067
case 0: startscreen(screen,&state,&grapset,&fullscreen);

abbaye/src/startscreen.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ void startscreen(SDL_Window *screen,uint *state,uint *grapset,uint *fullscreen)
6464

6565
/* Check keyboard */
6666
if ( SDL_PollEvent(&keyp) ) {
67-
if (keyp.type == SDL_CONTROLLERDEVICEADDED) {
68-
SDL_GameControllerOpen(keyp.cdevice.which);
69-
}
7067
if (keyp.type == SDL_KEYDOWN) { /* Key pressed */
7168
if (keyp.key.keysym.sym == SDLK_c) { /* Change graphic set */
7269
if (*grapset == 0)

0 commit comments

Comments
 (0)