2013-11-22 09:33:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using BizHawk.Common;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
|
|
|
|
{
|
|
|
|
|
unsafe partial class LibsnesApi
|
|
|
|
|
{
|
|
|
|
|
bool Handle_SIG(eMessage msg)
|
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
using (_exe.EnterExit())
|
2013-11-22 09:33:56 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
switch (msg)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
2017-03-06 09:21:10 +00:00
|
|
|
|
|
2017-06-10 17:43:03 +00:00
|
|
|
|
case eMessage.eMessage_SIG_video_refresh:
|
2013-11-22 09:33:56 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
int width = _comm->width;
|
|
|
|
|
int height = _comm->height;
|
|
|
|
|
video_refresh?.Invoke((int*)_comm->ptr, width, height);
|
|
|
|
|
break;
|
2013-11-22 09:33:56 +00:00
|
|
|
|
}
|
2017-06-10 17:43:03 +00:00
|
|
|
|
case eMessage.eMessage_SIG_input_poll:
|
2013-11-22 09:33:56 +00:00
|
|
|
|
break;
|
2017-06-10 17:43:03 +00:00
|
|
|
|
case eMessage.eMessage_SIG_input_state:
|
2013-11-22 09:33:56 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
int port = _comm->port;
|
|
|
|
|
int device = _comm->device;
|
|
|
|
|
int index = _comm->index;
|
|
|
|
|
int id = (int)_comm->id;
|
|
|
|
|
if (input_state != null)
|
|
|
|
|
_comm->value = (uint)input_state(port, device, index, id);
|
|
|
|
|
break;
|
2013-11-22 09:33:56 +00:00
|
|
|
|
}
|
2017-06-10 17:43:03 +00:00
|
|
|
|
case eMessage.eMessage_SIG_input_notify:
|
2013-11-22 09:33:56 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
input_notify?.Invoke(_comm->index);
|
|
|
|
|
break;
|
2013-11-22 09:33:56 +00:00
|
|
|
|
}
|
2017-06-10 17:43:03 +00:00
|
|
|
|
case eMessage.eMessage_SIG_audio_flush:
|
2013-11-22 09:33:56 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
uint nsamples = _comm->size;
|
|
|
|
|
|
|
|
|
|
if (audio_sample != null)
|
2013-11-22 09:33:56 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
ushort* audiobuffer = ((ushort*)_comm->ptr);
|
|
|
|
|
for (uint i = 0; i < nsamples;)
|
|
|
|
|
{
|
|
|
|
|
ushort left = audiobuffer[i++];
|
|
|
|
|
ushort right = audiobuffer[i++];
|
|
|
|
|
audio_sample(left, right);
|
|
|
|
|
}
|
2013-11-22 09:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-10 17:43:03 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case eMessage.eMessage_SIG_path_request:
|
2013-11-22 09:33:56 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
int slot = _comm->slot;
|
|
|
|
|
string hint = _comm->GetAscii();
|
|
|
|
|
string ret = hint;
|
|
|
|
|
if (pathRequest != null)
|
|
|
|
|
hint = pathRequest(slot, hint);
|
|
|
|
|
CopyAscii(0, hint);
|
|
|
|
|
break;
|
2013-11-22 09:33:56 +00:00
|
|
|
|
}
|
2017-06-10 17:43:03 +00:00
|
|
|
|
case eMessage.eMessage_SIG_trace_callback:
|
2017-03-06 09:21:10 +00:00
|
|
|
|
{
|
2017-06-10 17:43:03 +00:00
|
|
|
|
traceCallback?.Invoke(_comm->value, _comm->GetAscii());
|
|
|
|
|
break;
|
2017-03-06 09:21:10 +00:00
|
|
|
|
}
|
2017-06-10 17:43:03 +00:00
|
|
|
|
case eMessage.eMessage_SIG_allocSharedMemory:
|
|
|
|
|
{
|
|
|
|
|
// NB: shared memory blocks are allocated on the unmanaged side
|
|
|
|
|
var name = _comm->GetAscii();
|
|
|
|
|
var size = _comm->size;
|
|
|
|
|
var ptr = _comm->ptr;
|
|
|
|
|
|
|
|
|
|
if (_sharedMemoryBlocks.ContainsKey(name))
|
|
|
|
|
throw new InvalidOperationException("Re-defined a shared memory block. Check bsnes init/shutdown code. Block name: " + name);
|
|
|
|
|
|
|
|
|
|
_sharedMemoryBlocks.Add(name, (IntPtr)ptr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case eMessage.eMessage_SIG_freeSharedMemory:
|
|
|
|
|
throw new InvalidOperationException("Unexpected call: SIG_freeSharedMemory");
|
|
|
|
|
} //switch(msg)
|
2017-03-06 09:21:10 +00:00
|
|
|
|
|
2017-06-10 17:43:03 +00:00
|
|
|
|
_core.Message(eMessage.eMessage_Resume);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-11-22 09:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-10 17:43:03 +00:00
|
|
|
|
}
|