gba: add some console debugging stuff

This commit is contained in:
goyuken 2012-11-20 01:28:31 +00:00
parent 3e496ae069
commit 8a4393cd56
6 changed files with 60 additions and 11 deletions

View File

@ -63,5 +63,19 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA
/// <param name="datalen">length of data in bytes</param>
[DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libmeteor_loadbios(byte[] data, uint datalen);
/// <summary>
/// core callback to print meaningful (or meaningless) log messages
/// </summary>
/// <param name="msg">message to be printed</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void MessageCallback(string msg);
/// <summary>
/// set callback for log messages. this can (and should) be called first
/// </summary>
/// <param name="cb"></param>
[DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libmeteor_setmessagecallback(MessageCallback cb);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -51,7 +51,8 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions);METDEBUG</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions);METDEBUG;METDEBUGLOG</PreprocessorDefinitions>
<DisableSpecificWarnings>4800;4396</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -67,6 +68,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4800;4396</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>

View File

@ -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 <sstream>
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 \