Merge pull request #1530 from reicast/fh/saveport-vmu

Save maple port of connected gamepads between runs. Display VMU LCD on pause
This commit is contained in:
skmp 2019-03-30 05:48:24 +01:00 committed by GitHub
commit 66580b16c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 219 additions and 84 deletions

View File

@ -644,9 +644,7 @@ struct maple_sega_vmu: maple_base
} }
} }
config->SetImage(lcd_data_decoded); config->SetImage(lcd_data_decoded);
#if !defined(TARGET_PANDORA) && HOST_OS != OS_DARWIN push_vmu_screen(bus_id, bus_port, lcd_data_decoded);
push_vmu_screen(lcd_data_decoded);
#endif
#if 0 #if 0
// Update LCD window // Update LCD window
if (!dev->lcd.visible) if (!dev->lcd.visible)
@ -791,7 +789,7 @@ struct maple_microphone: maple_base
switch (cmd) switch (cmd)
{ {
case MDC_DeviceRequest: case MDC_DeviceRequest:
LOGI("maple_microphone::dma MDC_DeviceRequest"); LOGI("maple_microphone::dma MDC_DeviceRequest\n");
//this was copied from the controller case with just the id and name replaced! //this was copied from the controller case with just the id and name replaced!
//caps //caps
@ -826,7 +824,7 @@ struct maple_microphone: maple_base
case MDCF_GetCondition: case MDCF_GetCondition:
{ {
LOGI("maple_microphone::dma MDCF_GetCondition"); LOGI("maple_microphone::dma MDCF_GetCondition\n");
//this was copied from the controller case with just the id replaced! //this was copied from the controller case with just the id replaced!
//PlainJoystickState pjs; //PlainJoystickState pjs;
@ -863,7 +861,7 @@ struct maple_microphone: maple_base
case MDC_DeviceReset: case MDC_DeviceReset:
//uhhh do nothing? //uhhh do nothing?
LOGI("maple_microphone::dma MDC_DeviceReset"); LOGI("maple_microphone::dma MDC_DeviceReset\n");
return MDRS_DeviceReply; return MDRS_DeviceReply;
case MDCF_MICControl: case MDCF_MICControl:
@ -932,7 +930,7 @@ struct maple_microphone: maple_base
LOGI("maple_microphone::dma MDCF_MICControl set gain %#010x\n",secondword); LOGI("maple_microphone::dma MDCF_MICControl set gain %#010x\n",secondword);
return MDRS_DeviceReply; return MDRS_DeviceReply;
case MDRE_TransmitAgain: case MDRE_TransmitAgain:
LOGW("maple_microphone::dma MDCF_MICControl MDRE_TransminAgain"); LOGW("maple_microphone::dma MDCF_MICControl MDRE_TransmitAgain\n");
//apparently this doesnt matter //apparently this doesnt matter
//wptr(micdata, SIZE_OF_MIC_DATA); //wptr(micdata, SIZE_OF_MIC_DATA);
return MDRS_DeviceReply;//MDRS_DataTransfer; return MDRS_DeviceReply;//MDRS_DataTransfer;

View File

@ -101,6 +101,6 @@ maple_device* maple_Create(MapleDeviceType type);
#define SIZE_OF_MIC_DATA 480 //ALSO DEFINED IN SipEmulator.java #define SIZE_OF_MIC_DATA 480 //ALSO DEFINED IN SipEmulator.java
#ifndef TARGET_PANDORA #ifndef TARGET_PANDORA
int get_mic_data(u8* buffer); //implemented in Android.cpp int get_mic_data(u8* buffer); //implemented in Android.cpp
int push_vmu_screen(u8* buffer); //implemented in Android.cpp
#endif #endif
void push_vmu_screen(int bus_id, int bus_port, u8* buffer);
#define MAPLE_PORTS 4 #define MAPLE_PORTS 4

View File

@ -21,6 +21,9 @@
#include "gamepad_device.h" #include "gamepad_device.h"
#include "rend/gui.h" #include "rend/gui.h"
#include "oslib/oslib.h" #include "oslib/oslib.h"
#include "cfg/cfg.h"
#define MAPLE_PORT_CFG_PREFIX "maple_"
extern void dc_exit(); extern void dc_exit();
@ -253,3 +256,36 @@ void GamepadDevice::detect_axis_input(input_detected_cb axis_moved)
_detection_start_time = os_GetSeconds() + 0.2; _detection_start_time = os_GetSeconds() + 0.2;
} }
void GamepadDevice::Register(std::shared_ptr<GamepadDevice> gamepad)
{
int maple_port = cfgLoadInt("input",
(MAPLE_PORT_CFG_PREFIX + gamepad->unique_id()).c_str(), 12345);
if (maple_port != 12345)
gamepad->set_maple_port(maple_port);
_gamepads_mutex.lock();
_gamepads.push_back(gamepad);
_gamepads_mutex.unlock();
}
void GamepadDevice::Unregister(std::shared_ptr<GamepadDevice> gamepad)
{
gamepad->save_mapping();
_gamepads_mutex.lock();
for (auto it = _gamepads.begin(); it != _gamepads.end(); it++)
if (*it == gamepad) {
_gamepads.erase(it);
break;
}
_gamepads_mutex.unlock();
}
void GamepadDevice::SaveMaplePorts()
{
for (int i = 0; i < GamepadDevice::GetGamepadCount(); i++)
{
std::shared_ptr<GamepadDevice> gamepad = GamepadDevice::GetGamepad(i);
if (gamepad != NULL && !gamepad->unique_id().empty())
cfgSaveInt("input", (MAPLE_PORT_CFG_PREFIX + gamepad->unique_id()).c_str(), gamepad->maple_port());
}
}

View File

@ -31,6 +31,7 @@ public:
const std::string& name() { return _name; } const std::string& name() { return _name; }
int maple_port() { return _maple_port; } int maple_port() { return _maple_port; }
void set_maple_port(int port) { _maple_port = port; } void set_maple_port(int port) { _maple_port = port; }
const std::string& unique_id() { return _unique_id; }
virtual bool gamepad_btn_input(u32 code, bool pressed); virtual bool gamepad_btn_input(u32 code, bool pressed);
bool gamepad_axis_input(u32 code, int value); bool gamepad_axis_input(u32 code, int value);
virtual ~GamepadDevice() {} virtual ~GamepadDevice() {}
@ -50,28 +51,13 @@ public:
virtual void update_rumble() {} virtual void update_rumble() {}
bool is_rumble_enabled() { return _rumble_enabled; } bool is_rumble_enabled() { return _rumble_enabled; }
static void Register(std::shared_ptr<GamepadDevice> gamepad) static void Register(std::shared_ptr<GamepadDevice> gamepad);
{
_gamepads_mutex.lock();
_gamepads.push_back(gamepad);
_gamepads_mutex.unlock();
}
static void Unregister(std::shared_ptr<GamepadDevice> gamepad) static void Unregister(std::shared_ptr<GamepadDevice> gamepad);
{
gamepad->save_mapping();
_gamepads_mutex.lock();
for (auto it = _gamepads.begin(); it != _gamepads.end(); it++)
if (*it == gamepad)
{
_gamepads.erase(it);
break;
}
_gamepads_mutex.unlock();
}
static int GetGamepadCount(); static int GetGamepadCount();
static std::shared_ptr<GamepadDevice> GetGamepad(int index); static std::shared_ptr<GamepadDevice> GetGamepad(int index);
static void SaveMaplePorts();
protected: protected:
GamepadDevice(int maple_port, const char *api_name, bool remappable = true) GamepadDevice(int maple_port, const char *api_name, bool remappable = true)
@ -83,6 +69,7 @@ protected:
virtual void load_axis_min_max(u32 axis) {} virtual void load_axis_min_max(u32 axis) {}
std::string _name; std::string _name;
std::string _unique_id = "";
InputMapping *input_mapper; InputMapping *input_mapper;
std::map<u32, int> axis_min_values; std::map<u32, int> axis_min_values;
std::map<u32, unsigned int> axis_ranges; std::map<u32, unsigned int> axis_ranges;

View File

@ -9,12 +9,18 @@ public:
: GamepadDevice(maple_port, "evdev"), _fd(fd), _rumble_effect_id(-1), _devnode(devnode) : GamepadDevice(maple_port, "evdev"), _fd(fd), _rumble_effect_id(-1), _devnode(devnode)
{ {
fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(fd, F_SETFL, O_NONBLOCK);
char name[256] = "Unknown"; char buf[256] = "Unknown";
if (ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) if (ioctl(fd, EVIOCGNAME(sizeof(buf) - 1), buf) < 0)
perror("evdev: ioctl(EVIOCGNAME)"); perror("evdev: ioctl(EVIOCGNAME)");
else else
printf("evdev: Opened device '%s' ", name); printf("evdev: Opened device '%s' ", buf);
_name = name; _name = buf;
buf[0] = 0;
if (ioctl(fd, EVIOCGUNIQ(sizeof(buf) - 1), buf) == 0)
_unique_id = buf;
if (_unique_id.empty())
_unique_id = devnode;
if (!find_mapping(mapping_file)) if (!find_mapping(mapping_file))
{ {
#if defined(TARGET_PANDORA) #if defined(TARGET_PANDORA)
@ -22,18 +28,18 @@ public:
#elif defined(TARGET_GCW0) #elif defined(TARGET_GCW0)
mapping_file = "controller_gcwz.cfg"; mapping_file = "controller_gcwz.cfg";
#else #else
if (!strcmp(name, "Microsoft X-Box 360 pad") if (_name == "Microsoft X-Box 360 pad"
|| !strcmp(name, "Xbox 360 Wireless Receiver") || _name == "Xbox 360 Wireless Receiver"
|| !strcmp(name, "Xbox 360 Wireless Receiver (XBOX)")) || _name == "Xbox 360 Wireless Receiver (XBOX)")
{ {
mapping_file = "controller_xpad.cfg"; mapping_file = "controller_xpad.cfg";
} }
else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL) else if (_name.find("Xbox Gamepad (userspace driver)") != std::string::npos)
{ {
mapping_file = "controller_xboxdrv.cfg"; mapping_file = "controller_xboxdrv.cfg";
} }
else if (strstr(name, "keyboard") != NULL || else if (_name.find("keyboard") != std::string::npos
strstr(name, "Keyboard") != NULL) || _name.find("Keyboard") != std::string::npos)
{ {
mapping_file = "keyboard.cfg"; mapping_file = "keyboard.cfg";
} }

View File

@ -408,7 +408,6 @@ int main(int argc, wchar* argv[])
#endif #endif
int get_mic_data(u8* buffer) { return 0; } int get_mic_data(u8* buffer) { return 0; }
int push_vmu_screen(u8* buffer) { return 0; }
void os_DebugBreak() void os_DebugBreak()
{ {

View File

@ -52,6 +52,7 @@ public:
X11MouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11") X11MouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11")
{ {
_name = "Mouse"; _name = "Mouse";
_unique_id = "x11_mouse";
if (!find_mapping()) if (!find_mapping())
input_mapper = new MouseInputMapping(); input_mapper = new MouseInputMapping();
} }

View File

@ -181,6 +181,7 @@ public:
X11KbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11") X11KbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11")
{ {
_name = "Keyboard"; _name = "Keyboard";
_unique_id = "x11_keyboard";
if (!find_mapping()) if (!find_mapping())
input_mapper = new KbInputMapping(); input_mapper = new KbInputMapping();
} }

View File

@ -22,6 +22,7 @@
#include "imgread/common.h" #include "imgread/common.h"
#include "rend/gui.h" #include "rend/gui.h"
#include "profiler/profiler.h" #include "profiler/profiler.h"
#include "input/gamepad_device.h"
void FlushCache(); void FlushCache();
void LoadCustom(); void LoadCustom();
@ -741,6 +742,9 @@ void SaveSettings()
paths += path; paths += path;
} }
cfgSaveStr("config", "Dreamcast.ContentPath", paths.c_str()); cfgSaveStr("config", "Dreamcast.ContentPath", paths.c_str());
GamepadDevice::SaveMaplePorts();
#ifdef _ANDROID #ifdef _ANDROID
void SaveAndroidSettings(); void SaveAndroidSettings();
SaveAndroidSettings(); SaveAndroidSettings();

View File

@ -585,3 +585,20 @@ void ImGui_ImplOpenGL3_DrawBackground()
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
} }
ImTextureID ImGui_ImplOpenGL3_CreateVmuTexture(const unsigned int *data)
{
GLuint tex_id;
glGenTextures(1, &tex_id);
glBindTexture(GL_TEXTURE_2D, tex_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 48, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
return reinterpret_cast<ImTextureID>(tex_id);
}
void ImGui_ImplOpenGL3_DeleteVmuTexture(ImTextureID tex_id)
{
glDeleteTextures(1, &(GLuint &)tex_id);
}

View File

@ -34,6 +34,8 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_background = false); IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_background = false);
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DrawBackground(); IMGUI_IMPL_API void ImGui_ImplOpenGL3_DrawBackground();
IMGUI_IMPL_API ImTextureID ImGui_ImplOpenGL3_CreateVmuTexture(const unsigned int *);
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DeleteVmuTexture(ImTextureID);
// Called by Init/NewFrame/Shutdown // Called by Init/NewFrame/Shutdown
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();

