Skip to content
Permalink
Browse files
Merge branch 'msu1'
  • Loading branch information
bearoso committed Nov 14, 2016
2 parents 0703abf + dcf97e9 commit 27e6bc1b0114b088bf9000a2bd51c0d2108cf474
Showing with 883 additions and 23 deletions.
  1. +86 −1 apu/apu.cpp
  2. +4 −0 cpu.cpp
  3. +1 −0 getset.h
  4. +1 −0 globals.cpp
  5. +5 −0 gtk/Makefile.am
  6. +1 −0 libretro/Makefile.common
  7. +16 −2 memmap.cpp
  8. +467 −0 msu1.cpp
  9. +237 −0 msu1.h
  10. +1 −1 port.h
  11. +6 −1 ppu.cpp
  12. +31 −0 snapshot.cpp
  13. +1 −1 snapshot.h
  14. +1 −0 snes9x.h
  15. +1 −1 unix/Makefile.in
  16. +3 −3 win32/CD3DCG.cpp
  17. +10 −10 win32/CDirect3D.cpp
  18. +3 −3 win32/CXAudio2.cpp
  19. +2 −0 win32/snes9xw.vcxproj
  20. +6 −0 win32/snes9xw.vcxproj.filters
@@ -190,6 +190,7 @@
#include <math.h>
#include "snes9x.h"
#include "apu.h"
#include "msu1.h"
#include "snapshot.h"
#include "display.h"
#include "hermite_resampler.h"
@@ -239,6 +240,13 @@ namespace spc
static uint32 ratio_denominator = APU_DENOMINATOR_NTSC;
}

namespace msu
{
static int buffer_size;
static uint8 *landing_buffer = NULL;
static Resampler *resampler = NULL;
}

static void EightBitize (uint8 *, int);
static void DeStereo (uint8 *, int);
static void ReverseStereo (uint8 *, int);
@@ -311,6 +319,9 @@ bool8 S9xMixSamples (uint8 *buffer, int sample_count)
memset(dest, 0, sample_count << 1);
spc::resampler->clear();

if(Settings.MSU1)
msu::resampler->clear();

return (FALSE);
}
else
@@ -320,6 +331,17 @@ bool8 S9xMixSamples (uint8 *buffer, int sample_count)
spc::resampler->read((short *) dest, sample_count);
if (spc::lag == spc::lag_master)
spc::lag = 0;

if (Settings.MSU1)
{
if (msu::resampler->avail() >= sample_count)
{
uint8 *msu_sample = new uint8[sample_count * 2];
msu::resampler->read((short *)msu_sample, sample_count);
for (uint32 i = 0; i < sample_count; ++i)
*((int16*)(dest+(i * 2))) += *((int16*)(msu_sample+(i * 2)));
}
}
}
else
{
@@ -361,7 +383,19 @@ void S9xFinalizeSamples (void)
{
if (!Settings.Mute)
{
if (!spc::resampler->push((short *) spc::landing_buffer, SNES::dsp.spc_dsp.sample_count ()))
if (Settings.MSU1)
{
S9xMSU1Generate(SNES::dsp.spc_dsp.sample_count());
if (!msu::resampler->push((short *)msu::landing_buffer, S9xMSU1Samples()))
{
//spc::sound_in_sync = FALSE;

//if (Settings.SoundSync && !Settings.TurboMode)
//return;
}
}

if (!spc::resampler->push((short *)spc::landing_buffer, SNES::dsp.spc_dsp.sample_count()))
{
/* We weren't able to process the entire buffer. Potential overrun. */
spc::sound_in_sync = FALSE;
@@ -371,6 +405,7 @@ void S9xFinalizeSamples (void)
}
}


if (!Settings.SoundSync || Settings.TurboMode || Settings.Mute)
spc::sound_in_sync = TRUE;
else
@@ -380,6 +415,9 @@ void S9xFinalizeSamples (void)
spc::sound_in_sync = FALSE;

SNES::dsp.spc_dsp.set_output((SNES::SPC_DSP::sample_t *) spc::landing_buffer, spc::buffer_size);

if (Settings.MSU1)
S9xMSU1SetOutput((int16 *)msu::landing_buffer, msu::buffer_size);
}

void S9xLandSamples (void)
@@ -393,6 +431,8 @@ void S9xLandSamples (void)
void S9xClearSamples (void)
{
spc::resampler->clear();
if (Settings.MSU1)
msu::resampler->clear();
spc::lag = spc::lag_master;
}

@@ -419,6 +459,12 @@ static void UpdatePlaybackRate (void)

double time_ratio = (double) Settings.SoundInputRate * spc::timing_hack_numerator / (Settings.SoundPlaybackRate * spc::timing_hack_denominator);
spc::resampler->time_ratio(time_ratio);

if (Settings.MSU1)
{
time_ratio = (44100.0 / Settings.SoundPlaybackRate) * (Settings.SoundInputRate / 32040.5);
msu::resampler->time_ratio(time_ratio);
}
}

