savestate and other bugfixes
authornotaz <notasas@gmail.com>
Tue, 5 Jun 2007 19:36:17 +0000 (19:36 +0000)
committernotaz <notasas@gmail.com>
Tue, 5 Jun 2007 19:36:17 +0000 (19:36 +0000)
git-svn-id: file:///home/notaz/opt/svn/fceu@154 be3aeb3a-fb24-0410-a615-afba39da0efa

driver.h
drivers/gp2x/gp2x-sound.c
drivers/gp2x/gp2x-video.c
drivers/gp2x/input.c
drivers/gp2x/main.c
endian.h
fce.c
ncpu.h
out_gp2x/readme.txt
state.c
svga.c

index e240960..1d47e50 100644 (file)
--- a/driver.h
+++ b/driver.h
@@ -165,6 +165,7 @@ void FCEUI_LoadState(void);
 int32 FCEUI_GetDesiredFPS(void);
 void FCEUI_SaveSnapshot(void);
 void FCEU_DispMessage(char *format, ...);
 int32 FCEUI_GetDesiredFPS(void);
 void FCEUI_SaveSnapshot(void);
 void FCEU_DispMessage(char *format, ...);
+void FCEU_CancelDispMessage(void);
 #define FCEUI_DispMessage FCEU_DispMessage
 
 int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type);
 #define FCEUI_DispMessage FCEU_DispMessage
 
 int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type);
index e188873..666aee1 100644 (file)
@@ -29,7 +29,7 @@ extern int soundvol;
 void WriteSound(int16 *Buffer, int Count)
 {
        gp2x_sound_write(Buffer, Count<<1);
 void WriteSound(int16 *Buffer, int Count)
 {
        gp2x_sound_write(Buffer, Count<<1);
-       SpeedThrottle();
+//     SpeedThrottle();
 }
 
 void SilenceSound(int n)
 }
 
 void SilenceSound(int n)
index 9b73e46..198222d 100644 (file)
@@ -99,7 +99,7 @@ int InitVideo(void)
 }
 
 
 }
 
 
-// 16: rrrr rggg gggb bbbb
+// 16: rrrr rggg gg0b bbbb
 void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b)
 {
        /* note: menu depends on bit5 being 0 */
 void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b)
 {
        /* note: menu depends on bit5 being 0 */
@@ -167,8 +167,6 @@ void BlitScreen(uint8 *buf)
 
        framesRendered++;
 
 
        framesRendered++;
 
-       printFps(gp2x_screen);
-
        if (eoptions & EO_CLIPSIDES)
        {
                int i, *p = (int *) ((char *)gp2x_screen + 32);
        if (eoptions & EO_CLIPSIDES)
        {
                int i, *p = (int *) ((char *)gp2x_screen + 32);
@@ -178,6 +176,8 @@ void BlitScreen(uint8 *buf)
                }
        }
 
                }
        }
 
+       printFps(gp2x_screen);
+
        if (Settings.scaling == 3)
        {
                soft_scale((char *)gp2x_screen + 32, gp2x_palette16, srendline, erendline-srendline);
        if (Settings.scaling == 3)
        {
                soft_scale((char *)gp2x_screen + 32, gp2x_palette16, srendline, erendline-srendline);
index 6a51264..c2f88f6 100644 (file)
@@ -88,7 +88,7 @@ static void do_emu_acts(uint32 acts)
                                FCEUD_Update(XBuf+8,NULL,0);
                                while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
                                if (keys & GP2X_X) do_it = 0;
                                FCEUD_Update(XBuf+8,NULL,0);
                                while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
                                if (keys & GP2X_X) do_it = 0;
-                               FCEU_DispMessage("");
+                               FCEU_CancelDispMessage();
                        }
                        if (do_it) FCEUI_LoadState();
                }
                        }
                        if (do_it) FCEUI_LoadState();
                }
@@ -107,7 +107,7 @@ static void do_emu_acts(uint32 acts)
                                        FCEUD_Update(XBuf+8,NULL,0);
                                        while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
                                        if (keys & GP2X_X) do_it = 0;
                                        FCEUD_Update(XBuf+8,NULL,0);
                                        while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
                                        if (keys & GP2X_X) do_it = 0;
-                                       FCEU_DispMessage("");
+                                       FCEU_CancelDispMessage();
                                }
                        }
                        if (do_it) FCEUI_SaveState();
                                }
                        }
                        if (do_it) FCEUI_SaveState();
