-
Notifications
You must be signed in to change notification settings - Fork 10
/
r4300iMemory.cpp
360 lines (323 loc) · 9.81 KB
/
r4300iMemory.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
* Project 64 - A Nintendo 64 emulator.
*
* (c) Copyright 2001 zilmar ([email protected]) and
* Jabo ([email protected]).
*
* pj64 homepage: www.pj64.net
*
* Permission to use, copy, modify and distribute Project64 in both binary and
* source form, for non-commercial purposes, is hereby granted without fee,
* providing that this license information and copyright notice appear with
* all copies and any derived work.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event shall the authors be held liable for any damages
* arising from the use of this software.
*
* Project64 is freeware for PERSONAL USE only. Commercial users should
* seek permission of the copyright holders first. Commercial use includes
* charging money for Project64 or software derived from Project64.
*
* The copyright holders request that bug fixes and improvements to the code
* should be forwarded to them so if they want them.
*
*/
#if (!defined(EXTERNAL_RELEASE))
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "main.h"
#include "CPU.h"
#include "debugger.h"
#include "resource.h"
#define IDC_VADDR 0x100
#define IDC_PADDR 0x101
#define IDC_LIST_VIEW 0x102
#define IDC_SCRL_BAR 0x103
void Setup_Memory_Window (HWND hDlg);
LRESULT CALLBACK Memory_Window_Proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static HWND Memory_Win_hDlg, hAddrEdit, hVAddr, hPAddr, hList, hScrlBar;
static int InMemoryWindow = FALSE;
void Create_Memory_Window ( int Child ) {
DWORD ThreadID;
if ( Child ) {
InMemoryWindow = TRUE;
DialogBox( hInst, "MEMORY", NULL,(DLGPROC) Memory_Window_Proc );
InMemoryWindow = FALSE;
} else {
if (!InMemoryWindow) {
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Create_Memory_Window,
(LPVOID)TRUE,0, &ThreadID);
} else {
SetForegroundWindow(Memory_Win_hDlg);
}
}
}
void __cdecl Enter_Memory_Window ( void ) {
if (!HaveDebugger) { return; }
Create_Memory_Window ( FALSE );
}
void Insert_MemoryLineDump (unsigned int location, int InsertPos) {
char Output[20], Hex[60], Ascii[20], HexAddOn[15], AsciiAddOn[15], OldText[100];
LV_ITEM item, OldItem;
int count;
MIPS_WORD word;
location = location << 4;
item.mask = LVIF_TEXT | LVIF_PARAM;
item.iItem = InsertPos;
item.lParam = location;
sprintf(Output,"0x%08X",location);
item.pszText = Output;
item.iSubItem = 0;
OldItem.mask = LVIF_TEXT | LVIF_PARAM;
OldItem.iItem = InsertPos;
OldItem.pszText = OldText;
OldItem.cchTextMax = sizeof( OldText )-1;
OldItem.iSubItem = 0;
if (ListView_GetItemCount(hList) <= InsertPos) {
ListView_InsertItem(hList,&item);
} else {
ListView_GetItem(hList,&OldItem);
if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) {
ListView_SetItem(hList,&item);
}
}
sprintf(Hex,"\0"); sprintf(Ascii,"\0");
__try {
if ( SendMessage(hVAddr,BM_GETSTATE,0,0) & BST_CHECKED != 0 ) {
for (count = 0; count < 4; count ++) {
if (r4300i_LW_VAddr(location, &word.UW)) {
sprintf(HexAddOn,"%02X %02X %02X %02X",word.UB[3],
word.UB[2],word.UB[1],word.UB[0]);
sprintf(AsciiAddOn,"0x%08X",word.UW);
sprintf(AsciiAddOn,"%c%c%c%c",
word.UB[3]==0 ? ' ':word.UB[3],
word.UB[2]==0 ? ' ':word.UB[2],
word.UB[1]==0 ? ' ':word.UB[1],
word.UB[0]==0 ? ' ':word.UB[0]);
} else {
strcpy(HexAddOn,"** ** ** **");
strcpy(AsciiAddOn,"****");
}
if (count != 3) {
strcat(HexAddOn,"-");
}
strcat(Hex,HexAddOn);
strcat(Ascii,AsciiAddOn);
location += 4;
}
} else {
for (count = 0; count < 4; count ++) {
if (location < 0x1FFFFFFC) {
r4300i_LW_PAddr(location, &word.UW);
sprintf(HexAddOn,"%02X %02X %02X %02X",word.UB[3],
word.UB[2],word.UB[1],word.UB[0]);
sprintf(AsciiAddOn,"0x%08X",word.UW);
sprintf(AsciiAddOn,"%c%c%c%c",
word.UB[3]==0 ? ' ':word.UB[3],
word.UB[2]==0 ? ' ':word.UB[2],
word.UB[1]==0 ? ' ':word.UB[1],
word.UB[0]==0 ? ' ':word.UB[0]);
} else {
strcpy(HexAddOn,"** ** ** **");
strcpy(AsciiAddOn,"****");
}
if (count != 3) {
strcat(HexAddOn,"-");
}
strcat(Hex,HexAddOn);
strcat(Ascii,AsciiAddOn);
location += 4;
}
}
} __except( r4300i_Command_MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) {
DisplayError(GS(MSG_UNKNOWN_MEM_ACTION));
PostQuitMessage(0);
}
item.mask = LVIF_TEXT;
item.pszText = Hex;
item.iSubItem = 1;
OldItem.mask = LVIF_TEXT;
OldItem.iSubItem = 1;
ListView_GetItem(hList,&OldItem);
if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) {
ListView_SetItem(hList,&item);
}
item.pszText = Ascii;
item.iSubItem = 2;
OldItem.iSubItem = 2;
ListView_GetItem(hList,&OldItem);
if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) {
ListView_SetItem(hList,&item);
}
}
LRESULT CALLBACK Memory_Window_Proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
RECT rcBox;
switch (uMsg) {
case WM_INITDIALOG:
Memory_Win_hDlg = hDlg;
Setup_Memory_Window ( hDlg );
break;
case WM_MOVE:
if (IsIconic(hDlg)) { break; }
StoreCurrentWinPos("Memory",hDlg);
break;
case WM_PAINT:
BeginPaint( hDlg, &ps );
SelectObject(ps.hdc, GetStockObject(ANSI_FIXED_FONT));
SetBkMode( ps.hdc, TRANSPARENT );
TextOut(ps.hdc,25,17,"Address:",8);
rcBox.left = 5;
rcBox.top = 5;
rcBox.right = 666;
rcBox.bottom = 310;
DrawEdge( ps.hdc, &rcBox, EDGE_RAISED, BF_RECT );
rcBox.left = 8;
rcBox.top = 8;
rcBox.right = 663;
rcBox.bottom = 307;
DrawEdge( ps.hdc, &rcBox, EDGE_ETCHED, BF_RECT );
EndPaint( hDlg, &ps );
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_ADDR_EDIT:
if (HIWORD(wParam) == EN_CHANGE ) {
Refresh_Memory();
}
break;
case IDC_VADDR:
case IDC_PADDR:
Refresh_Memory();
break;
case IDC_CLOSE_BUTTON:
case IDCANCEL:
EndDialog( hDlg, IDCANCEL );
break;
}
case WM_VSCROLL:
if ((HWND)lParam == hScrlBar) {
unsigned int location;
char Value[20];
GetWindowText(hAddrEdit,Value,sizeof(Value));
location = AsciiToHex(Value);
switch (LOWORD(wParam)) {
case SB_LINEDOWN:
if (location < 0xFFFFFFEF) {
sprintf(Value,"%08X",location + 0x10);
SetWindowText(hAddrEdit,Value);
} else {
sprintf(Value,"%08X",0xFFFFFFFF);
SetWindowText(hAddrEdit,Value);
}
break;
case SB_LINEUP:
if (location > 0x10 ) {
sprintf(Value,"%08X",location - 0x10);
SetWindowText(hAddrEdit,Value);
} else {
sprintf(Value,"%08X",0);
SetWindowText(hAddrEdit,Value);
}
break;
case SB_PAGEDOWN:
if (location < 0xFFFFFEFF) {
sprintf(Value,"%08X",location + 0x100);
SetWindowText(hAddrEdit,Value);
} else {
sprintf(Value,"%08X",0xFFFFFFFF);
SetWindowText(hAddrEdit,Value);
}
break;
case SB_PAGEUP:
if (location > 0x100 ) {
sprintf(Value,"%08X",location - 0x100);
SetWindowText(hAddrEdit,Value);
} else {
sprintf(Value,"%08X",0);
SetWindowText(hAddrEdit,Value);
}
break;
}
}
break;
default:
return FALSE;
}
return TRUE;
}
void __cdecl Refresh_Memory ( void ) {
DWORD location;
char Value[20];
int count;
if (InMemoryWindow == FALSE) { return; }
GetWindowText(hAddrEdit,Value,sizeof(Value));
location = (AsciiToHex(Value) >> 4);
if (location > 0x0FFFFFF0) { location = 0x0FFFFFF0; }
for (count = 0 ; count < 16;count ++ ){
Insert_MemoryLineDump ( count + location , count );
}
}
void Setup_Memory_Window (HWND hDlg) {
#define WindowWidth 683
#define WindowHeight 341
DWORD X, Y;
hVAddr = CreateWindowEx(0,"BUTTON", "Virtual Addressing", WS_CHILD | WS_VISIBLE |
BS_AUTORADIOBUTTON, 215,13,150,21,hDlg,(HMENU)IDC_VADDR,hInst,NULL );
SendMessage(hVAddr,BM_SETCHECK, BST_CHECKED,0);
hPAddr = CreateWindowEx(0,"BUTTON", "Physical Addressing", WS_CHILD | WS_VISIBLE |
BS_AUTORADIOBUTTON, 375,13,155,21,hDlg,(HMENU)IDC_PADDR,hInst,NULL );
hList = CreateWindowEx(WS_EX_CLIENTEDGE,WC_LISTVIEW, "", WS_CHILD | WS_VISIBLE |
/*LVS_OWNERDRAWFIXED | */ LVS_REPORT | LVS_NOSORTHEADER, 14,39,622,261,hDlg,
(HMENU)IDC_LIST_VIEW,hInst,NULL );
if (hList) {
LV_COLUMN col;
int count;
col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
col.fmt = LVCFMT_LEFT;
col.pszText = "Address";
col.cx = 90;
col.iSubItem = 0;
ListView_InsertColumn ( hList, 0, &col);
col.pszText = "Memory Dump";
col.cx = 390;
col.iSubItem = 1;
ListView_InsertColumn ( hList, 1, &col);
col.cx = 140;
col.pszText = "Memory Ascii";
col.iSubItem = 2;
ListView_InsertColumn ( hList, 2, &col);
ListView_SetItemCount ( hList, 16);
SendMessage(hList,WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT),0);
for (count = 0 ; count < 16;count ++ ){
Insert_MemoryLineDump (count,count);
}
}
SetWindowPos(GetDlgItem(hDlg,IDC_CLOSE_BUTTON),NULL, 560,13,90,21, SWP_NOZORDER |
SWP_SHOWWINDOW);
hAddrEdit = GetDlgItem(hDlg,IDC_ADDR_EDIT);
SetWindowText(hAddrEdit,"00000000");
SendMessage(hAddrEdit,EM_SETLIMITTEXT,(WPARAM)8,(LPARAM)0);
SetWindowPos(hAddrEdit,NULL, 100,13,100,21, SWP_NOZORDER | SWP_SHOWWINDOW);
SendMessage(hAddrEdit,WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT),0);
hScrlBar = CreateWindowEx(WS_EX_STATICEDGE, "SCROLLBAR","", WS_CHILD | WS_VISIBLE |
WS_TABSTOP | SBS_VERT, 635,39,18,260, hDlg, (HMENU)IDC_SCRL_BAR, hInst, NULL );
if (hScrlBar) {
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
si.nMin = 0;
si.nMax = 300;
si.nPos = 145;
si.nPage = 10;
SetScrollInfo(hScrlBar,SB_CTL,&si,TRUE);
}
if ( !GetStoredWinPos( "Memory", &X, &Y ) ) {
X = (GetSystemMetrics( SM_CXSCREEN ) - WindowWidth) / 2;
Y = (GetSystemMetrics( SM_CYSCREEN ) - WindowHeight) / 2;
}
SetWindowPos(hDlg,NULL,X,Y,WindowWidth,WindowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
}
#endif