aboutsummaryrefslogtreecommitdiff
path: root/games/SameBoy/joypad.patch
blob: fc089e4223592de1600a805585cd0c166e5d4257 (plain)
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
From 7ffed9c43cd533c4ab16ab9d8b0879a39a00a02b Mon Sep 17 00:00:00 2001
From: Lior Halphon <LIJI32@gmail.com>
Date: Sat, 10 Nov 2018 19:39:57 +0200
Subject: [PATCH] Reconnect the joypad when SameBoy starts directly to a ROM
 (fixes #131)

---
 SDL/gui.c  | 10 ++++++++--
 SDL/gui.h  |  1 +
 SDL/main.c |  3 +++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/SDL/gui.c b/SDL/gui.c
index c32eec4d..ed9f3573 100644
--- a/SDL/gui.c
+++ b/SDL/gui.c
@@ -721,8 +721,7 @@ joypad_axis_t get_joypad_axis(uint8_t physical_axis)
 }
 
 
-extern void set_filename(const char *new_filename, bool new_should_free);
-void run_gui(bool is_running)
+void connect_joypad(void)
 {
     if (joystick && !SDL_NumJoysticks()) {
         if (controller) {
@@ -743,6 +742,13 @@ void run_gui(bool is_running)
             joystick = SDL_JoystickOpen(0);
         }
     }
+}
+
+extern void set_filename(const char *new_filename, bool new_should_free);
+void run_gui(bool is_running)
+{
+    connect_joypad();
+    
     /* Draw the background screen */
     static SDL_Surface *converted_background = NULL;
     if (!converted_background) {
diff --git a/SDL/gui.h b/SDL/gui.h
index 9893eb61..4d106143 100644
--- a/SDL/gui.h
+++ b/SDL/gui.h
@@ -92,6 +92,7 @@ extern configuration_t configuration;
 void update_viewport(void);
 void run_gui(bool is_running);
 void render_texture(void *pixels, void *previous);
+void connect_joypad(void);
 
 joypad_button_t get_joypad_button(uint8_t physical_button);
 joypad_axis_t get_joypad_axis(uint8_t physical_axis);
diff --git a/SDL/main.c b/SDL/main.c
index 7db59be4..99facf8d 100755
--- a/SDL/main.c
+++ b/SDL/main.c
@@ -616,6 +616,9 @@ int main(int argc, char **argv)
     if (filename == NULL) {
         run_gui(false);
     }
+    else {
+        connect_joypad();
+    }
     SDL_PauseAudioDevice(device_id, 0);
     run(); // Never returns
     return 0;