1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 1998 BERO
5 * Copyright (C) 2002 Ben Parnell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
58 static void (*RefreshLine)(uint8 *P, uint32 vofs) = NULL;
59 static void PRefreshLine(void);
61 static void ResetPPU(void);
62 static void PowerPPU(void);
64 uint64 timestampbase=0;
70 uint32 MMC5HackVROMMask;
71 uint8 *MMC5HackExNTARAMPtr;
72 uint8 *MMC5HackVROMPTR;
73 uint8 MMC5HackCHRMode=0;
75 uint8 MMC5HackSPScroll;
78 uint8 *MMC5SPRVPage[8];
79 uint8 *MMC5BGVPage[8];
82 uint8 VRAMBuffer,PPUGenLatch;
88 /* Color deemphasis emulation. Joy... */
90 static int deempcnt[8];
95 void (*GameInterface)(int h);
97 void FP_FASTAPASS(1) (*PPU_hook)(uint32 A);
99 void (*GameStateRestore)(int version);
100 void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void);
102 readfunc ARead[0x10000];
103 writefunc BWrite[0x10000];
104 static readfunc *AReadG;
105 static writefunc *BWriteG;
109 static void asmcpu_update(int32 cycles)
111 // some code from x6502.c
125 if((PSG[0x10]&0x80) && !(PSG[0x10]&0x40))
127 extern uint8 SIRQStat;
129 X6502_IRQBegin(FCEU_IQDPCM);
135 void asmcpu_unpack(void)
137 nes_registers[0] = X.A << 24;
138 nes_registers[1] = X.X;
139 nes_registers[2] = X.Y;
141 nes_registers[3] = X.PC;
143 nes_registers[4] = X.S << 24;
144 nes_registers[4]|= X.IRQlow << 8;
145 nes_registers[7] = (uint32)X.count << 16;
148 nes_registers[4]|= X.P & 0x5d;
149 nes_registers[5] = X.P << 24; // N
150 if (!(X.P&0x02)) nes_registers[5] |= 1; // Z
153 void asmcpu_pack(void)
155 X.A = nes_registers[0] >> 24;
156 X.X = nes_registers[1];
157 X.Y = nes_registers[2];
158 X.PC= nes_registers[3] - pc_base;
159 X.S = nes_registers[4] >> 24;
160 X.IRQlow = nes_registers[4] >> 8;
161 X.count = (int32) nes_registers[7] >> 16;
164 X.P = nes_registers[4] & 0x5d;
165 if ( nes_registers[5]&0x80000000) X.P |= 0x80; // N
166 if (!(nes_registers[5]&0x000000ff)) X.P |= 0x02; // Z
180 int AllocGenieRW(void)
182 if(!(AReadG=FCEU_malloc(0x8000*sizeof(readfunc))))
184 if(!(BWriteG=FCEU_malloc(0x8000*sizeof(writefunc))))
190 void FlushGenieRW(void)
196 for(x=0;x<0x8000;x++)
198 ARead[x+0x8000]=AReadG[x];
199 BWrite[x+0x8000]=BWriteG[x];
209 readfunc FASTAPASS(1) GetReadHandler(int32 a)
211 if(a>=0x8000 && RWWrap)
212 return AReadG[a-0x8000];
217 void FASTAPASS(3) SetReadHandler(int32 start, int32 end, readfunc func)
225 for(x=end;x>=start;x--)
228 AReadG[x-0x8000]=func;
234 for(x=end;x>=start;x--)
238 writefunc FASTAPASS(1) GetWriteHandler(int32 a)
240 if(RWWrap && a>=0x8000)
241 return BWriteG[a-0x8000];
246 void FASTAPASS(3) SetWriteHandler(int32 start, int32 end, writefunc func)
254 for(x=end;x>=start;x--)
257 BWriteG[x-0x8000]=func;
262 for(x=end;x>=start;x--)
269 uint32 TempAddr,RefreshAddr;
272 /* scanline is equal to the current visible scanline we're on. */
276 uint8 GameMemBlock[131072] __attribute__ ((aligned (4)));
277 uint8 NTARAM[0x800] __attribute__ ((aligned (4)));
278 uint8 PALRAM[0x20] __attribute__ ((aligned (4)));
279 #if !defined(ASM_6502) || defined(DEBUG_ASM_6502)
280 uint8 RAM[0x800] __attribute__ ((aligned (4)));
289 #define MMC5BGVRAMADR(V) &MMC5BGVPage[(V)>>10][(V)]
290 #define VRAMADR(V) &VPage[(V)>>10][(V)]
292 static int linestartts;
295 static void ResetRL(void)
297 linestartts=timestamp*48+X6502_GetCycleCount();
301 static INLINE void Fixit1(void);
303 static void TryFixit1(void)
305 #define TOFIXNUM (272-0x4)
308 if (scanline < 240 && tofix)
310 lastpixel = (timestamp*48-linestartts)>>4;
311 if (PAL) lastpixel += lastpixel>>4;
313 //printf("lastpixel: %i\n", lastpixel);
315 if(lastpixel>=TOFIXNUM)
352 ret|=PPUGenLatch&0x1F;
356 dprintf("r [2002] %02x",ret);
371 uint32 tmp=RefreshAddr&0x3FFF;
377 if(PPU_hook) PPU_hook(tmp);
378 PPUGenLatch=VRAMBuffer;
381 VRAMBuffer=VPage[tmp>>10][tmp];
385 VRAMBuffer=vnapage[(tmp>>10)&0x3][tmp&0x3FF];
388 if (INC32) RefreshAddr+=32;
390 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
391 dprintf("r [2007] %02x",ret);
413 //printf("$%04x:$%02x, %d\n",X.PC,V,scanline);
441 //printf("$%02x:$%02x\n",PPUSPL,V);
481 TempAddr|=(V&0x3f)<<8;
488 RefreshAddr=TempAddr;
490 PPU_hook(RefreshAddr);
498 uint32 tmp=RefreshAddr&0x3FFF;
504 PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3f;
505 else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f;
509 if(PPUCHRRAM&(1<<(tmp>>10)))
510 VPage[tmp>>10][tmp]=V;
514 if(PPUNTARAM&(1<<((tmp&0xF00)>>10)))
515 vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V;
517 if (INC32) RefreshAddr+=32;
519 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
528 B2004(0x2004,X.DB=ARead[t+x](t+x));
529 X6502_AddCycles(512);
532 void BGRender(uint8 *target)
535 vofs=((PPU[0]&0x10)<<8) | ((RefreshAddr>>12)&7);
541 RefreshLine(target-XOffset, vofs);
552 *(uint32 *)target=*(uint32 *)(target+4)=tem;
557 int FSkip_setting=-1; // auto
559 void FCEUI_FrameSkip(int x)
565 /* This is called at the beginning of each visible scanline */
566 static void Loop6502(void)
570 uint8 *target=XBuf+scanline*320+32;
572 if(ScreenON || SpriteON)
574 /* PRefreshLine() will not get called on skipped frames. This
575 could cause a problem, but the solution would be rather complex,
576 due to the current sprite 0 hit code.
584 if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine)
594 tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
596 FCEU_dwmemset(target,tem,264);
601 if (SpriteON && scanline)
602 RefreshSprite(target);
610 ((uint32 *)target)[x]=((uint32*)target)[x]&0xF0F0F0F0;
614 ((uint32 *)target)[x]=(((uint32*)target)[x]&0x3f3f3f3f)|0x40404040;
617 ((uint32 *)target)[x]=((uint32*)target)[x]|0xC0C0C0C0;
620 ((uint32 *)target)[x]=((uint32*)target)[x]&0x3f3f3f3f;
621 FCEU_dwmemset(target- 8,0x3f3f3f3f,8);
622 FCEU_dwmemset(target+256,0x3f3f3f3f,8);
629 tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
630 FCEU_dwmemset(target,tem,256);
632 if(InputScanlineHook)
633 InputScanlineHook(target, scanline);
636 #define PAL(c) ((c)+cc)
639 static void PRefreshLine(void)
645 if (BGAdrHI) vofs = 0x1000;
647 vofs+=(RefreshAddr>>12)&7;
653 zz2=(uint8)((RefreshAddr>>10)&3);
654 PPU_hook(0x2000|(RefreshAddr&0xFFF));
655 no = vnapage[zz2][(RefreshAddr&0x3ff)];
656 PPU_hook((no<<4)+vofs);
657 if((RefreshAddr&0x1f)==0x1f)
664 /* This high-level graphics MMC5 emulation code was written
665 for MMC5 carts in "CL" mode. It's probably not totally
666 correct for carts in "SL" mode.
668 static void RefreshLine_MMC5Hack1(uint8 *P, uint32 vofs)
672 tochange=MMC5HackSPMode&0x1F;
674 for(X1=33;X1;X1--,P+=8)
680 if((tochange<=0 && MMC5HackSPMode&0x40) ||
681 (tochange>0 && !(MMC5HackSPMode&0x40)))
686 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
687 if(ys>=0x1E) ys-=0x1E;
688 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
690 C = MMC5HackVROMPTR+vadr;
691 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
693 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
694 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
699 zz2=(RefreshAddr>>10)&3;
700 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
701 C = MMC5BGVRAMADR(vadr);
702 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
703 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
707 if((RefreshAddr&0x1f)==0x1f)
715 static void RefreshLine_MMC5Hack2(uint8 *P, uint32 vofs)
719 tochange=MMC5HackSPMode&0x1F;
721 for(X1=33;X1;X1--,P+=8)
728 if((tochange<=0 && MMC5HackSPMode&0x40) ||
729 (tochange>0 && !(MMC5HackSPMode&0x40)))
734 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
735 if(ys>=0x1E) ys-=0x1E;
736 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
738 C = MMC5HackVROMPTR+vadr;
739 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
741 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
742 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
747 zz2=(RefreshAddr>>10)&3;
748 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
749 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
750 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
751 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
755 if((RefreshAddr&0x1f)==0x1f)
763 static void RefreshLine_MMC5Hack3(uint8 *P, uint32 vofs)
767 for(X1=33;X1;X1--,P+=8)
775 zz2=(RefreshAddr>>10)&3;
776 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
777 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
778 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
779 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
783 if((RefreshAddr&0x1f)==0x1f)
790 static void RefreshLine_MMC5Hack4(uint8 *P, uint32 vofs)
794 for(X1=33;X1;X1--,P+=8)
801 zz2=(RefreshAddr>>10)&3;
802 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
803 C = MMC5BGVRAMADR(vadr);
804 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
805 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
809 if((RefreshAddr&0x1f)==0x1f)
816 static void RefreshLine_PPU_hook(uint8 *P, uint32 vofs)
820 for(X1=33;X1;X1--,P+=8)
827 zz2=(RefreshAddr>>10)&3;
828 PPU_hook(0x2000|(RefreshAddr&0xFFF));
829 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
830 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
831 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
838 if((RefreshAddr&0x1f)==0x1f)
845 static void RefreshLine_normal(uint8 *P, uint32 vofs) // vofs is 0x107 max
848 uint32 rfraddr = RefreshAddr;
849 uint8 *page = vnapage[(rfraddr>>10)&3];
852 if ((rfraddr&0xc)!=0)
853 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
855 for (X1=33;X1;X1--,P+=8)
860 vadr=(page[rfraddr&0x3ff]<<4)+vofs;
862 if ((rfraddr&0xc)==0)
863 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
864 cc=((cc2 >> ((rfraddr&2) + ((rfraddr&0x40)>>4) + ((rfraddr&0xc)<<1))) & 3) << 2;
868 if((rfraddr&0x1f)==0x1f) {
870 page = vnapage[(rfraddr>>10)&3];
874 RefreshAddr = rfraddr;
877 static void SetRefreshLine(void)
879 if(MMC5Hack && geniestage!=1)
881 if(MMC5HackCHRMode==0 && (MMC5HackSPMode&0x80))
883 if (RefreshLine != RefreshLine_MMC5Hack1) printf("set refr RefreshLine_MMC5Hack1\n");
884 RefreshLine = RefreshLine_MMC5Hack1;
886 else if(MMC5HackCHRMode==1 && (MMC5HackSPMode&0x80))
888 if (RefreshLine != RefreshLine_MMC5Hack2) printf("set refr RefreshLine_MMC5Hack2\n");
889 RefreshLine = RefreshLine_MMC5Hack2;
891 else if(MMC5HackCHRMode==1)
893 if (RefreshLine != RefreshLine_MMC5Hack3) printf("set refr RefreshLine_MMC5Hack3\n");
894 RefreshLine = RefreshLine_MMC5Hack3;
898 if (RefreshLine != RefreshLine_MMC5Hack4) printf("set refr RefreshLine_MMC5Hack4\n");
899 RefreshLine = RefreshLine_MMC5Hack4;
901 } // End if(MMC5Hack)
904 if (RefreshLine != RefreshLine_PPU_hook) printf("set refr RefreshLine_PPU_hook\n");
905 RefreshLine = RefreshLine_PPU_hook;
909 if (RefreshLine != RefreshLine_normal) printf("set refr RefreshLine_normal\n");
910 RefreshLine = RefreshLine_normal;
917 if(ScreenON || SpriteON)
919 uint32 rad=RefreshAddr;
921 rad|=TempAddr&0x041f;
923 //PPU_hook(RefreshAddr,-1);
930 if(ScreenON || SpriteON)
932 uint32 rad=RefreshAddr;
934 if((rad&0x7000)==0x7000)
937 if((rad&0x3E0)==0x3A0)
944 if((rad&0x3E0)==0x3e0)
952 //PPU_hook(RefreshAddr,-1);
957 /* This is called at the beginning of all h-blanks on visible lines. */
958 static void DoHBlank(void)
960 if(ScreenON || SpriteON)
962 if(GameHBIRQHook && (ScreenON || SpriteON))
972 X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
976 if(GameHBIRQHook2 && (ScreenON || SpriteON))
979 //fprintf(stderr,"%3d: $%04x\n",scanline,RefreshAddr);
986 // ============================//
988 // ===========================//
990 void ResetMapping(void)
994 SetReadHandler(0x0000,0xFFFF,ANull);
995 SetWriteHandler(0x0000,0xFFFF,BNull);
997 SetReadHandler(0,0x7FF,ARAML);
998 SetWriteHandler(0,0x7FF,BRAML);
1000 SetReadHandler(0x800,0x1FFF,ARAMH); /* Part of a little */
1001 SetWriteHandler(0x800,0x1FFF,BRAMH); /* hack for a small speed boost. */
1003 for(x=0x2000;x<0x4000;x+=8)
1023 BWrite[0x4014]=B4014;
1029 void CloseGame(void)
1033 if(FCEUGameInfo.type!=GIT_NSF)
1036 if(FSettings.NetworkPlay) KillNetplay();
1038 GameInterface(GI_CLOSE);
1044 void ResetGameLoaded(void)
1046 if(GameLoaded) CloseGame();
1049 GameHBIRQHook=GameHBIRQHook2=0;
1050 GameExpSound.Fill=0;
1051 GameExpSound.RChange=0;
1052 if(GameExpSound.Kill)
1053 GameExpSound.Kill();
1054 GameExpSound.Kill=0;
1060 FCEUGameInfo.name=0;
1061 FCEUGameInfo.type=GIT_CART;
1062 FCEUGameInfo.vidsys=GIV_USER;
1063 FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=-1;
1064 FCEUGameInfo.inputfc=-1;
1067 char lastLoadedGameName [2048];
1068 int UNIFLoad(const char *name, int fp);
1069 int iNESLoad(const char *name, int fp);
1070 int FDSLoad(const char *name, int fp);
1071 int NSFLoad(int fp);
1073 FCEUGI *FCEUI_LoadGame(char *name)
1082 strncpy(name2, name, sizeof(name2));
1083 name2[sizeof(name2)-1] = 0;
1085 fp=FCEU_fopen(name2,"rb");
1088 FCEU_PrintError("Error opening \"%s\"!",name);
1093 char *p = name2 + strlen(name2) - 4;
1094 if (strcmp(p, ".fcm") == 0)
1097 printf("movie detected\n");
1100 fp=FCEU_fopen(name2,"rb");
1102 printf("no ROM for movie\n");
1109 strcpy(lastLoadedGameName, name2);
1112 if(iNESLoad(name2,fp))
1116 if(FDSLoad(name2,fp))
1118 if(UNIFLoad(name2,fp))
1121 FCEU_PrintError("An error occurred while loading the file.");
1130 if(FCEUGameInfo.type!=GIT_NSF)
1131 if(FSettings.GameGenie)
1136 if(FSettings.NetworkPlay) InitNetplay();
1139 if(FCEUGameInfo.type!=GIT_NSF)
1145 FCEU_ResetPalette();
1149 FCEUI_LoadMovie(name, 1);
1150 return(&FCEUGameInfo);
1154 void FCEU_ResetVidSys(void)
1158 if(FCEUGameInfo.vidsys==GIV_NTSC)
1160 else if(FCEUGameInfo.vidsys==GIV_PAL)
1168 FSettings.FirstSLine=FSettings.UsrFirstSLine[1];
1169 FSettings.LastSLine=FSettings.UsrLastSLine[1];
1174 FSettings.FirstSLine=FSettings.UsrFirstSLine[0];
1175 FSettings.LastSLine=FSettings.UsrLastSLine[0];
1177 printf("PAL = %i\n", PAL);
1178 SetSoundVariables();
1181 int FCEUI_Initialize(void)
1183 if(!InitVirtualVideo())
1185 memset(&FSettings,0,sizeof(FSettings));
1186 FSettings.UsrFirstSLine[0]=8;
1187 FSettings.UsrFirstSLine[1]=0;
1188 FSettings.UsrLastSLine[0]=FSettings.UsrLastSLine[1]=239;
1189 FSettings.SoundVolume=65535; // 100%
1193 static INLINE void Thingo(void)
1197 // check: Battletoads & Double Dragon
1204 // sky glitches in SMB1 if done wrong
1205 X6502_Run(tosprite);
1207 X6502_Run(256-tosprite);
1218 uint32 scanlines_per_frame = PAL ? 312 : 262;
1220 ApplyPeriodicCheats();
1223 if(ppudead) /* Needed for Knight Rider, possibly others. */
1225 memset(XBuf, 0x80, 256*240);
1226 X6502_Run(scanlines_per_frame*(256+85));
1231 //printf("asdc: %i\n", asdc);
1236 PPU[3]=PPUSPL=0; /* Not sure if this is correct. According
1237 to Matt Conte and my own tests, it is. Timing is probably
1238 off, though. NOTE: Not having this here
1239 breaks a Super Donkey Kong game. */
1241 X6502_Run(12); /* I need to figure out the true nature and length
1244 if(FCEUGameInfo.type==GIT_NSF)
1249 // Note: this is needed for asm core
1250 // Warning: using 'scanline' var here breaks Castlevania III
1253 X6502_Run(256+85-12);
1254 for (lines=scanlines_per_frame-242-1;lines;lines--)
1257 // X6502_Run((scanlines_per_frame-242)*(256+85)-12);
1263 if(ScreenON || SpriteON)
1273 if(ScreenON || SpriteON)
1275 RefreshAddr=TempAddr;
1276 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
1284 if(FCEUGameInfo.type==GIT_NSF)
1286 X6502_Run((256+85)*240);
1294 for(scanline=0;scanline<240;) // scanline is incremented in DoLine. Evil. :/
1299 for(x=1,max=0,maxref=0;x<7;x++)
1308 //FCEU_DispMessage("%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x %d",deempcnt[0],deempcnt[1],deempcnt[2],deempcnt[3],deempcnt[4],deempcnt[5],deempcnt[6],deempcnt[7],maxref);
1309 //memset(deempcnt,0,sizeof(deempcnt));
1310 SetNESDeemph(maxref,0);
1317 ssize=FlushEmulateSound();
1319 timestampbase += timestamp;
1325 FCEU_PutImageDummy();
1327 FCEUD_Update(0,WaveFinalMono,ssize);
1333 FCEUD_Update(XBuf+8,WaveFinalMono,ssize);
1347 #include <sys/time.h>
1350 void FCEUI_Emulate(void)
1353 uint64 starttime,end;
1356 gettimeofday(&tv,0);
1357 starttime=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1362 // Probably won't work well on Windows port; for
1363 // debugging/speed testing.
1367 gettimeofday(&tv,0);
1368 end=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1369 w=frcount*10000000000LL/(end-starttime);
1372 printf("Average FPS: %d.%04d\n",i,frac);
1378 void FCEUI_CloseGame(void)
1383 static void ResetPPU(void)
1385 VRAMBuffer=PPU[0]=PPU[1]=PPU[2]=PPU[3]=0;
1388 RefreshAddr=TempAddr=0;
1394 static void PowerPPU(void)
1396 memset(NTARAM,0x00,0x800);
1397 memset(PALRAM,0x00,0x20);
1398 memset(SPRAM,0x00,0x100);
1404 if(!GameLoaded || (FCEUGameInfo.type==GIT_NSF)) return;
1405 GameInterface(GI_RESETM2);
1413 if(!GameLoaded) return;
1415 FCEU_CheatResetRAM();
1416 FCEU_CheatAddRAM(2,0,RAM);
1420 memset(RAM,0x00,0x800);
1422 GameInterface(GI_POWER);
1430 /* savestate stuff */
1431 uint16 TempAddrT,RefreshAddrT;
1433 SFORMAT FCEUPPU_STATEINFO[]={
1434 { NTARAM, 0x800, "NTAR"},
1435 { PALRAM, 0x20, "PRAM"},
1436 { SPRAM, 0x100, "SPRA"},
1437 { PPU, 0x4, "PPUR"},
1438 { &XOffset, 1, "XOFF"},
1439 { &vtoggle, 1, "VTOG"},
1440 { &RefreshAddrT, 2|RLSB, "RADD"},
1441 { &TempAddrT, 2|RLSB, "TADD"},
1442 { &VRAMBuffer, 1, "VBUF"},
1443 { &PPUGenLatch, 1, "PGEN"},
1445 { &kook, 1, "KOOK"},
1446 { &ppudead, 1, "DEAD"},
1447 { &PPUSPL, 1, "PSPL"},