/* seek to track/head/sector relative position in image file */ static int d88image_seek(d88image * w, UINT8 t, UINT8 h, UINT8 s) { unsigned long offset; /* allow two additional tracks */ if (t >= D88_NUM_TRACK/2) { logerror("d88image track %d >= %d\n", t, D88_NUM_TRACK/2); return 0; } if (h >= 2) { logerror("d88image head %d >= %d\n", h, 2); return 0; } if (s >= w->num_sects[t*2+h]) { logerror("d88image sector %d\n", w->num_sects[t*2+h]); return 0; } offset = w->sects[t*2+h][s].offset; #if VERBOSE logerror("d88image seek track:%d head:%d sector:%d-> offset #0x%08lX\n", t, h, s, offset); #endif if (offset > w->image_size) { logerror("d88image seek offset %ld >= %ld\n", offset, w->image_size); return 0; } if (mame_fseek(w->image_file, offset, SEEK_SET) < 0) { logerror("d88image seek failed\n"); return 0; } return 1; }
int state_save_check_file(mame_file *file, const char *gamename, int validate_signature, void (CLIB_DECL *errormsg)(const char *fmt, ...)) { UINT32 signature = 0; UINT8 header[0x18]; /* if we want to validate the signature, compute it */ if (validate_signature) signature = get_signature(); /* seek to the beginning and read the header */ mame_fseek(file, 0, SEEK_SET); if (mame_fread(file, header, sizeof(header)) != sizeof(header)) { if (errormsg) errormsg("Could not read " APPNAME " save file header"); return -1; } /* let the generic header check work out the rest */ return validate_header(header, gamename, signature, errormsg, ""); }
state_save_error state_save_write_file(running_machine *machine, mame_file *file) { state_private *global = machine->state_data; UINT32 signature = get_signature(machine); UINT8 header[HEADER_SIZE]; state_callback *func; state_entry *entry; /* if we have illegal registrations, return an error */ if (global->illegal_regs > 0) return STATERR_ILLEGAL_REGISTRATIONS; /* generate the header */ memcpy(&header[0], ss_magic_num, 8); header[8] = SAVE_VERSION; header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST); strncpy((char *)&header[0x0a], machine->gamedrv->name, 0x1c - 0x0a); *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(signature); /* write the header and turn on compression for the rest of the file */ mame_fcompress(file, FCOMPRESS_NONE); mame_fseek(file, 0, SEEK_SET); if (mame_fwrite(file, header, sizeof(header)) != sizeof(header)) return STATERR_WRITE_ERROR; mame_fcompress(file, FCOMPRESS_MEDIUM); /* call the pre-save functions */ for (func = global->prefunclist; func != NULL; func = func->next) (*func->func.presave)(machine, func->param); /* then write all the data */ for (entry = global->entrylist; entry != NULL; entry = entry->next) { UINT32 totalsize = entry->typesize * entry->typecount; if (mame_fwrite(file, entry->data, totalsize) != totalsize) return STATERR_WRITE_ERROR; } return STATERR_NONE; }
state_save_error state_save_check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...)) { UINT8 header[HEADER_SIZE]; UINT32 signature = 0; /* if we want to validate the signature, compute it */ if (machine != NULL) signature = get_signature(machine); /* seek to the beginning and read the header */ mame_fcompress(file, FCOMPRESS_NONE); mame_fseek(file, 0, SEEK_SET); if (mame_fread(file, header, sizeof(header)) != sizeof(header)) { if (errormsg != NULL) (*errormsg)(_("Could not read " APPNAME " save file header")); return STATERR_READ_ERROR; } /* let the generic header check work out the rest */ return validate_header(header, gamename, signature, errormsg, ""); }
static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample *sample) { unsigned long offset = 0; UINT32 length, rate, filesize; UINT16 bits, temp16; char buf[32]; UINT32 sindex; /* read the core header and make sure it's a WAVE file */ offset += mame_fread(f, buf, 4); if (offset < 4) return 0; if (memcmp(&buf[0], "RIFF", 4) != 0) return 0; /* get the total size */ offset += mame_fread(f, &filesize, 4); if (offset < 8) return 0; filesize = LITTLE_ENDIANIZE_INT32(filesize); /* read the RIFF file type and make sure it's a WAVE file */ offset += mame_fread(f, buf, 4); if (offset < 12) return 0; if (memcmp(&buf[0], "WAVE", 4) != 0) return 0; /* seek until we find a format tag */ while (1) { offset += mame_fread(f, buf, 4); offset += mame_fread(f, &length, 4); length = LITTLE_ENDIANIZE_INT32(length); if (memcmp(&buf[0], "fmt ", 4) == 0) break; /* seek to the next block */ mame_fseek(f, length, SEEK_CUR); offset += length; if (offset >= filesize) return 0; } /* read the format -- make sure it is PCM */ offset += mame_fread(f, &temp16, 2); temp16 = LITTLE_ENDIANIZE_INT16(temp16); if (temp16 != 1) return 0; /* number of channels -- only mono is supported */ offset += mame_fread(f, &temp16, 2); temp16 = LITTLE_ENDIANIZE_INT16(temp16); if (temp16 != 1) return 0; /* sample rate */ offset += mame_fread(f, &rate, 4); rate = LITTLE_ENDIANIZE_INT32(rate); /* bytes/second and block alignment are ignored */ offset += mame_fread(f, buf, 6); /* bits/sample */ offset += mame_fread(f, &bits, 2); bits = LITTLE_ENDIANIZE_INT16(bits); if (bits != 8 && bits != 16) return 0; /* seek past any extra data */ mame_fseek(f, length - 16, SEEK_CUR); offset += length - 16; /* seek until we find a data tag */ while (1) { offset += mame_fread(f, buf, 4); offset += mame_fread(f, &length, 4); length = LITTLE_ENDIANIZE_INT32(length); if (memcmp(&buf[0], "data", 4) == 0) break; /* seek to the next block */ mame_fseek(f, length, SEEK_CUR); offset += length; if (offset >= filesize) return 0; } /* if there was a 0 length data block, we're done */ if (length == 0) return 0; /* fill in the sample data */ sample->length = length; sample->frequency = rate; /* read the data in */ if (bits == 8) { unsigned char *tempptr; int sindex; sample->data = auto_alloc_array(machine, INT16, length); mame_fread(f, sample->data, length); /* convert 8-bit data to signed samples */ tempptr = (unsigned char *)sample->data; for (sindex = length - 1; sindex >= 0; sindex--) sample->data[sindex] = (INT8)(tempptr[sindex] ^ 0x80) * 256; } else { /* 16-bit data is fine as-is */ sample->data = auto_alloc_array(machine, INT16, length/2); mame_fread(f, sample->data, length); sample->length /= 2; if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE) for (sindex = 0; sindex < sample->length; sindex++) sample->data[sindex] = LITTLE_ENDIANIZE_INT16(sample->data[sindex]); } return 1; }
/* and doesn't search the rompath */ static struct GameSample *vc20_read_wav_sample (mame_file *f) { /* NPW 28-Feb-2005 - this code sucks */ return NULL; #if 0 unsigned long offset = 0; UINT32 length, rate, filesize, temp32; UINT16 bits, temp16; char buf[32]; struct GameSample *result; /* read the core header and make sure it's a WAVE file */ offset += mame_fread (f, buf, 4); if (offset < 4) return NULL; if (memcmp (&buf[0], "RIFF", 4) != 0) return NULL; /* get the total size */ offset += mame_fread (f, &filesize, 4); if (offset < 8) return NULL; filesize = LITTLE_ENDIANIZE_INT32 (filesize); /* read the RIFF file type and make sure it's a WAVE file */ offset += mame_fread (f, buf, 4); if (offset < 12) return NULL; if (memcmp (&buf[0], "WAVE", 4) != 0) return NULL; /* seek until we find a format tag */ while (1) { offset += mame_fread (f, buf, 4); offset += mame_fread (f, &length, 4); length = LITTLE_ENDIANIZE_INT32 (length); if (memcmp (&buf[0], "fmt ", 4) == 0) break; /* seek to the next block */ mame_fseek (f, length, SEEK_CUR); offset += length; if (offset >= filesize) return NULL; } /* read the format -- make sure it is PCM */ offset += mame_fread_lsbfirst (f, &temp16, 2); if (temp16 != 1) return NULL; /* number of channels -- only mono is supported */ offset += mame_fread_lsbfirst (f, &temp16, 2); if (temp16 != 1) return NULL; /* sample rate */ offset += mame_fread (f, &rate, 4); rate = LITTLE_ENDIANIZE_INT32 (rate); /* bytes/second and block alignment are ignored */ offset += mame_fread (f, buf, 6); /* bits/sample */ offset += mame_fread_lsbfirst (f, &bits, 2); if (bits != 8 && bits != 16) return NULL; /* seek past any extra data */ mame_fseek (f, length - 16, SEEK_CUR); offset += length - 16; /* seek until we find a data tag */ while (1) { offset += mame_fread (f, buf, 4); offset += mame_fread (f, &length, 4); length = LITTLE_ENDIANIZE_INT32 (length); if (memcmp (&buf[0], "data", 4) == 0) break; /* seek to the next block */ mame_fseek (f, length, SEEK_CUR); offset += length; if (offset >= filesize) return NULL; } /* allocate the game sample */ result = (struct GameSample *)malloc (sizeof (struct GameSample) + length); if (result == NULL) return NULL; /* fill in the sample data */ result->length = length; result->smpfreq = rate; result->resolution = bits; /* read the data in */ if (bits == 8) { mame_fread (f, result->data, length); /* convert 8-bit data to signed samples */ for (temp32 = 0; temp32 < length; temp32++) result->data[temp32] -= 0x80; } else { /* 16-bit data is fine as-is */ mame_fread_lsbfirst (f, result->data, length); } return result; #endif }
int cli_frontend_init (int argc, char **argv) { machine_config drv; char buffer[128]; char *cmd_name; int game_index; int i; gamename = NULL; game_index = -1; /* clear all core options */ memset(&options,0,sizeof(options)); /* create the rc object */ rc = cli_rc_create(); if (!rc) { osd_die ("error on rc creation\n"); } /* parse the commandline */ got_gamename = 0; if (rc_parse_commandline(rc, argc, argv, 2, config_handle_arg)) { osd_die ("error while parsing cmdline\n"); } /* determine global configfile name */ cmd_name = win_strip_extension(win_basename(argv[0])); if (!cmd_name) { osd_die ("who am I? cannot determine the name I was called with\n"); } sprintf (buffer, "%s.ini", cmd_name); /* parse mame.ini/mess.ini even if called with another name */ if (mame_stricmp(cmd_name, APPNAME) != 0) { if (parse_config (APPNAME".ini", NULL)) exit(1); } /* parse cmd_name.ini */ if (parse_config (buffer, NULL)) exit(1); #ifdef MAME_DEBUG if (parse_config( "debug.ini", NULL)) exit(1); #endif /* if requested, write out cmd_name.ini (normally "mame.ini") */ if (createconfig) { rc_save(rc, buffer, 0); exit(0); } if (showconfig) { sprintf (buffer, " %s running parameters", cmd_name); rc_write(rc, stdout, buffer); exit(0); } if (showusage) { fprintf(stdout, "Usage: %s [" GAMENOUN "] [options]\n" "Options:\n", cmd_name); /* actual help message */ rc_print_help(rc, stdout); exit(0); } /* no longer needed */ free(cmd_name); /* handle playback */ if (playbackname != NULL) { options.playback = mame_fopen(playbackname,0,FILETYPE_INPUTLOG,0); if (!options.playback) { osd_die("failed to open %s for playback\n", playbackname); } } /* check for game name embedded in .inp header */ if (options.playback) { inp_header inp_header; /* read playback header */ mame_fread(options.playback, &inp_header, sizeof(inp_header)); if (!isalnum(inp_header.name[0])) /* If first byte is not alpha-numeric */ mame_fseek(options.playback, 0, SEEK_SET); /* old .inp file - no header */ else { for (i = 0; (drivers[i] != 0); i++) /* find game and play it */ { if (strcmp(drivers[i]->name, inp_header.name) == 0) { game_index = i; gamename = (char *)drivers[i]->name; printf("Playing back previously recorded " GAMENOUN " %s (%s) [press return]\n", drivers[game_index]->name,drivers[game_index]->description); getchar(); break; } } } } /* check for frontend options, horrible 1234 hack */ if (frontend_help(gamename) != 1234) exit(0); gamename = win_basename(gamename); gamename = win_strip_extension(gamename); /* if not given by .inp file yet */ if (game_index == -1) { /* do we have a driver for this? */ for (i = 0; drivers[i]; i++) if (mame_stricmp(gamename,drivers[i]->name) == 0) { game_index = i; break; } } #ifdef MAME_DEBUG if (game_index == -1) { /* pick a random game */ if (strcmp(gamename,"random") == 0) { i = 0; while (drivers[i]) i++; /* count available drivers */ srand(time(0)); /* call rand() once to get away from the seed */ rand(); game_index = rand() % i; fprintf(stderr, "running %s (%s) [press return]",drivers[game_index]->name,drivers[game_index]->description); getchar(); } } #endif /* we give up. print a few approximate matches */ if (game_index == -1) { fprintf(stderr, "\n\"%s\" approximately matches the following\n" "supported " GAMESNOUN " (best match first):\n\n", gamename); show_approx_matches(); exit(1); } /* ok, got a gamename */ /* if this is a vector game, parse vector.ini first */ expand_machine_driver(drivers[game_index]->drv, &drv); if (drv.video_attributes & VIDEO_TYPE_VECTOR) if (parse_config ("vector.ini", NULL)) exit(1); /* nice hack: load source_file.ini (omit if referenced later any) */ { const game_driver *tmp_gd; const char *start; /* remove the path and the .c suffix from the source file name */ start = strrchr(drivers[game_index]->source_file, '/'); if (!start) start = strrchr(drivers[game_index]->source_file, '\\'); if (!start) start = drivers[game_index]->source_file - 1; sprintf(buffer, "%s", start + 1); buffer[strlen(buffer) - 2] = 0; tmp_gd = drivers[game_index]; while (tmp_gd != NULL) { if (strcmp(tmp_gd->name, buffer) == 0) break; tmp_gd = tmp_gd->clone_of; } if (tmp_gd == NULL) /* not referenced later, so load it here */ { strcat(buffer, ".ini"); if (parse_config (buffer, NULL)) exit(1); } } /* now load gamename.ini */ /* this possibly checks for clonename.ini recursively! */ if (parse_config (NULL, drivers[game_index])) exit(1); /* handle record option */ if (recordname) { options.record = mame_fopen(recordname,0,FILETYPE_INPUTLOG,1); if (!options.record) { osd_die("failed to open %s for recording\n", recordname); } } if (options.record) { inp_header inp_header; memset(&inp_header, '\0', sizeof(inp_header)); strcpy(inp_header.name, drivers[game_index]->name); /* MAME32 stores the MAME version numbers at bytes 9 - 11 * MAME DOS keeps this information in a string, the * Windows code defines them in the Makefile. */ /* inp_header.version[0] = 0; inp_header.version[1] = VERSION; inp_header.version[2] = BETA_VERSION; */ mame_fwrite(options.record, &inp_header, sizeof(inp_header)); } if (statename) options.savegame = statename; #if defined(MAME_DEBUG) && defined(NEW_DEBUGGER) if (debugscript) debug_source_script(debugscript); #endif /* need a decent default for debug width/height */ if (options.debug_width == 0) options.debug_width = 640; if (options.debug_height == 0) options.debug_height = 480; options.debug_depth = 8; /* no sound is indicated by a 0 samplerate */ if (!enable_sound) options.samplerate = 0; /* set the artwork options */ options.use_artwork = ARTWORK_USE_ALL; if (use_backdrops == 0) options.use_artwork &= ~ARTWORK_USE_BACKDROPS; if (use_overlays == 0) options.use_artwork &= ~ARTWORK_USE_OVERLAYS; if (use_bezels == 0) options.use_artwork &= ~ARTWORK_USE_BEZELS; if (!use_artwork) options.use_artwork = ARTWORK_USE_NONE; { /* first start with the game's built in orientation */ int orientation = drivers[game_index]->flags & ORIENTATION_MASK; options.ui_orientation = orientation; if (options.ui_orientation & ORIENTATION_SWAP_XY) { /* if only one of the components is inverted, switch them */ if ((options.ui_orientation & ROT180) == ORIENTATION_FLIP_X || (options.ui_orientation & ROT180) == ORIENTATION_FLIP_Y) options.ui_orientation ^= ROT180; } /* override if no rotation requested */ if (video_norotate) orientation = options.ui_orientation = ROT0; /* rotate right */ if (video_ror) { /* if only one of the components is inverted, switch them */ if ((orientation & ROT180) == ORIENTATION_FLIP_X || (orientation & ROT180) == ORIENTATION_FLIP_Y) orientation ^= ROT180; orientation ^= ROT90; } /* rotate left */ if (video_rol) { /* if only one of the components is inverted, switch them */ if ((orientation & ROT180) == ORIENTATION_FLIP_X || (orientation & ROT180) == ORIENTATION_FLIP_Y) orientation ^= ROT180; orientation ^= ROT270; } /* auto-rotate right (e.g. for rotating lcds), based on original orientation */ if (video_autoror && (drivers[game_index]->flags & ORIENTATION_SWAP_XY) ) { /* if only one of the components is inverted, switch them */ if ((orientation & ROT180) == ORIENTATION_FLIP_X || (orientation & ROT180) == ORIENTATION_FLIP_Y) orientation ^= ROT180; orientation ^= ROT90; } /* auto-rotate left (e.g. for rotating lcds), based on original orientation */ if (video_autorol && (drivers[game_index]->flags & ORIENTATION_SWAP_XY) ) { /* if only one of the components is inverted, switch them */ if ((orientation & ROT180) == ORIENTATION_FLIP_X || (orientation & ROT180) == ORIENTATION_FLIP_Y) orientation ^= ROT180; orientation ^= ROT270; } /* flip X/Y */ if (video_flipx) orientation ^= ORIENTATION_FLIP_X; if (video_flipy) orientation ^= ORIENTATION_FLIP_Y; blit_flipx = ((orientation & ORIENTATION_FLIP_X) != 0); blit_flipy = ((orientation & ORIENTATION_FLIP_Y) != 0); blit_swapxy = ((orientation & ORIENTATION_SWAP_XY) != 0); if( options.vector_width == 0 && options.vector_height == 0 ) { options.vector_width = 640; options.vector_height = 480; } if( blit_swapxy ) { int temp; temp = options.vector_width; options.vector_width = options.vector_height; options.vector_height = temp; } } return game_index; }
/**************************************************************************** * GetNextToken - Pointer to the token string pointer * Pointer to position within file * * Returns token, or TOKEN_INVALID if at end of file ****************************************************************************/ static UINT32 GetNextToken(char **ppszTokenText, long *pdwPosition) { UINT32 dwLength; /* Length of symbol */ long dwPos; /* Temporary position */ UINT8 *pbTokenPtr = bToken; /* Point to the beginning */ UINT8 bData; /* Temporary data byte */ while (1) { bData = mame_fgetc(fp); /* Get next character */ /* If we're at the end of the file, bail out */ if (mame_feof(fp)) return(TOKEN_INVALID); /* If it's not whitespace, then let's start eating characters */ if (' ' != bData && '\t' != bData) { /* Store away our file position (if given on input) */ if (pdwPosition) *pdwPosition = dwFilePos; /* If it's a separator, special case it */ if (',' == bData || '=' == bData) { *pbTokenPtr++ = bData; *pbTokenPtr = '\0'; ++dwFilePos; if (',' == bData) return(TOKEN_COMMA); else return(TOKEN_EQUALS); } /* Otherwise, let's try for a symbol */ if (bData > ' ') { dwLength = 0; /* Assume we're 0 length to start with */ /* Loop until we've hit something we don't understand */ while (bData != ',' && bData != '=' && bData != ' ' && bData != '\t' && bData != '\n' && bData != '\r' && mame_feof(fp) == 0) { ++dwFilePos; *pbTokenPtr++ = bData; /* Store our byte */ ++dwLength; assert(dwLength < MAX_TOKEN_LENGTH); bData = mame_fgetc(fp); } /* If it's not the end of the file, put the last received byte */ /* back. We don't want to touch the file position, though if */ /* we're past the end of the file. Otherwise, adjust it. */ if (0 == mame_feof(fp)) { mame_ungetc(bData, fp); } /* Null terminate the token */ *pbTokenPtr = '\0'; /* Connect up the */ if (ppszTokenText) *ppszTokenText = (char *)bToken; return(TOKEN_SYMBOL); } /* Not a symbol. Let's see if it's a cr/cr, lf/lf, or cr/lf/cr/lf */ /* sequence */ if (LF == bData) { /* Unix style perhaps? */ bData = mame_fgetc(fp); /* Peek ahead */ mame_ungetc(bData, fp); /* Force a retrigger if subsequent LF's */ if (LF == bData) /* Two LF's in a row - it's a UNIX hard CR */ { ++dwFilePos; *pbTokenPtr++ = bData; /* A real linefeed */ *pbTokenPtr = '\0'; return(TOKEN_LINEBREAK); } /* Otherwise, fall through and keep parsing. */ } else if (CR == bData) /* Carriage return? */ { /* Figure out if it's Mac or MSDOS format */ ++dwFilePos; bData = mame_fgetc(fp); /* Peek ahead */ /* We don't need to bother with EOF checking. It will be 0xff if */ /* it's the end of the file and will be caught by the outer loop. */ if (CR == bData) /* Mac style hard return! */ { /* Do not advance the file pointer in case there are successive */ /* CR/CR sequences */ /* Stuff our character back upstream for successive CR's */ mame_ungetc(bData, fp); *pbTokenPtr++ = bData; /* A real carriage return (hard) */ *pbTokenPtr = '\0'; return(TOKEN_LINEBREAK); } else if (LF == bData) /* MSDOS format! */ { ++dwFilePos; /* Our file position to reset to */ dwPos = dwFilePos; /* Here so we can reposition things */ /* Look for a followup CR/LF */ bData = mame_fgetc(fp); /* Get the next byte */ if (CR == bData) /* CR! Good! */ { bData = mame_fgetc(fp); /* Get the next byte */ /* We need to do this to pick up subsequent CR/LF sequences */ mame_fseek(fp, dwPos, SEEK_SET); if (pdwPosition) *pdwPosition = dwPos; if (LF == bData) /* LF? Good! */ { *pbTokenPtr++ = '\r'; *pbTokenPtr++ = '\n'; *pbTokenPtr = '\0'; return(TOKEN_LINEBREAK); } } else { --dwFilePos; mame_ungetc(bData, fp); /* Put the character back. No good */ } } else { --dwFilePos; mame_ungetc(bData, fp); /* Put the character back. No good */ } /* Otherwise, fall through and keep parsing */ } } ++dwFilePos; } }
static int mame_fseek_thunk(void *file, INT64 offset, int whence) { return mame_fseek((mame_file *) file, offset, whence); }
static UINT32 mess_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer) { mame_fseek((mame_file *)file, offset, SEEK_SET); return mame_fwrite((mame_file *)file, buffer, count); }
static int process_rom_entries(struct rom_load_data *romdata, const struct RomModule *romp) { UINT32 lastflags = 0; /* loop until we hit the end of this region */ while (!ROMENTRY_ISREGIONEND(romp)) { /* if this is a continue entry, it's invalid */ if (ROMENTRY_ISCONTINUE(romp)) { printf("Error in RomModule definition: ROM_CONTINUE not preceded by ROM_LOAD\n"); goto fatalerror; } /* if this is a reload entry, it's invalid */ if (ROMENTRY_ISRELOAD(romp)) { printf("Error in RomModule definition: ROM_RELOAD not preceded by ROM_LOAD\n"); goto fatalerror; } /* handle fills */ if (ROMENTRY_ISFILL(romp)) { if (!fill_rom_data(romdata, romp++)) goto fatalerror; } /* handle copies */ else if (ROMENTRY_ISCOPY(romp)) { if (!copy_rom_data(romdata, romp++)) goto fatalerror; } /* handle files */ else if (ROMENTRY_ISFILE(romp)) { if (!ROM_GETBIOSFLAGS(romp) || (ROM_GETBIOSFLAGS(romp) == (system_bios+1))) /* alternate bios sets */ { const struct RomModule *baserom = romp; int explength = 0; /* open the file */ debugload("Opening ROM file: %s\n", ROM_GETNAME(romp)); if (!open_rom_file(romdata, romp)) handle_missing_file(romdata, romp); /* loop until we run out of reloads */ do { /* loop until we run out of continues */ do { struct RomModule modified_romp = *romp++; int readresult; /* handle flag inheritance */ if (!ROM_INHERITSFLAGS(&modified_romp)) lastflags = modified_romp._flags; else modified_romp._flags = (modified_romp._flags & ~ROM_INHERITEDFLAGS) | lastflags; explength += ROM_GETLENGTH(&modified_romp); /* attempt to read using the modified entry */ readresult = read_rom_data(romdata, &modified_romp); if (readresult == -1) goto fatalerror; } while (ROMENTRY_ISCONTINUE(romp)); /* if this was the first use of this file, verify the length and CRC */ if (baserom) { debugload("Verifying length (%X) and checksums\n", explength); verify_length_and_hash(romdata, ROM_GETNAME(baserom), explength, ROM_GETHASHDATA(baserom)); debugload("Verify finished\n"); } /* reseek to the start and clear the baserom so we don't reverify */ if (romdata->file) mame_fseek(romdata->file, 0, SEEK_SET); baserom = NULL; explength = 0; } while (ROMENTRY_ISRELOAD(romp)); /* close the file */ if (romdata->file) { debugload("Closing ROM file\n"); mame_fclose(romdata->file); romdata->file = NULL; } } else { romp++; /* skip over file */ } } } return 1; /* error case */ fatalerror: if (romdata->file) mame_fclose(romdata->file); romdata->file = NULL; return 0; }
UINT32 audit_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer) { mame_fseek((mame_file *)file, offset, SEEK_SET); return mame_fread((mame_file *)file, buffer, count); }
static int image_load_internal(mess_image *img, const char *name, int is_create, int create_format, option_resolution *create_args) { const struct IODevice *dev; const char *s; char *newname; int err = INIT_PASS; mame_file *file = NULL; UINT8 *buffer = NULL; UINT64 size; unsigned int readable, writeable, creatable; /* unload if we are loaded */ if (img->status & IMAGE_STATUS_ISLOADED) image_unload(img); /* clear out the error */ image_clear_error(img); /* if we are attempting to "load" NULL, then exit at this point */ if (!name) return INIT_PASS; dev = image_device(img); assert(dev); img->status |= IMAGE_STATUS_ISLOADING; if (name && *name) { newname = image_strdup(img, name); if (!newname) { err = IMAGE_ERROR_OUTOFMEMORY; goto error; } } else newname = NULL; img->name = newname; img->dir = NULL; osd_image_load_status_changed(img, 0); /* do we need to reset the CPU? */ if ((timer_get_time() > 0) && dev->reset_on_load) machine_reset(); /* prepare to open the file */ img->created = 0; img->writeable = 0; file = NULL; if (dev->getdispositions) { dev->getdispositions(dev, image_index_in_device(img), &readable, &writeable, &creatable); } else { readable = dev->readable; writeable = dev->writeable; creatable = dev->creatable; } /* is this a ZIP file? */ s = strrchr(img->name, '.'); if (s && !mame_stricmp(s, ".ZIP")) { /* ZIP files are writeable */ writeable = 0; creatable = 0; } if (readable && !writeable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ); } else if (!readable && writeable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_WRITE); img->writeable = file ? 1 : 0; } else if (readable && writeable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW); img->writeable = file ? 1 : 0; if (!file) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ); if (!file && creatable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW_CREATE); img->writeable = file ? 1 : 0; img->created = file ? 1 : 0; } } } /* did this attempt succeed? */ if (!file) { img->err = IMAGE_ERROR_FILENOTFOUND; goto error; } /* if applicable, call device verify */ if (dev->imgverify && !image_has_been_created(img)) { size = mame_fsize(file); buffer = malloc(size); if (!buffer) { img->err = IMAGE_ERROR_OUTOFMEMORY; goto error; } if (mame_fread(file, buffer, (UINT32) size) != size) { img->err = IMAGE_ERROR_INVALIDIMAGE; goto error; } err = dev->imgverify(buffer, size); if (err) { img->err = IMAGE_ERROR_INVALIDIMAGE; goto error; } mame_fseek(file, 0, SEEK_SET); free(buffer); buffer = NULL; } /* call device load or create */ if (image_has_been_created(img) && dev->create) { err = dev->create(img, file, create_format, create_args); if (err) { if (!img->err) img->err = IMAGE_ERROR_UNSPECIFIED; goto error; } } else if (dev->load) { /* using device load */ err = dev->load(img, file); if (err) { if (!img->err) img->err = IMAGE_ERROR_UNSPECIFIED; goto error; } } img->status &= ~IMAGE_STATUS_ISLOADING; img->status |= IMAGE_STATUS_ISLOADED; return INIT_PASS; error: if (file) mame_fclose(file); if (buffer) free(buffer); if (img) { img->fp = NULL; img->name = NULL; img->status &= ~IMAGE_STATUS_ISLOADING|IMAGE_STATUS_ISLOADED; } osd_image_load_status_changed(img, 0); return INIT_FAIL; }