aboutsummaryrefslogtreecommitdiff
path: root/source/cpuexec.c
diff options
context:
space:
mode:
authorTwinaphex2017-08-16 06:04:43 +0200
committerGitHub2017-08-16 06:04:43 +0200
commite2cffaea148cfb79cc3546642acb61245b96069e (patch)
treec0a7c48d53a52641d6451aef386b7c2b73c0752a /source/cpuexec.c
parent4b70a73bcdb09e7f96a1e5696a512f4d33667f40 (diff)
parentb3711dfa5041d08490a8603fe221f267c0da290a (diff)
downloadsnes9x2005-e2cffaea148cfb79cc3546642acb61245b96069e.tar.gz
snes9x2005-e2cffaea148cfb79cc3546642acb61245b96069e.tar.bz2
snes9x2005-e2cffaea148cfb79cc3546642acb61245b96069e.zip
Merge pull request #41 from jamsilva/master
SA1 fixes and Brunnis' lagfix port
Diffstat (limited to 'source/cpuexec.c')
-rw-r--r--source/cpuexec.c416
1 files changed, 258 insertions, 158 deletions
diff --git a/source/cpuexec.c b/source/cpuexec.c
index e031483..2bbf90a 100644
--- a/source/cpuexec.c
+++ b/source/cpuexec.c
@@ -46,248 +46,348 @@ void S9xMainLoop()
void S9xMainLoop_SA1_SFX()
{
- for (;;)
+#ifdef LAGFIX
+ do
{
- APU_EXECUTE();
- if (CPU.Flags)
+#endif
+ do
{
- if (CPU.Flags & NMI_FLAG)
+ APU_EXECUTE();
+ if (CPU.Flags)
{
- if (--CPU.NMICycleCount == 0)
+ if (CPU.Flags & NMI_FLAG)
{
- CPU.Flags &= ~NMI_FLAG;
- if (CPU.WaitingForInterrupt)
+ if (--CPU.NMICycleCount == 0)
{
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
+ CPU.Flags &= ~NMI_FLAG;
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ S9xOpcode_NMI();
}
- S9xOpcode_NMI();
}
- }
- if (CPU.Flags & IRQ_PENDING_FLAG)
- {
- if (CPU.IRQCycleCount == 0)
+ if (CPU.Flags & IRQ_PENDING_FLAG)
{
- if (CPU.WaitingForInterrupt)
- {
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
- }
- if (CPU.IRQActive && !Settings.DisableIRQ)
+ if (CPU.IRQCycleCount == 0)
{
- if (!CheckFlag(IRQ))
- S9xOpcode_IRQ();
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ if (CPU.IRQActive && !Settings.DisableIRQ)
+ {
+ if (!CheckFlag(IRQ))
+ S9xOpcode_IRQ();
+ }
+ else
+ CPU.Flags &= ~IRQ_PENDING_FLAG;
}
- else
- CPU.Flags &= ~IRQ_PENDING_FLAG;
+ else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
+ CPU.IRQCycleCount = 1;
}
- else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
- CPU.IRQCycleCount = 1;
+ if (CPU.Flags & SCAN_KEYS_FLAG)
+ break;
}
- if (CPU.Flags & SCAN_KEYS_FLAG)
- break;
- }
- CPU.PCAtOpcodeStart = CPU.PC;
- CPU.Cycles += CPU.MemSpeed;
- (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
+ CPU.PCAtOpcodeStart = CPU.PC;
+ CPU.Cycles += CPU.MemSpeed;
+ (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
- if (SA1.Executing)
- S9xSA1MainLoop();
- DO_HBLANK_CHECK_SFX();
- }
+ if (SA1.Executing)
+ S9xSA1MainLoop();
+ DO_HBLANK_CHECK_SFX();
+
+#ifdef LAGFIX
+ if(finishedFrame)
+ break;
+#endif
+ } while(true);
- ICPU.Registers.PC = CPU.PC - CPU.PCBase;
- S9xPackStatus();
+ ICPU.Registers.PC = CPU.PC - CPU.PCBase;
+#ifndef USE_BLARGG_APU
+ IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
+#endif
+
+#ifdef LAGFIX
+ if(!finishedFrame)
+ {
+#endif
+ S9xPackStatus();
#ifndef USE_BLARGG_APU
- IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
- S9xAPUPackStatus();
+ S9xAPUPackStatus();
+#endif
+ CPU.Flags &= ~SCAN_KEYS_FLAG;
+#ifdef LAGFIX
+ }
+ else
+ {
+ finishedFrame = false;
+ break;
+ }
+ } while(!finishedFrame);
#endif
- CPU.Flags &= ~SCAN_KEYS_FLAG;
}
void S9xMainLoop_SA1_NoSFX()
{
- for (;;)
+#ifdef LAGFIX
+ do
{
- APU_EXECUTE();
- if (CPU.Flags)
+#endif
+ do
{
- if (CPU.Flags & NMI_FLAG)
+ APU_EXECUTE();
+ if (CPU.Flags)
{
- if (--CPU.NMICycleCount == 0)
+ if (CPU.Flags & NMI_FLAG)
{
- CPU.Flags &= ~NMI_FLAG;
- if (CPU.WaitingForInterrupt)
+ if (--CPU.NMICycleCount == 0)
{
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
+ CPU.Flags &= ~NMI_FLAG;
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ S9xOpcode_NMI();
}
- S9xOpcode_NMI();
}
- }
- if (CPU.Flags & IRQ_PENDING_FLAG)
- {
- if (CPU.IRQCycleCount == 0)
+ if (CPU.Flags & IRQ_PENDING_FLAG)
{
- if (CPU.WaitingForInterrupt)
- {
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
- }
- if (CPU.IRQActive && !Settings.DisableIRQ)
+ if (CPU.IRQCycleCount == 0)
{
- if (!CheckFlag(IRQ))
- S9xOpcode_IRQ();
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ if (CPU.IRQActive && !Settings.DisableIRQ)
+ {
+ if (!CheckFlag(IRQ))
+ S9xOpcode_IRQ();
+ }
+ else
+ CPU.Flags &= ~IRQ_PENDING_FLAG;
}
- else
- CPU.Flags &= ~IRQ_PENDING_FLAG;
+ else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
+ CPU.IRQCycleCount = 1;
}
- else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
- CPU.IRQCycleCount = 1;
+ if (CPU.Flags & SCAN_KEYS_FLAG)
+ break;
}
- if (CPU.Flags & SCAN_KEYS_FLAG)
- break;
- }
- CPU.PCAtOpcodeStart = CPU.PC;
- CPU.Cycles += CPU.MemSpeed;
- (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
+ CPU.PCAtOpcodeStart = CPU.PC;
+ CPU.Cycles += CPU.MemSpeed;
+ (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
- if (SA1.Executing)
- S9xSA1MainLoop();
- DO_HBLANK_CHECK_NoSFX();
- }
+ if (SA1.Executing)
+ S9xSA1MainLoop();
+ DO_HBLANK_CHECK_NoSFX();
+
+#ifdef LAGFIX
+ if(finishedFrame)
+ break;
+#endif
+ } while(true);
+
+ ICPU.Registers.PC = CPU.PC - CPU.PCBase;
+#ifndef USE_BLARGG_APU
+ IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
+#endif
- ICPU.Registers.PC = CPU.PC - CPU.PCBase;
- S9xPackStatus();
+#ifdef LAGFIX
+ if(!finishedFrame)
+ {
+#endif
+ S9xPackStatus();
#ifndef USE_BLARGG_APU
- IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
- S9xAPUPackStatus();
+ S9xAPUPackStatus();
+#endif
+ CPU.Flags &= ~SCAN_KEYS_FLAG;
+#ifdef LAGFIX
+ }
+ else
+ {
+ finishedFrame = false;
+ break;
+ }
+ } while(!finishedFrame);
#endif
- CPU.Flags &= ~SCAN_KEYS_FLAG;
}
void S9xMainLoop_NoSA1_SFX()
{
- for (;;)
+#ifdef LAGFIX
+ do
{
- APU_EXECUTE();
- if (CPU.Flags)
+#endif
+ do
{
- if (CPU.Flags & NMI_FLAG)
+ APU_EXECUTE();
+ if (CPU.Flags)
{
- if (--CPU.NMICycleCount == 0)
+ if (CPU.Flags & NMI_FLAG)
{
- CPU.Flags &= ~NMI_FLAG;
- if (CPU.WaitingForInterrupt)
+ if (--CPU.NMICycleCount == 0)
{
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
+ CPU.Flags &= ~NMI_FLAG;
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ S9xOpcode_NMI();
}
- S9xOpcode_NMI();
}
- }
- if (CPU.Flags & IRQ_PENDING_FLAG)
- {
- if (CPU.IRQCycleCount == 0)
+ if (CPU.Flags & IRQ_PENDING_FLAG)
{
- if (CPU.WaitingForInterrupt)
+ if (CPU.IRQCycleCount == 0)
{
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ if (CPU.IRQActive && !Settings.DisableIRQ)
+ {
+ if (!CheckFlag(IRQ))
+ S9xOpcode_IRQ();
+ }
+ else
+ CPU.Flags &= ~IRQ_PENDING_FLAG;
}
- if (CPU.IRQActive && !Settings.DisableIRQ)
- {
- if (!CheckFlag(IRQ))
- S9xOpcode_IRQ();
- }
- else
- CPU.Flags &= ~IRQ_PENDING_FLAG;
+ else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
+ CPU.IRQCycleCount = 1;
}
- else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
- CPU.IRQCycleCount = 1;
+ if (CPU.Flags & SCAN_KEYS_FLAG)
+ break;
}
- if (CPU.Flags & SCAN_KEYS_FLAG)
+
+ CPU.PCAtOpcodeStart = CPU.PC;
+ CPU.Cycles += CPU.MemSpeed;
+ (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
+ DO_HBLANK_CHECK_SFX();
+
+#ifdef LAGFIX
+ if(finishedFrame)
break;
- }
+#endif
+ } while(true);
- CPU.PCAtOpcodeStart = CPU.PC;
- CPU.Cycles += CPU.MemSpeed;
- (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
- DO_HBLANK_CHECK_SFX();
- }
+ ICPU.Registers.PC = CPU.PC - CPU.PCBase;
+#ifndef USE_BLARGG_APU
+ IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
+#endif
- ICPU.Registers.PC = CPU.PC - CPU.PCBase;
- S9xPackStatus();
+#ifdef LAGFIX
+ if(!finishedFrame)
+ {
+#endif
+ S9xPackStatus();
#ifndef USE_BLARGG_APU
- IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
- S9xAPUPackStatus();
+ S9xAPUPackStatus();
+#endif
+ CPU.Flags &= ~SCAN_KEYS_FLAG;
+#ifdef LAGFIX
+ }
+ else
+ {
+ finishedFrame = false;
+ break;
+ }
+ } while(!finishedFrame);
#endif
- CPU.Flags &= ~SCAN_KEYS_FLAG;
}
void S9xMainLoop_NoSA1_NoSFX()
{
- for (;;)
+#ifdef LAGFIX
+ do
{
- APU_EXECUTE();
- if (CPU.Flags)
+#endif
+ do
{
- if (CPU.Flags & NMI_FLAG)
+ APU_EXECUTE();
+ if (CPU.Flags)
{
- if (--CPU.NMICycleCount == 0)
+ if (CPU.Flags & NMI_FLAG)
{
- CPU.Flags &= ~NMI_FLAG;
- if (CPU.WaitingForInterrupt)
+ if (--CPU.NMICycleCount == 0)
{
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
+ CPU.Flags &= ~NMI_FLAG;
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ S9xOpcode_NMI();
}
- S9xOpcode_NMI();
}
- }
- if (CPU.Flags & IRQ_PENDING_FLAG)
- {
- if (CPU.IRQCycleCount == 0)
+ if (CPU.Flags & IRQ_PENDING_FLAG)
{
- if (CPU.WaitingForInterrupt)
- {
- CPU.WaitingForInterrupt = false;
- CPU.PC++;
- }
- if (CPU.IRQActive && !Settings.DisableIRQ)
+ if (CPU.IRQCycleCount == 0)
{
- if (!CheckFlag(IRQ))
- S9xOpcode_IRQ();
+ if (CPU.WaitingForInterrupt)
+ {
+ CPU.WaitingForInterrupt = false;
+ CPU.PC++;
+ }
+ if (CPU.IRQActive && !Settings.DisableIRQ)
+ {
+ if (!CheckFlag(IRQ))
+ S9xOpcode_IRQ();
+ }
+ else
+ CPU.Flags &= ~IRQ_PENDING_FLAG;
}
- else
- CPU.Flags &= ~IRQ_PENDING_FLAG;
+ else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
+ CPU.IRQCycleCount = 1;
}
- else if (--CPU.IRQCycleCount == 0 && CheckFlag(IRQ))
- CPU.IRQCycleCount = 1;
+ if (CPU.Flags & SCAN_KEYS_FLAG)
+ break;
}
- if (CPU.Flags & SCAN_KEYS_FLAG)
+
+ CPU.PCAtOpcodeStart = CPU.PC;
+ CPU.Cycles += CPU.MemSpeed;
+ (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
+ DO_HBLANK_CHECK_NoSFX();
+
+#ifdef LAGFIX
+ if(finishedFrame)
break;
- }
+#endif
+ } while(true);
- CPU.PCAtOpcodeStart = CPU.PC;
- CPU.Cycles += CPU.MemSpeed;
- (*ICPU.S9xOpcodes [*CPU.PC++].S9xOpcode)();
- DO_HBLANK_CHECK_NoSFX();
- }
+ ICPU.Registers.PC = CPU.PC - CPU.PCBase;
+#ifndef USE_BLARGG_APU
+ IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
+#endif
- ICPU.Registers.PC = CPU.PC - CPU.PCBase;
- S9xPackStatus();
+#ifdef LAGFIX
+ if(!finishedFrame)
+ {
+#endif
+ S9xPackStatus();
#ifndef USE_BLARGG_APU
- IAPU.Registers.PC = IAPU.PC - IAPU.RAM;
- S9xAPUPackStatus();
+ S9xAPUPackStatus();
+#endif
+ CPU.Flags &= ~SCAN_KEYS_FLAG;
+#ifdef LAGFIX
+ }
+ else
+ {
+ finishedFrame = false;
+ break;
+ }
+ } while(!finishedFrame);
#endif
- CPU.Flags &= ~SCAN_KEYS_FLAG;
}
void S9xSetIRQ(uint32_t source)