View File

@ -64,6 +64,10 @@ GuiState gui_state = Main;
static bool settings_opening; static bool settings_opening;
static bool touch_up; static bool touch_up;
static void display_vmus();
static void reset_vmus();
static void term_vmus();
void gui_init() void gui_init()
{ {
if (inited) if (inited)
@ -290,6 +294,8 @@ static void gui_display_commands()
if (!settings_opening) if (!settings_opening)
ImGui_ImplOpenGL3_DrawBackground(); ImGui_ImplOpenGL3_DrawBackground();
display_vmus();
ImGui::SetNextWindowPos(ImVec2(screen_width / 2.f, screen_height / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowPos(ImVec2(screen_width / 2.f, screen_height / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(ImVec2(330 * scaling, 0)); ImGui::SetNextWindowSize(ImVec2(330 * scaling, 0));
@ -635,6 +641,7 @@ static void gui_display_settings()
gui_state = Main; gui_state = Main;
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST #if DC_PLATFORM == DC_PLATFORM_DREAMCAST
maple_ReconnectDevices(); maple_ReconnectDevices();
reset_vmus();
#endif #endif
SaveSettings(); SaveSettings();
} }
@ -1470,6 +1477,7 @@ void gui_open_onboarding()
void gui_term() void gui_term()
{ {
inited = false; inited = false;
term_vmus();
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
} }
@ -1495,3 +1503,94 @@ void gui_refresh_files()
game_list_done = false; game_list_done = false;
subfolders_read = false; subfolders_read = false;
} }
#define VMU_WIDTH (70 * 48 * scaling / 32)
#define VMU_HEIGHT (70 * scaling)
#define VMU_PADDING (8 * scaling)
static u32 vmu_lcd_data[8][48 * 32];
static bool vmu_lcd_status[8];
static ImTextureID vmu_lcd_tex_ids[8];
void push_vmu_screen(int bus_id, int bus_port, u8* buffer)
{
int vmu_id = bus_id * 2 + bus_port;
if (vmu_id < 0 || vmu_id >= ARRAY_SIZE(vmu_lcd_data))
return;
u32 *p = &vmu_lcd_data[vmu_id][0];
for (int i = 0; i < ARRAY_SIZE(vmu_lcd_data[vmu_id]); i++, buffer++)
*p++ = *buffer != 0 ? 0xFFFFFFFFu : 0xFF000000u;
vmu_lcd_status[vmu_id] = true;
}
static const int vmu_coords[8][2] = {
{ 0 , 0 },
{ 0 , 0 },
{ 1 , 0 },
{ 1 , 0 },
{ 0 , 1 },
{ 0 , 1 },
{ 1 , 1 },
{ 1 , 1 },
};
static void display_vmus()
{
if (!game_started)
return;
ImGui::SetNextWindowBgAlpha(0);
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(screen_width, screen_height));
ImGui::Begin("vmu-window", NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs
| ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoFocusOnAppearing);
for (int i = 0; i < 8; i++)
{
if (!vmu_lcd_status[i])
continue;
if (vmu_lcd_tex_ids[i] != (ImTextureID)0)
ImGui_ImplOpenGL3_DeleteVmuTexture(vmu_lcd_tex_ids[i]);
vmu_lcd_tex_ids[i] = ImGui_ImplOpenGL3_CreateVmuTexture(vmu_lcd_data[i]);
int x = vmu_coords[i][0];
int y = vmu_coords[i][1];
ImVec2 pos;
if (x == 0)
pos.x = VMU_PADDING;
else
pos.x = screen_width - VMU_WIDTH - VMU_PADDING;
if (y == 0)
{
pos.y = VMU_PADDING;
if (i & 1)
pos.y += VMU_HEIGHT + VMU_PADDING;
}
else
{
pos.y = screen_height - VMU_HEIGHT - VMU_PADDING;
if (i & 1)
pos.y -= VMU_HEIGHT + VMU_PADDING;
}
ImVec2 pos_b(pos.x + VMU_WIDTH, pos.y + VMU_HEIGHT);
ImGui::GetWindowDrawList()->AddImage(vmu_lcd_tex_ids[i], pos, pos_b, ImVec2(0, 1), ImVec2(1, 0), 0xC0ffffff);
}
ImGui::End();
}
static void reset_vmus()
{
for (int i = 0; i < ARRAY_SIZE(vmu_lcd_status); i++)
vmu_lcd_status[i] = false;
}
static void term_vmus()
{
for (int i = 0; i < ARRAY_SIZE(vmu_lcd_status); i++)
{
if (vmu_lcd_tex_ids[i] != (ImTextureID)0)
{
ImGui_ImplOpenGL3_DeleteVmuTexture(vmu_lcd_tex_ids[i]);
vmu_lcd_tex_ids[i] = (ImTextureID)0;
}
}
}

View File

@ -183,7 +183,7 @@ void select_directory_popup(const char *prompt, float scaling, StringCallback ca
} }
ImGui::Text("%s", error_message.empty() ? select_current_directory.c_str() : error_message.c_str()); ImGui::Text("%s", error_message.empty() ? select_current_directory.c_str() : error_message.c_str());
ImGui::BeginChild(ImGui::GetID("dir_list"), ImVec2(0, -ImGui::CalcTextSize("Cancel").y - ImGui::GetStyle().FramePadding. y * 2 - ImGui::GetStyle().ItemSpacing.y), true); ImGui::BeginChild(ImGui::GetID("dir_list"), ImVec2(0, - 30 * scaling - ImGui::GetStyle().ItemSpacing.y), true);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8 * scaling, 20 * scaling)); // from 8, 4 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8 * scaling, 20 * scaling)); // from 8, 4
@ -245,14 +245,14 @@ void select_directory_popup(const char *prompt, float scaling, StringCallback ca
} }
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::EndChild(); ImGui::EndChild();
if (ImGui::Button("Select Current Directory")) if (ImGui::Button("Select Current Directory", ImVec2(0, 30 * scaling)))
{ {
subfolders_read = false; subfolders_read = false;
callback(false, select_current_directory); callback(false, select_current_directory);
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Cancel")) if (ImGui::Button("Cancel", ImVec2(0, 30 * scaling)))
{ {
subfolders_read = false; subfolders_read = false;
callback(true, ""); callback(true, "");

View File

@ -50,6 +50,13 @@ public:
_name = SDL_JoystickName(sdl_joystick); _name = SDL_JoystickName(sdl_joystick);
sdl_joystick_instance = SDL_JoystickInstanceID(sdl_joystick); sdl_joystick_instance = SDL_JoystickInstanceID(sdl_joystick);
printf("SDL: Opened joystick on port %d: '%s' ", maple_port, _name.c_str()); printf("SDL: Opened joystick on port %d: '%s' ", maple_port, _name.c_str());
SDL_JoystickGUID guid = SDL_JoystickGetGUID(sdl_joystick);
char buf[33];
SDL_JoystickGetGUIDString(guid, buf, sizeof(buf));
_unique_id = buf;
if (_unique_id.empty())
_unique_id = _name;
if (!find_mapping()) if (!find_mapping())
{ {
if (_name == "Microsoft X-Box 360 pad") if (_name == "Microsoft X-Box 360 pad")
@ -175,6 +182,7 @@ public:
SDLKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "SDL") SDLKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "SDL")
{ {
_name = "Keyboard"; _name = "Keyboard";
_unique_id = "sdl_keyboard;
if (!find_mapping()) if (!find_mapping())
input_mapper = new KbInputMapping(); input_mapper = new KbInputMapping();
} }
@ -201,6 +209,7 @@ public:
SDLMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "SDL") SDLMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "SDL")
{ {
_name = "Mouse"; _name = "Mouse";
_unique_id = "sdl_mouse";
if (!find_mapping()) if (!find_mapping())
input_mapper = new MouseInputMapping(); input_mapper = new MouseInputMapping();
} }

View File

@ -36,6 +36,9 @@ public:
XInputGamepadDevice(int maple_port, int xinput_port) XInputGamepadDevice(int maple_port, int xinput_port)
: GamepadDevice(maple_port, "xinput"), _xinput_port(xinput_port) : GamepadDevice(maple_port, "xinput"), _xinput_port(xinput_port)
{ {
char buf[32];
sprintf(buf, "xinput-%d", xinput_port + 1);
_unique_id = buf;
} }
void ReadInput() void ReadInput()
@ -231,6 +234,7 @@ public:
WinKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "win32") WinKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "win32")
{ {
_name = "Keyboard"; _name = "Keyboard";
_unique_id = "win_keyboard";
if (!find_mapping()) if (!find_mapping())
input_mapper = new KbInputMapping(); input_mapper = new KbInputMapping();
} }
@ -257,6 +261,7 @@ public:
WinMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "win32") WinMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "win32")
{ {
_name = "Mouse"; _name = "Mouse";
_unique_id = "win_mouse";
if (!find_mapping()) if (!find_mapping())
input_mapper = new MouseInputMapping(); input_mapper = new MouseInputMapping();
} }

