bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size, int *exrom, int *game) { // read the header cbm_crt_header header; core_fread(file, &header, CRT_HEADER_LENGTH); if (memcmp(header.signature, CRT_SIGNATURE, 16) != 0) return false; UINT16 hardware = pick_integer_be(header.hardware, 0, 2); *exrom = header.exrom; *game = header.game; if (LOG) { logerror("Name: %s\n", header.name); logerror("Hardware: %04x\n", hardware); logerror("Slot device: %s\n", CRT_C64_SLOT_NAMES[hardware]); logerror("EXROM: %u\n", header.exrom); logerror("GAME: %u\n", header.game); } // determine ROM region lengths while (!core_feof(file)) { cbm_crt_chip chip; core_fread(file, &chip, CRT_CHIP_LENGTH); UINT16 address = pick_integer_be(chip.start_address, 0, 2); UINT16 size = pick_integer_be(chip.image_size, 0, 2); UINT16 type = pick_integer_be(chip.chip_type, 0, 2); if (LOG) { logerror("CHIP Address: %04x\n", address); logerror("CHIP Size: %04x\n", size); logerror("CHIP Type: %04x\n", type); } switch (address) { case 0x8000: *roml_size += size; break; case 0xa000: *romh_size += size; break; case 0xe000: *romh_size += size; break; default: logerror("Invalid CHIP loading address!\n"); break; } core_fseek(file, size, SEEK_CUR); } return true; }
bool cbm_crt_read_data(core_file* file, UINT8 *roml, UINT8 *romh) { offs_t roml_offset = 0; offs_t romh_offset = 0; core_fseek(file, CRT_HEADER_LENGTH, SEEK_SET); while (!core_feof(file)) { cbm_crt_chip chip; core_fread(file, &chip, CRT_CHIP_LENGTH); UINT16 address = pick_integer_be(chip.start_address, 0, 2); UINT16 size = pick_integer_be(chip.image_size, 0, 2); switch (address) { case 0x8000: core_fread(file, roml + roml_offset, size); roml_offset += size; break; case 0xa000: core_fread(file, romh + romh_offset, size); romh_offset += size; break; case 0xe000: core_fread(file, romh + romh_offset, size); romh_offset += size; break; } } return true; }
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 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 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 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; }
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"); }
UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz) { UINT32 result = 0; switch(stream->imgtype) { case IMG_FILE: assert(sz == (UINT32) sz); core_fseek(stream->u.file, stream->position, SEEK_SET); result = core_fread(stream->u.file, buf, (UINT32) sz); break; case IMG_MEM: /* do we have to limit sz? */ if (sz > (stream->filesize - stream->position)) sz = (UINT32) (stream->filesize - stream->position); memcpy(buf, stream->u.buffer + stream->position, sz); result = sz; break; default: assert(0); break; } stream->position += result; return result; }
UINT32 emu_file::read(void *buffer, UINT32 length) { // load the ZIP file now if we haven't yet if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE) return 0; // read the data if we can if (m_file != NULL) return core_fread(m_file, buffer, length); return 0; }
UINT32 emu_file::read(void *buffer, UINT32 length) { // load the ZIP file now if we haven't yet if (compressed_file_ready()) return 0; // read the data if we can if (m_file != NULL) return core_fread(m_file, buffer, length); return 0; }
const char * cbm_crt_get_card(core_file *file) { // read the header cbm_crt_header header; core_fread(file, &header, CRT_HEADER_LENGTH); if (memcmp(header.signature, CRT_SIGNATURE, 16) == 0) { UINT16 hardware = pick_integer_be(header.hardware, 0, 2); return CRT_C64_SLOT_NAMES[hardware]; } return NULL; }
void cbm_crt_get_card(astring &result, core_file *file) { // read the header cbm_crt_header header; core_fread(file, &header, CRT_HEADER_LENGTH); if (memcmp(header.signature, CRT_SIGNATURE, 16) == 0) { UINT16 hardware = pick_integer_be(header.hardware, 0, 2); result.cpy(CRT_C64_SLOT_NAMES[hardware]); return; } result.reset(); }
xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts) { xml_parse_info parse_info; int done; /* set up the parser */ if (!expat_setup_parser(&parse_info, opts)) return NULL; /* loop through the file and parse it */ do { char tempbuf[TEMP_BUFFER_SIZE]; /* read as much as we can */ int bytes = core_fread(file, tempbuf, sizeof(tempbuf)); done = core_feof(file); /* parse the data */ if (XML_Parse(parse_info.parser, tempbuf, bytes, done) == XML_STATUS_ERROR) { if (opts != NULL && opts->error != NULL) { opts->error->error_message = XML_ErrorString(XML_GetErrorCode(parse_info.parser)); opts->error->error_line = XML_GetCurrentLineNumber(parse_info.parser); opts->error->error_column = XML_GetCurrentColumnNumber(parse_info.parser); } xml_file_free(parse_info.rootnode); XML_ParserFree(parse_info.parser); return NULL; } } while (!done); /* free the parser */ XML_ParserFree(parse_info.parser); /* return the root node */ return parse_info.rootnode; }
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"); }
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"); }
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; }
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; } }
int core_fgetc(core_file *file) { int result; /* refresh buffer, if necessary */ if (file->back_char_head == file->back_char_tail) { utf16_char utf16_buffer[UTF16_CHAR_MAX]; char utf8_buffer[UTF8_CHAR_MAX]; char default_buffer[16]; unicode_char uchar = (unicode_char) ~0; int readlen, charlen; /* do we need to check the byte order marks? */ if (file->offset == 0) { UINT8 bom[4]; int pos = 0; if (core_fread(file, bom, 4) == 4) { if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf) { file->text_type = TFT_UTF8; pos = 3; } else if (bom[0] == 0x00 && bom[1] == 0x00 && bom[2] == 0xfe && bom[3] == 0xff) { file->text_type = TFT_UTF32BE; pos = 4; } else if (bom[0] == 0xff && bom[1] == 0xfe && bom[2] == 0x00 && bom[3] == 0x00) { file->text_type = TFT_UTF32LE; pos = 4; } else if (bom[0] == 0xfe && bom[1] == 0xff) { file->text_type = TFT_UTF16BE; pos = 2; } else if (bom[0] == 0xff && bom[1] == 0xfe) { file->text_type = TFT_UTF16LE; pos = 2; } else { file->text_type = TFT_OSD; pos = 0; } } core_fseek(file, pos, SEEK_SET); } /* fetch the next character */ switch (file->text_type) { default: case TFT_OSD: readlen = core_fread(file, default_buffer, sizeof(default_buffer)); if (readlen > 0) { charlen = osd_uchar_from_osdchar(&uchar, default_buffer, readlen / sizeof(default_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(default_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF8: readlen = core_fread(file, utf8_buffer, sizeof(utf8_buffer)); if (readlen > 0) { charlen = uchar_from_utf8(&uchar, utf8_buffer, readlen / sizeof(utf8_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(utf8_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF16BE: readlen = core_fread(file, utf16_buffer, sizeof(utf16_buffer)); if (readlen > 0) { charlen = uchar_from_utf16be(&uchar, utf16_buffer, readlen / sizeof(utf16_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(utf16_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF16LE: readlen = core_fread(file, utf16_buffer, sizeof(utf16_buffer)); if (readlen > 0) { charlen = uchar_from_utf16le(&uchar, utf16_buffer, readlen / sizeof(utf16_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(utf16_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF32BE: if (core_fread(file, &uchar, sizeof(uchar)) == sizeof(uchar)) uchar = BIG_ENDIANIZE_INT32(uchar); break; case TFT_UTF32LE: if (core_fread(file, &uchar, sizeof(uchar)) == sizeof(uchar)) uchar = LITTLE_ENDIANIZE_INT32(uchar); break; } if (uchar != ~0) { /* place the new character in the ring buffer */ file->back_char_head = 0; file->back_char_tail = utf8_from_uchar(file->back_chars, ARRAY_LENGTH(file->back_chars), uchar); /* assert(file->back_char_tail != -1);*/ } } /* now read from the ring buffer */ if (file->back_char_head != file->back_char_tail) { result = file->back_chars[file->back_char_head++]; file->back_char_head %= ARRAY_LENGTH(file->back_chars); } else result = EOF; return result; }
std::string msx_slot_cartridge_device::get_default_card_software() { 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 (auto & elem : extrainfo_map) { if (elem.extrainfo == extrainfo_type) { type = elem.mapper; } } } } if (type == NOMAPPER) { // Not identified through hashfile, try automatic detection core_fread(m_file, &rom[0], length); type = get_cart_type(&rom[0], length); } if (type > NOMAPPER) { slot_string = msx_cart_get_slot_option(type); } return std::string(slot_string); } return software_get_default_slot("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 size_t corefile_readproc(void *file, void *buffer, size_t length) { return core_fread((core_file*)file, buffer, length); }