Mesen-X/Core/ScriptHost.cpp

83 lines
1.8 KiB
C++
Raw Normal View History

2017-08-30 18:31:27 -04:00
#include "stdafx.h"
#include "ScriptHost.h"
#include "ScriptingContext.h"
2018-01-05 15:37:49 -05:00
#ifndef LIBRETRO
2017-08-30 18:31:27 -04:00
#include "LuaScriptingContext.h"
2018-01-05 15:37:49 -05:00
#endif
2017-08-30 18:31:27 -04:00
ScriptHost::ScriptHost(int scriptId)
{
_scriptId = scriptId;
}
int ScriptHost::GetScriptId()
{
return _scriptId;
}
const char* ScriptHost::GetLog()
{
shared_ptr<ScriptingContext> context = _context;
return context ? context->GetLog() : "";
2017-08-30 18:31:27 -04:00
}
bool ScriptHost::LoadScript(string scriptName, string scriptContent, Debugger* debugger)
2017-08-30 18:31:27 -04:00
{
2018-01-05 15:37:49 -05:00
#ifndef LIBRETRO
_context.reset(new LuaScriptingContext(debugger));
if(!_context->LoadScript(scriptName, scriptContent, debugger)) {
return false;
2017-08-30 18:31:27 -04:00
}
return true;
2018-01-05 15:37:49 -05:00
#else
return false;
#endif
2017-08-30 18:31:27 -04:00
}
void ScriptHost::ProcessCpuOperation(uint16_t addr, uint8_t &value, MemoryOperationType type)
2017-08-30 18:31:27 -04:00
{
if(_context) {
switch(type) {
case MemoryOperationType::Read: _context->CallMemoryCallback(addr, value, CallbackType::CpuRead); break;
case MemoryOperationType::Write: _context->CallMemoryCallback(addr, value, CallbackType::CpuWrite); break;
case MemoryOperationType::ExecOpCode: _context->CallMemoryCallback(addr, value, CallbackType::CpuExec); break;
default: break;
2017-08-30 18:31:27 -04:00
}
}
}
void ScriptHost::ProcessPpuOperation(uint16_t addr, uint8_t &value, MemoryOperationType type)
2017-08-30 18:31:27 -04:00
{
if(_context) {
switch(type) {
case MemoryOperationType::Read: _context->CallMemoryCallback(addr, value, CallbackType::PpuRead); break;
case MemoryOperationType::Write: _context->CallMemoryCallback(addr, value, CallbackType::PpuWrite); break;
default: break;
2017-08-30 18:31:27 -04:00
}
}
}
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;
}