From 249def5363954adeb2b10c280d2cae50bc217995 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 5 Jan 2011 12:51:11 +0000 Subject: [PATCH] - Moved RAM device into emu core [Miodrag Milanovic] - Moved COMP and CONS macros in driver.h --- .gitattributes | 2 + src/emu/driver.h | 34 ++++++ src/emu/emu.mak | 1 + src/emu/emuopts.c | 9 +- src/emu/emuopts.h | 1 + src/emu/info.c | 55 +++++++-- src/emu/machine/ram.c | 269 ++++++++++++++++++++++++++++++++++++++++++ src/emu/machine/ram.h | 68 +++++++++++ 8 files changed, 423 insertions(+), 16 deletions(-) create mode 100644 src/emu/machine/ram.c create mode 100644 src/emu/machine/ram.h diff --git a/.gitattributes b/.gitattributes index 5a6048c309d..1412fd1af2c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/src/emu/driver.h b/src/emu/driver.h index cfc675197cd..5100c44ec75 100644 --- a/src/emu/driver.h +++ b/src/emu/driver.h @@ -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 diff --git a/src/emu/emu.mak b/src/emu/emu.mak index 3d2a37cb566..d4f2555c481 100644 --- a/src/emu/emu.mak +++ b/src/emu/emu.mak @@ -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 \ diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c index 5c09df00566..3258a242a42 100644 --- a/src/emu/emuopts.c +++ b/src/emu/emuopts.c @@ -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; } diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h index bfb8299af20..42661c7c4c2 100644 --- a/src/emu/emuopts.h +++ b/src/emu/emuopts.h @@ -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" diff --git a/src/emu/info.c b/src/emu/info.c index 6bc88e15260..f09f994e456 100644 --- a/src/emu/info.c +++ b/src/emu/info.c @@ -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(device)->inline_config(); + fprintf(out, "\t\t%u\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%u\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\n"); } @@ -1090,11 +1129,7 @@ void print_mame_xml(FILE *out, const game_driver *const games[], const char *gam "\t\n" "\t\n" "\t\n" -#ifdef MESS "\t\n" -#else - "\t\n" -#endif "\t\t\n" "\t\t\n" "\t\t\n" @@ -1213,10 +1248,8 @@ void print_mame_xml(FILE *out, const game_driver *const games[], const char *gam "\t\t\n" "\t\t\t\n" "\t\t\t\n" -#ifdef MESS "\t\t\n" "\t\t\t\n" -#endif "]>\n\n" "<" XML_ROOT " build=\"%s\" debug=\"" #ifdef MAME_DEBUG diff --git a/src/emu/machine/ram.c b/src/emu/machine/ram.c new file mode 100644 index 00000000000..0d2de4d5a1a --- /dev/null +++ b/src/emu/machine/ram.c @@ -0,0 +1,269 @@ +/************************************************************************* + + RAM device + + Provides a configurable amount of RAM to drivers + +**************************************************************************/ + +#include +#include + +#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(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(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(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;jsource_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); diff --git a/src/emu/machine/ram.h b/src/emu/machine/ram.h new file mode 100644 index 00000000000..ea7bc50a5b0 --- /dev/null +++ b/src/emu/machine/ram.h @@ -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__ */