summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/devtempl.h
blob: eaff32b3d41546459400bc180b543894a1144066 (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
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/***************************************************************************

    devtempl.h

    Template include for defining devices.

    Copyright Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

****************************************************************************

    Typical usage is as follows:

static const char DEVTEMPLATE_SOURCE[] = __FILE__;

// for a primary device....
#define DEVTEMPLATE_ID(p,s)             p##devicenameprefix##s
#define DEVTEMPLATE_FEATURES            DT_HAS_xxx | DT_HAS_yyy | ...
#define DEVTEMPLATE_NAME                "Device Name String"
#define DEVTEMPLATE_FAMILY              "Device Family String"
#define DEVTEMPLATE_CLASS               DEVICE_CLASS_xxxx
#include "devtempl.h"

// for a derived device....
#define DEVTEMPLATE_DERIVED_ID(p,s)     p##derivednameprefix##s
#define DEVTEMPLATE_DERIVED_FEATURES    DT_HAS_xxx | DT_HAS_yyy | ...
#define DEVTEMPLATE_NAME                "Derived Name String"
#include "devtempl.h"

****************************************************************************

    Parameters are as follows:

    DEVTEMPLATE_ID(p,s) - required - macro to produce device function and
        type names with a prefix of 'p' and a suffix of 's'

    DEVTEMPLATE_FEATURES - required - bitmask consisting of one of the
        DT_HAS_* flags, indicating which standard-named callbacks or
        pointers are specified by this device (everything else is assumed
        to be NULL, which is the default)

    DEVTEMPLATE_NAME - required - a string describing the device

    DEVTEMPLATE_FAMILY - required - a string describing the device family
        name

    DEVTEMPLATE_STATE - optional - the name of the device's state
        structure; by default, this is assumed to be
        DEVTEMPLATE_ID(,_state)

    DEVTEMPLATE_CLASS - optional - the device's class (default is
        DEVICE_CLASS_PERIPHERAL)

    DEVTEMPLATE_VERSION - optional - the device's version string (default
        is "1.0")

    DEVTEMPLATE_CREDITS - optional - the device's credit string (default
        is "Copyright Nicola Salmoria and the MAME Team")

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


#define DEVTEMPLATE_ID1(x) DEVTEMPLATE_ID(x,)
#define DEVTEMPLATE_DERIVED_ID1(x) DEVTEMPLATE_DERIVED_ID(x,)

/* flag bits for DEVTEMPLATE_FEATURES */
#define DT_HAS_START			0x0001
#define DT_HAS_RESET			0x0002
#define DT_HAS_STOP				0x0004
#define DT_HAS_EXECUTE			0x0008
#define DT_HAS_NVRAM			0x0010
#define DT_HAS_VALIDITY_CHECK	0x0020
#define DT_HAS_CUSTOM_CONFIG	0x0040
#define DT_HAS_ROM_REGION		0x0080
#define DT_HAS_MACHINE_CONFIG	0x0100
#define DT_HAS_INLINE_CONFIG	0x0200
#define DT_HAS_CONTRACT_LIST	0x0400
#define DT_HAS_PROGRAM_SPACE	0x1000
#define DT_HAS_DATA_SPACE		0x2000
#define DT_HAS_IO_SPACE			0x4000


/* verify core stuff is specified */
#ifndef DEVTEMPLATE_ID
#error DEVTEMPLATE_ID must be specified!
#endif

#ifndef DEVTEMPLATE_FEATURES
#error DEVTEMPLATE_FEATURES must be specified!
#endif

#if (((DEVTEMPLATE_FEATURES) & DT_HAS_START) == 0)
#error Device start routine is required!
#endif

#ifndef DEVTEMPLATE_NAME
#error DEVTEMPLATE_NAME must be specified!
#endif

#ifndef DEVTEMPLATE_FAMILY
#error DEVTEMPLATE_FAMILY must be specified!
#endif

#if (((DEVTEMPLATE_FEATURES) & (DT_HAS_PROGRAM_SPACE | DT_HAS_DATA_SPACE | DT_HAS_IO_SPACE)) != 0)
#ifndef DEVTEMPLATE_ENDIANNESS
#error DEVTEMPLATE_ENDIANNESS must be specified if an address space is present!
#endif
#endif

#ifdef DEVTEMPLATE_DERIVED_FEATURES
#ifndef DEVTEMPLATE_DERIVED_NAME
#error DEVTEMPLATE_DERIVED_NAME must be specified!
#endif
#endif


/* primary device case */
#ifndef DEVTEMPLATE_DERIVED_FEATURES

/* derive standard state name (unless explicitly provided) */
#ifndef DEVTEMPLATE_STATE
#define DEVTEMPLATE_STATE		DEVTEMPLATE_ID(,_state)
#endif

/* default to DEVICE_CLASS_PERIPHERAL */
#ifndef DEVTEMPLATE_CLASS
#define DEVTEMPLATE_CLASS		DEVICE_CLASS_PERIPHERAL
#endif

/* default to version 1.0 */
#ifndef DEVTEMPLATE_VERSION
#define DEVTEMPLATE_VERSION		"1.0"
#endif

/* default to the standard copyright attribution */
#ifndef DEVTEMPLATE_CREDITS
#define DEVTEMPLATE_CREDITS 	"Copyright Nicola Salmoria and the MAME Team"
#endif

/* declare callback functions */
static DEVICE_START( DEVTEMPLATE_ID(,) );
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_RESET)
static DEVICE_RESET( DEVTEMPLATE_ID(,) );
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_STOP)
static DEVICE_STOP( DEVTEMPLATE_ID(,) );
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_EXECUTE)
static DEVICE_EXECUTE( DEVTEMPLATE_ID(,) );
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_NVRAM)
static DEVICE_NVRAM( DEVTEMPLATE_ID(,) );
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_VALIDITY_CHECK)
static DEVICE_VALIDITY_CHECK( DEVTEMPLATE_ID(,) );
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_CUSTOM_CONFIG)
static DEVICE_CUSTOM_CONFIG( DEVTEMPLATE_ID(,) );
#endif

