From 9f104fc38c22e5a63846d56d0d1026b03f8d3ede Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 29 Apr 2017 23:03:35 +0000 Subject: [PATCH] fix extended attributes in newppu better, and fix old ppu's chr banking to match newppu maybe? --- trunk/src/boards/mmc5.cpp | 19 ++++++++++++++----- trunk/src/ppu.cpp | 15 ++------------- trunk/src/ppu.h | 1 + 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/trunk/src/boards/mmc5.cpp b/trunk/src/boards/mmc5.cpp index 1ca5478b..98d996a6 100644 --- a/trunk/src/boards/mmc5.cpp +++ b/trunk/src/boards/mmc5.cpp @@ -27,6 +27,7 @@ #define SpriteON (PPU[1] & 0x10) //Show Sprite #define ScreenON (PPU[1] & 0x08) //Show screen #define PPUON (PPU[1] & 0x18) //PPU should operate +#define Sprite16 (PPU[0] & 0x20) //Sprites 8x16/8x8 static void (*sfun)(int P); static void (*psfun)(void); @@ -113,9 +114,9 @@ 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) { + +uint8* MMC5BGVRAMADR(uint32 A) +{ if(Sprite16) { bool isPattern = PPUON; @@ -235,12 +236,20 @@ uint8 FASTCALL mmc5_PPURead(uint32 A) return ExRAM[A & 0x3FF]; } } - + if (MMC5HackCHRMode == 1) { if((A&0x3FF)>=0x3C0) { - return ExRAM[NTRefreshAddr & 0x3ff]; + uint8 byte = ExRAM[NTRefreshAddr & 0x3ff]; + //get attribute part + byte >>= 6; + //adjust it to the right position within the byte + int x = NTRefreshAddr&31; + int y = NTRefreshAddr>>5; + if(y&2) byte <<= 4; + if(x&2) byte <<= 2; + return byte; } } diff --git a/trunk/src/ppu.cpp b/trunk/src/ppu.cpp index c2909ec1..ee043a70 100644 --- a/trunk/src/ppu.cpp +++ b/trunk/src/ppu.cpp @@ -374,18 +374,7 @@ uint8 UPALRAM[0x03];//for 0x4/0x8/0xC addresses in palette, the ones in #define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V) >> 10][(V)] #define VRAMADR(V) &VPage[(V) >> 10][(V)] -//mbg 8/6/08 - fix a bug relating to -//"When in 8x8 sprite mode, only one set is used for both BG and sprites." -//in mmc5 docs -uint8 * MMC5BGVRAMADR(uint32 V) { - if (!Sprite16) { - extern uint8 mmc5ABMode; /* A=0, B=1 */ - if (mmc5ABMode == 0) - return MMC5SPRVRAMADR(V); - else - return &MMC5BGVPage[(V) >> 10][(V)]; - } else return &MMC5BGVPage[(V) >> 10][(V)]; -} +extern uint8* MMC5BGVRAMADR(uint32 A); //this duplicates logic which is embedded in the ppu rendering code //which figures out where to get CHR data from depending on various hack modes @@ -500,7 +489,7 @@ void (*FFCEUX_PPUWrite)(uint32 A, uint8 V) = 0; #define CALL_PPUWRITE(A, V) (FFCEUX_PPUWrite ? FFCEUX_PPUWrite(A, V) : FFCEUX_PPUWrite_Default(A, V)) -//whether to use the new ppu (new PPU doesn't handle MMC5 extra nametables at all +//whether to use the new ppu int newppu = 0; void ppu_getScroll(int &xpos, int &ypos) { diff --git a/trunk/src/ppu.h b/trunk/src/ppu.h index a3ec54a1..a3d2ded5 100644 --- a/trunk/src/ppu.h +++ b/trunk/src/ppu.h @@ -22,6 +22,7 @@ void FCEUPPU_SaveState(void); void FCEUPPU_LoadState(int version); uint32 FCEUPPU_PeekAddress(); uint8* FCEUPPU_GetCHR(uint32 vadr, uint32 refreshaddr); +int FCEUPPU_GetAttr(int ntnum, int xt, int yt); void ppu_getScroll(int &xpos, int &ypos);