File: keys.cpp

package info (click to toggle)
postal1 2015.git20250526%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 14,024 kB
  • sloc: cpp: 130,877; ansic: 38,942; python: 874; makefile: 351; sh: 61
file content (348 lines) | stat: -rw-r--r-- 7,892 bytes parent folder | download
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// Keys.cpp
// Project: Nostril (aka Postal)
//
// History:
//		03/31/97	JMI	Started.
//
//		07/06/97	JMI	Changed pu8ScanKey parm in KeyDescriptionToValue
//							call from a U8 to a short.
//							Also, changed g_apszButtonDescriptions to 
//							g_apszMouseButtonDescriptions.
//
//		08/10/97	JMI	Changed description of 0 to "None" (was "NULL").
//
//		08/24/97	JMI	Changed descriptions of Numpad <whatever>s to Numpad 
//							<whatever symbol>s.
//							Also, changed 'UNUSED 59' to 'Semicolon' and 'UNUSED 61'
//							to 'Equal'.
//
//		08/27/97	JMI	Reduced mouse strings to minimum verbosity.
//
//		10/10/97	JMI	Added g_apszJoyButtonDescriptions and
//							JoyButtonDescriptionToMask().
//
////////////////////////////////////////////////////////////////////////////////
//
//	Key stuff.  I'm not sure if this will ever amount to more than just the 
// descriptions.
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// RSPiX Includes.
////////////////////////////////////////////////////////////////////////////////
#include "RSPiX.h"

////////////////////////////////////////////////////////////////////////////////
// C Includes.
////////////////////////////////////////////////////////////////////////////////
#include <string.h>

////////////////////////////////////////////////////////////////////////////////
// Postal Includes.
////////////////////////////////////////////////////////////////////////////////
#include "keys.h"

////////////////////////////////////////////////////////////////////////////////
// Macros.
////////////////////////////////////////////////////////////////////////////////

// Determines the number of elements in the passed array at compile time.
#define NUM_ELEMENTS(a)		(sizeof(a) / sizeof(a[0]) )

////////////////////////////////////////////////////////////////////////////////
// Data.
////////////////////////////////////////////////////////////////////////////////

// Array of key descriptors.
extern char* g_apszKeyDescriptions[128]	=
	{
	"None",
	"End",
	"Home",
	"Left",
	"Up",
	"Right",
	"Down",
	"UNUSED 7",
	"Backspace",
	"Tab",
	"Insert",
	"Delete",
	"UNUSED 12",
	"Enter",
	"Left Shift",
	"Shift",
	"Right Shift",
	"Left Control",
	"Control",
	"Right Control",
	"Left Alt",
	"Alt",
	"Right Alt",
	"UNUSED 23",
	"UNUSED 24",
	"Page Up",
	"Page Down",
	"Escape",
	"Pause",
	"Capital",
	"Numlock",
	"Scroll",
	"Space",
	"Print Screen",
	"UNUSED 34",
	"UNUSED 35",
	"UNUSED 36",
	"UNUSED 37",
	"UNUSED 38",
	"Right Quote",
	"UNUSED 40",
	"UNUSED 41",
	"UNUSED 42",
	"UNUSED 43",
	"Comma",
	"Minus",
	"Period",
	"Slash",
	"0",
	"1",
	"2",
	"3",
	"4",
	"5",
	"6",
	"7",
	"8",
	"9",
	"UNUSED 58",
	"Semicolon",
	"UNUSED 60",
	"Equals",
	"UNUSED 62",
	"UNUSED 63",
	"UNUSED 64",
	"A",
	"B",
	"C",
	"D",
	"E",
	"F",
	"G",
	"H",
	"I",
	"J",
	"K",
	"L",
	"M",
	"N",
	"O",
	"P",
	"Q",
	"R",
	"S",
	"T",
	"U",
	"V",
	"W",
	"X",
	"Y",
	"Z",
	"Left Bracket",
	"Back Slash",
	"Right Bracket",
	"UNUSED 94",
	"UNUSED 95",
	"Left Quote",
	"Numpad 0",
	"Numpad 1",
	"Numpad 2",
	"Numpad 3",
	"Numpad 4",
	"Numpad 5",
	"Numpad 6",
	"Numpad 7",
	"Numpad 8",
	"Numpad 9",
	"Numpad *",
	"Numpad +",
	"Numpad -",
	"Numpad .",
	"Numpad /",
	"UNUSED 112",
	"F1",
	"F2",
	"F3",
	"F4",
	"F5",
	"F6",
	"F7",
	"F8",
	"F9",
	"F10",
	"F11",
	"F12",
	"Left System",
	"System",
	"Right System"
	};

