int gbcLoadStateFromBuffer(const signed char * data) { loadstate_from_buffer(data); vram_dirty(); pal_dirty(); sound_dirty(); mem_updatemap(); return 1; }
int gbcLoadState(const char* filename) { loadstate(filename); vram_dirty(); pal_dirty(); sound_dirty(); mem_updatemap(); return 1; }
void state_load(int n) { FILE *f; char *name; if (n < 0) n = saveslot; if (n < 0) n = 0; name = malloc(strlen(saveprefix) + 5); sprintf(name, "%s.%03d", saveprefix, n); if ((f = fopen(name, "rb"))) { loadstate(f); fclose(f); vram_dirty(); pal_dirty(); sound_dirty(); mem_updatemap(); } free(name); }
void loadstate(int fd) { int i, j; byte buf[4096]; un32 (*header)[2] = (un32 (*)[2])buf; un32 d; int irl = hw.cgb ? 8 : 2; int vrl = hw.cgb ? 4 : 2; int srl = mbc.ramsize << 1; size_t base_offset; ver = hramofs = hiofs = palofs = oamofs = wavofs = 0; base_offset = lseek(fd, 0, SEEK_CUR); read(fd,buf, 4096); for (j = 0; header[j][0]; j++) { for (i = 0; svars[i].ptr; i++) { if (header[j][0] != svars[i].k.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 (wavofs) memcpy(ram.hi+48, buf+wavofs, 16); 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); lseek(fd, base_offset + (iramblock << 12), SEEK_SET); read(fd,ram.ibank, 4096*irl); lseek(fd, base_offset + (vramblock << 12), SEEK_SET); read(fd,lcd.vbank, 4096*vrl); lseek(fd, base_offset + (sramblock << 12), SEEK_SET); read(fd,ram.sbank, 4096*srl); vram_dirty(); pal_dirty(); sound_dirty(); mem_updatemap(); }
int menu_state(int save){ char **statebody=NULL; char* name; int i, flags,ret, del=0,l; #ifndef OHBOY_FILE_STAT_NOT_AVAILABLE /* Not all platforms implement stat()/fstat() */ struct stat fstat; time_t time; char *tstr; #endif char *savedir; char *savename; char *saveprefix; FILE *f; int sizeof_slots=0; while (slots[sizeof_slots] != NULL) sizeof_slots++; statebody = malloc(sizeof_slots * sizeof(char*)); /* FIXME check for NULL return from malloc */ savedir = rc_getstr("savedir"); savename = rc_getstr("savename"); saveprefix = malloc(strlen(savedir) + strlen(savename) + 2); sprintf(saveprefix, "%s%s%s", savedir, DIRSEP, savename); dialog_begin(save?"Save State":"Load State",rom.name); for(i=0; i<sizeof_slots; i++){ name = malloc(strlen(saveprefix) + 5); sprintf(name, "%s.%03d", saveprefix, i); #ifndef OHBOY_FILE_STAT_NOT_AVAILABLE /* if the file exists lookup the timestamp */ if(!stat(name,&fstat)){ time = fstat.st_mtime; tstr = ctime(&time); l = strlen(tstr); statebody[i] = malloc(l); strcpy(statebody[i],tstr); statebody[i][l-1]=0; #else /* check if the file exists */ if(f=fopen(name,"rb")){ fclose(f); statebody[i] = (char*)not_emptyslot; #endif /* OHBOY_FILE_STAT_NOT_AVAILABLE */ flags = FIELD_SELECTABLE; } else { statebody[i] = (char*)emptyslot; flags = save ? FIELD_SELECTABLE : 0; } dialog_text(slots[i],statebody[i],flags); free(name); } if(ret=dialog_end()){ name = malloc(strlen(saveprefix) + 5); sprintf(name, "%s.%03d", saveprefix, ret-1); if(save){ if(f=fopen(name,"wb")){ savestate(f); fclose(f); } }else{ if(f=fopen(name,"rb")){ loadstate(f); fclose(f); vram_dirty(); pal_dirty(); sound_dirty(); mem_updatemap(); } } free(name); } for(i=0; i<sizeof_slots; i++) if(statebody[i] != emptyslot && statebody[i] != not_emptyslot) free(statebody[i]); free(saveprefix); return ret; } #define GBPAL_COUNT 27 struct pal_s{ char name[16]; unsigned int dmg_bgp[4]; unsigned int dmg_wndp[4]; unsigned int dmg_obp0[4]; unsigned int dmg_obp1[4]; }gbpal[GBPAL_COUNT] = { { .name = "Default", .dmg_bgp = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C}, .dmg_wndp = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C}, .dmg_obp0 = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C}, .dmg_obp1 = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C} },{//Grey Palette .name = "Grey", .dmg_bgp = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //BG .dmg_wndp = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //WIN .dmg_obp0 = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //OB0 .dmg_obp1 = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 } //OB1 },{//Realistic Palette .name = "DMG",