From 41ac140076686eea2439675dd8c4371da1cfa449 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sun, 26 Sep 2021 21:28:31 +0200 Subject: [PATCH] ggpo: lightgun support for arcade games ui: display button names in arcade mode only --- core/hw/maple/maple_cfg.cpp | 5 +++-- core/hw/maple/maple_cfg.h | 2 ++ core/hw/maple/maple_jvs.cpp | 17 +++++++++-------- core/network/ggpo.cpp | 25 +++++++++++++++++++++---- core/rend/gui.cpp | 10 +++++++--- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/core/hw/maple/maple_cfg.cpp b/core/hw/maple/maple_cfg.cpp index a0f61665f..df48cda93 100644 --- a/core/hw/maple/maple_cfg.cpp +++ b/core/hw/maple/maple_cfg.cpp @@ -154,8 +154,9 @@ void MapleConfigMap::SetImage(u8 *img) void MapleConfigMap::GetAbsCoordinates(int& x, int& y) { - x = mo_x_abs[playerNum()]; - y = mo_y_abs[playerNum()]; + const MapleInputState& inputState = mapleInputState[playerNum()]; + x = inputState.absPointerX; + y = inputState.absPointerY; } void MapleConfigMap::GetMouseInput(u8& buttons, int& x, int& y, int& wheel) diff --git a/core/hw/maple/maple_cfg.h b/core/hw/maple/maple_cfg.h index 1a38451dd..5ab475ce1 100644 --- a/core/hw/maple/maple_cfg.h +++ b/core/hw/maple/maple_cfg.h @@ -77,6 +77,8 @@ struct MapleInputState u32 kcode = ~0; u8 halfAxes[PJTI_Count]; // LT, RT int8_t fullAxes[PJAI_Count]; // Left X, Y, Right X, Y + int absPointerX = -1; + int absPointerY = -1; }; extern MapleInputState mapleInputState[4]; diff --git a/core/hw/maple/maple_jvs.cpp b/core/hw/maple/maple_jvs.cpp index 50d3164cc..08670dc55 100644 --- a/core/hw/maple/maple_jvs.cpp +++ b/core/hw/maple/maple_jvs.cpp @@ -475,8 +475,8 @@ protected: u16 read_analog_axis(int player_num, int player_axis, bool inverted) override { if (init_in_progress) return 0; - player_num = std::min(player_num, (int)ARRAY_SIZE(mo_x_abs)); - if (mo_x_abs[player_num] < 0 || mo_x_abs[player_num] > 639 || mo_y_abs[player_num] < 0 || mo_y_abs[player_num] > 479) + const MapleInputState& inputState = mapleInputState[std::min(player_num, (int)ARRAY_SIZE(mapleInputState) - 1)]; + if (inputState.absPointerX < 0 || inputState.absPointerX > 639 || inputState.absPointerY < 0 || inputState.absPointerY > 479) return 0; else return 0x8000; @@ -1485,10 +1485,11 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou for (; axis / 2 < player_count && axis < buffer_in[cmdi + 1]; axis += 2) { int playerNum = first_player + axis / 2; + const MapleInputState& inputState = mapleInputState[std::min(playerNum, (int)ARRAY_SIZE(mapleInputState) - 1)]; u16 x; u16 y; - if (mo_x_abs[playerNum] < 0 || mo_x_abs[playerNum] > 639 - || mo_y_abs[playerNum] < 0 || mo_y_abs[playerNum] > 479 + if (inputState.absPointerX < 0 || inputState.absPointerX > 639 + || inputState.absPointerY < 0 || inputState.absPointerY > 479 || (buttons[playerNum] & NAOMI_RELOAD_KEY) != 0) { x = 0; @@ -1496,8 +1497,8 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou } else { - x = mo_x_abs[playerNum] * 0xFFFF / 639; - y = mo_y_abs[playerNum] * 0xFFFF / 479; + x = inputState.absPointerX * 0xFFFF / 639; + y = inputState.absPointerY * 0xFFFF / 479; } LOGJVS("x,y:%4x,%4x ", x, y); JVS_OUT(x >> 8); // X, MSB @@ -1615,8 +1616,8 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou // Ninja Assault: u32 xr = 0x19d - 0x37; u32 yr = 0x1fe - 0x40; - x = mo_x_abs[playerNum] * xr / 639 + 0x37; - y = mo_y_abs[playerNum] * yr / 479 + 0x40; + x = mapleInputState[playerNum].absPointerX * xr / 639 + 0x37; + y = mapleInputState[playerNum].absPointerY * yr / 479 + 0x40; } LOGJVS("lightgun %4x,%4x ", x, y); JVS_OUT(x >> 8); // X, MSB diff --git a/core/network/ggpo.cpp b/core/network/ggpo.cpp index a977db9e6..aab7b3f2f 100644 --- a/core/network/ggpo.cpp +++ b/core/network/ggpo.cpp @@ -18,6 +18,7 @@ */ #include "ggpo.h" #include "hw/maple/maple_cfg.h" +#include "hw/maple/maple_devs.h" #include "input/gamepad_device.h" namespace ggpo @@ -38,6 +39,8 @@ static void getLocalInput(MapleInputState inputState[4]) state.fullAxes[PJAI_Y1] = joyy[player]; state.fullAxes[PJAI_X2] = joyrx[player]; state.fullAxes[PJAI_Y2] = joyry[player]; + state.absPointerX = mo_x_abs[player]; + state.absPointerY = mo_y_abs[player]; } } @@ -82,6 +85,7 @@ static int msPerFrameAvg; static bool _endOfFrame; static MiniUPnP miniupnp; static int analogAxes; +static bool absPointerPos; struct MemPages { @@ -380,7 +384,10 @@ void startSession(int localPort, int localPlayerNum) else { analogAxes = 0; - if (NaomiGameInputs != nullptr) + absPointerPos = false; + if (settings.input.JammaSetup == JVS::LightGun || settings.input.JammaSetup == JVS::LightGunAsAnalog) + absPointerPos = true; + else if (NaomiGameInputs != nullptr) { for (const auto& axis : NaomiGameInputs->axes) { @@ -392,7 +399,7 @@ void startSession(int localPort, int localPlayerNum) } NOTICE_LOG(NETWORK, "GGPO: Using %d full analog axes", analogAxes); } - u32 inputSize = sizeof(kcode[0]) + analogAxes; + u32 inputSize = sizeof(kcode[0]) + analogAxes + (int)absPointerPos * 4; GGPOErrorCode result = ggpo_start_session(&ggpoSession, &cb, config::Settings::instance().getGameId().c_str(), MAX_PLAYERS, inputSize, localPort); if (result != GGPO_OK) { @@ -470,7 +477,7 @@ void getInput(MapleInputState inputState[4]) for (int player = 0; player < 4; player++) inputState[player] = {}; - u32 inputSize = sizeof(u32) + analogAxes; + u32 inputSize = sizeof(u32) + analogAxes + (int)absPointerPos * 4; std::vector inputs(inputSize * MAX_PLAYERS); // should not call any callback GGPOErrorCode error = ggpo_synchronize_input(ggpoSession, (void *)&inputs[0], inputs.size(), nullptr); @@ -490,6 +497,11 @@ void getInput(MapleInputState inputState[4]) if (analogAxes >= 2) state.fullAxes[PJAI_Y1] = inputs[player * inputSize + 5]; } + else if (absPointerPos) + { + state.absPointerX = *(s16 *)&inputs[player * inputSize + 4]; + state.absPointerY = *(s16 *)&inputs[player * inputSize + 6]; + } state.halfAxes[PJTI_R] = (state.kcode & BTN_TRIGGER_RIGHT) == 0 ? 255 : 0; state.halfAxes[PJTI_L] = (state.kcode & BTN_TRIGGER_LEFT) == 0 ? 255 : 0; } @@ -539,7 +551,7 @@ bool nextFrame() input |= BTN_TRIGGER_LEFT; else input &= ~BTN_TRIGGER_LEFT; - u32 inputSize = sizeof(input) + analogAxes; + u32 inputSize = sizeof(input) + analogAxes + (int)absPointerPos * 4; std::vector allInput(inputSize); *(u32 *)&allInput[0] = input; if (analogAxes > 0) @@ -548,6 +560,11 @@ bool nextFrame() if (analogAxes >= 2) allInput[5] = joyy[localPlayerNum]; } + else if (absPointerPos) + { + *(s16 *)&allInput[4] = mo_x_abs[localPlayerNum]; + *(s16 *)&allInput[6] = mo_y_abs[localPlayerNum]; + } GGPOErrorCode result = ggpo_add_local_input(ggpoSession, localPlayer, &allInput[0], inputSize); if (result == GGPO_OK) break; diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 66c3c77dc..88c4fad6a 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1010,9 +1010,13 @@ static void controller_mapping_popup(const std::shared_ptr& gamep sprintf(key_id, "key_id%d", systemMapping->key); ImGui::PushID(key_id); - const char *game_btn_name = GetCurrentGameButtonName(systemMapping->key); - if (game_btn_name == nullptr) - game_btn_name = GetCurrentGameAxisName(systemMapping->key); + const char *game_btn_name = nullptr; + if (arcade_button_mode) + { + game_btn_name = GetCurrentGameButtonName(systemMapping->key); + if (game_btn_name == nullptr) + game_btn_name = GetCurrentGameAxisName(systemMapping->key); + } if (game_btn_name != nullptr && game_btn_name[0] != '\0') ImGui::Text("%s - %s", systemMapping->name, game_btn_name); else