-
Notifications
You must be signed in to change notification settings - Fork 10
/
BreakPoints.cpp
530 lines (467 loc) · 14.8 KB
/
BreakPoints.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/*
* 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 "plugin.h"
#define IDC_LIST 100
#define IDC_TAB_CONTROL 101
#define IDC_REMOVE_BUTTON 103
#define IDC_REMOVEALL_BUTTON 104
#define IDC_LOCATION_EDIT 105
#define IDC_FUNCTION_COMBO 106
void BPoint_AddButtonPressed ( void);
void Create_BPoint_Window ( int );
void DrawBPItem ( LPARAM );
void HideBPointPanel ( int Panel);
void Paint_BPoint_Win ( HWND );
void __cdecl RefreshBreakPoints (void);
void Setup_BPoint_Win ( HWND );
void ShowBPointPanel ( int Panel);
LRESULT CALLBACK BPoint_Proc ( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK RefreshBPProc ( HWND, UINT, WPARAM, LPARAM );
static HWND BPoint_Win_hDlg, hTab, hList, hStatic, hR4300iLocation, hFunctionlist,
hAddButton, hRemoveButton, hRemoveAllButton;
static BOOL InBPWindow = FALSE;
static FARPROC RefProc;
int RSPBP_count;
int Add_R4300iBPoint( DWORD Location, int Confirm ) {
int count;
if (NoOfBpoints == MaxBPoints) {
DisplayError("Max amount of Break Points set");
return FALSE;
}
for (count = 0; count < NoOfBpoints; count ++) {
if (BPoint[count].Location == Location) {
DisplayError("You already have this Break Point");
return FALSE;
}
}
if (Confirm) {
char Message[150], Label[100];
int Response;
sprintf(Label,"%s", LabelName(Location));
sprintf(Message,"0x%08X", Location);
if(strcmp(Label,Message) == 0) {
sprintf(Message,"Break when:\n\nR4300i's Program Counter = 0x%08X\n\nIs this correct?",
Location);
} else {
sprintf(Message,"Break on:\n\n%s (R4300i PC = 0x%08X)\n\nIs this correct?",
Label, Location);
}
Response = MessageBox(BPoint_Win_hDlg, Message, AppName, MB_YESNO | MB_ICONINFORMATION);
if (Response == IDNO) {
return FALSE;
}
}
BPoint[NoOfBpoints].Location = Location;
NoOfBpoints += 1;
RefreshBreakPoints();
/*if (CPU_Action.Stepping || hMipsCPU == NULL) {
ClearAllx86Code();
} else {
CPU_Action.ResetX86Code = TRUE;
CPU_Action.do_or_check_something += 1;
}*/
return TRUE;
}
void BPoint_AddButtonPressed (void) {
DWORD Selected, Location;
char Title[10];
TC_ITEM item;
item.mask = TCIF_PARAM;
TabCtrl_GetItem( hTab, TabCtrl_GetCurSel( hTab ), &item );
switch( item.lParam ) {
case R4300i_BP:
GetWindowText(hR4300iLocation,Title,sizeof(Title));
if (!Add_R4300iBPoint(AsciiToHex(Title),TRUE )) {
SendMessage(hR4300iLocation,EM_SETSEL,(WPARAM)0,(LPARAM)-1);
SetFocus(hR4300iLocation);
}
break;
case R4300i_FUNCTION:
Selected = SendMessage(hFunctionlist,CB_GETCURSEL,0,0);
Location = SendMessage(hFunctionlist,CB_GETITEMDATA,(WPARAM)Selected,0);
Add_R4300iBPoint(Location,TRUE );
SetFocus(hFunctionlist);
break;
case RSP_BP:
if (RspDebug.UseBPoints) { RspDebug.Add_BPoint(); }
break;
}
}
LRESULT CALLBACK BPoint_Proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static RECT rcDisp;
static int CurrentPanel = R4300i_BP;
int selected;
TC_ITEM item;
switch (uMsg) {
case WM_INITDIALOG:
BPoint_Win_hDlg = hDlg;
Setup_BPoint_Win( hDlg );
RefreshBreakPoints();
break;
case WM_MOVE:
StoreCurrentWinPos("Break Point",hDlg);
break;
case WM_SIZE:
GetClientRect( hDlg, &rcDisp);
TabCtrl_AdjustRect( hTab, FALSE, &rcDisp );
break;
case WM_PAINT:
Paint_BPoint_Win( hDlg );
return TRUE;
case WM_NOTIFY:
switch (((NMHDR *)lParam)->code) {
case TCN_SELCHANGE:
InvalidateRect( hTab, &rcDisp, TRUE );
HideBPointPanel (CurrentPanel);
item.mask = TCIF_PARAM;
TabCtrl_GetItem( hTab, TabCtrl_GetCurSel( hTab ), &item );
CurrentPanel = item.lParam;
InvalidateRect( hStatic, NULL, FALSE );
ShowBPointPanel ( CurrentPanel );
break;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
BPoint_AddButtonPressed();
break;
case IDC_REMOVE_BUTTON:
selected = SendMessage(hList,LB_GETCURSEL,0,0);
if (selected < NoOfBpoints) {
DWORD location;
location = SendMessage(hList,LB_GETITEMDATA,selected,0);
RemoveR4300iBreakPoint(location);
break;
}
selected -= NoOfBpoints;
if (selected < RSPBP_count) {
RspDebug.RemoveBpoint(hList,SendMessage(hList,LB_GETCURSEL,0,0));
break;
}
DisplayError("what is this BP");
break;
case IDC_REMOVEALL_BUTTON:
NoOfBpoints = 0;
if (RspDebug.UseBPoints) { RspDebug.RemoveAllBpoint(); }
RefreshBreakPoints();
RefreshR4300iCommands();
break;
case IDCANCEL:
CurrentPanel = R4300i_BP;
EndDialog( hDlg, IDCANCEL );
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
int CheckForR4300iBPoint ( DWORD Location ) {
int count;
for (count = 0; count < NoOfBpoints; count ++){
if (BPoint[count].Location == Location) {
return TRUE;
}
}
return FALSE;
}
void Create_BPoint_Window (int Child) {
DWORD ThreadID;
if (Child) {
InBPWindow = TRUE;
DialogBox( hInst, "BLANK", NULL,(DLGPROC) BPoint_Proc );
InBPWindow = FALSE;
} else {
if (!InBPWindow) {
CloseHandle(CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Create_BPoint_Window,
(LPVOID)TRUE,0, &ThreadID));
} else {
BringWindowToTop(BPoint_Win_hDlg);
}
}
}
void __cdecl Enter_BPoint_Window ( void ) {
Create_BPoint_Window ( FALSE );
}
void HideBPointPanel ( int Panel) {
switch( Panel ) {
case R4300i_BP: ShowWindow(hR4300iLocation, FALSE); break;
case R4300i_FUNCTION: ShowWindow(hFunctionlist, FALSE); break;
case RSP_BP: if (RspDebug.UseBPoints) { RspDebug.HideBPPanel(); } break;
}
}
void Paint_BPoint_Win (HWND hDlg) {
RECT rcBox;
PAINTSTRUCT ps;
HFONT hOldFont;
int OldBkMode;
BeginPaint( hDlg, &ps );
rcBox.left = 5;
rcBox.top = 175;
rcBox.right = 255;
rcBox.bottom = 290;
DrawEdge( ps.hdc, &rcBox, EDGE_RAISED, BF_RECT );
rcBox.left = 8;
rcBox.top = 178;
rcBox.right = 252;
rcBox.bottom = 287;
DrawEdge( ps.hdc, &rcBox, EDGE_ETCHED, BF_RECT );
hOldFont = SelectObject(ps.hdc,GetStockObject(DEFAULT_GUI_FONT));
OldBkMode = SetBkMode( ps.hdc, TRANSPARENT );
TextOut( ps.hdc, 9,159,"Breakpoints: ",13);
SelectObject( ps.hdc,hOldFont );
SetBkMode( ps.hdc, OldBkMode );
EndPaint( hDlg, &ps );
}
void __cdecl RefreshBreakPoints (void) {
char Message[100];
int count;
if (!InBPWindow) { return; }
SendMessage(hList,LB_RESETCONTENT,0,0);
for (count = 0; count < NoOfBpoints; count ++ ) {
sprintf(Message," at 0x%08X (r4300i)", BPoint[count].Location);
SendMessage(hList,LB_ADDSTRING,0,(LPARAM)Message);
SendMessage(hList,LB_SETITEMDATA,count,(LPARAM)BPoint[count].Location);
}
count = SendMessage(hList,LB_GETCOUNT,0,0);
if (RspDebug.UseBPoints) { RspDebug.RefreshBpoints(hList); }
RSPBP_count = SendMessage(hList,LB_GETCOUNT,0,0) - count;
if (SendMessage(hList,LB_GETCOUNT,0,0) > 0) {
EnableWindow( hRemoveButton, TRUE );
EnableWindow( hRemoveAllButton, TRUE );
}
}
LRESULT CALLBACK RefreshBPProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
PAINTSTRUCT ps;
RECT rcBox;
HFONT hOldFont;
int OldBkMode;
TC_ITEM item;
switch( uMsg ) {
case WM_PAINT:
BeginPaint( hWnd, &ps );
rcBox.left = 15;
rcBox.top = 40;
rcBox.right = 235;
rcBox.bottom = 125;
DrawEdge( ps.hdc, &rcBox, EDGE_ETCHED, BF_RECT );
hOldFont = SelectObject( ps.hdc,
GetStockObject(DEFAULT_GUI_FONT) );
OldBkMode = SetBkMode( ps.hdc, TRANSPARENT );
item.mask = TCIF_PARAM;
TabCtrl_GetItem( hTab, TabCtrl_GetCurSel( hTab ), &item );
switch (item.lParam) {
case R4300i_BP:
TextOut( ps.hdc, 29,60,"Break when the Program Counter equals",37);
TextOut( ps.hdc, 59,85,"0x",2);
break;
case R4300i_FUNCTION:
TextOut( ps.hdc, 75,60,"Break on label:",15);
break;
case RSP_BP:
if (RspDebug.UseBPoints) { RspDebug.PaintBPPanel(ps); }
break;
}
SelectObject( ps.hdc,hOldFont );
SetBkMode( ps.hdc, OldBkMode );
EndPaint( hWnd, &ps );
break;
default:
return( (*RefProc)(hWnd, uMsg, wParam, lParam) );
}
return( FALSE );
}
void RemoveR4300iBreakPoint (DWORD Location) {
int count, location = -1;
for (count = 0; count < NoOfBpoints; count ++){
if (BPoint[count].Location == Location) {
location = count;
count = NoOfBpoints;
}
}
if (location >= 0) {
for (count = location; count < NoOfBpoints - 1; count ++ ){
BPoint[count].Location = BPoint[count + 1].Location;
}
NoOfBpoints -= 1;
RefreshBreakPoints ();
}
/*if (CPU_Action.Stepping || hMipsCPU == NULL) {
ClearAllx86Code();
} else {
CPU_Action.ResetX86Code = TRUE;
CPU_Action.do_or_check_something += 1;
}*/
}
void Setup_BPoint_Win (HWND hDlg) {
#define WindowWidth 350
#define WindowHeight 320
DWORD X, Y;
hAddButton = CreateWindowEx(0,"BUTTON","&Add",
BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
262,26,75,22,hDlg,(HMENU)IDOK,
hInst,NULL );
if ( hAddButton ) {
SendMessage(hAddButton,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
}
hRemoveButton = CreateWindowEx(0,"BUTTON","&Remove",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE | WS_TABSTOP |
WS_DISABLED,262,177,75,22,hDlg,(HMENU)IDC_REMOVE_BUTTON,
hInst,NULL );
if ( hRemoveButton ) {
SendMessage(hRemoveButton,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
}
hRemoveAllButton = CreateWindowEx(0,"BUTTON","Remove A&ll", WS_CHILD |
BS_PUSHBUTTON | WS_VISIBLE | WS_TABSTOP | WS_DISABLED,262,202,75,22,hDlg,
(HMENU)IDC_REMOVEALL_BUTTON,hInst,NULL );
if ( hRemoveAllButton ) {
SendMessage(hRemoveAllButton,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
}
hTab = CreateWindowEx(0,WC_TABCONTROL,"", WS_CHILD | WS_TABSTOP | WS_VISIBLE,
5,6,250,150,hDlg,(HMENU)IDC_TAB_CONTROL,hInst,NULL );
if (hTab) {
TC_ITEM item;
SendMessage(hTab, WM_SETFONT, (WPARAM)GetStockObject( DEFAULT_GUI_FONT ), 0 );
item.mask = TCIF_TEXT | TCIF_PARAM;
item.pszText = " R4300i ";
item.lParam = R4300i_BP;
TabCtrl_InsertItem( hTab,0, &item);
if (NoOfMapEntries != 0) {
item.mask = TCIF_TEXT | TCIF_PARAM;
item.pszText = " Function ";
item.lParam = R4300i_FUNCTION;
TabCtrl_InsertItem( hTab,1, &item);
}
if (RspDebug.UseBPoints) {
RECT rcBox;
rcBox.left = 15; rcBox.top = 40;
rcBox.right = 235; rcBox.bottom = 125;
item.mask = TCIF_TEXT | TCIF_PARAM;
item.pszText = RspDebug.BPPanelName;
item.lParam = RSP_BP;
TabCtrl_InsertItem( hTab,2, &item);
RspDebug.CreateBPPanel(hDlg,rcBox);
}
}
hR4300iLocation = CreateWindowEx(0,"EDIT","", WS_CHILD | WS_VISIBLE | WS_BORDER |
ES_UPPERCASE | WS_TABSTOP,83,90,100,17,hDlg,(HMENU)IDC_LOCATION_EDIT,hInst,NULL);
if (hR4300iLocation) {
char Title[20];
SendMessage(hR4300iLocation,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
SendMessage(hR4300iLocation,EM_SETLIMITTEXT,(WPARAM)8,(LPARAM)0);
sprintf(Title,"%08X",PROGRAM_COUNTER);
SetWindowText(hR4300iLocation,Title);
}
hFunctionlist = CreateWindowEx(0,"COMBOBOX","", WS_CHILD | WS_VSCROLL |
CBS_DROPDOWNLIST | CBS_SORT | WS_TABSTOP,55,90,150,150,hDlg,
(HMENU)IDC_FUNCTION_COMBO,hInst,NULL);
if (hFunctionlist) {
DWORD count, pos;
SendMessage(hFunctionlist,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
for (count = 0; count < NoOfMapEntries; count ++ ) {
pos = SendMessage(hFunctionlist,CB_ADDSTRING,(WPARAM)0,(LPARAM)MapTable[count].Label);
SendMessage(hFunctionlist,CB_SETITEMDATA,(WPARAM)pos,(LPARAM)MapTable[count].VAddr);
}
SendMessage(hFunctionlist,CB_SETCURSEL,(WPARAM)1,(LPARAM)0);
}
hList = CreateWindowEx(WS_EX_STATICEDGE, "LISTBOX","", WS_CHILD | WS_VISIBLE | LBS_DISABLENOSCROLL |WS_VSCROLL,
16,187,228,112, hDlg, (HMENU)IDC_LIST, hInst,NULL );
if ( hList) {
SendMessage(hList,WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
}
hStatic = CreateWindowEx(0,"STATIC","", WS_CHILD | WS_VISIBLE, 5,6,250,150,hDlg,0,hInst,NULL );
RefProc = (FARPROC)SetWindowLong( hStatic,GWL_WNDPROC,(long)RefreshBPProc);
SetWindowText(hDlg," Breakpoints");
if ( !GetStoredWinPos( "Break Point", &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);
}
void ShowBPointPanel ( int Panel) {
switch( Panel ) {
case R4300i_BP: ShowWindow(hR4300iLocation, TRUE); break;
case R4300i_FUNCTION: ShowWindow(hFunctionlist, TRUE); break;
case RSP_BP: if (RspDebug.UseBPoints) { RspDebug.ShowBPPanel(); } break;
}
}
void UpdateBPointGUI (void) {
TC_ITEM item;
DWORD count;
if (!InBPWindow) { return; }
if (TabCtrl_GetCurSel(hTab) != 0) {
InvalidateRect( hTab, NULL, TRUE );
item.mask = TCIF_PARAM;
TabCtrl_GetItem( hTab, TabCtrl_GetCurSel( hTab ), &item );
HideBPointPanel (item.lParam);
TabCtrl_SetCurSel(hTab, 0);
TabCtrl_GetItem( hTab, TabCtrl_GetCurSel( hTab ), &item );
InvalidateRect( hStatic, NULL, FALSE );
ShowBPointPanel ( item.lParam );
}
for (count = TabCtrl_GetItemCount(hTab); count > 1; count--) {
TabCtrl_DeleteItem(hTab, count - 1);
}
if (NoOfMapEntries > 0) {
item.mask = TCIF_TEXT | TCIF_PARAM;
item.pszText = " Function ";
item.lParam = R4300i_FUNCTION;
TabCtrl_InsertItem( hTab,1, &item);
}
if (RspDebug.UseBPoints) {
RECT rcBox;
rcBox.left = 15; rcBox.top = 40;
rcBox.right = 235; rcBox.bottom = 125;
item.mask = TCIF_TEXT | TCIF_PARAM;
item.pszText = RspDebug.BPPanelName;
item.lParam = RSP_BP;
TabCtrl_InsertItem( hTab,2, &item);
RspDebug.CreateBPPanel(BPoint_Win_hDlg, rcBox);
}
InvalidateRect( BPoint_Win_hDlg, NULL, TRUE );
RefreshBreakPoints ();
}
void UpdateBP_FunctionList (void) {
DWORD pos, count;
if (!InBPWindow) { return; }
SendMessage(hFunctionlist,CB_RESETCONTENT,(WPARAM)0,(LPARAM)0);
for (count = 0; count < NoOfMapEntries; count ++ ) {
pos = SendMessage(hFunctionlist,CB_ADDSTRING,(WPARAM)0,(LPARAM)MapTable[count].Label);
SendMessage(hFunctionlist,CB_SETITEMDATA,(WPARAM)pos,(LPARAM)MapTable[count].VAddr);
}
SendMessage(hFunctionlist,CB_SETCURSEL,(WPARAM)1,(LPARAM)0);
UpdateBPointGUI();
}
#endif