Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 66580b1

Browse files
authored
Merge pull request #1530 from reicast/fh/saveport-vmu
Save maple port of connected gamepads between runs. Display VMU LCD on pause
2 parents 95f4c8e + 7f44bb9 commit 66580b1

File tree

19 files changed

+219
-84
lines changed

19 files changed

+219
-84
lines changed

core/hw/maple/maple_devs.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,7 @@ struct maple_sega_vmu: maple_base
644644
}
645645
}
646646
config->SetImage(lcd_data_decoded);
647-
#if !defined(TARGET_PANDORA) && HOST_OS != OS_DARWIN
648-
push_vmu_screen(lcd_data_decoded);
649-
#endif
647+
push_vmu_screen(bus_id, bus_port, lcd_data_decoded);
650648
#if 0
651649
// Update LCD window
652650
if (!dev->lcd.visible)
@@ -791,7 +789,7 @@ struct maple_microphone: maple_base
791789
switch (cmd)
792790
{
793791
case MDC_DeviceRequest:
794-
LOGI("maple_microphone::dma MDC_DeviceRequest");
792+
LOGI("maple_microphone::dma MDC_DeviceRequest\n");
795793
//this was copied from the controller case with just the id and name replaced!
796794

797795
//caps
@@ -826,7 +824,7 @@ struct maple_microphone: maple_base
826824

827825
case MDCF_GetCondition:
828826
{
829-
LOGI("maple_microphone::dma MDCF_GetCondition");
827+
LOGI("maple_microphone::dma MDCF_GetCondition\n");
830828
//this was copied from the controller case with just the id replaced!
831829

832830
//PlainJoystickState pjs;
@@ -863,7 +861,7 @@ struct maple_microphone: maple_base
863861

864862
case MDC_DeviceReset:
865863
//uhhh do nothing?
866-
LOGI("maple_microphone::dma MDC_DeviceReset");
864+
LOGI("maple_microphone::dma MDC_DeviceReset\n");
867865
return MDRS_DeviceReply;
868866

869867
case MDCF_MICControl:
@@ -932,7 +930,7 @@ struct maple_microphone: maple_base
932930
LOGI("maple_microphone::dma MDCF_MICControl set gain %#010x\n",secondword);
933931
return MDRS_DeviceReply;
934932
case MDRE_TransmitAgain:
935-
LOGW("maple_microphone::dma MDCF_MICControl MDRE_TransminAgain");
933+
LOGW("maple_microphone::dma MDCF_MICControl MDRE_TransmitAgain\n");
936934
//apparently this doesnt matter
937935
//wptr(micdata, SIZE_OF_MIC_DATA);
938936
return MDRS_DeviceReply;//MDRS_DataTransfer;

core/hw/maple/maple_devs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ maple_device* maple_Create(MapleDeviceType type);
101101
#define SIZE_OF_MIC_DATA 480 //ALSO DEFINED IN SipEmulator.java
102102
#ifndef TARGET_PANDORA
103103
int get_mic_data(u8* buffer); //implemented in Android.cpp
104-
int push_vmu_screen(u8* buffer); //implemented in Android.cpp
105104
#endif
105+
void push_vmu_screen(int bus_id, int bus_port, u8* buffer);
106106
#define MAPLE_PORTS 4

core/input/gamepad_device.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include "gamepad_device.h"
2222
#include "rend/gui.h"
2323
#include "oslib/oslib.h"
24+
#include "cfg/cfg.h"
25+
26+
#define MAPLE_PORT_CFG_PREFIX "maple_"
2427

2528
extern void dc_exit();
2629

@@ -253,3 +256,36 @@ void GamepadDevice::detect_axis_input(input_detected_cb axis_moved)
253256
_detection_start_time = os_GetSeconds() + 0.2;
254257
}
255258

259+
void GamepadDevice::Register(std::shared_ptr<GamepadDevice> gamepad)
260+
{
261+
int maple_port = cfgLoadInt("input",
262+
(MAPLE_PORT_CFG_PREFIX + gamepad->unique_id()).c_str(), 12345);
263+
if (maple_port != 12345)
264+
gamepad->set_maple_port(maple_port);
265+
266+
_gamepads_mutex.lock();
267+
_gamepads.push_back(gamepad);
268+
_gamepads_mutex.unlock();
269+
}
270+
271+
void GamepadDevice::Unregister(std::shared_ptr<GamepadDevice> gamepad)
272+
{
273+
gamepad->save_mapping();
274+
_gamepads_mutex.lock();
275+
for (auto it = _gamepads.begin(); it != _gamepads.end(); it++)
276+
if (*it == gamepad) {
277+
_gamepads.erase(it);
278+
break;
279+
}
280+
_gamepads_mutex.unlock();
281+
}
282+
283+
void GamepadDevice::SaveMaplePorts()
284+
{
285+
for (int i = 0; i < GamepadDevice::GetGamepadCount(); i++)
286+
{
287+
std::shared_ptr<GamepadDevice> gamepad = GamepadDevice::GetGamepad(i);
288+
if (gamepad != NULL && !gamepad->unique_id().empty())
289+
cfgSaveInt("input", (MAPLE_PORT_CFG_PREFIX + gamepad->unique_id()).c_str(), gamepad->maple_port());
290+
}
291+
}

core/input/gamepad_device.h

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class GamepadDevice
3131
const std::string& name() { return _name; }
3232
int maple_port() { return _maple_port; }
3333
void set_maple_port(int port) { _maple_port = port; }
34+
const std::string& unique_id() { return _unique_id; }
3435
virtual bool gamepad_btn_input(u32 code, bool pressed);
3536
bool gamepad_axis_input(u32 code, int value);
3637
virtual ~GamepadDevice() {}
@@ -50,28 +51,13 @@ class GamepadDevice
5051
virtual void update_rumble() {}
5152
bool is_rumble_enabled() { return _rumble_enabled; }
5253

53-
static void Register(std::shared_ptr<GamepadDevice> gamepad)
54-
{
55-
_gamepads_mutex.lock();
56-
_gamepads.push_back(gamepad);
57-
_gamepads_mutex.unlock();
58-
}
54+
static void Register(std::shared_ptr<GamepadDevice> gamepad);
5955

60-
static void Unregister(std::shared_ptr<GamepadDevice> gamepad)
61-
{
62-
gamepad->save_mapping();
63-
_gamepads_mutex.lock();
64-
for (auto it = _gamepads.begin(); it != _gamepads.end(); it++)
65-
if (*it == gamepad)
66-
{
67-
_gamepads.erase(it);
68-
break;
69-
}
70-
_gamepads_mutex.unlock();
71-
}
56+
static void Unregister(std::shared_ptr<GamepadDevice> gamepad);
7257

7358
static int GetGamepadCount();
7459
static std::shared_ptr<GamepadDevice> GetGamepad(int index);
60+
static void SaveMaplePorts();
7561

7662
protected:
7763
GamepadDevice(int maple_port, const char *api_name, bool remappable = true)
@@ -83,6 +69,7 @@ class GamepadDevice
8369
virtual void load_axis_min_max(u32 axis) {}
8470

8571
std::string _name;
72+
std::string _unique_id = "";
8673
InputMapping *input_mapper;
8774
std::map<u32, int> axis_min_values;
8875
std::map<u32, unsigned int> axis_ranges;

core/linux-dist/evdev_gamepad.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,37 @@ class EvdevGamepadDevice : public GamepadDevice
99
: GamepadDevice(maple_port, "evdev"), _fd(fd), _rumble_effect_id(-1), _devnode(devnode)
1010
{
1111
fcntl(fd, F_SETFL, O_NONBLOCK);
12-
char name[256] = "Unknown";
13-
if (ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0)
12+
char buf[256] = "Unknown";
13+
if (ioctl(fd, EVIOCGNAME(sizeof(buf) - 1), buf) < 0)
1414
perror("evdev: ioctl(EVIOCGNAME)");
1515
else
16-
printf("evdev: Opened device '%s' ", name);
17-
_name = name;
16+
printf("evdev: Opened device '%s' ", buf);
17+
_name = buf;
18+
buf[0] = 0;
19+
if (ioctl(fd, EVIOCGUNIQ(sizeof(buf) - 1), buf) == 0)
20+
_unique_id = buf;
21+
if (_unique_id.empty())
22+
_unique_id = devnode;
23+
1824
if (!find_mapping(mapping_file))
1925
{
2026
#if defined(TARGET_PANDORA)
2127
mapping_file = "controller_pandora.cfg";
2228
#elif defined(TARGET_GCW0)
2329
mapping_file = "controller_gcwz.cfg";
2430
#else
25-
if (!strcmp(name, "Microsoft X-Box 360 pad")
26-
|| !strcmp(name, "Xbox 360 Wireless Receiver")
27-
|| !strcmp(name, "Xbox 360 Wireless Receiver (XBOX)"))
31+
if (_name == "Microsoft X-Box 360 pad"
32+
|| _name == "Xbox 360 Wireless Receiver"
33+
|| _name == "Xbox 360 Wireless Receiver (XBOX)")
2834
{
2935
mapping_file = "controller_xpad.cfg";
3036
}
31-
else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL)
37+
else if (_name.find("Xbox Gamepad (userspace driver)") != std::string::npos)
3238
{
3339
mapping_file = "controller_xboxdrv.cfg";
3440
}
35-
else if (strstr(name, "keyboard") != NULL ||
36-
strstr(name, "Keyboard") != NULL)
41+
else if (_name.find("keyboard") != std::string::npos
42+
|| _name.find("Keyboard") != std::string::npos)
3743
{
3844
mapping_file = "keyboard.cfg";
3945
}

core/linux-dist/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ int main(int argc, wchar* argv[])
408408
#endif
409409

410410
int get_mic_data(u8* buffer) { return 0; }
411-
int push_vmu_screen(u8* buffer) { return 0; }
412411

413412
void os_DebugBreak()
414413
{

core/linux-dist/x11.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class X11MouseGamepadDevice : public GamepadDevice
5252
X11MouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11")
5353
{
5454
_name = "Mouse";
55+
_unique_id = "x11_mouse";
5556
if (!find_mapping())
5657
input_mapper = new MouseInputMapping();
5758
}

core/linux-dist/x11_keyboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class X11KbGamepadDevice : public GamepadDevice
181181
X11KbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11")
182182
{
183183
_name = "Keyboard";
184+
_unique_id = "x11_keyboard";
184185
if (!find_mapping())
185186
input_mapper = new KbInputMapping();
186187
}

core/nullDC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "imgread/common.h"
2323
#include "rend/gui.h"
2424
#include "profiler/profiler.h"
25+
#include "input/gamepad_device.h"
2526

2627
void FlushCache();
2728
void LoadCustom();
@@ -741,6 +742,9 @@ void SaveSettings()
741742
paths += path;
742743
}
743744
cfgSaveStr("config", "Dreamcast.ContentPath", paths.c_str());
745+
746+
GamepadDevice::SaveMaplePorts();
747+
744748
#ifdef _ANDROID
745749
void SaveAndroidSettings();
746750
SaveAndroidSettings();

core/rend/gles/imgui_impl_opengl3.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,20 @@ void ImGui_ImplOpenGL3_DrawBackground()
585585
glClear(GL_COLOR_BUFFER_BIT);
586586
}
587587
}
588+
589+
ImTextureID ImGui_ImplOpenGL3_CreateVmuTexture(const unsigned int *data)
590+
{
591+
GLuint tex_id;
592+
glGenTextures(1, &tex_id);
593+
glBindTexture(GL_TEXTURE_2D, tex_id);
594+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
595+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
596+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 48, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
597+
598+
return reinterpret_cast<ImTextureID>(tex_id);
599+
}
600+
601+
void ImGui_ImplOpenGL3_DeleteVmuTexture(ImTextureID tex_id)
602+
{
603+
glDeleteTextures(1, &(GLuint &)tex_id);
604+
}

0 commit comments

Comments
 (0)