palette ram reading fix for old ppu
This commit is contained in:
parent
37b0f97f1d
commit
9d778993b7
112
src/ppu.cpp
112
src/ppu.cpp
|
@ -1,23 +1,23 @@
|
|||
/* FCE Ultra - NES/Famicom Emulator
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
* Copyright (C) 1998 BERO
|
||||
* Copyright (C) 2003 Xodnizel
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
* Copyright (C) 1998 BERO
|
||||
* Copyright (C) 2003 Xodnizel
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
@ -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,23 +273,19 @@ 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;
|
||||
|
||||
ppulut3[xo | (cc << 3)] = 0;
|
||||
for (pixel = 0; pixel < 8; pixel++) {
|
||||
int shiftr;
|
||||
shiftr = (pixel + xo) / 8;
|
||||
shiftr *= 2;
|
||||
ppulut3[ xo | (cc << 3) ] |= ((cc >> shiftr) & 3) << (2 + pixel * 4);
|
||||
ppulut3[xo | (cc << 3)] |= ((cc >> shiftr) & 3) << (2 + pixel * 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -345,7 +339,7 @@ static uint32 scanlines_per_frame;
|
|||
uint8 PPU[4];
|
||||
uint8 PPUSPL;
|
||||
uint8 NTARAM[0x800], PALRAM[0x20], SPRAM[0x100], SPRBUF[0x100];
|
||||
uint8 UPALRAM[0x03]; //for 0x4/0x8/0xC addresses in palette, the ones in
|
||||
uint8 UPALRAM[0x03];//for 0x4/0x8/0xC addresses in palette, the ones in
|
||||
//0x20 are 0 to not break fceu rendering.
|
||||
|
||||
|
||||
|
@ -527,7 +521,7 @@ static DECLFR(A2004) {
|
|||
// to 0xFF
|
||||
if (ppur.status.cycle < 64)
|
||||
return spr_read.ret = 0xFF;
|
||||
else{
|
||||
else {
|
||||
for (int i = spr_read.last;
|
||||
i != ppur.status.cycle; ++i) {
|
||||
if (i < 256) {
|
||||
|
@ -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;
|
||||
|
@ -1182,7 +1198,7 @@ static void DoLine(void) {
|
|||
X6502_Run(256);
|
||||
EndRL();
|
||||
|
||||
if (!renderbg) { // User asked to not display background data.
|
||||
if (!renderbg) {// User asked to not display background data.
|
||||
uint32 tem;
|
||||
uint8 col;
|
||||
if (gNoBGFillColor == 0xFF)
|
||||
|
@ -1495,7 +1511,7 @@ static void RefreshSprites(void) {
|
|||
if (J & 0x02) C[1] = VB[pixdata & 3];
|
||||
pixdata >>= 4;
|
||||
if (J & 0x01) C[0] = VB[pixdata];
|
||||
} else{
|
||||
} else {
|
||||
if (J & 0x80) C[0] = VB[pixdata & 3];
|
||||
pixdata >>= 4;
|
||||
if (J & 0x40) C[1] = VB[pixdata & 3];
|
||||
|
@ -1678,11 +1694,11 @@ int FCEUPPU_Loop(int skip) {
|
|||
X6502_Run(12);
|
||||
if (GameInfo->type == GIT_NSF)
|
||||
DoNSFFrame();
|
||||
else{
|
||||
else {
|
||||
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);
|
||||
|
||||
|
@ -1738,7 +1754,7 @@ int FCEUPPU_Loop(int skip) {
|
|||
X6502_Run((256 + 85) * 240);
|
||||
}
|
||||
#endif
|
||||
else{
|
||||
else {
|
||||
int x, max, maxref;
|
||||
|
||||
deemp = PPU[1] >> 5;
|
||||
|
@ -1958,7 +1974,7 @@ int FCEUX_PPU_Loop(int skip) {
|
|||
//if(PPUON)
|
||||
// ppur.install_latches();
|
||||
|
||||
static uint8 oams[2][64][8]; //[7] turned to [8] for faster indexing
|
||||
static uint8 oams[2][64][8];//[7] turned to [8] for faster indexing
|
||||
static int oamcounts[2] = { 0, 0 };
|
||||
static int oamslot = 0;
|
||||
static int oamcount;
|
||||
|
@ -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
|
||||
|
@ -2254,7 +2270,7 @@ int FCEUX_PPU_Loop(int skip) {
|
|||
framectr++;
|
||||
}
|
||||
|
||||
finish:
|
||||
finish:
|
||||
FCEU_PutImage();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue