Added new functions for building device-relative tags. Changed machine

configuration builder to use these functions. Also changed the laserdisc
player devices to use them. Updated Z80 CTC/SIO code to assume that the
CPU provided for the clock is relative to the device that the CTC/SIO
belong to. Updated memory code to assume that regions and devices
referenced by the memory map are relative to the device the associated
CPU belongs to.
This commit is contained in:
Aaron Giles 2008-10-03 16:29:33 +00:00
parent d707ec622e
commit 099373081e
9 changed files with 99 additions and 51 deletions

View File

@ -175,6 +175,44 @@ void device_list_remove(device_config **listheadptr, device_type type, const cha
}
/*-------------------------------------------------
device_build_tag - build a tag that combines
the device's name and the given tag
-------------------------------------------------*/
const char *device_build_tag(astring *dest, const char *devicetag, const char *tag)
{
if (devicetag != NULL)
{
astring_cpyc(dest, devicetag);
astring_catc(dest, ":");
astring_catc(dest, tag);
}
else
astring_cpyc(dest, tag);
return astring_c(dest);
}
/*-------------------------------------------------
device_inherit_tag - build a tag with the same
device prefix as the source tag
-------------------------------------------------*/
const char *device_inherit_tag(astring *dest, const char *sourcetag, const char *tag)
{
const char *divider = strrchr(sourcetag, ':');
if (divider != NULL)
{
astring_cpych(dest, sourcetag, divider + 1 - sourcetag);
astring_catc(dest, tag);
}
else
astring_cpyc(dest, tag);
return astring_c(dest);
}
/***************************************************************************
TYPE-BASED DEVICE ACCESS

View File

@ -215,6 +215,12 @@ device_config *device_list_add(device_config **listheadptr, device_type type, co
/* remove a device from a device list */
void device_list_remove(device_config **listheadptr, device_type type, const char *tag);
/* build a tag that combines the device's name and the given tag */
const char *device_build_tag(astring *dest, const char *devicetag, const char *tag);
/* build a tag with the same device prefix as the source tag*/
const char *device_inherit_tag(astring *dest, const char *sourcetag, const char *tag);
/* ----- type-based device access ----- */

View File

@ -259,8 +259,7 @@ static void pr8210_init(laserdisc_state *ld)
ldplayer_data *player = ld->player;
/* find our CPU */
astring_printf(tempstring, "%s:%s", ld->device->tag, "pr8210");
player->cpunum = mame_find_cpu_index(ld->device->machine, astring_c(tempstring));
player->cpunum = mame_find_cpu_index(ld->device->machine, device_build_tag(tempstring, ld->device->tag, "pr8210"));
astring_free(tempstring);
/* do a soft reset */
@ -884,8 +883,7 @@ static void simutrek_init(laserdisc_state *ld)
pr8210_init(ld);
/* find the Simutrek CPU */
astring_printf(tempstring, "%s:%s", ld->device->tag, "simutrek");
ld->player->simutrek.cpunum = mame_find_cpu_index(ld->device->machine, astring_c(tempstring));
ld->player->simutrek.cpunum = mame_find_cpu_index(ld->device->machine, device_build_tag(tempstring, ld->device->tag, "simutrek"));
astring_free(tempstring);
}

View File

@ -214,12 +214,10 @@ static void vp931_init(laserdisc_state *ld)
ldplayer_data *player = ld->player;
/* find our CPU */
astring_printf(tempstring, "%s:%s", ld->device->tag, "vp931");
player->cpunum = mame_find_cpu_index(ld->device->machine, astring_c(tempstring));
player->cpunum = mame_find_cpu_index(ld->device->machine, device_build_tag(tempstring, ld->device->tag, "vp931"));
/* find our timer */
astring_printf(tempstring, "%s:%s", ld->device->tag, "tracktimer");
player->tracktimer = device_list_find_by_tag(ld->device->machine->config->devicelist, TIMER, astring_c(tempstring));
player->tracktimer = device_list_find_by_tag(ld->device->machine->config->devicelist, TIMER, device_build_tag(tempstring, ld->device->tag, "tracktimer"));
timer_device_set_ptr(player->tracktimer, ld);
astring_free(tempstring);

View File

