summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/devintrf.h
blob: 3e05c742089dd5fd5d1d23184578b747539c02b7 (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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/***************************************************************************

    devintrf.h

    Device interface functions.

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

    Copyright Aaron Giles
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in
          the documentation and/or other materials provided with the
          distribution.
        * Neither the name 'MAME' nor the names of its contributors may be
          used to endorse or promote products derived from this software
          without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

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

#pragma once

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

#ifndef __DEVINTRF_H__
#define __DEVINTRF_H__



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

// 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_reset(mach,tag)								(mach).device(tag)->reset()

// often derived devices need only a different name and a simple parameter to differentiate them
// these are provided as macros because you can't pass string literals to templates, annoyingly enough
// use this to declare the existence of a derived device in the header file
#define DECLARE_TRIVIAL_DERIVED_DEVICE(_ConfigClass, _ConfigBase, _DeviceClass, _DeviceBase) \
typedef _DeviceBase _DeviceClass;														\
class _ConfigClass;																		\
																						\
class _ConfigClass : public _ConfigBase 												\
{																						\
protected:																				\
	_ConfigClass(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock, UINT32 param = 0); \
																						\
public: 																				\
	static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); \
	virtual device_t *alloc_device(running_machine &machine) const;						\
};																						\

// use this macro to define the actual implementation in the source file
#define DEFINE_TRIVIAL_DERIVED_DEVICE(_ConfigClass, _ConfigBase, _DeviceClass, _DeviceBase, _Name, _Param) \
_ConfigClass::_ConfigClass(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock, UINT32 param) \
	: _ConfigBase(mconfig, static_alloc_device_config, _Name, tag, owner, clock, param)	\
{																						\
}																						\
																						\
device_config *_ConfigClass::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \
{																						\
	return global_alloc(_ConfigClass(mconfig, tag, owner, clock, _Param));				\
}																						\
																						\
device_t *_ConfigClass::alloc_device(running_machine &machine) const					\
{																						\
	return auto_alloc(machine, _DeviceClass(machine, *this));							\
}																						\



//**************************************************************************
//  DEVICE CONFIGURATION MACROS
//**************************************************************************

// configure devices
#define MCFG_DEVICE_CONFIG(_config) \
	device_config::static_set_static_config(device, &(_config)); \

#define MCFG_DEVICE_CONFIG_CLEAR() \
	device_config::static_set_static_config(device, NULL); \

#define MCFG_DEVICE_CLOCK(_clock) \
	device_config::static_set_clock(device, _clock); \

#define MCFG_DEVICE_INPUT_DEFAULTS(_config) \
	device_config::static_set_input_default(device, DEVICE_INPUT_DEFAULTS_NAME(_config)); \


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

// forward references
class memory_region;
class device_debug;
class device_config;
class device_config_interface;
class device_t;
class device_interface;
class device_execute_interface;
class device_memory_interface;
class device_state_interface;
struct rom_entry;
class machine_config;
class emu_timer;
typedef union _input_port_token input_port_token;
typedef struct _input_device_default input_device_default;


// exception classes
class device_missing_dependencies : public emu_exception { };


// a device_type is simply a pointer to its alloc function
typedef device_config *(*device_type)(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);


// timer IDs for devices
typedef UINT32 device_timer_id;


// read/write types for I/O lines (similar to read/write handlers but no offset)
typedef int (*read_line_device_func)(device_t *device);
typedef void (*write_line_device_func)(device_t *device, int state);



// ======================> tagged_device_list

// tagged_device_list is a tagged_list with additional searching based on type
template<class T>
class tagged_device_list : public tagged_list<T>
{
	typedef tagged_list<T> super;

public:
	tagged_device_list(resource_pool &pool = global_resource_pool)
		: tagged_list<T>(pool) { }

	// pull the generic forms forward
	using super::first;
	using super::count;
	using super::indexof;
	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 indexof(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 indexof(device_type type, const char *tag) const
	{
		T *object = find(tag);
		return (object != NULL && object->type() == type) ? indexof(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 interface-specific overrides
	template<class I>
	bool first(I *&intf) const
	{
		for (T *cur = super::first(); cur != NULL; cur = cur->next())
			if (cur->interface(intf))
				return true;
		return false;
	}
};



// ======================> device_config_list

// device_config_list manages a list of device_configs
typedef tagged_device_list<device_config> device_config_list;



// ======================> device_list

// device_list manages a list of device_ts
class device_list : public tagged_device_list<device_t>
{
	running_machine *m_machine;

	static void static_reset(running_machine &machine);
	static void static_exit(running_machine &machine);
	static void static_pre_save(running_machine &machine, void *param);
	static void static_post_load(running_machine &machine, void *param);

public:
	device_list(resource_pool &pool = global_resource_pool);
	void import_config_list(const device_config_list &list, running_machine &machine);

	void start_all();
	void reset_all();
};



// ======================> device_config

// device_config represents a device configuration that is attached to a machine_config
class device_config
{
	DISABLE_COPYING(device_config);

	friend class machine_config;
	friend class device_t;
	friend class device_config_interface;
	friend class simple_list<device_config>;

protected:
	// construction/destruction
	device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock, UINT32 param = 0);
	device_config(const machine_config &mconfig, device_type type, const char *name, const char *shortname, const char *tag, const device_config *owner, UINT32 clock, UINT32 param = 0);
	virtual ~device_config();

public:
	// iteration helpers
	device_config *next() const { return m_next; }
	device_config *typenext() const;
	device_config *owner() const { return m_owner; }

	// interface helpers
	template<class T> bool interface(const T *&intf) const { intf = dynamic_cast<const T *>(this); return (intf != NULL); }
	template<class T> bool next(T *&intf) const
	{
		for (device_config *cur = m_next; cur != NULL; cur = cur->m_next)
			if (cur->interface(intf))
				return true;
		return false;
	}

	// owned object helpers
	astring &subtag(astring &dest, const char *tag) const;
	astring &siblingtag(astring &dest, const char *tag) const;

	// basic information getters
	device_type type() const { return m_type; }
	UINT32 clock() const { return m_clock; }
	const char *name() const { return m_name; }
	const char *shortname() const { return m_shortname; }
	const char *searchpath() const { return m_searchpath; }
	const char *tag() const { return m_tag; }
	const void *static_config() const { return m_static_config; }
	const machine_config &mconfig() const { return m_machine_config; }
	const input_device_default *input_ports_defaults() const { return m_input_defaults; }
	const rom_entry *rom_region() const { return device_rom_region(); }
	machine_config_constructor machine_config_additions() const { return device_mconfig_additions(); }
	const input_port_token *input_ports() const { return device_input_ports(); }

	// methods that wrap both interface-level and device-level behavior
	void config_complete();
	bool validity_check(emu_options &options, const game_driver &driver) const;

	// configuration helpers
	static void static_set_clock(device_config *device, UINT32 clock) { device->m_clock = clock; }
	static void static_set_static_config(device_config *device, const void *config) { device->m_static_config = config; }
	static void static_set_input_default(device_config *device, const input_device_default *config) { device->m_input_defaults = config; }

	//------------------- begin derived class overrides

	// required operation overrides
	virtual device_t *alloc_device(running_machine &machine) const = 0;

	// optional operation overrides
protected:
	virtual void device_config_complete();
	virtual bool device_validity_check(emu_options &options, const game_driver &driver) const;

	// optional information overrides
	virtual const rom_entry *device_rom_region() const;
	virtual machine_config_constructor device_mconfig_additions() const;
	virtual const input_port_token *device_input_ports() const;

	//------------------- end derived class overrides

	// device relationships
	device_config *			m_next;					// next device (of any type/class)
	device_config *			m_owner;				// device that owns us, or NULL if nobody
	device_config_interface *m_interface_list;		// head of interface list

	const device_type		m_type;					// device type
	UINT32					m_clock;				// device clock

	const machine_config &	m_machine_config;		// reference to the machine's configuration
	const void *			m_static_config;		// static device configuration
	const input_device_default *m_input_defaults;   // devices input ports default overrides

	astring					m_name;					// name of the device
	astring					m_shortname;			// short name of the device
	astring					m_searchpath;			// search path, used for media loading

private:
	astring 				m_tag;					// tag for this instance
	bool					m_config_complete;		// have we completed our configuration?
};



// ======================> device_config_interface

// device_config_interface represents configuration information for a particular device interface
class device_config_interface
{
	DISABLE_COPYING(device_config_interface);

protected:
	// construction/destruction
	device_config_interface(const machine_config &mconfig, device_config &devconfig);
	virtual ~device_config_interface();

public:
	// casting helpers
	const device_config &devconfig() const { return m_device_config; }
	operator const device_config &() const { return m_device_config; }
	operator const device_config *() const { return &m_device_config; }

	// iteration helpers
	device_config_interface *interface_next() const { return m_interface_next; }
	template<class T> bool next(T *&intf) const { return m_device_config.next(intf); }

	// optional operation overrides
	virtual void interface_config_complete();
	virtual bool interface_validity_check(emu_options &options, const game_driver &driver) const;

protected:
	const device_config &		m_device_config;
	const machine_config &		m_machine_config;
	device_config_interface *	m_interface_next;
};



// ======================> device_t

// device_t represents a device that is live and attached to a running_machine
class device_t : public bindable_object
{
	DISABLE_COPYING(device_t);

	friend class device_interface;
	friend class simple_list<device_t>;
	friend class device_list;

protected:
	// construction/destruction
	device_t(running_machine &machine, const device_config &config);
	virtual ~device_t();

public:
	// getters
	running_machine &machine() const { return m_machine; }

	// iteration helpers
	device_t *next() const { return m_next; }
	device_t *typenext() const;
	device_t *owner() const { return m_owner; }

	// interface helpers
	template<class T> bool interface(T *&intf) { intf = dynamic_cast<T *>(this); return (intf != NULL); }
	template<class T> bool interface(T *&intf) const { intf = dynamic_cast<const T *>(this); return (intf != NULL); }
	template<class T> bool next(T *&intf) const
	{
		for (device_t *cur = m_next; cur != NULL; cur = cur->m_next)
			if (cur->interface(intf))
				return true;
		return false;
	}

	// specialized helpers for common core interfaces
	bool interface(device_execute_interface *&intf) { intf = m_execute; return (intf != NULL); }
	bool interface(device_execute_interface *&intf) const { intf = m_execute; return (intf != NULL); }
	bool interface(device_memory_interface *&intf) { intf = m_memory; return (intf != NULL); }
	bool interface(device_memory_interface *&intf) const { intf = m_memory; return (intf != NULL); }
	bool interface(device_state_interface *&intf) { intf = m_state; return (intf != NULL); }
	bool interface(device_state_interface *&intf) const { intf = m_state; return (intf != NULL); }
	device_memory_interface &memory() const { assert(m_memory != NULL); return *m_memory; }

	// owned object helpers
	astring &subtag(astring &dest, const char *tag) const { return m_baseconfig.subtag(dest, tag); }
	astring &siblingtag(astring &dest, const char *tag) const { return m_baseconfig.siblingtag(dest, tag); }
	const memory_region *subregion(const char *tag) const;
	device_t *subdevice(const char *tag) const;
	device_t *siblingdevice(const char *tag) const;
	template<class T> inline T *subdevice(const char *tag) { return downcast<T *>(subdevice(tag)); }
	template<class T> inline T *siblingdevice(const char *tag) { return downcast<T *>(siblingdevice(tag)); }

	// configuration helpers
	const device_config &baseconfig() const { return m_baseconfig; }
	const memory_region *region() const { return m_region; }

	// state helpers
	bool started() const { return m_started; }
	void reset();

	// clock/timing accessors
	UINT32 clock() const { return m_clock; }
	UINT32 unscaled_clock() const { return m_unscaled_clock; }
	void set_unscaled_clock(UINT32 clock);
	double clock_scale() const { return m_clock_scale; }
	void set_clock_scale(double clockscale);
	attotime clocks_to_attotime(UINT64 clocks) const;
	UINT64 attotime_to_clocks(attotime duration) const;

	// timer interfaces
	emu_timer *timer_alloc(device_timer_id id = 0, void *ptr = NULL);
	void timer_set(attotime duration, device_timer_id id = 0, int param = 0, void *ptr = NULL);
	void synchronize(device_timer_id id = 0, int param = 0, void *ptr = NULL) { timer_set(attotime::zero, id, param, ptr); }
	void timer_expired(emu_timer &timer, device_timer_id id, int param, void *ptr) { device_timer(timer, id, param, ptr); }

	// state saving interfaces
	template<typename T>
	void save_item(T &value, const char *valname, int index = 0) { m_state_manager.save_item(name(), tag(), index, value, valname); }
	template<typename T>
	void save_pointer(T *value, const char *valname, UINT32 count, int index = 0) { m_state_manager.save_pointer(name(), tag(), index, value, valname, count); }

	// debugging
	device_debug *debug() const { return m_debug; }

	// basic information getters ... pass through to underlying config
	device_type type() const { return m_baseconfig.type(); }
	const char *name() const { return m_baseconfig.name(); }
	const char *tag() const { return m_baseconfig.tag(); }

	// machine and ROM configuration getters ... pass through to underlying config
	const rom_entry *rom_region() const { return m_baseconfig.rom_region(); }
	machine_config_constructor machine_config_additions() const { return m_baseconfig.machine_config_additions(); }
	const input_port_token *input_ports() const { return m_baseconfig.input_ports(); }

protected:
	// miscellaneous helpers
	void find_interfaces();
	void start();
	void debug_setup();
	void pre_save();
	void post_load();
	void notify_clock_changed();

	//------------------- begin derived class overrides

	// device-level overrides
	virtual void device_start() = 0;
	virtual void device_reset();
	virtual void device_pre_save();
	virtual void device_post_load();
	virtual void device_clock_changed();
	virtual void device_debug_setup();
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);

	//------------------- end derived class overrides

	running_machine &		m_machine;
	state_manager &			m_state_manager;
	device_debug *			m_debug;

	// core device interfaces for speed
	device_execute_interface *m_execute;
	device_memory_interface *m_memory;
	device_state_interface *m_state;

	// device relationships
	device_t *				m_next;					// next device (of any type/class)
	device_t *				m_owner;				// device that owns us, or NULL if nobody
	device_interface *		m_interface_list;		// head of interface list

	bool					m_started;				// true if the start function has succeeded
	UINT32					m_clock;				// device clock
	const memory_region *	m_region;				// our device-local region

	const device_config &	m_baseconfig;			// reference to our device_config
	UINT32					m_unscaled_clock;		// unscaled clock
	double					m_clock_scale;			// clock scale factor
	attoseconds_t			m_attoseconds_per_clock;// period in attoseconds

	// helper class to request auto-object discovery in the constructor of a derived class
	class auto_finder_base
	{
	public:
		// construction/destruction
		auto_finder_base(device_t &base, const char *tag);
		virtual ~auto_finder_base();

		// getters
		virtual void findit(device_t &base) = 0;

		// helpers
		device_t *find_device(device_t &device, const char *tag);
		void *find_shared_ptr(device_t &device, const char *tag);
		size_t find_shared_size(device_t &device, const char *tag);

		// internal state
		auto_finder_base *m_next;
		const char *m_tag;
	};

	// templated version bound to a specific type
	template<typename _TargetType, bool _Required>
	class auto_finder_type : public auto_finder_base
	{
	public:
		// construction/destruction
		auto_finder_type(device_t &base, const char *tag)
			: auto_finder_base(base, tag),
			  m_target(0) { }

		// operators to make use transparent
		operator _TargetType() { return m_target; }
		operator _TargetType() const { return m_target; }
		_TargetType operator->() { return m_target; }

		// setter for setting the object
		void set_target(_TargetType target)
		{
			m_target = target;
			if (target == 0 && _Required)
				throw emu_fatalerror("Unable to find required object '%s'", this->m_tag);
		}

		// internal state
		_TargetType m_target;
	};

	// optional device finder
	template<class _DeviceClass>
	class optional_device : public auto_finder_type<_DeviceClass *, false>
	{
	public:
		optional_device(device_t &base, const char *tag) : auto_finder_type<_DeviceClass *, false>(base, tag) { }
		virtual void findit(device_t &base) { this->set_target(downcast<_DeviceClass *>(this->find_device(base, this->m_tag))); }
	};

	// required devices are similar but throw an error if they are not found
	template<class _DeviceClass>
	class required_device : public auto_finder_type<_DeviceClass *, true>
	{
	public:
		required_device(device_t &base, const char *tag) : auto_finder_type<_DeviceClass *, true>(base, tag) { }
		virtual void findit(device_t &base) { this->set_target(downcast<_DeviceClass *>(this->find_device(base, this->m_tag))); }
	};

	// optional shared pointer finder
	template<typename _PointerType>
	class optional_shared_ptr : public auto_finder_type<_PointerType *, false>
	{
	public:
		optional_shared_ptr(device_t &base, const char *tag) : auto_finder_type<_PointerType *, false>(base, tag) { }
		virtual void findit(device_t &base) { this->set_target(reinterpret_cast<_PointerType *>(this->find_shared_ptr(base, this->m_tag))); }
	};

	// required shared pointer finder
	template<typename _PointerType>
	class required_shared_ptr : public auto_finder_type<_PointerType *, true>
	{
	public:
		required_shared_ptr(device_t &base, const char *tag) : auto_finder_type<_PointerType *, true>(base, tag) { }
		virtual void findit(device_t &base) { this->set_target(reinterpret_cast<_PointerType *>(this->find_shared_ptr(base, this->m_tag))); }
	};

	// optional shared pointer size finder
	class optional_shared_size : public auto_finder_type<size_t, false>
	{
	public:
		optional_shared_size(device_t &base, const char *tag) : auto_finder_type<size_t, false>(base, tag) { }
		virtual void findit(device_t &base) { this->set_target(find_shared_size(base, this->m_tag)); }
	};

	// required shared pointer size finder
	class required_shared_size : public auto_finder_type<size_t, true>
	{
	public:
		required_shared_size(device_t &base, const char *tag) : auto_finder_type<size_t, true>(base, tag) { }
		virtual void findit(device_t &base) { this->set_target(find_shared_size(base, this->m_tag)); }
	};

	// internal helpers
	void register_auto_finder(auto_finder_base &autodev);

	auto_finder_base *		m_auto_finder_list;
};



// ======================> device_interface

// device_interface represents runtime information for a particular device interface
class device_interface
{
	DISABLE_COPYING(device_interface);

protected:
	// construction/destruction
	device_interface(running_machine &machine, const device_config &config, device_t &device);
	virtual ~device_interface();

public:
	// casting helpers
	device_t &device() { return m_device; }
	const device_t &device() const { return m_device; }
	operator device_t &() { return m_device; }
	operator device_t *() { return &m_device; }

	// iteration helpers
	device_interface *interface_next() const { return m_interface_next; }
	template<class T> bool next(T *&intf) const { return m_device.next(intf); }

	// optional operation overrides
	virtual void interface_pre_start();
	virtual void interface_post_start();
	virtual void interface_pre_reset();
	virtual void interface_post_reset();
	virtual void interface_pre_save();
	virtual void interface_post_load();
	virtual void interface_clock_changed();
	virtual void interface_debug_setup();

protected:
	device_interface *		m_interface_next;
	device_t &				m_device;
};



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


// ======================> device config helpers

// find the next device_config of the same type
inline device_config *device_config::typenext() const
{
	device_config *cur;
	for (cur = m_next; cur != NULL && cur->m_type != m_type; cur = cur->m_next) ;
	return cur;
}

// create a tag for an object that is owned by this device
inline astring &device_config::subtag(astring &dest, const char *_tag) const
{
	// temp. for now: don't include the root tag in the full tag name
	return (this != NULL && m_owner != NULL) ? dest.cpy(m_tag).cat(":").cat(_tag) : dest.cpy(_tag);
}

// create a tag for an object that a sibling to this device
inline astring &device_config::siblingtag(astring &dest, const char *_tag) const
{
	return (this != NULL && m_owner != NULL) ? m_owner->subtag(dest, _tag) : dest.cpy(_tag);
}



// ======================> running device helpers

// find the next device_t of the same type
inline device_t *device_t::typenext() const
{
	device_t *cur;
	for (cur = m_next; cur != NULL && cur->type() != type(); cur = cur->m_next) ;
	return cur;
}


#endif	/* __DEVINTRF_H__ */