From: notaz Date: Tue, 5 Jun 2007 19:36:17 +0000 (+0000) Subject: savestate and other bugfixes X-Git-Tag: r1~28 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bb3fe122854be9af6c3024fef9f503d27bc63a1;p=fceu.git savestate and other bugfixes git-svn-id: file:///home/notaz/opt/svn/fceu@154 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/driver.h b/driver.h index e240960..1d47e50 100644 --- 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, ...); +void FCEU_CancelDispMessage(void); #define FCEUI_DispMessage FCEU_DispMessage int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type); diff --git a/drivers/gp2x/gp2x-sound.c b/drivers/gp2x/gp2x-sound.c index e188873..666aee1 100644 --- a/drivers/gp2x/gp2x-sound.c +++ b/drivers/gp2x/gp2x-sound.c @@ -29,7 +29,7 @@ extern int soundvol; void WriteSound(int16 *Buffer, int Count) { gp2x_sound_write(Buffer, Count<<1); - SpeedThrottle(); +// SpeedThrottle(); } void SilenceSound(int n) diff --git a/drivers/gp2x/gp2x-video.c b/drivers/gp2x/gp2x-video.c index 9b73e46..198222d 100644 --- a/drivers/gp2x/gp2x-video.c +++ b/drivers/gp2x/gp2x-video.c @@ -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 */ @@ -167,8 +167,6 @@ void BlitScreen(uint8 *buf) framesRendered++; - printFps(gp2x_screen); - 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); diff --git a/drivers/gp2x/input.c b/drivers/gp2x/input.c index 6a51264..c2f88f6 100644 --- a/drivers/gp2x/input.c +++ b/drivers/gp2x/input.c @@ -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; - FCEU_DispMessage(""); + FCEU_CancelDispMessage(); } 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; - FCEU_DispMessage(""); + FCEU_CancelDispMessage(); } } if (do_it) FCEUI_SaveState(); diff --git a/drivers/gp2x/main.c b/drivers/gp2x/main.c index cbd8679..ac48a2d 100644 --- a/drivers/gp2x/main.c +++ b/drivers/gp2x/main.c @@ -466,11 +466,13 @@ static void DriverKill(void) void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count) { - if(!Count && !(eoptions&EO_NOTHROTTLE)) + if(!(eoptions&EO_NOTHROTTLE)) + { + if(Count) + WriteSound(Buffer,Count); SpeedThrottle(); + } + FCEUD_UpdateInput(); // must update input before blitting because of save confirmation stuff BlitScreen(xbuf); - if(Count && !(eoptions&EO_NOTHROTTLE)) - WriteSound(Buffer,Count); - FCEUD_UpdateInput(); } diff --git a/endian.h b/endian.h index 23ee4ed..0499258 100644 --- 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); + +#define write32le write32 +#define read32le read32 diff --git a/fce.c b/fce.c index d3b5c63..51e6621 100644 --- 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; + if (MapIRQHook) + nes_registers[4] |= 1<<16; // MapIRQHook set bit nes_registers[7] = (uint32)X.count << 16; // NVUB DIZC @@ -1514,9 +1516,9 @@ void PowerNES(void) memset(RAM,0x00,0x800); #endif ResetMapping(); - GameInterface(GI_POWER, 0); PowerSound(); PowerPPU(); + GameInterface(GI_POWER, 0); timestampbase=0; #ifdef ASM_6502 if (geniestage) diff --git a/ncpu.h b/ncpu.h index ac46a33..301e9a0 100644 --- a/ncpu.h +++ b/ncpu.h @@ -76,7 +76,7 @@ * ++++++++---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 diff --git a/out_gp2x/readme.txt b/out_gp2x/readme.txt index cf1cbc3..6fe6845 100644 --- a/out_gp2x/readme.txt +++ b/out_gp2x/readme.txt @@ -175,7 +175,12 @@ with additional .fcm extension added. Examples: ver 0.4 (by notaz) - + rev 154 + - Fixed savestate subsections (were causing some mapper data not + to be saved). + - Fixed an issue of MapIRQHook getting lost after loading a savestate + (glitched Akumajou Densetsu and other games after savestate load). + rev 153 - Lots of work on the asm core. Timing fixed for some instructions. Some missing undocumented instruction handlers added. Lots of tweaking to make it compatible with all that mapper code. diff --git a/state.c b/state.c index c349cff..deacbbf 100644 --- 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); - for(x=bsize=0;xv) { - 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=53) - bsize+=count<<3; - else + while(ftell(st)=53) - { - int temp; - temp=ftell(st); + read32le(&tsize,st); - while(ftell(st)v,1,tmp->s&(~RLSB),st); - for(x=0;x=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=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 } - } - 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; } + 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 -// 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; diff --git a/svga.c b/svga.c index d00a38a..5ac1d70 100644 --- a/svga.c +++ b/svga.c @@ -82,6 +82,11 @@ void FCEU_DispMessage(char *format, ...) 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;