all repos — mgba @ 4ec19aac71722cd8e639ed00293737d59b4fa35b

mGBA Game Boy Advance Emulator

src/platform/qt/MemoryView.cpp (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6
 7#include "MemoryView.h"
 8
 9#include "GameController.h"
10
11extern "C" {
12#include "gba/memory.h"
13}
14
15using namespace QGBA;
16
17MemoryView::MemoryView(GameController* controller, QWidget* parent)
18	: QWidget(parent)
19	, m_controller(controller)
20{
21	m_ui.setupUi(this);
22
23	m_ui.hexfield->setController(controller);
24
25	connect(m_ui.regions, SIGNAL(currentIndexChanged(int)), this, SLOT(setIndex(int)));
26
27	connect(m_ui.width8, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(1); });
28	connect(m_ui.width16, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(2); });
29	connect(m_ui.width32, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(4); });
30	connect(m_ui.setAddress, SIGNAL(valueChanged(const QString&)), m_ui.hexfield, SLOT(jumpToAddress(const QString&)));
31
32	connect(m_ui.hexfield, SIGNAL(selectionChanged(uint32_t, uint32_t)), this, SLOT(updateStatus(uint32_t, uint32_t)));
33
34	connect(controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(close()));
35}
36
37void MemoryView::setIndex(int index) {
38	static struct {
39		const char* name;
40		uint32_t base;
41		uint32_t size;
42	} indexInfo[] = {
43		{ "All", 0, 0x10000000 },
44		{ "BIOS", BASE_BIOS, SIZE_BIOS },
45		{ "EWRAM", BASE_WORKING_RAM, SIZE_WORKING_RAM },
46		{ "IWRAM", BASE_WORKING_IRAM, SIZE_WORKING_IRAM },
47		{ "MMIO", BASE_IO, SIZE_IO },
48		{ "Palette", BASE_PALETTE_RAM, SIZE_PALETTE_RAM },
49		{ "VRAM", BASE_VRAM, SIZE_VRAM },
50		{ "OAM", BASE_OAM, SIZE_OAM },
51		{ "ROM", BASE_CART0, SIZE_CART0 },
52		{ "ROM WS1", BASE_CART1, SIZE_CART1 },
53		{ "ROM WS2", BASE_CART2, SIZE_CART2 },
54		{ "SRAM", BASE_CART_SRAM, SIZE_CART_SRAM },
55	};
56	const auto& info = indexInfo[index];
57	m_ui.hexfield->setRegion(info.base, info.size, info.name);
58}
59
60void MemoryView::updateStatus(uint32_t start, uint32_t end) {
61	int align = m_ui.hexfield->alignment();
62	if (start & (align - 1) || end - start != align) {
63		m_ui.sintVal->clear();
64		m_ui.uintVal->clear();
65		return;
66	}
67	ARMCore* cpu = m_controller->thread()->cpu;
68	union {
69		uint32_t u32;
70		int32_t i32;
71		uint16_t u16;
72		int16_t i16;
73		uint8_t u8;
74		int8_t i8;
75	} value;
76	switch (align) {
77	case 1:
78		value.u8 = cpu->memory.load8(cpu, start, nullptr);
79		m_ui.sintVal->setText(QString::number(value.i8));
80		m_ui.uintVal->setText(QString::number(value.u8));
81		break;
82	case 2:
83		value.u16 = cpu->memory.load16(cpu, start, nullptr);
84		m_ui.sintVal->setText(QString::number(value.i16));
85		m_ui.uintVal->setText(QString::number(value.u16));
86		break;
87	case 4:
88		value.u32 = cpu->memory.load32(cpu, start, nullptr);
89		m_ui.sintVal->setText(QString::number(value.i32));
90		m_ui.uintVal->setText(QString::number(value.u32));
91		break;
92	}
93}