bool8 S9xInitSound (int buffer_ms, int lag_ms)
@@ -442,6 +488,7 @@ bool8 S9xInitSound (int buffer_ms, int lag_ms)
spc::buffer_size <<= 1;
if (Settings.SixteenBitSound)
spc::buffer_size <<= 1;
msu::buffer_size = ((buffer_ms * 44100 / 1000) * 441000 / 320405) << 2; // Always 16-bit, Stereo

printf("Sound buffer size: %d (%d samples)\n", spc::buffer_size, sample_count);

@@ -450,6 +497,11 @@ bool8 S9xInitSound (int buffer_ms, int lag_ms)
spc::landing_buffer = new uint8[spc::buffer_size * 2];
if (!spc::landing_buffer)
return (FALSE);
if (msu::landing_buffer)
delete[] msu::landing_buffer;
msu::landing_buffer = new uint8[msu::buffer_size * 2];
if (!msu::landing_buffer)
return (FALSE);

/* The resampler and spc unit use samples (16-bit short) as
arguments. Use 2x in the resampler for buffer leveling with SoundSync */
@@ -465,6 +517,20 @@ bool8 S9xInitSound (int buffer_ms, int lag_ms)
else
spc::resampler->resize(spc::buffer_size >> (Settings.SoundSync ? 0 : 1));


if (!msu::resampler)
{
msu::resampler = new HermiteResampler(msu::buffer_size);
if (!msu::resampler)
{
delete[] msu::landing_buffer;
return (FALSE);
}
}
else
msu::resampler->resize(msu::buffer_size);


SNES::dsp.spc_dsp.set_output ((SNES::SPC_DSP::sample_t *) spc::landing_buffer, spc::buffer_size);

UpdatePlaybackRate();
@@ -503,6 +569,7 @@ bool8 S9xInitAPU (void)
spc::landing_buffer = NULL;
spc::shrink_buffer = NULL;
spc::resampler = NULL;
msu::resampler = NULL;

return (TRUE);
}
@@ -526,6 +593,18 @@ void S9xDeinitAPU (void)
delete[] spc::shrink_buffer;
spc::shrink_buffer = NULL;
}

if (msu::resampler)
{
delete msu::resampler;
msu::resampler = NULL;
}

if (msu::landing_buffer)
{
delete[] msu::landing_buffer;
msu::landing_buffer = NULL;
}
}

static inline int S9xAPUGetClock (int32 cpucycles)
@@ -603,6 +682,9 @@ void S9xResetAPU (void)
SNES::dsp.spc_dsp.set_spc_snapshot_callback(SPCSnapshotCallback);

spc::resampler->clear();

if (Settings.MSU1)
msu::resampler->clear();
}

void S9xSoftResetAPU (void)
@@ -615,6 +697,9 @@ void S9xSoftResetAPU (void)
SNES::dsp.spc_dsp.set_output ((SNES::SPC_DSP::sample_t *) spc::landing_buffer, spc::buffer_size >> 1);

spc::resampler->clear();

if (Settings.MSU1)
msu::resampler->clear();
}

