aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/qt_sdl/RAMInfoDialog.h
blob: 33afd988876c55415c0193fdb570c73d58d07318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
    Copyright 2016-2021 Arisotura

    This file is part of melonDS.

    melonDS is free software: you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free
    Software Foundation, either version 3 of the License, or (at your option)
    any later version.

    melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with melonDS. If not, see http://www.gnu.org/licenses/.
*/

#ifndef RAMINFODIALOG_H
#define RAMINFODIALOG_H

#include <QDialog>
#include <QTableWidget>
#include <QScrollBar>
#include <QThread>
#include <QTimer>

#include "types.h"
#include "NDS.h"

namespace Ui { class RAMInfoDialog; }
class RAMInfoDialog;
class RAMSearchThread;
class RAMUpdateThread;

enum ramInfo_ByteType
{
    ramInfo_OneByte = 1, 
    ramInfo_TwoBytes = 2, 
    ramInfo_FourBytes = 4
};

enum ramInfoSTh_SearchMode
{
    ramInfoSTh_Default,
    ramInfoSTh_SearchAll
};

enum
{
    ramInfo_Address, 
    ramInfo_Value, 
    ramInfo_Previous
};

s32 GetMainRAMValue(const u32& addr, const ramInfo_ByteType& byteType);

struct ramInfo_RowData
{
    u32 Address;
    s32 Value;
    s32 Previous;

    void Update(const ramInfo_ByteType& byteType)
    {
        Value = GetMainRAMValue(Address, byteType);
    }

    void SetValue(const s32& value)
    {
        NDS::MainRAM[Address&NDS::MainRAMMask] = (u32)value;
        Value = value;
    }
};

class RAMInfoDialog : public QDialog
{
    Q_OBJECT

public:
    explicit RAMInfoDialog(QWidget* parent);
    ~RAMInfoDialog();

    static RAMInfoDialog* currentDlg;
    static RAMInfoDialog* openDlg(QWidget* parent)
    {
        if (currentDlg)
        {
            currentDlg->activateWindow();
            return currentDlg;
        }

        currentDlg = new RAMInfoDialog(parent);
        currentDlg->show();
        return currentDlg;
    }
    static void closeDlg()
    {
        currentDlg = nullptr;
    }

    s32 SearchValue = 0;

    void ClearTableContents();

private slots:
    void done(int r);

    void on_btnSearch_clicked();
    void on_btnClear_clicked();
    void on_radiobtn1byte_clicked();
    void on_radiobtn2bytes_clicked();
    void on_radiobtn4bytes_clicked();
    void on_ramTable_itemChanged(QTableWidgetItem *item);

    void OnSearchFinished();
    void ShowRowsInTable();
    void SetProgressbarValue(const u32& value);

private:
    Ui::RAMInfoDialog* ui;
    
    RAMSearchThread* SearchThread;
    QTimer* TableUpdater;
};

class RAMSearchThread : public QThread
{
    Q_OBJECT

public:
    explicit RAMSearchThread(RAMInfoDialog* dialog);
    ~RAMSearchThread() override;

    void Start(const s32& searchValue, const ramInfoSTh_SearchMode& searchMode = ramInfoSTh_Default);
    void Start(const ramInfoSTh_SearchMode& searchMode);
    
    void SetSearchByteType(const ramInfo_ByteType& bytetype);
    ramInfo_ByteType GetSearchByteType() const;
    std::vector<ramInfo_RowData>* GetResults();

    void Stop();

private:
    virtual void run() override;

    RAMInfoDialog* Dialog;
    bool SearchRunning = false;

    ramInfoSTh_SearchMode SearchMode;
    s32 SearchValue;
    ramInfo_ByteType SearchByteType = ramInfo_OneByte;
    std::vector<ramInfo_RowData>* RowDataVector = nullptr;

    void ClearTableContents();

signals:
    void SetProgressbarValue(const u32& value);
};

#endif // RAMINFODIALOG_H