/* the actual get_info function */
DEVICE_GET_INFO( DEVTEMPLATE_ID(,) )
{
	switch (state)
	{
		/* --- the following bits of info are returned as 64-bit signed integers --- */
		case DEVINFO_INT_TOKEN_BYTES:			info->i = sizeof(DEVTEMPLATE_STATE);							break;
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_INLINE_CONFIG)
		case DEVINFO_INT_INLINE_CONFIG_BYTES:	info->i = sizeof(DEVTEMPLATE_ID(,_config));						break;
#endif
		case DEVINFO_INT_CLASS:					info->i = DEVTEMPLATE_CLASS;									break;
#ifdef DEVTEMPLATE_ENDIANNESS
		case DEVINFO_INT_ENDIANNESS:			info->i = DEVTEMPLATE_ENDIANNESS;								break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_PROGRAM_SPACE)
		case DEVINFO_INT_DATABUS_WIDTH_0:		info->i = DEVTEMPLATE_PGM_DATAWIDTH;							break;
		case DEVINFO_INT_ADDRBUS_WIDTH_0:		info->i = DEVTEMPLATE_PGM_ADDRWIDTH;							break;
#ifdef DEVTEMPLATE_PGM_ADDRSHIFT
		case DEVINFO_INT_ADDRBUS_SHIFT_0:		info->i = DEVTEMPLATE_PGM_ADDRSHIFT;							break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_DATA_SPACE)
		case DEVINFO_INT_DATABUS_WIDTH_1:		info->i = DEVTEMPLATE_DATA_DATAWIDTH;							break;
		case DEVINFO_INT_ADDRBUS_WIDTH_1:		info->i = DEVTEMPLATE_DATA_ADDRWIDTH;							break;
#ifdef DEVTEMPLATE_DATA_ADDRSHIFT
		case DEVINFO_INT_ADDRBUS_SHIFT_1:		info->i = DEVTEMPLATE_DATA_ADDRSHIFT;							break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_IO_SPACE)
		case DEVINFO_INT_DATABUS_WIDTH_2:		info->i = DEVTEMPLATE_IO_DATAWIDTH;								break;
		case DEVINFO_INT_ADDRBUS_WIDTH_2:		info->i = DEVTEMPLATE_IO_ADDRWIDTH;								break;
#ifdef DEVTEMPLATE_IO_ADDRSHIFT
		case DEVINFO_INT_ADDRBUS_SHIFT_2:		info->i = DEVTEMPLATE_IO_ADDRSHIFT;								break;
#endif
#endif

		/* --- the following bits of info are returned as pointers --- */
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_ROM_REGION)
		case DEVINFO_PTR_ROM_REGION:			info->romregion = DEVTEMPLATE_ID1(ROM_NAME());						break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_MACHINE_CONFIG)
		case DEVINFO_PTR_MACHINE_CONFIG:		info->machine_config = DEVTEMPLATE_ID1(MACHINE_DRIVER_NAME());		break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_CONTRACT_LIST)
		case DEVINFO_PTR_CONTRACT_LIST:			info->contract_list = DEVTEMPLATE_ID1(DEVICE_CONTRACT_LIST_NAME());	break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_PROGRAM_SPACE)
