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(controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(close()));
33}
34
35void MemoryView::setIndex(int index) {
36 static struct {
37 const char* name;
38 uint32_t base;
39 uint32_t size;
40 } indexInfo[] = {
41 { "All", 0, 0x10000000 },
42 { "BIOS", BASE_BIOS, SIZE_BIOS },
43 { "EWRAM", BASE_WORKING_RAM, SIZE_WORKING_RAM },
44 { "IWRAM", BASE_WORKING_IRAM, SIZE_WORKING_IRAM },
45 { "MMIO", BASE_IO, SIZE_IO },
46 { "Palette", BASE_PALETTE_RAM, SIZE_PALETTE_RAM },
47 { "VRAM", BASE_VRAM, SIZE_VRAM },
48 { "OAM", BASE_OAM, SIZE_OAM },
49 { "ROM", BASE_CART0, SIZE_CART0 },
50 { "ROM WS1", BASE_CART1, SIZE_CART1 },
51 { "ROM WS2", BASE_CART2, SIZE_CART2 },
52 { "SRAM", BASE_CART_SRAM, SIZE_CART_SRAM },
53 };
54 const auto& info = indexInfo[index];
55 m_ui.hexfield->setRegion(info.base, info.size, info.name);
56}