static DEVICE_RESET( ti99_pcoden ) { logerror("ti99_pcode: reset\n"); ti99_pcoden_state *pcode = get_safe_token(device); /* If the card is selected in the menu, register the card */ if (input_port_read(device->machine(), "EXTCARD") & EXT_PCODE) { device_t *peb = device->owner(); int success = mount_card(peb, device, &pcode_ncard, get_pebcard_config(device)->slot); if (!success) return; astring *region = new astring(); astring_assemble_3(region, device->tag(), ":", pcode_region); pcode->rom0 = device->machine().region(astring_c(region))->base(); pcode->rom1 = pcode->rom0 + 0x1000; pcode->rom2 = pcode->rom0 + 0x2000; pcode->grom = pcode->rom0 + 0x3000; pcode->bank_select = 0; pcode->selected = 0; astring *gromname = new astring(); for (int i=0; i < 8; i++) { astring_printf(gromname, "grom_%d", i); pcode->gromdev[i] = device->subdevice(astring_c(gromname)); } } }
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; }
static void output_footer_and_close_file(core_file *file, const astring *templatefile, const astring *title) { astring *modified; modified = astring_dup(templatefile); astring_replacec(modified, 0, "<!--TITLE-->", astring_c(title)); core_fwrite(file, astring_c(modified), astring_len(modified)); astring_free(modified); core_fclose(file); }
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; }
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 MACHINE_RESET( ldplayer ) { /* set up a timer to start playing immediately */ timer_set(machine, attotime_zero, NULL, 0, autoplay); /* indicate the name of the file we opened */ popmessage("Opened %s\n", astring_c(filename)); }
const char *LibMame_RunningGame_GetSpeedText(LibMame_RunningGame *game) { (void) game; g_state.machine->video().speed_text(g_state.speed_text); return astring_c(&(g_state.speed_text)); }
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 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 const multicartslot_pcb_type *identify_pcb(device_image_interface &image) { const multicartslot_config *config = get_config(&image.device()); astring pcb_name; const multicartslot_pcb_type *pcb_type = NULL; multicart_t *mc; int i; if (image.exists()) { /* try opening this as if it were a multicart */ multicart_open_error me = multicart_open(image.device().machine().options(), image.filename(), image.device().machine().system().name, MULTICART_FLAGS_DONT_LOAD_RESOURCES, &mc); if (me == MCERR_NONE) { /* this was a multicart - read from it */ astring_cpyc(&pcb_name, mc->pcb_type); multicart_close(image.device().machine().options(), mc); } else { if (me != MCERR_NOT_MULTICART) fatalerror("multicart error: %s", multicart_error_text(me)); } /* look for PCB type with matching name */ for (i = 0; (i < ARRAY_LENGTH(config->pcb_types)) && (config->pcb_types[i].name != NULL); i++) { if ((config->pcb_types[i].name[0] == '\0') || !strcmp(astring_c(&pcb_name), config->pcb_types[i].name)) { pcb_type = &config->pcb_types[i]; break; } } /* check for unknown PCB type */ if ((mc != NULL) && (pcb_type == NULL)) fatalerror("Unknown PCB type \"%s\"", astring_c(&pcb_name)); } else { /* no device loaded; use the default */ pcb_type = (config->pcb_types[0].name != NULL) ? &config->pcb_types[0] : NULL; } return pcb_type; }
static core_file *create_file_and_output_header(const astring *filename, const astring *templatefile, const astring *title) { astring *modified; core_file *file; /* create the indexfile */ if (core_fopen(astring_c(filename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE) return NULL; /* print a header */ modified = astring_dup(templatefile); astring_replacec(modified, 0, "<!--TITLE-->", astring_c(title)); core_fwrite(file, astring_c(modified), astring_len(modified)); /* return the file */ astring_free(modified); return file; }
int main(int argc, char *argv[]) { astring *dirname = NULL, *tempfilename = NULL, *tempheader = NULL, *tempfooter = NULL; UINT32 bufsize; void *buffer; int listnum; int result; /* first argument is the directory */ if (argc < 4) { fprintf(stderr, "Usage:\nregrep <template> <outputdir> <summary1> [<summary2> [<summary3> ...]]\n"); return 1; } tempfilename = astring_dupc(argv[1]); dirname = astring_dupc(argv[2]); list_count = argc - 3; /* read the template file into an astring */ if (core_fload(astring_c(tempfilename), &buffer, &bufsize) == FILERR_NONE) { tempheader = astring_dupch((const char *)buffer, bufsize); free(buffer); } /* verify the template */ if (tempheader == NULL) { fprintf(stderr, "Unable to read template file\n"); return 1; } result = astring_findc(tempheader, 0, "<!--CONTENT-->"); if (result == -1) { fprintf(stderr, "Template is missing a <!--CONTENT--> marker\n"); return 1; } tempfooter = astring_substr(astring_dup(tempheader), result + 14, -1); tempheader = astring_substr(tempheader, 0, result); /* loop over arguments and read the files */ for (listnum = 0; listnum < list_count; listnum++) { result = read_summary_log(argv[listnum + 3], listnum); if (result != 0) return result; } /* output the summary */ output_report(dirname, tempheader, tempfooter, sort_file_list()); astring_free(dirname); astring_free(tempfilename); astring_free(tempheader); astring_free(tempfooter); return 0; }
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 astring *find_include_file(int srcrootlen, const astring *srcfile, 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_dup(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) { int sepindex_part = astring_rchr(srcincpath, 0, PATH_SEPARATOR[0]); if (sepindex_part != -1) astring_substr(srcincpath, 0, sepindex_part); } /* 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) { /* close the file */ core_fclose(testfile); return srcincpath; } /* free our include path */ astring_free(srcincpath); } return NULL; }
static void recurse_dependencies(file_entry *file, tagmap *map) { int filelen = astring_len(file->name); exclude_path *exclude; dependency *dep; /* skip if we're in an exclude path */ for (exclude = excpaths; exclude != NULL; exclude = exclude->next) if (exclude->pathlen < filelen && strncmp(astring_c(file->name), astring_c(exclude->path), exclude->pathlen) == 0) if (exclude->recursive || astring_chr(file->name, exclude->pathlen + 1, '/') == -1) return; /* attempt to add; if we get an error, we're already present */ if (tagmap_add(map, astring_c(file->name), file->name, FALSE) != TMERR_NONE) return; /* recurse the list from there */ for (dep = file->deplist; dep != NULL; dep = dep->next) recurse_dependencies(dep->file, map); }
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; }
static multicart_open_error load_ram_resource(emu_options &options, multicart_load_state *state, xml_data_node *resource_node, multicart_resource *resource) { const char *length_string; const char *ram_type; const char *ram_filename; astring *ram_pathname; /* locate the 'length' attribute */ length_string = xml_get_attribute_string(resource_node, "length", NULL); if (length_string == NULL) return MCERR_MISSING_RAM_LENGTH; /* ...and parse it */ resource->length = ram_parse_string(length_string); if (resource->length <= 0) return MCERR_INVALID_RAM_SPEC; /* allocate bytes for this resource */ resource->ptr = pool_malloc_lib(state->multicart->data->pool, resource->length); if (resource->ptr == NULL) return MCERR_OUT_OF_MEMORY; /* Is this a persistent RAM resource? Then try to load it. */ ram_type = xml_get_attribute_string(resource_node, "type", NULL); if (ram_type != NULL) { if (strcmp(ram_type, "persistent")==0) { astring tmp; /* Get the file name. */ ram_filename = xml_get_attribute_string(resource_node, "file", NULL); if (ram_filename==NULL) return MCERR_XML_ERROR; ram_pathname = astring_assemble_3(&tmp, state->multicart->gamedrv_name, PATH_SEPARATOR, ram_filename); /* Save the file name so that we can write the contents on unloading. If the RAM resource has no filename, we know that it was volatile only. */ resource->filename = pool_strdup_lib(state->multicart->data->pool, astring_c(ram_pathname)); if (resource->filename == NULL) return MCERR_OUT_OF_MEMORY; image_battery_load_by_name(options, resource->filename, resource->ptr, resource->length, 0x00); } /* else this type is volatile, in which case we just have a memory expansion */ } return MCERR_NONE; }
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; }
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; }
void x86log_printf(x86log_context *log, const char *format, ...) { va_list va; /* open the file, creating it if necessary */ if (log->file == NULL) log->file = fopen(astring_c(log->filename), "w"); if (log->file == NULL) return; /* do the printf */ va_start(va, format); vfprintf(log->file, format, va); va_end(va); /* flush the file */ fflush(log->file); }
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; }
static core_file *create_file_and_output_header(const astring *filename, const char *title, const char *subtitle) { core_file *file; /* create the indexfile */ if (core_fopen(astring_c(filename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE) return NULL; /* print a header */ core_fprintf(file, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" "\n" "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" "<head>\n" "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" "\t<title>%s</title>\n" "\t<link rel=\"stylesheet\" href=\"http://mamedev.org/styles-site.css\" type=\"text/css\" />\n" "</head>\n" "\n" "<body>\n" "\t<div id=\"outer\">\n" "\n" "\t<div id=\"banner\">\n" "\t<h1>%s</h1>\n" "\t<h2>%s</h2>\n" "\t</div>\n" "\n" "\t<div id=\"left\">\n" "\t<div class=\"sidebar\">\n" "\t<!--#include virtual=\"/links.txt\" -->\n" "\t</div>\n" "\t</div>\n" "\n" "\t<div id=\"center\">\n" "\t<div class=\"content\">\n" "\n", title, title, (subtitle == NULL) ? " " : subtitle ); /* return the file */ return file; }
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); }
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; }
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 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; }