#ifdef DEVTEMPLATE_PGM_INTMAP
		case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0:	info->p = (void *)DEVTEMPLATE_PGM_INTMAP;							break;
#endif
#ifdef DEVTEMPLATE_PGM_DEFMAP
		case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0:	info->p = (void *)DEVTEMPLATE_PGM_DEFMAP;							break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_DATA_SPACE)
#ifdef DEVTEMPLATE_DATA_INTMAP
		case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0:	info->p = (void *)DEVTEMPLATE_DATA_INTMAP;							break;
#endif
#ifdef DEVTEMPLATE_DATA_DEFMAP
		case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0:	info->p = (void *)DEVTEMPLATE_DATA_DEFMAP;							break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_IO_SPACE)
#ifdef DEVTEMPLATE_IO_INTMAP
		case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0:	info->p = (void *)DEVTEMPLATE_IO_INTMAP;							break;
#endif
#ifdef DEVTEMPLATE_IO_DEFMAP
		case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0:	info->p = (void *)DEVTEMPLATE_IO_DEFMAP;							break;
#endif
#endif


		/* --- the following bits of info are returned as pointers to data or functions --- */
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_START)
		case DEVINFO_FCT_START:					info->start = DEVTEMPLATE_ID1(DEVICE_START_NAME()); 					break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_RESET)
		case DEVINFO_FCT_RESET:					info->reset = DEVTEMPLATE_ID1(DEVICE_RESET_NAME()); 					break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_STOP)
		case DEVINFO_FCT_STOP:					info->stop = DEVTEMPLATE_ID1(DEVICE_STOP_NAME());					break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_EXECUTE)
		case DEVINFO_FCT_EXECUTE:				info->execute = DEVTEMPLATE_ID1(DEVICE_EXECUTE_NAME()); 				break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_NVRAM)
		case DEVINFO_FCT_NVRAM:					info->nvram = DEVTEMPLATE_ID1(DEVICE_NVRAM_NAME()); 					break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_VALIDITY_CHECK)
		case DEVINFO_FCT_VALIDITY_CHECK:		info->validity_check = DEVTEMPLATE_ID1(DEVICE_VALIDITY_CHECK_NAME());	break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_CUSTOM_CONFIG)
		case DEVINFO_FCT_CUSTOM_CONFIG:			info->custom_config = DEVTEMPLATE_ID1(DEVICE_CUSTOM_CONFIG_NAME());	break;
#endif

		/* --- the following bits of info are returned as NULL-terminated strings --- */
		case DEVINFO_STR_NAME:					strcpy(info->s, DEVTEMPLATE_NAME);								break;
		case DEVINFO_STR_FAMILY:				strcpy(info->s, DEVTEMPLATE_FAMILY);							break;
		case DEVINFO_STR_VERSION:				strcpy(info->s, DEVTEMPLATE_VERSION);							break;
		case DEVINFO_STR_SOURCE_FILE:			strcpy(info->s, DEVTEMPLATE_SOURCE);							break;
		case DEVINFO_STR_CREDITS:				strcpy(info->s, DEVTEMPLATE_CREDITS);							break;
	}
}


/* derived device case */
#else

/* declare callback functions */
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_START)
static DEVICE_START( DEVTEMPLATE_DERIVED_ID(,) );
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_RESET)
static DEVICE_RESET( DEVTEMPLATE_DERIVED_ID(,) );
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_STOP)
static DEVICE_STOP( DEVTEMPLATE_DERIVED_ID(,) );
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_EXECUTE)
static DEVICE_EXECUTE( DEVTEMPLATE_DERIVED_ID(,) );
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_NVRAM)
static DEVICE_NVRAM( DEVTEMPLATE_DERIVED_ID(,) );
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_VALIDITY_CHECK)
static DEVICE_VALIDITY_CHECK( DEVTEMPLATE_DERIVED_ID(,) );
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_CUSTOM_CONFIG)
static DEVICE_CUSTOM_CONFIG( DEVTEMPLATE_DERIVED_ID(,) );
#endif

/* the actual get_info function */
DEVICE_GET_INFO( DEVTEMPLATE_DERIVED_ID(,) )
{
	switch (state)
	{
		/* --- the following bits of info are returned as 64-bit signed integers --- */
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_PROGRAM_SPACE)
		case DEVINFO_INT_DATABUS_WIDTH_0:		info->i = DEVTEMPLATE_DERIVED_PGM_DATAWIDTH;					break;
		case DEVINFO_INT_ADDRBUS_WIDTH_0:		info->i = DEVTEMPLATE_DERIVED_PGM_ADDRWIDTH;					break;
#ifdef DEVTEMPLATE_PGM_ADDRSHIFT
		case DEVINFO_INT_ADDRBUS_SHIFT_0:		info->i = DEVTEMPLATE_DERIVED_PGM_ADDRSHIFT;					break;
#endif
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_DATA_SPACE)
		case DEVINFO_INT_DATABUS_WIDTH_1:		info->i = DEVTEMPLATE_DERIVED_DATA_DATAWIDTH;					break;
		case DEVINFO_INT_ADDRBUS_WIDTH_1:		info->i = DEVTEMPLATE_DERIVED_DATA_ADDRWIDTH;					break;