@ -463,13 +463,18 @@ static void z80ctc_irq_reti(const device_config *device)
static DEVICE_START( z80ctc )
{
const z80ctc_interface *intf = device->static_config;
astring *tempstring = astring_alloc();
z80ctc *ctc = get_safe_token(device);
char unique_tag[30];
int cpunum = -1;
int ch;
if (intf->cpu != NULL)
cpunum = mame_find_cpu_index(device->machine, intf->cpu);
{
cpunum = mame_find_cpu_index(device->machine, device_inherit_tag(tempstring, device->tag, intf->cpu));
if (cpunum == -1)
fatalerror("Z80CTC:Unable to find CPU %s\n", device_inherit_tag(tempstring, device->tag, intf->cpu));
}
if (cpunum != -1)
ctc->clock = device->machine->config->cpu[cpunum].clock;
else
@ -503,6 +508,7 @@ static DEVICE_START( z80ctc )
state_save_register_item(unique_tag, ch, channel->int_state);
}
astring_free(tempstring);
return DEVICE_START_OK;
}

View File

@ -785,12 +785,17 @@ static void z80sio_irq_reti(const device_config *device)
static DEVICE_START( z80sio )
{
const z80sio_interface *intf = device->static_config;
astring *tempstring = astring_alloc();
z80sio *sio = get_safe_token(device);
void *ptr = (void *)device;
int cpunum = -1;
if (intf->cpu != NULL)
cpunum = mame_find_cpu_index(device->machine, intf->cpu);
{
cpunum = mame_find_cpu_index(device->machine, device_inherit_tag(tempstring, device->tag, intf->cpu));
if (cpunum == -1)
fatalerror("Z80SIO:Unable to find CPU %s\n", device_inherit_tag(tempstring, device->tag, intf->cpu));
}
if (cpunum != -1)
sio->clock = device->machine->config->cpu[cpunum].clock;
else
@ -806,6 +811,7 @@ static DEVICE_START( z80sio )
sio->transmit_cb = intf->transmit_cb;
sio->receive_poll_cb = intf->receive_poll_cb;
astring_free(tempstring);
return DEVICE_START_OK;
}

View File

