diff --git a/core/hw/maple/maple_devs.cpp b/core/hw/maple/maple_devs.cpp index 3efc18fe8..ef9d5ac35 100755 --- a/core/hw/maple/maple_devs.cpp +++ b/core/hw/maple/maple_devs.cpp @@ -644,9 +644,7 @@ struct maple_sega_vmu: maple_base } } config->SetImage(lcd_data_decoded); -#if !defined(TARGET_PANDORA) && HOST_OS != OS_DARWIN - push_vmu_screen(lcd_data_decoded); -#endif + push_vmu_screen(bus_id, bus_port, lcd_data_decoded); #if 0 // Update LCD window if (!dev->lcd.visible) @@ -791,7 +789,7 @@ struct maple_microphone: maple_base switch (cmd) { 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! //caps @@ -826,7 +824,7 @@ struct maple_microphone: maple_base 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! //PlainJoystickState pjs; @@ -863,7 +861,7 @@ struct maple_microphone: maple_base case MDC_DeviceReset: //uhhh do nothing? - LOGI("maple_microphone::dma MDC_DeviceReset"); + LOGI("maple_microphone::dma MDC_DeviceReset\n"); return MDRS_DeviceReply; case MDCF_MICControl: @@ -932,7 +930,7 @@ struct maple_microphone: maple_base LOGI("maple_microphone::dma MDCF_MICControl set gain %#010x\n",secondword); return MDRS_DeviceReply; case MDRE_TransmitAgain: - LOGW("maple_microphone::dma MDCF_MICControl MDRE_TransminAgain"); + LOGW("maple_microphone::dma MDCF_MICControl MDRE_TransmitAgain\n"); //apparently this doesnt matter //wptr(micdata, SIZE_OF_MIC_DATA); return MDRS_DeviceReply;//MDRS_DataTransfer; diff --git a/core/hw/maple/maple_devs.h b/core/hw/maple/maple_devs.h index 8ad5db972..ec45b4986 100755 --- a/core/hw/maple/maple_devs.h +++ b/core/hw/maple/maple_devs.h @@ -101,6 +101,6 @@ maple_device* maple_Create(MapleDeviceType type); #define SIZE_OF_MIC_DATA 480 //ALSO DEFINED IN SipEmulator.java #ifndef TARGET_PANDORA int get_mic_data(u8* buffer); //implemented in Android.cpp -int push_vmu_screen(u8* buffer); //implemented in Android.cpp #endif +void push_vmu_screen(int bus_id, int bus_port, u8* buffer); #define MAPLE_PORTS 4 diff --git a/core/input/gamepad_device.cpp b/core/input/gamepad_device.cpp index f8bee9bb7..843f18d62 100644 --- a/core/input/gamepad_device.cpp +++ b/core/input/gamepad_device.cpp @@ -21,6 +21,9 @@ #include "gamepad_device.h" #include "rend/gui.h" #include "oslib/oslib.h" +#include "cfg/cfg.h" + +#define MAPLE_PORT_CFG_PREFIX "maple_" 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; } +void GamepadDevice::Register(std::shared_ptr 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 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 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()); + } +} diff --git a/core/input/gamepad_device.h b/core/input/gamepad_device.h index d7cb5d4a5..92a75692d 100644 --- a/core/input/gamepad_device.h +++ b/core/input/gamepad_device.h @@ -31,6 +31,7 @@ public: const std::string& name() { return _name; } int maple_port() { return _maple_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); bool gamepad_axis_input(u32 code, int value); virtual ~GamepadDevice() {} @@ -50,28 +51,13 @@ public: virtual void update_rumble() {} bool is_rumble_enabled() { return _rumble_enabled; } - static void Register(std::shared_ptr gamepad) - { - _gamepads_mutex.lock(); - _gamepads.push_back(gamepad); - _gamepads_mutex.unlock(); - } + static void Register(std::shared_ptr gamepad); - static void Unregister(std::shared_ptr 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 void Unregister(std::shared_ptr gamepad); static int GetGamepadCount(); static std::shared_ptr GetGamepad(int index); + static void SaveMaplePorts(); protected: GamepadDevice(int maple_port, const char *api_name, bool remappable = true) @@ -83,6 +69,7 @@ protected: virtual void load_axis_min_max(u32 axis) {} std::string _name; + std::string _unique_id = ""; InputMapping *input_mapper; std::map axis_min_values; std::map axis_ranges; diff --git a/core/linux-dist/evdev_gamepad.h b/core/linux-dist/evdev_gamepad.h index f3c5c4bd4..2d06ce4fe 100644 --- a/core/linux-dist/evdev_gamepad.h +++ b/core/linux-dist/evdev_gamepad.h @@ -9,12 +9,18 @@ public: : GamepadDevice(maple_port, "evdev"), _fd(fd), _rumble_effect_id(-1), _devnode(devnode) { fcntl(fd, F_SETFL, O_NONBLOCK); - char name[256] = "Unknown"; - if (ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) + char buf[256] = "Unknown"; + if (ioctl(fd, EVIOCGNAME(sizeof(buf) - 1), buf) < 0) perror("evdev: ioctl(EVIOCGNAME)"); else - printf("evdev: Opened device '%s' ", name); - _name = name; + printf("evdev: Opened device '%s' ", buf); + _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 defined(TARGET_PANDORA) @@ -22,18 +28,18 @@ public: #elif defined(TARGET_GCW0) mapping_file = "controller_gcwz.cfg"; #else - if (!strcmp(name, "Microsoft X-Box 360 pad") - || !strcmp(name, "Xbox 360 Wireless Receiver") - || !strcmp(name, "Xbox 360 Wireless Receiver (XBOX)")) + if (_name == "Microsoft X-Box 360 pad" + || _name == "Xbox 360 Wireless Receiver" + || _name == "Xbox 360 Wireless Receiver (XBOX)") { 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"; } - else if (strstr(name, "keyboard") != NULL || - strstr(name, "Keyboard") != NULL) + else if (_name.find("keyboard") != std::string::npos + || _name.find("Keyboard") != std::string::npos) { mapping_file = "keyboard.cfg"; } diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index cee37671d..044fa9aa6 100644 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -408,7 +408,6 @@ int main(int argc, wchar* argv[]) #endif int get_mic_data(u8* buffer) { return 0; } -int push_vmu_screen(u8* buffer) { return 0; } void os_DebugBreak() { diff --git a/core/linux-dist/x11.cpp b/core/linux-dist/x11.cpp index da977e6b3..85c6fd5f1 100644 --- a/core/linux-dist/x11.cpp +++ b/core/linux-dist/x11.cpp @@ -52,6 +52,7 @@ public: X11MouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11") { _name = "Mouse"; + _unique_id = "x11_mouse"; if (!find_mapping()) input_mapper = new MouseInputMapping(); } diff --git a/core/linux-dist/x11_keyboard.h b/core/linux-dist/x11_keyboard.h index e78717e32..70e3edd69 100644 --- a/core/linux-dist/x11_keyboard.h +++ b/core/linux-dist/x11_keyboard.h @@ -181,6 +181,7 @@ public: X11KbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "X11") { _name = "Keyboard"; + _unique_id = "x11_keyboard"; if (!find_mapping()) input_mapper = new KbInputMapping(); } diff --git a/core/nullDC.cpp b/core/nullDC.cpp index 868e6f1b9..00309f0dc 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -22,6 +22,7 @@ #include "imgread/common.h" #include "rend/gui.h" #include "profiler/profiler.h" +#include "input/gamepad_device.h" void FlushCache(); void LoadCustom(); @@ -741,6 +742,9 @@ void SaveSettings() paths += path; } cfgSaveStr("config", "Dreamcast.ContentPath", paths.c_str()); + + GamepadDevice::SaveMaplePorts(); + #ifdef _ANDROID void SaveAndroidSettings(); SaveAndroidSettings(); diff --git a/core/rend/gles/imgui_impl_opengl3.cpp b/core/rend/gles/imgui_impl_opengl3.cpp index 3fe069942..fce30f9fa 100644 --- a/core/rend/gles/imgui_impl_opengl3.cpp +++ b/core/rend/gles/imgui_impl_opengl3.cpp @@ -585,3 +585,20 @@ void ImGui_ImplOpenGL3_DrawBackground() 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(tex_id); +} + +void ImGui_ImplOpenGL3_DeleteVmuTexture(ImTextureID tex_id) +{ + glDeleteTextures(1, &(GLuint &)tex_id); +} diff --git a/core/rend/gles/imgui_impl_opengl3.h b/core/rend/gles/imgui_impl_opengl3.h index f736563bb..a5146a6e2 100644 --- a/core/rend/gles/imgui_impl_opengl3.h +++ b/core/rend/gles/imgui_impl_opengl3.h @@ -34,6 +34,8 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 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_DrawBackground(); +IMGUI_IMPL_API ImTextureID ImGui_ImplOpenGL3_CreateVmuTexture(const unsigned int *); +IMGUI_IMPL_API void ImGui_ImplOpenGL3_DeleteVmuTexture(ImTextureID); // Called by Init/NewFrame/Shutdown IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index f16414182..4b53795fb 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -64,6 +64,10 @@ GuiState gui_state = Main; static bool settings_opening; static bool touch_up; +static void display_vmus(); +static void reset_vmus(); +static void term_vmus(); + void gui_init() { if (inited) @@ -290,6 +294,8 @@ static void gui_display_commands() if (!settings_opening) ImGui_ImplOpenGL3_DrawBackground(); + display_vmus(); + ImGui::SetNextWindowPos(ImVec2(screen_width / 2.f, screen_height / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowSize(ImVec2(330 * scaling, 0)); @@ -635,6 +641,7 @@ static void gui_display_settings() gui_state = Main; #if DC_PLATFORM == DC_PLATFORM_DREAMCAST maple_ReconnectDevices(); + reset_vmus(); #endif SaveSettings(); } @@ -1470,6 +1477,7 @@ void gui_open_onboarding() void gui_term() { inited = false; + term_vmus(); ImGui_ImplOpenGL3_Shutdown(); ImGui::DestroyContext(); } @@ -1495,3 +1503,94 @@ void gui_refresh_files() game_list_done = 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; + } + } +} diff --git a/core/rend/gui_util.cpp b/core/rend/gui_util.cpp index d1c6ede53..f9e9ce91b 100644 --- a/core/rend/gui_util.cpp +++ b/core/rend/gui_util.cpp @@ -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::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 @@ -245,14 +245,14 @@ void select_directory_popup(const char *prompt, float scaling, StringCallback ca } ImGui::PopStyleVar(); ImGui::EndChild(); - if (ImGui::Button("Select Current Directory")) + if (ImGui::Button("Select Current Directory", ImVec2(0, 30 * scaling))) { subfolders_read = false; callback(false, select_current_directory); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); - if (ImGui::Button("Cancel")) + if (ImGui::Button("Cancel", ImVec2(0, 30 * scaling))) { subfolders_read = false; callback(true, ""); diff --git a/core/sdl/sdl_gamepad.h b/core/sdl/sdl_gamepad.h index 4d970a700..9f74f578c 100644 --- a/core/sdl/sdl_gamepad.h +++ b/core/sdl/sdl_gamepad.h @@ -50,6 +50,13 @@ public: _name = SDL_JoystickName(sdl_joystick); sdl_joystick_instance = SDL_JoystickInstanceID(sdl_joystick); 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 (_name == "Microsoft X-Box 360 pad") @@ -175,6 +182,7 @@ public: SDLKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "SDL") { _name = "Keyboard"; + _unique_id = "sdl_keyboard; if (!find_mapping()) input_mapper = new KbInputMapping(); } @@ -201,6 +209,7 @@ public: SDLMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "SDL") { _name = "Mouse"; + _unique_id = "sdl_mouse"; if (!find_mapping()) input_mapper = new MouseInputMapping(); } diff --git a/core/windows/xinput_gamepad.h b/core/windows/xinput_gamepad.h index 5aa9f70e7..894d0aa79 100644 --- a/core/windows/xinput_gamepad.h +++ b/core/windows/xinput_gamepad.h @@ -36,6 +36,9 @@ public: XInputGamepadDevice(int maple_port, int 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() @@ -231,6 +234,7 @@ public: WinKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "win32") { _name = "Keyboard"; + _unique_id = "win_keyboard"; if (!find_mapping()) input_mapper = new KbInputMapping(); } @@ -257,6 +261,7 @@ public: WinMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "win32") { _name = "Mouse"; + _unique_id = "win_mouse"; if (!find_mapping()) input_mapper = new MouseInputMapping(); } diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/InputDeviceManager.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/InputDeviceManager.java index e8ff499d0..cfe754612 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/InputDeviceManager.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/periph/InputDeviceManager.java @@ -24,7 +24,7 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene { maple_port = 0; 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(); for (int id : ids) onInputDeviceAdded(id); @@ -49,7 +49,7 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene if ((device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) { 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 joystickAxisEvent(int id, int button, int value); 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); } diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index 3acc179e9..3ab96e5dd 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -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 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_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"))); @@ -315,10 +315,6 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_diskSwap(JNIEnv *env, //stuff for microphone jobject sipemu; jmethodID getmicdata; -//stuff for vmu lcd -jobject vmulcd = NULL; -jbyteArray jpix = NULL; -jmethodID updatevmuscreen; extern bool game_started; //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"); } -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) { if (game_started) @@ -362,18 +352,6 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_destroy(JNIEnv *env,j 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) { if (cmd==0) @@ -584,19 +562,6 @@ int get_mic_data(u8* buffer) 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() { // 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"); } -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); - std::shared_ptr gamepad = std::make_shared(maple_port, id, joyname); + const char* unique_id = env->GetStringUTFChars(junique_id, 0); + std::shared_ptr gamepad = std::make_shared(maple_port, id, joyname, unique_id); AndroidGamepadDevice::AddAndroidGamepad(gamepad); 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) { diff --git a/shell/android-studio/reicast/src/main/jni/src/android_gamepad.h b/shell/android-studio/reicast/src/main/jni/src/android_gamepad.h index 28cb874b4..c1fe2b465 100644 --- a/shell/android-studio/reicast/src/main/jni/src/android_gamepad.h +++ b/shell/android-studio/reicast/src/main/jni/src/android_gamepad.h @@ -87,10 +87,12 @@ public: class AndroidGamepadDevice : public GamepadDevice { 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; - 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) { input_mapper = new IdentityInputMapping(); @@ -213,6 +215,7 @@ public: AndroidMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "Android") { _name = "Mouse"; + _unique_id = "android_mouse"; if (!find_mapping()) input_mapper = new MouseInputMapping(); } diff --git a/shell/apple/emulator-osx/emulator-osx/osx_gamepad.h b/shell/apple/emulator-osx/emulator-osx/osx_gamepad.h index da3c92773..6b7e0d461 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx_gamepad.h +++ b/shell/apple/emulator-osx/emulator-osx/osx_gamepad.h @@ -36,6 +36,7 @@ public: OSXKbGamepadDevice(int maple_port) : GamepadDevice(maple_port, "OSX") { _name = "Keyboard"; + _unique_id = "osx_keyboard"; if (!find_mapping()) input_mapper = new KbInputMapping(); } @@ -61,6 +62,7 @@ public: OSXMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "OSX") { _name = "Mouse"; + _unique_id = "osx_mouse"; if (!find_mapping()) input_mapper = new MouseInputMapping(); }