// Array of mouse button descriptors.
extern char* g_apszMouseButtonDescriptions[8]	=
	{
	"None",
	"Left",
	"Right",
	"Middle",
	"Button 4",
	"Button 5",
	"Wheel Up",
	"Wheel Down",
	};

// Array of joy button descriptors.
extern char* g_apszJoyButtonDescriptions[18] =
{
	"None",
	"A",
	"B",
	"X",
	"Y",
	"Back",
	"Guide",
	"Start",
	"LS",
	"RS",
	"LB",
	"RB",
	"Up",
	"Down",
	"Left",
	"Right",
	"LT",
	"RT"
};
/*
extern char* g_apszJoyButtonDescriptions[16]	=
	{
	"None",								// 0000
	"A",									// 0001
	"B",									// 0010
	"A,B",								// 0011
	"C",									// 0100
	"A,C",								// 0101
	"B,C",								// 0110
	"A,B,C",								// 0111
	"D",									// 1000
	"A,D",								// 1001
	"B,D",								// 1010
	"A,B,D",								// 1011
	"C,D",								// 1100
	"A,C,D",								// 1101
	"B,C,D",								// 1110
	"A,B,C,D",							// 1111
	};
	*/
////////////////////////////////////////////////////////////////////////////////
// Functions.
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Given a string, returns the appropriate key code.
////////////////////////////////////////////////////////////////////////////////
extern int16_t KeyDescriptionToValue(	// Returns 0 on success.  Returns non-zero, if
												// key not found.
	char*		pszKeyDescriptor,			// In:  Description of key.
	U32*	psScanKey)					// Out: Key value.
	{
	int16_t	sRes	= 1;	// Assume failure.

	U8	u8KeyIndex;
	for (u8KeyIndex = 0; u8KeyIndex < NUM_ELEMENTS(g_apszKeyDescriptions); u8KeyIndex++)
		{
		if (rspStricmp(pszKeyDescriptor, g_apszKeyDescriptions[u8KeyIndex]) == 0)
			{
			// Found it!
			*psScanKey	= u8KeyIndex;
			sRes	= 0;

			break;
			}
		}

	return sRes;
	}

////////////////////////////////////////////////////////////////////////////////
// Given a string, returns the appropriate button mask.
////////////////////////////////////////////////////////////////////////////////
extern int16_t MouseButtonDescriptionToMask(	// Returns 0 on success.  Returns
															// non-zero, if description not 
															// found.
	char*		pszButtonDescriptor,					// In:  Description of button.
	U32*	psButtonMask)							// Out: Button mask.
	{
	int16_t	sRes	= 1;	// Assume failure.

	int16_t	sButtonIndex;
	for (sButtonIndex = 0; sButtonIndex < NUM_ELEMENTS(g_apszMouseButtonDescriptions); sButtonIndex++)
		{
		if (rspStricmp(pszButtonDescriptor, g_apszMouseButtonDescriptions[sButtonIndex]) == 0)
			{
			// Found it!
			*psButtonMask = MouseIndexToBitfield(sButtonIndex);
			sRes	= 0;

			break;
			}
		}

	return sRes;
	}

////////////////////////////////////////////////////////////////////////////////
// Given a string, returns the appropriate button mask.
////////////////////////////////////////////////////////////////////////////////
extern int16_t JoyButtonDescriptionToMask(	// Returns 0 on success.  Returns 
														// non-zero, if description not found.
	char*		pszButtonDescriptor,				// In:  Description of button.
	U32*	psButtonMask)						// Out: Button mask.
	{
	int16_t	sRes	= 1;	// Assume failure.

	int16_t	sButtonIndex;
	for (sButtonIndex = 0; sButtonIndex < NUM_ELEMENTS(g_apszJoyButtonDescriptions); sButtonIndex++)
		{
		if (rspStricmp(pszButtonDescriptor, g_apszJoyButtonDescriptions[sButtonIndex]) == 0)
			{
			// Found it!
			*psButtonMask = JoyIndexToBitfield(sButtonIndex);
			sRes	= 0;

			break;
			}
		}

	return sRes;
	}

////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////