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];
100 void (*GameInterface)(int h);
102 void FP_FASTAPASS(1) (*PPU_hook)(uint32 A);
104 void (*GameStateRestore)(int version);
105 void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void);
107 readfunc ARead[0x10000];
108 writefunc BWrite[0x10000];
109 static readfunc *AReadG;
110 static writefunc *BWriteG;
114 static void asmcpu_update(int32 cycles)
116 // some code from x6502.c
130 if((PSG[0x10]&0x80) && !(PSG[0x10]&0x40))
132 extern uint8 SIRQStat;
134 X6502_IRQBegin(FCEU_IQDPCM);
140 void asmcpu_unpack(void)
142 nes_registers[0] = X.A << 24;
143 nes_registers[1] = X.X;
144 nes_registers[2] = X.Y;
146 nes_registers[3] = X.PC;
148 nes_registers[4] = X.S << 24;
149 nes_registers[4]|= X.IRQlow << 8;
150 nes_registers[7] = (uint32)X.count << 16;
153 nes_registers[4]|= X.P & 0x5d;
154 nes_registers[5] = X.P << 24; // N
155 if (!(X.P&0x02)) nes_registers[5] |= 1; // Z
158 void asmcpu_pack(void)
160 X.A = nes_registers[0] >> 24;
161 X.X = nes_registers[1];
162 X.Y = nes_registers[2];
163 X.PC= nes_registers[3] - pc_base;
164 X.S = nes_registers[4] >> 24;
165 X.IRQlow = nes_registers[4] >> 8;
166 X.count = (int32) nes_registers[7] >> 16;
169 X.P = nes_registers[4] & 0x5d;
170 if ( nes_registers[5]&0x80000000) X.P |= 0x80; // N
171 if (!(nes_registers[5]&0x000000ff)) X.P |= 0x02; // Z
185 int AllocGenieRW(void)
187 if(!(AReadG=FCEU_malloc(0x8000*sizeof(readfunc))))
189 if(!(BWriteG=FCEU_malloc(0x8000*sizeof(writefunc))))
195 void FlushGenieRW(void)
201 for(x=0;x<0x8000;x++)
203 ARead[x+0x8000]=AReadG[x];
204 BWrite[x+0x8000]=BWriteG[x];
217 readfunc FASTAPASS(1) GetReadHandler(int32 a)
219 if(a>=0x8000 && RWWrap)
220 return AReadG[a-0x8000];
225 void FASTAPASS(3) SetReadHandler(int32 start, int32 end, readfunc func)
233 for(x=end;x>=start;x--)
236 AReadG[x-0x8000]=func;
242 for(x=end;x>=start;x--)
246 writefunc FASTAPASS(1) GetWriteHandler(int32 a)
248 if(RWWrap && a>=0x8000)
249 return BWriteG[a-0x8000];
254 void FASTAPASS(3) SetWriteHandler(int32 start, int32 end, writefunc func)
262 for(x=end;x>=start;x--)
265 BWriteG[x-0x8000]=func;
270 for(x=end;x>=start;x--)
277 uint32 TempAddr,RefreshAddr;
280 /* scanline is equal to the current visible scanline we're on. */
284 uint8 GameMemBlock[131072] __attribute__ ((aligned (4)));
285 uint8 NTARAM[0x800] __attribute__ ((aligned (4)));
286 uint8 PALRAM[0x20] __attribute__ ((aligned (4)));
287 #if !defined(ASM_6502) || defined(DEBUG_ASM_6502)
288 uint8 RAM[0x800] __attribute__ ((aligned (4)));
297 #define MMC5BGVRAMADR(V) &MMC5BGVPage[(V)>>10][(V)]
298 #define VRAMADR(V) &VPage[(V)>>10][(V)]
300 static int linestartts;
303 static void ResetRL(void)
305 linestartts=timestamp*48+X6502_GetCycleCount();
309 static INLINE void Fixit1(void);
311 static void TryFixit1(void)
313 #define TOFIXNUM (272-0x4)
316 if (scanline < 240 && tofix)
318 lastpixel = (timestamp*48-linestartts)>>4;
319 if (PAL) lastpixel += lastpixel>>4;
321 //printf("lastpixel: %i\n", lastpixel);
323 if(lastpixel>=TOFIXNUM)
360 ret|=PPUGenLatch&0x1F;
364 //dprintf("r [2002] %02x",ret);
379 uint32 tmp=RefreshAddr&0x3FFF;
385 if(PPU_hook) PPU_hook(tmp);
386 PPUGenLatch=VRAMBuffer;
389 VRAMBuffer=VPage[tmp>>10][tmp];
393 VRAMBuffer=vnapage[(tmp>>10)&0x3][tmp&0x3FF];
396 if (INC32) RefreshAddr+=32;
398 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
399 dprintf("r [2007] %02x",ret);
421 //printf("$%04x:$%02x, %d\n",X.PC,V,scanline);
449 //printf("$%02x:$%02x\n",PPUSPL,V);
489 TempAddr|=(V&0x3f)<<8;
496 RefreshAddr=TempAddr;
498 PPU_hook(RefreshAddr);
506 uint32 tmp=RefreshAddr&0x3FFF;
512 PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3f;
513 else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f;
517 if(PPUCHRRAM&(1<<(tmp>>10)))
518 VPage[tmp>>10][tmp]=V;
522 if(PPUNTARAM&(1<<((tmp&0xF00)>>10)))
523 vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V;
525 if (INC32) RefreshAddr+=32;
527 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
536 B2004(0x2004,X.DB=ARead[t+x](t+x));
537 X6502_AddCycles(512);
540 void BGRender(uint8 *target)
543 vofs=((PPU[0]&0x10)<<8) | ((RefreshAddr>>12)&7);
549 RefreshLine(target-XOffset, vofs);
560 *(uint32 *)target=*(uint32 *)(target+4)=tem;
566 void FCEUI_FrameSkip(int x)
572 /* This is called at the beginning of each visible scanline */
573 static void Loop6502(void)
577 uint8 *target=XBuf+scanline*320+32;
579 if(ScreenON || SpriteON)
581 /* PRefreshLine() will not get called on skipped frames. This
582 could cause a problem, but the solution would be rather complex,
583 due to the current sprite 0 hit code.
591 if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine)
601 tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
603 FCEU_dwmemset(target,tem,264);
608 if (SpriteON && scanline)
609 RefreshSprite(target);
617 ((uint32 *)target)[x]=((uint32*)target)[x]&0xF0F0F0F0;
620 if((PPU[1]>>5)==0x7) block_or(target, 256, 0xc0);
621 else if(PPU[1]&0xE0) block_andor(target, 256, 0x3f, 0x40);
622 else block_andor(target, 256, 0x3f, 0x80);
626 ((uint32 *)target)[x]=(((uint32*)target)[x])|0xc0c0c0c0;
629 ((uint32 *)target)[x]=(((uint32*)target)[x]&0x3f3f3f3f)|0x40404040;
632 ((uint32 *)target)[x]=(((uint32*)target)[x]&0x3f3f3f3f)|0x80808080;
635 ((uint32 *)target)[-2]=((uint32 *)target)[-1]=0;
636 ((uint32 *)target)[64]=((uint32 *)target)[65]=0;
643 tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
644 FCEU_dwmemset(target,tem,256);
646 if(InputScanlineHook)
647 InputScanlineHook(target, scanline);
650 #define PAL(c) ((c)+cc)
653 static void PRefreshLine(void)
659 if (BGAdrHI) vofs = 0x1000;
661 vofs+=(RefreshAddr>>12)&7;
667 zz2=(uint8)((RefreshAddr>>10)&3);
668 PPU_hook(0x2000|(RefreshAddr&0xFFF));
669 no = vnapage[zz2][(RefreshAddr&0x3ff)];
670 PPU_hook((no<<4)+vofs);
671 if((RefreshAddr&0x1f)==0x1f)
678 /* This high-level graphics MMC5 emulation code was written
679 for MMC5 carts in "CL" mode. It's probably not totally
680 correct for carts in "SL" mode.
682 static void RefreshLine_MMC5Hack1(uint8 *P, uint32 vofs)
686 tochange=MMC5HackSPMode&0x1F;
688 for(X1=33;X1;X1--,P+=8)
694 if((tochange<=0 && MMC5HackSPMode&0x40) ||
695 (tochange>0 && !(MMC5HackSPMode&0x40)))
700 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
701 if(ys>=0x1E) ys-=0x1E;
702 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
704 C = MMC5HackVROMPTR+vadr;
705 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
707 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
708 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
713 zz2=(RefreshAddr>>10)&3;
714 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
715 C = MMC5BGVRAMADR(vadr);
716 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
717 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
721 if((RefreshAddr&0x1f)==0x1f)
729 static void RefreshLine_MMC5Hack2(uint8 *P, uint32 vofs)
733 tochange=MMC5HackSPMode&0x1F;
735 for(X1=33;X1;X1--,P+=8)
742 if((tochange<=0 && MMC5HackSPMode&0x40) ||
743 (tochange>0 && !(MMC5HackSPMode&0x40)))
748 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
749 if(ys>=0x1E) ys-=0x1E;
750 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
752 C = MMC5HackVROMPTR+vadr;
753 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
755 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
756 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
761 zz2=(RefreshAddr>>10)&3;
762 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
763 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
764 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
765 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
769 if((RefreshAddr&0x1f)==0x1f)
777 static void RefreshLine_MMC5Hack3(uint8 *P, uint32 vofs)
781 for(X1=33;X1;X1--,P+=8)
789 zz2=(RefreshAddr>>10)&3;
790 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
791 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
792 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
793 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
797 if((RefreshAddr&0x1f)==0x1f)
804 static void RefreshLine_MMC5Hack4(uint8 *P, uint32 vofs)
808 for(X1=33;X1;X1--,P+=8)
815 zz2=(RefreshAddr>>10)&3;
816 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
817 C = MMC5BGVRAMADR(vadr);
818 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
819 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
823 if((RefreshAddr&0x1f)==0x1f)
830 static void RefreshLine_PPU_hook(uint8 *P, uint32 vofs)
834 for(X1=33;X1;X1--,P+=8)
841 zz2=(RefreshAddr>>10)&3;
842 PPU_hook(0x2000|(RefreshAddr&0xFFF));
843 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
844 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
845 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
852 if((RefreshAddr&0x1f)==0x1f)
859 static void RefreshLine_normal(uint8 *P, uint32 vofs) // vofs is 0x107 max
862 uint32 rfraddr = RefreshAddr;
863 uint8 *page = vnapage[(rfraddr>>10)&3];
866 if ((rfraddr&0xc)!=0)
867 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
869 for (X1=33;X1;X1--,P+=8)
874 vadr=(page[rfraddr&0x3ff]<<4)+vofs;
876 if ((rfraddr&0xc)==0)
877 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
878 cc=((cc2 >> ((rfraddr&2) + ((rfraddr&0x40)>>4) + ((rfraddr&0xc)<<1))) & 3) << 2;
882 if((rfraddr&0x1f)==0x1f) {
884 page = vnapage[(rfraddr>>10)&3];
888 RefreshAddr = rfraddr;
891 static void SetRefreshLine(void)
893 if(MMC5Hack && geniestage!=1)
895 if(MMC5HackCHRMode==0 && (MMC5HackSPMode&0x80))
897 if (RefreshLine != RefreshLine_MMC5Hack1) printf("set refr RefreshLine_MMC5Hack1\n");
898 RefreshLine = RefreshLine_MMC5Hack1;
900 else if(MMC5HackCHRMode==1 && (MMC5HackSPMode&0x80))
902 if (RefreshLine != RefreshLine_MMC5Hack2) printf("set refr RefreshLine_MMC5Hack2\n");
903 RefreshLine = RefreshLine_MMC5Hack2;
905 else if(MMC5HackCHRMode==1)
907 if (RefreshLine != RefreshLine_MMC5Hack3) printf("set refr RefreshLine_MMC5Hack3\n");
908 RefreshLine = RefreshLine_MMC5Hack3;
912 if (RefreshLine != RefreshLine_MMC5Hack4) printf("set refr RefreshLine_MMC5Hack4\n");
913 RefreshLine = RefreshLine_MMC5Hack4;
915 } // End if(MMC5Hack)
918 if (RefreshLine != RefreshLine_PPU_hook) printf("set refr RefreshLine_PPU_hook\n");
919 RefreshLine = RefreshLine_PPU_hook;
923 if (RefreshLine != RefreshLine_normal) printf("set refr RefreshLine_normal\n");
924 RefreshLine = RefreshLine_normal;
931 if(ScreenON || SpriteON)
933 uint32 rad=RefreshAddr;
935 rad|=TempAddr&0x041f;
937 //PPU_hook(RefreshAddr,-1);
944 if(ScreenON || SpriteON)
946 uint32 rad=RefreshAddr;
948 if((rad&0x7000)==0x7000)
951 if((rad&0x3E0)==0x3A0)
958 if((rad&0x3E0)==0x3e0)
966 //PPU_hook(RefreshAddr,-1);
971 /* This is called at the beginning of all h-blanks on visible lines. */
972 static void DoHBlank(void)
974 if(ScreenON || SpriteON)
976 if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18))
986 X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
990 if(GameHBIRQHook2 && (ScreenON || SpriteON))
993 //fprintf(stderr,"%3d: $%04x\n",scanline,RefreshAddr);
1001 // ============================//
1003 // ===========================//
1005 void ResetMapping(void)
1009 SetReadHandler(0x0000,0xFFFF,ANull);
1010 SetWriteHandler(0x0000,0xFFFF,BNull);
1012 SetReadHandler(0,0x7FF,ARAML);
1013 SetWriteHandler(0,0x7FF,BRAML);
1015 SetReadHandler(0x800,0x1FFF,ARAMH); /* Part of a little */
1016 SetWriteHandler(0x800,0x1FFF,BRAMH); /* hack for a small speed boost. */
1018 for(x=0x2000;x<0x4000;x+=8)
1038 BWrite[0x4014]=B4014;
1044 void CloseGame(void)
1048 if(FCEUGameInfo.type!=GIT_NSF)
1049 FCEU_FlushGameCheats(0,0);
1051 if(FSettings.NetworkPlay) KillNetplay();
1053 GameInterface(GI_CLOSE);
1059 void ResetGameLoaded(void)
1061 if(GameLoaded) CloseGame();
1064 GameHBIRQHook=GameHBIRQHook2=0;
1065 GameExpSound.Fill=0;
1066 GameExpSound.RChange=0;
1067 if(GameExpSound.Kill)
1068 GameExpSound.Kill();
1069 GameExpSound.Kill=0;
1075 FCEUGameInfo.name=0;
1076 FCEUGameInfo.type=GIT_CART;
1077 FCEUGameInfo.vidsys=GIV_USER;
1078 FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=-1;
1079 FCEUGameInfo.inputfc=-1;
1082 char lastLoadedGameName [2048];
1083 int LoadGameLastError = 0;
1084 int UNIFLoad(const char *name, int fp);
1085 int iNESLoad(const char *name, int fp);
1086 int FDSLoad(const char *name, int fp);
1087 int NSFLoad(int fp);
1089 FCEUGI *FCEUI_LoadGame(char *name)
1096 LoadGameLastError = 0;
1099 strncpy(name2, name, sizeof(name2));
1100 name2[sizeof(name2)-1] = 0;
1102 fp=FCEU_fopen(name2,"rb");
1105 FCEU_PrintError("Error opening \"%s\"!",name);
1106 LoadGameLastError = 1;
1111 char *p = name2 + strlen(name2) - 4;
1112 if (strcmp(p, ".fcm") == 0)
1115 printf("movie detected\n");
1118 fp=FCEU_fopen(name2,"rb");
1119 if (!fp && p - name2 > 2) p[-2] = 0;
1120 fp=FCEU_fopen(name2,"rb");
1122 printf("no ROM for movie\n");
1123 LoadGameLastError = 2;
1131 if(iNESLoad(name2,fp))
1135 if(FDSLoad(name2,fp))
1137 if(UNIFLoad(name2,fp))
1140 FCEU_PrintError("An error occurred while loading the file.");
1142 // format handlers may set LoadGameLastError themselves.
1143 if (LoadGameLastError == 0) LoadGameLastError = 3;
1151 if(FCEUGameInfo.type!=GIT_NSF)
1152 if(FSettings.GameGenie)
1157 if(FSettings.NetworkPlay) InitNetplay();
1160 if(FCEUGameInfo.type!=GIT_NSF)
1162 FCEU_LoadGamePalette();
1163 FCEU_LoadGameCheats(0);
1166 FCEU_ResetPalette();
1170 FCEUI_LoadMovie(name, 1);
1172 strcpy(lastLoadedGameName, name2);
1174 return(&FCEUGameInfo);
1178 void FCEU_ResetVidSys(void)
1182 if(FCEUGameInfo.vidsys==GIV_NTSC)
1184 else if(FCEUGameInfo.vidsys==GIV_PAL)
1192 FSettings.FirstSLine=FSettings.UsrFirstSLine[1];
1193 FSettings.LastSLine=FSettings.UsrLastSLine[1];
1198 FSettings.FirstSLine=FSettings.UsrFirstSLine[0];
1199 FSettings.LastSLine=FSettings.UsrLastSLine[0];
1201 printf("ResetVidSys: PAL = %i\n", PAL);
1202 SetSoundVariables();
1205 int FCEUI_Initialize(void)
1207 if(!InitVirtualVideo())
1209 memset(&FSettings,0,sizeof(FSettings));
1210 FSettings.UsrFirstSLine[0]=8;
1211 FSettings.UsrFirstSLine[1]=0;
1212 FSettings.UsrLastSLine[0]=FSettings.UsrLastSLine[1]=239;
1213 FSettings.SoundVolume=100;
1217 void MMC5_hb(int); /* Ugh ugh ugh. */
1218 static INLINE void Thingo(void)
1222 if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
1224 // check: Battletoads & Double Dragon
1231 // sky glitches in SMB1 if done wrong
1232 X6502_Run(tosprite);
1234 X6502_Run(256-tosprite);
1246 uint32 scanlines_per_frame = PAL ? 312 : 262;
1248 FCEU_ApplyPeriodicCheats();
1251 if(ppudead) /* Needed for Knight Rider, possibly others. */
1253 //memset(XBuf, 0, 320*240);
1254 X6502_Run(scanlines_per_frame*(256+85));
1262 PPU[3]=PPUSPL=0; /* Not sure if this is correct. According
1263 to Matt Conte and my own tests, it is. Timing is probably
1264 off, though. NOTE: Not having this here
1265 breaks a Super Donkey Kong game. */
1267 X6502_Run(12); /* I need to figure out the true nature and length
1270 if(FCEUGameInfo.type==GIT_NSF)
1275 // Note: this is needed for asm core
1276 // Warning: using 'scanline' var here breaks Castlevania III
1279 X6502_Run(256+85-12);
1280 for (lines=scanlines_per_frame-242-1;lines;lines--)
1283 // X6502_Run((scanlines_per_frame-242)*(256+85)-12);
1288 if(ScreenON || SpriteON)
1293 for(x=0;x<42;x++) {PPU_hook(0x2000); PPU_hook(0);} // ugh
1300 if(ScreenON || SpriteON)
1302 RefreshAddr=TempAddr;
1303 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
1311 if(FCEUGameInfo.type==GIT_NSF)
1313 // run scanlines for asm core to fuction
1314 for(scanline=0;scanline<240;scanline++)
1323 for(scanline=0;scanline<240;) // scanline is incremented in DoLine. Evil. :/
1328 if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
1329 for(x=1,max=0,maxref=0;x<7;x++)
1338 SetNESDeemph(maxref,0);
1345 ssize=FlushEmulateSound();
1347 timestampbase += timestamp;
1353 FCEU_PutImageDummy();
1355 FCEUD_Update(0,WaveFinalMono,ssize);
1361 FCEUD_Update(XBuf+8,WaveFinalMono,ssize);
1375 #include <sys/time.h>
1378 void FCEUI_Emulate(void)
1381 uint64 starttime,end;
1384 gettimeofday(&tv,0);
1385 starttime=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1390 // Probably won't work well on Windows port; for
1391 // debugging/speed testing.
1395 gettimeofday(&tv,0);
1396 end=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1397 w=frcount*10000000000LL/(end-starttime);
1400 printf("Average FPS: %d.%04d\n",i,frac);
1406 void FCEUI_CloseGame(void)
1411 static void ResetPPU(void)
1413 VRAMBuffer=PPU[0]=PPU[1]=PPU[2]=PPU[3]=0;
1416 RefreshAddr=TempAddr=0;
1422 static void PowerPPU(void)
1424 memset(NTARAM,0x00,0x800);
1425 memset(PALRAM,0x00,0x20);
1426 memset(SPRAM,0x00,0x100);
1432 if(!GameLoaded) return;
1433 GameInterface(GI_RESETM2);
1439 static void FCEU_MemoryRand(uint8 *ptr, uint32 size)
1444 *ptr=(x&4)?0xFF:0x00;
1453 if(!GameLoaded) return;
1455 FCEU_CheatResetRAM();
1456 FCEU_CheatAddRAM(2,0,RAM);
1460 #ifndef DEBUG_ASM_6502
1461 FCEU_MemoryRand(RAM,0x800);
1463 memset(RAM,0x00,0x800);
1466 GameInterface(GI_POWER);
1478 /* savestate stuff */
1479 uint16 TempAddrT,RefreshAddrT;
1481 SFORMAT FCEUPPU_STATEINFO[]={
1482 { NTARAM, 0x800, "NTAR"},
1483 { PALRAM, 0x20, "PRAM"},
1484 { SPRAM, 0x100, "SPRA"},
1485 { PPU, 0x4, "PPUR"},
1486 { &XOffset, 1, "XOFF"},
1487 { &vtoggle, 1, "VTOG"},
1488 { &RefreshAddrT, 2|RLSB, "RADD"},
1489 { &TempAddrT, 2|RLSB, "TADD"},
1490 { &VRAMBuffer, 1, "VBUF"},
1491 { &PPUGenLatch, 1, "PGEN"},
1493 { &kook, 1, "KOOK"},
1494 { &ppudead, 1, "DEAD"},
1495 { &PPUSPL, 1, "PSPL"},