aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliaspider2014-11-03 11:11:05 +0100
committeraliaspider2014-11-03 11:11:05 +0100
commit7077e9821593b2c9b78830c4cc5055c6a79cdd69 (patch)
tree615195d3db586f5542eddd0cbd17e46e816f954b
parent3564bfe8134ce6e1294a59212484e9ee487ab4f5 (diff)
downloadsnesemu-7077e9821593b2c9b78830c4cc5055c6a79cdd69.tar.gz
snesemu-7077e9821593b2c9b78830c4cc5055c6a79cdd69.tar.bz2
snesemu-7077e9821593b2c9b78830c4cc5055c6a79cdd69.zip
can build with USE_BLARGG_APU enabled, still not working.
-rw-r--r--Makefile2
-rw-r--r--libretro.c39
-rw-r--r--source/apu.h45
-rw-r--r--source/apu_blargg.c8
-rw-r--r--source/cpuexec.c11
-rw-r--r--source/cpuops.c4
-rw-r--r--source/dma.c3
-rw-r--r--source/globals.c9
-rw-r--r--source/memmap.c6
-rw-r--r--source/ppu.c5
-rw-r--r--source/snes9x.h3
11 files changed, 115 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 001d83d..407ba6e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
DEBUG = 0
PERF_TEST = 1
-HAVE_GRIFFIN = 0
+HAVE_GRIFFIN = 1
LOAD_FROM_MEMORY_TEST = 0
USE_BLARGG_APU = 0
diff --git a/libretro.c b/libretro.c
index 3040171..4302019 100644
--- a/libretro.c
+++ b/libretro.c
@@ -251,7 +251,7 @@ void init_sfc_setting(void)
{
memset(&Settings, 0, sizeof(Settings));
Settings.JoystickEnabled = FALSE;
- Settings.SoundPlaybackRate = 44100; // -> ds2sound.h for defs
+ Settings.SoundPlaybackRate = 32000; // -> ds2sound.h for defs
Settings.SoundBufferSize = 512;
Settings.CyclesPercentage = 100;
@@ -306,19 +306,23 @@ void retro_init(void)
S9xInitAPU();
S9xInitDisplay();
S9xInitGFX();
+#ifdef USE_BLARGG_APU
+ S9xInitSound(16, 0);
+#else
S9xInitSound(Settings.SoundPlaybackRate,
TRUE,
Settings.SoundBufferSize);
+#endif
}
void retro_deinit(void)
{
- if(Settings.SPC7110)
+ if (Settings.SPC7110)
(*CleanUp7110)();
- SaveSRAM (S9xGetFilename ("srm"));
+ SaveSRAM(S9xGetFilename("srm"));
S9xDeinitGFX();
S9xDeinitDisplay();
@@ -388,7 +392,7 @@ void retro_run(void)
if (samples_to_play > 512)
{
- S9xMixSamples((uint8*)audio_buf, ((int)samples_to_play) * 2);
+ S9xMixSamples((void*)audio_buf, ((int)samples_to_play) * 2);
audio_batch_cb(audio_buf, (int)samples_to_play);
samples_to_play -= (int)samples_to_play;
}
@@ -579,8 +583,11 @@ void retro_reset(void)
size_t retro_serialize_size(void)
{
return sizeof(CPU) + sizeof(ICPU) + sizeof(PPU) + sizeof(DMA) +
- 0x10000 + 0x20000 + 0x20000 + 0x8000 + sizeof(APU) +
- sizeof(IAPU) + 0x10000 + sizeof(SA1) +
+ 0x10000 + 0x20000 + 0x20000 + 0x8000 +
+#ifndef USE_BLARGG_APU
+ sizeof(APU) + sizeof(IAPU)
+#endif
+ + 0x10000 + sizeof(SA1) +
sizeof(s7r) + sizeof(rtc_f9);
}
@@ -590,7 +597,7 @@ bool retro_serialize(void* data, size_t size)
S9xUpdateRTC();
S9xSRTCPreSaveState();
-
+#ifndef USE_BLARGG_APU
for (i = 0; i < 8; i++)
{
SoundData.channels[i].previous16[0] = (int16)
@@ -598,7 +605,7 @@ bool retro_serialize(void* data, size_t size)
SoundData.channels[i].previous16[1] = (int16)
SoundData.channels[i].previous[1];
}
-
+#endif
uint8_t* buffer = data;
memcpy(buffer, &CPU, sizeof(CPU));
buffer += sizeof(CPU);
@@ -616,12 +623,14 @@ bool retro_serialize(void* data, size_t size)
buffer += 0x20000;
memcpy(buffer, Memory.FillRAM, 0x8000);
buffer += 0x8000;
+#ifndef USE_BLARGG_APU
memcpy(buffer, &APU, sizeof(APU));
buffer += sizeof(APU);
memcpy(buffer, &IAPU, sizeof(IAPU));
buffer += sizeof(IAPU);
memcpy(buffer, IAPU.RAM, 0x10000);
buffer += 0x10000;
+#endif
SA1.Registers.PC = SA1.PC - SA1.PCBase;
S9xSA1PackStatus();
@@ -643,9 +652,9 @@ bool retro_unserialize(const void* data, size_t size)
return false;
S9xReset();
-
+#ifndef USE_BLARGG_APU
uint8* IAPU_RAM_current = IAPU.RAM;
-
+#endif
memcpy(&CPU, buffer, sizeof(CPU));
buffer += sizeof(CPU);
memcpy(&ICPU, buffer, sizeof(ICPU));
@@ -662,6 +671,7 @@ bool retro_unserialize(const void* data, size_t size)
buffer += 0x20000;
memcpy(Memory.FillRAM, buffer, 0x8000);
buffer += 0x8000;
+#ifndef USE_BLARGG_APU
memcpy(&APU, buffer, sizeof(APU));
buffer += sizeof(APU);
memcpy(&IAPU, buffer, sizeof(IAPU));
@@ -671,6 +681,7 @@ bool retro_unserialize(const void* data, size_t size)
IAPU.RAM = IAPU_RAM_current;
memcpy(IAPU.RAM, buffer, 0x10000);
buffer += 0x10000;
+#endif
memcpy(&SA1, buffer, sizeof(SA1));
buffer += sizeof(SA1);
@@ -686,9 +697,11 @@ bool retro_unserialize(const void* data, size_t size)
CPU.InDMA = FALSE;
S9xFixColourBrightness();
- S9xAPUUnpackStatus();
S9xSA1UnpackStatus();
+#ifndef USE_BLARGG_APU
+ S9xAPUUnpackStatus();
S9xFixSoundAfterSnapshotLoad();
+#endif
ICPU.ShiftedPB = ICPU.Registers.PB << 16;
ICPU.ShiftedDB = ICPU.Registers.DB << 16;
S9xSetPCBase(ICPU.ShiftedPB + ICPU.Registers.PC);
@@ -730,7 +743,11 @@ bool retro_load_game(const struct retro_game_info* game)
samples_per_frame = av_info.timing.sample_rate / av_info.timing.fps;
+#ifdef USE_BLARGG_APU
+ Settings.SoundPlaybackRate = av_info.timing.sample_rate;
+#else
S9xSetPlaybackRate(av_info.timing.sample_rate);
+#endif
return true;
}
diff --git a/source/apu.h b/source/apu.h
index 046749d..59c8aeb 100644
--- a/source/apu.h
+++ b/source/apu.h
@@ -210,5 +210,50 @@ extern void (*S9xApuOpcodes [256])(void);
#define FREQUENCY_MASK 0x3fff
#endif
+#else
+#include "apu_blargg.h"
+#define ONE_APU_CYCLE 21
+#define APU_EXECUTE1() do{}while(0)
+#define APU_EXECUTE() do{}while(0)
+
+//typedef struct
+//{
+// uint8* PC;
+// SAPURegisters Registers;
+// uint8* RAM;
+// uint8* DirectPage;
+// bool8 APUExecuting;
+// uint8 Bit;
+// uint32 Address;
+// uint8* WaitAddress1;
+// uint8* WaitAddress2;
+// uint32 WaitCounter;
+// uint8 _Carry;
+// uint8 _Zero;
+// uint8 _Overflow;
+// uint32 TimerErrorCounter;
+// uint32 Scanline;
+// int32 OneCycle;
+// int32 TwoCycles;
+//} SIAPU;
+
+//typedef struct
+//{
+// int32 Cycles;
+// bool8 ShowROM;
+// uint8 Flags;
+// uint8 KeyedChannels;
+// uint8 OutPorts [4];
+// uint8 DSP [0x80];
+// uint8 ExtraRAM [64];
+// uint16 Timer [3];
+// uint16 TimerTarget [3];
+// bool8 TimerEnabled [3];
+// bool8 TimerValueWritten [3];
+//} SAPU;
+
+//SAPU APU;
+//SIAPU IAPU;
+
#endif
diff --git a/source/apu_blargg.c b/source/apu_blargg.c
index c2afa9b..78b4c25 100644
--- a/source/apu_blargg.c
+++ b/source/apu_blargg.c
@@ -182,12 +182,16 @@
#include <limits.h>
#include "blargg_endian.h"
-#include "apu.h"
+#include "apu_blargg.h"
#include "snes9x.h"
-#include "snapshot.h"
+//#include "snapshot.h"
#include "display.h"
+#ifndef INLINE
+#define INLINE inline
+#endif
+
/***********************************************************************************
SPC DSP
***********************************************************************************/
diff --git a/source/cpuexec.c b/source/cpuexec.c
index 2c1b67a..ce2d5c3 100644
--- a/source/cpuexec.c
+++ b/source/cpuexec.c
@@ -612,6 +612,8 @@ void S9xDoHBlankProcessing_SFX()
if (CPU.V_Counter >= FIRST_VISIBLE_LINE &&
CPU.V_Counter < PPU.ScreenHeight + FIRST_VISIBLE_LINE)
RenderLine(CPU.V_Counter - FIRST_VISIBLE_LINE);
+
+#ifndef USE_BLARGG_APU
// Use TimerErrorCounter to skip update of SPC700 timers once
// every 128 updates. Needed because this section of code is called
// once every emulated 63.5 microseconds, which coresponds to
@@ -665,6 +667,7 @@ void S9xDoHBlankProcessing_SFX()
}
}
}
+#endif // #ifndef USE_BLARGG_APU
break;
case HTIMER_BEFORE_EVENT:
@@ -700,6 +703,7 @@ void S9xDoHBlankProcessing_NoSFX()
case HBLANK_END_EVENT:
+#ifndef USE_BLARGG_APU
#ifndef STORM
if (Settings.SoundSync)
S9xGenerateSound();
@@ -715,6 +719,11 @@ void S9xDoHBlankProcessing_NoSFX()
}
else
APU.Cycles = 0;
+#else
+ S9xAPUExecute();
+ CPU.Cycles -= Settings.H_Max;
+ S9xAPUSetReferenceTime(CPU.Cycles);
+#endif
CPU.NextEvent = -1;
ICPU.Scanline++;
@@ -804,6 +813,7 @@ void S9xDoHBlankProcessing_NoSFX()
// if (IAPU.TimerErrorCounter >= )
// IAPU.TimerErrorCounter = 0;
// else
+#ifndef USE_BLARGG_APU
{
if (APU.TimerEnabled [2])
{
@@ -848,6 +858,7 @@ void S9xDoHBlankProcessing_NoSFX()
}
}
}
+#endif
break;
case HTIMER_BEFORE_EVENT:
diff --git a/source/cpuops.c b/source/cpuops.c
index 83b6910..f398e0c 100644
--- a/source/cpuops.c
+++ b/source/cpuops.c
@@ -3383,6 +3383,7 @@ static inline void CPUShutdown()
CPU.WaitAddress = NULL;
if (Settings.SA1)
S9xSA1ExecuteDuringSleep();
+#ifndef USE_BLARGG_APU
CPU.Cycles = CPU.NextEvent;
if (IAPU.APUExecuting)
{
@@ -3394,6 +3395,7 @@ static inline void CPUShutdown()
while (APU.Cycles < CPU.NextEvent);
ICPU.CPUExecuting = TRUE;
}
+#endif
}
else if (CPU.WaitCounter >= 2)
CPU.WaitCounter = 1;
@@ -4980,6 +4982,7 @@ static void OpCB(void)
if (Settings.Shutdown)
{
CPU.Cycles = CPU.NextEvent;
+#ifndef USE_BLARGG_APU
if (IAPU.APUExecuting)
{
ICPU.CPUExecuting = FALSE;
@@ -4990,6 +4993,7 @@ static void OpCB(void)
while (APU.Cycles < CPU.NextEvent);
ICPU.CPUExecuting = TRUE;
}
+#endif
}
else
{
diff --git a/source/dma.c b/source/dma.c
index a5e4a35..f02d10a 100644
--- a/source/dma.c
+++ b/source/dma.c
@@ -811,11 +811,12 @@ void S9xDoDMA(uint8 Channel)
}
while (count);
}
-
+#ifndef USE_BLARGG_APU
#ifdef SPC700_C
IAPU.APUExecuting = Settings.APUEnabled;
APU_EXECUTE();
#endif
+#endif
if (Settings.SuperFX)
while (CPU.Cycles > CPU.NextEvent)
S9xDoHBlankProcessing_SFX();
diff --git a/source/globals.c b/source/globals.c
index e2c9d7c..3303dca 100644
--- a/source/globals.c
+++ b/source/globals.c
@@ -110,9 +110,11 @@ SICPU ICPU;
SCPUState CPU;
+#ifndef USE_BLARGG_APU
SAPU APU;
-
SIAPU IAPU;
+SSoundData SoundData;
+#endif
SSettings Settings;
@@ -120,7 +122,7 @@ SDSP1 DSP1;
SSA1 SA1;
-SSoundData SoundData;
+
SnesModel M1SNES = {1, 3, 2};
SnesModel M2SNES = {2, 4, 3};
@@ -169,6 +171,7 @@ uint32 even_low[4][16];
SCheatData Cheat;
#endif
+#ifndef USE_BLARGG_APU
SoundStatus so;
int Echo [24000];
@@ -178,7 +181,7 @@ int EchoBuffer [SOUND_BUFFER_SIZE];
int FilterTaps [8];
unsigned long Z = 0;
int Loop [16];
-
+#endif
uint16 SignExtend [2] =
{
0x00, 0xff00
diff --git a/source/memmap.c b/source/memmap.c
index 587a2c2..60e190a 100644
--- a/source/memmap.c
+++ b/source/memmap.c
@@ -1455,7 +1455,9 @@ void InitROM(bool8 Interleaved)
}
}
+#ifndef USE_BLARGG_APU
IAPU.OneCycle = ONE_APU_CYCLE;
+#endif
Settings.Shutdown = Settings.ShutdownMaster;
SetDSP = &DSP1SetByte;
@@ -3714,6 +3716,7 @@ void ApplyROMFixes()
//APU timing hacks
+#ifndef USE_BLARGG_APU
// Stunt Racer FX
if (strcmp(Memory.ROMId, "CQ ") == 0 ||
// Illusion of Gaia
@@ -3721,6 +3724,7 @@ void ApplyROMFixes()
strcmp(Memory.ROMName, "GAIA GENSOUKI 1 JPN") == 0)
IAPU.OneCycle = 13;
+
// RENDERING RANGER R2
if (strcmp(Memory.ROMId, "AVCJ") == 0 ||
//Mark Davis
@@ -3768,7 +3772,7 @@ void ApplyROMFixes()
|| //Kamen Rider
strncmp(Memory.ROMName, "LETs PACHINKO(", 14) == 0) //A set of BS games
IAPU.OneCycle = 15;
-
+#endif
//Specific game fixes
diff --git a/source/ppu.c b/source/ppu.c
index 181fdaf..bc28114 100644
--- a/source/ppu.c
+++ b/source/ppu.c
@@ -886,6 +886,7 @@ void S9xSetPPU(uint8 Byte, uint16 Address)
case 0x217d:
case 0x217e:
case 0x217f:
+#ifndef USE_BLARGG_APU
#ifdef SPCTOOL
_SPCInPB(Address & 3, Byte);
#else
@@ -897,6 +898,7 @@ void S9xSetPPU(uint8 Byte, uint16 Address)
IAPU.WaitCounter++;
#endif
#endif // SPCTOOL
+#endif // #ifndef USE_BLARGG_APU
break;
case 0x2180:
REGISTER_2180(Byte);
@@ -1269,6 +1271,7 @@ uint8 S9xGetPPU(uint16 Address)
case 0x217d:
case 0x217e:
case 0x217f:
+#ifndef USE_BLARGG_APU
#ifdef SPCTOOL
return ((uint8) _SPCOutP [Address & 3]);
#else
@@ -1291,7 +1294,7 @@ uint8 S9xGetPPU(uint16 Address)
return (APU.OutPorts [Address & 3]);
}
-
+#endif
switch (Settings.SoundSkipMethod)
{
case 0:
diff --git a/source/snes9x.h b/source/snes9x.h
index 48a5714..e9c04a5 100644
--- a/source/snes9x.h
+++ b/source/snes9x.h
@@ -322,6 +322,9 @@ typedef struct
bool8 OBC1;
/* Sound options */
uint32 SoundPlaybackRate;
+#ifdef USE_BLARGG_APU
+ uint32 SoundInputRate;
+#endif
bool8 TraceSoundDSP;
bool8 EightBitConsoleSound; // due to caching, this needs S9xSetEightBitConsoleSound()
int SoundBufferSize;