summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/devintrf.h
blob: b82590bccabf847cf8c616cd9347133debfc7b97 (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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/***************************************************************************

    devintrf.h

    Device interface functions.

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

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

#pragma once

#ifndef __EMU_H__
#error Dont include this file directly; include emu.h instead.
#endif

#ifndef __DEVINTRF_H__
#define __DEVINTRF_H__



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

/* forward references */
struct rom_entry;
union machine_config_token;


/* device classes */
enum device_class
{
	DEVICE_CLASS_GENERAL = 0,			/* default class for general devices */
	DEVICE_CLASS_PERIPHERAL,			/* peripheral devices: PIAs, timers, etc. */
	DEVICE_CLASS_AUDIO,					/* audio devices (not sound chips), including speakers */
	DEVICE_CLASS_VIDEO,					/* video devices, including screens */
	DEVICE_CLASS_CPU_CHIP,				/* CPU chips; only CPU cores should return this class */
	DEVICE_CLASS_SOUND_CHIP,			/* sound chips; only sound cores should return this class */
	DEVICE_CLASS_TIMER,					/* timer devices */
	DEVICE_CLASS_OTHER					/* anything else (the list may expand in the future) */
};


/* useful in device_list functions for scanning through all devices */
#define DEVICE_TYPE_WILDCARD			NULL


/* state constants passed to the device_get_config_func */
enum
{
	/* --- the following bits of info are returned as 64-bit signed integers --- */
	DEVINFO_INT_FIRST = 0x00000,

		DEVINFO_INT_TOKEN_BYTES = DEVINFO_INT_FIRST,	/* R/O: bytes to allocate for the token */
		DEVINFO_INT_INLINE_CONFIG_BYTES,				/* R/O: bytes to allocate for the inline configuration */
		DEVINFO_INT_CLASS,								/* R/O: the device's class */

		DEVINFO_INT_ENDIANNESS,							/* R/O: either ENDIANNESS_BIG or ENDIANNESS_LITTLE */
		DEVINFO_INT_DATABUS_WIDTH,						/* R/O: data bus size for each address space (8,16,32,64) */
		DEVINFO_INT_DATABUS_WIDTH_0 = DEVINFO_INT_DATABUS_WIDTH + 0,
		DEVINFO_INT_DATABUS_WIDTH_1 = DEVINFO_INT_DATABUS_WIDTH + 1,
		DEVINFO_INT_DATABUS_WIDTH_2 = DEVINFO_INT_DATABUS_WIDTH + 2,
		DEVINFO_INT_DATABUS_WIDTH_3 = DEVINFO_INT_DATABUS_WIDTH + 3,
		DEVINFO_INT_DATABUS_WIDTH_LAST = DEVINFO_INT_DATABUS_WIDTH + ADDRESS_SPACES - 1,
		DEVINFO_INT_ADDRBUS_WIDTH,						/* R/O: address bus size for each address space (12-32) */
		DEVINFO_INT_ADDRBUS_WIDTH_0 = DEVINFO_INT_ADDRBUS_WIDTH + 0,
		DEVINFO_INT_ADDRBUS_WIDTH_1 = DEVINFO_INT_ADDRBUS_WIDTH + 1,
		DEVINFO_INT_ADDRBUS_WIDTH_2 = DEVINFO_INT_ADDRBUS_WIDTH + 2,
		DEVINFO_INT_ADDRBUS_WIDTH_3 = DEVINFO_INT_ADDRBUS_WIDTH + 3,
		DEVINFO_INT_ADDRBUS_WIDTH_LAST = DEVINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACES - 1,
		DEVINFO_INT_ADDRBUS_SHIFT,						/* R/O: shift applied to addresses each address space (+3 means >>3, -1 means <<1) */
		DEVINFO_INT_ADDRBUS_SHIFT_0 = DEVINFO_INT_ADDRBUS_SHIFT + 0,
		DEVINFO_INT_ADDRBUS_SHIFT_1 = DEVINFO_INT_ADDRBUS_SHIFT + 1,
		DEVINFO_INT_ADDRBUS_SHIFT_2 = DEVINFO_INT_ADDRBUS_SHIFT + 2,
		DEVINFO_INT_ADDRBUS_SHIFT_3 = DEVINFO_INT_ADDRBUS_SHIFT + 3,
		DEVINFO_INT_ADDRBUS_SHIFT_LAST = DEVINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACES - 1,

	DEVINFO_INT_CLASS_SPECIFIC = 0x04000,				/* R/W: device-specific values start here */
	DEVINFO_INT_DEVICE_SPECIFIC = 0x08000,				/* R/W: device-specific values start here */
	DEVINFO_INT_LAST = 0x0ffff,

	/* --- the following bits of info are returned as pointers --- */
	DEVINFO_PTR_FIRST = 0x10000,

		DEVINFO_PTR_ROM_REGION = DEVINFO_PTR_FIRST,		/* R/O: pointer to device-specific ROM region */
		DEVINFO_PTR_MACHINE_CONFIG,						/* R/O: pointer to device-specific machine config */
		DEVINFO_PTR_CONTRACT_LIST,						/* R/O: pointer to list of supported device contracts */

		DEVINFO_PTR_INTERNAL_MEMORY_MAP,				/* R/O: const addrmap_token *map */
		DEVINFO_PTR_INTERNAL_MEMORY_MAP_0 = DEVINFO_PTR_INTERNAL_MEMORY_MAP + 0,
		DEVINFO_PTR_INTERNAL_MEMORY_MAP_1 = DEVINFO_PTR_INTERNAL_MEMORY_MAP + 1,
		DEVINFO_PTR_INTERNAL_MEMORY_MAP_2 = DEVINFO_PTR_INTERNAL_MEMORY_MAP + 2,
		DEVINFO_PTR_INTERNAL_MEMORY_MAP_3 = DEVINFO_PTR_INTERNAL_MEMORY_MAP + 3,
		DEVINFO_PTR_INTERNAL_MEMORY_MAP_LAST = DEVINFO_PTR_INTERNAL_MEMORY_MAP + ADDRESS_SPACES - 1,

		DEVINFO_PTR_DEFAULT_MEMORY_MAP,					/* R/O: const addrmap_token *map */
		DEVINFO_PTR_DEFAULT_MEMORY_MAP_0 = DEVINFO_PTR_DEFAULT_MEMORY_MAP + 0,
		DEVINFO_PTR_DEFAULT_MEMORY_MAP_1 = DEVINFO_PTR_DEFAULT_MEMORY_MAP + 1,
		DEVINFO_PTR_DEFAULT_MEMORY_MAP_2 = DEVINFO_PTR_DEFAULT_MEMORY_MAP + 2,
		DEVINFO_PTR_DEFAULT_MEMORY_MAP_3 = DEVINFO_PTR_DEFAULT_MEMORY_MAP + 3,
		DEVINFO_PTR_DEFAULT_MEMORY_MAP_LAST = DEVINFO_PTR_DEFAULT_MEMORY_MAP + ADDRESS_SPACES - 1,

	DEVINFO_PTR_CLASS_SPECIFIC = 0x14000,				/* R/W: device-specific values start here */
	DEVINFO_PTR_DEVICE_SPECIFIC = 0x18000,				/* R/W: device-specific values start here */
	DEVINFO_PTR_LAST = 0x1ffff,

	/* --- the following bits of info are returned as pointers to functions --- */
	DEVINFO_FCT_FIRST = 0x20000,

		DEVINFO_FCT_START = DEVINFO_FCT_FIRST,			/* R/O: device_start_func */
		DEVINFO_FCT_STOP,								/* R/O: device_stop_func */
		DEVINFO_FCT_RESET,								/* R/O: device_reset_func */
		DEVINFO_FCT_EXECUTE,							/* R/O: device_execute_func */
		DEVINFO_FCT_VALIDITY_CHECK,						/* R/O: device_validity_check_func */
		DEVINFO_FCT_NVRAM,								/* R/O: device_nvram_func */
		DEVINFO_FCT_CUSTOM_CONFIG,						/* R/O: device_custom_config_func */
		DEVINFO_FCT_GET_RUNTIME_INFO,					/* R/O: device_get_runtime_info_func */

	DEVINFO_FCT_CLASS_SPECIFIC = 0x24000,				/* R/W: device-specific values start here */
	DEVINFO_FCT_DEVICE_SPECIFIC = 0x28000,				/* R/W: device-specific values start here */
	DEVINFO_FCT_LAST = 0x2ffff,

	/* --- the following bits of info are returned as NULL-terminated strings --- */
	DEVINFO_STR_FIRST = 0x30000,

		DEVINFO_STR_NAME = DEVINFO_STR_FIRST,			/* R/O: name of the device */
		DEVINFO_STR_FAMILY,								/* R/O: family of the device */
		DEVINFO_STR_VERSION,							/* R/O: version of the device */
		DEVINFO_STR_SOURCE_FILE,						/* R/O: file containing the device implementation */
		DEVINFO_STR_CREDITS,							/* R/O: credits for the device implementation */

	DEVINFO_STR_CLASS_SPECIFIC = 0x34000,				/* R/W: device-specific values start here */
	DEVINFO_STR_DEVICE_SPECIFIC = 0x38000,				/* R/W: device-specific values start here */
	DEVINFO_STR_LAST = 0x3ffff
};



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

#define DEVICE_GET_INFO_NAME(name)	device_get_config_##name
#define DEVICE_GET_INFO(name)		void DEVICE_GET_INFO_NAME(name)(const device_config *device, UINT32 state, deviceinfo *info)
#define DEVICE_GET_INFO_CALL(name)	DEVICE_GET_INFO_NAME(name)(device, state, info)

#define DEVICE_VALIDITY_CHECK_NAME(name)	device_validity_check_##name
#define DEVICE_VALIDITY_CHECK(name)			int DEVICE_VALIDITY_CHECK_NAME(name)(const game_driver *driver, const device_config *device)
#define DEVICE_VALIDITY_CHECK_CALL(name)	DEVICE_VALIDITY_CHECK_NAME(name)(driver, device)

#define DEVICE_CUSTOM_CONFIG_NAME(name)		device_custom_config_##name
#define DEVICE_CUSTOM_CONFIG(name)			const machine_config_token *DEVICE_CUSTOM_CONFIG_NAME(name)(const device_config *device, UINT32 entrytype, const machine_config_token *tokens)
#define DEVICE_CUSTOM_CONFIG_CALL(name)		DEVICE_CUSTOM_CONFIG_NAME(name)(device, entrytype, tokens)


#define DEVICE_GET_RUNTIME_INFO_NAME(name)	device_get_runtime_info_##name
#define DEVICE_GET_RUNTIME_INFO(name)		void DEVICE_GET_RUNTIME_INFO_NAME(name)(running_device *device, UINT32 state, deviceinfo *info)
#define DEVICE_GET_RUNTIME_INFO_CALL(name)	DEVICE_GET_RUNTIME_INFO_NAME(name)(device, state, info)

#define DEVICE_START_NAME(name)		device_start_##name
#define DEVICE_START(name)			void DEVICE_START_NAME(name)(running_device *device)
#define DEVICE_START_CALL(name)		DEVICE_START_NAME(name)(device)

#define DEVICE_STOP_NAME(name)		device_stop_##name
#define DEVICE_STOP(name)			void DEVICE_STOP_NAME(name)(running_device *device)
#define DEVICE_STOP_CALL(name)		DEVICE_STOP_NAME(name)(device)

#define DEVICE_RESET_NAME(name)		device_reset_##name
#define DEVICE_RESET(name)			void DEVICE_RESET_NAME(name)(running_device *device)
#define DEVICE_RESET_CALL(name)		DEVICE_RESET_NAME(name)(device)

#define DEVICE_EXECUTE_NAME(name)	device_execute_##name
#define DEVICE_EXECUTE(name)		INT32 DEVICE_EXECUTE_NAME(name)(running_device *device, INT32 clocks)
#define DEVICE_EXECUTE_CALL(name)	DEVICE_EXECUTE_NAME(name)(device, clocks)

#define DEVICE_NVRAM_NAME(name)		device_nvram_##name
#define DEVICE_NVRAM(name)			void DEVICE_NVRAM_NAME(name)(running_device *device, mame_file *file, int read_or_write)
#define DEVICE_NVRAM_CALL(name)		DEVICE_NVRAM_NAME(name)(device, file, read_or_write)


/* device contract lists */
#define DEVICE_CONTRACT_LIST_NAME(name)		device_contract_list_##name

#define DEVICE_CONTRACT_LIST_START(name)	static const device_contract DEVICE_CONTRACT_LIST_NAME(name)[] = {
#define DEVICE_CONTRACT_ENTRY(type, var)	{ type, sizeof(var), &(var) },
#define DEVICE_CONTRACT_LIST_END			{ NULL, 0, NULL } };


/* macro for specifying a clock derived from an owning device */
#define DERIVED_CLOCK(num, den)		(0xff000000 | ((num) << 12) | ((den) << 0))


/* shorthand for accessing devices by machine/type/tag */
#define devtag_get_device(mach,tag)							(mach)->device(tag)

#define devtag_reset(mach,tag)								device_reset((mach)->device(tag))


/* shorthand for getting standard data about devices */
#define device_get_endianness(dev)							(dev)->get_config_int(DEVINFO_INT_ENDIANNESS)
#define device_get_databus_width(dev,space)					(dev)->get_config_int(DEVINFO_INT_DATABUS_WIDTH + (space))
#define device_get_addrbus_width(dev,space)					(dev)->get_config_int(DEVINFO_INT_ADDRBUS_WIDTH + (space))
#define device_get_addrbus_shift(dev,space)					(dev)->get_config_int(DEVINFO_INT_ADDRBUS_SHIFT + (space))
#define device_get_name(dev)								(dev)->get_config_string(DEVINFO_STR_NAME)
#define device_get_family(dev)								(dev)->get_config_string(DEVINFO_STR_FAMILY)
#define device_get_version(dev) 							(dev)->get_config_string(DEVINFO_STR_VERSION)
#define device_get_source_file(dev)							(dev)->get_config_string(DEVINFO_STR_SOURCE_FILE)
#define device_get_credits(dev) 							(dev)->get_config_string(DEVINFO_STR_CREDITS)



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

/* forward-declare these types */
class device_config;
class running_device;
union deviceinfo;


/* a device contract */
struct device_contract
{
	const char *	name;			/* name of this contract */
	UINT32			size;			/* size of this contract in bytes */
	const void *	contract;		/* pointer to the contract struct itself */
};


/* device interface function types */
typedef void (*device_get_config_func)(const device_config *device, UINT32 state, deviceinfo *info);
typedef int (*device_validity_check_func)(const game_driver *driver, const device_config *device);
typedef const machine_config_token *(*device_custom_config_func)(const device_config *device, UINT32 entrytype, const machine_config_token *tokens);

typedef void (*device_start_func)(running_device *device);
typedef void (*device_stop_func)(running_device *device);
typedef INT32 (*device_execute_func)(running_device *device, INT32 clocks);
typedef void (*device_reset_func)(running_device *device);
typedef void (*device_nvram_func)(running_device *device, mame_file *file, int read_or_write);
typedef void (*device_get_runtime_info_func)(running_device *device, UINT32 state, deviceinfo *info);


/* a device_type is simply a pointer to its get_info function */
typedef device_get_config_func device_type;


// template specializations
template<class T> class tagged_device_list : public tagged_list<T>
{
	typedef tagged_list<T> super;
	
public:
	// pull the generic forms forward
	using super::first;
	using super::count;
	using super::index;
	using super::find;
	
	// provide type-specific overrides
	T *first(device_type type) const
	{
		T *cur;
		for (cur = super::first(); cur != NULL && cur->type != type; cur = cur->next) ;
		return cur;
	}
	
	int count(device_type type) const
	{
		int num = 0;
		for (const T *curdev = first(type); curdev != NULL; curdev = curdev->typenext()) num++;
		return num;
	}
	
	int index(device_type type, T *object) const
	{
		int num = 0;
		for (T *cur = first(type); cur != NULL; cur = cur->typenext(), num++)
			if (cur == object) return num;
		return -1;
	}
	
	int index(device_type type, const char *tag) const
	{
		T *object = find(tag);
		return (object != NULL && object->type == type) ? index(type, object) : -1;
	}
	
	T *find(device_type type, int index) const
	{
		for (T *cur = first(type); cur != NULL; cur = cur->typenext())
			if (index-- == 0) return cur;
		return NULL;
	}

	// provide class-specific overrides
	T *first(device_class devclass) const
	{
		T *cur;
		for (cur = super::first(); cur != NULL && cur->devclass != devclass; cur = cur->next) ;
		return cur;
	}
	
	int count(device_class devclass) const
	{
		int num = 0;
		for (const T *curdev = first(devclass); curdev != NULL; curdev = curdev->classnext()) num++;
		return num;
	}
	
	int index(device_class devclass, T *object) const
	{
		int num = 0;
		for (T *cur = first(devclass); cur != NULL; cur = cur->classnext(), num++)
			if (cur == object) return num;
		return -1;
	}
	
	int index(device_class devclass, const char *tag) const
	{
		T *object = find(tag);
		return (object != NULL && object->devclass == devclass) ? index(devclass, object) : -1;
	}
	
	T *find(device_class devclass, int index) const
	{
		for (T *cur = first(devclass); cur != NULL; cur = cur->classnext())
			if (index-- == 0) return cur;
		return NULL;
	}
};


// template specializations
typedef tagged_device_list<device_config> device_config_list;

class device_list : public tagged_device_list<running_device>
{
public:
	void import_config_list(const device_config_list &list, running_machine &machine);
};


/* the actual deviceinfo union */
union deviceinfo
{
	INT64					i;							/* generic integers */
	void *					p;							/* generic pointers */
	genf *  				f;							/* generic function pointers */
	char *					s;							/* generic strings */

	device_start_func		start;						/* DEVINFO_FCT_START */
	device_stop_func		stop;						/* DEVINFO_FCT_STOP */
	device_reset_func		reset;						/* DEVINFO_FCT_RESET */
	device_execute_func 	execute;					/* DEVINFO_FCT_EXECUTE */
	device_validity_check_func validity_check;			/* DEVINFO_FCT_VALIDITY_CHECK */
	device_custom_config_func custom_config;			/* DEVINFO_FCT_CUSTOM_CONFIG */
	device_nvram_func		nvram;						/* DEVINFO_FCT_NVRAM */
	device_get_runtime_info_func get_runtime_info;		/* DEVINFO_FCT_GET_RUNTIME_INFO */
	const rom_entry *		romregion;					/* DEVINFO_PTR_ROM_REGION */
	const machine_config_token *machine_config;			/* DEVINFO_PTR_MACHINE_CONFIG */
	const device_contract *	contract_list;				/* DEVINFO_PTR_CONTRACT_LIST */
	const addrmap8_token *	internal_map8;				/* DEVINFO_PTR_INTERNAL_MEMORY_MAP */
	const addrmap16_token *	internal_map16;				/* DEVINFO_PTR_INTERNAL_MEMORY_MAP */
	const addrmap32_token *	internal_map32;				/* DEVINFO_PTR_INTERNAL_MEMORY_MAP */
	const addrmap64_token *	internal_map64;				/* DEVINFO_PTR_INTERNAL_MEMORY_MAP */
	const addrmap8_token *	default_map8;				/* DEVINFO_PTR_DEFAULT_MEMORY_MAP */
	const addrmap16_token *	default_map16;				/* DEVINFO_PTR_DEFAULT_MEMORY_MAP */
	const addrmap32_token *	default_map32;				/* DEVINFO_PTR_DEFAULT_MEMORY_MAP */
	const addrmap64_token *	default_map64;				/* DEVINFO_PTR_DEFAULT_MEMORY_MAP */
};


/* the configuration for a general device */
enum device_space
{
	AS_PROGRAM = 0,
	AS_DATA = 1,
	AS_IO = 2
};

class region_info;

class device_config
{
	DISABLE_COPYING(device_config);
	
public:
	device_config(const device_config *owner, device_type type, const char *tag, UINT32 clock);
	~device_config();

	device_config *typenext() const
	{
		device_config *cur;
		for (cur = this->next; cur != NULL && cur->type != type; cur = cur->next) ;
		return cur;
	}

	device_config *classnext() const
	{
		device_config *cur;
		for (cur = this->next; cur != NULL && cur->devclass != devclass; cur = cur->next) ;
		return cur;
	}

	// get state from a device config
	INT64 get_config_int(UINT32 state) const;
	void *get_config_ptr(UINT32 state) const;
	genf *get_config_fct(UINT32 state) const;
	const char *get_config_string(UINT32 state) const;

	/* device relationships */
	device_config *			next;					/* next device (of any type/class) */
	device_config *			owner;					/* device that owns us, or NULL if nobody */

	/* device properties */
	astring 				tag;					/* tag for this instance */
	device_type				type;					/* device type */
	device_class			devclass;				/* device class */

	/* device configuration */
	UINT32					clock;					/* device clock */
	const addrmap_token *	address_map[ADDRESS_SPACES]; /* address maps for each address space */
	const void *			static_config;			/* static device configuration */
	void *					inline_config;			/* inline device configuration */
};


class running_device
{
	DISABLE_COPYING(running_device);
	
	const device_config &	_baseconfig;
	
public:	// private eventually
	const address_space *	addrspace[ADDRESS_SPACES];	/* auto-discovered address spaces */

public:
	running_device(running_machine &machine, const device_config &config);
	~running_device();
	
	const device_config &baseconfig() const { return _baseconfig; }

	inline const address_space *space(int index = 0) const;
	inline const address_space *space(device_space index) const;

	const region_info *subregion(const char *tag) const;
	running_device *subdevice(const char *tag) const;
	
	running_device *typenext() const
	{
		running_device *cur;
		for (cur = this->next; cur != NULL && cur->type != type; cur = cur->next) ;
		return cur;
	}

	running_device *classnext() const
	{
		running_device *cur;
		for (cur = this->next; cur != NULL && cur->devclass != devclass; cur = cur->next) ;
		return cur;
	}

	// get state from a device config
	INT64 get_config_int(UINT32 state) const { return _baseconfig.get_config_int(state); }
	void *get_config_ptr(UINT32 state) const { return _baseconfig.get_config_ptr(state); }
	genf *get_config_fct(UINT32 state) const { return _baseconfig.get_config_fct(state); }
	const char *get_config_string(UINT32 state) const { return _baseconfig.get_config_string(state); }

	INT64 get_runtime_int(UINT32 state);
	void *get_runtime_ptr(UINT32 state);
	const char *get_runtime_string(UINT32 state);
	
	void set_address_space(int spacenum, const address_space *space);

	/* these fields are only valid once the device is attached to a machine */
	running_machine *		machine;				/* machine if device is live */

	/* device relationships */
	running_device *		next;					/* next device (of any type/class) */
	running_device *		owner;					/* device that owns us, or NULL if nobody */

	/* device properties */
	astring 				tag;					/* tag for this instance */
	device_type				type;					/* device type */
	device_class			devclass;				/* device class */

	/* device configuration */
	UINT32					clock;					/* device clock */

	/* these fields are only valid if the device is live */
	UINT8					started;				/* TRUE if the start function has succeeded */
	void *					token;					/* token if device is live */
	UINT32					tokenbytes;				/* size of the token data allocated */
	const region_info *		region;					/* our device-local region */

	device_execute_func 	execute;				/* quick pointer to execute callback */
	device_get_runtime_info_func get_runtime_info;
};



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


/* ----- device configuration ----- */

/* build a tag that combines the device's name and the given tag */
astring &device_build_tag(astring &dest, const device_config *devconfig, const char *tag);

/* build a tag with the same device prefix as the source tag*/
astring &device_inherit_tag(astring &dest, const char *sourcetag, const char *tag);

/* find a given contract on a device */
const device_contract *device_get_contract(running_device *device, const char *name);



/* ----- live device management ----- */

/* start the configured list of devices for a machine */
void device_list_start(running_machine *machine);

/* reset a device based on an allocated device_config */
void device_reset(running_device *device);

/* change the clock on a device */
void device_set_clock(running_device *device, UINT32 clock);

/* allow a device to ask for its initialization to be delayed */
void device_delay_init(running_device *device);



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

/*-------------------------------------------------
    space - return an address space within a
    device
-------------------------------------------------*/

inline const address_space *running_device::space(int index) const
{
	return addrspace[index];
}

inline const address_space *running_device::space(device_space index) const
{
	return space(static_cast<int>(index));
}



#endif	/* __DEVINTRF_H__ */