update libsnes building for new output directory, and add support for exec/read/write/nmi/irq hooks

This commit is contained in:
zeromus 2013-11-03 22:44:49 +00:00
parent ed5cfe39a6
commit 7a260abb54
8 changed files with 112 additions and 8 deletions

View File

@ -46,7 +46,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>true</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>

View File

@ -389,7 +389,18 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES
eMessage_SetBuffer, eMessage_SetBuffer,
eMessage_BeginBufferIO, eMessage_BeginBufferIO,
eMessage_EndBufferIO eMessage_EndBufferIO,
eMessage_set_state_hook_exec,
eMessage_set_state_hook_read,
eMessage_set_state_hook_write,
eMessage_set_state_hook_nmi,
eMessage_set_state_hook_irq,
eMessage_snes_cb_hook_exec,
eMessage_snes_cb_hook_read,
eMessage_snes_cb_hook_write,
eMessage_snes_cb_hook_nmi,
eMessage_snes_cb_hook_irq,
}; };
static bool DryRun(string exePath) static bool DryRun(string exePath)
@ -635,6 +646,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES
public void snes_term() { WritePipeMessage(eMessage.eMessage_snes_term); } public void snes_term() { WritePipeMessage(eMessage.eMessage_snes_term); }
public void snes_unload_cartridge() { WritePipeMessage(eMessage.eMessage_snes_unload_cartridge); } public void snes_unload_cartridge() { WritePipeMessage(eMessage.eMessage_snes_unload_cartridge); }
public void snes_set_state_hook_exec(bool state)
{
WritePipeMessage(eMessage.eMessage_set_state_hook_exec);
bwPipe.Write(state);
}
public bool snes_load_cartridge_super_game_boy(string rom_xml, byte[] rom_data, uint rom_size, string dmg_xml, byte[] dmg_data, uint dmg_size) public bool snes_load_cartridge_super_game_boy(string rom_xml, byte[] rom_data, uint rom_size, string dmg_xml, byte[] dmg_data, uint dmg_size)
{ {
WritePipeMessage(eMessage.eMessage_snes_load_cartridge_super_game_boy); WritePipeMessage(eMessage.eMessage_snes_load_cartridge_super_game_boy);
@ -932,6 +949,29 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES
SharedMemoryBlocks.Remove(name); SharedMemoryBlocks.Remove(name);
break; break;
} }
case eMessage.eMessage_snes_cb_hook_exec:
{
var addr = brPipe.ReadInt32();
//Console.WriteLine("received hook messages from libsnes\n");
//not sure how to shuttle these out of an emu core yet. do we have mechanisms for that?
break;
}
case eMessage.eMessage_snes_cb_hook_read:
{
var addr = brPipe.ReadInt32();
break;
}
case eMessage.eMessage_snes_cb_hook_write:
{
var addr = brPipe.ReadInt32();
var value = brPipe.ReadByte();
break;
}
case eMessage.eMessage_snes_cb_hook_nmi:
break;
case eMessage.eMessage_snes_cb_hook_irq:
break;
} }
} }
} //WaitForCompletion() } //WaitForCompletion()

View File

@ -259,6 +259,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES
CoreComm.CpuTraceAvailable = true; CoreComm.CpuTraceAvailable = true;
api.snes_power(); api.snes_power();
api.snes_set_state_hook_exec(true);
SetupMemoryDomains(romData,sgbRomData); SetupMemoryDomains(romData,sgbRomData);

View File

@ -15,10 +15,10 @@ if [ "$1" == "32" ]; then
fi fi
#debug: #debug:
#export BIZWINCFLAGS="-I. -O0 -g -masm=intel -DLIBCO_IMPORT -DLIBCO_MSVC -static-libgcc -static-libstdc++" #export BIZWINCFLAGS="-I. -O0 -g -masm=intel -DHOOKS -DLIBCO_IMPORT -DLIBCO_MSVC -static-libgcc -static-libstdc++"
#not debug #not debug
export BIZWINCFLAGS="-I. -O3 -masm=intel -static-libgcc -static-libstdc++ ${cflags64}" export BIZWINCFLAGS="-I. -O3 -masm=intel -DHOOKS -static-libgcc -static-libstdc++ ${cflags64}"
export TARGET_LIBSNES_LIBDEPS="-L ../libco_msvc_win32/release/ -static -static-libgcc -static-libstdc++ ${cflags64} ${cflags32} -mwindows" export TARGET_LIBSNES_LIBDEPS="-L ../libco_msvc_win32/release/ -static -static-libgcc -static-libstdc++ ${cflags64} ${cflags32} -mwindows"
export profile=$2 export profile=$2
@ -28,7 +28,7 @@ platform=win target=libsnes make -e -j 4
cd .. cd ..
filename=libsneshawk-${bits}-${profile}.exe filename=libsneshawk-${bits}-${profile}.exe
targetdir=../BizHawk.MultiClient/output/dll targetdir=../output/dll
targetpath=${targetdir}/${filename} targetpath=${targetdir}/${filename}
cp bsnes/out/${filename} ${targetdir} cp bsnes/out/${filename} ${targetdir}
if [ "$3" == "compress" ]; then if [ "$3" == "compress" ]; then

