project64/Source/Project64-rsp/breakpoint.cpp

184 lines
4.1 KiB
C++
Raw Normal View History

2016-01-27 09:11:59 +00:00
#include "breakpoint.h"
#include "Rsp.h"
#include <Project64-rsp-core\RSPInfo.h>
#include <stdio.h>
#include <windows.h>
2016-01-27 09:11:59 +00:00
#define IDC_LOCATION_EDIT 105
2016-01-27 09:11:59 +00:00
HWND BPoint_Win_hDlg, hRSPLocation = NULL;
BPOINT BPoint[MaxBPoints];
int NoOfBpoints;
void Add_BPoint(void)
2016-01-27 09:11:59 +00:00
{
char Title[10];
GetWindowTextA(hRSPLocation, Title, sizeof(Title));
2023-06-29 02:59:07 +00:00
if (!AddRSP_BPoint(AsciiToHex(Title), true))
{
SendMessage(hRSPLocation, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
SetFocus(hRSPLocation);
}
2016-01-27 09:11:59 +00:00
}
int AddRSP_BPoint(DWORD Location, int Confirm)
2016-01-27 09:11:59 +00:00
{
int count;
if (NoOfBpoints == MaxBPoints)
{
DisplayError("Max amount of breakpoints set");
2023-06-29 02:59:07 +00:00
return false;
}
for (count = 0; count < NoOfBpoints; count++)
{
if (BPoint[count].Location == Location)
{
DisplayError("You already have this breakpoint");
2023-06-29 02:59:07 +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?",
Location);
Response = MessageBoxA(BPoint_Win_hDlg, Message, "Breakpoint", MB_YESNO | MB_ICONINFORMATION);
if (Response == IDNO)
{
2023-06-29 02:59:07 +00:00
return false;
}
}
BPoint[NoOfBpoints].Location = Location;
NoOfBpoints += 1;
if (DebugInfo.UpdateBreakPoints)
{
DebugInfo.UpdateBreakPoints();
}
2023-06-29 02:59:07 +00:00
return true;
2016-01-27 09:11:59 +00:00
}
int CheckForRSPBPoint(DWORD Location)
2016-01-27 09:11:59 +00:00
{
int count;
for (count = 0; count < NoOfBpoints; count++)
{
if (BPoint[count].Location == Location)
{
2023-06-29 02:59:07 +00:00
return true;
}
}
2023-06-29 02:59:07 +00:00
return false;
2016-01-27 09:11:59 +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
BPoint_Win_hDlg = (HWND)hDlg;
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);
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", *RSPInfo.SP_PC_REG);
SetWindowTextA(hRSPLocation, Title);
}
2016-01-27 09:11:59 +00:00
}
void HideBPPanel(void)
2016-01-27 09:11:59 +00:00
{
2023-06-29 02:59:07 +00:00
ShowWindow(hRSPLocation, false);
2016-01-27 09:11:59 +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)
2016-01-27 09:11:59 +00:00
{
2023-06-29 02:59:07 +00:00
ShowWindow(hRSPLocation, true);
2016-01-27 09:11:59 +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,
LB_SETITEMDATA,
(WPARAM)location,
(LPARAM)BPoint[count].Location);
}
2016-01-27 09:11:59 +00:00
}
void RemoveAllBpoint(void)
2016-01-27 09:11:59 +00:00
{
NoOfBpoints = 0;
2016-01-27 09:11:59 +00:00
}
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);
if (response < 0 || response > 0x7FFFFFFFL)
{
DisplayError(
"LB_GETITEMDATA response for %i out of DWORD range.",
index);
}
location = (uint32_t)response;
RemoveRSPBreakPoint(location);
2016-01-27 09:11:59 +00:00
}
void RemoveRSPBreakPoint(DWORD Location)
2016-01-27 09:11:59 +00:00
{
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();
}
}
2016-01-27 09:11:59 +00:00
}