Mesen-S/Core/ScriptHost.cpp

72 lines
1.5 KiB
C++
Raw Permalink Normal View History

2019-05-12 21:18:05 -04:00
#include "stdafx.h"
#include "ScriptHost.h"
#include "ScriptingContext.h"
#include "EventType.h"
#ifndef LIBRETRO
#include "LuaScriptingContext.h"
#endif
ScriptHost::ScriptHost(int scriptId)
{
_scriptId = scriptId;
}
int ScriptHost::GetScriptId()
{
return _scriptId;
}
const char* ScriptHost::GetLog()
{
shared_ptr<ScriptingContext> context = _context;
return context ? context->GetLog() : "";
}
bool ScriptHost::LoadScript(string scriptName, string scriptContent, Debugger* debugger)
{
#ifndef LIBRETRO
_context.reset(new LuaScriptingContext(debugger));
if(!_context->LoadScript(scriptName, scriptContent, debugger)) {
return false;
}
return true;
#else
return false;
#endif
}
void ScriptHost::ProcessMemoryOperation(uint32_t addr, uint8_t &value, MemoryOperationType type, CpuType cpuType)
2019-05-12 21:18:05 -04:00
{
if(_context) {
switch(type) {
case MemoryOperationType::Read: _context->CallMemoryCallback(addr, value, CallbackType::CpuRead, cpuType); break;
case MemoryOperationType::Write: _context->CallMemoryCallback(addr, value, CallbackType::CpuWrite, cpuType); break;
case MemoryOperationType::ExecOpCode: _context->CallMemoryCallback(addr, value, CallbackType::CpuExec, cpuType); break;
2019-05-12 21:18:05 -04:00
default: break;
}
}
}
void ScriptHost::ProcessEvent(EventType eventType)
{
if(_context) {
_context->CallEventCallback(eventType);
}
}
bool ScriptHost::ProcessSavestate()
{
if(_context) {
return _context->ProcessSavestate();
}
return false;
}
bool ScriptHost::CheckStateLoadedFlag()
{
if(_context) {
return _context->CheckStateLoadedFlag();
}
return false;
}