Added ppu interface functions to JS engine.
This commit is contained in:
parent
a5071f10f0
commit
401110bae8
|
@ -44,6 +44,7 @@
|
||||||
#include "../../video.h"
|
#include "../../video.h"
|
||||||
#include "../../x6502.h"
|
#include "../../x6502.h"
|
||||||
#include "../../debug.h"
|
#include "../../debug.h"
|
||||||
|
#include "../../ppu.h"
|
||||||
|
|
||||||
#include "common/os_utils.h"
|
#include "common/os_utils.h"
|
||||||
#include "utils/xstring.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<QtScriptInstance*>(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<int8_t>(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; i<size; i++)
|
||||||
|
{
|
||||||
|
int byte = FFCEUX_PPURead(start + i);
|
||||||
|
|
||||||
|
QJSValue element = byte;
|
||||||
|
|
||||||
|
array.setProperty(i, element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void PpuScriptObject::writeByte(int address, int value)
|
||||||
|
{
|
||||||
|
if (FFCEUX_PPUWrite != nullptr)
|
||||||
|
{
|
||||||
|
FFCEUX_PPUWrite(address, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
//---- Memory Script Object
|
//---- Memory Script Object
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
@ -928,6 +1006,11 @@ void QtScriptInstance::shutdownEngine()
|
||||||
delete rom;
|
delete rom;
|
||||||
rom = nullptr;
|
rom = nullptr;
|
||||||
}
|
}
|
||||||
|
if (ppu != nullptr)
|
||||||
|
{
|
||||||
|
delete ppu;
|
||||||
|
ppu = nullptr;
|
||||||
|
}
|
||||||
if (mem != nullptr)
|
if (mem != nullptr)
|
||||||
{
|
{
|
||||||
mem->reset();
|
mem->reset();
|
||||||
|
@ -955,6 +1038,7 @@ int QtScriptInstance::initEngine()
|
||||||
|
|
||||||
emu = new JS::EmuScriptObject(this);
|
emu = new JS::EmuScriptObject(this);
|
||||||
rom = new JS::RomScriptObject(this);
|
rom = new JS::RomScriptObject(this);
|
||||||
|
ppu = new JS::PpuScriptObject(this);
|
||||||
mem = new JS::MemoryScriptObject(this);
|
mem = new JS::MemoryScriptObject(this);
|
||||||
|
|
||||||
emu->setDialog(dialog);
|
emu->setDialog(dialog);
|
||||||
|
@ -967,18 +1051,27 @@ int QtScriptInstance::initEngine()
|
||||||
rom->setEngine(engine);
|
rom->setEngine(engine);
|
||||||
mem->setEngine(engine);
|
mem->setEngine(engine);
|
||||||
|
|
||||||
|
// emu
|
||||||
QJSValue emuObject = engine->newQObject(emu);
|
QJSValue emuObject = engine->newQObject(emu);
|
||||||
|
|
||||||
engine->globalObject().setProperty("emu", emuObject);
|
engine->globalObject().setProperty("emu", emuObject);
|
||||||
|
|
||||||
|
// rom
|
||||||
QJSValue romObject = engine->newQObject(rom);
|
QJSValue romObject = engine->newQObject(rom);
|
||||||
|
|
||||||
engine->globalObject().setProperty("rom", romObject);
|
engine->globalObject().setProperty("rom", romObject);
|
||||||
|
|
||||||
|
// ppu
|
||||||
|
QJSValue ppuObject = engine->newQObject(ppu);
|
||||||
|
|
||||||
|
engine->globalObject().setProperty("ppu", ppuObject);
|
||||||
|
|
||||||
|
// memory
|
||||||
QJSValue memObject = engine->newQObject(mem);
|
QJSValue memObject = engine->newQObject(mem);
|
||||||
|
|
||||||
engine->globalObject().setProperty("memory", memObject);
|
engine->globalObject().setProperty("memory", memObject);
|
||||||
|
|
||||||
|
// gui
|
||||||
QJSValue guiObject = engine->newQObject(this);
|
QJSValue guiObject = engine->newQObject(this);
|
||||||
|
|
||||||
engine->globalObject().setProperty("gui", guiObject);
|
engine->globalObject().setProperty("gui", guiObject);
|
||||||
|
|
|
@ -194,6 +194,29 @@ public slots:
|
||||||
Q_INVOKABLE void unregisterExec(const QJSValue& func, int address, int size = 1);
|
Q_INVOKABLE void unregisterExec(const QJSValue& func, int address, int size = 1);
|
||||||
Q_INVOKABLE void unregisterAll();
|
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
|
} // JS
|
||||||
|
|
||||||
class ScriptExecutionState
|
class ScriptExecutionState
|
||||||
|
@ -263,6 +286,7 @@ private:
|
||||||
QScriptDialog_t* dialog = nullptr;
|
QScriptDialog_t* dialog = nullptr;
|
||||||
JS::EmuScriptObject* emu = nullptr;
|
JS::EmuScriptObject* emu = nullptr;
|
||||||
JS::RomScriptObject* rom = nullptr;
|
JS::RomScriptObject* rom = nullptr;
|
||||||
|
JS::PpuScriptObject* ppu = nullptr;
|
||||||
JS::MemoryScriptObject* mem = nullptr;
|
JS::MemoryScriptObject* mem = nullptr;
|
||||||
QWidget* ui_rootWidget = nullptr;
|
QWidget* ui_rootWidget = nullptr;
|
||||||
QJSValue *onFrameBeginCallback = nullptr;
|
QJSValue *onFrameBeginCallback = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue