- Moved RAM device into emu core [Miodrag Milanovic]

- Moved COMP and CONS macros in driver.h
This commit is contained in:
Miodrag Milanovic 2011-01-05 12:51:11 +00:00
parent f8b8f4f26b
commit 249def5363
8 changed files with 423 additions and 16 deletions

2
.gitattributes vendored
View File

@ -789,6 +789,8 @@ src/emu/machine/pic8259.c svneol=native#text/plain
src/emu/machine/pic8259.h svneol=native#text/plain
src/emu/machine/pit8253.c svneol=native#text/plain
src/emu/machine/pit8253.h svneol=native#text/plain
src/emu/machine/ram.c svneol=native#text/plain
src/emu/machine/ram.h svneol=native#text/plain
src/emu/machine/rescap.h svneol=native#text/plain
src/emu/machine/roc10937.c svneol=native#text/plain
src/emu/machine/roc10937.h svneol=native#text/plain

View File

@ -115,7 +115,41 @@ extern const game_driver GAME_NAME(NAME) = \
&LAYOUT[0] \
};
#define CONS(YEAR,NAME,PARENT,COMPAT,MACHINE,INPUT,INIT,COMPANY,FULLNAME,FLAGS) \
extern const game_driver GAME_NAME(NAME) = \
{ \
__FILE__, \
#PARENT, \
#NAME, \
FULLNAME, \
#YEAR, \
COMPANY, \
MACHINE_CONFIG_NAME(MACHINE), \
INPUT_PORTS_NAME(INPUT), \
DRIVER_INIT_NAME(INIT), \
ROM_NAME(NAME), \
#COMPAT, \
ROT0|(FLAGS), \
NULL \
};
#define COMP(YEAR,NAME,PARENT,COMPAT,MACHINE,INPUT,INIT,COMPANY,FULLNAME,FLAGS) \
extern const game_driver GAME_NAME(NAME) = \
{ \
__FILE__, \
#PARENT, \
#NAME, \
FULLNAME, \
#YEAR, \
COMPANY, \
MACHINE_CONFIG_NAME(MACHINE), \
INPUT_PORTS_NAME(INPUT), \
DRIVER_INIT_NAME(INIT), \
ROM_NAME(NAME), \
#COMPAT, \
ROT0|(FLAGS), \
NULL \
};
/***************************************************************************
GLOBAL VARIABLES

View File

@ -188,6 +188,7 @@ EMUMACHINEOBJS = \
$(EMUMACHINE)/pic8259.o \
$(EMUMACHINE)/pit8253.o \
$(EMUMACHINE)/pd4990a.o \
$(EMUMACHINE)/ram.o \
$(EMUMACHINE)/roc10937.o \
$(EMUMACHINE)/rp5h01.o \
$(EMUMACHINE)/rtc65271.o \

View File

@ -159,6 +159,10 @@ const options_entry mame_core_options[] =
{ "cheat;c", "0", OPTION_BOOLEAN, "enable cheat subsystem" },
{ "skip_gameinfo", "0", OPTION_BOOLEAN, "skip displaying the information screen at startup" },
{ "uifont", "default", 0, "specify a font to use" },
{ "ramsize;ram", NULL, 0, "size of RAM (if supported by driver)" },
#ifdef MESS
{ "newui;nu", "0", OPTION_BOOLEAN, "use the new MESS UI" },
#endif
/* image device options */
{ OPTION_ADDED_DEVICE_OPTIONS, "0", OPTION_BOOLEAN | OPTION_INTERNAL, "image device-specific options have been added" },
@ -306,10 +310,5 @@ core_options *mame_options_init(const options_entry *entries)
/* we need to dynamically add options when the device name is parsed */
options_set_option_callback(opts, OPTION_GAMENAME, image_driver_name_callback);
#ifdef MESS
mess_options_init(opts);
#endif /* MESS */
return opts;
}

View File

@ -153,6 +153,7 @@
#define OPTION_CHEAT "cheat"
#define OPTION_SKIP_GAMEINFO "skip_gameinfo"
#define OPTION_UI_FONT "uifont"
#define OPTION_RAMSIZE "ramsize"
/* image device options */
#define OPTION_ADDED_DEVICE_OPTIONS "added_device_options"

