From b737959d1181c0fa4077a3629fddbd7c8aaaa565 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Sat, 27 May 2017 14:32:12 -0400 Subject: [PATCH] snes9xHawk which is totally not a thing: connect audio --- .../Consoles/Nintendo/SNES9X/LibSnes9x.cs | 12 ++-- .../Consoles/Nintendo/SNES9X/Snes9x.cs | 57 ++++++++++++------- BizHawk.Emulation.Cores/Waterbox/Heap.cs | 2 +- waterbox/readme.txt | 2 +- waterbox/snes9x | 2 +- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/LibSnes9x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/LibSnes9x.cs index 26470559f0..303c5001a5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/LibSnes9x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/LibSnes9x.cs @@ -19,10 +19,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X [StructLayout(LayoutKind.Sequential)] public class frame_info { - public IntPtr ptr; - public int pitch; - public int width; - public int height; + public IntPtr vptr; + public int vpitch; + public int vwidth; + public int vheight; + public IntPtr sptr; + public int slen; }; @@ -44,7 +46,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X public abstract void biz_run([In, Out] frame_info frame); [BizImport(CC)] public abstract bool biz_is_ntsc(); - [BizImport(CC, Compatibility = true)] + [BizImport(CC)] public abstract void biz_get_memory_area(int which, [In, Out] memory_area mem); } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs index c9b7f7652c..4c9ca9ac13 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs @@ -2,6 +2,7 @@ using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Waterbox; using BizHawk.Common.BizInvoke; +using System.Runtime.InteropServices; namespace BizHawk.Emulation.Cores.Nintendo.SNES9X { @@ -12,7 +13,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X private LibSnes9x _core; private PeRunner _exe; - [CoreConstructor("SNES")] public Snes9x(CoreComm comm, byte[] rom) { @@ -23,10 +23,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X { Path = comm.CoreFileProvider.DllPath(), Filename = "snes9x.exe", - NormalHeapSizeKB = 32 * 1024, - SealedHeapSizeKB = 32 * 1024, - InvisibleHeapSizeKB = 32 * 1024, - SpecialHeapSizeKB = 1024 + NormalHeapSizeKB = 1024, + SealedHeapSizeKB = 12 * 1024, + InvisibleHeapSizeKB = 6 * 1024, + SpecialHeapSizeKB = 64 }); try @@ -40,6 +40,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X { throw new InvalidOperationException("LoadRom() failed"); } + + if (_core.biz_is_ntsc()) + { + Console.WriteLine("NTSC rom loaded"); + VsyncNumerator = 21477272; + VsyncDenominator = 357366; + } + else + { + Console.WriteLine("PAL rom loaded"); + VsyncNumerator = 21281370; + VsyncDenominator = 425568; + } } catch { @@ -78,6 +91,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X _core.biz_run(frame); Blit(frame); + Sblit(frame); } public int Frame { get; private set; } @@ -95,19 +109,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X private unsafe void Blit(LibSnes9x.frame_info frame) { - BufferWidth = frame.width; - BufferHeight = frame.height; + BufferWidth = frame.vwidth; + BufferHeight = frame.vheight; - int vinc = frame.pitch / sizeof(ushort) - frame.width; + int vinc = frame.vpitch / sizeof(ushort) - frame.vwidth; - ushort* src = (ushort*)frame.ptr; + ushort* src = (ushort*)frame.vptr; fixed (int* _dst = _vbuff) { byte* dst = (byte*)_dst; - for (int j = 0; j < frame.height; j++) + for (int j = 0; j < frame.vheight; j++) { - for (int i = 0; i < frame.width; i++) + for (int i = 0; i < frame.vwidth; i++) { var c = *src++; @@ -132,32 +146,31 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X public int VsyncNumerator { - [FeatureNotImplemented] - get - { - return NullVideo.DefaultVsyncNum; - } + get; } public int VsyncDenominator { - [FeatureNotImplemented] - get - { - return NullVideo.DefaultVsyncDen; - } + get; } #endregion #region ISoundProvider + private void Sblit(LibSnes9x.frame_info frame) + { + Marshal.Copy(frame.sptr, _sbuff, 0, frame.slen * 2); + _nsamp = frame.slen; + } + + private int _nsamp; private short[] _sbuff = new short[2048]; public void GetSamplesSync(out short[] samples, out int nsamp) { samples = _sbuff; - nsamp = 735; + nsamp = _nsamp; } public void DiscardSamples() diff --git a/BizHawk.Emulation.Cores/Waterbox/Heap.cs b/BizHawk.Emulation.Cores/Waterbox/Heap.cs index f62cd778e1..af89729544 100644 --- a/BizHawk.Emulation.Cores/Waterbox/Heap.cs +++ b/BizHawk.Emulation.Cores/Waterbox/Heap.cs @@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Cores.Waterbox ulong ret = Memory.Start + Used; Memory.Protect(ret, newused - Used, MemoryBlock.Protection.RW); Used = newused; - Console.WriteLine("Allocated {0} bytes on {1}", size, Name); + Console.WriteLine($"Allocated {size} bytes on {Name}, utilization {Used}/{Memory.Size} ({100.0 * Used / Memory.Size:0.#}%)"); return ret; } diff --git a/waterbox/readme.txt b/waterbox/readme.txt index 339bfb5853..caddbd4343 100644 --- a/waterbox/readme.txt +++ b/waterbox/readme.txt @@ -4,7 +4,7 @@ libc.so, libgcc_s.so, libstdc++.so.6, and the waterbox executables are built wit The makefiles for the cores only support the cross compilation setup (build from whatever linux box you built midipix from). -The mmglue portion of the midipix project is modified; get the correct version from . +The mmglue portion of the midipix project is modified; get the correct version from . gpgx: This is a modified version of our gpgx core snes9x: Based off of snes9x 1.54. diff --git a/waterbox/snes9x b/waterbox/snes9x index 33c4a7ce37..ba009bc839 160000 --- a/waterbox/snes9x +++ b/waterbox/snes9x @@ -1 +1 @@ -Subproject commit 33c4a7ce3760cad10f2ed132d73d8197fc845061 +Subproject commit ba009bc83960ee39f9eb24ae1724a67d9b87f51e