#include "dprintf.h"
+#ifdef GP2X
+#include "drivers/gp2x/asmutils.h"
+#endif
+
#define Pal (PALRAM)
static uint8 deemp=0;
static int deempcnt[8];
-int tosprite=256;
-
FCEUGI FCEUGameInfo;
-void (*GameInterface)(int h);
+void (*GameInterface)(int h, void *param);
void FP_FASTAPASS(1) (*PPU_hook)(uint32 A);
ARead[x+0x8000]=AReadG[x];
BWrite[x+0x8000]=BWriteG[x];
}
+#ifdef ASM_6502
+ GenieSetPages(1);
+#endif
free(AReadG);
free(BWriteG);
AReadG=0;
static int linestartts;
static int tofix=0;
-static void ResetRL(void)
+static uint8 *Plinef;
+
+extern uint8 sprlinebuf[256+8];
+extern int32 sphitx;
+extern uint8 sphitdata;
+
+extern int spork; /* spork the world. Any sprites on this line?
+ Then this will be set to 1. Needed for zapper
+ emulation and *gasp* sprite emulation.
+ */
+
+static void ResetRL(uint8 *target)
{
+ if(InputScanlineHook)
+ InputScanlineHook(0,0,0,0);
+ Plinef=target;
linestartts=timestamp*48+X6502_GetCycleCount();
tofix=1;
}
static INLINE void Fixit1(void);
-static void TryFixit1(void)
+/* faking FCEUPPU_LineUpdate() from later versions of the emu */
+static void FakedLineUpdate(void)
{
#define TOFIXNUM (272-0x4)
int lastpixel;
- if (scanline < 240 && tofix)
+ if (scanline >= 240) return;
+
+ if (tofix || sphitx != 0x100)
{
lastpixel = (timestamp*48-linestartts)>>4;
if (PAL) lastpixel += lastpixel>>4;
-
//printf("lastpixel: %i\n", lastpixel);
+ }
- if(lastpixel>=TOFIXNUM)
+ if (tofix && lastpixel>=TOFIXNUM)
+ {
+ Fixit1();
+ tofix=0;
+ }
+
+ // CheckSpriteHit()
+ if(sphitx!=0x100)
+ {
+ int l=lastpixel-16;
+ int x;
+
+ for(x=sphitx;x<(sphitx+8) && x<l;x++)
{
- Fixit1();
- tofix=0;
+ if((sphitdata&(0x80>>(x-sphitx))) && !(Plinef[x]&64))
+ {
+ PPU_status|=0x40;
+ sphitx=0x100;
+ break;
+ }
}
}
}
/* merged */
uint8 ret;
- TryFixit1();
+ FakedLineUpdate();
ret = PPU_status;
ret|=PPUGenLatch&0x1F;
vtoggle=0;
static DECLFR(A200x)
{
/* merged */
- TryFixit1();
+ FakedLineUpdate();
return PPUGenLatch;
}
uint8 ret;
uint32 tmp=RefreshAddr&0x3FFF;
- TryFixit1();
+ FakedLineUpdate();
ret=VRAMBuffer;
static DECLFW(B2000)
{
/* NMI2? */
- TryFixit1();
+ FakedLineUpdate();
PPUGenLatch=V;
PPU[0]=V;
TempAddr&=0xF3FF;
static DECLFW(B2001)
{
/* merged */
- TryFixit1();
+ FakedLineUpdate();
PPUGenLatch=V;
PPU[1]=V;
if(V&0xE0)
{
/* merged */
uint32 tmp=TempAddr;
- TryFixit1();
+ FakedLineUpdate();
PPUGenLatch=V;
if (!vtoggle)
{
static DECLFW(B2006)
{
/* merged */
- TryFixit1();
+ FakedLineUpdate();
PPUGenLatch=V;
if(!vtoggle)
}
#ifdef FRAMESKIP
-int FSkip_setting=-1; // auto
int FSkip=0;
void FCEUI_FrameSkip(int x)
{
#endif
/* This is called at the beginning of each visible scanline */
-static void Loop6502(void)
+static void LineUpdate(uint8 *target)
{
uint32 tem;
- int x;
- uint8 *target=XBuf+scanline*320+32;
- if(ScreenON || SpriteON)
- {
- /* PRefreshLine() will not get called on skipped frames. This
- could cause a problem, but the solution would be rather complex,
- due to the current sprite 0 hit code.
- */
- #ifdef FRAMESKIP
- if(!FSkip)
+ if(FSkip || scanline < FSettings.FirstSLine || scanline > FSettings.LastSLine)
+ {
+ if(PPU_hook)
+ PRefreshLine();
+ }
+ else
+ {
+ if(ScreenON)
{
- #endif
- if(ScreenON)
- {
- if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine)
- BGRender(target);
- else
- {
- if(PPU_hook)
- PRefreshLine();
- }
- }
- else
- {
- tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
- tem|=0x40404040;
- FCEU_dwmemset(target,tem,264);
- }
- #ifdef FRAMESKIP
+ BGRender(target);
}
- #endif
- if (SpriteON && scanline)
- RefreshSprite(target);
- #ifdef FRAMESKIP
- if(!FSkip)
+ else
{
- #endif
- if(PPU[1]&0x01)
- {
- for(x=63;x>=0;x--)
- ((uint32 *)target)[x]=((uint32*)target)[x]&0xF0F0F0F0;
- }
- if((PPU[1]>>5)==0x7)
- for(x=63;x>=0;x--)
- ((uint32 *)target)[x]=(((uint32*)target)[x]&0x3f3f3f3f)|0x40404040;
- else if(PPU[1]&0xE0)
- for(x=63;x>=0;x--)
- ((uint32 *)target)[x]=((uint32*)target)[x]|0xC0C0C0C0;
- else
- for(x=63;x>=0;x--)
- ((uint32 *)target)[x]=((uint32*)target)[x]&0x3f3f3f3f;
- FCEU_dwmemset(target- 8,0x3f3f3f3f,8);
- FCEU_dwmemset(target+256,0x3f3f3f3f,8);
- #ifdef FRAMESKIP
+ tem=Pal[0]|0x40;
+ tem|=tem << 8;
+ tem|=tem << 16;
+ FCEU_dwmemset(target,tem,256);
}
- #endif
- }
- else
- {
- tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24);
- FCEU_dwmemset(target,tem,256);
}
+
if(InputScanlineHook)
- InputScanlineHook(target, scanline);
+ InputScanlineHook(target,spork?sprlinebuf:0,linestartts,256);
+}
+
+
+static void LineUpdateEnd(uint8 *target)
+{
+#ifdef GP2X
+ if(ScreenON || SpriteON) // Yes, very el-cheapo.
+ {
+ if(PPU[1]&0x01)
+ block_and(target, 256, 0x30);
+ }
+ if((PPU[1]>>5)==0x7)
+ block_or(target, 256, 0xc0);
+ else if(PPU[1]&0xE0)
+ block_or(target, 256, 0x40);
+ else
+ block_andor(target, 256, 0x3f, 0x80);
+#else
+ int x;
+
+ if(ScreenON || SpriteON) // Yes, very el-cheapo.
+ {
+ if(PPU[1]&0x01)
+ {
+ for(x=63;x>=0;x--)
+ *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])&0x30303030;
+ }
+ }
+ if((PPU[1]>>5)==0x7)
+ {
+ for(x=63;x>=0;x--)
+ *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0xc0c0c0c0;
+ }
+ else if(PPU[1]&0xE0)
+ for(x=63;x>=0;x--)
+ *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])|0x40404040;
+ else
+ for(x=63;x>=0;x--)
+ *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0x80808080;
+#endif
+
+ // black borders
+ ((uint32 *)target)[-2]=((uint32 *)target)[-1]=0;
+ ((uint32 *)target)[64]=((uint32 *)target)[65]=0;
}
#define PAL(c) ((c)+cc)
}
-/* This is called at the beginning of all h-blanks on visible lines. */
-static void DoHBlank(void)
-{
- if(ScreenON || SpriteON)
- FetchSpriteData();
- if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18))
- {
- X6502_Run(6);
- Fixit2();
- X6502_Run(4);
- GameHBIRQHook();
- X6502_Run(85-16-10);
- }
- else
- {
- X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
- Fixit2();
- X6502_Run(85-6-16);
- }
- if(GameHBIRQHook2 && (ScreenON || SpriteON))
- GameHBIRQHook2();
- //PPU_hook(0,-1);
- //fprintf(stderr,"%3d: $%04x\n",scanline,RefreshAddr);
- scanline++;
- if (scanline<240)
- ResetRL();
- X6502_Run(16);
-}
-
-
// ============================//
// end of new code
// ===========================//
int GameLoaded=0;
void CloseGame(void)
{
+ FCEUI_StopMovie();
if(GameLoaded)
{
if(FCEUGameInfo.type!=GIT_NSF)
#ifdef NETWORK
if(FSettings.NetworkPlay) KillNetplay();
#endif
- GameInterface(GI_CLOSE);
+ GameInterface(GI_CLOSE, 0);
CloseGenie();
GameLoaded=0;
}
}
char lastLoadedGameName [2048];
+int LoadGameLastError = 0;
int UNIFLoad(const char *name, int fp);
int iNESLoad(const char *name, int fp);
int FDSLoad(const char *name, int fp);
int have_movie = 0;
int fp;
- Exit=1;
+ //Exit=1;
+ LoadGameLastError = 0;
ResetGameLoaded();
strncpy(name2, name, sizeof(name2));
if(!fp)
{
FCEU_PrintError("Error opening \"%s\"!",name);
+ LoadGameLastError = 1;
return 0;
}
FCEU_fclose(fp);
*p = 0;
fp=FCEU_fopen(name2,"rb");
+ if (!fp && p - name2 > 2) p[-2] = 0;
+ fp=FCEU_fopen(name2,"rb");
if (!fp) {
printf("no ROM for movie\n");
+ LoadGameLastError = 2;
return 0;
}
have_movie = 1;
}
}
- strcpy(lastLoadedGameName, name2);
-
GetFileBase(name2);
if(iNESLoad(name2,fp))
goto endlseq;
FCEU_PrintError("An error occurred while loading the file.");
FCEU_fclose(fp);
+ // format handlers may set LoadGameLastError themselves.
+ if (LoadGameLastError == 0) LoadGameLastError = 3;
return 0;
endlseq:
if (have_movie)
FCEUI_LoadMovie(name, 1);
+
+ strcpy(lastLoadedGameName, name2);
+
return(&FCEUGameInfo);
}
FSettings.FirstSLine=FSettings.UsrFirstSLine[0];
FSettings.LastSLine=FSettings.UsrLastSLine[0];
}
- printf("PAL = %i\n", PAL);
+ printf("ResetVidSys: PAL = %i\n", PAL);
SetSoundVariables();
}
}
void MMC5_hb(int); /* Ugh ugh ugh. */
-static INLINE void Thingo(void)
+static void DoLine(void)
{
- Loop6502();
+ uint8 *target=XBuf+scanline*320+32;
+
+ LineUpdate(target);
if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
- // check: Battletoads & Double Dragon
- if(tosprite>=256)
+ X6502_Run(256);
+
+ // check: Battletoads & Double Dragon, Addams Family
+ // sky glitches in SMB1 if done wrong
+ FakedLineUpdate();
+
+#ifdef FRAMESKIP
+ if(!FSkip)
+#endif
+ if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine)
{
- X6502_Run(256);
+ if(SpriteON && spork)
+ CopySprites(target);
+
+ LineUpdateEnd(target);
+ }
+ sphitx=0x100;
+
+ if(ScreenON || SpriteON)
+ FetchSpriteData();
+
+ // DoHBlank();
+ if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18))
+ {
+ X6502_Run(6);
+ Fixit2();
+ X6502_Run(4);
+ GameHBIRQHook();
+ X6502_Run(85-10-16);
}
else
{
- // sky glitches in SMB1 if done wrong
- X6502_Run(tosprite);
- PPU[2]|=0x40;
- X6502_Run(256-tosprite);
- tosprite = 256;
+ X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
+ Fixit2();
+ X6502_Run(85-6-16);
}
- TryFixit1();
- DoHBlank();
+
+ if(SpriteON)
+ RefreshSprites();
+ if(GameHBIRQHook2 && (ScreenON || SpriteON))
+ GameHBIRQHook2();
+ scanline++;
+ if (scanline<240)
+ ResetRL(XBuf+scanline*320+32);
+ X6502_Run(16);
}
+
void EmLoop(void)
{
for(;;)
// FCEUPPU_Loop:
if(ppudead) /* Needed for Knight Rider, possibly others. */
{
- memset(XBuf, 0x80, 320*240);
+ //memset(XBuf, 0, 320*240);
X6502_Run(scanlines_per_frame*(256+85));
ppudead--;
goto update;
RefreshAddr=TempAddr;
if(PPU_hook) PPU_hook(RefreshAddr&0x3fff);
}
- ResetRL();
+ spork=0;
+ ResetRL(XBuf+32);
X6502_Run(16-kook);
kook ^= 1;
if(FCEUGameInfo.type==GIT_NSF)
{
- X6502_Run((256+85)*240);
+ // run scanlines for asm core to fuction
+ for(scanline=0;scanline<240;scanline++)
+ X6502_Run(256+85);
}
- #ifdef FRAMESKIP
- else if(FSkip)
- {
- int y;
-
- y=SPRAM[0];
- y++;
-
- PPU_status|=0x20; // Fixes "Bee 52". Does it break anything?
- if(GameHBIRQHook)
- {
- X6502_Run(256);
- for(scanline=0;scanline<240;scanline++)
- {
- if(ScreenON || SpriteON)
- GameHBIRQHook();
- if(scanline==y && SpriteON) PPU_status|=0x40;
- X6502_Run((scanline==239)?85:(256+85));
- ResetRL(); // ??
- }
- }
- else if(y<240)
- {
- X6502_Run((256+85)*y);
- if(SpriteON) PPU_status|=0x40; // Quick and very dirty hack.
- X6502_Run((256+85)*(240-y));
- }
- else
- X6502_Run((256+85)*240);
- }
- #endif
else
{
int x,max,maxref;
for(scanline=0;scanline<240;) // scanline is incremented in DoLine. Evil. :/
{
deempcnt[deemp]++;
- Thingo();
+ DoLine();
}
if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline);
for(x=1,max=0,maxref=0;x<7;x++)
if(Exit)
{
- CloseGame();
+ //CloseGame();
break;
}
void ResetNES(void)
{
if(!GameLoaded) return;
- GameInterface(GI_RESETM2);
+ GameInterface(GI_RESETM2, 0);
ResetSound();
ResetPPU();
X6502_Reset();
}
+static void FCEU_MemoryRand(uint8 *ptr, uint32 size)
+{
+ int x=0;
+ while(size)
+ {
+ *ptr=(x&4)?0xFF:0x00;
+ x++;
+ size--;
+ ptr++;
+ }
+}
+
void PowerNES(void)
{
if(!GameLoaded) return;
GeniePower();
+#ifndef DEBUG_ASM_6502
+ FCEU_MemoryRand(RAM,0x800);
+#else
memset(RAM,0x00,0x800);
+#endif
ResetMapping();
- GameInterface(GI_POWER);
+ GameInterface(GI_POWER, 0);
PowerSound();
PowerPPU();
timestampbase=0;
+#ifdef ASM_6502
+ if (geniestage)
+ GenieSetPages(0);
+#endif
X6502_Power();
}