View File

@ -10,6 +10,7 @@
***************************************************************************/
#include "emu.h"
#include "machine/ram.h"
#include "sound/samples.h"
#include "info.h"
#include "xmlfile.h"
@ -990,6 +991,47 @@ static void print_game_software_list(FILE *out, const game_driver *game, const m
}
}
/* device iteration helpers */
#define ram_first(config) (config).m_devicelist.first(RAM)
#define ram_next(previous) ((previous)->typenext())
/*-------------------------------------------------
print_game_ramoptions - prints out all RAM
options for this system
-------------------------------------------------*/
static void print_game_ramoptions(FILE *out, const game_driver *game, const machine_config &config)
{
const device_config *device;
for (device = ram_first(config); device != NULL; device = ram_next(device))
{
ram_config *ram = (ram_config *)downcast<const legacy_device_config_base *>(device)->inline_config();
fprintf(out, "\t\t<ramoption default=\"1\">%u</ramoption>\n", ram_parse_string(ram->default_size));
if (ram->extra_options != NULL)
{
int j;
int size = strlen(ram->extra_options);
char * const s = mame_strdup(ram->extra_options);
char * const e = s + size;
char *p = s;
for (j=0;j<size;j++) {
if (p[j]==',') p[j]=0;
}
/* try to parse each option */
while(p <= e)
{
fprintf(out, "\t\t<ramoption>%u</ramoption>\n", ram_parse_string(p));
p += strlen(p);
if (p == e)
break;
p += 1;
}
osd_free(s);
}
}
}
/*-------------------------------------------------
print_game_info - print the XML information
for one particular game driver
@ -1064,11 +1106,8 @@ static void print_game_info(FILE *out, const game_driver *game)
print_game_adjusters(out, game, portlist);
print_game_driver(out, game, config);
print_game_images( out, game, config );
print_game_software_list( out, game, config );
#ifdef MESS
print_mess_game_xml(out, game, config);
#endif /* MESS */
print_game_software_list( out, game, config );
print_game_ramoptions( out, game, config );
/* close the topmost tag */
fprintf(out, "\t</" XML_TOP ">\n");
}
@ -1090,11 +1129,7 @@ void print_mame_xml(FILE *out, const game_driver *const games[], const char *gam
"\t<!ATTLIST " XML_ROOT " build CDATA #IMPLIED>\n"
"\t<!ATTLIST " XML_ROOT " debug (yes|no) \"no\">\n"
"\t<!ATTLIST " XML_ROOT " mameconfig CDATA #REQUIRED>\n"
#ifdef MESS
"\t<!ELEMENT " XML_TOP " (description, year?, manufacturer, biosset*, rom*, disk*, sample*, chip*, display*, sound?, input?, dipswitch*, configuration*, category*, adjuster*, driver?, device*, ramoption*, softwarelist*)>\n"
#else
"\t<!ELEMENT " XML_TOP " (description, year?, manufacturer, biosset*, rom*, disk*, sample*, chip*, display*, sound?, input?, dipswitch*, configuration*, category*, adjuster*, driver?, device*, softwarelist*)>\n"
#endif
"\t\t<!ATTLIST " XML_TOP " name CDATA #REQUIRED>\n"
"\t\t<!ATTLIST " XML_TOP " sourcefile CDATA #IMPLIED>\n"
"\t\t<!ATTLIST " XML_TOP " isbios (yes|no) \"no\">\n"
@ -1213,10 +1248,8 @@ void print_mame_xml(FILE *out, const game_driver *const games[], const char *gam
"\t\t<!ELEMENT softwarelist EMPTY>\n"
"\t\t\t<!ATTLIST softwarelist name CDATA #REQUIRED>\n"
"\t\t\t<!ATTLIST softwarelist status (original|compatible) #REQUIRED>\n"
#ifdef MESS
"\t\t<!ELEMENT ramoption (#PCDATA)>\n"
"\t\t\t<!ATTLIST ramoption default CDATA #IMPLIED>\n"
#endif
"]>\n\n"
"<" XML_ROOT " build=\"%s\" debug=\""
#ifdef MAME_DEBUG

269
src/emu/machine/ram.c Normal file
View File

@ -0,0 +1,269 @@
/*************************************************************************
RAM device
Provides a configurable amount of RAM to drivers
**************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include "emu.h"
#include "emuopts.h"
#include "ram.h"
/***************************************************************************
CONSTANTS
***************************************************************************/
#define RAM_STRING_BUFLEN 16
#define MAX_RAM_OPTIONS 16
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef struct _ram_state ram_state;
struct _ram_state
{
UINT32 size; /* total amount of ram configured */
UINT8 *ram; /* pointer to the start of ram */
};
/*****************************************************************************
INLINE FUNCTIONS
*****************************************************************************/
INLINE ram_state *get_safe_token(device_t *device)
{
assert(device != NULL);
assert(device->type() == RAM);
return (ram_state *)downcast<legacy_device_base *>(device)->token();
}
/*****************************************************************************
HELPER FUNCTIONS
*****************************************************************************/
/*-------------------------------------------------
ram_parse_string - convert a ram string to an
integer value
-------------------------------------------------*/
UINT32 ram_parse_string(const char *s)
{
UINT32 ram;
char suffix = '\0';
s += sscanf(s, "%u%c", &ram, &suffix);
switch(tolower(suffix))
{
case 'k':
/* kilobytes */
ram *= 1024;
break;
case 'm':
/* megabytes */
ram *= 1024*1024;
break;
case '\0':
/* no suffix */
break;
default:
/* parse failure */
ram = 0;
break;
}
return ram;
}
/*****************************************************************************
DEVICE INTERFACE
*****************************************************************************/
static DEVICE_START( ram )
{
ram_state *ram = get_safe_token(device);
ram_config *config = (ram_config *)downcast<const legacy_device_config_base &>(device->baseconfig()).inline_config();
/* the device named 'ram' can get ram options from command line */
if (strcmp(device->tag(), RAM_TAG) == 0)
{
const char *ramsize_string = options_get_string(mame_options(), OPTION_RAMSIZE);
if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
ram->size = ram_parse_string(ramsize_string);
}
/* if we didn't get a size yet, use the default */
if (ram->size == 0)
ram->size = ram_parse_string(config->default_size);
/* allocate space for the ram */
ram->ram = auto_alloc_array(device->machine, UINT8, ram->size);
/* reset ram to the default value */
memset(ram->ram, config->default_value, ram->size);
/* register for state saving */
state_save_register_device_item(device, 0, ram->size);
state_save_register_device_item_pointer(device, 0, ram->ram, ram->size);
}
static DEVICE_VALIDITY_CHECK( ram )
{
ram_config *config = (ram_config *)downcast<const legacy_device_config_base *>(device)->inline_config();
const char *ramsize_string = NULL;
int is_valid = FALSE;
UINT32 specified_ram = 0;
int error = FALSE;
const char *gamename_option = NULL;
/* verify default ram value */
if (config!=NULL && ram_parse_string(config->default_size) == 0)
{
mame_printf_error("%s: '%s' has an invalid default RAM option: %s\n", driver->source_file, driver->name, config->default_size);
error = TRUE;
}
/* command line options are only parsed for the device named RAM_TAG */
if (device->tag()!=NULL && strcmp(device->tag(), RAM_TAG) == 0)
{
if (mame_options()==NULL) return FALSE;
/* verify command line ram option */
ramsize_string = options_get_string(mame_options(), OPTION_RAMSIZE);
gamename_option = options_get_string(mame_options(), OPTION_GAMENAME);
if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
{
specified_ram = ram_parse_string(ramsize_string);
if (specified_ram == 0)
{
mame_printf_error("%s: '%s' cannot recognize the RAM option %s\n", driver->source_file, driver->name, ramsize_string);
error = TRUE;
}
if (gamename_option != NULL && *gamename_option != 0 && strcmp(gamename_option, driver->name) == 0)
{
/* compare command line option to default value */
if (ram_parse_string(config->default_size) == specified_ram)
is_valid = TRUE;
/* verify extra ram options */
if (config->extra_options != NULL)
{
int j;
int size = strlen(config->extra_options);
char * const s = mame_strdup(config->extra_options);
char * const e = s + size;
char *p = s;
for (j=0;j<size;j++) {
if (p[j]==',') p[j]=0;
}
/* try to parse each option */
while(p <= e)
{
UINT32 option_ram_size = ram_parse_string(p);
if (option_ram_size == 0)
{
mame_printf_error("%s: '%s' has an invalid RAM option: %s\n", driver->source_file, driver->name, p);
error = TRUE;
}
if (option_ram_size == specified_ram)
is_valid = TRUE;
p += strlen(p);
if (p == e)
break;
p += 1;
}
osd_free(s);
}
} else {
/* if not for this driver then return ok */
is_valid = TRUE;
}
}
else
{
/* not specifying the ramsize on the command line is valid as well */
is_valid = TRUE;
}
}
else
is_valid = TRUE;
if (!is_valid)
{
mame_printf_error("%s: '%s' cannot recognize the RAM option %s", driver->source_file, driver->name, ramsize_string);
mame_printf_error(" (valid options are %s", config->default_size);
if (config->extra_options != NULL)
mame_printf_error(",%s).\n", config->extra_options);
else
mame_printf_error(").\n");
error = TRUE;
}
return error;
}
DEVICE_GET_INFO( ram )
{
switch (state)
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ram_state); break;
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(ram_config); break;
/* --- the following bits of info are returned as pointers to data or functions --- */
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ram); break;
case DEVINFO_FCT_STOP: /* Nothing */ break;
case DEVINFO_FCT_RESET: /* Nothing */ break;
case DEVINFO_FCT_VALIDITY_CHECK: info->p = (void*)DEVICE_VALIDITY_CHECK_NAME(ram); break;
/* --- the following bits of info are returned as NULL-terminated strings --- */
case DEVINFO_STR_NAME: strcpy(info->s, "RAM"); break;
case DEVINFO_STR_FAMILY: strcpy(info->s, "RAM"); break;
case DEVINFO_STR_VERSION: strcpy(info->s, "1.00"); break;
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break;
}
}
/***************************************************************************
IMPLEMENTATION
***************************************************************************/
UINT32 ram_get_size(device_t *device)
{
ram_state *ram = get_safe_token(device);
return ram->size;
}
UINT8 *ram_get_ptr(device_t *device)
{
ram_state *ram = get_safe_token(device);
return ram->ram;
}
DEFINE_LEGACY_DEVICE(RAM, ram);

