project64/Source/RSP/breakpoint.cpp

181 lines
3.6 KiB
C++
Raw Normal View History

2016-01-27 09:11:59 +00:00
#include <windows.h>
#include <stdio.h>
#include "Rsp.h"
2016-01-27 09:11:59 +00:00
#include "CPU.h"
#include "breakpoint.h"
#define IDC_LOCATION_EDIT 105
HWND BPoint_Win_hDlg, hRSPLocation = NULL;
BPOINT BPoint[MaxBPoints];
int NoOfBpoints;
2016-01-27 09:11:59 +00:00
void Add_BPoint ( void )
{
char Title[10];
GetWindowTextA(hRSPLocation,Title,sizeof(Title));
2016-01-27 09:11:59 +00:00
if (!AddRSP_BPoint(AsciiToHex(Title),TRUE )) {
SendMessage(hRSPLocation,EM_SETSEL,(WPARAM)0,(LPARAM)-1);
SetFocus(hRSPLocation);
}
}
int AddRSP_BPoint( DWORD Location, int Confirm )
{
int count;
if (NoOfBpoints == MaxBPoints)
{
DisplayError("Max amount of breakpoints set");
2016-01-27 09:11:59 +00:00
return FALSE;
}
for (count = 0; count < NoOfBpoints; count ++)
{
if (BPoint[count].Location == Location)
{
DisplayError("You already have this breakpoint");
2016-01-27 09:11:59 +00:00
return FALSE;
}
}
if (Confirm)
{
char Message[150];
int Response;
sprintf(Message,"Break when:\n\nRSP's program counter = 0x%03X\n\nIs this correct?",
2016-01-27 09:11:59 +00:00
Location);
Response = MessageBoxA(BPoint_Win_hDlg, Message, "Breakpoint", MB_YESNO | MB_ICONINFORMATION);
2016-01-27 09:11:59 +00:00
if (Response == IDNO)
{
return FALSE;
}
}
BPoint[NoOfBpoints].Location = Location;
NoOfBpoints += 1;
if (DebugInfo.UpdateBreakPoints)
{
DebugInfo.UpdateBreakPoints();
}
return TRUE;
}
int CheckForRSPBPoint ( DWORD Location )
{
int count;
for (count = 0; count < NoOfBpoints; count ++)
{
if (BPoint[count].Location == Location)
{
return TRUE;
}
}
return FALSE;
}
2016-02-14 06:03:35 +00:00
void CreateBPPanel ( void * hDlg, rectangle rcBox )
2016-01-27 09:11:59 +00:00
{
if (hRSPLocation != NULL) { return; }
rcBox = rcBox; // Remove warning of unused
2016-01-27 09:11:59 +00:00
BPoint_Win_hDlg = (HWND)hDlg;
2016-01-27 09:11:59 +00:00
hRSPLocation = CreateWindowExA(0,"EDIT","", WS_CHILD | WS_BORDER | ES_UPPERCASE | WS_TABSTOP,
83,90,100,17, (HWND)hDlg,(HMENU)IDC_LOCATION_EDIT,(HINSTANCE)RSPInfo.hInst,NULL);
2016-01-27 09:11:59 +00:00
if (hRSPLocation)
{
char Title[20];
SendMessage(hRSPLocation,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
SendMessage(hRSPLocation,EM_SETLIMITTEXT,(WPARAM)3,(LPARAM)0);
sprintf(Title,"%03X",*PrgCount);
SetWindowTextA(hRSPLocation,Title);
2016-01-27 09:11:59 +00:00
}
}
void HideBPPanel ( void )
{
ShowWindow(hRSPLocation,FALSE);
}
2016-02-14 06:03:35 +00:00
void PaintBPPanel ( window_paint ps )
2016-01-27 09:11:59 +00:00
{
TextOutA((HDC)ps.hdc, 29,60,"Break when the program counter equals",37);
TextOutA((HDC)ps.hdc, 59,85,"0x",2);
2016-01-27 09:11:59 +00:00
}
void ShowBPPanel ( void )
{
ShowWindow(hRSPLocation,TRUE);
}
2016-02-14 06:03:35 +00:00
void RefreshBpoints ( void * hList )
2016-01-27 09:11:59 +00:00
{
char Message[100];
LRESULT location;
int count;
for (count = 0; count < NoOfBpoints; count ++ ) {
sprintf(Message," at 0x%03X (RSP)", BPoint[count].Location);
location = SendMessageA((HWND)hList, LB_ADDSTRING, 0, (LPARAM)Message);
SendMessageA(
(HWND)hList,
2016-01-27 09:11:59 +00:00
LB_SETITEMDATA,
(WPARAM)location,
(LPARAM)BPoint[count].Location
);
}
}
void RemoveAllBpoint ( void )
{
NoOfBpoints = 0;
}
void RemoveBpoint (void * hList, int index )
2016-01-27 09:11:59 +00:00
{
LRESULT response;
uint32_t location;
response = SendMessage((HWND)hList, LB_GETITEMDATA, (WPARAM)index, 0);
2016-01-27 09:11:59 +00:00
if (response < 0 || response > 0x7FFFFFFFL)
{
DisplayError(
"LB_GETITEMDATA response for %i out of DWORD range.",
index
);
}
location = (uint32_t)response;
RemoveRSPBreakPoint(location);
}
void RemoveRSPBreakPoint (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;
if (DebugInfo.UpdateBreakPoints)
{
DebugInfo.UpdateBreakPoints();
}
}
}