void S9xAPUSaveState (uint8 *block)
@@ -312,6 +312,8 @@ void S9xReset (void)
S9xResetOBC1();
if (Settings.SRTC)
S9xResetSRTC();
if (Settings.MSU1)
S9xMSU1Init();

S9xInitCheatData();
}
@@ -346,6 +348,8 @@ void S9xSoftReset (void)
S9xResetOBC1();
if (Settings.SRTC)
S9xResetSRTC();
if (Settings.MSU1)
S9xMSU1Init();

S9xInitCheatData();
}
@@ -199,6 +199,7 @@
#include "obc1.h"
#include "seta.h"
#include "bsx.h"
#include "msu1.h"

#define addCyclesInMemoryAccess \
if (!CPU.InDMAorHDMA) \
@@ -232,6 +232,7 @@ struct SSPC7110Snapshot s7snap;
struct SSRTCSnapshot srtcsnap;
struct SRTCData RTCData;
struct SBSX BSX;
struct SMSU1 MSU1;
struct SMulti Multi;
struct SSettings Settings;
struct SSNESGameFixes SNESGameFixes;
@@ -136,6 +136,11 @@ snes9x_gtk_SOURCES += \
../apu/bapu/smp/smp.cpp \
../apu/bapu/smp/smp_state.cpp

# MSU1
snes9x_gtk_SOURCES += \
../msu1.cpp \
../msu1.h

# DSP
snes9x_gtk_SOURCES += \
../dsp.cpp \
@@ -46,4 +46,5 @@ SOURCES_CXX := $(CORE_DIR)/apu/apu.cpp \
$(CORE_DIR)/spc7110.cpp \
$(CORE_DIR)/srtc.cpp \
$(CORE_DIR)/tile.cpp \
$(CORE_DIR)/msu1.cpp \
$(CORE_DIR)/libretro/libretro.cpp
@@ -205,6 +205,7 @@
#endif

#include <ctype.h>
#include <sys/stat.h>

#include "snes9x.h"
#include "memmap.h"
@@ -1274,6 +1275,12 @@ static bool8 is_GNEXT_Add_On (const uint8 *data, uint32 size)
return (FALSE);
}

static bool8 MsuRomExists (void)
{
struct stat buf;
return (stat(S9xGetFilename(".msu", ROMFILENAME_DIR), &buf) == 0);
}

int CMemory::ScoreHiROM (bool8 skip_header, int32 romoff)
{
uint8 *buf = ROM + 0xff00 + romoff + (skip_header ? 0x200 : 0);
@@ -1887,7 +1894,7 @@ bool8 CMemory::LoadMultiCartInt ()
memmove(ROM + Multi.cartOffsetA, ROM, Multi.cartSizeA + Multi.cartSizeB);
else if(Multi.cartOffsetB) // clear cart A so the bios can detect that it's not present
memset(ROM, 0, Multi.cartOffsetB);

FILE *fp;
size_t size;
char path[PATH_MAX + 1];
@@ -2364,6 +2371,7 @@ void CMemory::InitROM (void)
Settings.SETA = 0;
Settings.SRTC = FALSE;
Settings.BS = FALSE;
Settings.MSU1 = FALSE;

SuperFX.nRomBanks = CalculatedSize >> 15;

@@ -2538,6 +2546,9 @@ void CMemory::InitROM (void)
break;
}

// MSU1
Settings.MSU1 = MsuRomExists();

//// Map memory and calculate checksum

Map_Initialize();
@@ -3490,7 +3501,7 @@ const char * CMemory::KartContents (void)
static char str[64];
static const char *contents[3] = { "ROM", "ROM+RAM", "ROM+RAM+BAT" };

char chip[16];
char chip[20];

if (ROMType == 0 && !Settings.BS)
return ("ROM");
@@ -3536,6 +3547,9 @@ const char * CMemory::KartContents (void)
else
strcpy(chip, "");

if (Settings.MSU1)
sprintf(chip + strlen(chip), "+MSU-1");

sprintf(str, "%s%s", contents[(ROMType & 0xf) % 3], chip);

return (str);
Loading

0 comments on commit 27e6bc1

Please sign in to comment.