diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs index f0af983992..ef1082f3bd 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs @@ -21,6 +21,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public abstract void CopyBuffer(int id, void* ptr, int size); [BizImport(CallingConvention.Cdecl, Compatibility = true)] public abstract void SetBuffer(int id, void* ptr, int size); + [BizImport(CallingConvention.Cdecl)] + public abstract void PostLoadState(); } public unsafe partial class LibsnesApi : IDisposable, IMonitor, IBinaryStateable @@ -57,7 +59,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES Filename = "libsnes.wbx", Path = dllPath, SbrkHeapSizeKB = 4 * 1024, - InvisibleHeapSizeKB = 1024, + InvisibleHeapSizeKB = 2048, MmapHeapSizeKB = 32 * 1024, // TODO: see if we can safely make libco stacks smaller PlainHeapSizeKB = 2 * 1024, // TODO: wasn't there more in here? SealedHeapSizeKB = 128 * 1024 @@ -374,6 +376,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public void LoadStateBinary(BinaryReader reader) { _exe.LoadStateBinary(reader); + _core.PostLoadState(); } } } diff --git a/output64/dll/libsnes.wbx.gz b/output64/dll/libsnes.wbx.gz index a8d07501e6..60aa0bb5e1 100644 Binary files a/output64/dll/libsnes.wbx.gz and b/output64/dll/libsnes.wbx.gz differ diff --git a/waterbox/libsnes/bsnes/snes/alt/ppu-compatibility/render/cache.cpp b/waterbox/libsnes/bsnes/snes/alt/ppu-compatibility/render/cache.cpp index 189e55a7ed..551af9104c 100644 --- a/waterbox/libsnes/bsnes/snes/alt/ppu-compatibility/render/cache.cpp +++ b/waterbox/libsnes/bsnes/snes/alt/ppu-compatibility/render/cache.cpp @@ -127,12 +127,12 @@ void PPU::flush_pixel_cache() { } void PPU::alloc_tiledata_cache() { - bg_tiledata[TILE_2BIT] = new uint8_t[262144](); - bg_tiledata[TILE_4BIT] = new uint8_t[131072](); - bg_tiledata[TILE_8BIT] = new uint8_t[ 65536](); - bg_tiledata_state[TILE_2BIT] = new uint8_t[ 4096](); - bg_tiledata_state[TILE_4BIT] = new uint8_t[ 2048](); - bg_tiledata_state[TILE_8BIT] = new uint8_t[ 1024](); + bg_tiledata[TILE_2BIT] = (uint8_t*)alloc_invisible(262144); + bg_tiledata[TILE_4BIT] = (uint8_t*)alloc_invisible(131072); + bg_tiledata[TILE_8BIT] = (uint8_t*)alloc_invisible( 65536); + bg_tiledata_state[TILE_2BIT] = (uint8_t*)alloc_invisible( 4096); + bg_tiledata_state[TILE_4BIT] = (uint8_t*)alloc_invisible( 2048); + bg_tiledata_state[TILE_8BIT] = (uint8_t*)alloc_invisible( 1024); } //marks all tiledata cache entries as dirty @@ -143,12 +143,7 @@ void PPU::flush_tiledata_cache() { } void PPU::free_tiledata_cache() { - delete[] bg_tiledata[TILE_2BIT]; - delete[] bg_tiledata[TILE_4BIT]; - delete[] bg_tiledata[TILE_8BIT]; - delete[] bg_tiledata_state[TILE_2BIT]; - delete[] bg_tiledata_state[TILE_4BIT]; - delete[] bg_tiledata_state[TILE_8BIT]; + abort(); } #endif diff --git a/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.cpp b/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.cpp index 7d0fe80315..c0942b2f8f 100644 --- a/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.cpp +++ b/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.cpp @@ -112,22 +112,23 @@ uint8* PPU::Cache::tile(unsigned bpp, unsigned tile) { } PPU::Cache::Cache(PPU &self) : self(self) { - tiledata[0] = new uint8[262144](); - tiledata[1] = new uint8[131072](); - tiledata[2] = new uint8[ 65536](); - tilevalid[0] = new uint8[ 4096](); - tilevalid[1] = new uint8[ 2048](); - tilevalid[2] = new uint8[ 1024](); + tiledata[0] = (uint8*)alloc_invisible(262144); + tiledata[1] = (uint8*)alloc_invisible(131072); + tiledata[2] = (uint8*)alloc_invisible(65536); + tilevalid[0] = (uint8*)alloc_invisible(4096); + tilevalid[1] = (uint8*)alloc_invisible(2048); + tilevalid[2] = (uint8*)alloc_invisible(1024); +} + +PPU::Cache::invalidate() { + memset(tilevalid[0], 0, 4096); + memset(tilevalid[1], 0, 2048); + memset(tilevalid[2], 0, 1024); } PPU::Cache::~Cache() { - delete[] tiledata[0]; - delete[] tiledata[1]; - delete[] tiledata[2]; - delete[] tilevalid[0]; - delete[] tilevalid[1]; - delete[] tilevalid[2]; + abort(); } #endif diff --git a/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.hpp b/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.hpp index 58ba60550a..ec4b2a543e 100644 --- a/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.hpp +++ b/waterbox/libsnes/bsnes/snes/alt/ppu-performance/cache/cache.hpp @@ -7,6 +7,7 @@ public: uint8* tile_4bpp(unsigned tile); uint8* tile_8bpp(unsigned tile); uint8* tile(unsigned bpp, unsigned tile); + void invalidate(); Cache(PPU &self); ~Cache(); diff --git a/waterbox/libsnes/bsnes/target-libsnes/libsnes.cpp b/waterbox/libsnes/bsnes/target-libsnes/libsnes.cpp index 19e2399a40..c5f8e53bdb 100644 --- a/waterbox/libsnes/bsnes/target-libsnes/libsnes.cpp +++ b/waterbox/libsnes/bsnes/target-libsnes/libsnes.cpp @@ -214,9 +214,9 @@ void snes_set_cartridge_basename(const char *basename) { } template inline void reconstruct(T* t) { - t->~T(); + /*t->~T(); memset(t,0,sizeof(*t)); - new(t) T(); + new(t) T();*/ } void snes_init(void) { diff --git a/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp b/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp index fd0c994408..23dcd80196 100644 --- a/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp +++ b/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp @@ -659,6 +659,11 @@ EXPORT void SetBuffer(int id, void* ptr, int32 size) comm.SetBuffer(id, ptr, size); } +EXPORT void PostLoadState() +{ + SNES::ppu.flush_tiledata_cache(); +} + int main() { return 0;