68
src/emu/machine/ram.h Normal file
View File

@ -0,0 +1,68 @@
/*************************************************************************
RAM device
Provides a configurable amount of RAM to drivers
**************************************************************************/
#ifndef __RAM_H__
#define __RAM_H__
/***************************************************************************
CONSTANTS
***************************************************************************/
#define RAM_DEFAULT_VALUE 0xcd
#define RAM_TAG "ram"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef struct _ram_config ram_config;
struct _ram_config
{
const char *default_size;
const char *extra_options;
UINT8 default_value;
};
/***************************************************************************
DEVICE CONFIGURATION MACROS
***************************************************************************/
DECLARE_LEGACY_DEVICE(RAM, ram);
#define MCFG_RAM_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, RAM, 0) \
MCFG_DEVICE_CONFIG_DATA32(ram_config, default_value, RAM_DEFAULT_VALUE)
#define MCFG_RAM_REMOVE(_tag) \
MCFG_DEVICE_REMOVE(_tag)
#define MCFG_RAM_MODIFY(_tag) \
MCFG_DEVICE_MODIFY(_tag) \
MCFG_DEVICE_CONFIG_DATAPTR(ram_config, extra_options, NULL)
#define MCFG_RAM_DEFAULT_SIZE(_default_size) \
MCFG_DEVICE_CONFIG_DATAPTR(ram_config, default_size, _default_size)
#define MCFG_RAM_EXTRA_OPTIONS(_extra_options) \
MCFG_DEVICE_CONFIG_DATAPTR(ram_config, extra_options, _extra_options)
#define MCFG_RAM_DEFAULT_VALUE(_default_value) \
MCFG_DEVICE_CONFIG_DATA32(ram_config, default_value, _default_value)
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
UINT32 ram_get_size(device_t *device);
UINT8 *ram_get_ptr(device_t *device);
UINT32 ram_parse_string(const char *s);
#endif /* __RAM_H__ */