diff options
Diffstat (limited to 'src')
32 files changed, 544 insertions, 442 deletions
diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp index 3defd33d0bb..823e5e80c9e 100644 --- a/src/emu/emuopts.cpp +++ b/src/emu/emuopts.cpp @@ -157,8 +157,9 @@ const options_entry emu_options::s_option_entries[] = { OPTION_UI_ACTIVE, "0", core_options::option_type::BOOLEAN, "enable user interface on top of emulated keyboard (if present)" }, { OPTION_OFFSCREEN_RELOAD ";reload", "0", core_options::option_type::BOOLEAN, "convert lightgun button 2 into offscreen reload" }, { OPTION_JOYSTICK_MAP ";joymap", "auto", core_options::option_type::STRING, "explicit joystick map, or auto to auto-select" }, - { OPTION_JOYSTICK_DEADZONE ";joy_deadzone;jdz(0.00-1)", "0.3", core_options::option_type::FLOAT, "center deadzone range for joystick where change is ignored (0.0 center, 1.0 end)" }, - { OPTION_JOYSTICK_SATURATION ";joy_saturation;jsat(0.00-1)", "0.85", core_options::option_type::FLOAT, "end of axis saturation range for joystick where change is ignored (0.0 center, 1.0 end)" }, + { OPTION_JOYSTICK_DEADZONE ";joy_deadzone;jdz(0.00-1)", "0.15", core_options::option_type::FLOAT, "center deadzone range for joystick where change is ignored (0.0 center, 1.0 end)" }, + { OPTION_JOYSTICK_SATURATION ";joy_saturation;jsat(0.00-1)", "0.85", core_options::option_type::FLOAT, "end of axis saturation range for joystick where change is ignored (0.0 center, 1.0 end)" }, + { OPTION_JOYSTICK_THRESHOLD ";joy_threshold;jthresh(0.00-1)", "0.3", core_options::option_type::FLOAT, "threshold for joystick to be considered active as a switch (0.0 center, 1.0 end)" }, { OPTION_NATURAL_KEYBOARD ";nat", "0", core_options::option_type::BOOLEAN, "specifies whether to use a natural keyboard or not" }, { OPTION_JOYSTICK_CONTRADICTORY ";joy_contradictory","0", core_options::option_type::BOOLEAN, "enable contradictory direction digital joystick input at the same time" }, { OPTION_COIN_IMPULSE, "0", core_options::option_type::INTEGER, "set coin impulse time (n<0 disable impulse, n==0 obey driver, 0<n set time n)" }, diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h index a8641c72579..0a1b1dcf413 100644 --- a/src/emu/emuopts.h +++ b/src/emu/emuopts.h @@ -136,6 +136,7 @@ #define OPTION_JOYSTICK_MAP "joystick_map" #define OPTION_JOYSTICK_DEADZONE "joystick_deadzone" #define OPTION_JOYSTICK_SATURATION "joystick_saturation" +#define OPTION_JOYSTICK_THRESHOLD "joystick_threshold" #define OPTION_NATURAL_KEYBOARD "natural" #define OPTION_JOYSTICK_CONTRADICTORY "joystick_contradictory" #define OPTION_COIN_IMPULSE "coin_impulse" @@ -426,6 +427,7 @@ public: const char *joystick_map() const { return value(OPTION_JOYSTICK_MAP); } float joystick_deadzone() const { return float_value(OPTION_JOYSTICK_DEADZONE); } float joystick_saturation() const { return float_value(OPTION_JOYSTICK_SATURATION); } + float joystick_threshold() const { return float_value(OPTION_JOYSTICK_THRESHOLD); } bool steadykey() const { return bool_value(OPTION_STEADYKEY); } bool ui_active() const { return bool_value(OPTION_UI_ACTIVE); } bool offscreen_reload() const { return bool_value(OPTION_OFFSCREEN_RELOAD); } diff --git a/src/emu/inpttype.ipp b/src/emu/inpttype.ipp index 6741fd7de12..80e207de034 100644 --- a/src/emu/inpttype.ipp +++ b/src/emu/inpttype.ipp @@ -580,7 +580,7 @@ namespace { INPUT_PORT_DIGITAL_TYPE( 0, OTHER, COIN10, N_p("input-name", "Coin 10"), input_seq() ) \ INPUT_PORT_DIGITAL_TYPE( 0, OTHER, COIN11, N_p("input-name", "Coin 11"), input_seq() ) \ INPUT_PORT_DIGITAL_TYPE( 0, OTHER, COIN12, N_p("input-name", "Coin 12"), input_seq() ) \ - INPUT_PORT_DIGITAL_TYPE( 0, OTHER, BILL1, N_p("input-name", "Bill 1"), input_seq(KEYCODE_BACKSPACE) ) \ + INPUT_PORT_DIGITAL_TYPE( 0, OTHER, BILL1, N_p("input-name", "Banknote 1"), input_seq(KEYCODE_BACKSPACE) ) \ CORE_INPUT_TYPES_END() #define CORE_INPUT_TYPES_SERVICE \ @@ -739,30 +739,30 @@ namespace { #define CORE_INPUT_TYPES_TRACKBALL_X \ CORE_INPUT_TYPES_BEGIN(trackball_x) \ - INPUT_PORT_ANALOG_TYPE( 1, PLAYER1, TRACKBALL_X, N_p("input-name", "Track X"), input_seq(MOUSECODE_X_INDEXED(0), input_seq::or_code, JOYCODE_X_INDEXED(0)), input_seq(KEYCODE_LEFT), input_seq(KEYCODE_RIGHT) ) \ - INPUT_PORT_ANALOG_TYPE( 2, PLAYER2, TRACKBALL_X, N_p("input-name", "Track X 2"), input_seq(MOUSECODE_X_INDEXED(1), input_seq::or_code, JOYCODE_X_INDEXED(1)), input_seq(KEYCODE_D), input_seq(KEYCODE_G) ) \ - INPUT_PORT_ANALOG_TYPE( 3, PLAYER3, TRACKBALL_X, N_p("input-name", "Track X 3"), input_seq(MOUSECODE_X_INDEXED(2), input_seq::or_code, JOYCODE_X_INDEXED(2)), input_seq(KEYCODE_J), input_seq(KEYCODE_L) ) \ - INPUT_PORT_ANALOG_TYPE( 4, PLAYER4, TRACKBALL_X, N_p("input-name", "Track X 4"), input_seq(MOUSECODE_X_INDEXED(3), input_seq::or_code, JOYCODE_X_INDEXED(3)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 5, PLAYER5, TRACKBALL_X, N_p("input-name", "Track X 5"), input_seq(MOUSECODE_X_INDEXED(4), input_seq::or_code, JOYCODE_X_INDEXED(4)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 6, PLAYER6, TRACKBALL_X, N_p("input-name", "Track X 6"), input_seq(MOUSECODE_X_INDEXED(5), input_seq::or_code, JOYCODE_X_INDEXED(5)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 7, PLAYER7, TRACKBALL_X, N_p("input-name", "Track X 7"), input_seq(MOUSECODE_X_INDEXED(6), input_seq::or_code, JOYCODE_X_INDEXED(6)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 8, PLAYER8, TRACKBALL_X, N_p("input-name", "Track X 8"), input_seq(MOUSECODE_X_INDEXED(7), input_seq::or_code, JOYCODE_X_INDEXED(7)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 9, PLAYER9, TRACKBALL_X, N_p("input-name", "Track X 9"), input_seq(MOUSECODE_X_INDEXED(8), input_seq::or_code, JOYCODE_X_INDEXED(8)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 10, PLAYER10, TRACKBALL_X, N_p("input-name", "Track X 10"), input_seq(MOUSECODE_X_INDEXED(9), input_seq::or_code, JOYCODE_X_INDEXED(9)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 1, PLAYER1, TRACKBALL_X, N_p("input-name", "Trackball X"), input_seq(MOUSECODE_X_INDEXED(0), input_seq::or_code, JOYCODE_X_INDEXED(0)), input_seq(KEYCODE_LEFT), input_seq(KEYCODE_RIGHT) ) \ + INPUT_PORT_ANALOG_TYPE( 2, PLAYER2, TRACKBALL_X, N_p("input-name", "Trackball X 2"), input_seq(MOUSECODE_X_INDEXED(1), input_seq::or_code, JOYCODE_X_INDEXED(1)), input_seq(KEYCODE_D), input_seq(KEYCODE_G) ) \ + INPUT_PORT_ANALOG_TYPE( 3, PLAYER3, TRACKBALL_X, N_p("input-name", "Trackball X 3"), input_seq(MOUSECODE_X_INDEXED(2), input_seq::or_code, JOYCODE_X_INDEXED(2)), input_seq(KEYCODE_J), input_seq(KEYCODE_L) ) \ + INPUT_PORT_ANALOG_TYPE( 4, PLAYER4, TRACKBALL_X, N_p("input-name", "Trackball X 4"), input_seq(MOUSECODE_X_INDEXED(3), input_seq::or_code, JOYCODE_X_INDEXED(3)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 5, PLAYER5, TRACKBALL_X, N_p("input-name", "Trackball X 5"), input_seq(MOUSECODE_X_INDEXED(4), input_seq::or_code, JOYCODE_X_INDEXED(4)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 6, PLAYER6, TRACKBALL_X, N_p("input-name", "Trackball X 6"), input_seq(MOUSECODE_X_INDEXED(5), input_seq::or_code, JOYCODE_X_INDEXED(5)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 7, PLAYER7, TRACKBALL_X, N_p("input-name", "Trackball X 7"), input_seq(MOUSECODE_X_INDEXED(6), input_seq::or_code, JOYCODE_X_INDEXED(6)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 8, PLAYER8, TRACKBALL_X, N_p("input-name", "Trackball X 8"), input_seq(MOUSECODE_X_INDEXED(7), input_seq::or_code, JOYCODE_X_INDEXED(7)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 9, PLAYER9, TRACKBALL_X, N_p("input-name", "Trackball X 9"), input_seq(MOUSECODE_X_INDEXED(8), input_seq::or_code, JOYCODE_X_INDEXED(8)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 10, PLAYER10, TRACKBALL_X, N_p("input-name", "Trackball X 10"), input_seq(MOUSECODE_X_INDEXED(9), input_seq::or_code, JOYCODE_X_INDEXED(9)), input_seq(), input_seq() ) \ CORE_INPUT_TYPES_END() #define CORE_INPUT_TYPES_TRACKBALL_Y \ CORE_INPUT_TYPES_BEGIN(trackball_y) \ - INPUT_PORT_ANALOG_TYPE( 1, PLAYER1, TRACKBALL_Y, N_p("input-name", "Track Y"), input_seq(MOUSECODE_Y_INDEXED(0), input_seq::or_code, JOYCODE_Y_INDEXED(0)), input_seq(KEYCODE_UP), input_seq(KEYCODE_DOWN) ) \ - INPUT_PORT_ANALOG_TYPE( 2, PLAYER2, TRACKBALL_Y, N_p("input-name", "Track Y 2"), input_seq(MOUSECODE_Y_INDEXED(1), input_seq::or_code, JOYCODE_Y_INDEXED(1)), input_seq(KEYCODE_R), input_seq(KEYCODE_F) ) \ - INPUT_PORT_ANALOG_TYPE( 3, PLAYER3, TRACKBALL_Y, N_p("input-name", "Track Y 3"), input_seq(MOUSECODE_Y_INDEXED(2), input_seq::or_code, JOYCODE_Y_INDEXED(2)), input_seq(KEYCODE_I), input_seq(KEYCODE_K) ) \ - INPUT_PORT_ANALOG_TYPE( 4, PLAYER4, TRACKBALL_Y, N_p("input-name", "Track Y 4"), input_seq(MOUSECODE_Y_INDEXED(3), input_seq::or_code, JOYCODE_Y_INDEXED(3)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 5, PLAYER5, TRACKBALL_Y, N_p("input-name", "Track Y 5"), input_seq(MOUSECODE_Y_INDEXED(4), input_seq::or_code, JOYCODE_Y_INDEXED(4)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 6, PLAYER6, TRACKBALL_Y, N_p("input-name", "Track Y 6"), input_seq(MOUSECODE_Y_INDEXED(5), input_seq::or_code, JOYCODE_Y_INDEXED(5)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 7, PLAYER7, TRACKBALL_Y, N_p("input-name", "Track Y 7"), input_seq(MOUSECODE_Y_INDEXED(6), input_seq::or_code, JOYCODE_Y_INDEXED(6)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 8, PLAYER8, TRACKBALL_Y, N_p("input-name", "Track Y 8"), input_seq(MOUSECODE_Y_INDEXED(7), input_seq::or_code, JOYCODE_Y_INDEXED(7)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 9, PLAYER9, TRACKBALL_Y, N_p("input-name", "Track Y 9"), input_seq(MOUSECODE_Y_INDEXED(8), input_seq::or_code, JOYCODE_Y_INDEXED(8)), input_seq(), input_seq() ) \ - INPUT_PORT_ANALOG_TYPE( 10, PLAYER10, TRACKBALL_Y, N_p("input-name", "Track Y 10"), input_seq(MOUSECODE_Y_INDEXED(9), input_seq::or_code, JOYCODE_Y_INDEXED(9)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 1, PLAYER1, TRACKBALL_Y, N_p("input-name", "Trackball Y"), input_seq(MOUSECODE_Y_INDEXED(0), input_seq::or_code, JOYCODE_Y_INDEXED(0)), input_seq(KEYCODE_UP), input_seq(KEYCODE_DOWN) ) \ + INPUT_PORT_ANALOG_TYPE( 2, PLAYER2, TRACKBALL_Y, N_p("input-name", "Trackball Y 2"), input_seq(MOUSECODE_Y_INDEXED(1), input_seq::or_code, JOYCODE_Y_INDEXED(1)), input_seq(KEYCODE_R), input_seq(KEYCODE_F) ) \ + INPUT_PORT_ANALOG_TYPE( 3, PLAYER3, TRACKBALL_Y, N_p("input-name", "Trackball Y 3"), input_seq(MOUSECODE_Y_INDEXED(2), input_seq::or_code, JOYCODE_Y_INDEXED(2)), input_seq(KEYCODE_I), input_seq(KEYCODE_K) ) \ + INPUT_PORT_ANALOG_TYPE( 4, PLAYER4, TRACKBALL_Y, N_p("input-name", "Trackball Y 4"), input_seq(MOUSECODE_Y_INDEXED(3), input_seq::or_code, JOYCODE_Y_INDEXED(3)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 5, PLAYER5, TRACKBALL_Y, N_p("input-name", "Trackball Y 5"), input_seq(MOUSECODE_Y_INDEXED(4), input_seq::or_code, JOYCODE_Y_INDEXED(4)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 6, PLAYER6, TRACKBALL_Y, N_p("input-name", "Trackball Y 6"), input_seq(MOUSECODE_Y_INDEXED(5), input_seq::or_code, JOYCODE_Y_INDEXED(5)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 7, PLAYER7, TRACKBALL_Y, N_p("input-name", "Trackball Y 7"), input_seq(MOUSECODE_Y_INDEXED(6), input_seq::or_code, JOYCODE_Y_INDEXED(6)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 8, PLAYER8, TRACKBALL_Y, N_p("input-name", "Trackball Y 8"), input_seq(MOUSECODE_Y_INDEXED(7), input_seq::or_code, JOYCODE_Y_INDEXED(7)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 9, PLAYER9, TRACKBALL_Y, N_p("input-name", "Trackball Y 9"), input_seq(MOUSECODE_Y_INDEXED(8), input_seq::or_code, JOYCODE_Y_INDEXED(8)), input_seq(), input_seq() ) \ + INPUT_PORT_ANALOG_TYPE( 10, PLAYER10, TRACKBALL_Y, N_p("input-name", "Trackball Y 10"), input_seq(MOUSECODE_Y_INDEXED(9), input_seq::or_code, JOYCODE_Y_INDEXED(9)), input_seq(), input_seq() ) \ CORE_INPUT_TYPES_END() #define CORE_INPUT_TYPES_AD_STICK_X \ diff --git a/src/emu/input.cpp b/src/emu/input.cpp index 6c3699a833a..d8029216624 100644 --- a/src/emu/input.cpp +++ b/src/emu/input.cpp @@ -24,6 +24,8 @@ +namespace { + //************************************************************************** // TYPE DEFINITIONS //************************************************************************** @@ -49,8 +51,8 @@ struct code_string_table return nullptr; } - u32 m_code; - const char * m_string; + u32 m_code; + const char * m_string; }; @@ -60,7 +62,7 @@ struct code_string_table //************************************************************************** // token strings for device classes -static const code_string_table devclass_token_table[] = +const code_string_table devclass_token_table[] = { { DEVICE_CLASS_KEYBOARD, "KEYCODE" }, { DEVICE_CLASS_MOUSE, "MOUSECODE" }, @@ -70,7 +72,7 @@ static const code_string_table devclass_token_table[] = }; // friendly strings for device classes -static const code_string_table devclass_string_table[] = +const code_string_table devclass_string_table[] = { { DEVICE_CLASS_KEYBOARD, "Kbd" }, { DEVICE_CLASS_MOUSE, "Mouse" }, @@ -80,7 +82,7 @@ static const code_string_table devclass_string_table[] = }; // token strings for item modifiers -static const code_string_table modifier_token_table[] = +const code_string_table modifier_token_table[] = { { ITEM_MODIFIER_REVERSE, "REVERSE" }, { ITEM_MODIFIER_POS, "POS" }, @@ -93,7 +95,7 @@ static const code_string_table modifier_token_table[] = }; // friendly strings for item modifiers -static const code_string_table modifier_string_table[] = +const code_string_table modifier_string_table[] = { { ITEM_MODIFIER_REVERSE, "Reverse" }, { ITEM_MODIFIER_POS, "+" }, @@ -106,7 +108,7 @@ static const code_string_table modifier_string_table[] = }; // token strings for item classes -static const code_string_table itemclass_token_table[] = +const code_string_table itemclass_token_table[] = { { ITEM_CLASS_SWITCH, "SWITCH" }, { ITEM_CLASS_ABSOLUTE, "ABSOLUTE" }, @@ -115,7 +117,7 @@ static const code_string_table itemclass_token_table[] = }; // token strings for standard item ids -static const code_string_table itemid_token_table[] = +const code_string_table itemid_token_table[] = { // standard keyboard codes { ITEM_ID_A, "A" }, @@ -355,6 +357,48 @@ static const code_string_table itemid_token_table[] = //************************************************************************** +// UTILITY FUNCTIONS +//************************************************************************** + +inline void accumulate_axis_value( + s32 &result, + input_item_class &resultclass, + input_item_class &resultclasszero, + s32 value, + input_item_class valueclass, + input_item_class valueclasszero) +{ + if (!value) + { + // track the highest-priority zero + if ((ITEM_CLASS_ABSOLUTE == valueclasszero) || (ITEM_CLASS_INVALID == resultclasszero)) + resultclasszero = valueclasszero; + } + else if (ITEM_CLASS_ABSOLUTE == valueclass) + { + // absolute values override relative values + if (ITEM_CLASS_ABSOLUTE == resultclass) + result += value; + else + result = value; + resultclass = ITEM_CLASS_ABSOLUTE; + } + else if (ITEM_CLASS_RELATIVE == valueclass) + { + // relative values accumulate + if (resultclass != ITEM_CLASS_ABSOLUTE) + { + result += value; + resultclass = ITEM_CLASS_RELATIVE; + } + } +} + +} // anonymous namespace + + + +//************************************************************************** // INPUT MANAGER //************************************************************************** @@ -861,91 +905,83 @@ bool input_manager::seq_pressed(const input_seq &seq) s32 input_manager::seq_axis_value(const input_seq &seq, input_item_class &itemclass) { - // start with no valid classes - input_item_class itemclasszero = ITEM_CLASS_INVALID; + // start with zero result and no valid classes + s32 result = 0; itemclass = ITEM_CLASS_INVALID; + input_item_class itemclasszero = ITEM_CLASS_INVALID; // iterate over all of the codes - s32 result = 0; + s32 groupval = 0; + input_item_class groupclass = ITEM_CLASS_INVALID; + input_item_class groupclasszero = ITEM_CLASS_INVALID; bool invert = false; bool enable = true; for (int codenum = 0; ; codenum++) { - input_code code = seq[codenum]; + input_code const code = seq[codenum]; if (code == input_seq::not_code) { - // handle NOT + // handle NOT - invert the next code invert = true; } else if (code == input_seq::end_code) { - // handle END + // handle END - commit group and break out of loop + accumulate_axis_value( + result, itemclass, itemclasszero, + groupval, groupclass, groupclasszero); break; } else if (code == input_seq::or_code) { - // handle OR - - // reset invert and enable for the next group + // handle OR - commit group and reset for the next group + accumulate_axis_value( + result, itemclass, itemclasszero, + groupval, groupclass, groupclasszero); + groupval = 0; + groupclasszero = ITEM_CLASS_INVALID; + groupclass = ITEM_CLASS_INVALID; invert = false; enable = true; } else if (enable) { // handle everything else only if we're still enabled + input_item_class const codeclass = code.item_class(); // switch codes serve as enables - if (code.item_class() == ITEM_CLASS_SWITCH) + if (ITEM_CLASS_SWITCH == codeclass) { // AND against previous digital codes if (enable) + { enable = code_pressed(code) ^ invert; - // FIXME: need to clear current group value if enable became false - // you can't create a sequence where this matters using the internal UI, - // but you can by editing a CFG file (or controller config file) + if (!enable) + { + // clear current group if enable became false - only way out is an OR code + groupval = 0; + groupclasszero = ITEM_CLASS_INVALID; + groupclass = ITEM_CLASS_INVALID; + } + } } else { // non-switch codes are analog values - s32 value = code_value(code); - - // if we got a 0 value, don't do anything except remember the first type - if (value == 0) - { - if (itemclasszero == ITEM_CLASS_INVALID) - itemclasszero = code.item_class(); - } - else if (code.item_class() == ITEM_CLASS_ABSOLUTE) - { - // non-zero absolute values override relative values - if (itemclass == ITEM_CLASS_ABSOLUTE) - result += value; - else - result = value; - itemclass = ITEM_CLASS_ABSOLUTE; - } - else if (code.item_class() == ITEM_CLASS_RELATIVE) - { - // non-zero relative values accumulate in the absence of absolute values - if (itemclass != ITEM_CLASS_ABSOLUTE) - { - result += value; - itemclass = ITEM_CLASS_RELATIVE; - } - } + accumulate_axis_value( + groupval, groupclass, groupclasszero, + code_value(code), codeclass, codeclass); } - // clear the invert flag + // clear the invert flag - it only applies to one item invert = false; } } - // saturate mixed absolute values - if (itemclass == ITEM_CLASS_ABSOLUTE) + // saturate mixed absolute values, report neutral type + if (ITEM_CLASS_ABSOLUTE == itemclass) result = std::clamp(result, osd::INPUT_ABSOLUTE_MIN, osd::INPUT_ABSOLUTE_MAX); - - // if the caller wants to know the type, provide it - if (result == 0) + else if (ITEM_CLASS_INVALID == itemclass) itemclass = itemclasszero; return result; } diff --git a/src/emu/inputdev.cpp b/src/emu/inputdev.cpp index 40bdd88b8d8..5f426374761 100644 --- a/src/emu/inputdev.cpp +++ b/src/emu/inputdev.cpp @@ -28,7 +28,12 @@ class input_device_switch_item : public input_device_item { public: // construction/destruction - input_device_switch_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate); + input_device_switch_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate); // readers virtual s32 read_as_switch(input_item_modifier modifier) override; @@ -54,7 +59,12 @@ class input_device_relative_item : public input_device_item { public: // construction/destruction - input_device_relative_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate); + input_device_relative_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate); // readers virtual s32 read_as_switch(input_item_modifier modifier) override; @@ -71,7 +81,12 @@ class input_device_absolute_item : public input_device_item { public: // construction/destruction - input_device_absolute_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate); + input_device_absolute_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate); // readers virtual s32 read_as_switch(input_item_modifier modifier) override; @@ -258,14 +273,15 @@ u8 joystick_map::update(s32 xaxisval, s32 yaxisval) //------------------------------------------------- input_device::input_device(input_manager &manager, std::string_view name, std::string_view id, void *internal) - : m_manager(manager), - m_name(name), - m_id(id), - m_devindex(-1), - m_maxitem(input_item_id(0)), - m_internal(internal), - m_steadykey_enabled(manager.machine().options().steadykey()), - m_lightgun_reload_button(manager.machine().options().offscreen_reload()) + : m_manager(manager) + , m_name(name) + , m_id(id) + , m_devindex(-1) + , m_maxitem(input_item_id(0)) + , m_internal(internal) + , m_threshold(std::max<s32>(s32(manager.machine().options().joystick_threshold() * osd::INPUT_ABSOLUTE_MAX), 1)) + , m_steadykey_enabled(manager.machine().options().steadykey()) + , m_lightgun_reload_button(manager.machine().options().offscreen_reload()) { } @@ -283,7 +299,11 @@ input_device::~input_device() // add_item - add a new item to an input device //------------------------------------------------- -input_item_id input_device::add_item(std::string_view name, input_item_id itemid, item_get_state_func getstate, void *internal) +input_item_id input_device::add_item( + std::string_view name, + input_item_id itemid, + item_get_state_func getstate, + void *internal) { if (machine().phase() != machine_phase::INIT) throw emu_fatalerror("Can only call input_device::add_item at init time!"); @@ -411,9 +431,10 @@ input_device_lightgun::input_device_lightgun(input_manager &manager, std::string //------------------------------------------------- input_device_joystick::input_device_joystick(input_manager &manager, std::string_view _name, std::string_view _id, void *_internal) - : input_device(manager, _name, _id, _internal), - m_joystick_deadzone(s32(manager.machine().options().joystick_deadzone() * osd::INPUT_ABSOLUTE_MAX)), - m_joystick_saturation(s32(manager.machine().options().joystick_saturation() * osd::INPUT_ABSOLUTE_MAX)) + : input_device(manager, _name, _id, _internal) + , m_deadzone(s32(manager.machine().options().joystick_deadzone() * osd::INPUT_ABSOLUTE_MAX)) + , m_saturation(s32(manager.machine().options().joystick_saturation() * osd::INPUT_ABSOLUTE_MAX)) + , m_range(m_saturation - m_deadzone) { // get the default joystick map const char *mapstring = machine().options().joystick_map(); @@ -440,24 +461,16 @@ input_device_joystick::input_device_joystick(input_manager &manager, std::string s32 input_device_joystick::adjust_absolute_value(s32 result) const { // properties are symmetric - bool negative = false; - if (result < 0) - { - negative = true; + bool const negative = result < 0;; + if (negative) result = -result; - } - // if in the deadzone, return 0 - if (result < m_joystick_deadzone) + if (result < m_deadzone) // if in the deadzone, return 0 result = 0; - - // if saturated, return the max - else if (result > m_joystick_saturation) + else if (result >= m_saturation) // if saturated, return the max result = osd::INPUT_ABSOLUTE_MAX; - - // otherwise, scale - else - result = s64(result - m_joystick_deadzone) * s64(osd::INPUT_ABSOLUTE_MAX) / s64(m_joystick_saturation - m_joystick_deadzone); + else // otherwise, scale + result = s64(result - m_deadzone) * s64(osd::INPUT_ABSOLUTE_MAX) / m_range; // re-apply sign and return return negative ? -result : result; @@ -671,25 +684,31 @@ bool input_class_joystick::set_global_joystick_map(const char *mapstring) // input_device_item - constructor //------------------------------------------------- -input_device_item::input_device_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate, input_item_class itemclass) - : m_device(device), - m_name(name), - m_internal(internal), - m_itemid(itemid), - m_itemclass(itemclass), - m_getstate(getstate), - m_current(0) +input_device_item::input_device_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate, + input_item_class itemclass) + : m_device(device) + , m_name(name) + , m_internal(internal) + , m_itemid(itemid) + , m_itemclass(itemclass) + , m_getstate(getstate) + , m_current(0) { const char *standard_token = manager().standard_token(itemid); if (standard_token) { - // use a standard token name for know item IDs - m_token.assign(standard_token); + // use a standard token name for known item IDs + m_token = standard_token; } else { // otherwise, create a tokenized name - m_token.assign(strmakeupper(name)); + m_token = strmakeupper(name); strdelchr(m_token, ' '); strdelchr(m_token, '_'); } @@ -725,10 +744,15 @@ bool input_device_item::check_axis(input_item_modifier modifier, s32 memory) // input_device_switch_item - constructor //------------------------------------------------- -input_device_switch_item::input_device_switch_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate) - : input_device_item(device, name, internal, itemid, getstate, ITEM_CLASS_SWITCH), - m_steadykey(0), - m_oldkey(0) +input_device_switch_item::input_device_switch_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate) + : input_device_item(device, name, internal, itemid, getstate, ITEM_CLASS_SWITCH) + , m_steadykey(0) + , m_oldkey(0) { } @@ -830,7 +854,12 @@ bool input_device_switch_item::steadykey_changed() // input_device_relative_item - constructor //------------------------------------------------- -input_device_relative_item::input_device_relative_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate) +input_device_relative_item::input_device_relative_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate) : input_device_item(device, name, internal, itemid, getstate, ITEM_CLASS_RELATIVE) { } @@ -911,7 +940,12 @@ bool input_device_relative_item::item_check_axis(input_item_modifier modifier, s // input_device_absolute_item - constructor //------------------------------------------------- -input_device_absolute_item::input_device_absolute_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate) +input_device_absolute_item::input_device_absolute_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate) : input_device_item(device, name, internal, itemid, getstate, ITEM_CLASS_ABSOLUTE) { } @@ -925,8 +959,7 @@ input_device_absolute_item::input_device_absolute_item(input_device &device, std s32 input_device_absolute_item::read_as_switch(input_item_modifier modifier) { // start with the current value - s32 result = m_device.adjust_absolute(update_value()); - assert(result >= osd::INPUT_ABSOLUTE_MIN && result <= osd::INPUT_ABSOLUTE_MAX); + s32 const result = update_value(); // left/right/up/down: if this is a joystick, fetch the paired X/Y axis values and convert if (m_device.devclass() == DEVICE_CLASS_JOYSTICK && modifier >= ITEM_MODIFIER_LEFT && modifier <= ITEM_MODIFIER_DOWN) @@ -944,18 +977,24 @@ s32 input_device_absolute_item::read_as_switch(input_item_modifier modifier) // now map the X and Y axes to a 9x9 grid using the raw values joystick_map &joymap = downcast<input_device_joystick &>(m_device).joymap(); - return (joymap.update(xaxis_item->current(), yaxis_item->current()) >> (modifier - ITEM_MODIFIER_LEFT)) & 1; + return BIT(joymap.update(xaxis_item->current(), yaxis_item->current()), modifier - ITEM_MODIFIER_LEFT); } } - // positive/negative: true if past the deadzone in either direction - if (modifier == ITEM_MODIFIER_POS || modifier == ITEM_MODIFIER_RIGHT || modifier == ITEM_MODIFIER_DOWN) - return (result > 0); - else if (modifier == ITEM_MODIFIER_NEG || modifier == ITEM_MODIFIER_LEFT || modifier == ITEM_MODIFIER_UP) - return (result < 0); - - // all other cases just return 0 - return 0; + // positive/negative: true if past the threshold in either direction, otherwise zero + switch (modifier) + { + case ITEM_MODIFIER_POS: + case ITEM_MODIFIER_RIGHT: + case ITEM_MODIFIER_DOWN: + return result >= m_device.threshold(); + case ITEM_MODIFIER_NEG: + case ITEM_MODIFIER_LEFT: + case ITEM_MODIFIER_UP: + return -result >= m_device.threshold(); + default: + return 0; + } } diff --git a/src/emu/inputdev.h b/src/emu/inputdev.h index 78f2b6eeb95..06a11866cea 100644 --- a/src/emu/inputdev.h +++ b/src/emu/inputdev.h @@ -100,7 +100,13 @@ public: protected: // construction/destruction - input_device_item(input_device &device, std::string_view name, void *internal, input_item_id itemid, item_get_state_func getstate, input_item_class itemclass); + input_device_item( + input_device &device, + std::string_view name, + void *internal, + input_item_id itemid, + item_get_state_func getstate, + input_item_class itemclass); // internal state input_device & m_device; // reference to our owning device @@ -138,14 +144,19 @@ public: input_device_item *item(input_item_id index) const { return m_item[index].get(); } input_item_id maxitem() const { return m_maxitem; } void *internal() const { return m_internal; } + s32 threshold() const { return m_threshold; } bool steadykey_enabled() const { return m_steadykey_enabled; } bool lightgun_reload_button() const { return m_lightgun_reload_button; } // setters void set_devindex(int devindex) { m_devindex = devindex; } - // item management - virtual input_item_id add_item(std::string_view name, input_item_id itemid, item_get_state_func getstate, void *internal) override; + // interface for host input device + virtual input_item_id add_item( + std::string_view name, + input_item_id itemid, + item_get_state_func getstate, + void *internal) override; // helpers s32 adjust_absolute(s32 value) const { return adjust_absolute_value(value); } @@ -164,10 +175,11 @@ private: int m_devindex; // device index of this device std::unique_ptr<input_device_item> m_item[ITEM_ID_ABSOLUTE_MAXIMUM+1]; // array of pointers to items input_item_id m_maxitem; // maximum item index - void * m_internal; // internal callback pointer + void *const m_internal; // internal callback pointer - bool m_steadykey_enabled; // steadykey enabled for keyboards - bool m_lightgun_reload_button; // lightgun reload hack + s32 const m_threshold; // threshold for treating absolute axis as active + bool const m_steadykey_enabled; // steadykey enabled for keyboards + bool const m_lightgun_reload_button; // lightgun reload hack }; @@ -238,9 +250,10 @@ protected: private: // joystick information - joystick_map m_joymap; // joystick map for this device - s32 m_joystick_deadzone; // deadzone for joystick - s32 m_joystick_saturation; // saturation position for joystick + joystick_map m_joymap; // joystick map for this device + s32 const m_deadzone; // deadzone for joystick + s32 const m_saturation; // saturation position for joystick + s64 const m_range; // difference between saturation and deadzone }; diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp index 1a16accd94c..fb8e6e3651c 100644 --- a/src/emu/ioport.cpp +++ b/src/emu/ioport.cpp @@ -91,19 +91,21 @@ ***************************************************************************/ #include "emu.h" -#include "emuopts.h" + #include "config.h" +#include "emuopts.h" #include "fileio.h" -#include "xmlfile.h" -#include "profiler.h" -#include "ui/uimain.h" #include "inputdev.h" #include "natkeyboard.h" +#include "profiler.h" + +#include "ui/uimain.h" #include "util/corestr.h" #include "util/ioprocsfilter.h" #include "util/language.h" #include "util/unicode.h" +#include "util/xmlfile.h" #include "osdepend.h" @@ -163,6 +165,22 @@ inline s32 apply_scale(s32 value, s64 scale) return (s64(value) * scale) / (1 << 24); } +//------------------------------------------------- +// compute_shift -- get shift required to right- +// align an I/O port field value +//------------------------------------------------- + +inline u8 compute_shift(ioport_value mask) +{ + u8 result = 0U; + while (mask && !BIT(mask, 0)) + { + mask >>= 1; + ++result; + } + return result; +} + //************************************************************************** @@ -3398,9 +3416,9 @@ ioport_configurer& ioport_configurer::onoff_alloc(const char *name, ioport_value //------------------------------------------------- dynamic_field::dynamic_field(ioport_field &field) - : m_field(field), - m_shift(0), - m_oldval(field.defvalue()) + : m_field(field) + , m_shift(0) + , m_oldval(field.defvalue()) { // fill in the data for (ioport_value mask = field.mask(); !(mask & 1); mask >>= 1) @@ -3455,45 +3473,36 @@ void dynamic_field::write(ioport_value newval) //------------------------------------------------- analog_field::analog_field(ioport_field &field) - : m_field(field), - m_shift(0), - m_adjdefvalue(field.defvalue() & field.mask()), - m_adjmin(field.minval() & field.mask()), - m_adjmax(field.maxval() & field.mask()), - m_adjoverride(field.defvalue() & field.mask()), - m_sensitivity(field.sensitivity()), - m_reverse(field.analog_reverse()), - m_delta(field.delta()), - m_centerdelta(field.centerdelta()), - m_accum(0), - m_previous(0), - m_previousanalog(0), - m_minimum(osd::INPUT_ABSOLUTE_MIN), - m_maximum(osd::INPUT_ABSOLUTE_MAX), - m_center(0), - m_reverse_val(0), - m_scalepos(0), - m_scaleneg(0), - m_keyscalepos(0), - m_keyscaleneg(0), - m_positionalscale(0), - m_absolute(false), - m_wraps(false), - m_autocenter(false), - m_single_scale(false), - m_interpolate(false), - m_lastdigital(false), - m_use_adjoverride(false) -{ - // compute the shift amount and number of bits - for (ioport_value mask = field.mask(); !(mask & 1); mask >>= 1) - m_shift++; - - // initialize core data - m_adjdefvalue >>= m_shift; - m_adjmin >>= m_shift; - m_adjmax >>= m_shift; - + : m_field(field) + , m_shift(compute_shift(field.mask())) + , m_adjdefvalue((field.defvalue() & field.mask()) >> m_shift) + , m_adjmin((field.minval() & field.mask()) >> m_shift) + , m_adjmax((field.maxval() & field.mask()) >> m_shift) + , m_adjoverride((field.defvalue() & field.mask()) >> m_shift) + , m_sensitivity(field.sensitivity()) + , m_reverse(field.analog_reverse()) + , m_delta(field.delta()) + , m_centerdelta(field.centerdelta()) + , m_accum(0) + , m_previous(0) + , m_previousanalog(0) + , m_minimum(osd::INPUT_ABSOLUTE_MIN) + , m_maximum(osd::INPUT_ABSOLUTE_MAX) + , m_center(0) + , m_reverse_val(0) + , m_scalepos(0) + , m_scaleneg(0) + , m_keyscalepos(0) + , m_keyscaleneg(0) + , m_positionalscale(0) + , m_absolute(false) + , m_wraps(false) + , m_autocenter(false) + , m_single_scale(false) + , m_interpolate(false) + , m_lastdigital(false) + , m_use_adjoverride(false) +{ // set basic parameters based on the configured type switch (field.type()) { @@ -3557,21 +3566,23 @@ analog_field::analog_field(ioport_field &field) fatalerror("Unknown analog port type -- don't know if it is absolute or not\n"); } - // further processing for absolute controls if (m_absolute) { + // further processing for absolute controls + // if the default value is pegged at the min or max, use a single scale value for the whole axis m_single_scale = (m_adjdefvalue == m_adjmin) || (m_adjdefvalue == m_adjmax); // if not "single scale", compute separate scales for each side of the default if (!m_single_scale) { - // unsigned - m_scalepos = compute_scale(m_adjmax - m_adjdefvalue, osd::INPUT_ABSOLUTE_MAX - 0); - m_scaleneg = compute_scale(m_adjdefvalue - m_adjmin, 0 - osd::INPUT_ABSOLUTE_MIN); - - if (m_adjmin > m_adjmax) - m_scaleneg = -m_scaleneg; + // unsigned, potentially passing through zero + m_scalepos = compute_scale( + (m_adjmax - m_adjdefvalue) & (field.mask() >> m_shift), + osd::INPUT_ABSOLUTE_MAX); + m_scaleneg = compute_scale( + (m_adjdefvalue - m_adjmin) & (field.mask() >> m_shift), + -osd::INPUT_ABSOLUTE_MIN); // reverse point is at center m_reverse_val = 0; @@ -3588,11 +3599,11 @@ analog_field::analog_field(ioport_field &field) m_reverse_val = m_maximum; } } - - // relative and positional controls all map directly with a 512x scale factor else { - // The relative code is set up to allow specifing PORT_MINMAX and default values. + // relative and positional controls all map directly with a 512x scale factor + + // The relative code is set up to allow specifying PORT_MINMAX and default values. // The validity checks are purposely set up to not allow you to use anything other // a default of 0 and PORT_MINMAX(0,mask). This is in case the need arises to use // this feature in the future. Keeping the code in does not hurt anything. @@ -3610,8 +3621,10 @@ analog_field::analog_field(ioport_field &field) m_scaleneg = m_scalepos = compute_scale(1, osd::INPUT_RELATIVE_PER_PIXEL); if (m_field.analog_reset()) + { // delta values reverse from center m_reverse_val = 0; + } else { // positional controls reverse from their max range @@ -3621,8 +3634,8 @@ analog_field::analog_field(ioport_field &field) if (m_wraps) { // FIXME: positional needs -1, using osd::INPUT_RELATIVE_PER_PIXEL skips a position (and reads outside the table array) - if(field.type() == IPT_POSITIONAL || field.type() == IPT_POSITIONAL_V) - m_reverse_val --; + if (field.type() == IPT_POSITIONAL || field.type() == IPT_POSITIONAL_V) + m_reverse_val--; else m_reverse_val -= osd::INPUT_RELATIVE_PER_PIXEL; } diff --git a/src/emu/save.cpp b/src/emu/save.cpp index b8acfa24b0a..3590b3c0a6b 100644 --- a/src/emu/save.cpp +++ b/src/emu/save.cpp @@ -221,7 +221,7 @@ save_error save_manager::check_file(running_machine &machine, util::core_file &f if (file.read(header, sizeof(header), actual) || actual != sizeof(header)) { if (errormsg != nullptr) - (*errormsg)("Could not read %s save file header",emulator_info::get_appname()); + (*errormsg)("Could not read %s save file header", emulator_info::get_appname()); return STATERR_READ_ERROR; } @@ -548,7 +548,7 @@ save_error save_manager::validate_header(const u8 *header, const char *gamename, if (memcmp(header, STATE_MAGIC_NUM, 8)) { if (errormsg != nullptr) - (*errormsg)("%sThis is not a %s save file", error_prefix,emulator_info::get_appname()); + (*errormsg)("%sThis is not a %s save file", error_prefix, emulator_info::get_appname()); return STATERR_INVALID_HEADER; } diff --git a/src/emu/uiinput.cpp b/src/emu/uiinput.cpp index d1398591687..02bf1f2aa31 100644 --- a/src/emu/uiinput.cpp +++ b/src/emu/uiinput.cpp @@ -257,7 +257,7 @@ bool ui_input_manager::pressed_repeat(int code, int speed) g_profiler.start(PROFILER_INPUT); /* get the status of this key (assumed to be only in the defaults) */ - assert(code >= IPT_UI_CONFIGURE && code <= IPT_OSD_16); + assert(code > IPT_UI_FIRST && code < IPT_UI_LAST); pressed = (m_seqpressed[code] == SEQ_PRESSED_TRUE); /* if down, handle it specially */ diff --git a/src/emu/validity.cpp b/src/emu/validity.cpp index 8fed2d6def0..f9acc18d47d 100644 --- a/src/emu/validity.cpp +++ b/src/emu/validity.cpp @@ -2457,26 +2457,29 @@ void validity_checker::validate_inputs(device_t &root) if (field.is_analog()) validate_analog_input_field(field); - // look for invalid (0) types which should be mapped to IPT_OTHER - if (field.type() == IPT_INVALID) + // checks based on field type + if ((field.type() > IPT_UI_FIRST) && (field.type() < IPT_UI_LAST)) + { + osd_printf_error("Field has invalid UI control type\n"); + } + else if (field.type() == IPT_INVALID) + { osd_printf_error("Field has an invalid type (0); use IPT_OTHER instead\n"); - - if (field.type() == IPT_SPECIAL) + } + else if (field.type() == IPT_SPECIAL) + { osd_printf_error("Field has an invalid type IPT_SPECIAL\n"); - - // verify dip switches - if (field.type() == IPT_DIPSWITCH) + } + else if (field.type() == IPT_DIPSWITCH) { - // dip switch fields must have a specific name + // DIP switch fields must have a specific name if (field.specific_name() == nullptr) osd_printf_error("DIP switch has no specific name\n"); // verify the settings list validate_dip_settings(field); } - - // verify config settings - if (field.type() == IPT_CONFIG) + else if (field.type() == IPT_CONFIG) { // config fields must have a specific name if (field.specific_name() == nullptr) @@ -2484,7 +2487,7 @@ void validity_checker::validate_inputs(device_t &root) } // verify names - const char *name = field.specific_name(); + char const *const name = field.specific_name(); if (name != nullptr) { // check for empty string diff --git a/src/frontend/mame/infoxml.cpp b/src/frontend/mame/infoxml.cpp index 4b5d3902c98..7e75d07455a 100644 --- a/src/frontend/mame/infoxml.cpp +++ b/src/frontend/mame/infoxml.cpp @@ -13,9 +13,11 @@ #include "mameopts.h" +// devices #include "machine/ram.h" #include "sound/samples.h" +// emu #include "config.h" #include "drivenum.h" #include "romload.h" @@ -23,6 +25,7 @@ #include "softlist_dev.h" #include "speaker.h" +// lib/util #include "corestr.h" #include "xmlfile.h" @@ -1388,11 +1391,11 @@ void output_input(std::ostream &out, const ioport_list &portlist) int maxbuttons; // max index of buttons (using IPT_BUTTONn) [probably to be removed soonish] int ways; // directions for joystick bool analog; // is analog input? - uint8_t helper[3]; // for dual joysticks [possibly to be removed soonish] - int32_t min; // analog minimum value - int32_t max; // analog maximum value - int32_t sensitivity; // default analog sensitivity - int32_t keydelta; // default analog keydelta + uint8_t helper[3]; // for dual joysticks [possibly to be removed soonish] + int32_t min; // analog minimum value + int32_t max; // analog maximum value + int32_t sensitivity; // default analog sensitivity + int32_t keydelta; // default analog keydelta bool reverse; // default analog reverse setting } control_info[CTRL_COUNT * CTRL_PCOUNT]; diff --git a/src/frontend/mame/ui/analogipt.cpp b/src/frontend/mame/ui/analogipt.cpp index 520026ea479..d8bbbae5eb6 100644 --- a/src/frontend/mame/ui/analogipt.cpp +++ b/src/frontend/mame/ui/analogipt.cpp @@ -37,13 +37,19 @@ inline menu_analog::item_data::item_data(ioport_field &f, int t) noexcept inline menu_analog::field_data::field_data(ioport_field &f) noexcept : field(f) - , range(f.maxval() - f.minval()) - , neutral(float(f.analog_reverse() ? (f.maxval() - f.defvalue()) : (f.defvalue() - f.minval())) / range) - , origin((f.analog_wraps() && (f.defvalue() != f.minval()) && (f.defvalue() != f.maxval())) ? 0.0f : neutral) + , range(0.0F) + , neutral(0.0F) + , origin(0.0F) , shift(0U) , show_neutral((f.defvalue() != f.minval()) && (f.defvalue() != f.maxval())) { for (ioport_value m = f.mask(); m && !BIT(m, 0); m >>= 1, ++shift) { } + ioport_value const m(f.mask() >> shift); + range = (f.maxval() - f.minval()) & m; + ioport_value const n((f.analog_reverse() ? (f.maxval() - f.defvalue()) : (f.defvalue() - f.minval())) & m); + neutral = float(n) / range; + if (!f.analog_wraps() || (f.defvalue() == f.minval()) || (f.defvalue() == f.maxval())) + origin = neutral; } @@ -175,7 +181,7 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa ioport_value cur(0U); data.field.get().live().analog->read(cur); - cur = (cur >> data.shift) - data.field.get().minval(); + cur = ((cur >> data.shift) - data.field.get().minval()) & (data.field.get().mask() >> data.shift); float fill(float(cur) / data.range); if (data.field.get().analog_reverse()) fill = 1.0f - fill; diff --git a/src/frontend/mame/ui/submenu.cpp b/src/frontend/mame/ui/submenu.cpp index 82eb23d6a17..5fbb0c47d9c 100644 --- a/src/frontend/mame/ui/submenu.cpp +++ b/src/frontend/mame/ui/submenu.cpp @@ -91,6 +91,7 @@ std::vector<submenu::option> submenu::advanced_options() { option_type::EMU, N_("Off-screen reload"), OPTION_OFFSCREEN_RELOAD }, { option_type::EMU, N_("Joystick deadzone"), OPTION_JOYSTICK_DEADZONE }, { option_type::EMU, N_("Joystick saturation"), OPTION_JOYSTICK_SATURATION }, + { option_type::EMU, N_("Joystick threshold"), OPTION_JOYSTICK_THRESHOLD }, { option_type::EMU, N_("Natural keyboard"), OPTION_NATURAL_KEYBOARD }, { option_type::EMU, N_("Allow contradictory joystick inputs"), OPTION_JOYSTICK_CONTRADICTORY }, { option_type::EMU, N_("Coin impulse"), OPTION_COIN_IMPULSE } }; diff --git a/src/frontend/mame/ui/viewgfx.cpp b/src/frontend/mame/ui/viewgfx.cpp index 0b7b9a47e1d..59d3ffbc53f 100644 --- a/src/frontend/mame/ui/viewgfx.cpp +++ b/src/frontend/mame/ui/viewgfx.cpp @@ -537,6 +537,7 @@ private: { if (!uistate) m_machine.resume(); + m_machine.ui_input().reset(); m_bitmap_dirty = true; return UI_HANDLER_CANCEL; } diff --git a/src/mame/taito/taitoio_yoke.cpp b/src/mame/taito/taitoio_yoke.cpp index 9d7fa7fec24..eac82c0f369 100644 --- a/src/mame/taito/taitoio_yoke.cpp +++ b/src/mame/taito/taitoio_yoke.cpp @@ -66,13 +66,13 @@ void taitoio_yoke_device::device_reset() // TODO: requires LEFT/RIGHT_AD_STICK in framework static INPUT_PORTS_START( yoke_inputs ) PORT_START("STICK_X") - PORT_BIT( 0x0fff, 0x0000, IPT_AD_STICK_X ) PORT_MINMAX(0x00800, 0x07ff) PORT_SENSITIVITY(100) PORT_KEYDELTA(20) PORT_NAME("Yoke X") + PORT_BIT( 0x0fff, 0x0000, IPT_AD_STICK_X ) PORT_MINMAX(0x0800, 0x07ff) PORT_SENSITIVITY(100) PORT_KEYDELTA(20) PORT_NAME("Yoke X") PORT_START("STICK_Y") - PORT_BIT( 0x0fff, 0x0000, IPT_AD_STICK_Y ) PORT_MINMAX(0x00800, 0x07ff) PORT_SENSITIVITY(100) PORT_KEYDELTA(20) PORT_NAME("Yoke Y") + PORT_BIT( 0x0fff, 0x0000, IPT_AD_STICK_Y ) PORT_MINMAX(0x0800, 0x07ff) PORT_SENSITIVITY(100) PORT_KEYDELTA(20) PORT_NAME("Yoke Y") PORT_START("THROTTLE") - PORT_BIT( 0x0fff, 0x0000, IPT_AD_STICK_Y ) PORT_MINMAX(0x0800,0x07ff) PORT_SENSITIVITY(30) PORT_KEYDELTA(40) PORT_NAME("Throttle Lever") + PORT_BIT( 0x0fff, 0x0000, IPT_AD_STICK_Z ) PORT_MINMAX(0x0800,0x07ff) PORT_SENSITIVITY(30) PORT_KEYDELTA(40) PORT_CENTERDELTA(0) PORT_NAME("Throttle Lever") INPUT_PORTS_END ioport_constructor taitoio_yoke_device::device_input_ports() const diff --git a/src/mame/universal/getaway.cpp b/src/mame/universal/getaway.cpp index e552e19a0ae..29a26ef8d72 100644 --- a/src/mame/universal/getaway.cpp +++ b/src/mame/universal/getaway.cpp @@ -62,15 +62,11 @@ public: , m_screen(*this, "screen") , m_inputs(*this, "IN.%u", 0) , m_dsw(*this, "DSW") - , m_wheel(*this, "WHEEL") { } // machine configs void getaway(machine_config &config); - // input functions - ioport_value read_wheel() { return (m_wheel->read() - 0x08) & 0xff; } - protected: virtual void machine_start() override; @@ -81,7 +77,6 @@ private: required_device<screen_device> m_screen; required_ioport_array<3> m_inputs; required_ioport m_dsw; - required_ioport m_wheel; void main_map(address_map &map); void io_map(address_map &map); @@ -336,10 +331,7 @@ static INPUT_PORTS_START( getaway ) PORT_START("IN.2") // steering wheel, signed byte, absolute values larger than 8 ignored - PORT_BIT( 0xff, 0x00, IPT_CUSTOM ) PORT_CUSTOM_MEMBER(getaway_state, read_wheel) - - PORT_START("WHEEL") - PORT_BIT( 0xff, 0x08, IPT_PADDLE ) PORT_MINMAX(0x00, 0x10) PORT_SENSITIVITY(5) PORT_KEYDELTA(15) + PORT_BIT( 0xff, 0x00, IPT_PADDLE ) PORT_MINMAX(0xf8, 0x08) PORT_SENSITIVITY(5) PORT_KEYDELTA(15) PORT_START("DSW") // credit display is shown if both extended plays are on "None" diff --git a/src/mame/venture/looping.cpp b/src/mame/venture/looping.cpp index 17c823bd43f..8522c8a3f6f 100644 --- a/src/mame/venture/looping.cpp +++ b/src/mame/venture/looping.cpp @@ -453,7 +453,7 @@ WRITE_LINE_MEMBER(looping_state::speech_enable_w) WRITE_LINE_MEMBER(looping_state::ballon_enable_w) { - osd_printf_debug("ballon_enable_w = %d\n", state); + logerror("ballon_enable_w = %d\n", state); } diff --git a/src/osd/modules/font/font_dwrite.cpp b/src/osd/modules/font/font_dwrite.cpp index 47a52dbd197..b66a53e4383 100644 --- a/src/osd/modules/font/font_dwrite.cpp +++ b/src/osd/modules/font/font_dwrite.cpp @@ -41,6 +41,11 @@ DEFINE_GUID(GUID_WICPixelFormat8bppAlpha, 0xe6cd0116, 0xeeba, 0x4161, 0xaa, 0x85 #include <wrl/client.h> #undef interface + +namespace osd { + +namespace { + using namespace Microsoft::WRL; //------------------------------------------------- @@ -363,7 +368,7 @@ public: bool italic = (strreplace(name, "[I]", "") + strreplace(name, "[i]", "") > 0); // convert the face name - std::wstring familyName = osd::text::to_wstring(name.c_str()); + std::wstring familyName = text::to_wstring(name); // find the font HR_RET0(find_font( @@ -625,7 +630,7 @@ private: HR_RETHR(fonts->FindFamilyName(familyName.c_str(), &family_index, &exists)); if (!exists) { - osd_printf_error("Font with family name %s does not exist.\n", osd::text::from_wstring(familyName)); + osd_printf_error("Font with family name %s does not exist.\n", text::from_wstring(familyName)); return E_FAIL; } @@ -744,7 +749,7 @@ public: std::unique_ptr<WCHAR[]> name = nullptr; HR_RET0(get_localized_familyname(names, name)); - std::string utf8_name = osd::text::from_wstring(name.get()); + std::string utf8_name = text::from_wstring(name.get()); name.reset(); // Review: should the config name, be unlocalized? @@ -808,8 +813,15 @@ private: } }; +} // anonymous namespace + +} // namespace osd + #else -MODULE_NOT_SUPPORTED(font_dwrite, OSD_FONT_PROVIDER, "dwrite") + +namespace osd { namespace { MODULE_NOT_SUPPORTED(font_dwrite, OSD_FONT_PROVIDER, "dwrite") } } + #endif -MODULE_DEFINITION(FONT_DWRITE, font_dwrite) + +MODULE_DEFINITION(FONT_DWRITE, osd::font_dwrite) diff --git a/src/osd/modules/input/input_dinput.cpp b/src/osd/modules/input/input_dinput.cpp index 56f46532eb1..3461f9aad24 100644 --- a/src/osd/modules/input/input_dinput.cpp +++ b/src/osd/modules/input/input_dinput.cpp @@ -413,6 +413,7 @@ dinput_joystick_device::dinput_joystick_device(running_machine &machine, std::st void dinput_joystick_device::reset() { memset(&joystick.state, 0, sizeof(joystick.state)); + std::fill(std::begin(joystick.state.rgdwPOV), std::end(joystick.state.rgdwPOV), 0xffff); } void dinput_joystick_device::poll() @@ -531,11 +532,10 @@ int dinput_joystick_device::configure() std::string name = dinput_module::device_item_name(this, offset, default_button_name(butnum).c_str(), nullptr); input_item_id itemid; - if (butnum < INPUT_MAX_BUTTONS) - itemid = static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum); + itemid = input_item_id(ITEM_ID_BUTTON1 + butnum); else if (butnum < INPUT_MAX_BUTTONS + INPUT_MAX_ADD_SWITCH) - itemid = static_cast<input_item_id>(ITEM_ID_ADD_SWITCH1 - INPUT_MAX_BUTTONS + butnum); + itemid = input_item_id(ITEM_ID_ADD_SWITCH1 - INPUT_MAX_BUTTONS + butnum); else itemid = ITEM_ID_OTHER_SWITCH; diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp index 9aab7f1dec0..3cde2b3d2aa 100644 --- a/src/osd/modules/lib/osdobj_common.cpp +++ b/src/osd/modules/lib/osdobj_common.cpp @@ -166,6 +166,9 @@ const options_entry osd_options::s_option_entries[] = { OSDOPTION_AUDIO_EFFECT "9", OSDOPTVAL_NONE, core_options::option_type::STRING, "AudioUnit effect 9" }, #endif + { nullptr, nullptr, core_options::option_type::HEADER, "OSD MIDI OPTIONS" }, + { OSDOPTION_MIDI_PROVIDER, OSDOPTVAL_AUTO, core_options::option_type::STRING, "MIDI I/O method: " }, + { nullptr, nullptr, core_options::option_type::HEADER, "BGFX POST-PROCESSING OPTIONS" }, { OSDOPTION_BGFX_PATH, "bgfx", core_options::option_type::PATH, "path to BGFX-related files" }, { OSDOPTION_BGFX_BACKEND, "auto", core_options::option_type::STRING, "BGFX backend to use (d3d9, d3d11, d3d12, metal, opengl, gles, vulkan)" }, @@ -221,7 +224,7 @@ osd_common_t::~osd_common_t() osd_output::pop(this); } -#define REGISTER_MODULE(_O, _X ) { extern const module_type _X; _O . register_module( _X ); } +#define REGISTER_MODULE(O, X) { extern const module_type X; O.register_module(X); } void osd_common_t::register_options() { @@ -301,72 +304,16 @@ void osd_common_t::register_options() // after initialization we know which modules are supported - const char *names[20]; - int num; - std::vector<const char *> dnames; - - m_mod_man.get_module_names(OSD_MONITOR_PROVIDER, 20, num, names); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_MONITOR_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_FONT_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_FONT_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_KEYBOARDINPUT_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_KEYBOARDINPUT_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_MOUSEINPUT_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_MOUSEINPUT_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_LIGHTGUNINPUT_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_LIGHTGUNINPUT_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_JOYSTICKINPUT_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_JOYSTICKINPUT_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_SOUND_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_SOUND_PROVIDER, dnames); - -#if 0 - // Register midi options and update options - m_mod_man.get_module_names(OSD_MIDI_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_MIDI_PROVIDER, dnames); -#endif - - // Register debugger options and update options - m_mod_man.get_module_names(OSD_DEBUG_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_DEBUG_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_OUTPUT_PROVIDER, 20, num, names); - dnames.clear(); - for (int i = 0; i < num; i++) - dnames.push_back(names[i]); - update_option(OSD_OUTPUT_PROVIDER, dnames); + update_option(OSD_MONITOR_PROVIDER, m_mod_man.get_module_names(OSD_MONITOR_PROVIDER)); + update_option(OSD_FONT_PROVIDER, m_mod_man.get_module_names(OSD_FONT_PROVIDER)); + update_option(OSD_KEYBOARDINPUT_PROVIDER, m_mod_man.get_module_names(OSD_KEYBOARDINPUT_PROVIDER)); + update_option(OSD_MOUSEINPUT_PROVIDER, m_mod_man.get_module_names(OSD_MOUSEINPUT_PROVIDER)); + update_option(OSD_LIGHTGUNINPUT_PROVIDER, m_mod_man.get_module_names(OSD_LIGHTGUNINPUT_PROVIDER)); + update_option(OSD_JOYSTICKINPUT_PROVIDER, m_mod_man.get_module_names(OSD_JOYSTICKINPUT_PROVIDER)); + update_option(OSD_SOUND_PROVIDER, m_mod_man.get_module_names(OSD_SOUND_PROVIDER)); + update_option(OSD_MIDI_PROVIDER, m_mod_man.get_module_names(OSD_MIDI_PROVIDER)); + update_option(OSD_DEBUG_PROVIDER, m_mod_man.get_module_names(OSD_DEBUG_PROVIDER)); + update_option(OSD_OUTPUT_PROVIDER, m_mod_man.get_module_names(OSD_OUTPUT_PROVIDER)); // Register video options and update options video_options_add("none", nullptr); @@ -374,21 +321,20 @@ void osd_common_t::register_options() update_option(OSDOPTION_VIDEO, m_video_names); } -void osd_common_t::update_option(const std::string &key, std::vector<const char *> &values) +void osd_common_t::update_option(const std::string &key, std::vector<std::string_view> const &values) { std::string current_value(m_options.description(key.c_str())); std::string new_option_value(""); for (unsigned int index = 0; index < values.size(); index++) { - std::string t(values[index]); if (new_option_value.length() > 0) { - if( index != (values.size()-1)) + if (index != (values.size() - 1)) new_option_value.append(", "); else new_option_value.append(" or "); } - new_option_value.append(t); + new_option_value.append(values[index]); } m_option_descs[key] = current_value + new_option_value; diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h index bf680195fca..00e7ddc0483 100644 --- a/src/osd/modules/lib/osdobj_common.h +++ b/src/osd/modules/lib/osdobj_common.h @@ -24,8 +24,9 @@ #include <iosfwd> #include <list> -#include <string> #include <memory> +#include <string> +#include <string_view> #include <unordered_map> #include <vector> @@ -86,8 +87,7 @@ #define OSDOPTION_AUDIO_OUTPUT "audio_output" #define OSDOPTION_AUDIO_EFFECT "audio_effect" -#define OSDOPTVAL_AUTO "auto" -#define OSDOPTVAL_NONE "none" +#define OSDOPTION_MIDI_PROVIDER "midiprovider" #define OSDOPTION_BGFX_PATH "bgfx_path" #define OSDOPTION_BGFX_BACKEND "bgfx_backend" @@ -97,6 +97,9 @@ #define OSDOPTION_BGFX_LUT "bgfx_lut" #define OSDOPTION_BGFX_AVI_NAME "bgfx_avi_name" +#define OSDOPTVAL_AUTO "auto" +#define OSDOPTVAL_NONE "none" + //============================================================ // TYPE DEFINITIONS //============================================================ @@ -286,7 +289,7 @@ private: osd_module_manager m_mod_man; font_module *m_font_module; - void update_option(const std::string &key, std::vector<const char *> &values); + void update_option(const std::string &key, std::vector<std::string_view> const &values); // FIXME: should be elsewhere osd_module *select_module_options(const core_options &opts, const std::string &opt_name) { @@ -321,7 +324,7 @@ protected: std::vector<ui::menu_item> m_sliders; private: - std::vector<const char *> m_video_names; + std::vector<std::string_view> m_video_names; std::unordered_map<std::string, std::string> m_option_descs; }; diff --git a/src/osd/modules/midi/none.cpp b/src/osd/modules/midi/none.cpp index 21837d1be3c..97333cb54de 100644 --- a/src/osd/modules/midi/none.cpp +++ b/src/osd/modules/midi/none.cpp @@ -6,87 +6,56 @@ Empty shim for systems not supporting midi / portmidi -*******************************************************************c********/ +***************************************************************************/ #include "osdcore.h" #include "modules/osdmodule.h" #include "midi_module.h" -class none_module : public osd_module, public midi_module -{ -public: +#include <memory> - none_module() : osd_module(OSD_MIDI_PROVIDER, "pm"), midi_module() - { - } - virtual ~none_module() { } - virtual int init(const osd_options &options) override; - virtual void exit() override; - - virtual std::unique_ptr<osd_midi_device> create_midi_device() override; - virtual void list_midi_devices() override; -}; +namespace osd { +namespace { class osd_midi_device_none : public osd_midi_device { public: - virtual ~osd_midi_device_none() { } - virtual bool open_input(const char *devname) override; - virtual bool open_output(const char *devname) override; - virtual void close() override; - virtual bool poll() override; - virtual int read(uint8_t *pOut) override; - virtual void write(uint8_t data) override; + virtual bool open_input(const char *devname) override { return false; } + virtual bool open_output(const char *devname) override { return false; } + virtual void close() override { } + virtual bool poll() override { return false; } + virtual int read(uint8_t *pOut) override { return 0; } + virtual void write(uint8_t data) override { } }; -std::unique_ptr<osd_midi_device> none_module::create_midi_device() -{ - return std::make_unique<osd_midi_device_none>(); -} - -int none_module::init(const osd_options &options) +class none_module : public osd_module, public midi_module { - return 0; -} +public: + none_module() : osd_module(OSD_MIDI_PROVIDER, "none"), midi_module() { } -void none_module::exit() -{ -} + virtual int init(const osd_options &options) override { return 0; } + virtual void exit() override { } -void none_module::list_midi_devices() -{ - osd_printf_warning("\nMIDI is not supported in this build\n"); -} - -bool osd_midi_device_none::open_input(const char *devname) -{ - return false; -} + virtual std::unique_ptr<osd_midi_device> create_midi_device() override; + virtual void list_midi_devices() override; +}; -bool osd_midi_device_none::open_output(const char *devname) +std::unique_ptr<osd_midi_device> none_module::create_midi_device() { - return false; + return std::make_unique<osd_midi_device_none>(); } -void osd_midi_device_none::close() +void none_module::list_midi_devices() { + osd_printf_warning("\nMIDI is not supported in this configuration\n"); } -bool osd_midi_device_none::poll() -{ - return false; -} +} // anonymous namespace -int osd_midi_device_none::read(uint8_t *pOut) -{ - return 0; -} +} // namespace osd -void osd_midi_device_none::write(uint8_t data) -{ -} -MODULE_DEFINITION(MIDI_NONE, none_module) +MODULE_DEFINITION(MIDI_NONE, osd::none_module) diff --git a/src/osd/modules/midi/portmidi.cpp b/src/osd/modules/midi/portmidi.cpp index 73d965d854a..4661779c0bd 100644 --- a/src/osd/modules/midi/portmidi.cpp +++ b/src/osd/modules/midi/portmidi.cpp @@ -8,14 +8,22 @@ *******************************************************************c********/ +#include "midi_module.h" + +#include "modules/osdmodule.h" + #ifndef NO_USE_MIDI #include <portmidi.h> -#include "modules/osdmodule.h" -#include "midi_module.h" + #include <cstdio> #include <cstring> + +namespace osd { + +namespace { + class pm_module : public osd_module, public midi_module { public: @@ -26,7 +34,7 @@ public: virtual ~pm_module() { } virtual int init(const osd_options &options)override; - virtual void exit()override; + virtual void exit() override; virtual std::unique_ptr<osd_midi_device> create_midi_device() override; virtual void list_midi_devices() override; @@ -464,12 +472,16 @@ void osd_midi_device_pm::write(uint8_t data) } } + +} // anonymous namespace + +} // namespace osd + #else - #include "modules/osdmodule.h" - #include "midi_module.h" - MODULE_NOT_SUPPORTED(pm_module, OSD_MIDI_PROVIDER, "pm") +namespace osd { namespace { MODULE_NOT_SUPPORTED(pm_module, OSD_MIDI_PROVIDER, "pm") } } + #endif -MODULE_DEFINITION(MIDI_PM, pm_module) +MODULE_DEFINITION(MIDI_PM, osd::pm_module) diff --git a/src/osd/modules/osdmodule.cpp b/src/osd/modules/osdmodule.cpp index 4f2cf079e3b..9c3f0a9a693 100644 --- a/src/osd/modules/osdmodule.cpp +++ b/src/osd/modules/osdmodule.cpp @@ -1,11 +1,12 @@ // license:BSD-3-Clause // copyright-holders:Couriersud /* - * osdmodule.c + * osdmodule.cpp * */ #include "modules/osdmodule.h" + #include "osdcore.h" #include <algorithm> @@ -83,12 +84,13 @@ int osd_module_manager::get_module_index(const char *type, const char *name) con return -1; } -void osd_module_manager::get_module_names(const char *type, const int max, int &num, const char *names[]) const +std::vector<std::string_view> osd_module_manager::get_module_names(const char *type) const { - num = 0; - for (int i = 0; (m_modules.size() > i) && (max > num); i++) + std::vector<std::string_view> result; + for (auto &m : m_modules) { - if (m_modules[i]->type() == type) - names[num++] = m_modules[i]->name().c_str(); + if (m->type() == type) + result.emplace_back(m->name()); } + return result; } diff --git a/src/osd/modules/osdmodule.h b/src/osd/modules/osdmodule.h index 1c662417601..3e944b28a9f 100644 --- a/src/osd/modules/osdmodule.h +++ b/src/osd/modules/osdmodule.h @@ -15,6 +15,7 @@ #include <functional> #include <memory> #include <string> +#include <string_view> #include <vector> @@ -24,7 +25,10 @@ class osd_options; -// ======================> osd_module + +//============================================================ +// TYPE DEFINITIONS +//============================================================ class osd_module { @@ -48,9 +52,11 @@ private: std::string const m_type; }; + // a module_type is simply a pointer to its alloc function typedef std::unique_ptr<osd_module> (*module_type)(); + // this template function creates a stub which constructs a module template <class ModuleClass> std::unique_ptr<osd_module> module_creator() @@ -58,6 +64,7 @@ std::unique_ptr<osd_module> module_creator() return std::unique_ptr<osd_module>(new ModuleClass); } + class osd_module_manager { public: @@ -77,7 +84,7 @@ public: osd_module *select_module(const char *type, const char *name = ""); - void get_module_names(const char *type, const int max, int &num, const char *names[]) const; + std::vector<std::string_view> get_module_names(const char *type) const; void init(const osd_options &options); @@ -90,18 +97,20 @@ private: std::vector<std::reference_wrapper<osd_module> > m_selected; }; + #define MODULE_DEFINITION(mod_id, mod_class) \ - extern const module_type mod_id ; \ - const module_type mod_id = &module_creator< mod_class >; + extern const module_type mod_id ; \ + const module_type mod_id = &module_creator<mod_class>; #define MODULE_NOT_SUPPORTED(mod_class, mod_type, mod_name) \ - class mod_class : public osd_module { \ - public: \ - mod_class () : osd_module(mod_type, mod_name) { } \ - virtual ~mod_class() { } \ - virtual int init(const osd_options &options) override { return -1; } \ - virtual bool probe() override { return false; } \ - }; + class mod_class : public osd_module \ + { \ + public: \ + mod_class () : osd_module(mod_type, mod_name) { } \ + virtual ~mod_class() { } \ + virtual int init(const osd_options &options) override { return -1; } \ + virtual bool probe() override { return false; } \ + }; #endif /* MAME_OSD_MODULES_OSDMODULE_H */ diff --git a/src/osd/modules/output/none.cpp b/src/osd/modules/output/none.cpp index a4a613ef29f..2e103cded8e 100644 --- a/src/osd/modules/output/none.cpp +++ b/src/osd/modules/output/none.cpp @@ -9,13 +9,17 @@ *******************************************************************c********/ #include "output_module.h" + #include "modules/osdmodule.h" +namespace osd { + +namespace { + class output_none : public osd_module, public output_module { public: - output_none() - : osd_module(OSD_OUTPUT_PROVIDER, "none"), output_module() + output_none() : osd_module(OSD_OUTPUT_PROVIDER, "none") { } virtual ~output_none() { } @@ -29,4 +33,8 @@ public: }; -MODULE_DEFINITION(OUTPUT_NONE, output_none) +} // anonymous namespace + +} // namespace osd + +MODULE_DEFINITION(OUTPUT_NONE, osd::output_none) diff --git a/src/osd/modules/sound/coreaudio_sound.cpp b/src/osd/modules/sound/coreaudio_sound.cpp index dcc74ec5fe9..675b01c8451 100644 --- a/src/osd/modules/sound/coreaudio_sound.cpp +++ b/src/osd/modules/sound/coreaudio_sound.cpp @@ -24,16 +24,9 @@ #include <cstring> -#ifdef MAC_OS_X_VERSION_MAX_ALLOWED - -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 - -typedef ComponentDescription AudioComponentDescription; - -#endif // MAC_OS_X_VERSION_MAX_ALLOWED < 1060 - -#endif // MAC_OS_X_VERSION_MAX_ALLOWED +namespace osd { +namespace { class sound_coreaudio : public osd_module, public sound_module { @@ -1013,8 +1006,14 @@ OSStatus sound_coreaudio::render_callback( return ((sound_coreaudio *)refcon)->render(action_flags, timestamp, bus_number, number_frames, data); } +} // anonymous namespace + +} // namespace osd + #else /* SDLMAME_MACOSX */ - MODULE_NOT_SUPPORTED(sound_coreaudio, OSD_SOUND_PROVIDER, "coreaudio") + +namespace osd { namespace { MODULE_NOT_SUPPORTED(sound_coreaudio, OSD_SOUND_PROVIDER, "coreaudio") } } + #endif -MODULE_DEFINITION(SOUND_COREAUDIO, sound_coreaudio) +MODULE_DEFINITION(SOUND_COREAUDIO, osd::sound_coreaudio) diff --git a/src/osd/modules/sound/js_sound.cpp b/src/osd/modules/sound/js_sound.cpp index afcf6ec8f2b..f863973d1de 100644 --- a/src/osd/modules/sound/js_sound.cpp +++ b/src/osd/modules/sound/js_sound.cpp @@ -47,7 +47,7 @@ public: }; -#else /* SDLMAME_UNIX */ +#else /* SDLMAME_EMSCRIPTEN */ MODULE_NOT_SUPPORTED(sound_js, OSD_SOUND_PROVIDER, "js") #endif diff --git a/src/osd/modules/sound/none.cpp b/src/osd/modules/sound/none.cpp index 685cdc884c2..8d18ea635b1 100644 --- a/src/osd/modules/sound/none.cpp +++ b/src/osd/modules/sound/none.cpp @@ -2,20 +2,25 @@ // copyright-holders:Miodrag Milanovic /*************************************************************************** - none.c + none.cpp Dummy sound interface. *******************************************************************c********/ #include "sound_module.h" + #include "modules/osdmodule.h" + +namespace osd { + +namespace { + class sound_none : public osd_module, public sound_module { public: - sound_none() - : osd_module(OSD_SOUND_PROVIDER, "none"), sound_module() + sound_none() : osd_module(OSD_SOUND_PROVIDER, "none") { } virtual ~sound_none() { } @@ -27,7 +32,10 @@ public: virtual void update_audio_stream(bool is_throttled, const int16_t *buffer, int samples_this_frame) override { } virtual void set_mastervolume(int attenuation) override { } - }; -MODULE_DEFINITION(SOUND_NONE, sound_none) +} // anonymous namespace + +} // namespace osd + +MODULE_DEFINITION(SOUND_NONE, osd::sound_none) diff --git a/src/osd/modules/sound/pa_sound.cpp b/src/osd/modules/sound/pa_sound.cpp index 9472f6812cb..fec69835851 100644 --- a/src/osd/modules/sound/pa_sound.cpp +++ b/src/osd/modules/sound/pa_sound.cpp @@ -9,35 +9,40 @@ *******************************************************************c********/ #include "sound_module.h" + #include "modules/osdmodule.h" #ifndef NO_USE_PORTAUDIO -#include <portaudio.h> #include "modules/lib/osdobj_common.h" +#include "osdcore.h" -#include <iostream> -#include <fstream> -#include <sstream> +#include <portaudio.h> + +#include <algorithm> #include <atomic> -#include <cmath> #include <climits> -#include <algorithm> +#include <cmath> +#include <fstream> +#include <iostream> +#include <sstream> #ifdef _WIN32 #include "pa_win_wasapi.h" #endif + +namespace osd { + +namespace { + #define LOG_FILE "pa.log" #define LOG_BUFCNT 0 -using osd::s16; - class sound_pa : public osd_module, public sound_module { public: - sound_pa() - : osd_module(OSD_SOUND_PROVIDER, "portaudio"), sound_module() + sound_pa() : osd_module(OSD_SOUND_PROVIDER, "portaudio") { } virtual ~sound_pa() { } @@ -458,8 +463,14 @@ void sound_pa::exit() osd_printf_verbose("Sound: overflows=%d underflows=%d\n", m_overflows, m_underflows); } +} // anonymous namespace + +} // namespace osd + #else - MODULE_NOT_SUPPORTED(sound_pa, OSD_SOUND_PROVIDER, "portaudio") + +namespace osd { namespace { MODULE_NOT_SUPPORTED(sound_pa, OSD_SOUND_PROVIDER, "portaudio") } } + #endif -MODULE_DEFINITION(SOUND_PORTAUDIO, sound_pa) +MODULE_DEFINITION(SOUND_PORTAUDIO, osd::sound_pa) diff --git a/src/osd/modules/sound/sdl_sound.cpp b/src/osd/modules/sound/sdl_sound.cpp index 9b65a6c176b..d17e3b7d296 100644 --- a/src/osd/modules/sound/sdl_sound.cpp +++ b/src/osd/modules/sound/sdl_sound.cpp @@ -9,6 +9,7 @@ //============================================================ #include "sound_module.h" + #include "modules/osdmodule.h" #if (defined(OSD_SDL) || defined(USE_SDL_SOUND)) @@ -26,6 +27,11 @@ #include <fstream> #include <memory> + +namespace osd { + +namespace { + //============================================================ // DEBUGGING //============================================================ @@ -41,13 +47,13 @@ class sound_sdl : public osd_module, public sound_module public: // number of samples per SDL callback - static const int SDL_XFER_SAMPLES = 512; + static inline constexpr int SDL_XFER_SAMPLES = 512; sound_sdl() : osd_module(OSD_SOUND_PROVIDER, "sdl"), sound_module(), stream_in_initialized(0), attenuation(0), buf_locked(0), stream_buffer(nullptr), stream_buffer_size(0), buffer_underflows(0), buffer_overflows(0) -{ + { sdl_xfer_samples = SDL_XFER_SAMPLES; } virtual ~sound_sdl() { } @@ -456,10 +462,15 @@ void sound_sdl::sdl_destroy_buffers() stream_buffer.reset(); } +} // anonymous namespace + +} // namespace osd + + +#else // (defined(OSD_SDL) || defined(USE_SDL_SOUND)) +namespace osd { namespace { MODULE_NOT_SUPPORTED(sound_sdl, OSD_SOUND_PROVIDER, "sdl") } } -#else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(sound_sdl, OSD_SOUND_PROVIDER, "sdl") #endif -MODULE_DEFINITION(SOUND_SDL, sound_sdl) +MODULE_DEFINITION(SOUND_SDL, osd::sound_sdl) diff --git a/src/osd/modules/sound/sound_module.h b/src/osd/modules/sound/sound_module.h index b72f50f7c8c..d741c732622 100644 --- a/src/osd/modules/sound/sound_module.h +++ b/src/osd/modules/sound/sound_module.h @@ -4,9 +4,10 @@ * sound_module.h * */ +#ifndef MAME_OSD_SOUND_SOUND_MODULE_H +#define MAME_OSD_SOUND_SOUND_MODULE_H -#ifndef SOUND_MODULE_H_ -#define SOUND_MODULE_H_ +#pragma once #include <cstdint> @@ -21,15 +22,16 @@ class sound_module public: sound_module() : m_sample_rate(0), m_audio_latency(1) { } - virtual ~sound_module() { } + virtual ~sound_module() = default; virtual void update_audio_stream(bool is_throttled, const int16_t *buffer, int samples_this_frame) = 0; virtual void set_mastervolume(int attenuation) = 0; int sample_rate() const { return m_sample_rate; } + // FIXME: these should be set by the implementation on initialisation, not by the OSD object int m_sample_rate; int m_audio_latency; }; -#endif /* FONT_MODULE_H_ */ +#endif // MAME_OSD_SOUND_SOUND_MODULE_H |