diff options
author | 2014-09-17 05:38:53 +0000 | |
---|---|---|
committer | 2014-09-17 05:38:53 +0000 | |
commit | e734a2efc9fa0e58febb6415bdac762dd8c16ef9 (patch) | |
tree | ea88ba5392d4418bd36fd1a9006a32a07da28361 /src/emu/bus/generic/slot.h | |
parent | cd2ef4ee205b55d602d55d740662eff857ca8aca (diff) |
added generic cartslot / ROM socket slot device, which offers
basic allocation and access handlers, and converted a few
drivers to use this instead of code from cartslot.c [Fabio Priuli]
out of whatsnew: the RAM socket part is just a proof of concept,
and the natural extension of the line of thought which lead me
to this generic socket/cartslot. it might allow to convert current RAM
device to be a slot device as well (after some refactorization, of
course, since current code lacks many of the necessary features),
or be removed soonish, depending on consensus.
Diffstat (limited to 'src/emu/bus/generic/slot.h')
-rw-r--r-- | src/emu/bus/generic/slot.h | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/src/emu/bus/generic/slot.h b/src/emu/bus/generic/slot.h new file mode 100644 index 00000000000..73830950944 --- /dev/null +++ b/src/emu/bus/generic/slot.h @@ -0,0 +1,165 @@ +#ifndef __GENERIC_SLOT_H +#define __GENERIC_SLOT_H + +/*************************************************************************** + TYPE DEFINITIONS + ***************************************************************************/ + + +// ======================> device_generic_cart_interface + +class device_generic_cart_interface : public device_slot_card_interface +{ +public: + // construction/destruction + device_generic_cart_interface(const machine_config &mconfig, device_t &device); + virtual ~device_generic_cart_interface(); + + // reading and writing + virtual DECLARE_READ8_MEMBER(read_rom) { return 0xff; } + virtual DECLARE_READ16_MEMBER(read16_rom) { return 0xffff; } + + virtual DECLARE_READ8_MEMBER(read_ram) { return 0xff; } + virtual DECLARE_WRITE8_MEMBER(write_ram) {}; + + virtual void rom_alloc(size_t size, int width, const char *tag); + virtual void ram_alloc(UINT32 size); + + UINT8* get_rom_base() { return m_rom; } + UINT32 get_rom_size() { return m_rom_size; } + + UINT8* get_ram_base() { return m_ram; } + UINT32 get_ram_size() { return m_ram.count(); } + + // internal state + UINT8 *m_rom; + UINT32 m_rom_size; + dynamic_buffer m_ram; +}; + + +enum +{ + GENERIC_ROM8_WIDTH = 1, + GENERIC_ROM16_WIDTH +}; + + +#define MCFG_GENERIC_MANDATORY \ + static_cast<generic_slot_device *>(device)->set_must_be_loaded(TRUE); + +#define MCFG_GENERIC_WIDTH(_width) \ + static_cast<generic_slot_device *>(device)->set_width(_width); + +#define MCFG_GENERIC_DEFAULT_CARD(_def_card) \ + static_cast<generic_slot_device *>(device)->set_default_card(_def_card); + +#define MCFG_GENERIC_INTERFACE(_intf) \ + static_cast<generic_slot_device *>(device)->set_interface(_intf); + +#define MCFG_GENERIC_EXTENSIONS(_ext) \ + static_cast<generic_slot_device *>(device)->set_extensions(_ext); + +#define MCFG_GENERIC_LOAD(_class, _method) \ + generic_slot_device::static_set_device_load(*device, device_image_load_delegate(&DEVICE_IMAGE_LOAD_NAME(_class,_method), #_class "::device_image_load_" #_method, downcast<_class *>(owner))); + +#define MCFG_GENERIC_UNLOAD(_class, _method) \ + generic_slot_device::static_set_device_unload(*device, device_image_func_delegate(&DEVICE_IMAGE_UNLOAD_NAME(_class,_method), #_class "::device_image_unload_" #_method, downcast<_class *>(owner))); + + + +typedef device_delegate<void (int layer, int bank, int *code, int *color, int *flags)> generic_load_delegate; + + +// ======================> generic_slot_device + +class generic_slot_device : public device_t, + public device_image_interface, + public device_slot_interface +{ +public: + // construction/destruction + generic_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + virtual ~generic_slot_device(); + + static void static_set_device_load(device_t &device, device_image_load_delegate callback) { downcast<generic_slot_device &>(device).m_device_image_load = callback; } + static void static_set_device_unload(device_t &device, device_image_func_delegate callback) { downcast<generic_slot_device &>(device).m_device_image_unload = callback; } + + void set_interface(const char * interface) { m_interface = interface; } + void set_default_card(const char * def) { m_default_card = def; } + void set_extensions(const char * exts) { m_extensions = exts; } + void set_must_be_loaded(bool mandatory) { m_must_be_loaded = mandatory; } + void set_width(int width) { m_width = width; } + + // device-level overrides + virtual void device_start(); + virtual void device_config_complete(); + + // image-level overrides + virtual bool call_load(); + virtual void call_unload(); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); + + bool cart_mounted() { return !m_empty; } + + virtual iodevice_t image_type() const { return IO_CARTSLOT; } + virtual bool is_readable() const { return 1; } + virtual bool is_writeable() const { return 0; } + virtual bool is_creatable() const { return 0; } + virtual bool must_be_loaded() const { return m_must_be_loaded; } + virtual bool is_reset_on_load() const { return 1; } + virtual const option_guide *create_option_guide() const { return NULL; } + virtual const char *image_interface() const { return m_interface; } + virtual const char *file_extensions() const { return m_extensions; } + + // slot interface overrides + virtual void get_default_card_software(astring &result); + + // reading and writing + virtual DECLARE_READ8_MEMBER(read_rom); + virtual DECLARE_READ16_MEMBER(read16_rom); + + virtual DECLARE_READ8_MEMBER(read_ram); + virtual DECLARE_WRITE8_MEMBER(write_ram); + + virtual void rom_alloc(size_t size, int width) { if (m_cart) m_cart->rom_alloc(size, width, tag()); } + virtual void ram_alloc(UINT32 size) { if (m_cart) m_cart->ram_alloc(size); } + + UINT8* get_rom_base() { if (m_cart) return m_cart->get_rom_base(); return NULL; } + UINT8* get_ram_base() { if (m_cart) return m_cart->get_ram_base(); return NULL; } + +protected: + + const char *m_interface; + const char *m_default_card; + const char *m_extensions; + bool m_must_be_loaded; + int m_width; + bool m_empty; + device_generic_cart_interface *m_cart; + device_image_load_delegate m_device_image_load; + device_image_func_delegate m_device_image_unload; +}; + + +// device type definition +extern const device_type GENERIC_SOCKET; + + +/*************************************************************************** + DEVICE CONFIGURATION MACROS + ***************************************************************************/ + +#define MCFG_GENERIC_CARTSLOT_ADD(_tag, _width, _slot_intf, _dev_intf) \ + MCFG_DEVICE_ADD(_tag, GENERIC_SOCKET, 0) \ + MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, NULL, false) \ + MCFG_GENERIC_INTERFACE(_dev_intf) \ + MCFG_GENERIC_WIDTH(_width) + +#define MCFG_GENERIC_SOCKET_ADD(_tag, _width, _slot_intf, _dev_intf) \ + MCFG_DEVICE_ADD(_tag, GENERIC_SOCKET, 0) \ + MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, NULL, false) \ + MCFG_GENERIC_INTERFACE(_dev_intf) \ + MCFG_GENERIC_WIDTH(_width) + +#endif |