CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/Debugger/CtrlMemView.h
Views: 1401
1
#pragma once
2
3
//////////////////////////////////////////////////////////////////////////
4
//CtrlDisAsmView
5
// CtrlDisAsmView.cpp
6
//////////////////////////////////////////////////////////////////////////
7
//This Win32 control is made to be flexible and usable with
8
//every kind of CPU architecture that has fixed width instruction words.
9
//Just supply it an instance of a class derived from Debugger, with all methods
10
//overridden for full functionality.
11
//
12
//To add to a dialog box, just draw a User Control in the dialog editor,
13
//and set classname to "CtrlDisAsmView". you also need to call CtrlDisAsmView::init()
14
//before opening this dialog, to register the window class.
15
//
16
//To get a class instance to be able to access it, just use getFrom(HWND wnd).
17
18
#include <cstdint>
19
#include <vector>
20
#include "Core/Debugger/DebugInterface.h"
21
#include "Core/Debugger/MemBlockInfo.h"
22
23
enum OffsetSpacing {
24
offsetSpace = 3, // the number of blank lines that should be left to make space for the offsets
25
offsetLine = 1, // the line on which the offsets should be written
26
};
27
28
enum CommonToggles {
29
On,
30
Off,
31
};
32
33
class CtrlMemView
34
{
35
public:
36
CtrlMemView(HWND _wnd);
37
~CtrlMemView();
38
static void init();
39
static void deinit();
40
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
41
static CtrlMemView *getFrom(HWND wnd);
42
43
void setDebugger(DebugInterface *deb) {
44
debugger_ = deb;
45
}
46
DebugInterface *getDebugger() {
47
return debugger_;
48
}
49
std::vector<u32> searchString(const std::string &searchQuery);
50
void onPaint(WPARAM wParam, LPARAM lParam);
51
void onVScroll(WPARAM wParam, LPARAM lParam);
52
void onKeyDown(WPARAM wParam, LPARAM lParam);
53
void onChar(WPARAM wParam, LPARAM lParam);
54
void onMouseDown(WPARAM wParam, LPARAM lParam, int button);
55
void onMouseUp(WPARAM wParam, LPARAM lParam, int button);
56
void onMouseMove(WPARAM wParam, LPARAM lParam, int button);
57
void redraw();
58
void gotoAddr(unsigned int addr);
59
60
void drawOffsetScale(HDC hdc);
61
void toggleOffsetScale(CommonToggles toggle);
62
void setHighlightType(MemBlockFlags flags);
63
64
private:
65
bool ParseSearchString(const std::string &query, bool asHex, std::vector<uint8_t> &data);
66
void updateStatusBarText();
67
void search(bool continueSearch);
68
uint32_t pickTagColor(const std::string &tag);
69
70
enum class GotoMode {
71
RESET,
72
RESET_IF_OUTSIDE,
73
FROM_CUR,
74
EXTEND,
75
};
76
static GotoMode GotoModeFromModifiers(bool isRightClick);
77
void UpdateSelectRange(uint32_t target, GotoMode mode);
78
void GotoPoint(int x, int y, GotoMode mode);
79
void ScrollWindow(int lines, GotoMode mdoe);
80
void ScrollCursor(int bytes, GotoMode mdoe);
81
82
static wchar_t szClassName[];
83
DebugInterface *debugger_ = nullptr;
84
85
HWND wnd;
86
HFONT font;
87
HFONT underlineFont;
88
89
bool redrawScheduled_ = false;
90
// Whether to draw things using focused styles.
91
bool hasFocus_ = false;
92
MemBlockFlags highlightFlags_ = MemBlockFlags::ALLOC;
93
94
// Current cursor position.
95
uint32_t curAddress_ = 0;
96
// Selected range, which should always be around the cursor.
97
uint32_t selectRangeStart_ = 0;
98
uint32_t selectRangeEnd_ = 0;
99
// Last select reset position, for selecting ranges.
100
uint32_t lastSelectReset_ = 0;
101
// Address of the first displayed byte.
102
uint32_t windowStart_ = 0;
103
// Number of bytes displayed per row.
104
int rowSize_ = 16;
105
106
// Width of one monospace character (to maintain grid.)
107
int charWidth_ = 0;
108
// Height of one row of bytes.
109
int rowHeight_ = 0;
110
// Y position of offset header (at top.)
111
int offsetPositionY_;
112
// X position of addresses (at left.)
113
int addressStartX_ = 0;
114
// X position of hex display.
115
int hexStartX_ = 0;
116
// X position of text display.
117
int asciiStartX_ = 0;
118
// Whether cursor is within text display or hex display.
119
bool asciiSelected_ = false;
120
// Which nibble is selected, if in hex display. 0 means leftmost, i.e. most significant.
121
int selectedNibble_ = 0;
122
123
bool displayOffsetScale_ = false;
124
125
// Number of rows visible as of last redraw.
126
int visibleRows_ = 0;
127
// Position and size as of last redraw.
128
RECT rect_;
129
130
// Last used search query, used when continuing a search.
131
std::string searchQuery_;
132
// Address of last match when continuing search.
133
uint32_t matchAddress_ = 0xFFFFFFFF;
134
// Whether a search is in progress.
135
bool searching_ = false;
136
};
137
138