View File

@ -24,7 +24,7 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
{ {
maple_port = 0; maple_port = 0;
if (applicationContext.getPackageManager().hasSystemFeature("android.hardware.touchscreen")) if (applicationContext.getPackageManager().hasSystemFeature("android.hardware.touchscreen"))
joystickAdded(VIRTUAL_GAMEPAD_ID, "Virtual Gamepad", maple_port == 3 ? 3 : maple_port++); joystickAdded(VIRTUAL_GAMEPAD_ID, "Virtual Gamepad", maple_port == 3 ? 3 : maple_port++, "virtual_gamepad_uid");
int[] ids = InputDevice.getDeviceIds(); int[] ids = InputDevice.getDeviceIds();
for (int id : ids) for (int id : ids)
onInputDeviceAdded(id); onInputDeviceAdded(id);
@ -49,7 +49,7 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
if ((device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) { if ((device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) {
port = this.maple_port == 3 ? 3 : this.maple_port++; port = this.maple_port == 3 ? 3 : this.maple_port++;
} }
joystickAdded(i, device.getName(), port); joystickAdded(i, device.getName(), port, device.getDescriptor());
} }
} }
@ -96,6 +96,6 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
public native boolean joystickButtonEvent(int id, int button, boolean pressed); public native boolean joystickButtonEvent(int id, int button, boolean pressed);
public native boolean joystickAxisEvent(int id, int button, int value); public native boolean joystickAxisEvent(int id, int button, int value);
public native void mouseEvent(int xpos, int ypos, int buttons); public native void mouseEvent(int xpos, int ypos, int buttons);
private native void joystickAdded(int id, String name, int maple_port); private native void joystickAdded(int id, String name, int maple_port, String uniqueId);
private native void joystickRemoved(int id); private native void joystickRemoved(int id);
} }

