summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTwinaphex2019-05-06 17:21:49 +0200
committerGitHub2019-05-06 17:21:49 +0200
commit903c003cad96add4599f0a94fab7a03735e20d3e (patch)
tree6d0fc22ba7e247461a2e8f100e32b9357b7e5e9e
parent6064e58855c7f3acc76ad55ce4ea2af985fe3c59 (diff)
parent25f5a184255518b92c5a9786312fb543fb6278d0 (diff)
downloadsnes9x2002-903c003cad96add4599f0a94fab7a03735e20d3e.tar.gz
snes9x2002-903c003cad96add4599f0a94fab7a03735e20d3e.tar.bz2
snes9x2002-903c003cad96add4599f0a94fab7a03735e20d3e.zip
Merge pull request #33 from Brunnis/master
Port input lag fix already used in the other snes9x cores
-rw-r--r--.vs/slnx.sqlitebin0 -> 86016 bytes
-rw-r--r--Makefile1
-rw-r--r--Makefile.common6
-rw-r--r--src/cpuexec.c107
-rw-r--r--src/gfx.c5
-rw-r--r--src/gfx16.c5
-rw-r--r--src/globals.c4
-rw-r--r--src/snes9x.h4
8 files changed, 101 insertions, 31 deletions
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
new file mode 100644
index 0000000..594fc9f
--- /dev/null
+++ b/.vs/slnx.sqlite
Binary files differ
diff --git a/Makefile b/Makefile
index fb4f7d6..87733b5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
DEBUG=0
+LAGFIX=1
TARGET_NAME = snes9x2002
ifeq ($(platform),)
diff --git a/Makefile.common b/Makefile.common
index 5316a49..b7078e2 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -118,4 +118,10 @@ CODE_DEFINES = -fomit-frame-pointer
endif
endif
+ifeq ($(LAGFIX), 1)
+ifneq ($(ASM_CPU), 1)
+DEFINES += -DLAGFIX
+endif
+endif
+
COMMON_DEFINES += $(CODE_DEFINES) $(WARNINGS_DEFINES) $(fpic)
diff --git a/src/cpuexec.c b/src/cpuexec.c
index ad7b254..950b7b9 100644
--- a/src/cpuexec.c
+++ b/src/cpuexec.c
@@ -131,6 +131,10 @@ void S9xMainLoop_SA1_APU(void)
S9xSA1MainLoop();
DO_HBLANK_CHECK();
+#ifdef LAGFIX
+ if (finishedFrame)
+ break;
+#endif
}
}
@@ -196,6 +200,10 @@ void S9xMainLoop_SA1_NoAPU(void)
S9xSA1MainLoop();
DO_HBLANK_CHECK();
+#ifdef LAGFIX
+ if (finishedFrame)
+ break;
+#endif
}
}
// USE_SA1
@@ -260,6 +268,11 @@ void S9xMainLoop_NoSA1_APU(void)
//S9xUpdateAPUTimer ();
DO_HBLANK_CHECK();
+
+#ifdef LAGFIX
+ if (finishedFrame)
+ break;
+#endif
}
}
@@ -323,6 +336,10 @@ void S9xMainLoop_NoSA1_NoAPU(void)
DO_HBLANK_CHECK();
+#ifdef LAGFIX
+ if (finishedFrame)
+ break;
+#endif
}
}
#endif
@@ -331,53 +348,81 @@ void S9xMainLoop_NoSA1_NoAPU(void)
void
S9xMainLoop(void)
{
-#ifndef ASMCPU
- if (Settings.APUEnabled == 1)
+#ifdef LAGFIX
+ do
{
-#ifdef USE_SA1
- if (Settings.SA1)
- S9xMainLoop_SA1_APU();
- else
#endif
- S9xMainLoop_NoSA1_APU();
- }
- else
- {
+#ifndef ASMCPU
+ if (Settings.APUEnabled == 1)
+ {
#ifdef USE_SA1
- if (Settings.SA1)
- S9xMainLoop_SA1_NoAPU();
+ if (Settings.SA1)
+ S9xMainLoop_SA1_APU();
+ else
+#endif
+ S9xMainLoop_NoSA1_APU();
+ }
else
+ {
+#ifdef USE_SA1
+ if (Settings.SA1)
+ S9xMainLoop_SA1_NoAPU();
+ else
#endif
- S9xMainLoop_NoSA1_NoAPU();
- }
+ S9xMainLoop_NoSA1_NoAPU();
+ }
#else
#ifdef ASM_SPC700
- if (Settings.asmspc700)
- asmMainLoop_spcAsm(&CPU);
- else
+ if (Settings.asmspc700)
+ asmMainLoop_spcAsm(&CPU);
+ else
#endif
- asmMainLoop_spcC(&CPU);
+ asmMainLoop_spcC(&CPU);
#endif
- Registers.PC = CPU.PC - CPU.PCBase;
+
+#ifdef LAGFIX
+ if (!finishedFrame)
+ {
+#endif
+#ifndef LAGFIX
+ Registers.PC = CPU.PC - CPU.PCBase;
#ifndef ASMCPU
- S9xPackStatus();
+ S9xPackStatus();
#endif
- S9xAPUPackStatus();
+ S9xAPUPackStatus();
+#endif
+ //if (CPU.Flags & SCAN_KEYS_FLAG)
+ // {
+ CPU.Flags &= ~SCAN_KEYS_FLAG;
+ //}
- //if (CPU.Flags & SCAN_KEYS_FLAG)
- // {
- CPU.Flags &= ~SCAN_KEYS_FLAG;
- //}
+ if (CPU.BRKTriggered && Settings.SuperFX && !CPU.TriedInterleavedMode2)
+ {
+ CPU.TriedInterleavedMode2 = TRUE;
+ CPU.BRKTriggered = FALSE;
+ S9xDeinterleaveMode2();
+ }
+#ifdef LAGFIX
+ }
+ else
+ {
+ finishedFrame = false;
+
+ Registers.PC = CPU.PC - CPU.PCBase;
- if (CPU.BRKTriggered && Settings.SuperFX && !CPU.TriedInterleavedMode2)
- {
- CPU.TriedInterleavedMode2 = TRUE;
- CPU.BRKTriggered = FALSE;
- S9xDeinterleaveMode2();
- }
+#ifndef ASMCPU
+ S9xPackStatus();
+#endif
+
+ S9xAPUPackStatus();
+
+ break;
+ }
+ } while (!finishedFrame);
+#endif
}
void S9xSetIRQ(uint32 source)
diff --git a/src/gfx.c b/src/gfx.c
index 3c39f87..3842d1d 100644
--- a/src/gfx.c
+++ b/src/gfx.c
@@ -635,6 +635,11 @@ void S9xEndScreenRefresh()
S9xDeinitUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight,
1);
}
+
+#ifdef LAGFIX
+ finishedFrame = true;
+#endif
+
#ifndef RC_OPTIMIZED
S9xApplyCheats();
#endif
diff --git a/src/gfx16.c b/src/gfx16.c
index 5653a44..51d1240 100644
--- a/src/gfx16.c
+++ b/src/gfx16.c
@@ -655,6 +655,11 @@ void S9xEndScreenRefresh()
S9xDeinitUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight,
1);
}
+
+#ifdef LAGFIX
+ finishedFrame = true;
+#endif
+
#ifndef RC_OPTIMIZED
S9xApplyCheats();
#endif
diff --git a/src/globals.c b/src/globals.c
index 8d09213..f7bfe5e 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -162,6 +162,10 @@ uint32 current_graphic_format = RGB565;
uint8 GetBank = 0;
SCheatData Cheat;
+#ifdef LAGFIX
+bool8 finishedFrame = false;
+#endif
+
SoundStatus so;
SSoundData SoundData;
int Echo [24000];
diff --git a/src/snes9x.h b/src/snes9x.h
index 3bc6df0..424cce8 100644
--- a/src/snes9x.h
+++ b/src/snes9x.h
@@ -378,6 +378,10 @@ extern SCPUState CPU;
extern SSNESGameFixes SNESGameFixes;
extern char String [513];
+#ifdef LAGFIX
+extern bool8 finishedFrame;
+#endif
+
void S9xExit(void);
void S9xMessage(int type, int number, const char* message);
void S9xLoadSDD1Data(void);