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

@ -1,22 +1,22 @@
/* FCE Ultra - NES/Famicom Emulator /* FCE Ultra - NES/Famicom Emulator
* *
* Copyright notice for this file: * Copyright notice for this file:
* Copyright (C) 2002 Xodnizel * Copyright (C) 2002 Xodnizel
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/// \file /// \file
/// \brief This file contains all code for coordinating the mapping in of the address space external to the NES. /// \brief This file contains all code for coordinating the mapping in of the address space external to the NES.
@ -37,8 +37,8 @@
#include "utils/memory.h" #include "utils/memory.h"
uint8 *Page[32],*VPage[8]; uint8 *Page[32], *VPage[8];
uint8 **VPageR=VPage; uint8 **VPageR = VPage;
uint8 *VPageG[8]; uint8 *VPageG[8];
uint8 *MMC5SPRVPage[8]; uint8 *MMC5SPRVPage[8];
uint8 *MMC5BGVPage[8]; uint8 *MMC5BGVPage[8];
@ -66,7 +66,7 @@ uint32 CHRmask2[32];
uint32 CHRmask4[32]; uint32 CHRmask4[32];
uint32 CHRmask8[32]; uint32 CHRmask8[32];
int geniestage=0; int geniestage = 0;
int modcon; int modcon;
@ -75,614 +75,487 @@ uint8 geniech[3];
uint32 genieaddr[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;
uint32 AB=A>>11;
int x; int x;
if(p) if (p)
for(x=(s>>1)-1;x>=0;x--) for (x = (s >> 1) - 1; x >= 0; x--) {
{ PRGIsRAM[AB + x] = ram;
PRGIsRAM[AB+x]=ram; Page[AB + x] = p - A;
Page[AB+x]=p-A;
} }
else else
for(x=(s>>1)-1;x>=0;x--) for (x = (s >> 1) - 1; x >= 0; x--) {
{ PRGIsRAM[AB + x] = 0;
PRGIsRAM[AB+x]=0; Page[AB + x] = 0;
Page[AB+x]=0;
} }
} }
static uint8 nothing[8192]; static uint8 nothing[8192];
void ResetCartMapping(void) void ResetCartMapping(void) {
{
int x; int x;
PPU_ResetHooks(); PPU_ResetHooks();
for(x=0;x<32;x++) for (x = 0; x < 32; x++) {
{ Page[x] = nothing - x * 2048;
Page[x]=nothing-x*2048; PRGptr[x] = CHRptr[x] = 0;
PRGptr[x]=CHRptr[x]=0; PRGsize[x] = CHRsize[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;
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;
PRGptr[chip]=p; PRGsize[chip] = size;
PRGsize[chip]=size;
PRGmask2[chip]=(size>>11)-1; PRGmask2[chip] = (size >> 11) - 1;
PRGmask4[chip]=(size>>12)-1; PRGmask4[chip] = (size >> 12) - 1;
PRGmask8[chip]=(size>>13)-1; PRGmask8[chip] = (size >> 13) - 1;
PRGmask16[chip]=(size>>14)-1; PRGmask16[chip] = (size >> 14) - 1;
PRGmask32[chip]=(size>>15)-1; PRGmask32[chip] = (size >> 15) - 1;
PRGram[chip]=ram?1:0; 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;
CHRptr[chip]=p; CHRsize[chip] = size;
CHRsize[chip]=size;
CHRmask1[chip]=(size>>10)-1; CHRmask1[chip] = (size >> 10) - 1;
CHRmask2[chip]=(size>>11)-1; CHRmask2[chip] = (size >> 11) - 1;
CHRmask4[chip]=(size>>12)-1; CHRmask4[chip] = (size >> 12) - 1;
CHRmask8[chip]=(size>>13)-1; CHRmask8[chip] = (size >> 13) - 1;
CHRram[chip]=ram; CHRram[chip] = ram;
} }
DECLFR(CartBR) DECLFR(CartBR) {
{ return Page[A >> 11][A];
return Page[A>>11][A];
} }
DECLFW(CartBW) DECLFW(CartBW) {
{
//printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]); //printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]);
if(PRGIsRAM[A>>11] && Page[A>>11]) if (PRGIsRAM[A >> 11] && Page[A >> 11])
Page[A>>11][A]=V; Page[A >> 11][A] = V;
} }
DECLFR(CartBROB) DECLFR(CartBROB) {
{ if (!Page[A >> 11])
if(!Page[A>>11]) return(X.DB); return(X.DB);
return Page[A>>11][A];
}
void setprg2r(int r, unsigned int A, unsigned int V)
{
V&=PRGmask2[r];
setpageptr(2,A,PRGptr[r]?(&PRGptr[r][V<<11]):0,PRGram[r]);
}
void setprg2(uint32 A, uint32 V)
{
setprg2r(0,A,V);
}
void setprg4r(int r, unsigned int A, unsigned int V)
{
V&=PRGmask4[r];
setpageptr(4,A,PRGptr[r]?(&PRGptr[r][V<<12]):0,PRGram[r]);
}
void setprg4(uint32 A, uint32 V)
{
setprg4r(0,A,V);
}
void setprg8r(int r, unsigned int A, unsigned int V)
{
if(PRGsize[r]>=8192)
{
V&=PRGmask8[r];
setpageptr(8,A,PRGptr[r]?(&PRGptr[r][V<<13]):0,PRGram[r]);
}
else else
{ return Page[A >> 11][A];
uint32 VA=V<<2; }
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) {
setprg2r(0, A, 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) {
setprg4r(0, A, V);
}
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 {
uint32 VA = V << 2;
int x; int x;
for(x=0;x<4;x++) for (x = 0; x < 4; x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]);
} }
} }
void setprg8(uint32 A, uint32 V) void setprg8(uint32 A, uint32 V) {
{ setprg8r(0, A, V);
setprg8r(0,A,V);
} }
void setprg16r(int r, unsigned int A, unsigned int V) void setprg16r(int r, uint32 A, uint32 V) {
{ if (PRGsize[r] >= 16384) {
if(PRGsize[r]>=16384) V &= PRGmask16[r];
{ setpageptr(16, A, PRGptr[r] ? (&PRGptr[r][V << 14]) : 0, PRGram[r]);
V&=PRGmask16[r]; } else {
setpageptr(16,A,PRGptr[r]?(&PRGptr[r][V<<14]):0,PRGram[r]); uint32 VA = V << 3;
}
else
{
uint32 VA=V<<3;
int x; int x;
for(x=0;x<8;x++) for (x = 0; x < 8; x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]);
} }
} }
void setprg16(uint32 A, uint32 V) void setprg16(uint32 A, uint32 V) {
{ setprg16r(0, A, V);
setprg16r(0,A,V);
} }
void setprg32r(int r,unsigned int A, unsigned int V) void setprg32r(int r, uint32 A, uint32 V) {
{ if (PRGsize[r] >= 32768) {
if(PRGsize[r]>=32768) V &= PRGmask32[r];
{ setpageptr(32, A, PRGptr[r] ? (&PRGptr[r][V << 15]) : 0, PRGram[r]);
V&=PRGmask32[r]; } else {
setpageptr(32,A,PRGptr[r]?(&PRGptr[r][V<<15]):0,PRGram[r]); uint32 VA = V << 4;
}
else
{
uint32 VA=V<<4;
int x; int x;
for(x=0;x<16;x++) for (x = 0; x < 16; x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]);
} }
} }
void setprg32(uint32 A, uint32 V) void setprg32(uint32 A, uint32 V) {
{ setprg32r(0, A, 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;
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate(); FCEUPPU_LineUpdate();
V&=CHRmask1[r]; V &= CHRmask1[r];
if(CHRram[r]) if (CHRram[r])
PPUCHRRAM|=(1<<(A>>10)); PPUCHRRAM |= (1 << (A >> 10));
else else
PPUCHRRAM&=~(1<<(A>>10)); PPUCHRRAM &= ~(1 << (A >> 10));
VPageR[(A)>>10]=&CHRptr[r][(V)<<10]-(A); 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;
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate(); FCEUPPU_LineUpdate();
V&=CHRmask2[r]; V &= CHRmask2[r];
VPageR[(A)>>10]=VPageR[((A)>>10)+1]=&CHRptr[r][(V)<<11]-(A); VPageR[(A) >> 10] = VPageR[((A) >> 10) + 1] = &CHRptr[r][(V) << 11] - (A);
if(CHRram[r]) if (CHRram[r])
PPUCHRRAM|=(3<<(A>>10)); PPUCHRRAM |= (3 << (A >> 10));
else else
PPUCHRRAM&=~(3<<(A>>10)); 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;
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate(); FCEUPPU_LineUpdate();
V&=CHRmask4[r]; V &= CHRmask4[r];
VPageR[(A)>>10]=VPageR[((A)>>10)+1]= VPageR[(A) >> 10] = VPageR[((A) >> 10) + 1] =
VPageR[((A)>>10)+2]=VPageR[((A)>>10)+3]=&CHRptr[r][(V)<<12]-(A); VPageR[((A) >> 10) + 2] = VPageR[((A) >> 10) + 3] = &CHRptr[r][(V) << 12] - (A);
if(CHRram[r]) if (CHRram[r])
PPUCHRRAM|=(15<<(A>>10)); PPUCHRRAM |= (15 << (A >> 10));
else else
PPUCHRRAM&=~(15<<(A>>10)); PPUCHRRAM &= ~(15 << (A >> 10));
} }
void setchr8r(int r, unsigned int V) void setchr8r(int r, uint32 V) {
{
int x; int x;
if(!CHRptr[r]) return; if (!CHRptr[r]) return;
FCEUPPU_LineUpdate(); FCEUPPU_LineUpdate();
V&=CHRmask8[r]; V &= CHRmask8[r];
for(x=7;x>=0;x--) for (x = 7; x >= 0; x--)
VPageR[x]=&CHRptr[r][V<<13]; VPageR[x] = &CHRptr[r][V << 13];
if(CHRram[r]) if (CHRram[r])
PPUCHRRAM|=(255); PPUCHRRAM |= (255);
else else
PPUCHRRAM=0; PPUCHRRAM = 0;
} }
void setchr1(unsigned int A, unsigned int V) void setchr1(uint32 A, uint32 V) {
{ setchr1r(0, A, V);
setchr1r(0,A,V);
} }
void setchr2(unsigned int A, unsigned int V) void setchr2(uint32 A, uint32 V) {
{ setchr2r(0, A, V);
setchr2r(0,A,V);
} }
void setchr4(unsigned int A, unsigned int V) void setchr4(uint32 A, uint32 V) {
{ setchr4r(0, A, V);
setchr4r(0,A,V);
} }
void setchr8(unsigned int V) void setchr8(uint32 V) {
{ setchr8r(0, 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(). */ /* 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(); FCEUPPU_LineUpdate();
vnapage[b]=p; vnapage[b] = p;
PPUNTARAM&=~(1<<b); PPUNTARAM &= ~(1 << b);
if(ram) if (ram)
PPUNTARAM|=1<<b; PPUNTARAM |= 1 << b;
} }
static int mirrorhard=0; 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(); FCEUPPU_LineUpdate();
vnapage[0]=NTARAM+a*0x400; vnapage[0] = NTARAM + a * 0x400;
vnapage[1]=NTARAM+b*0x400; vnapage[1] = NTARAM + b * 0x400;
vnapage[2]=NTARAM+c*0x400; vnapage[2] = NTARAM + c * 0x400;
vnapage[3]=NTARAM+d*0x400; vnapage[3] = NTARAM + d * 0x400;
} }
void setmirror(int t) void setmirror(int t) {
{
FCEUPPU_LineUpdate(); FCEUPPU_LineUpdate();
if(!mirrorhard) if (!mirrorhard) {
{ switch (t) {
switch(t)
{
case MI_H: case MI_H:
vnapage[0]=vnapage[1]=NTARAM;vnapage[2]=vnapage[3]=NTARAM+0x400; vnapage[0] = vnapage[1] = NTARAM; vnapage[2] = vnapage[3] = NTARAM + 0x400;
break; break;
case MI_V: case MI_V:
vnapage[0]=vnapage[2]=NTARAM;vnapage[1]=vnapage[3]=NTARAM+0x400; vnapage[0] = vnapage[2] = NTARAM; vnapage[1] = vnapage[3] = NTARAM + 0x400;
break; break;
case MI_0: case MI_0:
vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=NTARAM; vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = NTARAM;
break; break;
case MI_1: case MI_1:
vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=NTARAM+0x400; vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = NTARAM + 0x400;
break; break;
} }
PPUNTARAM=0xF; PPUNTARAM = 0xF;
} }
} }
void SetupCartMirroring(int m, int hard, uint8 *extra) void SetupCartMirroring(int m, int hard, uint8 *extra) {
{ if (m < 4) {
if(m<4)
{
mirrorhard = 0; mirrorhard = 0;
setmirror(m); setmirror(m);
} else {
vnapage[0] = NTARAM;
vnapage[1] = NTARAM + 0x400;
vnapage[2] = extra;
vnapage[3] = extra + 0x400;
PPUNTARAM = 0xF;
} }
else mirrorhard = hard;
{
vnapage[0]=NTARAM;
vnapage[1]=NTARAM+0x400;
vnapage[2]=extra;
vnapage[3]=extra+0x400;
PPUNTARAM=0xF;
}
mirrorhard=hard;
} }
static uint8 *GENIEROM=0; static uint8 *GENIEROM = 0;
void FixGenieMap(void); void FixGenieMap(void);
// Called when a game(file) is opened successfully. // Called when a game(file) is opened successfully.
void OpenGenie(void) void FCEU_OpenGenie(void) {
{
FILE *fp; FILE *fp;
int x; int x;
if(!GENIEROM) if (!GENIEROM) {
{
char *fn; char *fn;
if(!(GENIEROM=(uint8 *)FCEU_malloc(4096+1024))) return; if (!(GENIEROM = (uint8*)FCEU_malloc(4096 + 1024))) return;
fn=strdup(FCEU_MakeFName(FCEUMKF_GGROM,0,0).c_str()); fn = strdup(FCEU_MakeFName(FCEUMKF_GGROM, 0, 0).c_str());
fp=FCEUD_UTF8fopen(fn,"rb"); fp = FCEUD_UTF8fopen(fn, "rb");
if(!fp) if (!fp) {
{
FCEU_PrintError("Error opening Game Genie ROM image!"); FCEU_PrintError("Error opening Game Genie ROM image!");
free(GENIEROM); free(GENIEROM);
GENIEROM=0; GENIEROM = 0;
return; return;
} }
if(fread(GENIEROM,1,16,fp)!=16) if (fread(GENIEROM, 1, 16, fp) != 16) {
{ grerr:
grerr:
FCEU_PrintError("Error reading from Game Genie ROM image!"); FCEU_PrintError("Error reading from Game Genie ROM image!");
free(GENIEROM); free(GENIEROM);
GENIEROM=0; GENIEROM = 0;
fclose(fp); fclose(fp);
return; return;
} }
if(GENIEROM[0]==0x4E) /* iNES ROM image */ if (GENIEROM[0] == 0x4E) { /* iNES ROM image */
{ if (fread(GENIEROM, 1, 4096, fp) != 4096)
if(fread(GENIEROM,1,4096,fp)!=4096)
goto grerr; goto grerr;
if(fseek(fp,16384-4096,SEEK_CUR)) if (fseek(fp, 16384 - 4096, SEEK_CUR))
goto grerr; goto grerr;
if(fread(GENIEROM+4096,1,256,fp)!=256) if (fread(GENIEROM + 4096, 1, 256, fp) != 256)
goto grerr; goto grerr;
} } else {
else if (fread(GENIEROM + 16, 1, 4352 - 16, fp) != (4352 - 16))
{
if(fread(GENIEROM+16,1,4352-16,fp)!=(4352-16))
goto grerr; goto grerr;
} }
fclose(fp); fclose(fp);
/* Workaround for the FCE Ultra CHR page size only being 1KB */ /* Workaround for the FCE Ultra CHR page size only being 1KB */
for(x=0;x<4;x++) for (x = 0; x < 4; x++)
memcpy(GENIEROM+4096+(x<<8),GENIEROM+4096,256); memcpy(GENIEROM + 4096 + (x << 8), GENIEROM + 4096, 256);
} }
geniestage=1; geniestage = 1;
} }
/* Called when a game is closed. */ /* Called when a game is closed. */
void CloseGenie(void) void FCEU_CloseGenie(void) {
{
/* No good reason to free() the Game Genie ROM image data. */ /* No good reason to free() the Game Genie ROM image data. */
geniestage=0; geniestage = 0;
FlushGenieRW(); FlushGenieRW();
VPageR=VPage; VPageR = VPage;
} }
void FCEU_KillGenie(void) void FCEU_KillGenie(void) {
{ if (GENIEROM) {
if(GENIEROM)
{
free(GENIEROM); free(GENIEROM);
GENIEROM=0; GENIEROM = 0;
} }
} }
static DECLFR(GenieRead) static DECLFR(GenieRead) {
{ return GENIEROM[A & 4095];
return GENIEROM[A&4095];
} }
static DECLFW(GenieWrite) static DECLFW(GenieWrite) {
{ switch (A) {
switch(A)
{
case 0x800c: case 0x800c:
case 0x8008: case 0x8008:
case 0x8004:genieval[((A-4)&0xF)>>2]=V;break; case 0x8004: genieval[((A - 4) & 0xF) >> 2] = V; break;
case 0x800b: case 0x800b:
case 0x8007: case 0x8007:
case 0x8003:geniech[((A-3)&0xF)>>2]=V;break; case 0x8003: geniech[((A - 3) & 0xF) >> 2] = V; break;
case 0x800a: case 0x800a:
case 0x8006: case 0x8006:
case 0x8002:genieaddr[((A-2)&0xF)>>2]&=0xFF00;genieaddr[((A-2)&0xF)>>2]|=V;break; case 0x8002: genieaddr[((A - 2) & 0xF) >> 2] &= 0xFF00; genieaddr[((A - 2) & 0xF) >> 2] |= V; break;
case 0x8009: case 0x8009:
case 0x8005: case 0x8005:
case 0x8001:genieaddr[((A-1)&0xF)>>2]&=0xFF;genieaddr[((A-1)&0xF)>>2]|=(V|0x80)<<8;break; case 0x8001: genieaddr[((A - 1) & 0xF) >> 2] &= 0xFF; genieaddr[((A - 1) & 0xF) >> 2] |= (V | 0x80) << 8; break;
case 0x8000:if(!V) case 0x8000:
FixGenieMap(); if (!V)
else FixGenieMap();
{ else {
modcon=V^0xFF; modcon = V ^ 0xFF;
if(V==0x71) if (V == 0x71)
modcon=0; modcon = 0;
} }
break; break;
} }
} }
static readfunc GenieBackup[3]; static readfunc GenieBackup[3];
static DECLFR(GenieFix1) static DECLFR(GenieFix1) {
{ uint8 r = GenieBackup[0](A);
uint8 r=GenieBackup[0](A);
if((modcon>>1)&1) // No check if ((modcon >> 1) & 1) // No check
return genieval[0]; return genieval[0];
else if(r==geniech[0]) else if (r == geniech[0])
return genieval[0]; return genieval[0];
return r; return r;
} }
static DECLFR(GenieFix2) static DECLFR(GenieFix2) {
{ uint8 r = GenieBackup[1](A);
uint8 r=GenieBackup[1](A);
if((modcon>>2)&1) // No check if ((modcon >> 2) & 1) // No check
return genieval[1]; return genieval[1];
else if(r==geniech[1]) else if (r == geniech[1])
return genieval[1]; return genieval[1];
return r; return r;
} }
static DECLFR(GenieFix3) static DECLFR(GenieFix3) {
{ uint8 r = GenieBackup[2](A);
uint8 r=GenieBackup[2](A);
if((modcon>>3)&1) // No check if ((modcon >> 3) & 1) // No check
return genieval[2]; return genieval[2];
else if(r==geniech[2]) else if (r == geniech[2])
return genieval[2]; return genieval[2];
return r; return r;
} }
void FixGenieMap(void) void FixGenieMap(void) {
{
int x; int x;
geniestage=2; geniestage = 2;
for(x=0;x<8;x++) for (x = 0; x < 8; x++)
VPage[x]=VPageG[x]; VPage[x] = VPageG[x];
VPageR=VPage; VPageR = VPage;
FlushGenieRW(); FlushGenieRW();
//printf("Rightyo\n"); //printf("Rightyo\n");
for(x=0;x<3;x++) for (x = 0; x < 3; x++)
if((modcon>>(4+x))&1) if ((modcon >> (4 + x)) & 1) {
{ readfunc tmp[3] = { GenieFix1, GenieFix2, GenieFix3 };
readfunc tmp[3]={GenieFix1,GenieFix2,GenieFix3}; GenieBackup[x] = GetReadHandler(genieaddr[x]);
GenieBackup[x]=GetReadHandler(genieaddr[x]); SetReadHandler(genieaddr[x], genieaddr[x], tmp[x]);
SetReadHandler(genieaddr[x],genieaddr[x],tmp[x]);
} }
} }
void GeniePower(void) void FCEU_GeniePower(void) {
{
uint32 x; uint32 x;
if(!geniestage) if (!geniestage)
return; return;
geniestage=1; geniestage = 1;
for(x=0;x<3;x++) for (x = 0; x < 3; x++) {
{ genieval[x] = 0xFF;
genieval[x]=0xFF; geniech[x] = 0xFF;
geniech[x]=0xFF; genieaddr[x] = 0xFFFF;
genieaddr[x]=0xFFFF;
} }
modcon=0; modcon = 0;
SetWriteHandler(0x8000,0xFFFF,GenieWrite); SetWriteHandler(0x8000, 0xFFFF, GenieWrite);
SetReadHandler(0x8000,0xFFFF,GenieRead); SetReadHandler(0x8000, 0xFFFF, GenieRead);
for(x=0;x<8;x++) for (x = 0; x < 8; x++)
VPage[x]=GENIEROM+4096-0x400*x; VPage[x] = GENIEROM + 4096 - 0x400 * x;
if(AllocGenieRW()) if (AllocGenieRW())
VPageR=VPageG; VPageR = VPageG;
else else
geniestage=2; geniestage = 2;
} }
void FCEU_SaveGameSave(CartInfo *LocalHWInfo) void FCEU_SaveGameSave(CartInfo *LocalHWInfo) {
{ if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) {
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
FILE *sp; FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav"); 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());
FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot.c_str()); } else {
} for (int x = 0; x < 4; x++)
else if (LocalHWInfo->SaveGame[x]) {
{ fwrite(LocalHWInfo->SaveGame[x], 1,
for(int x=0;x<4;x++) LocalHWInfo->SaveGameLen[x], sp);
if(LocalHWInfo->SaveGame[x])
{
fwrite(LocalHWInfo->SaveGame[x],1,
LocalHWInfo->SaveGameLen[x],sp);
} }
} }
} }
} }
// hack, movie.cpp has to communicate with this function somehow // hack, movie.cpp has to communicate with this function somehow
int disableBatteryLoading=0; int disableBatteryLoading = 0;
void FCEU_LoadGameSave(CartInfo *LocalHWInfo) void FCEU_LoadGameSave(CartInfo *LocalHWInfo) {
{ if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading) {
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading)
{
FILE *sp; FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav"); std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav");
sp=FCEUD_UTF8fopen(soot,"rb"); sp = FCEUD_UTF8fopen(soot, "rb");
if(sp!=NULL) if (sp != NULL) {
{ for (int x = 0; x < 4; x++)
for(int x=0;x<4;x++) if (LocalHWInfo->SaveGame[x])
if(LocalHWInfo->SaveGame[x]) fread(LocalHWInfo->SaveGame[x], 1, LocalHWInfo->SaveGameLen[x], sp);
fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp);
} }
} }
} }
//clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though) //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) void FCEU_ClearGameSave(CartInfo *LocalHWInfo) {
{ if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) {
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) for (int x = 0; x < 4; x++)
{ if (LocalHWInfo->SaveGame[x])
for(int x=0;x<4;x++) memset(LocalHWInfo->SaveGame[x], 0, LocalHWInfo->SaveGameLen[x]);
if(LocalHWInfo->SaveGame[x])
memset(LocalHWInfo->SaveGame[x],0,LocalHWInfo->SaveGameLen[x]);
} }
} }

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -51,31 +51,18 @@ uint8 *ROM = NULL;
uint8 *VROM = NULL; uint8 *VROM = NULL;
iNES_HEADER head; iNES_HEADER head;
static CartInfo iNESCart; static CartInfo iNESCart;
uint8 iNESMirroring = 0; uint8 Mirroring = 0;
uint16 iNESCHRBankList[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
int32 iNESIRQLatch = 0, iNESIRQCount = 0;
uint8 iNESIRQa = 0;
uint32 ROM_size = 0; uint32 ROM_size = 0;
uint32 VROM_size = 0; uint32 VROM_size = 0;
char LoadedRomFName[2048]; //mbg merge 7/17/06 added char LoadedRomFName[2048]; //mbg merge 7/17/06 added
static int CHRRAMSize = -1; static int CHRRAMSize = -1;
static void iNESPower(void); static int iNES_Init(int num);
static int NewiNES_Init(int num);
void (*MapperReset)(void);
static int MapperNo = 0; 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) { static DECLFR(TrainerRead) {
return(trainerpoo[A & 0x1FF]); return(trainerpoo[A & 0x1FF]);
} }
@ -106,8 +93,6 @@ void iNESGI(GI h) { //bbit edited: removed static keyword
break; break;
case GI_RESETM2: case GI_RESETM2:
if (MapperReset)
MapperReset();
if (iNESCart.Reset) if (iNESCart.Reset)
iNESCart.Reset(); iNESCart.Reset();
break; break;
@ -117,16 +102,19 @@ void iNESGI(GI h) { //bbit edited: removed static keyword
case GI_CLOSE: case GI_CLOSE:
{ {
FCEU_SaveGameSave(&iNESCart); FCEU_SaveGameSave(&iNESCart);
if (iNESCart.Close)
if (iNESCart.Close) iNESCart.Close(); iNESCart.Close();
if (ROM) { if (ROM) {
free(ROM); ROM = NULL; free(ROM);
ROM = NULL;
} }
if (VROM) { if (VROM) {
free(VROM); VROM = NULL; free(VROM);
VROM = NULL;
} }
if (trainerpoo) { if (trainerpoo) {
FCEU_gfree(trainerpoo); trainerpoo = 0; FCEU_gfree(trainerpoo);
trainerpoo = NULL;
} }
} }
break; break;
@ -249,10 +237,7 @@ static struct BADINF BadROMImages[] =
}; };
void CheckBad(uint64 md5partial) { void CheckBad(uint64 md5partial) {
int x; int32 x = 0;
x = 0;
//printf("0x%llx\n",md5partial);
while (BadROMImages[x].name) { while (BadROMImages[x].name) {
if (BadROMImages[x].md5partial == md5partial) { 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); 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; 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[] = { static const TMasterRomInfo sMasterRomInfo[] = {
{ 0x62b51b108a01d2beLL, "bonus=0" }, //4-in-1 (FK23C8021)[p1][!].nes { 0x62b51b108a01d2beLL, "bonus=0" }, //4-in-1 (FK23C8021)[p1][!].nes
{ 0x8bb48490d8d22711LL, "bonus=0" }, //4-in-1 (FK23C8033)[p1][!].nes { 0x8bb48490d8d22711LL, "bonus=0" }, //4-in-1 (FK23C8033)[p1][!].nes
@ -345,14 +318,11 @@ static void CheckHInfo(void) {
{ {
#include "ines-correct.h" #include "ines-correct.h"
}; };
int tofix = 0; int32 tofix = 0, x;
int x;
uint64 partialmd5 = 0; uint64 partialmd5 = 0;
for (x = 0; x < 8; x++) { for (x = 0; x < 8; x++)
partialmd5 |= (uint64)iNESCart.MD5[15 - x] << (x * 8); partialmd5 |= (uint64)iNESCart.MD5[15 - x] << (x * 8);
//printf("%16llx\n",partialmd5);
}
CheckBad(partialmd5); CheckBad(partialmd5);
MasterRomInfo = NULL; MasterRomInfo = NULL;
@ -373,7 +343,6 @@ static void CheckHInfo(void) {
} }
x = 0; x = 0;
do { do {
if (moo[x].crc32 == iNESGameCRC32) { if (moo[x].crc32 == iNESGameCRC32) {
if (moo[x].mapper >= 0) { if (moo[x].mapper >= 0) {
@ -451,7 +420,7 @@ static void CheckHInfo(void) {
} }
typedef struct { typedef struct {
int mapper; int32 mapper;
void (*init)(CartInfo *); void (*init)(CartInfo *);
} NewMI; } NewMI;
@ -466,8 +435,8 @@ static int not_power2[] =
228 228
}; };
typedef struct { typedef struct {
char* name; char *name;
int number; int32 number;
void (*init)(CartInfo *); void (*init)(CartInfo *);
} BMAPPINGLocal; } BMAPPINGLocal;
@ -865,9 +834,10 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
iNESCart.battery = (head.ROM_type & 2) ? 1 : 0; iNESCart.battery = (head.ROM_type & 2) ? 1 : 0;
iNESCart.mirror = Mirroring; iNESCart.mirror = Mirroring;
if (!iNES_Init(MapperNo))
FCEU_PrintError("iNES mapper #%d is not supported at all.", MapperNo);
GameInfo->mappernum = MapperNo; GameInfo->mappernum = MapperNo;
MapperInit();
FCEU_LoadGameSave(&iNESCart); FCEU_LoadGameSave(&iNESCart);
strcpy(LoadedRomFName, name); //bbit edited: line added strcpy(LoadedRomFName, name); //bbit edited: line added
@ -966,461 +936,7 @@ char *iNesShortFName() {
return ret + 1; return ret + 1;
} }
void VRAM_BANK1(uint32 A, uint8 V) { static int iNES_Init(int num) {
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) {
BMAPPINGLocal *tmp = bmap; BMAPPINGLocal *tmp = bmap;
CHRRAMSize = -1; CHRRAMSize = -1;
@ -1430,9 +946,9 @@ static int NewiNES_Init(int num) {
while (tmp->init) { while (tmp->init) {
if (num == tmp->number) { if (num == tmp->number) {
UNIFchrrama = 0; // need here for compatibility with UNIF mapper code UNIFchrrama = 0; // need here for compatibility with UNIF mapper code
if (!VROM_size) { if (!VROM_size) {
switch (num) { // FIXME, mapper or game data base with the board parameters and ROM/RAM sizes switch (num) { // FIXME, mapper or game data base with the board parameters and ROM/RAM sizes
case 13: CHRRAMSize = 16 * 1024; break; case 13: CHRRAMSize = 16 * 1024; break;
case 6: case 6:
case 96: CHRRAMSize = 32 * 1024; break; case 96: CHRRAMSize = 32 * 1024; break;

View File

@ -26,46 +26,17 @@
#include <map> #include <map>
#ifdef INESPRIV #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 */ /* This order is necessary */
#define WRAM (GameMemBlock) #define WRAM (GameMemBlock)
#define sizeofWRAM 8192 #define sizeofWRAM 8192
#define MapperExRAM (GameMemBlock+sizeofWRAM)
#define sizeofMapperExRAM 32768
/* for the MMC5 code to work properly. It might be fixed later... */ /* for the MMC5 code to work properly. It might be fixed later... */
#define CHRRAM (GameMemBlock + sizeofWRAM)
#define sizeofCHRRAM 8192
#define CHRRAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM) #define ExtraNTARAM (GameMemBlock + sizeofWRAM + sizeofCHRRAM)
#define sizeofCHRRAM 8192 #define sizeofExtraNTARAM 2048
#define ExtraNTARAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM+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 #else
#endif #endif
@ -94,12 +65,12 @@ extern TMasterRomInfoParams MasterRomInfoParams;
//mbg merge 7/19/06 changed to c++ decl format //mbg merge 7/19/06 changed to c++ decl format
struct iNES_HEADER { struct iNES_HEADER {
char ID[4]; /*NES^Z*/ char ID[4]; /*NES^Z*/
uint8 ROM_size; uint8 ROM_size;
uint8 VROM_size; uint8 VROM_size;
uint8 ROM_type; uint8 ROM_type;
uint8 ROM_type2; uint8 ROM_type2;
uint8 reserve[8]; uint8 reserve[8];
void cleanup() void cleanup()
{ {
@ -124,248 +95,11 @@ struct iNES_HEADER {
}; };
extern struct iNES_HEADER head; //for mappers usage 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 NSFVRC6_Init(void);
void NSFMMC5_Init(void); void NSFMMC5_Init(void);
void NSFAY_Init(void); void NSFAY_Init(void);
void NSFN106_Init(void); void NSFN106_Init(void);
void NSFVRC7_Init(void); void NSFVRC7_Init(void);
void Mapper19_ESI(void);
void Mapper1_Init(CartInfo *); void Mapper1_Init(CartInfo *);
void Mapper4_Init(CartInfo *); void Mapper4_Init(CartInfo *);