int config_load_settings(running_machine *machine) { const char *controller = options_get_string(mame_options(), OPTION_CTRLR); file_error filerr; config_type *type; mame_file *file; int loaded = 0; astring *fname; /* loop over all registrants and call their init function */ for (type = typelist; type; type = type->next) (*type->load)(CONFIG_TYPE_INIT, NULL); /* now load the controller file */ if (controller[0] != 0) { /* open the config file */ fname = astring_assemble_2(astring_alloc(), controller, ".cfg"); filerr = mame_fopen(SEARCHPATH_CTRLR, astring_c(fname), OPEN_FLAG_READ, &file); astring_free(fname); if (filerr != FILERR_NONE) fatalerror("Could not load controller file %s.cfg", controller); /* load the XML */ if (!config_load_xml(machine, file, CONFIG_TYPE_CONTROLLER)) fatalerror("Could not load controller file %s.cfg", controller); mame_fclose(file); } /* next load the defaults file */ filerr = mame_fopen(SEARCHPATH_CONFIG, "default.cfg", OPEN_FLAG_READ, &file); if (filerr == FILERR_NONE) { config_load_xml(machine, file, CONFIG_TYPE_DEFAULT); mame_fclose(file); } /* finally, load the game-specific file */ fname = astring_assemble_2(astring_alloc(), machine->basename, ".cfg"); filerr = mame_fopen(SEARCHPATH_CONFIG, astring_c(fname), OPEN_FLAG_READ, &file); astring_free(fname); if (filerr == FILERR_NONE) { loaded = config_load_xml(machine, file, CONFIG_TYPE_GAME); mame_fclose(file); } /* loop over all registrants and call their final function */ for (type = typelist; type; type = type->next) (*type->load)(CONFIG_TYPE_FINAL, NULL); /* if we didn't find a saved config, return 0 so the main core knows that it */ /* is the first time the game is run and it should diplay the disclaimer. */ return loaded; }
int memcard_insert(int index) { file_error filerr; mame_file *file; char name[16]; astring *fname; /* if a card is already inserted, eject it first */ if (memcard_inserted != -1) memcard_eject(Machine); assert(memcard_inserted == -1); /* create a name */ memcard_name(index, name); fname = astring_assemble_3(astring_alloc(), Machine->basename, PATH_SEPARATOR, name); /* open the file; if we can't, it's an error */ filerr = mame_fopen(SEARCHPATH_MEMCARD, astring_c(fname), OPEN_FLAG_READ, &file); astring_free(fname); if (filerr != FILERR_NONE) return 1; /* initialize and then load the card */ if (Machine->drv->memcard_handler) (*Machine->drv->memcard_handler)(Machine, file, MEMCARD_INSERT); /* close the file */ mame_fclose(file); memcard_inserted = index; return 0; }
void memcard_eject(running_machine *machine) { file_error filerr; mame_file *file; char name[16]; astring *fname; /* if no card is preset, just ignore */ if (memcard_inserted == -1) return; /* create a name */ memcard_name(memcard_inserted, name); fname = astring_assemble_3(astring_alloc(), Machine->basename, PATH_SEPARATOR, name); /* open the file; if we can't, it's an error */ filerr = mame_fopen(SEARCHPATH_MEMCARD, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); astring_free(fname); if (filerr != FILERR_NONE) { mame_fclose(file); return; } /* initialize and then load the card */ if (machine->drv->memcard_handler) (*machine->drv->memcard_handler)(machine, file, MEMCARD_EJECT); /* close the file */ mame_fclose(file); memcard_inserted = -1; }
/*------------------------------------------------- battery_save - stores the battery backed RAM for an image. The file name is created from the machine driver name and the image name. -------------------------------------------------*/ void device_image_interface::battery_save(const void *buffer, int length) { astring *fname = astring_assemble_4(astring_alloc(), device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv"); image_battery_save_by_name(device().machine().options(), astring_c(fname), buffer, length); astring_free(fname); }
void config_save_settings(running_machine *machine) { file_error filerr; config_type *type; mame_file *file; astring *fname; /* loop over all registrants and call their init function */ for (type = typelist; type; type = type->next) (*type->save)(CONFIG_TYPE_INIT, NULL); /* save the defaults file */ filerr = mame_fopen(SEARCHPATH_CONFIG, "default.cfg", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); if (filerr == FILERR_NONE) { config_save_xml(machine, file, CONFIG_TYPE_DEFAULT); mame_fclose(file); } /* finally, save the game-specific file */ fname = astring_assemble_2(astring_alloc(), machine->basename, ".cfg"); filerr = mame_fopen(SEARCHPATH_CONFIG, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); astring_free(fname); if (filerr == FILERR_NONE) { config_save_xml(machine, file, CONFIG_TYPE_GAME); mame_fclose(file); } /* loop over all registrants and call their final function */ for (type = typelist; type; type = type->next) (*type->save)(CONFIG_TYPE_FINAL, NULL); }
static void romident(const char *filename, romident_status *status) { osd_directory *directory; /* reset the status */ memset(status, 0, sizeof(*status)); /* first try to open as a directory */ directory = osd_opendir(filename); if (directory != NULL) { const osd_directory_entry *entry; /* iterate over all files in the directory */ while ((entry = osd_readdir(directory)) != NULL) if (entry->type == ENTTYPE_FILE) { astring *curfile = astring_assemble_3(astring_alloc(), filename, PATH_SEPARATOR, entry->name); identify_file(astring_c(curfile), status); astring_free(curfile); } osd_closedir(directory); } /* if that failed, and the filename ends with .zip, identify as a ZIP file */ else if (core_filename_ends_with(filename, ".zip")) { /* first attempt to examine it as a valid ZIP file */ zip_file *zip = NULL; zip_error ziperr = zip_file_open(filename, &zip); if (ziperr == ZIPERR_NONE && zip != NULL) { const zip_file_header *entry; /* loop over entries in the ZIP, skipping empty files and directories */ for (entry = zip_file_first_file(zip); entry; entry = zip_file_next_file(zip)) if (entry->uncompressed_length != 0) { UINT8 *data = (UINT8 *)malloc(entry->uncompressed_length); if (data != NULL) { /* decompress data into RAM and identify it */ ziperr = zip_file_decompress(zip, data, entry->uncompressed_length); if (ziperr == ZIPERR_NONE) identify_data(entry->filename, data, entry->uncompressed_length, status); free(data); } } /* close up */ zip_file_close(zip); } } /* otherwise, identify as a raw file */ else identify_file(filename, status); }
static void identify_data(const char *name, const UINT8 *data, int length, romident_status *status) { char hash[HASH_BUF_SIZE]; UINT8 *tempjed = NULL; astring *basename; int found = 0; jed_data jed; /* if this is a '.jed' file, process it into raw bits first */ if (core_filename_ends_with(name, ".jed") && jed_parse(data, length, &jed) == JEDERR_NONE) { /* now determine the new data length and allocate temporary memory for it */ length = jedbin_output(&jed, NULL, 0); tempjed = malloc(length); if (tempjed == NULL) return; /* create a binary output of the JED data and use that instead */ jedbin_output(&jed, tempjed, length); data = tempjed; } /* compute the hash of the data */ hash_data_clear(hash); hash_compute(hash, data, length, HASH_SHA1 | HASH_CRC); /* output the name */ status->total++; basename = core_filename_extract_base(astring_alloc(), name, FALSE); mame_printf_info("%-20s", astring_c(basename)); astring_free(basename); /* see if we can find a match in the ROMs */ match_roms(hash, length, &found); /* if we didn't find it, try to guess what it might be */ if (found == 0) { /* if not a power of 2, assume it is a non-ROM file */ if ((length & (length - 1)) != 0) { mame_printf_info("NOT A ROM\n"); status->nonroms++; } /* otherwise, it's just not a match */ else mame_printf_info("NO MATCH\n"); } /* if we did find it, count it as a match */ else status->matches++; /* free any temporary JED data */ if (tempjed != NULL) free(tempjed); }
static emu_file *nvram_system_fopen( running_machine &machine, UINT32 openflags, const char *name) { file_error filerr; astring *fname = astring_assemble_4( astring_alloc(), machine.system().name, PATH_SEPARATOR, name, ".nv"); emu_file *file = global_alloc(emu_file(machine.options().nvram_directory(), openflags)); filerr = file->open(astring_c( fname)); astring_free( fname); return (filerr == FILERR_NONE) ? file : NULL; }
static file_error OpenDIBFile(const char *dir_name, const char *zip_name, const char *filename, core_file **file, void **buffer) { file_error filerr; zip_error ziperr; zip_file *zip; const zip_file_header *zip_header; astring *fname; // clear out result *file = NULL; // look for the raw file fname = astring_assemble_3(astring_alloc(), dir_name, PATH_SEPARATOR, filename); filerr = core_fopen(astring_c(fname), OPEN_FLAG_READ, file); astring_free(fname); // did the raw file not exist? if (filerr != FILERR_NONE) { // look into zip file fname = astring_assemble_4(astring_alloc(), dir_name, PATH_SEPARATOR, zip_name, ".zip"); ziperr = zip_file_open(astring_c(fname), &zip); astring_free(fname); if (ziperr == ZIPERR_NONE) { zip_header = zip_file_seek_file(zip, filename); if (zip_header != NULL) { *buffer = malloc(zip_header->uncompressed_length); ziperr = zip_file_decompress(zip, *buffer, zip_header->uncompressed_length); if (ziperr == ZIPERR_NONE) { filerr = core_fopen_ram(*buffer, zip_header->uncompressed_length, OPEN_FLAG_READ, file); } } zip_file_close(zip); } } return filerr; }
struct loaded_samples *readsamples(const char *const *samplenames, const char *basename) { struct loaded_samples *samples; int skipfirst = 0; int i; /* if the user doesn't want to use samples, bail */ if (!options_get_bool(mame_options(), OPTION_SAMPLES)) return NULL; if (samplenames == 0 || samplenames[0] == 0) return NULL; /* if a name begins with '*', we will also look under that as an alternate basename */ if (samplenames[0][0] == '*') skipfirst = 1; /* count the samples */ for (i = 0; samplenames[i+skipfirst] != 0; i++) ; if (i == 0) return NULL; /* allocate the array */ samples = auto_malloc(sizeof(struct loaded_samples) + (i-1) * sizeof(struct loaded_sample)); memset(samples, 0, sizeof(struct loaded_samples) + (i-1) * sizeof(struct loaded_sample)); samples->total = i; /* load the samples */ for (i = 0; i < samples->total; i++) if (samplenames[i+skipfirst][0]) { file_error filerr; mame_file *f; astring *fname; fname = astring_assemble_3(astring_alloc(), basename, PATH_SEPARATOR, samplenames[i+skipfirst]); filerr = mame_fopen(SEARCHPATH_SAMPLE, astring_c(fname), OPEN_FLAG_READ, &f); if (filerr != FILERR_NONE && skipfirst) { astring_assemble_3(fname, samplenames[0] + 1, PATH_SEPARATOR, samplenames[i+skipfirst]); filerr = mame_fopen(SEARCHPATH_SAMPLE, astring_c(fname), OPEN_FLAG_READ, &f); } if (filerr == FILERR_NONE) { read_wav_sample(f, &samples->sample[i]); mame_fclose(f); } astring_free(fname); } return samples; }
mame_file *nvram_fopen(running_machine *machine, UINT32 openflags) { file_error filerr; mame_file *file; astring *fname; fname = astring_assemble_2(astring_alloc(), machine->basename, ".nv"); filerr = mame_fopen(SEARCHPATH_NVRAM, astring_c(fname), openflags, &file); astring_free(fname); return (filerr == FILERR_NONE) ? file : NULL; }
static void output_path_as_links(core_file *file, const astring *path, int end_is_directory, int link_to_file) { astring *substr = astring_alloc(); int srcdepth, curdepth, depth; int slashindex, lastslash; /* first count how deep we are */ srcdepth = 0; for (slashindex = astring_chr(path, 0, '/'); slashindex != -1; slashindex = astring_chr(path, slashindex + 1, '/')) srcdepth++; if (end_is_directory) srcdepth++; /* output a link to the root */ core_fprintf(file, "<a href=\""); for (depth = 0; depth < srcdepth; depth++) core_fprintf(file, "../"); core_fprintf(file, "index.html\"><root></a>/"); /* now output links to each path up the chain */ curdepth = 0; lastslash = 0; for (slashindex = astring_chr(path, lastslash, '/'); slashindex != -1; slashindex = astring_chr(path, lastslash, '/')) { astring_cpysubstr(substr, path, lastslash, slashindex - lastslash); curdepth++; core_fprintf(file, "<a href=\""); for (depth = curdepth; depth < srcdepth; depth++) core_fprintf(file, "../"); core_fprintf(file, "index.html\">%s</a>/", astring_c(substr)); lastslash = slashindex + 1; } /* and a final link to the current directory */ astring_cpysubstr(substr, path, lastslash, -1); if (end_is_directory) core_fprintf(file, "<a href=\"index.html\">%s</a>", astring_c(substr)); else if (link_to_file) core_fprintf(file, "<a href=\"%s\">%s</a>", astring_c(substr), astring_c(substr)); else core_fprintf(file, "<a href=\"%s.html\">%s</a>", astring_c(substr), astring_c(substr)); astring_free(substr); }
ROM_END /*------------------------------------------------- device start callback -------------------------------------------------*/ static DEVICE_START( namco_50xx ) { namco_50xx_state *state = get_safe_token(device); astring *tempstring = astring_alloc(); /* find our CPU */ state->cpu = cputag_get_cpu(device->machine, device_build_tag(tempstring, device, "mcu")); assert(state->cpu != NULL); astring_free(tempstring); }
int cli_info_listsource(core_options *options, const char *gamename) { astring *filename = astring_alloc(); int drvindex, count = 0; /* iterate over drivers */ for (drvindex = 0; drivers[drvindex]; drvindex++) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) { /* output the remaining information */ mame_printf_info("%-8s %s\n", drivers[drvindex]->name, astring_c(core_filename_extract_base(filename, drivers[drvindex]->source_file, FALSE))); count++; } /* return an error if none found */ astring_free(filename); return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME; }
z80_daisy_state *z80daisy_init(const device_config *cpudevice, const z80_daisy_chain *daisy) { astring *tempstring = astring_alloc(); z80_daisy_state *head = NULL; z80_daisy_state **tailptr = &head; /* create a linked list of devices */ for ( ; daisy->devname != NULL; daisy++) { *tailptr = auto_alloc(cpudevice->machine, z80_daisy_state); (*tailptr)->next = NULL; (*tailptr)->device = devtag_get_device(cpudevice->machine, device_inherit_tag(tempstring, cpudevice->tag, daisy->devname)); if ((*tailptr)->device == NULL) fatalerror("Unable to locate device '%s'", daisy->devname); (*tailptr)->irq_state = (z80_daisy_irq_state)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_IRQ_STATE); (*tailptr)->irq_ack = (z80_daisy_irq_ack)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_IRQ_ACK); (*tailptr)->irq_reti = (z80_daisy_irq_reti)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_IRQ_RETI); tailptr = &(*tailptr)->next; } astring_free(tempstring); return head; }
int memcard_create(int index, int overwrite) { file_error filerr; mame_file *file; astring *fname; char name[16]; /* create a name */ memcard_name(index, name); /* if we can't overwrite, fail if the file already exists */ fname = astring_assemble_3(astring_alloc(), Machine->basename, PATH_SEPARATOR, name); if (!overwrite) { filerr = mame_fopen(SEARCHPATH_MEMCARD, astring_c(fname), OPEN_FLAG_READ, &file); if (filerr == FILERR_NONE) { mame_fclose(file); astring_free(fname); return 1; } } /* create a new file */ filerr = mame_fopen(SEARCHPATH_MEMCARD, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); astring_free(fname); if (filerr != FILERR_NONE) return 1; /* initialize and then save the card */ if (Machine->drv->memcard_handler) (*Machine->drv->memcard_handler)(Machine, file, MEMCARD_CREATE); /* close the file */ mame_fclose(file); return 0; }
int cli_execute(int argc, char **argv, const options_entry *osd_options) { core_options *options; astring *gamename = astring_alloc(); astring *exename = astring_alloc(); const char *gamename_option; const game_driver *driver; int result; /* initialize the options manager and add the CLI-specific options */ options = mame_options_init(osd_options); options_add_entries(options, cli_options); /* parse the command line first; if we fail here, we're screwed */ if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE)) { result = MAMERR_INVALID_CONFIG; goto error; } /* parse the simple commmands before we go any further */ core_filename_extract_base(exename, argv[0], TRUE); result = execute_simple_commands(options, astring_c(exename)); if (result != -1) { goto error; } /* find out what game we might be referring to */ gamename_option = options_get_string(options, OPTION_GAMENAME); core_filename_extract_base(gamename, gamename_option, TRUE); driver = driver_get_name(astring_c(gamename)); /* execute any commands specified */ result = execute_commands(options, astring_c(exename), driver); if (result != -1) { goto error; } /* if we don't have a valid driver selected, offer some suggestions */ if (strlen(gamename_option) > 0 && driver == NULL) { const game_driver *matches[10]; int drvnum; /* get the top 10 approximate matches */ driver_list_get_approx_matches(drivers, gamename_option, ARRAY_LENGTH(matches), matches); /* print them out */ fprintf(stderr, "\n\"%s\" approximately matches the following\n" "supported " GAMESNOUN " (best match first):\n\n", gamename_option); for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++) if (matches[drvnum] != NULL) fprintf(stderr, "%-10s%s\n", matches[drvnum]->name, matches[drvnum]->description); /* exit with an error */ result = MAMERR_NO_SUCH_GAME; goto error; } /* run the game */ result = mame_execute(options); error: /* free our options and exit */ options_free(options); astring_free(gamename); astring_free(exename); return result; }
BOOL LoadDIB(const char *filename, HGLOBAL *phDIB, HPALETTE *pPal, int pic_type) { file_error filerr; core_file *file = NULL; BOOL success = FALSE; const char *dir_name; const char *zip_name; astring *fname; void *buffer = NULL; if (pPal != NULL ) { DeletePalette(pPal); } switch (pic_type) { case TAB_SCREENSHOT: dir_name = GetImgDir(); zip_name = "snap"; break; case TAB_FLYER: dir_name = GetFlyerDir(); zip_name = "flyers"; break; case TAB_CABINET: dir_name = GetCabinetDir(); zip_name = "cabinets"; break; case TAB_MARQUEE: dir_name = GetMarqueeDir(); zip_name = "marquees"; break; case TAB_TITLE: dir_name = GetTitlesDir(); zip_name = "titles"; break; case TAB_CONTROL_PANEL: dir_name = GetControlPanelDir(); zip_name = "cpanel"; break; case TAB_PCB : dir_name = GetPcbDir(); zip_name = "pcb"; break; case BACKGROUND: dir_name = GetBgDir(); zip_name = "bkground"; break; default : // in case a non-image tab gets here, which can happen return FALSE; } //Add handling for the displaying of all the different supported snapshot patterntypes //%g fname = astring_assemble_2(astring_alloc(), filename, ".png"); filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer); astring_free(fname); if (filerr != FILERR_NONE) { //%g/%i fname = astring_assemble_3(astring_alloc(), filename, PATH_SEPARATOR, "0000.png"); filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer); astring_free(fname); } if (filerr != FILERR_NONE) { //%g%i fname = astring_assemble_2(astring_alloc(), filename, "0000.png"); filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer); astring_free(fname); } if (filerr != FILERR_NONE) { //%g/%g fname = astring_assemble_4(astring_alloc(), filename, PATH_SEPARATOR, filename, ".png"); filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer); astring_free(fname); } if (filerr != FILERR_NONE) { //%g/%g%i fname = astring_assemble_4(astring_alloc(), filename, PATH_SEPARATOR, filename, "0000.png"); filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer); astring_free(fname); } if (filerr == FILERR_NONE) { success = png_read_bitmap_gui(file, phDIB, pPal); core_fclose(file); } // free the buffer if we have to if (buffer != NULL) { free(buffer); } return success; }
static astring *find_include_file(int srcrootlen, int dstrootlen, const astring *srcfile, const astring *dstfile, const astring *filename) { include_path *curpath; /* iterate over include paths and find the file */ for (curpath = incpaths; curpath != NULL; curpath = curpath->next) { astring *srcincpath = astring_cat(astring_dupsubstr(srcfile, 0, srcrootlen + 1), curpath->path); core_file *testfile; int lastsepindex = 0; int sepindex; /* a '.' include path is specially treated */ if (astring_cmpc(curpath->path, ".") == 0) astring_cpysubstr(srcincpath, srcfile, 0, astring_rchr(srcfile, 0, PATH_SEPARATOR[0])); /* append the filename piecemeal to account for directories */ while ((sepindex = astring_chr(filename, lastsepindex, '/')) != -1) { astring *pathpart = astring_dupsubstr(filename, lastsepindex, sepindex - lastsepindex); /* handle .. by removing a chunk from the incpath */ if (astring_cmpc(pathpart, "..") == 0) { sepindex = astring_rchr(srcincpath, 0, PATH_SEPARATOR[0]); if (sepindex != -1) astring_substr(srcincpath, 0, sepindex); } /* otherwise, append a path separator and the pathpart */ else astring_cat(astring_catc(srcincpath, PATH_SEPARATOR), pathpart); /* advance past the previous index */ lastsepindex = sepindex + 1; /* free the path part we extracted */ astring_free(pathpart); } /* now append the filename */ astring_catsubstr(astring_catc(srcincpath, PATH_SEPARATOR), filename, lastsepindex, -1); /* see if we can open it */ if (core_fopen(astring_c(srcincpath), OPEN_FLAG_READ, &testfile) == FILERR_NONE) { astring *tempfile = astring_alloc(); astring *tempinc = astring_alloc(); /* close the file */ core_fclose(testfile); /* find the longest matching directory substring between the include and source file */ lastsepindex = 0; while ((sepindex = astring_chr(srcincpath, lastsepindex, PATH_SEPARATOR[0])) != -1) { /* get substrings up to the current directory */ astring_cpysubstr(tempfile, srcfile, 0, sepindex); astring_cpysubstr(tempinc, srcincpath, 0, sepindex); /* if we don't match, stop */ if (astring_cmp(tempfile, tempinc) != 0) break; lastsepindex = sepindex + 1; } /* chop off the common parts of the paths */ astring_cpysubstr(tempfile, srcfile, lastsepindex, -1); astring_replacechr(astring_substr(srcincpath, lastsepindex, -1), PATH_SEPARATOR[0], '/'); /* for each directory left in the filename, we need to prepend a "../" */ while ((sepindex = astring_chr(tempfile, 0, PATH_SEPARATOR[0])) != -1) { astring_substr(tempfile, sepindex + 1, -1); astring_insc(srcincpath, 0, "../"); } astring_catc(srcincpath, ".html"); /* free the strings and return the include path */ astring_free(tempfile); astring_free(tempinc); return srcincpath; } /* free our include path */ astring_free(srcincpath); } return NULL; }
static messtest_result_t run_test(int flags, messtest_results *results) { const game_driver *driver; messtest_result_t rc; clock_t begin_time; double real_run_time; astring *fullpath = NULL; const char *device_opt; const char *fake_argv[2]; core_options *opts; /* lookup driver */ driver = driver_get_name(current_testcase.driver); /* cannot find driver? */ if (driver == NULL) { report_message(MSG_FAILURE, "Cannot find driver '%s'", current_testcase.driver); return MESSTEST_RESULT_STARTFAILURE; } /* prepare testing state */ current_command = current_testcase.commands; state = STATE_READY; test_flags = flags; screenshot_num = 0; runtime_hash = 0; had_failure = FALSE; //videoram = NULL; //videoram_size = 0; /* set up options */ opts = mame_options_init(win_mess_opts); options_set_string(opts, OPTION_GAMENAME, driver->name, OPTION_PRIORITY_CMDLINE); if( current_testcase.bios ) options_set_string(opts, OPTION_BIOS, current_testcase.bios, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_SKIP_GAMEINFO, TRUE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_THROTTLE, FALSE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_DEBUG, FALSE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_DEBUG_INTERNAL, FALSE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_WRITECONFIG, FALSE, OPTION_PRIORITY_CMDLINE); if (current_testcase.ram != 0) { options_set_int(opts, OPTION_RAMSIZE, current_testcase.ram, OPTION_PRIORITY_CMDLINE); } /* ugh... hideous ugly fake arguments */ fake_argv[0] = "MESSTEST"; fake_argv[1] = driver->name; options_parse_command_line(opts, ARRAY_LENGTH(fake_argv), (char **) fake_argv, OPTION_PRIORITY_CMDLINE,TRUE); /* preload any needed images */ while(current_command->command_type == MESSTEST_COMMAND_IMAGE_PRELOAD) { /* get the path */ fullpath = assemble_software_path(astring_alloc(), driver, current_command->u.image_args.filename); /* get the option name */ device_opt = device_config_image_interface::device_typename(current_command->u.image_args.device_ident.type); /* set the option */ options_set_string(opts, device_opt, astring_c(fullpath), OPTION_PRIORITY_CMDLINE); /* cleanup */ astring_free(fullpath); fullpath = NULL; /* next command */ current_command++; } /* perform the test */ report_message(MSG_INFO, "Beginning test (driver '%s')", current_testcase.driver); begin_time = clock(); mame_set_output_channel(OUTPUT_CHANNEL_ERROR, messtest_output_error, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_WARNING, mame_null_output_callback, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_INFO, mame_null_output_callback, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_DEBUG, mame_null_output_callback, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_LOG, mame_null_output_callback, NULL, NULL, NULL); test_osd_interface osd; mame_execute(osd, opts); real_run_time = ((double) (clock() - begin_time)) / CLOCKS_PER_SEC; /* what happened? */ switch(state) { case STATE_ABORTED: report_message(MSG_FAILURE, "Test aborted"); rc = MESSTEST_RESULT_RUNTIMEFAILURE; break; case STATE_DONE: if (had_failure) { report_message(MSG_FAILURE, "Test failed (real time %.2f; emu time %.2f [%i%%])", real_run_time, final_time.as_double(), (int) ((final_time.as_double() / real_run_time) * 100)); rc = MESSTEST_RESULT_RUNTIMEFAILURE; } else { report_message(MSG_INFO, "Test succeeded (real time %.2f; emu time %.2f [%i%%])", real_run_time, final_time.as_double(), (int) ((final_time.as_double() / real_run_time) * 100)); rc = MESSTEST_RESULT_SUCCESS; } break; default: state = STATE_ABORTED; report_message(MSG_FAILURE, "Abnormal termination"); rc = MESSTEST_RESULT_STARTFAILURE; break; } if (results) { results->rc = rc; results->runtime_hash = runtime_hash; } options_free(opts); return rc; }
static int generate_png_diff(const summary_file *curfile, const astring *destdir, const char *destname) { bitmap_t *bitmaps[MAX_COMPARES] = { NULL }; astring *srcimgname = astring_alloc(); astring *dstfilename = astring_alloc(); astring *tempname = astring_alloc(); bitmap_t *finalbitmap = NULL; int width, height, maxwidth; int bitmapcount = 0; int listnum, bmnum; core_file *file = NULL; file_error filerr; png_error pngerr; int error = -1; int starty; /* generate the common source filename */ astring_printf(dstfilename, "%s" PATH_SEPARATOR "%s", astring_c(destdir), destname); astring_printf(srcimgname, "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name); /* open and load all unique bitmaps */ for (listnum = 0; listnum < list_count; listnum++) if (curfile->matchbitmap[listnum] == listnum) { astring_printf(tempname, "%s" PATH_SEPARATOR "%s", lists[listnum].dir, astring_c(srcimgname)); /* open the source image */ filerr = core_fopen(astring_c(tempname), OPEN_FLAG_READ, &file); if (filerr != FILERR_NONE) goto error; /* load the source image */ pngerr = png_read_bitmap(file, &bitmaps[bitmapcount++]); core_fclose(file); if (pngerr != PNGERR_NONE) goto error; } /* if there's only one unique bitmap, skip it */ if (bitmapcount <= 1) goto error; /* determine the size of the final bitmap */ height = width = 0; maxwidth = bitmaps[0]->width; for (bmnum = 1; bmnum < bitmapcount; bmnum++) { int curwidth; /* determine the maximal width */ maxwidth = MAX(maxwidth, bitmaps[bmnum]->width); curwidth = bitmaps[0]->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth; width = MAX(width, curwidth); /* add to the height */ height += MAX(bitmaps[0]->height, bitmaps[bmnum]->height); if (bmnum != 1) height += BITMAP_SPACE; } /* allocate the final bitmap */ finalbitmap = bitmap_alloc(width, height, BITMAP_FORMAT_ARGB32); if (finalbitmap == NULL) goto error; /* now copy and compare each set of bitmaps */ starty = 0; for (bmnum = 1; bmnum < bitmapcount; bmnum++) { bitmap_t *bitmap1 = bitmaps[0]; bitmap_t *bitmap2 = bitmaps[bmnum]; int curheight = MAX(bitmap1->height, bitmap2->height); int x, y; /* iterate over rows in these bitmaps */ for (y = 0; y < curheight; y++) { UINT32 *src1 = (y < bitmap1->height) ? BITMAP_ADDR32(bitmap1, y, 0) : NULL; UINT32 *src2 = (y < bitmap2->height) ? BITMAP_ADDR32(bitmap2, y, 0) : NULL; UINT32 *dst1 = BITMAP_ADDR32(finalbitmap, starty + y, 0); UINT32 *dst2 = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE); UINT32 *dstdiff = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE); /* now iterate over columns */ for (x = 0; x < maxwidth; x++) { int pix1 = -1, pix2 = -2; if (src1 != NULL && x < bitmap1->width) pix1 = dst1[x] = src1[x]; if (src2 != NULL && x < bitmap2->width) pix2 = dst2[x] = src2[x]; dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000; } } /* update the starting Y position */ starty += BITMAP_SPACE + MAX(bitmap1->height, bitmap2->height); } /* write the final PNG */ filerr = core_fopen(astring_c(dstfilename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file); if (filerr != FILERR_NONE) goto error; pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL); core_fclose(file); if (pngerr != PNGERR_NONE) goto error; /* if we get here, we are error free */ error = 0; error: if (finalbitmap != NULL) bitmap_free(finalbitmap); for (bmnum = 0; bmnum < bitmapcount; bmnum++) if (bitmaps[bmnum] != NULL) bitmap_free(bitmaps[bmnum]); if (error) osd_rmfile(astring_c(dstfilename)); astring_free(dstfilename); astring_free(srcimgname); astring_free(tempname); return error; }
static int compare_screenshots(summary_file *curfile) { bitmap_t *bitmaps[MAX_COMPARES]; int unique[MAX_COMPARES]; int numunique = 0; int listnum; /* iterate over all files and load their bitmaps */ for (listnum = 0; listnum < list_count; listnum++) { bitmaps[listnum] = NULL; if (curfile->status[listnum] == STATUS_SUCCESS) { astring *fullname = astring_alloc(); file_error filerr; core_file *file; /* get the filename for the image */ astring_printf(fullname, "%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", lists[listnum].dir, curfile->name); /* open the file */ filerr = core_fopen(astring_c(fullname), OPEN_FLAG_READ, &file); /* if that failed, look in the old location */ if (filerr != FILERR_NONE) { /* get the filename for the image */ astring_printf(fullname, "%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "_%s.png", lists[listnum].dir, curfile->name); /* open the file */ filerr = core_fopen(astring_c(fullname), OPEN_FLAG_READ, &file); } /* if that worked, load the file */ if (filerr == FILERR_NONE) { png_read_bitmap(file, &bitmaps[listnum]); core_fclose(file); } astring_free(fullname); } } /* now find all the different bitmap types */ for (listnum = 0; listnum < list_count; listnum++) { curfile->matchbitmap[listnum] = 0xff; if (bitmaps[listnum] != NULL) { bitmap_t *this_bitmap = bitmaps[listnum]; int compnum; /* compare against all unique bitmaps */ for (compnum = 0; compnum < numunique; compnum++) { bitmap_t *base_bitmap = bitmaps[unique[compnum]]; int bitmaps_differ; int x, y; /* if the sizes are different, we differ; otherwise start off assuming we are the same */ bitmaps_differ = (this_bitmap->width != base_bitmap->width || this_bitmap->height != base_bitmap->height); /* compare scanline by scanline */ for (y = 0; y < this_bitmap->height && !bitmaps_differ; y++) { UINT32 *base = BITMAP_ADDR32(base_bitmap, y, 0); UINT32 *curr = BITMAP_ADDR32(this_bitmap, y, 0); /* scan the scanline */ for (x = 0; x < this_bitmap->width; x++) if (*base++ != *curr++) break; bitmaps_differ = (x != this_bitmap->width); } /* if we matched, remember which listnum index we matched, and stop */ if (!bitmaps_differ) { curfile->matchbitmap[listnum] = unique[compnum]; break; } /* if different from the first unique entry, adjust the status */ if (bitmaps_differ && compnum == 0) curfile->status[listnum] = STATUS_SUCCESS_DIFFERENT; } /* if we're unique, add ourselves to the list */ if (compnum >= numunique) { unique[numunique++] = listnum; curfile->matchbitmap[listnum] = listnum; continue; } } } /* free the bitmaps */ for (listnum = 0; listnum < list_count; listnum++) if (bitmaps[listnum] != NULL) bitmap_free(bitmaps[listnum]); /* if all screenshots matched, we're good */ if (numunique == 1) return BUCKET_GOOD; /* if the last screenshot matched the first unique one, we're good but changed */ if (curfile->matchbitmap[listnum - 1] == unique[0]) return BUCKET_GOOD_BUT_CHANGED_SCREENSHOTS; /* otherwise we're just changed */ return BUCKET_CHANGED; }
static void output_report(const astring *dirname, const astring *tempheader, const astring *tempfooter, summary_file *filelist) { summary_file *buckethead[BUCKET_COUNT], **buckettailptr[BUCKET_COUNT]; summary_file *curfile; astring *title = astring_dupc("MAME Regressions"); astring *tempname = astring_alloc(); int listnum, bucknum; core_file *indexfile; int count = 0, total; /* initialize the lists */ for (bucknum = 0; bucknum < BUCKET_COUNT; bucknum++) { buckethead[bucknum] = NULL; buckettailptr[bucknum] = &buckethead[bucknum]; } /* compute the total number of files */ total = 0; for (curfile = filelist; curfile != NULL; curfile = curfile->next) total++; /* first bucketize the games */ for (curfile = filelist; curfile != NULL; curfile = curfile->next) { int statcount[STATUS_COUNT] = { 0 }; int bucket = BUCKET_UNKNOWN; int unique_codes = 0; int first_valid; /* print status */ if (++count % 100 == 0) fprintf(stderr, "Processing file %d/%d\n", count, total); /* find the first valid entry */ for (first_valid = 0; curfile->status[first_valid] == STATUS_NOT_PRESENT; first_valid++) ; /* do we need to output anything? */ for (listnum = first_valid; listnum < list_count; listnum++) if (statcount[curfile->status[listnum]]++ == 0) unique_codes++; /* were we consistent? */ if (unique_codes == 1) { /* were we consistently ok? */ if (curfile->status[first_valid] == STATUS_SUCCESS) bucket = compare_screenshots(curfile); /* must have been consistently erroring */ else bucket = BUCKET_CONSISTENT_ERROR; } /* ok, we're not consistent; could be a number of things */ else { /* were we ok at the start and end but not in the middle? */ if (curfile->status[first_valid] == STATUS_SUCCESS && curfile->status[list_count - 1] == STATUS_SUCCESS) bucket = BUCKET_GOOD_BUT_CHANGED; /* did we go from good to bad? */ else if (curfile->status[first_valid] == STATUS_SUCCESS) bucket = BUCKET_REGRESSED; /* did we go from bad to good? */ else if (curfile->status[list_count - 1] == STATUS_SUCCESS) bucket = BUCKET_IMPROVED; /* must have had multiple errors */ else bucket = BUCKET_MULTI_ERROR; } /* add us to the appropriate list */ *buckettailptr[bucket] = curfile; buckettailptr[bucket] = &curfile->next; } /* terminate all the lists */ for (bucknum = 0; bucknum < BUCKET_COUNT; bucknum++) *buckettailptr[bucknum] = NULL; /* output header */ astring_printf(tempname, "%s" PATH_SEPARATOR "%s", astring_c(dirname), "index.html"); indexfile = create_file_and_output_header(tempname, tempheader, title); if (indexfile == NULL) { fprintf(stderr, "Error creating file '%s'\n", astring_c(tempname)); astring_free(tempname); astring_free(title); return; } /* iterate over buckets and output them */ for (bucknum = 0; bucknum < ARRAY_LENGTH(bucket_output_order); bucknum++) { int curbucket = bucket_output_order[bucknum]; if (buckethead[curbucket] != NULL) { fprintf(stderr, "Outputting bucket: %s\n", bucket_name[curbucket]); append_driver_list_table(bucket_name[curbucket], dirname, indexfile, buckethead[curbucket], tempheader, tempfooter); } } /* output footer */ output_footer_and_close_file(indexfile, tempfooter, title); astring_free(tempname); astring_free(title); }
static int recurse_dir(int srcrootlen, const astring *srcdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; int result = 0; int entindex; /* iterate first over directories, then over files */ for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; const osd_directory_entry *entry; list_entry **listarray = NULL; list_entry *list = NULL; list_entry *curlist; osd_directory *dir; int found = 0; /* open the directory and iterate through it */ dir = osd_opendir(astring_c(srcdir)); if (dir == NULL) { result = 1; goto error; } /* build up the list of files */ while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = (list_entry *)malloc(sizeof(*lentry)); lentry->name = astring_dupc(entry->name); lentry->next = list; list = lentry; found++; } /* close the directory */ osd_closedir(dir); /* skip if nothing found */ if (found == 0) continue; /* allocate memory for sorting */ listarray = (list_entry **)malloc(sizeof(list_entry *) * found); found = 0; for (curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; /* sort the list */ qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); /* rebuild the list */ list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } free(listarray); /* iterate through each file */ for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring *srcfile; /* build the source filename */ srcfile = astring_alloc(); astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name)); /* if we have a file, output it */ if (entry_type == ENTTYPE_FILE) { /* make sure we care, first */ if (core_filename_ends_with(astring_c(curlist->name), ".c")) { tagmap *depend_map = tagmap_alloc(); tagmap_entry *map_entry; file_entry *file; astring *target; int taghash; /* find dependencies */ file = compute_dependencies(srcrootlen, srcfile); recurse_dependencies(file, depend_map); /* convert the target from source to object (makes assumptions about rules) */ target = astring_dup(file->name); astring_replacec(target, 0, "src/", "$(OBJ)/"); astring_replacec(target, 0, ".c", ".o"); printf("\n%s : \\\n", astring_c(target)); /* iterate over the hashed dependencies and output them as well */ for (taghash = 0; taghash < TAGMAP_HASH_SIZE; taghash++) for (map_entry = depend_map->table[taghash]; map_entry != NULL; map_entry = map_entry->next) printf("\t%s \\\n", astring_c((astring *)map_entry->object)); astring_free(target); tagmap_free(depend_map); } } /* if we have a directory, recurse */ else result = recurse_dir(srcrootlen, srcfile); /* free memory for the names */ astring_free(srcfile); } /* free all the allocated entries */ while (list != NULL) { list_entry *next = list->next; astring_free((astring *)list->name); free(list); list = next; } } error: return result; }
static void command_image_loadcreate(running_machine &machine) { device_image_interface *image; const char *filename; const char *format_name; char buf[128]; const char *file_extensions; astring *filepath; int success; const game_driver *gamedrv; const image_device_format *format = NULL; /* look up the image slot */ image = find_device_by_identity(machine, ¤t_command->u.image_args.device_ident); if (image == NULL) return; file_extensions = image->image_config().file_extensions(); /* is an image format specified? */ format_name = current_command->u.image_args.format; if (format_name != NULL) { if (current_command->command_type != MESSTEST_COMMAND_IMAGE_CREATE) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Cannot specify format unless creating"); return; } /* look up the format name */ format = image->device_get_named_creatable_format(format_name); if (format == NULL) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Unknown device format '%s'", format_name); return; } } /* figure out the filename */ filename = current_command->u.image_args.filename; if (!filename) { snprintf(buf, ARRAY_LENGTH(buf), "%s.%s", current_testcase.name, file_extensions); //osd_get_temp_filename(buf, ARRAY_LENGTH(buf), buf); filename = buf; } success = FALSE; for (gamedrv = machine.system(); !success && gamedrv; gamedrv = driver_get_compatible(gamedrv)) { /* assemble the full path */ filepath = assemble_software_path(astring_alloc(), gamedrv, filename); /* actually create or load the image */ switch(current_command->command_type) { case MESSTEST_COMMAND_IMAGE_CREATE: success = (image->create(astring_c(filepath), format, NULL) == IMAGE_INIT_PASS); break; case MESSTEST_COMMAND_IMAGE_LOAD: success = (image->load(astring_c(filepath)) == IMAGE_INIT_PASS); break; default: fatalerror("Unexpected error"); break; } astring_free(filepath); } if (!success) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Failed to load/create image '%s': %s", filename, image->error()); return; } }
astring *auto_astring_alloc_file_line(const char *file, int line) { return restrack_register_object(OBJTYPE_ASTRING, astring_alloc(), 0, file, line); }
astring *auto_astring_alloc_file_line(running_machine *machine, const char *file, int line) { return (astring *)restrack_register_object(OBJTYPE_ASTRING, astring_alloc(), 0, file, line); }
static void machine_config_detokenize(machine_config *config, const machine_config_token *tokens, const device_config *owner, int depth) { UINT32 entrytype = MCONFIG_TOKEN_INVALID; astring *tempstring = astring_alloc(); device_config *device = NULL; /* loop over tokens until we hit the end */ while (entrytype != MCONFIG_TOKEN_END) { device_custom_config_func custom; int size, offset, bits; UINT32 data32, clock; device_type devtype; const char *tag; UINT64 data64; /* unpack the token from the first entry */ TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8); switch (entrytype) { /* end */ case MCONFIG_TOKEN_END: break; /* including */ case MCONFIG_TOKEN_INCLUDE: machine_config_detokenize(config, TOKEN_GET_PTR(tokens, tokenptr), owner, depth + 1); break; /* device management */ case MCONFIG_TOKEN_DEVICE_ADD: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32); devtype = TOKEN_GET_PTR(tokens, devtype); tag = TOKEN_GET_STRING(tokens); device = device_list_add(&config->devicelist, owner, devtype, device_build_tag(tempstring, owner, tag), clock); break; case MCONFIG_TOKEN_DEVICE_REMOVE: tag = TOKEN_GET_STRING(tokens); remove_device(&config->devicelist, device_build_tag(tempstring, owner, tag)); device = NULL; break; case MCONFIG_TOKEN_DEVICE_MODIFY: tag = TOKEN_GET_STRING(tokens); device = (device_config *)device_list_find_by_tag(config->devicelist, device_build_tag(tempstring, owner, tag)); if (device == NULL) fatalerror("Unable to find device: tag=%s\n", astring_c(tempstring)); break; case MCONFIG_TOKEN_DEVICE_CLOCK: assert(device != NULL); TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, device->clock, 32); break; case MCONFIG_TOKEN_DEVICE_MAP: assert(device != NULL); TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, data32, 8); device->address_map[data32] = TOKEN_GET_PTR(tokens, addrmap); break; case MCONFIG_TOKEN_DEVICE_CONFIG: assert(device != NULL); device->static_config = TOKEN_GET_PTR(tokens, voidptr); break; case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_1: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_2: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_3: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_4: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_5: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_6: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_7: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_8: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_9: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_FREE: assert(device != NULL); custom = (device_custom_config_func)devtype_get_info_fct(device->type, DEVINFO_FCT_CUSTOM_CONFIG); assert(custom != NULL); tokens = (*custom)(device, entrytype, tokens); break; case MCONFIG_TOKEN_DEVICE_CONFIG_DATA32: assert(device != NULL); TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK3(tokens, entrytype, 8, size, 4, offset, 12); data32 = TOKEN_GET_UINT32(tokens); switch (size) { case 1: *(UINT8 *) ((UINT8 *)device->inline_config + offset) = data32; break; case 2: *(UINT16 *)((UINT8 *)device->inline_config + offset) = data32; break; case 4: *(UINT32 *)((UINT8 *)device->inline_config + offset) = data32; break; } break; case MCONFIG_TOKEN_DEVICE_CONFIG_DATA64: assert(device != NULL); TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK3(tokens, entrytype, 8, size, 4, offset, 12); TOKEN_EXTRACT_UINT64(tokens, data64); switch (size) { case 1: *(UINT8 *) ((UINT8 *)device->inline_config + offset) = data64; break; case 2: *(UINT16 *)((UINT8 *)device->inline_config + offset) = data64; break; case 4: *(UINT32 *)((UINT8 *)device->inline_config + offset) = data64; break; case 8: *(UINT64 *)((UINT8 *)device->inline_config + offset) = data64; break; } break; case MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32: assert(device != NULL); TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK4(tokens, entrytype, 8, size, 4, bits, 6, offset, 12); data32 = TOKEN_GET_UINT32(tokens); switch (size) { case 4: *(float *)((UINT8 *)device->inline_config + offset) = (float)(INT32)data32 / (float)(1 << bits); break; case 8: *(double *)((UINT8 *)device->inline_config + offset) = (double)(INT32)data32 / (double)(1 << bits); break; } break; /* core parameters */ case MCONFIG_TOKEN_DRIVER_DATA: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, config->driver_data_size, 24); break; case MCONFIG_TOKEN_QUANTUM_TIME: TOKEN_EXTRACT_UINT64(tokens, data64); config->minimum_quantum = UINT64_ATTOTIME_TO_ATTOTIME(data64); break; case MCONFIG_TOKEN_QUANTUM_PERFECT_CPU: config->perfect_cpu_quantum = TOKEN_GET_STRING(tokens); break; case MCONFIG_TOKEN_WATCHDOG_VBLANK: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, config->watchdog_vblank_count, 24); break; case MCONFIG_TOKEN_WATCHDOG_TIME: TOKEN_EXTRACT_UINT64(tokens, data64); config->watchdog_time = UINT64_ATTOTIME_TO_ATTOTIME(data64); break; /* core functions */ case MCONFIG_TOKEN_MACHINE_START: config->machine_start = TOKEN_GET_PTR(tokens, machine_start); break; case MCONFIG_TOKEN_MACHINE_RESET: config->machine_reset = TOKEN_GET_PTR(tokens, machine_reset); break; case MCONFIG_TOKEN_NVRAM_HANDLER: config->nvram_handler = TOKEN_GET_PTR(tokens, nvram_handler); break; case MCONFIG_TOKEN_MEMCARD_HANDLER: config->memcard_handler = TOKEN_GET_PTR(tokens, memcard_handler); break; /* core video parameters */ case MCONFIG_TOKEN_VIDEO_ATTRIBUTES: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, config->video_attributes, 24); break; case MCONFIG_TOKEN_GFXDECODE: config->gfxdecodeinfo = TOKEN_GET_PTR(tokens, gfxdecode); break; case MCONFIG_TOKEN_PALETTE_LENGTH: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, config->total_colors, 24); break; case MCONFIG_TOKEN_DEFAULT_LAYOUT: config->default_layout = TOKEN_GET_STRING(tokens); break; /* core video functions */ case MCONFIG_TOKEN_PALETTE_INIT: config->init_palette = TOKEN_GET_PTR(tokens, palette_init); break; case MCONFIG_TOKEN_VIDEO_START: config->video_start = TOKEN_GET_PTR(tokens, video_start); break; case MCONFIG_TOKEN_VIDEO_RESET: config->video_reset = TOKEN_GET_PTR(tokens, video_reset); break; case MCONFIG_TOKEN_VIDEO_EOF: config->video_eof = TOKEN_GET_PTR(tokens, video_eof); break; case MCONFIG_TOKEN_VIDEO_UPDATE: config->video_update = TOKEN_GET_PTR(tokens, video_update); break; /* core sound functions */ case MCONFIG_TOKEN_SOUND_START: config->sound_start = TOKEN_GET_PTR(tokens, sound_start); break; case MCONFIG_TOKEN_SOUND_RESET: config->sound_reset = TOKEN_GET_PTR(tokens, sound_reset); break; default: fatalerror("Invalid token %d in machine config\n", entrytype); break; } } /* if we are the outermost level, process any device-specific machine configurations */ if (depth == 0) for (device = config->devicelist; device != NULL; device = device->next) { tokens = (const machine_config_token *)device_get_info_ptr(device, DEVINFO_PTR_MACHINE_CONFIG); if (tokens != NULL) machine_config_detokenize(config, tokens, device, depth + 1); } astring_free(tempstring); }
static void create_linked_file(const astring *dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile, const astring *tempheader, const astring *tempfooter) { astring *linkname = astring_alloc(); astring *filename = astring_alloc(); astring *title = astring_alloc(); core_file *linkfile; int listnum; /* create the filename */ astring_printf(filename, "%s.html", curfile->name); /* output header */ astring_printf(title, "%s Regressions (%s)", curfile->name, curfile->source); astring_printf(linkname, "%s" PATH_SEPARATOR "%s", astring_c(dirname), astring_c(filename)); linkfile = create_file_and_output_header(linkname, tempheader, title); if (linkfile == NULL) { fprintf(stderr, "Error creating file '%s'\n", astring_c(filename)); astring_free(title); astring_free(filename); astring_free(linkname); return; } /* link to the previous/next entries */ core_fprintf(linkfile, "\t<p>\n"); core_fprintf(linkfile, "\t<table width=\"100%%\">\n"); core_fprintf(linkfile, "\t\t<td align=\"left\" width=\"40%%\" style=\"border:none\">"); if (prevfile != NULL) core_fprintf(linkfile, "<a href=\"%s.html\"><< %s (%s)</a>", prevfile->name, prevfile->name, prevfile->source); core_fprintf(linkfile, "</td>\n"); core_fprintf(linkfile, "\t\t<td align=\"center\" width=\"20%%\" style=\"border:none\"><a href=\"index.html\">Home</a></td>\n"); core_fprintf(linkfile, "\t\t<td align=\"right\" width=\"40%%\" style=\"border:none\">"); if (nextfile != NULL) core_fprintf(linkfile, "<a href=\"%s.html\">%s (%s) >></a>", nextfile->name, nextfile->name, nextfile->source); core_fprintf(linkfile, "</td>\n"); core_fprintf(linkfile, "\t</table>\n"); core_fprintf(linkfile, "\t</p>\n"); /* output data for each one */ for (listnum = 0; listnum < list_count; listnum++) { int imageindex = -1; /* generate the HTML */ core_fprintf(linkfile, "\n\t<h2>%s</h2>\n", lists[listnum].version); core_fprintf(linkfile, "\t<p>\n"); core_fprintf(linkfile, "\t<b>Status:</b> %s\n", status_text[curfile->status[listnum]]); if (pngfile != NULL) imageindex = get_unique_index(curfile, listnum); if (imageindex != -1) core_fprintf(linkfile, " [%d]", imageindex); core_fprintf(linkfile, "\t</p>\n"); if (curfile->text[listnum] != NULL) { core_fprintf(linkfile, "\t<p>\n"); core_fprintf(linkfile, "\t<b>Errors:</b>\n"); core_fprintf(linkfile, "\t<pre>%s</pre>\n", curfile->text[listnum]); core_fprintf(linkfile, "\t</p>\n"); } } /* output link to the image */ if (pngfile != NULL) { core_fprintf(linkfile, "\n\t<h2>Screenshot Comparisons</h2>\n"); core_fprintf(linkfile, "\t<p>\n"); core_fprintf(linkfile, "\t<img src=\"%s\" />\n", pngfile); core_fprintf(linkfile, "\t</p>\n"); } /* output footer */ output_footer_and_close_file(linkfile, tempfooter, title); astring_free(title); astring_free(filename); astring_free(linkname); }
static int recurse_dir(int srcrootlen, int dstrootlen, const astring *srcdir, const astring *dstdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; const astring *srcdir_subpath; core_file *indexfile = NULL; astring *indexname; int result = 0; int entindex; /* extract a normalized subpath */ srcdir_subpath = normalized_subpath(srcdir, srcrootlen + 1); if (srcdir_subpath == NULL) return 1; /* create an index file */ indexname = astring_alloc(); astring_printf(indexname, "%s%c%s", astring_c(dstdir), PATH_SEPARATOR[0], "index.html"); indexfile = create_file_and_output_header(indexname, "MAME Source Code", astring_c(srcdir_subpath)); astring_free(indexname); /* output the directory navigation */ core_fprintf(indexfile, "<h3>Viewing Directory: "); output_path_as_links(indexfile, srcdir_subpath, TRUE, FALSE); core_fprintf(indexfile, "</h3>"); astring_free((astring *)srcdir_subpath); /* iterate first over directories, then over files */ for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; const osd_directory_entry *entry; list_entry *list = NULL; list_entry **listarray; list_entry *curlist; osd_directory *dir; int found = 0; /* open the directory and iterate through it */ dir = osd_opendir(astring_c(srcdir)); if (dir == NULL) { result = 1; goto error; } /* build up the list of files */ while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = malloc(sizeof(*lentry)); lentry->name = astring_dupc(entry->name); lentry->next = list; list = lentry; found++; } /* close the directory */ osd_closedir(dir); /* skip if nothing found */ if (found == 0) continue; /* allocate memory for sorting */ listarray = malloc(sizeof(list_entry *) * found); found = 0; for (curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; /* sort the list */ qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); /* rebuild the list */ list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } /* iterate through each file */ for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring *srcfile, *dstfile; /* add a header */ if (curlist == list) core_fprintf(indexfile, "\t<h2>%s</h2>\n\t<ul>\n", (entry_type == ENTTYPE_DIR) ? "Directories" : "Files"); /* build the source filename */ srcfile = astring_alloc(); astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name)); /* if we have a file, output it */ dstfile = astring_alloc(); if (entry_type == ENTTYPE_FILE) { file_type type = FILE_TYPE_INVALID; int extnum; /* make sure we care, first */ for (extnum = 0; extnum < ARRAY_LENGTH(extension_lookup); extnum++) if (core_filename_ends_with(astring_c(curlist->name), extension_lookup[extnum].extension)) { type = extension_lookup[extnum].type; break; } /* if we got a valid file, process it */ if (type != FILE_TYPE_INVALID) { astring_printf(dstfile, "%s%c%s.html", astring_c(dstdir), PATH_SEPARATOR[0], astring_c(curlist->name)); if (indexfile != NULL) core_fprintf(indexfile, "\t<li><a href=\"%s.html\">%s</a></li>\n", astring_c(curlist->name), astring_c(curlist->name)); result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, astring_cmp(srcdir, dstdir) == 0); } } /* if we have a directory, recurse */ else { astring_printf(dstfile, "%s%c%s", astring_c(dstdir), PATH_SEPARATOR[0], astring_c(curlist->name)); if (indexfile != NULL) core_fprintf(indexfile, "\t<li><a href=\"%s/index.html\">%s/</a></li>\n", astring_c(curlist->name), astring_c(curlist->name)); result = recurse_dir(srcrootlen, dstrootlen, srcfile, dstfile); } /* free memory for the names */ astring_free(srcfile); astring_free(dstfile); } /* close the list if we found some stuff */ if (list != NULL) core_fprintf(indexfile, "\t</ul>\n"); /* free all the allocated entries */ while (list != NULL) { list_entry *next = list->next; astring_free((astring *)list->name); free(list); list = next; } } error: if (indexfile != NULL) output_footer_and_close_file(indexfile); return result; }