mirror of
https://github.com/holub/mame
synced 2025-04-28 19:14:55 +03:00
Made multcart slot separate device, and prepared cartslot for rewrite (no whatsnew)
This commit is contained in:
parent
26fbdd4206
commit
31f7bf981f
@ -9,7 +9,6 @@
|
||||
#include <ctype.h>
|
||||
#include "emu.h"
|
||||
#include "cartslot.h"
|
||||
#include "multcart.h"
|
||||
|
||||
/***************************************************************************
|
||||
CONSTANTS
|
||||
@ -27,14 +26,6 @@ typedef enum _process_mode process_mode;
|
||||
INLINE FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
INLINE cartslot_t *get_token(device_t *device)
|
||||
{
|
||||
assert(device != NULL);
|
||||
assert(device->type() == CARTSLOT);
|
||||
return (cartslot_t *) downcast<legacy_device_base *>(device)->token();
|
||||
}
|
||||
|
||||
|
||||
INLINE const cartslot_config *get_config(const device_t *device)
|
||||
{
|
||||
assert(device != NULL);
|
||||
@ -42,7 +33,6 @@ INLINE const cartslot_config *get_config(const device_t *device)
|
||||
return (const cartslot_config *) downcast<const legacy_device_base *>(device)->inline_config();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
IMPLEMENTATION
|
||||
***************************************************************************/
|
||||
@ -194,95 +184,19 @@ static int process_cartridge(device_image_interface *image, process_mode mode)
|
||||
return IMAGE_INIT_PASS;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
cartslot_get_pcb
|
||||
-------------------------------------------------*/
|
||||
|
||||
device_t *cartslot_get_pcb(device_t *device)
|
||||
{
|
||||
cartslot_t *cart = get_token(device);
|
||||
return cart->pcb_device;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
cartslot_get_socket
|
||||
-------------------------------------------------*/
|
||||
|
||||
void *cartslot_get_socket(device_t *device, const char *socket_name)
|
||||
{
|
||||
cartslot_t *cart = get_token(device);
|
||||
device_image_interface *image = dynamic_cast<device_image_interface *>(device);
|
||||
void *result = NULL;
|
||||
|
||||
if (cart->mc != NULL)
|
||||
{
|
||||
const multicart_socket *socket;
|
||||
for (socket = cart->mc->sockets; socket != NULL; socket = socket->next)
|
||||
{
|
||||
if (!strcmp(socket->id, socket_name))
|
||||
break;
|
||||
}
|
||||
result = socket ? socket->ptr : NULL;
|
||||
}
|
||||
else if (socket_name[0] == '\0')
|
||||
{
|
||||
result = image->ptr();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
cartslot_get_resource_length
|
||||
-------------------------------------------------*/
|
||||
|
||||
int cartslot_get_resource_length(device_t *device, const char *socket_name)
|
||||
{
|
||||
cartslot_t *cart = get_token(device);
|
||||
int result = 0;
|
||||
|
||||
if (cart->mc != NULL)
|
||||
{
|
||||
const multicart_socket *socket;
|
||||
|
||||
for (socket = cart->mc->sockets; socket != NULL; socket = socket->next)
|
||||
{
|
||||
if (!strcmp(socket->id, socket_name)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (socket != NULL)
|
||||
result = socket->resource->length;
|
||||
}
|
||||
else
|
||||
result = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_START( cartslot )
|
||||
-------------------------------------------------*/
|
||||
|
||||
static DEVICE_START( cartslot )
|
||||
{
|
||||
cartslot_t *cart = get_token(device);
|
||||
const cartslot_config *config = get_config(device);
|
||||
|
||||
/* if this cartridge has a custom DEVICE_START, use it */
|
||||
if (config->device_start != NULL)
|
||||
{
|
||||
(*config->device_start)(device);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* find the PCB (if there is one) */
|
||||
cart->pcb_device = device->subdevice(TAG_PCB);
|
||||
|
||||
done:
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -292,28 +206,15 @@ done:
|
||||
|
||||
static DEVICE_IMAGE_LOAD( cartslot )
|
||||
{
|
||||
int result;
|
||||
device_t *device = &image.device();
|
||||
cartslot_t *cart = get_token(device);
|
||||
const cartslot_config *config = get_config(device);
|
||||
|
||||
/* if this cartridge has a custom DEVICE_IMAGE_LOAD, use it */
|
||||
if (config->device_load != NULL)
|
||||
return (*config->device_load)(image);
|
||||
|
||||
/* try opening this as if it were a multicart */
|
||||
multicart_open(device->machine().options(), image.filename(), device->machine().system().name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc);
|
||||
if (cart->mc == NULL)
|
||||
{
|
||||
|
||||
|
||||
/* otherwise try the normal route */
|
||||
result = process_cartridge(&image, PROCESS_LOAD);
|
||||
if (result != IMAGE_INIT_PASS)
|
||||
return result;
|
||||
}
|
||||
|
||||
return IMAGE_INIT_PASS;
|
||||
/* otherwise try the normal route */
|
||||
return process_cartridge(&image, PROCESS_LOAD);
|
||||
}
|
||||
|
||||
|
||||
@ -324,7 +225,6 @@ static DEVICE_IMAGE_LOAD( cartslot )
|
||||
static DEVICE_IMAGE_UNLOAD( cartslot )
|
||||
{
|
||||
device_t *device = &image.device();
|
||||
cartslot_t *cart = get_token(device);
|
||||
const cartslot_config *config = get_config(device);
|
||||
|
||||
/* if this cartridge has a custom DEVICE_IMAGE_UNLOAD, use it */
|
||||
@ -333,82 +233,9 @@ static DEVICE_IMAGE_UNLOAD( cartslot )
|
||||
(*config->device_unload)(image);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cart->mc != NULL)
|
||||
{
|
||||
multicart_close(device->machine().options(), cart->mc);
|
||||
cart->mc = NULL;
|
||||
}
|
||||
|
||||
process_cartridge(&image, PROCESS_CLEAR);
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
identify_pcb
|
||||
-------------------------------------------------*/
|
||||
|
||||
static const cartslot_pcb_type *identify_pcb(device_image_interface &image)
|
||||
{
|
||||
const cartslot_config *config = get_config(&image.device());
|
||||
astring pcb_name;
|
||||
const cartslot_pcb_type *pcb_type = NULL;
|
||||
multicart_t *mc;
|
||||
int i;
|
||||
|
||||
if (image.exists())
|
||||
{
|
||||
/* try opening this as if it were a multicart */
|
||||
multicart_open_error me = multicart_open(image.device().machine().options(), image.filename(), image.device().machine().system().name, MULTICART_FLAGS_DONT_LOAD_RESOURCES, &mc);
|
||||
if (me == MCERR_NONE)
|
||||
{
|
||||
/* this was a multicart - read from it */
|
||||
astring_cpyc(&pcb_name, mc->pcb_type);
|
||||
multicart_close(image.device().machine().options(), mc);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (me != MCERR_NOT_MULTICART)
|
||||
fatalerror("multicart error: %s", multicart_error_text(me));
|
||||
}
|
||||
|
||||
/* look for PCB type with matching name */
|
||||
for (i = 0; (i < ARRAY_LENGTH(config->pcb_types)) && (config->pcb_types[i].name != NULL); i++)
|
||||
{
|
||||
if ((config->pcb_types[i].name[0] == '\0') || !strcmp(astring_c(&pcb_name), config->pcb_types[i].name))
|
||||
{
|
||||
pcb_type = &config->pcb_types[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for unknown PCB type */
|
||||
if ((mc != NULL) && (pcb_type == NULL))
|
||||
fatalerror("Unknown PCB type \"%s\"", astring_c(&pcb_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no device loaded; use the default */
|
||||
pcb_type = (config->pcb_types[0].name != NULL) ? &config->pcb_types[0] : NULL;
|
||||
}
|
||||
return pcb_type;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_IMAGE_GET_DEVICES(cartslot)
|
||||
-------------------------------------------------*/
|
||||
static DEVICE_IMAGE_GET_DEVICES(cartslot)
|
||||
{
|
||||
const cartslot_pcb_type *pcb_type;
|
||||
device_t *device = &image.device();
|
||||
|
||||
pcb_type = identify_pcb(image);
|
||||
if (pcb_type != NULL)
|
||||
{
|
||||
image_add_device_with_subdevices(device,pcb_type->devtype,TAG_PCB,0);
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_IMAGE_SOFTLIST_LOAD(cartslot)
|
||||
-------------------------------------------------*/
|
||||
@ -427,7 +254,7 @@ DEVICE_GET_INFO( cartslot )
|
||||
switch(state)
|
||||
{
|
||||
/* --- the following bits of info are returned as 64-bit signed integers --- */
|
||||
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cartslot_t); break;
|
||||
case DEVINFO_INT_TOKEN_BYTES: info->i = 0; break;
|
||||
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(cartslot_config); break;
|
||||
case DEVINFO_INT_IMAGE_TYPE: info->i = IO_CARTSLOT; break;
|
||||
case DEVINFO_INT_IMAGE_READABLE: info->i = 1; break;
|
||||
@ -446,7 +273,6 @@ DEVICE_GET_INFO( cartslot )
|
||||
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(cartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(cartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_GET_DEVICES: info->f = (genf *) DEVICE_IMAGE_GET_DEVICES_NAME(cartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_SOFTLIST_LOAD: info->f = (genf *) DEVICE_IMAGE_SOFTLIST_LOAD_NAME(cartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_PARTIAL_HASH:
|
||||
if ( device && downcast<const legacy_image_device_base *>(device)->inline_config() && get_config(device)->device_partialhash) {
|
||||
@ -487,40 +313,3 @@ DEVICE_GET_INFO( cartslot )
|
||||
}
|
||||
|
||||
DEFINE_LEGACY_IMAGE_DEVICE(CARTSLOT, cartslot);
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
// DEVICE CARTSLOT INTERFACE
|
||||
//**************************************************************************
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_cart_slot_interface - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
device_cart_slot_interface::device_cart_slot_interface(const machine_config &mconfig, device_t &device)
|
||||
: device_interface(device)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// ~device_cart_slot_interface - destructor
|
||||
//-------------------------------------------------
|
||||
|
||||
device_cart_slot_interface::~device_cart_slot_interface()
|
||||
{
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
// LIVE LEGACY cart_slot DEVICE
|
||||
//**************************************************************************
|
||||
|
||||
//-------------------------------------------------
|
||||
// legacy_cart_slot_device_base - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
legacy_cart_slot_device_base::legacy_cart_slot_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, device_get_config_func get_config)
|
||||
: legacy_device_base(mconfig, type, tag, owner, clock, get_config),
|
||||
device_cart_slot_interface(mconfig, *this)
|
||||
{
|
||||
}
|
||||
|
@ -8,14 +8,11 @@
|
||||
#define __CARTSLOT_H__
|
||||
|
||||
#include "image.h"
|
||||
#include "multcart.h"
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
MACROS
|
||||
***************************************************************************/
|
||||
#define TAG_PCB "pcb"
|
||||
|
||||
#define ROM_CART_LOAD(tag,offset,length,flags) \
|
||||
{ NULL, tag, offset, length, ROMENTRYTYPE_CARTRIDGE | (flags) },
|
||||
|
||||
@ -33,22 +30,6 @@ DECLARE_LEGACY_IMAGE_DEVICE(CARTSLOT, cartslot);
|
||||
TYPE DEFINITIONS
|
||||
***************************************************************************/
|
||||
|
||||
typedef struct _cartslot_t cartslot_t;
|
||||
struct _cartslot_t
|
||||
{
|
||||
device_t *pcb_device;
|
||||
multicart_t *mc;
|
||||
};
|
||||
|
||||
|
||||
typedef struct _cartslot_pcb_type cartslot_pcb_type;
|
||||
struct _cartslot_pcb_type
|
||||
{
|
||||
const char * name;
|
||||
device_type devtype;
|
||||
};
|
||||
|
||||
|
||||
typedef struct _cartslot_config cartslot_config;
|
||||
struct _cartslot_config
|
||||
{
|
||||
@ -60,24 +41,9 @@ struct _cartslot_config
|
||||
device_image_unload_func device_unload;
|
||||
device_image_partialhash_func device_partialhash;
|
||||
device_image_display_info_func device_displayinfo;
|
||||
cartslot_pcb_type pcb_types[16];
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
FUNCTION PROTOTYPES
|
||||
***************************************************************************/
|
||||
|
||||
/* accesses the PCB associated with this cartslot */
|
||||
device_t *cartslot_get_pcb(device_t *device);
|
||||
|
||||
/* accesses a particular socket */
|
||||
void *cartslot_get_socket(device_t *device, const char *socket_name);
|
||||
|
||||
/* accesses a particular socket; gets the length of the associated resource */
|
||||
int cartslot_get_resource_length(device_t *device, const char *socket_name);
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
DEVICE CONFIGURATION MACROS
|
||||
***************************************************************************/
|
||||
@ -112,44 +78,7 @@ int cartslot_get_resource_length(device_t *device, const char *socket_name);
|
||||
#define MCFG_CARTSLOT_PARTIALHASH(_partialhash) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, device_partialhash, _partialhash)
|
||||
|
||||
#define MCFG_CARTSLOT_PCBTYPE(_index, _pcb_type_name, _pcb_devtype) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR_ARRAY_MEMBER(cartslot_config, pcb_types, _index, cartslot_pcb_type, name, _pcb_type_name) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR_ARRAY_MEMBER(cartslot_config, pcb_types, _index, cartslot_pcb_type, devtype, _pcb_devtype)
|
||||
|
||||
#define MCFG_CARTSLOT_INTERFACE(_interface) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR(cartslot_config, interface, _interface )
|
||||
|
||||
#define DECLARE_LEGACY_CART_SLOT_DEVICE(name, basename) _DECLARE_LEGACY_DEVICE(name, basename, basename##_device, legacy_cart_slot_device_base)
|
||||
#define DEFINE_LEGACY_CART_SLOT_DEVICE(name, basename) _DEFINE_LEGACY_DEVICE(name, basename, basename##_device, legacy_cart_slot_device_base)
|
||||
|
||||
|
||||
// ======================> device_cart_slot_interface
|
||||
|
||||
// class representing interface-specific live cart_slot
|
||||
class device_cart_slot_interface : public device_interface
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
device_cart_slot_interface(const machine_config &mconfig, device_t &device);
|
||||
virtual ~device_cart_slot_interface();
|
||||
};
|
||||
|
||||
|
||||
// ======================> legacy_cart_slot_device
|
||||
|
||||
// legacy_cart_slot_device is a legacy_device_base with a cart_slot interface
|
||||
class legacy_cart_slot_device_base : public legacy_device_base,
|
||||
public device_cart_slot_interface
|
||||
{
|
||||
protected:
|
||||
// construction/destruction
|
||||
legacy_cart_slot_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, device_get_config_func get_config);
|
||||
|
||||
public:
|
||||
using legacy_device_base::get_legacy_int;
|
||||
using legacy_device_base::get_legacy_fct;
|
||||
using legacy_device_base::get_legacy_ptr;
|
||||
|
||||
// device_cart_slot_interface overrides
|
||||
};
|
||||
#endif /* __cart_slot_H__ */
|
||||
|
@ -61,10 +61,161 @@ const char *multicart_error_text(multicart_open_error error)
|
||||
return error_text[(int)error];
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
INLINE FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
INLINE multicartslot_t *get_token(device_t *device)
|
||||
{
|
||||
assert(device != NULL);
|
||||
assert(device->type() == MULTICARTSLOT);
|
||||
return (multicartslot_t *) downcast<legacy_device_base *>(device)->token();
|
||||
}
|
||||
|
||||
|
||||
INLINE const multicartslot_config *get_config(const device_t *device)
|
||||
{
|
||||
assert(device != NULL);
|
||||
assert(device->type() == MULTICARTSLOT);
|
||||
return (const multicartslot_config *) downcast<const legacy_device_base *>(device)->inline_config();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
IMPLEMENTATION
|
||||
***************************************************************************/
|
||||
|
||||
/*-------------------------------------------------
|
||||
cartslot_get_pcb
|
||||
-------------------------------------------------*/
|
||||
|
||||
device_t *cartslot_get_pcb(device_t *device)
|
||||
{
|
||||
multicartslot_t *cart = get_token(device);
|
||||
return cart->pcb_device;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
cartslot_get_socket
|
||||
-------------------------------------------------*/
|
||||
|
||||
void *cartslot_get_socket(device_t *device, const char *socket_name)
|
||||
{
|
||||
multicartslot_t *cart = get_token(device);
|
||||
device_image_interface *image = dynamic_cast<device_image_interface *>(device);
|
||||
void *result = NULL;
|
||||
|
||||
if (cart->mc != NULL)
|
||||
{
|
||||
const multicart_socket *socket;
|
||||
for (socket = cart->mc->sockets; socket != NULL; socket = socket->next)
|
||||
{
|
||||
if (!strcmp(socket->id, socket_name))
|
||||
break;
|
||||
}
|
||||
result = socket ? socket->ptr : NULL;
|
||||
}
|
||||
else if (socket_name[0] == '\0')
|
||||
{
|
||||
result = image->ptr();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
cartslot_get_resource_length
|
||||
-------------------------------------------------*/
|
||||
|
||||
int cartslot_get_resource_length(device_t *device, const char *socket_name)
|
||||
{
|
||||
multicartslot_t *cart = get_token(device);
|
||||
int result = 0;
|
||||
|
||||
if (cart->mc != NULL)
|
||||
{
|
||||
const multicart_socket *socket;
|
||||
|
||||
for (socket = cart->mc->sockets; socket != NULL; socket = socket->next)
|
||||
{
|
||||
if (!strcmp(socket->id, socket_name)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (socket != NULL)
|
||||
result = socket->resource->length;
|
||||
}
|
||||
else
|
||||
result = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
/*-------------------------------------------------
|
||||
identify_pcb
|
||||
-------------------------------------------------*/
|
||||
|
||||
static const multicartslot_pcb_type *identify_pcb(device_image_interface &image)
|
||||
{
|
||||
const multicartslot_config *config = get_config(&image.device());
|
||||
astring pcb_name;
|
||||
const multicartslot_pcb_type *pcb_type = NULL;
|
||||
multicart_t *mc;
|
||||
int i;
|
||||
|
||||
if (image.exists())
|
||||
{
|
||||
/* try opening this as if it were a multicart */
|
||||
multicart_open_error me = multicart_open(image.device().machine().options(), image.filename(), image.device().machine().system().name, MULTICART_FLAGS_DONT_LOAD_RESOURCES, &mc);
|
||||
if (me == MCERR_NONE)
|
||||
{
|
||||
/* this was a multicart - read from it */
|
||||
astring_cpyc(&pcb_name, mc->pcb_type);
|
||||
multicart_close(image.device().machine().options(), mc);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (me != MCERR_NOT_MULTICART)
|
||||
fatalerror("multicart error: %s", multicart_error_text(me));
|
||||
}
|
||||
|
||||
/* look for PCB type with matching name */
|
||||
for (i = 0; (i < ARRAY_LENGTH(config->pcb_types)) && (config->pcb_types[i].name != NULL); i++)
|
||||
{
|
||||
if ((config->pcb_types[i].name[0] == '\0') || !strcmp(astring_c(&pcb_name), config->pcb_types[i].name))
|
||||
{
|
||||
pcb_type = &config->pcb_types[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for unknown PCB type */
|
||||
if ((mc != NULL) && (pcb_type == NULL))
|
||||
fatalerror("Unknown PCB type \"%s\"", astring_c(&pcb_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no device loaded; use the default */
|
||||
pcb_type = (config->pcb_types[0].name != NULL) ? &config->pcb_types[0] : NULL;
|
||||
}
|
||||
return pcb_type;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_IMAGE_GET_DEVICES(cartslot)
|
||||
-------------------------------------------------*/
|
||||
static DEVICE_IMAGE_GET_DEVICES(multicartslot)
|
||||
{
|
||||
const multicartslot_pcb_type *pcb_type;
|
||||
device_t *device = &image.device();
|
||||
|
||||
pcb_type = identify_pcb(image);
|
||||
if (pcb_type != NULL)
|
||||
{
|
||||
image_add_device_with_subdevices(device,pcb_type->devtype,TAG_PCB,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
find_file
|
||||
-------------------------------------------------*/
|
||||
@ -606,3 +757,132 @@ void multicart_close(emu_options &options, multicart_t *cart)
|
||||
save_ram_resources(options, cart);
|
||||
pool_free_lib(cart->data->pool);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_START( multicartslot )
|
||||
-------------------------------------------------*/
|
||||
|
||||
static DEVICE_START( multicartslot )
|
||||
{
|
||||
const multicartslot_config *config = get_config(device);
|
||||
|
||||
/* if this cartridge has a custom DEVICE_START, use it */
|
||||
if (config->device_start != NULL)
|
||||
{
|
||||
(*config->device_start)(device);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_IMAGE_LOAD( cartslot )
|
||||
-------------------------------------------------*/
|
||||
|
||||
static DEVICE_IMAGE_LOAD( multicartslot )
|
||||
{
|
||||
device_t *device = &image.device();
|
||||
const multicartslot_config *config = get_config(device);
|
||||
|
||||
/* if this cartridge has a custom DEVICE_IMAGE_LOAD, use it */
|
||||
if (config->device_load != NULL)
|
||||
return (*config->device_load)(image);
|
||||
|
||||
/* otherwise try the normal route */
|
||||
return IMAGE_INIT_PASS;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_IMAGE_UNLOAD( multicartslot )
|
||||
-------------------------------------------------*/
|
||||
|
||||
static DEVICE_IMAGE_UNLOAD( multicartslot )
|
||||
{
|
||||
device_t *device = &image.device();
|
||||
const multicartslot_config *config = get_config(device);
|
||||
|
||||
/* if this cartridge has a custom DEVICE_IMAGE_UNLOAD, use it */
|
||||
if (config->device_unload != NULL)
|
||||
{
|
||||
(*config->device_unload)(image);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*-------------------------------------------------
|
||||
DEVICE_GET_INFO( multicartslot )
|
||||
-------------------------------------------------*/
|
||||
|
||||
DEVICE_GET_INFO( multicartslot )
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
/* --- the following bits of info are returned as 64-bit signed integers --- */
|
||||
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(multicartslot_t); break;
|
||||
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(multicartslot_config); break;
|
||||
case DEVINFO_INT_IMAGE_TYPE: info->i = IO_CARTSLOT; break;
|
||||
case DEVINFO_INT_IMAGE_READABLE: info->i = 1; break;
|
||||
case DEVINFO_INT_IMAGE_WRITEABLE: info->i = 0; break;
|
||||
case DEVINFO_INT_IMAGE_CREATABLE: info->i = 0; break;
|
||||
case DEVINFO_INT_IMAGE_RESET_ON_LOAD: info->i = 1; break;
|
||||
case DEVINFO_INT_IMAGE_MUST_BE_LOADED: info->i = 0; break;
|
||||
|
||||
/* --- the following bits of info are returned as pointers to functions --- */
|
||||
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(multicartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(multicartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(multicartslot); break;
|
||||
case DEVINFO_FCT_IMAGE_GET_DEVICES: info->f = (genf *) DEVICE_IMAGE_GET_DEVICES_NAME(multicartslot); break;
|
||||
|
||||
/* --- the following bits of info are returned as NULL-terminated strings --- */
|
||||
case DEVINFO_STR_NAME: strcpy(info->s, "MultiCartslot"); break;
|
||||
case DEVINFO_STR_FAMILY: strcpy(info->s, "MultiCartslot"); break;
|
||||
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
|
||||
case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:
|
||||
if ( device && downcast<const legacy_image_device_base *>(device)->inline_config() && get_config(device)->extensions )
|
||||
{
|
||||
strcpy(info->s, get_config(device)->extensions);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(info->s, "bin");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_LEGACY_IMAGE_DEVICE(MULTICARTSLOT, multicartslot);
|
||||
|
||||
//**************************************************************************
|
||||
// DEVICE CARTSLOT INTERFACE
|
||||
//**************************************************************************
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_cart_slot_interface - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
device_cart_slot_interface::device_cart_slot_interface(const machine_config &mconfig, device_t &device)
|
||||
: device_interface(device)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// ~device_cart_slot_interface - destructor
|
||||
//-------------------------------------------------
|
||||
|
||||
device_cart_slot_interface::~device_cart_slot_interface()
|
||||
{
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
// LIVE LEGACY cart_slot DEVICE
|
||||
//**************************************************************************
|
||||
|
||||
//-------------------------------------------------
|
||||
// legacy_cart_slot_device_base - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
legacy_cart_slot_device_base::legacy_cart_slot_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, device_get_config_func get_config)
|
||||
: legacy_device_base(mconfig, type, tag, owner, clock, get_config),
|
||||
device_cart_slot_interface(mconfig, *this)
|
||||
{
|
||||
}
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
#include "osdcore.h"
|
||||
|
||||
#define TAG_PCB "pcb"
|
||||
|
||||
DECLARE_LEGACY_IMAGE_DEVICE(MULTICARTSLOT, multicartslot);
|
||||
|
||||
/***************************************************************************
|
||||
TYPE DEFINITIONS
|
||||
@ -65,6 +68,31 @@ struct _multicart_t
|
||||
multicart_private * data;
|
||||
};
|
||||
|
||||
typedef struct _multicartslot_t multicartslot_t;
|
||||
struct _multicartslot_t
|
||||
{
|
||||
device_t *pcb_device;
|
||||
multicart_t *mc;
|
||||
};
|
||||
|
||||
|
||||
typedef struct _multicartslot_pcb_type multicartslot_pcb_type;
|
||||
struct _multicartslot_pcb_type
|
||||
{
|
||||
const char * name;
|
||||
device_type devtype;
|
||||
};
|
||||
|
||||
|
||||
typedef struct _multicartslot_config multicartslot_config;
|
||||
struct _multicartslot_config
|
||||
{
|
||||
const char * extensions;
|
||||
device_start_func device_start;
|
||||
device_image_load_func device_load;
|
||||
device_image_unload_func device_unload;
|
||||
multicartslot_pcb_type pcb_types[16];
|
||||
};
|
||||
|
||||
enum _multicart_open_error
|
||||
{
|
||||
@ -97,4 +125,70 @@ multicart_open_error multicart_open(emu_options &options, const char *filename,
|
||||
/* closes a multicart */
|
||||
void multicart_close(emu_options &options, multicart_t *cart);
|
||||
|
||||
/* accesses the PCB associated with this cartslot */
|
||||
device_t *cartslot_get_pcb(device_t *device);
|
||||
|
||||
/* accesses a particular socket */
|
||||
void *cartslot_get_socket(device_t *device, const char *socket_name);
|
||||
|
||||
/* accesses a particular socket; gets the length of the associated resource */
|
||||
int cartslot_get_resource_length(device_t *device, const char *socket_name);
|
||||
|
||||
#define DECLARE_LEGACY_CART_SLOT_DEVICE(name, basename) _DECLARE_LEGACY_DEVICE(name, basename, basename##_device, legacy_cart_slot_device_base)
|
||||
#define DEFINE_LEGACY_CART_SLOT_DEVICE(name, basename) _DEFINE_LEGACY_DEVICE(name, basename, basename##_device, legacy_cart_slot_device_base)
|
||||
|
||||
#define MCFG_MULTICARTSLOT_ADD(_tag) \
|
||||
MCFG_DEVICE_ADD(_tag, MULTICARTSLOT, 0) \
|
||||
|
||||
#define MCFG_MULTICARTSLOT_MODIFY(_tag) \
|
||||
MCFG_DEVICE_MODIFY(_tag) \
|
||||
|
||||
#define MCFG_MULTICARTSLOT_PCBTYPE(_index, _pcb_type_name, _pcb_devtype) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR_ARRAY_MEMBER(multicartslot_config, pcb_types, _index, multicartslot_pcb_type, name, _pcb_type_name) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR_ARRAY_MEMBER(multicartslot_config, pcb_types, _index, multicartslot_pcb_type, devtype, _pcb_devtype)
|
||||
|
||||
#define MCFG_MULTICARTSLOT_START(_start) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR(multicartslot_config, device_start, DEVICE_START_NAME(_start))
|
||||
|
||||
#define MCFG_MULTICARTSLOT_LOAD(_load) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR(multicartslot_config, device_load, DEVICE_IMAGE_LOAD_NAME(_load))
|
||||
|
||||
#define MCFG_MULTICARTSLOT_UNLOAD(_unload) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR(multicartslot_config, device_unload, DEVICE_IMAGE_UNLOAD_NAME(_unload))
|
||||
|
||||
#define MCFG_MULTICARTSLOT_EXTENSION_LIST(_extensions) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR(multicartslot_config, extensions, _extensions)
|
||||
|
||||
|
||||
// ======================> device_cart_slot_interface
|
||||
|
||||
// class representing interface-specific live cart_slot
|
||||
class device_cart_slot_interface : public device_interface
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
device_cart_slot_interface(const machine_config &mconfig, device_t &device);
|
||||
virtual ~device_cart_slot_interface();
|
||||
};
|
||||
|
||||
|
||||
// ======================> legacy_cart_slot_device
|
||||
|
||||
// legacy_cart_slot_device is a legacy_device_base with a cart_slot interface
|
||||
class legacy_cart_slot_device_base : public legacy_device_base,
|
||||
public device_cart_slot_interface
|
||||
{
|
||||
protected:
|
||||
// construction/destruction
|
||||
legacy_cart_slot_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, device_get_config_func get_config);
|
||||
|
||||
public:
|
||||
using legacy_device_base::get_legacy_int;
|
||||
using legacy_device_base::get_legacy_fct;
|
||||
using legacy_device_base::get_legacy_ptr;
|
||||
|
||||
// device_cart_slot_interface overrides
|
||||
};
|
||||
|
||||
|
||||
#endif /* __MULTCART_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user