diff --git a/core/hw/maple/maple_cfg.cpp b/core/hw/maple/maple_cfg.cpp index 7a79fc05e..afd4bb8d1 100644 --- a/core/hw/maple/maple_cfg.cpp +++ b/core/hw/maple/maple_cfg.cpp @@ -4,31 +4,12 @@ #include "hw/naomi/naomi_cart.h" #include "input/gamepad_device.h" -#define HAS_VMU -/* -bus_x=0{p0=1{config};p1=2{config};config;} -Plugins: - Input Source - EventMap -- 'Raw' interface, source_name[seid]:mode - KeyMap -- translated chars ( no re-mapping possible) - Output - Image - -*/ -/* - MapleConfig: - InputUpdate(&fmt); - ImageUpdate(data); -*/ -void UpdateInputState(u32 port); -void UpdateVibration(u32 port, float power, float inclination, u32 duration_ms); - -u8 GetBtFromSgn(s8 val) +static u8 GetBtFromSgn(s8 val) { return val+128; } -u32 awave_button_mapping[16] = { +u32 awave_button_mapping[32] = { AWAVE_SERVICE_KEY, // DC_BTN_C AWAVE_BTN1_KEY, // DC_BTN_B AWAVE_BTN0_KEY, // DC_BTN_A @@ -47,7 +28,7 @@ u32 awave_button_mapping[16] = { 0, // DC_DPAD2_RIGHT }; -u32 awavelg_button_mapping[16] = { +u32 awavelg_button_mapping[32] = { AWAVE_SERVICE_KEY, // DC_BTN_C AWAVE_BTN0_KEY, // DC_BTN_B AWAVE_TRIGGER_KEY, // DC_BTN_A @@ -64,6 +45,8 @@ u32 awavelg_button_mapping[16] = { AWAVE_BTN4_KEY, // DC_DPAD2_DOWN 0, // DC_DPAD2_LEFT 0, // DC_DPAD2_RIGHT + + AWAVE_BTN0_KEY // DC_BTN_RELOAD (not needed for AW, mapped to BTN0 = pump) }; struct MapleConfigMap : IMapleConfigMap @@ -86,34 +69,78 @@ struct MapleConfigMap : IMapleConfigMap void GetInput(PlainJoystickState* pjs) { int player_num = this->player_num == -1 ? dev->bus_id : this->player_num; - UpdateInputState(player_num); - pjs->kcode=kcode[player_num]; if (settings.platform.system == DC_PLATFORM_DREAMCAST) { - pjs->joy[PJAI_X1]=GetBtFromSgn(joyx[player_num]); - pjs->joy[PJAI_Y1]=GetBtFromSgn(joyy[player_num]); - pjs->trigger[PJTI_R]=rt[player_num]; - pjs->trigger[PJTI_L]=lt[player_num]; + pjs->kcode = kcode[player_num]; + pjs->joy[PJAI_X1] = GetBtFromSgn(joyx[player_num]); + pjs->joy[PJAI_Y1] = GetBtFromSgn(joyy[player_num]); + pjs->trigger[PJTI_R] = rt[player_num]; + pjs->trigger[PJTI_L] = lt[player_num]; } else if (settings.platform.system == DC_PLATFORM_ATOMISWAVE) { const u32* mapping = settings.input.JammaSetup == JVS::LightGun ? awavelg_button_mapping : awave_button_mapping; - pjs->kcode = 0xFFFF; - for (int i = 0; i < 16; i++) + pjs->kcode = ~0; + for (u32 i = 0; i < ARRAY_SIZE(awave_button_mapping); i++) { if ((kcode[player_num] & (1 << i)) == 0) pjs->kcode &= ~mapping[i]; } - pjs->joy[PJAI_X1] = GetBtFromSgn(joyx[player_num]); - if (NaomiGameInputs != NULL && NaomiGameInputs->axes[1].name != NULL && NaomiGameInputs->axes[1].type == Half) + if (NaomiGameInputs != NULL) { - // Driving games: put axis 2 on RT (accel) and axis 3 on LT (brake) - pjs->joy[PJAI_Y1] = rt[player_num]; - pjs->joy[PJAI_X2] = lt[player_num]; + for (u32 axis = 0; axis < PJAI_Count; axis++) + { + if (NaomiGameInputs->axes[axis].name != NULL) + { + if (NaomiGameInputs->axes[axis].type == Full) + { + switch (NaomiGameInputs->axes[axis].axis) + { + case 0: + pjs->joy[axis] = GetBtFromSgn(joyx[player_num]); + break; + case 1: + pjs->joy[axis] = GetBtFromSgn(joyy[player_num]); + break; + case 2: + pjs->joy[axis] = GetBtFromSgn(joyrx[player_num]); + break; + case 3: + pjs->joy[axis] = GetBtFromSgn(joyry[player_num]); + break; + default: + pjs->joy[axis] = 0x80; + break; + } + } + else + { + switch (NaomiGameInputs->axes[axis].axis) + { + case 4: + pjs->joy[axis] = rt[player_num]; + break; + case 5: + pjs->joy[axis] = lt[player_num]; + break; + default: + pjs->joy[axis] = 0x80; + break; + } + } + if (NaomiGameInputs->axes[axis].inverted) + pjs->joy[axis] = pjs->joy[axis] == 0 ? 0xff : 0x100 - pjs->joy[axis]; + } + else + { + pjs->joy[axis] = 0x80; + } + } } else { + pjs->joy[PJAI_X1] = GetBtFromSgn(joyx[player_num]); pjs->joy[PJAI_Y1] = GetBtFromSgn(joyy[player_num]); pjs->joy[PJAI_X2] = rt[player_num]; pjs->joy[PJAI_Y2] = lt[player_num]; diff --git a/core/hw/maple/maple_cfg.h b/core/hw/maple/maple_cfg.h index ca08783ac..4bcd947f8 100644 --- a/core/hw/maple/maple_cfg.h +++ b/core/hw/maple/maple_cfg.h @@ -1,21 +1,6 @@ #pragma once #include "types.h" -enum PlainJoystickButtonId -{ - PJBI_B = 1, - PJBI_A = 2, - PJBI_START = 3, - PJBI_DPAD_UP = 4, - PJBI_DPAD_DOWN = 5, - PJBI_DPAD_LEFT = 6, - PJBI_DPAD_RIGHT = 7, - PJBI_Y = 9, - PJBI_X = 10, - - PJBI_Count=16 -}; - enum PlainJoystickAxisId { PJAI_X1 = 0, @@ -38,12 +23,11 @@ struct PlainJoystickState { PlainJoystickState() { - kcode=0xFFFF; joy[0]=joy[1]=joy[2]=joy[3]=0x80; trigger[0]=trigger[1]=0; } - u32 kcode; + u32 kcode = ~0; u8 joy[PJAI_Count]; u8 trigger[PJTI_Count]; diff --git a/core/hw/maple/maple_devs.cpp b/core/hw/maple/maple_devs.cpp index a63343cfa..7c562e6c1 100755 --- a/core/hw/maple/maple_devs.cpp +++ b/core/hw/maple/maple_devs.cpp @@ -8,6 +8,7 @@ #include "stdclass.h" #include +#include #include #include #include @@ -340,10 +341,7 @@ struct maple_atomiswave_controller: maple_sega_controller if (index < 2 || index > 5) return 0x80; index -= 2; - if (NaomiGameInputs != NULL && NaomiGameInputs->axes[index].name != NULL && NaomiGameInputs->axes[index].inverted) - return pjs.joy[index] == 0 ? 0xff : 0x100 - pjs.joy[index]; - else - return pjs.joy[index]; + return pjs.joy[index]; } }; @@ -811,23 +809,18 @@ struct maple_sega_vmu: maple_base { case MFID_3_Clock: { - u32 bp=r32(); + u32 bp = r32(); if (bp) - { INFO_LOG(MAPLE, "BEEP : %08X", bp); - } - return MDRS_DeviceReply;//just ko } - break; + return MDRS_DeviceReply; //just ko default: - { - INFO_LOG(MAPLE, "VMU: command MDCF_SetCondition -> Bad function used, returning MDRE_UnknownFunction"); - return MDRE_UnknownFunction;//bad function - } - break; + INFO_LOG(MAPLE, "VMU: command MDCF_SetCondition -> Bad function used, returning MDRE_UnknownFunction"); + return MDRE_UnknownFunction; //bad function } } + break; case MDC_DeviceReset: return MDRS_DeviceReply; @@ -1367,6 +1360,8 @@ struct maple_mouse : maple_base struct maple_lightgun : maple_base { virtual u32 transform_kcode(u32 kcode) { + if ((kcode & DC_BTN_RELOAD) == 0) + kcode &= ~DC_BTN_A; // trigger return kcode | 0xFF01; } @@ -1445,7 +1440,13 @@ struct maple_lightgun : maple_base virtual bool get_lightgun_pos() override { - read_lightgun_position(mo_x_abs, mo_y_abs); + PlainJoystickState pjs; + config->GetInput(&pjs); + + if ((pjs.kcode & DC_BTN_RELOAD) == 0) + read_lightgun_position(-1, -1); + else + read_lightgun_position(mo_x_abs, mo_y_abs); return true; } }; @@ -1453,6 +1454,7 @@ struct maple_lightgun : maple_base struct atomiswave_lightgun : maple_lightgun { virtual u32 transform_kcode(u32 kcode) override { + // No need for reload on AW return (kcode & AWAVE_TRIGGER_KEY) == 0 ? ~AWAVE_BTN0_KEY : ~0; } }; @@ -1484,7 +1486,7 @@ void load_naomi_eeprom() } } -static u32 naomi_button_mapping[] = { +static u32 naomi_button_mapping[32] = { NAOMI_SERVICE_KEY, // DC_BTN_C NAOMI_BTN1_KEY, // DC_BTN_B NAOMI_BTN0_KEY, // DC_BTN_A @@ -1501,8 +1503,83 @@ static u32 naomi_button_mapping[] = { NAOMI_BTN5_KEY, // DC_DPAD2_DOWN NAOMI_BTN6_KEY, // DC_DPAD2_LEFT NAOMI_BTN7_KEY, // DC_DPAD2_RIGHT + + 0, // DC_BTN_RELOAD NAOMI_BTN8_KEY, }; +extern u32 awave_button_mapping[32]; +extern u32 awavelg_button_mapping[32]; + +const char *GetCurrentGameButtonName(DreamcastKey key) +{ + if (NaomiGameInputs == nullptr || key == EMU_BTN_NONE) + return nullptr; + u32 pos = 0; + u32 val = (u32)key; + while ((val & 1) == 0) + { + pos++; + val >>= 1; + } + u32 arcade_key; + if (settings.platform.system == DC_PLATFORM_NAOMI) + { + if (pos >= ARRAY_SIZE(naomi_button_mapping)) + return nullptr; + arcade_key = naomi_button_mapping[pos]; + } + else + { + if (pos >= ARRAY_SIZE(awave_button_mapping)) + return nullptr; + const u32* mapping = settings.input.JammaSetup == JVS::LightGun ? awavelg_button_mapping : awave_button_mapping; + arcade_key = mapping[pos]; + } + for (int i = 0; NaomiGameInputs->buttons[i].source != 0; i++) + if (NaomiGameInputs->buttons[i].source == arcade_key) + return NaomiGameInputs->buttons[i].name; + + return nullptr; +} + +const char *GetCurrentGameAxisName(DreamcastKey axis) +{ + if (NaomiGameInputs == nullptr || axis == EMU_BTN_NONE) + return nullptr; + + for (int i = 0; NaomiGameInputs->axes[i].name != nullptr; i++) + { + DreamcastKey cur_axis; + switch (NaomiGameInputs->axes[i].axis) + { + case 0: + cur_axis = DC_AXIS_X; + break; + case 1: + cur_axis = DC_AXIS_Y; + break; + case 2: + cur_axis = DC_AXIS_X2; + break; + case 3: + cur_axis = DC_AXIS_Y2; + break; + case 4: + cur_axis = DC_AXIS_RT; + break; + case 5: + cur_axis = DC_AXIS_LT; + break; + default: + cur_axis = EMU_BTN_NONE; + break; + } + if (cur_axis == axis) + return NaomiGameInputs->axes[i].name; + } + + return nullptr; +} /* * Sega JVS I/O board @@ -1520,7 +1597,7 @@ public: this->node_id = node_id; this->parent = parent; this->first_player = first_player; - init_p2_mapping(); + init_mappings(); } virtual ~jvs_io_board() = default; @@ -1533,28 +1610,47 @@ public: protected: virtual const char *get_id() = 0; virtual u16 read_analog_axis(int player_num, int player_axis, bool inverted); - virtual u32 read_digital_in(int player_num) { - if (player_num >= (int)ARRAY_SIZE(kcode)) - return 0; - u32 buttons = 0; - if (player_num > 0 && !p2_mappings.empty()) - { - // Check for P1 buttons mapped to P2 inputs - u32 keycode = ~kcode[player_num - 1]; - for (const auto& pair : p2_mappings) - if ((keycode & pair.first) != 0) - buttons |= pair.second; - return buttons; - } - u32 keycode = ~kcode[player_num]; - for (int i = 0; i < 16; i++) + virtual void read_digital_in(u16 *v) + { + memset(v, 0, sizeof(u16) * 4); + for (u32 player = first_player; player < ARRAY_SIZE(kcode); player++) { - if ((keycode & (1 << i)) != 0) - buttons |= naomi_button_mapping[i]; + u32 keycode = ~kcode[player]; + if (keycode == 0) + continue; + if (keycode & DC_BTN_RELOAD) + keycode |= DC_BTN_A; + + // P1 mapping (only for P2) + if (player == 1) + { + for (u32 i = 0; i < p1_mapping.size(); i++) + if ((keycode & (1 << i)) != 0) + v[0] |= p1_mapping[i]; + } + // normal mapping + for (u32 i = 0; i < cur_mapping.size(); i++) + if ((keycode & (1 << i)) != 0) + v[player - first_player] |= cur_mapping[i]; + // P2 mapping (only for P1) + if (player == 0) + { + bool found = false; + for (u32 i = 0; i < p2_mapping.size(); i++) + { + if ((keycode & (1 << i)) != 0) + v[1] |= p2_mapping[i]; + if (p2_mapping[i] != 0) + found = true; + } + if (found) + // if there are P2 mappings for P1 then there's only 1 player + break; + } } - return buttons; } + virtual void write_digital_out(int count, u8 *data) { } u32 player_count = 0; @@ -1567,29 +1663,41 @@ protected: bool init_in_progress = false; private: - void init_p2_mapping() + void init_mappings() { + p1_mapping.fill(0); + p2_mapping.fill(0); + memcpy(&cur_mapping[0], naomi_button_mapping, sizeof(naomi_button_mapping)); if (NaomiGameInputs == nullptr) + // Use default mapping return; - for (int i = 0; NaomiGameInputs->buttons[i].name != nullptr; i++) + + for (int i = 0; NaomiGameInputs->buttons[i].source != 0; i++) { - const ButtonDescriptor& button = NaomiGameInputs->buttons[i]; - if (button.p2_mask == 0) - continue; - for (int i = 0; i < 16; i++) + u32 source = NaomiGameInputs->buttons[i].source; + for (u32 j = 0; j < ARRAY_SIZE(naomi_button_mapping); j++) { - if (naomi_button_mapping[i] == button.mask) + if (naomi_button_mapping[j] == source) { - p2_mappings.push_back(std::make_pair(1 << i, button.p2_mask)); + p1_mapping[j] = NaomiGameInputs->buttons[i].p1_target; + p2_mapping[j] = NaomiGameInputs->buttons[i].p2_target; + u32 target = NaomiGameInputs->buttons[i].target; + if (target == 0 && p1_mapping[j] == 0 && p2_mapping[j] == 0) + target = source; + cur_mapping[j] = target; break; } } } } + u8 node_id; maple_naomi_jamma *parent; u8 first_player; - std::vector> p2_mappings; + + std::array cur_mapping; + std::array p1_mapping; + std::array p2_mapping; }; // Most common JVS board @@ -1700,35 +1808,29 @@ public: { } protected: - virtual u32 read_digital_in(int player_num) override { - u32 rv = jvs_837_13844::read_digital_in(player_num); + virtual void read_digital_in(u16 *v) override + { + jvs_837_13844::read_digital_in(v); // The drive board RX0-7 is connected to the following player inputs - if (player_num == 0) - { - rv |= NAOMI_BTN2_KEY | NAOMI_BTN3_KEY | NAOMI_BTN4_KEY | NAOMI_BTN5_KEY; - if (drive_board & 16) - rv &= ~NAOMI_BTN5_KEY; - if (drive_board & 32) - rv &= ~NAOMI_BTN4_KEY; - if (drive_board & 64) - rv &= ~NAOMI_BTN3_KEY; - if (drive_board & 128) - rv &= ~NAOMI_BTN2_KEY; - } - else if (player_num == 1) - { - rv |= NAOMI_BTN2_KEY | NAOMI_BTN3_KEY | NAOMI_BTN4_KEY | NAOMI_BTN5_KEY; - if (drive_board & 1) - rv &= ~NAOMI_BTN5_KEY; - if (drive_board & 2) - rv &= ~NAOMI_BTN4_KEY; - if (drive_board & 4) - rv &= ~NAOMI_BTN3_KEY; - if (drive_board & 8) - rv &= ~NAOMI_BTN2_KEY; - } - return rv; + v[0] |= NAOMI_BTN2_KEY | NAOMI_BTN3_KEY | NAOMI_BTN4_KEY | NAOMI_BTN5_KEY; + if (drive_board & 16) + v[0] &= ~NAOMI_BTN5_KEY; + if (drive_board & 32) + v[0] &= ~NAOMI_BTN4_KEY; + if (drive_board & 64) + v[0] &= ~NAOMI_BTN3_KEY; + if (drive_board & 128) + v[0] &= ~NAOMI_BTN2_KEY; + v[1] |= NAOMI_BTN2_KEY | NAOMI_BTN3_KEY | NAOMI_BTN4_KEY | NAOMI_BTN5_KEY; + if (drive_board & 1) + v[1] &= ~NAOMI_BTN5_KEY; + if (drive_board & 2) + v[1] &= ~NAOMI_BTN4_KEY; + if (drive_board & 4) + v[1] &= ~NAOMI_BTN3_KEY; + if (drive_board & 8) + v[1] &= ~NAOMI_BTN2_KEY; } virtual void write_digital_out(int count, u8 *data) override { @@ -1846,31 +1948,20 @@ public: protected: virtual const char *get_id() override { return "SEGA ENTERPRISES,LTD.;I/O BD JVS;837-13551 ;Ver1.00;98/10"; } - virtual u32 read_digital_in(int player_num) override { - u32 keycode1 = jvs_io_board::read_digital_in(0); - u32 keycode2 = jvs_io_board::read_digital_in(1); - u32 keycode3 = jvs_io_board::read_digital_in(2); - u32 keycode4 = jvs_io_board::read_digital_in(3); + virtual void read_digital_in(u16 *v) override + { + jvs_io_board::read_digital_in(v); // main button - return ((keycode1 & NAOMI_BTN0_KEY) << 6) // start - | ((keycode2 & NAOMI_BTN0_KEY) << 2) // left - | ((keycode3 & NAOMI_BTN0_KEY) << 1) // right - | ((keycode4 & NAOMI_BTN0_KEY) >> 1) // btn1 - // soft kick -// | ((~keycode1 & NAOMI_BTN1_KEY) >> 1) // btn2 -// | ((~keycode2 & NAOMI_BTN1_KEY) >> 3) // btn4 -// | ((~keycode3 & NAOMI_BTN1_KEY) >> 5) // btn6 -// | ((~keycode4 & NAOMI_BTN1_KEY) >> 7) // test? -// // hard kick -// | ((~keycode1 & NAOMI_BTN2_KEY) >> 1) // btn3 -// | ((~keycode2 & NAOMI_BTN2_KEY) >> 3) // btn5 -// | ((~keycode3 & NAOMI_BTN2_KEY) >> 5) // btn7 -// | ((~keycode4 & NAOMI_BTN2_KEY) >> 7) // coin? + v[0] = ((v[0] & NAOMI_BTN0_KEY) << 6) // start + | ((v[1] & NAOMI_BTN0_KEY) << 2) // left + | ((v[2] & NAOMI_BTN0_KEY) << 1) // right + | ((v[3] & NAOMI_BTN0_KEY) >> 1) // btn1 // enter - | ((keycode1 & NAOMI_BTN3_KEY) << 3) // btn0 + | ((v[0] & NAOMI_BTN3_KEY) << 3) // btn0 // service menu - | (keycode1 & (NAOMI_TEST_KEY | NAOMI_SERVICE_KEY | NAOMI_UP_KEY | NAOMI_DOWN_KEY)); + | (v[0] & (NAOMI_TEST_KEY | NAOMI_SERVICE_KEY | NAOMI_UP_KEY | NAOMI_DOWN_KEY)); } + u16 read_joystick_x(int joy_num) { s8 axis_x = joyx[joy_num]; @@ -1936,15 +2027,19 @@ public: protected: virtual const char *get_id() override { return "SEGA ENTERPRISES,LTD.;I/O BD JVS;837-13551 ;Ver1.00;98/10"; } - virtual u32 read_digital_in(int player_num) override { - u32 keycode = jvs_io_board::read_digital_in(player_num); - u8 trigger = rt[player_num] >> 2; - // Ball button - return ((trigger & 0x20) << 3) | ((trigger & 0x10) << 5) | ((trigger & 0x08) << 7) - | ((trigger & 0x04) << 9) | ((trigger & 0x02) << 11) | ((trigger & 0x01) << 13) - // other buttons - | (keycode & (NAOMI_SERVICE_KEY | NAOMI_TEST_KEY | NAOMI_START_KEY)) - | ((keycode & NAOMI_BTN0_KEY) >> 4); // remap button4 to button0 (change button) + virtual void read_digital_in(u16 *v) override + { + jvs_io_board::read_digital_in(v); + for (u32 player = 0; player < player_count; player++) + { + u8 trigger = rt[player] >> 2; + // Ball button + v[player] = ((trigger & 0x20) << 3) | ((trigger & 0x10) << 5) | ((trigger & 0x08) << 7) + | ((trigger & 0x04) << 9) | ((trigger & 0x02) << 11) | ((trigger & 0x01) << 13) + // other buttons + | (v[player] & (NAOMI_SERVICE_KEY | NAOMI_TEST_KEY | NAOMI_START_KEY)) + | ((v[player] & NAOMI_BTN0_KEY) >> 4); // remap button4 to button0 (change button) + } } u16 read_joystick_x(int joy_num) @@ -2774,8 +2869,6 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou if (jvs_cmd >= 0x20 && jvs_cmd <= 0x38) // Read inputs and more { LOGJVS("JVS Node %d: ", node_id); - PlainJoystickState pjs; - parent->config->GetInput(&pjs); JVS_STATUS1(); // status for (u32 cmdi = 0; cmdi < length_in; ) @@ -2786,18 +2879,18 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou { JVS_STATUS1(); // report byte + u16 btns[4]; + read_digital_in(btns); + JVS_OUT((btns[0] & NAOMI_TEST_KEY) ? 0x80 : 0x00); // test, tilt1, tilt2, tilt3, unused, unused, unused, unused LOGJVS("btns "); for (int player = 0; player < buffer_in[cmdi + 1]; player++) { - u16 cur_btns = read_digital_in(first_player + player); - if (player == 0) - JVS_OUT((cur_btns & NAOMI_TEST_KEY) ? 0x80 : 0x00); // test, tilt1, tilt2, tilt3, unused, unused, unused, unused - LOGJVS("P%d %02x ", player + 1 + first_player, cur_btns >> 8); - JVS_OUT(cur_btns >> 8); + LOGJVS("P%d %02x ", player + 1 + first_player, btns[player] >> 8); + JVS_OUT(btns[player] >> 8); if (buffer_in[cmdi + 2] == 2) { - LOGJVS("%02x ", cur_btns & 0xFF); - JVS_OUT(cur_btns); + LOGJVS("%02x ", btns[player] & 0xFF); + JVS_OUT(btns[player]); } } cmdi += 3; @@ -2809,7 +2902,7 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou JVS_STATUS1(); // report byte LOGJVS("coins "); u32 mask = 0; - for (int i = 0; i < 16; i++) + for (u32 i = 0; i < ARRAY_SIZE(naomi_button_mapping); i++) { if (naomi_button_mapping[i] == NAOMI_COIN_KEY) { @@ -2819,7 +2912,7 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou } for (int slot = 0; slot < buffer_in[cmdi + 1]; slot++) { - u16 keycode = ~kcode[first_player + slot]; + u32 keycode = ~kcode[first_player + slot]; bool coin_chute = false; if (keycode & mask) { @@ -2847,13 +2940,19 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou LOGJVS("ana "); if (lightgun_as_analog) { - u16 x = mo_x_abs * 0xFFFF / 639; - u16 y = mo_y_abs * 0xFFFF / 479; - if (mo_x_abs < 0 || mo_x_abs > 639 || mo_y_abs < 0 || mo_y_abs > 479) + u16 x; + u16 y; + if (mo_x_abs < 0 || mo_x_abs > 639 || mo_y_abs < 0 || mo_y_abs > 479 + || (kcode[first_player] & DC_BTN_RELOAD) == 0) { x = 0; y = 0; } + else + { + x = mo_x_abs * 0xFFFF / 639; + y = mo_y_abs * 0xFFFF / 479; + } LOGJVS("x,y:%4x,%4x ", x, y); JVS_OUT(x >> 8); // X, MSB JVS_OUT(x); // X, LSB @@ -2863,7 +2962,6 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou } int full_axis_count = 0; - int half_axis_count = 0; for (; axis < buffer_in[cmdi + 1]; axis++) { u16 axis_value; @@ -2874,15 +2972,14 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou const AxisDescriptor& axisDesc = NaomiGameInputs->axes[axis]; if (axisDesc.type == Half) { - if (half_axis_count == 0) + if (axisDesc.axis == 4) axis_value = rt[first_player] << 8; - else if (half_axis_count == 1) + else if (axisDesc.axis == 5) axis_value = lt[first_player] << 8; else axis_value = 0; if (axisDesc.inverted) axis_value = 0xff00u - axis_value; - half_axis_count++; } else { @@ -2950,6 +3047,8 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou u32 yr = 0x1fe - 0x40; s16 x = mo_x_abs * xr / 639 + 0x37; s16 y = mo_y_abs * yr / 479 + 0x40; + if ((kcode[first_player] & DC_BTN_RELOAD) == 0) + x = y = 0; LOGJVS("lightgun %4x,%4x ", x, y); JVS_OUT(x >> 8); // X, MSB JVS_OUT(x); // X, LSB diff --git a/core/hw/maple/maple_devs.h b/core/hw/maple/maple_devs.h index 0fd242db4..a74b04501 100755 --- a/core/hw/maple/maple_devs.h +++ b/core/hw/maple/maple_devs.h @@ -1,6 +1,7 @@ #pragma once #include "types.h" #include +#include "input/gamepad.h" enum MapleDeviceType { @@ -145,3 +146,6 @@ extern f32 mo_y_delta; extern f32 mo_wheel_delta; #define SWAP32(a) ((((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) + +const char *GetCurrentGameButtonName(DreamcastKey key); +const char *GetCurrentGameAxisName(DreamcastKey axis); diff --git a/core/hw/maple/maple_if.cpp b/core/hw/maple/maple_if.cpp index 638944f5a..01a493adb 100644 --- a/core/hw/maple/maple_if.cpp +++ b/core/hw/maple/maple_if.cpp @@ -19,6 +19,7 @@ maple_device* MapleDevices[4][6]; int maple_schid; +void UpdateInputState(); /* Maple host controller Direct processing, async interrupt handling @@ -145,6 +146,9 @@ static void maple_DoDma() return; } #endif + + UpdateInputState(); + const bool swap_msb = (SB_MMSEL == 0); u32 xfer_count=0; bool last = false; diff --git a/core/hw/naomi/naomi_cart.h b/core/hw/naomi/naomi_cart.h index 686982390..48ce3c0a7 100644 --- a/core/hw/naomi/naomi_cart.h +++ b/core/hw/naomi/naomi_cart.h @@ -103,9 +103,11 @@ extern Cartridge *CurrentCartridge; struct ButtonDescriptor { - u32 mask; + u32 source; const char *name; - u32 p2_mask; + u32 target; + u32 p2_target; // map P1 input to JVS P2 + u32 p1_target; // map P2 input to JVS P1 }; enum AxisType { diff --git a/core/hw/naomi/naomi_roms_input.h b/core/hw/naomi/naomi_roms_input.h index d1df3642d..fd15d5fac 100644 --- a/core/hw/naomi/naomi_roms_input.h +++ b/core/hw/naomi/naomi_roms_input.h @@ -37,9 +37,10 @@ static InputDescriptors _18wheelr_inputs = { { { NAOMI_BTN0_KEY, "HORN" }, { NAOMI_DOWN_KEY, "VIEW" }, - { NAOMI_BTN1_KEY, "SHIFT L", NAOMI_DOWN_KEY }, // This button uses P2 inputs for P1 - { NAOMI_BTN2_KEY, "SHIFT H", NAOMI_UP_KEY }, // This button uses P2 inputs for P1 - { NAOMI_BTN3_KEY, "SHIFT R", NAOMI_LEFT_KEY }, // This button uses P2 inputs for P1 + { NAOMI_BTN1_KEY, "SHIFT L", 0, NAOMI_DOWN_KEY }, // This button uses P2 inputs for P1 + { NAOMI_BTN2_KEY, "SHIFT H", 0, NAOMI_UP_KEY }, // This button uses P2 inputs for P1 + { NAOMI_BTN3_KEY, "SHIFT R", 0, NAOMI_LEFT_KEY | NAOMI_DOWN_KEY }, + // This button uses P2 inputs for P1 NAO_START_DESC NAO_BASE_BTN_DESC { 0 }, @@ -55,9 +56,9 @@ static InputDescriptors _18wheelr_inputs = { static InputDescriptors alienfnt_inputs = { { { NAOMI_BTN0_KEY, "LEFT SHOT" }, - { NAOMI_BTN1_KEY, "ROTATION R" }, - { NAOMI_BTN2_KEY, "RIGHT SHOT" }, - { NAOMI_BTN3_KEY, "ROTATION L" }, + { NAOMI_BTN3_KEY, "ROTATION R", NAOMI_BTN1_KEY }, + { NAOMI_BTN1_KEY, "RIGHT SHOT", NAOMI_BTN2_KEY }, + { NAOMI_BTN2_KEY, "ROTATION L", NAOMI_BTN3_KEY }, NAO_START_DESC NAO_BASE_BTN_DESC { 0 }, @@ -80,12 +81,12 @@ static InputDescriptors alpilot_inputs = { { 0 }, }, { - { "ELEVATOR", Full, 0 }, - { "AILERON", Full, 1 }, - { "", Full, 2 }, - { "RUDDER PEDAL", Full, 3 }, - { "THRUST LEVER L", Half, 4 }, - { "THRUST LEVER R", Half, 5 }, + { "ELEVATOR", Full, 1 }, + { "AILERON", Full, 0 }, + { "", Full, 3 }, + { "RUDDER PEDAL", Full, 2 }, + { "THRUST LEVER L", Half, 5 }, + { "THRUST LEVER R", Half, 4 }, { NULL }, }, }; @@ -156,20 +157,6 @@ static InputDescriptors trigger_inputs = { }, }; -static InputDescriptors deathcox_inputs = { - { - { NAOMI_BTN0_KEY, "TRIGGER" }, - NAO_START_DESC - NAO_BASE_BTN_DESC - { 0 }, - }, - { - { "GUN-X", Full, 0 }, - { "GUN-Y", Full, 1 }, - { NULL }, - }, -}; - static InputDescriptors gunsur2_inputs = { { { NAOMI_BTN0_KEY, "GUN BUTTON" }, @@ -190,8 +177,8 @@ static InputDescriptors gunsur2_inputs = { static InputDescriptors jambo_inputs = { { - { NAOMI_UP_KEY, "LEVER UP", NAOMI_DOWN_KEY }, // This button uses P2 inputs for P1 - { NAOMI_DOWN_KEY, "LEVER DOWN", NAOMI_UP_KEY }, // This button uses P2 inputs for P1 + { NAOMI_BTN1_KEY, "LEVER UP", 0, NAOMI_DOWN_KEY }, // This button uses P2 inputs for P1 + { NAOMI_BTN0_KEY, "LEVER DOWN", 0, NAOMI_UP_KEY }, // This button uses P2 inputs for P1 NAO_START_DESC NAO_BASE_BTN_DESC { 0 }, @@ -248,11 +235,9 @@ static InputDescriptors sfz3ugd_inputs = { static InputDescriptors ninjaslt_inputs = { { - { NAOMI_BTN0_KEY, "ENTER" }, - { NAOMI_BTN2_KEY, "START 1P" }, - { NAOMI_BTN3_KEY, "START 2P" }, - { NAOMI_BTN4_KEY, "TRIGGER 1P" }, - { NAOMI_BTN5_KEY, "TRIGGER 2P" }, + { NAOMI_BTN2_KEY, "ENTER", NAOMI_BTN0_KEY }, + { NAOMI_START_KEY, "START", NAOMI_BTN2_KEY, 0, NAOMI_BTN3_KEY }, + { NAOMI_BTN0_KEY, "TRIGGER", NAOMI_BTN4_KEY, 0, NAOMI_BTN5_KEY }, { NAOMI_UP_KEY, "SELECT UP" }, { NAOMI_DOWN_KEY, "SELECT DOWN" }, NAO_BASE_BTN_DESC @@ -271,14 +256,14 @@ static InputDescriptors vonot_inputs = { { NAOMI_RIGHT_KEY, "L RIGHT" }, { NAOMI_BTN0_KEY, "L TRIGGER" }, { NAOMI_BTN1_KEY, "L TURBO" }, - { NAOMI_BTN2_KEY, "QM" }, + { NAOMI_BTN8_KEY, "QM" }, // These buttons use P2 inputs for P1 - { NAOMI_BTN3_KEY, "R TRIGGER", NAOMI_BTN0_KEY }, - { NAOMI_BTN4_KEY, "R TURBO", NAOMI_BTN1_KEY }, - { NAOMI_BTN5_KEY, "R UP", NAOMI_UP_KEY }, - { NAOMI_BTN6_KEY, "R DOWN", NAOMI_DOWN_KEY }, - { NAOMI_BTN7_KEY, "R LEFT", NAOMI_LEFT_KEY }, - { NAOMI_BTN8_KEY, "R RIGHT", NAOMI_RIGHT_KEY }, + { NAOMI_BTN2_KEY, "R TRIGGER", 0, NAOMI_BTN0_KEY }, + { NAOMI_BTN3_KEY, "R TURBO", 0, NAOMI_BTN1_KEY }, + { NAOMI_BTN4_KEY, "R UP", 0, NAOMI_UP_KEY }, + { NAOMI_BTN5_KEY, "R DOWN", 0, NAOMI_DOWN_KEY }, + { NAOMI_BTN6_KEY, "R LEFT", 0, NAOMI_LEFT_KEY }, + { NAOMI_BTN7_KEY, "R RIGHT", 0, NAOMI_RIGHT_KEY }, NAO_START_DESC NAO_BASE_BTN_DESC @@ -347,18 +332,18 @@ static InputDescriptors tokyobus_inputs = { { NAOMI_LEFT_KEY, "ANNOUNCE" }, { NAOMI_RIGHT_KEY, "DOOR CLOSE" }, // These buttons uses P2 inputs for P1 - { NAOMI_BTN1_KEY, "WINKER RIGHT", NAOMI_BTN0_KEY }, - { NAOMI_BTN2_KEY, "WINKER LEFT", NAOMI_BTN1_KEY }, - { NAOMI_BTN3_KEY, "SHIFT FRONT", NAOMI_UP_KEY }, - { NAOMI_BTN4_KEY, "SHIFT REVERSE", NAOMI_DOWN_KEY }, + { NAOMI_BTN1_KEY, "WINKER RIGHT", 0, NAOMI_BTN0_KEY }, + { NAOMI_BTN2_KEY, "WINKER LEFT", 0, NAOMI_BTN1_KEY }, + { NAOMI_BTN3_KEY, "SHIFT FRONT", 0, NAOMI_UP_KEY }, + { NAOMI_BTN4_KEY, "SHIFT REVERSE", 0, NAOMI_DOWN_KEY }, NAO_START_DESC NAO_BASE_BTN_DESC { 0 }, }, { { "HANDLE", Full, 0 }, - { "ACCEL", Half, 1 }, - { "BRAKE", Half, 2 }, + { "ACCEL", Half, 4 }, + { "BRAKE", Half, 5 }, { NULL }, }, }; @@ -372,13 +357,14 @@ static InputDescriptors wrungp_inputs = { }, { { "HANDLE BAR", Full, 0 }, - { "THROTTLE LEVER", Half, 1, true }, + { "THROTTLE LEVER", Half, 4, true }, { "ROLL", Full, 2 }, { "PITCH", Full, 3 }, { NULL }, }, }; +// Standard cabinet. The Deluxe version has different (and more) inputs. static InputDescriptors marine_fishing_inputs = { { { NAOMI_START_KEY, "CAST" }, @@ -391,7 +377,7 @@ static InputDescriptors marine_fishing_inputs = { { "ROD X", Full, 0 }, { "STICK X", Full, 2 }, { "STICK Y", Full, 3 }, - { "REEL SPEED", Half, 0 }, + { "REEL SPEED", Half, 4 }, { NULL }, }, }; @@ -401,9 +387,9 @@ static InputDescriptors f355_inputs = { { NAOMI_BTN0_KEY, "ASSIST SC" }, { NAOMI_BTN1_KEY, "ASSIST TC" }, { NAOMI_BTN2_KEY, "ASSIST ABS" }, - { NAOMI_BTN3_KEY, "ASSIST IBS", NAOMI_BTN1_KEY }, - { NAOMI_BTN4_KEY, "WING SHIFT L", NAOMI_DOWN_KEY }, - { NAOMI_BTN5_KEY, "WING SHIFT R", NAOMI_UP_KEY }, + { NAOMI_BTN3_KEY, "ASSIST IBS", 0, NAOMI_BTN1_KEY }, + { NAOMI_BTN4_KEY, "WING SHIFT L", 0, NAOMI_DOWN_KEY }, + { NAOMI_BTN5_KEY, "WING SHIFT R", 0, NAOMI_UP_KEY }, // Manual gearshift (Deluxe only) // L R @@ -420,8 +406,8 @@ static InputDescriptors f355_inputs = { { 0 }, }, { - { "ACCEL", Half, 0 }, - { "BRAKE", Half, 1 }, + { "ACCEL", Half, 4 }, + { "BRAKE", Half, 5 }, { "CLUTCH", Full, 2 }, // Deluxe only { "unused", Full, 4 }, { "HANDLE", Full, 0 }, @@ -465,8 +451,8 @@ static InputDescriptors ftspeed_inputs = { }, { { "STEERING WHEEL", Full, 0 }, - { "GAS PEDAL", Half, 1 }, - { "BRAKE PEDAL", Half, 2 }, + { "GAS PEDAL", Half, 4 }, + { "BRAKE PEDAL", Half, 5 }, { NULL }, }, }; @@ -515,8 +501,8 @@ static InputDescriptors maxspeed_inputs = { }, { { "STEERING", Full, 0 }, - { "ACCELERATOR", Half, 1 }, - { "BRAKE", Half, 2 }, + { "ACCELERATOR", Half, 4 }, + { "BRAKE", Half, 5 }, { NULL }, }, }; @@ -563,6 +549,9 @@ static InputDescriptors blockpong_inputs = { }, { { "ANALOG X", Full, 0, true }, + { "ANALOG Y", Full, 1 }, + { "ANALOG X", Full, 0 }, // for P2 + { "ANALOG Y", Full, 1 }, // for P2 { NULL }, }, }; diff --git a/core/input/gamepad.h b/core/input/gamepad.h index 6a096461b..5bbb958eb 100644 --- a/core/input/gamepad.h +++ b/core/input/gamepad.h @@ -35,10 +35,10 @@ enum DreamcastKey DC_DPAD2_DOWN = 1 << 13, DC_DPAD2_LEFT = 1 << 14, DC_DPAD2_RIGHT = 1 << 15, + DC_BTN_RELOAD = 1 << 16, // Not a real button but handled like one // System buttons EMU_BTN_NONE = 0, - EMU_BTN_ESCAPE = 1 << 16, EMU_BTN_TRIGGER_LEFT = 1 << 17, EMU_BTN_TRIGGER_RIGHT = 1 << 18, EMU_BTN_MENU = 1 << 19, @@ -47,6 +47,7 @@ enum DreamcastKey EMU_BTN_ANA_DOWN = 1 << 22, EMU_BTN_ANA_LEFT = 1 << 23, EMU_BTN_ANA_RIGHT = 1 << 24, + EMU_BTN_ESCAPE = 1 << 25, // Real axes DC_AXIS_LT = 0x10000, diff --git a/core/input/gamepad_device.cpp b/core/input/gamepad_device.cpp index 1f87c5159..5c6f61dec 100644 --- a/core/input/gamepad_device.cpp +++ b/core/input/gamepad_device.cpp @@ -29,7 +29,7 @@ #define MAPLE_PORT_CFG_PREFIX "maple_" // Gamepads -u16 kcode[4] = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF }; +u32 kcode[4] = { ~0u, ~0u, ~0u, ~0u }; s8 joyx[4]; s8 joyy[4]; s8 joyrx[4]; @@ -63,44 +63,44 @@ bool GamepadDevice::gamepad_btn_input(u32 code, bool pressed) if (key == EMU_BTN_NONE) return false; - if (key < 0x10000) + if (key <= DC_BTN_RELOAD) { if (pressed) { - kcode[port] &= ~(u16)key; + kcode[port] &= ~key; // Avoid two opposite dpad keys being pressed simultaneously switch (key) { case DC_DPAD_UP: - kcode[port] |= (u16)DC_DPAD_DOWN; + kcode[port] |= DC_DPAD_DOWN; break; case DC_DPAD_DOWN: - kcode[port] |= (u16)DC_DPAD_UP; + kcode[port] |= DC_DPAD_UP; break; case DC_DPAD_LEFT: - kcode[port] |= (u16)DC_DPAD_RIGHT; + kcode[port] |= DC_DPAD_RIGHT; break; case DC_DPAD_RIGHT: - kcode[port] |= (u16)DC_DPAD_LEFT; + kcode[port] |= DC_DPAD_LEFT; break; case DC_DPAD2_UP: - kcode[port] |= (u16)DC_DPAD2_DOWN; + kcode[port] |= DC_DPAD2_DOWN; break; case DC_DPAD2_DOWN: - kcode[port] |= (u16)DC_DPAD2_UP; + kcode[port] |= DC_DPAD2_UP; break; case DC_DPAD2_LEFT: - kcode[port] |= (u16)DC_DPAD2_RIGHT; + kcode[port] |= DC_DPAD2_RIGHT; break; case DC_DPAD2_RIGHT: - kcode[port] |= (u16)DC_DPAD2_LEFT; + kcode[port] |= DC_DPAD2_LEFT; break; default: break; } } else - kcode[port] |= (u16)key; + kcode[port] |= key; #ifdef TEST_AUTOMATION if (record_input != NULL) fprintf(record_input, "%ld button %x %04x\n", sh4_sched_now64(), port, kcode[port]); diff --git a/core/input/gamepad_device.h b/core/input/gamepad_device.h index b96d958f9..58f25b04f 100644 --- a/core/input/gamepad_device.h +++ b/core/input/gamepad_device.h @@ -101,7 +101,9 @@ private: void replay_input(); #endif -extern u16 kcode[4]; +extern u32 kcode[4]; extern u8 rt[4], lt[4]; extern s8 joyx[4], joyy[4]; extern s8 joyrx[4], joyry[4]; + +void UpdateVibration(u32 port, float power, float inclination, u32 duration_ms); diff --git a/core/input/mapping.cpp b/core/input/mapping.cpp index 39efd3491..9d24442a3 100644 --- a/core/input/mapping.cpp +++ b/core/input/mapping.cpp @@ -54,6 +54,7 @@ button_list[] = { EMU_BTN_ANA_DOWN, "compat", "btn_analog_down" }, { EMU_BTN_ANA_LEFT, "compat", "btn_analog_left" }, { EMU_BTN_ANA_RIGHT, "compat", "btn_analog_right" }, + { DC_BTN_RELOAD, "dreamcast", "reload" }, }; static struct diff --git a/core/linux-dist/evdev.cpp b/core/linux-dist/evdev.cpp index 7341e4778..7446a43d5 100644 --- a/core/linux-dist/evdev.cpp +++ b/core/linux-dist/evdev.cpp @@ -202,8 +202,7 @@ void input_evdev_close() EvdevGamepadDevice::CloseDevices(); } -// FIXME this shouldn't be done by port. Need something like: handle_events() then get_port(0), get_port(2), ... -bool input_evdev_handle(u32 port) +bool input_evdev_handle() { #ifdef USE_UDEV get_udev_events(); diff --git a/core/linux-dist/evdev.h b/core/linux-dist/evdev.h index 2fa28b9f9..79fdac705 100644 --- a/core/linux-dist/evdev.h +++ b/core/linux-dist/evdev.h @@ -3,4 +3,4 @@ extern void input_evdev_init(); extern void input_evdev_close(); -extern bool input_evdev_handle(u32 port); +extern bool input_evdev_handle(); diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index c95497b28..2074114d3 100644 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -73,18 +73,18 @@ void os_SetupInput() #endif } -void UpdateInputState(u32 port) +void UpdateInputState() { #if defined(USE_JOYSTICK) - input_joystick_handle(joystick_fd, port); + input_joystick_handle(joystick_fd, 0); #endif #if defined(USE_EVDEV) - input_evdev_handle(port); + input_evdev_handle(); #endif #if defined(USE_SDL) - input_sdl_handle(port); + input_sdl_handle(); #endif } diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 5d74c68a0..c41bc8d77 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -39,7 +39,7 @@ #include "log/LogManager.h" #include "emulator.h" -extern void UpdateInputState(u32 port); +extern void UpdateInputState(); extern bool game_started; extern int screen_width, screen_height; @@ -158,7 +158,7 @@ void ImGui_Impl_NewFrame() ImGuiIO& io = ImGui::GetIO(); - UpdateInputState(0); + UpdateInputState(); // Read keyboard modifiers inputs io.KeyCtrl = (kb_shift & (0x01 | 0x10)) != 0; @@ -446,18 +446,22 @@ const DreamcastKey button_keys[] = { DC_BTN_START, DC_BTN_A, DC_BTN_B, DC_BTN_X, DC_BTN_Y, DC_DPAD_UP, DC_DPAD_DOWN, DC_DPAD_LEFT, DC_DPAD_RIGHT, EMU_BTN_MENU, EMU_BTN_ESCAPE, EMU_BTN_FFORWARD, EMU_BTN_TRIGGER_LEFT, EMU_BTN_TRIGGER_RIGHT, DC_BTN_C, DC_BTN_D, DC_BTN_Z, DC_DPAD2_UP, DC_DPAD2_DOWN, DC_DPAD2_LEFT, DC_DPAD2_RIGHT, + DC_BTN_RELOAD, EMU_BTN_ANA_UP, EMU_BTN_ANA_DOWN, EMU_BTN_ANA_LEFT, EMU_BTN_ANA_RIGHT }; const char *button_names[] = { "Start", "A", "B", "X", "Y", "DPad Up", "DPad Down", "DPad Left", "DPad Right", "Menu", "Exit", "Fast-forward", "Left Trigger", "Right Trigger", "C", "D", "Z", "Right Dpad Up", "Right DPad Down", "Right DPad Left", "Right DPad Right", + "Reload", "Left Stick Up", "Left Stick Down", "Left Stick Left", "Left Stick Right" }; const char *arcade_button_names[] = { "Start", "Button 1", "Button 2", "Button 3", "Button 4", "Up", "Down", "Left", "Right", "Menu", "Exit", "Fast-forward", "N/A", "N/A", - "Service", "Coin", "Test", "Button 5", "Button 6", "Button 7", "Button 8", "N/A", "N/A", "N/A", "N/A" + "Service", "Coin", "Test", "Button 5", "Button 6", "Button 7", "Button 8", + "Reload", + "N/A", "N/A", "N/A", "N/A" }; const DreamcastKey axis_keys[] = { DC_AXIS_X, DC_AXIS_Y, DC_AXIS_LT, DC_AXIS_RT, DC_AXIS_X2, DC_AXIS_Y2, EMU_AXIS_DPAD1_X, EMU_AXIS_DPAD1_Y, @@ -556,11 +560,10 @@ static void controller_mapping_popup(std::shared_ptr gamepad) if (ImGui::BeginPopupModal("Controller Mapping", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) { const float width = screen_width / 2; - const float col0_width = ImGui::CalcTextSize("Right DPad Downxxx").x + ImGui::GetStyle().FramePadding.x * 2.0f + ImGui::GetStyle().ItemSpacing.x; - const float col1_width = width + const float col_width = (width - ImGui::GetStyle().GrabMinSize - - (col0_width + ImGui::GetStyle().ItemSpacing.x) - - (ImGui::CalcTextSize("Map").x + ImGui::GetStyle().FramePadding.x * 2.0f + ImGui::GetStyle().ItemSpacing.x); + - (0 + ImGui::GetStyle().ItemSpacing.x) + - (ImGui::CalcTextSize("Map").x + ImGui::GetStyle().FramePadding.x * 2.0f + ImGui::GetStyle().ItemSpacing.x)) / 2; std::shared_ptr input_mapping = gamepad->get_input_mapping(); if (input_mapping == NULL || ImGui::Button("Done", ImVec2(100 * scaling, 30 * scaling))) @@ -599,13 +602,20 @@ static void controller_mapping_popup(std::shared_ptr gamepad) ImGui::BeginChildFrame(ImGui::GetID("buttons"), ImVec2(width, 0), ImGuiWindowFlags_None); ImGui::Columns(3, "bindings", false); - ImGui::SetColumnWidth(0, col0_width); - ImGui::SetColumnWidth(1, col1_width); + ImGui::SetColumnWidth(0, col_width); + ImGui::SetColumnWidth(1, col_width); for (u32 j = 0; j < ARRAY_SIZE(button_keys); j++) { sprintf(key_id, "key_id%d", j); ImGui::PushID(key_id); - ImGui::Text("%s", arcade_button_mode ? arcade_button_names[j] : button_names[j]); + + const char *btn_name = arcade_button_mode ? arcade_button_names[j] : button_names[j]; + const char *game_btn_name = GetCurrentGameButtonName(button_keys[j]); + if (game_btn_name != nullptr) + ImGui::Text("%s - %s", btn_name, game_btn_name); + else + ImGui::Text("%s", btn_name); + ImGui::NextColumn(); u32 code = input_mapping->get_button_code(gamepad_port, button_keys[j]); if (code != (u32)-1) @@ -638,14 +648,21 @@ static void controller_mapping_popup(std::shared_ptr gamepad) ImGui::Text(" Analog Axes "); ImGui::BeginChildFrame(ImGui::GetID("analog"), ImVec2(width, 0), ImGuiWindowFlags_None); ImGui::Columns(3, "bindings", false); - ImGui::SetColumnWidth(0, col0_width); - ImGui::SetColumnWidth(1, col1_width); + ImGui::SetColumnWidth(0, col_width); + ImGui::SetColumnWidth(1, col_width); for (u32 j = 0; j < ARRAY_SIZE(axis_keys); j++) { sprintf(key_id, "axis_id%d", j); ImGui::PushID(key_id); - ImGui::Text("%s", arcade_button_mode ? arcade_axis_names[j] : axis_names[j]); + + const char *axis_name = arcade_button_mode ? arcade_axis_names[j] : axis_names[j]; + const char *game_axis_name = GetCurrentGameAxisName(axis_keys[j]); + if (game_axis_name != nullptr) + ImGui::Text("%s - %s", axis_name, game_axis_name); + else + ImGui::Text("%s", axis_name); + ImGui::NextColumn(); u32 code = input_mapping->get_axis_code(gamepad_port, axis_keys[j]); if (code != (u32)-1) diff --git a/core/sdl/sdl.cpp b/core/sdl/sdl.cpp index bafb95bc0..e185a0332 100644 --- a/core/sdl/sdl.cpp +++ b/core/sdl/sdl.cpp @@ -99,11 +99,9 @@ static void set_mouse_position(int x, int y) } } -// FIXME this shouldn't be done by port. Need something like: handle_events() then get_port(0), get_port(2), ... -void input_sdl_handle(u32 port) +void input_sdl_handle() { - if (port == 0) // FIXME hack - SDLGamepadDevice::UpdateRumble(); + SDLGamepadDevice::UpdateRumble(); #define SET_FLAG(field, mask, expr) (field) = ((expr) ? ((field) & ~(mask)) : ((field) | (mask))) SDL_Event event; diff --git a/core/sdl/sdl.h b/core/sdl/sdl.h index 41750d3df..27dd3bb53 100644 --- a/core/sdl/sdl.h +++ b/core/sdl/sdl.h @@ -3,7 +3,7 @@ #include "types.h" extern void input_sdl_init(); -extern void input_sdl_handle(u32 port); +extern void input_sdl_handle(); extern void sdl_window_create(); extern void sdl_window_set_text(const char* text); extern void sdl_window_destroy(); diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index 33afb1eb5..b9d8e0ce7 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -209,29 +209,17 @@ static Win32KeyboardDevice keyboard(0); void ToggleFullscreen(); -void UpdateInputState(u32 port) +void UpdateInputState() { #if defined(USE_SDL) - input_sdl_handle(port); + input_sdl_handle(); #else - /* - Disabled for now. Need new EMU_BTN_ANA_LEFT/RIGHT/.. virtual controller keys - - joyx[port]=joyy[port]=0; - - if (GetAsyncKeyState('J')) - joyx[port]-=126; - if (GetAsyncKeyState('L')) - joyx[port]+=126; - - if (GetAsyncKeyState('I')) - joyy[port]-=126; - if (GetAsyncKeyState('K')) - joyy[port]+=126; - */ - std::shared_ptr gamepad = XInputGamepadDevice::GetXInputDevice(port); - if (gamepad != NULL) - gamepad->ReadInput(); + for (int port = 0; port < 4; port++) + { + std::shared_ptr gamepad = XInputGamepadDevice::GetXInputDevice(port); + if (gamepad != nullptr) + gamepad->ReadInput(); + } #endif } 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 bf538c5ad..366268df0 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -134,8 +134,6 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_screenDpi(JNIEnv *env screen_dpi = screenDpi; } -bool egl_makecurrent(); - extern int screen_width,screen_height; float vjoy_pos[15][8]; @@ -150,21 +148,14 @@ static ANativeWindow *g_window = 0; void os_DoEvents() { - // @@@ Nothing here yet } void os_CreateWindow() { } -// -// Platform-specific NullDC functions -// - - -void UpdateInputState(u32 Port) +void UpdateInputState() { - // @@@ Nothing here yet } void common_linux_setup(); @@ -339,8 +330,6 @@ JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_data(JNIEnv *env, job return 0; } -extern void egl_stealcntx(); - static void *render_thread_func(void *) { #ifdef USE_VULKAN @@ -387,19 +376,16 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinitJava(JNIEnv * { screen_width = width; screen_height = height; - // FIXME egl_stealcntx(); rend_init_renderer(); } JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_rendframeJava(JNIEnv *env,jobject obj) { - // FIXME egl_stealcntx(); return (jboolean)rend_single_frame(); } JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendtermJava(JNIEnv * env, jobject obj) { - // FIXME egl_stealcntx(); rend_term_renderer(); } diff --git a/shell/apple/emulator-ios/emulator/ios_main.mm b/shell/apple/emulator-ios/emulator/ios_main.mm index 2c8684889..7534a9e85 100644 --- a/shell/apple/emulator-ios/emulator/ios_main.mm +++ b/shell/apple/emulator-ios/emulator/ios_main.mm @@ -87,7 +87,7 @@ void os_CreateWindow() { void os_SetupInput() { } -void UpdateInputState(u32 port) { +void UpdateInputState() { } diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index 2a5561077..810dd92b9 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -54,9 +54,9 @@ void os_SetWindowText(const char * text) { void os_DoEvents() { } -void UpdateInputState(u32 port) { +void UpdateInputState() { #if defined(USE_SDL) - input_sdl_handle(port); + input_sdl_handle(); #endif } diff --git a/tests/src/test_stubs.cpp b/tests/src/test_stubs.cpp index b26220702..d3728f8f0 100644 --- a/tests/src/test_stubs.cpp +++ b/tests/src/test_stubs.cpp @@ -24,7 +24,7 @@ void os_SetupInput() { } -void UpdateInputState(u32 port) +void UpdateInputState() { }