-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMMUMonitor.cpp
275 lines (234 loc) · 7 KB
/
MMUMonitor.cpp
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// This file is part of VCC (Virtual Color Computer).
//
// VCC (Virtual Color Computer) 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.
//
// VCC (Virtual Color Computer) 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 VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
//
// Processor State Display - Part of the Debugger package for VCC
// Authors: Mike Rojas, Chet Simpson
#include "MMUMonitor.h"
#include "Debugger.h"
#include "DebuggerUtils.h"
#include "defines.h"
#include "tcc1014mmu.h"
#include "resource.h"
#include <string>
#include <stdexcept>
namespace VCC { namespace Debugger { namespace UI { namespace
{
// Color constants
const COLORREF rgbBlack = RGB( 0, 0, 0);
const COLORREF rgbViolet = RGB(100, 0, 170);
const COLORREF rgbGray = RGB(120, 120, 120);
CriticalSection Section_;
MMUState MMUState_;
HWND MMUMonitorWindow = NULL;
HWND hWndMMUMonitor;
BackBufferInfo BackBuffer_;
class MMUMonitorDebugClient : public Client
{
public:
void OnReset() override {
}
void OnUpdate() override {
SectionLocker lock(Section_);
MMUState_ = GetMMUState();
}
};
// Convert unsigned int to uppercase hex string
std::string HexUpc(long value,unsigned int width)
{
return ToHexString(value, width, true);
}
// Draw string centered in rectangle width w, height 20
// x,y set the top left corner of the centering box
void PutText(HDC hdc,int x,int y,int w,std::string s)
{
RECT rc;
SetRect( &rc, x, y, x + w, y + 20);
DrawText( hdc, s.c_str(), s.size(), &rc,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
// Draw a visible box
void MakeBox(HDC hdc,HPEN pen,int x,int y,int w,int h)
{
SelectObject(hdc, pen);
MoveToEx(hdc, x, y, NULL);
LineTo(hdc, x + w, y);
LineTo(hdc, x + w, y + h);
LineTo(hdc, x, y + h);
LineTo(hdc, x, y);
}
// Set draw color per task number
void SetTaskColor(HDC hdc,int Task,COLORREF Tsk0,COLORREF Tsk1)
{
if (Task==1) {
SetTextColor(hdc, Tsk1);
} else {
SetTextColor(hdc, Tsk0);
}
}
// Draw the Monitor Window
void DrawMMUMonitor(HDC hdc, LPRECT clientRect)
{
RECT rect = *clientRect;
// Clear background.
HBRUSH brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
FillRect(hdc, &rect, brush);
HPEN pen = (HPEN)CreatePen(PS_SOLID, 1, rgbGray);
HPEN thickPen = (HPEN)CreatePen(PS_SOLID, 2, rgbGray);
HFONT hFont = CreateFont(14, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY,
FIXED_PITCH, TEXT("Consolas"));
SelectObject(hdc, hFont);
// Quick pull out MMU state
MMUState regs;
{
SectionLocker lock(Section_);
regs = MMUState_;
}
// X,Y position for MMU registers
int x = rect.left + 4;
int y = rect.top + 4;
// Header
SetTextColor(hdc, rgbBlack);
PutText(hdc,x+4, y,80,"Real");
PutText(hdc,x+71 ,y,40,"MAP 0");
PutText(hdc,x+121,y,80,"CPU Memory");
PutText(hdc,x+212,y,40,"MAP 1");
PutText(hdc,x+239,y,80,"Real");
// Rows
for (int n = 0; n < 8; n++)
{
// Y position for row
y += 20;
// Map 0 Real Memory
SetTaskColor(hdc,regs.ActiveTask,rgbViolet,rgbGray);
PutText(hdc,x+14,y,60,HexUpc(regs.Task0[n]*8192,6));
// Map 0 Box
MakeBox(hdc,pen,x+76,y+1,30,16);
SetTaskColor(hdc,regs.ActiveTask,rgbBlack,rgbGray);
PutText(hdc,x+76,y,30,HexUpc(regs.Task0[n],2));
// CPU memory
SetTextColor(hdc, rgbViolet);
PutText(hdc,x+131,y,60,HexUpc(n * 8192,4));
// Map 1 Box
MakeBox(hdc,pen,x+216,y+1,30,16);
SetTaskColor(hdc,regs.ActiveTask,rgbGray,rgbBlack);
PutText(hdc,x+216,y,30,HexUpc(regs.Task1[n],2));
// Map 1 Real Memory
SetTaskColor(hdc,regs.ActiveTask,rgbGray,rgbViolet);
PutText(hdc,x+248,y,60,HexUpc(regs.Task1[n]*8192,6));
// Active task indicator arrows
SelectObject(hdc, thickPen);
int dx = (regs.ActiveTask == 0) ? x : x+66;
PutText(hdc,dx+115,y,5,"<");
MoveToEx(hdc,dx+120,y+10, NULL);
LineTo(hdc,dx+135,y+10);
PutText(hdc,dx+137,y,5,">");
}
// Position for the Control bits
x = rect.left + 3;
y = rect.top + 190;
// MMU Enable bit
SetTextColor(hdc,rgbViolet);
PutText(hdc,x,y,130,"FF90:b6 Enable ");
MakeBox(hdc,pen,x+130,y+2,20,16);
SetTextColor(hdc,rgbBlack);
PutText(hdc,x+130,y,20,std::to_string(regs.Enabled));
// MMU task bit
SetTextColor(hdc,rgbViolet);
PutText(hdc,x,y+20,130,"FF91:b0 MMU Task");
MakeBox(hdc,pen,x+130,y+22,20,16);
SetTextColor(hdc,rgbBlack);
PutText(hdc,x+130,y+20,20,std::to_string(regs.ActiveTask));
// X position for second column control bits
x = rect.left + 164;
// Ram Vectors
SetTextColor(hdc,rgbViolet);
PutText(hdc,x,y,140, "FF90:b3 RAM Vector");
MakeBox(hdc,pen,x+140,y+2,20,16);
SetTextColor(hdc,rgbBlack);
PutText(hdc,x+140,y,20,std::to_string(regs.RamVectors));
// Rom Mapping
SetTextColor(hdc,rgbViolet);
PutText(hdc,x,y+20,140,"FF90:b1-0 ROM Map ");
MakeBox(hdc,pen,x+140,y+22,20,16);
SetTextColor(hdc,rgbBlack);
PutText(hdc,x+140,y+20,20,std::to_string(regs.RomMap));
// Cleanup.
DeleteObject(pen);
DeleteObject(thickPen);
DeleteObject(hFont);
}
INT_PTR CALLBACK MMUMonitorDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
{
switch (message)
{
case WM_INITDIALOG:
{
hWndMMUMonitor = hDlg;
RECT Rect;
GetClientRect(hDlg, &Rect);
BackBuffer_ = AttachBackBuffer(hDlg, 0, -36);
SetTimer(hDlg, IDT_PROC_TIMER, 64, (TIMERPROC)NULL);
EmuState.Debugger.RegisterClient(hDlg, std::make_unique<MMUMonitorDebugClient>());
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hDlg, &ps);
DrawMMUMonitor(BackBuffer_.DeviceContext, &BackBuffer_.Rect);
BitBlt(hdc, 0, 0, BackBuffer_.Width, BackBuffer_.Height, BackBuffer_.DeviceContext, 0, 0, SRCCOPY);
EndPaint(hDlg, &ps);
break;
}
case WM_TIMER:
switch (wParam)
{
case IDT_PROC_TIMER:
InvalidateRect(hDlg, &BackBuffer_.Rect, FALSE);
return 0;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCLOSE:
case WM_DESTROY:
KillTimer(hDlg, IDT_PROC_TIMER);
DeleteDC(BackBuffer_.DeviceContext);
DestroyWindow(hDlg);
MMUMonitorWindow = NULL;
EmuState.Debugger.RemoveClient(hDlg);
break;
}
break;
}
return FALSE;
}
} } } }
void VCC::Debugger::UI::OpenMMUMonitorWindow(HINSTANCE instance, HWND parent)
{
if (MMUMonitorWindow == NULL)
{
MMUMonitorWindow = CreateDialog(
instance,
MAKEINTRESOURCE(IDD_MMU_MONITOR),
parent,
MMUMonitorDlgProc);
ShowWindow(MMUMonitorWindow, SW_SHOWNORMAL);
}
SetFocus(MMUMonitorWindow);
}