aboutsummaryrefslogtreecommitdiff
path: root/source/fxemu.c
diff options
context:
space:
mode:
authorTwinaphex2017-01-15 09:16:59 +0100
committerGitHub2017-01-15 09:16:59 +0100
commit0e8ec6b5f7ab59ad13970536c76e2c8c52a23965 (patch)
tree87330b0cb53dd4302071999a312c712672466550 /source/fxemu.c
parenta25a25f9a1327a996fe4ff37d3bfb7e3c15d174e (diff)
parentf1ca19db63461fd36a5739b0b7bd172185811d50 (diff)
downloadsnes9x2005-0e8ec6b5f7ab59ad13970536c76e2c8c52a23965.tar.gz
snes9x2005-0e8ec6b5f7ab59ad13970536c76e2c8c52a23965.tar.bz2
snes9x2005-0e8ec6b5f7ab59ad13970536c76e2c8c52a23965.zip
Merge pull request #23 from jamsilva/master
Cleanups, fixes (including one for "Retroarch/RetroPie Super Mario Allstars")
Diffstat (limited to 'source/fxemu.c')
-rw-r--r--source/fxemu.c271
1 files changed, 8 insertions, 263 deletions
diff --git a/source/fxemu.c b/source/fxemu.c
index ecef971..c16ee58 100644
--- a/source/fxemu.c
+++ b/source/fxemu.c
@@ -1,93 +1,5 @@
-/*******************************************************************************
- Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
+#include "../copyright"
- (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and
- Jerremy Koot (jkoot@snes9x.com)
-
- (c) Copyright 2001 - 2004 John Weidman (jweidman@slip.net)
-
- (c) Copyright 2002 - 2004 Brad Jorsch (anomie@users.sourceforge.net),
- funkyass (funkyass@spam.shaw.ca),
- Joel Yliluoma (http://iki.fi/bisqwit/)
- Kris Bleakley (codeviolation@hotmail.com),
- Matthew Kendora,
- Nach (n-a-c-h@users.sourceforge.net),
- Peter Bortas (peter@bortas.org) and
- zones (kasumitokoduck@yahoo.com)
-
- C4 x86 assembler and some C emulation code
- (c) Copyright 2000 - 2003 zsKnight (zsknight@zsnes.com),
- _Demo_ (_demo_@zsnes.com), and Nach
-
- C4 C++ code
- (c) Copyright 2003 Brad Jorsch
-
- DSP-1 emulator code
- (c) Copyright 1998 - 2004 Ivar (ivar@snes9x.com), _Demo_, Gary Henderson,
- John Weidman, neviksti (neviksti@hotmail.com),
- Kris Bleakley, Andreas Naive
-
- DSP-2 emulator code
- (c) Copyright 2003 Kris Bleakley, John Weidman, neviksti, Matthew Kendora, and
- Lord Nightmare (lord_nightmare@users.sourceforge.net
-
- OBC1 emulator code
- (c) Copyright 2001 - 2004 zsKnight, pagefault (pagefault@zsnes.com) and
- Kris Bleakley
- Ported from x86 assembler to C by sanmaiwashi
-
- SPC7110 and RTC C++ emulator code
- (c) Copyright 2002 Matthew Kendora with research by
- zsKnight, John Weidman, and Dark Force
-
- S-DD1 C emulator code
- (c) Copyright 2003 Brad Jorsch with research by
- Andreas Naive and John Weidman
-
- S-RTC C emulator code
- (c) Copyright 2001 John Weidman
-
- ST010 C++ emulator code
- (c) Copyright 2003 Feather, Kris Bleakley, John Weidman and Matthew Kendora
-
- Super FX x86 assembler emulator code
- (c) Copyright 1998 - 2003 zsKnight, _Demo_, and pagefault
-
- Super FX C emulator code
- (c) Copyright 1997 - 1999 Ivar, Gary Henderson and John Weidman
-
-
- SH assembler code partly based on x86 assembler code
- (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
-
- (c) Copyright 2014 - 2016 Daniel De Matteis. (UNDER NO CIRCUMSTANCE
- WILL COMMERCIAL RIGHTS EVER BE APPROPRIATED TO ANY PARTY)
-
- Specific ports contains the works of other authors. See headers in
- individual files.
-
- Snes9x homepage: http://www.snes9x.com
-
- Permission to use, copy, modify and distribute Snes9x in both binary and
- source form, for non-commercial purposes, is hereby granted without fee,
- providing that this license information and copyright notice appear with
- all copies and any derived work.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event shall the authors be held liable for any damages
- arising from the use of this software.
-
- Snes9x is freeware for PERSONAL USE only. Commercial users should
- seek permission of the copyright holders first. Commercial use includes
- charging money for Snes9x or software derived from Snes9x.
-
- The copyright holders request that bug fixes and improvements to the code
- should be forwarded to them so everyone can benefit from the modifications
- in future versions.
-
- Super NES and Super Nintendo Entertainment System are trademarks of
- Nintendo Co., Limited and its subsidiary companies.
-*******************************************************************************/
#include "fxemu.h"
#include "fxinst.h"
#include <stdlib.h>
@@ -101,133 +13,21 @@ uint32_t(**fx_ppfFunctionTable)(uint32_t) = 0;
void (**fx_ppfPlotTable)() = 0;
void (**fx_ppfOpcodeTable)() = 0;
-#if 0
-void fx_setCache()
-{
- uint32_t c;
- GSU.bCacheActive = true;
- GSU.pvRegisters[0x3e] &= 0xf0;
- c = (uint32_t)GSU.pvRegisters[0x3e];
- c |= ((uint32_t)GSU.pvRegisters[0x3f]) << 8;
- if (c == GSU.vCacheBaseReg)
- return;
- GSU.vCacheBaseReg = c;
- GSU.vCacheFlags = 0;
- if (c < (0x10000 - 512))
- {
- uint8_t const* t = &ROM(c);
- memcpy(GSU.pvCache, t, 512);
- }
- else
- {
- uint8_t const* t1;
- uint8_t const* t2;
- uint32_t i = 0x10000 - c;
- t1 = &ROM(c);
- t2 = &ROM(0);
- memcpy(GSU.pvCache, t1, i);
- memcpy(&GSU.pvCache[i], t2, 512 - i);
- }
-}
-#endif
-
void FxCacheWriteAccess(uint16_t vAddress)
{
-#if 0
- if (!GSU.bCacheActive)
- {
- uint8_t v = GSU.pvCache[GSU.pvCache[vAddress & 0x1ff];
- fx_setCache();
- GSU.pvCache[GSU.pvCache[vAddress & 0x1ff] = v;
- }
-#endif
- if ((vAddress & 0x00f) == 0x00f)
- GSU.vCacheFlags |= 1 << ((vAddress & 0x1f0) >> 4);
+ if ((vAddress & 0x00f) == 0x00f)
+ GSU.vCacheFlags |= 1 << ((vAddress & 0x1f0) >> 4);
}
- void FxFlushCache()
+void FxFlushCache()
{
GSU.vCacheFlags = 0;
GSU.vCacheBaseReg = 0;
GSU.bCacheActive = false;
- // GSU.vPipe = 0x1;
-}
-
-static void fx_backupCache()
-{
-#if 0
- uint32_t i;
- uint32_t v = GSU.vCacheFlags;
- uint32_t c = USEX16(GSU.vCacheBaseReg);
- if (v)
- for (i = 0; i < 32; i++)
- {
- if (v & 1)
- {
- if (c < (0x10000 - 16))
- {
- uint8_t* t = &GSU.pvPrgBank[c];
- memcpy(&GSU.avCacheBackup[i << 4], t, 16);
- memcpy(t, &GSU.pvCache[i << 4], 16);
- }
- else
- {
- uint8_t* t1;
- uint8_t* t2;
- uint32_t a = 0x10000 - c;
- t1 = &GSU.pvPrgBank[c];
- t2 = &GSU.pvPrgBank[0];
- memcpy(&GSU.avCacheBackup[i << 4], t1, a);
- memcpy(t1, &GSU.pvCache[i << 4], a);
- memcpy(&GSU.avCacheBackup[(i << 4) + a], t2, 16 - a);
- memcpy(t2, &GSU.pvCache[(i << 4) + a], 16 - a);
- }
- }
- c = USEX16(c + 16);
- v >>= 1;
- }
-#endif
-}
-
-static void fx_restoreCache()
-{
-#if 0
- uint32_t i;
- uint32_t v = GSU.vCacheFlags;
- uint32_t c = USEX16(GSU.vCacheBaseReg);
- if (v)
- for (i = 0; i < 32; i++)
- {
- if (v & 1)
- {
- if (c < (0x10000 - 16))
- {
- uint8_t* t = &GSU.pvPrgBank[c];
- memcpy(t, &GSU.avCacheBackup[i << 4], 16);
- memcpy(&GSU.pvCache[i << 4], t, 16);
- }
- else
- {
- uint8_t* t1;
- uint8_t* t2;
- uint32_t a = 0x10000 - c;
- t1 = &GSU.pvPrgBank[c];
- t2 = &GSU.pvPrgBank[0];
- memcpy(t1, &GSU.avCacheBackup[i << 4], a);
- memcpy(&GSU.pvCache[i << 4], t1, a);
- memcpy(t2, &GSU.avCacheBackup[(i << 4) + a], 16 - a);
- memcpy(&GSU.pvCache[(i << 4) + a], t2, 16 - a);
- }
- }
- c = USEX16(c + 16);
- v >>= 1;
- }
-#endif
}
void fx_flushCache()
{
- fx_restoreCache();
GSU.vCacheFlags = 0;
GSU.bCacheActive = false;
}
@@ -285,10 +85,6 @@ static void fx_readRegisterSpace()
i |= ((int)(!!(p[GSU_SCMR] & 0x20))) << 1;
GSU.vScreenHeight = GSU.vScreenRealHeight = avHeight[i];
GSU.vMode = p[GSU_SCMR] & 0x03;
-#if 0
- if (GSU.vMode == 2)
- error illegal color depth GSU.vMode;
-#endif
if (i == 3)
GSU.vScreenSize = (256 / 8) * (256 / 8) * 32;
else
@@ -298,14 +94,9 @@ static void fx_readRegisterSpace()
/* OBJ Mode (for drawing into sprites) */
GSU.vScreenHeight = 256;
}
-#if 0
- if (GSU.pvScreenBase + GSU.vScreenSize > GSU.pvRam + (GSU.nRamBanks * 65536))
- error illegal address for screen base register
-#else
if (GSU.pvScreenBase + GSU.vScreenSize > GSU.pvRam + (GSU.nRamBanks * 65536))
GSU.pvScreenBase = GSU.pvRam + (GSU.nRamBanks * 65536) - GSU.vScreenSize;
-#endif
- GSU.pfPlot = fx_apfPlotTable[GSU.vMode];
+ GSU.pfPlot = fx_apfPlotTable[GSU.vMode];
GSU.pfRpix = fx_apfPlotTable[GSU.vMode + 5];
fx_ppfOpcodeTable[0x04c] = GSU.pfPlot;
@@ -314,8 +105,6 @@ static void fx_readRegisterSpace()
fx_ppfOpcodeTable[0x34c] = GSU.pfRpix;
fx_computeScreenPointers();
-
- fx_backupCache();
}
void fx_dirtySCBR()
@@ -483,8 +272,6 @@ static void fx_writeRegisterSpace()
p[GSU_RAMBR] = (uint8_t)GSU.vRamBankReg;
p[GSU_CBR] = (uint8_t)GSU.vCacheBaseReg;
p[GSU_CBR + 1] = (uint8_t)(GSU.vCacheBaseReg >> 8);
-
- fx_restoreCache();
}
/* Reset the FxChip */
@@ -493,30 +280,15 @@ void FxReset(struct FxInit_s* psFxInfo)
int i;
static uint32_t(**appfFunction[])(uint32_t) =
{
- &fx_apfFunctionTable[0],
-#if 0
- &fx_a_apfFunctionTable[0],
- &fx_r_apfFunctionTable[0],
- &fx_ar_apfFunctionTable[0],
-#endif
+ &fx_apfFunctionTable[0]
};
static void (**appfPlot[])() =
{
- &fx_apfPlotTable[0],
-#if 0
- &fx_a_apfPlotTable[0],
- &fx_r_apfPlotTable[0],
- &fx_ar_apfPlotTable[0],
-#endif
+ &fx_apfPlotTable[0]
};
static void (**appfOpcode[])() =
{
- &fx_apfOpcodeTable[0],
-#if 0
- &fx_a_apfOpcodeTable[0],
- &fx_r_apfOpcodeTable[0],
- &fx_ar_apfOpcodeTable[0],
-#endif
+ &fx_apfOpcodeTable[0]
};
/* Get function pointers for the current emulation mode */
@@ -624,22 +396,12 @@ int FxEmulate(uint32_t nInstructions)
{
CF(G);
fx_writeRegisterSpace();
-#if 0
- GSU.vIllegalAddress = (GSU.vPrgBankReg << 24) | R15;
- return FX_ERROR_ILLEGAL_ADDRESS;
-#else
return 0;
-#endif
}
/* Execute GSU session */
CF(IRQ);
- /*
- if (GSU.bBreakPoint)
- vCount = fx_ppfFunctionTable[FX_FUNCTION_RUN_TO_BREAKPOINT](nInstructions);
- else
- */
vCount = fx_ppfFunctionTable[FX_FUNCTION_RUN](nInstructions);
/* Store GSU registers */
@@ -652,18 +414,6 @@ int FxEmulate(uint32_t nInstructions)
return vCount;
}
-/* Breakpoints */
-/*
-void FxBreakPointSet(uint32_t vAddress)
-{
- GSU.bBreakPoint = true;
- GSU.vBreakPoint = USEX16(vAddress);
-}
-void FxBreakPointClear()
-{
- GSU.bBreakPoint = false;
-}*/
-
/* Step by step execution */
int FxStepOver(uint32_t nInstructions)
{
@@ -674,12 +424,7 @@ int FxStepOver(uint32_t nInstructions)
if (!fx_checkStartAddress())
{
CF(G);
-#if 0
- GSU.vIllegalAddress = (GSU.vPrgBankReg << 24) | R15;
- return FX_ERROR_ILLEGAL_ADDRESS;
-#else
return 0;
-#endif
}
if (PIPE >= 0xf0)