diff options
Diffstat (limited to 'src/emu/ioport.h')
-rw-r--r-- | src/emu/ioport.h | 475 |
1 files changed, 20 insertions, 455 deletions
diff --git a/src/emu/ioport.h b/src/emu/ioport.h index c767d44c250..bbff70db21d 100644 --- a/src/emu/ioport.h +++ b/src/emu/ioport.h @@ -17,12 +17,15 @@ #ifndef MAME_EMU_IOPORT_H #define MAME_EMU_IOPORT_H +#include "inpttype.h" + #include "ioprocs.h" #include <array> #include <cstdint> #include <cstring> #include <ctime> +#include <initializer_list> #include <list> #include <memory> #include <vector> @@ -32,9 +35,6 @@ // CONSTANTS //************************************************************************** -// input ports support up to 32 bits each -typedef u32 ioport_value; - // active high/low values for input ports constexpr ioport_value IP_ACTIVE_HIGH = 0x00000000; constexpr ioport_value IP_ACTIVE_LOW = 0xffffffff; @@ -51,18 +51,6 @@ constexpr char32_t UCHAR_SHIFT_END = UCHAR_SHIFT_2; constexpr char32_t UCHAR_MAMEKEY_BEGIN = UCHAR_PRIVATE + 2; -// sequence types for input_port_seq() call -enum input_seq_type -{ - SEQ_TYPE_INVALID = -1, - SEQ_TYPE_STANDARD = 0, - SEQ_TYPE_INCREMENT, - SEQ_TYPE_DECREMENT, - SEQ_TYPE_TOTAL -}; -DECLARE_ENUM_INCDEC_OPERATORS(input_seq_type) - - // crosshair types enum crosshair_axis_t { @@ -92,323 +80,6 @@ enum ioport_group }; -// various input port types -enum ioport_type -{ - // pseudo-port types - IPT_INVALID = 0, - IPT_UNUSED, - IPT_END, - IPT_UNKNOWN, - IPT_PORT, - IPT_DIPSWITCH, - IPT_CONFIG, - - // start buttons - IPT_START1, - IPT_START2, - IPT_START3, - IPT_START4, - IPT_START5, - IPT_START6, - IPT_START7, - IPT_START8, - IPT_START9, - IPT_START10, - - // coin slots - IPT_COIN1, - IPT_COIN2, - IPT_COIN3, - IPT_COIN4, - IPT_COIN5, - IPT_COIN6, - IPT_COIN7, - IPT_COIN8, - IPT_COIN9, - IPT_COIN10, - IPT_COIN11, - IPT_COIN12, - IPT_BILL1, - - // service coin - IPT_SERVICE1, - IPT_SERVICE2, - IPT_SERVICE3, - IPT_SERVICE4, - - // tilt inputs - IPT_TILT1, - IPT_TILT2, - IPT_TILT3, - IPT_TILT4, - - // misc other digital inputs - IPT_POWER_ON, - IPT_POWER_OFF, - IPT_SERVICE, - IPT_TILT, - IPT_INTERLOCK, - IPT_MEMORY_RESET, - IPT_VOLUME_UP, - IPT_VOLUME_DOWN, - IPT_START, // use the numbered start button(s) for coin-ops - IPT_SELECT, - IPT_KEYPAD, - IPT_KEYBOARD, - - // digital joystick inputs - IPT_DIGITAL_JOYSTICK_FIRST, - - // use IPT_JOYSTICK for panels where the player has one single joystick - IPT_JOYSTICK_UP, - IPT_JOYSTICK_DOWN, - IPT_JOYSTICK_LEFT, - IPT_JOYSTICK_RIGHT, - - // use IPT_JOYSTICKLEFT and IPT_JOYSTICKRIGHT for dual joystick panels - IPT_JOYSTICKRIGHT_UP, - IPT_JOYSTICKRIGHT_DOWN, - IPT_JOYSTICKRIGHT_LEFT, - IPT_JOYSTICKRIGHT_RIGHT, - IPT_JOYSTICKLEFT_UP, - IPT_JOYSTICKLEFT_DOWN, - IPT_JOYSTICKLEFT_LEFT, - IPT_JOYSTICKLEFT_RIGHT, - - IPT_DIGITAL_JOYSTICK_LAST, - - // action buttons - IPT_BUTTON1, - IPT_BUTTON2, - IPT_BUTTON3, - IPT_BUTTON4, - IPT_BUTTON5, - IPT_BUTTON6, - IPT_BUTTON7, - IPT_BUTTON8, - IPT_BUTTON9, - IPT_BUTTON10, - IPT_BUTTON11, - IPT_BUTTON12, - IPT_BUTTON13, - IPT_BUTTON14, - IPT_BUTTON15, - IPT_BUTTON16, - - // mahjong inputs - IPT_MAHJONG_FIRST, - - IPT_MAHJONG_A, - IPT_MAHJONG_B, - IPT_MAHJONG_C, - IPT_MAHJONG_D, - IPT_MAHJONG_E, - IPT_MAHJONG_F, - IPT_MAHJONG_G, - IPT_MAHJONG_H, - IPT_MAHJONG_I, - IPT_MAHJONG_J, - IPT_MAHJONG_K, - IPT_MAHJONG_L, - IPT_MAHJONG_M, - IPT_MAHJONG_N, - IPT_MAHJONG_O, - IPT_MAHJONG_P, - IPT_MAHJONG_Q, - IPT_MAHJONG_KAN, - IPT_MAHJONG_PON, - IPT_MAHJONG_CHI, - IPT_MAHJONG_REACH, - IPT_MAHJONG_RON, - IPT_MAHJONG_FLIP_FLOP, - IPT_MAHJONG_BET, - IPT_MAHJONG_SCORE, - IPT_MAHJONG_DOUBLE_UP, - IPT_MAHJONG_BIG, - IPT_MAHJONG_SMALL, - IPT_MAHJONG_LAST_CHANCE, - - IPT_MAHJONG_LAST, - - // hanafuda inputs - IPT_HANAFUDA_FIRST, - - IPT_HANAFUDA_A, - IPT_HANAFUDA_B, - IPT_HANAFUDA_C, - IPT_HANAFUDA_D, - IPT_HANAFUDA_E, - IPT_HANAFUDA_F, - IPT_HANAFUDA_G, - IPT_HANAFUDA_H, - IPT_HANAFUDA_YES, - IPT_HANAFUDA_NO, - - IPT_HANAFUDA_LAST, - - // gambling inputs - IPT_GAMBLING_FIRST, - - IPT_GAMBLE_KEYIN, // attendant - IPT_GAMBLE_KEYOUT, // attendant - IPT_GAMBLE_SERVICE, // attendant - IPT_GAMBLE_BOOK, // attendant - IPT_GAMBLE_DOOR, // attendant - // IPT_GAMBLE_DOOR2, // many gambling games have several doors. - // IPT_GAMBLE_DOOR3, - // IPT_GAMBLE_DOOR4, - // IPT_GAMBLE_DOOR5, - - IPT_GAMBLE_PAYOUT, // player - IPT_GAMBLE_BET, // player - IPT_GAMBLE_DEAL, // player - IPT_GAMBLE_STAND, // player - IPT_GAMBLE_TAKE, // player - IPT_GAMBLE_D_UP, // player - IPT_GAMBLE_HALF, // player - IPT_GAMBLE_HIGH, // player - IPT_GAMBLE_LOW, // player - - // poker-specific inputs - IPT_POKER_HOLD1, - IPT_POKER_HOLD2, - IPT_POKER_HOLD3, - IPT_POKER_HOLD4, - IPT_POKER_HOLD5, - IPT_POKER_CANCEL, - - // slot-specific inputs - IPT_SLOT_STOP1, - IPT_SLOT_STOP2, - IPT_SLOT_STOP3, - IPT_SLOT_STOP4, - IPT_SLOT_STOP_ALL, - - IPT_GAMBLING_LAST, - - // analog inputs - IPT_ANALOG_FIRST, - - IPT_ANALOG_ABSOLUTE_FIRST, - - IPT_AD_STICK_X, // absolute // autocenter - IPT_AD_STICK_Y, // absolute // autocenter - IPT_AD_STICK_Z, // absolute // autocenter - IPT_PADDLE, // absolute // autocenter - IPT_PADDLE_V, // absolute // autocenter - IPT_PEDAL, // absolute // autocenter - IPT_PEDAL2, // absolute // autocenter - IPT_PEDAL3, // absolute // autocenter - IPT_LIGHTGUN_X, // absolute - IPT_LIGHTGUN_Y, // absolute - IPT_POSITIONAL, // absolute // autocenter if not wraps - IPT_POSITIONAL_V, // absolute // autocenter if not wraps - - IPT_ANALOG_ABSOLUTE_LAST, - - IPT_DIAL, // relative - IPT_DIAL_V, // relative - IPT_TRACKBALL_X, // relative - IPT_TRACKBALL_Y, // relative - IPT_MOUSE_X, // relative - IPT_MOUSE_Y, // relative - - IPT_ANALOG_LAST, - - // analog adjuster support - IPT_ADJUSTER, - - // the following are special codes for user interface handling - not to be used by drivers! - IPT_UI_FIRST, - - IPT_UI_CONFIGURE, - IPT_UI_ON_SCREEN_DISPLAY, - IPT_UI_DEBUG_BREAK, - IPT_UI_PAUSE, - IPT_UI_PAUSE_SINGLE, - IPT_UI_REWIND_SINGLE, - IPT_UI_RESET_MACHINE, - IPT_UI_SOFT_RESET, - IPT_UI_SHOW_GFX, - IPT_UI_FRAMESKIP_DEC, - IPT_UI_FRAMESKIP_INC, - IPT_UI_THROTTLE, - IPT_UI_FAST_FORWARD, - IPT_UI_SHOW_FPS, - IPT_UI_SNAPSHOT, - IPT_UI_RECORD_MNG, - IPT_UI_RECORD_AVI, - IPT_UI_TOGGLE_CHEAT, - IPT_UI_UP, - IPT_UI_DOWN, - IPT_UI_LEFT, - IPT_UI_RIGHT, - IPT_UI_HOME, - IPT_UI_END, - IPT_UI_PAGE_UP, - IPT_UI_PAGE_DOWN, - IPT_UI_FOCUS_NEXT, - IPT_UI_FOCUS_PREV, - IPT_UI_SELECT, - IPT_UI_CANCEL, - IPT_UI_DISPLAY_COMMENT, - IPT_UI_CLEAR, - IPT_UI_ZOOM_IN, - IPT_UI_ZOOM_OUT, - IPT_UI_ZOOM_DEFAULT, - IPT_UI_PREV_GROUP, - IPT_UI_NEXT_GROUP, - IPT_UI_ROTATE, - IPT_UI_SHOW_PROFILER, - IPT_UI_TOGGLE_UI, - IPT_UI_RELEASE_POINTER, - IPT_UI_PASTE, - IPT_UI_SAVE_STATE, - IPT_UI_LOAD_STATE, - IPT_UI_TAPE_START, - IPT_UI_TAPE_STOP, - IPT_UI_DATS, - IPT_UI_FAVORITES, - IPT_UI_EXPORT, - IPT_UI_AUDIT, - - // additional OSD-specified UI port types (up to 16) - IPT_OSD_1, - IPT_OSD_2, - IPT_OSD_3, - IPT_OSD_4, - IPT_OSD_5, - IPT_OSD_6, - IPT_OSD_7, - IPT_OSD_8, - IPT_OSD_9, - IPT_OSD_10, - IPT_OSD_11, - IPT_OSD_12, - IPT_OSD_13, - IPT_OSD_14, - IPT_OSD_15, - IPT_OSD_16, - - IPT_UI_LAST, - - IPT_OTHER, // not mapped to standard defaults - - IPT_SPECIAL, // uninterpreted characters - IPT_CUSTOM, // handled by custom code - IPT_OUTPUT, - - IPT_COUNT -}; -DECLARE_ENUM_INCDEC_OPERATORS(ioport_type) -// aliases for some types -#define IPT_PADDLE_H IPT_PADDLE -#define IPT_PEDAL1 IPT_PEDAL -#define IPT_POSITIONAL_H IPT_POSITIONAL -#define IPT_DIAL_H IPT_DIAL - - // input type classes enum ioport_type_class { @@ -662,116 +333,6 @@ typedef device_delegate<void (ioport_field &, u32, ioport_value, ioport_value)> typedef device_delegate<float (float)> ioport_field_crossmap_delegate; -// ======================> inp_header - -// header at the front of INP files -class inp_header -{ -public: - // parameters - static constexpr unsigned MAJVERSION = 3; - static constexpr unsigned MINVERSION = 0; - - bool read(emu_file &f) - { - return f.read(m_data, sizeof(m_data)) == sizeof(m_data); - } - bool write(emu_file &f) const - { - return f.write(m_data, sizeof(m_data)) == sizeof(m_data); - } - - bool check_magic() const - { - return 0 == std::memcmp(MAGIC, m_data + OFFS_MAGIC, OFFS_BASETIME - OFFS_MAGIC); - } - u64 get_basetime() const - { - return - (u64(m_data[OFFS_BASETIME + 0]) << (0 * 8)) | - (u64(m_data[OFFS_BASETIME + 1]) << (1 * 8)) | - (u64(m_data[OFFS_BASETIME + 2]) << (2 * 8)) | - (u64(m_data[OFFS_BASETIME + 3]) << (3 * 8)) | - (u64(m_data[OFFS_BASETIME + 4]) << (4 * 8)) | - (u64(m_data[OFFS_BASETIME + 5]) << (5 * 8)) | - (u64(m_data[OFFS_BASETIME + 6]) << (6 * 8)) | - (u64(m_data[OFFS_BASETIME + 7]) << (7 * 8)); - } - unsigned get_majversion() const - { - return m_data[OFFS_MAJVERSION]; - } - unsigned get_minversion() const - { - return m_data[OFFS_MINVERSION]; - } - std::string get_sysname() const - { - return get_string<OFFS_SYSNAME, OFFS_APPDESC>(); - } - std::string get_appdesc() const - { - return get_string<OFFS_APPDESC, OFFS_END>(); - } - - void set_magic() - { - std::memcpy(m_data + OFFS_MAGIC, MAGIC, OFFS_BASETIME - OFFS_MAGIC); - } - void set_basetime(u64 time) - { - m_data[OFFS_BASETIME + 0] = u8((time >> (0 * 8)) & 0x00ff); - m_data[OFFS_BASETIME + 1] = u8((time >> (1 * 8)) & 0x00ff); - m_data[OFFS_BASETIME + 2] = u8((time >> (2 * 8)) & 0x00ff); - m_data[OFFS_BASETIME + 3] = u8((time >> (3 * 8)) & 0x00ff); - m_data[OFFS_BASETIME + 4] = u8((time >> (4 * 8)) & 0x00ff); - m_data[OFFS_BASETIME + 5] = u8((time >> (5 * 8)) & 0x00ff); - m_data[OFFS_BASETIME + 6] = u8((time >> (6 * 8)) & 0x00ff); - m_data[OFFS_BASETIME + 7] = u8((time >> (7 * 8)) & 0x00ff); - } - void set_version() - { - m_data[OFFS_MAJVERSION] = MAJVERSION; - m_data[OFFS_MINVERSION] = MINVERSION; - } - void set_sysname(std::string const &name) - { - set_string<OFFS_SYSNAME, OFFS_APPDESC>(name); - } - void set_appdesc(std::string const &desc) - { - set_string<OFFS_APPDESC, OFFS_END>(desc); - } - -private: - template <std::size_t BEGIN, std::size_t END> void set_string(std::string const &str) - { - std::size_t const used = (std::min<std::size_t>)(str.size() + 1, END - BEGIN); - std::memcpy(m_data + BEGIN, str.c_str(), used); - if ((END - BEGIN) > used) - std::memset(m_data + BEGIN + used, 0, (END - BEGIN) - used); - } - template <std::size_t BEGIN, std::size_t END> std::string get_string() const - { - char const *const begin = reinterpret_cast<char const *>(m_data + BEGIN); - return std::string(begin, std::find(begin, reinterpret_cast<char const *>(m_data + END), '\0')); - } - - static constexpr std::size_t OFFS_MAGIC = 0x00; // 0x08 bytes - static constexpr std::size_t OFFS_BASETIME = 0x08; // 0x08 bytes (little-endian binary integer) - static constexpr std::size_t OFFS_MAJVERSION = 0x10; // 0x01 bytes (binary integer) - static constexpr std::size_t OFFS_MINVERSION = 0x11; // 0x01 bytes (binary integer) - // 0x02 bytes reserved - static constexpr std::size_t OFFS_SYSNAME = 0x14; // 0x0c bytes (ASCII) - static constexpr std::size_t OFFS_APPDESC = 0x20; // 0x20 bytes (ASCII) - static constexpr std::size_t OFFS_END = 0x40; - - static u8 const MAGIC[OFFS_BASETIME - OFFS_MAGIC]; - - u8 m_data[OFFS_END]; -}; - - // ======================> input_device_default // device defined default input settings @@ -798,7 +359,7 @@ public: ioport_group group() const noexcept { return m_group; } u8 player() const noexcept { return m_player; } const char *token() const noexcept { return m_token; } - const char *name() const noexcept { return m_name; } + std::string name() const; input_seq &defseq(input_seq_type seqtype = SEQ_TYPE_STANDARD) noexcept { return m_defseq[seqtype]; } const input_seq &defseq(input_seq_type seqtype = SEQ_TYPE_STANDARD) const noexcept { return m_defseq[seqtype]; } const input_seq &seq(input_seq_type seqtype = SEQ_TYPE_STANDARD) const noexcept { return m_seq[seqtype]; } @@ -1026,6 +587,7 @@ public: u8 player() const { return m_player; } bool digital_value() const { return m_digital_value; } void set_value(ioport_value value); + void clear_value(); bool optional() const { return ((m_flags & FIELD_FLAG_OPTIONAL) != 0); } bool cocktail() const { return ((m_flags & FIELD_FLAG_COCKTAIL) != 0); } @@ -1037,7 +599,7 @@ public: bool analog_invert() const { return ((m_flags & ANALOG_FLAG_INVERT) != 0); } u8 impulse() const noexcept { return m_impulse; } - const char *name() const; + std::string name() const; const char *specific_name() const noexcept { return m_name; } const input_seq &seq(input_seq_type seqtype = SEQ_TYPE_STANDARD) const noexcept; const input_seq &defseq(input_seq_type seqtype = SEQ_TYPE_STANDARD) const noexcept; @@ -1262,8 +824,9 @@ public: float crosshair_read(); void frame_update(running_machine &machine); - // setters + // programmatic override (for script bindings) void set_value(s32 value); + void clear_value(); private: // helpers @@ -1276,10 +839,11 @@ private: ioport_field & m_field; // pointer to the input field referenced // adjusted values (right-justified and tweaked) - u8 m_shift; // shift to align final value in the port - s32 m_adjdefvalue; // adjusted default value from the config + u8 const m_shift; // shift to align final value in the port + s32 const m_adjdefvalue; // adjusted default value from the config s32 m_adjmin; // adjusted minimum value from the config s32 m_adjmax; // adjusted maximum value from the config + s32 m_adjoverride; // programmatically set adjusted value // live values of configurable parameters s32 m_sensitivity; // current live sensitivity (100=normal) @@ -1291,7 +855,6 @@ private: s32 m_accum; // accumulated value (including relative adjustments) s32 m_previous; // previous adjusted value s32 m_previousanalog; // previous analog value - s32 m_prog_analog_value; // programmatically set analog value // parameters for modifying live values s32 m_minimum; // minimum adjusted value @@ -1313,7 +876,7 @@ private: bool m_single_scale; // scale joystick differently if default is between min/max bool m_interpolate; // should we do linear interpolation for mid-frame reads? bool m_lastdigital; // was the last modification caused by a digital form? - bool m_was_written; // was the last modification caused programmatically? + bool m_use_adjoverride; // override what will be read from the field }; @@ -1382,7 +945,7 @@ public: // type helpers const std::vector<input_type_entry> &types() const noexcept { return m_typelist; } bool type_pressed(ioport_type type, int player = 0); - const char *type_name(ioport_type type, u8 player) const noexcept; + std::string type_name(ioport_type type, u8 player) const; ioport_group type_group(ioport_type type, int player) const noexcept; const input_seq &type_seq(ioport_type type, int player = 0, input_seq_type seqtype = SEQ_TYPE_STANDARD) const noexcept; void set_type_seq(ioport_type type, int player, input_seq_type seqtype, const input_seq &newseq) noexcept; @@ -1399,7 +962,7 @@ public: private: // internal helpers void init_port_types(); - void init_autoselect_devices(int type1, int type2, int type3, const char *option, const char *ananame); + void init_autoselect_devices(std::initializer_list<ioport_type> types, std::string_view option, std::string_view ananame); void frame_update_callback(); void frame_update(); @@ -1414,6 +977,7 @@ private: bool load_default_config(int type, int player, const std::pair<input_seq, char const *> (&newseq)[SEQ_TYPE_TOTAL]); bool load_controller_config(util::xml::data_node const &portnode, int type, int player, const std::pair<input_seq, char const *> (&newseq)[SEQ_TYPE_TOTAL]); void load_system_config(util::xml::data_node const &portnode, int type, int player, const std::pair<input_seq, char const *> (&newseq)[SEQ_TYPE_TOTAL]); + void apply_device_defaults(); void save_config(config_type cfg_type, util::xml::data_node *parentnode); bool save_this_input_field_type(ioport_type type); @@ -1449,8 +1013,8 @@ private: attoseconds_t m_last_delta_nsec; // nanoseconds that passed since the previous callback // playback/record information - emu_file m_record_file; // recording file (closed if not recording) - emu_file m_playback_file; // playback file (closed if not recording) + std::unique_ptr<emu_file> m_record_file; // recording file (nullptr if not recording) + std::unique_ptr<emu_file> m_playback_file; // playback file (nullptr if not recording) util::write_stream::ptr m_record_stream; // recording stream (nullptr if not recording) util::read_stream::ptr m_playback_stream; // playback stream (nullptr if not recording) u64 m_playback_accumulated_speed; // accumulated speed during playback @@ -1458,6 +1022,7 @@ private: // storage for inactive configuration std::unique_ptr<util::xml::file> m_deselected_card_config; + bool m_applied_device_defaults; }; @@ -1658,10 +1223,10 @@ ATTR_COLD void INPUT_PORTS_NAME(_name)(device_t &owner, ioport_list &portlist, s configurer.field_set_crosshair(CROSSHAIR_AXIS_##axis, altaxis, scale, offset); #define PORT_CROSSHAIR_MAPPER(_callback) \ - configurer.field_set_crossmapper(ioport_field_crossmap_delegate(_callback, #_callback, DEVICE_SELF, (device_t *)nullptr)); + configurer.field_set_crossmapper(ioport_field_crossmap_delegate(owner, DEVICE_SELF, _callback, #_callback)); #define PORT_CROSSHAIR_MAPPER_MEMBER(_device, _class, _member) \ - configurer.field_set_crossmapper(ioport_field_crossmap_delegate(&_class::_member, #_class "::" #_member, _device, (_class *)nullptr)); + configurer.field_set_crossmapper(ioport_field_crossmap_delegate(owner, _device, &_class::_member, #_class "::" #_member)); // how many optical counts for 1 full turn of the control #define PORT_FULL_TURN_COUNT(_count) \ |