View File

@ -32,7 +32,7 @@ template<typename R, typename... P> struct hook<R (P...)> {
function<R (P...)> callback; function<R (P...)> callback;
R operator()(P... p) const { R operator()(P... p) const {
#if defined(DEBUGGER) #if defined(DEBUGGER) || defined(HOOKS)
if(callback) return callback(std::forward<P>(p)...); if(callback) return callback(std::forward<P>(p)...);
#endif #endif
return R(); return R();

View File

@ -135,6 +135,7 @@ privileged:
static void Enter(); static void Enter();
void op_step(); void op_step();
public:
struct Debugger { struct Debugger {
hook<void (uint24)> op_exec; hook<void (uint24)> op_exec;
hook<void (uint24)> op_read; hook<void (uint24)> op_read;

View File

@ -169,7 +169,7 @@ HANDLE hPipe, hMapFile;
void* hMapFilePtr; void* hMapFilePtr;
static bool running = false; static bool running = false;
enum eMessage : int enum eMessage : int32
{ {
eMessage_Complete, eMessage_Complete,
@ -228,7 +228,18 @@ enum eMessage : int
eMessage_SetBuffer, eMessage_SetBuffer,
eMessage_BeginBufferIO, eMessage_BeginBufferIO,
eMessage_EndBufferIO eMessage_EndBufferIO,
eMessage_set_state_hook_exec,
eMessage_set_state_hook_read,
eMessage_set_state_hook_write,
eMessage_set_state_hook_nmi,
eMessage_set_state_hook_irq,
eMessage_snes_cb_hook_exec,
eMessage_snes_cb_hook_read,
eMessage_snes_cb_hook_write,
eMessage_snes_cb_hook_nmi,
eMessage_snes_cb_hook_irq,
}; };
void ReadPipeBuffer(void* buf, int len) void ReadPipeBuffer(void* buf, int len)
@ -474,6 +485,36 @@ void InitBsnes()
snes_set_freeSharedMemory(snes_freeSharedMemory); snes_set_freeSharedMemory(snes_freeSharedMemory);
} }
static void debug_op_exec(uint24 addr)
{
WritePipe(eMessage_snes_cb_hook_exec);
WritePipe((uint32)addr);
}
static void debug_op_read(uint24 addr)
{
WritePipe(eMessage_snes_cb_hook_read);
WritePipe((uint32)addr);
}
static void debug_op_write(uint24 addr, uint8 value)
{
WritePipe(eMessage_snes_cb_hook_write);
WritePipe((uint32)addr);
WritePipe(value);
}
static void debug_op_nmi()
{
WritePipe(eMessage_snes_cb_hook_nmi);
}
static void debug_op_irq()
{
WritePipe(eMessage_snes_cb_hook_irq);
}
void RunMessageLoop() void RunMessageLoop()
{ {
for(;;) for(;;)
@ -689,6 +730,26 @@ void RunMessageLoop()
bufio = false; bufio = false;
break; break;
case eMessage_set_state_hook_exec:
SNES::cpu.debugger.op_exec = ReadPipe<bool>() ? debug_op_exec : hook<void (uint24)>();
break;
case eMessage_set_state_hook_read:
SNES::cpu.debugger.op_read = ReadPipe<bool>() ? debug_op_read : hook<void (uint24)>();
break;
case eMessage_set_state_hook_write:
SNES::cpu.debugger.op_write = ReadPipe<bool>() ? debug_op_write : hook<void (uint24, uint8)>();
break;
case eMessage_set_state_hook_nmi:
SNES::cpu.debugger.op_nmi = ReadPipe<bool>() ? debug_op_nmi : hook<void ()>();
break;
case eMessage_set_state_hook_irq:
SNES::cpu.debugger.op_irq = ReadPipe<bool>() ? debug_op_irq : hook<void ()>();
break;
} //switch(msg) } //switch(msg)
} }
} }
@ -764,5 +825,6 @@ int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine
void pwrap_init() void pwrap_init()
{ {
//bsnes's interface initialization calls into this after initializing itself, so we can get a chance to mod it for pwrap functionalities
InitBsnes(); InitBsnes();
} }