Previous 15994 Revisions Next

r13974 Wednesday 11th January, 2012 at 11:16:06 UTC by Miodrag Milanović
Cartslot is now C++ device (no whatsnew)
Require clean compile
[src/emu/imagedev]cartslot.c cartslot.h

src/emu/imagedev/cartslot.h
r13973r13974
2222#define ROM_FILL_FF      0x04000000
2323#define ROM_NOCLEAR      0x08000000
2424
25DECLARE_LEGACY_IMAGE_DEVICE(CARTSLOT, cartslot);
26
27
28
2925/***************************************************************************
3026    TYPE DEFINITIONS
3127***************************************************************************/
3228
33typedef struct _cartslot_config cartslot_config;
34struct _cartslot_config
29// ======================> cartslot_image_device
30
31class cartslot_image_device :   public device_t,
32                        public device_image_interface
3533{
36   const char *               extensions;
37   const char *               interface;
38   int                        must_be_loaded;
39   device_start_func            device_start;
40   device_image_load_func         device_load;
41   device_image_unload_func      device_unload;
42   device_image_partialhash_func   device_partialhash;
43   device_image_display_info_func   device_displayinfo;
34public:
35   // construction/destruction
36   cartslot_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
37   virtual ~cartslot_image_device();
38
39   // image-level overrides
40   virtual bool call_load();
41   virtual void call_unload();
42   virtual void call_display_info() { if (m_device_displayinfo) m_device_displayinfo(*this); }
43   virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) {    load_software_part_region( this, swlist, swname, start_entry ); return TRUE; }
44   virtual device_image_partialhash_func get_partial_hash() const { return m_device_partialhash; }
45   
46   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
47
48   virtual bool is_readable()  const { return 1; }
49   virtual bool is_writeable() const { return 0; }
50   virtual bool is_creatable() const { return 0; }
51   virtual bool must_be_loaded() const { return m_must_be_loaded; }
52   virtual bool is_reset_on_load() const { return 1; }
53   virtual const char *image_interface() const { return m_interface; }
54   virtual const char *file_extensions() const { return m_extensions; }
55   virtual const option_guide *create_option_guide() const { return NULL; }
56   
57   void set_extensions(const char *_extensions) { m_extensions = _extensions; }
58   void set_interface(const char *_interface) { m_interface = _interface; }
59   void set_must_be_loaded(bool _must_be_loaded) { m_must_be_loaded = _must_be_loaded; }
60   void set_device_start(device_start_func _start) { m_device_start = _start; }
61   void set_device_load(device_image_load_func _load) { m_device_load = _load; }
62   void set_device_unload(device_image_unload_func _unload) { m_device_unload = _unload; }
63   void set_partialhash(device_image_partialhash_func _partialhash) { m_device_partialhash = _partialhash; }
64   void set_displayinfo(device_image_display_info_func _displayinfo) { m_device_displayinfo = _displayinfo; }
65
66protected:
67   // device-level overrides
68    virtual void device_config_complete();
69   virtual void device_start();
70   
71   int load_cartridge(const rom_entry *romrgn, const rom_entry *roment, bool load);
72   int process_cartridge(bool load);
73   
74
75   const char *               m_extensions;
76   const char *               m_interface;
77   bool                     m_must_be_loaded;
78   device_start_func            m_device_start;
79   device_image_load_func         m_device_load;
80   device_image_unload_func      m_device_unload;
81   device_image_partialhash_func   m_device_partialhash;
82   device_image_display_info_func   m_device_displayinfo;
4483};
4584
85// device type definition
86extern const device_type CARTSLOT;
4687
4788/***************************************************************************
4889    DEVICE CONFIGURATION MACROS
r13973r13974
5596   MCFG_DEVICE_MODIFY(_tag)                           \
5697
5798#define MCFG_CARTSLOT_EXTENSION_LIST(_extensions)                  \
58   MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, extensions, _extensions)
99   static_cast<cartslot_image_device *>(device)->set_extensions(_extensions);
59100
101#define MCFG_CARTSLOT_INTERFACE(_interface)                     \
102   static_cast<cartslot_image_device *>(device)->set_interface(_interface);
103
60104#define MCFG_CARTSLOT_NOT_MANDATORY                              \
61   MCFG_DEVICE_CONFIG_DATA32(cartslot_config, must_be_loaded, FALSE)
105   static_cast<cartslot_image_device *>(device)->set_must_be_loaded(FALSE);
62106
63107#define MCFG_CARTSLOT_MANDATORY                                 \
64   MCFG_DEVICE_CONFIG_DATA32(cartslot_config, must_be_loaded, TRUE)
108   static_cast<cartslot_image_device *>(device)->set_must_be_loaded(TRUE);
65109
66110#define MCFG_CARTSLOT_START(_start)                              \
67   MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, device_start, DEVICE_START_NAME(_start))
111   static_cast<cartslot_image_device *>(device)->set_device_start(DEVICE_START_NAME(_start));
68112
69113#define MCFG_CARTSLOT_LOAD(_load)                              \
70   MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, device_load, DEVICE_IMAGE_LOAD_NAME(_load))
114   static_cast<cartslot_image_device *>(device)->set_device_load(DEVICE_IMAGE_LOAD_NAME(_load));
71115
72116#define MCFG_CARTSLOT_UNLOAD(_unload)                           \
73   MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, device_unload, DEVICE_IMAGE_UNLOAD_NAME(_unload))
117   static_cast<cartslot_image_device *>(device)->set_device_unload(DEVICE_IMAGE_UNLOAD_NAME(_unload));
74118
75#define MCFG_CARTSLOT_DISPLAY_INFO(_displayinfo)                              \
76   MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, device_displayinfo, DEVICE_IMAGE_DISPLAY_INFO_NAME(_displayinfo))
77
78119#define MCFG_CARTSLOT_PARTIALHASH(_partialhash)                     \
79   MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, device_partialhash, _partialhash)
120   static_cast<cartslot_image_device *>(device)->set_partialhash(_partialhash);
80121
81#define MCFG_CARTSLOT_INTERFACE(_interface)                     \
82   MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, interface, _interface )
122#define MCFG_CARTSLOT_DISPLAY_INFO(_displayinfo)                              \
123   static_cast<cartslot_image_device *>(device)->set_displayinfo(DEVICE_IMAGE_DISPLAY_INFO_NAME(_displayinfo));
83124
84#endif /* __cart_slot_H__ */
125#endif /* __CARTSLOT_H__ */
src/emu/imagedev/cartslot.c
r13973r13974
1010#include "emu.h"
1111#include "cartslot.h"
1212
13/***************************************************************************
14    CONSTANTS
15***************************************************************************/
1613
17enum _process_mode
14// device type definition
15const device_type CARTSLOT = &device_creator<cartslot_image_device>;
16
17//-------------------------------------------------
18//  cartslot_image_device - constructor
19//-------------------------------------------------
20
21cartslot_image_device::cartslot_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
22    : device_t(mconfig, CARTSLOT, "Cartslot", tag, owner, clock),
23     device_image_interface(mconfig, *this),
24     m_extensions("bin"),
25     m_interface(NULL),
26     m_must_be_loaded(0),
27     m_device_start(NULL),
28     m_device_load(NULL),
29     m_device_unload(NULL),
30     m_device_partialhash(NULL),
31     m_device_displayinfo(NULL)
1832{
19   PROCESS_CLEAR,
20   PROCESS_LOAD
21};
22typedef enum _process_mode process_mode;
2333
34}
2435
25/***************************************************************************
26    INLINE FUNCTIONS
27***************************************************************************/
36//-------------------------------------------------
37//  cartslot_image_device - destructor
38//-------------------------------------------------
2839
29INLINE const cartslot_config *get_config(const device_t *device)
40cartslot_image_device::~cartslot_image_device()
3041{
31   assert(device != NULL);
32   assert(device->type() == CARTSLOT);
33   return (const cartslot_config *) downcast<const legacy_device_base *>(device)->inline_config();
3442}
3543
44//-------------------------------------------------
45//  device_config_complete - perform any
46//  operations now that the configuration is
47//  complete
48//-------------------------------------------------
49
50void cartslot_image_device::device_config_complete()
51{
52   // set brief and instance name
53   update_names();
54}
55
3656/***************************************************************************
3757    IMPLEMENTATION
3858***************************************************************************/
r13973r13974
4161    load_cartridge
4262-------------------------------------------------*/
4363
44static int load_cartridge(device_image_interface *image, const rom_entry *romrgn, const rom_entry *roment, process_mode mode)
64int cartslot_image_device::load_cartridge(const rom_entry *romrgn, const rom_entry *roment, bool load)
4565{
4666   const char *region;
4767   const char *type;
4868   UINT32 flags;
49   offs_t offset, length, read_length, pos = 0, len;
69   offs_t offset, size, read_length, pos = 0, len;
5070   UINT8 *ptr;
5171   UINT8 clear_val;
5272   int datawidth, littleendian, i, j;
5373   device_t *cpu;
5474
5575   astring regiontag;
56   image->device().siblingtag(regiontag, ROMREGION_GETTAG(romrgn));
76   device().siblingtag(regiontag, ROMREGION_GETTAG(romrgn));
5777   region = regiontag.cstr();
5878   offset = ROM_GETOFFSET(roment);
59   length = ROM_GETLENGTH(roment);
79   size = ROM_GETLENGTH(roment);
6080   flags = ROM_GETFLAGS(roment);
61   ptr = ((UINT8 *) image->device().machine().region(region)->base()) + offset;
81   ptr = ((UINT8 *) device().machine().region(region)->base()) + offset;
6282
63   if (mode == PROCESS_LOAD)
83   if (load)
6484   {
65      if (image->software_entry() == NULL)
85      if (software_entry() == NULL)
6686      {
6787         /* must this be full size */
6888         if (flags & ROM_FULLSIZE)
6989         {
70            if (image->length() != length)
90            if (length() != size)
7191               return IMAGE_INIT_FAIL;
7292         }
7393
7494         /* read the ROM */
75         pos = read_length = image->fread(ptr, length);
95         pos = read_length = fread(ptr, size);
7696
7797         /* reset the ROM to the initial point. */
7898         /* eventually, we could add a flag to allow the ROM to continue instead of restarting whenever a new cart region is present */
79         image->fseek(0, SEEK_SET);
99         fseek(0, SEEK_SET);
80100      }
81101      else
82102      {
83103         /* must this be full size */
84104         if (flags & ROM_FULLSIZE)
85105         {
86            if (image->get_software_region_length("rom") != length)
106            if (get_software_region_length("rom") != size)
87107               return IMAGE_INIT_FAIL;
88108         }
89109
90110         /* read the ROM */
91         pos = read_length = image->get_software_region_length("rom");
92         memcpy(ptr, image->get_software_region("rom"), read_length);
111         pos = read_length = get_software_region_length("rom");
112         memcpy(ptr, get_software_region("rom"), read_length);
93113      }
94114
95115      /* do we need to mirror the ROM? */
96116      if (flags & ROM_MIRROR)
97117      {
98         while(pos < length)
118         while(pos < size)
99119         {
100            len = MIN(read_length, length - pos);
120            len = MIN(read_length, size - pos);
101121            memcpy(ptr + pos, ptr, len);
102122            pos += len;
103123         }
r13973r13974
110130
111131      /* if the region is inverted, do that now */
112132      device_memory_interface *memory;
113      cpu = image->device().machine().device(type);
133      cpu = device().machine().device(type);
114134      if (cpu!=NULL && cpu->interface(memory))
115135      {
116136         datawidth = cpu->memory().space_config(AS_PROGRAM)->m_databus_width / 8;
r13973r13974
124144      if (datawidth > 1 && littleendian)
125145#endif
126146      {
127         for (i = 0; i < length; i += datawidth)
147         for (i = 0; i < size; i += datawidth)
128148         {
129149            UINT8 temp[8];
130150            memcpy(temp, &ptr[i], datawidth);
r13973r13974
138158   if (!(flags & ROM_NOCLEAR))
139159   {
140160      clear_val = (flags & ROM_FILL_FF) ? 0xFF : 0x00;
141      memset(ptr + pos, clear_val, length - pos);
161      memset(ptr + pos, clear_val, size - pos);
142162   }
143163   return IMAGE_INIT_PASS;
144164}
r13973r13974
149169    process_cartridge
150170-------------------------------------------------*/
151171
152static int process_cartridge(device_image_interface *image, process_mode mode)
172int cartslot_image_device::process_cartridge(bool load)
153173{
154174   const rom_source *source;
155175   const rom_entry *romrgn, *roment;
156176   int result = 0;
157177
158   for (source = rom_first_source(image->device().machine().config()); source != NULL; source = rom_next_source(*source))
178   for (source = rom_first_source(device().machine().config()); source != NULL; source = rom_next_source(*source))
159179   {
160180      for (romrgn = rom_first_region(*source); romrgn != NULL; romrgn = rom_next_region(romrgn))
161181      {
r13973r13974
165185            if (ROMENTRY_GETTYPE(roment) == ROMENTRYTYPE_CARTRIDGE)
166186            {
167187               astring regiontag;
168               image->device().siblingtag(regiontag, roment->_hashdata);
188               device().siblingtag(regiontag, roment->_hashdata);
169189
170               if (strcmp(regiontag.cstr(),image->device().tag())==0)
190               if (strcmp(regiontag.cstr(),device().tag())==0)
171191               {
172                  result |= load_cartridge(image, romrgn, roment, mode);
192                  result |= load_cartridge(romrgn, roment, load);
173193
174194                  /* if loading failed in any cart region, stop loading */
175195                  if (result)
r13973r13974
184204   return IMAGE_INIT_PASS;
185205}
186206
187/*-------------------------------------------------
188    DEVICE_START( cartslot )
189-------------------------------------------------*/
207//-------------------------------------------------
208//  device_start - device-specific startup
209//-------------------------------------------------
190210
191static DEVICE_START( cartslot )
211void cartslot_image_device::device_start()
192212{
193   const cartslot_config *config = get_config(device);
194213
195214   /* if this cartridge has a custom DEVICE_START, use it */
196   if (config->device_start != NULL)
215   if (m_device_start != NULL)
197216   {
198      (*config->device_start)(device);
217      (*m_device_start)(this);
199218   }
200219}
201220
202221
203222/*-------------------------------------------------
204    DEVICE_IMAGE_LOAD( cartslot )
223    call_load
205224-------------------------------------------------*/
206225
207static DEVICE_IMAGE_LOAD( cartslot )
226bool cartslot_image_device::call_load()
208227{
209   device_t *device = &image.device();
210   const cartslot_config *config = get_config(device);
211
212228   /* if this cartridge has a custom DEVICE_IMAGE_LOAD, use it */
213   if (config->device_load != NULL)
214      return (*config->device_load)(image);
229   if (m_device_load != NULL)
230      return (*m_device_load)(*this);
215231
216232   /* otherwise try the normal route */
217   return process_cartridge(&image, PROCESS_LOAD);
233   return process_cartridge(true);
218234}
219235
220236
221237/*-------------------------------------------------
222    DEVICE_IMAGE_UNLOAD( cartslot )
238    call_unload
223239-------------------------------------------------*/
224
225static DEVICE_IMAGE_UNLOAD( cartslot )
240void cartslot_image_device::call_unload()
226241{
227   device_t *device = &image.device();
228   const cartslot_config *config = get_config(device);
229
230242   /* if this cartridge has a custom DEVICE_IMAGE_UNLOAD, use it */
231   if (config->device_unload != NULL)
243   if (m_device_unload != NULL)
232244   {
233      (*config->device_unload)(image);
245      (*m_device_unload)(*this);
234246      return;
235247   }
236   process_cartridge(&image, PROCESS_CLEAR);
248   process_cartridge(false);
237249}
238250
239/*-------------------------------------------------
240    DEVICE_IMAGE_SOFTLIST_LOAD(cartslot)
241-------------------------------------------------*/
242static DEVICE_IMAGE_SOFTLIST_LOAD(cartslot)
243{
244   load_software_part_region( &image.device(), swlist, swname, start_entry );
245   return TRUE;
246}
247251
248/*-------------------------------------------------
249    DEVICE_GET_INFO( cartslot )
250-------------------------------------------------*/
251
252DEVICE_GET_INFO( cartslot )
253{
254   switch(state)
255   {
256      /* --- the following bits of info are returned as 64-bit signed integers --- */
257      case DEVINFO_INT_TOKEN_BYTES:            info->i = 0; break;
258      case DEVINFO_INT_INLINE_CONFIG_BYTES:      info->i = sizeof(cartslot_config); break;
259      case DEVINFO_INT_IMAGE_TYPE:            info->i = IO_CARTSLOT; break;
260      case DEVINFO_INT_IMAGE_READABLE:         info->i = 1; break;
261      case DEVINFO_INT_IMAGE_WRITEABLE:         info->i = 0; break;
262      case DEVINFO_INT_IMAGE_CREATABLE:         info->i = 0; break;
263      case DEVINFO_INT_IMAGE_RESET_ON_LOAD:      info->i = 1; break;
264      case DEVINFO_INT_IMAGE_MUST_BE_LOADED:
265         if ( device && downcast<const legacy_image_device_base *>(device)->inline_config()) {
266            info->i = get_config(device)->must_be_loaded;
267         } else {
268            info->i = 0;
269         }
270         break;
271
272      /* --- the following bits of info are returned as pointers to functions --- */
273      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME(cartslot);               break;
274      case DEVINFO_FCT_IMAGE_LOAD:            info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(cartslot);      break;
275      case DEVINFO_FCT_IMAGE_UNLOAD:            info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(cartslot);      break;
276      case DEVINFO_FCT_IMAGE_SOFTLIST_LOAD:      info->f = (genf *) DEVICE_IMAGE_SOFTLIST_LOAD_NAME(cartslot);   break;
277      case DEVINFO_FCT_IMAGE_PARTIAL_HASH:
278         if ( device && downcast<const legacy_image_device_base *>(device)->inline_config() && get_config(device)->device_partialhash) {
279            info->f = (genf *) get_config(device)->device_partialhash;
280         } else {
281            info->f = NULL;
282         }
283         break;
284      case DEVINFO_FCT_IMAGE_DISPLAY_INFO:
285         if ( device && downcast<const legacy_image_device_base *>(device)->inline_config() && get_config(device)->device_displayinfo) {
286            info->f = (genf *) get_config(device)->device_displayinfo;
287         } else {
288            info->f = NULL;
289         }
290         break;
291
292      /* --- the following bits of info are returned as NULL-terminated strings --- */
293      case DEVINFO_STR_NAME:                  strcpy(info->s, "Cartslot"); break;
294      case DEVINFO_STR_FAMILY:               strcpy(info->s, "Cartslot"); break;
295      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__); break;
296      case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:
297         if ( device && downcast<const legacy_image_device_base *>(device)->inline_config() && get_config(device)->extensions )
298         {
299            strcpy(info->s, get_config(device)->extensions);
300         }
301         else
302         {
303            strcpy(info->s, "bin");
304         }
305         break;
306      case DEVINFO_STR_IMAGE_INTERFACE:
307         if ( device && downcast<const legacy_image_device_base *>(device)->inline_config() && get_config(device)->interface )
308         {
309            strcpy(info->s, get_config(device)->interface );
310         }
311         break;
312   }
313}
314
315DEFINE_LEGACY_IMAGE_DEVICE(CARTSLOT, cartslot);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team