2017-08-30 18:31:27 -04:00
|
|
|
#include "stdafx.h"
|
2017-08-30 19:36:20 -04:00
|
|
|
#include <algorithm>
|
2017-08-30 18:31:27 -04:00
|
|
|
#include "ScriptingContext.h"
|
|
|
|
#include "DebuggerTypes.h"
|
|
|
|
|
2017-09-28 21:27:38 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:36:20 -04:00
|
|
|
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());
|
|
|
|
}
|