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/WatchItemWindow.cpp
Views: 1401
1
// Copyright (c) 2023- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "Common/Common.h"
19
#include "Common/Data/Encoding/Utf8.h"
20
#include "Windows/Debugger/WatchItemWindow.h"
21
#include "Windows/resource.h"
22
23
INT_PTR CALLBACK WatchItemWindow::StaticDlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
24
WatchItemWindow *thiz;
25
if (iMsg == WM_INITDIALOG) {
26
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lParam);
27
thiz = (WatchItemWindow *)lParam;
28
} else {
29
thiz = (WatchItemWindow *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
30
}
31
32
if (!thiz)
33
return FALSE;
34
return thiz->DlgFunc(hWnd, iMsg, wParam, lParam);
35
}
36
37
INT_PTR WatchItemWindow::DlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
38
switch (iMsg) {
39
case WM_INITDIALOG:
40
SetWindowTextW(GetDlgItem(hWnd, IDC_BREAKPOINT_ADDRESS), ConvertUTF8ToWString(name_).c_str());
41
SetWindowTextW(GetDlgItem(hWnd, IDC_BREAKPOINT_CONDITION), ConvertUTF8ToWString(expression_).c_str());
42
43
// We only need to set one state on dialog init.
44
if (format_ == WatchFormat::HEX)
45
SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_HEX), BM_SETCHECK, BST_CHECKED, 0);
46
else if (format_ == WatchFormat::INT)
47
SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_INT), BM_SETCHECK, BST_CHECKED, 0);
48
else if (format_ == WatchFormat::FLOAT)
49
SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_FLOAT), BM_SETCHECK, BST_CHECKED, 0);
50
else if (format_ == WatchFormat::STR)
51
SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_STR), BM_SETCHECK, BST_CHECKED, 0);
52
return TRUE;
53
54
case WM_COMMAND:
55
switch (LOWORD(wParam)) {
56
case IDC_BREAKPOINT_OK:
57
switch (HIWORD(wParam)) {
58
case BN_CLICKED:
59
if (FetchDialogData(hWnd)) {
60
EndDialog(hWnd, true);
61
return TRUE;
62
}
63
break;
64
};
65
break;
66
case IDC_BREAKPOINT_CANCEL:
67
switch (HIWORD(wParam)) {
68
case BN_CLICKED:
69
EndDialog(hWnd, false);
70
return TRUE;
71
};
72
break;
73
case IDOK:
74
if (FetchDialogData(hWnd)) {
75
EndDialog(hWnd, true);
76
return TRUE;
77
}
78
break;
79
case IDCANCEL:
80
EndDialog(hWnd, false);
81
return TRUE;
82
}
83
break;
84
85
default:
86
break;
87
}
88
89
return FALSE;
90
}
91
92
bool WatchItemWindow::Exec() {
93
return DialogBoxParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_CPUWATCH), parentHwnd_, StaticDlgFunc, (LPARAM)this) != 0;
94
}
95
96
static bool IsControlChecked(HWND hWnd, int id) {
97
return SendMessage(GetDlgItem(hWnd, id), BM_GETCHECK, 0, 0) != 0;
98
}
99
100
bool WatchItemWindow::FetchDialogData(HWND hwnd) {
101
wchar_t textValue[512];
102
103
GetWindowTextW(GetDlgItem(hwnd, IDC_BREAKPOINT_ADDRESS), textValue, ARRAY_SIZE(textValue));
104
name_ = ConvertWStringToUTF8(textValue);
105
106
GetWindowTextW(GetDlgItem(hwnd, IDC_BREAKPOINT_CONDITION), textValue, ARRAY_SIZE(textValue));
107
expression_ = ConvertWStringToUTF8(textValue);
108
PostfixExpression compiled;
109
if (!cpu_->initExpression(expression_.c_str(), compiled)) {
110
char errorMessage[512];
111
snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", expression_.c_str(), getExpressionError());
112
MessageBoxA(hwnd, errorMessage, "Error", MB_OK);
113
return false;
114
}
115
116
if (IsControlChecked(hwnd, IDC_DISASM_FMT_HEX))
117
format_ = WatchFormat::HEX;
118
else if (IsControlChecked(hwnd, IDC_DISASM_FMT_INT))
119
format_ = WatchFormat::INT;
120
else if (IsControlChecked(hwnd, IDC_DISASM_FMT_FLOAT))
121
format_ = WatchFormat::FLOAT;
122
else if (IsControlChecked(hwnd, IDC_DISASM_FMT_STR))
123
format_ = WatchFormat::STR;
124
125
return true;
126
}
127
128