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;
565 int FSkip_setting=-1; // auto
567 void FCEUI_FrameSkip(int x)
573 /* This is called at the beginning of each visible scanline */
574 static void Loop6502(void)
578 uint8 *target=XBuf+scanline*320+32;
580 if(ScreenON || SpriteON)
582 /* PRefreshLine() will not get called on skipped frames. This
583 could cause a problem, but the solution would be rather complex,
584 due to the current sprite 0 hit code.
592 if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine)
602 tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
604 FCEU_dwmemset(target,tem,264);
609 if (SpriteON && scanline)
610 RefreshSprite(target);
618 ((uint32 *)target)[x]=((uint32*)target)[x]&0xF0F0F0F0;
621 if((PPU[1]>>5)==0x7) block_or(target, 256, 0xc0);
622 else if(PPU[1]&0xE0) block_andor(target, 256, 0x3f, 0x40);
623 else block_andor(target, 256, 0x3f, 0x80);
627 ((uint32 *)target)[x]=(((uint32*)target)[x])|0xc0c0c0c0;
630 ((uint32 *)target)[x]=(((uint32*)target)[x]&0x3f3f3f3f)|0x40404040;
633 ((uint32 *)target)[x]=(((uint32*)target)[x]&0x3f3f3f3f)|0x80808080;
636 ((uint32 *)target)[-2]=((uint32 *)target)[-1]=0;
637 ((uint32 *)target)[64]=((uint32 *)target)[65]=0;
644 tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
645 FCEU_dwmemset(target,tem,256);
647 if(InputScanlineHook)
648 InputScanlineHook(target, scanline);
651 #define PAL(c) ((c)+cc)
654 static void PRefreshLine(void)
660 if (BGAdrHI) vofs = 0x1000;
662 vofs+=(RefreshAddr>>12)&7;
668 zz2=(uint8)((RefreshAddr>>10)&3);
669 PPU_hook(0x2000|(RefreshAddr&0xFFF));
670 no = vnapage[zz2][(RefreshAddr&0x3ff)];
671 PPU_hook((no<<4)+vofs);
672 if((RefreshAddr&0x1f)==0x1f)
679 /* This high-level graphics MMC5 emulation code was written
680 for MMC5 carts in "CL" mode. It's probably not totally
681 correct for carts in "SL" mode.
683 static void RefreshLine_MMC5Hack1(uint8 *P, uint32 vofs)
687 tochange=MMC5HackSPMode&0x1F;
689 for(X1=33;X1;X1--,P+=8)
695 if((tochange<=0 && MMC5HackSPMode&0x40) ||
696 (tochange>0 && !(MMC5HackSPMode&0x40)))
701 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
702 if(ys>=0x1E) ys-=0x1E;
703 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
705 C = MMC5HackVROMPTR+vadr;
706 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
708 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
709 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
714 zz2=(RefreshAddr>>10)&3;
715 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
716 C = MMC5BGVRAMADR(vadr);
717 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
718 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
722 if((RefreshAddr&0x1f)==0x1f)
730 static void RefreshLine_MMC5Hack2(uint8 *P, uint32 vofs)
734 tochange=MMC5HackSPMode&0x1F;
736 for(X1=33;X1;X1--,P+=8)
743 if((tochange<=0 && MMC5HackSPMode&0x40) ||
744 (tochange>0 && !(MMC5HackSPMode&0x40)))
749 ys=((scanline>>3)+MMC5HackSPScroll)&0x1F;
750 if(ys>=0x1E) ys-=0x1E;
751 vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7);
753 C = MMC5HackVROMPTR+vadr;
754 C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12);
756 cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)];
757 cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3) <<2;
762 zz2=(RefreshAddr>>10)&3;
763 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
764 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
765 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
766 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
770 if((RefreshAddr&0x1f)==0x1f)
778 static void RefreshLine_MMC5Hack3(uint8 *P, uint32 vofs)
782 for(X1=33;X1;X1--,P+=8)
790 zz2=(RefreshAddr>>10)&3;
791 vadr = (vnapage[zz2][RefreshAddr & 0x3ff] << 4) + vofs;
792 C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f &
793 MMC5HackVROMMask) << 12) + (vadr & 0xfff);
794 vadr = (MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>> 4;
798 if((RefreshAddr&0x1f)==0x1f)
805 static void RefreshLine_MMC5Hack4(uint8 *P, uint32 vofs)
809 for(X1=33;X1;X1--,P+=8)
816 zz2=(RefreshAddr>>10)&3;
817 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
818 C = MMC5BGVRAMADR(vadr);
819 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
820 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
824 if((RefreshAddr&0x1f)==0x1f)
831 static void RefreshLine_PPU_hook(uint8 *P, uint32 vofs)
835 for(X1=33;X1;X1--,P+=8)
842 zz2=(RefreshAddr>>10)&3;
843 PPU_hook(0x2000|(RefreshAddr&0xFFF));
844 cc=vnapage[zz2][0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)];
845 cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3) <<2;
846 vadr=(vnapage[zz2][RefreshAddr&0x3ff]<<4)+vofs;
853 if((RefreshAddr&0x1f)==0x1f)
860 static void RefreshLine_normal(uint8 *P, uint32 vofs) // vofs is 0x107 max
863 uint32 rfraddr = RefreshAddr;
864 uint8 *page = vnapage[(rfraddr>>10)&3];
867 if ((rfraddr&0xc)!=0)
868 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
870 for (X1=33;X1;X1--,P+=8)
875 vadr=(page[rfraddr&0x3ff]<<4)+vofs;
877 if ((rfraddr&0xc)==0)
878 cc2=*(uint32 *) (page + ((rfraddr&0x380)>>4) + ((rfraddr&0x10)>>2) + 0x3c0);
879 cc=((cc2 >> ((rfraddr&2) + ((rfraddr&0x40)>>4) + ((rfraddr&0xc)<<1))) & 3) << 2;
883 if((rfraddr&0x1f)==0x1f) {
885 page = vnapage[(rfraddr>>10)&3];
889 RefreshAddr = rfraddr;
892 static void SetRefreshLine(void)
894 if(MMC5Hack && geniestage!=1)
896 if(MMC5HackCHRMode==0 && (MMC5HackSPMode&0x80))
898 if (RefreshLine != RefreshLine_MMC5Hack1) printf("set refr RefreshLine_MMC5Hack1\n");
899 RefreshLine = RefreshLine_MMC5Hack1;
901 else if(MMC5HackCHRMode==1 && (MMC5HackSPMode&0x80))
903 if (RefreshLine != RefreshLine_MMC5Hack2) printf("set refr RefreshLine_MMC5Hack2\n");
904 RefreshLine = RefreshLine_MMC5Hack2;
906 else if(MMC5HackCHRMode==1)
908 if (RefreshLine != RefreshLine_MMC5Hack3) printf("set refr RefreshLine_MMC5Hack3\n");
909 RefreshLine = RefreshLine_MMC5Hack3;
913 if (RefreshLine != RefreshLine_MMC5Hack4) printf("set refr RefreshLine_MMC5Hack4\n");
914 RefreshLine = RefreshLine_MMC5Hack4;
916 } // End if(MMC5Hack)
919 if (RefreshLine != RefreshLine_PPU_hook) printf("set refr RefreshLine_PPU_hook\n");
920 RefreshLine = RefreshLine_PPU_hook;
924 if (RefreshLine != RefreshLine_normal) printf("set refr RefreshLine_normal\n");
925 RefreshLine = RefreshLine_normal;
932 if(ScreenON || SpriteON)
934 uint32 rad=RefreshAddr;
936 rad|=TempAddr&0x041f;
938 //PPU_hook(RefreshAddr,-1);
945 if(ScreenON || SpriteON)
947 uint32 rad=RefreshAddr;
949 if((rad&0x7000)==0x7000)
952 if((rad&0x3E0)==0x3A0)
959 if((rad&0x3E0)==0x3e0)
967 //PPU_hook(RefreshAddr,-1);
972 /* This is called at the beginning of all h-blanks on visible lines. */
973 static void DoHBlank(void)
975 if(ScreenON || SpriteON)
977 if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18))
987 X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
991 if(GameHBIRQHook2 && (ScreenON || SpriteON))
994 //fprintf(stderr,"%3d: $%04x\n",scanline,RefreshAddr);
1002 // ============================//
1004 // ===========================//
1006 void ResetMapping(void)
1010 SetReadHandler(0x0000,0xFFFF,ANull);
1011 SetWriteHandler(0x0000,0xFFFF,BNull);
1013 SetReadHandler(0,0x7FF,ARAML);
1014 SetWriteHandler(0,0x7FF,BRAML);
1016 SetReadHandler(0x800,0x1FFF,ARAMH); /* Part of a little */
1017 SetWriteHandler(0x800,0x1FFF,BRAMH); /* hack for a small speed boost. */
1019 for(x=0x2000;x<0x4000;x+=8)
1039 BWrite[0x4014]=B4014;
1045 void CloseGame(void)
1049 if(FCEUGameInfo.type!=GIT_NSF)
1050 FCEU_FlushGameCheats(0,0);
1052 if(FSettings.NetworkPlay) KillNetplay();
1054 GameInterface(GI_CLOSE);
1060 void ResetGameLoaded(void)
1062 if(GameLoaded) CloseGame();
1065 GameHBIRQHook=GameHBIRQHook2=0;
1066 GameExpSound.Fill=0;
1067 GameExpSound.RChange=0;
1068 if(GameExpSound.Kill)
1069 GameExpSound.Kill();
1070 GameExpSound.Kill=0;
1076 FCEUGameInfo.name=0;
1077 FCEUGameInfo.type=GIT_CART;
1078 FCEUGameInfo.vidsys=GIV_USER;
1079 FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=-1;
1080 FCEUGameInfo.inputfc=-1;
1083 char lastLoadedGameName [2048];
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)
1098 strncpy(name2, name, sizeof(name2));
1099 name2[sizeof(name2)-1] = 0;
1101 fp=FCEU_fopen(name2,"rb");
1104 FCEU_PrintError("Error opening \"%s\"!",name);
1109 char *p = name2 + strlen(name2) - 4;
1110 if (strcmp(p, ".fcm") == 0)
1113 printf("movie detected\n");
1116 fp=FCEU_fopen(name2,"rb");
1117 if (!fp && p - name2 > 2) p[-2] = 0;
1118 fp=FCEU_fopen(name2,"rb");
1120 printf("no ROM for movie\n");
1127 strcpy(lastLoadedGameName, name2);
1130 if(iNESLoad(name2,fp))
1134 if(FDSLoad(name2,fp))
1136 if(UNIFLoad(name2,fp))
1139 FCEU_PrintError("An error occurred while loading the file.");
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);
1168 return(&FCEUGameInfo);
1172 void FCEU_ResetVidSys(void)
1176 if(FCEUGameInfo.vidsys==GIV_NTSC)
1178 else if(FCEUGameInfo.vidsys==GIV_PAL)
1186 FSettings.FirstSLine=FSettings.UsrFirstSLine[1];
1187 FSettings.LastSLine=FSettings.UsrLastSLine[1];
1192 FSettings.FirstSLine=FSettings.UsrFirstSLine[0];
1193 FSettings.LastSLine=FSettings.UsrLastSLine[0];
1195 printf("ResetVidSys: PAL = %i\n", PAL);
1196 SetSoundVariables();
1199 int FCEUI_Initialize(void)
1201 if(!InitVirtualVideo())
1203 memset(&FSettings,0,sizeof(FSettings));
1204 FSettings.UsrFirstSLine[0]=8;
1205 FSettings.UsrFirstSLine[1]=0;
1206 FSettings.UsrLastSLine[0]=FSettings.UsrLastSLine[1]=239;
1207 FSettings.SoundVolume=100;
1211 void MMC5_hb(int); /* Ugh ugh ugh. */
1212 static INLINE void Thingo(void)
1216 if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
1218 // check: Battletoads & Double Dragon
1225 // sky glitches in SMB1 if done wrong
1226 X6502_Run(tosprite);
1228 X6502_Run(256-tosprite);
1240 uint32 scanlines_per_frame = PAL ? 312 : 262;
1242 FCEU_ApplyPeriodicCheats();
1245 if(ppudead) /* Needed for Knight Rider, possibly others. */
1247 //memset(XBuf, 0, 320*240);
1248 X6502_Run(scanlines_per_frame*(256+85));
1256 PPU[3]=PPUSPL=0; /* Not sure if this is correct. According
1257 to Matt Conte and my own tests, it is. Timing is probably
1258 off, though. NOTE: Not having this here
1259 breaks a Super Donkey Kong game. */
1261 X6502_Run(12); /* I need to figure out the true nature and length
1264 if(FCEUGameInfo.type==GIT_NSF)
1269 // Note: this is needed for asm core
1270 // Warning: using 'scanline' var here breaks Castlevania III
1273 X6502_Run(256+85-12);
1274 for (lines=scanlines_per_frame-242-1;lines;lines--)
1277 // X6502_Run((scanlines_per_frame-242)*(256+85)-12);
1282 if(ScreenON || SpriteON)
1287 for(x=0;x<42;x++) {PPU_hook(0x2000); PPU_hook(0);} // ugh
1294 if(ScreenON || SpriteON)
1296 RefreshAddr=TempAddr;
1297 if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
1305 if(FCEUGameInfo.type==GIT_NSF)
1307 // run scanlines for asm core to fuction
1308 for(scanline=0;scanline<240;scanline++)
1317 for(scanline=0;scanline<240;) // scanline is incremented in DoLine. Evil. :/
1322 if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
1323 for(x=1,max=0,maxref=0;x<7;x++)
1332 SetNESDeemph(maxref,0);
1339 ssize=FlushEmulateSound();
1341 timestampbase += timestamp;
1347 FCEU_PutImageDummy();
1349 FCEUD_Update(0,WaveFinalMono,ssize);
1355 FCEUD_Update(XBuf+8,WaveFinalMono,ssize);
1369 #include <sys/time.h>
1372 void FCEUI_Emulate(void)
1375 uint64 starttime,end;
1378 gettimeofday(&tv,0);
1379 starttime=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1384 // Probably won't work well on Windows port; for
1385 // debugging/speed testing.
1389 gettimeofday(&tv,0);
1390 end=((uint64)tv.tv_sec*1000000)+tv.tv_usec;
1391 w=frcount*10000000000LL/(end-starttime);
1394 printf("Average FPS: %d.%04d\n",i,frac);
1400 void FCEUI_CloseGame(void)
1405 static void ResetPPU(void)
1407 VRAMBuffer=PPU[0]=PPU[1]=PPU[2]=PPU[3]=0;
1410 RefreshAddr=TempAddr=0;
1416 static void PowerPPU(void)
1418 memset(NTARAM,0x00,0x800);
1419 memset(PALRAM,0x00,0x20);
1420 memset(SPRAM,0x00,0x100);
1426 if(!GameLoaded) return;
1427 GameInterface(GI_RESETM2);
1433 static void FCEU_MemoryRand(uint8 *ptr, uint32 size)
1438 *ptr=(x&4)?0xFF:0x00;
1447 if(!GameLoaded) return;
1449 FCEU_CheatResetRAM();
1450 FCEU_CheatAddRAM(2,0,RAM);
1454 #ifndef DEBUG_ASM_6502
1455 FCEU_MemoryRand(RAM,0x800);
1457 memset(RAM,0x00,0x800);
1460 GameInterface(GI_POWER);
1472 /* savestate stuff */
1473 uint16 TempAddrT,RefreshAddrT;
1475 SFORMAT FCEUPPU_STATEINFO[]={
1476 { NTARAM, 0x800, "NTAR"},
1477 { PALRAM, 0x20, "PRAM"},
1478 { SPRAM, 0x100, "SPRA"},
1479 { PPU, 0x4, "PPUR"},
1480 { &XOffset, 1, "XOFF"},
1481 { &vtoggle, 1, "VTOG"},
1482 { &RefreshAddrT, 2|RLSB, "RADD"},
1483 { &TempAddrT, 2|RLSB, "TADD"},
1484 { &VRAMBuffer, 1, "VBUF"},
1485 { &PPUGenLatch, 1, "PGEN"},
1487 { &kook, 1, "KOOK"},
1488 { &ppudead, 1, "DEAD"},
1489 { &PPUSPL, 1, "PSPL"},