+static uint8 *real_pages[16];
+
+void GenieSetPages(int restore)
+{
+ int page;
+ if (restore)
+ {
+ for (page=16; page<32; page++)
+ Page[page] = real_pages[page-16];
+ }
+ else
+ {
+ for (page=16; page<32; page++) {
+ real_pages[page-16] = Page[page];
+ Page[page]=GENIEROM - (page<<11) + ((page&1)<<11);
+ }
+ }
+}
+
+void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
+{
+ if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
+ {
+ FILE *sp;
+ char *soot;
+
+ soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
+ if((sp=FCEUD_UTF8fopen(soot,"wb"))==NULL)
+ {
+ FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot);
+ }
+ else
+ {
+ int x;
+
+ for(x=0;x<4;x++)
+ if(LocalHWInfo->SaveGame[x])
+ {
+ fwrite(LocalHWInfo->SaveGame[x],1,
+ LocalHWInfo->SaveGameLen[x],sp);
+ }
+ }
+ free(soot);
+ }
+}
+
+// hack, movie.c has to communicate with this function somehow
+int disableBatteryLoading=0;
+
+void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
+{
+ if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading)
+ {
+ FILE *sp;
+ char *soot;
+
+ soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
+ sp=FCEUD_UTF8fopen(soot,"rb");
+ if(sp!=NULL)
+ {
+ int x;
+ for(x=0;x<4;x++)
+ if(LocalHWInfo->SaveGame[x])
+ fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp);
+ }
+ free(soot);
+ }
+}
+
+void DumpEmptyCartMapping(void)
+{
+ int x, st=0, end=-1;
+
+ for(x=8;x<32;x++)
+ {
+ if (Page[x] == (nothing-x*2048) || Page[x] == 0)
+ {
+ if (end != x) st=x;
+ end=x+1;
+ }
+ if (end == x)
+ printf("DumpEmptyCartMapping: %04x-%04x\n", st*2048, end*2048-1);
+ }
+ if (end==32)
+ printf("DumpEmptyCartMapping: %04x-%04x\n", st*2048, end*2048-1);
+}
+