Qt: Add shadow ROM exporting

This commit is contained in:
Vicki Pfau 2023-09-12 01:55:52 -07:00
parent 8610147ad7
commit c03b15944b
3 changed files with 67 additions and 22 deletions

View File

@ -8,6 +8,7 @@
#include <QVBoxLayout>
#include "GBAApp.h"
#include "utils.h"
#include "VFileDevice.h"
using namespace QGBA;
@ -19,6 +20,7 @@ MemoryAccessLogView::MemoryAccessLogView(std::shared_ptr<CoreController> control
m_ui.setupUi(this);
connect(m_ui.browse, &QAbstractButton::clicked, this, &MemoryAccessLogView::selectFile);
connect(m_ui.exportButton, &QAbstractButton::clicked, this, &MemoryAccessLogView::exportFile);
connect(this, &MemoryAccessLogView::loggingChanged, m_ui.start, &QWidget::setDisabled);
connect(this, &MemoryAccessLogView::loggingChanged, m_ui.stop, &QWidget::setEnabled);
connect(this, &MemoryAccessLogView::loggingChanged, m_ui.filename, &QWidget::setDisabled);
@ -58,7 +60,7 @@ void MemoryAccessLogView::updateRegion(const QString& internalName, bool checked
return;
}
m_regionBoxes[internalName]->setEnabled(false);
mDebuggerAccessLoggerWatchMemoryBlockName(&m_logger, internalName.toUtf8().constData(), activeFlags());
m_regionMapping[internalName] = mDebuggerAccessLoggerWatchMemoryBlockName(&m_logger, internalName.toUtf8().constData(), activeFlags());
}
void MemoryAccessLogView::start() {
@ -72,6 +74,7 @@ void MemoryAccessLogView::start() {
return;
}
mDebuggerAccessLoggerInit(&m_logger);
CoreController::Interrupter interrupter(m_controller);
m_controller->attachDebuggerModule(&m_logger.d);
if (!mDebuggerAccessLoggerOpen(&m_logger, vf, flags)) {
mDebuggerAccessLoggerDeinit(&m_logger);
@ -83,7 +86,12 @@ void MemoryAccessLogView::start() {
emit loggingChanged(true);
for (const auto& region : m_watchedRegions) {
m_regionBoxes[region]->setEnabled(false);
mDebuggerAccessLoggerWatchMemoryBlockName(&m_logger, region.toUtf8().constData(), activeFlags());
m_regionMapping[region] = mDebuggerAccessLoggerWatchMemoryBlockName(&m_logger, region.toUtf8().constData(), activeFlags());
}
interrupter.resume();
if (m_watchedRegions.contains(QString("cart0"))) {
m_ui.exportButton->setEnabled(true);
}
}
@ -91,12 +99,16 @@ void MemoryAccessLogView::stop() {
if (!m_active) {
return;
}
CoreController::Interrupter interrupter(m_controller);
m_controller->detachDebuggerModule(&m_logger.d);
mDebuggerAccessLoggerDeinit(&m_logger);
emit loggingChanged(false);
interrupter.resume();
for (const auto& region : m_watchedRegions) {
m_regionBoxes[region]->setEnabled(true);
}
m_ui.exportButton->setEnabled(false);
}
void MemoryAccessLogView::selectFile() {
@ -113,3 +125,23 @@ mDebuggerAccessLogRegionFlags MemoryAccessLogView::activeFlags() const {
}
return loggerFlags;
}
void MemoryAccessLogView::exportFile() {
if (!m_regionMapping.contains("cart0")) {
return;
}
QString filename = GBAApp::app()->getSaveFileName(this, tr("Select access log file"), romFilters(false, m_controller->platform(), true));
if (filename.isEmpty()) {
return;
}
VFile* vf = VFileDevice::open(filename, O_CREAT | O_TRUNC | O_WRONLY);
if (!vf) {
// log error
return;
}
CoreController::Interrupter interrupter(m_controller);
mDebuggerAccessLoggerCreateShadowFile(&m_logger, m_regionMapping[QString("cart0")], vf, 0);
vf->close(vf);
}

View File

@ -32,6 +32,8 @@ private slots:
void start();
void stop();
void exportFile();
signals:
void loggingChanged(bool active);
@ -41,6 +43,7 @@ private:
std::shared_ptr<CoreController> m_controller;
QSet<QString> m_watchedRegions;
QHash<QString, QCheckBox*> m_regionBoxes;
QHash<QString, int> m_regionMapping;
struct mDebuggerAccessLogger m_logger;
bool m_active = false;

View File

@ -17,29 +17,15 @@
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item row="2" column="0">
<widget class="QPushButton" name="start">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="stop">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Log file</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLineEdit" name="filename"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="browse">
<property name="text">
@ -47,9 +33,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="filename"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="logExtra">
<property name="text">
@ -78,6 +61,33 @@
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="exportButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Export ROM snapshot</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="start">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="stop">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>