all repos — mgba @ 1326626777dacd7a7882e39c0f6dccc752549a1e

mGBA Game Boy Advance Emulator

Core: Add raw memory read/write operations
Jeffrey Pfau jeffrey@endrift.com
Thu, 05 May 2016 23:19:39 -0700
commit

1326626777dacd7a7882e39c0f6dccc752549a1e

parent

20f790bb61dc9808f4f220a6ebb380ac25f848b5

M src/core/core.hsrc/core/core.h

@@ -104,6 +104,14 @@ void (*busWrite8)(struct mCore*, uint32_t address, uint8_t);

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*);
M src/gb/core.csrc/gb/core.c

@@ -389,6 +389,12 @@ core->busRead32 = _GBCoreBusRead32;

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;
M src/gba/core.csrc/gba/core.c

@@ -325,6 +325,36 @@ struct ARMCore* cpu = core->cpu;

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 @@ core->busRead32 = _GBACoreBusRead32;

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;
M src/platform/qt/MemoryModel.cppsrc/platform/qt/MemoryModel.cpp

@@ -19,14 +19,14 @@ #include <QSlider>

#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 @@ setRegion(0, 0x10000000, tr("All"));

} 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 @@ }

} 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 @@ }

} 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 @@ }

} 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 @@ break;

} 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 @@ ++m_bufferedNybbles;

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;
M src/platform/qt/MemoryModel.hsrc/platform/qt/MemoryModel.h

@@ -12,7 +12,7 @@ #include <QSize>

#include <QStaticText> #include <QVector> -struct ARMCore; +struct mCore; namespace QGBA {

@@ -60,7 +60,7 @@ void adjustCursor(int adjust, bool shift);

void serialize(QDataStream* stream); - ARMCore* m_cpu; + mCore* m_core; QFont m_font; int m_cellHeight; int m_letterWidth;