index cbd8679..ac48a2d 100644 (file)
@@ -466,11 +466,13 @@ static void DriverKill(void)
 
 void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count)
 {
 
 void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count)
 {
- if(!Count && !(eoptions&EO_NOTHROTTLE))
+ if(!(eoptions&EO_NOTHROTTLE))
+ {
+  if(Count)
+   WriteSound(Buffer,Count);
   SpeedThrottle();
   SpeedThrottle();
+ }
+ FCEUD_UpdateInput();  // must update input before blitting because of save confirmation stuff
  BlitScreen(xbuf);
  BlitScreen(xbuf);
- if(Count && !(eoptions&EO_NOTHROTTLE))
-  WriteSound(Buffer,Count);
- FCEUD_UpdateInput();
 }
 
 }
 
index 23ee4ed..0499258 100644 (file)
--- a/endian.h
+++ b/endian.h
@@ -1,3 +1,6 @@
 int write16(uint16 b, FILE *fp);
 int write32(uint32 b, FILE *fp);
 int read32(void *Bufo, FILE *fp);
 int write16(uint16 b, FILE *fp);
 int write32(uint32 b, FILE *fp);
 int read32(void *Bufo, FILE *fp);
+
+#define write32le write32
+#define read32le read32
diff --git a/fce.c b/fce.c
index d3b5c63..51e6621 100644 (file)
--- a/fce.c
+++ b/fce.c
@@ -145,6 +145,8 @@ void asmcpu_unpack(void)
        X6502_Rebase_a();
        nes_registers[4] = X.S << 24;
        nes_registers[4]|= X.IRQlow << 8;
        X6502_Rebase_a();
        nes_registers[4] = X.S << 24;
        nes_registers[4]|= X.IRQlow << 8;
+       if (MapIRQHook)
+               nes_registers[4] |= 1<<16; // MapIRQHook set bit
        nes_registers[7] = (uint32)X.count << 16;
 
        // NVUB DIZC
        nes_registers[7] = (uint32)X.count << 16;
 
        // NVUB DIZC
@@ -1514,9 +1516,9 @@ void PowerNES(void)
         memset(RAM,0x00,0x800);
 #endif
         ResetMapping();
         memset(RAM,0x00,0x800);
 #endif
         ResetMapping();
-       GameInterface(GI_POWER, 0);
         PowerSound();
        PowerPPU();
         PowerSound();
        PowerPPU();
+       GameInterface(GI_POWER, 0);
        timestampbase=0;
 #ifdef ASM_6502
        if (geniestage)
        timestampbase=0;
 #ifdef ASM_6502
        if (geniestage)
diff --git a/ncpu.h b/ncpu.h
index ac46a33..301e9a0 100644 (file)
--- a/ncpu.h
+++ b/ncpu.h
@@ -76,7 +76,7 @@
  * ++++++++---S ¥¹¥¿¥Ã¥¯¥Ý¥¤¥ó¥¿
  *
  * note: fceu uses this differently
  * ++++++++---S ¥¹¥¿¥Ã¥¯¥Ý¥¤¥ó¥¿
  *
  * note: fceu uses this differently
- * [7:0]   - interrupt flags (same as above)
+ * [7:0]   - flags (same as above)
  * [15:8]  - FCEU IRQ pending sources
  * [16]    - a flag which indicates that MapIRQHook is not null
  * [23:17] - unused
  * [15:8]  - FCEU IRQ pending sources
  * [16]    - a flag which indicates that MapIRQHook is not null
  * [23:17] - unused
index cf1cbc3..6fe6845 100644 (file)
@@ -175,7 +175,12 @@ with additional .fcm extension added. Examples:
 \r
 \r
 ver 0.4 (by notaz)\r
 \r
 \r
 ver 0.4 (by notaz)\r
-\r
+  rev 154\r
+          - Fixed savestate subsections (were causing some mapper data not\r
+            to be saved).\r
+          - Fixed an issue of MapIRQHook getting lost after loading a savestate\r
+            (glitched Akumajou Densetsu and other games after savestate load).\r
+  rev 153\r
           - Lots of work on the asm core. Timing fixed for some instructions.\r
             Some missing undocumented instruction handlers added. Lots of\r
             tweaking to make it compatible with all that mapper code.\r
           - Lots of work on the asm core. Timing fixed for some instructions.\r
             Some missing undocumented instruction handlers added. Lots of\r
             tweaking to make it compatible with all that mapper code.\r
