palette ram reading fix for old ppu
This commit is contained in:
parent
37b0f97f1d
commit
9d778993b7
284
src/ppu.cpp
284
src/ppu.cpp
|
@ -1,64 +1,63 @@
|
||||||
/* FCE Ultra - NES/Famicom Emulator
|
/* FCE Ultra - NES/Famicom Emulator
|
||||||
*
|
*
|
||||||
* Copyright notice for this file:
|
* Copyright notice for this file:
|
||||||
* Copyright (C) 1998 BERO
|
* Copyright (C) 1998 BERO
|
||||||
* Copyright (C) 2003 Xodnizel
|
* Copyright (C) 2003 Xodnizel
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "x6502.h"
|
#include "x6502.h"
|
||||||
#include "fceu.h"
|
#include "fceu.h"
|
||||||
#include "ppu.h"
|
#include "ppu.h"
|
||||||
#include "nsf.h"
|
#include "nsf.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "utils/endian.h"
|
#include "utils/endian.h"
|
||||||
#include "utils/memory.h"
|
#include "utils/memory.h"
|
||||||
|
|
||||||
#include "cart.h"
|
#include "cart.h"
|
||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "debug.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
|
||||||
|
#define SpAdrHI (PPU[0] & 0x08) //Sprite pattern adr $0000/$1000
|
||||||
|
#define INC32 (PPU[0] & 0x04) //auto increment 1/32
|
||||||
|
|
||||||
#define VBlankON (PPU[0] & 0x80) //Generate VBlank NMI
|
#define SpriteON (PPU[1] & 0x10) //Show Sprite
|
||||||
#define Sprite16 (PPU[0] & 0x20) //Sprites 8x16/8x8
|
#define ScreenON (PPU[1] & 0x08) //Show screen
|
||||||
#define BGAdrHI (PPU[0] & 0x10) //BG pattern adr $0000/$1000
|
#define PPUON (PPU[1] & 0x18) //PPU should operate
|
||||||
#define SpAdrHI (PPU[0] & 0x08) //Sprite pattern adr $0000/$1000
|
#define GRAYSCALE (PPU[1] & 0x01) //Grayscale (AND palette entries with 0x30)
|
||||||
#define INC32 (PPU[0] & 0x04) //auto increment 1/32
|
|
||||||
|
|
||||||
#define SpriteON (PPU[1] & 0x10) //Show Sprite
|
#define SpriteLeft8 (PPU[1] & 0x04)
|
||||||
#define ScreenON (PPU[1] & 0x08) //Show screen
|
#define BGLeft8 (PPU[1] & 0x02)
|
||||||
#define PPUON (PPU[1] & 0x18) //PPU should operate
|
|
||||||
#define GRAYSCALE (PPU[1] & 0x01) //Grayscale (AND palette entries with 0x30)
|
|
||||||
|
|
||||||
#define SpriteLeft8 (PPU[1] & 0x04)
|
#define PPU_status (PPU[2])
|
||||||
#define BGLeft8 (PPU[1] & 0x02)
|
|
||||||
|
|
||||||
#define PPU_status (PPU[2])
|
#define Pal (PALRAM)
|
||||||
|
|
||||||
#define Pal (PALRAM)
|
|
||||||
|
|
||||||
static void FetchSpriteData(void);
|
static void FetchSpriteData(void);
|
||||||
static void RefreshLine(int lastpixel);
|
static void RefreshLine(int lastpixel);
|
||||||
|
@ -146,21 +145,21 @@ uint8 idleSynch = 1;
|
||||||
//uses the internal counters concept at http://nesdev.icequake.net/PPU%20addressing.txt
|
//uses the internal counters concept at http://nesdev.icequake.net/PPU%20addressing.txt
|
||||||
struct PPUREGS {
|
struct PPUREGS {
|
||||||
//normal clocked regs. as the game can interfere with these at any time, they need to be savestated
|
//normal clocked regs. as the game can interfere with these at any time, they need to be savestated
|
||||||
uint32 fv; //3
|
uint32 fv; //3
|
||||||
uint32 v; //1
|
uint32 v; //1
|
||||||
uint32 h; //1
|
uint32 h; //1
|
||||||
uint32 vt; //5
|
uint32 vt; //5
|
||||||
uint32 ht; //5
|
uint32 ht; //5
|
||||||
|
|
||||||
//temp unlatched regs (need savestating, can be written to at any time)
|
//temp unlatched regs (need savestating, can be written to at any time)
|
||||||
uint32 _fv, _v, _h, _vt, _ht;
|
uint32 _fv, _v, _h, _vt, _ht;
|
||||||
|
|
||||||
//other regs that need savestating
|
//other regs that need savestating
|
||||||
uint32 fh; //3 (horz scroll)
|
uint32 fh; //3 (horz scroll)
|
||||||
uint32 s; //1 ($2000 bit 4: "Background pattern table address (0: $0000; 1: $1000)")
|
uint32 s; //1 ($2000 bit 4: "Background pattern table address (0: $0000; 1: $1000)")
|
||||||
|
|
||||||
//other regs that don't need saving
|
//other regs that don't need saving
|
||||||
uint32 par; //8 (sort of a hack, just stored in here, but not managed by this system)
|
uint32 par; //8 (sort of a hack, just stored in here, but not managed by this system)
|
||||||
|
|
||||||
//cached state data. these are always reset at the beginning of a frame and don't need saving
|
//cached state data. these are always reset at the beginning of a frame and don't need saving
|
||||||
//but just to be safe, we're gonna save it
|
//but just to be safe, we're gonna save it
|
||||||
|
@ -207,8 +206,8 @@ struct PPUREGS {
|
||||||
fv++;
|
fv++;
|
||||||
int fv_overflow = (fv >> 3);
|
int fv_overflow = (fv >> 3);
|
||||||
vt += fv_overflow;
|
vt += fv_overflow;
|
||||||
vt &= 31; //fixed tecmo super bowl
|
vt &= 31; //fixed tecmo super bowl
|
||||||
if (vt == 30 && fv_overflow == 1) { //caution here (only do it at the exact instant of overflow) fixes p'radikus conflict
|
if (vt == 30 && fv_overflow == 1) { //caution here (only do it at the exact instant of overflow) fixes p'radikus conflict
|
||||||
v++;
|
v++;
|
||||||
vt = 0;
|
vt = 0;
|
||||||
}
|
}
|
||||||
|
@ -266,7 +265,6 @@ struct PPUREGS {
|
||||||
}
|
}
|
||||||
} ppur;
|
} ppur;
|
||||||
|
|
||||||
|
|
||||||
static void makeppulut(void) {
|
static void makeppulut(void) {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
@ -275,23 +273,19 @@ static void makeppulut(void) {
|
||||||
|
|
||||||
for (x = 0; x < 256; x++) {
|
for (x = 0; x < 256; x++) {
|
||||||
ppulut1[x] = 0;
|
ppulut1[x] = 0;
|
||||||
|
for (y = 0; y < 8; y++)
|
||||||
for (y = 0; y < 8; y++) {
|
|
||||||
ppulut1[x] |= ((x >> (7 - y)) & 1) << (y * 4);
|
ppulut1[x] |= ((x >> (7 - y)) & 1) << (y * 4);
|
||||||
}
|
|
||||||
|
|
||||||
ppulut2[x] = ppulut1[x] << 1;
|
ppulut2[x] = ppulut1[x] << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (cc = 0; cc < 16; cc++) {
|
for (cc = 0; cc < 16; cc++) {
|
||||||
for (xo = 0; xo < 8; xo++) {
|
for (xo = 0; xo < 8; xo++) {
|
||||||
ppulut3[ xo | (cc << 3) ] = 0;
|
ppulut3[xo | (cc << 3)] = 0;
|
||||||
|
|
||||||
for (pixel = 0; pixel < 8; pixel++) {
|
for (pixel = 0; pixel < 8; pixel++) {
|
||||||
int shiftr;
|
int shiftr;
|
||||||
shiftr = (pixel + xo) / 8;
|
shiftr = (pixel + xo) / 8;
|
||||||
shiftr *= 2;
|
shiftr *= 2;
|
||||||
ppulut3[ xo | (cc << 3) ] |= ((cc >> shiftr) & 3) << (2 + pixel * 4);
|
ppulut3[xo | (cc << 3)] |= ((cc >> shiftr) & 3) << (2 + pixel * 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,8 +339,8 @@ static uint32 scanlines_per_frame;
|
||||||
uint8 PPU[4];
|
uint8 PPU[4];
|
||||||
uint8 PPUSPL;
|
uint8 PPUSPL;
|
||||||
uint8 NTARAM[0x800], PALRAM[0x20], SPRAM[0x100], SPRBUF[0x100];
|
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.
|
//0x20 are 0 to not break fceu rendering.
|
||||||
|
|
||||||
|
|
||||||
#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V) >> 10][(V)]
|
#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V) >> 10][(V)]
|
||||||
|
@ -357,7 +351,7 @@ uint8 UPALRAM[0x03]; //for 0x4/0x8/0xC addresses in palette, the ones in
|
||||||
//in mmc5 docs
|
//in mmc5 docs
|
||||||
uint8 * MMC5BGVRAMADR(uint32 V) {
|
uint8 * MMC5BGVRAMADR(uint32 V) {
|
||||||
if (!Sprite16) {
|
if (!Sprite16) {
|
||||||
extern uint8 mmc5ABMode; /* A=0, B=1 */
|
extern uint8 mmc5ABMode; /* A=0, B=1 */
|
||||||
if (mmc5ABMode == 0)
|
if (mmc5ABMode == 0)
|
||||||
return MMC5SPRVRAMADR(V);
|
return MMC5SPRVRAMADR(V);
|
||||||
else
|
else
|
||||||
|
@ -374,7 +368,7 @@ uint8* FCEUPPU_GetCHR(uint32 vadr, uint32 refreshaddr) {
|
||||||
if (MMC5HackCHRMode == 1) {
|
if (MMC5HackCHRMode == 1) {
|
||||||
uint8 *C = MMC5HackVROMPTR;
|
uint8 *C = MMC5HackVROMPTR;
|
||||||
C += (((MMC5HackExNTARAMPtr[refreshaddr & 0x3ff]) & 0x3f & MMC5HackVROMMask) << 12) + (vadr & 0xfff);
|
C += (((MMC5HackExNTARAMPtr[refreshaddr & 0x3ff]) & 0x3f & MMC5HackVROMMask) << 12) + (vadr & 0xfff);
|
||||||
C += (MMC50x5130 & 0x3) << 18; //11-jun-2009 for kuja_killer
|
C += (MMC50x5130 & 0x3) << 18; //11-jun-2009 for kuja_killer
|
||||||
return C;
|
return C;
|
||||||
} else {
|
} else {
|
||||||
return MMC5BGVRAMADR(vadr);
|
return MMC5BGVRAMADR(vadr);
|
||||||
|
@ -527,7 +521,7 @@ static DECLFR(A2004) {
|
||||||
// to 0xFF
|
// to 0xFF
|
||||||
if (ppur.status.cycle < 64)
|
if (ppur.status.cycle < 64)
|
||||||
return spr_read.ret = 0xFF;
|
return spr_read.ret = 0xFF;
|
||||||
else{
|
else {
|
||||||
for (int i = spr_read.last;
|
for (int i = spr_read.last;
|
||||||
i != ppur.status.cycle; ++i) {
|
i != ppur.status.cycle; ++i) {
|
||||||
if (i < 256) {
|
if (i < 256) {
|
||||||
|
@ -649,7 +643,7 @@ static DECLFR(A2004) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DECLFR(A200x) { /* Not correct for $2004 reads. */
|
static DECLFR(A200x) { /* Not correct for $2004 reads. */
|
||||||
FCEUPPU_LineUpdate();
|
FCEUPPU_LineUpdate();
|
||||||
return PPUGenLatch;
|
return PPUGenLatch;
|
||||||
}
|
}
|
||||||
|
@ -699,20 +693,41 @@ static DECLFR(A2007) {
|
||||||
} else {
|
} else {
|
||||||
FCEUPPU_LineUpdate();
|
FCEUPPU_LineUpdate();
|
||||||
|
|
||||||
ret = VRAMBuffer;
|
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
|
#ifdef FCEUDEF_DEBUGGER
|
||||||
if (!fceuindbg)
|
if (!fceuindbg)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (PPU_hook) PPU_hook(tmp);
|
if (PPU_hook) PPU_hook(tmp);
|
||||||
PPUGenLatch = VRAMBuffer;
|
PPUGenLatch = VRAMBuffer;
|
||||||
if (tmp < 0x2000) {
|
if (tmp < 0x2000) {
|
||||||
if (debug_loggingCD)
|
if (debug_loggingCD)
|
||||||
LogAddress = GetCHRAddress(tmp);
|
LogAddress = GetCHRAddress(tmp);
|
||||||
VRAMBuffer = VPage[tmp >> 10][tmp];
|
VRAMBuffer = VPage[tmp >> 10][tmp];
|
||||||
} else if (tmp < 0x3F00) {
|
} else if (tmp < 0x3F00)
|
||||||
VRAMBuffer = vnapage[(tmp >> 10) & 0x3][tmp & 0x3FF];
|
VRAMBuffer = vnapage[(tmp >> 10) & 0x3][tmp & 0x3FF];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef FCEUDEF_DEBUGGER
|
#ifdef FCEUDEF_DEBUGGER
|
||||||
|
@ -866,19 +881,20 @@ static DECLFW(B2007) {
|
||||||
RefreshAddr = ppur.get_2007access();
|
RefreshAddr = ppur.get_2007access();
|
||||||
} else {
|
} else {
|
||||||
PPUGenLatch = V;
|
PPUGenLatch = V;
|
||||||
if (tmp >= 0x3F00) {
|
if (tmp < 0x2000) {
|
||||||
// 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 (PPUCHRRAM & (1 << (tmp >> 10)))
|
if (PPUCHRRAM & (1 << (tmp >> 10)))
|
||||||
VPage[tmp >> 10][tmp] = V;
|
VPage[tmp >> 10][tmp] = V;
|
||||||
} else {
|
} else if (tmp < 0x3F00) {
|
||||||
if (PPUNTARAM & (1 << ((tmp & 0xF00) >> 10)))
|
if (PPUNTARAM & (1 << ((tmp & 0xF00) >> 10)))
|
||||||
vnapage[((tmp & 0xF00) >> 10)][tmp & 0x3FF] = V;
|
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)
|
if (INC32)
|
||||||
RefreshAddr += 32;
|
RefreshAddr += 32;
|
||||||
|
@ -903,7 +919,7 @@ static DECLFW(B4014) {
|
||||||
|
|
||||||
static uint8 *Pline, *Plinef;
|
static uint8 *Pline, *Plinef;
|
||||||
static int firsttile;
|
static int firsttile;
|
||||||
int linestartts; //no longer static so the debugger can see it
|
int linestartts; //no longer static so the debugger can see it
|
||||||
static int tofix = 0;
|
static int tofix = 0;
|
||||||
|
|
||||||
static void ResetRL(uint8 *target) {
|
static void ResetRL(uint8 *target) {
|
||||||
|
@ -1172,7 +1188,7 @@ static void Fixit1(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMC5_hb(int); //Ugh ugh ugh.
|
void MMC5_hb(int); //Ugh ugh ugh.
|
||||||
static void DoLine(void) {
|
static void DoLine(void) {
|
||||||
int x;
|
int x;
|
||||||
uint8 *target = XBuf + (scanline << 8);
|
uint8 *target = XBuf + (scanline << 8);
|
||||||
|
@ -1182,7 +1198,7 @@ static void DoLine(void) {
|
||||||
X6502_Run(256);
|
X6502_Run(256);
|
||||||
EndRL();
|
EndRL();
|
||||||
|
|
||||||
if (!renderbg) { // User asked to not display background data.
|
if (!renderbg) {// User asked to not display background data.
|
||||||
uint32 tem;
|
uint32 tem;
|
||||||
uint8 col;
|
uint8 col;
|
||||||
if (gNoBGFillColor == 0xFF)
|
if (gNoBGFillColor == 0xFF)
|
||||||
|
@ -1196,7 +1212,7 @@ static void DoLine(void) {
|
||||||
if (SpriteON)
|
if (SpriteON)
|
||||||
CopySprites(target);
|
CopySprites(target);
|
||||||
|
|
||||||
if (ScreenON || SpriteON) { // Yes, very el-cheapo.
|
if (ScreenON || SpriteON) { // Yes, very el-cheapo.
|
||||||
if (PPU[1] & 0x01) {
|
if (PPU[1] & 0x01) {
|
||||||
for (x = 63; x >= 0; x--)
|
for (x = 63; x >= 0; x--)
|
||||||
*(uint32*)&target[x << 2] = (*(uint32*)&target[x << 2]) & 0x30303030;
|
*(uint32*)&target[x << 2] = (*(uint32*)&target[x << 2]) & 0x30303030;
|
||||||
|
@ -1224,7 +1240,7 @@ static void DoLine(void) {
|
||||||
GameHBIRQHook();
|
GameHBIRQHook();
|
||||||
X6502_Run(85 - 16 - 10);
|
X6502_Run(85 - 16 - 10);
|
||||||
} else {
|
} else {
|
||||||
X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
|
X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others)
|
||||||
Fixit2();
|
Fixit2();
|
||||||
X6502_Run(85 - 6 - 16);
|
X6502_Run(85 - 6 - 16);
|
||||||
|
|
||||||
|
@ -1495,7 +1511,7 @@ static void RefreshSprites(void) {
|
||||||
if (J & 0x02) C[1] = VB[pixdata & 3];
|
if (J & 0x02) C[1] = VB[pixdata & 3];
|
||||||
pixdata >>= 4;
|
pixdata >>= 4;
|
||||||
if (J & 0x01) C[0] = VB[pixdata];
|
if (J & 0x01) C[0] = VB[pixdata];
|
||||||
} else{
|
} else {
|
||||||
if (J & 0x80) C[0] = VB[pixdata & 3];
|
if (J & 0x80) C[0] = VB[pixdata & 3];
|
||||||
pixdata >>= 4;
|
pixdata >>= 4;
|
||||||
if (J & 0x40) C[1] = VB[pixdata & 3];
|
if (J & 0x40) C[1] = VB[pixdata & 3];
|
||||||
|
@ -1526,7 +1542,7 @@ static void CopySprites(uint8 *target) {
|
||||||
if (!spork) return;
|
if (!spork) return;
|
||||||
spork = 0;
|
spork = 0;
|
||||||
|
|
||||||
if (!rendersprites) return; //User asked to not display sprites.
|
if (!rendersprites) return; //User asked to not display sprites.
|
||||||
|
|
||||||
loopskie:
|
loopskie:
|
||||||
{
|
{
|
||||||
|
@ -1535,51 +1551,51 @@ static void CopySprites(uint8 *target) {
|
||||||
if (t != 0x80808080) {
|
if (t != 0x80808080) {
|
||||||
#ifdef LSB_FIRST
|
#ifdef LSB_FIRST
|
||||||
if (!(t & 0x80)) {
|
if (!(t & 0x80)) {
|
||||||
if (!(t & 0x40) || (P[n] & 0x40)) // Normal sprite || behind bg sprite
|
if (!(t & 0x40) || (P[n] & 0x40)) // Normal sprite || behind bg sprite
|
||||||
P[n] = sprlinebuf[n];
|
P[n] = sprlinebuf[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(t & 0x8000)) {
|
if (!(t & 0x8000)) {
|
||||||
if (!(t & 0x4000) || (P[n + 1] & 0x40)) // Normal sprite || behind bg sprite
|
if (!(t & 0x4000) || (P[n + 1] & 0x40)) // Normal sprite || behind bg sprite
|
||||||
P[n + 1] = (sprlinebuf + 1)[n];
|
P[n + 1] = (sprlinebuf + 1)[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(t & 0x800000)) {
|
if (!(t & 0x800000)) {
|
||||||
if (!(t & 0x400000) || (P[n + 2] & 0x40)) // Normal sprite || behind bg sprite
|
if (!(t & 0x400000) || (P[n + 2] & 0x40)) // Normal sprite || behind bg sprite
|
||||||
P[n + 2] = (sprlinebuf + 2)[n];
|
P[n + 2] = (sprlinebuf + 2)[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(t & 0x80000000)) {
|
if (!(t & 0x80000000)) {
|
||||||
if (!(t & 0x40000000) || (P[n + 3] & 0x40)) // Normal sprite || behind bg sprite
|
if (!(t & 0x40000000) || (P[n + 3] & 0x40)) // Normal sprite || behind bg sprite
|
||||||
P[n + 3] = (sprlinebuf + 3)[n];
|
P[n + 3] = (sprlinebuf + 3)[n];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* TODO: Simplify */
|
/* TODO: Simplify */
|
||||||
if (!(t & 0x80000000)) {
|
if (!(t & 0x80000000)) {
|
||||||
if (!(t & 0x40000000)) // Normal sprite
|
if (!(t & 0x40000000)) // Normal sprite
|
||||||
P[n] = sprlinebuf[n];
|
P[n] = sprlinebuf[n];
|
||||||
else if (P[n] & 64) // behind bg sprite
|
else if (P[n] & 64) // behind bg sprite
|
||||||
P[n] = sprlinebuf[n];
|
P[n] = sprlinebuf[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(t & 0x800000)) {
|
if (!(t & 0x800000)) {
|
||||||
if (!(t & 0x400000)) // Normal sprite
|
if (!(t & 0x400000)) // Normal sprite
|
||||||
P[n + 1] = (sprlinebuf + 1)[n];
|
P[n + 1] = (sprlinebuf + 1)[n];
|
||||||
else if (P[n + 1] & 64) // behind bg sprite
|
else if (P[n + 1] & 64) // behind bg sprite
|
||||||
P[n + 1] = (sprlinebuf + 1)[n];
|
P[n + 1] = (sprlinebuf + 1)[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(t & 0x8000)) {
|
if (!(t & 0x8000)) {
|
||||||
if (!(t & 0x4000)) // Normal sprite
|
if (!(t & 0x4000)) // Normal sprite
|
||||||
P[n + 2] = (sprlinebuf + 2)[n];
|
P[n + 2] = (sprlinebuf + 2)[n];
|
||||||
else if (P[n + 2] & 64) // behind bg sprite
|
else if (P[n + 2] & 64) // behind bg sprite
|
||||||
P[n + 2] = (sprlinebuf + 2)[n];
|
P[n + 2] = (sprlinebuf + 2)[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(t & 0x80)) {
|
if (!(t & 0x80)) {
|
||||||
if (!(t & 0x40)) // Normal sprite
|
if (!(t & 0x40)) // Normal sprite
|
||||||
P[n + 3] = (sprlinebuf + 3)[n];
|
P[n + 3] = (sprlinebuf + 3)[n];
|
||||||
else if (P[n + 3] & 64) // behind bg sprite
|
else if (P[n + 3] & 64) // behind bg sprite
|
||||||
P[n + 3] = (sprlinebuf + 3)[n];
|
P[n + 3] = (sprlinebuf + 3)[n];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1642,7 +1658,7 @@ void FCEUPPU_Power(void) {
|
||||||
BWrite[x + 2] = B2002;
|
BWrite[x + 2] = B2002;
|
||||||
ARead[x + 3] = A200x;
|
ARead[x + 3] = A200x;
|
||||||
BWrite[x + 3] = B2003;
|
BWrite[x + 3] = B2003;
|
||||||
ARead[x + 4] = A2004; //A2004;
|
ARead[x + 4] = A2004; //A2004;
|
||||||
BWrite[x + 4] = B2004;
|
BWrite[x + 4] = B2004;
|
||||||
ARead[x + 5] = A200x;
|
ARead[x + 5] = A200x;
|
||||||
BWrite[x + 5] = B2005;
|
BWrite[x + 5] = B2005;
|
||||||
|
@ -1678,11 +1694,11 @@ int FCEUPPU_Loop(int skip) {
|
||||||
X6502_Run(12);
|
X6502_Run(12);
|
||||||
if (GameInfo->type == GIT_NSF)
|
if (GameInfo->type == GIT_NSF)
|
||||||
DoNSFFrame();
|
DoNSFFrame();
|
||||||
else{
|
else {
|
||||||
if (VBlankON)
|
if (VBlankON)
|
||||||
TriggerNMI();
|
TriggerNMI();
|
||||||
}
|
}
|
||||||
X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12); //-12);
|
X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12);
|
||||||
PPU_status &= 0x1f;
|
PPU_status &= 0x1f;
|
||||||
X6502_Run(256);
|
X6502_Run(256);
|
||||||
|
|
||||||
|
@ -1721,7 +1737,7 @@ int FCEUPPU_Loop(int skip) {
|
||||||
y = SPRAM[0];
|
y = SPRAM[0];
|
||||||
y++;
|
y++;
|
||||||
|
|
||||||
PPU_status |= 0x20; // Fixes "Bee 52". Does it break anything?
|
PPU_status |= 0x20; // Fixes "Bee 52". Does it break anything?
|
||||||
if (GameHBIRQHook) {
|
if (GameHBIRQHook) {
|
||||||
X6502_Run(256);
|
X6502_Run(256);
|
||||||
for (scanline = 0; scanline < 240; scanline++) {
|
for (scanline = 0; scanline < 240; scanline++) {
|
||||||
|
@ -1732,17 +1748,17 @@ int FCEUPPU_Loop(int skip) {
|
||||||
}
|
}
|
||||||
} else if (y < 240) {
|
} else if (y < 240) {
|
||||||
X6502_Run((256 + 85) * y);
|
X6502_Run((256 + 85) * y);
|
||||||
if (SpriteON) PPU_status |= 0x40; // Quick and very dirty hack.
|
if (SpriteON) PPU_status |= 0x40; // Quick and very dirty hack.
|
||||||
X6502_Run((256 + 85) * (240 - y));
|
X6502_Run((256 + 85) * (240 - y));
|
||||||
} else
|
} else
|
||||||
X6502_Run((256 + 85) * 240);
|
X6502_Run((256 + 85) * 240);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else{
|
else {
|
||||||
int x, max, maxref;
|
int x, max, maxref;
|
||||||
|
|
||||||
deemp = PPU[1] >> 5;
|
deemp = PPU[1] >> 5;
|
||||||
for (scanline = 0; scanline < 240; ) { //scanline is incremented in DoLine. Evil. :/
|
for (scanline = 0; scanline < 240; ) { //scanline is incremented in DoLine. Evil. :/
|
||||||
deempcnt[deemp]++;
|
deempcnt[deemp]++;
|
||||||
DEBUG(FCEUD_UpdatePPUView(scanline, 1));
|
DEBUG(FCEUD_UpdatePPUView(scanline, 1));
|
||||||
DoLine();
|
DoLine();
|
||||||
|
@ -1758,7 +1774,7 @@ int FCEUPPU_Loop(int skip) {
|
||||||
}
|
}
|
||||||
SetNESDeemph(maxref, 0);
|
SetNESDeemph(maxref, 0);
|
||||||
}
|
}
|
||||||
} //else... to if(ppudead)
|
} //else... to if(ppudead)
|
||||||
|
|
||||||
#ifdef FRAMESKIP
|
#ifdef FRAMESKIP
|
||||||
if (skip) {
|
if (skip) {
|
||||||
|
@ -1893,7 +1909,7 @@ struct BGData {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Record main[34]; //one at the end is junk, it can never be rendered
|
Record main[34]; //one at the end is junk, it can never be rendered
|
||||||
} bgdata;
|
} bgdata;
|
||||||
|
|
||||||
static inline int PaletteAdjustPixel(int pixel) {
|
static inline int PaletteAdjustPixel(int pixel) {
|
||||||
|
@ -1933,11 +1949,11 @@ int FCEUX_PPU_Loop(int skip) {
|
||||||
//Timing is probably off, though.
|
//Timing is probably off, though.
|
||||||
//NOTE: Not having this here breaks a Super Donkey Kong game.
|
//NOTE: Not having this here breaks a Super Donkey Kong game.
|
||||||
PPU[3] = PPUSPL = 0;
|
PPU[3] = PPUSPL = 0;
|
||||||
const int delay = 20; //fceu used 12 here but I couldnt get it to work in marble madness and pirates.
|
const int delay = 20; //fceu used 12 here but I couldnt get it to work in marble madness and pirates.
|
||||||
|
|
||||||
ppur.status.sl = 241; //for sprite reads
|
ppur.status.sl = 241; //for sprite reads
|
||||||
|
|
||||||
runppu(delay); //X6502_Run(12);
|
runppu(delay); //X6502_Run(12);
|
||||||
if (VBlankON) TriggerNMI();
|
if (VBlankON) TriggerNMI();
|
||||||
if (PAL)
|
if (PAL)
|
||||||
runppu(70 * (kLineTime) - delay);
|
runppu(70 * (kLineTime) - delay);
|
||||||
|
@ -1958,7 +1974,7 @@ int FCEUX_PPU_Loop(int skip) {
|
||||||
//if(PPUON)
|
//if(PPUON)
|
||||||
// ppur.install_latches();
|
// 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 oamcounts[2] = { 0, 0 };
|
||||||
static int oamslot = 0;
|
static int oamslot = 0;
|
||||||
static int oamcount;
|
static int oamcount;
|
||||||
|
@ -2136,7 +2152,7 @@ int FCEUX_PPU_Loop(int skip) {
|
||||||
|
|
||||||
uint8* const oam = oams[scanslot][s];
|
uint8* const oam = oams[scanslot][s];
|
||||||
uint32 line = yp - oam[0];
|
uint32 line = yp - oam[0];
|
||||||
if (oam[2] & 0x80) //vflip
|
if (oam[2] & 0x80) //vflip
|
||||||
line = spriteHeight - line - 1;
|
line = spriteHeight - line - 1;
|
||||||
|
|
||||||
uint32 patternNumber = oam[1];
|
uint32 patternNumber = oam[1];
|
||||||
|
@ -2181,7 +2197,7 @@ int FCEUX_PPU_Loop(int skip) {
|
||||||
//does not set SpriteON in the beginning but it does
|
//does not set SpriteON in the beginning but it does
|
||||||
//set the bg on so if using the conditional SpriteON the MMC3 counter
|
//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
|
//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))
|
//(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
|
//http://nesdevwiki.org/wiki/index.php/Nintendo_MMC3
|
||||||
//test cases for timing: SMB3, Crystalis
|
//test cases for timing: SMB3, Crystalis
|
||||||
|
@ -2245,7 +2261,7 @@ int FCEUX_PPU_Loop(int skip) {
|
||||||
//first one on every second frame, then this delay simply doesn't exist.
|
//first one on every second frame, then this delay simply doesn't exist.
|
||||||
if (ppur.status.end_cycle == 341)
|
if (ppur.status.end_cycle == 341)
|
||||||
runppu(1);
|
runppu(1);
|
||||||
} //scanline loop
|
} //scanline loop
|
||||||
|
|
||||||
if (MMC5Hack && PPUON) MMC5_hb(240);
|
if (MMC5Hack && PPUON) MMC5_hb(240);
|
||||||
|
|
||||||
|
@ -2254,7 +2270,7 @@ int FCEUX_PPU_Loop(int skip) {
|
||||||
framectr++;
|
framectr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
FCEU_PutImage();
|
FCEU_PutImage();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue