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
57 #include "drivers/gp2x/asmutils.h"
63 static void (*RefreshLine)(uint8 *P, uint32 vofs) = NULL;
64 static void PRefreshLine(void);
66 static void ResetPPU(void);
67 static void PowerPPU(void);
69 uint64 timestampbase=0;
75 uint32 MMC5HackVROMMask;
76 uint8 *MMC5HackExNTARAMPtr;
77 uint8 *MMC5HackVROMPTR;
78 uint8 MMC5HackCHRMode=0;
80 uint8 MMC5HackSPScroll;
83 uint8 *MMC5SPRVPage[8];
84 uint8 *MMC5BGVPage[8];
87 uint8 VRAMBuffer,PPUGenLatch;
93 /* Color deemphasis emulation. Joy... */
95 static int deempcnt[8];
98 void (*GameInterface)(int h, void *param);
100 void FP_FASTAPASS(1) (*PPU_hook)(uint32 A);
102 void (*GameStateRestore)(int version);
103 void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void);
105 readfunc ARead[0x10000];
106 writefunc BWrite[0x10000];
107 static readfunc *AReadG;
108 static writefunc *BWriteG;
112 static void asmcpu_update(int32 cycles)
114 // some code from x6502.c
128 if((PSG[0x10]&0x80) && !(PSG[0x10]&0x40))
130 extern uint8 SIRQStat;
132 X6502_IRQBegin(FCEU_IQDPCM);
138 void asmcpu_unpack(void)
140 nes_registers[0] = X.A << 24;
141 nes_registers[1] = X.X;
142 nes_registers[2] = X.Y;
144 nes_registers[3] = X.PC;
146 nes_registers[4] = X.S << 24;
147 nes_registers[4]|= X.IRQlow << 8;
148 nes_registers[7] = (uint32)X.count << 16;
151 nes_registers[4]|= X.P & 0x5d;
152 nes_registers[5] = X.P << 24; // N
153 if (!(X.P&0x02)) nes_registers[5] |= 1; // Z
156 void asmcpu_pack(void)
158 X.A = nes_registers[0] >> 24;
159 X.X = nes_registers[1];
160 X.Y = nes_registers[2];
161 X.PC= nes_registers[3] - pc_base;
162 X.S = nes_registers[4] >> 24;
163 X.IRQlow = nes_registers[4] >> 8;
164 X.count = (int32) nes_registers[7] >> 16;
167 X.P = nes_registers[4] & 0x5d;
168 if ( nes_registers[5]&0x80000000) X.P |= 0x80; // N
169 if (!(nes_registers[5]&0x000000ff)) X.P |= 0x02; // Z
183 int AllocGenieRW(void)
185 if(!(AReadG=FCEU_malloc(0x8000*sizeof(readfunc))))
187 if(!(BWriteG=FCEU_malloc(0x8000*sizeof(writefunc))))
193 void FlushGenieRW(void)
199 for(x=0;x<0x8000;x++)
201 ARead[x+0x8000]=AReadG[x];
202 BWrite[x+0x8000]=BWriteG[x];
215 readfunc FASTAPASS(1) GetReadHandler(int32 a)
217 if(a>=0x8000 && RWWrap)
218 return AReadG[a-0x8000];
223 void FASTAPASS(3) SetReadHandler(int32 start, int32 end, readfunc func)
231 for(x=end;x>=start;x--)
234 AReadG[x-0x8000]=func;
240 for(x=end;x>=start;x--)
244 writefunc FASTAPASS(1) GetWriteHandler(int32 a)
246 if(RWWrap && a>=0x8000)
247 return BWriteG[a-0x8000];
252 void FASTAPASS(3) SetWriteHandler(int32 start, int32 end, writefunc func)
260 for(x=end;x>=start;x--)
263 BWriteG[x-0x8000]=func;
268 for(x=end;x>=start;x--)
275 uint32 TempAddr,RefreshAddr;
278 /* scanline is equal to the current visible scanline we're on. */
282 uint8 GameMemBlock[131072] __attribute__ ((aligned (4)));
283 uint8 NTARAM[0x800] __attribute__ ((aligned (4)));
284 uint8 PALRAM[0x20] __attribute__ ((aligned (4)));
285 #if !defined(ASM_6502) || defined(DEBUG_ASM_6502)
286 uint8 RAM[0x800] __attribute__ ((aligned (4)));
295 #define MMC5BGVRAMADR(V) &MMC5BGVPage[(V)>>10][(V)]
296 #define VRAMADR(V) &VPage[(V)>>10][(V)]
298 static int linestartts;
301 static uint8 *Plinef;
303 extern uint8 sprlinebuf[256+8];
305 extern uint8 sphitdata;
307 extern int spork; /* spork the world. Any sprites on this line?
308 Then this will be set to 1. Needed for zapper
309 emulation and *gasp* sprite emulation.
312 static void ResetRL(uint8 *target)
314 if(InputScanlineHook)
315 InputScanlineHook(0,0,0,0);
317 linestartts=timestamp*48+X6502_GetCycleCount();
321 static INLINE void Fixit1(void);
323 /* faking FCEUPPU_LineUpdate() from later versions of the emu */
324 static void FakedLineUpdate(void)
326 #define TOFIXNUM (272-0x4)
329 if (scanline >= 240) return;
331 if (tofix || sphitx != 0x100)
333 lastpixel = (timestamp*48-linestartts)>>4;
334 if (PAL) lastpixel += lastpixel>>4;
335 //printf("lastpixel: %i\n", lastpixel);
338 if (tofix && lastpixel>=TOFIXNUM)
350 for(x=sphitx;x<(sphitx+8) && x<l;x++)
352 if((sphitdata&(0x80>>(x-sphitx))) && !(Plinef[x]&64))
391 ret|=PPUGenLatch&0x1F;
395 //dprintf("r [2002] %02x",ret);
410 uint32 tmp=RefreshAddr&0x3FFF;
416 if(PPU_hook) PPU_hook(tmp);
417 PPUGenLatch=VRAMBuffer;
420 VRAMBuffer=VPage[tmp>>10][tmp];
424 VRAMBuffer=vnapage[(tmp>>10)&0x3][tmp&0x3FF];
427 if (INC32) RefreshAddr+=32;
429 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
430 dprintf("r [2007] %02x",ret);
452 //printf("$%04x:$%02x, %d\n",X.PC,V,scanline);
480 //printf("$%02x:$%02x\n",PPUSPL,V);
520 TempAddr|=(V&0x3f)<<8;
527 RefreshAddr=TempAddr;
529 PPU_hook(RefreshAddr);
537 uint32 tmp=RefreshAddr&0x3FFF;
543 PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3f;
544 else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f;
548 if(PPUCHRRAM&(1<<(tmp>>10)))
549 VPage[tmp>>10][tmp]=V;
553 if(PPUNTARAM&(1<<((tmp&0xF00)>>10)))
554 vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V;
556 if (INC32) RefreshAddr+=32;
558 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
567 B2004(0x2004,X.DB=ARead[t+x](t+x));
568 X6502_AddCycles(512);
571 void BGRender(uint8 *target)
574 vofs=((PPU[0]&0x10)<<8) | ((RefreshAddr>>12)&7);
580 RefreshLine(target-XOffset, vofs);
591 *(uint32 *)target=*(uint32 *)(target+4)=tem;
597 void FCEUI_FrameSkip(int x)
603 /* This is called at the beginning of each visible scanline */
604 static void LineUpdate(uint8 *target)
608 if(FSkip || scanline < FSettings.FirstSLine || scanline > FSettings.LastSLine)
624 FCEU_dwmemset(target,tem,256);
628 if(InputScanlineHook)
629 InputScanlineHook(target,spork?sprlinebuf:0,linestartts,256);
633 static void LineUpdateEnd(uint8 *target)
636 if(ScreenON || SpriteON) // Yes, very el-cheapo.
639 block_and(target, 256, 0x30);
642 block_or(target, 256, 0xc0);
644 block_or(target, 256, 0x40);
646 block_andor(target, 256, 0x3f, 0x80);
650 if(ScreenON || SpriteON) // Yes, very el-cheapo.
655 *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])&0x30303030;
661 *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0xc0c0c0c0;
665 *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])|0x40404040;
668 *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0x80808080;
672 ((uint32 *)target)[-2]=((uint32 *)target)[-1]=0;
673 ((uint32 *)target)[64]=((uint32 *)target)[65]=0;
676 #define PAL(c) ((c)+cc)
679 static void PRefreshLine(void)
685 if (BGAdrHI) vofs = 0x1000;
687 vofs+=(RefreshAddr>>12)&7;
693 zz2=(uint8)((RefreshAddr>>10)&3);
694 PPU_hook(0x2000|(RefreshAddr&0xFFF));
695 no = vnapage[zz2][(RefreshAddr&0x3ff)];
696 PPU_hook((no<<4)+vofs);
697 if((RefreshAddr&0x1f)==0x1f)
704 /* This high-level graphics MMC5 emulation code was written
705 for MMC5 carts in "CL" mode. It's probably not totally
706 correct for carts in "SL" mode.
708 static void RefreshLine_MMC5Hack1(uint8 *P, uint32 vofs)
712 tochange=MMC5HackSPMode&0x1F;
714 for(X1=33;X1;X1--,P+=8)
720 if((tochange<=0 && MMC5HackSPMode&0x40) ||
721 (tochange>0 && !(MMC5HackSPMode&0x40)))
726 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
727 if(ys>=0x1E) ys-=0x1E;
728 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
730 C = MMC5HackVROMPTR+vadr;
731 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
733 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
734 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
739 zz2=(RefreshAddr>>10)&3;
740 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
741 C = MMC5BGVRAMADR(vadr);
742 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
743 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
747 if((RefreshAddr&0x1f)==0x1f)
755 static void RefreshLine_MMC5Hack2(uint8 *P, uint32 vofs)
759 tochange=MMC5HackSPMode&0x1F;
761 for(X1=33;X1;X1--,P+=8)
768 if((tochange<=0 && MMC5HackSPMode&0x40) ||
769 (tochange>0 && !(MMC5HackSPMode&0x40)))
774 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
775 if(ys>=0x1E) ys-=0x1E;
776 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
778 C = MMC5HackVROMPTR+vadr;
779 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
781 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
782 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
787 zz2=(RefreshAddr>>10)&3;
788 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
789 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
790 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
791 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
795 if((RefreshAddr&0x1f)==0x1f)
803 static void RefreshLine_MMC5Hack3(uint8 *P, uint32 vofs)
807 for(X1=33;X1;X1--,P+=8)
815 zz2=(RefreshAddr>>10)&3;
816 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
817 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
818 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
819 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
823 if((RefreshAddr&0x1f)==0x1f)
830 static void RefreshLine_MMC5Hack4(uint8 *P, uint32 vofs)
834 for(X1=33;X1;X1--,P+=8)
841 zz2=(RefreshAddr>>10)&3;
842 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
843 C = MMC5BGVRAMADR(vadr);
844 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
845 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
849 if((RefreshAddr&0x1f)==0x1f)
856 static void RefreshLine_PPU_hook(uint8 *P, uint32 vofs)
860 for(X1=33;X1;X1--,P+=8)
867 zz2=(RefreshAddr>>10)&3;
868 PPU_hook(0x2000|(RefreshAddr&0xFFF));
869 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
870 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
871 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
878 if((RefreshAddr&0x1f)==0x1f)
885 static void RefreshLine_normal(uint8 *P, uint32 vofs) // vofs is 0x107 max
888 uint32 rfraddr = RefreshAddr;
889 uint8 *page = vnapage[(rfraddr>>10)&3];
892 if ((rfraddr&0xc)!=0)
893 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
895 for (X1=33;X1;X1--,P+=8)
900 vadr=(page[rfraddr&0x3ff]<<4)+vofs;
902 if ((rfraddr&0xc)==0)
903 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
904 cc=((cc2 >> ((rfraddr&2) + ((rfraddr&0x40)>>4) + ((rfraddr&0xc)<<1))) & 3) << 2;
908 if((rfraddr&0x1f)==0x1f) {
910 page = vnapage[(rfraddr>>10)&3];
914 RefreshAddr = rfraddr;
917 static void SetRefreshLine(void)
919 if(MMC5Hack && geniestage!=1)
921 if(MMC5HackCHRMode==0 && (MMC5HackSPMode&0x80))
923 if (RefreshLine != RefreshLine_MMC5Hack1) printf("set refr RefreshLine_MMC5Hack1\n");
924 RefreshLine = RefreshLine_MMC5Hack1;
926 else if(MMC5HackCHRMode==1 && (MMC5HackSPMode&0x80))
928 if (RefreshLine != RefreshLine_MMC5Hack2) printf("set refr RefreshLine_MMC5Hack2\n");
929 RefreshLine = RefreshLine_MMC5Hack2;
931 else if(MMC5HackCHRMode==1)
933 if (RefreshLine != RefreshLine_MMC5Hack3) printf("set refr RefreshLine_MMC5Hack3\n");
934 RefreshLine = RefreshLine_MMC5Hack3;
938 if (RefreshLine != RefreshLine_MMC5Hack4) printf("set refr RefreshLine_MMC5Hack4\n");
939 RefreshLine = RefreshLine_MMC5Hack4;
941 } // End if(MMC5Hack)
944 if (RefreshLine != RefreshLine_PPU_hook) printf("set refr RefreshLine_PPU_hook\n");
945 RefreshLine = RefreshLine_PPU_hook;
949 if (RefreshLine != RefreshLine_normal) printf("set refr RefreshLine_normal\n");
950 RefreshLine = RefreshLine_normal;
957 if(ScreenON || SpriteON)
959 uint32 rad=RefreshAddr;
961 rad|=TempAddr&0x041f;
963 //PPU_hook(RefreshAddr,-1);
970 if(ScreenON || SpriteON)
972 uint32 rad=RefreshAddr;
974 if((rad&0x7000)==0x7000)
977 if((rad&0x3E0)==0x3A0)
984 if((rad&0x3E0)==0x3e0)
992 //PPU_hook(RefreshAddr,-1);
997 // ============================//
999 // ===========================//
1001 void ResetMapping(void)
1005 SetReadHandler(0x0000,0xFFFF,ANull);
1006 SetWriteHandler(0x0000,0xFFFF,BNull);
1008 SetReadHandler(0,0x7FF,ARAML);
1009 SetWriteHandler(0,0x7FF,BRAML);
1011 SetReadHandler(0x800,0x1FFF,ARAMH); /* Part of a little */
1012 SetWriteHandler(0x800,0x1FFF,BRAMH); /* hack for a small speed boost. */
1014 for(x=0x2000;x<0x4000;x+=8)
1034 BWrite[0x4014]=B4014;
1040 void CloseGame(void)
1045 if(FCEUGameInfo.type!=GIT_NSF)
1046 FCEU_FlushGameCheats(0,0);
1048 if(FSettings.NetworkPlay) KillNetplay();
1050 GameInterface(GI_CLOSE, 0);
1056 void ResetGameLoaded(void)
1058 if(GameLoaded) CloseGame();
1061 GameHBIRQHook=GameHBIRQHook2=0;
1062 GameExpSound.Fill=0;
1063 GameExpSound.RChange=0;
1064 if(GameExpSound.Kill)
1065 GameExpSound.Kill();
1066 GameExpSound.Kill=0;
1072 FCEUGameInfo.name=0;
1073 FCEUGameInfo.type=GIT_CART;
1074 FCEUGameInfo.vidsys=GIV_USER;
1075 FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=-1;
1076 FCEUGameInfo.inputfc=-1;
1079 char lastLoadedGameName [2048];
1080 int LoadGameLastError = 0;
1081 int UNIFLoad(const char *name, int fp);
1082 int iNESLoad(const char *name, int fp);
1083 int FDSLoad(const char *name, int fp);
1084 int NSFLoad(int fp);
1086 FCEUGI *FCEUI_LoadGame(char *name)
1093 LoadGameLastError = 0;
1096 strncpy(name2, name, sizeof(name2));
1097 name2[sizeof(name2)-1] = 0;
1099 fp=FCEU_fopen(name2,"rb");
1102 FCEU_PrintError("Error opening \"%s\"!",name);
1103 LoadGameLastError = 1;
1108 char *p = name2 + strlen(name2) - 4;
1109 if (strcmp(p, ".fcm") == 0)
1112 printf("movie detected\n");
1115 fp=FCEU_fopen(name2,"rb");
1116 if (!fp && p - name2 > 2) p[-2] = 0;
1117 fp=FCEU_fopen(name2,"rb");
1119 printf("no ROM for movie\n");
1120 LoadGameLastError = 2;
1128 if(iNESLoad(name2,fp))
1132 if(FDSLoad(name2,fp))
1134 if(UNIFLoad(name2,fp))
1137 FCEU_PrintError("An error occurred while loading the file.");
1139 // format handlers may set LoadGameLastError themselves.
1140 if (LoadGameLastError == 0) LoadGameLastError = 3;
1148 if(FCEUGameInfo.type!=GIT_NSF)
1149 if(FSettings.GameGenie)
1154 if(FSettings.NetworkPlay) InitNetplay();
1157 if(FCEUGameInfo.type!=GIT_NSF)
1159 FCEU_LoadGamePalette();
1160 FCEU_LoadGameCheats(0);
1163 FCEU_ResetPalette();
1167 FCEUI_LoadMovie(name, 1);
1169 strcpy(lastLoadedGameName, name2);
1171 return(&FCEUGameInfo);
1175 void FCEU_ResetVidSys(void)
1179 if(FCEUGameInfo.vidsys==GIV_NTSC)
1181 else if(FCEUGameInfo.vidsys==GIV_PAL)
1189 FSettings.FirstSLine=FSettings.UsrFirstSLine[1];
1190 FSettings.LastSLine=FSettings.UsrLastSLine[1];
1195 FSettings.FirstSLine=FSettings.UsrFirstSLine[0];
1196 FSettings.LastSLine=FSettings.UsrLastSLine[0];
1198 printf("ResetVidSys: PAL = %i\n", PAL);
1199 SetSoundVariables();
1202 int FCEUI_Initialize(void)
1204 if(!InitVirtualVideo())
1206 memset(&FSettings,0,sizeof(FSettings));
1207 FSettings.UsrFirstSLine[0]=8;
1208 FSettings.UsrFirstSLine[1]=0;
1209 FSettings.UsrLastSLine[0]=FSettings.UsrLastSLine[1]=239;
1210 FSettings.SoundVolume=100;
1214 void MMC5_hb(int); /* Ugh ugh ugh. */
1215 static void DoLine(void)
1217 uint8 *target=XBuf+scanline*320+32;
1221 if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
1225 // check: Battletoads & Double Dragon, Addams Family
1226 // sky glitches in SMB1 if done wrong
1232 if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine)
1234 if(SpriteON && spork)
1235 CopySprites(target);
1237 LineUpdateEnd(target);
1241 if(ScreenON || SpriteON)
1245 if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18))
1251 X6502_Run(85-10-16);
1255 X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
1262 if(GameHBIRQHook2 && (ScreenON || SpriteON))
1266 ResetRL(XBuf+scanline*320+32);
1276 uint32 scanlines_per_frame = PAL ? 312 : 262;
1278 FCEU_ApplyPeriodicCheats();
1281 if(ppudead) /* Needed for Knight Rider, possibly others. */
1283 //memset(XBuf, 0, 320*240);
1284 X6502_Run(scanlines_per_frame*(256+85));
1292 PPU[3]=PPUSPL=0; /* Not sure if this is correct. According
1293 to Matt Conte and my own tests, it is. Timing is probably
1294 off, though. NOTE: Not having this here
1295 breaks a Super Donkey Kong game. */
1297 X6502_Run(12); /* I need to figure out the true nature and length
1300 if(FCEUGameInfo.type==GIT_NSF)
1305 // Note: this is needed for asm core
1306 // Warning: using 'scanline' var here breaks Castlevania III
1309 X6502_Run(256+85-12);
1310 for (lines=scanlines_per_frame-242-1;lines;lines--)
1313 // X6502_Run((scanlines_per_frame-242)*(256+85)-12);
1318 if(ScreenON || SpriteON)
1323 for(x=0;x<42;x++) {PPU_hook(0x2000); PPU_hook(0);} // ugh
1330 if(ScreenON || SpriteON)
1332 RefreshAddr=TempAddr;
1333 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
1342 if(FCEUGameInfo.type==GIT_NSF)
1344 // run scanlines for asm core to fuction
1345 for(scanline=0;scanline<240;scanline++)
1354 for(scanline=0;scanline<240;) // scanline is incremented in DoLine. Evil. :/
1359 if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
1360 for(x=1,max=0,maxref=0;x<7;x++)
1369 SetNESDeemph(maxref,0);
1376 ssize=FlushEmulateSound();
1378 timestampbase += timestamp;
1384 FCEU_PutImageDummy();
1386 FCEUD_Update(0,WaveFinalMono,ssize);
1392 FCEUD_Update(XBuf+8,WaveFinalMono,ssize);
1406 #include <sys/time.h>
1409 void FCEUI_Emulate(void)
1412 uint64 starttime,end;
1415 gettimeofday(&tv,0);
1416 starttime=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1421 // Probably won't work well on Windows port; for
1422 // debugging/speed testing.
1426 gettimeofday(&tv,0);
1427 end=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1428 w=frcount*10000000000LL/(end-starttime);
1431 printf("Average FPS: %d.%04d\n",i,frac);
1437 void FCEUI_CloseGame(void)
1442 static void ResetPPU(void)
1444 VRAMBuffer=PPU[0]=PPU[1]=PPU[2]=PPU[3]=0;
1447 RefreshAddr=TempAddr=0;
1453 static void PowerPPU(void)
1455 memset(NTARAM,0x00,0x800);
1456 memset(PALRAM,0x00,0x20);
1457 memset(SPRAM,0x00,0x100);
1463 if(!GameLoaded) return;
1464 GameInterface(GI_RESETM2, 0);
1470 static void FCEU_MemoryRand(uint8 *ptr, uint32 size)
1475 *ptr=(x&4)?0xFF:0x00;
1484 if(!GameLoaded) return;
1486 FCEU_CheatResetRAM();
1487 FCEU_CheatAddRAM(2,0,RAM);
1491 #ifndef DEBUG_ASM_6502
1492 FCEU_MemoryRand(RAM,0x800);
1494 memset(RAM,0x00,0x800);
1497 GameInterface(GI_POWER, 0);
1509 /* savestate stuff */
1510 uint16 TempAddrT,RefreshAddrT;
1512 SFORMAT FCEUPPU_STATEINFO[]={
1513 { NTARAM, 0x800, "NTAR"},
1514 { PALRAM, 0x20, "PRAM"},
1515 { SPRAM, 0x100, "SPRA"},
1516 { PPU, 0x4, "PPUR"},
1517 { &XOffset, 1, "XOFF"},
1518 { &vtoggle, 1, "VTOG"},
1519 { &RefreshAddrT, 2|RLSB, "RADD"},
1520 { &TempAddrT, 2|RLSB, "TADD"},
1521 { &VRAMBuffer, 1, "VBUF"},
1522 { &PPUGenLatch, 1, "PGEN"},
1524 { &kook, 1, "KOOK"},
1525 { &ppudead, 1, "DEAD"},
1526 { &PPUSPL, 1, "PSPL"},