diff --git a/state.c b/state.c
index c349cff..deacbbf 100644 (file)
--- a/state.c
+++ b/state.c
@@ -106,145 +106,128 @@ SFORMAT SFSND[]={
 
 
 
 
 
 
-int WriteStateChunk(FILE *st, int type, SFORMAT *sf)
+static int SubWrite(FILE *st, SFORMAT *sf)
 {
 {
- int bsize, count;
- int x;
+ uint32 acc=0;
 
 
- count = x = 0;
- while (sf[x++].v) count++;
+ while(sf->v)
+ {
+  if(sf->s==~0)                /* Link to another struct.      */
+  {
+   uint32 tmp;
+
+   if(!(tmp=SubWrite(st,(SFORMAT *)sf->v)))
+    return(0);
+   acc+=tmp;
+   sf++;
+   continue;
+  }
+
+  acc+=8;                      /* Description + size */
+  acc+=sf->s&(~RLSB);
+
+  if(st)                       /* Are we writing or calculating the size of this block? */
+  {
+   fwrite(sf->desc,1,4,st);
+   write32le(sf->s&(~RLSB),st);
+
+   #ifndef LSB_FIRST
+   if(sf->s&RLSB)
+    FlipByteOrder(sf->v,sf->s&(~RLSB));
+   #endif
+
+   fwrite((uint8 *)sf->v,1,sf->s&(~RLSB),st);
+   /* Now restore the original byte order. */
+   #ifndef LSB_FIRST
+   if(sf->s&RLSB)
+    FlipByteOrder(sf->v,sf->s&(~RLSB));
+   #endif
+  }
+  sf++;
+ }
+
+ return(acc);
+}
+
+static int WriteStateChunk(FILE *st, int type, SFORMAT *sf)
+{
+ int bsize;
 
  fputc(type,st);
 
 
  fputc(type,st);
 
- for(x=bsize=0;x<count;x++)
-  bsize+=sf[x].s&(~RLSB);
- bsize+=count<<3;
- write32(bsize,st);
- for(x=0;x<count;x++)
+ bsize=SubWrite(0,sf);
+ write32le(bsize,st);
+
+ if(!SubWrite(st,sf))
+ {
+        return(0);
+ }
+ return (bsize+5);
+}
+
+static SFORMAT *CheckS(SFORMAT *sf, uint32 tsize, char *desc)
+{
+ while(sf->v)
  {
  {
-  fwrite(sf[x].desc,1,4,st);
-  write32(sf[x].s&(~RLSB),st);
-  #ifdef LSB_FIRST
-  fwrite((uint8 *)sf[x].v,1,sf[x].s&(~RLSB),st);
-  #else
+  if(sf->s==~0)                /* Link to another SFORMAT structure. */
   {
   {
-  int z;
-  if(sf[x].s&RLSB)
+   SFORMAT *tmp;
+   if((tmp= CheckS((SFORMAT *)sf->v, tsize, desc) ))
+    return(tmp);
+   sf++;
+   continue;
+  }
+  if(!memcmp(desc,sf->desc,4))
   {
   {
-   for(z=(sf[x].s&(~RLSB))-1;z>=0;z--)
+   if(tsize!=(sf->s&(~RLSB)))
    {
    {
-    fputc(*(uint8*)sf[x].v,st);
+    printf("ReadStateChunk: sect \"%c%c%c%c\" has wrong size\n", desc[0], desc[1], desc[2], desc[3]);
+    return(0);
    }
    }
+   return(sf);
   }
   }
-  else
-   fwrite((uint8 *)sf[x].v,1,sf[x].s&(~RLSB),st);
-  }
-  #endif
+  sf++;
  }
  }
- return (bsize+5);
+ return(0);
 }
 
 }
 
-int ReadStateChunk(FILE *st, SFORMAT *sf, int size)
+static int ReadStateChunk(FILE *st, SFORMAT *sf, int size)
 {
 {
- uint8 tmpyo[16];
- int bsize, count;
- int x;
+ //if(scan_chunks)
+ //  return fseek(st,size,SEEK_CUR) == 0;
 
 
- // recalculate count ourselves
count = x = 0;
while (sf[x++].v) count++;
+ SFORMAT *tmp;
int temp;
temp=ftell(st);
 
 
- for(x=bsize=0;x<count;x++)
-  bsize+=sf[x].s&(~RLSB);
- if(stateversion>=53)
-  bsize+=count<<3;
- else
+ while(ftell(st)<temp+size)
  {
  {
-  if(bsize!=size)
-  {
-   fseek(st,size,SEEK_CUR);
+  uint32 tsize;
+  char toa[4];
+  if(fread(toa,1,4,st)<=0)
    return 0;
    return 0;
-  }
- }
-
- if(stateversion<56)
-  memcpy(tmpyo,mapbyte3,16);
 
 
- if(stateversion>=53)
- {
-  int temp;
-  temp=ftell(st);
+  read32le(&tsize,st);
 
 
-  while(ftell(st)<temp+size)
+  if((tmp=CheckS(sf,tsize,toa)))
   {
   {
-   int tsize;
-   char toa[4];
-
-   if(fread(toa,1,4,st)<=0)
-    return 0;
-   read32(&tsize,st);
+   fread((uint8 *)tmp->v,1,tmp->s&(~RLSB),st);
 
 
-   for(x=0;x<count;x++)
-   {
-    if(!memcmp(toa,sf[x].desc,4))
-    {
-     if(tsize!=(sf[x].s&(~RLSB)))
-     {
-      printf("ReadStateChunk: sect \"%c%c%c%c\" has wrong size\n", toa[0], toa[1], toa[2], toa[3]);
-      goto nkayo;
-     }
-     #ifndef LSB_FIRST
-     if(sf[x].s&RLSB)
-     {
-      int z;
-       for(z=(sf[x].s&(~RLSB))-1;z>=0;z--)
-        *(uint8*)sf[x].v=fgetc(st);
-     }
-     else
-     #endif
-     {
-       fread((uint8 *)sf[x].v,1,sf[x].s&(~RLSB),st);
-     }
-     goto bloo;
-    }
-   }
-  printf("ReadStateChunk: sect \"%c%c%c%c\" not handled\n", toa[0], toa[1], toa[2], toa[3]);
-  nkayo:
-  fseek(st,tsize,SEEK_CUR);
-  bloo:;
-  } // while(...)
- }  // >=53
- else
- {
-  for(x=0;x<count;x++)
-  {
-   #ifdef LSB_FIRST
-   fread((uint8 *)sf[x].v,1,sf[x].s&(~RLSB),st);
-   #else
-   int z;
-   if(sf[x].s&RLSB)
-    for(z=(sf[x].s&(~RLSB))-1;z>=0;z--)
-    {
-     *(uint8*)sf[x].v=fgetc(st);
-    }
-   else
-    fread((uint8 *)sf[x].v,1,sf[x].s&(~RLSB),st);
+   #ifndef LSB_FIRST
+   if(tmp->s&RLSB)
+    FlipByteOrder(tmp->v,tmp->s&(~RLSB));
    #endif
   }
    #endif
   }
- }
- if(stateversion<56)
- {
-  for(x=0;x<16;x++)
-   #ifdef LSB_FIRST
-   mapbyte1[x]=mapbyte1[x<<1];
-   #else
-   mapbyte1[x]=mapbyte1[(x<<1)+1];
-   #endif
-  memcpy(mapbyte3,tmpyo,16);
- }
+  else
+  {
+   fseek(st,tsize,SEEK_CUR);
+   printf("ReadStateChunk: sect \"%c%c%c%c\" not handled\n", toa[0], toa[1], toa[2], toa[3]);
+  }
+ } // while(...)
  return 1;
 }
 
  return 1;
 }
 
+
 static int ReadStateChunks(FILE *st)
 {
  int t;
 static int ReadStateChunks(FILE *st)
 {
  int t;
@@ -462,8 +445,7 @@ void AddExState(void *v, uint32 s, int type, char *desc)
   strcpy(SFMDATA[SFEXINDEX].desc,desc);
  }
  else
   strcpy(SFMDATA[SFEXINDEX].desc,desc);
  }
  else
-//  SFMDATA[SFEXINDEX].desc=0;
-  return; // do not support recursive save structures
+  SFMDATA[SFEXINDEX].desc=0;
  SFMDATA[SFEXINDEX].v=v;
  SFMDATA[SFEXINDEX].s=s;
  if(type) SFMDATA[SFEXINDEX].s|=RLSB;
  SFMDATA[SFEXINDEX].v=v;
  SFMDATA[SFEXINDEX].s=s;
  if(type) SFMDATA[SFEXINDEX].s|=RLSB;
diff --git a/svga.c b/svga.c
index d00a38a..5ac1d70 100644 (file)
--- a/svga.c
+++ b/svga.c
@@ -82,6 +82,11 @@ void FCEU_DispMessage(char *format, ...)
   printf("%s\n", errmsg);
 }
 
   printf("%s\n", errmsg);
 }
 
+void FCEU_CancelDispMessage(void)
+{
+ howlong=0;
+}
+
 void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall)
 {
  FSettings.UsrFirstSLine[0]=ntscf;
 void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall)
 {
  FSettings.UsrFirstSLine[0]=ntscf;