1
/***************************************************************************
5
Handle input ports and mappings.
7
Copyright Nicola Salmoria and the MAME Team.
8
Visit http://mamedev.org for licensing and usage restrictions.
10
***************************************************************************/
15
#error Dont include this file directly; include emu.h instead.
18
#ifndef __INPTPORT_H__
19
#define __INPTPORT_H__
25
/***************************************************************************
27
***************************************************************************/
31
#define IP_ACTIVE_HIGH 0x00000000
32
#define IP_ACTIVE_LOW 0xffffffff
35
/* flags for input_field_configs */
36
#define FIELD_FLAG_UNUSED 0x01 /* set if this field is unused but relevant to other games on the same hw */
37
#define FIELD_FLAG_COCKTAIL 0x02 /* set if this field is relevant only for cocktail cabinets */
38
#define FIELD_FLAG_TOGGLE 0x04 /* set if this field should behave as a toggle */
39
#define FIELD_FLAG_ROTATED 0x08 /* set if this field represents a rotated control */
40
#define ANALOG_FLAG_REVERSE 0x10 /* analog only: reverse the sense of the axis */
41
#define ANALOG_FLAG_RESET 0x20 /* analog only: always preload in->default for relative axes, returning only deltas */
42
#define ANALOG_FLAG_WRAPS 0x40 /* analog only: positional count wraps around */
43
#define ANALOG_FLAG_INVERT 0x80 /* analog only: bitwise invert bits */
46
/* INP file information */
47
#define INP_HEADER_SIZE 64
48
#define INP_HEADER_MAJVERSION 3
49
#define INP_HEADER_MINVERSION 0
52
/* sequence types for input_port_seq() call */
55
SEQ_TYPE_STANDARD = 0,
60
typedef enum _input_seq_type input_seq_type;
61
DECLARE_ENUM_OPERATORS(input_seq_type)
64
/* conditions for DIP switches */
71
PORTCOND_NOTGREATERTHAN,
80
CROSSHAIR_AXIS_NONE = 0,
86
/* groups for input ports */
104
/* various input port types */
107
/* pseudo-port types */
116
IPT_CATEGORY, /* MESS only */
155
/* misc other digital inputs */
161
IPT_START, /* MESS only */
162
IPT_SELECT, /* MESS only */
163
IPT_KEYPAD, /* MESS only */
164
IPT_KEYBOARD, /* MESS only */
166
#define __ipt_digital_joystick_start IPT_JOYSTICK_UP
167
/* use IPT_JOYSTICK for panels where the player has one single joystick */
173
/* use IPT_JOYSTICKLEFT and IPT_JOYSTICKRIGHT for dual joystick panels */
174
IPT_JOYSTICKRIGHT_UP,
175
IPT_JOYSTICKRIGHT_DOWN,
176
IPT_JOYSTICKRIGHT_LEFT,
177
IPT_JOYSTICKRIGHT_RIGHT,
179
IPT_JOYSTICKLEFT_DOWN,
180
IPT_JOYSTICKLEFT_LEFT,
181
IPT_JOYSTICKLEFT_RIGHT,
182
#define __ipt_digital_joystick_end IPT_JOYSTICKLEFT_RIGHT
226
IPT_MAHJONG_LAST_CHANCE,
228
IPT_MAHJONG_DOUBLE_UP,
229
IPT_MAHJONG_FLIP_FLOP,
233
/* hanafuda inputs */
245
/* gambling inputs */
261
/* poker-specific inputs */
270
/* slot-specific inputs */
278
#define __ipt_analog_start IPT_PADDLE
279
#define __ipt_analog_absolute_start IPT_PADDLE
280
IPT_PADDLE, /* absolute */
281
IPT_PADDLE_V, /* absolute */
282
IPT_AD_STICK_X, /* absolute */
283
IPT_AD_STICK_Y, /* absolute */
284
IPT_AD_STICK_Z, /* absolute */
285
IPT_LIGHTGUN_X, /* absolute */
286
IPT_LIGHTGUN_Y, /* absolute */
287
IPT_PEDAL, /* absolute */
288
IPT_PEDAL2, /* absolute */
289
IPT_PEDAL3, /* absolute */
290
IPT_POSITIONAL, /* absolute */
291
IPT_POSITIONAL_V, /* absolute */
292
#define __ipt_analog_absolute_end IPT_POSITIONAL_V
294
IPT_DIAL, /* relative */
295
IPT_DIAL_V, /* relative */
296
IPT_TRACKBALL_X, /* relative */
297
IPT_TRACKBALL_Y, /* relative */
298
IPT_MOUSE_X, /* relative */
299
IPT_MOUSE_Y, /* relative */
300
#define __ipt_analog_end IPT_MOUSE_Y
302
/* analog adjuster support */
305
/* the following are special codes for user interface handling - not to be used by drivers! */
306
#define __ipt_ui_start IPT_UI_CONFIGURE
308
IPT_UI_ON_SCREEN_DISPLAY,
311
IPT_UI_RESET_MACHINE,
314
IPT_UI_FRAMESKIP_DEC,
315
IPT_UI_FRAMESKIP_INC,
332
IPT_UI_DISPLAY_COMMENT,
339
IPT_UI_SHOW_PROFILER,
346
/* additional OSD-specified UI port types (up to 16) */
363
#define __ipt_ui_end IPT_OSD_16
365
/* other meaning not mapped to standard defaults */
368
/* special meaning handled by custom code */
376
/* default strings used in port definitions */
379
INPUT_STRING_Off = 1,
384
INPUT_STRING_Bonus_Life,
385
INPUT_STRING_Difficulty,
386
INPUT_STRING_Demo_Sounds,
387
INPUT_STRING_Coinage,
424
INPUT_STRING_Free_Play,
425
INPUT_STRING_Cabinet,
426
INPUT_STRING_Upright,
427
INPUT_STRING_Cocktail,
428
INPUT_STRING_Flip_Screen,
429
INPUT_STRING_Service_Mode,
433
INPUT_STRING_Version,
435
INPUT_STRING_International,
441
INPUT_STRING_Hispanic,
442
INPUT_STRING_Language,
443
INPUT_STRING_English,
444
INPUT_STRING_Japanese,
447
INPUT_STRING_Italian,
448
INPUT_STRING_Spanish,
449
INPUT_STRING_Very_Easy,
450
INPUT_STRING_Easiest,
453
INPUT_STRING_Medium_Easy,
456
INPUT_STRING_Medium_Hard,
459
INPUT_STRING_Hardest,
460
INPUT_STRING_Very_Hard,
461
INPUT_STRING_Medium_Difficult,
462
INPUT_STRING_Difficult,
463
INPUT_STRING_More_Difficult,
464
INPUT_STRING_Most_Difficult,
465
INPUT_STRING_Very_Difficult,
466
INPUT_STRING_Very_Low,
470
INPUT_STRING_Highest,
471
INPUT_STRING_Very_High,
472
INPUT_STRING_Players,
473
INPUT_STRING_Controls,
476
INPUT_STRING_Game_Time,
477
INPUT_STRING_Continue_Price,
478
INPUT_STRING_Controller,
479
INPUT_STRING_Light_Gun,
480
INPUT_STRING_Joystick,
481
INPUT_STRING_Trackball,
482
INPUT_STRING_Continues,
483
INPUT_STRING_Allow_Continue,
484
INPUT_STRING_Level_Select,
485
INPUT_STRING_Infinite,
489
INPUT_STRING_Unknown,
490
INPUT_STRING_Standard,
491
INPUT_STRING_Reverse,
492
INPUT_STRING_Alternate,
502
INPUT_CLASS_INTERNAL,
503
INPUT_CLASS_KEYBOARD,
504
INPUT_CLASS_CONTROLLER,
506
INPUT_CLASS_DIPSWITCH,
507
INPUT_CLASS_CATEGORIZED,
511
#define UCHAR_PRIVATE (0x100000)
512
#define UCHAR_SHIFT_1 (UCHAR_PRIVATE + 0)
513
#define UCHAR_SHIFT_2 (UCHAR_PRIVATE + 1)
514
#define UCHAR_MAMEKEY_BEGIN (UCHAR_PRIVATE + 2)
515
#define UCHAR_MAMEKEY(code) (UCHAR_MAMEKEY_BEGIN + ITEM_ID_##code)
517
#define UCHAR_SHIFT_BEGIN (UCHAR_SHIFT_1)
518
#define UCHAR_SHIFT_END (UCHAR_SHIFT_2)
520
/***************************************************************************
522
***************************************************************************/
524
/* input ports support up to 32 bits each */
525
typedef UINT32 input_port_value;
528
/* opaque types pointing to live state */
529
typedef struct _input_port_state input_port_state;
530
typedef struct _input_field_state input_field_state;
533
/* forward declarations */
534
class input_port_config;
535
class input_field_config;
538
/* template specializations */
539
typedef tagged_list<input_port_config> ioport_list;
542
/* read input port callback function */
543
typedef delegate<UINT32 (const input_field_config &, void *)> input_field_read_delegate;
545
/* input port write callback function */
546
typedef delegate<void (const input_field_config &, void *, input_port_value, input_port_value)> input_field_write_delegate;
548
/* crosshair mapping function */
549
typedef delegate<float (const input_field_config &, float)> input_field_crossmap_delegate;
552
/* encapsulates a condition on a port field or setting */
553
typedef struct _input_condition input_condition;
554
struct _input_condition
556
const char * tag; /* tag of port whose condition is to be tested */
557
input_port_value mask; /* mask to apply to the port */
558
input_port_value value; /* value to compare against */
559
UINT8 condition; /* condition to use */
563
/* a single setting for a configuration or DIP switch */
564
class input_setting_config
566
DISABLE_COPYING(input_setting_config);
567
friend class simple_list<input_setting_config>;
570
input_setting_config(input_field_config &field, input_port_value value, const char *name);
571
input_setting_config *next() const { return m_next; }
573
input_port_value value; /* value of the bits in this setting */
574
input_condition condition; /* condition under which this setting is valid */
575
const char * name; /* user-friendly name to display */
576
UINT16 category; /* (MESS-specific) category */
579
input_field_config & m_field; /* pointer back to the field that owns us */
580
input_setting_config * m_next; /* pointer to next setting in sequence */
584
/* a mapping from a bit to a physical DIP switch description */
585
class input_field_diplocation
587
DISABLE_COPYING(input_field_diplocation);
588
friend class simple_list<input_field_diplocation>;
591
input_field_diplocation(const char *string, UINT8 swnum, bool invert);
592
input_field_diplocation *next() const { return m_next; }
594
astring swname; /* name of the physical DIP switch */
595
UINT8 swnum; /* physical switch number */
596
bool invert; /* is this an active-high DIP? */
599
input_field_diplocation * m_next; /* pointer to the next bit */
603
/* a single bitfield within an input port */
604
class input_field_config
606
DISABLE_COPYING(input_field_config);
607
friend class simple_list<input_field_config>;
610
input_field_config(input_port_config &port, int type, input_port_value defvalue, input_port_value maskbits, const char *name = NULL);
612
input_field_config *next() const { return m_next; }
613
input_port_config &port() const { return m_port; }
614
running_machine &machine() const;
615
simple_list<input_setting_config> &settinglist() { return m_settinglist; }
616
const simple_list<input_setting_config> &settinglist() const { return m_settinglist; }
617
simple_list<input_field_diplocation> &diploclist() { return m_diploclist; }
618
int modcount() const { return m_modcount; }
620
/* generally-applicable data */
621
input_port_value mask; /* mask of bits belonging to the field */
622
input_port_value defvalue; /* default value of these bits */
623
input_condition condition; /* condition under which this field is relevant */
624
UINT32 type; /* IPT_* type for this port */
625
UINT8 player; /* player number (0-based) */
626
UINT16 category; /* (MESS-specific) category */
627
UINT32 flags; /* combination of FIELD_FLAG_* and ANALOG_FLAG_* above */
628
UINT8 impulse; /* number of frames before reverting to defvalue */
629
const char * name; /* user-friendly name to display */
630
input_seq seq[SEQ_TYPE_TOTAL];/* sequences of all types */
631
input_field_read_delegate read; /* read callback routine */
632
void * read_param; /* parameter for read callback routine */
633
const char * read_device; /* parameter for read callback routine */
634
input_field_write_delegate write; /* write callback routine */
635
void * write_param; /* parameter for write callback routine */
636
const char * write_device; /* parameter for write callback routine */
638
/* data relevant to analog control types */
639
INT32 min; /* minimum value for absolute axes */
640
INT32 max; /* maximum value for absolute axes */
641
INT32 sensitivity; /* sensitivity (100=normal) */
642
INT32 delta; /* delta to apply each frame a digital inc/dec key is pressed */
643
INT32 centerdelta; /* delta to apply each frame no digital inputs are pressed */
644
UINT8 crossaxis; /* crosshair axis */
645
double crossscale; /* crosshair scale */
646
double crossoffset; /* crosshair offset */
647
double crossaltaxis; /* crosshair alternate axis value */
648
input_field_crossmap_delegate crossmapper; /* crosshair mapping function */
649
const char * crossmapper_device; /* parameter for write callback routine */
650
UINT16 full_turn_count;/* number of optical counts for 1 full turn of the original control */
651
const input_port_value * remap_table; /* pointer to an array that remaps the port value */
653
/* data relevant to other specific types */
654
UINT8 way; /* digital joystick 2/4/8-way descriptions */
655
unicode_char chars[3]; /* (MESS-specific) unicode key data */
657
/* this field is only valid if the device is live */
658
input_field_state * state; /* live state of field (NULL if not live) */
661
input_field_config * m_next; /* pointer to next field in sequence */
662
input_port_config & m_port; /* pointer back to the port that owns us */
664
simple_list<input_setting_config> m_settinglist; /* list of input_setting_configs */
665
simple_list<input_field_diplocation> m_diploclist; /* list of locations for various bits */
669
/* user-controllable settings for a field */
670
typedef struct _input_field_user_settings input_field_user_settings;
671
struct _input_field_user_settings
673
input_port_value value; /* for DIP switches */
674
input_seq seq[SEQ_TYPE_TOTAL];/* sequences of all types */
675
INT32 sensitivity; /* for analog controls */
676
INT32 delta; /* for analog controls */
677
INT32 centerdelta; /* for analog controls */
678
UINT8 reverse; /* for analog controls */
681
/* device defined default input settings */
682
typedef struct _input_device_default input_device_default;
683
struct _input_device_default
685
const char * tag; /* tag of port to update */
686
input_port_value mask; /* mask to apply to the port */
687
input_port_value defvalue; /* new default value */
690
/* a single input port configuration */
691
class input_port_config
693
DISABLE_COPYING(input_port_config);
694
friend class simple_list<input_port_config>;
697
// construction/destruction
698
input_port_config(device_t &owner, const char *tag);
701
input_port_config *next() const { return m_next; }
702
device_t &owner() const { return m_owner; }
703
running_machine &machine() const;
704
input_field_config *first_field() const { return m_fieldlist.first(); }
705
simple_list<input_field_config> &fieldlist() { return m_fieldlist; }
706
const char *tag() const { return m_tag; }
707
int modcount() const { return m_modcount; }
709
void bump_modcount() { m_modcount++; }
711
void collapse_fields(astring &errorbuf);
713
/* these fields are only valid if the port is live */
714
input_port_state * state; /* live state of port (NULL if not live) */
715
input_port_value active; /* mask of active bits in the port */
718
input_port_config * m_next; /* pointer to next port */
719
device_t & m_owner; /* associated device, when appropriate */
720
simple_list<input_field_config> m_fieldlist; /* list of input_field_configs */
721
astring m_tag; /* pointer to this port's tag */
726
/* describes a fundamental input type, including default input sequences */
727
class input_type_entry
729
friend class simple_list<input_type_entry>;
732
input_type_entry(UINT32 type, ioport_group group, int player, const char *token, const char *name, input_seq standard);
733
input_type_entry(UINT32 type, ioport_group group, int player, const char *token, const char *name, input_seq standard, input_seq decrement, input_seq increment);
735
input_type_entry *next() const { return m_next; }
737
UINT32 type; /* IPT_* for this entry */
738
ioport_group group; /* which group the port belongs to */
739
UINT8 player; /* player number (0 is player 1) */
740
const char * token; /* token used to store settings */
741
const char * name; /* user-friendly name */
742
input_seq defseq[SEQ_TYPE_TOTAL];/* default input sequence */
743
input_seq seq[SEQ_TYPE_TOTAL];/* currently configured sequences */
746
input_type_entry * m_next; /* next description in the list */
750
/* header at the front of INP files */
751
typedef struct _inp_header inp_header;
754
char header[8]; /* +00: 8 byte header - must be "MAMEINP\0" */
755
UINT64 basetime; /* +08: base time of recording */
756
UINT8 majversion; /* +10: major INP version */
757
UINT8 minversion; /* +11: minor INP version */
758
UINT8 reserved[2]; /* +12: must be zero */
759
char gamename[12]; /* +14: game name string, NULL-terminated */
760
char version[32]; /* +20: system version string, NULL-terminated */
765
/***************************************************************************
767
***************************************************************************/
769
/* macro for a read callback function (PORT_CUSTOM) */
770
#define CUSTOM_INPUT(name) input_port_value name(device_t &device, const input_field_config &field, void *param)
771
#define CUSTOM_INPUT_MEMBER(name) input_port_value name(const input_field_config &field, void *param)
772
#define DECLARE_CUSTOM_INPUT_MEMBER(name) input_port_value name(const input_field_config &field, void *param)
774
/* macro for port write callback functions (PORT_CHANGED) */
775
#define INPUT_CHANGED(name) void name(device_t &device, const input_field_config &field, void *param, input_port_value oldval, input_port_value newval)
776
#define INPUT_CHANGED_MEMBER(name) void name(const input_field_config &field, void *param, input_port_value oldval, input_port_value newval)
777
#define DECLARE_INPUT_CHANGED_MEMBER(name) void name(const input_field_config &field, void *param, input_port_value oldval, input_port_value newval)
779
/* macro for port changed callback functions (PORT_CROSSHAIR_MAPPER) */
780
#define CROSSHAIR_MAPPER(name) float name(device_t &device, const input_field_config &field, float linear_value)
781
#define CROSSHAIR_MAPPER_MEMBER(name) float name(const input_field_config &field, float linear_value)
782
#define DECLARE_CROSSHAIR_MAPPER_MEMBER(name) float name(const input_field_config &field, float linear_value)
784
/* macro for wrapping a default string */
785
#define DEF_STR(str_num) ((const char *)INPUT_STRING_##str_num)
788
template<int (*_FunctionPointer)(device_t *)>
789
input_port_value ioport_read_line_wrapper(device_t &device, const input_field_config &field, void *param)
791
return (*_FunctionPointer)(&device);
794
template<class _FunctionClass, int (_FunctionClass::*_FunctionPointer)()>
795
input_port_value ioport_read_line_wrapper(_FunctionClass &device, const input_field_config &field, void *param)
797
return (device.*_FunctionPointer)();
800
template<void (*_FunctionPointer)(device_t *, int)>
801
void ioport_write_line_wrapper(device_t &device, const input_field_config &field, void *param, input_port_value oldval, input_port_value newval)
803
return (*_FunctionPointer)(&device, newval);
806
template<class _FunctionClass, void (_FunctionClass::*_FunctionPointer)(int)>
807
void ioport_write_line_wrapper(_FunctionClass &device, const input_field_config &field, void *param, input_port_value oldval, input_port_value newval)
809
return (device.*_FunctionPointer)(newval);
814
/***************************************************************************
815
MACROS FOR BUILDING INPUT PORTS
816
***************************************************************************/
818
typedef void (*ioport_constructor)(device_t &owner, ioport_list &portlist, astring &errorbuf);
820
/* so that "0" can be used for unneeded input ports */
821
#define construct_ioport_0 NULL
824
#define INPUT_PORTS_NAME(_name) construct_ioport_##_name
827
#define INPUT_PORTS_START(_name) \
828
void INPUT_PORTS_NAME(_name)(device_t &owner, ioport_list &portlist, astring &errorbuf) \
831
input_setting_config *cursetting = NULL; \
832
input_field_config *curfield = NULL; \
833
input_port_config *curport = NULL; \
834
input_port_value maskbits = 0; \
835
(void)cursetting; (void)curfield; (void)curport; (void)maskbits; \
838
#define INPUT_PORTS_END \
842
#define INPUT_PORTS_EXTERN(_name) \
843
extern void INPUT_PORTS_NAME(_name)(device_t &owner, ioport_list &portlist, astring &errorbuf)
846
#define PORT_INCLUDE(_name) \
847
INPUT_PORTS_NAME(_name)(owner, portlist, errorbuf); \
849
/* start of a new input port (with included tag) */
850
#define PORT_START(_tag) \
851
curport = ioconfig_alloc_port(portlist, owner, _tag); \
856
/* modify an existing port */
857
#define PORT_MODIFY(_tag) \
858
curport = ioconfig_modify_port(portlist, owner, _tag); \
863
/* input bit definition */
864
#define PORT_BIT(_mask, _default, _type) \
865
curfield = ioconfig_alloc_field(*curport, (_type), (_default), (_mask)); \
868
#define PORT_SPECIAL_ONOFF(_mask, _default, _strindex) PORT_SPECIAL_ONOFF_DIPLOC(_mask, _default, _strindex, NULL)
870
#define PORT_SPECIAL_ONOFF_DIPLOC(_mask, _default, _strindex, _diploc) \
871
curfield = ioconfig_alloc_onoff(*curport, DEF_STR(_strindex), _default, _mask, _diploc, errorbuf); \
875
#define PORT_CODE(_code) \
876
ioconfig_add_code(*curfield, SEQ_TYPE_STANDARD, _code);
878
#define PORT_CODE_DEC(_code) \
879
ioconfig_add_code(*curfield, SEQ_TYPE_DECREMENT, _code);
881
#define PORT_CODE_INC(_code) \
882
ioconfig_add_code(*curfield, SEQ_TYPE_INCREMENT, _code);
897
#define PORT_ROTATED \
898
curfield->flags |= FIELD_FLAG_ROTATED
901
#define PORT_NAME(_name) \
902
curfield->name = input_port_string_from_token(_name);
904
#define PORT_PLAYER(_player) \
905
curfield->player = (_player) - 1;
907
#define PORT_COCKTAIL \
908
curfield->flags |= FIELD_FLAG_COCKTAIL; \
909
curfield->player = 1;
911
#define PORT_TOGGLE \
912
curfield->flags |= FIELD_FLAG_TOGGLE;
914
#define PORT_IMPULSE(_duration) \
915
curfield->impulse = _duration;
917
#define PORT_REVERSE \
918
curfield->flags |= ANALOG_FLAG_REVERSE;
921
curfield->flags |= ANALOG_FLAG_RESET;
923
#define PORT_UNUSED \
924
curfield->flags |= FIELD_FLAG_UNUSED;
926
/* analog settings */
927
/* if this macro is not used, the minimum defaluts to 0 and maximum defaults to the mask value */
928
#define PORT_MINMAX(_min, _max) \
929
curfield->min = _min; \
930
curfield->max = _max;
932
#define PORT_SENSITIVITY(_sensitivity) \
933
curfield->sensitivity = _sensitivity;
935
#define PORT_KEYDELTA(_delta) \
936
curfield->delta = curfield->centerdelta = _delta;
938
/* note that PORT_CENTERDELTA must appear after PORT_KEYDELTA */
939
#define PORT_CENTERDELTA(_delta) \
940
curfield->centerdelta = _delta;
942
#define PORT_CROSSHAIR(axis, scale, offset, altaxis) \
943
curfield->crossaxis = CROSSHAIR_AXIS_##axis; \
944
curfield->crossaltaxis = altaxis; \
945
curfield->crossscale = scale; \
946
curfield->crossoffset = offset;
948
#define PORT_CROSSHAIR_MAPPER(_callback) \
949
curfield->crossmapper = input_field_crossmap_delegate(_callback, #_callback, (device_t *)NULL); \
950
curfield->crossmapper_device = DEVICE_SELF;
952
#define PORT_CROSSHAIR_MAPPER_MEMBER(_device, _class, _member) \
953
curfield->crossmapper = input_field_crossmap_delegate(&_class::_member, #_class "::" #_member, (_class *)NULL); \
954
curfield->crossmapper_device = _device;
956
/* how many optical counts for 1 full turn of the control */
957
#define PORT_FULL_TURN_COUNT(_count) \
958
curfield->full_turn_count = _count;
960
/* positional controls can be binary or 1 of X */
961
/* 1 of X not completed yet */
962
/* if it is specified as PORT_REMAP_TABLE then it is binary, but remapped */
963
/* otherwise it is binary */
964
#define PORT_POSITIONS(_positions) \
965
curfield->max = _positions;
967
/* positional control wraps at min/max */
969
curfield->flags |= ANALOG_FLAG_WRAPS;
971
/* positional control uses this remap table */
972
#define PORT_REMAP_TABLE(_table) \
973
curfield->remap_table = _table;
975
/* positional control bits are active low */
976
#define PORT_INVERT \
977
curfield->flags |= ANALOG_FLAG_INVERT;
980
#define PORT_CUSTOM(_callback, _param) \
981
curfield->read = input_field_read_delegate(_callback, #_callback, (device_t *)NULL); \
982
curfield->read_param = (void *)(_param); \
983
curfield->read_device = DEVICE_SELF;
985
#define PORT_CUSTOM_MEMBER(_device, _class, _member, _param) \
986
curfield->read = input_field_read_delegate(&_class::_member, #_class "::" #_member, (_class *)NULL); \
987
curfield->read_param = (void *)(_param); \
988
curfield->read_device = (_device);
990
/* write callbacks */
991
#define PORT_CHANGED(_callback, _param) \
992
curfield->write = input_field_write_delegate(_callback, #_callback, (device_t *)NULL); \
993
curfield->write_param = (void *)(_param); \
994
curfield->write_device = DEVICE_SELF;
996
#define PORT_CHANGED_MEMBER(_device, _class, _member, _param) \
997
curfield->write = input_field_write_delegate(&_class::_member, #_class "::" #_member, (_class *)NULL); \
998
curfield->write_param = (void *)(_param); \
999
curfield->write_device = (_device);
1001
/* input device handler */
1002
#define PORT_READ_LINE_DEVICE(_device, _read_line_device) \
1003
curfield->read = input_field_read_delegate(&ioport_read_line_wrapper<_read_line_device>, #_read_line_device, (device_t *)NULL); \
1004
curfield->read_param = NULL; \
1005
curfield->read_device = _device;
1007
#define PORT_READ_LINE_DEVICE_MEMBER(_device, _class, _member) \
1008
curfield->read = input_field_read_delegate(&ioport_read_line_wrapper<_class, &_class::_member>, #_class "::" #_member, (_class *)NULL); \
1009
curfield->read_param = NULL; \
1010
curfield->read_device = _device;
1012
/* output device handler */
1013
#define PORT_WRITE_LINE_DEVICE(_device, _write_line_device) \
1014
curfield->write = input_field_write_delegate(&ioport_write_line_wrapper<_write_line_device>, #_write_line_device, (device_t *)NULL); \
1015
curfield->write_param = NULL; \
1016
curfield->write_device = _device;
1018
#define PORT_WRITE_LINE_DEVICE_MEMBER(_device, _class, _member) \
1019
curfield->write = input_field_write_delegate(&ioport_write_line_wrapper<_class, &_class::_member>, #_class "::" #_member, (_class *)NULL); \
1020
curfield->write_param = NULL; \
1021
curfield->write_device = _device;
1023
/* dip switch definition */
1024
#define PORT_DIPNAME(_mask, _default, _name) \
1025
curfield = ioconfig_alloc_field(*curport, IPT_DIPSWITCH, (_default), (_mask), (_name)); \
1028
#define PORT_DIPSETTING(_default, _name) \
1029
cursetting = ioconfig_alloc_setting(*curfield, (_default) & curfield->mask, (_name));
1031
/* physical location, of the form: name:[!]sw,[name:][!]sw,... */
1032
/* note that these are specified LSB-first */
1033
#define PORT_DIPLOCATION(_location) \
1034
diplocation_list_alloc(*curfield, _location, errorbuf);
1036
/* conditionals for dip switch settings */
1037
#define PORT_CONDITION(_tag, _mask, _condition, _value) \
1039
input_condition &condition = (cursetting != NULL) ? cursetting->condition : curfield->condition; \
1040
condition.tag = (_tag); \
1041
condition.mask = (_mask); \
1042
condition.condition = (_condition); \
1043
condition.value = (_value); \
1046
/* analog adjuster definition */
1047
#define PORT_ADJUSTER(_default, _name) \
1048
curfield = ioconfig_alloc_field(*curport, IPT_ADJUSTER, (_default), 0xff, (_name)); \
1049
cursetting = NULL; \
1051
/* config definition */
1052
#define PORT_CONFNAME(_mask, _default, _name) \
1053
curfield = ioconfig_alloc_field(*curport, IPT_CONFIG, (_default), (_mask), (_name)); \
1054
cursetting = NULL; \
1056
#define PORT_CONFSETTING(_default, _name) \
1057
cursetting = ioconfig_alloc_setting(*curfield, (_default) & curfield->mask, (_name));
1059
/* keyboard chars */
1060
#define PORT_CHAR(_ch) \
1061
ioconfig_field_add_char(*curfield, _ch, errorbuf);
1064
#define PORT_CATEGORY(_category) \
1065
curfield->category = (_category);
1067
#define PORT_CATEGORY_CLASS(_mask, _default, _name) \
1068
curfield = ioconfig_alloc_field(*curport, IPT_CATEGORY, (_default), (_mask), (_name)); \
1071
#define PORT_CATEGORY_ITEM(_default, _name, _category) \
1072
cursetting = ioconfig_alloc_setting(*curfield, (_default) & curfield->mask, (_name)); \
1073
cursetting->category = (_category);
1077
#define DEVICE_INPUT_DEFAULTS_NAME(_name) device_iptdef_##_name
1079
/* start of table */
1080
#define DEVICE_INPUT_DEFAULTS_START(_name) \
1081
const input_device_default DEVICE_INPUT_DEFAULTS_NAME(_name)[] = {
1084
#define DEVICE_INPUT_DEFAULTS(_tag,_mask,_defval) \
1085
{ _tag ,_mask, _defval }, \
1088
#define DEVICE_INPUT_DEFAULTS_END \
1091
/***************************************************************************
1093
***************************************************************************/
1095
#define PORT_DIPUNUSED_DIPLOC(_mask, _default, _diploc) \
1096
PORT_SPECIAL_ONOFF_DIPLOC(_mask, _default, Unused, _diploc)
1098
#define PORT_DIPUNUSED(_mask, _default) \
1099
PORT_SPECIAL_ONOFF(_mask, _default, Unused)
1101
#define PORT_DIPUNKNOWN_DIPLOC(_mask, _default, _diploc) \
1102
PORT_SPECIAL_ONOFF_DIPLOC(_mask, _default, Unknown, _diploc)
1104
#define PORT_DIPUNKNOWN(_mask, _default) \
1105
PORT_SPECIAL_ONOFF(_mask, _default, Unknown)
1107
#define PORT_SERVICE_DIPLOC(_mask, _default, _diploc) \
1108
PORT_SPECIAL_ONOFF_DIPLOC(_mask, _default, Service_Mode, _diploc)
1110
#define PORT_SERVICE(_mask, _default) \
1111
PORT_SPECIAL_ONOFF(_mask, _default, Service_Mode)
1113
#define PORT_SERVICE_NO_TOGGLE(_mask, _default) \
1114
PORT_BIT( _mask, _mask & _default, IPT_SERVICE ) PORT_NAME( DEF_STR( Service_Mode ))
1118
/***************************************************************************
1120
***************************************************************************/
1123
/* ----- core system management ----- */
1125
/* initialize the input ports, processing the given token list */
1126
time_t input_port_init(running_machine &machine);
1130
/* ----- port configurations ----- */
1132
/* initialize an input port list structure and allocate ports according to the given tokens */
1133
void input_port_list_init(device_t &device, ioport_list &portlist, astring &errorbuf);
1135
/* return the field that matches the given tag and mask */
1136
const input_field_config *input_field_by_tag_and_mask(const ioport_list &portlist, const char *tag, input_port_value mask);
1140
/* ----- accessors for input types ----- */
1142
/* return TRUE if the given type represents an analog control */
1143
int input_type_is_analog(int type);
1145
/* return the name for the given type/player */
1146
const char *input_type_name(running_machine &machine, int type, int player);
1148
/* return the group for the given type/player */
1149
int input_type_group(running_machine &machine, int type, int player);
1151
/* return the global input mapping sequence for the given type/player */
1152
const input_seq &input_type_seq(running_machine &machine, int type, int player, input_seq_type seqtype);
1154
/* change the global input sequence for the given type/player */
1155
void input_type_set_seq(running_machine &machine, int type, int player, input_seq_type seqtype, const input_seq *newseq);
1157
/* return TRUE if the sequence for the given input type/player is pressed */
1158
int input_type_pressed(running_machine &machine, int type, int player);
1160
/* return the list of default mappings */
1161
const simple_list<input_type_entry> &input_type_list(running_machine &machine);
1165
/* ----- accessors for input fields ----- */
1167
/* return the expanded string name of the field */
1168
const char *input_field_name(const input_field_config *field);
1170
/* return the input sequence for the given input field */
1171
const input_seq &input_field_seq(const input_field_config *field, input_seq_type seqtype);
1173
/* return the current settings for the given input field */
1174
void input_field_get_user_settings(const input_field_config *field, input_field_user_settings *settings);
1176
/* modify the current settings for the given input field */
1177
void input_field_set_user_settings(const input_field_config *field, const input_field_user_settings *settings);
1179
/* return the expanded setting name for a field */
1180
const char *input_field_setting_name(const input_field_config *field);
1182
/* return TRUE if the given field has a "previous" setting */
1183
int input_field_has_previous_setting(const input_field_config *field);
1185
/* select the previous item for a DIP switch or configuration field */
1186
void input_field_select_previous_setting(const input_field_config *field);
1188
/* return TRUE if the given field has a "next" setting */
1189
int input_field_has_next_setting(const input_field_config *field);
1191
/* select the next item for a DIP switch or configuration field */
1192
void input_field_select_next_setting(const input_field_config *field);
1195
/* ----- port checking ----- */
1197
/* return whether an input port exists */
1198
bool input_port_exists(running_machine &machine, const char *tag);
1200
/* return a bitmask of which bits of an input port are active (i.e. not unused or unknown) */
1201
input_port_value input_port_active(running_machine &machine, const char *tag);
1203
/* return a bitmask of which bits of an input port are active (i.e. not unused or unknown), or a default value if the port does not exist */
1204
input_port_value input_port_active_safe(running_machine &machine, const char *tag, input_port_value defvalue);
1207
/* ----- port reading ----- */
1209
/* return the value of an input port */
1210
input_port_value input_port_read_direct(const input_port_config *port);
1212
/* return the value of an input port specified by tag */
1213
input_port_value input_port_read(running_machine &machine, const char *tag);
1215
/* return the value of a device input port specified by tag */
1216
input_port_value input_port_read(device_t *device, const char *tag);
1218
/* return the value of an input port specified by tag, or a default value if the port does not exist */
1219
input_port_value input_port_read_safe(running_machine &machine, const char *tag, input_port_value defvalue);
1221
/* return the extracted crosshair values for the given player */
1222
int input_port_get_crosshair_position(running_machine &machine, int player, float *x, float *y);
1224
/* force an update to the input port values based on current conditions */
1225
void input_port_update_defaults(running_machine &machine);
1229
/* ----- port writing ----- */
1231
/* write a value to a port */
1232
void input_port_write_direct(const input_port_config *port, input_port_value value, input_port_value mask);
1234
/* write a value to a port specified by tag */
1235
void input_port_write(running_machine &machine, const char *tag, input_port_value value, input_port_value mask);
1237
/* write a value to a port, ignore if the port does not exist */
1238
void input_port_write_safe(running_machine &machine, const char *tag, input_port_value value, input_port_value mask);
1242
/* ----- misc helper functions ----- */
1244
/* return the TRUE if the given condition attached is true */
1245
int input_condition_true(running_machine &machine, const input_condition *condition,device_t &owner);
1247
/* convert an input_port_token to a default string */
1248
const char *input_port_string_from_token(const char *token);
1250
/* return TRUE if machine use full keyboard emulation */
1251
int input_machine_has_keyboard(running_machine &machine);
1253
/* these are called by the core; they should not be called from FEs */
1254
void inputx_init(running_machine &machine);
1256
/* called by drivers to setup natural keyboard support */
1257
void inputx_setup_natural_keyboard(running_machine &machine,
1258
int (*queue_chars)(running_machine &machine, const unicode_char *text, size_t text_len),
1259
int (*accept_char)(running_machine &machine, unicode_char ch),
1260
int (*charqueue_empty)(running_machine &machine));
1262
/* validity checks */
1263
int validate_natural_keyboard_statics(void);
1265
/* these can be called from FEs */
1266
int inputx_can_post(running_machine &machine);
1268
/* various posting functions; can be called from FEs */
1269
void inputx_postc(running_machine &machine, unicode_char ch);
1270
void inputx_post_utf8(running_machine &machine, const char *text);
1271
void inputx_post_utf8_rate(running_machine &machine, const char *text, attotime rate);
1272
int inputx_is_posting(running_machine &machine);
1274
/* miscellaneous functions */
1275
int input_classify_port(const input_field_config *field);
1276
int input_has_input_class(running_machine &machine, int inputclass);
1277
int input_player_number(const input_field_config *field);
1278
int input_count_players(running_machine &machine);
1279
int input_category_active(running_machine &machine, int category);
1282
inline running_machine &input_field_config::machine() const
1284
return m_port.machine();
1288
// temporary construction helpers
1289
void field_config_insert(input_field_config &newfield, input_port_value &disallowedbits, astring &errorbuf);
1290
void diplocation_list_alloc(input_field_config &field, const char *location, astring &errorbuf);
1293
input_port_config *ioconfig_alloc_port(ioport_list &portlist, device_t &device, const char *tag);
1294
input_port_config *ioconfig_modify_port(ioport_list &portlist, device_t &device, const char *tag);
1295
input_field_config *ioconfig_alloc_field(input_port_config &port, int type, input_port_value defval, input_port_value mask, const char *name = NULL);
1296
input_field_config *ioconfig_alloc_onoff(input_port_config &port, const char *name, input_port_value defval, input_port_value mask, const char *diplocation, astring &errorbuf);
1297
input_setting_config *ioconfig_alloc_setting(input_field_config &field, input_port_value value, const char *name);
1298
void ioconfig_field_add_char(input_field_config &field, unicode_char ch, astring &errorbuf);
1299
void ioconfig_add_code(input_field_config &field, int which, input_code code);
1301
#endif /* __INPTPORT_H__ */