// Called to add child folders of the top level extra folders already created BOOL TryAddExtraFolderAndChildren(int parent_index) { FILE* fp = NULL; char fname[MAX_PATH]; char readbuf[256]; char* p; char* name; int id, current_id; LPTREEFOLDER lpTemp = NULL; LPTREEFOLDER lpFolder = treeFolders[parent_index]; current_id = lpFolder->m_nFolderId; id = lpFolder->m_nFolderId - MAX_FOLDERS; /* "folder\title.ini" */ sprintf( fname, "%s\\%s.ini", GetFolderDir(), ExtraFolderData[id]->m_szTitle); fp = fopen(fname, "r"); if (fp == NULL) return FALSE; while ( fgets(readbuf, 256, fp) ) { /* do we have [...] ? */ if (readbuf[0] == '[') { p = strchr(readbuf, ']'); if (p == NULL) { continue; } *p = '\0'; name = &readbuf[1]; /* is it [FOLDER_SETTINGS]? */ if (strcmp(name, "FOLDER_SETTINGS") == 0) { current_id = -1; continue; } else { /* it it [ROOT_FOLDER]? */ if (!strcmp(name, "ROOT_FOLDER")) { current_id = lpFolder->m_nFolderId; lpTemp = lpFolder; } else { /* must be [folder name] */ current_id = next_folder_id++; /* create a new folder with this name, and the flags for this folder as read from the registry */ lpTemp = NewFolder(name,current_id,parent_index, ExtraFolderData[id]->m_nSubIconId, GetFolderFlags(numFolders) | F_CUSTOM); AddFolder(lpTemp); } } } else if (current_id != -1) { /* string on a line by itself -- game name */ name = strtok(readbuf, " \t\r\n"); if (name == NULL) { current_id = -1; continue; } /* IMPORTANT: This assumes that all driver names are lowercase! */ _strlwr( name ); if (lpTemp == NULL) { ErrorMsg("Error parsing %s: missing [folder name] or [ROOT_FOLDER]", fname); current_id = lpFolder->m_nFolderId; lpTemp = lpFolder; } AddGame(lpTemp,GetGameNameIndex(name)); } } if ( fp ) { fclose( fp ); } return TRUE; }
/************************************************************************** * index_datafile * Create an index for the records in the currently open datafile. * * Returns 0 on error, or the number of index entries created. **************************************************************************/ static int index_datafile (struct tDatafileIndex **_index) { struct tDatafileIndex *idx; int count = 0; UINT32 token = TOKEN_SYMBOL; /* rewind file */ if (ParseSeek (0L, SEEK_SET)) return 0; /* allocate index */ idx = *_index = malloc (MAX_DATAFILE_ENTRIES * sizeof (struct tDatafileIndex)); if (NULL == idx) return 0; /* loop through datafile */ while ((count < (MAX_DATAFILE_ENTRIES - 1)) && TOKEN_INVALID != token) { long tell; char *s; token = GetNextToken (&s, &tell); if (TOKEN_SYMBOL != token) continue; /* DATAFILE_TAG_KEY identifies the driver */ if (!ci_strncmp (DATAFILE_TAG_KEY, s, strlen (DATAFILE_TAG_KEY))) { token = GetNextToken (&s, &tell); if (TOKEN_EQUALS == token) { int done = 0; token = GetNextToken (&s, &tell); while (!done && TOKEN_SYMBOL == token) { int game_index; char *p; for (p = s; *p; p++) *p = tolower(*p); game_index = GetGameNameIndex(s); if (game_index >= 0) { idx->driver = drivers[game_index]; idx->offset = tell; idx++; count++; /* done = 1; Not done, as we must process other clones in list */ } if (!done) { token = GetNextToken (&s, &tell); if (TOKEN_COMMA == token) token = GetNextToken (&s, &tell); else done = 1; /* end of key field */ } } } } } /* mark end of index */ idx->offset = 0L; idx->driver = 0; return count; }
static struct DriversInfo* GetDriversInfo(int driver_index) { if (drivers_info == NULL) { int ndriver; drivers_info = (DriversInfo*)malloc(sizeof(struct DriversInfo) * GetNumGames()); for (ndriver = 0; ndriver < GetNumGames(); ndriver++) { const game_driver *gamedrv = drivers[ndriver]; struct DriversInfo *gameinfo = &drivers_info[ndriver]; const rom_entry *region, *rom; machine_config *config; const rom_source *source; int num_speakers; /* Allocate machine config */ config = global_alloc(machine_config(gamedrv->machine_config)); gameinfo->isClone = (GetParentRomSetIndex(gamedrv) != -1); gameinfo->isBroken = ((gamedrv->flags & GAME_NOT_WORKING) != 0); gameinfo->supportsSaveState = ((gamedrv->flags & GAME_SUPPORTS_SAVE) != 0); gameinfo->isHarddisk = FALSE; gameinfo->isVertical = (gamedrv->flags & ORIENTATION_SWAP_XY) ? TRUE : FALSE; for (source = rom_first_source(gamedrv, config); source != NULL; source = rom_next_source(gamedrv, config, source)) { for (region = rom_first_region(gamedrv, source); region; region = rom_next_region(region)) { if (ROMREGION_ISDISKDATA(region)) gameinfo->isHarddisk = TRUE; } } gameinfo->hasOptionalBIOS = FALSE; if (gamedrv->rom != NULL) { for (rom = gamedrv->rom; !ROMENTRY_ISEND(rom); rom++) { if (ROMENTRY_ISSYSTEM_BIOS(rom)) { gameinfo->hasOptionalBIOS = TRUE; break; } } } num_speakers = numberOfSpeakers(config); gameinfo->isStereo = (num_speakers > 1); gameinfo->screenCount = numberOfScreens(config); gameinfo->isVector = isDriverVector(config); // ((drv.video_attributes & VIDEO_TYPE_VECTOR) != 0); gameinfo->usesRoms = FALSE; for (source = rom_first_source(gamedrv, config); source != NULL; source = rom_next_source(gamedrv, config, source)) { for (region = rom_first_region(gamedrv, source); region; region = rom_next_region(region)) { for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { gameinfo->usesRoms = TRUE; break; } } } gameinfo->usesSamples = FALSE; { const device_config_sound_interface *sound; const char * const * samplenames = NULL; for (bool gotone = config->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) { if (sound->devconfig().type() == SOUND_SAMPLES) { const samples_interface *intf = (const samples_interface *)sound->devconfig().static_config(); samplenames = intf->samplenames; if (samplenames != 0 && samplenames[0] != 0) { gameinfo->usesSamples = TRUE; break; } } } } gameinfo->numPlayers = 0; gameinfo->numButtons = 0; memset(gameinfo->usesController, 0, sizeof gameinfo->usesController); gameinfo->parentIndex = -1; if (gameinfo->isClone) { int i; for (i = 0; i < GetNumGames(); i++) { if (GetParentRomSetIndex(gamedrv) == i) { gameinfo->parentIndex = i; break; } } } gameinfo->biosIndex = -1; if (DriverIsBios(ndriver)) gameinfo->biosIndex = ndriver; else if (gameinfo->hasOptionalBIOS) { int parentIndex; if (gameinfo->isClone) parentIndex = gameinfo->parentIndex; else parentIndex = ndriver; while (1) { parentIndex = GetGameNameIndex(drivers[parentIndex]->parent); if (parentIndex == -1) { dprintf("bios for %s is not found", drivers[ndriver]->name); break; } if (DriverIsBios(parentIndex)) { gameinfo->biosIndex = parentIndex; break; } } } /* Free the structure */ global_free(config); gameinfo->usesTrackball = FALSE; gameinfo->usesLightGun = FALSE; if (gamedrv->ipt != NULL) { const input_port_config *port; ioport_list portlist; input_port_list_init(portlist, gamedrv->ipt, NULL, 0, FALSE); for (port = portlist.first(); port != NULL; port = port->next()) { const input_field_config *field; for (field = port->fieldlist; field != NULL; field = field->next) { UINT32 type; type = field->type; if (type == IPT_END) break; if (type == IPT_DIAL || type == IPT_PADDLE || type == IPT_TRACKBALL_X || type == IPT_TRACKBALL_Y || type == IPT_AD_STICK_X || type == IPT_AD_STICK_Y) gameinfo->usesTrackball = TRUE; if (type == IPT_LIGHTGUN_X || type == IPT_LIGHTGUN_Y) gameinfo->usesLightGun = TRUE; if (type == IPT_MOUSE_X || type == IPT_MOUSE_Y) gameinfo->usesMouse = TRUE; } } } } UpdateController(); } return &drivers_info[driver_index]; }
/************************************************************************** * index_datafile * Create an index for the records in the currently open datafile. * * Returns 0 on error, or the number of index entries created. **************************************************************************/ static int index_datafile(struct tDatafileIndex **_index, int source) { struct tDatafileIndex *idx; int count = 0; char readbuf[512]; char name[40]; int num_games = driver_list::total(); /* rewind file */ if (ParseSeek (0L, SEEK_SET)) return 0; /* allocate index */ idx = *_index = global_alloc_array(tDatafileIndex, (num_games + 1) * sizeof (struct tDatafileIndex)); if (!idx) return 0; while (fgets(readbuf, 512, fp)) { /* DATAFILE_TAG_KEY identifies the driver */ if (!core_strnicmp(DATAFILE_TAG_KEY, readbuf, strlen(DATAFILE_TAG_KEY))) { int game_index = 0; char *curpoint = &readbuf[strlen(DATAFILE_TAG_KEY) + 1]; char *pch = NULL; char *ends = &readbuf[strlen(readbuf) - 1]; while (curpoint < ends) { // search for comma pch = strpbrk(curpoint, ","); // found it if (pch) { // copy data and validate driver int len = pch - curpoint; strncpy(name, curpoint, len); name[len] = '\0'; if (!source) game_index = GetGameNameIndex(name); else game_index = GetSrcDriverIndex(name); if (game_index >= 0) { idx->driver = &driver_list::driver(game_index); idx->offset = ftell(fp); idx++; count++; } // update current point curpoint = pch + 1; } // if comma not found, copy data while until reach the end of string else if (!pch && curpoint < ends) { int len = ends - curpoint; strncpy(name, curpoint, len); name[len] = '\0'; if (!source) game_index = GetGameNameIndex(name); else game_index = GetSrcDriverIndex(name); if (game_index >= 0) { idx->driver = &driver_list::driver(game_index); idx->offset = ftell(fp); idx++; count++; } // update current point curpoint = ends; } } } } /* mark end of index */ idx->offset = 0L; idx->driver = 0; return count; }
static struct DriversInfo* GetDriversInfo(int driver_index) { if (drivers_info == NULL) { UINT16 ndriver; drivers_info = (DriversInfo*)malloc(sizeof(struct DriversInfo) * GetNumGames()); for (ndriver = 0; ndriver < GetNumGames(); ndriver++) { const game_driver *gamedrv = &driver_list::driver(ndriver); struct DriversInfo *gameinfo = &drivers_info[ndriver]; const rom_entry *region, *rom; machine_config config(*gamedrv, MameUIGlobal()); const rom_source *source; int num_speakers; gameinfo->isClone = (GetParentRomSetIndex(gamedrv) != -1); gameinfo->isBroken = ((gamedrv->flags & GAME_NOT_WORKING) != 0); gameinfo->supportsSaveState = ((gamedrv->flags & GAME_SUPPORTS_SAVE) != 0); gameinfo->isHarddisk = FALSE; gameinfo->isVertical = (gamedrv->flags & ORIENTATION_SWAP_XY) ? TRUE : FALSE; for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) for (region = rom_first_region(*source); region; region = rom_next_region(region)) if (ROMREGION_ISDISKDATA(region)) gameinfo->isHarddisk = TRUE; gameinfo->hasOptionalBIOS = FALSE; if (gamedrv->rom != NULL) for (rom = gamedrv->rom; !ROMENTRY_ISEND(rom); rom++) if (ROMENTRY_ISSYSTEM_BIOS(rom)) { gameinfo->hasOptionalBIOS = TRUE; break; } num_speakers = numberOfSpeakers(&config); gameinfo->isStereo = (num_speakers > 1); gameinfo->screenCount = numberOfScreens(&config); gameinfo->isVector = isDriverVector(&config); // ((drv.video_attributes & VIDEO_TYPE_VECTOR) != 0); gameinfo->usesRoms = FALSE; for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) for (region = rom_first_region(*source); region; region = rom_next_region(region)) for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { gameinfo->usesRoms = TRUE; break; } gameinfo->usesSamples = FALSE; samples_device_iterator iter(config.root_device()); if (iter.first() != NULL) gameinfo->usesSamples = TRUE; gameinfo->numPlayers = 0; gameinfo->numButtons = 0; memset(gameinfo->usesController, 0, sizeof gameinfo->usesController); gameinfo->parentIndex = -1; if (gameinfo->isClone) { int i; for (i = 0; i < GetNumGames(); i++) { if (GetParentRomSetIndex(gamedrv) == i) { gameinfo->parentIndex = i; break; } } } gameinfo->biosIndex = -1; if (DriverIsBios(ndriver)) gameinfo->biosIndex = ndriver; else if (gameinfo->hasOptionalBIOS) { int parentIndex; if (gameinfo->isClone) parentIndex = gameinfo->parentIndex; else parentIndex = ndriver; while (1) { parentIndex = GetGameNameIndex(driver_list::driver(parentIndex).parent); if (parentIndex == -1) { dprintf("bios for %s is not found", driver_list::driver(ndriver).name); break; } if (DriverIsBios(parentIndex)) { gameinfo->biosIndex = parentIndex; break; } } } gameinfo->usesTrackball = FALSE; gameinfo->usesLightGun = FALSE; if (gamedrv->ipt != NULL) { input_port_config *port; ioport_list portlist; astring errors; device_iterator iter(config.root_device()); for (device_t *device = iter.first(); device != NULL; device = iter.next()) if (device->input_ports()!=NULL) input_port_list_init(*device, portlist, errors); for (port = portlist.first(); port != NULL; port = port->next()) { const input_field_config *field; for (field = port->first_field(); field != NULL; field = field->next()) { UINT32 type; type = field->type; if (type == IPT_END) break; if (type == IPT_DIAL || type == IPT_PADDLE || type == IPT_TRACKBALL_X || type == IPT_TRACKBALL_Y || type == IPT_AD_STICK_X || type == IPT_AD_STICK_Y) gameinfo->usesTrackball = TRUE; if (type == IPT_LIGHTGUN_X || type == IPT_LIGHTGUN_Y) gameinfo->usesLightGun = TRUE; if (type == IPT_MOUSE_X || type == IPT_MOUSE_Y) gameinfo->usesMouse = TRUE; } } } } UpdateController(); } return &drivers_info[driver_index]; }