removed old ines code, more formatting

This commit is contained in:
CaH4e3 2012-12-12 20:28:34 +00:00
parent 3a5e90fcc2
commit 880c9deb62
5 changed files with 673 additions and 1668 deletions

View File

@ -75,47 +75,39 @@ uint8 geniech[3];
uint32 genieaddr[3];
static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram)
{
static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram) {
uint32 AB = A >> 11;
int x;
if (p)
for(x=(s>>1)-1;x>=0;x--)
{
for (x = (s >> 1) - 1; x >= 0; x--) {
PRGIsRAM[AB + x] = ram;
Page[AB + x] = p - A;
}
else
for(x=(s>>1)-1;x>=0;x--)
{
for (x = (s >> 1) - 1; x >= 0; x--) {
PRGIsRAM[AB + x] = 0;
Page[AB + x] = 0;
}
}
static uint8 nothing[8192];
void ResetCartMapping(void)
{
void ResetCartMapping(void) {
int x;
PPU_ResetHooks();
for(x=0;x<32;x++)
{
for (x = 0; x < 32; x++) {
Page[x] = nothing - x * 2048;
PRGptr[x] = CHRptr[x] = 0;
PRGsize[x] = CHRsize[x] = 0;
}
for(x=0;x<8;x++)
{
for (x = 0; x < 8; x++) {
MMC5SPRVPage[x] = MMC5BGVPage[x] = VPageR[x] = nothing - 0x400 * x;
}
}
void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram)
{
void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram) {
PRGptr[chip] = p;
PRGsize[chip] = size;
@ -128,8 +120,7 @@ void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram)
PRGram[chip] = ram ? 1 : 0;
}
void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram)
{
void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram) {
CHRptr[chip] = p;
CHRsize[chip] = size;
@ -141,55 +132,46 @@ void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram)
CHRram[chip] = ram;
}
DECLFR(CartBR)
{
DECLFR(CartBR) {
return Page[A >> 11][A];
}
DECLFW(CartBW)
{
DECLFW(CartBW) {
//printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]);
if (PRGIsRAM[A >> 11] && Page[A >> 11])
Page[A >> 11][A] = V;
}
DECLFR(CartBROB)
{
if(!Page[A>>11]) return(X.DB);
DECLFR(CartBROB) {
if (!Page[A >> 11])
return(X.DB);
else
return Page[A >> 11][A];
}
void setprg2r(int r, unsigned int A, unsigned int V)
{
void setprg2r(int r, uint32 A, uint32 V) {
V &= PRGmask2[r];
setpageptr(2, A, PRGptr[r] ? (&PRGptr[r][V << 11]) : 0, PRGram[r]);
}
void setprg2(uint32 A, uint32 V)
{
void setprg2(uint32 A, uint32 V) {
setprg2r(0, A, V);
}
void setprg4r(int r, unsigned int A, unsigned int V)
{
void setprg4r(int r, uint32 A, uint32 V) {
V &= PRGmask4[r];
setpageptr(4, A, PRGptr[r] ? (&PRGptr[r][V << 12]) : 0, PRGram[r]);
}
void setprg4(uint32 A, uint32 V)
{
void setprg4(uint32 A, uint32 V) {
setprg4r(0, A, V);
}
void setprg8r(int r, unsigned int A, unsigned int V)
{
if(PRGsize[r]>=8192)
{
void setprg8r(int r, uint32 A, uint32 V) {
if (PRGsize[r] >= 8192) {
V &= PRGmask8[r];
setpageptr(8, A, PRGptr[r] ? (&PRGptr[r][V << 13]) : 0, PRGram[r]);
}
else
{
} else {
uint32 VA = V << 2;
int x;
for (x = 0; x < 4; x++)
@ -197,20 +179,15 @@ void setprg8r(int r, unsigned int A, unsigned int V)
}
}
void setprg8(uint32 A, uint32 V)
{
void setprg8(uint32 A, uint32 V) {
setprg8r(0, A, V);
}
void setprg16r(int r, unsigned int A, unsigned int V)
{
if(PRGsize[r]>=16384)
{
void setprg16r(int r, uint32 A, uint32 V) {
if (PRGsize[r] >= 16384) {
V &= PRGmask16[r];
setpageptr(16, A, PRGptr[r] ? (&PRGptr[r][V << 14]) : 0, PRGram[r]);
}
else
{
} else {
uint32 VA = V << 3;
int x;
@ -219,20 +196,15 @@ void setprg16r(int r, unsigned int A, unsigned int V)
}
}
void setprg16(uint32 A, uint32 V)
{
void setprg16(uint32 A, uint32 V) {
setprg16r(0, A, V);
}
void setprg32r(int r,unsigned int A, unsigned int V)
{
if(PRGsize[r]>=32768)
{
void setprg32r(int r, uint32 A, uint32 V) {
if (PRGsize[r] >= 32768) {
V &= PRGmask32[r];
setpageptr(32, A, PRGptr[r] ? (&PRGptr[r][V << 15]) : 0, PRGram[r]);
}
else
{
} else {
uint32 VA = V << 4;
int x;
@ -241,13 +213,11 @@ void setprg32r(int r,unsigned int A, unsigned int V)
}
}
void setprg32(uint32 A, uint32 V)
{
void setprg32(uint32 A, uint32 V) {
setprg32r(0, A, V);
}
void setchr1r(int r, unsigned int A, unsigned int V)
{
void setchr1r(int r, uint32 A, uint32 V) {
if (!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V &= CHRmask1[r];
@ -258,8 +228,7 @@ void setchr1r(int r, unsigned int A, unsigned int V)
VPageR[(A) >> 10] = &CHRptr[r][(V) << 10] - (A);
}
void setchr2r(int r, unsigned int A, unsigned int V)
{
void setchr2r(int r, uint32 A, uint32 V) {
if (!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V &= CHRmask2[r];
@ -270,8 +239,7 @@ void setchr2r(int r, unsigned int A, unsigned int V)
PPUCHRRAM &= ~(3 << (A >> 10));
}
void setchr4r(int r, unsigned int A, unsigned int V)
{
void setchr4r(int r, unsigned int A, unsigned int V) {
if (!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V &= CHRmask4[r];
@ -283,8 +251,7 @@ void setchr4r(int r, unsigned int A, unsigned int V)
PPUCHRRAM &= ~(15 << (A >> 10));
}
void setchr8r(int r, unsigned int V)
{
void setchr8r(int r, uint32 V) {
int x;
if (!CHRptr[r]) return;
@ -298,80 +265,25 @@ void setchr8r(int r, unsigned int V)
PPUCHRRAM = 0;
}
void setchr1(unsigned int A, unsigned int V)
{
void setchr1(uint32 A, uint32 V) {
setchr1r(0, A, V);
}
void setchr2(unsigned int A, unsigned int V)
{
void setchr2(uint32 A, uint32 V) {
setchr2r(0, A, V);
}
void setchr4(unsigned int A, unsigned int V)
{
void setchr4(uint32 A, uint32 V) {
setchr4r(0, A, V);
}
void setchr8(unsigned int V)
{
void setchr8(uint32 V) {
setchr8r(0, V);
}
void setvram8(uint8 *p)
{
int x;
for(x=7;x>=0;x--)
VPageR[x]=p;
PPUCHRRAM|=255;
}
void setvram4(uint32 A, uint8 *p)
{
int x;
for(x=3;x>=0;x--)
VPageR[(A>>10)+x]=p-A;
PPUCHRRAM|=(15<<(A>>10));
}
void setvramb1(uint8 *p, uint32 A, uint32 b)
{
FCEUPPU_LineUpdate();
VPageR[A>>10]=p-A+(b<<10);
PPUCHRRAM|=(1<<(A>>10));
}
void setvramb2(uint8 *p, uint32 A, uint32 b)
{
FCEUPPU_LineUpdate();
VPageR[(A>>10)]=VPageR[(A>>10)+1]=p-A+(b<<11);
PPUCHRRAM|=(3<<(A>>10));
}
void setvramb4(uint8 *p, uint32 A, uint32 b)
{
int x;
FCEUPPU_LineUpdate();
for(x=3;x>=0;x--)
VPageR[(A>>10)+x]=p-A+(b<<12);
PPUCHRRAM|=(15<<(A>>10));
}
void setvramb8(uint8 *p, uint32 b)
{
int x;
FCEUPPU_LineUpdate();
for(x=7;x>=0;x--)
VPageR[x]=p+(b<<13);
PPUCHRRAM|=255;
}
/* This function can be called without calling SetupCartMirroring(). */
void setntamem(uint8 *p, int ram, uint32 b)
{
void setntamem(uint8 *p, int ram, uint32 b) {
FCEUPPU_LineUpdate();
vnapage[b] = p;
PPUNTARAM &= ~(1 << b);
@ -380,8 +292,7 @@ void setntamem(uint8 *p, int ram, uint32 b)
}
static int mirrorhard = 0;
void setmirrorw(int a, int b, int c, int d)
{
void setmirrorw(int a, int b, int c, int d) {
FCEUPPU_LineUpdate();
vnapage[0] = NTARAM + a * 0x400;
vnapage[1] = NTARAM + b * 0x400;
@ -389,13 +300,10 @@ void setmirrorw(int a, int b, int c, int d)
vnapage[3] = NTARAM + d * 0x400;
}
void setmirror(int t)
{
void setmirror(int t) {
FCEUPPU_LineUpdate();
if(!mirrorhard)
{
switch(t)
{
if (!mirrorhard) {
switch (t) {
case MI_H:
vnapage[0] = vnapage[1] = NTARAM; vnapage[2] = vnapage[3] = NTARAM + 0x400;
break;
@ -413,15 +321,11 @@ void setmirror(int t)
}
}
void SetupCartMirroring(int m, int hard, uint8 *extra)
{
if(m<4)
{
void SetupCartMirroring(int m, int hard, uint8 *extra) {
if (m < 4) {
mirrorhard = 0;
setmirror(m);
}
else
{
} else {
vnapage[0] = NTARAM;
vnapage[1] = NTARAM + 0x400;
vnapage[2] = extra;
@ -436,28 +340,24 @@ static uint8 *GENIEROM=0;
void FixGenieMap(void);
// Called when a game(file) is opened successfully.
void OpenGenie(void)
{
void FCEU_OpenGenie(void) {
FILE *fp;
int x;
if(!GENIEROM)
{
if (!GENIEROM) {
char *fn;
if (!(GENIEROM = (uint8*)FCEU_malloc(4096 + 1024))) return;
fn = strdup(FCEU_MakeFName(FCEUMKF_GGROM, 0, 0).c_str());
fp = FCEUD_UTF8fopen(fn, "rb");
if(!fp)
{
if (!fp) {
FCEU_PrintError("Error opening Game Genie ROM image!");
free(GENIEROM);
GENIEROM = 0;
return;
}
if(fread(GENIEROM,1,16,fp)!=16)
{
if (fread(GENIEROM, 1, 16, fp) != 16) {
grerr:
FCEU_PrintError("Error reading from Game Genie ROM image!");
free(GENIEROM);
@ -465,17 +365,14 @@ grerr:
fclose(fp);
return;
}
if(GENIEROM[0]==0x4E) /* iNES ROM image */
{
if (GENIEROM[0] == 0x4E) { /* iNES ROM image */
if (fread(GENIEROM, 1, 4096, fp) != 4096)
goto grerr;
if (fseek(fp, 16384 - 4096, SEEK_CUR))
goto grerr;
if (fread(GENIEROM + 4096, 1, 256, fp) != 256)
goto grerr;
}
else
{
} else {
if (fread(GENIEROM + 16, 1, 4352 - 16, fp) != (4352 - 16))
goto grerr;
}
@ -490,32 +387,26 @@ grerr:
}
/* Called when a game is closed. */
void CloseGenie(void)
{
void FCEU_CloseGenie(void) {
/* No good reason to free() the Game Genie ROM image data. */
geniestage = 0;
FlushGenieRW();
VPageR = VPage;
}
void FCEU_KillGenie(void)
{
if(GENIEROM)
{
void FCEU_KillGenie(void) {
if (GENIEROM) {
free(GENIEROM);
GENIEROM = 0;
}
}
static DECLFR(GenieRead)
{
static DECLFR(GenieRead) {
return GENIEROM[A & 4095];
}
static DECLFW(GenieWrite)
{
switch(A)
{
static DECLFW(GenieWrite) {
switch (A) {
case 0x800c:
case 0x8008:
case 0x8004: genieval[((A - 4) & 0xF) >> 2] = V; break;
@ -532,10 +423,10 @@ static DECLFW(GenieWrite)
case 0x8005:
case 0x8001: genieaddr[((A - 1) & 0xF) >> 2] &= 0xFF; genieaddr[((A - 1) & 0xF) >> 2] |= (V | 0x80) << 8; break;
case 0x8000:if(!V)
case 0x8000:
if (!V)
FixGenieMap();
else
{
else {
modcon = V ^ 0xFF;
if (V == 0x71)
modcon = 0;
@ -546,8 +437,7 @@ static DECLFW(GenieWrite)
static readfunc GenieBackup[3];
static DECLFR(GenieFix1)
{
static DECLFR(GenieFix1) {
uint8 r = GenieBackup[0](A);
if ((modcon >> 1) & 1) // No check
@ -558,8 +448,7 @@ static DECLFR(GenieFix1)
return r;
}
static DECLFR(GenieFix2)
{
static DECLFR(GenieFix2) {
uint8 r = GenieBackup[1](A);
if ((modcon >> 2) & 1) // No check
@ -570,8 +459,7 @@ static DECLFR(GenieFix2)
return r;
}
static DECLFR(GenieFix3)
{
static DECLFR(GenieFix3) {
uint8 r = GenieBackup[2](A);
if ((modcon >> 3) & 1) // No check
@ -583,8 +471,7 @@ static DECLFR(GenieFix3)
}
void FixGenieMap(void)
{
void FixGenieMap(void) {
int x;
geniestage = 2;
@ -596,24 +483,21 @@ void FixGenieMap(void)
FlushGenieRW();
//printf("Rightyo\n");
for (x = 0; x < 3; x++)
if((modcon>>(4+x))&1)
{
if ((modcon >> (4 + x)) & 1) {
readfunc tmp[3] = { GenieFix1, GenieFix2, GenieFix3 };
GenieBackup[x] = GetReadHandler(genieaddr[x]);
SetReadHandler(genieaddr[x], genieaddr[x], tmp[x]);
}
}
void GeniePower(void)
{
void FCEU_GeniePower(void) {
uint32 x;
if (!geniestage)
return;
geniestage = 1;
for(x=0;x<3;x++)
{
for (x = 0; x < 3; x++) {
genieval[x] = 0xFF;
geniech[x] = 0xFF;
genieaddr[x] = 0xFFFF;
@ -633,22 +517,16 @@ void GeniePower(void)
}
void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
void FCEU_SaveGameSave(CartInfo *LocalHWInfo) {
if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) {
FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav");
if((sp=FCEUD_UTF8fopen(soot,"wb"))==NULL)
{
if ((sp = FCEUD_UTF8fopen(soot, "wb")) == NULL) {
FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n", soot.c_str());
}
else
{
} else {
for (int x = 0; x < 4; x++)
if(LocalHWInfo->SaveGame[x])
{
if (LocalHWInfo->SaveGame[x]) {
fwrite(LocalHWInfo->SaveGame[x], 1,
LocalHWInfo->SaveGameLen[x], sp);
}
@ -659,16 +537,13 @@ void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
// hack, movie.cpp has to communicate with this function somehow
int disableBatteryLoading = 0;
void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading)
{
void FCEU_LoadGameSave(CartInfo *LocalHWInfo) {
if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading) {
FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav");
sp = FCEUD_UTF8fopen(soot, "rb");
if(sp!=NULL)
{
if (sp != NULL) {
for (int x = 0; x < 4; x++)
if (LocalHWInfo->SaveGame[x])
fread(LocalHWInfo->SaveGame[x], 1, LocalHWInfo->SaveGameLen[x], sp);
@ -677,10 +552,8 @@ void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
}
//clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though)
void FCEU_ClearGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
void FCEU_ClearGameSave(CartInfo *LocalHWInfo) {
if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) {
for (int x = 0; x < 4; x++)
if (LocalHWInfo->SaveGame[x])
memset(LocalHWInfo->SaveGame[x], 0, LocalHWInfo->SaveGameLen[x]);

View File

@ -1,24 +1,22 @@
typedef struct {
/* Set by mapper/board code: */
// Set by mapper/board code:
void (*Power)(void);
void (*Reset)(void);
void (*Close)(void);
uint8 *SaveGame[4]; /* Pointers to memory to save/load. */
uint32 SaveGameLen[4]; /* How much memory to save/load. */
uint8 *SaveGame[4]; // Pointers to memory to save/load.
uint32 SaveGameLen[4]; // How much memory to save/load.
/* Set by iNES/UNIF loading code. */
int mirror; /* As set in the header or chunk.
iNES/UNIF specific. Intended
to help support games like "Karnov"
that are not really MMC3 but are
set to mapper 4.
*/
int battery; /* Presence of an actual battery. */
// Set by iNES/UNIF loading code.
int mirror; // As set in the header or chunk.
// iNES/UNIF specific. Intended
// to help support games like "Karnov"
// that are not really MMC3 but are
// set to mapper 4.
int battery; // Presence of an actual battery.
uint8 MD5[16];
uint32 CRC32; /* Should be set by the iNES/UNIF loading
code, used by mapper/board code, maybe
other code in the future.
*/
uint32 CRC32; // Should be set by the iNES/UNIF loading
// code, used by mapper/board code, maybe
// other code in the future.
} CartInfo;
void FCEU_SaveGameSave(CartInfo *LocalHWInfo);
@ -75,14 +73,6 @@ void setchr2(unsigned int A, unsigned int V);
void setchr4(unsigned int A, unsigned int V);
void setchr8(unsigned int V);
void setvram4(uint32 A, uint8 *p);
void setvram8(uint8 *p);
void setvramb1(uint8 *p, uint32 A, uint32 b);
void setvramb2(uint8 *p, uint32 A, uint32 b);
void setvramb4(uint8 *p, uint32 A, uint32 b);
void setvramb8(uint8 *p, uint32 b);
void setmirror(int t);
void setmirrorw(int a, int b, int c, int d);
void setntamem(uint8 *p, int ram, uint32 b);
@ -94,8 +84,8 @@ void setntamem(uint8 *p, int ram, uint32 b);
extern int geniestage;
void GeniePower(void);
void FCEU_GeniePower(void);
void OpenGenie(void);
void CloseGenie(void);
void FCEU_OpenGenie(void);
void FCEU_CloseGenie(void);
void FCEU_KillGenie(void);

View File

@ -90,46 +90,36 @@ bool DebuggerWasUpdated = false; //To prevent the debugger from updating things
FCEUGI::FCEUGI()
: filename(0)
, archiveFilename(0)
{
, archiveFilename(0) {
//printf("%08x",opsize); // WTF?!
}
FCEUGI::~FCEUGI()
{
FCEUGI::~FCEUGI() {
if (filename) delete filename;
if (archiveFilename) delete archiveFilename;
}
bool CheckFileExists(const char* filename)
{
bool CheckFileExists(const char* filename) {
//This function simply checks to see if the given filename exists
if (!filename) return false;
fstream test;
test.open(filename, fstream::in);
if (test.fail())
{
if (test.fail()) {
test.close();
return false;
}
else
{
} else {
test.close();
return true;
}
}
void FCEU_TogglePPU(void)
{
void FCEU_TogglePPU(void) {
newppu ^= 1;
if (newppu)
{
if (newppu) {
FCEU_DispMessage("New PPU loaded", 0);
FCEUI_printf("New PPU loaded");
}
else
{
} else {
FCEU_DispMessage("Old PPU loaded", 0);
FCEUI_printf("Old PPU loaded");
}
@ -138,34 +128,27 @@ void FCEU_TogglePPU(void)
#endif
}
static void FCEU_CloseGame(void)
{
if(GameInfo)
{
static void FCEU_CloseGame(void) {
if (GameInfo) {
#ifdef WIN32
//SP CODE
extern char LoadedRomFName[2048];
if (storePreferences(LoadedRomFName))
{
if (storePreferences(LoadedRomFName)) {
FCEUD_PrintError("Couldn't store debugging data");
}
#endif
if(FCEUnetplay)
{
if (FCEUnetplay) {
FCEUD_NetworkClose();
}
if(GameInfo->name)
{
if (GameInfo->name) {
free(GameInfo->name);
GameInfo->name = 0;
}
if(GameInfo->type!=GIT_NSF)
{
if (GameInfo->type != GIT_NSF) {
FCEU_FlushGameCheats(0, 0);
}
@ -180,7 +163,7 @@ static void FCEU_CloseGame(void)
if (XBuf)
memset(XBuf, 0, 256 * 256);
CloseGenie();
FCEU_CloseGenie();
delete GameInfo;
GameInfo = NULL;
@ -232,20 +215,18 @@ int AutosaveFrequency = 256; // Number of frames between autosaves
int EnableAutosave = 0;
///a wrapper for unzip.c
extern "C" FILE *FCEUI_UTF8fopen_C(const char *n, const char *m) { return ::FCEUD_UTF8fopen(n,m); }
static DECLFW(BNull)
{
extern "C" FILE *FCEUI_UTF8fopen_C(const char *n, const char *m) {
return ::FCEUD_UTF8fopen(n, m);
}
static DECLFR(ANull)
{
static DECLFW(BNull) {
}
static DECLFR(ANull) {
return(X.DB);
}
int AllocGenieRW(void)
{
int AllocGenieRW(void) {
if (!(AReadG = (readfunc*)FCEU_malloc(0x8000 * sizeof(readfunc))))
return 0;
if (!(BWriteG = (writefunc*)FCEU_malloc(0x8000 * sizeof(writefunc))))
@ -254,14 +235,11 @@ int AllocGenieRW(void)
return 1;
}
void FlushGenieRW(void)
{
void FlushGenieRW(void) {
int32 x;
if(RWWrap)
{
for(x=0;x<0x8000;x++)
{
if (RWWrap) {
for (x = 0; x < 0x8000; x++) {
ARead[x + 0x8000] = AReadG[x];
BWrite[x + 0x8000] = BWriteG[x];
}
@ -273,51 +251,44 @@ void FlushGenieRW(void)
}
}
readfunc GetReadHandler(int32 a)
{
readfunc GetReadHandler(int32 a) {
if (a >= 0x8000 && RWWrap)
return AReadG[a - 0x8000];
else
return ARead[a];
}
void SetReadHandler(int32 start, int32 end, readfunc func)
{
void SetReadHandler(int32 start, int32 end, readfunc func) {
int32 x;
if (!func)
func = ANull;
if (RWWrap)
for(x=end;x>=start;x--)
{
for (x = end; x >= start; x--) {
if (x >= 0x8000)
AReadG[x - 0x8000] = func;
else
ARead[x] = func;
}
else
for (x = end; x >= start; x--)
ARead[x] = func;
}
writefunc GetWriteHandler(int32 a)
{
writefunc GetWriteHandler(int32 a) {
if (RWWrap && a >= 0x8000)
return BWriteG[a - 0x8000];
else
return BWrite[a];
}
void SetWriteHandler(int32 start, int32 end, writefunc func)
{
void SetWriteHandler(int32 start, int32 end, writefunc func) {
int32 x;
if (!func)
func = BNull;
if (RWWrap)
for(x=end;x>=start;x--)
{
for (x = end; x >= start; x--) {
if (x >= 0x8000)
BWriteG[x - 0x8000] = func;
else
@ -334,14 +305,12 @@ uint8 *RAM;
//---------
//windows might need to allocate these differently, so we have some special code
static void AllocBuffers()
{
static void AllocBuffers() {
GameMemBlock = (uint8*)FCEU_gmalloc(GAME_MEM_BLOCK_SIZE);
RAM = (uint8*)FCEU_gmalloc(0x800);
}
static void FreeBuffers()
{
static void FreeBuffers() {
FCEU_free(GameMemBlock);
FCEU_free(RAM);
}
@ -349,35 +318,30 @@ static void FreeBuffers()
uint8 PAL = 0;
static DECLFW(BRAML)
{
static DECLFW(BRAML) {
RAM[A] = V;
#ifdef _S9XLUA_H
CallRegisteredLuaMemHook(A, 1, V, LUAMEMHOOK_WRITE);
#endif
}
static DECLFW(BRAMH)
{
static DECLFW(BRAMH) {
RAM[A & 0x7FF] = V;
#ifdef _S9XLUA_H
CallRegisteredLuaMemHook(A & 0x7FF, 1, V, LUAMEMHOOK_WRITE);
#endif
}
static DECLFR(ARAML)
{
static DECLFR(ARAML) {
return RAM[A];
}
static DECLFR(ARAMH)
{
static DECLFR(ARAMH) {
return RAM[A & 0x7FF];
}
void ResetGameLoaded(void)
{
void ResetGameLoaded(void) {
if (GameInfo) FCEU_CloseGame();
EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it
GameStateRestore = 0;
@ -402,8 +366,7 @@ int NSFLoad(const char *name, FCEUFILE *fp);
//char lastLoadedGameName [2048] = {0,}; // hack for movie WRAM clearing on record from poweron
//name should be UTF-8, hopefully, or else there may be trouble
FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode)
{
FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode) {
//mbg merge 7/17/07 - why is this here
//#ifdef WIN32
// StopSound();
@ -495,7 +458,7 @@ endlseq:
if (GameInfo->type != GIT_NSF)
if (FSettings.GameGenie)
OpenGenie();
FCEU_OpenGenie();
PowerNES();
if (GameInfo->type != GIT_NSF)
@ -516,19 +479,16 @@ endlseq:
return GameInfo;
}
FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode)
{
FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode) {
return FCEUI_LoadGameVirtual(name, OverwriteVidMode);
}
//Return: Flag that indicates whether the function was succesful or not.
bool FCEUI_Initialize()
{
bool FCEUI_Initialize() {
srand(time(0));
if(!FCEU_InitVirtualVideo())
{
if (!FCEU_InitVirtualVideo()) {
return false;
}
@ -558,8 +518,7 @@ bool FCEUI_Initialize()
return true;
}
void FCEUI_Kill(void)
{
void FCEUI_Kill(void) {
#ifdef _S9XLUA_H
FCEU_LuaStop();
#endif
@ -572,51 +531,38 @@ int rapidAlternator = 0;
int AutoFirePattern[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
int AutoFirePatternLength = 2;
void SetAutoFirePattern(int onframes, int offframes)
{
void SetAutoFirePattern(int onframes, int offframes) {
int i;
for(i = 0; i < onframes && i < 8; i++)
{
for (i = 0; i < onframes && i < 8; i++) {
AutoFirePattern[i] = 1;
}
for(;i < 8; i++)
{
for (; i < 8; i++) {
AutoFirePattern[i] = 0;
}
if(onframes + offframes < 2)
{
if (onframes + offframes < 2) {
AutoFirePatternLength = 2;
}
else if(onframes + offframes > 8)
{
} else if (onframes + offframes > 8) {
AutoFirePatternLength = 8;
}
else
{
} else {
AutoFirePatternLength = onframes + offframes;
}
AFon = onframes; AFoff = offframes;
}
void SetAutoFireOffset(int offset)
{
void SetAutoFireOffset(int offset) {
if (offset < 0 || offset > 8) return;
AutoFireOffset = offset;
}
void AutoFire(void)
{
void AutoFire(void) {
static int counter = 0;
if (justLagged == false)
counter = (counter + 1) % (8 * 7 * 5 * 3);
//If recording a movie, use the frame # for the autofire so the offset
//doesn't get screwed up when loading.
if(FCEUMOV_Mode(MOVIEMODE_RECORD | MOVIEMODE_PLAY))
{
if (FCEUMOV_Mode(MOVIEMODE_RECORD | MOVIEMODE_PLAY)) {
rapidAlternator = AutoFirePattern[(AutoFireOffset + FCEUMOV_GetFrame()) % AutoFirePatternLength]; //adelikat: TODO: Think through this, MOVIEMODE_FINISHED should not use movie data for auto-fire?
}
else
{
} else {
rapidAlternator = AutoFirePattern[(AutoFireOffset + counter) % AutoFirePatternLength];
}
}
@ -626,15 +572,13 @@ void UpdateAutosave(void);
///Emulates a single frame.
///Skip may be passed in, if FRAMESKIP is #defined, to cause this to emulate more than one frame
void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int skip)
{
void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int skip) {
//skip initiates frame skip if 1, or frame skip and sound skip if 2
int r, ssize;
JustFrameAdvanced = false;
if (frameAdvanceRequested)
{
if (frameAdvanceRequested) {
if (frameAdvanceDelay == 0 || frameAdvanceDelay >= 10)
EmulationPaused = 3;
if (frameAdvanceDelay == 0 || frameAdvanceDelay < 10)
@ -643,8 +587,7 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski
if (EmulationPaused & 2)
EmulationPaused &= ~1; // clear paused flag temporarily (frame advance)
else if((EmulationPaused&1))
{
else if ((EmulationPaused & 1)) {
memcpy(XBuf, XBackBuf, 256 * 256);
FCEU_PutImage();
*pXBuf = XBuf;
@ -693,50 +636,41 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski
timestamp = 0;
*pXBuf = skip ? 0 : XBuf;
if (skip == 2) //If skip = 2, then bypass sound
{
if (skip == 2) { //If skip = 2, then bypass sound
*SoundBuf = 0;
*SoundBufSize = 0;
}
else
{
} else {
*SoundBuf = WaveFinal;
*SoundBufSize = ssize;
}
if (EmulationPaused&2 && ( !frameAdvanceLagSkip || !lagFlag) )
if (EmulationPaused & 2 && (!frameAdvanceLagSkip || !lagFlag)) {
//Lots of conditions here. EmulationPaused&2 must be true. In addition frameAdvanceLagSkip or lagFlag must be false
{
EmulationPaused = 1; // restore paused flag
JustFrameAdvanced = true;
#ifdef WIN32
if (soundoptions & SO_MUTEFA) //mute the frame advance if the user requested it
*SoundBufSize = 0; //keep sound muted
#endif
}
if (lagFlag)
{
if (lagFlag) {
lagCounter++;
justLagged = true;
}
else justLagged = false;
} else justLagged = false;
if (movieSubtitles)
ProcessSubtitles();
}
void FCEUI_CloseGame(void)
{
void FCEUI_CloseGame(void) {
if (!FCEU_IsValidUI(FCEUI_CLOSEGAME))
return;
FCEU_CloseGame();
}
void ResetNES(void)
{
void ResetNES(void) {
FCEUMOV_AddCommand(FCEUNPCMD_RESET);
if (!GameInfo) return;
GameInterface(GI_RESETM2);
@ -751,11 +685,9 @@ void ResetNES(void)
FCEU_DispMessage("Reset", 0);
}
void FCEU_MemoryRand(uint8 *ptr, uint32 size)
{
void FCEU_MemoryRand(uint8 *ptr, uint32 size) {
int x = 0;
while(size)
{
while (size) {
*ptr = (x & 4) ? 0xFF : 0x00; // Huang Di DEBUG MODE enabled by default
// Cybernoid NO MUSIC by default
// *ptr = (x & 4) ? 0x7F : 0x00; // Huang Di DEBUG MODE enabled by default
@ -770,26 +702,17 @@ void FCEU_MemoryRand(uint8 *ptr, uint32 size)
}
}
void hand(X6502 *X, int type, unsigned int A)
{
void hand(X6502 *X, int type, uint32 A) {
}
//int suppressAddPowerCommand=0; // hack... yeah, I know...
void PowerNES(void)
{
//void MapperInit();
//MapperInit();
//if(!suppressAddPowerCommand)
void PowerNES(void) {
FCEUMOV_AddCommand(FCEUNPCMD_POWER);
if (!GameInfo) return;
FCEU_CheatResetRAM();
FCEU_CheatAddRAM(2, 0, RAM);
GeniePower();
FCEU_GeniePower();
//dont do this, it breaks some games: Cybernoid; Minna no Taabou no Nakayoshi Daisakusen; and maybe mechanized attack
//memset(RAM,0xFF,0x800);
@ -841,8 +764,7 @@ void PowerNES(void)
FCEU_DispMessage("Power on", 0);
}
void FCEU_ResetVidSys(void)
{
void FCEU_ResetVidSys(void) {
int w;
if (GameInfo->vidsys == GIV_NTSC)
@ -859,8 +781,7 @@ void FCEU_ResetVidSys(void)
FCEUS FSettings;
void FCEU_printf(char *format, ...)
{
void FCEU_printf(char *format, ...) {
char temp[2048];
va_list ap;
@ -872,8 +793,7 @@ void FCEU_printf(char *format, ...)
va_end(ap);
}
void FCEU_PrintError(char *format, ...)
{
void FCEU_PrintError(char *format, ...) {
char temp[2048];
va_list ap;
@ -885,38 +805,30 @@ void FCEU_PrintError(char *format, ...)
va_end(ap);
}
void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall)
{
void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) {
FSettings.UsrFirstSLine[0] = ntscf;
FSettings.UsrLastSLine[0] = ntscl;
FSettings.UsrFirstSLine[1] = palf;
FSettings.UsrLastSLine[1] = pall;
if(PAL)
{
if (PAL) {
FSettings.FirstSLine = FSettings.UsrFirstSLine[1];
FSettings.LastSLine = FSettings.UsrLastSLine[1];
}
else
{
} else {
FSettings.FirstSLine = FSettings.UsrFirstSLine[0];
FSettings.LastSLine = FSettings.UsrLastSLine[0];
}
}
void FCEUI_SetVidSystem(int a)
{
void FCEUI_SetVidSystem(int a) {
FSettings.PAL = a ? 1 : 0;
if(GameInfo)
{
if (GameInfo) {
FCEU_ResetVidSys();
FCEU_ResetPalette();
FCEUD_VideoChanged();
}
}
int FCEUI_GetCurrentVidSystem(int *slstart, int *slend)
{
int FCEUI_GetCurrentVidSystem(int *slstart, int *slend) {
if (slstart)
*slstart = FSettings.FirstSLine;
if (slend)
@ -925,8 +837,7 @@ int FCEUI_GetCurrentVidSystem(int *slstart, int *slend)
}
//Enable or disable Game Genie option.
void FCEUI_SetGameGenie(bool a)
{
void FCEUI_SetGameGenie(bool a) {
FSettings.GameGenie = a;
}
@ -936,63 +847,53 @@ void FCEUI_SetGameGenie(bool a)
// FSettings.SnapName = a;
//}
int32 FCEUI_GetDesiredFPS(void)
{
int32 FCEUI_GetDesiredFPS(void) {
if (PAL)
return(838977920); // ~50.007
else
return(1008307711); // ~60.1
}
int FCEUI_EmulationPaused(void)
{
int FCEUI_EmulationPaused(void) {
return(EmulationPaused & 1);
}
int FCEUI_EmulationFrameStepped()
{
int FCEUI_EmulationFrameStepped() {
return(EmulationPaused & 2);
}
void FCEUI_ClearEmulationFrameStepped()
{
void FCEUI_ClearEmulationFrameStepped() {
EmulationPaused &= ~2;
}
//mbg merge 7/18/06 added
//ideally maybe we shouldnt be using this, but i need it for quick merging
void FCEUI_SetEmulationPaused(int val)
{
void FCEUI_SetEmulationPaused(int val) {
EmulationPaused = val;
}
void FCEUI_ToggleEmulationPause(void)
{
void FCEUI_ToggleEmulationPause(void) {
EmulationPaused = (EmulationPaused & 1) ^ 1;
DebuggerWasUpdated = false;
}
void FCEUI_FrameAdvanceEnd(void)
{
void FCEUI_FrameAdvanceEnd(void) {
frameAdvanceRequested = false;
}
void FCEUI_FrameAdvance(void)
{
void FCEUI_FrameAdvance(void) {
frameAdvanceRequested = true;
frameAdvanceDelay = 0;
}
static int AutosaveCounter = 0;
void UpdateAutosave(void)
{
void UpdateAutosave(void) {
if (!EnableAutosave || turbo)
return;
char * f;
if(++AutosaveCounter >= AutosaveFrequency)
{
if (++AutosaveCounter >= AutosaveFrequency) {
AutosaveCounter = 0;
AutosaveIndex = (AutosaveIndex + 1) % AutosaveQty;
f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str());
@ -1003,21 +904,18 @@ void UpdateAutosave(void)
}
}
void FCEUI_Autosave(void)
{
void FCEUI_Autosave(void) {
if (!EnableAutosave || !AutoSS)
return;
if(AutosaveStatus[AutosaveIndex] == 1)
{
if (AutosaveStatus[AutosaveIndex] == 1) {
char * f;
f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str());
FCEUSS_Load(f);
free(f);
//Set pointer to previous available slot
if(AutosaveStatus[(AutosaveIndex + AutosaveQty-1)%AutosaveQty] == 1)
{
if (AutosaveStatus[(AutosaveIndex + AutosaveQty - 1) % AutosaveQty] == 1) {
AutosaveIndex = (AutosaveIndex + AutosaveQty - 1) % AutosaveQty;
}
@ -1026,19 +924,15 @@ void FCEUI_Autosave(void)
}
}
int FCEU_TextScanlineOffset(int y)
{
int FCEU_TextScanlineOffset(int y) {
return FSettings.FirstSLine * 256;
}
int FCEU_TextScanlineOffsetFromBottom(int y)
{
int FCEU_TextScanlineOffsetFromBottom(int y) {
return (FSettings.LastSLine - y) * 256;
}
bool FCEU_IsValidUI(EFCEUI ui)
{
switch(ui)
{
bool FCEU_IsValidUI(EFCEUI ui) {
switch (ui) {
case FCEUI_OPENGAME:
case FCEUI_CLOSEGAME:
if (FCEUMOV_Mode(MOVIEMODE_TASEDITOR)) return false;
@ -1080,7 +974,6 @@ bool FCEU_IsValidUI(EFCEUI ui)
#endif
if (!FCEUMOV_Mode(MOVIEMODE_INACTIVE)) return false;
break;
}
return true;
}
@ -1097,8 +990,8 @@ public:
FCEUXCart()
: CHR(0)
, PRG(0)
{}
, PRG(0) {
}
~FCEUXCart() {
if (CHR) delete[] CHR;
@ -1150,8 +1043,7 @@ void FCEUXGameInterface(GI command) {
bool FCEUXLoad(const char *name, FCEUFILE *fp)
{
bool FCEUXLoad(const char *name, FCEUFILE *fp) {
//read ines header
iNES_HEADER head;
if (FCEU_fread(&head, 1, 16, fp) != 16)

View File

@ -51,31 +51,18 @@ uint8 *ROM = NULL;
uint8 *VROM = NULL;
iNES_HEADER head;
static CartInfo iNESCart;
uint8 iNESMirroring = 0;
uint16 iNESCHRBankList[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
int32 iNESIRQLatch = 0, iNESIRQCount = 0;
uint8 iNESIRQa = 0;
uint8 Mirroring = 0;
uint32 ROM_size = 0;
uint32 VROM_size = 0;
char LoadedRomFName[2048]; //mbg merge 7/17/06 added
static int CHRRAMSize = -1;
static void iNESPower(void);
static int NewiNES_Init(int num);
void (*MapperReset)(void);
static int iNES_Init(int num);
static int MapperNo = 0;
/* MapperReset() is called when the NES is reset(with the reset button).
Mapperxxx_init is called when the NES has been powered on.
*/
static DECLFR(TrainerRead) {
return(trainerpoo[A & 0x1FF]);
}
@ -106,8 +93,6 @@ void iNESGI(GI h) { //bbit edited: removed static keyword
break;
case GI_RESETM2:
if (MapperReset)
MapperReset();
if (iNESCart.Reset)
iNESCart.Reset();
break;
@ -117,16 +102,19 @@ void iNESGI(GI h) { //bbit edited: removed static keyword
case GI_CLOSE:
{
FCEU_SaveGameSave(&iNESCart);
if (iNESCart.Close) iNESCart.Close();
if (iNESCart.Close)
iNESCart.Close();
if (ROM) {
free(ROM); ROM = NULL;
free(ROM);
ROM = NULL;
}
if (VROM) {
free(VROM); VROM = NULL;
free(VROM);
VROM = NULL;
}
if (trainerpoo) {
FCEU_gfree(trainerpoo); trainerpoo = 0;
FCEU_gfree(trainerpoo);
trainerpoo = NULL;
}
}
break;
@ -249,10 +237,7 @@ static struct BADINF BadROMImages[] =
};
void CheckBad(uint64 md5partial) {
int x;
x = 0;
//printf("0x%llx\n",md5partial);
int32 x = 0;
while (BadROMImages[x].name) {
if (BadROMImages[x].md5partial == md5partial) {
FCEU_PrintError("The copy game you have loaded, \"%s\", is bad, and will not work properly in FCEUX.", BadROMImages[x].name);
@ -270,18 +255,6 @@ struct CHINF {
const char* params;
};
void MapperInit() {
if (NewiNES_Init(MapperNo)) {
} else {
iNESCart.Power = iNESPower;
SetupCartPRGMapping(1, WRAM, 8192, 1);
if (head.ROM_type & 2) {
iNESCart.SaveGame[0] = WRAM;
iNESCart.SaveGameLen[0] = 8192;
}
}
}
static const TMasterRomInfo sMasterRomInfo[] = {
{ 0x62b51b108a01d2beLL, "bonus=0" }, //4-in-1 (FK23C8021)[p1][!].nes
{ 0x8bb48490d8d22711LL, "bonus=0" }, //4-in-1 (FK23C8033)[p1][!].nes
@ -345,14 +318,11 @@ static void CheckHInfo(void) {
{
#include "ines-correct.h"
};
int tofix = 0;
int x;
int32 tofix = 0, x;
uint64 partialmd5 = 0;
for (x = 0; x < 8; x++) {
for (x = 0; x < 8; x++)
partialmd5 |= (uint64)iNESCart.MD5[15 - x] << (x * 8);
//printf("%16llx\n",partialmd5);
}
CheckBad(partialmd5);
MasterRomInfo = NULL;
@ -373,7 +343,6 @@ static void CheckHInfo(void) {
}
x = 0;
do {
if (moo[x].crc32 == iNESGameCRC32) {
if (moo[x].mapper >= 0) {
@ -451,7 +420,7 @@ static void CheckHInfo(void) {
}
typedef struct {
int mapper;
int32 mapper;
void (*init)(CartInfo *);
} NewMI;
@ -467,7 +436,7 @@ static int not_power2[] =
};
typedef struct {
char *name;
int number;
int32 number;
void (*init)(CartInfo *);
} BMAPPINGLocal;
@ -865,9 +834,10 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
iNESCart.battery = (head.ROM_type & 2) ? 1 : 0;
iNESCart.mirror = Mirroring;
if (!iNES_Init(MapperNo))
FCEU_PrintError("iNES mapper #%d is not supported at all.", MapperNo);
GameInfo->mappernum = MapperNo;
MapperInit();
FCEU_LoadGameSave(&iNESCart);
strcpy(LoadedRomFName, name); //bbit edited: line added
@ -966,461 +936,7 @@ char *iNesShortFName() {
return ret + 1;
}
void VRAM_BANK1(uint32 A, uint8 V) {
V &= 7;
PPUCHRRAM |= (1 << (A >> 10));
CHRBankList[(A) >> 10] = V;
VPage[(A) >> 10] = &CHRRAM[V << 10] - (A);
}
void VRAM_BANK4(uint32 A, uint32 V) {
V &= 1;
PPUCHRRAM |= (0xF << (A >> 10));
CHRBankList[(A) >> 10] = (V << 2);
CHRBankList[((A) >> 10) + 1] = (V << 2) + 1;
CHRBankList[((A) >> 10) + 2] = (V << 2) + 2;
CHRBankList[((A) >> 10) + 3] = (V << 2) + 3;
VPage[(A) >> 10] = &CHRRAM[V << 10] - (A);
}
void VROM_BANK1(uint32 A, uint32 V) {
setchr1(A, V);
CHRBankList[(A) >> 10] = V;
}
void VROM_BANK2(uint32 A, uint32 V) {
setchr2(A, V);
CHRBankList[(A) >> 10] = (V << 1);
CHRBankList[((A) >> 10) + 1] = (V << 1) + 1;
}
void VROM_BANK4(uint32 A, uint32 V) {
setchr4(A, V);
CHRBankList[(A) >> 10] = (V << 2);
CHRBankList[((A) >> 10) + 1] = (V << 2) + 1;
CHRBankList[((A) >> 10) + 2] = (V << 2) + 2;
CHRBankList[((A) >> 10) + 3] = (V << 2) + 3;
}
void VROM_BANK8(uint32 V) {
setchr8(V);
CHRBankList[0] = (V << 3);
CHRBankList[1] = (V << 3) + 1;
CHRBankList[2] = (V << 3) + 2;
CHRBankList[3] = (V << 3) + 3;
CHRBankList[4] = (V << 3) + 4;
CHRBankList[5] = (V << 3) + 5;
CHRBankList[6] = (V << 3) + 6;
CHRBankList[7] = (V << 3) + 7;
}
void ROM_BANK8(uint32 A, uint32 V) {
setprg8(A, V);
if (A >= 0x8000)
PRGBankList[((A - 0x8000) >> 13)] = V;
}
void ROM_BANK16(uint32 A, uint32 V) {
setprg16(A, V);
if (A >= 0x8000) {
PRGBankList[((A - 0x8000) >> 13)] = V << 1;
PRGBankList[((A - 0x8000) >> 13) + 1] = (V << 1) + 1;
}
}
void ROM_BANK32(uint32 V) {
setprg32(0x8000, V);
PRGBankList[0] = V << 2;
PRGBankList[1] = (V << 2) + 1;
PRGBankList[2] = (V << 2) + 2;
PRGBankList[3] = (V << 2) + 3;
}
void onemir(uint8 V) {
if (Mirroring == 2) return;
if (V > 1)
V = 1;
Mirroring = 0x10 | V;
setmirror(MI_0 + V);
}
void MIRROR_SET2(uint8 V) {
if (Mirroring == 2) return;
Mirroring = V;
setmirror(V);
}
void MIRROR_SET(uint8 V) {
if (Mirroring == 2) return;
V ^= 1;
Mirroring = V;
setmirror(V);
}
static void NONE_init(void) {
ROM_BANK16(0x8000, 0);
ROM_BANK16(0xC000, ~0);
if (VROM_size)
VROM_BANK8(0);
else
setvram8(CHRRAM);
}
void(*MapInitTab[256]) (void) =
{
0,
0,
0, //Mapper2_init,
0, //Mapper3_init,
0,
0,
0, //Mapper6_init,
0, //Mapper7_init,
0, //Mapper8_init,
0, //Mapper9_init,
0, //Mapper10_init,
0, //Mapper11_init,
0,
0, //Mapper13_init,
0,
0, //Mapper15_init,
0, //Mapper16_init,
0, //Mapper17_init,
0, //Mapper18_init,
0,
0,
0, //Mapper21_init,
0, //Mapper22_init,
0, //Mapper23_init,
0, //Mapper24_init,
0, //Mapper25_init,
0, //Mapper26_init,
0, //Mapper27_init,
0,
0,
0,
0,
0, //Mapper32_init,
0, //Mapper33_init,
0, //Mapper34_init,
0,
0,
0,
0,
0,
0, //Mapper40_init,
0, //Mapper41_init,
0, //Mapper42_init,
0, //Mapper43_init,
0,
0,
0, //Mapper46_init,
0,
0, //Mapper48_init,
0,
0, //Mapper50_init,
0, //Mapper51_init,
0,
0,
0,
0,
0,
0, //Mapper57_init,
0, //Mapper58_init,
0, //Mapper59_init,
0, //Mapper60_init,
0, //Mapper61_init,
0, //Mapper62_init,
0,
0, //Mapper64_init,
0, //Mapper65_init,
0, //Mapper66_init,
0, //Mapper67_init,
0, //Mapper68_init,
0, //Mapper69_init,
0, //Mapper70_init,
0, //Mapper71_init,
0, //Mapper72_init,
0, //Mapper73_init,
0,
0, //Mapper75_init,
0, //Mapper76_init,
0, //Mapper77_init,
0, //Mapper78_init,
0, //Mapper79_init,
0, //Mapper80_init,
0,
0, //Mapper82_init,
0, //Mapper83_init,
0,
0, //Mapper85_init,
0, //Mapper86_init,
0, //Mapper87_init,
0, //Mapper88_init,
0, //Mapper89_init,
0,
0, //Mapper91_init,
0, //Mapper92_init,
0, //Mapper93_init,
0, //Mapper94_init,
0,
0, //Mapper96_init,
0, //Mapper97_init,
0,
0, //Mapper99_init,
0,
0,
0,
0,
0,
0,
0,
0, //Mapper107_init,
0,
0,
0,
0,
0,
0, //Mapper113_init,
0,
0,
0, //Mapper116_init,
0, //Mapper117_init,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0, //Mapper140_init,
0,
0,
0,
0, //Mapper144_init,
0,
0,
0,
0,
0,
0,
0, //Mapper151_init,
0, //Mapper152_init,
0, //Mapper153_init,
0, //Mapper154_init,
0,
0, //Mapper156_init,
0, //Mapper157_init,
0, //Mapper158_init, removed
0,
0,
0,
0,
0,
0,
0,
0, //Mapper166_init,
0, //Mapper167_init,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0, //Mapper180_init,
0,
0,
0,
0, //Mapper184_init,
0, //Mapper185_init,
0,
0,
0,
0, //Mapper189_init,
0,
0, //Mapper191_init,
0,
0, //Mapper193_init,
0,
0,
0,
0,
0,
0,
0, //Mapper200_init,
0, //Mapper201_init,
0, //Mapper202_init,
0, //Mapper203_init,
0, //Mapper204_init,
0,
0,
0, //Mapper207_init,
0,
0,
0,
0, //Mapper211_init,
0, //Mapper212_init,
0, //Mapper213_init,
0, //Mapper214_init,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0, //Mapper225_init,
0, //Mapper226_init,
0, //Mapper227_init,
0, //Mapper228_init,
0, //Mapper229_init,
0, //Mapper230_init,
0, //Mapper231_init,
0, //Mapper232_init,
0,
0, //Mapper234_init,
0, //Mapper235_init,
0,
0,
0,
0,
0, //Mapper240_init,
0, //Mapper241_init,
0, //Mapper242_init,
0,
0, //Mapper244_init,
0,
0, //Mapper246_init,
0,
0,
0,
0,
0,
0,
0,
0,
0, //Mapper255_init
};
static DECLFW(BWRAM) {
WRAM[A - 0x6000] = V;
}
static DECLFR(AWRAM) {
return WRAM[A - 0x6000];
}
void (*MapStateRestore)(int version);
void iNESStateRestore(int version) {
int x;
if (!MapperNo) return;
for (x = 0; x < 4; x++)
setprg8(0x8000 + x * 8192, PRGBankList[x]);
if (VROM_size)
for (x = 0; x < 8; x++)
setchr1(0x400 * x, CHRBankList[x]);
if (0) switch (Mirroring) {
case 0: setmirror(MI_H); break;
case 1: setmirror(MI_V); break;
case 0x12:
case 0x10: setmirror(MI_0); break;
case 0x13:
case 0x11: setmirror(MI_1); break;
}
if (MapStateRestore) MapStateRestore(version);
}
static void iNESPower(void) {
int x;
int type = MapperNo;
SetReadHandler(0x8000, 0xFFFF, CartBR);
GameStateRestore = iNESStateRestore;
MapperReset = 0;
MapStateRestore = 0;
setprg8r(1, 0x6000, 0);
SetReadHandler(0x6000, 0x7FFF, AWRAM);
SetWriteHandler(0x6000, 0x7FFF, BWRAM);
FCEU_CheatAddRAM(8, 0x6000, WRAM);
/* This statement represents atrocious code. I need to rewrite
all of the iNES mapper code... */
IRQCount = IRQLatch = IRQa = 0;
if (head.ROM_type & 2)
memset(GameMemBlock + 8192, 0, GAME_MEM_BLOCK_SIZE - 8192);
else
memset(GameMemBlock, 0, GAME_MEM_BLOCK_SIZE);
NONE_init();
ResetExState(0, 0);
if (GameInfo->type == GIT_VSUNI)
AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0);
AddExState(WRAM, 8192, 0, "WRAM");
if (type == 85)
AddExState(MapperExRAM, 32768, 0, "MEXR");
if ((!VROM_size || type == 6 || type == 19) && (type != 13))
AddExState(CHRRAM, 8192 * 4, 0, "CHRR");
if (head.ROM_type & 8)
AddExState(ExtraNTARAM, 2048, 0, "EXNR");
/* Exclude some mappers whose emulation code handle save state stuff
themselves. */
if (type && type != 13) {
AddExState(mapbyte1, 32, 0, "MPBY");
AddExState(&Mirroring, 1, 0, "MIRR");
AddExState(&IRQCount, 4, 1, "IRQC");
AddExState(&IRQLatch, 4, 1, "IQL1");
AddExState(&IRQa, 1, 0, "IRQA");
AddExState(PRGBankList, 4, 0, "PBL");
for (x = 0; x < 8; x++) {
char tak[8];
sprintf(tak, "CBL%d", x);
AddExState(&CHRBankList[x], 2, 1, tak);
}
}
if (MapInitTab[type])
MapInitTab[type]();
else
if (type) {
FCEU_PrintError("iNES mapper #%d is not supported at all.", type);
}
}
static int NewiNES_Init(int num) {
static int iNES_Init(int num) {
BMAPPINGLocal *tmp = bmap;
CHRRAMSize = -1;

View File

@ -26,46 +26,17 @@
#include <map>
#ifdef INESPRIV
void iNESStateRestore(int version);
extern uint32 iNESGameCRC32;
extern uint32 VROM_size;
extern uint32 ROM_size;
extern void (*MapStateRestore)(int version);
extern void (*MapClose)(void);
extern void (*MapperReset)(void);
/* This order is necessary */
#define WRAM (GameMemBlock)
#define sizeofWRAM 8192
#define MapperExRAM (GameMemBlock+sizeofWRAM)
#define sizeofMapperExRAM 32768
/* for the MMC5 code to work properly. It might be fixed later... */
#define CHRRAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM)
#define CHRRAM (GameMemBlock + sizeofWRAM)
#define sizeofCHRRAM 8192
#define ExtraNTARAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM+sizeofCHRRAM)
#define ExtraNTARAM (GameMemBlock + sizeofWRAM + sizeofCHRRAM)
#define sizeofExtraNTARAM 2048
#define PRGBankList (ExtraNTARAM+sizeofExtraNTARAM)
#define mapbyte1 (PRGBankList+4)
#define mapbyte2 (mapbyte1+8)
#define mapbyte3 (mapbyte2+8)
#define mapbyte4 (mapbyte3+8)
extern uint16 iNESCHRBankList[8];
extern int32 iNESIRQLatch,iNESIRQCount;
extern uint8 iNESMirroring;
extern uint8 iNESIRQa;
#define IRQa iNESIRQa
#define Mirroring iNESMirroring
#define IRQCount iNESIRQCount
#define IRQLatch iNESIRQLatch
#define CHRBankList iNESCHRBankList
#else
#endif
@ -124,248 +95,11 @@ struct iNES_HEADER {
};
extern struct iNES_HEADER head; //for mappers usage
void VRAM_BANK1(uint32 A, uint8 V);
void VRAM_BANK4(uint32 A,uint32 V);
void VROM_BANK1(uint32 A,uint32 V);
void VROM_BANK2(uint32 A,uint32 V);
void VROM_BANK4(uint32 A, uint32 V);
void VROM_BANK8(uint32 V);
void ROM_BANK8(uint32 A, uint32 V);
void ROM_BANK16(uint32 A, uint32 V);
void ROM_BANK32(uint32 V);
extern uint8 vmask;
extern uint32 vmask1;
extern uint32 vmask2;
extern uint32 vmask4;
extern uint32 pmask8;
extern uint8 pmask16;
extern uint8 pmask32;
void onemir(uint8 V);
void MIRROR_SET2(uint8 V);
void MIRROR_SET(uint8 V);
//void Mapper0_init(void);
//void Mapper1_init(void);
//void Mapper2_init(void);
//void Mapper3_init(void);
//void Mapper6_init(void);
//void Mapper7_init(void);
//void Mapper8_init(void);
//void Mapper9_init(void);
//void Mapper10_init(void);
//void Mapper11_init(void);
void Mapper12_init(void);
//void Mapper13_init(void);
void Mapper14_init(void);
//void Mapper15_init(void);
//void Mapper16_init(void);
//void Mapper17_init(void);
//void Mapper18_init(void);
void Mapper19_init(void);
void Mapper20_init(void);
//void Mapper21_init(void);
//void Mapper22_init(void);
//void Mapper23_init(void);
//void Mapper24_init(void);
//void Mapper25_init(void);
//void Mapper26_init(void);
//void Mapper27_init(void);
void Mapper28_init(void);
void Mapper29_init(void);
void Mapper30_init(void);
void Mapper31_init(void);
//void Mapper32_init(void);
//void Mapper33_init(void);
//void Mapper34_init(void);
void Mapper35_init(void);
void Mapper36_init(void);
//void Mapper37_init(void);
//void Mapper38_init(void);
//void Mapper39_init(void);
//void Mapper40_init(void);
//void Mapper41_init(void);
//void Mapper42_init(void);
//void Mapper43_init(void);
void Mapper44_init(void);
void Mapper45_init(void);
//void Mapper46_init(void);
void Mapper47_init(void);
//void Mapper48_init(void);
void Mapper49_init(void);
//void Mapper50_init(void);
//void Mapper51_init(void);
void Mapper53_init(void);
void Mapper54_init(void);
void Mapper55_init(void);
void Mapper56_init(void);
//void Mapper59_init(void);
void Mapper60_init(void);
//void Mapper61_init(void);
//void Mapper62_init(void);
void Mapper63_init(void);
//void Mapper64_init(void);
//void Mapper65_init(void);
//void Mapper66_init(void);
//void Mapper67_init(void);
//void Mapper68_init(void);
//void Mapper69_init(void);
//void Mapper70_init(void);
//void Mapper71_init(void);
//void Mapper72_init(void);
//void Mapper73_init(void);
//void Mapper74_init(void);
//void Mapper75_init(void);
//void Mapper76_init(void);
//void Mapper77_init(void);
//void Mapper78_init(void);
//void Mapper79_init(void);
//void Mapper80_init(void);
void Mapper81_init(void);
//void Mapper82_init(void);
void Mapper83_init(void);
void Mapper84_init(void);
//void Mapper85_init(void);
//void Mapper86_init(void);
//void Mapper87_init(void);
void Mapper88_init(void);
//void Mapper89_init(void);
//void Mapper91_init(void);
//void Mapper92_init(void);
//void Mapper93_init(void);
//void Mapper94_init(void);
//void Mapper96_init(void);
//void Mapper97_init(void);
void Mapper98_init(void);
//void Mapper99_init(void);
void Mapper100_init(void);
//void Mapper101_init(void);
//void Mapper103_init(void);
void Mapper104_init(void);
//void Mapper106_init(void);
//void Mapper107_init(void);
//void Mapper108_init(void);
void Mapper109_init(void);
void Mapper110_init(void);
//void Mapper111_init(void);
//void Mapper113_init(void);
void Mapper115_init(void);
//void Mapper116_init(void);
//void Mapper117_init(void);
//void Mapper120_init(void);
//void Mapper121_init(void);
void Mapper122_init(void);
void Mapper123_init(void);
void Mapper124_init(void);
void Mapper126_init(void);
void Mapper127_init(void);
void Mapper128_init(void);
void Mapper129_init(void);
void Mapper130_init(void);
void Mapper131_init(void);
void Mapper132_init(void);
//void Mapper134_init(void);
void Mapper135_init(void);
void Mapper136_init(void);
void Mapper137_init(void);
void Mapper139_init(void);
//void Mapper140_init(void);
void Mapper141_init(void);
//void Mapper142_init(void);
void Mapper143_init(void);
//void Mapper144_init(void);
void Mapper150_init(void);
//void Mapper151_init(void);
//void Mapper152_init(void);
//void Mapper153_init(void);
void Mapper154_init(void);
//void Mapper156_init(void);
//void Mapper157_init(void);
//void Mapper158_init(void);
//void Mapper159_init(void);
void Mapper160_init(void);
void Mapper161_init(void);
void Mapper162_init(void);
//void Mapper166_init(void);
//void Mapper167_init(void);
void Mapper168_init(void);
//void Mapper169_init(void);
void Mapper170_init(void);
//void Mapper171_init(void);
//void Mapper172_init(void);
//void Mapper173_init(void);
void Mapper174_init(void);
void Mapper175_init(void);
void Mapper176_init(void);
//void Mapper177_init(void);
//void Mapper178_init(void);
//void Mapper179_init(void);
void Mapper180_init(void);
//void Mapper181_init(void);
//void Mapper184_init(void);
//void Mapper185_init(void);
//void Mapper189_init(void);
//void Mapper192_init(void);
//void Mapper193_init(void);
//void Mapper194_init(void);
//void Mapper195_init(void);
//void Mapper196_init(void);
//void Mapper197_init(void);
//void Mapper198_init(void);
void Mapper199_init(void);
//void Mapper200_init(void);
//void Mapper201_init(void);
//void Mapper202_init(void);
//void Mapper203_init(void);
//void Mapper204_init(void);
//void Mapper207_init(void);
//void Mapper211_init(void);
//void Mapper212_init(void);
//void Mapper213_init(void);
//void Mapper214_init(void);
//void Mapper218_init(void);
void Mapper219_init(void);
//void Mapper220_init(void);
//void Mapper221_init(void);
//void Mapper222_init(void);
void Mapper223_init(void);
void Mapper224_init(void);
//void Mapper225_init(void);
//void Mapper226_init(void);
//void Mapper227_init(void);
//void Mapper228_init(void);
//void Mapper229_init(void);
//void Mapper230_init(void);
//void Mapper231_init(void);
//void Mapper232_init(void);
//void Mapper233_init(void);
//void Mapper234_init(void);
//void Mapper235_init(void);
void Mapper236_init(void);
void Mapper237_init(void);
void Mapper238_init(void);
void Mapper239_init(void);
void Mapper240_init(void);
//void Mapper241_init(void);
//void Mapper242_init(void);
//void Mapper244_init(void);
void Mapper245_init(void);
//void Mapper246_init(void);
void Mapper247_init(void);
void Mapper249_init(void);
void Mapper251_init(void);
//void Mapper252_init(void);
//void Mapper253_init(void);
//void Mapper255_init(void);
void NSFVRC6_Init(void);
void NSFMMC5_Init(void);
void NSFAY_Init(void);
void NSFN106_Init(void);
void NSFVRC7_Init(void);
void Mapper19_ESI(void);
void Mapper1_Init(CartInfo *);
void Mapper4_Init(CartInfo *);