2018-12-03 12:26:02 +01:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
2009-11-30 09:14:38 +01:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "snes9x.h"
|
|
|
|
#include "memmap.h"
|
|
|
|
#include "dma.h"
|
2010-01-27 23:08:56 +01:00
|
|
|
#include "apu/apu.h"
|
|
|
|
#include "fxinst.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "fxemu.h"
|
2010-01-27 23:08:56 +01:00
|
|
|
#include "srtc.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "cheats.h"
|
|
|
|
#ifdef NETPLAY_SUPPORT
|
|
|
|
#include "netplay.h"
|
|
|
|
#endif
|
2010-01-27 23:08:56 +01:00
|
|
|
#ifdef DEBUGGER
|
|
|
|
#include "debug.h"
|
|
|
|
#include "missing.h"
|
2009-11-25 07:35:14 +01:00
|
|
|
#endif
|
2009-11-30 09:14:38 +01:00
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
struct SCPUState CPU;
|
|
|
|
struct SICPU ICPU;
|
|
|
|
struct SRegisters Registers;
|
|
|
|
struct SPPU PPU;
|
|
|
|
struct InternalPPU IPPU;
|
|
|
|
struct SDMA DMA[8];
|
|
|
|
struct STimings Timings;
|
|
|
|
struct SGFX GFX;
|
|
|
|
struct SBG BG;
|
|
|
|
struct SLineData LineData[240];
|
|
|
|
struct SLineMatrixData LineMatrixData[240];
|
|
|
|
struct SDSP0 DSP0;
|
|
|
|
struct SDSP1 DSP1;
|
|
|
|
struct SDSP2 DSP2;
|
|
|
|
struct SDSP3 DSP3;
|
|
|
|
struct SDSP4 DSP4;
|
|
|
|
struct SSA1 SA1;
|
|
|
|
struct SSA1Registers SA1Registers;
|
2011-01-17 14:54:34 +01:00
|
|
|
struct FxRegs_s GSU;
|
|
|
|
struct FxInfo_s SuperFX;
|
2010-01-27 23:08:56 +01:00
|
|
|
struct SST010 ST010;
|
|
|
|
struct SST011 ST011;
|
|
|
|
struct SST018 ST018;
|
|
|
|
struct SOBC1 OBC1;
|
|
|
|
struct SSPC7110Snapshot s7snap;
|
|
|
|
struct SSRTCSnapshot srtcsnap;
|
|
|
|
struct SRTCData RTCData;
|
|
|
|
struct SBSX BSX;
|
2018-01-17 15:23:10 +01:00
|
|
|
struct SMSU1 MSU1;
|
2010-01-27 23:08:56 +01:00
|
|
|
struct SMulti Multi;
|
|
|
|
struct SSettings Settings;
|
|
|
|
struct SSNESGameFixes SNESGameFixes;
|
|
|
|
#ifdef NETPLAY_SUPPORT
|
|
|
|
struct SNetPlay NetPlay;
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUGGER
|
|
|
|
struct Missing missing;
|
|
|
|
#endif
|
|
|
|
struct SCheatData Cheat;
|
|
|
|
struct Watch watches[16];
|
|
|
|
CMemory Memory;
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
char String[513];
|
|
|
|
uint8 OpenBus = 0;
|
|
|
|
uint8 *HDMAMemPointers[8];
|
|
|
|
uint16 BlackColourMap[256];
|
|
|
|
uint16 DirectColourMaps[8][256];
|
2009-11-30 09:14:38 +01:00
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
SnesModel M1SNES = { 1, 3, 2 };
|
|
|
|
SnesModel M2SNES = { 2, 4, 3 };
|
|
|
|
SnesModel *Model = &M1SNES;
|
2009-11-30 09:14:38 +01:00
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
uint16 SignExtend[2] =
|
|
|
|
{
|
|
|
|
0x0000,
|
|
|
|
0xff00
|
2008-08-06 03:09:59 +02:00
|
|
|
};
|
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
int HDMA_ModeByteCounts[8] =
|
|
|
|
{
|
|
|
|
1, 2, 2, 4, 4, 4, 2, 4
|
2008-08-06 03:09:59 +02:00
|
|
|
};
|
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
uint8 mul_brightness[16][32] =
|
|
|
|
{
|
|
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 },
|
|
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
|
|
|
|
0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04 },
|
|
|
|
{ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03,
|
|
|
|
0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06 },
|
|
|
|
{ 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04,
|
|
|
|
0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08 },
|
|
|
|
{ 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05,
|
|
|
|
0x05, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a },
|
|
|
|
{ 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06,
|
|
|
|
0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0c, 0x0c },
|
|
|
|
{ 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07,
|
|
|
|
0x07, 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e },
|
|
|
|
{ 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08,
|
|
|
|
0x09, 0x09, 0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x0e, 0x0e, 0x0f, 0x0f, 0x10, 0x11 },
|
|
|
|
{ 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x07, 0x07, 0x08, 0x08, 0x09,
|
|
|
|
0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0d, 0x0d, 0x0e, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x11, 0x12, 0x13 },
|
|
|
|
{ 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x05, 0x06, 0x07, 0x07, 0x08, 0x09, 0x09, 0x0a,
|
|
|
|
0x0b, 0x0b, 0x0c, 0x0d, 0x0d, 0x0e, 0x0f, 0x0f, 0x10, 0x11, 0x11, 0x12, 0x13, 0x13, 0x14, 0x15 },
|
|
|
|
{ 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x06, 0x07, 0x07, 0x08, 0x09, 0x0a, 0x0a, 0x0b,
|
|
|
|
0x0c, 0x0c, 0x0d, 0x0e, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x12, 0x13, 0x14, 0x15, 0x15, 0x16, 0x17 },
|
|
|
|
{ 0x00, 0x01, 0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0a, 0x0b, 0x0c,
|
|
|
|
0x0d, 0x0e, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x12, 0x13, 0x14, 0x15, 0x16, 0x16, 0x17, 0x18, 0x19 },
|
|
|
|
{ 0x00, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0a, 0x0b, 0x0c, 0x0d,
|
|
|
|
0x0e, 0x0f, 0x10, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x17, 0x18, 0x19, 0x1a, 0x1b },
|
|
|
|
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
|
|
|
0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d },
|
|
|
|
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
|
|
|
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }
|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