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; }
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; }
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; }
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)); } } }
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 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; }
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; }
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; }
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; }