283
312
attoseconds_t m_attoseconds_per_clock;// period in attoseconds
285
314
device_debug * m_debug;
286
const memory_region * m_region; // our device-local region
315
memory_region * m_region; // our device-local region
287
316
const machine_config & m_machine_config; // reference to the machine's configuration
288
317
const void * m_static_config; // static device configuration
289
318
const input_device_default *m_input_defaults; // devices input ports default overrides
291
// helper class to request auto-object discovery in the constructor of a derived class
292
class auto_finder_base
295
// construction/destruction
296
auto_finder_base(device_t &base, const char *tag);
297
virtual ~auto_finder_base();
300
virtual void findit(device_t &base) = 0;
303
device_t *find_device(device_t &device, const char *tag);
304
void *find_shared_ptr(device_t &device, const char *tag);
305
size_t find_shared_size(device_t &device, const char *tag);
308
auto_finder_base *m_next;
312
// templated version bound to a specific type
313
template<typename _TargetType, bool _Required>
314
class auto_finder_type : public auto_finder_base
317
// construction/destruction
318
auto_finder_type(device_t &base, const char *tag)
319
: auto_finder_base(base, tag),
322
// operators to make use transparent
323
operator _TargetType() { return m_target; }
324
operator _TargetType() const { return m_target; }
325
_TargetType operator->() { return m_target; }
327
// getter for explicit fetching
328
_TargetType target() const { return m_target; }
330
// setter for setting the object
331
void set_target(_TargetType target)
334
if (target == 0 && _Required)
335
throw emu_fatalerror("Unable to find required object '%s'", this->m_tag);
339
_TargetType m_target;
342
// optional device finder
343
template<class _DeviceClass>
344
class optional_device : public auto_finder_type<_DeviceClass *, false>
347
optional_device(device_t &base, const char *tag) : auto_finder_type<_DeviceClass *, false>(base, tag) { }
348
virtual void findit(device_t &base) { this->set_target(downcast<_DeviceClass *>(this->find_device(base, this->m_tag))); }
351
// required devices are similar but throw an error if they are not found
352
template<class _DeviceClass>
353
class required_device : public auto_finder_type<_DeviceClass *, true>
356
required_device(device_t &base, const char *tag) : auto_finder_type<_DeviceClass *, true>(base, tag) { }
357
virtual void findit(device_t &base) { this->set_target(downcast<_DeviceClass *>(this->find_device(base, this->m_tag))); }
360
// optional shared pointer finder
361
template<typename _PointerType>
362
class optional_shared_ptr : public auto_finder_type<_PointerType *, false>
365
optional_shared_ptr(device_t &base, const char *tag) : auto_finder_type<_PointerType *, false>(base, tag) { }
366
virtual void findit(device_t &base) { this->set_target(reinterpret_cast<_PointerType *>(this->find_shared_ptr(base, this->m_tag))); }
369
// required shared pointer finder
370
template<typename _PointerType>
371
class required_shared_ptr : public auto_finder_type<_PointerType *, true>
374
required_shared_ptr(device_t &base, const char *tag) : auto_finder_type<_PointerType *, true>(base, tag) { }
375
virtual void findit(device_t &base) { this->set_target(reinterpret_cast<_PointerType *>(this->find_shared_ptr(base, this->m_tag))); }
378
// optional shared pointer size finder
379
class optional_shared_size : public auto_finder_type<size_t, false>
382
optional_shared_size(device_t &base, const char *tag) : auto_finder_type<size_t, false>(base, tag) { }
383
virtual void findit(device_t &base) { this->set_target(find_shared_size(base, this->m_tag)); }
386
// required shared pointer size finder
387
class required_shared_size : public auto_finder_type<size_t, true>
390
required_shared_size(device_t &base, const char *tag) : auto_finder_type<size_t, true>(base, tag) { }
391
virtual void findit(device_t &base) { this->set_target(find_shared_size(base, this->m_tag)); }
395
void register_auto_finder(auto_finder_base &autodev);
397
auto_finder_base * m_auto_finder_list;
320
UINT8 m_system_bios; // the system BIOS we wish to load
321
UINT8 m_default_bios; // the default system BIOS
400
323
// private helpers
401
324
device_t *add_subdevice(device_type type, const char *tag, UINT32 clock);
410
333
astring m_basetag; // base part of the tag
411
334
bool m_config_complete; // have we completed our configuration?
412
335
bool m_started; // true if the start function has succeeded
336
finder_base * m_auto_finder_list; // list of objects to auto-find
340
// ======================> finder_base
342
// helper class to request auto-object discovery in the constructor of a derived class
343
class device_t::finder_base
345
friend class device_t;
348
// construction/destruction
349
finder_base(device_t &base, const char *tag);
350
virtual ~finder_base();
353
virtual bool findit() = 0;
357
void *find_memory(UINT8 width, size_t &bytes, bool required);
358
bool report_missing(bool found, const char *objname, bool required);
367
// ======================> object_finder_base
369
// helper class to find objects of a particular type
370
template<class _ObjectClass>
371
class device_t::object_finder_base : public device_t::finder_base
374
// construction/destruction
375
object_finder_base(device_t &base, const char *tag)
376
: finder_base(base, tag),
379
// operators to make use transparent
380
operator _ObjectClass *() const { return m_target; }
381
_ObjectClass *operator->() const { assert(m_target != NULL); return m_target; }
383
// getter for explicit fetching
384
_ObjectClass *target() const { return m_target; }
386
// setter for setting the object
387
void set_target(_ObjectClass *target) { m_target = target; }
391
_ObjectClass *m_target;
395
// ======================> device_finder
397
// device finder template
398
template<class _DeviceClass, bool _Required>
399
class device_t::device_finder : public device_t::object_finder_base<_DeviceClass>
402
// construction/destruction
403
device_finder(device_t &base, const char *tag)
404
: object_finder_base<_DeviceClass>(base, tag) { }
407
virtual bool findit()
409
device_t *device = this->m_base.subdevice(this->m_tag);
410
this->m_target = dynamic_cast<_DeviceClass *>(device);
411
if (device != NULL && this->m_target == NULL)
413
void mame_printf_warning(const char *format, ...) ATTR_PRINTF(1,2);
414
mame_printf_warning("Device '%s' found but is of incorrect type\n", this->m_tag);
416
return this->report_missing(this->m_target != NULL, "device", _Required);
420
// optional device finder
421
template<class _DeviceClass>
422
class device_t::optional_device : public device_t::device_finder<_DeviceClass, false>
425
optional_device(device_t &base, const char *tag) : device_finder<_DeviceClass, false>(base, tag) { }
428
// required devices are similar but throw an error if they are not found
429
template<class _DeviceClass>
430
class device_t::required_device : public device_t::device_finder<_DeviceClass, true>
433
required_device(device_t &base, const char *tag) : device_finder<_DeviceClass, true>(base, tag) { }
437
// ======================> memregion_finder
439
// device finder template
440
template<bool _Required>
441
class device_t::memory_region_finder : public device_t::object_finder_base<memory_region>
444
// construction/destruction
445
memory_region_finder(device_t &base, const char *tag)
446
: object_finder_base<memory_region>(base, tag) { }
449
virtual bool findit()
451
m_target = m_base.memregion(m_tag);
452
return this->report_missing(m_target != NULL, "memory region", _Required);
456
// optional device finder
457
class device_t::optional_memory_region : public device_t::memory_region_finder<false>
460
optional_memory_region(device_t &base, const char *tag) : memory_region_finder<false>(base, tag) { }
463
// required devices are similar but throw an error if they are not found
464
class device_t::required_memory_region : public device_t::memory_region_finder<true>
467
required_memory_region(device_t &base, const char *tag) : memory_region_finder<true>(base, tag) { }
471
// ======================> memory_bank_finder
473
// device finder template
474
template<bool _Required>
475
class device_t::memory_bank_finder : public device_t::object_finder_base<memory_bank>
478
// construction/destruction
479
memory_bank_finder(device_t &base, const char *tag)
480
: object_finder_base<memory_bank>(base, tag) { }
483
virtual bool findit()
485
m_target = m_base.membank(m_tag);
486
return this->report_missing(m_target != NULL, "memory bank", _Required);
490
// optional device finder
491
class device_t::optional_memory_bank : public device_t::memory_bank_finder<false>
494
optional_memory_bank(device_t &base, const char *tag) : memory_bank_finder<false>(base, tag) { }
497
// required devices are similar but throw an error if they are not found
498
class device_t::required_memory_bank : public device_t::memory_bank_finder<true>
501
required_memory_bank(device_t &base, const char *tag) : memory_bank_finder<true>(base, tag) { }
505
// ======================> ioport_finder
507
// device finder template
508
template<bool _Required>
509
class device_t::ioport_finder : public device_t::object_finder_base<ioport_port>
512
// construction/destruction
513
ioport_finder(device_t &base, const char *tag)
514
: object_finder_base<ioport_port>(base, tag) { }
517
virtual bool findit()
519
m_target = m_base.ioport(m_tag);
520
return this->report_missing(m_target != NULL, "I/O port", _Required);
524
// optional device finder
525
class device_t::optional_ioport : public device_t::ioport_finder<false>
528
optional_ioport(device_t &base, const char *tag) : ioport_finder<false>(base, tag) { }
531
// required devices are similar but throw an error if they are not found
532
class device_t::required_ioport : public device_t::ioport_finder<true>
535
required_ioport(device_t &base, const char *tag) : ioport_finder<true>(base, tag) { }
539
// ======================> shared_ptr_finder
541
// shared pointer finder template
542
template<typename _PointerType, bool _Required>
543
class device_t::shared_ptr_finder : public device_t::object_finder_base<_PointerType>
546
// construction/destruction
547
shared_ptr_finder(device_t &base, const char *tag, UINT8 width = sizeof(_PointerType) * 8)
548
: object_finder_base<_PointerType>(base, tag),
553
virtual ~shared_ptr_finder() { if (m_allocated) global_free(this->m_target); }
555
// operators to make use transparent
556
_PointerType operator[](int index) const { return this->m_target[index]; }
557
_PointerType &operator[](int index) { return this->m_target[index]; }
559
// getter for explicit fetching
560
UINT32 bytes() const { return m_bytes; }
562
// setter for setting the object
563
void set_target(_PointerType *target, size_t bytes) { this->m_target = target; m_bytes = bytes; }
565
// dynamic allocation of a shared pointer
566
void allocate(UINT32 entries)
568
assert(!m_allocated);
570
this->m_target = global_alloc_array_clear(_PointerType, entries);
571
m_bytes = entries * sizeof(_PointerType);
572
this->m_base.save_pointer(this->m_target, this->m_tag, entries);
576
virtual bool findit()
578
this->m_target = reinterpret_cast<_PointerType *>(this->find_memory(m_width, m_bytes, _Required));
579
return this->report_missing(this->m_target != NULL, "shared pointer", _Required);
589
// optional shared pointer finder
590
template<class _PointerType>
591
class device_t::optional_shared_ptr : public device_t::shared_ptr_finder<_PointerType, false>
594
optional_shared_ptr(device_t &base, const char *tag, UINT8 width = sizeof(_PointerType) * 8) : shared_ptr_finder<_PointerType, false>(base, tag, width) { }
597
// required shared pointer finder
598
template<class _PointerType>
599
class device_t::required_shared_ptr : public device_t::shared_ptr_finder<_PointerType, true>
602
required_shared_ptr(device_t &base, const char *tag, UINT8 width = sizeof(_PointerType) * 8) : shared_ptr_finder<_PointerType, true>(base, tag, width) { }
606
// ======================> shared_ptr_array_finder
608
// shared pointer array finder template
609
template<typename _PointerType, int _Count, bool _Required>
610
class device_t::shared_ptr_array_finder
612
typedef shared_ptr_finder<_PointerType, _Required> shared_ptr_type;
615
// construction/destruction
616
shared_ptr_array_finder(device_t &base, const char *basetag, UINT8 width = sizeof(_PointerType) * 8)
618
for (int index = 0; index < _Count; index++)
619
m_array[index] = global_alloc(shared_ptr_type(base, m_tag[index].format("%s.%d", basetag, index), width));
622
virtual ~shared_ptr_array_finder()
624
for (int index = 0; index < _Count; index++)
625
global_free(m_array[index]);
629
const shared_ptr_type &operator[](int index) const { assert(index < _Count); return *m_array[index]; }
630
shared_ptr_type &operator[](int index) { assert(index < _Count); return *m_array[index]; }
634
shared_ptr_type *m_array[_Count];
635
astring m_tag[_Count];
638
// optional shared pointer array finder
639
template<class _PointerType, int _Count>
640
class device_t::optional_shared_ptr_array : public device_t::shared_ptr_array_finder<_PointerType, _Count, false>
643
optional_shared_ptr_array(device_t &base, const char *tag, UINT8 width = sizeof(_PointerType) * 8) : shared_ptr_array_finder<_PointerType, _Count, false>(base, tag, width) { }
646
// required shared pointer array finder
647
template<class _PointerType, int _Count>
648
class device_t::required_shared_ptr_array : public device_t::shared_ptr_array_finder<_PointerType, _Count, true>
651
required_shared_ptr_array(device_t &base, const char *tag, UINT8 width = sizeof(_PointerType) * 8) : shared_ptr_array_finder<_PointerType, _Count, true>(base, tag, width) { }
417
655
// ======================> device_interface