summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/mconfig.h
blob: c5228374dde2f299b59c90909132a063e975a64d (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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
/***************************************************************************

    mconfig.h

    Machine configuration macros and functions.

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

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

#pragma once

#ifndef __MCONFIG_H__
#define __MCONFIG_H__

#include "devintrf.h"
#include "cpuexec.h"
#include "sndintrf.h"
#include <stddef.h>


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

/* by convention, tags should all lowercase and this length or less */
#define MAX_TAG_LENGTH			15


/* token types */
enum
{
	MCONFIG_TOKEN_INVALID,
	MCONFIG_TOKEN_END,
	MCONFIG_TOKEN_INCLUDE,

	MCONFIG_TOKEN_DEVICE_ADD,
	MCONFIG_TOKEN_DEVICE_REMOVE,
	MCONFIG_TOKEN_DEVICE_REPLACE,
	MCONFIG_TOKEN_DEVICE_MODIFY,
	MCONFIG_TOKEN_DEVICE_CLOCK,
	MCONFIG_TOKEN_DEVICE_CONFIG,
	MCONFIG_TOKEN_DEVICE_CONFIG_DATA32,
	MCONFIG_TOKEN_DEVICE_CONFIG_DATA64,
	MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32,
	MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP64,

	MCONFIG_TOKEN_DRIVER_DATA,
	MCONFIG_TOKEN_QUANTUM_TIME,
	MCONFIG_TOKEN_QUANTUM_PERFECT_CPU,
	MCONFIG_TOKEN_WATCHDOG_VBLANK,
	MCONFIG_TOKEN_WATCHDOG_TIME,

	MCONFIG_TOKEN_MACHINE_START,
	MCONFIG_TOKEN_MACHINE_RESET,
	MCONFIG_TOKEN_NVRAM_HANDLER,
	MCONFIG_TOKEN_MEMCARD_HANDLER,

	MCONFIG_TOKEN_VIDEO_ATTRIBUTES,
	MCONFIG_TOKEN_GFXDECODE,
	MCONFIG_TOKEN_PALETTE_LENGTH,
	MCONFIG_TOKEN_DEFAULT_LAYOUT,

	MCONFIG_TOKEN_PALETTE_INIT,
	MCONFIG_TOKEN_VIDEO_START,
	MCONFIG_TOKEN_VIDEO_RESET,
	MCONFIG_TOKEN_VIDEO_EOF,
	MCONFIG_TOKEN_VIDEO_UPDATE,

	MCONFIG_TOKEN_SOUND_START,
	MCONFIG_TOKEN_SOUND_RESET,

	MCONFIG_TOKEN_SOUND_ADD,
	MCONFIG_TOKEN_SOUND_REMOVE,
	MCONFIG_TOKEN_SOUND_MODIFY,
	MCONFIG_TOKEN_SOUND_CONFIG,
	MCONFIG_TOKEN_SOUND_REPLACE,
	MCONFIG_TOKEN_SOUND_ROUTE,
};


/* ----- flags for video_attributes ----- */

/* should VIDEO_UPDATE by called at the start of VBLANK or at the end? */
#define	VIDEO_UPDATE_BEFORE_VBLANK		0x0000
#define	VIDEO_UPDATE_AFTER_VBLANK		0x0004

/* indicates VIDEO_UPDATE will add container bits its */
#define VIDEO_SELF_RENDER				0x0008

/* automatically extend the palette creating a darker copy for shadows */
#define VIDEO_HAS_SHADOWS				0x0010

/* automatically extend the palette creating a brighter copy for highlights */
#define VIDEO_HAS_HIGHLIGHTS			0x0020

/* Mish 181099:  See comments in video/generic.c for details */
#define VIDEO_BUFFERS_SPRITERAM			0x0040

/* force VIDEO_UPDATE to be called even for skipped frames */
#define VIDEO_ALWAYS_UPDATE				0x0080

/* calls VIDEO_UPDATE for every visible scanline, even for skipped frames */
#define VIDEO_UPDATE_SCANLINE			0x0100



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

/* In mamecore.h: typedef struct _machine_config machine_config; */
struct _machine_config
{
	UINT32					driver_data_size;		/* amount of memory needed for driver_data */

	attotime				minimum_quantum;		/* minimum scheduling quantum */
	const char *			perfect_cpu_quantum;	/* tag of CPU to use for "perfect" scheduling */
	INT32					watchdog_vblank_count;	/* number of VBLANKs until the watchdog kills us */
	attotime				watchdog_time;			/* length of time until the watchdog kills us */

	machine_start_func		machine_start;			/* one-time machine start callback */
	machine_reset_func		machine_reset;			/* machine reset callback */

	nvram_handler_func		nvram_handler;			/* NVRAM save/load callback  */
	memcard_handler_func	memcard_handler;		/* memory card save/load callback  */

	UINT32					video_attributes;		/* flags describing the video system */
	const gfx_decode_entry *gfxdecodeinfo;			/* pointer to array of graphics decoding information */
	UINT32					total_colors;			/* total number of colors in the palette */
	const char *			default_layout;			/* default layout for this machine */

	palette_init_func		init_palette;			/* one-time palette init callback  */
	video_start_func		video_start;			/* one-time video start callback */
	video_reset_func		video_reset;			/* video reset callback */
	video_eof_func			video_eof;				/* end-of-frame video callback */
	video_update_func 		video_update; 			/* video update callback */

	sound_config			sound[MAX_SOUND];		/* array of sound chips in the system */
	astring *				soundtag[MAX_SOUND];	/* allocated strings for each sound tag */

	sound_start_func		sound_start;			/* one-time sound start callback */
	sound_reset_func		sound_reset;			/* sound reset callback */

	device_config *			devicelist;				/* list head for devices */
};



/***************************************************************************
    MACROS FOR BUILDING MACHINE DRIVERS
***************************************************************************/

/* this type is used to encode machine configuration definitions */
typedef union _machine_config_token machine_config_token;
union _machine_config_token
{
	TOKEN_COMMON_FIELDS
	const machine_config_token *tokenptr;
	const gfx_decode_entry *gfxdecode;
	const addrmap_token *addrmap;
	device_type devtype;
	driver_init_func driver_init;
	nvram_handler_func nvram_handler;
	memcard_handler_func memcard_handler;
	machine_start_func machine_start;
	machine_reset_func machine_reset;
	sound_start_func sound_start;
	sound_reset_func sound_reset;
	video_start_func video_start;
	video_reset_func video_reset;
	palette_init_func palette_init;
	video_eof_func video_eof;
	video_update_func video_update;
	sound_type sndtype;
};



/* start/end tags for the machine driver */
#define MACHINE_DRIVER_NAME(_name) \
	machine_config_##_name

#define MACHINE_DRIVER_START(_name) \
	const machine_config_token MACHINE_DRIVER_NAME(_name)[] = {

#define MACHINE_DRIVER_END \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_END, 8) };

/* use this to declare external references to a machine driver */
#define MACHINE_DRIVER_EXTERN(_name) \
	extern const machine_config_token machine_config_##_name[]


/* importing data from other machine drivers */
#define MDRV_IMPORT_FROM(_name) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_INCLUDE, 8), \
	TOKEN_PTR(tokenptr, machine_config_##_name),


/* add/remove/config devices */
#define MDRV_DEVICE_ADD(_tag, _type, _clock) \
	TOKEN_UINT64_PACK2(MCONFIG_TOKEN_DEVICE_ADD, 8, _clock, 32), \
	TOKEN_PTR(devtype, _type), \
	TOKEN_STRING(_tag),

#define MDRV_DEVICE_REMOVE(_tag, _type) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_REMOVE, 8), \
	TOKEN_PTR(devtype, _type), \
	TOKEN_STRING(_tag),

#define MDRV_DEVICE_MODIFY(_tag, _type)	\
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_MODIFY, 8), \
	TOKEN_PTR(devtype, _type), \
	TOKEN_STRING(_tag),

#define MDRV_DEVICE_CONFIG(_config) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_CONFIG, 8), \
	TOKEN_PTR(voidptr, &(_config)),

#define MDRV_DEVICE_CLOCK(_clock) \
	TOKEN_UINT64_PACK2(MCONFIG_TOKEN_DEVICE_CLOCK, 8, _clock, 32),

#define structsizeof(_struct, _field) sizeof(((_struct *)NULL)->_field)

#define MDRV_DEVICE_CONFIG_DATA32_EXPLICIT(_size, _offset, _val) \
	TOKEN_UINT32_PACK3(MCONFIG_TOKEN_DEVICE_CONFIG_DATA32, 8, (_size), 6, (_offset), 12), \
	TOKEN_UINT32((UINT32)(_val)),

#define MDRV_DEVICE_CONFIG_DATA32(_struct, _field, _val) \
	MDRV_DEVICE_CONFIG_DATA32_EXPLICIT(structsizeof(_struct, _field), offsetof(_struct, _field), _val)

#define MDRV_DEVICE_CONFIG_DATA32_ARRAY(_struct, _field, _index, _val) \
	MDRV_DEVICE_CONFIG_DATA32_EXPLICIT(structsizeof(_struct, _field[0]), offsetof(_struct, _field) + (_index) * structsizeof(_struct, _field[0]), _val)

#define MDRV_DEVICE_CONFIG_DATA32_ARRAY_MEMBER(_struct, _field, _index, _memstruct, _member, _val) \
	MDRV_DEVICE_CONFIG_DATA32_EXPLICIT(structsizeof(_memstruct, _member), offsetof(_struct, _field) + (_index) * structsizeof(_struct, _field[0]) + offsetof(_memstruct, _member), _val)

#define MDRV_DEVICE_CONFIG_DATA64_EXPLICIT(_size, _offset, _val) \
	TOKEN_UINT32_PACK3(MCONFIG_TOKEN_DEVICE_CONFIG_DATA64, 8, (_size), 6, (_offset), 12), \
	TOKEN_UINT64((UINT64)(_val)),

#define MDRV_DEVICE_CONFIG_DATA64(_struct, _field, _val) \
	MDRV_DEVICE_CONFIG_DATA64_EXPLICIT(structsizeof(_struct, _field), offsetof(_struct, _field), _val)

#define MDRV_DEVICE_CONFIG_DATA64_ARRAY(_struct, _field, _index, _val) \
	MDRV_DEVICE_CONFIG_DATA64_EXPLICIT(structsizeof(_struct, _field[0]), offsetof(_struct, _field) + (_index) * structsizeof(_struct, _field[0]), _val)

#define MDRV_DEVICE_CONFIG_DATA64_ARRAY_MEMBER(_struct, _field, _index, _memstruct, _member, _val) \
	MDRV_DEVICE_CONFIG_DATA64_EXPLICIT(structsizeof(_memstruct, _member), offsetof(_struct, _field) + (_index) * structsizeof(_struct, _field[0]) + offsetof(_memstruct, _member), _val)

#define MDRV_DEVICE_CONFIG_DATAFP32(_struct, _field, _val, _fixbits) \
	TOKEN_UINT32_PACK4(MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32, 8, structsizeof(_struct, _field), 6, _fixbits, 6, offsetof(_struct, _field), 12), \
	TOKEN_UINT32((INT32)((float)(_val) * (float)(1 << (_fixbits)))),

#define MDRV_DEVICE_CONFIG_DATAFP64(_struct, _field, _val, _fixbits) \
	TOKEN_UINT32_PACK4(MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP64, 8, structsizeof(_struct, _field), 6, _fixbits, 6, offsetof(_struct, _field), 12), \
	TOKEN_UINT64((INT64)((float)(_val) * (float)((UINT64)1 << (_fixbits)))),

#ifdef PTR64
#define MDRV_DEVICE_CONFIG_DATAPTR_EXPLICIT(_struct, _size, _offset) MDRV_DEVICE_CONFIG_DATA64_EXPLICIT(_struct, _size, _offset)
#define MDRV_DEVICE_CONFIG_DATAPTR(_struct, _field, _val) MDRV_DEVICE_CONFIG_DATA64(_struct, _field, _val)
#define MDRV_DEVICE_CONFIG_DATAPTR_ARRAY(_struct, _field, _index, _val) MDRV_DEVICE_CONFIG_DATA64_ARRAY(_struct, _field, _index, _val)
#define MDRV_DEVICE_CONFIG_DATAPTR_ARRAY_MEMBER(_struct, _field, _index, _memstruct, _member, _val) MDRV_DEVICE_CONFIG_DATA64_ARRAY_MEMBER(_struct, _field, _index, _memstruct, _member, _val)
#else
#define MDRV_DEVICE_CONFIG_DATAPTR_EXPLICIT(_struct, _size, _offset) MDRV_DEVICE_CONFIG_DATA32_EXPLICIT(_struct, _size, _offset)
#define MDRV_DEVICE_CONFIG_DATAPTR(_struct, _field, _val) MDRV_DEVICE_CONFIG_DATA32(_struct, _field, _val)
#define MDRV_DEVICE_CONFIG_DATAPTR_ARRAY(_struct, _field, _index, _val) MDRV_DEVICE_CONFIG_DATA32_ARRAY(_struct, _field, _index, _val)
#define MDRV_DEVICE_CONFIG_DATAPTR_ARRAY_MEMBER(_struct, _field, _index, _memstruct, _member, _val) MDRV_DEVICE_CONFIG_DATA32_ARRAY_MEMBER(_struct, _field, _index, _memstruct, _member, _val)
#endif


/* core parameters */
#define MDRV_DRIVER_DATA(_struct) \
	TOKEN_UINT32_PACK2(MCONFIG_TOKEN_DRIVER_DATA, 8, sizeof(_struct), 24),

#define MDRV_QUANTUM_TIME(_time) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_QUANTUM_TIME, 8), \
	TOKEN_UINT64(UINT64_ATTOTIME_IN_##_time),

#define MDRV_QUANTUM_PERFECT_CPU(_cputag) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_QUANTUM_PERFECT_CPU, 8), \
	TOKEN_STRING(_cputag),

#define MDRV_WATCHDOG_VBLANK_INIT(_count) \
	TOKEN_UINT32_PACK2(MCONFIG_TOKEN_WATCHDOG_VBLANK, 8, _count, 24),

#define MDRV_WATCHDOG_TIME_INIT(_time) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_WATCHDOG_TIME, 8), \
	TOKEN_UINT64(UINT64_ATTOTIME_IN_##_time),


/* core functions */
#define MDRV_MACHINE_START(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MACHINE_START, 8), \
	TOKEN_PTR(machine_start, machine_start_##_func),

#define MDRV_MACHINE_RESET(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MACHINE_RESET, 8), \
	TOKEN_PTR(machine_reset, machine_reset_##_func),

#define MDRV_NVRAM_HANDLER(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_NVRAM_HANDLER, 8), \
	TOKEN_PTR(nvram_handler, nvram_handler_##_func),

#define MDRV_MEMCARD_HANDLER(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MEMCARD_HANDLER, 8), \
	TOKEN_PTR(memcard_handler, memcard_handler_##_func),


/* core video parameters */
#define MDRV_VIDEO_ATTRIBUTES(_flags) \
	TOKEN_UINT32_PACK2(MCONFIG_TOKEN_VIDEO_ATTRIBUTES, 8, _flags, 24),

#define MDRV_GFXDECODE(_gfx) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_GFXDECODE, 8), \
	TOKEN_PTR(gfxdecode, gfxdecodeinfo_##_gfx),

#define MDRV_PALETTE_LENGTH(_length) \
	TOKEN_UINT32_PACK2(MCONFIG_TOKEN_PALETTE_LENGTH, 8, _length, 24),

#define MDRV_DEFAULT_LAYOUT(_layout) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEFAULT_LAYOUT, 8), \
	TOKEN_STRING(&(_layout)[0]),


/* core video functions */
#define MDRV_PALETTE_INIT(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_PALETTE_INIT, 8), \
	TOKEN_PTR(palette_init, palette_init_##_func),

#define MDRV_VIDEO_START(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_START, 8), \
	TOKEN_PTR(video_start, video_start_##_func),

#define MDRV_VIDEO_RESET(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_RESET, 8), \
	TOKEN_PTR(video_reset, video_reset_##_func),

#define MDRV_VIDEO_EOF(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_EOF, 8), \
	TOKEN_PTR(video_eof, video_eof_##_func),

#define MDRV_VIDEO_UPDATE(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_UPDATE, 8), \
	TOKEN_PTR(video_update, video_update_##_func),


/* add/remove speakers */
#define MDRV_SPEAKER_ADD(_tag, _x, _y, _z) \
	MDRV_DEVICE_ADD(_tag, SPEAKER_OUTPUT, 0) \
	MDRV_DEVICE_CONFIG_DATAFP32(speaker_config, x, _x, 24) \
	MDRV_DEVICE_CONFIG_DATAFP32(speaker_config, y, _y, 24) \
	MDRV_DEVICE_CONFIG_DATAFP32(speaker_config, z, _z, 24)

#define MDRV_SPEAKER_REMOVE(_tag) \
	MDRV_DEVICE_REMOVE(_tag, SPEAKER_OUTPUT)

#define MDRV_SPEAKER_STANDARD_MONO(_tag) \
	MDRV_SPEAKER_ADD(_tag, 0.0, 0.0, 1.0)

#define MDRV_SPEAKER_STANDARD_STEREO(_tagl, _tagr) \
	MDRV_SPEAKER_ADD(_tagl, -0.2, 0.0, 1.0) \
	MDRV_SPEAKER_ADD(_tagr, 0.2, 0.0, 1.0)


/* core sound functions */
#define MDRV_SOUND_START(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_START, 8), \
	TOKEN_PTR(sound_start, sound_start_##_func),

#define MDRV_SOUND_RESET(_func) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_RESET, 8), \
	TOKEN_PTR(sound_start, sound_reset_##_func),


/* add/remove/replace sounds */
#define MDRV_SOUND_ADD(_tag, _type, _clock) \
	TOKEN_UINT64_PACK2(MCONFIG_TOKEN_SOUND_ADD, 8, _clock, 32), \
	TOKEN_PTR(sndtype, SOUND_##_type), \
	TOKEN_STRING(_tag),

#define MDRV_SOUND_REMOVE(_tag) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_REMOVE, 8), \
	TOKEN_STRING(_tag),

#define MDRV_SOUND_MODIFY(_tag) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_MODIFY, 8), \
	TOKEN_STRING(_tag),

#define MDRV_SOUND_CONFIG(_config) \
	TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_CONFIG, 8), \
	TOKEN_PTR(voidptr, &(_config)),

#define MDRV_SOUND_REPLACE(_tag, _type, _clock) \
	TOKEN_UINT64_PACK2(MCONFIG_TOKEN_SOUND_REPLACE, 8, _clock, 32), \
	TOKEN_PTR(sndtype, SOUND_##_type), \
	TOKEN_STRING(_tag),

#define MDRV_SOUND_ROUTE_EX(_output, _target, _gain, _input)			\
	TOKEN_UINT64_PACK4(MCONFIG_TOKEN_SOUND_ROUTE, 8, _output, 12, _input, 12, (UINT32)((float)(_gain) * 16777216.0f), 32), \
	TOKEN_STRING(_target),

#define MDRV_SOUND_ROUTE(_output, _target, _gain) \
	MDRV_SOUND_ROUTE_EX(_output, _target, _gain, -1)



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


/* ----- machine configurations ----- */

/* allocate a new machine configuration and populate it using the supplied constructor */
machine_config *machine_config_alloc(const machine_config_token *tokens);

/* release memory allocated for a machine configuration */
void machine_config_free(machine_config *config);


#endif	/* __MCONFIG_H__ */