/************************************************************************* RAM device license: MAME, GPL-2.0+ copyright-holders: Dirk Best Provides a configurable amount of RAM to drivers **************************************************************************/ #include #include #include "emu.h" #include "emuopts.h" #include "ram.h" /***************************************************************************** LIVE DEVICE *****************************************************************************/ // device type definition const device_type RAM = &device_creator; //------------------------------------------------- // ram_device - constructor //------------------------------------------------- ram_device::ram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, RAM, "RAM", tag, owner, clock, "ram", __FILE__) { m_size = 0; m_pointer = NULL; m_default_size = NULL; m_extra_options = NULL; m_default_value = 0xCD; } //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- void ram_device::device_start() { /* the device named 'ram' can get ram options from command line */ m_size = 0; if (strcmp(tag(), ":" RAM_TAG) == 0) { const char *ramsize_string = machine().options().ram_size(); if ((ramsize_string != NULL) && (ramsize_string[0] != '\0')) m_size = parse_string(ramsize_string); } /* if we didn't get a size yet, use the default */ if (m_size == 0) m_size = default_size(); /* allocate space for the ram */ m_pointer = auto_alloc_array(machine(), UINT8, m_size); /* reset ram to the default value */ memset(m_pointer, m_default_value, m_size); /* register for state saving */ save_item(NAME(m_size)); save_pointer(NAME(m_pointer), m_size); } //------------------------------------------------- // device_validity_check - device-specific validity // checks //------------------------------------------------- void ram_device::device_validity_check(validity_checker &valid) const { const char *ramsize_string = NULL; int is_valid = FALSE; UINT32 specified_ram = 0; const char *gamename_option = NULL; /* verify default ram value */ if (default_size() == 0) mame_printf_error("Invalid default RAM option: %s\n", m_default_size); /* command line options are only parsed for the device named RAM_TAG */ if (tag() != NULL && strcmp(tag(), ":" RAM_TAG) == 0) { /* verify command line ram option */ ramsize_string = mconfig().options().ram_size(); gamename_option = mconfig().options().system_name(); if ((ramsize_string != NULL) && (ramsize_string[0] != '\0')) { specified_ram = parse_string(ramsize_string); if (specified_ram == 0) mame_printf_error("Cannot recognize the RAM option %s\n", ramsize_string); if (gamename_option != NULL && *gamename_option != 0 && strcmp(gamename_option, mconfig().gamedrv().name) == 0) { /* compare command line option to default value */ if (default_size() == specified_ram) is_valid = TRUE; /* verify extra ram options */ if (m_extra_options != NULL) { int j; int size = strlen(m_extra_options); char * const s = mame_strdup(m_extra_options); char * const e = s + size; char *p = s; for (j=0;j