2017-08-30 18:31:27 -04:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <deque>
|
|
|
|
#include "../Utilities/SimpleLock.h"
|
|
|
|
#include "DebuggerTypes.h"
|
|
|
|
|
|
|
|
class Debugger;
|
|
|
|
|
|
|
|
enum class CallbackType
|
|
|
|
{
|
|
|
|
CpuRead = 0,
|
|
|
|
CpuWrite = 1,
|
|
|
|
CpuExec = 2,
|
|
|
|
PpuRead = 3,
|
|
|
|
PpuWrite = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScriptingContext
|
|
|
|
{
|
|
|
|
private:
|
2017-09-28 21:27:38 -04:00
|
|
|
//Must be static to be thread-safe when switching game
|
|
|
|
//UI updates all script windows in a single thread, so this is safe
|
|
|
|
static string _log;
|
|
|
|
|
2017-08-30 18:31:27 -04:00
|
|
|
std::deque<string> _logRows;
|
|
|
|
SimpleLock _logLock;
|
|
|
|
bool _inStartFrameEvent = false;
|
2017-10-05 19:44:37 -04:00
|
|
|
bool _inExecOpEvent = false;
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
Debugger* _debugger = nullptr;
|
|
|
|
|
2017-10-05 19:44:37 -04:00
|
|
|
std::unordered_map<int32_t, string> _saveSlotData;
|
|
|
|
int32_t _saveSlot = -1;
|
|
|
|
int32_t _loadSlot = -1;
|
2017-10-07 19:48:45 -04:00
|
|
|
bool _stateLoaded = false;
|
2017-08-30 18:31:27 -04:00
|
|
|
|
|
|
|
protected:
|
2017-10-07 15:16:14 -04:00
|
|
|
string _scriptName;
|
2020-04-21 20:04:04 -04:00
|
|
|
bool _initDone = false;
|
2017-10-07 15:16:14 -04:00
|
|
|
|
2017-08-30 18:31:27 -04:00
|
|
|
vector<int> _callbacks[5][0x10000];
|
2017-11-19 23:08:23 -05:00
|
|
|
vector<int> _eventCallbacks[(int)EventType::EventTypeSize];
|
2017-08-30 18:31:27 -04:00
|
|
|
|
2017-10-05 19:44:37 -04:00
|
|
|
virtual void InternalCallMemoryCallback(uint16_t addr, uint8_t &value, CallbackType type) = 0;
|
|
|
|
virtual int InternalCallEventCallback(EventType type) = 0;
|
|
|
|
|
2017-08-30 18:31:27 -04:00
|
|
|
public:
|
2018-07-01 15:21:05 -04:00
|
|
|
ScriptingContext(Debugger* debugger);
|
2018-06-11 19:07:05 -04:00
|
|
|
virtual ~ScriptingContext() {}
|
2017-10-07 15:16:14 -04:00
|
|
|
virtual bool LoadScript(string scriptName, string scriptContent, Debugger* debugger) = 0;
|
2017-08-30 18:31:27 -04:00
|
|
|
|
|
|
|
void Log(string message);
|
|
|
|
const char* GetLog();
|
|
|
|
|
2018-07-02 16:39:24 -04:00
|
|
|
Debugger* GetDebugger();
|
2017-10-07 15:16:14 -04:00
|
|
|
string GetScriptName();
|
|
|
|
|
2017-10-05 19:44:37 -04:00
|
|
|
void RequestSaveState(int slot);
|
|
|
|
bool RequestLoadState(int slot);
|
|
|
|
void SaveState();
|
|
|
|
bool LoadState();
|
2017-10-07 19:48:45 -04:00
|
|
|
bool LoadState(string stateData);
|
2017-10-05 19:44:37 -04:00
|
|
|
string GetSavestateData(int slot);
|
|
|
|
void ClearSavestateData(int slot);
|
|
|
|
bool ProcessSavestate();
|
2017-08-30 18:31:27 -04:00
|
|
|
|
2017-10-05 19:44:37 -04:00
|
|
|
void CallMemoryCallback(uint16_t addr, uint8_t &value, CallbackType type);
|
2017-08-30 18:31:27 -04:00
|
|
|
int CallEventCallback(EventType type);
|
2020-04-21 20:04:04 -04:00
|
|
|
bool CheckInitDone();
|
2017-08-30 18:31:27 -04:00
|
|
|
bool CheckInStartFrameEvent();
|
2017-10-07 19:48:45 -04:00
|
|
|
bool CheckInExecOpEvent();
|
|
|
|
bool CheckStateLoadedFlag();
|
2017-10-05 19:44:37 -04:00
|
|
|
|
2017-08-30 18:31:27 -04:00
|
|
|
void RegisterMemoryCallback(CallbackType type, int startAddr, int endAddr, int reference);
|
2017-10-07 19:48:45 -04:00
|
|
|
virtual void UnregisterMemoryCallback(CallbackType type, int startAddr, int endAddr, int reference);
|
2017-08-30 18:31:27 -04:00
|
|
|
void RegisterEventCallback(EventType type, int reference);
|
2017-10-07 19:48:45 -04:00
|
|
|
virtual void UnregisterEventCallback(EventType type, int reference);
|
2017-08-30 18:31:27 -04:00
|
|
|
};
|