hash_collection &emu_file::hashes(const char *types) { // determine which hashes we need astring needed; for (const char *scan = types; *scan != 0; scan++) if (m_hashes.hash(*scan) == NULL) needed.cat(*scan); // if we need nothing, skip it if (!needed) return m_hashes; // load the ZIP file if needed if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE) return m_hashes; if (m_file == NULL) return m_hashes; // if we have ZIP data, just hash that directly if (m_zipdata != NULL) { m_hashes.compute(m_zipdata, m_ziplength, needed); return m_hashes; } // read the data if we can const UINT8 *filedata = (const UINT8 *)core_fbuffer(m_file); if (filedata == NULL) return m_hashes; // compute the hash m_hashes.compute(filedata, core_fsize(m_file), needed); return m_hashes; }
void sega8_cart_slot_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "rom"; UINT32 len = core_fsize(m_file), offset = 0; dynamic_buffer rom(len); int type; core_fread(m_file, &rom[0], len); if ((len % 0x4000) == 512) offset = 512; type = get_cart_type(&rom[offset], len - offset); slot_string = sega8_get_slot(type); //printf("type: %s\n", slot_string); clear(); result.assign(slot_string); return; } software_get_default_slot(result, "rom"); }
void apf_cart_slot_device::get_default_card_software(astring &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "std"; UINT32 size = core_fsize(m_file); int type = APF_STD; // attempt to identify Space Destroyer, which needs 1K of additional RAM if (size == 0x1800) type = APF_SPACEDST; if (size > 0x2000) type = APF_BASIC; slot_string = apf_get_slot(type); //printf("type: %s\n", slot_string); clear(); result.cpy(slot_string); return; } software_get_default_slot(result, "std"); }
void vc4000_cart_slot_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "std"; UINT32 size = core_fsize(m_file); int type = VC4000_STD; // attempt to identify the non-standard types if (size > 0x1000) // 6k rom + 1k ram - Chess2 only type = VC4000_CHESS2; else if (size > 0x0800) // some 4k roms have 1k of mirrored ram type = VC4000_RAM1K; slot_string = vc4000_get_slot(type); //printf("type: %s\n", slot_string); clear(); result.assign(slot_string); return; } software_get_default_slot(result, "std"); }
void a5200_cart_slot_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "a5200"; dynamic_buffer head(0x10); UINT32 len = core_fsize(m_file); int type = A5200_8K; // check whether there is an header, to identify the cart type if ((len % 0x1000) == 0x10) { core_fread(m_file, &head[0], 0x10); type = identify_cart_type(&head[0]); std::string info; if (hashfile_extrainfo(*this, info) && info.compare("A13MIRRORING")==0) type = A5200_16K_2CHIPS; } if (type < A5200_4K) osd_printf_info("This game is not designed for A5200. You might want to run it in A800 or A800XL.\n"); slot_string = a800_get_slot(type); clear(); result.assign(slot_string); } else software_get_default_slot(result, "a5200"); }
void a800_cart_slot_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "a800_8k"; dynamic_buffer head(0x10); UINT32 len = core_fsize(m_file); int type = A800_8K; // check whether there is an header, to identify the cart type if ((len % 0x1000) == 0x10) { core_fread(m_file, &head[0], 0x10); type = identify_cart_type(&head[0]); } else // otherwise try to guess based on size { if (len == 0x4000) type = A800_16K; if (len == 0x2000) type = A800_8K; } if (type >= A5200_4K) osd_printf_info("This game is not designed for A800. You might want to run it in A5200.\n"); slot_string = a800_get_slot(type); clear(); result.assign(slot_string); } else software_get_default_slot(result, "a800_8k"); }
void xegs_cart_slot_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "xegs"; dynamic_buffer head(0x10); UINT32 len = core_fsize(m_file); int type = A800_8K; // check whether there is an header, to identify the cart type if ((len % 0x1000) == 0x10) { core_fread(m_file, &head[0], 0x10); type = identify_cart_type(&head[0]); } if (type != A800_XEGS) { osd_printf_info("This game is not designed for XEGS. "); if (type >= A5200_4K) osd_printf_info("You might want to run it in A5200.\n"); else osd_printf_info("You might want to run it in A800 or A800XL.\n"); } slot_string = a800_get_slot(type); clear(); result.assign(slot_string); } else software_get_default_slot(result, "xegs"); }
file_error core_fload(const char *filename, dynamic_buffer &data) { core_file *file = NULL; file_error err; UINT64 size; /* attempt to open the file */ err = core_fopen(filename, OPEN_FLAG_READ, &file); if (err != FILERR_NONE) return err; /* get the size */ size = core_fsize(file); if ((UINT32)size != size) { core_fclose(file); return FILERR_OUT_OF_MEMORY; } /* allocate memory */ data.resize(size); /* read the data */ if (core_fread(file, &data[0], size) != size) { core_fclose(file); data.clear(); return FILERR_FAILURE; } /* close the file and return data */ core_fclose(file); return FILERR_NONE; }
std::string vectrex_cart_slot_device::get_default_card_software() { if (open_image_file(mconfig().options())) { const char *slot_string; UINT32 size = core_fsize(m_file); dynamic_buffer rom(size); int type = VECTREX_STD; core_fread(m_file, &rom[0], size); if (!memcmp(&rom[0x06], "SRAM", 4)) type = VECTREX_SRAM; if (size > 0x8000) type = VECTREX_64K; slot_string = vectrex_get_slot(type); //printf("type: %s\n", slot_string); clear(); return std::string(slot_string); } return software_get_default_slot("vec_rom"); }
const char * sega8_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) { if (open_image_file(options)) { const char *slot_string = "rom"; UINT32 len = core_fsize(m_file), offset = 0; UINT8 *ROM = global_alloc_array(UINT8, len); int type; core_fread(m_file, ROM, len); if ((len % 0x4000) == 512) offset = 512; type = get_cart_type(ROM + offset, len - offset); slot_string = sega8_get_slot(type); //printf("type: %s\n", slot_string); global_free(ROM); clear(); return slot_string; } return software_get_default_slot(config, options, this, "rom"); }
void CDI_init (FILE *fsource, image_s *image, char *fsourcename) { image->length = core_fsize(fsource); if (image->length < 8) printf( "Image file is too short"); fseek(fsource, image->length-8, SEEK_SET); fread(&image->version, 4, 1, fsource); fread(&image->header_offset, 4, 1, fsource); if (image->header_offset == 0) printf( "Bad image format"); }
UINT64 emu_file::size() { // use the ZIP length if present if (m_zipfile != NULL) return m_ziplength; // return length if we can if (m_file != NULL) return core_fsize(m_file); return 0; }
hash_collection &emu_file::hashes(const char *types) { // determine the hashes we already have std::string already_have; m_hashes.hash_types(already_have); // determine which hashes we need std::string needed; for (const char *scan = types; *scan != 0; scan++) if (already_have.find_first_of(*scan) == -1) needed.push_back(*scan); // if we need nothing, skip it if (needed.empty()) return m_hashes; // load the ZIP file if needed if (compressed_file_ready()) return m_hashes; if (m_file == nullptr) return m_hashes; // if we have ZIP data, just hash that directly if (!m__7zdata.empty()) { m_hashes.compute(&m__7zdata[0], m__7zdata.size(), needed.c_str()); return m_hashes; } if (!m_zipdata.empty()) { m_hashes.compute(&m_zipdata[0], m_zipdata.size(), needed.c_str()); return m_hashes; } // read the data if we can const UINT8 *filedata = (const UINT8 *)core_fbuffer(m_file); if (filedata == nullptr) return m_hashes; // compute the hash m_hashes.compute(filedata, core_fsize(m_file), needed.c_str()); return m_hashes; }
hash_collection &emu_file::hashes(const char *types) { // determine the hashes we already have astring already_have; m_hashes.hash_types(already_have); // determine which hashes we need astring needed; for (const char *scan = types; *scan != 0; scan++) if (already_have.chr(0, *scan) == -1) needed.cat(*scan); // if we need nothing, skip it if (!needed) return m_hashes; // load the ZIP file if needed if (compressed_file_ready()) return m_hashes; if (m_file == NULL) return m_hashes; // if we have ZIP data, just hash that directly if (m__7zdata.count() != 0) { m_hashes.compute(m__7zdata, m__7zdata.count(), needed); return m_hashes; } if (m_zipdata.count() != 0) { m_hashes.compute(m_zipdata, m_zipdata.count(), needed); return m_hashes; } // read the data if we can const UINT8 *filedata = (const UINT8 *)core_fbuffer(m_file); if (filedata == NULL) return m_hashes; // compute the hash m_hashes.compute(filedata, core_fsize(m_file), needed); return m_hashes; }
void crvision_cart_slot_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string; UINT32 size = core_fsize(m_file); int type = CRV_4K; switch (size) { case 0x4800: type = CRV_18K; break; case 0x4000: type = CRV_16K; break; case 0x3000: type = CRV_12K; break; case 0x2800: type = CRV_10K; break; case 0x2000: type = CRV_8K; break; case 0x1800: type = CRV_6K; break; case 0x1000: default: break; } slot_string = crvision_get_slot(type); //printf("type: %s\n", slot_string); clear(); result.assign(slot_string); return; } software_get_default_slot(result, "crv_rom4k"); }
void vcs_cart_slot_device::get_default_card_software(astring &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "a26_4k"; UINT32 len = core_fsize(m_file); dynamic_buffer rom(len); int type; core_fread(m_file, rom, len); type = identify_cart_type(rom, len); slot_string = vcs_get_slot(type); clear(); result.cpy(slot_string); } else software_get_default_slot(result, "a26_4k"); }
std::string scv_cart_slot_device::get_default_card_software() { if (open_image_file(mconfig().options())) { const char *slot_string; UINT32 len = core_fsize(m_file); dynamic_buffer rom(len); int type; core_fread(m_file, &rom[0], len); type = get_cart_type(&rom[0], len); slot_string = scv_get_slot(type); //printf("type: %s\n", slot_string); clear(); return std::string(slot_string); } return software_get_default_slot("rom8k"); }
bool CDI_init (FILE *fsource, image_s *image, const char *fsourcename) { image->length = core_fsize(fsource); if (image->length < 8) { printf("%s: Image file is too short\n", fsourcename); return false; } fseek(fsource, image->length-8, SEEK_SET); fread(&image->version, 4, 1, fsource); fread(&image->header_offset, 4, 1, fsource); if ((image->version != CDI_V2 && image->version != CDI_V3 && image->version != CDI_V35) || image->header_offset == 0) { printf("%s: Bad image format\n", fsourcename); return false; } return true; }
std::string channelf_cart_slot_device::get_default_card_software() { if (open_image_file(mconfig().options())) { const char *slot_string; UINT32 len = core_fsize(m_file); int type; if (len == 0x40000) type = CF_MULTI; else type = CF_CHESS; // is there any way to detect the other carts from fullpath? slot_string = chanf_get_slot(type); //printf("type: %s\n", slot_string); clear(); return std::string(slot_string); } return software_get_default_slot("chess"); }
std::string o2_cart_slot_device::get_default_card_software() { if (open_image_file(mconfig().options())) { const char *slot_string; UINT32 size = core_fsize(m_file); int type = O2_STD; if (size == 12288) type = O2_ROM12; if (size == 16384) type = O2_ROM16; slot_string = o2_get_slot(type); //printf("type: %s\n", slot_string); clear(); return std::string(slot_string); } return software_get_default_slot("o2_rom"); }
void gba_cart_slot_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "gba_rom"; UINT32 len = core_fsize(m_file); dynamic_buffer rom(len); int type; core_fread(m_file, &rom[0], len); type = get_cart_type(&rom[0], len); slot_string = gba_get_slot(type); //printf("type: %s\n", slot_string); clear(); result.assign(slot_string); return; } software_get_default_slot(result, "gba_rom"); }
const char * gba_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) { if (open_image_file(options)) { const char *slot_string = "gba_rom"; UINT32 len = core_fsize(m_file); UINT8 *ROM = global_alloc_array(UINT8, len); int type; core_fread(m_file, ROM, len); type = get_cart_type(ROM, len); slot_string = gba_get_slot(type); //printf("type: %s\n", slot_string); global_free(ROM); clear(); return slot_string; } return software_get_default_slot(config, options, this, "gba_rom"); }
std::string astrocade_cart_slot_device::get_default_card_software() { if (open_image_file(mconfig().options())) { const char *slot_string; UINT32 size = core_fsize(m_file); int type = ASTROCADE_STD; if (size == 0x40000) type = ASTROCADE_256K; if (size == 0x80000) type = ASTROCADE_512K; slot_string = astrocade_get_slot(type); //printf("type: %s\n", slot_string); clear(); return std::string(slot_string); } return software_get_default_slot("rom"); }
file_error core_fload(const char *filename, void **data, UINT32 *length) { core_file *file = NULL; file_error err; UINT64 size; /* attempt to open the file */ err = core_fopen(filename, OPEN_FLAG_READ, &file); if (err != FILERR_NONE) return err; /* get the size */ size = core_fsize(file); if ((UINT32)size != size) { core_fclose(file); return FILERR_OUT_OF_MEMORY; } /* allocate memory */ *data = osd_malloc(size); if (length != NULL) *length = (UINT32)size; /* read the data */ if (core_fread(file, *data, size) != size) { core_fclose(file); free(*data); return FILERR_FAILURE; } /* close the file and return data */ core_fclose(file); return FILERR_NONE; }
void msx_slot_cartridge_device::get_default_card_software(std::string &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "nomapper"; UINT32 length = core_fsize(m_file); dynamic_buffer rom(length); int type = NOMAPPER; // Check if there's some mapper related information in the hashfiles std::string extrainfo; if (hashfile_extrainfo(*this, extrainfo)) { int extrainfo_type = -1; if (1 == sscanf(extrainfo.c_str(), "%d", &extrainfo_type)) { static const struct { int extrainfo; int mapper; } extrainfo_map[] = { //{ 0, NOMAPPER }, { 1, MSXDOS2 }, { 2, KONAMI_SCC }, { 3, KONAMI }, { 4, ASCII8 }, { 5, ASCII16 }, { 6, GAMEMASTER2 }, { 7, ASCII8_SRAM }, { 8, ASCII16_SRAM }, { 9, RTYPE }, { 10, MAJUTSUSHI }, { 11, FMPAC }, { 12, SUPERLODERUNNER }, { 13, SYNTHESIZER }, { 14, CROSSBLAIM }, { 15, DISK_ROM }, { 16, KOREAN_80IN1 }, { 17, KOREAN_126IN1 } }; for (int i = 0; i < ARRAY_LENGTH(extrainfo_map); i++) { if (extrainfo_map[i].extrainfo == extrainfo_type) { type = extrainfo_map[i].mapper; } } } } if (type == NOMAPPER) { // Not identified through hashfile, try automatic detection type = get_cart_type(&rom[0], length); } if (type > NOMAPPER) { slot_string = msx_cart_get_slot_option(type); } result.assign(slot_string); return; } software_get_default_slot(result, "nomapper"); }
void a78_cart_slot_device::get_default_card_software(astring &result) { if (open_image_file(mconfig().options())) { const char *slot_string = "a78_rom"; dynamic_buffer head(128); int type = A78_TYPE0, mapper; // Load and check the header core_fread(m_file, head, 128); // let's try to auto-fix some common errors in the header mapper = validate_header((head[53] << 8) | head[54], FALSE); switch (mapper & 0x2e) { case 0x0000: type = BIT(mapper, 0) ? A78_TYPE1 : A78_TYPE0; break; case 0x0002: type = BIT(mapper, 0) ? A78_TYPE3 : A78_TYPE2; break; case 0x0006: type = A78_TYPE6; break; case 0x000a: type = A78_TYPEA; break; case 0x0022: case 0x0026: if (core_fsize(m_file) > 0x40000) type = A78_MEGACART; else type = A78_VERSABOARD; break; } // check if cart has a POKEY at $0450 (typically a VersaBoard variant)! if (mapper & 0x40) { if (type != A78_TYPE2) { type &= ~0x02; type += A78_POKEY0450; } } // check special bits, which override the previous if ((mapper & 0xff00) == 0x0100) type = A78_ACTIVISION; else if ((mapper & 0xff00) == 0x0200) type = A78_ABSOLUTE; logerror("Cart type: %x\n", type); slot_string = a78_get_slot(type); clear(); result.cpy(slot_string); } else software_get_default_slot(result, "a78_rom"); }
Disc* load_gdi(const char* file) { u32 iso_tc; Disc* disc = new Disc(); //memset(&gdi_toc,0xFFFFFFFF,sizeof(gdi_toc)); //memset(&gdi_ses,0xFFFFFFFF,sizeof(gdi_ses)); core_file* t=core_fopen(file); if (!t) return 0; size_t gdi_len = core_fsize(t); char gdi_data[8193] = { 0 }; if (gdi_len >= sizeof(gdi_data)) { core_fclose(t); return 0; } core_fread(t, gdi_data, gdi_len); core_fclose(t); istringstream gdi(gdi_data); gdi >> iso_tc; printf("\nGDI : %d tracks\n",iso_tc); char path[512]; strcpy(path,file); size_t len=strlen(file); while (len>2) { if (path[len]=='\\' || path[len]=='/') break; len--; } len++; char* pathptr=&path[len]; u32 TRACK=0,FADS=0,CTRL=0,SSIZE=0; s32 OFFSET=0; for (u32 i=0;i<iso_tc;i++) { string track_filename; //TRACK FADS CTRL SSIZE file OFFSET gdi >> TRACK; gdi >> FADS; gdi >> CTRL; gdi >> SSIZE; char last; do { gdi >> last; } while (isspace(last)); if (last == '"') { gdi >> std::noskipws; for(;;) { gdi >> last; if (last == '"') break; track_filename += last; } gdi >> std::skipws; } else {
static bool render_font_save_cached(render_font &font, const char *filename, UINT32 hash) { // attempt to open the file core_file *file; file_error filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file); if (filerr != FILERR_NONE) return true; core_file *tmp_file; astring tmp_filename(filename, ".tmp"); filerr = core_fopen(tmp_filename.cstr(), OPEN_FLAG_WRITE | OPEN_FLAG_READ, &tmp_file); if (filerr != FILERR_NONE) return true; core_fseek(tmp_file, 0, SEEK_END); try { // determine the number of characters int numchars = 0; for (int chnum = 0; chnum < 65536; chnum++) if (font.chars[chnum].width > 0) numchars++; total_numchars += numchars; // write the header dynamic_buffer tempbuffer(65536); UINT8 *dest = &tempbuffer[0]; *dest++ = 'f'; *dest++ = 'o'; *dest++ = 'n'; *dest++ = 't'; *dest++ = hash >> 24; *dest++ = hash >> 16; *dest++ = hash >> 8; *dest++ = hash & 0xff; *dest++ = font.height >> 8; *dest++ = font.height & 0xff; *dest++ = font.yoffs >> 8; *dest++ = font.yoffs & 0xff; *dest++ = total_numchars >> 24; *dest++ = total_numchars >> 16; *dest++ = total_numchars >> 8; *dest++ = total_numchars & 0xff; write_data(*file, tempbuffer, dest); // write the empty table to the beginning of the file //m_chartable.resize_keep(total_numchars * CACHED_CHAR_SIZE + 1); //write_data(*file, &m_chartable[0], &m_chartable[total_numchars * CACHED_CHAR_SIZE]); // loop over all characters int tableindex = total_numchars - numchars; for (int chnum = 0; chnum < 65536; chnum++) { render_font_char &ch = font.chars[chnum]; if (ch.width > 0) { // write out a bit-compressed bitmap if we have one if (ch.bitmap != NULL) { // write the data to the tempbuffer dest = tempbuffer; UINT8 accum = 0; UINT8 accbit = 7; // bit-encode the character data for (int y = 0; y < ch.bmheight; y++) { int desty = y + font.height + font.yoffs - ch.yoffs - ch.bmheight; const UINT32 *src = (desty >= 0 && desty < font.height) ? &ch.bitmap->pix32(desty) : NULL; for (int x = 0; x < ch.bmwidth; x++) { if (src != NULL && src[x] != 0) accum |= 1 << accbit; if (accbit-- == 0) { *dest++ = accum; accum = 0; accbit = 7; } } } // flush any extra if (accbit != 7) *dest++ = accum; // write the data write_data(*tmp_file, tempbuffer, dest); // free the bitmap and texture global_free(ch.bitmap); ch.bitmap = NULL; } // compute the table entry dest = &m_chartable[tableindex++ * CACHED_CHAR_SIZE]; *dest++ = chnum >> 8; *dest++ = chnum & 0xff; *dest++ = ch.width >> 8; *dest++ = ch.width & 0xff; *dest++ = ch.xoffs >> 8; *dest++ = ch.xoffs & 0xff; *dest++ = ch.yoffs >> 8; *dest++ = ch.yoffs & 0xff; *dest++ = ch.bmwidth >> 8; *dest++ = ch.bmwidth & 0xff; *dest++ = ch.bmheight >> 8; *dest++ = ch.bmheight & 0xff; ch.width = 0; } } // seek back to the beginning and rewrite the table core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET); write_data(*file, &m_chartable[0], &m_chartable[total_numchars * CACHED_CHAR_SIZE]); // mamep:copy from temporary file UINT32 filesize = (UINT32)core_fsize(tmp_file); tempbuffer.resize(filesize); tempbuffer.clear(); core_fseek(tmp_file, 0, SEEK_SET); core_fread(tmp_file, tempbuffer, filesize); core_fwrite(file, tempbuffer, filesize); // all done core_fclose(file); core_fclose(tmp_file); return false; } catch (...) { core_fclose(file); core_fclose(tmp_file); osd_rmfile(filename); osd_rmfile(tmp_filename.cstr()); return true; } }
imgtool_stream *stream_open(const char *fname, int read_or_write) { file_error filerr; const char *ext; imgtool_stream *imgfile = NULL; static const UINT32 write_modes[] = { OPEN_FLAG_READ, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, OPEN_FLAG_READ | OPEN_FLAG_WRITE, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE }; core_file *f = NULL; char *buf = NULL; int len, i; imgtool_stream *s = NULL; char c; /* maybe we are just a ZIP? */ ext = strrchr(fname, '.'); if (ext && !mame_stricmp(ext, ".zip")) return stream_open_zip(fname, NULL, read_or_write); filerr = core_fopen(fname, write_modes[read_or_write], &f); if (filerr != FILERR_NONE) { if (!read_or_write) { len = strlen(fname); /* can't open the file; try opening ZIP files with other names */ buf = (char*)malloc(len + 1); if (!buf) goto error; strcpy(buf, fname); for(i = len-1; !s && (i >= 0); i--) { if ((buf[i] == '\\') || (buf[i] == '/')) { c = buf[i]; buf[i] = '\0'; s = stream_open_zip(buf, buf + i + 1, read_or_write); buf[i] = c; } } free(buf); buf = NULL; if (s) return s; } /* ah well, it was worth a shot */ goto error; } imgfile = (imgtool_stream *)malloc(sizeof(struct _imgtool_stream)); if (!imgfile) goto error; /* Normal file */ memset(imgfile, 0, sizeof(*imgfile)); imgfile->imgtype = IMG_FILE; imgfile->position = 0; imgfile->filesize = core_fsize(f); imgfile->write_protect = read_or_write ? 0 : 1; imgfile->u.file = f; imgfile->name = fname; return imgfile; error: if (imgfile != NULL) free((void *) imgfile); if (f != NULL) core_fclose(f); if (buf) free(buf); return (imgtool_stream *) NULL; }
void node_testzippath(xml_data_node *node) { xml_attribute_node *attr_node; xml_data_node *first_child_node; xml_data_node *child_node; const char *path; const char *plus; astring *apath = NULL; zippath_directory *directory = NULL; const osd_directory_entry *dirent; const char *type_string; file_error err; UINT64 size; mess_pile pile; core_file *file = NULL; pile_init(&pile); /* name the test case */ report_testcase_begin("zippath"); /* retrieve path */ attr_node = xml_get_attribute(node, "path"); path = (attr_node != NULL) ? attr_node->value : ""; /* retrieve 'plus' - for testing zippath_combine */ attr_node = xml_get_attribute(node, "plus"); if (attr_node != NULL) { plus = attr_node->value; apath = zippath_combine(astring_alloc(), path, plus); report_message(MSG_INFO, "Testing ZIP Path '%s' + '%s' ==> '%s'", path, plus, astring_c(apath)); } else { apath = astring_cpyc(astring_alloc(), path); report_message(MSG_INFO, "Testing ZIP Path '%s'", astring_c(apath)); } /* try doing a file compare */ messtest_get_data(node, &pile); if (pile_size(&pile) > 0) { err = zippath_fopen(astring_c(apath), OPEN_FLAG_READ, &file, NULL); if (err != FILERR_NONE) { report_message(MSG_FAILURE, "Error %d opening file", (int) err); goto done; } if (pile_size(&pile) != core_fsize(file)) { report_message(MSG_FAILURE, "Expected file to be of length %d, instead got %d", (int) pile_size(&pile), (int) core_fsize(file)); goto done; } if (memcmp(pile_getptr(&pile), core_fbuffer(file), pile_size(&pile))) { report_message(MSG_FAILURE, "File sizes match, but contents do not"); goto done; } } /* try doing a directory listing */ first_child_node = xml_get_sibling(node->child, "entry"); if (first_child_node != NULL) { err = zippath_opendir(astring_c(apath), &directory); if (err != FILERR_NONE) { report_message(MSG_FAILURE, "Error %d opening directory", (int) err); goto done; } /* read each directory entry */ while((dirent = zippath_readdir(directory)) != NULL) { /* find it in the list */ for (child_node = first_child_node; child_node != NULL; child_node = xml_get_sibling(child_node->next, "entry")) { attr_node = xml_get_attribute(child_node, "name"); if ((attr_node != NULL) && !strcmp(attr_node->value, dirent->name)) break; } /* did we find the node? */ if (child_node != NULL) { /* check dirent type */ attr_node = xml_get_attribute(child_node, "type"); if (attr_node != NULL) { type_string = dir_entry_type_string(dirent->type); if (mame_stricmp(attr_node->value, type_string)) report_message(MSG_FAILURE, "Expected '%s' to be '%s', but instead got '%s'", dirent->name, attr_node->value, type_string); } /* check size */ attr_node = xml_get_attribute(child_node, "size"); if (attr_node != NULL) { size = atoi(attr_node->value); if (size != dirent->size) report_message(MSG_FAILURE, "Expected '%s' to be of size '%ld', but instead got '%ld'", dirent->name, (long) size, (long) dirent->size); } } else { report_message(MSG_FAILURE, "Unexpected directory entry '%s'", dirent->name); } } } done: pile_delete(&pile); if (apath != NULL) astring_free(apath); if (file != NULL) core_fclose(file); if (directory != NULL) zippath_closedir(directory); }