diff --git a/src/drivers/Qt/QtScriptManager.cpp b/src/drivers/Qt/QtScriptManager.cpp index ee364b4c..b359da48 100644 --- a/src/drivers/Qt/QtScriptManager.cpp +++ b/src/drivers/Qt/QtScriptManager.cpp @@ -44,6 +44,7 @@ #include "../../video.h" #include "../../x6502.h" #include "../../debug.h" +#include "../../ppu.h" #include "common/os_utils.h" #include "utils/xstring.h" @@ -468,6 +469,83 @@ void RomScriptObject::writeByte(int address, int value) } } //---------------------------------------------------- +//---- PPU Script Object +//---------------------------------------------------- +//---------------------------------------------------- +PpuScriptObject::PpuScriptObject(QObject* parent) + : QObject(parent) +{ + script = qobject_cast(parent); +} +//---------------------------------------------------- +PpuScriptObject::~PpuScriptObject() +{ +} +//---------------------------------------------------- +uint8_t PpuScriptObject::readByte(int address) +{ + uint8_t byte = 0; + if (FFCEUX_PPURead == nullptr) + { + byte = FFCEUX_PPURead(address); + } + return byte; +} +//---------------------------------------------------- +uint8_t PpuScriptObject::readByteUnsigned(int address) +{ + uint8_t byte = 0; + if (FFCEUX_PPURead == nullptr) + { + byte = FFCEUX_PPURead(address); + } + return byte; +} +//---------------------------------------------------- +int8_t PpuScriptObject::readByteSigned(int address) +{ + int8_t byte = 0; + if (FFCEUX_PPURead == nullptr) + { + byte = static_cast(FFCEUX_PPURead(address)); + } + return byte; +} +//---------------------------------------------------- +QJSValue PpuScriptObject::readByteRange(int start, int end) +{ + QJSValue array; + int size = end - start + 1; + + if (FFCEUX_PPURead == nullptr) + { + return array; + } + + if (size > 0) + { + array = engine->newArray(size); + + for (int i=0; ireset(); @@ -955,6 +1038,7 @@ int QtScriptInstance::initEngine() emu = new JS::EmuScriptObject(this); rom = new JS::RomScriptObject(this); + ppu = new JS::PpuScriptObject(this); mem = new JS::MemoryScriptObject(this); emu->setDialog(dialog); @@ -967,18 +1051,27 @@ int QtScriptInstance::initEngine() rom->setEngine(engine); mem->setEngine(engine); + // emu QJSValue emuObject = engine->newQObject(emu); engine->globalObject().setProperty("emu", emuObject); + // rom QJSValue romObject = engine->newQObject(rom); engine->globalObject().setProperty("rom", romObject); + // ppu + QJSValue ppuObject = engine->newQObject(ppu); + + engine->globalObject().setProperty("ppu", ppuObject); + + // memory QJSValue memObject = engine->newQObject(mem); engine->globalObject().setProperty("memory", memObject); + // gui QJSValue guiObject = engine->newQObject(this); engine->globalObject().setProperty("gui", guiObject); diff --git a/src/drivers/Qt/QtScriptManager.h b/src/drivers/Qt/QtScriptManager.h index 0e6123d6..e9cd0817 100644 --- a/src/drivers/Qt/QtScriptManager.h +++ b/src/drivers/Qt/QtScriptManager.h @@ -194,6 +194,29 @@ public slots: Q_INVOKABLE void unregisterExec(const QJSValue& func, int address, int size = 1); Q_INVOKABLE void unregisterAll(); }; + +class PpuScriptObject: public QObject +{ + Q_OBJECT +public: + PpuScriptObject(QObject* parent = nullptr); + ~PpuScriptObject(); + + void setEngine(QJSEngine* _engine){ engine = _engine; } + void setDialog(QScriptDialog_t* _dialog){ dialog = _dialog; } +private: + QJSEngine* engine = nullptr; + QScriptDialog_t* dialog = nullptr; + QtScriptInstance* script = nullptr; + +public slots: + Q_INVOKABLE uint8_t readByte(int address); + Q_INVOKABLE int8_t readByteSigned(int address); + Q_INVOKABLE uint8_t readByteUnsigned(int address); + Q_INVOKABLE QJSValue readByteRange(int start, int end); + Q_INVOKABLE void writeByte(int address, int value); +}; + } // JS class ScriptExecutionState @@ -263,6 +286,7 @@ private: QScriptDialog_t* dialog = nullptr; JS::EmuScriptObject* emu = nullptr; JS::RomScriptObject* rom = nullptr; + JS::PpuScriptObject* ppu = nullptr; JS::MemoryScriptObject* mem = nullptr; QWidget* ui_rootWidget = nullptr; QJSValue *onFrameBeginCallback = nullptr;