From 890e37ba2b8ea1c7593dc05926d7431e3bd00bfb Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 29 Apr 2007 21:28:22 +0000 Subject: [PATCH] some movies fixed git-svn-id: file:///home/notaz/opt/svn/fceu@116 be3aeb3a-fb24-0410-a615-afba39da0efa --- Makefile.gp2x | 2 +- drawing.h | 36 +++++++++--------- fce.c | 23 ++++++++++++ ines.c | 2 +- input.c | 44 ++++++++++++++++++++-- input.h | 3 ++ movie.c | 17 ++++----- state.c | 101 +++++++++++++++++++++++++------------------------- state.h | 2 + svga.c | 1 + 10 files changed, 148 insertions(+), 83 deletions(-) diff --git a/Makefile.gp2x b/Makefile.gp2x index 95398d6..8b1d55f 100644 --- a/Makefile.gp2x +++ b/Makefile.gp2x @@ -41,7 +41,7 @@ else OBJDRIVER += x6502.o endif -x6502.o: x6502.c x6502.h ops.h fce.h sound.h +x6502.o: x6502.c x6502.h ops.h fce.h sound.h dprintf.h ncpu.o: ncpu.S ncpu.h $(CC) $(TFLAGS) -c $< -o $@ diff --git a/drawing.h b/drawing.h index 61a94d3..31a8208 100644 --- a/drawing.h +++ b/drawing.h @@ -3,30 +3,30 @@ static void DrawDips(void) uint32 *dest; int y,x; - dest=(uint32 *)(XBuf+272*12+164); - for(y=24;y;y--,dest+=(272-72)>>2) + dest=(uint32 *)(XBuf+320*12+164); + for(y=24;y;y--,dest+=(320-72)>>2) { for(x=72>>2;x;x--,dest++) *dest=0x80808080; } - dest=(uint32 *)(XBuf+272*(12+4)+164+6 ); - for(y=16;y;y--,dest+=(272>>2)-16) + dest=(uint32 *)(XBuf+320*(12+4)+164+6 ); + for(y=16;y;y--,dest+=(320>>2)-16) for(x=8;x;x--) { *dest=0x81818181; dest+=2; } - dest=(uint32 *)(XBuf+272*(12+4)+164+6 ); + dest=(uint32 *)(XBuf+320*(12+4)+164+6 ); for(x=0;x<8;x++,dest+=2) { - uint32 *da=dest+(272>>2); + uint32 *da=dest+(320>>2); if(!((vsdip>>x)&1)) - da+=(272>>2)*10; + da+=(320>>2)*10; - for(y=4;y;y--,da+=272>>2) + for(y=4;y;y--,da+=320>>2) *da=0x80808080; } @@ -75,7 +75,7 @@ static void DrawState(void) uint8 *XBaf; int x,y,z; - XBaf=XBuf+4+(FSettings.LastSLine-44)*272; + XBaf=XBuf+4+(FSettings.LastSLine-44)*320; if(XBaf>=XBuf) for(z=1;z<11;z++) @@ -84,12 +84,12 @@ static void DrawState(void) { for(y=0;y<13;y++) for(x=0;x<21;x++) - XBaf[y*272+x+z*21+z]=sstat[y*21+x+(z-1)*21*12]; + XBaf[y*320+x+z*21+z]=sstat[y*21+x+(z-1)*21*12]; } else { for(y=0;y<13;y++) for(x=0;x<21;x++) if(sstat[y*21+x+(z-1)*21*12]!=0x83) - XBaf[y*272+x+z*21+z]=sstat[y*21+x+(z-1)*21*12]; + XBaf[y*320+x+z*21+z]=sstat[y*21+x+(z-1)*21*12]; } if(CurrentState==z%10) { @@ -97,8 +97,8 @@ static void DrawState(void) XBaf[x+z*21+z*1]=132; for(x=1;x<12;x++) { - XBaf[272*x+z*21+z*1]= - XBaf[272*x+z*21+z*1+20]=132; + XBaf[320*x+z*21+z*1]= + XBaf[320*x+z*21+z*1+20]=132; } for(x=0;x<21;x++) XBaf[3264+x+z*21+z*1]=132; @@ -128,27 +128,27 @@ void DrawBars(void) if(controlselect==1) { - DrawTextTrans(XBuf+128-12+180*272, 272, (uint8 *)"Hue", 0x85); + DrawTextTrans(XBuf+128-12+180*320, 320, (uint8 *)"Hue", 0x85); which=ntschue<<1; } else if(controlselect==2) { - DrawTextTrans(XBuf+128-16+180*272, 272, (uint8 *)"Tint", 0x85); + DrawTextTrans(XBuf+128-16+180*320, 320, (uint8 *)"Tint", 0x85); which=ntsctint<<1; } - XBaf=XBuf+200*272; + XBaf=XBuf+200*320; for(x=0;x=-6;x2--) { - XBaf[x-272*x2]=0x85; + XBaf[x-320*x2]=0x85; } } for(;x<256;x+=2) { for(x2=2;x2>=-2;x2--) - XBaf[x-272*x2]=0x85; + XBaf[x-320*x2]=0x85; } } diff --git a/fce.c b/fce.c index 561661a..53abd93 100644 --- a/fce.c +++ b/fce.c @@ -1416,3 +1416,26 @@ void PowerNES(void) X6502_Power(); } + +/* savestate stuff */ +uint16 TempAddrT,RefreshAddrT; + +SFORMAT FCEUPPU_STATEINFO[]={ + { NTARAM, 0x800, "NTAR"}, + { PALRAM, 0x20, "PRAM"}, + { SPRAM, 0x100, "SPRA"}, + { PPU, 0x4, "PPUR"}, + { &XOffset, 1, "XOFF"}, + { &vtoggle, 1, "VTOG"}, + { &RefreshAddrT, 2|RLSB, "RADD"}, + { &TempAddrT, 2|RLSB, "TADD"}, + { &VRAMBuffer, 1, "VBUF"}, + { &PPUGenLatch, 1, "PGEN"}, + // from 0.98.15 + { &kook, 1, "KOOK"}, + { &ppudead, 1, "DEAD"}, + { &PPUSPL, 1, "PSPL"}, + { 0 } + }; + + diff --git a/ines.c b/ines.c index 6f8bb1b..3ffcfce 100644 --- a/ines.c +++ b/ines.c @@ -501,7 +501,7 @@ int iNESLoad(char *name, int fp) iNESGameCRC32=CalcCRC32(0,ROM,ROM_size<<14); if(VROM_size) iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13); - printf("\n PRG ROM: %3d x 16k\n CHR ROM: %3d x 8k\n ROM CRC32: %08lx\n Mapper: %d\n Mirroring: %s\n",head.ROM_size,head.VROM_size,iNESGameCRC32,MapperNo,Mirroring==2?"None(Four-screen)":Mirroring?"Vertical":"Horizontal"); + printf("\n PRG ROM: %3d x 16k\n CHR ROM: %3d x 8k\n ROM CRC32: %08x\n Mapper: %d\n Mirroring: %s\n",head.ROM_size,head.VROM_size,iNESGameCRC32,MapperNo,Mirroring==2?"None(Four-screen)":Mirroring?"Vertical":"Horizontal"); if(head.ROM_type&2) puts(" Battery-backed."); if(head.ROM_type&4) puts(" Trained."); puts(""); diff --git a/input.c b/input.c index a3a9979..e4223bc 100644 --- a/input.c +++ b/input.c @@ -28,6 +28,7 @@ #include "svga.h" #include "input.h" +#include "state.h" #include "movie.h" #include "dprintf.h" @@ -40,7 +41,8 @@ extern INPUTCFC *FCEU_InitArkanoidFC(void); extern INPUTCFC *FCEU_InitSpaceShadow(void); extern INPUTCFC *FCEU_InitFKB(void); static uint8 joy_readbit[2]; -static uint16 joy[4]={0,0,0,0}; +static uint8 joy[4]={0,0,0,0}; +static uint8 LastStrobe; extern int coinon; @@ -122,7 +124,7 @@ static DECLFW(B4016) if(JPorts[1]->Write) JPorts[1]->Write(V&1); - if((PSG[0x16]&1) && (!(V&1))) + if((LastStrobe&1) && (!(V&1))) { /* This strobe code is just for convenience. If it were with the code in input / *.c, it would more accurately represent @@ -137,7 +139,7 @@ static DECLFW(B4016) if(FCExp->Strobe) FCExp->Strobe(); } - PSG[0x16]=V; + LastStrobe=V&1; } static void FP_FASTAPASS(1) StrobeGP(int w) @@ -298,6 +300,7 @@ void InitializeInput(void) { memset(joy_readbit,0,sizeof(joy_readbit)); memset(joy,0,sizeof(joy)); + LastStrobe=0; if(FCEUGameInfo.type==GIT_VSUNI) { @@ -333,3 +336,38 @@ void FCEUI_SetInputFC(int type, void *ptr, int attrib) InputDataPtrFC=ptr; SetInputStuffFC(); } + +// quick paste +#define FCEUNPCMD_RESET 0x01 +#define FCEUNPCMD_POWER 0x02 + +#define FCEUNPCMD_VSUNICOIN 0x07 +#define FCEUNPCMD_VSUNIDIP0 0x08 +#define FCEUNPCMD_FDSINSERT 0x18 +#define FCEUNPCMD_FDSSELECT 0x1A + + +void FCEU_DoSimpleCommand(int cmd) +{ + switch(cmd) + { +// case FCEUNPCMD_FDSINSERT: FCEU_FDSInsert();break; +// case FCEUNPCMD_FDSSELECT: FCEU_FDSSelect();break; +// case FCEUNPCMD_FDSEJECT: FCEU_FDSEject();break; +// case FCEUNPCMD_VSUNICOIN: FCEU_VSUniCoin(); break; +// case FCEUNPCMD_VSUNIDIP0 ... (FCEUNPCMD_VSUNIDIP0 + 7): FCEU_VSUniToggleDIP(cmd - FCEUNPCMD_VSUNIDIP0);break; + case FCEUNPCMD_POWER: PowerNES();break; + case FCEUNPCMD_RESET: ResetNES();break; + default: printf("FCEU_DoSimpleCommand: can't handle cmd %i\n", cmd); break; + } +} + + +SFORMAT FCEUCTRL_STATEINFO[]={ + { joy_readbit, 2, "JYRB"}, + { joy, 4, "JOYS"}, + { &LastStrobe, 1, "LSTS"}, + { 0 } +}; + + diff --git a/input.h b/input.h index 8cec68a..8c301cf 100644 --- a/input.h +++ b/input.h @@ -21,3 +21,6 @@ void UpdateInput(void); void InitializeInput(void); extern void (*PStrobe[2])(void); extern void (*InputScanlineHook)(uint8 *buf, int line); + +void FCEU_DoSimpleCommand(int cmd); + diff --git a/movie.c b/movie.c index d4a6505..064c256 100644 --- a/movie.c +++ b/movie.c @@ -47,7 +47,7 @@ typedef struct // backwards compat static void FCEUI_LoadMovie_v1(char *fname, int _read_only); -static int FCEUI_MovieGetInfo_v1(const char* fname, MOVIE_INFO* info); +//static int FCEUI_MovieGetInfo_v1(const char* fname, MOVIE_INFO* info); extern char FileBase[]; @@ -87,10 +87,10 @@ static uint32 savestate_offset = 0; static uint32 rerecord_count = 0; /*static*/ int movie_readonly = 1; int frame_display = 0; -static uint32 last_frame_display = ~0; +//static uint32 last_frame_display = ~0; int input_display = 0; static uint32 cur_input_display = 0; -static uint32 last_input_display = ~0; +//static uint32 last_input_display = ~0; int resetDMCacc=0; @@ -112,11 +112,11 @@ SFORMAT FCEUMOV_STATEINFO[]={ }; static int CurrentMovie = 1; -static int MovieShow = 0; +//static int MovieShow = 0; static int MovieStatus[10]; -static void DoEncode(int joy, int button, int); +//static void DoEncode(int joy, int button, int); int FCEUMOV_IsPlaying(void) { @@ -716,9 +716,9 @@ static void DoEncode(int joy, int button, int dummy) // TODO: make this function legible! (what are all these magic numbers and weirdly named variables and crazy unexplained loops?) void FCEUMOV_AddJoy(uint8 *js) { - int x,y; +// int x,y; -// if(!current) return; // Not playback nor recording. + if(!current) return; // Not playback nor recording. if(current < 0) // Playback { @@ -732,10 +732,7 @@ void FCEUMOV_AddJoy(uint8 *js) if(nextd&0x80) { //puts("Egads"); - // TODO? -#if 0 FCEU_DoSimpleCommand(nextd&0x1F); -#endif } else joop[(nextd >> 3)&0x3] ^= 1 << (nextd&0x7); diff --git a/state.c b/state.c index 106d5ed..e306eda 100644 --- a/state.c +++ b/state.c @@ -47,55 +47,38 @@ static SFORMAT SFMDATA[64]; static int SFEXINDEX; static int stateversion; -#define RLSB 0x80000000 +extern SFORMAT FCEUPPU_STATEINFO[]; // 3 +extern SFORMAT FCEUCTRL_STATEINFO[]; // 4 -#define SFCPUELEMENTS 7 - -SFORMAT SFCPU[SFCPUELEMENTS]={ +SFORMAT SFCPU[]={ // 1 { &X.PC, 2|RLSB, "PC\0"}, { &X.A, 1, "A\0\0"}, { &X.P, 1, "P\0\0"}, { &X.X, 1, "X\0\0"}, { &X.Y, 1, "Y\0\0"}, { &X.S, 1, "S\0\0"}, - { RAM, 0x800, "RAM"} + { RAM, 0x800, "RAM"}, + { 0, } }; -#define SFCPUCELEMENTS 6 -SFORMAT SFCPUC[SFCPUCELEMENTS]={ +SFORMAT SFCPUC[]={ // 2 { &X.jammed, 1, "JAMM"}, { &X.IRQlow, 1, "IRQL"}, { &X.tcount, 4|RLSB, "ICoa"}, { &X.count, 4|RLSB, "ICou"}, { ×tamp, 4|RLSB, "TIME"}, - { ×tampbase, 8|RLSB, "TMEB"} + { ×tampbase, 8|RLSB, "TMEB"}, + // from 0.98.15 + { ×tampbase, sizeof(timestampbase) | RLSB, "TSBS"}, // size seems to match? + { &X.mooPI, 1, "MooP"}, // alternative to the "quick and dirty hack" + // TODO: IQLB? + { 0, } }; -static uint16 TempAddrT,RefreshAddrT; - -#define SFPPUELEMENTS 10 -SFORMAT SFPPU[SFPPUELEMENTS]={ - { NTARAM, 0x800, "NTAR"}, - { PALRAM, 0x20, "PRAM"}, - { SPRAM, 0x100, "SPRA"}, - { PPU, 0x4, "PPUR"}, - { &XOffset, 1, "XOFF"}, - { &vtoggle, 1, "VTOG"}, - { &RefreshAddrT, 2|RLSB, "RADD"}, - { &TempAddrT, 2|RLSB, "TADD"}, - { &VRAMBuffer, 1, "VBUF"}, - { &PPUGenLatch, 1, "PGEN"}, -}; +extern uint16 TempAddrT,RefreshAddrT; -// Is this chunk necessary? I'll fix it later. -//#define SFCTLRELEMENTS 2 -//SFORMAT SFCTLR[SFCTLRELEMENTS]={ -// { &joy_readbit, 1, "J1RB"}, -// { &joy2_readbit, 1, "J2RB"} -//}; -#define SFSNDELEMENTS 18 -SFORMAT SFSND[SFSNDELEMENTS]={ +SFORMAT SFSND[]={ { &fhcnt, 4|RLSB,"FHCN"}, { &fcnt, 1, "FCNT"}, { PSG, 14, "PSG"}, @@ -113,15 +96,20 @@ SFORMAT SFSND[SFSNDELEMENTS]={ { DecCountTo1, 3,"DCT1"}, { &PCMBitIndex, 1,"PBIN"}, { &PCMAddressIndex, 4|RLSB, "PAIN"}, - { &PCMSizeIndex, 4|RLSB, "PSIN"} + { &PCMSizeIndex, 4|RLSB, "PSIN"}, + { 0, } }; -int WriteStateChunk(FILE *st, int type, SFORMAT *sf, int count) + +int WriteStateChunk(FILE *st, int type, SFORMAT *sf) { - int bsize; + int bsize, count; int x; + count = x = 0; + while (sf[x++].v) count++; + fputc(type,st); for(x=bsize=0;x=53) @@ -193,7 +185,10 @@ int ReadStateChunk(FILE *st, SFORMAT *sf, int count, int size) 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) { @@ -209,6 +204,7 @@ int ReadStateChunk(FILE *st, SFORMAT *sf, int count, int size) 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:; @@ -245,7 +241,7 @@ int ReadStateChunk(FILE *st, SFORMAT *sf, int count, int size) return 1; } -int ReadStateChunks(FILE *st) +static int ReadStateChunks(FILE *st) { int t; uint32 size; @@ -256,24 +252,27 @@ for(;;) t=fgetc(st); if(t==EOF) break; if(!read32(&size,st)) break; + + // printf("ReadStateChunks: chunk %i\n", t); switch(t) { - case 1:if(!ReadStateChunk(st,SFCPU,SFCPUELEMENTS,size)) ret=0; + case 1:if(!ReadStateChunk(st,SFCPU,size)) ret=0; #ifdef ASM_6502 asmcpu_unpack(); #endif break; - case 2:if(!ReadStateChunk(st,SFCPUC,SFCPUCELEMENTS,size)) ret=0; + case 2:if(!ReadStateChunk(st,SFCPUC,size)) ret=0; else { X.mooPI=X.P; // Quick and dirty hack. } break; - case 3:if(!ReadStateChunk(st,SFPPU,SFPPUELEMENTS,size)) ret=0;break; -// case 4:if(!ReadStateChunk(st,SFCTLR,SFCTLRELEMENTS,size)) ret=0;break; - case 5:if(!ReadStateChunk(st,SFSND,SFSNDELEMENTS,size)) ret=0;break; - case 0x10:if(!ReadStateChunk(st,SFMDATA,SFEXINDEX,size)) ret=0;break; - default: if(fseek(st,size,SEEK_CUR)<0) goto endo;break; + case 3:if(!ReadStateChunk(st,FCEUPPU_STATEINFO,size)) ret=0;break; + case 4:if(!ReadStateChunk(st,FCEUCTRL_STATEINFO,size)) ret=0;break; + case 5:if(!ReadStateChunk(st,SFSND,size)) ret=0;break; + case 0x10:if(!ReadStateChunk(st,SFMDATA,size)) ret=0;break; + default:printf("ReadStateChunks: unknown chunk: %i\n", t); + if(fseek(st,size,SEEK_CUR)<0) goto endo;break; } } endo: @@ -309,12 +308,12 @@ void SaveState(void) #ifdef ASM_6502 asmcpu_pack(); #endif - totalsize=WriteStateChunk(st,1,SFCPU,SFCPUELEMENTS); - totalsize+=WriteStateChunk(st,2,SFCPUC,SFCPUCELEMENTS); - totalsize+=WriteStateChunk(st,3,SFPPU,SFPPUELEMENTS); - // totalsize+=WriteStateChunk(st,4,SFCTLR,SFCTLRELEMENTS); - totalsize+=WriteStateChunk(st,5,SFSND,SFSNDELEMENTS); - totalsize+=WriteStateChunk(st,0x10,SFMDATA,SFEXINDEX); + totalsize=WriteStateChunk(st,1,SFCPU); + totalsize+=WriteStateChunk(st,2,SFCPUC); + totalsize+=WriteStateChunk(st,3,FCEUPPU_STATEINFO); + totalsize+=WriteStateChunk(st,4,FCEUCTRL_STATEINFO); + totalsize+=WriteStateChunk(st,5,SFSND); + totalsize+=WriteStateChunk(st,0x10,SFMDATA); fseek(st,4,SEEK_SET); write32(totalsize,st); @@ -506,6 +505,8 @@ static int LoadStateOld(FILE *st) uint8 version; nada=0; + printf("LoadStateOld\n"); + StateBuffer=FCEU_malloc(59999); if(StateBuffer==NULL) return 0; diff --git a/state.h b/state.h index 71163f7..3d94900 100644 --- a/state.h +++ b/state.h @@ -40,3 +40,5 @@ typedef struct { void ResetExState(void); void AddExState(void *v, uint32 s, int type, char *desc); +#define RLSB 0x80000000 + diff --git a/svga.c b/svga.c index b632336..76d21f1 100644 --- a/svga.c +++ b/svga.c @@ -76,6 +76,7 @@ void FCEU_DispMessage(char *format, ...) va_end(ap); howlong=180; + printf("%s\n", errmsg); } void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) -- 2.39.2