palette ram reading fix for old ppu

This commit is contained in:
CaH4e3 2013-03-14 12:55:36 +00:00
parent 37b0f97f1d
commit 9d778993b7
1 changed files with 150 additions and 134 deletions

View File

@ -41,7 +41,6 @@
#include "driver.h"
#include "debug.h"
#define VBlankON (PPU[0] & 0x80) //Generate VBlank NMI
#define Sprite16 (PPU[0] & 0x20) //Sprites 8x16/8x8
#define BGAdrHI (PPU[0] & 0x10) //BG pattern adr $0000/$1000
@ -266,7 +265,6 @@ struct PPUREGS {
}
} ppur;
static void makeppulut(void) {
int x;
int y;
@ -275,18 +273,14 @@ static void makeppulut(void) {
for (x = 0; x < 256; x++) {
ppulut1[x] = 0;
for (y = 0; y < 8; y++) {
for (y = 0; y < 8; y++)
ppulut1[x] |= ((x >> (7 - y)) & 1) << (y * 4);
}
ppulut2[x] = ppulut1[x] << 1;
}
for (cc = 0; cc < 16; cc++) {
for (xo = 0; xo < 8; xo++) {
ppulut3[xo | (cc << 3)] = 0;
for (pixel = 0; pixel < 8; pixel++) {
int shiftr;
shiftr = (pixel + xo) / 8;
@ -699,6 +693,27 @@ static DECLFR(A2007) {
} else {
FCEUPPU_LineUpdate();
if (tmp >= 0x3F00) { // Palette RAM tied directly to the output data, without VRAM buffer
if (!(tmp & 3)) {
if (!(tmp & 0xC))
ret = PALRAM[0x00];
else
ret = UPALRAM[((tmp & 0xC) >> 2) - 1];
} else
ret = PALRAM[tmp & 0x1F];
if (GRAYSCALE)
ret &= 0x30;
#ifdef FCEUDEF_DEBUGGER
if (!fceuindbg)
#endif
{
if ((tmp - 0x1000) < 0x2000)
VRAMBuffer = VPage[(tmp - 0x1000) >> 10][tmp - 0x1000];
else
VRAMBuffer = vnapage[((tmp - 0x1000) >> 10) & 0x3][(tmp - 0x1000) & 0x3FF];
if (PPU_hook) PPU_hook(tmp);
}
} else {
ret = VRAMBuffer;
#ifdef FCEUDEF_DEBUGGER
@ -711,7 +726,7 @@ static DECLFR(A2007) {
if (debug_loggingCD)
LogAddress = GetCHRAddress(tmp);
VRAMBuffer = VPage[tmp >> 10][tmp];
} else if (tmp < 0x3F00) {
} else if (tmp < 0x3F00)
VRAMBuffer = vnapage[(tmp >> 10) & 0x3][tmp & 0x3FF];
}
}
@ -866,19 +881,20 @@ static DECLFW(B2007) {
RefreshAddr = ppur.get_2007access();
} else {
PPUGenLatch = V;
if (tmp >= 0x3F00) {
// hmmm....
if (!(tmp & 0xf))
PALRAM[0x00] = PALRAM[0x04] = PALRAM[0x08] = PALRAM[0x0C] = V & 0x3F;
else
if (tmp & 3)
PALRAM[(tmp & 0x1f)] = V & 0x3f;
} else if (tmp < 0x2000) {
if (tmp < 0x2000) {
if (PPUCHRRAM & (1 << (tmp >> 10)))
VPage[tmp >> 10][tmp] = V;
} else {
} else if (tmp < 0x3F00) {
if (PPUNTARAM & (1 << ((tmp & 0xF00) >> 10)))
vnapage[((tmp & 0xF00) >> 10)][tmp & 0x3FF] = V;
} else {
if (!(tmp & 3)) {
if (!(tmp & 0xC))
PALRAM[0x00] = PALRAM[0x04] = PALRAM[0x08] = PALRAM[0x0C] = V & 0x3F;
else
UPALRAM[((tmp & 0xC) >> 2) - 1] = V & 0x3F;
} else
PALRAM[tmp & 0x1F] = V & 0x3F;
}
if (INC32)
RefreshAddr += 32;
@ -1682,7 +1698,7 @@ int FCEUPPU_Loop(int skip) {
if (VBlankON)
TriggerNMI();
}
X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12); //-12);
X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12);
PPU_status &= 0x1f;
X6502_Run(256);
@ -2181,7 +2197,7 @@ int FCEUX_PPU_Loop(int skip) {
//does not set SpriteON in the beginning but it does
//set the bg on so if using the conditional SpriteON the MMC3 counter
//the counter will never count and no IRQs will be fired so use PPUON
if (((PPU[0] & 0x38) != 0x18) && s == 2 && PPUON) { //SpriteON ) {
if (((PPU[0] & 0x38) != 0x18) && s == 2 && PPUON) {
//(The MMC3 scanline counter is based entirely on PPU A12, triggered on rising edges (after the line remains low for a sufficiently long period of time))
//http://nesdevwiki.org/wiki/index.php/Nintendo_MMC3
//test cases for timing: SMB3, Crystalis