#ifdef DEVTEMPLATE_DATA_ADDRSHIFT
		case DEVINFO_INT_ADDRBUS_SHIFT_1:		info->i = DEVTEMPLATE_DERIVED_DATA_ADDRSHIFT;					break;
#endif
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_IO_SPACE)
		case DEVINFO_INT_DATABUS_WIDTH_2:		info->i = DEVTEMPLATE_DERIVED_IO_DATAWIDTH;					break;
		case DEVINFO_INT_ADDRBUS_WIDTH_2:		info->i = DEVTEMPLATE_DERIVED_IO_ADDRWIDTH;					break;
#ifdef DEVTEMPLATE_IO_ADDRSHIFT
		case DEVINFO_INT_ADDRBUS_SHIFT_2:		info->i = DEVTEMPLATE_DERIVED_IO_ADDRSHIFT;					break;
#endif
#endif

		/* --- the following bits of info are returned as pointers --- */
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_ROM_REGION)
		case DEVINFO_PTR_ROM_REGION:			info->romregion = DEVTEMPLATE_DERIVED_ID1(ROM_NAME());						break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_MACHINE_CONFIG)
		case DEVINFO_PTR_MACHINE_CONFIG:		info->machine_config = DEVTEMPLATE_DERIVED_ID1(MACHINE_DRIVER_NAME());		break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_CONTRACT_LIST)
		case DEVINFO_PTR_CONTRACT_LIST:			info->contract_list = DEVTEMPLATE_DERIVED_ID1(DEVICE_CONTRACT_LIST_NAME()); 			break;
#endif

		/* --- the following bits of info are returned as pointers to data or functions --- */
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_START)
		case DEVINFO_FCT_START:					info->start = DEVTEMPLATE_DERIVED_ID1(DEVICE_START_NAME()); 					break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_RESET)
		case DEVINFO_FCT_RESET:					info->reset = DEVTEMPLATE_DERIVED_ID1(DEVICE_RESET_NAME()); 					break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_STOP)
		case DEVINFO_FCT_STOP:					info->stop = DEVTEMPLATE_DERIVED_ID1(DEVICE_STORE_NAME());					break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_EXECUTE)
		case DEVINFO_FCT_EXECUTE:				info->execute = DEVTEMPLATE_DERIVED_ID1(DEVICE_EXECUTE_NAME()); 				break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_NVRAM)
		case DEVINFO_FCT_NVRAM:					info->nvram = DEVTEMPLATE_DERIVED_ID1(DEVICE_NVRAM_NAME()); 					break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_VALIDITY_CHECK)
		case DEVINFO_FCT_VALIDITY_CHECK:		info->validity_check = DEVTEMPLATE_DERIVED_ID1(DEVICE_VALIDITY_CHECK_NAME()); break;
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_CUSTOM_CONFIG)
		case DEVINFO_FCT_CUSTOM_CONFIG:			info->custom_config = DEVTEMPLATE_DERIVED_ID1(DEVICE_CUSTOM_CONFIG_NAME()); 	break;
#endif

		/* --- the following bits of info are returned as NULL-terminated strings --- */
		case DEVINFO_STR_NAME:					strcpy(info->s, DEVTEMPLATE_DERIVED_NAME);								break;
		default:								DEVICE_GET_INFO_CALL(DEVTEMPLATE_ID(,));								break;
	}
}

#endif



#undef DT_HAS_RESET
#undef DT_HAS_STOP
#undef DT_HAS_EXECUTE
#undef DT_HAS_NVRAM
#undef DT_HAS_VALIDITY_CHECK
#undef DT_HAS_CUSTOM_CONFIG
#undef DT_HAS_ROM_REGION
#undef DT_HAS_MACHINE_CONFIG
#undef DT_HAS_INLINE_CONFIG
#undef DT_HAS_CONTRACT_LIST
#undef DT_HAS_PROGRAM_SPACE
#undef DT_HAS_DATA_SPACE
#undef DT_HAS_IO_SPACE

#undef DEVTEMPLATE_DERIVED_ID
#undef DEVTEMPLATE_DERIVED_FEATURES
#undef DEVTEMPLATE_DERIVED_NAME