int load_rom(char *filename) { int size, offset = 0; uint8 header[0x200]; uint8 *ptr; ptr = load_archive(filename, &size); if(!ptr) return (0); int rom_size = size; if((size / 512) & 1) { int i; size -= 512; offset += 512; memcpy(header, ptr, 512); for(i = 0; i < (size / 0x4000); i += 1) { deinterleave_block(ptr + offset + (i * 0x4000)); } } memset(cart_rom, 0, 0x400000); if(size > 0x400000) size = 0x400000; memcpy(cart_rom, ptr + offset, size); /* Free allocated file data */ free(ptr); /* Byteswap the ROM */ // bswap(cart_rom, 0x400000); /* Load SRAM */ //sram_init(); return (1); }
static VbError_t load_localized_graphics(uint32_t locale) { char str[256]; /* check whether we've already loaded the archive for this locale */ if (locale_data.archive) { if (locale_data.archive_locale == locale) return VBERROR_SUCCESS; /* No need to keep more than one locale graphics at a time */ free(locale_data.archive); } /* compose archive name using the language code */ snprintf(str, sizeof(str), "locale_%s.bin", locale_data.codes[locale]); RETURN_ON_ERROR(load_archive(str, &locale_data.archive)); /* Remember what's cached */ locale_data.archive_locale = locale; return VBERROR_SUCCESS; }
static long state_unc_open(const char *fname, const char *mode) { //mode = "wb" or "rb" //If mode is write then create a new buffer to hold written data //when file is closed buffer will be compressed to zip file and then freed if(mode[0]=='r') { //Read mode requested if(check_zip((char*)fname)) { //File is a zip, so uncompress mFileZipMode = 1; //zip mode mFileRWMode = 0; mFileMem=load_archive((char*)fname,&mFileMemSize); if(!mFileMem) return 0; mFileMemPos=0; strcpy(mFileName,fname); return 1; } else { mFileZipMode = 0; //normal file mode mFile = fopen(fname, mode); return (long) mFile; } } else { //Write mode requested. Zip only option mFileRWMode = 1; mFileZipMode = 1; //always zip mFileMem=(char*)malloc(200); mFileMemSize=200; mFileMemPos = 0; strcpy(mFileName,fname); return 1; } }
void loadstate(const char *filename) { int i, j; byte *buf;//[4096]; byte *bufptr; //menu_message("Loading"); int irl = hw.cgb ? 8 : 2; int vrl = hw.cgb ? 4 : 2; int srl = mbc.ramsize << 1; int bufsize = (1 + irl + vrl + srl) * 4096; buf=(byte*)malloc(bufsize); bufptr = buf; int n = load_archive(filename, "GBCOID", buf, bufsize); if (n < 0) { FILE *file = fopen(filename, "rb"); if (file != NULL) { n = fread(buf, 1, bufsize, file); fclose(file); } } if (n != bufsize) { free(buf); return; } un32 (*header)[2] = (un32 (*)[2])buf; un32 d; ver = hramofs = hiofs = palofs = oamofs = wavofs = 0; bufptr += 4096; for (j = 0; header[j][0]; j++) { for (i = 0; svars[i].ptr; i++) { if (header[j][0] != *(un32 *)svars[i].key) continue; d = LIL(header[j][1]); switch (svars[i].len) { case 1: *(byte *)svars[i].ptr = d; break; case 2: *(un16 *)svars[i].ptr = d; break; case 4: *(un32 *)svars[i].ptr = d; break; } break; } } /* obsolete as of version 0x104 */ if (hramofs) memcpy(ram.hi+128, buf+hramofs, 127); if (hiofs) memcpy(ram.hi, buf+hiofs, sizeof ram.hi); if (palofs) memcpy(lcd.pal, buf+palofs, sizeof lcd.pal); if (oamofs) memcpy(lcd.oam.mem, buf+oamofs, sizeof lcd.oam); if (wavofs) memcpy(snd.wave, buf+wavofs, sizeof snd.wave); else memcpy(snd.wave, ram.hi+0x30, 16); /* patch data from older files */ //fseek(f, iramblock<<12, SEEK_SET); memcpy(ram.ibank, bufptr, 4096 * irl); bufptr += 4096 * irl; //fseek(f, vramblock<<12, SEEK_SET); memcpy(lcd.vbank, bufptr, 4096 * vrl); bufptr += 4096 * vrl; //fseek(f, sramblock<<12, SEEK_SET); memcpy(ram.sbank, bufptr, 4096 * srl); bufptr += 4096 * srl; free(buf); }