diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index 9e95886f11..4b4db8c673 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -112,6 +112,23 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool snes_unserialize(IntPtr data, int size); + [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern int snes_poll_message(); + + [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern void snes_dequeue_message(IntPtr strBuffer); + + public static bool HasMessage { get { return snes_poll_message() != -1; } } + + public static string DequeueMessage() + { + int len = snes_poll_message(); + sbyte* temp = stackalloc sbyte[len + 1]; + temp[len] = 0; + snes_dequeue_message(new IntPtr(temp)); + return new string(temp); + } + [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void snes_set_layer_enable(int layer, int priority, [MarshalAs(UnmanagedType.U1)] @@ -482,6 +499,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES timeFrameCounter++; LibsnesDll.snes_run(); + while (LibsnesDll.HasMessage) + Console.WriteLine(LibsnesDll.DequeueMessage()); + if (IsLagFrame) LagCount++; } diff --git a/BizHawk.MultiClient/output/libsneshawk.dll b/BizHawk.MultiClient/output/libsneshawk.dll index f240de6be4..4e2e05522d 100644 Binary files a/BizHawk.MultiClient/output/libsneshawk.dll and b/BizHawk.MultiClient/output/libsneshawk.dll differ diff --git a/libsnes/bizwinclean.sh b/libsnes/bizwinclean.sh index 5589cfad58..15fb9eb7f6 100644 --- a/libsnes/bizwinclean.sh +++ b/libsnes/bizwinclean.sh @@ -1 +1,2 @@ -rm bsnes/obj/*.o \ No newline at end of file +rm -r bsnes/obj +rm -r bsnes/out \ No newline at end of file diff --git a/libsnes/bizwinmake.sh b/libsnes/bizwinmake.sh index c97ae476d7..3a81fd0706 100644 --- a/libsnes/bizwinmake.sh +++ b/libsnes/bizwinmake.sh @@ -1,6 +1,8 @@ cd bsnes +mkdir obj +mkdir out export BIZWINCFLAGS="-I. -O3 -masm=intel -DLIBCO_IMPORT -DLIBCO_MSVC -static-libgcc -static-libstdc++" export TARGET_LIBSNES_LIBDEPS="-L ../libco_msvc_win32/release/ -llibco_msvc_win32 -static-libgcc -static-libstdc++" -profile=compatibility platform=win target=libsnes make -e -j +profile=compatibility platform=win target=libsnes make -e cd .. cp bsnes/out/snes.dll ../BizHawk.MultiClient/output/libsneshawk.dll \ No newline at end of file diff --git a/libsnes/bsnes/target-libsnes/libsnes.cpp b/libsnes/bsnes/target-libsnes/libsnes.cpp index bffa5be468..b4e6b6fb7e 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.cpp +++ b/libsnes/bsnes/target-libsnes/libsnes.cpp @@ -3,6 +3,9 @@ #include #include + +#include + using namespace nall; struct Interface : public SNES::Interface { @@ -18,6 +21,9 @@ struct Interface : public SNES::Interface { //zero 11-sep-2012 time_t randomSeed() { return 0; } + //zero 26-sep-2012 + std::queue messages; + void videoRefresh(const uint32_t *data, bool hires, bool interlace, bool overscan) { unsigned width = hires ? 512 : 256; unsigned height = overscan ? 239 : 224; @@ -58,7 +64,7 @@ struct Interface : public SNES::Interface { } void message(const string &text) { - print(text, "\n"); + messages.push(text); } string path(SNES::Cartridge::Slot slot, const string &hint) { @@ -510,3 +516,14 @@ unsigned snes_get_memory_size(unsigned id) { return size; } +int snes_poll_message() +{ + if(interface.messages.size() == 0) return -1; + return interface.messages.front().length(); +} +void snes_dequeue_message(char* buffer) +{ + int len = interface.messages.front().length(); + memcpy(buffer,(const char*)interface.messages.front(),len); + interface.messages.pop(); +} \ No newline at end of file diff --git a/libsnes/bsnes/target-libsnes/libsnes.hpp b/libsnes/bsnes/target-libsnes/libsnes.hpp index a1357179aa..d2d70b54c0 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.hpp +++ b/libsnes/bsnes/target-libsnes/libsnes.hpp @@ -135,6 +135,10 @@ bool snes_check_cartridge(const uint8_t *rom_data, unsigned rom_size); void snes_set_layer_enable(int layer, int priority, bool enable); typedef void (*snes_scanlineStart_t)(int); void snes_set_scanlineStart(snes_scanlineStart_t); +//returns -1 if no messages, messagelength if there is one +int snes_poll_message(); +//give us a buffer of messagelength and we'll dequeue a message into it. you better take care of the null pointer +void snes_dequeue_message(char* buffer); //$2105 #define SNES_REG_BG_MODE 0