1 // license:BSD-3-Clause 2 // copyright-holders:Ryan Holtz 3 #ifndef MAME_BUS_VSMILE_VSMILE_SLOT_H 4 #define MAME_BUS_VSMILE_VSMILE_SLOT_H 5 6 #pragma once 7 8 #include "softlist_dev.h" 9 10 11 /*************************************************************************** 12 TYPE DEFINITIONS 13 ***************************************************************************/ 14 15 #define VSMILE_SLOT_ROM_REGION_TAG ":cart:rom" 16 17 enum 18 { 19 VSMILE_STD = 0, 20 VSMILE_NVRAM 21 }; 22 23 // ======================> device_vsmile_cart_interface 24 25 class device_vsmile_cart_interface : public device_interface 26 { 27 public: 28 // construction/destruction 29 virtual ~device_vsmile_cart_interface(); 30 31 // reading and writing bank0_r(offs_t offset)32 virtual uint16_t bank0_r(offs_t offset) { return 0; } bank1_r(offs_t offset)33 virtual uint16_t bank1_r(offs_t offset) { return 0; } bank2_r(offs_t offset)34 virtual uint16_t bank2_r(offs_t offset) { return 0; } bank3_r(offs_t offset)35 virtual uint16_t bank3_r(offs_t offset) { return 0; } bank0_w(offs_t offset,uint16_t data)36 virtual void bank0_w(offs_t offset, uint16_t data) { } bank1_w(offs_t offset,uint16_t data)37 virtual void bank1_w(offs_t offset, uint16_t data) { } bank2_w(offs_t offset,uint16_t data)38 virtual void bank2_w(offs_t offset, uint16_t data) { } bank3_w(offs_t offset,uint16_t data)39 virtual void bank3_w(offs_t offset, uint16_t data) { } 40 41 // banking 42 virtual void set_cs2(bool cs2) = 0; 43 44 void rom_alloc(uint32_t size, const char *tag); 45 void nvram_alloc(uint32_t size); get_rom_base()46 uint16_t* get_rom_base() { return m_rom; } get_nvram_base()47 uint16_t* get_nvram_base() { return &m_nvram[0]; } get_rom_size()48 uint32_t get_rom_size() { return m_rom_size; } get_nvram_size()49 uint32_t get_nvram_size() { return m_nvram.size() * sizeof(uint16_t); } set_rom_size(uint32_t val)50 void set_rom_size(uint32_t val) { m_rom_size = val; } 51 save_nvram()52 void save_nvram() { device().save_item(NAME(m_nvram)); } 53 54 protected: 55 device_vsmile_cart_interface(const machine_config &mconfig, device_t &device); 56 57 // internal state 58 uint16_t *m_rom; // this points to the cart rom region 59 uint32_t m_rom_size; // this is the actual game size, not the rom region size! 60 std::vector<uint16_t> m_nvram; 61 }; 62 63 64 // ======================> vsmile_cart_slot_device 65 66 class vsmile_cart_slot_device : public device_t, 67 public device_image_interface, 68 public device_single_card_slot_interface<device_vsmile_cart_interface> 69 { 70 public: 71 // construction/destruction 72 template <typename T> vsmile_cart_slot_device(machine_config const & mconfig,char const * tag,device_t * owner,T && opts,char const * dflt)73 vsmile_cart_slot_device(machine_config const &mconfig, char const *tag, device_t *owner, T &&opts, char const *dflt) 74 : vsmile_cart_slot_device(mconfig, tag, owner, (uint32_t)0) 75 { 76 option_reset(); 77 opts(*this); 78 set_default_option(dflt); 79 set_fixed(false); 80 } 81 vsmile_cart_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); 82 virtual ~vsmile_cart_slot_device(); 83 84 // image-level overrides 85 virtual image_init_result call_load() override; 86 virtual void call_unload() override; 87 image_type()88 virtual iodevice_t image_type() const noexcept override { return IO_CARTSLOT; } is_readable()89 virtual bool is_readable() const noexcept override { return true; } is_writeable()90 virtual bool is_writeable() const noexcept override { return false; } is_creatable()91 virtual bool is_creatable() const noexcept override { return false; } must_be_loaded()92 virtual bool must_be_loaded() const noexcept override { return false; } is_reset_on_load()93 virtual bool is_reset_on_load() const noexcept override { return true; } image_interface()94 virtual const char *image_interface() const noexcept override { return "vsmile_cart"; } file_extensions()95 virtual const char *file_extensions() const noexcept override { return "u1,u3,bin"; } 96 97 // slot interface overrides 98 virtual std::string get_default_card_software(get_default_card_software_hook &hook) const override; 99 save_nvram()100 void save_nvram() { if (m_cart && m_cart->get_nvram_size()) m_cart->save_nvram(); } get_rom_size()101 uint32_t get_rom_size() { return m_cart ? m_cart->get_rom_size() : 0; } 102 103 // reading and writing 104 uint16_t bank0_r(offs_t offset); 105 uint16_t bank1_r(offs_t offset); 106 uint16_t bank2_r(offs_t offset); 107 uint16_t bank3_r(offs_t offset); 108 void bank0_w(offs_t offset, uint16_t data); 109 void bank1_w(offs_t offset, uint16_t data); 110 void bank2_w(offs_t offset, uint16_t data); 111 void bank3_w(offs_t offset, uint16_t data); 112 113 // banking 114 void set_cs2(bool cs2); 115 116 protected: 117 // device-level overrides 118 virtual void device_start() override; 119 120 // device_image_interface implementation get_software_list_loader()121 virtual const software_list_loader &get_software_list_loader() const override { return rom_software_list_loader::instance(); } 122 123 int m_type; 124 device_vsmile_cart_interface* m_cart; 125 }; 126 127 // device type definition 128 DECLARE_DEVICE_TYPE(VSMILE_CART_SLOT, vsmile_cart_slot_device) 129 130 #endif // MAME_BUS_VSMILE_VSMILE_SLOT_H 131