diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index 0b33c67c0d..e1d02becd8 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -32,6 +32,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES public static extern void snes_run(); [DllImport("snes.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void snes_term(); + [DllImport("snes.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern void snes_unload_cartridge(); [DllImport("snes.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void snes_load_cartridge_normal( @@ -190,6 +192,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_set_input_state(null); BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_set_audio_sample(null); + LibsnesDll.snes_unload_cartridge(); LibsnesDll.snes_term(); resampler.Dispose(); @@ -232,6 +235,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES } LibsnesDll.snes_load_cartridge_normal(null, romData, romData.Length); + LibsnesDll.snes_power(); + SetupMemoryDomains(romData); } diff --git a/BizHawk.MultiClient/output/snes.dll b/BizHawk.MultiClient/output/snes.dll index f27dfd8887..f1d5784e4d 100644 Binary files a/BizHawk.MultiClient/output/snes.dll and b/BizHawk.MultiClient/output/snes.dll differ diff --git a/libsnes/bsnes/target-libsnes/libsnes.cpp b/libsnes/bsnes/target-libsnes/libsnes.cpp index 321db10afd..b5eac3cb92 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.cpp +++ b/libsnes/bsnes/target-libsnes/libsnes.cpp @@ -126,32 +126,34 @@ void snes_set_cartridge_basename(const char *basename) { interface.basename = basename; } -#include -static jmp_buf buf; - -void second(void) { - printf("second\n"); // prints - longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 -} - -void first(void) { - second(); - printf("first\n"); // does not print -} - -void test() { - if ( ! setjmp(buf) ) { - first(); // when executed, setjmp returns 0 - } else { // when longjmp jumps back, setjmp returns 1 - printf("main\n"); // prints - } - - +template inline void reconstruct(T* t) { + t->~T(); + new(t) T(); } void snes_init(void) { - test(); SNES::interface = &interface; + + //because we're tasers and we didnt make this core, and we're paranoid, lets reconstruct everything so we know subsequent runs are as similar as possible + reconstruct(&SNES::icd2); + reconstruct(&SNES::nss); + reconstruct(&SNES::superfx); + reconstruct(&SNES::sa1); + reconstruct(&SNES::necdsp); + reconstruct(&SNES::hitachidsp); + reconstruct(&SNES::armdsp); + reconstruct(&SNES::bsxsatellaview); + reconstruct(&SNES::bsxcartridge); + reconstruct(&SNES::bsxflash); + reconstruct(&SNES::srtc); + reconstruct(&SNES::sdd1); + reconstruct(&SNES::spc7110); + reconstruct(&SNES::obc1); + reconstruct(&SNES::msu1); + reconstruct(&SNES::link); + reconstruct(&SNES::video); + reconstruct(&SNES::audio); + SNES::system.init(); SNES::input.connect(SNES::Controller::Port1, SNES::Input::Device::Joypad); SNES::input.connect(SNES::Controller::Port2, SNES::Input::Device::Joypad);