From ddd786eadf464031649de656888f01a7a8e99827 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 24 Aug 2008 00:04:09 +0000 Subject: [PATCH] support mmc5 in newppu --- src/boards/mmc5.cpp | 22 +++++++++++++++++----- src/fceu.cpp | 2 ++ src/ppu.cpp | 14 ++++++++++++++ src/ppu.h | 7 +++++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/boards/mmc5.cpp b/src/boards/mmc5.cpp index bf5074da..31c23610 100644 --- a/src/boards/mmc5.cpp +++ b/src/boards/mmc5.cpp @@ -80,6 +80,18 @@ typedef struct __cartdata { uint8 size; } 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) { uint32 tmp = A; extern uint8 PALRAM[0x20]; @@ -104,15 +116,15 @@ static void mmc5_PPUWrite(uint32 A, uint8 V) { } uint8 mmc5_PPURead(uint32 A) { - uint32 tmp = A; - - if(tmp<0x2000) + if(A<0x2000) { - return VPage[tmp>>10][tmp]; + if(ppuphase == PPUPHASE_BG) + return *MMC5BGVRAMADR(A); + else return MMC5SPRVPage[(A)>>10][(A)]; } else { - return vnapage[(tmp>>10)&0x3][tmp&0x3FF]; + return vnapage[(A>>10)&0x3][A&0x3FF]; } } diff --git a/src/fceu.cpp b/src/fceu.cpp index b2973676..9734770a 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -309,6 +309,8 @@ void ResetGameLoaded(void) GameStateRestore=0; PPU_hook=0; GameHBIRQHook=0; + FFCEUX_PPURead = 0; + FFCEUX_PPUWrite = 0; if(GameExpSound.Kill) GameExpSound.Kill(); memset(&GameExpSound,0,sizeof(GameExpSound)); diff --git a/src/ppu.cpp b/src/ppu.cpp index edccd1cf..f96b6da3 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -67,6 +67,8 @@ static uint32 ppulut1[256]; static uint32 ppulut2[256]; static uint32 ppulut3[128]; +PPUPHASE ppuphase; + template struct BITREVLUT { @@ -1809,6 +1811,7 @@ int FCEUX_PPU_Loop(int skip) { { PPU_status |= 0x80; + ppuphase = PPUPHASE_VBL; //Not sure if this is correct. According to Matt Conte and my own tests, it is. //Timing is probably off, though. @@ -1847,11 +1850,16 @@ int FCEUX_PPU_Loop(int skip) { for(int sl=0;sl<241;sl++) { int yp = sl-1; + ppuphase = PPUPHASE_BG; + if(sl != 0) { DEBUG(FCEUD_UpdatePPUView(scanline=yp,1)); DEBUG(FCEUD_UpdateNTView(scanline=yp,1)); } + if(sl != 0) if(MMC5Hack && PPUON) MMC5_hb(yp); + + //twiddle the oam buffers int scanslot = oamslot^1; int renderslot = oamslot; @@ -1986,6 +1994,8 @@ int FCEUX_PPU_Loop(int skip) { if(PPUON && sl != 0) ppur.install_h_latches(); + ppuphase = PPUPHASE_OBJ; + //fetch sprite patterns 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 for(int xt=0;xt<2;xt++) bgdata.main[xt].Read(); @@ -2071,6 +2083,8 @@ int FCEUX_PPU_Loop(int skip) { idleSynch ++; if(idleSynch==2) idleSynch = 0; + if(MMC5Hack && PPUON) MMC5_hb(240); + //idle for one line runppu(kLineTime); diff --git a/src/ppu.h b/src/ppu.h index f0f45e74..7e596e4b 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -22,3 +22,10 @@ extern uint8 (*FFCEUX_PPURead)(uint32 A); extern void (*FFCEUX_PPUWrite)(uint32 A, uint8 V); extern int scanline; +extern uint8 PPU[4]; + +enum PPUPHASE { + PPUPHASE_VBL, PPUPHASE_BG, PPUPHASE_OBJ +}; + +extern PPUPHASE ppuphase;