summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/inputseq.h
blob: 748b0440e8d71ce4315b2875d370b32130b3d5b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/***************************************************************************

    inputseq.h

    Input sequence abstractions.

    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

***************************************************************************/

#pragma once

#ifndef __INPUTSEQ_H__
#define __INPUTSEQ_H__

#include "input.h"


/***************************************************************************
    CONSTANTS
***************************************************************************/

/* additional expanded input codes for sequences */
enum
{
	/* special codes */
	SEQCODE_END = INTERNAL_CODE(0),
	SEQCODE_DEFAULT = INTERNAL_CODE(1),
	SEQCODE_NOT = INTERNAL_CODE(2),
	SEQCODE_OR = INTERNAL_CODE(3)
};



/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

/* a sequence of inputs */
typedef struct _input_seq input_seq;
struct _input_seq
{
	input_code code[16];
};



/***************************************************************************
    MACROS
***************************************************************************/

#define SEQ_DEF_7(a,b,c,d,e,f,g) {{ a, b, c, d, e, f, g, SEQCODE_END }}
#define SEQ_DEF_6(a,b,c,d,e,f)	{{ a, b, c, d, e, f, SEQCODE_END }}
#define SEQ_DEF_5(a,b,c,d,e)	{{ a, b, c, d, e, SEQCODE_END }}
#define SEQ_DEF_4(a,b,c,d)		{{ a, b, c, d, SEQCODE_END }}
#define SEQ_DEF_3(a,b,c)		{{ a, b, c, SEQCODE_END }}
#define SEQ_DEF_2(a,b)			{{ a, b, SEQCODE_END }}
#define SEQ_DEF_1(a)			{{ a, SEQCODE_END }}
#define SEQ_DEF_0				{{ SEQCODE_END }}



/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/


/* ----- state queries ----- */

/* return TRUE if the given switch sequence has been pressed */
int input_seq_pressed(const input_seq *seq);

/* return the value of an axis sequence */
INT32 input_seq_axis_value(const input_seq *seq, input_item_class *itemclass_ptr);



/* ----- sequence polling ----- */

/* begin polling for a new sequence of the given itemclass */
void input_seq_poll_start(input_item_class itemclass, const input_seq *startseq);

/* continue polling for a sequence */
int input_seq_poll(input_seq *finalseq);



/* ----- strings and tokenization ----- */

/* generate the friendly name of an input sequence */
astring *input_seq_name(astring *string, const input_seq *seq);

/* convert an input sequence to tokens, returning the length */
astring *input_seq_to_tokens(astring *string, const input_seq *seq);

/* convert a set of tokens back to an input sequence */
int input_seq_from_tokens(const char *string, input_seq *seq);



/***************************************************************************
    INLINE FUNCTIONS
***************************************************************************/

/*-------------------------------------------------
    input_seq_get_1 - fetch the first item of an
    input sequence
-------------------------------------------------*/

INLINE input_code input_seq_get_1(const input_seq *seq)
{
	return seq->code[0];
}


/*-------------------------------------------------
    input_seq_set_n - set a sequence of n codes
    as an input sequence
-------------------------------------------------*/

INLINE void input_seq_set_5(input_seq *seq, input_code code0, input_code code1, input_code code2, input_code code3, input_code code4)
{
	int codenum;
	seq->code[0] = code0;
	seq->code[1] = code1;
	seq->code[2] = code2;
	seq->code[3] = code3;
	seq->code[4] = code4;
	for (codenum = 5; codenum < ARRAY_LENGTH(seq->code); codenum++)
		seq->code[codenum] = SEQCODE_END;
}

INLINE void input_seq_set_4(input_seq *seq, input_code code0, input_code code1, input_code code2, input_code code3)
{
	input_seq_set_5(seq, code0, code1, code2, code3, SEQCODE_END);
}

INLINE void input_seq_set_3(input_seq *seq, input_code code0, input_code code1, input_code code2)
{
	input_seq_set_5(seq, code0, code1, code2, SEQCODE_END, SEQCODE_END);
}

INLINE void input_seq_set_2(input_seq *seq, input_code code0, input_code code1)
{
	input_seq_set_5(seq, code0, code1, SEQCODE_END, SEQCODE_END, SEQCODE_END);
}

INLINE void input_seq_set_1(input_seq *seq, input_code code0)
{
	input_seq_set_5(seq, code0, SEQCODE_END, SEQCODE_END, SEQCODE_END, SEQCODE_END);
}

INLINE void input_seq_set_0(input_seq *seq)
{
	input_seq_set_5(seq, SEQCODE_END, SEQCODE_END, SEQCODE_END, SEQCODE_END, SEQCODE_END);
}


/*-------------------------------------------------
    input_seq_cmp - compare two input sequences
-------------------------------------------------*/

INLINE int input_seq_cmp(const input_seq *seqa, const input_seq *seqb)
{
	int codenum;
	for (codenum = 0; codenum < ARRAY_LENGTH(seqa->code); codenum++)
	{
		if (seqa->code[codenum] != seqb->code[codenum])
			return -1;
		if (seqa->code[codenum] == SEQCODE_END)
			break;
	}
	return 0;
}

#endif	/* __INPUTSEQ_H__ */