diff --git a/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs b/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs
index 9c73e83766..ae7168156b 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs
@@ -63,5 +63,19 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA
/// length of data in bytes
[DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libmeteor_loadbios(byte[] data, uint datalen);
+
+ ///
+ /// core callback to print meaningful (or meaningless) log messages
+ ///
+ /// message to be printed
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate void MessageCallback(string msg);
+
+ ///
+ /// set callback for log messages. this can (and should) be called first
+ ///
+ ///
+ [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void libmeteor_setmessagecallback(MessageCallback cb);
}
}
diff --git a/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs b/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs
index a0f3da4b41..fc5cfef4ac 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs
@@ -125,22 +125,26 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA
}
static GBA attachedcore;
+ LibMeteor.MessageCallback messagecallback;
void Init()
{
if (attachedcore != null)
attachedcore.Dispose();
+ messagecallback = (str) => Console.Write(str.Replace("\n","\r\n"));
+ LibMeteor.libmeteor_setmessagecallback(messagecallback);
+
LibMeteor.libmeteor_init();
videobuffer = new int[240 * 160];
videohandle = GCHandle.Alloc(videobuffer, GCHandleType.Pinned);
- soundbuffer = new short[2048];
+ soundbuffer = new short[2048]; // nominal length of one frame is something like 1480 shorts?
soundhandle = GCHandle.Alloc(soundbuffer, GCHandleType.Pinned);
if (!LibMeteor.libmeteor_setbuffers
(videohandle.AddrOfPinnedObject(), (uint)(sizeof(int) * videobuffer.Length),
soundhandle.AddrOfPinnedObject(), (uint)(sizeof(short) * soundbuffer.Length)))
- throw new Exception("libmeteor_setbuffers() returned false!");
+ throw new Exception("libmeteor_setbuffers() returned false??");
attachedcore = this;
}
diff --git a/BizHawk.MultiClient/output/dll/libmeteor.dll b/BizHawk.MultiClient/output/dll/libmeteor.dll
index 54d5a771fe..bb3bdf477d 100644
Binary files a/BizHawk.MultiClient/output/dll/libmeteor.dll and b/BizHawk.MultiClient/output/dll/libmeteor.dll differ
diff --git a/libmeteor/cinterface.cpp b/libmeteor/cinterface.cpp
index 530f3352ae..ff8957f675 100644
--- a/libmeteor/cinterface.cpp
+++ b/libmeteor/cinterface.cpp
@@ -1,8 +1,28 @@
#include "ameteor.hpp"
#include "ameteor/cartmem.hpp"
+#include "source/debug.hpp"
#define EXPORT extern "C" __declspec(dllexport)
+void (*messagecallback)(const char *msg) = NULL;
+
+EXPORT void libmeteor_setmessagecallback(void (*callback)(const char *msg))
+{
+ messagecallback = callback;
+ print_bizhawk("libmeteor message stream operational.");
+}
+
+void print_bizhawk(const char *msg)
+{
+ if (messagecallback)
+ messagecallback(msg);
+}
+void print_bizhawk(std::string &msg)
+{
+ if (messagecallback)
+ messagecallback(msg.c_str());
+}
+
EXPORT void libmeteor_reset()
{
AMeteor::Reset(AMeteor::UNIT_ALL ^ AMeteor::UNIT_MEMORY_BIOS);
@@ -56,7 +76,7 @@ EXPORT int libmeteor_setbuffers(uint32_t *vid, unsigned vidlen, int16_t *aud, un
return 0;
videobuff = vid;
soundbuff = aud;
- soundbuffend = soundbuff + audlen;
+ soundbuffend = soundbuff + audlen / sizeof(int16_t);
libmeteor_emptysound();
return 1;
}
diff --git a/libmeteor/libmeteor.vcxproj b/libmeteor/libmeteor.vcxproj
index 63084fdf02..af4244960e 100644
--- a/libmeteor/libmeteor.vcxproj
+++ b/libmeteor/libmeteor.vcxproj
@@ -51,7 +51,8 @@
Level3
Disabled
- WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions);METDEBUG
+ WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions);METDEBUG;METDEBUGLOG
+ 4800;4396
Windows
@@ -67,6 +68,7 @@
true
true
WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions)
+ 4800;4396
Windows
diff --git a/libmeteor/source/debug.hpp b/libmeteor/source/debug.hpp
index 350cacd45c..3e77a7e181 100644
--- a/libmeteor/source/debug.hpp
+++ b/libmeteor/source/debug.hpp
@@ -25,6 +25,10 @@
// for abort macro
#include "ameteor.hpp"
+// from cinterface.cpp
+void print_bizhawk(const char *msg);
+void print_bizhawk(std::string &msg);
+
#if 0
#define met_abort(str) \
{ \
@@ -38,7 +42,7 @@
#endif
#ifdef METDEBUG
#include
-extern "C" int __stdcall MessageBoxA(int, const char *, const char *, int);
+//extern "C" int __stdcall MessageBoxA(int, const char *, const char *, int);
#define met_abort(_str) if(true)\
{ \
std::stringstream _zisrny; \
@@ -47,7 +51,7 @@ extern "C" int __stdcall MessageBoxA(int, const char *, const char *, int);
<< IOS_ADD << ::AMeteor::_cpu.Reg(15) << "\n[r15] = " << IOS_ADD \
<< ::AMeteor::_memory.Read32(::AMeteor::_cpu.Reg(15)) \
<< "\nFlag T : " << ::AMeteor::_cpu.ICpsr().thumb << std::endl; \
- MessageBoxA(NULL, _zisrny.str().c_str(), "FUCK!", 0); \
+ print_bizhawk(_zisrny.str().c_str()); \
}
#else
@@ -60,13 +64,18 @@ extern "C" int __stdcall MessageBoxA(int, const char *, const char *, int);
#if defined METDEBUG && defined METDEBUGLOG
//XXX
# define MYDEBUG
-# define debug(str) \
- STDBG << str << std::endl
-# define debug_(str) \
- STDBG << str
+# define debug(_str) \
+ { \
+ std::stringstream _zisrny; \
+ _zisrny << _str << std::endl; \
+ print_bizhawk(_zisrny.str()); \
+ }
+ //STDBG << str << std::endl
+//# define debug_(str) \
+// STDBG << str
#else
# define debug(s) {}
-# define debug_(s) {}
+//# define debug_(s) {}
#endif
#define IOS_ADD \