View File

@ -114,7 +114,7 @@ JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_guiIsOpen(JNIEnv
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_guiIsContentBrowser(JNIEnv *env,jobject obj) __attribute__((visibility("default"))); JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_guiIsContentBrowser(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_init(JNIEnv *env, jobject obj) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_init(JNIEnv *env, jobject obj) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickAdded(JNIEnv *env, jobject obj, jint id, jstring name, jint maple_port) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickAdded(JNIEnv *env, jobject obj, jint id, jstring name, jint maple_port, jstring junique_id) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickRemoved(JNIEnv *env, jobject obj, jint id) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickRemoved(JNIEnv *env, jobject obj, jint id) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_virtualGamepadEvent(JNIEnv *env, jobject obj, jint kcode, jint joyx, jint joyy, jint lt, jint rt) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_virtualGamepadEvent(JNIEnv *env, jobject obj, jint kcode, jint joyx, jint joyy, jint lt, jint rt) __attribute__((visibility("default")));
JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickButtonEvent(JNIEnv *env, jobject obj, jint id, jint key, jboolean pressed) __attribute__((visibility("default"))); JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickButtonEvent(JNIEnv *env, jobject obj, jint id, jint key, jboolean pressed) __attribute__((visibility("default")));
@ -315,10 +315,6 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_diskSwap(JNIEnv *env,
//stuff for microphone //stuff for microphone
jobject sipemu; jobject sipemu;
jmethodID getmicdata; jmethodID getmicdata;
//stuff for vmu lcd
jobject vmulcd = NULL;
jbyteArray jpix = NULL;
jmethodID updatevmuscreen;
extern bool game_started; extern bool game_started;
//stuff for audio //stuff for audio
@ -333,12 +329,6 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupMic(JNIEnv *env,
getmicdata = env->GetMethodID(env->GetObjectClass(sipemu),"getData","()[B"); getmicdata = env->GetMethodID(env->GetObjectClass(sipemu),"getData","()[B");
} }
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupVmu(JNIEnv *env,jobject obj,jobject vmu)
{
vmulcd = env->NewGlobalRef(vmu);
updatevmuscreen = env->GetMethodID(env->GetObjectClass(vmu),"updateBytes","([B)V");
}
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_pause(JNIEnv *env,jobject obj) JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_pause(JNIEnv *env,jobject obj)
{ {
if (game_started) if (game_started)
@ -362,18 +352,6 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_destroy(JNIEnv *env,j
dc_term(); dc_term();
} }
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_vmuSwap(JNIEnv *env,jobject obj)
{
maple_device* olda = MapleDevices[0][0];
maple_device* oldb = MapleDevices[0][1];
MapleDevices[0][0] = NULL;
MapleDevices[0][1] = NULL;
usleep(50000);//50 ms, wait for host to detect disconnect
MapleDevices[0][0] = oldb;
MapleDevices[0][1] = olda;
}
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_send(JNIEnv *env,jobject obj,jint cmd, jint param) JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_send(JNIEnv *env,jobject obj,jint cmd, jint param)
{ {
if (cmd==0) if (cmd==0)
@ -584,19 +562,6 @@ int get_mic_data(u8* buffer)
return 1; return 1;
} }
int push_vmu_screen(u8* buffer)
{
if(vmulcd==NULL){
return 0;
}
if(jpix==NULL){
jpix = jvm_attacher.getEnv()->NewByteArray(1536);
}
jvm_attacher.getEnv()->SetByteArrayRegion(jpix, 0, 1536, (jbyte*)buffer);
jvm_attacher.getEnv()->CallVoidMethod(vmulcd, updatevmuscreen, jpix);
return 1;
}
void os_DebugBreak() void os_DebugBreak()
{ {
// TODO: notify the parent thread about it ... // TODO: notify the parent thread about it ...
@ -622,13 +587,14 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_init(
input_device_manager_rumble = env->GetMethodID(env->GetObjectClass(obj), "rumble", "(IFFI)Z"); input_device_manager_rumble = env->GetMethodID(env->GetObjectClass(obj), "rumble", "(IFFI)Z");
} }
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickAdded(JNIEnv *env, jobject obj, jint id, jstring name, jint maple_port) JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickAdded(JNIEnv *env, jobject obj, jint id, jstring name, jint maple_port, jstring junique_id)
{ {
const char* joyname = env->GetStringUTFChars(name,0); const char* joyname = env->GetStringUTFChars(name,0);
std::shared_ptr<AndroidGamepadDevice> gamepad = std::make_shared<AndroidGamepadDevice>(maple_port, id, joyname); const char* unique_id = env->GetStringUTFChars(junique_id, 0);
std::shared_ptr<AndroidGamepadDevice> gamepad = std::make_shared<AndroidGamepadDevice>(maple_port, id, joyname, unique_id);
AndroidGamepadDevice::AddAndroidGamepad(gamepad); AndroidGamepadDevice::AddAndroidGamepad(gamepad);
env->ReleaseStringUTFChars(name, joyname); env->ReleaseStringUTFChars(name, joyname);
env->ReleaseStringUTFChars(name, unique_id);
} }
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickRemoved(JNIEnv *env, jobject obj, jint id) JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickRemoved(JNIEnv *env, jobject obj, jint id)
{ {

View File

@ -87,10 +87,12 @@ public:
class AndroidGamepadDevice : public GamepadDevice class AndroidGamepadDevice : public GamepadDevice
{ {
public: public:
AndroidGamepadDevice(int maple_port, int id, const char *name) : GamepadDevice(maple_port, "Android", id != VIRTUAL_GAMEPAD_ID), android_id(id) AndroidGamepadDevice(int maple_port, int id, const char *name, const char *unique_id)
: GamepadDevice(maple_port, "Android", id != VIRTUAL_GAMEPAD_ID), android_id(id)
{ {
_name = name; _name = name;
printf("Android: Opened joystick %d on port %d: '%s' ", id, maple_port, _name.c_str()); _unique_id = unique_id;
printf("Android: Opened joystick %d on port %d: '%s' descriptor '%s'", id, maple_port, _name.c_str(), _unique_id.c_str());
if (id == VIRTUAL_GAMEPAD_ID) if (id == VIRTUAL_GAMEPAD_ID)
{ {
input_mapper = new IdentityInputMapping(); input_mapper = new IdentityInputMapping();
@ -213,6 +215,7 @@ public:
AndroidMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "Android") AndroidMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "Android")
{ {
_name = "Mouse"; _name = "Mouse";
_unique_id = "android_mouse";
if (!find_mapping()) if (!find_mapping())
input_mapper = new MouseInputMapping(); input_mapper = new MouseInputMapping();
} }

View File

@ -36,6 +36,7 @@ public:
OSXKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "OSX") OSXKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "OSX")
{ {
_name = "Keyboard"; _name = "Keyboard";
_unique_id = "osx_keyboard";
if (!find_mapping()) if (!find_mapping())
input_mapper = new KbInputMapping(); input_mapper = new KbInputMapping();
} }
@ -61,6 +62,7 @@ public:
OSXMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "OSX") OSXMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "OSX")
{ {
_name = "Mouse"; _name = "Mouse";
_unique_id = "osx_mouse";
if (!find_mapping()) if (!find_mapping())
input_mapper = new MouseInputMapping(); input_mapper = new MouseInputMapping();
} }