@ -22,26 +22,6 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
/*-------------------------------------------------
create_tag - create a combined tag,
allocating strings as necessary
-------------------------------------------------*/
INLINE const char *create_tag(astring *result, const char *prefix, const char *tag)
{
if (prefix != NULL && prefix[0] != 0)
astring_printf(result, "%s:%s", prefix, tag);
else
astring_cpyc(result, tag);
return astring_c(result);
}
/***************************************************************************
MACHINE CONFIGURATIONS
***************************************************************************/
@ -61,7 +41,7 @@ machine_config *machine_config_alloc(const machine_config_token *tokens)
memset(config, 0, sizeof(*config));
/* parse tokens into the config */
machine_config_detokenize(config, tokens, "", 0);
machine_config_detokenize(config, tokens, NULL, 0);
return config;
}
@ -271,20 +251,20 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
case MCONFIG_TOKEN_DEVICE_ADD:
devtype = TOKEN_GET_PTR(tokens, devtype);
tag = TOKEN_GET_STRING(tokens);
device = device_list_add(&config->devicelist, devtype, create_tag(tempstring, tagprefix, tag));
device = device_list_add(&config->devicelist, devtype, device_build_tag(tempstring, tagprefix, tag));
break;
case MCONFIG_TOKEN_DEVICE_REMOVE:
devtype = TOKEN_GET_PTR(tokens, devtype);
tag = TOKEN_GET_STRING(tokens);
device_list_remove(&config->devicelist, devtype, create_tag(tempstring, tagprefix, tag));
device_list_remove(&config->devicelist, devtype, device_build_tag(tempstring, tagprefix, tag));
device = NULL;
break;
case MCONFIG_TOKEN_DEVICE_MODIFY:
devtype = TOKEN_GET_PTR(tokens, devtype);
tag = TOKEN_GET_STRING(tokens);
device = (device_config *)device_list_find_by_tag(config->devicelist, devtype, create_tag(tempstring, tagprefix, tag));
device = (device_config *)device_list_find_by_tag(config->devicelist, devtype, device_build_tag(tempstring, tagprefix, tag));
if (device == NULL)
fatalerror("Unable to find device: type=%s tag=%s\n", devtype_name(devtype), astring_c(tempstring));
break;
@ -351,17 +331,17 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
TOKEN_UNGET_UINT32(tokens);
TOKEN_GET_UINT64_UNPACK3(tokens, entrytype, 8, type, 24, clock, 32);
tag = TOKEN_GET_STRING(tokens);
cpu = cpu_add(config, create_tag(tempstring, tagprefix, tag), type, clock);
cpu = cpu_add(config, device_build_tag(tempstring, tagprefix, tag), type, clock);
break;
case MCONFIG_TOKEN_CPU_MODIFY:
tag = TOKEN_GET_STRING(tokens);
cpu = cpu_find(config, create_tag(tempstring, tagprefix, tag));
cpu = cpu_find(config, device_build_tag(tempstring, tagprefix, tag));
break;
case MCONFIG_TOKEN_CPU_REMOVE:
tag = TOKEN_GET_STRING(tokens);
cpu_remove(config, create_tag(tempstring, tagprefix, tag));
cpu_remove(config, device_build_tag(tempstring, tagprefix, tag));
cpu = NULL;
break;
@ -369,7 +349,7 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
TOKEN_UNGET_UINT32(tokens);
TOKEN_GET_UINT64_UNPACK3(tokens, entrytype, 8, type, 24, clock, 32);
tag = TOKEN_GET_STRING(tokens);
cpu = cpu_find(config, create_tag(tempstring, tagprefix, tag));
cpu = cpu_find(config, device_build_tag(tempstring, tagprefix, tag));
if (cpu == NULL)
fatalerror("Unable to find CPU: tag=%s\n", astring_c(tempstring));
cpu->type = type;
@ -522,7 +502,7 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
TOKEN_UNGET_UINT32(tokens);
TOKEN_GET_UINT64_UNPACK3(tokens, entrytype, 8, type, 24, clock, 32);
tag = TOKEN_GET_STRING(tokens);
sound = sound_add(config, create_tag(tempstring, tagprefix, tag), type, clock);
sound = sound_add(config, device_build_tag(tempstring, tagprefix, tag), type, clock);
break;
case MCONFIG_TOKEN_SOUND_REMOVE:
@ -531,7 +511,7 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
case MCONFIG_TOKEN_SOUND_MODIFY:
tag = TOKEN_GET_STRING(tokens);
sound = sound_find(config, create_tag(tempstring, tagprefix, tag));
sound = sound_find(config, device_build_tag(tempstring, tagprefix, tag));
if (sound == NULL)
fatalerror("Unable to find sound: tag=%s\n", astring_c(tempstring));
sound->routes = 0;
@ -546,7 +526,7 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
TOKEN_UNGET_UINT32(tokens);
TOKEN_GET_UINT64_UNPACK3(tokens, entrytype, 8, type, 24, clock, 32);
tag = TOKEN_GET_STRING(tokens);
sound = sound_find(config, create_tag(tempstring, tagprefix, tag));
sound = sound_find(config, device_build_tag(tempstring, tagprefix, tag));
if (sound == NULL)
fatalerror("Unable to find sound: tag=%s\n", astring_c(tempstring));
sound->type = type;
@ -578,7 +558,7 @@ static void machine_config_detokenize(machine_config *config, const machine_conf
{
tokens = device_get_info_ptr(device, DEVINFO_PTR_MACHINE_CONFIG);
if (tokens != NULL)
machine_config_detokenize(config, tokens, create_tag(tempstring, tagprefix, device->tag), depth + 1);
machine_config_detokenize(config, tokens, device->tag, depth + 1);
}
astring_free(tempstring);

View File

@ -367,7 +367,7 @@ const char *const address_space_names[ADDRESS_SPACES] = { "program", "data", "I/
FUNCTION PROTOTYPES
***************************************************************************/
static void address_map_detokenize(address_map *map, const game_driver *driver, const addrmap_token *tokens);
static void address_map_detokenize(address_map *map, const game_driver *driver, const char *cputag, const addrmap_token *tokens);
static void memory_init_cpudata(running_machine *machine);
static void memory_init_preflight(running_machine *machine);
@ -854,6 +854,7 @@ const data_accessors *memory_get_accessors(int spacenum, int databits, int endia
address_map *address_map_alloc(const machine_config *config, const game_driver *driver, int cpunum, int spacenum)
{
const char *cputag = config->cpu[cpunum].tag;
int cputype = config->cpu[cpunum].type;
const addrmap_token *internal_map = (const addrmap_token *)cputype_get_info_ptr(cputype, CPUINFO_PTR_INTERNAL_MEMORY_MAP + spacenum);
address_map *map;
@ -863,13 +864,13 @@ address_map *address_map_alloc(const machine_config *config, const game_driver *
/* append the internal CPU map (first so it takes priority) */
if (internal_map != NULL)
address_map_detokenize(map, driver, internal_map);
address_map_detokenize(map, driver, cputag, internal_map);
/* construct the standard map */
if (config->cpu[cpunum].address_map[spacenum][0] != NULL)
address_map_detokenize(map, driver, config->cpu[cpunum].address_map[spacenum][0]);
address_map_detokenize(map, driver, cputag, config->cpu[cpunum].address_map[spacenum][0]);
if (config->cpu[cpunum].address_map[spacenum][1] != NULL)
address_map_detokenize(map, driver, config->cpu[cpunum].address_map[spacenum][1]);
address_map_detokenize(map, driver, cputag, config->cpu[cpunum].address_map[spacenum][1]);
return map;
}
@ -887,6 +888,12 @@ void address_map_free(address_map *map)
{
address_map_entry *entry = map->entrylist;
map->entrylist = entry->next;
if (entry->read_devtag_string != NULL)
astring_free(entry->read_devtag_string);
if (entry->write_devtag_string != NULL)
astring_free(entry->write_devtag_string);
if (entry->region_string != NULL)
astring_free(entry->region_string);
free(entry);
}
@ -928,7 +935,7 @@ const address_map *memory_get_address_map(int cpunum, int spacenum)
fatalerror("%s: %s AM_RANGE(0x%x, 0x%x) setting %s already set!\n", driver->source_file, driver->name, entry->addrstart, entry->addrend, #field); \
} while (0)
static void address_map_detokenize(address_map *map, const game_driver *driver, const addrmap_token *tokens)
static void address_map_detokenize(address_map *map, const game_driver *driver, const char *cputag, const addrmap_token *tokens)
{
address_map_entry **entryptr;
address_map_entry *entry;
@ -967,7 +974,7 @@ static void address_map_detokenize(address_map *map, const game_driver *driver,
/* including */
case ADDRMAP_TOKEN_INCLUDE:
address_map_detokenize(map, driver, TOKEN_GET_PTR(tokens, tokenptr));
address_map_detokenize(map, driver, cputag, TOKEN_GET_PTR(tokens, tokenptr));
for (entryptr = &map->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next) ;
entry = NULL;
break;
@ -1030,7 +1037,9 @@ static void address_map_detokenize(address_map *map, const game_driver *driver,
entry->read = TOKEN_GET_PTR(tokens, read);
entry->read_name = TOKEN_GET_STRING(tokens);
entry->read_devtype = TOKEN_GET_PTR(tokens, devtype);
entry->read_devtag = TOKEN_GET_STRING(tokens);
if (entry->read_devtag_string == NULL)
entry->read_devtag_string = astring_alloc();
entry->read_devtag = device_inherit_tag(entry->read_devtag_string, cputag, TOKEN_GET_STRING(tokens));
break;
case ADDRMAP_TOKEN_DEVICE_WRITE:
@ -1040,7 +1049,9 @@ static void address_map_detokenize(address_map *map, const game_driver *driver,
entry->write = TOKEN_GET_PTR(tokens, write);
entry->write_name = TOKEN_GET_STRING(tokens);
entry->write_devtype = TOKEN_GET_PTR(tokens, devtype);
entry->write_devtag = TOKEN_GET_STRING(tokens);
if (entry->write_devtag_string == NULL)
entry->write_devtag_string = astring_alloc();
entry->write_devtag = device_inherit_tag(entry->write_devtag_string, cputag, TOKEN_GET_STRING(tokens));
break;
case ADDRMAP_TOKEN_READ_PORT:
@ -1052,7 +1063,9 @@ static void address_map_detokenize(address_map *map, const game_driver *driver,
check_entry_field(region);
TOKEN_UNGET_UINT32(tokens);
TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, entry->rgnoffs, 32);
entry->region = TOKEN_GET_STRING(tokens);
if (entry->region_string == NULL)
entry->region_string = astring_alloc();
entry->region = device_inherit_tag(entry->region_string, cputag, TOKEN_GET_STRING(tokens));
break;
case ADDRMAP_TOKEN_SHARE:

View File

@ -202,6 +202,9 @@ typedef struct _address_map_entry address_map_entry;
struct _address_map_entry
{
address_map_entry * next; /* pointer to the next entry */
astring * read_devtag_string; /* string used to hold derived names */
astring * write_devtag_string;/* string used to hold derived names */
astring * region_string; /* string used to hold derived names */
offs_t addrstart; /* start address */
offs_t addrend; /* end address */