support mmc5 in newppu

This commit is contained in:
zeromus 2008-08-24 00:04:09 +00:00
parent 1135f414f7
commit ddd786eadf
4 changed files with 40 additions and 5 deletions

View File

@ -80,6 +80,18 @@ typedef struct __cartdata {
uint8 size; uint8 size;
} cartdata; } cartdata;
#define Sprite16 (PPU[0]&0x20) //Sprites 8x16/8x8
//#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)]
static inline uint8 * MMC5BGVRAMADR(uint32 A)
{
if(!Sprite16) {
if(mmc5ABMode==0)
return &MMC5SPRVPage[(A)>>10][(A)];
else
return &MMC5BGVPage[(A)>>10][(A)];
} else return &MMC5BGVPage[(A)>>10][(A)];
}
static void mmc5_PPUWrite(uint32 A, uint8 V) { static void mmc5_PPUWrite(uint32 A, uint8 V) {
uint32 tmp = A; uint32 tmp = A;
extern uint8 PALRAM[0x20]; extern uint8 PALRAM[0x20];
@ -104,15 +116,15 @@ static void mmc5_PPUWrite(uint32 A, uint8 V) {
} }
uint8 mmc5_PPURead(uint32 A) { uint8 mmc5_PPURead(uint32 A) {
uint32 tmp = A; if(A<0x2000)
if(tmp<0x2000)
{ {
return VPage[tmp>>10][tmp]; if(ppuphase == PPUPHASE_BG)
return *MMC5BGVRAMADR(A);
else return MMC5SPRVPage[(A)>>10][(A)];
} }
else else
{ {
return vnapage[(tmp>>10)&0x3][tmp&0x3FF]; return vnapage[(A>>10)&0x3][A&0x3FF];
} }
} }

View File

@ -309,6 +309,8 @@ void ResetGameLoaded(void)
GameStateRestore=0; GameStateRestore=0;
PPU_hook=0; PPU_hook=0;
GameHBIRQHook=0; GameHBIRQHook=0;
FFCEUX_PPURead = 0;
FFCEUX_PPUWrite = 0;
if(GameExpSound.Kill) if(GameExpSound.Kill)
GameExpSound.Kill(); GameExpSound.Kill();
memset(&GameExpSound,0,sizeof(GameExpSound)); memset(&GameExpSound,0,sizeof(GameExpSound));

View File

@ -67,6 +67,8 @@ static uint32 ppulut1[256];
static uint32 ppulut2[256]; static uint32 ppulut2[256];
static uint32 ppulut3[128]; static uint32 ppulut3[128];
PPUPHASE ppuphase;
template<typename T, int BITS> template<typename T, int BITS>
struct BITREVLUT { struct BITREVLUT {
@ -1809,6 +1811,7 @@ int FCEUX_PPU_Loop(int skip) {
{ {
PPU_status |= 0x80; PPU_status |= 0x80;
ppuphase = PPUPHASE_VBL;
//Not sure if this is correct. According to Matt Conte and my own tests, it is. //Not sure if this is correct. According to Matt Conte and my own tests, it is.
//Timing is probably off, though. //Timing is probably off, though.
@ -1847,11 +1850,16 @@ int FCEUX_PPU_Loop(int skip) {
for(int sl=0;sl<241;sl++) { for(int sl=0;sl<241;sl++) {
int yp = sl-1; int yp = sl-1;
ppuphase = PPUPHASE_BG;
if(sl != 0) { if(sl != 0) {
DEBUG(FCEUD_UpdatePPUView(scanline=yp,1)); DEBUG(FCEUD_UpdatePPUView(scanline=yp,1));
DEBUG(FCEUD_UpdateNTView(scanline=yp,1)); DEBUG(FCEUD_UpdateNTView(scanline=yp,1));
} }
if(sl != 0) if(MMC5Hack && PPUON) MMC5_hb(yp);
//twiddle the oam buffers //twiddle the oam buffers
int scanslot = oamslot^1; int scanslot = oamslot^1;
int renderslot = oamslot; int renderslot = oamslot;
@ -1986,6 +1994,8 @@ int FCEUX_PPU_Loop(int skip) {
if(PPUON && sl != 0) if(PPUON && sl != 0)
ppur.install_h_latches(); ppur.install_h_latches();
ppuphase = PPUPHASE_OBJ;
//fetch sprite patterns //fetch sprite patterns
for(int s=0;s<8;s++) { for(int s=0;s<8;s++) {
@ -2044,6 +2054,8 @@ int FCEUX_PPU_Loop(int skip) {
} }
} }
ppuphase = PPUPHASE_BG;
//fetch BG: two tiles for next line //fetch BG: two tiles for next line
for(int xt=0;xt<2;xt++) for(int xt=0;xt<2;xt++)
bgdata.main[xt].Read(); bgdata.main[xt].Read();
@ -2071,6 +2083,8 @@ int FCEUX_PPU_Loop(int skip) {
idleSynch ++; idleSynch ++;
if(idleSynch==2) idleSynch = 0; if(idleSynch==2) idleSynch = 0;
if(MMC5Hack && PPUON) MMC5_hb(240);
//idle for one line //idle for one line
runppu(kLineTime); runppu(kLineTime);

View File

@ -22,3 +22,10 @@ extern uint8 (*FFCEUX_PPURead)(uint32 A);
extern void (*FFCEUX_PPUWrite)(uint32 A, uint8 V); extern void (*FFCEUX_PPUWrite)(uint32 A, uint8 V);
extern int scanline; extern int scanline;
extern uint8 PPU[4];
enum PPUPHASE {
PPUPHASE_VBL, PPUPHASE_BG, PPUPHASE_OBJ
};
extern PPUPHASE ppuphase;