Mesen-X/Core/ScriptingContext.cpp

91 lines
2 KiB
C++
Raw Normal View History

2017-08-30 18:31:27 -04:00
#include "stdafx.h"
#include <algorithm>
2017-08-30 18:31:27 -04:00
#include "ScriptingContext.h"
#include "DebuggerTypes.h"
string ScriptingContext::_log = "";
2017-08-30 18:31:27 -04:00
void ScriptingContext::Log(string message)
{
auto lock = _logLock.AcquireSafe();
_logRows.push_back(message);
if(_logRows.size() > 500) {
_logRows.pop_front();
}
}
const char* ScriptingContext::GetLog()
{
auto lock = _logLock.AcquireSafe();
stringstream ss;
for(string &msg : _logRows) {
ss << msg << "\n";
}
_log = ss.str();
return _log.c_str();
}
int ScriptingContext::CallEventCallback(EventType type)
{
_inStartFrameEvent = type == EventType::StartFrame;
int returnValue = InternalCallEventCallback(type);
_inStartFrameEvent = false;
return returnValue;
}
bool ScriptingContext::CheckInStartFrameEvent()
{
return _inStartFrameEvent;
}
void ScriptingContext::RegisterMemoryCallback(CallbackType type, int startAddr, int endAddr, int reference)
{
if(endAddr < startAddr) {
return;
}
if(startAddr == 0 && endAddr == 0) {
if(type <= CallbackType::CpuExec) {
endAddr = 0xFFFF;
} else {
endAddr = 0x3FFF;
}
}
for(int i = startAddr; i < endAddr; i++) {
_callbacks[(int)type][i].push_back(reference);
}
}
void ScriptingContext::UnregisterMemoryCallback(CallbackType type, int startAddr, int endAddr, int reference)
{
if(endAddr < startAddr) {
return;
}
if(startAddr == 0 && endAddr == 0) {
if(type <= CallbackType::CpuExec) {
endAddr = 0xFFFF;
} else {
endAddr = 0x3FFF;
}
}
for(int i = startAddr; i < endAddr; i++) {
2017-08-30 18:31:27 -04:00
vector<int> &refs = _callbacks[(int)type][i];
refs.erase(std::remove(refs.begin(), refs.end(), reference), refs.end());
}
}
void ScriptingContext::RegisterEventCallback(EventType type, int reference)
{
_eventCallbacks[(int)type].push_back(reference);
}
void ScriptingContext::UnregisterEventCallback(EventType type, int reference)
{
vector<int> &callbacks = _eventCallbacks[(int)type];
callbacks.erase(std::remove(callbacks.begin(), callbacks.end(), reference), callbacks.end());
}