Added memory access functions for JS script interface.
This commit is contained in:
parent
7a0be296fa
commit
2fce5ffe74
|
@ -41,6 +41,8 @@
|
||||||
|
|
||||||
#include "../../fceu.h"
|
#include "../../fceu.h"
|
||||||
#include "../../movie.h"
|
#include "../../movie.h"
|
||||||
|
#include "../../x6502.h"
|
||||||
|
#include "../../debug.h"
|
||||||
|
|
||||||
#include "common/os_utils.h"
|
#include "common/os_utils.h"
|
||||||
|
|
||||||
|
@ -199,6 +201,137 @@ QString EmuScriptObject::getDir()
|
||||||
return QString(fceuExecutablePath());
|
return QString(fceuExecutablePath());
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
//---- Memory Script Object
|
||||||
|
//----------------------------------------------------
|
||||||
|
MemoryScriptObject::MemoryScriptObject(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
script = qobject_cast<QtScriptInstance*>(parent);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
MemoryScriptObject::~MemoryScriptObject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint8_t MemoryScriptObject::readByte(int address)
|
||||||
|
{
|
||||||
|
return GetMem(address);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint8_t MemoryScriptObject::readByteUnsigned(int address)
|
||||||
|
{
|
||||||
|
return GetMem(address);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
int8_t MemoryScriptObject::readByteSigned(int address)
|
||||||
|
{
|
||||||
|
return static_cast<int8_t>(GetMem(address));
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint16_t MemoryScriptObject::readWord(int addressLow, int addressHigh)
|
||||||
|
{
|
||||||
|
// little endian, unless the high byte address is specified as a 2nd parameter
|
||||||
|
if (addressHigh < 0)
|
||||||
|
{
|
||||||
|
addressHigh = addressLow + 1;
|
||||||
|
}
|
||||||
|
uint16_t result = GetMem(addressLow) | (GetMem(addressHigh) << 8);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint16_t MemoryScriptObject::readWordUnsigned(int addressLow, int addressHigh)
|
||||||
|
{
|
||||||
|
// little endian, unless the high byte address is specified as a 2nd parameter
|
||||||
|
if (addressHigh < 0)
|
||||||
|
{
|
||||||
|
addressHigh = addressLow + 1;
|
||||||
|
}
|
||||||
|
uint16_t result = GetMem(addressLow) | (GetMem(addressHigh) << 8);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
int16_t MemoryScriptObject::readWordSigned(int addressLow, int addressHigh)
|
||||||
|
{
|
||||||
|
// little endian, unless the high byte address is specified as a 2nd parameter
|
||||||
|
if (addressHigh < 0)
|
||||||
|
{
|
||||||
|
addressHigh = addressLow + 1;
|
||||||
|
}
|
||||||
|
uint16_t result = GetMem(addressLow) | (GetMem(addressHigh) << 8);
|
||||||
|
return static_cast<int16_t>(result);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void MemoryScriptObject::writeByte(int address, int value)
|
||||||
|
{
|
||||||
|
uint32_t A = address;
|
||||||
|
uint8_t V = value;
|
||||||
|
|
||||||
|
if (A < 0x10000)
|
||||||
|
{
|
||||||
|
BWrite[A](A, V);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint16_t MemoryScriptObject::getRegisterPC()
|
||||||
|
{
|
||||||
|
return X.PC;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint8_t MemoryScriptObject::getRegisterA()
|
||||||
|
{
|
||||||
|
return X.A;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint8_t MemoryScriptObject::getRegisterX()
|
||||||
|
{
|
||||||
|
return X.X;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint8_t MemoryScriptObject::getRegisterY()
|
||||||
|
{
|
||||||
|
return X.Y;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint8_t MemoryScriptObject::getRegisterS()
|
||||||
|
{
|
||||||
|
return X.S;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
uint8_t MemoryScriptObject::getRegisterP()
|
||||||
|
{
|
||||||
|
return X.P;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void MemoryScriptObject::setRegisterPC(uint16_t v)
|
||||||
|
{
|
||||||
|
X.PC = v;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void MemoryScriptObject::setRegisterA(uint8_t v)
|
||||||
|
{
|
||||||
|
X.A = v;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void MemoryScriptObject::setRegisterX(uint8_t v)
|
||||||
|
{
|
||||||
|
X.X = v;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void MemoryScriptObject::setRegisterY(uint8_t v)
|
||||||
|
{
|
||||||
|
X.Y = v;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void MemoryScriptObject::setRegisterS(uint8_t v)
|
||||||
|
{
|
||||||
|
X.S = v;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void MemoryScriptObject::setRegisterP(uint8_t v)
|
||||||
|
{
|
||||||
|
X.P = v;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
//---- Qt Script Instance
|
//---- Qt Script Instance
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
QtScriptInstance::QtScriptInstance(QObject* parent)
|
QtScriptInstance::QtScriptInstance(QObject* parent)
|
||||||
|
@ -207,15 +340,18 @@ QtScriptInstance::QtScriptInstance(QObject* parent)
|
||||||
QScriptDialog_t* win = qobject_cast<QScriptDialog_t*>(parent);
|
QScriptDialog_t* win = qobject_cast<QScriptDialog_t*>(parent);
|
||||||
|
|
||||||
emu = new EmuScriptObject(this);
|
emu = new EmuScriptObject(this);
|
||||||
|
mem = new MemoryScriptObject(this);
|
||||||
|
|
||||||
if (win != nullptr)
|
if (win != nullptr)
|
||||||
{
|
{
|
||||||
dialog = win;
|
dialog = win;
|
||||||
emu->setDialog(dialog);
|
emu->setDialog(dialog);
|
||||||
|
mem->setDialog(dialog);
|
||||||
}
|
}
|
||||||
engine = new QJSEngine(nullptr);
|
engine = new QJSEngine(nullptr);
|
||||||
|
|
||||||
emu->setEngine(engine);
|
emu->setEngine(engine);
|
||||||
|
mem->setEngine(engine);
|
||||||
|
|
||||||
configEngine();
|
configEngine();
|
||||||
|
|
||||||
|
@ -263,6 +399,10 @@ int QtScriptInstance::configEngine()
|
||||||
|
|
||||||
engine->globalObject().setProperty("emu", emuObject);
|
engine->globalObject().setProperty("emu", emuObject);
|
||||||
|
|
||||||
|
QJSValue memObject = engine->newQObject(mem);
|
||||||
|
|
||||||
|
engine->globalObject().setProperty("memory", memObject);
|
||||||
|
|
||||||
QJSValue guiObject = engine->newQObject(this);
|
QJSValue guiObject = engine->newQObject(this);
|
||||||
|
|
||||||
engine->globalObject().setProperty("gui", guiObject);
|
engine->globalObject().setProperty("gui", guiObject);
|
||||||
|
|
|
@ -69,6 +69,43 @@ public slots:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MemoryScriptObject: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MemoryScriptObject(QObject* parent = nullptr);
|
||||||
|
~MemoryScriptObject();
|
||||||
|
|
||||||
|
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 uint16_t readWord(int addressLow, int addressHigh = -1);
|
||||||
|
Q_INVOKABLE int16_t readWordSigned(int addressLow, int addressHigh = -1);
|
||||||
|
Q_INVOKABLE uint16_t readWordUnsigned(int addressLow, int addressHigh = -1);
|
||||||
|
Q_INVOKABLE void writeByte(int address, int value);
|
||||||
|
Q_INVOKABLE uint16_t getRegisterPC();
|
||||||
|
Q_INVOKABLE uint8_t getRegisterA();
|
||||||
|
Q_INVOKABLE uint8_t getRegisterX();
|
||||||
|
Q_INVOKABLE uint8_t getRegisterY();
|
||||||
|
Q_INVOKABLE uint8_t getRegisterS();
|
||||||
|
Q_INVOKABLE uint8_t getRegisterP();
|
||||||
|
Q_INVOKABLE void setRegisterPC(uint16_t v);
|
||||||
|
Q_INVOKABLE void setRegisterA(uint8_t v);
|
||||||
|
Q_INVOKABLE void setRegisterX(uint8_t v);
|
||||||
|
Q_INVOKABLE void setRegisterY(uint8_t v);
|
||||||
|
Q_INVOKABLE void setRegisterS(uint8_t v);
|
||||||
|
Q_INVOKABLE void setRegisterP(uint8_t v);
|
||||||
|
};
|
||||||
|
|
||||||
class QtScriptInstance : public QObject
|
class QtScriptInstance : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -98,6 +135,7 @@ private:
|
||||||
QJSEngine* engine = nullptr;
|
QJSEngine* engine = nullptr;
|
||||||
QScriptDialog_t* dialog = nullptr;
|
QScriptDialog_t* dialog = nullptr;
|
||||||
EmuScriptObject* emu = nullptr;
|
EmuScriptObject* emu = nullptr;
|
||||||
|
MemoryScriptObject* mem = nullptr;
|
||||||
QWidget* ui_rootWidget = nullptr;
|
QWidget* ui_rootWidget = nullptr;
|
||||||
QJSValue onFrameBeginCallback;
|
QJSValue onFrameBeginCallback;
|
||||||
QJSValue onFrameFinishCallback;
|
QJSValue onFrameFinishCallback;
|
||||||
|
|
Loading…
Reference in New Issue