From 647eb5ab3d6bc49379d8138ed44012e612e601c1 Mon Sep 17 00:00:00 2001 From: Moliman Date: Wed, 19 Jun 2019 22:00:11 -0400 Subject: [PATCH] Add binary data type on RAM watch * Currently support only 1 byte size --- src/drivers/win/ramwatch.cpp | 27 +++++++++++++++++++++++++++ src/drivers/win/ramwatch.h | 2 +- src/drivers/win/res.rc | 9 +++++---- src/drivers/win/resource.h | 1 + 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/ramwatch.cpp b/src/drivers/win/ramwatch.cpp index 11769cf1..10853afe 100644 --- a/src/drivers/win/ramwatch.cpp +++ b/src/drivers/win/ramwatch.cpp @@ -12,6 +12,7 @@ using namespace std; #include #include #include +#include /* #include @@ -825,6 +826,9 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara case 'h': SendDlgItemMessage(hDlg, IDC_HEX, BM_SETCHECK, BST_CHECKED, 0); break; + case 'b': + SendDlgItemMessage(hDlg, IDC_BINARY, BM_SETCHECK, BST_CHECKED, 0); + break; } } else SetDlgItemText(hDlg, IDC_EDIT_COMPAREADDRESS, "---------"); @@ -844,6 +848,7 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara EnableWindow(GetDlgItem(hDlg, IDC_SIGNED), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_UNSIGNED), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_HEX), FALSE); + EnableWindow(GetDlgItem(hDlg, IDC_BINARY), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_1_BYTE), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_2_BYTES), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_4_BYTES), FALSE); @@ -886,6 +891,8 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara watcher.Type = 'u'; else if (SendDlgItemMessage(hDlg, IDC_HEX, BM_GETCHECK, 0, 0) == BST_CHECKED) watcher.Type = 'h'; + else if (SendDlgItemMessage(hDlg, IDC_BINARY, BM_GETCHECK, 0, 0) == BST_CHECKED) + watcher.Type = 'b'; else { MessageBox(hDlg, "Type must be specified.", "Error", MB_OK | MB_ICONERROR); return true; @@ -903,6 +910,12 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara return true; } + if (watcher.Type == 'b' && (watcher.Size == 'd' || watcher.Size == 'w')) + { + MessageBox(hDlg, "Only 1 byte is supported on binary format.", "Error", MB_OK | MB_ICONERROR); + return true; + } + // address GetDlgItemText(hDlg, IDC_EDIT_COMPAREADDRESS, Str_Tmp, 1024); char *addrstr = Str_Tmp; @@ -1160,6 +1173,18 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam int i = rswatches[iNum].CurValue; int t = rswatches[iNum].Type; int size = rswatches[iNum].Size; + if (rswatches[iNum].Type == 'b') + { + auto bits = bitset<8>(i); // Currently work with 1 byte size only + int j = 0, k = 7; + while (k >= 0) + { + if (k == 3) num[j++] = ' '; + num[j++] = bits[k--] ? '1' : '0'; + } + Item->item.pszText = num; + break; + } const char* formatString = ((t == 's') ? "%d" : (t == 'u') ? "%u" : (size == 'd' ? "%08X" : size == 'w' ? "%04X" : "%02X")); switch (size) { @@ -1442,6 +1467,8 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam numberType = 1; else if(rswatches[watchIndex].Type == 'h') numberType = 2; + else if (rswatches[watchIndex].Type == 'b') + numberType = 3; // Don't open cheat dialog diff --git a/src/drivers/win/ramwatch.h b/src/drivers/win/ramwatch.h index 2df1638d..1366ae1c 100644 --- a/src/drivers/win/ramwatch.h +++ b/src/drivers/win/ramwatch.h @@ -54,7 +54,7 @@ struct AddressWatcher char* comment = NULL; // NULL means no comment, non-NULL means allocated comment bool WrongEndian; char Size; //'d' = 4 bytes, 'w' = 2 bytes, 'b' = 1 byte, and 'S' means it's a separator. - char Type;//'s' = signed integer, 'u' = unsigned, 'h' = hex, 'S' = separator + char Type;//'s' = signed integer, 'u' = unsigned, 'h' = hex, 'b' = binary, 'S' = separator short Cheats; // how many bytes are affected by cheat }; diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index b513395e..edf9f298 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -2164,7 +2164,7 @@ BEGIN PUSHBUTTON "Separator",IDC_C_WATCH_SEPARATE,225,137,36,14 END -IDD_EDITWATCH DIALOGEX 0, 0, 181, 95 +IDD_EDITWATCH DIALOGEX 0, 0, 181, 125 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION " Edit Watch" FONT 8, "MS Shell Dlg", 400, 0, 0x1 @@ -2173,16 +2173,17 @@ BEGIN EDITTEXT IDC_EDIT_COMPAREADDRESS,48,10,65,12,ES_UPPERCASE | ES_AUTOHSCROLL CTEXT "Notes:",IDC_PROMPT_TEXT,23,24,22,8 EDITTEXT IDC_PROMPT_EDIT,48,22,119,12,ES_AUTOHSCROLL - GROUPBOX "Data Type",IDC_DATATYPE_GROUPBOX,14,37,75,42,0,WS_EX_TRANSPARENT + GROUPBOX "Data Type",IDC_DATATYPE_GROUPBOX,14,37,75,51,0,WS_EX_TRANSPARENT CONTROL "&Signed",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,18,47,67,9 CONTROL "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,18,57,67,9 CONTROL "&Hexadecimal",IDC_HEX,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,18,67,67,9 + CONTROL "&Binary", IDC_BINARY, "Button", BS_AUTORADIOBUTTON | WS_TABSTOP, 18, 77, 67, 9 GROUPBOX "Data Size",IDC_DATASIZE_GROUPBOX,94,37,73,42,0,WS_EX_TRANSPARENT CONTROL "&1 byte",IDC_1_BYTE,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,98,47,61,11 CONTROL "&2 bytes",IDC_2_BYTES,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,98,57,61,11 CONTROL "&4 bytes",IDC_4_BYTES,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,98,67,61,11 - DEFPUSHBUTTON "&OK",IDOK,66,80,50,14 - PUSHBUTTON "&Cancel",IDCANCEL,120,80,50,14 + DEFPUSHBUTTON "&OK",IDOK,66,90,50,14 + PUSHBUTTON "&Cancel",IDCANCEL,120,90,50,14 END DLG_SNESPAD DIALOGEX 4, 109, 243, 121 diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index b93118b9..badd2def 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -704,6 +704,7 @@ #define IDC_CHEAT_VAL_LABEL 1314 #define IDC_CHEAT_COM_LABEL 1315 #define IDC_CHEAT_LABEL_KNOWN 1316 +#define IDC_BINARY 1317 #define MENU_NETWORK 40040 #define MENU_PALETTE 40041 #define MENU_SOUND 40042