Core: Add raw memory read/write operations

This commit is contained in:
Jeffrey Pfau 2016-05-05 23:19:39 -07:00
parent 20f790bb61
commit 1326626777
5 changed files with 65 additions and 15 deletions

View File

@ -104,6 +104,14 @@ struct mCore {
void (*busWrite16)(struct mCore*, uint32_t address, uint16_t);
void (*busWrite32)(struct mCore*, uint32_t address, uint32_t);
uint32_t (*rawRead8)(struct mCore*, uint32_t address);
uint32_t (*rawRead16)(struct mCore*, uint32_t address);
uint32_t (*rawRead32)(struct mCore*, uint32_t address);
void (*rawWrite8)(struct mCore*, uint32_t address, uint8_t);
void (*rawWrite16)(struct mCore*, uint32_t address, uint16_t);
void (*rawWrite32)(struct mCore*, uint32_t address, uint32_t);
bool (*supportsDebuggerType)(struct mCore*, enum mDebuggerType);
struct mDebuggerPlatform* (*debuggerPlatform)(struct mCore*);
struct CLIDebuggerSystem* (*cliDebuggerSystem)(struct mCore*);

View File

@ -389,6 +389,12 @@ struct mCore* GBCoreCreate(void) {
core->busWrite8 = _GBCoreBusWrite8;
core->busWrite16 = _GBCoreBusWrite16;
core->busWrite32 = _GBCoreBusWrite32;
core->rawRead8 = NULL;
core->rawRead16 = NULL;
core->rawRead32 = NULL;
core->rawWrite8 = NULL;
core->rawWrite16 = NULL;
core->rawWrite32 = NULL;
core->supportsDebuggerType = _GBCoreSupportsDebuggerType;
core->debuggerPlatform = _GBCoreDebuggerPlatform;
core->cliDebuggerSystem = _GBCoreCliDebuggerSystem;

View File

@ -325,6 +325,36 @@ static void _GBACoreBusWrite32(struct mCore* core, uint32_t address, uint32_t va
cpu->memory.store32(cpu, address, value, 0);
}
static uint32_t _GBACoreRawRead8(struct mCore* core, uint32_t address) {
struct ARMCore* cpu = core->cpu;
return GBAView8(cpu, address);
}
static uint32_t _GBACoreRawRead16(struct mCore* core, uint32_t address) {
struct ARMCore* cpu = core->cpu;
return GBAView16(cpu, address);
}
static uint32_t _GBACoreRawRead32(struct mCore* core, uint32_t address) {
struct ARMCore* cpu = core->cpu;
return GBAView32(cpu, address);
}
static void _GBACoreRawWrite8(struct mCore* core, uint32_t address, uint8_t value) {
struct ARMCore* cpu = core->cpu;
GBAPatch8(cpu, address, value, NULL);
}
static void _GBACoreRawWrite16(struct mCore* core, uint32_t address, uint16_t value) {
struct ARMCore* cpu = core->cpu;
GBAPatch16(cpu, address, value, NULL);
}
static void _GBACoreRawWrite32(struct mCore* core, uint32_t address, uint32_t value) {
struct ARMCore* cpu = core->cpu;
GBAPatch32(cpu, address, value, NULL);
}
static bool _GBACoreSupportsDebuggerType(struct mCore* core, enum mDebuggerType type) {
UNUSED(core);
switch (type) {
@ -419,6 +449,12 @@ struct mCore* GBACoreCreate(void) {
core->busWrite8 = _GBACoreBusWrite8;
core->busWrite16 = _GBACoreBusWrite16;
core->busWrite32 = _GBACoreBusWrite32;
core->rawRead8 = _GBACoreRawRead8;
core->rawRead16 = _GBACoreRawRead16;
core->rawRead32 = _GBACoreRawRead32;
core->rawWrite8 = _GBACoreRawWrite8;
core->rawWrite16 = _GBACoreRawWrite16;
core->rawWrite32 = _GBACoreRawWrite32;
core->supportsDebuggerType = _GBACoreSupportsDebuggerType;
core->debuggerPlatform = _GBACoreDebuggerPlatform;
core->cliDebuggerSystem = _GBACoreCliDebuggerSystem;

View File

@ -19,14 +19,14 @@
#include <QWheelEvent>
extern "C" {
#include "gba/memory.h"
#include "core/core.h"
}
using namespace QGBA;
MemoryModel::MemoryModel(QWidget* parent)
: QAbstractScrollArea(parent)
, m_cpu(nullptr)
, m_core(nullptr)
, m_top(0)
, m_align(1)
, m_selection(0, 0)
@ -87,7 +87,7 @@ MemoryModel::MemoryModel(QWidget* parent)
}
void MemoryModel::setController(GameController* controller) {
m_cpu = static_cast<ARMCore*>(controller->thread()->core->cpu);
m_core = controller->thread()->core;
}
void MemoryModel::setRegion(uint32_t base, uint32_t size, const QString& name) {
@ -169,17 +169,17 @@ void MemoryModel::serialize(QDataStream* stream) {
switch (m_align) {
case 1:
for (uint32_t i = m_selection.first; i < m_selection.second; i += m_align) {
*stream << GBAView8(m_cpu, i);
*stream << m_core->rawRead8(m_core, i);
}
break;
case 2:
for (uint32_t i = m_selection.first; i < m_selection.second; i += m_align) {
*stream << GBAView16(m_cpu, i);
*stream << m_core->rawRead16(m_core, i);
}
break;
case 4:
for (uint32_t i = m_selection.first; i < m_selection.second; i += m_align) {
*stream << GBAView32(m_cpu, i);
*stream << m_core->rawRead32(m_core, i);
}
break;
}
@ -230,7 +230,7 @@ void MemoryModel::paintEvent(QPaintEvent* event) {
} else {
painter.setPen(palette.color(QPalette::WindowText));
}
uint16_t b = GBAView16(m_cpu, address);
uint16_t b = m_core->rawRead16(m_core, address);
painter.drawStaticText(
QPointF(m_cellSize.width() * (x + 1.0) - 2 * m_letterWidth + m_margins.left(), yp),
m_staticNumbers[(b >> 8) & 0xFF]);
@ -255,7 +255,7 @@ void MemoryModel::paintEvent(QPaintEvent* event) {
} else {
painter.setPen(palette.color(QPalette::WindowText));
}
uint32_t b = GBAView32(m_cpu, address);
uint32_t b = m_core->rawRead32(m_core, address);
painter.drawStaticText(
QPointF(m_cellSize.width() * (x + 2.0) - 4 * m_letterWidth + m_margins.left(), yp),
m_staticNumbers[(b >> 24) & 0xFF]);
@ -285,7 +285,7 @@ void MemoryModel::paintEvent(QPaintEvent* event) {
} else {
painter.setPen(palette.color(QPalette::WindowText));
}
uint8_t b = GBAView8(m_cpu, address);
uint8_t b = m_core->rawRead8(m_core, address);
painter.drawStaticText(QPointF(m_cellSize.width() * (x + 0.5) - m_letterWidth + m_margins.left(), yp),
m_staticNumbers[b]);
}
@ -293,7 +293,7 @@ void MemoryModel::paintEvent(QPaintEvent* event) {
}
painter.setPen(palette.color(QPalette::WindowText));
for (int x = 0; x < 16; ++x) {
uint8_t b = GBAView8(m_cpu, (y + m_top) * 16 + x + m_base);
uint8_t b =m_core->rawRead8(m_core, (y + m_top) * 16 + x + m_base);
painter.drawStaticText(
QPointF(viewport()->size().width() - (16 - x) * m_margins.right() / 17.0 - m_letterWidth * 0.5, yp),
b < 0x80 ? m_staticAscii[b] : m_staticAscii[0]);
@ -410,13 +410,13 @@ void MemoryModel::keyPressEvent(QKeyEvent* event) {
if (m_bufferedNybbles == m_align * 2) {
switch (m_align) {
case 1:
GBAPatch8(m_cpu, m_selection.first, m_buffer, nullptr);
m_core->rawWrite8(m_core, m_selection.first, m_buffer);
break;
case 2:
GBAPatch16(m_cpu, m_selection.first, m_buffer, nullptr);
m_core->rawWrite16(m_core, m_selection.first, m_buffer);
break;
case 4:
GBAPatch32(m_cpu, m_selection.first, m_buffer, nullptr);
m_core->rawWrite32(m_core, m_selection.first, m_buffer);
break;
}
m_bufferedNybbles = 0;

View File

@ -12,7 +12,7 @@
#include <QStaticText>
#include <QVector>
struct ARMCore;
struct mCore;
namespace QGBA {
@ -60,7 +60,7 @@ private:
void serialize(QDataStream* stream);
ARMCore* m_cpu;
mCore* m_core;
QFont m_font;
int m_cellHeight;
int m_letterWidth;