From a3689c3ae66262e0d7feb68d11c4d0d3c0201cc5 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 20:06:17 -0400 Subject: [PATCH 001/103] kill combined label/offset disassembly It was a bad idea --- src/drivers/win/debugger.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 2fba0cfe9..e9101be3d 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -536,9 +536,7 @@ void HighlightSyntax(HWND hWnd, int lines) numpos = SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&num); if (numpos != 0) { - if (debug_wstr[numpos + 3] == L',' || debug_wstr[numpos + 3] == L')' || debug_wstr[numpos + 3] == L'\n' - || debug_wstr[numpos + 3] == L' ' //zero 30-nov-2017 - in support of combined label/offset disassembly. not sure this is a good idea - ) + if (debug_wstr[numpos + 3] == L',' || debug_wstr[numpos + 3] == L')' || debug_wstr[numpos + 3] == L'\n') wordbreak = numpos + 2; else wordbreak = numpos + 4; From 3e21f156e6c7f4c50d44fec679a2608a7911807f Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 21:36:24 -0400 Subject: [PATCH 002/103] change loop condition and update comments --- src/drivers/win/debuggersp.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index 1f78660ff..c7846c93f 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -506,7 +506,7 @@ void freeList(Name* n) * The caller needs to make sure that str is large enough. * * @param list NL list of address definitions -* @param str The string where replacing takes place. +* @param str The string where replacing takes place, including trace data. * @param addressesLog Vector for collecting addresses that were replaced by names **/ void replaceNames(Name* list, char* str, std::vector* addressesLog) @@ -543,7 +543,7 @@ void replaceNames(Name* list, char* str, std::vector* addressesLog) addrlen = 3; } - for(;;) + while (src) { int myAddrlen = addrlen; @@ -566,10 +566,7 @@ void replaceNames(Name* list, char* str, std::vector* addressesLog) myAddrlen = 5; } - //special hack: sometimes we have #$00, and we dont want to replace that. - //(this isn't a problem with $0000 because on the 6502 we ... dont.. have ... #$XXXX ? - //honestly, I don't know anything about this CPU. don't tell anyone. - //I'm just inferring from the fact that the algorithm previously relied on that assumption... + //we actually found an immediate value, don't replace it if(pos[-1] == '#') { src = pos + myAddrlen; From 3995dfc45a5509e75c02508a4f19e011a74d8ce6 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 21:36:51 -0400 Subject: [PATCH 003/103] get rid of address/label debugging once and for all --- src/drivers/win/debuggersp.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index c7846c93f..b4f3209c4 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -573,11 +573,8 @@ void replaceNames(Name* list, char* str, std::vector* addressesLog) continue; } - //zero 30-nov-2017 - change how this works so we can display the address still - //append beginning part, plus addrlen for the offset - strncat(buff,src,pos-src+myAddrlen); - //append a space - strcat(buff," "); + //append beginning part + strncat(buff, src, pos-src); //append the label strcat(buff, list->name); //begin processing after that offset From fbe8bf84df36efbefa4468138501e852b1140c87 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 22:00:14 -0400 Subject: [PATCH 004/103] add that == L' ' line back in I did not fully understand the consequences of my actions --- src/drivers/win/debugger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index e9101be3d..345c1e85f 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -536,7 +536,7 @@ void HighlightSyntax(HWND hWnd, int lines) numpos = SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&num); if (numpos != 0) { - if (debug_wstr[numpos + 3] == L',' || debug_wstr[numpos + 3] == L')' || debug_wstr[numpos + 3] == L'\n') + if (debug_wstr[numpos + 3] == L',' || debug_wstr[numpos + 3] == L')' || debug_wstr[numpos + 3] == L'\n' || debug_wstr[numpos + 3] == L' ') wordbreak = numpos + 2; else wordbreak = numpos + 4; From 77b418113114ead271941a0066a30655b4f24f8c Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 22:01:18 -0400 Subject: [PATCH 005/103] don't do symbolic address coloring on comment lines This fixes a bug where a comment ending in a colon would get parsed as a label. --- src/drivers/win/debugger.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 345c1e85f..279e310ba 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -495,15 +495,17 @@ void HighlightSyntax(HWND hWnd, int lines) int oldline = newline.chrg.cpMin; newline.chrg.cpMin = SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&newline) + 1; if(newline.chrg.cpMin == 0) break; - // symbolic address - if (debug_wstr[newline.chrg.cpMin - 2] == L':') - { - SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)oldline, (LPARAM)newline.chrg.cpMin); - SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgSym)); - continue; - } - if (!commentline) - SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgMnem)); + if (!commentline) + { + // symbolic address + if (debug_wstr[newline.chrg.cpMin - 2] == L':') + { + SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)oldline, (LPARAM)newline.chrg.cpMin); + SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgSym)); + continue; + } + SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgMnem)); + } // comment if (opbreak < newline.chrg.cpMin) { From 41f5be8aa8cf58718b177d2f0e621dca3ad8a02b Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 22:54:26 -0400 Subject: [PATCH 006/103] add lines to RTI opcodes --- src/drivers/win/debugger.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 279e310ba..5c9ff9527 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -106,7 +106,7 @@ struct DBGCOLORMENU { { "Operand note" , PPCCF(DbgOpNt) }, { "Effective address", PPCCF(DbgEff) }, { NULL }, - { "RTS Line", PPCCF(DbgRts) } + { "RTS/RTI Line", PPCCF(DbgRts) } }; #define IDC_DEBUGGER_RESTORESIZE 1000 @@ -717,8 +717,10 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) replaceNames(pageNames[p], bufferForDisassemblyWithPlentyOfStuff, &disassembly_operands[i]); } - // special case: an RTS opcode - if (GetMem(instruction_addr) == 0x60) + uint8 opCode = GetMem(instruction_addr); + + // special case: an RTS or RTI opcode + if (opCode == 0x60 || opCode == 0x40) { // add "----------" to emphasize the end of subroutine strcat(bufferForDisassemblyWithPlentyOfStuff, " "); From 07c81eabb21df9ca4564cef8e8407d387ceb21b2 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 23:42:51 -0400 Subject: [PATCH 007/103] initial attempt at .byte directive --- src/drivers/win/debugger.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 5c9ff9527..d5b91f731 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -568,6 +568,21 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } +bool IsData(unsigned int addr) +{ + if (cdloggerdataSize) + { + unsigned int instruction_addr = GetNesFileAddress(disassembly_addresses[i]) - 16; + if (instruction_addr >= 0 && instruction_addr < cdloggerdataSize) + { + uint8 cdl_data = cdloggerdata[instruction_addr] & 3; + return cdlData == 2; // Data only + } + } + + return false; +} + void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) { wchar_t chr[40] = { 0 }; @@ -675,6 +690,27 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) // Add address wcscat(debug_wstr, chr); disassembly_addresses.push_back(addr); + + // Get up to 8 data bytes according to CDL + int count = 0; + uint8 buff[8]; + while(addr!== X.PC && IsData(addr) && count < 8) + { + buff[count++] = GetMem(addr++) + } + + if (count > 0) + { + swprintf(debug_wstr, L".byte #$%02X", buff[0]) + for(int j = 1; j < count; j++) + { + swprintf(L", #$%02X", buff[j]) + } + wcscat(debug_wstr, L"\n"); + instructions_count++; + continue; + } + if (symbDebugEnabled) disassembly_operands.resize(i + 1); From 91cfeb40fb46be459f5636f8731d14f7f6c72434 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 8 Jun 2021 23:53:04 -0400 Subject: [PATCH 008/103] fix incredibly simple build errors This is what you get for using Notepad++. Don't be like me. --- src/drivers/win/debugger.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index d5b91f731..b6ab93ee6 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -572,10 +572,10 @@ bool IsData(unsigned int addr) { if (cdloggerdataSize) { - unsigned int instruction_addr = GetNesFileAddress(disassembly_addresses[i]) - 16; + unsigned int instruction_addr = GetNesFileAddress(addr) - 16; if (instruction_addr >= 0 && instruction_addr < cdloggerdataSize) { - uint8 cdl_data = cdloggerdata[instruction_addr] & 3; + uint8 cdlData = cdloggerdata[instruction_addr] & 3; return cdlData == 2; // Data only } } @@ -694,14 +694,14 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) // Get up to 8 data bytes according to CDL int count = 0; uint8 buff[8]; - while(addr!== X.PC && IsData(addr) && count < 8) + while(addr != X.PC && IsData(addr) && count < 8) { - buff[count++] = GetMem(addr++) + buff[count++] = GetMem(addr++); } if (count > 0) { - swprintf(debug_wstr, L".byte #$%02X", buff[0]) + swprintf(debug_wstr, L".byte #$%02X", buff[0]); for(int j = 1; j < count; j++) { swprintf(L", #$%02X", buff[j]) From 239e03b9bb1e7cf052ec3e5ed0ae3cab16361f75 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 9 Jun 2021 00:07:54 -0400 Subject: [PATCH 009/103] Revert "fix incredibly simple build errors" This reverts commit 1af8ad50b2f0d6d390aea667f096a1ef0dd85c56. --- src/drivers/win/debugger.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index b6ab93ee6..d5b91f731 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -572,10 +572,10 @@ bool IsData(unsigned int addr) { if (cdloggerdataSize) { - unsigned int instruction_addr = GetNesFileAddress(addr) - 16; + unsigned int instruction_addr = GetNesFileAddress(disassembly_addresses[i]) - 16; if (instruction_addr >= 0 && instruction_addr < cdloggerdataSize) { - uint8 cdlData = cdloggerdata[instruction_addr] & 3; + uint8 cdl_data = cdloggerdata[instruction_addr] & 3; return cdlData == 2; // Data only } } @@ -694,14 +694,14 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) // Get up to 8 data bytes according to CDL int count = 0; uint8 buff[8]; - while(addr != X.PC && IsData(addr) && count < 8) + while(addr!== X.PC && IsData(addr) && count < 8) { - buff[count++] = GetMem(addr++); + buff[count++] = GetMem(addr++) } if (count > 0) { - swprintf(debug_wstr, L".byte #$%02X", buff[0]); + swprintf(debug_wstr, L".byte #$%02X", buff[0]) for(int j = 1; j < count; j++) { swprintf(L", #$%02X", buff[j]) From a1b2a8c1d40063ae8e651e5662169b98222c4096 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 9 Jun 2021 00:08:01 -0400 Subject: [PATCH 010/103] Revert "initial attempt at .byte directive" This reverts commit 409b0c365d8887fdefdad06751bb581afbf916ba. --- src/drivers/win/debugger.cpp | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index d5b91f731..5c9ff9527 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -568,21 +568,6 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } -bool IsData(unsigned int addr) -{ - if (cdloggerdataSize) - { - unsigned int instruction_addr = GetNesFileAddress(disassembly_addresses[i]) - 16; - if (instruction_addr >= 0 && instruction_addr < cdloggerdataSize) - { - uint8 cdl_data = cdloggerdata[instruction_addr] & 3; - return cdlData == 2; // Data only - } - } - - return false; -} - void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) { wchar_t chr[40] = { 0 }; @@ -690,27 +675,6 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) // Add address wcscat(debug_wstr, chr); disassembly_addresses.push_back(addr); - - // Get up to 8 data bytes according to CDL - int count = 0; - uint8 buff[8]; - while(addr!== X.PC && IsData(addr) && count < 8) - { - buff[count++] = GetMem(addr++) - } - - if (count > 0) - { - swprintf(debug_wstr, L".byte #$%02X", buff[0]) - for(int j = 1; j < count; j++) - { - swprintf(L", #$%02X", buff[j]) - } - wcscat(debug_wstr, L"\n"); - instructions_count++; - continue; - } - if (symbDebugEnabled) disassembly_operands.resize(i + 1); From bf8639f5cd47aad9f0b3e2dca2edef51eee7f38e Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 21 Jun 2021 19:37:52 -0400 Subject: [PATCH 011/103] add inlineAddressEnabled flag Set to hardcoded true for now. --- src/drivers/win/debuggersp.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index b4f3209c4..9eabe1655 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -57,6 +57,7 @@ extern char LoadedRomFName[2048]; char NLfilename[2048]; bool symbDebugEnabled = true; bool symbRegNames = true; +bool inlineAddressEnabled = true; int debuggerWasActive = 0; char temp_chr[40] = {0}; char delimiterChar[2] = "#"; @@ -572,12 +573,22 @@ void replaceNames(Name* list, char* str, std::vector* addressesLog) src = pos + myAddrlen; continue; } - - //append beginning part - strncat(buff, src, pos-src); + + if (inlineAddressEnabled) + { + //append up to and including the address, + a space + strncat(buff, src, pos - src + myAddrlen); + strcat(buff, " "); + } + else + { + //append up to but not including the address + strncat(buff, src, pos - src); + } + //append the label strcat(buff, list->name); - //begin processing after that offset + //begin processing after this offset src = pos + myAddrlen; if (addressesLog) @@ -600,9 +611,16 @@ void replaceNames(Name* list, char* str, std::vector* addressesLog) *buff = 0; src = str; + // BUG: This method is called for each string in the named label list, + // but it looks for all the reg names every time. while (pos = strstr(src, RegNames[i].offset)) { - *pos = 0; - strcat(buff, src); + if (inlineAddressEnabled) { + strncat(buff, src, pos - src + 5); + strcat(buff, " "); + } else { + strncat(buff, src, pos - src); + } + strcat(buff, RegNames[i].name); src = pos + 5; } From 4669de16ee237cf99ce847c1dc71c9e9343adb4b Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 21 Jun 2021 20:05:41 -0400 Subject: [PATCH 012/103] split out a replaceRegNames method Previously, this logic got called once for each named label that needed replacing. I guess no one noticed because it was idempotent, but that's not the case anymore! --- src/drivers/win/debugger.cpp | 2 ++ src/drivers/win/debuggersp.cpp | 34 +++++++++++++++++++++++++--------- src/drivers/win/debuggersp.h | 2 ++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 5c9ff9527..6a425b537 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -711,6 +711,8 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) if (symbDebugEnabled) { + if (symbRegNames) + replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, &disassembly_operands[i]); for(int p=0;p* addressesLog) } list = list->next; } +} + +/** +* Replaces all offsets in a string with the names of the corresponding NES hardware registers +* The caller needs to make sure that str is large enough. +* +* @param str The string where replacing takes place, including trace data. +**/ +void replaceRegNames(char* str) +{ + static char buff[1001]; + char* pos; + char* src; - for (int i = 0; i < RegNameCount; i++) { - if (!symbRegNames) break; + for (int i = 0; i < RegNameCount; i++) + { // copypaste, because Name* is too complex to abstract *buff = 0; src = str; - // BUG: This method is called for each string in the named label list, - // but it looks for all the reg names every time. - while (pos = strstr(src, RegNames[i].offset)) { - if (inlineAddressEnabled) { + while (pos = strstr(src, RegNames[i].offset)) + { + if (inlineAddressEnabled) + { strncat(buff, src, pos - src + 5); strcat(buff, " "); - } else { + } + else + { strncat(buff, src, pos - src); } - + strcat(buff, RegNames[i].name); src = pos + 5; } - if (*buff) { + if (*buff) + { strcat(buff, src); strcpy(str, buff); } diff --git a/src/drivers/win/debuggersp.h b/src/drivers/win/debuggersp.h index 01b7d9070..50cf52f20 100644 --- a/src/drivers/win/debuggersp.h +++ b/src/drivers/win/debuggersp.h @@ -41,6 +41,7 @@ struct MemoryMappedRegister extern bool symbDebugEnabled; extern bool symbRegNames; +extern bool inlineAddressEnabled; extern std::vector> bookmarks; extern int debuggerWasActive; @@ -54,6 +55,7 @@ Name* getNamesPointerForAddress(uint16 address); void setNamesPointerForAddress(uint16 address, Name* newNode); void loadNameFiles(); void replaceNames(Name* list, char* str, std::vector* addressesLog = 0); +void replaceRegNames(char* str); void AddDebuggerBookmark(HWND hwnd); void DeleteDebuggerBookmark(HWND hwnd); void EditDebuggerBookmark(HWND hwnd); From 000dac34954fa423fc2babda0e86f3e98b56fbbe Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 21 Jun 2021 20:34:24 -0400 Subject: [PATCH 013/103] add button to toggle combined label/offset disassembly --- src/drivers/win/debugger.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 6a425b537..54d074a88 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -111,6 +111,7 @@ struct DBGCOLORMENU { #define IDC_DEBUGGER_RESTORESIZE 1000 #define ID_COLOR_DEBUGGER 2000 +#define ID_DEBUGGER_ADDRESSLINE 3000 bool ChangeColor(HWND hwnd, DBGCOLORMENU* item) { @@ -2046,6 +2047,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // prepare menu HMENU hdbgmenu = GetMenu(hwndDlg); InsertMenu(hdbgmenu, 0, MF_STRING | MF_BYPOSITION, IDC_DEBUGGER_RESTORESIZE, "Default window size"); + InsertMenu(hdbgmenu, 2, MF_STRING | MF_BYPOSITION, ID_DEBUGGER_ADDRESSLINE, "Combined Label/Offset Disassembly"); HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, 1); for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); @@ -2208,6 +2210,10 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case IDC_DEBUGGER_RESTORESIZE: RestoreSize(hwndDlg); break; + case ID_DEBUGGER_ADDRESSLINE: + inlineAddressEnabled ^= 1; + UpdateDebugger(false); + break; } } } From 66d5025c2527b2d7d4638fde00b9317339bd3925 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 21 Jun 2021 23:17:53 -0400 Subject: [PATCH 014/103] clean up some REALLY crufty comments Many of these were from 2006, when FCEU was "moved to its own folder to make room for other projects." I was 9 years old. --- src/drivers/win/debugger.cpp | 68 +++++++--------------------------- src/drivers/win/debuggersp.cpp | 10 ----- 2 files changed, 14 insertions(+), 64 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 54d074a88..543e55ffe 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -70,7 +70,6 @@ static HMENU hDisasmcontext; //Handle to context menu static HMENU hDisasmcontextsub; //Handle to context sub menu WNDPROC IDC_DEBUGGER_DISASSEMBLY_oldWndProc = 0; -// static HFONT hFont; static SCROLLINFO si; bool debuggerAutoload = false; @@ -157,7 +156,7 @@ void UpdateOtherDebuggingDialogs() #define DEBUGGER_MIN_WIDTH 360 // Minimum width for debugger #define DEBUGGER_DEFAULT_HEIGHT 594 // default height for debugger -// owomomo: default width of the debugger is depend on the default width of disasm view, so it's not defined here. +// Default width of the debugger depends on the default width of disasm view, so it's not defined here. void RestoreSize(HWND hwndDlg) { @@ -305,13 +304,6 @@ static void UpdateDialog(HWND hwndDlg) { EnableWindow(GetDlgItem(hwndDlg,IDC_ADDBP_MEM_CPU),enable); EnableWindow(GetDlgItem(hwndDlg,IDC_ADDBP_MEM_PPU),enable); EnableWindow(GetDlgItem(hwndDlg,IDC_ADDBP_MEM_SPR),enable); - //nah.. lets leave these checked - //CheckDlgButton(hwndDlg,IDC_ADDBP_MODE_R,BST_UNCHECKED); - //CheckDlgButton(hwndDlg,IDC_ADDBP_MODE_W,BST_UNCHECKED); - //CheckDlgButton(hwndDlg,IDC_ADDBP_MODE_X,BST_UNCHECKED); - //CheckDlgButton(hwndDlg,IDC_ADDBP_MEM_CPU,BST_UNCHECKED); - //CheckDlgButton(hwndDlg,IDC_ADDBP_MEM_PPU,BST_UNCHECKED); - //CheckDlgButton(hwndDlg,IDC_ADDBP_MEM_SPR,BST_UNCHECKED); } INT_PTR CALLBACK AddbpCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -923,7 +915,6 @@ void FCEUD_DebugBreakpoint(int bp_num) // normal breakpoint sprintf(str_temp, "Breakpoint %u Hit at $%04X: ", bp_num, X.PC); strcat(str_temp, BreakToText(bp_num)); - //watchpoint[num].condText OutputLogLine(str_temp); } else if (bp_num == BREAK_TYPE_BADOP) { @@ -972,7 +963,7 @@ void FCEUD_DebugBreakpoint(int bp_num) void win_debuggerLoop(); // HACK to let user interact with the Debugger while emulator isn't updating win_debuggerLoop(); - // since we unfreezed emulation, reset delta_cycles counter + // since we unfroze emulation, reset delta_cycles counter ResetDebugStatisticsDeltaCounters(); } @@ -1038,8 +1029,6 @@ void UpdateDebugger(bool jump_to_pc) // "Address Bookmark Add" follows the address - //sprintf(str, "%04X", starting_address); - //SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); sprintf(str, "%02X", X.A); SetDlgItemText(hDebug, IDC_DEBUGGER_VAL_A, str); @@ -1130,7 +1119,6 @@ void UpdateDebugger(bool jump_to_pc) sprintf(str, "%02X", GetMem(tmp)); for (i = 1; i < 128; i++) { - //tmp = ((tmp+1)|0x0100)&0x01FF; //increment and fix pointer to $0100-$01FF range tmp++; if (tmp > 0x1FF) break; @@ -1291,7 +1279,7 @@ void KillDebugger() { DebuggerExit(); } FCEUI_Debugger().reset(); - FCEUI_SetEmulationPaused(0); //mbg merge 7/18/06 changed from userpause + FCEUI_SetEmulationPaused(0); } @@ -1354,7 +1342,6 @@ INT_PTR CALLBACK AssemblerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l } } SetWindowText(hwndDlg, "Inline Assembler *Patches Applied*"); - //MessageBeep(MB_OK); applied = 1; } break; @@ -1440,7 +1427,7 @@ INT_PTR CALLBACK AssemblerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l } INT_PTR CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - char str[64]; //mbg merge 7/18/06 changed from unsigned char + char str[64]; uint8 *c; int i; int *p; @@ -1456,7 +1443,7 @@ INT_PTR CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa if(iapoffset != -1){ CheckDlgButton(hwndDlg, IDC_ROMPATCHER_DOTNES_OFFSET, BST_CHECKED); - sprintf((char*)str,"%X",iapoffset); //mbg merge 7/18/06 added cast + sprintf((char*)str,"%X",iapoffset); SetDlgItemText(hwndDlg,IDC_ROMPATCHER_OFFSET,str); } @@ -1513,7 +1500,7 @@ void DebuggerExit() { debugger_open = 0; inDebugger = false; - // in case someone call it multiple times + // in case someone calls it multiple times if (hDebug) { // release bitmap icons @@ -1537,7 +1524,7 @@ void DebuggerExit() static RECT currDebuggerRect; static RECT newDebuggerRect; -//used to move all child items in the dialog when you resize (except for the dock fill controls which are resized) +//moves all child items in the dialog when you resize (except for the dock fill controls which are resized) BOOL CALLBACK DebuggerEnumWindowsProc(HWND hwnd, LPARAM lParam) { POINT* p = (POINT*)lParam; @@ -1992,12 +1979,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP //setup font SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_DISASSEMBLY,WM_SETFONT,(WPARAM)debugSystem->hDisasmFont,FALSE); SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_DISASSEMBLY_LEFT_PANEL,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - //SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_A,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - //SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_X,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - //SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_Y,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - //SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PC,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_STACK_CONTENTS,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - //SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); //text limits @@ -2012,13 +1994,11 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // limit input // Don't limit address entry. See: debugcpp offsetStringToInt - //DefaultEditCtrlProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PCSEEK), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); DefaultEditCtrlProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PC), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_A), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_X), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_Y), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); - //SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_BOOKMARK), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); //I'm lazy, disable the controls which I can't mess with right now SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PPU,EM_SETREADONLY,TRUE,0); @@ -2066,8 +2046,8 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP DbgSizeX = newDebuggerRect.right - newDebuggerRect.left; //Store new size (this will be used to store in the .cfg file) DbgSizeY = newDebuggerRect.bottom - newDebuggerRect.top; - // convert minimum size to actural screen size - // owomomo: the minimum height is different between left and right part, + // convert minimum size to actual screen size. + // the minimum height is different between left and right part, // but width is the same, similarly hereinafter HDC hdc = GetDC(hwndDlg); int min_w = MulDiv(DEBUGGER_MIN_WIDTH, GetDeviceCaps(hdc, LOGPIXELSX), 96); @@ -2109,7 +2089,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case WM_CLOSE: case WM_QUIT: - //exitdebug: DebuggerExit(); break; case WM_MOVING: @@ -2127,7 +2106,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } break; - //adelikat: Buttons that don't need a rom loaded to do something, such as autoload + // Buttons that don't need a rom loaded to do something, such as autoload case WM_COMMAND: { switch (HIWORD(wParam)) @@ -2240,7 +2219,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } case WM_VSCROLL: { - //mbg merge 7/18/06 changed pausing check if (FCEUI_EmulationPaused()) UpdateRegs(hwndDlg); if (lParam) @@ -2287,7 +2265,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } break; } - case SB_THUMBPOSITION: //break; + case SB_THUMBPOSITION: case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; } if (si.nPos < si.nMin) @@ -2312,7 +2290,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // Only open the menu if a breakpoint is selected if (SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0) >= 0) { hDebugcontextsub = GetSubMenu(hDebugcontext,0); - //SetMenuDefaultItem(hDebugcontextsub, DEBUGGER_CONTEXT_TOGGLEBREAK, false); if (lParam != -1) TrackPopupMenu(hDebugcontextsub,TPM_RIGHTBUTTON,LOWORD(lParam),HIWORD(lParam),0,hwndDlg,0); //Create menu else { // Handle the context menu keyboard key @@ -2396,7 +2373,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // mouse_y < 538 // > 33) tmp = 33 - //mbg merge 7/18/06 changed pausing check if (FCEUI_EmulationPaused() && (mouse_x > 6) && (mouse_x < 30) && (mouse_y > 10)) { // ################################## End of SP CODE ########################### @@ -2404,7 +2380,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP if (tmp < (int)disassembly_addresses.size()) { int i = disassembly_addresses[tmp]; - //DoPatcher(GetNesFileAddress(i),hwndDlg); iaPC=i; if (iaPC >= 0x8000) { @@ -2419,7 +2394,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP { int mouse_x = GET_X_LPARAM(lParam); int mouse_y = GET_Y_LPARAM(lParam); - //mbg merge 7/18/06 changed pausing check if (FCEUI_EmulationPaused() && (mouse_x > 6) && (mouse_x < 30) && (mouse_y > 10)) { int tmp = (mouse_y - 10) / debugSystem->disasmFontHeight; @@ -2440,7 +2414,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP { int mouse_x = GET_X_LPARAM(lParam); int mouse_y = GET_Y_LPARAM(lParam); - //mbg merge 7/18/06 changed pausing check if (FCEUI_EmulationPaused() && (mouse_x > 6) && (mouse_x < 30) && (mouse_y > 10)) { int tmp = (mouse_y - 10) / debugSystem->disasmFontHeight; @@ -2477,7 +2450,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP UpdateDebugger(false); break; case IDC_DEBUGGER_RUN: - //mbg merge 7/18/06 changed pausing check and set if (FCEUI_EmulationPaused()) { UpdateRegs(hwndDlg); FCEUI_ToggleEmulationPause(); @@ -2500,8 +2472,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP uint64 ts=timestampbase; ts+=timestamp; ts+=341/3; - //if (scanline == 240) vblankScanLines++; - //else vblankScanLines = 0; FCEUI_Debugger().runline_end_time=ts; } FCEUI_SetEmulationPaused(0); @@ -2516,14 +2486,11 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP ts+=timestamp; ts+=128*341/3; FCEUI_Debugger().runline_end_time=ts; - //if (scanline+128 >= 240 && scanline+128 <= 257) vblankScanLines = (scanline+128)-240; - //else vblankScanLines = 0; } FCEUI_SetEmulationPaused(0); UpdateOtherDebuggingDialogs(); break; case IDC_DEBUGGER_STEP_OUT: - //mbg merge 7/18/06 changed pausing check and set if (FCEUI_EmulationPaused() > 0) { DebuggerState &dbgstate = FCEUI_Debugger(); UpdateRegs(hwndDlg); @@ -2535,7 +2502,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } break; case IDC_DEBUGGER_STEP_OVER: - //mbg merge 7/18/06 changed pausing check and set if (FCEUI_EmulationPaused()) { UpdateRegs(hwndDlg); int tmp = X.PC; @@ -2557,7 +2523,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } break; case IDC_DEBUGGER_SEEK_PC: - //mbg merge 7/18/06 changed pausing check if (FCEUI_EmulationPaused()) { UpdateRegs(hwndDlg); @@ -2566,7 +2531,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP break; case IDC_DEBUGGER_SEEK_TO: { - //mbg merge 7/18/06 changed pausing check if (FCEUI_EmulationPaused()) UpdateRegs(hwndDlg); char str[16]; @@ -2698,7 +2662,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } - return FALSE; //TRUE; + return FALSE; } extern void iNESGI(GI h); @@ -2721,7 +2685,7 @@ void DoPatcher(int address, HWND hParent) } void UpdatePatcher(HWND hwndDlg){ - char str[75]; //mbg merge 7/18/06 changed from unsigned + char str[75]; uint8 *p; if(iapoffset != -1){ EnableWindow(GetDlgItem(hwndDlg,IDC_ROMPATCHER_PATCH_DATA),TRUE); @@ -2768,7 +2732,7 @@ void DoDebug(uint8 halt) if (!debugger_open) { // init buffers - // owomomo: initialize buffers even before the debugger is open, + // initialize buffers even before the debugger is open, // because some of the operations about hDebug may occur before // its WM_INITDIALOG runs. debug_wstr = (wchar_t*)malloc(16384 * sizeof(wchar_t)); @@ -2780,7 +2744,6 @@ void DoDebug(uint8 halt) } if (hDebug) { - //SetWindowPos(hDebug,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); ShowWindow(hDebug, SW_SHOWNORMAL); SetForegroundWindow(hDebug); @@ -2839,8 +2802,6 @@ void DebugSystem::init() GetTextMetrics(hdc,&tm); fixedFontHeight = tm.tmHeight; fixedFontWidth = tm.tmAveCharWidth; - //printf("fixed font height: %d\n",fixedFontHeight); - //printf("fixed font width: %d\n",fixedFontWidth); SelectObject(hdc, hHexeditorFont); GetTextMetrics(hdc,&tm); HexeditorFontHeight = tm.tmHeight; @@ -2881,4 +2842,3 @@ DebugSystem::~DebugSystem() hIDAFont = 0; } } - diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index 05f96d41e..42d9e71de 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -33,18 +33,8 @@ int GetNesFileAddress(int A); inline int RomPageIndexForAddress(int addr) { return (addr-0x8000)>>(debuggerPageSize); } -//old -//Name* lastBankNames = 0; -//Name* loadedBankNames = 0; - -//new Name* pageNames[32] = {0}; //the maximum number of pages we could have is 32, based on 1KB debuggerPageSize -//old -//int lastBank = -1; -//int loadedBank = -1; - -//new int pageNumbersLoaded[32] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, From 8c71886b9ae039ba34fb9fa72fdab04a7523a1e3 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 21 Jun 2021 23:23:44 -0400 Subject: [PATCH 015/103] tweak vxxproj to work on VSCode 2017 No idea if this is correct or appropriate, but it's what I needed to get it running on my computer. --- vc/vc14_fceux.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vc/vc14_fceux.vcxproj b/vc/vc14_fceux.vcxproj index 29cb00b59..6f5d42963 100644 --- a/vc/vc14_fceux.vcxproj +++ b/vc/vc14_fceux.vcxproj @@ -31,7 +31,7 @@ {6893EF44-FEA3-46DF-B236-C4C200F54294} fceux Win32Proj - 10.0 + 10.0.14393.0 @@ -71,7 +71,7 @@ - v142 + v141 v141_xp From 21270c76abaf9945860d559db46d810233827224 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 02:29:35 -0400 Subject: [PATCH 016/103] rename to inline addresses --- src/drivers/win/debugger.cpp | 7 ++++--- src/drivers/win/debuggersp.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 543e55ffe..169d25a89 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -110,7 +110,7 @@ struct DBGCOLORMENU { #define IDC_DEBUGGER_RESTORESIZE 1000 #define ID_COLOR_DEBUGGER 2000 -#define ID_DEBUGGER_ADDRESSLINE 3000 +#define ID_DEBUGGER_INLINE_ADDRESS 3000 bool ChangeColor(HWND hwnd, DBGCOLORMENU* item) { @@ -2027,7 +2027,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // prepare menu HMENU hdbgmenu = GetMenu(hwndDlg); InsertMenu(hdbgmenu, 0, MF_STRING | MF_BYPOSITION, IDC_DEBUGGER_RESTORESIZE, "Default window size"); - InsertMenu(hdbgmenu, 2, MF_STRING | MF_BYPOSITION, ID_DEBUGGER_ADDRESSLINE, "Combined Label/Offset Disassembly"); + InsertMenu(hdbgmenu, 2, MF_STRING | MF_BYPOSITION | MF_UNCHECKED, ID_DEBUGGER_INLINE_ADDRESS, "Inline Addresses"); HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, 1); for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); @@ -2189,8 +2189,9 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case IDC_DEBUGGER_RESTORESIZE: RestoreSize(hwndDlg); break; - case ID_DEBUGGER_ADDRESSLINE: + case ID_DEBUGGER_INLINE_ADDRESS: inlineAddressEnabled ^= 1; + CheckDlgButton(hwndDlg, ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled); UpdateDebugger(false); break; } diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index 42d9e71de..438dd120d 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -47,7 +47,7 @@ extern char LoadedRomFName[2048]; char NLfilename[2048]; bool symbDebugEnabled = true; bool symbRegNames = true; -bool inlineAddressEnabled = true; +bool inlineAddressEnabled = false; int debuggerWasActive = 0; char temp_chr[40] = {0}; char delimiterChar[2] = "#"; From ab45f908b15fe89a420cf292578b40d86297e4d4 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 11:20:47 -0400 Subject: [PATCH 017/103] add the toggle to an options menu and rename it --- src/drivers/win/debugger.cpp | 6 +++--- src/drivers/win/res.rc | 4 ++++ src/drivers/win/resource.h | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 169d25a89..5877dfb47 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -110,7 +110,6 @@ struct DBGCOLORMENU { #define IDC_DEBUGGER_RESTORESIZE 1000 #define ID_COLOR_DEBUGGER 2000 -#define ID_DEBUGGER_INLINE_ADDRESS 3000 bool ChangeColor(HWND hwnd, DBGCOLORMENU* item) { @@ -2027,11 +2026,12 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // prepare menu HMENU hdbgmenu = GetMenu(hwndDlg); InsertMenu(hdbgmenu, 0, MF_STRING | MF_BYPOSITION, IDC_DEBUGGER_RESTORESIZE, "Default window size"); - InsertMenu(hdbgmenu, 2, MF_STRING | MF_BYPOSITION | MF_UNCHECKED, ID_DEBUGGER_INLINE_ADDRESS, "Inline Addresses"); HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, 1); for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); + CheckMenuItem(GetSubMenu(hdbgmenu, 2), ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_CHECKED : MF_UNCHECKED); + debugger_open = 1; inDebugger = true; break; @@ -2191,7 +2191,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP break; case ID_DEBUGGER_INLINE_ADDRESS: inlineAddressEnabled ^= 1; - CheckDlgButton(hwndDlg, ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled); + CheckMenuItem(GetSubMenu(GetMenu(hwndDlg), 2), ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_CHECKED : MF_UNCHECKED); UpdateDebugger(false); break; } diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 810f7343e..0f964e876 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3024,6 +3024,10 @@ BEGIN MENUITEM SEPARATOR MENUITEM "Restore default", ID_DEBUGGER_DEFCOLOR END + POPUP "Options" + BEGIN + MENUITEM "Show Symbol Addresses", ID_DEBUGGER_INLINE_ADDRESS, CHECKED + END END diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index ea863c968..aea17046e 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1219,13 +1219,14 @@ #define IDC_NTVIEW_SCANLINE_TEXT 65534 #define IDC_BOOKMARK_SHORTCUT_PREFIX_TEXT 65534 #define IDC_DEBUGGER_TEXT_X 65534 +#define ID_DEBUGGER_INLINE_ADDRESS 65535 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 313 -#define _APS_NEXT_COMMAND_VALUE 40012 +#define _APS_NEXT_COMMAND_VALUE 40013 #define _APS_NEXT_CONTROL_VALUE 1050 #define _APS_NEXT_SYMED_VALUE 101 #endif From ef7ac99e26e2192dc67a663406da53e7b33614a3 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 12:24:33 -0400 Subject: [PATCH 018/103] consolidate some things into a Symbols menu item --- src/drivers/win/debugger.cpp | 23 +++++++++++++++++++++-- src/drivers/win/res.rc | 11 ++++++++--- src/drivers/win/resource.h | 6 +++++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 5877dfb47..cb7ef0b85 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1937,6 +1937,11 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w return CallWindowProc(IDC_DEBUGGER_DISASSEMBLY_oldWndProc, hwndDlg, uMsg, wParam, lParam); } +// Need to coordinate these with res.rc +#define MENU_OPTIONS_POS 0 +#define MENU_COLORS_POS 1 +#define MENU_SYMBOLS_POS 2 + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { //these messages get handled at any time @@ -2025,12 +2030,13 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // prepare menu HMENU hdbgmenu = GetMenu(hwndDlg); + // This will go in a submenu soon. InsertMenu(hdbgmenu, 0, MF_STRING | MF_BYPOSITION, IDC_DEBUGGER_RESTORESIZE, "Default window size"); - HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, 1); + HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, MENU_COLORS_POS); for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); - CheckMenuItem(GetSubMenu(hdbgmenu, 2), ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS), ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_CHECKED : MF_UNCHECKED); debugger_open = 1; inDebugger = true; @@ -2194,6 +2200,19 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP CheckMenuItem(GetSubMenu(GetMenu(hwndDlg), 2), ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_CHECKED : MF_UNCHECKED); UpdateDebugger(false); break; + // TODO: Reuse the old IDs from the persistent buttons instead? + case ID_DEBUGGER_RELOAD_SYMBOLS: + printf("Coming soon!\n"); + break; + case ID_DEBUGGER_LOAD_DEB_FILE: + printf("Coming soon!\n"); + break; + case ID_DEBUGGER_SYMBOLIC_DEBUG: + printf("Coming soon!\n"); + break; + case ID_DEBUGGER_DEFAULT_REG_NAMES: + printf("Coming soon!\n"); + break; } } } diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 0f964e876..b35c451dc 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3019,14 +3019,19 @@ END DEBUGGERMENU MENU BEGIN - POPUP "Syntax highlight" + POPUP "Colors" BEGIN MENUITEM SEPARATOR MENUITEM "Restore default", ID_DEBUGGER_DEFCOLOR END - POPUP "Options" + POPUP "Symbols" BEGIN - MENUITEM "Show Symbol Addresses", ID_DEBUGGER_INLINE_ADDRESS, CHECKED + MENUITEM "Reload", ID_DEBUGGER_RELOAD_SYMBOLS + MENUITEM "Load .DEB file", ID_DEBUGGER_LOAD_DEB_FILE, CHECKED + MENUITEM SEPARATOR + MENUITEM "Symbolic Debug", ID_DEBUGGER_SYMBOLIC_DEBUG, CHECKED + MENUITEM "Show Symbol Addresses", ID_DEBUGGER_INLINE_ADDRESS, CHECKED + MENUITEM "Default Register Names", ID_DEBUGGER_DEFAULT_REG_NAMES, CHECKED END END diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index aea17046e..70191f6d2 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1207,6 +1207,11 @@ #define CHEAT_CONTEXT_POSSI_ADDCHEAT 40601 #define CHEAT_CONTEXT_POSSI_ADDTORAMWATCH 40603 #define IDC_DEBUGGER_BOOKMARKS 45535 +#define ID_DEBUGGER_INLINE_ADDRESS 45536 +#define ID_DEBUGGER_RELOAD_SYMBOLS 45537 +#define ID_DEBUGGER_LOAD_DEB_FILE 45538 +#define ID_DEBUGGER_SYMBOLIC_DEBUG 45539 +#define ID_DEBUGGER_DEFAULT_REG_NAMES 45540 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 @@ -1219,7 +1224,6 @@ #define IDC_NTVIEW_SCANLINE_TEXT 65534 #define IDC_BOOKMARK_SHORTCUT_PREFIX_TEXT 65534 #define IDC_DEBUGGER_TEXT_X 65534 -#define ID_DEBUGGER_INLINE_ADDRESS 65535 // Next default values for new objects // From e40b2a47ef3fa84291d3c8d6fc5a922cc4435638 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 22:59:30 -0400 Subject: [PATCH 019/103] put actual functionality in the menu items --- src/drivers/win/debugger.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index cb7ef0b85..34ccccb57 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1942,6 +1942,17 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_COLORS_POS 1 #define MENU_SYMBOLS_POS 2 +inline void UpdateSymbolsPopup(HMENU symbolsPopup) +{ + CheckMenuItem(symbolsPopup, ID_DEBUGGER_SYMBOLIC_DEBUG, symbDebugEnabled ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, symbRegNames ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_ENABLED : MF_DISABLED); + + // Gray out potentially irrelavant options + EnableMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, symbDebugEnabled ? MF_ENABLED : MF_GRAYED); + EnableMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, symbDebugEnabled ? MF_ENABLED : MF_GRAYED); +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { //these messages get handled at any time @@ -2036,7 +2047,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); - CheckMenuItem(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS), ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_CHECKED : MF_UNCHECKED); + UpdateSymbolsPopup(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); debugger_open = 1; inDebugger = true; @@ -2202,16 +2213,26 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP break; // TODO: Reuse the old IDs from the persistent buttons instead? case ID_DEBUGGER_RELOAD_SYMBOLS: - printf("Coming soon!\n"); + ramBankNamesLoaded = false; + for (int i = 0; i < ARRAYSIZE(pageNumbersLoaded); i++) + pageNumbersLoaded[i] = -1; + loadNameFiles(); + UpdateDebugger(false); break; case ID_DEBUGGER_LOAD_DEB_FILE: printf("Coming soon!\n"); break; case ID_DEBUGGER_SYMBOLIC_DEBUG: - printf("Coming soon!\n"); + { + symbDebugEnabled ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); + UpdateDebugger(false); break; + } case ID_DEBUGGER_DEFAULT_REG_NAMES: - printf("Coming soon!\n"); + symbRegNames ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); + UpdateDebugger(false); break; } } @@ -2599,7 +2620,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // ################################## Start of SP CODE ########################### case IDC_DEBUGGER_RELOAD_SYMS: - { + { // TODO: delete/merge with ID_DEBUGGER_RELOAD_SYMBOLS ramBankNamesLoaded = false; for(int i=0;i Date: Tue, 22 Jun 2021 22:59:46 -0400 Subject: [PATCH 020/103] MISSED ONE --- src/drivers/win/debugger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 34ccccb57..bae92d9ee 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -437,7 +437,7 @@ INT_PTR CALLBACK AddbpCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara } break; } - return FALSE; //TRUE; + return FALSE; } void HighlightPC(HWND hWnd) From 9123765b039b340abf9cee52059a8cabc6471129 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 23:00:05 -0400 Subject: [PATCH 021/103] rename to restore defaults --- src/drivers/win/debugger.cpp | 2 +- src/drivers/win/res.rc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index bae92d9ee..588da9c41 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -702,7 +702,7 @@ void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); if (symbDebugEnabled) - { + { // TODO: This will add in both the default name and custom name if you have inlineAddresses enabled. if (symbRegNames) replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, &disassembly_operands[i]); diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index b35c451dc..15c5151d4 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3022,7 +3022,7 @@ BEGIN POPUP "Colors" BEGIN MENUITEM SEPARATOR - MENUITEM "Restore default", ID_DEBUGGER_DEFCOLOR + MENUITEM "Restore defaults", ID_DEBUGGER_DEFCOLOR END POPUP "Symbols" BEGIN From 712d6efcbb0d6350dcf0cf2be92fcdf2a4af7dbf Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 23:22:53 -0400 Subject: [PATCH 022/103] add load .DEB file and define a macro --- src/drivers/win/debugger.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 588da9c41..93249a5d5 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1942,15 +1942,19 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_COLORS_POS 1 #define MENU_SYMBOLS_POS 2 +#define CHECKED_FLAG(b) ((b) ? MF_CHECKED : MF_UNCHECKED) +#define ENABLED_FLAG(b) ((b) ? MF_ENABLED : MF_GRAYED) + inline void UpdateSymbolsPopup(HMENU symbolsPopup) { - CheckMenuItem(symbolsPopup, ID_DEBUGGER_SYMBOLIC_DEBUG, symbDebugEnabled ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, symbRegNames ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_ENABLED : MF_DISABLED); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_LOAD_DEB_FILE, CHECKED_FLAG(debuggerSaveLoadDEBFiles)); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_SYMBOLIC_DEBUG, CHECKED_FLAG(symbDebugEnabled)); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, CHECKED_FLAG(inlineAddressEnabled)); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, CHECKED_FLAG(symbRegNames)); // Gray out potentially irrelavant options - EnableMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, symbDebugEnabled ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, symbDebugEnabled ? MF_ENABLED : MF_GRAYED); + EnableMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, ENABLED_FLAG(symbDebugEnabled)); + EnableMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, ENABLED_FLAG(symbDebugEnabled)); } INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -2135,7 +2139,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case DEBUGAUTOLOAD: debuggerAutoload ^= 1; break; - case DEBUGLOADDEB: + case DEBUGLOADDEB: // TODO: delete/merge with ID_DEBUGGER_LOAD_DEB_FILE debuggerSaveLoadDEBFiles = !debuggerSaveLoadDEBFiles; break; case DEBUGIDAFONT: @@ -2206,11 +2210,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case IDC_DEBUGGER_RESTORESIZE: RestoreSize(hwndDlg); break; - case ID_DEBUGGER_INLINE_ADDRESS: - inlineAddressEnabled ^= 1; - CheckMenuItem(GetSubMenu(GetMenu(hwndDlg), 2), ID_DEBUGGER_INLINE_ADDRESS, inlineAddressEnabled ? MF_CHECKED : MF_UNCHECKED); - UpdateDebugger(false); - break; // TODO: Reuse the old IDs from the persistent buttons instead? case ID_DEBUGGER_RELOAD_SYMBOLS: ramBankNamesLoaded = false; @@ -2219,16 +2218,20 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP loadNameFiles(); UpdateDebugger(false); break; + case ID_DEBUGGER_INLINE_ADDRESS: + inlineAddressEnabled ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); + UpdateDebugger(false); + break; case ID_DEBUGGER_LOAD_DEB_FILE: - printf("Coming soon!\n"); + debuggerSaveLoadDEBFiles ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); break; case ID_DEBUGGER_SYMBOLIC_DEBUG: - { symbDebugEnabled ^= 1; UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); UpdateDebugger(false); break; - } case ID_DEBUGGER_DEFAULT_REG_NAMES: symbRegNames ^= 1; UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); From 636ea70f8c81f052a6a97e564f4ab2ab550cee34 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 23:50:00 -0400 Subject: [PATCH 023/103] replace macros with inline functions Macros are cringe --- src/drivers/win/debugger.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 93249a5d5..c1abc5be1 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1942,19 +1942,26 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_COLORS_POS 1 #define MENU_SYMBOLS_POS 2 -#define CHECKED_FLAG(b) ((b) ? MF_CHECKED : MF_UNCHECKED) -#define ENABLED_FLAG(b) ((b) ? MF_ENABLED : MF_GRAYED) +inline int CheckedFlag(bool b) +{ + return b ? MF_CHECKED : MF_UNCHECKED; +} + +inline int EnabledFlag(bool b) +{ + return b ? MF_ENABLED : MF_GRAYED; +} inline void UpdateSymbolsPopup(HMENU symbolsPopup) { - CheckMenuItem(symbolsPopup, ID_DEBUGGER_LOAD_DEB_FILE, CHECKED_FLAG(debuggerSaveLoadDEBFiles)); - CheckMenuItem(symbolsPopup, ID_DEBUGGER_SYMBOLIC_DEBUG, CHECKED_FLAG(symbDebugEnabled)); - CheckMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, CHECKED_FLAG(inlineAddressEnabled)); - CheckMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, CHECKED_FLAG(symbRegNames)); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_LOAD_DEB_FILE, CheckedFlag(debuggerSaveLoadDEBFiles)); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_SYMBOLIC_DEBUG, CheckedFlag(symbDebugEnabled)); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, CheckedFlag(inlineAddressEnabled)); + CheckMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, CheckedFlag(symbRegNames)); // Gray out potentially irrelavant options - EnableMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, ENABLED_FLAG(symbDebugEnabled)); - EnableMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, ENABLED_FLAG(symbDebugEnabled)); + EnableMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, EnabledFlag(symbDebugEnabled)); + EnableMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, EnabledFlag(symbDebugEnabled)); } INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) From 92e258fa5c9e98e2319b28cb7c8c0a8826ab51c5 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 22 Jun 2021 23:59:29 -0400 Subject: [PATCH 024/103] add skeleton for options menu --- src/drivers/win/debugger.cpp | 24 +++++++++++++++++++----- src/drivers/win/res.rc | 8 ++++++++ src/drivers/win/resource.h | 4 ++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index c1abc5be1..b0b19599f 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -108,7 +108,6 @@ struct DBGCOLORMENU { { "RTS/RTI Line", PPCCF(DbgRts) } }; -#define IDC_DEBUGGER_RESTORESIZE 1000 #define ID_COLOR_DEBUGGER 2000 bool ChangeColor(HWND hwnd, DBGCOLORMENU* item) @@ -1952,6 +1951,11 @@ inline int EnabledFlag(bool b) return b ? MF_ENABLED : MF_GRAYED; } +inline void UpdateOptionsPopup(HMENU optionsPopup) +{ + +} + inline void UpdateSymbolsPopup(HMENU symbolsPopup) { CheckMenuItem(symbolsPopup, ID_DEBUGGER_LOAD_DEB_FILE, CheckedFlag(debuggerSaveLoadDEBFiles)); @@ -2052,12 +2056,11 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // prepare menu HMENU hdbgmenu = GetMenu(hwndDlg); - // This will go in a submenu soon. - InsertMenu(hdbgmenu, 0, MF_STRING | MF_BYPOSITION, IDC_DEBUGGER_RESTORESIZE, "Default window size"); HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, MENU_COLORS_POS); for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); + UpdateOptionsPopup(GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); UpdateSymbolsPopup(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); debugger_open = 1; @@ -2214,10 +2217,21 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } } break; - case IDC_DEBUGGER_RESTORESIZE: + // Options menu + // TODO: Reuse/merge with the old IDs from the persistent buttons. + case ID_DEBUGGER_AUTO_OPEN: + printf("Coming soon!\n"); + break; + case ID_DEBUGGER_IDA_FONT: + printf("Coming soon!\n"); + break; + case ID_DEBUGGER_SHOW_ROM_OFFSETS: + printf("Coming soon!\n"); + break; + case ID_DEBUGGER_RESTORE_SIZE: RestoreSize(hwndDlg); break; - // TODO: Reuse the old IDs from the persistent buttons instead? + // Symbols menu case ID_DEBUGGER_RELOAD_SYMBOLS: ramBankNamesLoaded = false; for (int i = 0; i < ARRAYSIZE(pageNumbersLoaded); i++) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 15c5151d4..1e6c65bfe 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3019,6 +3019,14 @@ END DEBUGGERMENU MENU BEGIN + POPUP "Options" + BEGIN + MENUITEM "Auto Open on ROM Load", ID_DEBUGGER_AUTO_OPEN, CHECKED + MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED + MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED + MENUITEM SEPARATOR + MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE + END POPUP "Colors" BEGIN MENUITEM SEPARATOR diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 70191f6d2..cbe4d332d 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1212,6 +1212,10 @@ #define ID_DEBUGGER_LOAD_DEB_FILE 45538 #define ID_DEBUGGER_SYMBOLIC_DEBUG 45539 #define ID_DEBUGGER_DEFAULT_REG_NAMES 45540 +#define ID_DEBUGGER_AUTO_OPEN 45541 +#define ID_DEBUGGER_IDA_FONT 45542 +#define ID_DEBUGGER_SHOW_ROM_OFFSETS 45543 +#define ID_DEBUGGER_RESTORE_SIZE 45544 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From ab7a4f01f0476ecece8b2e45f1b9d594432ff278 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 23 Jun 2021 00:46:02 -0400 Subject: [PATCH 025/103] MISSED ANOTHER ONE --- src/drivers/win/debugger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index b0b19599f..eec892553 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -140,7 +140,7 @@ int beginningOfPCPointerLine = -1; // index of the first char within debug_str[] void UpdateOtherDebuggingDialogs() { - //adelikat: This updates all the other dialogs such as ppu, nametable, logger, etc in one function, should be applied to all the step type buttons + //This updates all the other dialogs such as ppu, nametable, logger, etc in one function, should be applied to all the step type buttons NTViewDoBlit(0); //Nametable Viewer UpdateLogWindow(); //Trace Logger UpdateCDLogger(); //Code/Data Logger From 545a25b30f2dbcf0b0f620601801573cf3a81f82 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 23 Jun 2021 00:47:01 -0400 Subject: [PATCH 026/103] implement the Options menu --- src/drivers/win/debugger.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index eec892553..e729d1f30 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1953,7 +1953,9 @@ inline int EnabledFlag(bool b) inline void UpdateOptionsPopup(HMENU optionsPopup) { - + CheckMenuItem(optionsPopup, ID_DEBUGGER_AUTO_OPEN, CheckedFlag(debuggerAutoload)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_IDA_FONT, CheckedFlag(debuggerIDAFont)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_ROM_OFFSETS, CheckedFlag(debuggerDisplayROMoffsets)); } inline void UpdateSymbolsPopup(HMENU symbolsPopup) @@ -2146,13 +2148,13 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP { switch (LOWORD(wParam)) { - case DEBUGAUTOLOAD: + case DEBUGAUTOLOAD: // TODO: delete/merge with ID_DEBUGGER_AUTO_OPEN debuggerAutoload ^= 1; break; case DEBUGLOADDEB: // TODO: delete/merge with ID_DEBUGGER_LOAD_DEB_FILE debuggerSaveLoadDEBFiles = !debuggerSaveLoadDEBFiles; break; - case DEBUGIDAFONT: + case DEBUGIDAFONT: // TODO: delete/merge with ID_DEBUGGER_IDA_FONT debuggerIDAFont ^= 1; debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; @@ -2220,13 +2222,21 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // Options menu // TODO: Reuse/merge with the old IDs from the persistent buttons. case ID_DEBUGGER_AUTO_OPEN: - printf("Coming soon!\n"); + debuggerAutoload ^= 1; + UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); break; case ID_DEBUGGER_IDA_FONT: - printf("Coming soon!\n"); + debuggerIDAFont ^= 1; + debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; + debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; + SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); + UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); + UpdateDebugger(false); break; case ID_DEBUGGER_SHOW_ROM_OFFSETS: - printf("Coming soon!\n"); + debuggerDisplayROMoffsets ^= 1; + UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); + UpdateDebugger(false); break; case ID_DEBUGGER_RESTORE_SIZE: RestoreSize(hwndDlg); @@ -2673,7 +2683,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP // ################################## End of SP CODE ########################### case IDC_DEBUGGER_ROM_OFFSETS: - { + { // TODO: delete/merge with ID_DEBUGGER_SHOW_ROM_OFFSETS debuggerDisplayROMoffsets ^= 1; UpdateDebugger(false); break; From 7bc2d5e4a8aa2b556dadbfcbaf2c7f63e8fc7e20 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 23 Jun 2021 00:47:39 -0400 Subject: [PATCH 027/103] put color menu item labels in title case --- src/drivers/win/debugger.cpp | 6 +++--- src/drivers/win/res.rc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index e729d1f30..58656485e 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -98,12 +98,12 @@ struct DBGCOLORMENU { { NULL }, { "Mnemonic", PPCCF(DbgMnem) }, { NULL }, - { "Symbolic name", PPCCF(DbgSym) }, + { "Symbolic Name", PPCCF(DbgSym) }, { "Comment" , PPCCF(DbgComm) }, { NULL }, { "Operand" , PPCCF(DbgOper) }, - { "Operand note" , PPCCF(DbgOpNt) }, - { "Effective address", PPCCF(DbgEff) }, + { "Operand Note" , PPCCF(DbgOpNt) }, + { "Effective Address", PPCCF(DbgEff) }, { NULL }, { "RTS/RTI Line", PPCCF(DbgRts) } }; diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 1e6c65bfe..3da2d6daf 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3030,7 +3030,7 @@ BEGIN POPUP "Colors" BEGIN MENUITEM SEPARATOR - MENUITEM "Restore defaults", ID_DEBUGGER_DEFCOLOR + MENUITEM "Restore Defaults", ID_DEBUGGER_DEFCOLOR END POPUP "Symbols" BEGIN From b1db239d9a5550f89468c16e6af975e4f9232552 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 23 Jun 2021 12:24:57 -0400 Subject: [PATCH 028/103] add tools menu It runs the ROM patcher, as well as a placeholder for my planned code dumper ideas. --- src/drivers/win/debugger.cpp | 29 ++++++++++++++++++++++++++++- src/drivers/win/res.rc | 5 +++++ src/drivers/win/resource.h | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 58656485e..a6e87e6f8 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1940,6 +1940,7 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_OPTIONS_POS 0 #define MENU_COLORS_POS 1 #define MENU_SYMBOLS_POS 2 +#define MENU_TOOLS_POS 3 inline int CheckedFlag(bool b) { @@ -1970,8 +1971,15 @@ inline void UpdateSymbolsPopup(HMENU symbolsPopup) EnableMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, EnabledFlag(symbDebugEnabled)); } +inline void UpdateToolsPopup(HMENU symbolsPopup) +{ + EnableMenuItem(symbolsPopup, ID_DEBUGGER_ROM_PATCHER, EnabledFlag(GameInfo)); + EnableMenuItem(symbolsPopup, ID_DEBUGGER_CODE_DUMPER, EnabledFlag(GameInfo)); +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { + static HMENU toolsPopup = NULL; //these messages get handled at any time switch(uMsg) { @@ -2064,6 +2072,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP UpdateOptionsPopup(GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); UpdateSymbolsPopup(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); + UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); debugger_open = 1; inDebugger = true; @@ -2268,10 +2277,28 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); UpdateDebugger(false); break; + // Tools menu + case ID_DEBUGGER_ROM_PATCHER: + DoPatcher(-1, hwndDlg); + break; + case ID_DEBUGGER_CODE_DUMPER: + printf("Currently, I can only dump the contents of the visible window to console...\n\n"); + printf("%ls\n", debug_wstr); + break; } } } } + case WM_INITMENUPOPUP: + { + // LOWORD(lParam) == position in parent menu, but we can't get a handle to the parent... + HMENU menu = (HMENU)wParam; + if (menu == toolsPopup) + { + UpdateToolsPopup((HMENU)wParam); + } + break; + } } //these messages only get handled when a game is loaded @@ -2688,7 +2715,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP UpdateDebugger(false); break; } - case IDC_DEBUGGER_ROM_PATCHER: DoPatcher(-1,hwndDlg); break; + case IDC_DEBUGGER_ROM_PATCHER: DoPatcher(-1,hwndDlg); break; // TODO: delete/merge with ID_DEBUGGER_ROM_PATCHER case DEBUGGER_CONTEXT_TOGGLEBREAK: DebuggerCallB(hwndDlg, WM_COMMAND, (LBN_DBLCLK * 0x10000) | (IDC_DEBUGGER_BP_LIST), lParam); break; } break; diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 3da2d6daf..4267b3468 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3041,6 +3041,11 @@ BEGIN MENUITEM "Show Symbol Addresses", ID_DEBUGGER_INLINE_ADDRESS, CHECKED MENUITEM "Default Register Names", ID_DEBUGGER_DEFAULT_REG_NAMES, CHECKED END + POPUP "Tools" + BEGIN + MENUITEM "ROM Patcher...", ID_DEBUGGER_ROM_PATCHER + MENUITEM "Code Dumper...", ID_DEBUGGER_CODE_DUMPER + END END diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index cbe4d332d..fa66a0498 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1216,6 +1216,8 @@ #define ID_DEBUGGER_IDA_FONT 45542 #define ID_DEBUGGER_SHOW_ROM_OFFSETS 45543 #define ID_DEBUGGER_RESTORE_SIZE 45544 +#define ID_DEBUGGER_ROM_PATCHER 45545 +#define ID_DEBUGGER_CODE_DUMPER 45546 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From a44232d47e7d29fbc8c3048df1d1129854288e0e Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 23 Jun 2021 12:28:21 -0400 Subject: [PATCH 029/103] add a few comments --- src/drivers/win/debugger.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index a6e87e6f8..8603dc27d 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1028,6 +1028,7 @@ void UpdateDebugger(bool jump_to_pc) // "Address Bookmark Add" follows the address + // Update register values sprintf(str, "%02X", X.A); SetDlgItemText(hDebug, IDC_DEBUGGER_VAL_A, str); sprintf(str, "%02X", X.X); @@ -1107,6 +1108,7 @@ void UpdateDebugger(bool jump_to_pc) UpdateBreakpointsCaption(); + // Draw the stack tmp = X.S|0x0100; sprintf(str, "Stack $%04X", tmp); SetDlgItemText(hDebug, IDC_DEBUGGER_VAL_S, str); @@ -2716,6 +2718,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP break; } case IDC_DEBUGGER_ROM_PATCHER: DoPatcher(-1,hwndDlg); break; // TODO: delete/merge with ID_DEBUGGER_ROM_PATCHER + // Double click the breakpoint list case DEBUGGER_CONTEXT_TOGGLEBREAK: DebuggerCallB(hwndDlg, WM_COMMAND, (LBN_DBLCLK * 0x10000) | (IDC_DEBUGGER_BP_LIST), lParam); break; } break; @@ -2773,6 +2776,7 @@ void DoDebuggerStepInto() { if (!hDebug) return; + // Click the Step Into button DebuggerCallB(hDebug, WM_COMMAND, IDC_DEBUGGER_STEP_IN, 0); } From c1d2af7042c09d6443cc0066221ee0ccb1966249 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 24 Jun 2021 03:32:47 -0400 Subject: [PATCH 030/103] split out the "gameless" window callbacks into dedicated functions --- src/drivers/win/debugger.cpp | 587 ++++++++++++++++++----------------- 1 file changed, 308 insertions(+), 279 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 8603dc27d..9ad6dbc96 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1944,6 +1944,8 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_SYMBOLS_POS 2 #define MENU_TOOLS_POS 3 +HMENU toolsPopup; + inline int CheckedFlag(bool b) { return b ? MF_CHECKED : MF_UNCHECKED; @@ -1979,158 +1981,329 @@ inline void UpdateToolsPopup(HMENU symbolsPopup) EnableMenuItem(symbolsPopup, ID_DEBUGGER_CODE_DUMPER, EnabledFlag(GameInfo)); } -INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +void DebuggerInitDialog(HWND hwndDlg) { - static HMENU toolsPopup = NULL; - //these messages get handled at any time - switch(uMsg) - { - case WM_INITDIALOG: - { - char str[256] = { 0 }; - CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_CYCLES, break_on_cycles ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS, break_on_instructions ? BST_CHECKED : BST_UNCHECKED); - sprintf(str, "%u", (unsigned)break_cycles_limit); - SetDlgItemText(hwndDlg, IDC_DEBUGGER_CYCLES_EXCEED, str); - sprintf(str, "%u", (unsigned)break_instructions_limit); - SetDlgItemText(hwndDlg, IDC_DEBUGGER_INSTRUCTIONS_EXCEED, str); - - CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_BAD_OP, FCEUI_Debugger().badopbreak ? BST_CHECKED : BST_UNCHECKED); - - CheckDlgButton(hwndDlg, DEBUGLOADDEB, debuggerSaveLoadDEBFiles ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, DEBUGIDAFONT, debuggerIDAFont ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, DEBUGAUTOLOAD, debuggerAutoload ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_ROM_OFFSETS, debuggerDisplayROMoffsets ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_ENABLE_SYMBOLIC, symbDebugEnabled ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_PREDEFINED_REGS, symbRegNames ? BST_CHECKED : BST_UNCHECKED); - - if (DbgPosX==-32000) DbgPosX=0; //Just in case - if (DbgPosY==-32000) DbgPosY=0; - SetWindowPos(hwndDlg,0,DbgPosX,DbgPosY,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER); - - GetWindowRect(hwndDlg,&currDebuggerRect); - - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_ALL; - si.nMin = 0; - si.nMax = 0x10000; - si.nPos = 0; - si.nPage = 8; - SetScrollInfo(GetDlgItem(hwndDlg,IDC_DEBUGGER_DISASSEMBLY_VSCR),SB_CTL,&si,TRUE); - - //setup font - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_DISASSEMBLY,WM_SETFONT,(WPARAM)debugSystem->hDisasmFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_DISASSEMBLY_LEFT_PANEL,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_STACK_CONTENTS,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - - //text limits - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_A,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_X,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_Y,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PC,EM_SETLIMITTEXT,4,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_STACK_CONTENTS,EM_SETLIMITTEXT,383,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,EM_SETLIMITTEXT,4,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PPU,EM_SETLIMITTEXT,4,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_SPR,EM_SETLIMITTEXT,2,0); - - // limit input - // Don't limit address entry. See: debugcpp offsetStringToInt - DefaultEditCtrlProc = (WNDPROC) - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PC), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_A), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_X), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_Y), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); - - //I'm lazy, disable the controls which I can't mess with right now - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PPU,EM_SETREADONLY,TRUE,0); - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_SPR,EM_SETREADONLY,TRUE,0); + char str[256] = { 0 }; + CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_CYCLES, break_on_cycles ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS, break_on_instructions ? BST_CHECKED : BST_UNCHECKED); + sprintf(str, "%u", (unsigned)break_cycles_limit); + SetDlgItemText(hwndDlg, IDC_DEBUGGER_CYCLES_EXCEED, str); + sprintf(str, "%u", (unsigned)break_instructions_limit); + SetDlgItemText(hwndDlg, IDC_DEBUGGER_INSTRUCTIONS_EXCEED, str); + + CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_BAD_OP, FCEUI_Debugger().badopbreak ? BST_CHECKED : BST_UNCHECKED); + + CheckDlgButton(hwndDlg, DEBUGLOADDEB, debuggerSaveLoadDEBFiles ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, DEBUGIDAFONT, debuggerIDAFont ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, DEBUGAUTOLOAD, debuggerAutoload ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DEBUGGER_ROM_OFFSETS, debuggerDisplayROMoffsets ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DEBUGGER_ENABLE_SYMBOLIC, symbDebugEnabled ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DEBUGGER_PREDEFINED_REGS, symbRegNames ? BST_CHECKED : BST_UNCHECKED); + + if (DbgPosX==-32000) DbgPosX=0; //Just in case + if (DbgPosY==-32000) DbgPosY=0; + SetWindowPos(hwndDlg,0,DbgPosX,DbgPosY,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER); + + GetWindowRect(hwndDlg,&currDebuggerRect); + + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_ALL; + si.nMin = 0; + si.nMax = 0x10000; + si.nPos = 0; + si.nPage = 8; + SetScrollInfo(GetDlgItem(hwndDlg,IDC_DEBUGGER_DISASSEMBLY_VSCR),SB_CTL,&si,TRUE); + + //setup font + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_DISASSEMBLY,WM_SETFONT,(WPARAM)debugSystem->hDisasmFont,FALSE); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_DISASSEMBLY_LEFT_PANEL,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_STACK_CONTENTS,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); + + //text limits + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_A,EM_SETLIMITTEXT,2,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_X,EM_SETLIMITTEXT,2,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_Y,EM_SETLIMITTEXT,2,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PC,EM_SETLIMITTEXT,4,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_STACK_CONTENTS,EM_SETLIMITTEXT,383,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,EM_SETLIMITTEXT,4,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PPU,EM_SETLIMITTEXT,4,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_SPR,EM_SETLIMITTEXT,2,0); + + // limit input + // Don't limit address entry. See: debugcpp offsetStringToInt + DefaultEditCtrlProc = (WNDPROC) + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PC), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_A), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_X), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_Y), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); + + //I'm lazy, disable the controls which I can't mess with right now + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PPU,EM_SETREADONLY,TRUE,0); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_SPR,EM_SETREADONLY,TRUE,0); // ################################## Start of SP CODE ########################### - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BOOKMARK,EM_SETLIMITTEXT,4,0); - - LoadGameDebuggerData(hwndDlg); + SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BOOKMARK,EM_SETLIMITTEXT,4,0); + + LoadGameDebuggerData(hwndDlg); - debuggerWasActive = 1; + debuggerWasActive = 1; // ################################## End of SP CODE ########################### - // Enable Context Sub-Menus - hDebugcontext = LoadMenu(fceu_hInstance,"DEBUGCONTEXTMENUS"); - hDisasmcontext = LoadMenu(fceu_hInstance,"DISASMCONTEXTMENUS"); + // Enable Context Sub-Menus + hDebugcontext = LoadMenu(fceu_hInstance,"DEBUGCONTEXTMENUS"); + hDisasmcontext = LoadMenu(fceu_hInstance,"DISASMCONTEXTMENUS"); + + // prevent the font of the edit control from screwing up when it contains MBC or characters not contained the current font. + SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, EM_SETLANGOPTIONS, 0, SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, EM_GETLANGOPTIONS, 0, 0) & ~IMF_AUTOFONT); - // prevent the font of the edit control from screwing up when it contains MBC or characters not contained the current font. - SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, EM_SETLANGOPTIONS, 0, SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, EM_GETLANGOPTIONS, 0, 0) & ~IMF_AUTOFONT); + // subclass editfield + IDC_DEBUGGER_DISASSEMBLY_oldWndProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY), GWLP_WNDPROC, (LONG_PTR)IDC_DEBUGGER_DISASSEMBLY_WndProc); - // subclass editfield - IDC_DEBUGGER_DISASSEMBLY_oldWndProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY), GWLP_WNDPROC, (LONG_PTR)IDC_DEBUGGER_DISASSEMBLY_WndProc); + // prepare menu + HMENU hdbgmenu = GetMenu(hwndDlg); + HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, MENU_COLORS_POS); + for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) + InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); - // prepare menu - HMENU hdbgmenu = GetMenu(hwndDlg); - HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, MENU_COLORS_POS); - for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) - InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); + UpdateOptionsPopup(GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); + UpdateSymbolsPopup(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); + UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); - UpdateOptionsPopup(GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); - UpdateSymbolsPopup(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); - UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); + debugger_open = 1; + inDebugger = true; +} - debugger_open = 1; - inDebugger = true; +void DebuggerResizeWindow(HWND hwndDlg, UINT resizeType) +{ + if(resizeType == SIZE_RESTORED) //If dialog was resized + { + GetWindowRect(hwndDlg,&newDebuggerRect); //Get new size + + //Force a minimum Dialog size------------------------------- + DbgSizeX = newDebuggerRect.right - newDebuggerRect.left; //Store new size (this will be stored in the .cfg file) + DbgSizeY = newDebuggerRect.bottom - newDebuggerRect.top; + + // convert minimum size to actual screen size. + // the minimum height is different between left and right part, + // but width is the same, similarly hereinafter + HDC hdc = GetDC(hwndDlg); + int min_w = MulDiv(DEBUGGER_MIN_WIDTH, GetDeviceCaps(hdc, LOGPIXELSX), 96); + int min_h_l = MulDiv(DEBUGGER_MIN_HEIGHT_LEFT, GetDeviceCaps(hdc, LOGPIXELSY), 96); + int min_h_r = MulDiv(DEBUGGER_MIN_HEIGHT_RIGHT, GetDeviceCaps(hdc, LOGPIXELSY), 96); + ReleaseDC(hwndDlg, hdc); + + // calculate current width and height + int curr_w = currDebuggerRect.right - currDebuggerRect.left; + int curr_h_l = currDebuggerRect.bottom - currDebuggerRect.top; + int curr_h_r = curr_h_l; + // calculate new width and height + int new_w = newDebuggerRect.right - newDebuggerRect.left; + int new_h_l = newDebuggerRect.bottom - newDebuggerRect.top; + int new_h_r = new_h_l; + + // when the size is smaller than the minimum, calculate it as the minimum size + if (curr_w < min_w) curr_w = min_w; + if (curr_h_l < min_h_l) curr_h_l = min_h_l; + if (curr_h_r < min_h_r) curr_h_r = min_h_r; + + if (new_w < min_w) new_w = min_w; + if (new_h_l < min_h_l) new_h_l = min_h_l; + if (new_h_r < min_h_r) new_h_r = min_h_r; + + POINT p[2]; + // Calculate ditto with size + p[0].x = p[1].x = new_w - curr_w; + p[0].y = new_h_l - curr_h_l; + p[1].y = new_h_r - curr_h_r; + EnumChildWindows(hwndDlg, DebuggerEnumWindowsProc, (LPARAM)p); //Initiate callback for resizing child windows + InvalidateRect(hwndDlg, 0, TRUE); + UpdateWindow(hwndDlg); + currDebuggerRect = newDebuggerRect; //Store current debugger window size (for future calculations in EnumChildWindows) + } +} + +void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) +{ + printf("bnclicked: %d\n", btnId); + switch (btnId) + { + case DEBUGAUTOLOAD: // TODO: delete/merge with ID_DEBUGGER_AUTO_OPEN + debuggerAutoload ^= 1; + break; + case DEBUGLOADDEB: // TODO: delete/merge with ID_DEBUGGER_LOAD_DEB_FILE + debuggerSaveLoadDEBFiles = !debuggerSaveLoadDEBFiles; + break; + case DEBUGIDAFONT: // TODO: delete/merge with ID_DEBUGGER_IDA_FONT + debuggerIDAFont ^= 1; + debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; + debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; + SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); + UpdateDebugger(false); + break; + case IDC_DEBUGGER_CYCLES_EXCEED: + { + // Pretty sure this was dead code. BN_CLICKED is not equal to EN_CHANGE. + // Does it need to be moved to an EN_CHANGED callback? + //if (HIWORD(wParam) == EN_CHANGE) + //{ + // char str[16]; + // GetDlgItemText(hwndDlg, IDC_DEBUGGER_CYCLES_EXCEED, str, 16); + // break_cycles_limit = strtoul(str, NULL, 10); + //} break; } - case WM_SIZE: + case IDC_DEBUGGER_INSTRUCTIONS_EXCEED: { - if(wParam == SIZE_RESTORED) //If dialog was resized + // Pretty sure this was dead code. BN_CLICKED is not equal to EN_CHANGE. + // Does it need to be moved to an EN_CHANGED callback? + //if (HIWORD(wParam) == EN_CHANGE) + //{ + // char str[16]; + // GetDlgItemText(hwndDlg, IDC_DEBUGGER_INSTRUCTIONS_EXCEED, str, 16); + // break_instructions_limit = strtoul(str, NULL, 10); + //} + break; + } + case ID_DEBUGGER_DEFCOLOR: + { + if (!IsDebugColorDefault() && MessageBox(hwndDlg, "Do you want to restore all the colors to default?", "Restore default colors", MB_YESNO | MB_ICONINFORMATION) == IDYES) { - GetWindowRect(hwndDlg,&newDebuggerRect); //Get new size - - //Force a minimum Dialog size------------------------------- - DbgSizeX = newDebuggerRect.right - newDebuggerRect.left; //Store new size (this will be used to store in the .cfg file) - DbgSizeY = newDebuggerRect.bottom - newDebuggerRect.top; - - // convert minimum size to actual screen size. - // the minimum height is different between left and right part, - // but width is the same, similarly hereinafter - HDC hdc = GetDC(hwndDlg); - int min_w = MulDiv(DEBUGGER_MIN_WIDTH, GetDeviceCaps(hdc, LOGPIXELSX), 96); - int min_h_l = MulDiv(DEBUGGER_MIN_HEIGHT_LEFT, GetDeviceCaps(hdc, LOGPIXELSY), 96); - int min_h_r = MulDiv(DEBUGGER_MIN_HEIGHT_RIGHT, GetDeviceCaps(hdc, LOGPIXELSY), 96); - ReleaseDC(hwndDlg, hdc); - - // calculate current width and height - int curr_w = currDebuggerRect.right - currDebuggerRect.left; - int curr_h_l = currDebuggerRect.bottom - currDebuggerRect.top; - int curr_h_r = curr_h_l; - // calculate new width and height - int new_w = newDebuggerRect.right - newDebuggerRect.left; - int new_h_l = newDebuggerRect.bottom - newDebuggerRect.top; - int new_h_r = new_h_l; - - // when the size is smaller than the minimum, calculate it as the minimum size - if (curr_w < min_w) curr_w = min_w; - if (curr_h_l < min_h_l) curr_h_l = min_h_l; - if (curr_h_r < min_h_r) curr_h_r = min_h_r; - - if (new_w < min_w) new_w = min_w; - if (new_h_l < min_h_l) new_h_l = min_h_l; - if (new_h_r < min_h_r) new_h_r = min_h_r; - - POINT p[2]; - // Calculate ditto with size - p[0].x = p[1].x = new_w - curr_w; - p[0].y = new_h_l - curr_h_l; - p[1].y = new_h_r - curr_h_r; - EnumChildWindows(hwndDlg, DebuggerEnumWindowsProc, (LPARAM)p); //Initiate callback for resizing child windows - InvalidateRect(hwndDlg, 0, TRUE); - UpdateWindow(hwndDlg); - currDebuggerRect = newDebuggerRect; //Store current debugger window size (for future calculations in EnumChildWindows + RestoreDefaultDebugColor(); + RECT rect; + GetClientRect(GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY), &rect); + UpdateDisassembleView(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, (rect.bottom - rect.top) / debugSystem->disasmFontHeight); + HMENU hcolorpopupmenu = GetSubMenu(GetMenu(hwndDlg), 1); + for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) + ModifyColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); } - break; } + break; + case ID_COLOR_DEBUGGER: + case ID_COLOR_DEBUGGER + 1: + case ID_COLOR_DEBUGGER + 2: + case ID_COLOR_DEBUGGER + 3: + case ID_COLOR_DEBUGGER + 4: + case ID_COLOR_DEBUGGER + 5: + case ID_COLOR_DEBUGGER + 6: + case ID_COLOR_DEBUGGER + 7: + case ID_COLOR_DEBUGGER + 8: + case ID_COLOR_DEBUGGER + 9: + case ID_COLOR_DEBUGGER + 10: + case ID_COLOR_DEBUGGER + 11: + case ID_COLOR_DEBUGGER + 12: + { + int index = btnId - ID_COLOR_DEBUGGER; + if (ChangeColor(hwndDlg, &dbgcolormenu[index])) + { + RECT rect; + GetClientRect(GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY), &rect); + UpdateDisassembleView(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, (rect.bottom - rect.top) / debugSystem->disasmFontHeight); + ModifyColorMenu(hwndDlg, GetSubMenu(GetMenu(hwndDlg), 1), &dbgcolormenu[index].menu, index, btnId); + } + } + break; + // Options menu + // TODO: Reuse/merge with the old IDs from the persistent buttons. + case ID_DEBUGGER_AUTO_OPEN: + debuggerAutoload ^= 1; + UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); + break; + case ID_DEBUGGER_IDA_FONT: + debuggerIDAFont ^= 1; + debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; + debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; + SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); + UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); + UpdateDebugger(false); + break; + case ID_DEBUGGER_SHOW_ROM_OFFSETS: + debuggerDisplayROMoffsets ^= 1; + UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); + UpdateDebugger(false); + break; + case ID_DEBUGGER_RESTORE_SIZE: + RestoreSize(hwndDlg); + break; + // Symbols menu + case ID_DEBUGGER_RELOAD_SYMBOLS: + ramBankNamesLoaded = false; + for (int i = 0; i < ARRAYSIZE(pageNumbersLoaded); i++) + pageNumbersLoaded[i] = -1; + loadNameFiles(); + UpdateDebugger(false); + break; + case ID_DEBUGGER_INLINE_ADDRESS: + inlineAddressEnabled ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); + UpdateDebugger(false); + break; + case ID_DEBUGGER_LOAD_DEB_FILE: + debuggerSaveLoadDEBFiles ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); + break; + case ID_DEBUGGER_SYMBOLIC_DEBUG: + symbDebugEnabled ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); + UpdateDebugger(false); + break; + case ID_DEBUGGER_DEFAULT_REG_NAMES: + symbRegNames ^= 1; + UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); + UpdateDebugger(false); + break; + // Tools menu + case ID_DEBUGGER_ROM_PATCHER: + DoPatcher(-1, hwndDlg); + break; + case ID_DEBUGGER_CODE_DUMPER: + printf("Currently, I can only dump the contents of the visible window to console...\n\n"); + printf("%ls\n", debug_wstr); + break; + } +} +void DebuggerInitMenuPopup(HWND hwndDlg, HMENU hmenu, uint16 pos, bool isWindowMenu) +{ + // We have position in parent menu, but we can't get a handle to the parent... + if (hmenu == toolsPopup) + { + UpdateToolsPopup(hmenu); + } +} +void DebuggerMoveWindow(HWND hwndDlg, uint16 x, uint16 y) +{ + if (!IsIconic(hwndDlg)) + { + RECT wrect; + GetWindowRect(hwndDlg,&wrect); + DbgPosX = wrect.left; + DbgPosY = wrect.top; + + #ifdef WIN32 + WindowBoundsCheckResize(DbgPosX,DbgPosY,DbgSizeX,wrect.right); + #endif + } +} + +INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + //these messages get handled at any time + switch(uMsg) + { + case WM_INITDIALOG: + { + DebuggerInitDialog(hwndDlg); + break; + } + case WM_SIZE: + { + DebuggerResizeWindow(hwndDlg, wParam); + break; + } case WM_CLOSE: case WM_QUIT: DebuggerExit(); @@ -2138,16 +2311,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case WM_MOVING: break; case WM_MOVE: - if (!IsIconic(hwndDlg)) { - RECT wrect; - GetWindowRect(hwndDlg,&wrect); - DbgPosX = wrect.left; - DbgPosY = wrect.top; - - #ifdef WIN32 - WindowBoundsCheckResize(DbgPosX,DbgPosY,DbgSizeX,wrect.right); - #endif - } + DebuggerMoveWindow(hwndDlg, LOWORD(lParam), HIWORD(lParam)); break; // Buttons that don't need a rom loaded to do something, such as autoload @@ -2157,148 +2321,14 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP { case BN_CLICKED: { - switch (LOWORD(wParam)) - { - case DEBUGAUTOLOAD: // TODO: delete/merge with ID_DEBUGGER_AUTO_OPEN - debuggerAutoload ^= 1; - break; - case DEBUGLOADDEB: // TODO: delete/merge with ID_DEBUGGER_LOAD_DEB_FILE - debuggerSaveLoadDEBFiles = !debuggerSaveLoadDEBFiles; - break; - case DEBUGIDAFONT: // TODO: delete/merge with ID_DEBUGGER_IDA_FONT - debuggerIDAFont ^= 1; - debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; - debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; - SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); - UpdateDebugger(false); - break; - case IDC_DEBUGGER_CYCLES_EXCEED: - { - if (HIWORD(wParam) == EN_CHANGE) - { - char str[16]; - GetDlgItemText(hwndDlg, IDC_DEBUGGER_CYCLES_EXCEED, str, 16); - break_cycles_limit = strtoul(str, NULL, 10); - } - break; - } - case IDC_DEBUGGER_INSTRUCTIONS_EXCEED: - { - if (HIWORD(wParam) == EN_CHANGE) - { - char str[16]; - GetDlgItemText(hwndDlg, IDC_DEBUGGER_INSTRUCTIONS_EXCEED, str, 16); - break_instructions_limit = strtoul(str, NULL, 10); - } - break; - } - case ID_DEBUGGER_DEFCOLOR: - { - if (!IsDebugColorDefault() && MessageBox(hwndDlg, "Do you want to restore all the colors to default?", "Restore default colors", MB_YESNO | MB_ICONINFORMATION) == IDYES) - { - RestoreDefaultDebugColor(); - RECT rect; - GetClientRect(GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY), &rect); - UpdateDisassembleView(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, (rect.bottom - rect.top) / debugSystem->disasmFontHeight); - HMENU hcolorpopupmenu = GetSubMenu(GetMenu(hwndDlg), 1); - for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) - ModifyColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); - } - } - break; - case ID_COLOR_DEBUGGER: - case ID_COLOR_DEBUGGER + 1: - case ID_COLOR_DEBUGGER + 2: - case ID_COLOR_DEBUGGER + 3: - case ID_COLOR_DEBUGGER + 4: - case ID_COLOR_DEBUGGER + 5: - case ID_COLOR_DEBUGGER + 6: - case ID_COLOR_DEBUGGER + 7: - case ID_COLOR_DEBUGGER + 8: - case ID_COLOR_DEBUGGER + 9: - case ID_COLOR_DEBUGGER + 10: - case ID_COLOR_DEBUGGER + 11: - case ID_COLOR_DEBUGGER + 12: - { - int index = wParam - ID_COLOR_DEBUGGER; - if (ChangeColor(hwndDlg, &dbgcolormenu[index])) - { - RECT rect; - GetClientRect(GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY), &rect); - UpdateDisassembleView(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, (rect.bottom - rect.top) / debugSystem->disasmFontHeight); - ModifyColorMenu(hwndDlg, GetSubMenu(GetMenu(hwndDlg), 1), &dbgcolormenu[index].menu, index, wParam); - } - } - break; - // Options menu - // TODO: Reuse/merge with the old IDs from the persistent buttons. - case ID_DEBUGGER_AUTO_OPEN: - debuggerAutoload ^= 1; - UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); - break; - case ID_DEBUGGER_IDA_FONT: - debuggerIDAFont ^= 1; - debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; - debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; - SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); - UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); - UpdateDebugger(false); - break; - case ID_DEBUGGER_SHOW_ROM_OFFSETS: - debuggerDisplayROMoffsets ^= 1; - UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); - UpdateDebugger(false); - break; - case ID_DEBUGGER_RESTORE_SIZE: - RestoreSize(hwndDlg); - break; - // Symbols menu - case ID_DEBUGGER_RELOAD_SYMBOLS: - ramBankNamesLoaded = false; - for (int i = 0; i < ARRAYSIZE(pageNumbersLoaded); i++) - pageNumbersLoaded[i] = -1; - loadNameFiles(); - UpdateDebugger(false); - break; - case ID_DEBUGGER_INLINE_ADDRESS: - inlineAddressEnabled ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); - UpdateDebugger(false); - break; - case ID_DEBUGGER_LOAD_DEB_FILE: - debuggerSaveLoadDEBFiles ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); - break; - case ID_DEBUGGER_SYMBOLIC_DEBUG: - symbDebugEnabled ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); - UpdateDebugger(false); - break; - case ID_DEBUGGER_DEFAULT_REG_NAMES: - symbRegNames ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); - UpdateDebugger(false); - break; - // Tools menu - case ID_DEBUGGER_ROM_PATCHER: - DoPatcher(-1, hwndDlg); - break; - case ID_DEBUGGER_CODE_DUMPER: - printf("Currently, I can only dump the contents of the visible window to console...\n\n"); - printf("%ls\n", debug_wstr); - break; - } + DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; } } } case WM_INITMENUPOPUP: { - // LOWORD(lParam) == position in parent menu, but we can't get a handle to the parent... - HMENU menu = (HMENU)wParam; - if (menu == toolsPopup) - { - UpdateToolsPopup((HMENU)wParam); - } + DebuggerInitMenuPopup(hwndDlg, (HMENU)wParam, LOWORD(lParam), HIWORD(lParam)); break; } } @@ -2766,7 +2796,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } } - return FALSE; } From 6b004b448291b61d740cf18143b47251e4a6bfac Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 24 Jun 2021 07:11:59 -0400 Subject: [PATCH 031/103] split out some of the "gameful" callbacks into dedicated functions My personal favorite is the WM_MOUSEWHEEL one. The lParam contains cursor X and Y coords, but someone had misinterpreted it as a handle to the scrollbar and used it to update the scroll info. So what happened? Garbage pointer dereference leading to nonsense scrolling and crashes? Nope! The ScrollInfo calls silently did nothing and everything worked as intended. --- src/drivers/win/debugger.cpp | 763 ++++++++++++++++++----------------- 1 file changed, 399 insertions(+), 364 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 9ad6dbc96..07722f5df 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1946,6 +1946,8 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w HMENU toolsPopup; +INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + inline int CheckedFlag(bool b) { return b ? MF_CHECKED : MF_UNCHECKED; @@ -2127,7 +2129,7 @@ void DebuggerResizeWindow(HWND hwndDlg, UINT resizeType) void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) { - printf("bnclicked: %d\n", btnId); + // Buttons that don't need a rom loaded to do something, such as autoload switch (btnId) { case DEBUGAUTOLOAD: // TODO: delete/merge with ID_DEBUGGER_AUTO_OPEN @@ -2263,6 +2265,255 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) printf("%ls\n", debug_wstr); break; } + + // Buttons that only get handled when a game is loaded + if (GameInfo) + { + switch (btnId) + { + case IDC_DEBUGGER_BP_ADD: + childwnd = 1; + if (DialogBoxParam(fceu_hInstance,"ADDBP",hwndDlg,AddbpCallB, 0)) AddBreakList(); + childwnd = 0; + UpdateDebugger(false); + break; + case IDC_DEBUGGER_BP_DEL: + DeleteBreak(SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0)); + break; + case IDC_DEBUGGER_BP_EDIT: + WP_edit = SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0); + if (DialogBoxParam(fceu_hInstance, "ADDBP", hwndDlg, AddbpCallB, 0)) EditBreakList(); + WP_edit = -1; + UpdateDebugger(false); + break; + case IDC_DEBUGGER_RUN: + if (FCEUI_EmulationPaused()) { + UpdateRegs(hwndDlg); + FCEUI_ToggleEmulationPause(); + //DebuggerWasUpdated = false done in above function; + } + break; + case IDC_DEBUGGER_STEP_IN: + if (FCEUI_EmulationPaused()) + UpdateRegs(hwndDlg); + FCEUI_Debugger().step = true; + FCEUI_SetEmulationPaused(0); + UpdateOtherDebuggingDialogs(); + + break; + case IDC_DEBUGGER_RUN_LINE: + if (FCEUI_EmulationPaused()) + UpdateRegs(hwndDlg); + FCEUI_Debugger().runline = true; + { + uint64 ts=timestampbase; + ts+=timestamp; + ts+=341/3; + FCEUI_Debugger().runline_end_time=ts; + } + FCEUI_SetEmulationPaused(0); + UpdateOtherDebuggingDialogs(); + break; + case IDC_DEBUGGER_RUN_FRAME2: + if (FCEUI_EmulationPaused()) + UpdateRegs(hwndDlg); + FCEUI_Debugger().runline = true; + { + uint64 ts=timestampbase; + ts+=timestamp; + ts+=128*341/3; + FCEUI_Debugger().runline_end_time=ts; + } + FCEUI_SetEmulationPaused(0); + UpdateOtherDebuggingDialogs(); + break; + case IDC_DEBUGGER_STEP_OUT: + if (FCEUI_EmulationPaused() > 0) { + DebuggerState &dbgstate = FCEUI_Debugger(); + UpdateRegs(hwndDlg); + if ((dbgstate.stepout) && (MessageBox(hwndDlg,"Step Out is currently in process. Cancel it and setup a new Step Out watch?","Step Out Already Active",MB_YESNO|MB_ICONINFORMATION) != IDYES)) break; + if (GetMem(X.PC) == 0x20) dbgstate.jsrcount = 1; + else dbgstate.jsrcount = 0; + dbgstate.stepout = 1; + FCEUI_SetEmulationPaused(0); + } + break; + case IDC_DEBUGGER_STEP_OVER: + if (FCEUI_EmulationPaused()) { + UpdateRegs(hwndDlg); + int tmp = X.PC; + uint8 opcode = GetMem(tmp); + bool jsr = opcode==0x20; + bool call = jsr; + #ifdef BRK_3BYTE_HACK + //with this hack, treat BRK similar to JSR + if(opcode == 0x00) + call = true; + #endif + if (call) { + if ((watchpoint[64].flags) && (MessageBox(hwndDlg,"Step Over is currently in process. Cancel it and setup a new Step Over watch?","Step Over Already Active",MB_YESNO|MB_ICONINFORMATION) != IDYES)) break; + watchpoint[64].address = (tmp+3); + watchpoint[64].flags = WP_E|WP_X; + } + else FCEUI_Debugger().step = true; + FCEUI_SetEmulationPaused(0); + } + break; + case IDC_DEBUGGER_SEEK_PC: + if (FCEUI_EmulationPaused()) + { + UpdateRegs(hwndDlg); + UpdateDebugger(true); + } + break; + case IDC_DEBUGGER_SEEK_TO: + { + if (FCEUI_EmulationPaused()) + UpdateRegs(hwndDlg); + char str[16]; + GetDlgItemText(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,str,5); + int tmp = offsetStringToInt(BT_C, str); + if (tmp != -1) + { + sprintf(str,"%04X", tmp); + SetDlgItemText(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,str); + Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, tmp); + // "Address Bookmark Add" follows the address + sprintf(str,"%04X", si.nPos); + SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); + } + break; + } + case IDC_DEBUGGER_BREAK_ON_BAD_OP: //Break on bad opcode + FCEUI_Debugger().badopbreak ^= 1; + break; + case IDC_DEBUGGER_FLAG_N: X.P^=N_FLAG; UpdateDebugger(false); break; + case IDC_DEBUGGER_FLAG_V: X.P^=V_FLAG; UpdateDebugger(false); break; + case IDC_DEBUGGER_FLAG_U: X.P^=U_FLAG; UpdateDebugger(false); break; + case IDC_DEBUGGER_FLAG_B: X.P^=B_FLAG; UpdateDebugger(false); break; + case IDC_DEBUGGER_FLAG_D: X.P^=D_FLAG; UpdateDebugger(false); break; + case IDC_DEBUGGER_FLAG_I: X.P^=I_FLAG; UpdateDebugger(false); break; + case IDC_DEBUGGER_FLAG_Z: X.P^=Z_FLAG; UpdateDebugger(false); break; + case IDC_DEBUGGER_FLAG_C: X.P^=C_FLAG; UpdateDebugger(false); break; + + case IDC_DEBUGGER_RESET_COUNTERS: + { + ResetDebugStatisticsCounters(); + UpdateDebugger(false); + break; + } + case IDC_DEBUGGER_BREAK_ON_CYCLES: + { + break_on_cycles ^= 1; + break; + } + case IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS: + { + break_on_instructions ^= 1; + break; + } + +// ################################## Start of SP CODE ########################### + + case IDC_DEBUGGER_RELOAD_SYMS: + { // TODO: delete/merge with ID_DEBUGGER_RELOAD_SYMBOLS + ramBankNamesLoaded = false; + for(int i=0;i= 0) + { + EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_DEL),TRUE); + EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_EDIT),TRUE); + } else + { + EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_DEL),FALSE); + EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_EDIT),FALSE); + } + break; + } + } } void DebuggerInitMenuPopup(HWND hwndDlg, HMENU hmenu, uint16 pos, bool isWindowMenu) @@ -2289,21 +2540,144 @@ void DebuggerMoveWindow(HWND hwndDlg, uint16 x, uint16 y) } } +void DebuggerWindowActivate(HWND hwndDlg, uint16 eventType, HWND hwndActivated) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + // Prevents numerous situations where the debugger is out of sync with the data + if (eventType != WA_INACTIVE) + { + UpdateDebugger(false); + } + else + { + if (FCEUI_EmulationPaused()) + UpdateRegs(hwndDlg); + } +} + +void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwndScrollBar) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + if (FCEUI_EmulationPaused()) + UpdateRegs(hwndDlg); + + if (hwndScrollBar) + { + GetScrollInfo(hwndScrollBar, SB_CTL, &si); + switch (eventType) + { + case SB_ENDSCROLL: + case SB_TOP: + case SB_BOTTOM: break; + case SB_LINEUP: + { + si.nPos = InstructionUp(si.nPos); + break; + } + case SB_LINEDOWN: + { + si.nPos = InstructionDown(si.nPos); + break; + } + case SB_PAGEUP: + { + for (int i = si.nPage; i > 0; i--) + { + si.nPos = InstructionUp(si.nPos); + if (si.nPos < si.nMin) + { + si.nPos = si.nMin; + break; + } + } + break; + } + case SB_PAGEDOWN: + { + for (int i = si.nPage; i > 0; i--) + { + si.nPos = InstructionDown(si.nPos); + if ((si.nPos + (int)si.nPage) > si.nMax) + { + si.nPos = si.nMax - si.nPage; + break; + } + } + break; + } + case SB_THUMBPOSITION: + case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; + } + if (si.nPos < si.nMin) + si.nPos = si.nMin; + if ((si.nPos + (int)si.nPage) > si.nMax) + si.nPos = si.nMax - si.nPage; + SetScrollInfo(hwndScrollBar, SB_CTL, &si, TRUE); + + Disassemble(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); + // The address in the Add Bookmark textbox follows the scroll pos. + char str[16]; + sprintf(str,"%04X", si.nPos); + SetDlgItemText(hwndDlg, IDC_DEBUGGER_BOOKMARK, str); + } +} + +void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 cursorY, uint16 vkeyFlags, LPARAM jankyHandle) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + // Try to scroll up or down in units of 8 lines + int i = rotAmt / WHEEL_DELTA; + if (i < 0) + { + for (i *= -(int)si.nPage; i > 0; i--) + { + si.nPos = InstructionDown(si.nPos); + if ((si.nPos + (int)si.nPage) > si.nMax) + { + si.nPos = si.nMax - si.nPage; + break; + } + } + } else if (i > 0) + { + for (i *= si.nPage; i > 0; i--) + { + si.nPos = InstructionUp(si.nPos); + if (si.nPos < si.nMin) + { + si.nPos = si.nMin; + break; + } + } + } + + // This function calls UpdateScrollInfo. Don't worry! + Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); + // The address in the Add Bookmark textbox follows the scroll pos. + char str[16]; + sprintf(str,"%04X", si.nPos); + SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - //these messages get handled at any time - switch(uMsg) + switch (uMsg) { case WM_INITDIALOG: - { DebuggerInitDialog(hwndDlg); break; - } case WM_SIZE: - { DebuggerResizeWindow(hwndDlg, wParam); break; - } case WM_CLOSE: case WM_QUIT: DebuggerExit(); @@ -2313,24 +2687,34 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case WM_MOVE: DebuggerMoveWindow(hwndDlg, LOWORD(lParam), HIWORD(lParam)); break; - - // Buttons that don't need a rom loaded to do something, such as autoload case WM_COMMAND: - { switch (HIWORD(wParam)) { case BN_CLICKED: - { DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); break; - } + case LBN_DBLCLK: + DebuggerDblClk(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case LBN_SELCANCEL: + DebuggerSelCancel(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case LBN_SELCHANGE: + DebuggerSelChange(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; } - } case WM_INITMENUPOPUP: - { DebuggerInitMenuPopup(hwndDlg, (HMENU)wParam, LOWORD(lParam), HIWORD(lParam)); break; - } + case WM_ACTIVATE: + DebuggerWindowActivate(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case WM_VSCROLL: + DebuggerVScroll(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); + break; + case WM_MOUSEWHEEL: + DebuggerMouseWheel(hwndDlg, HIWORD(wParam), LOWORD(lParam), HIWORD(lParam), LOWORD(wParam), lParam); + break; } //these messages only get handled when a game is loaded @@ -2338,84 +2722,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP { switch(uMsg) { - case WM_ACTIVATE: - { - //Prevents numerous situations where the debugger is out of date with the data - if (LOWORD(wParam) != WA_INACTIVE) - { - UpdateDebugger(false); - } else - { - if (FCEUI_EmulationPaused()) - UpdateRegs(hwndDlg); - } - break; - } - case WM_VSCROLL: - { - if (FCEUI_EmulationPaused()) - UpdateRegs(hwndDlg); - if (lParam) - { - GetScrollInfo((HWND)lParam,SB_CTL,&si); - switch(LOWORD(wParam)) - { - case SB_ENDSCROLL: - case SB_TOP: - case SB_BOTTOM: break; - case SB_LINEUP: - { - si.nPos = InstructionUp(si.nPos); - break; - } - case SB_LINEDOWN: - { - si.nPos = InstructionDown(si.nPos); - break; - } - case SB_PAGEUP: - { - for (int i = si.nPage; i > 0; i--) - { - si.nPos = InstructionUp(si.nPos); - if (si.nPos < si.nMin) - { - si.nPos = si.nMin; - break; - } - } - break; - } - case SB_PAGEDOWN: - { - for (int i = si.nPage; i > 0; i--) - { - si.nPos = InstructionDown(si.nPos); - if ((si.nPos + (int)si.nPage) > si.nMax) - { - si.nPos = si.nMax - si.nPage; - break; - } - } - break; - } - case SB_THUMBPOSITION: - case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; - } - if (si.nPos < si.nMin) - si.nPos = si.nMin; - if ((si.nPos + (int)si.nPage) > si.nMax) - si.nPos = si.nMax - si.nPage; - SetScrollInfo((HWND)lParam,SB_CTL,&si,TRUE); - - Disassemble(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); - // "Address Bookmark Add" follows the address - char str[16]; - sprintf(str,"%04X", si.nPos); - SetDlgItemText(hwndDlg, IDC_DEBUGGER_BOOKMARK, str); - } - break; - } case WM_CONTEXTMENU: { // Handle certain stubborn context menus for nearly incapable controls. @@ -2435,46 +2741,9 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } break; } - case WM_MOUSEWHEEL: - { - GetScrollInfo((HWND)lParam,SB_CTL,&si); - int i = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA; - if (i < 0) - { - for (i *= -(int)si.nPage; i > 0; i--) - { - si.nPos = InstructionDown(si.nPos); - if ((si.nPos + (int)si.nPage) > si.nMax) - { - si.nPos = si.nMax - si.nPage; - break; - } - } - } else if (i > 0) - { - for (i *= si.nPage; i > 0; i--) - { - si.nPos = InstructionUp(si.nPos); - if (si.nPos < si.nMin) - { - si.nPos = si.nMin; - break; - } - } - } - SetScrollInfo((HWND)lParam,SB_CTL,&si,TRUE); - - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); - // "Address Bookmark Add" follows the address - char str[16]; - sprintf(str,"%04X", si.nPos); - SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); - break; - } case WM_KEYDOWN: MessageBox(hwndDlg,"Die!","I'm dead!",MB_YESNO|MB_ICONINFORMATION); break; - case WM_MOUSEMOVE: { int mouse_x = GET_X_LPARAM(lParam); @@ -2559,240 +2828,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP } break; } - case WM_INITMENUPOPUP: - case WM_INITMENU: - break; - case WM_COMMAND: - { - switch(HIWORD(wParam)) - { - case BN_CLICKED: - switch(LOWORD(wParam)) { - case IDC_DEBUGGER_BP_ADD: - childwnd = 1; - if (DialogBoxParam(fceu_hInstance,"ADDBP",hwndDlg,AddbpCallB, 0)) AddBreakList(); - childwnd = 0; - UpdateDebugger(false); - break; - case IDC_DEBUGGER_BP_DEL: - DeleteBreak(SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0)); - break; - case IDC_DEBUGGER_BP_EDIT: - WP_edit = SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0); - if (DialogBoxParam(fceu_hInstance, "ADDBP", hwndDlg, AddbpCallB, 0)) EditBreakList(); - WP_edit = -1; - UpdateDebugger(false); - break; - case IDC_DEBUGGER_RUN: - if (FCEUI_EmulationPaused()) { - UpdateRegs(hwndDlg); - FCEUI_ToggleEmulationPause(); - //DebuggerWasUpdated = false done in above function; - } - break; - case IDC_DEBUGGER_STEP_IN: - if (FCEUI_EmulationPaused()) - UpdateRegs(hwndDlg); - FCEUI_Debugger().step = true; - FCEUI_SetEmulationPaused(0); - UpdateOtherDebuggingDialogs(); - - break; - case IDC_DEBUGGER_RUN_LINE: - if (FCEUI_EmulationPaused()) - UpdateRegs(hwndDlg); - FCEUI_Debugger().runline = true; - { - uint64 ts=timestampbase; - ts+=timestamp; - ts+=341/3; - FCEUI_Debugger().runline_end_time=ts; - } - FCEUI_SetEmulationPaused(0); - UpdateOtherDebuggingDialogs(); - break; - case IDC_DEBUGGER_RUN_FRAME2: - if (FCEUI_EmulationPaused()) - UpdateRegs(hwndDlg); - FCEUI_Debugger().runline = true; - { - uint64 ts=timestampbase; - ts+=timestamp; - ts+=128*341/3; - FCEUI_Debugger().runline_end_time=ts; - } - FCEUI_SetEmulationPaused(0); - UpdateOtherDebuggingDialogs(); - break; - case IDC_DEBUGGER_STEP_OUT: - if (FCEUI_EmulationPaused() > 0) { - DebuggerState &dbgstate = FCEUI_Debugger(); - UpdateRegs(hwndDlg); - if ((dbgstate.stepout) && (MessageBox(hwndDlg,"Step Out is currently in process. Cancel it and setup a new Step Out watch?","Step Out Already Active",MB_YESNO|MB_ICONINFORMATION) != IDYES)) break; - if (GetMem(X.PC) == 0x20) dbgstate.jsrcount = 1; - else dbgstate.jsrcount = 0; - dbgstate.stepout = 1; - FCEUI_SetEmulationPaused(0); - } - break; - case IDC_DEBUGGER_STEP_OVER: - if (FCEUI_EmulationPaused()) { - UpdateRegs(hwndDlg); - int tmp = X.PC; - uint8 opcode = GetMem(tmp); - bool jsr = opcode==0x20; - bool call = jsr; - #ifdef BRK_3BYTE_HACK - //with this hack, treat BRK similar to JSR - if(opcode == 0x00) - call = true; - #endif - if (call) { - if ((watchpoint[64].flags) && (MessageBox(hwndDlg,"Step Over is currently in process. Cancel it and setup a new Step Over watch?","Step Over Already Active",MB_YESNO|MB_ICONINFORMATION) != IDYES)) break; - watchpoint[64].address = (tmp+3); - watchpoint[64].flags = WP_E|WP_X; - } - else FCEUI_Debugger().step = true; - FCEUI_SetEmulationPaused(0); - } - break; - case IDC_DEBUGGER_SEEK_PC: - if (FCEUI_EmulationPaused()) - { - UpdateRegs(hwndDlg); - UpdateDebugger(true); - } - break; - case IDC_DEBUGGER_SEEK_TO: - { - if (FCEUI_EmulationPaused()) - UpdateRegs(hwndDlg); - char str[16]; - GetDlgItemText(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,str,5); - int tmp = offsetStringToInt(BT_C, str); - if (tmp != -1) - { - sprintf(str,"%04X", tmp); - SetDlgItemText(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,str); - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, tmp); - // "Address Bookmark Add" follows the address - sprintf(str,"%04X", si.nPos); - SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); - } - break; - } - case IDC_DEBUGGER_BREAK_ON_BAD_OP: //Break on bad opcode - FCEUI_Debugger().badopbreak ^= 1; - break; - case IDC_DEBUGGER_FLAG_N: X.P^=N_FLAG; UpdateDebugger(false); break; - case IDC_DEBUGGER_FLAG_V: X.P^=V_FLAG; UpdateDebugger(false); break; - case IDC_DEBUGGER_FLAG_U: X.P^=U_FLAG; UpdateDebugger(false); break; - case IDC_DEBUGGER_FLAG_B: X.P^=B_FLAG; UpdateDebugger(false); break; - case IDC_DEBUGGER_FLAG_D: X.P^=D_FLAG; UpdateDebugger(false); break; - case IDC_DEBUGGER_FLAG_I: X.P^=I_FLAG; UpdateDebugger(false); break; - case IDC_DEBUGGER_FLAG_Z: X.P^=Z_FLAG; UpdateDebugger(false); break; - case IDC_DEBUGGER_FLAG_C: X.P^=C_FLAG; UpdateDebugger(false); break; - - case IDC_DEBUGGER_RESET_COUNTERS: - { - ResetDebugStatisticsCounters(); - UpdateDebugger(false); - break; - } - case IDC_DEBUGGER_BREAK_ON_CYCLES: - { - break_on_cycles ^= 1; - break; - } - case IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS: - { - break_on_instructions ^= 1; - break; - } - -// ################################## Start of SP CODE ########################### - - case IDC_DEBUGGER_RELOAD_SYMS: - { // TODO: delete/merge with ID_DEBUGGER_RELOAD_SYMBOLS - ramBankNamesLoaded = false; - for(int i=0;i= 0) - { - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_DEL),TRUE); - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_EDIT),TRUE); - } else - { - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_DEL),FALSE); - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_EDIT),FALSE); - } - break; - } - } - break; - } - break; - } } } From d3a15d78ae7eb1cb2d56949b0154adaf6bb796e6 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 24 Jun 2021 07:22:43 -0400 Subject: [PATCH 032/103] move UpdateSymbolsPopup calls into DebuggerInitMenuPopup --- src/drivers/win/debugger.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 07722f5df..225241baa 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1944,7 +1944,7 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_SYMBOLS_POS 2 #define MENU_TOOLS_POS 3 -HMENU toolsPopup; +HMENU toolsPopup, symbolsPopup; INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -1975,6 +1975,7 @@ inline void UpdateSymbolsPopup(HMENU symbolsPopup) // Gray out potentially irrelavant options EnableMenuItem(symbolsPopup, ID_DEBUGGER_DEFAULT_REG_NAMES, EnabledFlag(symbDebugEnabled)); EnableMenuItem(symbolsPopup, ID_DEBUGGER_INLINE_ADDRESS, EnabledFlag(symbDebugEnabled)); + EnableMenuItem(symbolsPopup, ID_DEBUGGER_RELOAD_SYMBOLS, EnabledFlag(GameInfo)); } inline void UpdateToolsPopup(HMENU symbolsPopup) @@ -2071,7 +2072,7 @@ void DebuggerInitDialog(HWND hwndDlg) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); UpdateOptionsPopup(GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); - UpdateSymbolsPopup(GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); + UpdateSymbolsPopup(symbolsPopup = GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); debugger_open = 1; @@ -2239,21 +2240,17 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) break; case ID_DEBUGGER_INLINE_ADDRESS: inlineAddressEnabled ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); UpdateDebugger(false); break; case ID_DEBUGGER_LOAD_DEB_FILE: debuggerSaveLoadDEBFiles ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); break; case ID_DEBUGGER_SYMBOLIC_DEBUG: symbDebugEnabled ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); UpdateDebugger(false); break; case ID_DEBUGGER_DEFAULT_REG_NAMES: symbRegNames ^= 1; - UpdateSymbolsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_SYMBOLS_POS)); UpdateDebugger(false); break; // Tools menu @@ -2522,6 +2519,12 @@ void DebuggerInitMenuPopup(HWND hwndDlg, HMENU hmenu, uint16 pos, bool isWindowM if (hmenu == toolsPopup) { UpdateToolsPopup(hmenu); + return; + } + if (hmenu == symbolsPopup) + { + UpdateSymbolsPopup(symbolsPopup); + return; } } From ca11b6479b66aca7a8cf5e229c85dac6bd6899b0 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 24 Jun 2021 12:54:51 -0400 Subject: [PATCH 033/103] split out the context menu I'm going one at a time from now on! --- src/drivers/win/debugger.cpp | 49 ++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 225241baa..e714b84cc 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2671,6 +2671,33 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); } +void DebuggerContextMenu(HWND hwndDlg, HWND hwndReceiver, int16 cursorX, int16 cursorY) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + // Handle certain stubborn context menus for nearly incapable controls. + if (hwndReceiver == GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_LIST)) + { + // Only open the menu if a breakpoint is selected + if (SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_BP_LIST, LB_GETCURSEL, 0, 0) >= 0) + { + hDebugcontextsub = GetSubMenu(hDebugcontext,0); + if (cursorX != -1) + // Create menu at cursor pos + TrackPopupMenu(hDebugcontextsub, TPM_RIGHTBUTTON, cursorX, cursorY, 0, hwndDlg, NULL); + else + { // Handle the context menu keyboard key + RECT wrect; + GetWindowRect(GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_LIST), &wrect); + // Create menu over breakpoints list + TrackPopupMenu(hDebugcontextsub, TPM_RIGHTBUTTON, wrect.left + int((wrect.right - wrect.left) / 3), wrect.top + int((wrect.bottom - wrect.top) / 3), 0, hwndDlg, NULL); + } + } + } +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -2718,6 +2745,9 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case WM_MOUSEWHEEL: DebuggerMouseWheel(hwndDlg, HIWORD(wParam), LOWORD(lParam), HIWORD(lParam), LOWORD(wParam), lParam); break; + case WM_CONTEXTMENU: + DebuggerContextMenu(hwndDlg, (HWND)wParam, LOWORD(lParam), HIWORD(lParam)); + break; } //these messages only get handled when a game is loaded @@ -2725,25 +2755,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP { switch(uMsg) { - case WM_CONTEXTMENU: - { - // Handle certain stubborn context menus for nearly incapable controls. - - if (wParam == (INT_PTR)GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_LIST)) { - // Only open the menu if a breakpoint is selected - if (SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0) >= 0) { - hDebugcontextsub = GetSubMenu(hDebugcontext,0); - if (lParam != -1) - TrackPopupMenu(hDebugcontextsub,TPM_RIGHTBUTTON,LOWORD(lParam),HIWORD(lParam),0,hwndDlg,0); //Create menu - else { // Handle the context menu keyboard key - RECT wrect; - GetWindowRect(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_LIST), &wrect); - TrackPopupMenu(hDebugcontextsub,TPM_RIGHTBUTTON,wrect.left + int((wrect.right - wrect.left) / 3),wrect.top + int((wrect.bottom - wrect.top) / 3),0,hwndDlg,0); //Create menu - } - } - } - break; - } case WM_KEYDOWN: MessageBox(hwndDlg,"Die!","I'm dead!",MB_YESNO|MB_ICONINFORMATION); break; From 8dec80e43d7cadc5b23d9291a48b5e8b25bb9e98 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 24 Jun 2021 19:10:10 -0400 Subject: [PATCH 034/103] move UpdateOptionsPopup call into InitMenuPopup --- src/drivers/win/debugger.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index e714b84cc..8d550a69f 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1944,7 +1944,7 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_SYMBOLS_POS 2 #define MENU_TOOLS_POS 3 -HMENU toolsPopup, symbolsPopup; +HMENU toolsPopup, symbolsPopup, optionsPopup; INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -2071,7 +2071,7 @@ void DebuggerInitDialog(HWND hwndDlg) for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); - UpdateOptionsPopup(GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); + UpdateOptionsPopup(optionsPopup = GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); UpdateSymbolsPopup(symbolsPopup = GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); @@ -2212,19 +2212,16 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) // TODO: Reuse/merge with the old IDs from the persistent buttons. case ID_DEBUGGER_AUTO_OPEN: debuggerAutoload ^= 1; - UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); break; case ID_DEBUGGER_IDA_FONT: debuggerIDAFont ^= 1; debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); - UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); UpdateDebugger(false); break; case ID_DEBUGGER_SHOW_ROM_OFFSETS: debuggerDisplayROMoffsets ^= 1; - UpdateOptionsPopup(GetSubMenu(GetMenu(hwndDlg), MENU_OPTIONS_POS)); UpdateDebugger(false); break; case ID_DEBUGGER_RESTORE_SIZE: @@ -2526,6 +2523,11 @@ void DebuggerInitMenuPopup(HWND hwndDlg, HMENU hmenu, uint16 pos, bool isWindowM UpdateSymbolsPopup(symbolsPopup); return; } + if (hmenu == optionsPopup) + { + UpdateOptionsPopup(optionsPopup); + return; + } } void DebuggerMoveWindow(HWND hwndDlg, uint16 x, uint16 y) From 31a90b9dba687e57c757b34d86a95a00b13a21db Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 24 Jun 2021 20:01:41 -0400 Subject: [PATCH 035/103] split out the mousey ones --- src/drivers/win/debugger.cpp | 197 ++++++++++++++++++----------------- 1 file changed, 101 insertions(+), 96 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 8d550a69f..8dad4e9a2 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2700,6 +2700,92 @@ void DebuggerContextMenu(HWND hwndDlg, HWND hwndReceiver, int16 cursorX, int16 c } } +void DebuggerMouseMove(HWND hwndDlg, int cursorX, int cursorY, int vkFlags) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + bool setString = false; + if ((cursorX > 6) && (cursorX < 30) && (cursorY > 10)) + { + setString = true; + RECT rectDisassembly; + GetClientRect(GetDlgItem(hDebug, IDC_DEBUGGER_DISASSEMBLY), &rectDisassembly); + int height = rectDisassembly.bottom - rectDisassembly.top; + cursorY -= 10; + if (cursorY > height) + setString = false; + cursorY /= debugSystem->disasmFontHeight; + } + + if (setString) + SetDlgItemText(hDebug, IDC_DEBUGGER_ADDR_LINE, "Left click = Inline Assembler. Middle click = Game Genie. Right click = Hex Editor."); + else + SetDlgItemText(hDebug, IDC_DEBUGGER_ADDR_LINE, ""); +} + +void DebuggerLButtonDown(HWND hwndDlg, int cursorX, int cursorY, int vkFlags) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + if (FCEUI_EmulationPaused() && (cursorX > 6) && (cursorX < 30) && (cursorY > 10)) + { + int tmp = (cursorY - 10) / debugSystem->disasmFontHeight; + if (tmp < (int)disassembly_addresses.size()) + { + int i = disassembly_addresses[tmp]; + iaPC=i; + if (iaPC >= 0x8000) + { + DialogBox(fceu_hInstance, "ASSEMBLER", hwndDlg, AssemblerCallB); + UpdateDebugger(false); + } + } + } +} + +void DebuggerRButtonDown(HWND hwndDlg, int cursorX, int cursorY, int vkFlags) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + if (FCEUI_EmulationPaused() && (cursorX > 6) && (cursorX < 30) && (cursorY > 10)) + { + int tmp = (cursorY - 10) / debugSystem->disasmFontHeight; + if (tmp < (int)disassembly_addresses.size()) + { + int i = disassembly_addresses[tmp]; + if (i >= 0x8000) + // show ROM data in hex editor + ChangeMemViewFocus(3, GetNesFileAddress(i), -1); + else + // show RAM data in hex editor + ChangeMemViewFocus(0, i, -1); + } + } +} + +void DebuggerMButtonDown(HWND hwndDlg, int cursorX, int cursorY, int vkFlags) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + if (FCEUI_EmulationPaused() && (cursorX > 6) && (cursorX < 30) && (cursorY > 10)) + { + int tmp = (cursorY - 10) / debugSystem->disasmFontHeight; + if (tmp < (int)disassembly_addresses.size()) + { + int i = disassembly_addresses[tmp]; + SetGGConvFocus(i, GetMem(i)); + } + } +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -2750,103 +2836,22 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case WM_CONTEXTMENU: DebuggerContextMenu(hwndDlg, (HWND)wParam, LOWORD(lParam), HIWORD(lParam)); break; + case WM_MOUSEMOVE: + DebuggerMouseMove(hwndDlg, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam); + break; + case WM_LBUTTONDOWN: + DebuggerLButtonDown(hwndDlg, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam); + break; + case WM_RBUTTONDOWN: + DebuggerRButtonDown(hwndDlg, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam); + break; + case WM_MBUTTONDOWN: + DebuggerMButtonDown(hwndDlg, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam); + break; + case WM_KEYDOWN: + MessageBox(hwndDlg, "Die!", "I'm dead!", MB_YESNO | MB_ICONINFORMATION); + break; } - - //these messages only get handled when a game is loaded - if (GameInfo) - { - switch(uMsg) - { - case WM_KEYDOWN: - MessageBox(hwndDlg,"Die!","I'm dead!",MB_YESNO|MB_ICONINFORMATION); - break; - case WM_MOUSEMOVE: - { - int mouse_x = GET_X_LPARAM(lParam); - int mouse_y = GET_Y_LPARAM(lParam); - - bool setString = false; - if ((mouse_x > 6) && (mouse_x < 30) && (mouse_y > 10)) - { - setString = true; - RECT rectDisassembly; - GetClientRect(GetDlgItem(hDebug,IDC_DEBUGGER_DISASSEMBLY),&rectDisassembly); - int height = rectDisassembly.bottom-rectDisassembly.top; - mouse_y -= 10; - if(mouse_y > height) - setString = false; - mouse_y /= debugSystem->disasmFontHeight; - } - - if (setString) - SetDlgItemText(hDebug, IDC_DEBUGGER_ADDR_LINE, "Leftclick = Inline Assembler. Midclick = Game Genie. Rightclick = Hexeditor."); - else - SetDlgItemText(hDebug, IDC_DEBUGGER_ADDR_LINE, ""); - break; - } - case WM_LBUTTONDOWN: - { - int mouse_x = GET_X_LPARAM(lParam); - int mouse_y = GET_Y_LPARAM(lParam); -// ################################## Start of SP CODE ########################### - - // mouse_y < 538 - // > 33) tmp = 33 - if (FCEUI_EmulationPaused() && (mouse_x > 6) && (mouse_x < 30) && (mouse_y > 10)) - { -// ################################## End of SP CODE ########################### - int tmp = (mouse_y - 10) / debugSystem->disasmFontHeight; - if (tmp < (int)disassembly_addresses.size()) - { - int i = disassembly_addresses[tmp]; - iaPC=i; - if (iaPC >= 0x8000) - { - DialogBox(fceu_hInstance,"ASSEMBLER",hwndDlg,AssemblerCallB); - UpdateDebugger(false); - } - } - } - break; - } - case WM_RBUTTONDOWN: - { - int mouse_x = GET_X_LPARAM(lParam); - int mouse_y = GET_Y_LPARAM(lParam); - if (FCEUI_EmulationPaused() && (mouse_x > 6) && (mouse_x < 30) && (mouse_y > 10)) - { - int tmp = (mouse_y - 10) / debugSystem->disasmFontHeight; - if (tmp < (int)disassembly_addresses.size()) - { - int i = disassembly_addresses[tmp]; - if (i >= 0x8000) - // show ROM data in Hexeditor - ChangeMemViewFocus(3, GetNesFileAddress(i), -1); - else - // show RAM data in Hexeditor - ChangeMemViewFocus(0, i, -1); - } - } - break; - } - case WM_MBUTTONDOWN: - { - int mouse_x = GET_X_LPARAM(lParam); - int mouse_y = GET_Y_LPARAM(lParam); - if (FCEUI_EmulationPaused() && (mouse_x > 6) && (mouse_x < 30) && (mouse_y > 10)) - { - int tmp = (mouse_y - 10) / debugSystem->disasmFontHeight; - if (tmp < (int)disassembly_addresses.size()) - { - int i = disassembly_addresses[tmp]; - SetGGConvFocus(i,GetMem(i)); - } - } - break; - } - } - } - return FALSE; } From 5dfa77abf100190f7514cb32691490e6a9aa8c89 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Fri, 25 Jun 2021 00:40:36 -0400 Subject: [PATCH 036/103] initial implementation of code dumping --- src/drivers/win/debugger.cpp | 182 ++++++++++++++++++++++++++++++++++- 1 file changed, 180 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 8dad4e9a2..ae192b489 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -559,6 +559,179 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } +// This is most reliable if you dump one subroutine at a time. If you call it with 0x8000 - 0xFFFF, +// it may misinterpret some things depending on how the data is packed. For instance: +// Say we have 2C A9 10. The A9 byte is supposted to be the start of a routine (with LDA #$10), but maybe that +// 2C gets interpreted as the opcode and we get nonsense: BIT $10A9. But the next instruction continues as normal... +// Could potentially have it use Name*s to inform its search! +// A lot of reused logic here, but we really don't want to write the whole dumpfile to a string in memory. +// Note that the endAddr is actually the address of the last INSTRUCTION. This function will grab the +// operands if they exist, and so may spill over a bit. +// Could add config to not dump address and raw data. +void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) +{ + wchar_t chr[40] = { 0 }; + wchar_t debug_wbuf[2048] = { 0 }; + int size; + uint8 opcode[3]; + unsigned int instruction_addr; + unsigned int addr = startAddr; // Keeps track of which address to get the operands, etc. from + + if (symbDebugEnabled) + { + loadNameFiles(); + disassembly_operands.resize(0); + } + + //figure out how many lines we can draw + int lines = endAddr - startAddr + 1; + + // Could loop from startAddr to endAddr instead. Cut the bullshit + unsigned int instructions_count = 0; + for (int addr = startAddr; addr <= endAddr;) + { + // PC pointer + if (addr > 0xFFFF) break; + + instruction_addr = addr; + + if (symbDebugEnabled) + { + // insert Name and Comment lines if needed + Name* node = findNode(getNamesPointerForAddress(addr), addr); + if (node) + { + if (node->name) + { + swprintf(debug_wbuf, L"%S:\n", node->name); + // wcscat(debug_wstr, debug_wbuf); + fprintf(fout, "%ls", debug_wbuf); + } + if (node->comment) + { + // make a copy + strcpy(debug_str_decoration_comment, node->comment); + strcat(debug_str_decoration_comment, "\r\n"); + // divide the debug_str_decoration_comment into strings (Comment1, Comment2, ...) + debug_decoration_comment = debug_str_decoration_comment; + debug_decoration_comment_end_pos = strstr(debug_decoration_comment, "\r\n"); + while (debug_decoration_comment_end_pos) + { + debug_decoration_comment_end_pos[0] = 0; // set \0 instead of \r + debug_decoration_comment_end_pos[1] = 0; // set \0 instead of \n + swprintf(debug_wbuf, L"; %S\n", debug_decoration_comment); + // wcscat(debug_wstr, debug_wbuf); + fprintf(fout, "%ls", debug_wbuf); + + debug_decoration_comment_end_pos += 2; + debug_decoration_comment = debug_decoration_comment_end_pos; + debug_decoration_comment_end_pos = strstr(debug_decoration_comment_end_pos, "\r\n"); + } + } + } + } + + // Do we really want the PC arrow showing up in the dump? + if (addr == X.PC) + { + // wcscat(debug_wstr, L">"); + fprintf(fout, "%ls", L">"); + } + else + { + // wcscat(debug_wstr, L" "); + fprintf(fout, "%ls", L" "); + } + + if (addr >= 0x8000) + { + if (debuggerDisplayROMoffsets && GetNesFileAddress(addr) != -1) + { + swprintf(chr, L" %06X: ", GetNesFileAddress(addr)); + } + else + { + swprintf(chr, L"%02X:%04X: ", getBank(addr), addr); + } + } + else + { + swprintf(chr, L" :%04X: ", addr); + } + + // Add address + // wcscat(debug_wstr, chr); + fprintf(fout, "%ls", chr); + + size = opsize[GetMem(addr)]; + if (size == 0) + { + swprintf(chr, L"%02X UNDEFINED", GetMem(addr++)); + // wcscat(debug_wstr, chr); + fprintf(fout, "%ls", chr); + } + else + { + if ((addr + size) > 0xFFFF) + { + while (addr < 0xFFFF) + { + swprintf(chr, L"%02X OVERFLOW\n", GetMem(addr++)); + // wcscat(debug_wstr, chr); + fprintf(fout, "%ls", chr); + } + break; + } + for (int j = 0; j < size; j++) + { + swprintf(chr, L"%02X ", opcode[j] = GetMem(addr++)); + // wcscat(debug_wstr, chr); + fprintf(fout, "%ls", chr); + } + while (size < 3) + { + // wcscat(debug_wstr, L" "); //pad output to align ASM + fprintf(fout, "%ls", L" "); + size++; + } + + static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; //"plenty" + char* _a = Disassemble(addr, opcode); + strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); + + if (symbDebugEnabled) + { // TODO: This will add in both the default name and custom name if you have inlineAddresses enabled. + if (symbRegNames) + replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); + replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, NULL); + for (int p = 0; p Date: Fri, 25 Jun 2021 01:09:03 -0400 Subject: [PATCH 037/103] add logic to make it respect labels This heuristic only works if you've been poking around in the debugger for a while. --- src/drivers/win/debugger.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index ae192b489..947a36167 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -685,6 +685,14 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) for (int j = 0; j < size; j++) { swprintf(chr, L"%02X ", opcode[j] = GetMem(addr++)); + Name* node; + if (j != size - 1 && (node = findNode(getNamesPointerForAddress(addr), addr))) + { + // We were treating this as an operand, but it's named! + printf("$%04X - We were treating this as an operand, but it's named %s!\n", addr, node->name); + fprintf(fout, "XXXX\n"); + goto continueAddrLoop; // I don't care! YOU refactor it! + } // wcscat(debug_wstr, chr); fprintf(fout, "%ls", chr); } @@ -729,6 +737,8 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) // wcscat(debug_wstr, L"\n"); fprintf(fout, "%ls", L"\n"); instructions_count++; + + continueAddrLoop:; } } From ff41cbc3305115ffabe8557dc198c44ad59c144c Mon Sep 17 00:00:00 2001 From: warmCabin Date: Fri, 25 Jun 2021 01:24:14 -0400 Subject: [PATCH 038/103] refine the logic so it still writes the raw bytes --- src/drivers/win/debugger.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 947a36167..0c488b041 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -682,19 +682,20 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) } break; } + Name* node; for (int j = 0; j < size; j++) { + // Write the raw bytes of this instruction swprintf(chr, L"%02X ", opcode[j] = GetMem(addr++)); - Name* node; + // wcscat(debug_wstr, chr); + fprintf(fout, "%ls", chr); if (j != size - 1 && (node = findNode(getNamesPointerForAddress(addr), addr))) { // We were treating this as an operand, but it's named! printf("$%04X - We were treating this as an operand, but it's named %s!\n", addr, node->name); - fprintf(fout, "XXXX\n"); - goto continueAddrLoop; // I don't care! YOU refactor it! + size = j + 1; + break; } - // wcscat(debug_wstr, chr); - fprintf(fout, "%ls", chr); } while (size < 3) { @@ -702,6 +703,11 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) fprintf(fout, "%ls", L" "); size++; } + if (node) + { + fprintf(fout, " INTERRUPTED\n"); + goto continueAddrLoop; // I don't care! YOU refactor it! + } static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; //"plenty" char* _a = Disassemble(addr, opcode); From e1a73c3700fd7c6985dca9cccdd4bc797795cc00 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Fri, 25 Jun 2021 01:36:09 -0400 Subject: [PATCH 039/103] refactor to avoid goto I guess I did care :( --- src/drivers/win/debugger.cpp | 62 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 0c488b041..1d3eee41a 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -705,46 +705,46 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) } if (node) { - fprintf(fout, " INTERRUPTED\n"); - goto continueAddrLoop; // I don't care! YOU refactor it! + // TODO: Instead of this ominous and confusing message, could print ".byte $XX $YY..." + fprintf(fout, " INTERRUPTED"); } + else + { + static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; //"plenty" + char* _a = Disassemble(addr, opcode); // I want to remove everything after the @. + strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); + + if (symbDebugEnabled) + { // TODO: This will add in both the default name and custom name if you have inlineAddresses enabled. + if (symbRegNames) + replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); + replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, NULL); + for (int p = 0; p Date: Fri, 25 Jun 2021 02:40:54 -0400 Subject: [PATCH 040/103] remove trace info --- src/drivers/win/debugger.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 1d3eee41a..5ea7bb34a 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -710,8 +710,17 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) } else { - static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; //"plenty" - char* _a = Disassemble(addr, opcode); // I want to remove everything after the @. + static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; // "plenty" + char* _a = Disassemble(addr, opcode); + // This isn't a trace log, so we want to remove the data after the @ or =. + // There are lots of hardcoded sprintfs in Disassemble. This really is the easiest way. + char* traceInfoIndex = strstr(_a, "@"); + if (traceInfoIndex) + traceInfoIndex[-1] = 0; + traceInfoIndex = strstr(_a, "="); + if (traceInfoIndex) + traceInfoIndex[-1] = 0; + strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); if (symbDebugEnabled) From af47c8c66ddaea3a446a1050af1301a608ab7e09 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Fri, 25 Jun 2021 02:42:22 -0400 Subject: [PATCH 041/103] clean things up a bit --- src/drivers/win/debugger.cpp | 74 +++++++++++++++++------------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 5ea7bb34a..32e0084a6 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -559,15 +559,32 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } -// This is most reliable if you dump one subroutine at a time. If you call it with 0x8000 - 0xFFFF, -// it may misinterpret some things depending on how the data is packed. For instance: -// Say we have 2C A9 10. The A9 byte is supposted to be the start of a routine (with LDA #$10), but maybe that -// 2C gets interpreted as the opcode and we get nonsense: BIT $10A9. But the next instruction continues as normal... -// Could potentially have it use Name*s to inform its search! -// A lot of reused logic here, but we really don't want to write the whole dumpfile to a string in memory. -// Note that the endAddr is actually the address of the last INSTRUCTION. This function will grab the -// operands if they exist, and so may spill over a bit. -// Could add config to not dump address and raw data. +/** +* Dumps disassembled ROM code between startAddr and endAddr (inclusive) to a file. +* endAddr is the address of the last INSTRUCTION. This funcion will grab the operands if present, +* and may spill over a bit in the process. +* 0x80000 - 0xFFFF should get you the loaded banks. However, it's most reliable when you dump one subroutine at a time +* or already have a lot of labels. +* +* For example, say you have 2C A9 10 60, and the A9 byte is supposed to be the start of a subroutine. If the disassembler +* comes across that 2C first, it will interpret the code as: + +* 2C A9 10 BIT $10A9 +* 60 RTS + +* Nonsense. + +* But if you have a named label +* on that A9 byte, the 2C (BIT) instruction will be INTERRUPTED, and it will show up like this: + +* 2C INTERRUPTED +* my_subroutine: +* A9 10 LDA #$10 +* 60 RTS +* +* There is a lot of reused logic between this and Disassemble. However, they're different enough that it would +* be more trouble than it's worth to combine them. +*/ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) { wchar_t chr[40] = { 0 }; @@ -578,15 +595,8 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) unsigned int addr = startAddr; // Keeps track of which address to get the operands, etc. from if (symbDebugEnabled) - { loadNameFiles(); - disassembly_operands.resize(0); - } - - //figure out how many lines we can draw - int lines = endAddr - startAddr + 1; - // Could loop from startAddr to endAddr instead. Cut the bullshit unsigned int instructions_count = 0; for (int addr = startAddr; addr <= endAddr;) { @@ -597,14 +607,15 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) if (symbDebugEnabled) { - // insert Name and Comment lines if needed + // Insert name and comment lines if present Name* node = findNode(getNamesPointerForAddress(addr), addr); if (node) { if (node->name) { + // Could probably ditch these swprintf's and just do fwprintf. + // Need to verify exactly how the various buffers are used. swprintf(debug_wbuf, L"%S:\n", node->name); - // wcscat(debug_wstr, debug_wbuf); fprintf(fout, "%ls", debug_wbuf); } if (node->comment) @@ -620,7 +631,6 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) debug_decoration_comment_end_pos[0] = 0; // set \0 instead of \r debug_decoration_comment_end_pos[1] = 0; // set \0 instead of \n swprintf(debug_wbuf, L"; %S\n", debug_decoration_comment); - // wcscat(debug_wstr, debug_wbuf); fprintf(fout, "%ls", debug_wbuf); debug_decoration_comment_end_pos += 2; @@ -631,17 +641,7 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) } } - // Do we really want the PC arrow showing up in the dump? - if (addr == X.PC) - { - // wcscat(debug_wstr, L">"); - fprintf(fout, "%ls", L">"); - } - else - { - // wcscat(debug_wstr, L" "); - fprintf(fout, "%ls", L" "); - } + fprintf(fout, "%ls", L" "); if (addr >= 0x8000) { @@ -660,14 +660,12 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) } // Add address - // wcscat(debug_wstr, chr); fprintf(fout, "%ls", chr); size = opsize[GetMem(addr)]; if (size == 0) { swprintf(chr, L"%02X UNDEFINED", GetMem(addr++)); - // wcscat(debug_wstr, chr); fprintf(fout, "%ls", chr); } else @@ -677,7 +675,6 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) while (addr < 0xFFFF) { swprintf(chr, L"%02X OVERFLOW\n", GetMem(addr++)); - // wcscat(debug_wstr, chr); fprintf(fout, "%ls", chr); } break; @@ -687,19 +684,18 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) { // Write the raw bytes of this instruction swprintf(chr, L"%02X ", opcode[j] = GetMem(addr++)); - // wcscat(debug_wstr, chr); fprintf(fout, "%ls", chr); if (j != size - 1 && (node = findNode(getNamesPointerForAddress(addr), addr))) { // We were treating this as an operand, but it's named! - printf("$%04X - We were treating this as an operand, but it's named %s!\n", addr, node->name); + // Probably want an instruction to start here instead. + printf("$%04X (%s) came up as an operand for instruction @ %04X\n", addr, node->name, addr - j - 1); size = j + 1; break; } } while (size < 3) { - // wcscat(debug_wstr, L" "); //pad output to align ASM fprintf(fout, "%ls", L" "); size++; } @@ -735,7 +731,7 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) uint8 opCode = GetMem(instruction_addr); - // special case: an RTS or RTI opcode + // special case: RTS and RTI if (opCode == 0x60 || opCode == 0x40) { // add "----------" to emphasize the end of subroutine @@ -745,13 +741,11 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) bufferForDisassemblyWithPlentyOfStuff[LOG_DISASSEMBLY_MAX_LEN - 1] = 0; } - // append the disassembly to current line + // append disassembly to current line swprintf(debug_wbuf, L" %S", bufferForDisassemblyWithPlentyOfStuff); - // wcscat(debug_wstr, debug_wbuf); fprintf(fout, "%ls", debug_wbuf); } } - // wcscat(debug_wstr, L"\n"); fprintf(fout, "%ls", L"\n"); instructions_count++; } From e178581d3224a38ce654be060a28c80af6e78515 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sat, 26 Jun 2021 18:27:56 -0400 Subject: [PATCH 042/103] split patcher, assembler, and some disassembly logic to where it belongs --- src/asm.cpp | 76 ++++++++ src/asm.h | 2 + src/drivers/win/assembler.cpp | 159 +++++++++++++++ src/drivers/win/assembler.h | 5 + src/drivers/win/debugger.cpp | 355 +--------------------------------- src/drivers/win/debugger.h | 1 - src/drivers/win/patcher.cpp | 151 +++++++++++++++ src/drivers/win/patcher.h | 5 + vc/vc14_fceux.vcxproj | 4 + vc/vc14_fceux.vcxproj.filters | 12 ++ 10 files changed, 417 insertions(+), 353 deletions(-) create mode 100644 src/drivers/win/assembler.cpp create mode 100644 src/drivers/win/assembler.h create mode 100644 src/drivers/win/patcher.cpp create mode 100644 src/drivers/win/patcher.h diff --git a/src/asm.cpp b/src/asm.cpp index 0aa2a61ee..53306ac21 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -527,3 +527,79 @@ char *Disassemble(int addr, uint8 *opcode) { return str; } + +// Need to clean up this interface. +char *DisassembleLine(int addr) { + static char str[64] = { 0 }, chr[25] = { 0 }; + char *c; + int size, j; + uint8 opcode[3]; + + sprintf(str, "%02X:%04X: ", getBank(addr), addr); + size = opsize[GetMem(addr)]; + if (size == 0) + { + sprintf(chr, "%02X UNDEFINED", GetMem(addr++)); + strcat(str, chr); + } + else { + if ((addr + size) > 0x10000) { + sprintf(chr, "%02X OVERFLOW", GetMem(addr)); + strcat(str, chr); + } + else { + for (j = 0; j < size; j++) { + sprintf(chr, "%02X ", opcode[j] = GetMem(addr++)); + strcat(str, chr); + } + while (size < 3) { + strcat(str, " "); //pad output to align ASM + size++; + } + strcat(strcat(str, " "), Disassemble(addr, opcode)); + } + } + if ((c = strchr(str, '='))) *(c - 1) = 0; + if ((c = strchr(str, '@'))) *(c - 1) = 0; + return str; +} + +char *DisassembleData(int addr, uint8 *opcode) { + static char str[64] = { 0 }, chr[25] = { 0 }; + char *c; + int size, j; + + sprintf(str, "%02X:%04X: ", getBank(addr), addr); + size = opsize[opcode[0]]; + if (size == 0) + { + sprintf(chr, "%02X UNDEFINED", opcode[0]); + strcat(str, chr); + } + else + { + if ((addr + size) > 0x10000) + { + sprintf(chr, "%02X OVERFLOW", opcode[0]); + strcat(str, chr); + } + else + { + for (j = 0; j < size; j++) + { + sprintf(chr, "%02X ", opcode[j]); + addr++; + strcat(str, chr); + } + while (size < 3) + { + strcat(str, " "); //pad output to align ASM + size++; + } + strcat(strcat(str, " "), Disassemble(addr, opcode)); + } + } + if ((c = strchr(str, '='))) *(c - 1) = 0; + if ((c = strchr(str, '@'))) *(c - 1) = 0; + return str; +} diff --git a/src/asm.h b/src/asm.h index 5dff9f326..276aab16b 100644 --- a/src/asm.h +++ b/src/asm.h @@ -1,2 +1,4 @@ int Assemble(unsigned char *output, int addr, char *str); char *Disassemble(int addr, uint8 *opcode); +char *DisassembleLine(int addr); +char *DisassembleData(int addr, uint8 *opcode); diff --git a/src/drivers/win/assembler.cpp b/src/drivers/win/assembler.cpp new file mode 100644 index 000000000..8be768f72 --- /dev/null +++ b/src/drivers/win/assembler.cpp @@ -0,0 +1,159 @@ +#include + +#include "types.h" +#include "gui.h" +#include "resource.h" +#include "debugger.h" +#include "../../debug.h" +#include "asm.h" +#include "../../x6502.h" +#include "../../fceu.h" +#include "../../debug.h" +#include "../../nsf.h" +#include "../../ppu.h" +#include "../../cart.h" +#include "../../ines.h" +#include "../../asm.h" + +int AddAsmHistory(HWND hwndDlg, int id, char *str) { + int index; + index = SendDlgItemMessage(hwndDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)(LPSTR)str); + if (index == CB_ERR) { + SendDlgItemMessage(hwndDlg, id, CB_INSERTSTRING, -1, (LPARAM)(LPSTR)str); + return 0; + } + return 1; +} + +INT_PTR CALLBACK AssemblerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { + int romaddr, count, i, j; + char str[128], *dasm; + static int patchlen, applied, saved, lastundo; + static uint8 patchdata[64][3], undodata[64 * 3]; + uint8 *ptr; + + switch (uMsg) { + case WM_INITDIALOG: + CenterWindow(hwndDlg); + + //set font + SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hFixedFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, WM_SETFONT, (WPARAM)debugSystem->hFixedFont, FALSE); + + //set limits + SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_HISTORY, CB_LIMITTEXT, 20, 0); + + SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, DisassembleLine(iaPC)); + SetFocus(GetDlgItem(hwndDlg, IDC_ASSEMBLER_HISTORY)); + + patchlen = 0; + applied = 0; + saved = 0; + lastundo = 0; + break; + case WM_CLOSE: + case WM_QUIT: + EndDialog(hwndDlg, 0); + break; + case WM_COMMAND: + { + switch (HIWORD(wParam)) + { + case BN_CLICKED: + { + switch (LOWORD(wParam)) + { + case IDC_ASSEMBLER_APPLY: + if (patchlen) { + ptr = GetNesPRGPointer(GetNesFileAddress(iaPC) - 16); + count = 0; + for (i = 0; i < patchlen; i++) { + for (j = 0; j < opsize[patchdata[i][0]]; j++) { + if (count == lastundo) undodata[lastundo++] = ptr[count]; + ptr[count++] = patchdata[i][j]; + } + } + SetWindowText(hwndDlg, "Inline Assembler *Patches Applied*"); + applied = 1; + } + break; + case IDC_ASSEMBLER_SAVE: + if (applied) { + count = romaddr = GetNesFileAddress(iaPC); + for (i = 0; i < patchlen; i++) + { + count += opsize[patchdata[i][0]]; + } + if (patchlen) sprintf(str, "Write patch data to file at addresses 0x%06X - 0x%06X?", romaddr, count - 1); + else sprintf(str, "Undo all previously applied patches?"); + if (MessageBox(hwndDlg, str, "Save changes to file?", MB_YESNO | MB_ICONINFORMATION) == IDYES) { + if (iNesSave()) { + saved = 1; + applied = 0; + } + else MessageBox(hwndDlg, "Unable to save changes to file", "Error saving to file", MB_OK | MB_ICONERROR); + } + } + break; + case IDC_ASSEMBLER_UNDO: + if ((count = SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, LB_GETCOUNT, 0, 0))) { + SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, LB_DELETESTRING, count - 1, 0); + patchlen--; + count = 0; + for (i = 0; i < patchlen; i++) + { + count += opsize[patchdata[i][0]]; + } + if (count < lastundo) { + ptr = GetNesPRGPointer(GetNesFileAddress(iaPC) - 16); + j = opsize[patchdata[patchlen][0]]; + for (i = count; i < (count + j); i++) { + ptr[i] = undodata[i]; + } + lastundo -= j; + applied = 1; + } + SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, DisassembleLine(iaPC + count)); + } + break; + case IDC_ASSEMBLER_DEFPUSHBUTTON: + count = 0; + for (i = 0; i < patchlen; i++) + { + count += opsize[patchdata[i][0]]; + } + GetDlgItemText(hwndDlg, IDC_ASSEMBLER_HISTORY, str, 21); + if (!Assemble(patchdata[patchlen], (iaPC + count), str)) { + count = iaPC; + for (i = 0; i <= patchlen; i++) + { + count += opsize[patchdata[i][0]]; + } + if (count > 0x10000) { //note: don't use 0xFFFF! + MessageBox(hwndDlg, "Patch data cannot exceed address 0xFFFF", "Address error", MB_OK | MB_ICONERROR); + break; + } + SetDlgItemText(hwndDlg, IDC_ASSEMBLER_HISTORY, ""); + if (count < 0x10000) SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, DisassembleLine(count)); + else SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, "OVERFLOW"); + dasm = DisassembleData((count - opsize[patchdata[patchlen][0]]), patchdata[patchlen]); + SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, LB_INSERTSTRING, -1, (LPARAM)(LPSTR)dasm); + AddAsmHistory(hwndDlg, IDC_ASSEMBLER_HISTORY, dasm + 16); + SetWindowText(hwndDlg, "Inline Assembler"); + patchlen++; + } + else { //ERROR! + SetWindowText(hwndDlg, "Inline Assembler *Syntax Error*"); + MessageBeep(MB_ICONEXCLAMATION); + } + break; + } + SetFocus(GetDlgItem(hwndDlg, IDC_ASSEMBLER_HISTORY)); //set focus to combo box after anything is pressed! + break; + } + } + break; + } + } + return FALSE; +} diff --git a/src/drivers/win/assembler.h b/src/drivers/win/assembler.h new file mode 100644 index 000000000..a08bccf5e --- /dev/null +++ b/src/drivers/win/assembler.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +INT_PTR CALLBACK AssemblerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 32e0084a6..019e78e3d 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -38,6 +38,8 @@ #include "cdlogger.h" #include "ppuview.h" #include "richedit.h" +#include "assembler.h" +#include "patcher.h" // ################################## Start of SP CODE ########################### @@ -964,80 +966,6 @@ void PrintOffsetToSeekAndBookmarkFields(int offset) } } -char *DisassembleLine(int addr) { - static char str[64]={0},chr[25]={0}; - char *c; - int size,j; - uint8 opcode[3]; - - sprintf(str, "%02X:%04X: ", getBank(addr),addr); - size = opsize[GetMem(addr)]; - if (size == 0) - { - sprintf(chr, "%02X UNDEFINED", GetMem(addr++)); - strcat(str,chr); - } - else { - if ((addr+size) > 0x10000) { - sprintf(chr, "%02X OVERFLOW", GetMem(addr)); - strcat(str,chr); - } - else { - for (j = 0; j < size; j++) { - sprintf(chr, "%02X ", opcode[j] = GetMem(addr++)); - strcat(str,chr); - } - while (size < 3) { - strcat(str," "); //pad output to align ASM - size++; - } - strcat(strcat(str," "),Disassemble(addr,opcode)); - } - } - if ((c=strchr(str,'='))) *(c-1) = 0; - if ((c=strchr(str,'@'))) *(c-1) = 0; - return str; -} - -char *DisassembleData(int addr, uint8 *opcode) { - static char str[64]={0},chr[25]={0}; - char *c; - int size,j; - - sprintf(str, "%02X:%04X: ", getBank(addr), addr); - size = opsize[opcode[0]]; - if (size == 0) - { - sprintf(chr, "%02X UNDEFINED", opcode[0]); - strcat(str,chr); - } else - { - if ((addr+size) > 0x10000) - { - sprintf(chr, "%02X OVERFLOW", opcode[0]); - strcat(str,chr); - } else - { - for (j = 0; j < size; j++) - { - sprintf(chr, "%02X ", opcode[j]); - addr++; - strcat(str,chr); - } - while (size < 3) - { - strcat(str," "); //pad output to align ASM - size++; - } - strcat(strcat(str," "),Disassemble(addr,opcode)); - } - } - if ((c=strchr(str,'='))) *(c-1) = 0; - if ((c=strchr(str,'@'))) *(c-1) = 0; - return str; -} - - int GetEditHex(HWND hwndDlg, int id) { char str[9]; int tmp; @@ -1046,38 +974,6 @@ int GetEditHex(HWND hwndDlg, int id) { return tmp; } -int *GetEditHexData(HWND hwndDlg, int id){ - static int data[31]; - char str[60]; - int i,j, k; - - GetDlgItemText(hwndDlg,id,str,60); - memset(data,0,31*sizeof(int)); - j=0; - for(i = 0;i < 60;i++){ - if(str[i] == 0)break; - if((str[i] >= '0') && (str[i] <= '9'))j++; - if((str[i] >= 'A') && (str[i] <= 'F'))j++; - if((str[i] >= 'a') && (str[i] <= 'f'))j++; - } - - j=j&1; - for(i = 0;i < 60;i++){ - if(str[i] == 0)break; - k = -1; - if((str[i] >= '0') && (str[i] <= '9'))k=str[i]-'0'; - if((str[i] >= 'A') && (str[i] <= 'F'))k=(str[i]-'A')+10; - if((str[i] >= 'a') && (str[i] <= 'f'))k=(str[i]-'a')+10; - if(k != -1){ - if(j&1)data[j>>1] |= k; - else data[j>>1] |= k<<4; - j++; - } - } - data[j>>1]=-1; - return data; -} - void UpdateRegs(HWND hwndDlg) { if (DebuggerWasUpdated) { X.A = GetEditHex(hwndDlg,IDC_DEBUGGER_VAL_A); @@ -1474,218 +1370,6 @@ void KillDebugger() { FCEUI_SetEmulationPaused(0); } - -int AddAsmHistory(HWND hwndDlg, int id, char *str) { - int index; - index = SendDlgItemMessage(hwndDlg,id,CB_FINDSTRINGEXACT,-1,(LPARAM)(LPSTR)str); - if (index == CB_ERR) { - SendDlgItemMessage(hwndDlg,id,CB_INSERTSTRING,-1,(LPARAM)(LPSTR)str); - return 0; - } - return 1; -} - -INT_PTR CALLBACK AssemblerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - int romaddr,count,i,j; - char str[128],*dasm; - static int patchlen,applied,saved,lastundo; - static uint8 patchdata[64][3],undodata[64*3]; - uint8 *ptr; - - switch(uMsg) { - case WM_INITDIALOG: - CenterWindow(hwndDlg); - - //set font - SendDlgItemMessage(hwndDlg,IDC_ASSEMBLER_DISASSEMBLY,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_ASSEMBLER_PATCH_DISASM,WM_SETFONT,(WPARAM)debugSystem->hFixedFont,FALSE); - - //set limits - SendDlgItemMessage(hwndDlg,IDC_ASSEMBLER_HISTORY,CB_LIMITTEXT,20,0); - - SetDlgItemText(hwndDlg,IDC_ASSEMBLER_DISASSEMBLY,DisassembleLine(iaPC)); - SetFocus(GetDlgItem(hwndDlg,IDC_ASSEMBLER_HISTORY)); - - patchlen = 0; - applied = 0; - saved = 0; - lastundo = 0; - break; - case WM_CLOSE: - case WM_QUIT: - EndDialog(hwndDlg,0); - break; - case WM_COMMAND: - { - switch (HIWORD(wParam)) - { - case BN_CLICKED: - { - switch (LOWORD(wParam)) - { - case IDC_ASSEMBLER_APPLY: - if (patchlen) { - ptr = GetNesPRGPointer(GetNesFileAddress(iaPC)-16); - count = 0; - for (i = 0; i < patchlen; i++) { - for (j = 0; j < opsize[patchdata[i][0]]; j++) { - if (count == lastundo) undodata[lastundo++] = ptr[count]; - ptr[count++] = patchdata[i][j]; - } - } - SetWindowText(hwndDlg, "Inline Assembler *Patches Applied*"); - applied = 1; - } - break; - case IDC_ASSEMBLER_SAVE: - if (applied) { - count = romaddr = GetNesFileAddress(iaPC); - for (i = 0; i < patchlen; i++) - { - count += opsize[patchdata[i][0]]; - } - if (patchlen) sprintf(str,"Write patch data to file at addresses 0x%06X - 0x%06X?",romaddr,count-1); - else sprintf(str,"Undo all previously applied patches?"); - if (MessageBox(hwndDlg, str, "Save changes to file?", MB_YESNO|MB_ICONINFORMATION) == IDYES) { - if (iNesSave()) { - saved = 1; - applied = 0; - } - else MessageBox(hwndDlg, "Unable to save changes to file", "Error saving to file", MB_OK | MB_ICONERROR); - } - } - break; - case IDC_ASSEMBLER_UNDO: - if ((count = SendDlgItemMessage(hwndDlg,IDC_ASSEMBLER_PATCH_DISASM,LB_GETCOUNT,0,0))) { - SendDlgItemMessage(hwndDlg,IDC_ASSEMBLER_PATCH_DISASM,LB_DELETESTRING,count-1,0); - patchlen--; - count = 0; - for (i = 0; i < patchlen; i++) - { - count += opsize[patchdata[i][0]]; - } - if (count < lastundo) { - ptr = GetNesPRGPointer(GetNesFileAddress(iaPC)-16); - j = opsize[patchdata[patchlen][0]]; - for (i = count; i < (count+j); i++) { - ptr[i] = undodata[i]; - } - lastundo -= j; - applied = 1; - } - SetDlgItemText(hwndDlg,IDC_ASSEMBLER_DISASSEMBLY,DisassembleLine(iaPC+count)); - } - break; - case IDC_ASSEMBLER_DEFPUSHBUTTON: - count = 0; - for (i = 0; i < patchlen; i++) - { - count += opsize[patchdata[i][0]]; - } - GetDlgItemText(hwndDlg,IDC_ASSEMBLER_HISTORY,str,21); - if (!Assemble(patchdata[patchlen],(iaPC+count),str)) { - count = iaPC; - for (i = 0; i <= patchlen; i++) - { - count += opsize[patchdata[i][0]]; - } - if (count > 0x10000) { //note: don't use 0xFFFF! - MessageBox(hwndDlg, "Patch data cannot exceed address 0xFFFF", "Address error", MB_OK | MB_ICONERROR); - break; - } - SetDlgItemText(hwndDlg,IDC_ASSEMBLER_HISTORY,""); - if (count < 0x10000) SetDlgItemText(hwndDlg,IDC_ASSEMBLER_DISASSEMBLY,DisassembleLine(count)); - else SetDlgItemText(hwndDlg,IDC_ASSEMBLER_DISASSEMBLY,"OVERFLOW"); - dasm = DisassembleData((count-opsize[patchdata[patchlen][0]]),patchdata[patchlen]); - SendDlgItemMessage(hwndDlg,IDC_ASSEMBLER_PATCH_DISASM,LB_INSERTSTRING,-1,(LPARAM)(LPSTR)dasm); - AddAsmHistory(hwndDlg,IDC_ASSEMBLER_HISTORY,dasm+16); - SetWindowText(hwndDlg, "Inline Assembler"); - patchlen++; - } - else { //ERROR! - SetWindowText(hwndDlg, "Inline Assembler *Syntax Error*"); - MessageBeep(MB_ICONEXCLAMATION); - } - break; - } - SetFocus(GetDlgItem(hwndDlg,IDC_ASSEMBLER_HISTORY)); //set focus to combo box after anything is pressed! - break; - } - } - break; - } - } - return FALSE; -} - -INT_PTR CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - char str[64]; - uint8 *c; - int i; - int *p; - - switch(uMsg) { - case WM_INITDIALOG: - CenterWindow(hwndDlg); - - //set limits - SendDlgItemMessage(hwndDlg,IDC_ROMPATCHER_OFFSET,EM_SETLIMITTEXT,6,0); - SendDlgItemMessage(hwndDlg,IDC_ROMPATCHER_PATCH_DATA,EM_SETLIMITTEXT,30,0); - UpdatePatcher(hwndDlg); - - if(iapoffset != -1){ - CheckDlgButton(hwndDlg, IDC_ROMPATCHER_DOTNES_OFFSET, BST_CHECKED); - sprintf((char*)str,"%X",iapoffset); - SetDlgItemText(hwndDlg,IDC_ROMPATCHER_OFFSET,str); - } - - SetFocus(GetDlgItem(hwndDlg,IDC_ROMPATCHER_OFFSET_BOX)); - break; - case WM_CLOSE: - case WM_QUIT: - EndDialog(hwndDlg,0); - break; - case WM_COMMAND: - switch(HIWORD(wParam)) { - case BN_CLICKED: - switch(LOWORD(wParam)) { - case IDC_ROMPATCHER_BTN_EDIT: //todo: maybe get rid of this button and cause iapoffset to update every time you change the text - if(IsDlgButtonChecked(hwndDlg,IDC_ROMPATCHER_DOTNES_OFFSET) == BST_CHECKED) - iapoffset = GetEditHex(hwndDlg,IDC_ROMPATCHER_OFFSET); - else - iapoffset = GetNesFileAddress(GetEditHex(hwndDlg,IDC_ROMPATCHER_OFFSET)); - if((iapoffset < 16) && (iapoffset != -1)){ - MessageBox(hDebug, "Sorry, iNES Header editing isn't supported by this tool. If you want to edit the header, please use iNES Header Editor", "Error", MB_OK | MB_ICONASTERISK); - iapoffset = -1; - } - if((iapoffset > PRGsize[0]) && (iapoffset != -1)){ - MessageBox(hDebug, "Error: .Nes offset outside of PRG rom", "Error", MB_OK | MB_ICONERROR); - iapoffset = -1; - } - UpdatePatcher(hwndDlg); - break; - case IDC_ROMPATCHER_BTN_APPLY: - p = GetEditHexData(hwndDlg,IDC_ROMPATCHER_PATCH_DATA); - i=0; - c = GetNesPRGPointer(iapoffset-16); - while(p[i] != -1){ - c[i] = p[i]; - i++; - } - UpdatePatcher(hwndDlg); - break; - case IDC_ROMPATCHER_BTN_SAVE: - if (!iNesSave()) - MessageBox(NULL, "Error Saving", "Error", MB_OK | MB_ICONERROR); - break; - } - break; - } - break; - } - return FALSE; -} - extern char *iNesShortFName(); void DebuggerExit() @@ -2444,6 +2128,7 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) break; // Tools menu case ID_DEBUGGER_ROM_PATCHER: + printf("wtf"); DoPatcher(-1, hwndDlg); break; case ID_DEBUGGER_CODE_DUMPER: @@ -3072,40 +2757,6 @@ void DoPatcher(int address, HWND hParent) UpdateDebugger(false); } -void UpdatePatcher(HWND hwndDlg){ - char str[75]; - uint8 *p; - if(iapoffset != -1){ - EnableWindow(GetDlgItem(hwndDlg,IDC_ROMPATCHER_PATCH_DATA),TRUE); - EnableWindow(GetDlgItem(hwndDlg,IDC_ROMPATCHER_BTN_APPLY),TRUE); - - if(GetRomAddress(iapoffset) != -1)sprintf(str,"Current Data at NES ROM Address: %04X, .NES file Address: %04X",GetRomAddress(iapoffset),iapoffset); - else sprintf(str,"Current Data at .NES file Address: %04X",iapoffset); - - SetDlgItemText(hwndDlg,IDC_ROMPATCHER_CURRENT_DATA_BOX,str); - - sprintf(str,"%04X",GetRomAddress(iapoffset)); - SetDlgItemText(hwndDlg,IDC_ROMPATCHER_DISASSEMBLY,str); - - if(GetRomAddress(iapoffset) != -1)SetDlgItemText(hwndDlg,IDC_ROMPATCHER_DISASSEMBLY,DisassembleLine(GetRomAddress(iapoffset))); - else SetDlgItemText(hwndDlg,IDC_ROMPATCHER_DISASSEMBLY,"Not Currently Loaded in ROM for disassembly"); - - p = GetNesPRGPointer(iapoffset-16); - sprintf(str,"%02X %02X %02X %02X %02X %02X %02X %02X", - p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]); - SetDlgItemText(hwndDlg,IDC_ROMPATCHER_CURRENT_DATA,str); - - } else { - SetDlgItemText(hwndDlg,IDC_ROMPATCHER_CURRENT_DATA_BOX,"No Offset Selected"); - SetDlgItemText(hwndDlg,IDC_ROMPATCHER_CURRENT_DATA,""); - SetDlgItemText(hwndDlg,IDC_ROMPATCHER_DISASSEMBLY,""); - EnableWindow(GetDlgItem(hwndDlg,IDC_ROMPATCHER_PATCH_DATA),FALSE); - EnableWindow(GetDlgItem(hwndDlg,IDC_ROMPATCHER_BTN_APPLY),FALSE); - } - if(GameInfo->type != GIT_CART)EnableWindow(GetDlgItem(hwndDlg,IDC_ROMPATCHER_BTN_SAVE),FALSE); - else EnableWindow(GetDlgItem(hwndDlg,IDC_ROMPATCHER_BTN_SAVE),TRUE); -} - /// Updates debugger controls that should be enabled/disabled if a game is loaded. /// @param enable Flag that indicates whether the menus should be enabled (1) or disabled (0). void updateGameDependentMenusDebugger() { diff --git a/src/drivers/win/debugger.h b/src/drivers/win/debugger.h index 2063229e2..a171642c5 100644 --- a/src/drivers/win/debugger.h +++ b/src/drivers/win/debugger.h @@ -30,7 +30,6 @@ extern char* hexeditorFontName; void CenterWindow(HWND hwndDlg); void DoPatcher(int address,HWND hParent); -void UpdatePatcher(HWND hwndDlg); int GetEditHex(HWND hwndDlg, int id); extern void AddBreakList(); diff --git a/src/drivers/win/patcher.cpp b/src/drivers/win/patcher.cpp new file mode 100644 index 000000000..cc693f17e --- /dev/null +++ b/src/drivers/win/patcher.cpp @@ -0,0 +1,151 @@ +#include + +#include "types.h" +#include "gui.h" +#include "resource.h" +#include "debugger.h" +#include "../../debug.h" +#include "asm.h" +#include "../../x6502.h" +#include "../../fceu.h" +#include "../../debug.h" +#include "../../nsf.h" +#include "../../ppu.h" +#include "../../cart.h" +#include "../../ines.h" +#include "../../asm.h" + +int *GetEditHexData(HWND hwndDlg, int id) { + static int data[31]; + char str[60]; + int i, j, k; + + GetDlgItemText(hwndDlg, id, str, 60); + memset(data, 0, 31 * sizeof(int)); + j = 0; + for (i = 0; i < 60; i++) { + if (str[i] == 0)break; + if ((str[i] >= '0') && (str[i] <= '9'))j++; + if ((str[i] >= 'A') && (str[i] <= 'F'))j++; + if ((str[i] >= 'a') && (str[i] <= 'f'))j++; + } + + j = j & 1; + for (i = 0; i < 60; i++) { + if (str[i] == 0)break; + k = -1; + if ((str[i] >= '0') && (str[i] <= '9'))k = str[i] - '0'; + if ((str[i] >= 'A') && (str[i] <= 'F'))k = (str[i] - 'A') + 10; + if ((str[i] >= 'a') && (str[i] <= 'f'))k = (str[i] - 'a') + 10; + if (k != -1) { + if (j & 1)data[j >> 1] |= k; + else data[j >> 1] |= k << 4; + j++; + } + } + data[j >> 1] = -1; + return data; +} + +void UpdatePatcher(HWND hwndDlg) { + char str[75]; + uint8 *p; + if (iapoffset != -1) { + EnableWindow(GetDlgItem(hwndDlg, IDC_ROMPATCHER_PATCH_DATA), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_ROMPATCHER_BTN_APPLY), TRUE); + + if (GetRomAddress(iapoffset) != -1)sprintf(str, "Current Data at NES ROM Address: %04X, .NES file Address: %04X", GetRomAddress(iapoffset), iapoffset); + else sprintf(str, "Current Data at .NES file Address: %04X", iapoffset); + + SetDlgItemText(hwndDlg, IDC_ROMPATCHER_CURRENT_DATA_BOX, str); + + sprintf(str, "%04X", GetRomAddress(iapoffset)); + SetDlgItemText(hwndDlg, IDC_ROMPATCHER_DISASSEMBLY, str); + + if (GetRomAddress(iapoffset) != -1)SetDlgItemText(hwndDlg, IDC_ROMPATCHER_DISASSEMBLY, DisassembleLine(GetRomAddress(iapoffset))); + else SetDlgItemText(hwndDlg, IDC_ROMPATCHER_DISASSEMBLY, "Not Currently Loaded in ROM for disassembly"); + + p = GetNesPRGPointer(iapoffset - 16); + sprintf(str, "%02X %02X %02X %02X %02X %02X %02X %02X", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); + SetDlgItemText(hwndDlg, IDC_ROMPATCHER_CURRENT_DATA, str); + + } + else { + SetDlgItemText(hwndDlg, IDC_ROMPATCHER_CURRENT_DATA_BOX, "No Offset Selected"); + SetDlgItemText(hwndDlg, IDC_ROMPATCHER_CURRENT_DATA, ""); + SetDlgItemText(hwndDlg, IDC_ROMPATCHER_DISASSEMBLY, ""); + EnableWindow(GetDlgItem(hwndDlg, IDC_ROMPATCHER_PATCH_DATA), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_ROMPATCHER_BTN_APPLY), FALSE); + } + if (GameInfo->type != GIT_CART)EnableWindow(GetDlgItem(hwndDlg, IDC_ROMPATCHER_BTN_SAVE), FALSE); + else EnableWindow(GetDlgItem(hwndDlg, IDC_ROMPATCHER_BTN_SAVE), TRUE); +} + +INT_PTR CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { + char str[64]; + uint8 *c; + int i; + int *p; + + switch (uMsg) { + case WM_INITDIALOG: + CenterWindow(hwndDlg); + + //set limits + SendDlgItemMessage(hwndDlg, IDC_ROMPATCHER_OFFSET, EM_SETLIMITTEXT, 6, 0); + SendDlgItemMessage(hwndDlg, IDC_ROMPATCHER_PATCH_DATA, EM_SETLIMITTEXT, 30, 0); + UpdatePatcher(hwndDlg); + + if (iapoffset != -1) { + CheckDlgButton(hwndDlg, IDC_ROMPATCHER_DOTNES_OFFSET, BST_CHECKED); + sprintf((char*)str, "%X", iapoffset); + SetDlgItemText(hwndDlg, IDC_ROMPATCHER_OFFSET, str); + } + + SetFocus(GetDlgItem(hwndDlg, IDC_ROMPATCHER_OFFSET_BOX)); + break; + case WM_CLOSE: + case WM_QUIT: + EndDialog(hwndDlg, 0); + break; + case WM_COMMAND: + switch (HIWORD(wParam)) { + case BN_CLICKED: + switch (LOWORD(wParam)) { + case IDC_ROMPATCHER_BTN_EDIT: //todo: maybe get rid of this button and cause iapoffset to update every time you change the text + if (IsDlgButtonChecked(hwndDlg, IDC_ROMPATCHER_DOTNES_OFFSET) == BST_CHECKED) + iapoffset = GetEditHex(hwndDlg, IDC_ROMPATCHER_OFFSET); + else + iapoffset = GetNesFileAddress(GetEditHex(hwndDlg, IDC_ROMPATCHER_OFFSET)); + if ((iapoffset < 16) && (iapoffset != -1)) { + MessageBox(hDebug, "Sorry, iNES Header editing isn't supported by this tool. If you want to edit the header, please use iNES Header Editor", "Error", MB_OK | MB_ICONASTERISK); + iapoffset = -1; + } + if ((iapoffset > PRGsize[0]) && (iapoffset != -1)) { + MessageBox(hDebug, "Error: .Nes offset outside of PRG rom", "Error", MB_OK | MB_ICONERROR); + iapoffset = -1; + } + UpdatePatcher(hwndDlg); + break; + case IDC_ROMPATCHER_BTN_APPLY: + p = GetEditHexData(hwndDlg, IDC_ROMPATCHER_PATCH_DATA); + i = 0; + c = GetNesPRGPointer(iapoffset - 16); + while (p[i] != -1) { + c[i] = p[i]; + i++; + } + UpdatePatcher(hwndDlg); + break; + case IDC_ROMPATCHER_BTN_SAVE: + if (!iNesSave()) + MessageBox(NULL, "Error Saving", "Error", MB_OK | MB_ICONERROR); + break; + } + break; + } + break; + } + return FALSE; +} diff --git a/src/drivers/win/patcher.h b/src/drivers/win/patcher.h new file mode 100644 index 000000000..21e666e40 --- /dev/null +++ b/src/drivers/win/patcher.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +INT_PTR CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/vc/vc14_fceux.vcxproj b/vc/vc14_fceux.vcxproj index 6f5d42963..cbd0c3523 100644 --- a/vc/vc14_fceux.vcxproj +++ b/vc/vc14_fceux.vcxproj @@ -568,6 +568,7 @@ xcopy /y /d "$(ProjectDir)\..\src\drivers\win\7z_64.dll" "$(OutDir)" + @@ -596,6 +597,7 @@ xcopy /y /d "$(ProjectDir)\..\src\drivers\win\7z_64.dll" "$(OutDir)" + @@ -1028,6 +1030,7 @@ xcopy /y /d "$(ProjectDir)\..\src\drivers\win\7z_64.dll" "$(OutDir)" + @@ -1054,6 +1057,7 @@ xcopy /y /d "$(ProjectDir)\..\src\drivers\win\7z_64.dll" "$(OutDir)" + diff --git a/vc/vc14_fceux.vcxproj.filters b/vc/vc14_fceux.vcxproj.filters index c270d091d..2d1b4b792 100644 --- a/vc/vc14_fceux.vcxproj.filters +++ b/vc/vc14_fceux.vcxproj.filters @@ -1111,6 +1111,12 @@ boards + + drivers\win + + + drivers\win + @@ -1620,6 +1626,12 @@ drivers\win + + drivers + + + drivers\win + From c262b0803cb42eb6b92ac3fa3edf772fead7e256 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sat, 26 Jun 2021 19:29:43 -0400 Subject: [PATCH 043/103] initial commit for code dumper UI It looks so derpy! --- src/drivers/win/debugger.cpp | 11 +++++++---- src/drivers/win/res.rc | 16 ++++++++++++++++ src/drivers/win/resource.h | 6 ++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 019e78e3d..cf633ab0d 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2135,10 +2135,13 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) FILE *fout = fopen("testdump.txt", "w"); // Hardcoded start and end addresses for Rockman 2's NMI routine. Lol // Dump(fout, 0xCFED, 0xD0D3); - printf("Taking a dump...\n"); - Dump(fout, 0x8000, 0xFFFF); - printf("I'M DONE!\n"); - fclose(fout); + //printf("Taking a dump...\n"); + //Dump(fout, 0x8000, 0xFFFF); + //printf("I'M DONE!\n"); + //fclose(fout); + + DialogBox(fceu_hInstance, "CODEDUMPER", hwndDlg, AssemblerCallB); + break; } diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 4267b3468..d8af20a55 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -962,6 +962,22 @@ BEGIN GROUPBOX "Patch Data",108,3,81,292,30 END +CODEDUMPER DIALOGEX 84, 67, 304, 135 +STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Code Dumper" +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + CONTROL ".Nes File Addresses",ID_DUMPER_NES_ADDR_TOGGLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,12,71,10 + EDITTEXT ID_DUMPER_START_ADDR,77,12,47,12,ES_AUTOHSCROLL + LTEXT "-",109, 105,12,10,10 + EDITTEXT ID_DUMPER_END_ADDR,140,12,47,12,ES_AUTOHSCROLL + GROUPBOX "Offsets",107, 0,0,200,20 + LTEXT "Output: ",108, 7,40,45,12 + EDITTEXT ID_DUMPER_FILEPATH,60,40,100,12 + PUSHBUTTON "Browse...", ID_DUMPER_BROWSE,170,40,45,12 + PUSHBUTTON "Dump",ID_DUMPER_GO,150,60,45,12 +END + GGCONV DIALOGEX 84, 67, 186, 146 STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Game Genie Encoder/Decoder Tool" diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index fa66a0498..6680d9008 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1218,6 +1218,12 @@ #define ID_DEBUGGER_RESTORE_SIZE 45544 #define ID_DEBUGGER_ROM_PATCHER 45545 #define ID_DEBUGGER_CODE_DUMPER 45546 +#define ID_DUMPER_START_ADDR 45547 +#define ID_DUMPER_END_ADDR 45548 +#define ID_DUMPER_FILEPATH 45549 +#define ID_DUMPER_BROWSE 45550 +#define ID_DUMPER_GO 45551 +#define ID_DUMPER_NES_ADDR_TOGGLE 45552 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From 784771f95c146ac01ad876437864a30453beec34 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sat, 26 Jun 2021 19:36:24 -0400 Subject: [PATCH 044/103] tweak dumper window in editor --- src/drivers/win/res.rc | 73 ++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index d8af20a55..a6d8ce30f 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -962,20 +962,20 @@ BEGIN GROUPBOX "Patch Data",108,3,81,292,30 END -CODEDUMPER DIALOGEX 84, 67, 304, 135 +CODEDUMPER DIALOGEX 84, 67, 204, 66 STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Code Dumper" FONT 8, "MS Shell Dlg", 0, 0, 0x0 BEGIN - CONTROL ".Nes File Addresses",ID_DUMPER_NES_ADDR_TOGGLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,12,71,10 - EDITTEXT ID_DUMPER_START_ADDR,77,12,47,12,ES_AUTOHSCROLL - LTEXT "-",109, 105,12,10,10 - EDITTEXT ID_DUMPER_END_ADDR,140,12,47,12,ES_AUTOHSCROLL - GROUPBOX "Offsets",107, 0,0,200,20 - LTEXT "Output: ",108, 7,40,45,12 - EDITTEXT ID_DUMPER_FILEPATH,60,40,100,12 - PUSHBUTTON "Browse...", ID_DUMPER_BROWSE,170,40,45,12 - PUSHBUTTON "Dump",ID_DUMPER_GO,150,60,45,12 + CONTROL ".Nes File Addresses",ID_DUMPER_NES_ADDR_TOGGLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,11,77,10 + EDITTEXT ID_DUMPER_START_ADDR,85,10,47,12,ES_AUTOHSCROLL + LTEXT "-",109,138,12,10,10 + EDITTEXT ID_DUMPER_END_ADDR,147,10,47,12,ES_AUTOHSCROLL + GROUPBOX "Offsets",107,3,1,196,25 + LTEXT "Output: ",108,3,30,26,9 + EDITTEXT ID_DUMPER_FILEPATH,29,29,114,12 + PUSHBUTTON "Browse...",ID_DUMPER_BROWSE,146,30,45,12 + PUSHBUTTON "Dump",ID_DUMPER_GO,146,46,45,12 END GGCONV DIALOGEX 84, 67, 186, 146 @@ -1961,6 +1961,10 @@ BEGIN BEGIN END + "CODEDUMPER", DIALOG + BEGIN + END + "GGCONV", DIALOG BEGIN END @@ -2335,6 +2339,11 @@ BEGIN 0 END +CODEDUMPER AFX_DIALOG_LAYOUT +BEGIN + 0 +END + #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -3035,33 +3044,33 @@ END DEBUGGERMENU MENU BEGIN - POPUP "Options" - BEGIN - MENUITEM "Auto Open on ROM Load", ID_DEBUGGER_AUTO_OPEN, CHECKED - MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED - MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED - MENUITEM SEPARATOR - MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE - END + POPUP "Options" + BEGIN + MENUITEM "Auto Open on ROM Load", ID_DEBUGGER_AUTO_OPEN, CHECKED + MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED + MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED + MENUITEM SEPARATOR + MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE + END POPUP "Colors" BEGIN MENUITEM SEPARATOR MENUITEM "Restore Defaults", ID_DEBUGGER_DEFCOLOR END - POPUP "Symbols" - BEGIN - MENUITEM "Reload", ID_DEBUGGER_RELOAD_SYMBOLS - MENUITEM "Load .DEB file", ID_DEBUGGER_LOAD_DEB_FILE, CHECKED - MENUITEM SEPARATOR - MENUITEM "Symbolic Debug", ID_DEBUGGER_SYMBOLIC_DEBUG, CHECKED - MENUITEM "Show Symbol Addresses", ID_DEBUGGER_INLINE_ADDRESS, CHECKED - MENUITEM "Default Register Names", ID_DEBUGGER_DEFAULT_REG_NAMES, CHECKED - END - POPUP "Tools" - BEGIN - MENUITEM "ROM Patcher...", ID_DEBUGGER_ROM_PATCHER - MENUITEM "Code Dumper...", ID_DEBUGGER_CODE_DUMPER - END + POPUP "Symbols" + BEGIN + MENUITEM "Reload", ID_DEBUGGER_RELOAD_SYMBOLS + MENUITEM "Load .DEB file", ID_DEBUGGER_LOAD_DEB_FILE, CHECKED + MENUITEM SEPARATOR + MENUITEM "Symbolic Debug", ID_DEBUGGER_SYMBOLIC_DEBUG, CHECKED + MENUITEM "Show Symbol Addresses", ID_DEBUGGER_INLINE_ADDRESS, CHECKED + MENUITEM "Default Register Names", ID_DEBUGGER_DEFAULT_REG_NAMES, CHECKED + END + POPUP "Tools" + BEGIN + MENUITEM "ROM Patcher...", ID_DEBUGGER_ROM_PATCHER + MENUITEM "Code Dumper...", ID_DEBUGGER_CODE_DUMPER + END END From eb7847e5f0a1d6d1903cdf4cdd9fdb388d48d44a Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 00:58:17 -0400 Subject: [PATCH 045/103] split Dump stuff to dumper.cpp and add some frontend --- src/drivers/win/debugger.cpp | 215 +------------------------ src/drivers/win/dumper.cpp | 285 ++++++++++++++++++++++++++++++++++ src/drivers/win/dumper.h | 5 + src/drivers/win/window.cpp | 3 + vc/vc14_fceux.vcxproj | 2 + vc/vc14_fceux.vcxproj.filters | 6 + 6 files changed, 308 insertions(+), 208 deletions(-) create mode 100644 src/drivers/win/dumper.cpp create mode 100644 src/drivers/win/dumper.h diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index cf633ab0d..0aed2a2d8 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -40,6 +40,7 @@ #include "richedit.h" #include "assembler.h" #include "patcher.h" +#include "dumper.h" // ################################## Start of SP CODE ########################### @@ -80,11 +81,11 @@ bool debuggerIDAFont = false; unsigned int IDAFontSize = 16; bool debuggerDisplayROMoffsets = false; -wchar_t* debug_wstr; -char* debug_cdl_str; -char* debug_str_decoration_comment; -char* debug_decoration_comment; -char* debug_decoration_comment_end_pos; +static wchar_t* debug_wstr; +static char* debug_cdl_str; +static char* debug_str_decoration_comment; +static char* debug_decoration_comment; +static char* debug_decoration_comment_end_pos; FINDTEXT newline; FINDTEXT num; @@ -561,198 +562,6 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } -/** -* Dumps disassembled ROM code between startAddr and endAddr (inclusive) to a file. -* endAddr is the address of the last INSTRUCTION. This funcion will grab the operands if present, -* and may spill over a bit in the process. -* 0x80000 - 0xFFFF should get you the loaded banks. However, it's most reliable when you dump one subroutine at a time -* or already have a lot of labels. -* -* For example, say you have 2C A9 10 60, and the A9 byte is supposed to be the start of a subroutine. If the disassembler -* comes across that 2C first, it will interpret the code as: - -* 2C A9 10 BIT $10A9 -* 60 RTS - -* Nonsense. - -* But if you have a named label -* on that A9 byte, the 2C (BIT) instruction will be INTERRUPTED, and it will show up like this: - -* 2C INTERRUPTED -* my_subroutine: -* A9 10 LDA #$10 -* 60 RTS -* -* There is a lot of reused logic between this and Disassemble. However, they're different enough that it would -* be more trouble than it's worth to combine them. -*/ -void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) -{ - wchar_t chr[40] = { 0 }; - wchar_t debug_wbuf[2048] = { 0 }; - int size; - uint8 opcode[3]; - unsigned int instruction_addr; - unsigned int addr = startAddr; // Keeps track of which address to get the operands, etc. from - - if (symbDebugEnabled) - loadNameFiles(); - - unsigned int instructions_count = 0; - for (int addr = startAddr; addr <= endAddr;) - { - // PC pointer - if (addr > 0xFFFF) break; - - instruction_addr = addr; - - if (symbDebugEnabled) - { - // Insert name and comment lines if present - Name* node = findNode(getNamesPointerForAddress(addr), addr); - if (node) - { - if (node->name) - { - // Could probably ditch these swprintf's and just do fwprintf. - // Need to verify exactly how the various buffers are used. - swprintf(debug_wbuf, L"%S:\n", node->name); - fprintf(fout, "%ls", debug_wbuf); - } - if (node->comment) - { - // make a copy - strcpy(debug_str_decoration_comment, node->comment); - strcat(debug_str_decoration_comment, "\r\n"); - // divide the debug_str_decoration_comment into strings (Comment1, Comment2, ...) - debug_decoration_comment = debug_str_decoration_comment; - debug_decoration_comment_end_pos = strstr(debug_decoration_comment, "\r\n"); - while (debug_decoration_comment_end_pos) - { - debug_decoration_comment_end_pos[0] = 0; // set \0 instead of \r - debug_decoration_comment_end_pos[1] = 0; // set \0 instead of \n - swprintf(debug_wbuf, L"; %S\n", debug_decoration_comment); - fprintf(fout, "%ls", debug_wbuf); - - debug_decoration_comment_end_pos += 2; - debug_decoration_comment = debug_decoration_comment_end_pos; - debug_decoration_comment_end_pos = strstr(debug_decoration_comment_end_pos, "\r\n"); - } - } - } - } - - fprintf(fout, "%ls", L" "); - - if (addr >= 0x8000) - { - if (debuggerDisplayROMoffsets && GetNesFileAddress(addr) != -1) - { - swprintf(chr, L" %06X: ", GetNesFileAddress(addr)); - } - else - { - swprintf(chr, L"%02X:%04X: ", getBank(addr), addr); - } - } - else - { - swprintf(chr, L" :%04X: ", addr); - } - - // Add address - fprintf(fout, "%ls", chr); - - size = opsize[GetMem(addr)]; - if (size == 0) - { - swprintf(chr, L"%02X UNDEFINED", GetMem(addr++)); - fprintf(fout, "%ls", chr); - } - else - { - if ((addr + size) > 0xFFFF) - { - while (addr < 0xFFFF) - { - swprintf(chr, L"%02X OVERFLOW\n", GetMem(addr++)); - fprintf(fout, "%ls", chr); - } - break; - } - Name* node; - for (int j = 0; j < size; j++) - { - // Write the raw bytes of this instruction - swprintf(chr, L"%02X ", opcode[j] = GetMem(addr++)); - fprintf(fout, "%ls", chr); - if (j != size - 1 && (node = findNode(getNamesPointerForAddress(addr), addr))) - { - // We were treating this as an operand, but it's named! - // Probably want an instruction to start here instead. - printf("$%04X (%s) came up as an operand for instruction @ %04X\n", addr, node->name, addr - j - 1); - size = j + 1; - break; - } - } - while (size < 3) - { - fprintf(fout, "%ls", L" "); - size++; - } - if (node) - { - // TODO: Instead of this ominous and confusing message, could print ".byte $XX $YY..." - fprintf(fout, " INTERRUPTED"); - } - else - { - static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; // "plenty" - char* _a = Disassemble(addr, opcode); - // This isn't a trace log, so we want to remove the data after the @ or =. - // There are lots of hardcoded sprintfs in Disassemble. This really is the easiest way. - char* traceInfoIndex = strstr(_a, "@"); - if (traceInfoIndex) - traceInfoIndex[-1] = 0; - traceInfoIndex = strstr(_a, "="); - if (traceInfoIndex) - traceInfoIndex[-1] = 0; - - strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); - - if (symbDebugEnabled) - { // TODO: This will add in both the default name and custom name if you have inlineAddresses enabled. - if (symbRegNames) - replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); - replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, NULL); - for (int p = 0; p +#include + +#include "types.h" +#include "resource.h" +#include "debugger.h" +#include "debuggersp.h" +#include "../../debug.h" +#include "asm.h" +#include "../../x6502.h" +#include "../../fceu.h" +#include "../../debug.h" +#include "../../nsf.h" +#include "../../ppu.h" +#include "../../cart.h" +#include "../../ines.h" +#include "../../asm.h" +#include "tracer.h" +#include "window.h" + +extern Name* ramBankNames; +extern Name* pageNames[32]; + +static char* debug_str_decoration_comment; +static char* debug_decoration_comment; +static char* debug_decoration_comment_end_pos; +static char filename[257]; + +/** +* Dumps disassembled ROM code between startAddr and endAddr (inclusive) to a file. +* endAddr is the address of the last INSTRUCTION. This funcion will grab the operands if present, +* and may spill over a bit in the process. +* 0x80000 - 0xFFFF should get you the loaded banks. However, it's most reliable when you dump one subroutine at a time +* or already have a lot of labels. +* +* For example, say you have 2C A9 10 60, and the A9 byte is supposed to be the start of a subroutine. If the disassembler +* comes across that 2C first, it will interpret the code as: + +* 2C A9 10 BIT $10A9 +* 60 RTS + +* Nonsense. + +* But if you have a named label +* on that A9 byte, the 2C (BIT) instruction will be INTERRUPTED, and it will show up like this: + +* 2C INTERRUPTED +* my_subroutine: +* A9 10 LDA #$10 +* 60 RTS +* +* There is a lot of reused logic between this and Disassemble. However, they're different enough that it would +* be more trouble than it's worth to combine them. +*/ +void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) +{ + wchar_t chr[40] = { 0 }; + wchar_t debug_wbuf[2048] = { 0 }; + int size; + uint8 opcode[3]; + unsigned int instruction_addr; + unsigned int addr = startAddr; // Keeps track of which address to get the operands, etc. from + + if (symbDebugEnabled) + loadNameFiles(); + + unsigned int instructions_count = 0; + for (int addr = startAddr; addr <= endAddr;) + { + // PC pointer + if (addr > 0xFFFF) break; + + instruction_addr = addr; + + if (symbDebugEnabled) + { + // Insert name and comment lines if present + Name* node = findNode(getNamesPointerForAddress(addr), addr); + if (node) + { + if (node->name) + { + // Could probably ditch these swprintf's and just do fwprintf. + // Need to verify exactly how the various buffers are used. + swprintf(debug_wbuf, L"%S:\n", node->name); + fprintf(fout, "%ls", debug_wbuf); + } + if (node->comment) + { + // make a copy + strcpy(debug_str_decoration_comment, node->comment); + strcat(debug_str_decoration_comment, "\r\n"); + // divide the debug_str_decoration_comment into strings (Comment1, Comment2, ...) + debug_decoration_comment = debug_str_decoration_comment; + debug_decoration_comment_end_pos = strstr(debug_decoration_comment, "\r\n"); + while (debug_decoration_comment_end_pos) + { + debug_decoration_comment_end_pos[0] = 0; // set \0 instead of \r + debug_decoration_comment_end_pos[1] = 0; // set \0 instead of \n + swprintf(debug_wbuf, L"; %S\n", debug_decoration_comment); + fprintf(fout, "%ls", debug_wbuf); + + debug_decoration_comment_end_pos += 2; + debug_decoration_comment = debug_decoration_comment_end_pos; + debug_decoration_comment_end_pos = strstr(debug_decoration_comment_end_pos, "\r\n"); + } + } + } + } + + fprintf(fout, "%ls", L" "); + + if (addr >= 0x8000) + { + if (debuggerDisplayROMoffsets && GetNesFileAddress(addr) != -1) + { + swprintf(chr, L" %06X: ", GetNesFileAddress(addr)); + } + else + { + swprintf(chr, L"%02X:%04X: ", getBank(addr), addr); + } + } + else + { + swprintf(chr, L" :%04X: ", addr); + } + + // Add address + fprintf(fout, "%ls", chr); + + size = opsize[GetMem(addr)]; + if (size == 0) + { + swprintf(chr, L"%02X UNDEFINED", GetMem(addr++)); + fprintf(fout, "%ls", chr); + } + else + { + if ((addr + size) > 0xFFFF) + { + while (addr < 0xFFFF) + { + swprintf(chr, L"%02X OVERFLOW\n", GetMem(addr++)); + fprintf(fout, "%ls", chr); + } + break; + } + Name* node; + for (int j = 0; j < size; j++) + { + // Write the raw bytes of this instruction + swprintf(chr, L"%02X ", opcode[j] = GetMem(addr++)); + fprintf(fout, "%ls", chr); + if (j != size - 1 && (node = findNode(getNamesPointerForAddress(addr), addr))) + { + // We were treating this as an operand, but it's named! + // Probably want an instruction to start here instead. + printf("$%04X (%s) came up as an operand for instruction @ %04X\n", addr, node->name, addr - j - 1); + size = j + 1; + break; + } + } + while (size < 3) + { + fprintf(fout, "%ls", L" "); + size++; + } + if (node) + { + // TODO: Instead of this ominous and confusing message, could print ".byte $XX $YY..." + fprintf(fout, " INTERRUPTED"); + } + else + { + static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; // "plenty" + char* _a = Disassemble(addr, opcode); + // This isn't a trace log, so we want to remove the data after the @ or =. + // There are lots of hardcoded sprintfs in Disassemble. This really is the easiest way. + char* traceInfoIndex = strstr(_a, "@"); + if (traceInfoIndex) + traceInfoIndex[-1] = 0; + traceInfoIndex = strstr(_a, "="); + if (traceInfoIndex) + traceInfoIndex[-1] = 0; + + strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); + + if (symbDebugEnabled) + { // TODO: This will add in both the default name and custom name if you have inlineAddresses enabled. + if (symbRegNames) + replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); + replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, NULL); + for (int p = 0; p + +BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index b36e74bcc..cb4c78a3e 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -3362,6 +3362,9 @@ bool inline (*GetIsLetterLegal(UINT id))(char letter) // Array Size, Init value in Symbolic Name in Debugger case IDC_EDIT_SYMBOLIC_ARRAY: case IDC_EDIT_SYMBOLIC_INIT: + // Address boxes in Debugger -> Tools menus + case ID_DUMPER_START_ADDR: case ID_DUMPER_END_ADDR: + // Address, Value, Compare, Known Value, Note equal, Greater than and Less than in Cheat case IDC_CHEAT_ADDR: case IDC_CHEAT_VAL: case IDC_CHEAT_COM: case IDC_CHEAT_VAL_KNOWN: case IDC_CHEAT_VAL_NE_BY: diff --git a/vc/vc14_fceux.vcxproj b/vc/vc14_fceux.vcxproj index cbd0c3523..3bed0b094 100644 --- a/vc/vc14_fceux.vcxproj +++ b/vc/vc14_fceux.vcxproj @@ -577,6 +577,7 @@ xcopy /y /d "$(ProjectDir)\..\src\drivers\win\7z_64.dll" "$(OutDir)" + @@ -1038,6 +1039,7 @@ xcopy /y /d "$(ProjectDir)\..\src\drivers\win\7z_64.dll" "$(OutDir)" + diff --git a/vc/vc14_fceux.vcxproj.filters b/vc/vc14_fceux.vcxproj.filters index 2d1b4b792..a34827a64 100644 --- a/vc/vc14_fceux.vcxproj.filters +++ b/vc/vc14_fceux.vcxproj.filters @@ -1117,6 +1117,9 @@ drivers\win + + drivers\win + @@ -1632,6 +1635,9 @@ drivers\win + + drivers\win + From 86aee79504a4e49d8bf26a3c570ec70f5962230f Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 01:28:11 -0400 Subject: [PATCH 046/103] fix input handling in dumper dialog --- src/drivers/win/dumper.cpp | 26 +++++++++++++++----------- src/drivers/win/res.rc | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index b29858151..d4d76d0d8 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -230,6 +230,7 @@ BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) SetWindowLongPtr(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); SendDlgItemMessage(hwndDlg, ID_DUMPER_START_ADDR, EM_SETLIMITTEXT, 6, 0); SendDlgItemMessage(hwndDlg, ID_DUMPER_END_ADDR, EM_SETLIMITTEXT, 6, 0); + SendDlgItemMessage(hwndDlg, ID_DUMPER_FILEPATH, EM_SETLIMITTEXT, 256, 0); SetFocus(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR)); return true; case WM_CLOSE: @@ -247,35 +248,38 @@ BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) printf("Browser...\n"); return true; case ID_DUMPER_GO: - int startAddr = GetEditHex(hwndDlg, ID_DUMPER_START_ADDR); - int endAddr = GetEditHex(hwndDlg, ID_DUMPER_END_ADDR); - // Nothing was entered - if (startAddr == 0 && endAddr == 0) - { + static char str[7]; + int startAddr, endAddr; + + // Nothing was entered. + if (GetDlgItemText(hwndDlg, ID_DUMPER_START_ADDR, str, 6)) + startAddr = strtol(str, NULL, 16); + else startAddr = 0x8000; + + if (GetDlgItemText(hwndDlg, ID_DUMPER_END_ADDR, str, 6)) + endAddr = strtol(str, NULL, 16); + else endAddr = 0xFFFF; - } if (!GetDlgItemText(hwndDlg, ID_DUMPER_FILEPATH, filename, 256)) { - //printf("Filename was too long!\n"); - MessageBox(hwndDlg, "No file path entered.", "", MB_OK | MB_ICONINFORMATION); + MessageBox(hwndDlg, "No file path entered.", "Code Dumper", MB_OK | MB_ICONINFORMATION); break; } FILE *fout; if (!(fout = fopen(filename, "w"))) { - //printf("Could not open file for writing."); - MessageBox(hwndDlg, "Could not open file for writing.", "", MB_OK | MB_ICONINFORMATION); + MessageBox(hwndDlg, "Could not open file.", "Code Dumper", MB_OK | MB_ICONINFORMATION); break; } printf("Dumping $%04X - $%04X to \"%s\"...\n", startAddr, endAddr, filename); Dump(fout, startAddr, endAddr); fclose(fout); - printf("Done\n"); + printf("Done.\n"); return true; } } diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index a6d8ce30f..4c0058378 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -973,7 +973,7 @@ BEGIN EDITTEXT ID_DUMPER_END_ADDR,147,10,47,12,ES_AUTOHSCROLL GROUPBOX "Offsets",107,3,1,196,25 LTEXT "Output: ",108,3,30,26,9 - EDITTEXT ID_DUMPER_FILEPATH,29,29,114,12 + EDITTEXT ID_DUMPER_FILEPATH,29,29,114,12,ES_AUTOHSCROLL PUSHBUTTON "Browse...",ID_DUMPER_BROWSE,146,30,45,12 PUSHBUTTON "Dump",ID_DUMPER_GO,146,46,45,12 END From b9359d8066ab69d031b1bdc4b24e214176490104 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 01:38:42 -0400 Subject: [PATCH 047/103] split out separate handler methods --- src/drivers/win/dumper.cpp | 109 ++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 50 deletions(-) diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index d4d76d0d8..9049fc7da 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -218,21 +218,69 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) } } +bool DumperInitDialog(HWND hwndDlg) +{ + debug_str_decoration_comment = (char*)malloc(NL_MAX_MULTILINE_COMMENT_LEN + 10); + Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR), L"8000"); + Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), L"FFFF"); + SetWindowLongPtr(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); + SetWindowLongPtr(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); + SendDlgItemMessage(hwndDlg, ID_DUMPER_START_ADDR, EM_SETLIMITTEXT, 6, 0); + SendDlgItemMessage(hwndDlg, ID_DUMPER_END_ADDR, EM_SETLIMITTEXT, 6, 0); + SendDlgItemMessage(hwndDlg, ID_DUMPER_FILEPATH, EM_SETLIMITTEXT, 256, 0); + SetFocus(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR)); + return true; +} + +bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) +{ + switch (btnId) + { + case ID_DUMPER_BROWSE: + printf("Browser...\n"); + return true; + case ID_DUMPER_GO: + static char str[7]; + int startAddr, endAddr; + + // Nothing was entered. + if (GetDlgItemText(hwndDlg, ID_DUMPER_START_ADDR, str, 6)) + startAddr = strtol(str, NULL, 16); + else + startAddr = 0x8000; + + if (GetDlgItemText(hwndDlg, ID_DUMPER_END_ADDR, str, 6)) + endAddr = strtol(str, NULL, 16); + else + endAddr = 0xFFFF; + + if (!GetDlgItemText(hwndDlg, ID_DUMPER_FILEPATH, filename, 256)) + { + MessageBox(hwndDlg, "No file path entered.", "Code Dumper", MB_OK | MB_ICONINFORMATION); + break; + } + + FILE *fout; + if (!(fout = fopen(filename, "w"))) + { + MessageBox(hwndDlg, "Could not open file.", "Code Dumper", MB_OK | MB_ICONINFORMATION); + break; + } + + printf("Dumping $%04X - $%04X to \"%s\"...\n", startAddr, endAddr, filename); + Dump(fout, startAddr, endAddr); + fclose(fout); + printf("Done.\n"); + return true; + } +} + BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: - debug_str_decoration_comment = (char*)malloc(NL_MAX_MULTILINE_COMMENT_LEN + 10); - Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR), L"8000"); - Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), L"FFFF"); - SetWindowLongPtr(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); - SetWindowLongPtr(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); - SendDlgItemMessage(hwndDlg, ID_DUMPER_START_ADDR, EM_SETLIMITTEXT, 6, 0); - SendDlgItemMessage(hwndDlg, ID_DUMPER_END_ADDR, EM_SETLIMITTEXT, 6, 0); - SendDlgItemMessage(hwndDlg, ID_DUMPER_FILEPATH, EM_SETLIMITTEXT, 256, 0); - SetFocus(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR)); - return true; + return DumperInitDialog(hwndDlg); case WM_CLOSE: case WM_QUIT: free(debug_str_decoration_comment); @@ -242,46 +290,7 @@ BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) switch (HIWORD(wParam)) { case BN_CLICKED: - switch (LOWORD(wParam)) - { - case ID_DUMPER_BROWSE: - printf("Browser...\n"); - return true; - case ID_DUMPER_GO: - - static char str[7]; - int startAddr, endAddr; - - // Nothing was entered. - if (GetDlgItemText(hwndDlg, ID_DUMPER_START_ADDR, str, 6)) - startAddr = strtol(str, NULL, 16); - else - startAddr = 0x8000; - - if (GetDlgItemText(hwndDlg, ID_DUMPER_END_ADDR, str, 6)) - endAddr = strtol(str, NULL, 16); - else - endAddr = 0xFFFF; - - if (!GetDlgItemText(hwndDlg, ID_DUMPER_FILEPATH, filename, 256)) - { - MessageBox(hwndDlg, "No file path entered.", "Code Dumper", MB_OK | MB_ICONINFORMATION); - break; - } - - FILE *fout; - if (!(fout = fopen(filename, "w"))) - { - MessageBox(hwndDlg, "Could not open file.", "Code Dumper", MB_OK | MB_ICONINFORMATION); - break; - } - - printf("Dumping $%04X - $%04X to \"%s\"...\n", startAddr, endAddr, filename); - Dump(fout, startAddr, endAddr); - fclose(fout); - printf("Done.\n"); - return true; - } + return DumperBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); } break; } From a57ecb82d37a6071f828c03d9cffde2ac7e54bdb Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 03:11:06 -0400 Subject: [PATCH 048/103] support .NES file addresses checkbox --- src/drivers/win/dumper.cpp | 45 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index 9049fc7da..f4265010d 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -25,6 +25,7 @@ static char* debug_str_decoration_comment; static char* debug_decoration_comment; static char* debug_decoration_comment_end_pos; static char filename[257]; +static bool showNesFileOffests; /** * Dumps disassembled ROM code between startAddr and endAddr (inclusive) to a file. @@ -112,7 +113,7 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) if (addr >= 0x8000) { - if (debuggerDisplayROMoffsets && GetNesFileAddress(addr) != -1) + if (showNesFileOffests && GetNesFileAddress(addr) != -1) { swprintf(chr, L" %06X: ", GetNesFileAddress(addr)); } @@ -232,6 +233,19 @@ bool DumperInitDialog(HWND hwndDlg) return true; } +static inline int ParseAddressString(HWND hwndDlg, char *str, int default) +{ + if (!str[0]) + return default; + + int addr = strtol(str, NULL, 16); + + if (showNesFileOffests) + return GetRomAddress(addr); + else + return addr; +} + bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) { switch (btnId) @@ -240,19 +254,28 @@ bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) printf("Browser...\n"); return true; case ID_DUMPER_GO: - static char str[7]; + char str[7]; int startAddr, endAddr; + showNesFileOffests = IsDlgButtonChecked(hwndDlg, ID_DUMPER_NES_ADDR_TOGGLE) == BST_CHECKED; - // Nothing was entered. - if (GetDlgItemText(hwndDlg, ID_DUMPER_START_ADDR, str, 6)) - startAddr = strtol(str, NULL, 16); - else - startAddr = 0x8000; + GetDlgItemText(hwndDlg, ID_DUMPER_START_ADDR, str, 6); + startAddr = ParseAddressString(hwndDlg, str, 0x8000); - if (GetDlgItemText(hwndDlg, ID_DUMPER_END_ADDR, str, 6)) - endAddr = strtol(str, NULL, 16); - else - endAddr = 0xFFFF; + GetDlgItemText(hwndDlg, ID_DUMPER_END_ADDR, str, 6); + endAddr = ParseAddressString(hwndDlg, str, 0xFFFF); + + // -1 means no valid NES memory address for Rom file address. > 0xFFFF means you're dumb. + if (startAddr < 0 || startAddr > 0xFFFF) + { + MessageBox(hwndDlg, "Invalid start address.", "Code Dumper", MB_OK | MB_ICONINFORMATION); + break; + } + + if (endAddr < 0 || endAddr > 0xFFFF || endAddr < startAddr) + { + MessageBox(hwndDlg, "Invalid end address.", "Code Dumper", MB_OK | MB_ICONINFORMATION); + break; + } if (!GetDlgItemText(hwndDlg, ID_DUMPER_FILEPATH, filename, 256)) { From db071d05510f40c0489752bee539e0d7937057cb Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 03:11:39 -0400 Subject: [PATCH 049/103] clean up message handling for more fluent control --- src/drivers/win/dumper.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index f4265010d..90804fef3 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -219,17 +219,29 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) } } -bool DumperInitDialog(HWND hwndDlg) +bool DumperInitDialog(HWND hwndDlg, HWND hwndFocused, PROPSHEETPAGE *props) { debug_str_decoration_comment = (char*)malloc(NL_MAX_MULTILINE_COMMENT_LEN + 10); + Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR), L"8000"); Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), L"FFFF"); + SetWindowLongPtr(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); SetWindowLongPtr(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc); + SendDlgItemMessage(hwndDlg, ID_DUMPER_START_ADDR, EM_SETLIMITTEXT, 6, 0); SendDlgItemMessage(hwndDlg, ID_DUMPER_END_ADDR, EM_SETLIMITTEXT, 6, 0); SendDlgItemMessage(hwndDlg, ID_DUMPER_FILEPATH, EM_SETLIMITTEXT, 256, 0); + + // Overwrite default focus, return false SetFocus(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR)); + return false; +} + +bool DumperExit(HWND hwndDlg) +{ + free(debug_str_decoration_comment); + EndDialog(hwndDlg, 0); return true; } @@ -253,6 +265,7 @@ bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) case ID_DUMPER_BROWSE: printf("Browser...\n"); return true; + case IDOK: // Could make "Dump" a DEFPUSHBUTTON, but I don't like the highlight. case ID_DUMPER_GO: char str[7]; int startAddr, endAddr; @@ -295,7 +308,10 @@ bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) fclose(fout); printf("Done.\n"); return true; + case IDCANCEL: + return DumperExit(hwndDlg); } + return false; } BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -303,12 +319,10 @@ BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) switch (uMsg) { case WM_INITDIALOG: - return DumperInitDialog(hwndDlg); + return DumperInitDialog(hwndDlg, (HWND)wParam, (PROPSHEETPAGE*)lParam); case WM_CLOSE: case WM_QUIT: - free(debug_str_decoration_comment); - EndDialog(hwndDlg, 0); - return true; + return DumperExit(hwndDlg); case WM_COMMAND: switch (HIWORD(wParam)) { From 34fcc1243bf38eda691039078a71cad0ab280943 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 04:45:38 -0400 Subject: [PATCH 050/103] add file browsing functionality --- src/drivers/win/dumper.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index 90804fef3..de31410f3 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -24,8 +24,9 @@ extern Name* pageNames[32]; static char* debug_str_decoration_comment; static char* debug_decoration_comment; static char* debug_decoration_comment_end_pos; -static char filename[257]; +static char filename[MAX_PATH + 1]; static bool showNesFileOffests; +static OPENFILENAME ofn; /** * Dumps disassembled ROM code between startAddr and endAddr (inclusive) to a file. @@ -223,6 +224,14 @@ bool DumperInitDialog(HWND hwndDlg, HWND hwndFocused, PROPSHEETPAGE *props) { debug_str_decoration_comment = (char*)malloc(NL_MAX_MULTILINE_COMMENT_LEN + 10); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hwndDlg; + ofn.lpstrFilter = "All Files (*.*)\0*.*\0"; + ofn.lpstrFile = (LPSTR)filename; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT; + ofn.lpstrDefExt = (LPCTSTR)"asm"; + Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR), L"8000"); Edit_SetCueBannerText(GetDlgItem(hwndDlg, ID_DUMPER_END_ADDR), L"FFFF"); @@ -231,7 +240,7 @@ bool DumperInitDialog(HWND hwndDlg, HWND hwndFocused, PROPSHEETPAGE *props) SendDlgItemMessage(hwndDlg, ID_DUMPER_START_ADDR, EM_SETLIMITTEXT, 6, 0); SendDlgItemMessage(hwndDlg, ID_DUMPER_END_ADDR, EM_SETLIMITTEXT, 6, 0); - SendDlgItemMessage(hwndDlg, ID_DUMPER_FILEPATH, EM_SETLIMITTEXT, 256, 0); + SendDlgItemMessage(hwndDlg, ID_DUMPER_FILEPATH, EM_SETLIMITTEXT, MAX_PATH, 0); // Overwrite default focus, return false SetFocus(GetDlgItem(hwndDlg, ID_DUMPER_START_ADDR)); @@ -263,9 +272,13 @@ bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) switch (btnId) { case ID_DUMPER_BROWSE: - printf("Browser...\n"); + // Not sure if these need to be wide strs. + if (GetSaveFileName(&ofn)) + { + SetDlgItemText(hwndDlg, ID_DUMPER_FILEPATH, filename); + } return true; - case IDOK: // Could make "Dump" a DEFPUSHBUTTON, but I don't like the highlight. + case IDOK: // Enter press case ID_DUMPER_GO: char str[7]; int startAddr, endAddr; @@ -290,7 +303,7 @@ bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) break; } - if (!GetDlgItemText(hwndDlg, ID_DUMPER_FILEPATH, filename, 256)) + if (!GetDlgItemText(hwndDlg, ID_DUMPER_FILEPATH, filename, MAX_PATH)) { MessageBox(hwndDlg, "No file path entered.", "Code Dumper", MB_OK | MB_ICONINFORMATION); break; From 81e62e1653e288b70ab6215df3bd664c58f78c53 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 04:46:11 -0400 Subject: [PATCH 051/103] add loading cursor and wait beep for long dumps --- src/drivers/win/dumper.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index de31410f3..dc0579468 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -316,10 +316,19 @@ bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) break; } + // This could take a while... printf("Dumping $%04X - $%04X to \"%s\"...\n", startAddr, endAddr, filename); + EnableWindow(hwndDlg, false); + SetCursor(LoadCursor(NULL, IDC_WAIT)); + Dump(fout, startAddr, endAddr); fclose(fout); + printf("Done.\n"); + EnableWindow(hwndDlg, true); + SetCursor(LoadCursor(NULL, IDC_ARROW)); + MessageBeep(MB_ICONINFORMATION); + return true; case IDCANCEL: return DumperExit(hwndDlg); From fc60358f795d0b37b7ce62f9d75b57ccc729087a Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 04:47:46 -0400 Subject: [PATCH 052/103] add IDCANCEL and IDOK processing to patcher --- src/drivers/win/patcher.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/drivers/win/patcher.cpp b/src/drivers/win/patcher.cpp index cc693f17e..ee981a380 100644 --- a/src/drivers/win/patcher.cpp +++ b/src/drivers/win/patcher.cpp @@ -128,6 +128,7 @@ INT_PTR CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa } UpdatePatcher(hwndDlg); break; + case IDOK: case IDC_ROMPATCHER_BTN_APPLY: p = GetEditHexData(hwndDlg, IDC_ROMPATCHER_PATCH_DATA); i = 0; @@ -142,6 +143,9 @@ INT_PTR CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa if (!iNesSave()) MessageBox(NULL, "Error Saving", "Error", MB_OK | MB_ICONERROR); break; + case IDCANCEL: + EndDialog(hwndDlg, 0); + break; } break; } From cd13ee29f7d714fd96433bf9bcbc8019b26f4be2 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 06:29:57 -0400 Subject: [PATCH 053/103] revive that "dead" EN_CHANGE code in a new callback I have absolutely no idea how the old version ever worked! Seriously, it makes no sense. It checked if the HIWORD of wParam equaled EN_CHANGE even though it was in a BN_CLICKED case...but it still got the events. This implies that BN_CLICKED == EN_CHANGE, but 0 very much does not equal 0x300. --- src/drivers/win/debugger.cpp | 43 ++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 0aed2a2d8..4e03bc95b 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1831,30 +1831,6 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); UpdateDebugger(false); break; - case IDC_DEBUGGER_CYCLES_EXCEED: - { - // Pretty sure this was dead code. BN_CLICKED is not equal to EN_CHANGE. - // Does it need to be moved to an EN_CHANGED callback? - //if (HIWORD(wParam) == EN_CHANGE) - //{ - // char str[16]; - // GetDlgItemText(hwndDlg, IDC_DEBUGGER_CYCLES_EXCEED, str, 16); - // break_cycles_limit = strtoul(str, NULL, 10); - //} - break; - } - case IDC_DEBUGGER_INSTRUCTIONS_EXCEED: - { - // Pretty sure this was dead code. BN_CLICKED is not equal to EN_CHANGE. - // Does it need to be moved to an EN_CHANGED callback? - //if (HIWORD(wParam) == EN_CHANGE) - //{ - // char str[16]; - // GetDlgItemText(hwndDlg, IDC_DEBUGGER_INSTRUCTIONS_EXCEED, str, 16); - // break_instructions_limit = strtoul(str, NULL, 10); - //} - break; - } case ID_DEBUGGER_DEFCOLOR: { if (!IsDebugColorDefault() && MessageBox(hwndDlg, "Do you want to restore all the colors to default?", "Restore default colors", MB_YESNO | MB_ICONINFORMATION) == IDYES) @@ -2470,6 +2446,22 @@ void DebuggerMButtonDown(HWND hwndDlg, int cursorX, int cursorY, int vkFlags) } } +void DebuggerEnChange(HWND hwndDlg, uint16 textBoxId, HWND hwndTextbox) +{ + char str[16]; + switch (textBoxId) + { + case IDC_DEBUGGER_CYCLES_EXCEED: + GetDlgItemText(hwndDlg, IDC_DEBUGGER_CYCLES_EXCEED, str, 16); + break_cycles_limit = strtoul(str, NULL, 10); + break; + case IDC_DEBUGGER_INSTRUCTIONS_EXCEED: + GetDlgItemText(hwndDlg, IDC_DEBUGGER_INSTRUCTIONS_EXCEED, str, 16); + break_instructions_limit = strtoul(str, NULL, 10); + break; + } +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -2504,6 +2496,9 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case LBN_SELCHANGE: DebuggerSelChange(hwndDlg, LOWORD(wParam), (HWND)lParam); break; + case EN_CHANGE: + DebuggerEnChange(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; } case WM_INITMENUPOPUP: DebuggerInitMenuPopup(hwndDlg, (HMENU)wParam, LOWORD(lParam), HIWORD(lParam)); From 53c36d94c62def7f4c6e50de3157cafc4a416ebb Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 06:35:22 -0400 Subject: [PATCH 054/103] use new callbacks instead of DebuggerCallB when posible --- src/drivers/win/debugger.cpp | 128 +++++++++++++++++------------------ 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 4e03bc95b..b80cbdfd6 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1813,6 +1813,65 @@ void DebuggerResizeWindow(HWND hwndDlg, UINT resizeType) } } +void DebuggerLbnDblClk(HWND hwndDlg, uint16 itemId, HWND hwndBtn) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + switch (itemId) + { + case IDC_DEBUGGER_BP_LIST: + EnableBreak(SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_BP_LIST, LB_GETCURSEL, 0, 0)); + break; + case LIST_DEBUGGER_BOOKMARKS: + GoToDebuggerBookmark(hwndDlg); + break; + } +} + +void DebuggerLbnSelCancel(HWND hwndDlg, uint16 listBoxId, HWND hwndList) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + switch (listBoxId) + { + case IDC_DEBUGGER_BP_LIST: + // Disable the delete and edit buttons + EnableWindow(GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_DEL), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_EDIT), FALSE); + break; + } +} + +void DebuggerLbnSelChange(HWND hwndDlg, uint16 listBoxId, HWND hwndList) +{ + // None of these events can be processed without a game loaded. + if (!GameInfo) + return; + + switch (listBoxId) + { + case IDC_DEBUGGER_BP_LIST: + { + // If something is selected, enabled the delete and edit buttons. + if (SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_BP_LIST, LB_GETCURSEL, 0, 0) >= 0) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_DEL), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_EDIT), TRUE); + } + else + { + EnableWindow(GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_DEL), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_DEBUGGER_BP_EDIT), FALSE); + } + break; + } + } +} + void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) { // Buttons that don't need a rom loaded to do something, such as autoload @@ -2106,66 +2165,7 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) } case IDC_DEBUGGER_ROM_PATCHER: DoPatcher(-1,hwndDlg); break; // TODO: delete/merge with ID_DEBUGGER_ROM_PATCHER // Double click the breakpoint list - // TODO: wait for the clean double-click callback! - case DEBUGGER_CONTEXT_TOGGLEBREAK: DebuggerCallB(hwndDlg, WM_COMMAND, (LBN_DBLCLK * 0x10000) | (IDC_DEBUGGER_BP_LIST), (LPARAM)hwndBtn); break; - } - } -} - -void DebuggerDblClk(HWND hwndDlg, uint16 itemId, HWND hwndBtn) -{ - // None of these events can be processed without a game loaded. - if (!GameInfo) - return; - - switch (itemId) - { - case IDC_DEBUGGER_BP_LIST: - EnableBreak(SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0)); - break; - case LIST_DEBUGGER_BOOKMARKS: - GoToDebuggerBookmark(hwndDlg); - break; - } -} - -void DebuggerSelCancel(HWND hwndDlg, uint16 listBoxId, HWND hwndList) -{ - // None of these events can be processed without a game loaded. - if (!GameInfo) - return; - - switch (listBoxId) - { - case IDC_DEBUGGER_BP_LIST: - // Disable the delete and edit buttons - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_DEL),FALSE); - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_EDIT),FALSE); - break; - } -} - -void DebuggerSelChange(HWND hwndDlg, uint16 listBoxId, HWND hwndList) -{ - // None of these events can be processed without a game loaded. - if (!GameInfo) - return; - - switch (listBoxId) - { - case IDC_DEBUGGER_BP_LIST: - { - // If something is selected, enabled the delete and edit buttons. - if (SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BP_LIST,LB_GETCURSEL,0,0) >= 0) - { - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_DEL),TRUE); - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_EDIT),TRUE); - } else - { - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_DEL),FALSE); - EnableWindow(GetDlgItem(hwndDlg,IDC_DEBUGGER_BP_EDIT),FALSE); - } - break; + case DEBUGGER_CONTEXT_TOGGLEBREAK: DebuggerLbnDblClk(hwndDlg, IDC_DEBUGGER_BP_LIST, hwndBtn); break; } } } @@ -2488,13 +2488,13 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); break; case LBN_DBLCLK: - DebuggerDblClk(hwndDlg, LOWORD(wParam), (HWND)lParam); + DebuggerLbnDblClk(hwndDlg, LOWORD(wParam), (HWND)lParam); break; case LBN_SELCANCEL: - DebuggerSelCancel(hwndDlg, LOWORD(wParam), (HWND)lParam); + DebuggerLbnSelCancel(hwndDlg, LOWORD(wParam), (HWND)lParam); break; case LBN_SELCHANGE: - DebuggerSelChange(hwndDlg, LOWORD(wParam), (HWND)lParam); + DebuggerLbnSelChange(hwndDlg, LOWORD(wParam), (HWND)lParam); break; case EN_CHANGE: DebuggerEnChange(hwndDlg, LOWORD(wParam), (HWND)lParam); @@ -2541,7 +2541,7 @@ void DoDebuggerStepInto() if (!hDebug) return; // Click the Step Into button - DebuggerCallB(hDebug, WM_COMMAND, IDC_DEBUGGER_STEP_IN, 0); + DebuggerBnClicked(hDebug, IDC_DEBUGGER_STEP_IN, NULL); } void DoPatcher(int address, HWND hParent) From 58b151001273d3e7eb31887d9bbec6830126532b Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 06:37:26 -0400 Subject: [PATCH 055/103] replace remaining instances of that confusing comment with my verbiage --- src/drivers/win/debugger.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index b80cbdfd6..09563d54e 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -923,7 +923,7 @@ void UpdateDebugger(bool jump_to_pc) } - // "Address Bookmark Add" follows the address + // The address in the Add Bookmark textbox follows the scroll pos. // Update register values sprintf(str, "%02X", X.A); @@ -2091,7 +2091,7 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) sprintf(str,"%04X", tmp); SetDlgItemText(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,str); Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, tmp); - // "Address Bookmark Add" follows the address + // The address in the Add Bookmark textbox follows the scroll pos. sprintf(str,"%04X", si.nPos); SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); } @@ -2125,9 +2125,6 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) break_on_instructions ^= 1; break; } - -// ################################## Start of SP CODE ########################### - case IDC_DEBUGGER_RELOAD_SYMS: { // TODO: delete/merge with ID_DEBUGGER_RELOAD_SYMBOLS ramBankNamesLoaded = false; From e23e64392e2081e0671867e46ba15c96db23c81d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 06:39:24 -0400 Subject: [PATCH 056/103] add enter-press functionality to a few text fields --- src/drivers/win/debugger.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 09563d54e..93b48378d 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1977,6 +1977,22 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) case ID_DEBUGGER_CODE_DUMPER: DialogBox(fceu_hInstance, "CODEDUMPER", hwndDlg, DumperCallB); break; + case IDOK: + // Make pressing Enter synonymous with the button you'd expect depending on the focus. + HWND focus; + switch (GetDlgCtrlID(focus = GetFocus())) + { + case IDC_DEBUGGER_VAL_PCSEEK: + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_SEEK_TO, NULL); + break; + case IDC_DEBUGGER_BOOKMARK: + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_BOOKMARK_ADD, NULL); + break; + case IDC_DEBUGGER_VAL_PC: + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_SEEK_PC, NULL); + break; + } + break; } // Buttons that only get handled when a game is loaded From 2312ff32938bd266bb6ac9a989de70a2b5075494 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 06:40:12 -0400 Subject: [PATCH 057/103] Add enter-press functionality for break-when-exceed fields Not quite sure how I feel about this one. --- src/drivers/win/debugger.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 93b48378d..3021bc102 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1991,6 +1991,13 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) case IDC_DEBUGGER_VAL_PC: DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_SEEK_PC, NULL); break; + case IDC_DEBUGGER_CYCLES_EXCEED: + // Sending click events in this way does not auto-check the box. + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_BREAK_ON_CYCLES, NULL); + break; + case IDC_DEBUGGER_INSTRUCTIONS_EXCEED: + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS, NULL); + break; } break; } @@ -2134,11 +2141,13 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) case IDC_DEBUGGER_BREAK_ON_CYCLES: { break_on_cycles ^= 1; + CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_CYCLES, break_on_cycles); break; } case IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS: { break_on_instructions ^= 1; + CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS, break_on_instructions); break; } case IDC_DEBUGGER_RELOAD_SYMS: From c376a4460722a825bf1a03619900ce736149186a Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 06:57:47 -0400 Subject: [PATCH 058/103] add "break on bad opcodes" to menu --- src/drivers/win/debugger.cpp | 5 +++++ src/drivers/win/res.rc | 2 ++ src/drivers/win/resource.h | 1 + 3 files changed, 8 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 3021bc102..f25c9d7a0 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1648,6 +1648,7 @@ inline void UpdateOptionsPopup(HMENU optionsPopup) CheckMenuItem(optionsPopup, ID_DEBUGGER_AUTO_OPEN, CheckedFlag(debuggerAutoload)); CheckMenuItem(optionsPopup, ID_DEBUGGER_IDA_FONT, CheckedFlag(debuggerIDAFont)); CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_ROM_OFFSETS, CheckedFlag(debuggerDisplayROMoffsets)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_BAD_OPCODES, CheckedFlag(FCEUI_Debugger().badopbreak)); } inline void UpdateSymbolsPopup(HMENU symbolsPopup) @@ -1944,6 +1945,9 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) debuggerDisplayROMoffsets ^= 1; UpdateDebugger(false); break; + case ID_DEBUGGER_BREAK_BAD_OPCODES: + FCEUI_Debugger().badopbreak ^= 1; + break; case ID_DEBUGGER_RESTORE_SIZE: RestoreSize(hwndDlg); break; @@ -2120,6 +2124,7 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) } break; } + // TODO: delete/merge with ID_DEBUGGER_BREAK_BAD_OPCODES case IDC_DEBUGGER_BREAK_ON_BAD_OP: //Break on bad opcode FCEUI_Debugger().badopbreak ^= 1; break; diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 4c0058378..18dd4bce2 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3049,6 +3049,8 @@ BEGIN MENUITEM "Auto Open on ROM Load", ID_DEBUGGER_AUTO_OPEN, CHECKED MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED + MENUITEM SEPARATOR + MENUITEM "Break on Bad Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED MENUITEM SEPARATOR MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE END diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 6680d9008..99a63bcd1 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1224,6 +1224,7 @@ #define ID_DUMPER_BROWSE 45550 #define ID_DUMPER_GO 45551 #define ID_DUMPER_NES_ADDR_TOGGLE 45552 +#define ID_DEBUGGER_BREAK_BAD_OPCODES 45553 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From 86d6c1bd463b153d82daf1807871ce296cfd2e24 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 28 Jun 2021 09:17:59 -0400 Subject: [PATCH 059/103] rename stuff and add comments --- src/drivers/win/debugger.cpp | 23 ++++++++++++----------- src/drivers/win/debugger.h | 2 +- src/drivers/win/debuggersp.cpp | 4 +++- src/drivers/win/debuggersp.h | 2 +- src/drivers/win/dumper.cpp | 2 +- src/drivers/win/taseditor/history.h | 2 +- src/drivers/win/tracer.cpp | 2 +- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index f25c9d7a0..56bba10dd 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -258,6 +258,7 @@ unsigned int AddBreak(HWND hwndDlg) // This function is for "smart" scrolling... // it attempts to scroll up one line by a whole instruction +// Should we add the label-respecting logic from dumper.cpp? int InstructionUp(int from) { int i = std::min(16, from), j; @@ -562,7 +563,7 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } -void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr) +void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) { wchar_t chr[40] = { 0 }; wchar_t debug_wbuf[2048] = { 0 }; @@ -903,7 +904,7 @@ void UpdateDebugger(bool jump_to_pc) { starting_address = InstructionUp(starting_address); } - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); // HACK, but I don't see any other way to ensure the ">" pointer is visible when "Symbolic debug" is enabled if (!PCPointerWasDrawn && PC_pointerOffset) @@ -912,14 +913,14 @@ void UpdateDebugger(bool jump_to_pc) PC_pointerOffset = 0; starting_address = X.PC; // retry with (PC_pointerOffset = 0) now - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); } starting_address = X.PC; } else { starting_address = disassembly_addresses[0]; - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); } @@ -1231,7 +1232,7 @@ BOOL CALLBACK DebuggerEnumWindowsProc(HWND hwnd, LPARAM lParam) crect.bottom += dy_l; SetWindowPos(hwnd, 0, 0, 0, crect.right - crect.left, crect.bottom - crect.top, SWP_NOZORDER | SWP_NOMOVE); GetScrollInfo(GetDlgItem(parent, IDC_DEBUGGER_DISASSEMBLY_VSCR), SB_CTL, &si); - Disassemble(parent, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); + DisassembleToWindow(parent, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); break; case IDC_DEBUGGER_DISASSEMBLY_LEFT_PANEL: // vertical stretch, no movement @@ -1664,10 +1665,10 @@ inline void UpdateSymbolsPopup(HMENU symbolsPopup) EnableMenuItem(symbolsPopup, ID_DEBUGGER_RELOAD_SYMBOLS, EnabledFlag(GameInfo)); } -inline void UpdateToolsPopup(HMENU symbolsPopup) +inline void UpdateToolsPopup(HMENU toolsPopup) { - EnableMenuItem(symbolsPopup, ID_DEBUGGER_ROM_PATCHER, EnabledFlag(GameInfo)); - EnableMenuItem(symbolsPopup, ID_DEBUGGER_CODE_DUMPER, EnabledFlag(GameInfo)); + EnableMenuItem(toolsPopup, ID_DEBUGGER_ROM_PATCHER, EnabledFlag(GameInfo)); + EnableMenuItem(toolsPopup, ID_DEBUGGER_CODE_DUMPER, EnabledFlag(GameInfo)); } void DebuggerInitDialog(HWND hwndDlg) @@ -2117,7 +2118,7 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) { sprintf(str,"%04X", tmp); SetDlgItemText(hwndDlg,IDC_DEBUGGER_VAL_PCSEEK,str); - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, tmp); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, tmp); // The address in the Add Bookmark textbox follows the scroll pos. sprintf(str,"%04X", si.nPos); SetDlgItemText(hDebug, IDC_DEBUGGER_BOOKMARK, str); @@ -2312,7 +2313,7 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd si.nPos = si.nMax - si.nPage; SetScrollInfo(hwndScrollBar, SB_CTL, &si, TRUE); - Disassemble(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); + DisassembleToWindow(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); // The address in the Add Bookmark textbox follows the scroll pos. char str[16]; sprintf(str,"%04X", si.nPos); @@ -2353,7 +2354,7 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso } // This function calls UpdateScrollInfo. Don't worry! - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); // The address in the Add Bookmark textbox follows the scroll pos. char str[16]; sprintf(str,"%04X", si.nPos); diff --git a/src/drivers/win/debugger.h b/src/drivers/win/debugger.h index a171642c5..07195a57f 100644 --- a/src/drivers/win/debugger.h +++ b/src/drivers/win/debugger.h @@ -38,7 +38,7 @@ extern char* BreakToText(unsigned int num); void UpdateDebugger(bool jump_to_pc = true); void DoDebug(uint8 halt); void DebuggerExit(); -void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr); +void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr); void PrintOffsetToSeekAndBookmarkFields(int offset); void LoadGameDebuggerData(HWND hwndDlg); diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index 438dd120d..f0ecf5cf9 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -640,6 +640,8 @@ void replaceRegNames(char* str) /** * Searches an address node in a list of address nodes. The found node * has the same offset as the passed parameter offs. +* +* Could speed this up with an actual data structure... * * @param node The address node list * @offs The offset to search @@ -917,7 +919,7 @@ void GoToDebuggerBookmark(HWND hwnd) // If no bookmark is selected just return if (selectedItem == LB_ERR) return; unsigned int n = getBookmarkAddress(selectedItem); - Disassemble(hwnd, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, n); + DisassembleToWindow(hwnd, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, n); } INT_PTR CALLBACK SymbolicNamingCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) diff --git a/src/drivers/win/debuggersp.h b/src/drivers/win/debuggersp.h index 50cf52f20..03a98e2b1 100644 --- a/src/drivers/win/debuggersp.h +++ b/src/drivers/win/debuggersp.h @@ -71,5 +71,5 @@ void AddNewSymbolicName(uint16 newAddress, char* newOffset, char* newName, char* void DeleteSymbolicName(uint16 address, int size); void WriteNameFileToDisk(const char* filename, Name* node); -extern void Disassemble(HWND hWnd, int id, int scrollid, unsigned int addr); +extern void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr); extern void CenterWindow(HWND hwnd); \ No newline at end of file diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index dc0579468..86aad87b0 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -51,7 +51,7 @@ static OPENFILENAME ofn; * A9 10 LDA #$10 * 60 RTS * -* There is a lot of reused logic between this and Disassemble. However, they're different enough that it would +* There is a lot of reused logic between this and DisassembleToWindow. However, they're different enough that it would * be more trouble than it's worth to combine them. */ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) diff --git a/src/drivers/win/taseditor/history.h b/src/drivers/win/taseditor/history.h index 59d83c5ca..7cebe520d 100644 --- a/src/drivers/win/taseditor/history.h +++ b/src/drivers/win/taseditor/history.h @@ -108,7 +108,7 @@ class HISTORY int registerChanges(int mod_type, int start = 0, int end =-1, int size = 0, const char* comment = NULL, int consecutivenessTag = 0, RowsSelection* frameset = NULL); int registerAdjustLag(int start, int size); void registerMarkersChange(int modificationType, int start = 0, int end =-1, const char* comment = 0); - void registerBookmarkSet(int slot, BOOKMARK& backupÑopy, int oldCurrentBranch); + void registerBookmarkSet(int slot, BOOKMARK& backupCopy, int oldCurrentBranch); int registerBranching(int slot, bool markersWereChanged); void registerRecording(int frameOfChange, uint32 joypadDifferenceBits); int registerImport(MovieData& md, char* filename); diff --git a/src/drivers/win/tracer.cpp b/src/drivers/win/tracer.cpp index 661dac2c3..9e4a2aa2e 100644 --- a/src/drivers/win/tracer.cpp +++ b/src/drivers/win/tracer.cpp @@ -244,7 +244,7 @@ BOOL CALLBACK IDC_TRACER_LOG_WndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA DoDebug(0); if (hDebug) { - Disassemble(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, offset); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, offset); PrintOffsetToSeekAndBookmarkFields(offset); } } From 2b0e483a72acf250d14f9c5fa6ee3c7f0ee6780c Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 29 Jun 2021 07:24:50 -0400 Subject: [PATCH 060/103] obfuscate callback return type so it compiles on 64-bit machines --- src/drivers/win/dumper.cpp | 2 +- src/drivers/win/dumper.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index 86aad87b0..9529ce3d6 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -336,7 +336,7 @@ bool DumperBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) return false; } -BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { diff --git a/src/drivers/win/dumper.h b/src/drivers/win/dumper.h index a60c12c06..0eedaa7e0 100644 --- a/src/drivers/win/dumper.h +++ b/src/drivers/win/dumper.h @@ -2,4 +2,4 @@ #include -BOOL CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK DumperCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); From 4e0f034891abafd57a8dcc5bb87008ebd9371ac2 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 29 Jun 2021 07:37:04 -0400 Subject: [PATCH 061/103] janky merge conflict dodge --- src/drivers/win/res.rc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 18dd4bce2..44289b613 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -2339,6 +2339,11 @@ BEGIN 0 END +ARCHIVECHOOSERDIALOG AFX_DIALOG_LAYOUT +BEGIN + 0 +END + CODEDUMPER AFX_DIALOG_LAYOUT BEGIN 0 From d55e8ecc8f58f8b97895b15828928d826403edd7 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 29 Jun 2021 07:59:52 -0400 Subject: [PATCH 062/103] show a blank screen when no game is loaded --- src/drivers/win/debugger.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 56bba10dd..541c24246 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -885,6 +885,12 @@ void UpdateDebugger(bool jump_to_pc) ShowWindow(hDebug, SW_SHOWNORMAL); SetForegroundWindow(hDebug); + if (!GameInfo) + { + SetDlgItemText(hDebug, IDC_DEBUGGER_DISASSEMBLY, ""); + return; + } + char str[512] = {0}, str2[512] = {0}, chr[8]; int tmp, ret, i, starting_address; @@ -2235,10 +2241,6 @@ void DebuggerMoveWindow(HWND hwndDlg, uint16 x, uint16 y) void DebuggerWindowActivate(HWND hwndDlg, uint16 eventType, HWND hwndActivated) { - // None of these events can be processed without a game loaded. - if (!GameInfo) - return; - // Prevents numerous situations where the debugger is out of sync with the data if (eventType != WA_INACTIVE) { @@ -2246,7 +2248,7 @@ void DebuggerWindowActivate(HWND hwndDlg, uint16 eventType, HWND hwndActivated) } else { - if (FCEUI_EmulationPaused()) + if (GameInfo && FCEUI_EmulationPaused()) UpdateRegs(hwndDlg); } } From e2cb9dae39b09bb36b46f66d0bd489d5191de37d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 29 Jun 2021 08:12:24 -0400 Subject: [PATCH 063/103] fix '>' in comments highlighting like the PC --- src/drivers/win/debugger.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 541c24246..3350f138d 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -449,12 +449,22 @@ void HighlightPC(HWND hWnd) return; FINDTEXT ft; - ft.lpstrText = ">"; + ft.lpstrText = "\r"; ft.chrg.cpMin = 0; ft.chrg.cpMax = -1; - int start = SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&ft); + + int start = 0; + + for (int i = 0; i < PCLine; i++) + { + // Scroll down to PCLine by looking for newlines + start = SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&ft) + 1; + ft.chrg.cpMin = start; + } + if (start >= 0) { + // Highlight PC int old_start, old_end; SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_GETSEL, (WPARAM)&old_start, (LPARAM)&old_end); SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)start, (LPARAM)start+20); @@ -591,7 +601,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) debug_wstr[0] = 0; PCLine = -1; - unsigned int instructions_count = 0; + unsigned int line_count = 0; for (int i = 0; i < lines; i++) { // PC pointer @@ -612,6 +622,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) // we added one line to the disassembly window disassembly_addresses.push_back(addr); disassembly_operands.resize(i + 1); + line_count++; i++; } if (node->comment) @@ -636,6 +647,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) debug_decoration_comment_end_pos += 2; debug_decoration_comment = debug_decoration_comment_end_pos; debug_decoration_comment_end_pos = strstr(debug_decoration_comment_end_pos, "\r\n"); + line_count++; } } } @@ -643,11 +655,11 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) if (addr == X.PC) { - PC_pointerOffset = instructions_count; + PC_pointerOffset = line_count; PCPointerWasDrawn = true; beginningOfPCPointerLine = wcslen(debug_wstr); wcscat(debug_wstr, L">"); - PCLine = instructions_count; + PCLine = line_count; } else { wcscat(debug_wstr, L" "); @@ -731,7 +743,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) wcscat(debug_wstr, debug_wbuf); } wcscat(debug_wstr, L"\n"); - instructions_count++; + line_count++; } UpdateDisassembleView(hWnd, id, lines, true); @@ -905,6 +917,8 @@ void UpdateDebugger(bool jump_to_pc) if (PC_pointerOffset >= lines) PC_pointerOffset = 0; + // PC_PointerOffset now indicates number of visible lines, which totally breaks this and that "HACK" below. + // Might need to change InstructionUp. // keep the relative position of the ">" pointer inside the Disassembly window for (int i = PC_pointerOffset; i > 0; i--) { From 4370400c596711ddca1b180655638d2062168009 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 30 Jun 2021 05:14:47 -0400 Subject: [PATCH 064/103] initial attempt at making scrolling comment-sensitive It's a little awkward because I'm trying too hard to be clever. I just need to have ScrollDown check the name node data and set skiplines as appropriate. --- src/drivers/win/debugger.cpp | 105 +++++++++++++++++++++++++-------- src/drivers/win/debugger.h | 2 +- src/drivers/win/debuggersp.cpp | 1 + src/drivers/win/debuggersp.h | 1 - 4 files changed, 81 insertions(+), 28 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 3350f138d..6860d3217 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -134,6 +134,7 @@ int PCLine = -1; bool PCPointerWasDrawn = false; // and another hack... int beginningOfPCPointerLine = -1; // index of the first char within debug_str[] string, where the ">" line starts +static int skipLinesStatic = 0; #define INVALID_START_OFFSET 1 #define INVALID_END_OFFSET 2 @@ -288,6 +289,28 @@ int InstructionUp(int from) return (from - 1); // else, scroll up one byte return 0; // of course, if we can't scroll up, just return 0! } + +// This all works great if each scrollup call is accompanied by a disassembletowindow call. +// Realistically, I just need to make this function get the nodes and set things in a sane way. +int ScrollUp(int from) +{ + if (skipLinesStatic) + { + skipLinesStatic--; + return from; + } + + skipLinesStatic = -1; + return InstructionUp(from); +} + +// Can probably get rid of the parameters and let the static vars do the talking +int ScrollDown(int from) +{ + skipLinesStatic++; + return from; +} + int InstructionDown(int from) { int tmp = opsize[GetMem(si.nPos)]; @@ -573,8 +596,9 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } -void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) +void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int skiplines) { + // Why is this getting called twice per scroll? wchar_t chr[40] = { 0 }; wchar_t debug_wbuf[2048] = { 0 }; int size; @@ -617,13 +641,20 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) { if (node->name) { - swprintf(debug_wbuf, L"%S:\n", node->name); - wcscat(debug_wstr, debug_wbuf); - // we added one line to the disassembly window - disassembly_addresses.push_back(addr); - disassembly_operands.resize(i + 1); - line_count++; - i++; + if (skiplines == 0) + { + swprintf(debug_wbuf, L"%S:\n", node->name); + wcscat(debug_wstr, debug_wbuf); + // we added one line to the disassembly window + disassembly_addresses.push_back(addr); + disassembly_operands.resize(i + 1); + line_count++; + i++; + } + else + { + skiplines--; + } } if (node->comment) { @@ -637,20 +668,42 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr) { debug_decoration_comment_end_pos[0] = 0; // set \0 instead of \r debug_decoration_comment_end_pos[1] = 0; // set \0 instead of \n - swprintf(debug_wbuf, L"; %S\n", debug_decoration_comment); - wcscat(debug_wstr, debug_wbuf); - // we added one line to the disassembly window - disassembly_addresses.push_back(addr); - disassembly_operands.resize(i + 1); - i++; + if (skiplines == 0) + { + swprintf(debug_wbuf, L"; %S\n", debug_decoration_comment); + wcscat(debug_wstr, debug_wbuf); + // we added one line to the disassembly window + disassembly_addresses.push_back(addr); + disassembly_operands.resize(i + 1); + i++; + line_count++; + } + else + { + skiplines--; + } debug_decoration_comment_end_pos += 2; debug_decoration_comment = debug_decoration_comment_end_pos; debug_decoration_comment_end_pos = strstr(debug_decoration_comment_end_pos, "\r\n"); - line_count++; } } } + if (skiplines > 0) + { + // We were told to skip more comment/name lines than exist. + skipLinesStatic = skiplines = 0; + si.nPos = addr = InstructionDown(addr); + SetScrollInfo(GetDlgItem(hWnd, scrollid), SB_CTL, &si, TRUE); + continue; + } + if (skiplines < 0) + { + // Negative skiplines means it just kept going so this is our count + skipLinesStatic = -skiplines - 1; + skiplines = 0; + printf("Janky negative skiplines: %d\n", skipLinesStatic); + } } if (addr == X.PC) @@ -922,9 +975,9 @@ void UpdateDebugger(bool jump_to_pc) // keep the relative position of the ">" pointer inside the Disassembly window for (int i = PC_pointerOffset; i > 0; i--) { - starting_address = InstructionUp(starting_address); + starting_address = ScrollUp(starting_address); } - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address, skipLinesStatic); // HACK, but I don't see any other way to ensure the ">" pointer is visible when "Symbolic debug" is enabled if (!PCPointerWasDrawn && PC_pointerOffset) @@ -940,7 +993,7 @@ void UpdateDebugger(bool jump_to_pc) } else { starting_address = disassembly_addresses[0]; - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address, skipLinesStatic); } @@ -2286,19 +2339,19 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd case SB_BOTTOM: break; case SB_LINEUP: { - si.nPos = InstructionUp(si.nPos); + si.nPos = ScrollUp(si.nPos); break; } case SB_LINEDOWN: { - si.nPos = InstructionDown(si.nPos); + si.nPos = ScrollDown(si.nPos); break; } case SB_PAGEUP: { for (int i = si.nPage; i > 0; i--) { - si.nPos = InstructionUp(si.nPos); + si.nPos = ScrollUp(si.nPos); if (si.nPos < si.nMin) { si.nPos = si.nMin; @@ -2311,7 +2364,7 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd { for (int i = si.nPage; i > 0; i--) { - si.nPos = InstructionDown(si.nPos); + si.nPos = ScrollDown(si.nPos); if ((si.nPos + (int)si.nPage) > si.nMax) { si.nPos = si.nMax - si.nPage; @@ -2329,7 +2382,7 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd si.nPos = si.nMax - si.nPage; SetScrollInfo(hwndScrollBar, SB_CTL, &si, TRUE); - DisassembleToWindow(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); + DisassembleToWindow(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos, skipLinesStatic); // The address in the Add Bookmark textbox follows the scroll pos. char str[16]; sprintf(str,"%04X", si.nPos); @@ -2349,7 +2402,7 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso { for (i *= -(int)si.nPage; i > 0; i--) { - si.nPos = InstructionDown(si.nPos); + si.nPos = ScrollDown(si.nPos); if ((si.nPos + (int)si.nPage) > si.nMax) { si.nPos = si.nMax - si.nPage; @@ -2360,7 +2413,7 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso { for (i *= si.nPage; i > 0; i--) { - si.nPos = InstructionUp(si.nPos); + si.nPos = ScrollUp(si.nPos); if (si.nPos < si.nMin) { si.nPos = si.nMin; @@ -2370,7 +2423,7 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso } // This function calls UpdateScrollInfo. Don't worry! - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos, skipLinesStatic); // The address in the Add Bookmark textbox follows the scroll pos. char str[16]; sprintf(str,"%04X", si.nPos); diff --git a/src/drivers/win/debugger.h b/src/drivers/win/debugger.h index 07195a57f..31fb69bc5 100644 --- a/src/drivers/win/debugger.h +++ b/src/drivers/win/debugger.h @@ -38,7 +38,7 @@ extern char* BreakToText(unsigned int num); void UpdateDebugger(bool jump_to_pc = true); void DoDebug(uint8 halt); void DebuggerExit(); -void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr); +void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int skiplines = 0); void PrintOffsetToSeekAndBookmarkFields(int offset); void LoadGameDebuggerData(HWND hwndDlg); diff --git a/src/drivers/win/debuggersp.cpp b/src/drivers/win/debuggersp.cpp index f0ecf5cf9..e7936def1 100644 --- a/src/drivers/win/debuggersp.cpp +++ b/src/drivers/win/debuggersp.cpp @@ -21,6 +21,7 @@ #include "common.h" #include "utils/xstring.h" #include "debuggersp.h" +#include "debugger.h" #include "../../fceu.h" #include "../../debug.h" #include "../../conddebug.h" diff --git a/src/drivers/win/debuggersp.h b/src/drivers/win/debuggersp.h index 03a98e2b1..860ae3ffd 100644 --- a/src/drivers/win/debuggersp.h +++ b/src/drivers/win/debuggersp.h @@ -71,5 +71,4 @@ void AddNewSymbolicName(uint16 newAddress, char* newOffset, char* newName, char* void DeleteSymbolicName(uint16 address, int size); void WriteNameFileToDisk(const char* filename, Name* node); -extern void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr); extern void CenterWindow(HWND hwnd); \ No newline at end of file From 8afeb345395e8349aa0c55ccd11527318effba8e Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 30 Jun 2021 07:03:54 -0400 Subject: [PATCH 065/103] make scrolling comment-sensitive (for real) This has the added benefits that PC relative positioning works right, and there is no longer a need for that HACK that ensures the PC is visible when you jump to it. --- src/drivers/win/debugger.cpp | 120 +++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 47 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 6860d3217..d23bee544 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -130,9 +130,7 @@ std::vector> disassembly_operands; // this is used to autoscroll the Disassembly window while keeping relative position of the ">" pointer inside this window unsigned int PC_pointerOffset = 0; int PCLine = -1; -// this is used for dirty, but unavoidable hack, which is necessary to ensure the ">" pointer is visible when stepping/seeking to PC -bool PCPointerWasDrawn = false; -// and another hack... +// hack to help syntax highlighting find the PC int beginningOfPCPointerLine = -1; // index of the first char within debug_str[] string, where the ">" line starts static int skipLinesStatic = 0; @@ -257,8 +255,33 @@ unsigned int AddBreak(HWND hwndDlg) return 0; } -// This function is for "smart" scrolling... -// it attempts to scroll up one line by a whole instruction +// Tells you how many lines the comments and label name take for a given address. +// Used for smoothly scrolling through comments. +static int NumAnnotationLines(int addr) +{ + if (symbDebugEnabled) + { + Name* node = findNode(getNamesPointerForAddress(addr), addr); + if (node) + { + int count = 0; + + if (node->name) + count++; + + char* str = node->comment; + for (; str; count++) + str = strstr(str + 1, "\n"); + + return count; + } + } + + return 0; +} + +// This function is for "smart" scrolling. +// It attempts to scroll up by a whole instruction heuristically. // Should we add the label-respecting logic from dumper.cpp? int InstructionUp(int from) { @@ -290,8 +313,17 @@ int InstructionUp(int from) return 0; // of course, if we can't scroll up, just return 0! } -// This all works great if each scrollup call is accompanied by a disassembletowindow call. -// Realistically, I just need to make this function get the nodes and set things in a sane way. +int InstructionDown(int from) +{ + int tmp = opsize[GetMem(si.nPos)]; + if ((tmp)) + return from + tmp; + else + return from + 1; // this is data or undefined instruction +} + +// Scroll up one visible line, respecting comments and labels. +// skipLinesStatic will eventually tell the DisassembleToWindow function how many comment lines to skip. int ScrollUp(int from) { if (skipLinesStatic) @@ -300,24 +332,25 @@ int ScrollUp(int from) return from; } - skipLinesStatic = -1; - return InstructionUp(from); + int addr = InstructionUp(from); + skipLinesStatic = NumAnnotationLines(addr); + return addr; } // Can probably get rid of the parameters and let the static vars do the talking int ScrollDown(int from) { - skipLinesStatic++; - return from; -} - -int InstructionDown(int from) -{ - int tmp = opsize[GetMem(si.nPos)]; - if ((tmp)) - return from + tmp; + // TODO: Store this annotationLines info so we can stop recomputing it! + if (skipLinesStatic == NumAnnotationLines(from)) + { + skipLinesStatic = 0; + return InstructionDown(from); + } else - return from + 1; // this is data or undefined instruction + { + skipLinesStatic++; + return from; + } } static void UpdateDialog(HWND hwndDlg) { @@ -596,6 +629,19 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } +/** +* Starting at addr, disassembles code to the debugger window. The number of lines is automatically determined +* by the window size. id and scrollid tell the function which dialog items to modify, although a hardcoded ID +* is mixed in, so, eh. +* skiplines is used so that large comments can appear/disappear line by line, as you would expect in a text file, +* rather than jumping in all at once. +* +* @param hWnd Handle to the debugger window +* @param id id of the disassembly textbox +* @param scrollid id of the scrollbar +* @param addr starting address for disassembly +* @param skiplines how many comment/label lines to skip, used for smooth scrolling (default 0) +*/ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int skiplines) { // Why is this getting called twice per scroll? @@ -606,7 +652,6 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int unsigned int instruction_addr; disassembly_addresses.resize(0); - PCPointerWasDrawn = false; beginningOfPCPointerLine = -1; if (symbDebugEnabled) @@ -615,6 +660,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int disassembly_operands.resize(0); } + skipLinesStatic = skiplines; si.nPos = addr; SetScrollInfo(GetDlgItem(hWnd,scrollid),SB_CTL,&si,TRUE); @@ -689,27 +735,18 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int } } } - if (skiplines > 0) + if (skiplines) { // We were told to skip more comment/name lines than exist. - skipLinesStatic = skiplines = 0; - si.nPos = addr = InstructionDown(addr); - SetScrollInfo(GetDlgItem(hWnd, scrollid), SB_CTL, &si, TRUE); - continue; - } - if (skiplines < 0) - { - // Negative skiplines means it just kept going so this is our count - skipLinesStatic = -skiplines - 1; + skipLinesStatic -= skiplines; skiplines = 0; - printf("Janky negative skiplines: %d\n", skipLinesStatic); + continue; } } if (addr == X.PC) { PC_pointerOffset = line_count; - PCPointerWasDrawn = true; beginningOfPCPointerLine = wcslen(debug_wstr); wcscat(debug_wstr, L">"); PCLine = line_count; @@ -961,7 +998,9 @@ void UpdateDebugger(bool jump_to_pc) if (jump_to_pc || disassembly_addresses.size() == 0) { + // For relative positioning, we want start pos to be PC address with the comments scrolled offscreen. starting_address = X.PC; + skipLinesStatic = NumAnnotationLines(starting_address); // ensure that PC pointer will be visible even after the window was resized RECT rect; @@ -970,27 +1009,14 @@ void UpdateDebugger(bool jump_to_pc) if (PC_pointerOffset >= lines) PC_pointerOffset = 0; - // PC_PointerOffset now indicates number of visible lines, which totally breaks this and that "HACK" below. - // Might need to change InstructionUp. // keep the relative position of the ">" pointer inside the Disassembly window for (int i = PC_pointerOffset; i > 0; i--) { starting_address = ScrollUp(starting_address); } DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address, skipLinesStatic); - - // HACK, but I don't see any other way to ensure the ">" pointer is visible when "Symbolic debug" is enabled - if (!PCPointerWasDrawn && PC_pointerOffset) - { - // we've got a problem, probably due to Symbolic info taking so much space that PC pointer couldn't be seen with (PC_pointerOffset > 0) - PC_pointerOffset = 0; - starting_address = X.PC; - // retry with (PC_pointerOffset = 0) now - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address); - } - - starting_address = X.PC; - } else + } + else { starting_address = disassembly_addresses[0]; DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address, skipLinesStatic); From aa2c6aef92f313e85216595b1296252f5d20d433 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 30 Jun 2021 07:09:17 -0400 Subject: [PATCH 066/103] combine PCLine and PC_pointerOffset Both of them represented the same information. --- src/drivers/win/debugger.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index d23bee544..e0c28e4c8 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -128,8 +128,7 @@ std::vector disassembly_addresses; // this is used to keep track of addresses in operands of each printed instruction std::vector> disassembly_operands; // this is used to autoscroll the Disassembly window while keeping relative position of the ">" pointer inside this window -unsigned int PC_pointerOffset = 0; -int PCLine = -1; +unsigned int PCLine = -1; // hack to help syntax highlighting find the PC int beginningOfPCPointerLine = -1; // index of the first char within debug_str[] string, where the ">" line starts static int skipLinesStatic = 0; @@ -746,10 +745,9 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int if (addr == X.PC) { - PC_pointerOffset = line_count; + PCLine = line_count; beginningOfPCPointerLine = wcslen(debug_wstr); wcscat(debug_wstr, L">"); - PCLine = line_count; } else { wcscat(debug_wstr, L" "); @@ -1006,11 +1004,11 @@ void UpdateDebugger(bool jump_to_pc) RECT rect; GetClientRect(GetDlgItem(hDebug, IDC_DEBUGGER_DISASSEMBLY), &rect); unsigned int lines = (rect.bottom-rect.top) / debugSystem->disasmFontHeight; - if (PC_pointerOffset >= lines) - PC_pointerOffset = 0; + if (PCLine >= lines) + PCLine = 0; // keep the relative position of the ">" pointer inside the Disassembly window - for (int i = PC_pointerOffset; i > 0; i--) + for (int i = PCLine; i > 0; i--) { starting_address = ScrollUp(starting_address); } From 7c5f08ff80c7cf6bf90ab3731f0536cbced419f4 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 4 Jul 2021 08:43:51 -0400 Subject: [PATCH 067/103] remove the unused permanent buttons --- src/drivers/win/debugger.cpp | 76 ------------------------------------ src/drivers/win/memview.cpp | 2 - src/drivers/win/res.rc | 31 +++++---------- src/drivers/win/resource.h | 10 ----- 4 files changed, 10 insertions(+), 109 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index e0c28e4c8..df61993d9 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1379,7 +1379,6 @@ BOOL CALLBACK DebuggerEnumWindowsProc(HWND hwnd, LPARAM lParam) case IDC_DEBUGGER_BP_ADD: case IDC_DEBUGGER_BP_DEL: case IDC_DEBUGGER_BP_EDIT: - case IDC_DEBUGGER_BREAK_ON_BAD_OP: case IDC_DEBUGGER_STATUSFLAGS: case IDC_DEBUGGER_FLAG_N: case IDC_DEBUGGER_FLAG_V: @@ -1418,20 +1417,6 @@ BOOL CALLBACK DebuggerEnumWindowsProc(HWND hwnd, LPARAM lParam) crect.left += dx; SetWindowPos(hwnd, 0, crect.left, crect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); break; - case IDC_DEBUGGER_VAL_S3: - case IDC_DEBUGGER_ROM_OFFSETS: - case IDC_DEBUGGER_ENABLE_SYMBOLIC: - case IDC_DEBUGGER_PREDEFINED_REGS: - case IDC_DEBUGGER_RELOAD_SYMS: - case IDC_DEBUGGER_ROM_PATCHER: - case DEBUGAUTOLOAD: - case DEBUGLOADDEB: - case DEBUGIDAFONT: - // no stretch, move up and down full length, move left and right full length - crect.top += dy_r; - crect.left += dx; - SetWindowPos(hwnd, 0, crect.left, crect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - break; case IDC_DEBUGGER_ADDR_LINE: // horizontal stretch, move up and down full length crect.top += dy_l; @@ -1621,7 +1606,6 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w if (!symbDebugEnabled) { symbDebugEnabled = true; - CheckDlgButton(hDebug, IDC_DEBUGGER_ENABLE_SYMBOLIC, BST_CHECKED); } UpdateDebugger(false); } else @@ -1778,15 +1762,6 @@ void DebuggerInitDialog(HWND hwndDlg) sprintf(str, "%u", (unsigned)break_instructions_limit); SetDlgItemText(hwndDlg, IDC_DEBUGGER_INSTRUCTIONS_EXCEED, str); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_BAD_OP, FCEUI_Debugger().badopbreak ? BST_CHECKED : BST_UNCHECKED); - - CheckDlgButton(hwndDlg, DEBUGLOADDEB, debuggerSaveLoadDEBFiles ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, DEBUGIDAFONT, debuggerIDAFont ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, DEBUGAUTOLOAD, debuggerAutoload ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_ROM_OFFSETS, debuggerDisplayROMoffsets ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_ENABLE_SYMBOLIC, symbDebugEnabled ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_DEBUGGER_PREDEFINED_REGS, symbRegNames ? BST_CHECKED : BST_UNCHECKED); - if (DbgPosX==-32000) DbgPosX=0; //Just in case if (DbgPosY==-32000) DbgPosY=0; SetWindowPos(hwndDlg,0,DbgPosX,DbgPosY,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER); @@ -1976,19 +1951,6 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) // Buttons that don't need a rom loaded to do something, such as autoload switch (btnId) { - case DEBUGAUTOLOAD: // TODO: delete/merge with ID_DEBUGGER_AUTO_OPEN - debuggerAutoload ^= 1; - break; - case DEBUGLOADDEB: // TODO: delete/merge with ID_DEBUGGER_LOAD_DEB_FILE - debuggerSaveLoadDEBFiles = !debuggerSaveLoadDEBFiles; - break; - case DEBUGIDAFONT: // TODO: delete/merge with ID_DEBUGGER_IDA_FONT - debuggerIDAFont ^= 1; - debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont; - debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight; - SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); - UpdateDebugger(false); - break; case ID_DEBUGGER_DEFCOLOR: { if (!IsDebugColorDefault() && MessageBox(hwndDlg, "Do you want to restore all the colors to default?", "Restore default colors", MB_YESNO | MB_ICONINFORMATION) == IDYES) @@ -2028,7 +1990,6 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) } break; // Options menu - // TODO: Reuse/merge with the old IDs from the persistent buttons. case ID_DEBUGGER_AUTO_OPEN: debuggerAutoload ^= 1; break; @@ -2222,10 +2183,6 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) } break; } - // TODO: delete/merge with ID_DEBUGGER_BREAK_BAD_OPCODES - case IDC_DEBUGGER_BREAK_ON_BAD_OP: //Break on bad opcode - FCEUI_Debugger().badopbreak ^= 1; - break; case IDC_DEBUGGER_FLAG_N: X.P^=N_FLAG; UpdateDebugger(false); break; case IDC_DEBUGGER_FLAG_V: X.P^=V_FLAG; UpdateDebugger(false); break; case IDC_DEBUGGER_FLAG_U: X.P^=U_FLAG; UpdateDebugger(false); break; @@ -2253,42 +2210,9 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) CheckDlgButton(hwndDlg, IDC_DEBUGGER_BREAK_ON_INSTRUCTIONS, break_on_instructions); break; } - case IDC_DEBUGGER_RELOAD_SYMS: - { // TODO: delete/merge with ID_DEBUGGER_RELOAD_SYMBOLS - ramBankNamesLoaded = false; - for(int i=0;i Date: Mon, 5 Jul 2021 03:56:26 -0400 Subject: [PATCH 068/103] remove SP CODE comments The time where these meant anything to anyone has long past. --- src/drivers/win/debugger.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index df61993d9..7243eea11 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -403,8 +403,6 @@ INT_PTR CALLBACK AddbpCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara else CheckDlgButton(hwndDlg, IDC_ADDBP_MEM_CPU, BST_CHECKED); UpdateDialog(hwndDlg); - -// ################################## Start of SP CODE ########################### SendDlgItemMessage(hwndDlg,IDC_ADDBP_CONDITION,EM_SETLIMITTEXT,200,0); SendDlgItemMessage(hwndDlg,IDC_ADDBP_NAME,EM_SETLIMITTEXT,200,0); @@ -426,8 +424,6 @@ INT_PTR CALLBACK AddbpCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara { SetDlgItemText(hwndDlg, IDC_ADDBP_NAME, ""); } - -// ################################## End of SP CODE ########################### } else { CheckDlgButton(hwndDlg, IDC_ADDBP_MEM_CPU, BST_CHECKED); @@ -1233,11 +1229,9 @@ void DeleteBreak(int sel) watchpoint[i].address = watchpoint[i+1].address; watchpoint[i].endaddress = watchpoint[i+1].endaddress; watchpoint[i].flags = watchpoint[i+1].flags; -// ################################## Start of SP CODE ########################### watchpoint[i].cond = watchpoint[i+1].cond; watchpoint[i].condText = watchpoint[i+1].condText; watchpoint[i].desc = watchpoint[i+1].desc; -// ################################## End of SP CODE ########################### } // erase last BP item watchpoint[numWPs].address = 0; @@ -1247,9 +1241,7 @@ void DeleteBreak(int sel) watchpoint[numWPs].condText = 0; watchpoint[numWPs].desc = 0; numWPs--; -// ################################## Start of SP CODE ########################### myNumWPs--; -// ################################## End of SP CODE ########################### SendDlgItemMessage(hDebug,IDC_DEBUGGER_BP_LIST,LB_DELETESTRING,sel,0); // select next item in the list if (numWPs) @@ -1804,15 +1796,11 @@ void DebuggerInitDialog(HWND hwndDlg) SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_PPU,EM_SETREADONLY,TRUE,0); SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_VAL_SPR,EM_SETREADONLY,TRUE,0); -// ################################## Start of SP CODE ########################### - SendDlgItemMessage(hwndDlg,IDC_DEBUGGER_BOOKMARK,EM_SETLIMITTEXT,4,0); LoadGameDebuggerData(hwndDlg); debuggerWasActive = 1; - -// ################################## End of SP CODE ########################### // Enable Context Sub-Menus hDebugcontext = LoadMenu(fceu_hInstance,"DEBUGCONTEXTMENUS"); @@ -2098,7 +2086,6 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) FCEUI_Debugger().step = true; FCEUI_SetEmulationPaused(0); UpdateOtherDebuggingDialogs(); - break; case IDC_DEBUGGER_RUN_LINE: if (FCEUI_EmulationPaused()) From d143c69bd6d787980c128a83fb2c6d88c8ed5c70 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 7 Jul 2021 04:04:12 -0400 Subject: [PATCH 069/103] refactor the comment offset stuff into methods that deal with it for you --- src/drivers/win/debugger.cpp | 136 ++++++++++++++++++++--------------- src/drivers/win/debugger.h | 1 + 2 files changed, 81 insertions(+), 56 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 7243eea11..2d9eafb4f 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -131,7 +131,10 @@ std::vector> disassembly_operands; unsigned int PCLine = -1; // hack to help syntax highlighting find the PC int beginningOfPCPointerLine = -1; // index of the first char within debug_str[] string, where the ">" line starts -static int skipLinesStatic = 0; + +static int scrollAddress; +static int commentOffset = 0; // rename to commentOffset +static int linesPerComment; // Update in ScrollUp and ScrollDown when the address changes? How does that work with a hard jump? #define INVALID_START_OFFSET 1 #define INVALID_END_OFFSET 2 @@ -254,6 +257,12 @@ unsigned int AddBreak(HWND hwndDlg) return 0; } +typedef struct +{ + int address; + int commentOffset; +} AddrScrollInfo; + // Tells you how many lines the comments and label name take for a given address. // Used for smoothly scrolling through comments. static int NumAnnotationLines(int addr) @@ -321,35 +330,38 @@ int InstructionDown(int from) return from + 1; // this is data or undefined instruction } +// Updates the scroll address and comment offset, and sends that info to the debugger window. +// TODO: Make this extern? DebuggerSetScroll or similar. +inline void SetScroll(int addr, int offset) +{ + scrollAddress = addr; + commentOffset = offset; + si.nPos = addr; + SetScrollInfo(GetDlgItem(hDebug, IDC_DEBUGGER_DISASSEMBLY_VSCR), SB_CTL, &si, TRUE); +} + // Scroll up one visible line, respecting comments and labels. -// skipLinesStatic will eventually tell the DisassembleToWindow function how many comment lines to skip. -int ScrollUp(int from) +// commentOffset will eventually tell the DisassembleToWindow function how many comment lines to skip. +AddrScrollInfo ScrollUp() { - if (skipLinesStatic) - { - skipLinesStatic--; - return from; - } + if (commentOffset) + SetScroll(scrollAddress, --commentOffset); + else + SetScroll(scrollAddress = InstructionUp(scrollAddress), NumAnnotationLines(scrollAddress)); - int addr = InstructionUp(from); - skipLinesStatic = NumAnnotationLines(addr); - return addr; + return {scrollAddress, commentOffset}; } -// Can probably get rid of the parameters and let the static vars do the talking -int ScrollDown(int from) + +AddrScrollInfo ScrollDown() { // TODO: Store this annotationLines info so we can stop recomputing it! - if (skipLinesStatic == NumAnnotationLines(from)) - { - skipLinesStatic = 0; - return InstructionDown(from); - } + if (commentOffset >= NumAnnotationLines(scrollAddress)) + SetScroll(InstructionDown(scrollAddress), 0); else - { - skipLinesStatic++; - return from; - } + SetScroll(scrollAddress, ++commentOffset); + + return {scrollAddress, commentOffset}; } static void UpdateDialog(HWND hwndDlg) { @@ -625,19 +637,10 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) } /** -* Starting at addr, disassembles code to the debugger window. The number of lines is automatically determined -* by the window size. id and scrollid tell the function which dialog items to modify, although a hardcoded ID -* is mixed in, so, eh. -* skiplines is used so that large comments can appear/disappear line by line, as you would expect in a text file, -* rather than jumping in all at once. -* -* @param hWnd Handle to the debugger window -* @param id id of the disassembly textbox -* @param scrollid id of the scrollbar -* @param addr starting address for disassembly -* @param skiplines how many comment/label lines to skip, used for smooth scrolling (default 0) +* Disassembles to the debugger window using the existing address scroll info. +* Assumes that either SetScroll or the overload that takes address and offset was called. */ -void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int skiplines) +void DisassembleToWindow(HWND hWnd, int id, int scrollid) { // Why is this getting called twice per scroll? wchar_t chr[40] = { 0 }; @@ -645,6 +648,8 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int int size; uint8 opcode[3]; unsigned int instruction_addr; + unsigned int addr = scrollAddress; + int skiplines = commentOffset; disassembly_addresses.resize(0); beginningOfPCPointerLine = -1; @@ -655,10 +660,6 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int disassembly_operands.resize(0); } - skipLinesStatic = skiplines; - si.nPos = addr; - SetScrollInfo(GetDlgItem(hWnd,scrollid),SB_CTL,&si,TRUE); - //figure out how many lines we can draw RECT rect; GetClientRect(GetDlgItem(hWnd, id), &rect); @@ -733,9 +734,8 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int if (skiplines) { // We were told to skip more comment/name lines than exist. - skipLinesStatic -= skiplines; + commentOffset -= skiplines; skiplines = 0; - continue; } } @@ -859,6 +859,26 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int } SetDlgItemText(hWnd, IDC_DEBUGGER_DISASSEMBLY_LEFT_PANEL, debug_cdl_str); } + +/** +* Starting at addr, disassembles code to the debugger window. The number of lines is automatically determined +* by the window size. id and scrollid tell the function which dialog items to modify, although a hardcoded ID +* is mixed in, so, eh. +* skiplines is used so that large comments can appear/disappear line by line, as you would expect in a text file, +* rather than jumping in all at once. +* +* @param hWnd Handle to the debugger window +* @param id id of the disassembly textbox +* @param scrollid id of the scrollbar +* @param addr starting address for disassembly +* @param skiplines how many comment/label lines to skip, used for smooth scrolling (default 0) +*/ +void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int skiplines) +{ + SetScroll(addr, skiplines); + DisassembleToWindow(hWnd, id, scrollid); +} + void PrintOffsetToSeekAndBookmarkFields(int offset) { if (offset >= 0 && hDebug) @@ -988,13 +1008,12 @@ void UpdateDebugger(bool jump_to_pc) } char str[512] = {0}, str2[512] = {0}, chr[8]; - int tmp, ret, i, starting_address; + int tmp, ret, i; if (jump_to_pc || disassembly_addresses.size() == 0) { // For relative positioning, we want start pos to be PC address with the comments scrolled offscreen. - starting_address = X.PC; - skipLinesStatic = NumAnnotationLines(starting_address); + SetScroll(X.PC, NumAnnotationLines(scrollAddress)); // ensure that PC pointer will be visible even after the window was resized RECT rect; @@ -1006,14 +1025,13 @@ void UpdateDebugger(bool jump_to_pc) // keep the relative position of the ">" pointer inside the Disassembly window for (int i = PCLine; i > 0; i--) { - starting_address = ScrollUp(starting_address); + ScrollUp(); } - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address, skipLinesStatic); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR); } else { - starting_address = disassembly_addresses[0]; - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, starting_address, skipLinesStatic); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR); } @@ -2274,19 +2292,19 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd case SB_BOTTOM: break; case SB_LINEUP: { - si.nPos = ScrollUp(si.nPos); + ScrollUp(); break; } case SB_LINEDOWN: { - si.nPos = ScrollDown(si.nPos); + ScrollDown(); break; } case SB_PAGEUP: { for (int i = si.nPage; i > 0; i--) { - si.nPos = ScrollUp(si.nPos); + si.nPos = ScrollUp().address; if (si.nPos < si.nMin) { si.nPos = si.nMin; @@ -2299,7 +2317,7 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd { for (int i = si.nPage; i > 0; i--) { - si.nPos = ScrollDown(si.nPos); + si.nPos = ScrollDown().address; if ((si.nPos + (int)si.nPage) > si.nMax) { si.nPos = si.nMax - si.nPage; @@ -2312,12 +2330,18 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; } if (si.nPos < si.nMin) + { si.nPos = si.nMin; + commentOffset = 0; + } if ((si.nPos + (int)si.nPage) > si.nMax) + { si.nPos = si.nMax - si.nPage; - SetScrollInfo(hwndScrollBar, SB_CTL, &si, TRUE); + commentOffset = 0; + } + + DisassembleToWindow(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos, commentOffset); - DisassembleToWindow(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos, skipLinesStatic); // The address in the Add Bookmark textbox follows the scroll pos. char str[16]; sprintf(str,"%04X", si.nPos); @@ -2337,7 +2361,7 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso { for (i *= -(int)si.nPage; i > 0; i--) { - si.nPos = ScrollDown(si.nPos); + si.nPos = ScrollDown().address; if ((si.nPos + (int)si.nPage) > si.nMax) { si.nPos = si.nMax - si.nPage; @@ -2348,7 +2372,7 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso { for (i *= si.nPage; i > 0; i--) { - si.nPos = ScrollUp(si.nPos); + si.nPos = ScrollUp().address; if (si.nPos < si.nMin) { si.nPos = si.nMin; @@ -2358,7 +2382,7 @@ void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 curso } // This function calls UpdateScrollInfo. Don't worry! - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos, skipLinesStatic); + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, si.nPos, commentOffset); // The address in the Add Bookmark textbox follows the scroll pos. char str[16]; sprintf(str,"%04X", si.nPos); diff --git a/src/drivers/win/debugger.h b/src/drivers/win/debugger.h index 31fb69bc5..29768f865 100644 --- a/src/drivers/win/debugger.h +++ b/src/drivers/win/debugger.h @@ -39,6 +39,7 @@ void UpdateDebugger(bool jump_to_pc = true); void DoDebug(uint8 halt); void DebuggerExit(); void DisassembleToWindow(HWND hWnd, int id, int scrollid, unsigned int addr, int skiplines = 0); +void DisassembleToWindow(HWND hWnd, int id, int scrollid); void PrintOffsetToSeekAndBookmarkFields(int offset); void LoadGameDebuggerData(HWND hwndDlg); From 557f73c56a8159cdbdff5a491c834d3d5a6d0e30 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 7 Jul 2021 04:04:56 -0400 Subject: [PATCH 070/103] remove ancient comments --- src/drivers/win/debugger.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/drivers/win/debugger.h b/src/drivers/win/debugger.h index 29768f865..84e1e0345 100644 --- a/src/drivers/win/debugger.h +++ b/src/drivers/win/debugger.h @@ -13,10 +13,9 @@ #define TOO_MANY_BREAKPOINTS 1 #define INVALID_BREAKPOINT_CONDITION 3 -//extern volatile int userpause; //mbg merge 7/18/06 removed for merging extern HWND hDebug; -extern int childwnd,numWPs; //mbg merge 7/18/06 had to make extern +extern int childwnd,numWPs; extern bool debuggerAutoload; extern bool debuggerSaveLoadDEBFiles; extern bool debuggerDisplayROMoffsets; From d8043b7a96663e0263607b09cbd7a5697d89093d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 8 Jul 2021 02:00:51 -0400 Subject: [PATCH 071/103] add showTrace param to asm.cpp functions Previously there were several spots that manually removed it by adding null bytes. How silly! --- src/asm.cpp | 52 ++++++++++++++++++++---------------- src/asm.h | 8 +++--- src/drivers/win/debugger.cpp | 3 ++- src/drivers/win/dumper.cpp | 8 ------ 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/asm.cpp b/src/asm.cpp index 53306ac21..6d5c3ec50 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -255,7 +255,7 @@ int Assemble(unsigned char *output, int addr, char *str) { } ///disassembles the opcodes in the buffer assuming the provided address. Uses GetMem() and 6502 current registers to query referenced values. returns a static string buffer. -char *Disassemble(int addr, uint8 *opcode) { +char *Disassemble(int addr, uint8 *opcode, bool showTrace) { static char str[64]={0},chr[5]={0}; uint16 tmp,tmp2; @@ -333,7 +333,9 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xE1: strcpy(chr,"SBC"); goto _indirectx; _indirectx: indirectX(tmp); - sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + showTrace + ? sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) + : sprintf(str,"%s ($%02X,X)", chr,opcode[1]); break; //Zero Page @@ -359,10 +361,10 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xE5: strcpy(chr,"SBC"); goto _zeropage; case 0xE6: strcpy(chr,"INC"); goto _zeropage; _zeropage: - // ################################## Start of SP CODE ########################### // Change width to %04X // don't! - sprintf(str,"%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1])); - // ################################## End of SP CODE ########################### + showTrace + ? sprintf(str,"%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1])) + : sprintf(str,"%s $%02X", chr,opcode[1]); break; //#Immediate @@ -406,7 +408,9 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xEE: strcpy(chr,"INC"); goto _absolute; _absolute: absolute(tmp); - sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp)); + showTrace + ? sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp)) + : sprintf(str,"%s $%04X", chr,tmp); break; //branches @@ -434,7 +438,9 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xF1: strcpy(chr,"SBC"); goto _indirecty; _indirecty: indirectY(tmp); - sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + showTrace + ? sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) + : sprintf(str,"%s ($%02X),Y", chr,opcode[1]); break; //Zero Page,X @@ -456,10 +462,10 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xF6: strcpy(chr,"INC"); goto _zeropagex; _zeropagex: zpIndex(tmp,RX); - // ################################## Start of SP CODE ########################### // Change width to %04X // don't! - sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); - // ################################## End of SP CODE ########################### + showTrace + ? sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) + : sprintf(str,"%s $%02X,X", chr,opcode[1]); break; //Absolute,Y @@ -475,7 +481,9 @@ char *Disassemble(int addr, uint8 *opcode) { _absolutey: absolute(tmp); tmp2=(tmp+RY); - sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); + showTrace + ? sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)) + : sprintf(str,"%s $%04X,Y", chr,tmp); break; //Absolute,X @@ -497,7 +505,9 @@ char *Disassemble(int addr, uint8 *opcode) { _absolutex: absolute(tmp); tmp2=(tmp+RX); - sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); + showTrace + ? sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)) + : sprintf(str,"%s $%04X,X", chr,tmp); break; //jumps @@ -514,10 +524,10 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xB6: strcpy(chr,"LDX"); goto _zeropagey; _zeropagey: zpIndex(tmp,RY); - // ################################## Start of SP CODE ########################### // Change width to %04X // don't! - sprintf(str,"%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); - // ################################## End of SP CODE ########################### + showTrace + ? sprintf(str,"%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)) + : sprintf(str,"%s $%02X,Y", chr,opcode[1]); break; //UNDEFINED @@ -529,7 +539,7 @@ char *Disassemble(int addr, uint8 *opcode) { } // Need to clean up this interface. -char *DisassembleLine(int addr) { +char *DisassembleLine(int addr, bool showTrace) { static char str[64] = { 0 }, chr[25] = { 0 }; char *c; int size, j; @@ -556,15 +566,13 @@ char *DisassembleLine(int addr) { strcat(str, " "); //pad output to align ASM size++; } - strcat(strcat(str, " "), Disassemble(addr, opcode)); + strcat(strcat(str, " "), Disassemble(addr, opcode, showTrace)); } } - if ((c = strchr(str, '='))) *(c - 1) = 0; - if ((c = strchr(str, '@'))) *(c - 1) = 0; return str; } -char *DisassembleData(int addr, uint8 *opcode) { +char *DisassembleData(int addr, uint8 *opcode, bool showTrace) { static char str[64] = { 0 }, chr[25] = { 0 }; char *c; int size, j; @@ -596,10 +604,8 @@ char *DisassembleData(int addr, uint8 *opcode) { strcat(str, " "); //pad output to align ASM size++; } - strcat(strcat(str, " "), Disassemble(addr, opcode)); + strcat(strcat(str, " "), Disassemble(addr, opcode, showTrace)); } } - if ((c = strchr(str, '='))) *(c - 1) = 0; - if ((c = strchr(str, '@'))) *(c - 1) = 0; return str; } diff --git a/src/asm.h b/src/asm.h index 276aab16b..2348d6512 100644 --- a/src/asm.h +++ b/src/asm.h @@ -1,4 +1,6 @@ +#pragma once + int Assemble(unsigned char *output, int addr, char *str); -char *Disassemble(int addr, uint8 *opcode); -char *DisassembleLine(int addr); -char *DisassembleData(int addr, uint8 *opcode); +char *Disassemble(int addr, uint8 *opcode, bool showTrace = false); +char *DisassembleLine(int addr, bool showTrace = false); +char *DisassembleData(int addr, uint8 *opcode, bool showTrace = false); diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 2d9eafb4f..6e99dbdcd 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -797,7 +797,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) } static char bufferForDisassemblyWithPlentyOfStuff[64+NL_MAX_NAME_LEN*10]; //"plenty" - char* _a = Disassemble(addr, opcode); + char* _a = Disassemble(addr, opcode, true); // TODO: menu parameter strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); if (symbDebugEnabled) @@ -1996,6 +1996,7 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) } break; // Options menu + // TODO: show trace info (new) case ID_DEBUGGER_AUTO_OPEN: debuggerAutoload ^= 1; break; diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index 9529ce3d6..2c8c668fc 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -177,14 +177,6 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) { static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; // "plenty" char* _a = Disassemble(addr, opcode); - // This isn't a trace log, so we want to remove the data after the @ or =. - // There are lots of hardcoded sprintfs in Disassemble. This really is the easiest way. - char* traceInfoIndex = strstr(_a, "@"); - if (traceInfoIndex) - traceInfoIndex[-1] = 0; - traceInfoIndex = strstr(_a, "="); - if (traceInfoIndex) - traceInfoIndex[-1] = 0; strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); From 61842ca7e8c0e4051ad693f45a024be1fe12e25d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 8 Jul 2021 02:19:36 -0400 Subject: [PATCH 072/103] make DisassembleLine just call DisassembleData --- src/asm.cpp | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/asm.cpp b/src/asm.cpp index 6d5c3ec50..c80670672 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -254,7 +254,7 @@ int Assemble(unsigned char *output, int addr, char *str) { return 0; } -///disassembles the opcodes in the buffer assuming the provided address. Uses GetMem() and 6502 current registers to query referenced values. returns a static string buffer. +///Disassembles the instruction bytes in the buffer using the provided address for trace info. Uses GetMem() and 6502 current registers to query referenced values. Returns a static string buffer. char *Disassemble(int addr, uint8 *opcode, bool showTrace) { static char str[64]={0},chr[5]={0}; uint16 tmp,tmp2; @@ -538,38 +538,9 @@ char *Disassemble(int addr, uint8 *opcode, bool showTrace) { return str; } -// Need to clean up this interface. char *DisassembleLine(int addr, bool showTrace) { - static char str[64] = { 0 }, chr[25] = { 0 }; - char *c; - int size, j; - uint8 opcode[3]; - - sprintf(str, "%02X:%04X: ", getBank(addr), addr); - size = opsize[GetMem(addr)]; - if (size == 0) - { - sprintf(chr, "%02X UNDEFINED", GetMem(addr++)); - strcat(str, chr); - } - else { - if ((addr + size) > 0x10000) { - sprintf(chr, "%02X OVERFLOW", GetMem(addr)); - strcat(str, chr); - } - else { - for (j = 0; j < size; j++) { - sprintf(chr, "%02X ", opcode[j] = GetMem(addr++)); - strcat(str, chr); - } - while (size < 3) { - strcat(str, " "); //pad output to align ASM - size++; - } - strcat(strcat(str, " "), Disassemble(addr, opcode, showTrace)); - } - } - return str; + uint8 instruction[] = {GetMem(addr), GetMem(addr + 1), GetMem(addr + 2)}; + return DisassembleData(addr, instruction, showTrace); } char *DisassembleData(int addr, uint8 *opcode, bool showTrace) { From cb830bfd504d0be8f6b4f1988c4812a627cc2630 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 8 Jul 2021 03:28:48 -0400 Subject: [PATCH 073/103] add ROM offsets param to DisassembleToLine --- src/asm.cpp | 24 +++++++-- src/asm.h | 4 +- src/drivers/win/debugger.cpp | 102 ++++++++++++----------------------- src/drivers/win/dumper.cpp | 1 + 4 files changed, 56 insertions(+), 75 deletions(-) diff --git a/src/asm.cpp b/src/asm.cpp index c80670672..4a41968b5 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -538,17 +538,33 @@ char *Disassemble(int addr, uint8 *opcode, bool showTrace) { return str; } -char *DisassembleLine(int addr, bool showTrace) { +char *DisassembleLine(int addr, bool showTrace, bool showRomOffsets) { uint8 instruction[] = {GetMem(addr), GetMem(addr + 1), GetMem(addr + 2)}; - return DisassembleData(addr, instruction, showTrace); + return DisassembleData(addr, instruction, showTrace, showRomOffsets); } -char *DisassembleData(int addr, uint8 *opcode, bool showTrace) { +char *DisassembleData(int addr, uint8 *opcode, bool showTrace, bool showRomOffsets) { static char str[64] = { 0 }, chr[25] = { 0 }; char *c; int size, j; - sprintf(str, "%02X:%04X: ", getBank(addr), addr); + // TODO: Split out address formatter method + if (addr >= 0x8000) + { + if (showRomOffsets && GetNesFileAddress(addr) != -1) + { + sprintf(str, " %06X: ", GetNesFileAddress(addr)); + } + else + { + sprintf(str, "%02X:%04X: ", getBank(addr), addr); + } + } + else + { + sprintf(str, " :%04X: ", addr); + } + size = opsize[opcode[0]]; if (size == 0) { diff --git a/src/asm.h b/src/asm.h index 2348d6512..82c20f8b4 100644 --- a/src/asm.h +++ b/src/asm.h @@ -2,5 +2,5 @@ int Assemble(unsigned char *output, int addr, char *str); char *Disassemble(int addr, uint8 *opcode, bool showTrace = false); -char *DisassembleLine(int addr, bool showTrace = false); -char *DisassembleData(int addr, uint8 *opcode, bool showTrace = false); +char *DisassembleLine(int addr, bool showTrace = false, bool showRomOffsets = false); +char *DisassembleData(int addr, uint8 *opcode, bool showTrace = false, bool showRomOffsets = false); diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 6e99dbdcd..8340c9d0e 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -643,7 +643,6 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) void DisassembleToWindow(HWND hWnd, int id, int scrollid) { // Why is this getting called twice per scroll? - wchar_t chr[40] = { 0 }; wchar_t debug_wbuf[2048] = { 0 }; int size; uint8 opcode[3]; @@ -748,86 +747,51 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) { wcscat(debug_wstr, L" "); } - - if (addr >= 0x8000) - { - if (debuggerDisplayROMoffsets && GetNesFileAddress(addr) != -1) - { - swprintf(chr, L" %06X: ", GetNesFileAddress(addr)); - } else - { - swprintf(chr, L"%02X:%04X: ", getBank(addr), addr); - } - } else - { - swprintf(chr, L" :%04X: ", addr); - } // Add address - wcscat(debug_wstr, chr); disassembly_addresses.push_back(addr); if (symbDebugEnabled) disassembly_operands.resize(i + 1); - size = opsize[GetMem(addr)]; - if (size == 0) - { - swprintf(chr, L"%02X UNDEFINED", GetMem(addr++)); - wcscat(debug_wstr, chr); - } else - { - if ((addr + size) > 0xFFFF) - { - while (addr < 0xFFFF) - { - swprintf(chr, L"%02X OVERFLOW\n", GetMem(addr++)); - wcscat(debug_wstr, chr); - } - break; - } - for (int j = 0; j < size; j++) - { - swprintf(chr, L"%02X ", opcode[j] = GetMem(addr++)); - wcscat(debug_wstr, chr); - } - while (size < 3) - { - wcscat(debug_wstr, L" "); //pad output to align ASM - size++; - } - - static char bufferForDisassemblyWithPlentyOfStuff[64+NL_MAX_NAME_LEN*10]; //"plenty" - char* _a = Disassemble(addr, opcode, true); // TODO: menu parameter - strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); + static char bufferForDisassemblyWithPlentyOfStuff[64+NL_MAX_NAME_LEN*10]; //"plenty" + char* _a = DisassembleLine(addr, true, debuggerDisplayROMoffsets); // TODO: menu parameter + strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); - if (symbDebugEnabled) - { // TODO: This will add in both the default name and custom name if you have inlineAddresses enabled. - if (symbRegNames) - replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); - replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, &disassembly_operands[i]); - for(int p=0;p 0xFFFF) + break; } UpdateDisassembleView(hWnd, id, lines, true); diff --git a/src/drivers/win/dumper.cpp b/src/drivers/win/dumper.cpp index 2c8c668fc..dccd4efca 100644 --- a/src/drivers/win/dumper.cpp +++ b/src/drivers/win/dumper.cpp @@ -171,6 +171,7 @@ void Dump(FILE *fout, unsigned int startAddr, unsigned int endAddr) if (node) { // TODO: Instead of this ominous and confusing message, could print ".byte $XX $YY..." + // TODO: Work this logic into asm.cpp? fprintf(fout, " INTERRUPTED"); } else From 639d04ac26fe8ade07b884b6432fd9d0170f6fa8 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 8 Jul 2021 03:29:18 -0400 Subject: [PATCH 074/103] change "bad opcodes" to "unofficial opcodes" --- src/drivers/win/res.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 472aa16d0..37587c8c4 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3044,7 +3044,7 @@ BEGIN MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM SEPARATOR - MENUITEM "Break on Bad Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED + MENUITEM "Break on Unofficial Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED MENUITEM SEPARATOR MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE END From be59ac98d91e2d78d249ebb46df25b06d13a2b2c Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 8 Jul 2021 03:31:08 -0400 Subject: [PATCH 075/103] fix PC relative screen position not working --- src/drivers/win/debugger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 8340c9d0e..56bf74c53 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -977,7 +977,7 @@ void UpdateDebugger(bool jump_to_pc) if (jump_to_pc || disassembly_addresses.size() == 0) { // For relative positioning, we want start pos to be PC address with the comments scrolled offscreen. - SetScroll(X.PC, NumAnnotationLines(scrollAddress)); + SetScroll(X.PC, NumAnnotationLines(X.PC)); // ensure that PC pointer will be visible even after the window was resized RECT rect; From 80ee06aae91c31d1c045241f74ab752b03dff120 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 8 Jul 2021 04:13:37 -0400 Subject: [PATCH 076/103] add toggle for showing trace info --- src/drivers/win/debugger.cpp | 20 +++++++++++--------- src/drivers/win/res.rc | 1 + src/drivers/win/resource.h | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 56bf74c53..f0d88a58e 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -80,6 +80,7 @@ bool debuggerSaveLoadDEBFiles = true; bool debuggerIDAFont = false; unsigned int IDAFontSize = 16; bool debuggerDisplayROMoffsets = false; +bool debuggerShowTraceInfo = true; static wchar_t* debug_wstr; static char* debug_cdl_str; @@ -754,7 +755,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) disassembly_operands.resize(i + 1); static char bufferForDisassemblyWithPlentyOfStuff[64+NL_MAX_NAME_LEN*10]; //"plenty" - char* _a = DisassembleLine(addr, true, debuggerDisplayROMoffsets); // TODO: menu parameter + char* _a = DisassembleLine(addr, debuggerShowTraceInfo, debuggerDisplayROMoffsets); strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); if (symbDebugEnabled) @@ -991,12 +992,9 @@ void UpdateDebugger(bool jump_to_pc) { ScrollUp(); } - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR); - } - else - { - DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR); } + + DisassembleToWindow(hDebug, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR); // The address in the Add Bookmark textbox follows the scroll pos. @@ -1704,6 +1702,7 @@ inline void UpdateOptionsPopup(HMENU optionsPopup) CheckMenuItem(optionsPopup, ID_DEBUGGER_AUTO_OPEN, CheckedFlag(debuggerAutoload)); CheckMenuItem(optionsPopup, ID_DEBUGGER_IDA_FONT, CheckedFlag(debuggerIDAFont)); CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_ROM_OFFSETS, CheckedFlag(debuggerDisplayROMoffsets)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_TRACE_INFO, CheckedFlag(debuggerShowTraceInfo)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_BAD_OPCODES, CheckedFlag(FCEUI_Debugger().badopbreak)); } @@ -1960,7 +1959,6 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) } break; // Options menu - // TODO: show trace info (new) case ID_DEBUGGER_AUTO_OPEN: debuggerAutoload ^= 1; break; @@ -1971,6 +1969,10 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE); UpdateDebugger(false); break; + case ID_DEBUGGER_SHOW_TRACE_INFO: + debuggerShowTraceInfo ^= 1; + UpdateDebugger(false); + break; case ID_DEBUGGER_SHOW_ROM_OFFSETS: debuggerDisplayROMoffsets ^= 1; UpdateDebugger(false); @@ -2013,8 +2015,8 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) break; case IDOK: // Make pressing Enter synonymous with the button you'd expect depending on the focus. - HWND focus; - switch (GetDlgCtrlID(focus = GetFocus())) + HWND focus = GetFocus(); + switch (GetDlgCtrlID(focus)) { case IDC_DEBUGGER_VAL_PCSEEK: DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_SEEK_TO, NULL); diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 37587c8c4..2406990b0 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3044,6 +3044,7 @@ BEGIN MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM SEPARATOR + MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED MENUITEM "Break on Unofficial Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED MENUITEM SEPARATOR MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index ec1fbaa88..9882ca543 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1215,6 +1215,7 @@ #define ID_DUMPER_GO 45551 #define ID_DUMPER_NES_ADDR_TOGGLE 45552 #define ID_DEBUGGER_BREAK_BAD_OPCODES 45553 +#define ID_DEBUGGER_SHOW_TRACE_INFO 45554 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From fe9b71469cfda6d5f1dcd10af4d0641c7d693cf8 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Fri, 9 Jul 2021 10:09:55 -0400 Subject: [PATCH 077/103] cheat the merge conflict I'm conflict-averse --- src/drivers/win/res.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 2406990b0..d9ae7beb2 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -2330,7 +2330,7 @@ END ARCHIVECHOOSERDIALOG AFX_DIALOG_LAYOUT BEGIN - 0 + 0 END CODEDUMPER AFX_DIALOG_LAYOUT From 49a20c920c518297cbbf09fe7b189d3dc1321518 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Fri, 9 Jul 2021 10:47:57 -0400 Subject: [PATCH 078/103] delete duplicate resource --- src/drivers/win/res.rc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index d9ae7beb2..7e975630d 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -2328,11 +2328,6 @@ BEGIN 0 END -ARCHIVECHOOSERDIALOG AFX_DIALOG_LAYOUT -BEGIN - 0 -END - CODEDUMPER AFX_DIALOG_LAYOUT BEGIN 0 From 6e0a3a81998078c1e29b31de5233f360a036afe5 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sat, 10 Jul 2021 03:50:33 -0400 Subject: [PATCH 079/103] add toggles for CDL breaks --- src/drivers/win/debugger.cpp | 8 ++++++++ src/drivers/win/res.rc | 5 ++++- src/drivers/win/resource.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index f0d88a58e..00c777448 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1704,6 +1704,8 @@ inline void UpdateOptionsPopup(HMENU optionsPopup) CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_ROM_OFFSETS, CheckedFlag(debuggerDisplayROMoffsets)); CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_TRACE_INFO, CheckedFlag(debuggerShowTraceInfo)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_BAD_OPCODES, CheckedFlag(FCEUI_Debugger().badopbreak)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_CODE, CheckedFlag(break_on_unlogged_code)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_DATA, CheckedFlag(break_on_unlogged_data)); } inline void UpdateSymbolsPopup(HMENU symbolsPopup) @@ -1980,6 +1982,12 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) case ID_DEBUGGER_BREAK_BAD_OPCODES: FCEUI_Debugger().badopbreak ^= 1; break; + case ID_DEBUGGER_BREAK_UNLOGGED_CODE: + break_on_unlogged_code ^= 1; + break; + case ID_DEBUGGER_BREAK_UNLOGGED_DATA: + break_on_unlogged_data ^= 1; + break; case ID_DEBUGGER_RESTORE_SIZE: RestoreSize(hwndDlg); break; diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 7e975630d..e2e6c4ff9 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3036,11 +3036,14 @@ BEGIN POPUP "Options" BEGIN MENUITEM "Auto Open on ROM Load", ID_DEBUGGER_AUTO_OPEN, CHECKED + MENUITEM SEPARATOR MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED - MENUITEM SEPARATOR MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED + MENUITEM SEPARATOR MENUITEM "Break on Unofficial Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED + MENUITEM "Break on Unlogged Code", ID_DEBUGGER_BREAK_UNLOGGED_CODE, CHECKED + MENUITEM "Break on Unlogged Data", ID_DEBUGGER_BREAK_UNLOGGED_DATA, CHECKED MENUITEM SEPARATOR MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE END diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 9882ca543..12ff13807 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1216,6 +1216,8 @@ #define ID_DUMPER_NES_ADDR_TOGGLE 45552 #define ID_DEBUGGER_BREAK_BAD_OPCODES 45553 #define ID_DEBUGGER_SHOW_TRACE_INFO 45554 +#define ID_DEBUGGER_BREAK_UNLOGGED_CODE 45555 +#define ID_DEBUGGER_BREAK_UNLOGGED_DATA 45556 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From ac71eb489c65e8580a15e30ce164108649531ef9 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 22 Jul 2021 23:08:59 -0400 Subject: [PATCH 080/103] initial hotkey ideas --- src/drivers/win/debugger.cpp | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 00c777448..b89f83e44 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1683,6 +1683,12 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_SYMBOLS_POS 2 #define MENU_TOOLS_POS 3 +#define HKEY_STEP_ONE_ID 0 +#define HKEY_STEP_OUT_ID 1 +#define HKEY_SEEK_ADDR_ID 4 +#define HKEY_SEEK_PC_ID 5 +#define HKEY_SET_PC_ID 6 + HMENU toolsPopup, symbolsPopup, optionsPopup; INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -1805,6 +1811,14 @@ void DebuggerInitDialog(HWND hwndDlg) UpdateSymbolsPopup(symbolsPopup = GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); + // Register default hotkeys + // TODO: Be sure to unregister all these!! + RegisterHotKey(hwndDlg, HKEY_STEP_ONE_ID, 0, VK_F11); + RegisterHotKey(hwndDlg, HKEY_STEP_OUT_ID, MOD_SHIFT, VK_F11); + + RegisterHotKey(hwndDlg, HKEY_SEEK_ADDR_ID, MOD_CONTROL, 0x41); // A + RegisterHotKey(hwndDlg, HKEY_SEEK_PC_ID, MOD_CONTROL, 0x50); // P + debugger_open = 1; inDebugger = true; } @@ -2493,6 +2507,31 @@ void DebuggerEnChange(HWND hwndDlg, uint16 textBoxId, HWND hwndTextbox) } } +void DebuggerHotKey(HWND hwndDlg, UINT hotkeyId, uint16 keycode, uint16 mods) +{ + switch (hotkeyId) + { + // Do we want autorepeat on these? MOD_NOREPEAT doesn't seem to exist so idk what to do. + case HKEY_STEP_ONE_ID: + printf("Step one\n"); + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_IN, NULL); + break; + case HKEY_STEP_OUT_ID: + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_OUT, NULL); + printf("Step out\n"); + break; + case HKEY_SEEK_ADDR_ID: + printf("Seek to address\n"); + SetFocus(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PCSEEK)); + SetDlgItemText(hDebug, IDC_DEBUGGER_VAL_PCSEEK, ""); + break; + case HKEY_SEEK_PC_ID: + printf("Seek to PC\n"); + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_SEEK_PC, NULL); + break; + } +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -2558,6 +2597,9 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case WM_MBUTTONDOWN: DebuggerMButtonDown(hwndDlg, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam); break; + case WM_HOTKEY: + DebuggerHotKey(hwndDlg, wParam, HIWORD(lParam), LOWORD(lParam)); + break; case WM_KEYDOWN: MessageBox(hwndDlg, "Die!", "I'm dead!", MB_YESNO | MB_ICONINFORMATION); break; From 13bd9ddfd2be67596cf5def54f77242272ceb76c Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 2 Aug 2021 02:53:49 -0400 Subject: [PATCH 081/103] make color dialog a sub menu --- src/drivers/win/debugger.cpp | 16 +++++++++------- src/drivers/win/res.rc | 10 +++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index b89f83e44..bf2a88609 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1679,9 +1679,10 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w // Need to coordinate these with res.rc #define MENU_OPTIONS_POS 0 -#define MENU_COLORS_POS 1 -#define MENU_SYMBOLS_POS 2 -#define MENU_TOOLS_POS 3 +#define MENU_SYMBOLS_POS 1 +#define MENU_TOOLS_POS 2 + +#define MENU_OPTIONS_COLORS_POS 2 #define HKEY_STEP_ONE_ID 0 #define HKEY_STEP_OUT_ID 1 @@ -1803,14 +1804,15 @@ void DebuggerInitDialog(HWND hwndDlg) // prepare menu HMENU hdbgmenu = GetMenu(hwndDlg); - HMENU hcolorpopupmenu = GetSubMenu(hdbgmenu, MENU_COLORS_POS); - for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) - InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); UpdateOptionsPopup(optionsPopup = GetSubMenu(hdbgmenu, MENU_OPTIONS_POS)); UpdateSymbolsPopup(symbolsPopup = GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); + HMENU hcolorpopupmenu = GetSubMenu(optionsPopup, MENU_OPTIONS_COLORS_POS); + for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) + InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); + // Register default hotkeys // TODO: Be sure to unregister all these!! RegisterHotKey(hwndDlg, HKEY_STEP_ONE_ID, 0, VK_F11); @@ -1944,7 +1946,7 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) RECT rect; GetClientRect(GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY), &rect); UpdateDisassembleView(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, (rect.bottom - rect.top) / debugSystem->disasmFontHeight); - HMENU hcolorpopupmenu = GetSubMenu(GetMenu(hwndDlg), 1); + HMENU hcolorpopupmenu = GetSubMenu(optionsPopup, MENU_OPTIONS_COLORS_POS); for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) ModifyColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); } diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index e2e6c4ff9..63ad10ff7 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3037,6 +3037,11 @@ BEGIN BEGIN MENUITEM "Auto Open on ROM Load", ID_DEBUGGER_AUTO_OPEN, CHECKED MENUITEM SEPARATOR + POPUP "Colors..." + BEGIN + MENUITEM SEPARATOR + MENUITEM "Restore Defaults", ID_DEBUGGER_DEFCOLOR + END MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED @@ -3047,11 +3052,6 @@ BEGIN MENUITEM SEPARATOR MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE END - POPUP "Colors" - BEGIN - MENUITEM SEPARATOR - MENUITEM "Restore Defaults", ID_DEBUGGER_DEFCOLOR - END POPUP "Symbols" BEGIN MENUITEM "Reload", ID_DEBUGGER_RELOAD_SYMBOLS From 2d1cd5eb9aaa5264ed00b2e2c7b4b8f75d47f24a Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 2 Aug 2021 03:17:54 -0400 Subject: [PATCH 082/103] add run and step over hotkeys --- src/drivers/win/debugger.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index bf2a88609..b74b4bcaf 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1686,6 +1686,8 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define HKEY_STEP_ONE_ID 0 #define HKEY_STEP_OUT_ID 1 +#define HKEY_STEP_OVER_ID 2 +#define HKEY_RUN_ID 3 #define HKEY_SEEK_ADDR_ID 4 #define HKEY_SEEK_PC_ID 5 #define HKEY_SET_PC_ID 6 @@ -1817,6 +1819,8 @@ void DebuggerInitDialog(HWND hwndDlg) // TODO: Be sure to unregister all these!! RegisterHotKey(hwndDlg, HKEY_STEP_ONE_ID, 0, VK_F11); RegisterHotKey(hwndDlg, HKEY_STEP_OUT_ID, MOD_SHIFT, VK_F11); + RegisterHotKey(hwndDlg, HKEY_STEP_OVER_ID, 0, VK_F10); + RegisterHotKey(hwndDlg, HKEY_RUN_ID, 0, VK_F5); RegisterHotKey(hwndDlg, HKEY_SEEK_ADDR_ID, MOD_CONTROL, 0x41); // A RegisterHotKey(hwndDlg, HKEY_SEEK_PC_ID, MOD_CONTROL, 0x50); // P @@ -2522,6 +2526,11 @@ void DebuggerHotKey(HWND hwndDlg, UINT hotkeyId, uint16 keycode, uint16 mods) DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_OUT, NULL); printf("Step out\n"); break; + case HKEY_STEP_OVER_ID: + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_OVER, NULL); + break; + case HKEY_RUN_ID: + DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_RUN, NULL); case HKEY_SEEK_ADDR_ID: printf("Seek to address\n"); SetFocus(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PCSEEK)); From 052be52323b05a0fccca515ebc4aae355df0fd25 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 2 Aug 2021 03:18:09 -0400 Subject: [PATCH 083/103] fixup the hotkey method --- src/drivers/win/debugger.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index b74b4bcaf..ea6bc69c3 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2515,16 +2515,18 @@ void DebuggerEnChange(HWND hwndDlg, uint16 textBoxId, HWND hwndTextbox) void DebuggerHotKey(HWND hwndDlg, UINT hotkeyId, uint16 keycode, uint16 mods) { + // No idea if this is good programming. Should we use accelerators instead? + if (GetForegroundWindow() != hwndDlg) + return; + switch (hotkeyId) { // Do we want autorepeat on these? MOD_NOREPEAT doesn't seem to exist so idk what to do. case HKEY_STEP_ONE_ID: - printf("Step one\n"); DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_IN, NULL); break; case HKEY_STEP_OUT_ID: DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_OUT, NULL); - printf("Step out\n"); break; case HKEY_STEP_OVER_ID: DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_OVER, NULL); @@ -2532,12 +2534,10 @@ void DebuggerHotKey(HWND hwndDlg, UINT hotkeyId, uint16 keycode, uint16 mods) case HKEY_RUN_ID: DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_RUN, NULL); case HKEY_SEEK_ADDR_ID: - printf("Seek to address\n"); SetFocus(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PCSEEK)); SetDlgItemText(hDebug, IDC_DEBUGGER_VAL_PCSEEK, ""); break; case HKEY_SEEK_PC_ID: - printf("Seek to PC\n"); DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_SEEK_PC, NULL); break; } From a9205eac4ac10e0845e9bf56e0b24d784059d0c0 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 11 Aug 2021 04:03:50 -0400 Subject: [PATCH 084/103] down with hotkeys, long live accelerators! Hotkeys are SUPER jank. There should be some kind of warning in the docs or something. They are an operating system-level message, and if consumed, NO OTHER APPLICATION GETS TO HAVE IT. So this Ctrl+A hotkey meant the hex editor couldn't use it anymore. Neither could Visual Studio. Or Notepad++. Or Chrome. That's BAD. --- src/drivers/win/debugger.cpp | 103 ++++++++++++----------------------- src/drivers/win/main.cpp | 7 +++ src/drivers/win/res.rc | 10 ++++ src/drivers/win/resource.h | 1 + 4 files changed, 52 insertions(+), 69 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index ea6bc69c3..bfb13bfeb 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1684,14 +1684,6 @@ BOOL CALLBACK IDC_DEBUGGER_DISASSEMBLY_WndProc(HWND hwndDlg, UINT uMsg, WPARAM w #define MENU_OPTIONS_COLORS_POS 2 -#define HKEY_STEP_ONE_ID 0 -#define HKEY_STEP_OUT_ID 1 -#define HKEY_STEP_OVER_ID 2 -#define HKEY_RUN_ID 3 -#define HKEY_SEEK_ADDR_ID 4 -#define HKEY_SEEK_PC_ID 5 -#define HKEY_SET_PC_ID 6 - HMENU toolsPopup, symbolsPopup, optionsPopup; INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -1815,16 +1807,6 @@ void DebuggerInitDialog(HWND hwndDlg) for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); - // Register default hotkeys - // TODO: Be sure to unregister all these!! - RegisterHotKey(hwndDlg, HKEY_STEP_ONE_ID, 0, VK_F11); - RegisterHotKey(hwndDlg, HKEY_STEP_OUT_ID, MOD_SHIFT, VK_F11); - RegisterHotKey(hwndDlg, HKEY_STEP_OVER_ID, 0, VK_F10); - RegisterHotKey(hwndDlg, HKEY_RUN_ID, 0, VK_F5); - - RegisterHotKey(hwndDlg, HKEY_SEEK_ADDR_ID, MOD_CONTROL, 0x41); // A - RegisterHotKey(hwndDlg, HKEY_SEEK_PC_ID, MOD_CONTROL, 0x50); // P - debugger_open = 1; inDebugger = true; } @@ -2513,36 +2495,6 @@ void DebuggerEnChange(HWND hwndDlg, uint16 textBoxId, HWND hwndTextbox) } } -void DebuggerHotKey(HWND hwndDlg, UINT hotkeyId, uint16 keycode, uint16 mods) -{ - // No idea if this is good programming. Should we use accelerators instead? - if (GetForegroundWindow() != hwndDlg) - return; - - switch (hotkeyId) - { - // Do we want autorepeat on these? MOD_NOREPEAT doesn't seem to exist so idk what to do. - case HKEY_STEP_ONE_ID: - DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_IN, NULL); - break; - case HKEY_STEP_OUT_ID: - DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_OUT, NULL); - break; - case HKEY_STEP_OVER_ID: - DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_STEP_OVER, NULL); - break; - case HKEY_RUN_ID: - DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_RUN, NULL); - case HKEY_SEEK_ADDR_ID: - SetFocus(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PCSEEK)); - SetDlgItemText(hDebug, IDC_DEBUGGER_VAL_PCSEEK, ""); - break; - case HKEY_SEEK_PC_ID: - DebuggerBnClicked(hwndDlg, IDC_DEBUGGER_SEEK_PC, NULL); - break; - } -} - INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -2563,24 +2515,40 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP DebuggerMoveWindow(hwndDlg, LOWORD(lParam), HIWORD(lParam)); break; case WM_COMMAND: - switch (HIWORD(wParam)) - { - case BN_CLICKED: - DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); - break; - case LBN_DBLCLK: - DebuggerLbnDblClk(hwndDlg, LOWORD(wParam), (HWND)lParam); - break; - case LBN_SELCANCEL: - DebuggerLbnSelCancel(hwndDlg, LOWORD(wParam), (HWND)lParam); - break; - case LBN_SELCHANGE: - DebuggerLbnSelChange(hwndDlg, LOWORD(wParam), (HWND)lParam); - break; - case EN_CHANGE: - DebuggerEnChange(hwndDlg, LOWORD(wParam), (HWND)lParam); - break; - } + // I know you can cleverly ignore this difference and have all your menu messages come through as BN_CLICKED messagse. + // But then your accelerators come through as LBN_SELCHANGE messages, which makes absolutely no sense. + if (lParam) + // Normal messages + switch (HIWORD(wParam)) + { + case BN_CLICKED: + DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case LBN_DBLCLK: + DebuggerLbnDblClk(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case LBN_SELCANCEL: + DebuggerLbnSelCancel(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case LBN_SELCHANGE: + DebuggerLbnSelChange(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case EN_CHANGE: + DebuggerEnChange(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + } + else + switch (HIWORD(wParam)) + { + case 0: + // Menu items + DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + case 1: + // Accelerators + DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); + break; + } case WM_INITMENUPOPUP: DebuggerInitMenuPopup(hwndDlg, (HMENU)wParam, LOWORD(lParam), HIWORD(lParam)); break; @@ -2608,9 +2576,6 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP case WM_MBUTTONDOWN: DebuggerMButtonDown(hwndDlg, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam); break; - case WM_HOTKEY: - DebuggerHotKey(hwndDlg, wParam, HIWORD(lParam), LOWORD(lParam)); - break; case WM_KEYDOWN: MessageBox(hwndDlg, "Die!", "I'm dead!", MB_YESNO | MB_ICONINFORMATION); break; diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 54147dbc0..9e356f6cb 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -186,6 +186,7 @@ int ffbskip = 32; //Blit skips per blit when FF-ing HINSTANCE fceu_hInstance; HACCEL fceu_hAccel; +HACCEL debugger_hAccel; HRESULT ddrval; @@ -377,6 +378,11 @@ int BlockingCheck() if(!handled && taseditorWindow.hwndFindNote && IsChild(taseditorWindow.hwndFindNote, msg.hwnd)) handled = IsDialogMessage(taseditorWindow.hwndFindNote, &msg); + // Debugger + if(!handled && hDebug) + if(!(handled = TranslateAccelerator(hDebug, debugger_hAccel, &msg))) + handled = IsDialogMessage(hDebug, &msg); + // Sound Config extern HWND uug; if(!handled && uug && IsChild(uug, msg.hwnd)) @@ -711,6 +717,7 @@ int main(int argc,char *argv[]) fceu_hInstance = GetModuleHandle(0); fceu_hAccel = LoadAccelerators(fceu_hInstance,MAKEINTRESOURCE(IDR_ACCELERATOR1)); + debugger_hAccel = LoadAccelerators(fceu_hInstance,MAKEINTRESOURCE(IDR_DEBUGGER_ACCELERATOR)); // Get the base directory GetBaseDirectory(); diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 63ad10ff7..e50b577e6 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3129,6 +3129,16 @@ BEGIN "R", IDC_C_WATCH_REMOVE, VIRTKEY END +IDR_DEBUGGER_ACCELERATOR ACCELERATORS +BEGIN + VK_F11, IDC_DEBUGGER_STEP_IN, VIRTKEY + VK_F11, IDC_DEBUGGER_STEP_OUT, VIRTKEY, SHIFT + VK_F10, IDC_DEBUGGER_STEP_OVER, VIRTKEY + VK_F5, IDC_DEBUGGER_RUN, VIRTKEY + "A", IDC_DEBUGGER_VAL_PCSEEK, VIRTKEY, CONTROL + "P", IDC_DEBUGGER_SEEK_PC, VIRTKEY, CONTROL +END + ///////////////////////////////////////////////////////////////////////////// // diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 12ff13807..c93d4fe23 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1218,6 +1218,7 @@ #define ID_DEBUGGER_SHOW_TRACE_INFO 45554 #define ID_DEBUGGER_BREAK_UNLOGGED_CODE 45555 #define ID_DEBUGGER_BREAK_UNLOGGED_DATA 45556 +#define IDR_DEBUGGER_ACCELERATOR 45557 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From 5f368afdded6aa9a51e89bb01140ffe29ab5c8eb Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 11 Aug 2021 04:04:46 -0400 Subject: [PATCH 085/103] comments and menu label change --- src/drivers/win/debugger.cpp | 8 ++------ src/drivers/win/res.rc | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index bfb13bfeb..ae3dedc8b 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -41,9 +41,6 @@ #include "assembler.h" #include "patcher.h" #include "dumper.h" - -// ################################## Start of SP CODE ########################### - #include "debuggersp.h" extern Name* pageNames[32]; @@ -52,8 +49,6 @@ extern bool ramBankNamesLoaded; extern int pageNumbersLoaded[32]; extern int myNumWPs; -// ################################## End of SP CODE ########################### - extern int vblankScanLines; extern int vblankPixel; extern bool DebuggerWasUpdated; @@ -583,7 +578,7 @@ void HighlightSyntax(HWND hWnd, int lines) SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgComm)); else { - if (debug_wstr[opbreak] == L'-') + if (debug_wstr[opbreak] == L'-') // TODO: Gets confused if dashes in label name! SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgRts)); else @@ -1803,6 +1798,7 @@ void DebuggerInitDialog(HWND hwndDlg) UpdateSymbolsPopup(symbolsPopup = GetSubMenu(hdbgmenu, MENU_SYMBOLS_POS)); UpdateToolsPopup(toolsPopup = GetSubMenu(hdbgmenu, MENU_TOOLS_POS)); + // Preprocessor nonsense to dynamically generate the colors menu HMENU hcolorpopupmenu = GetSubMenu(optionsPopup, MENU_OPTIONS_COLORS_POS); for (int i = 0; i < sizeof(dbgcolormenu) / sizeof(DBGCOLORMENU); ++i) InsertColorMenu(hwndDlg, hcolorpopupmenu, &dbgcolormenu[i].menu, i, ID_COLOR_DEBUGGER + i); diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index e50b577e6..db35c6003 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3037,7 +3037,7 @@ BEGIN BEGIN MENUITEM "Auto Open on ROM Load", ID_DEBUGGER_AUTO_OPEN, CHECKED MENUITEM SEPARATOR - POPUP "Colors..." + POPUP "Syntax Highlighting" BEGIN MENUITEM SEPARATOR MENUITEM "Restore Defaults", ID_DEBUGGER_DEFCOLOR From 5a483e315783ace333f47f3711e8110822647905 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 11 Aug 2021 05:37:49 -0400 Subject: [PATCH 086/103] make it actually work --- src/drivers/win/debugger.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index ae3dedc8b..7e687d3d9 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2491,6 +2491,23 @@ void DebuggerEnChange(HWND hwndDlg, uint16 textBoxId, HWND hwndTextbox) } } +void DebuggerAccelerator(HWND hwndDlg, uint16 accId) +{ + switch (accId) + { + case IDC_DEBUGGER_STEP_IN: + case IDC_DEBUGGER_STEP_OUT: + case IDC_DEBUGGER_STEP_OVER: + case IDC_DEBUGGER_RUN: + case IDC_DEBUGGER_SEEK_PC: + DebuggerBnClicked(hwndDlg, accId, NULL); + break; + case IDC_DEBUGGER_VAL_PCSEEK: + SetFocus(GetDlgItem(hwndDlg, IDC_DEBUGGER_VAL_PCSEEK)); + SetDlgItemText(hDebug, IDC_DEBUGGER_VAL_PCSEEK, ""); + } +} + INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -2511,10 +2528,10 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP DebuggerMoveWindow(hwndDlg, LOWORD(lParam), HIWORD(lParam)); break; case WM_COMMAND: - // I know you can cleverly ignore this difference and have all your menu messages come through as BN_CLICKED messagse. + // I know you can cleverly ignore lParam and have all your menu messages come through as BN_CLICKED messages. // But then your accelerators come through as LBN_SELCHANGE messages, which makes absolutely no sense. if (lParam) - // Normal messages + { // Normal messages switch (HIWORD(wParam)) { case BN_CLICKED: @@ -2533,7 +2550,9 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP DebuggerEnChange(hwndDlg, LOWORD(wParam), (HWND)lParam); break; } + } else + { switch (HIWORD(wParam)) { case 0: @@ -2542,9 +2561,10 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP break; case 1: // Accelerators - DebuggerBnClicked(hwndDlg, LOWORD(wParam), (HWND)lParam); + DebuggerAccelerator(hwndDlg, LOWORD(wParam)); break; } + } case WM_INITMENUPOPUP: DebuggerInitMenuPopup(hwndDlg, (HMENU)wParam, LOWORD(lParam), HIWORD(lParam)); break; From b7f5dbf6cf8b0ab6801a442df3296139d61e6b0a Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 00:57:26 -0400 Subject: [PATCH 087/103] fix annoying BRK scroll bug BRK is a quirky opcode that has a length of 2 even though it doesn't take any operands. It's not disassembled as 2 bytes by FCEUX, so scrolling up by 2 like that didn't make sense. This has cause me a LOT of annoyance over the years! --- src/drivers/win/debugger.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 7e687d3d9..5f7b70492 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -310,10 +310,8 @@ int InstructionUp(int from) } // if we get here, no suitable instruction was found - if ((from >= 2) && (GetMem(from - 2) == 0x00)) - return (from - 2); // if a BRK instruction is possible, use that if (from) - return (from - 1); // else, scroll up one byte + return (from - 1); // scroll up one byte return 0; // of course, if we can't scroll up, just return 0! } From b32d9f179f2dd925e22527a08ba57011dc2003ce Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 01:06:15 -0400 Subject: [PATCH 088/103] initial commit for data blocks --- src/drivers/win/debugger.cpp | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 5f7b70492..d4ef50ecf 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -287,6 +287,7 @@ static int NumAnnotationLines(int addr) // This function is for "smart" scrolling. // It attempts to scroll up by a whole instruction heuristically. // Should we add the label-respecting logic from dumper.cpp? +// TOOD: Check IsData and scroll by up to 8. int InstructionUp(int from) { int i = std::min(16, from), j; @@ -315,6 +316,7 @@ int InstructionUp(int from) return 0; // of course, if we can't scroll up, just return 0! } +// TOOD: Check IsData and scroll by up to 8. int InstructionDown(int from) { int tmp = opsize[GetMem(si.nPos)]; @@ -630,6 +632,24 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } +bool IsData(unsigned int addr) +{ + printf("Checking CDL for $%04X...\n", addr); + if (cdloggerdataSize) + { + unsigned int romAddr = GetNesFileAddress(addr) - 16; // minus iNES header + printf("ROM[%04X], CDL[%04X]\n", romAddr + 16, romAddr); + + if (romAddr >= 0 && romAddr < cdloggerdataSize) + { + printf("CDL data: %02X\n", cdloggerdata[romAddr]); + return (cdloggerdata[romAddr] & 3) == 2; // Data only + } + } + printf("CDL inactive.\n"); + return false; +} + /** * Disassembles to the debugger window using the existing address scroll info. * Assumes that either SetScroll or the overload that takes address and offset was called. @@ -744,6 +764,58 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) // Add address disassembly_addresses.push_back(addr); + + if (IsData(addr)) + { + + // TODO: Split out address formatter method + if (addr >= 0x8000) + { + /*if (showRomOffsets && GetNesFileAddress(addr) != -1) + { + sprintf(str, " %06X: ", GetNesFileAddress(addr)); + } + else*/ + //{ + swprintf(debug_wbuf, L"%02X:%04X: ", getBank(addr), addr); + //} + } + else + { + swprintf(debug_wbuf, L" :%04X: ", addr); + } + + wcscat(debug_wstr, debug_wbuf); + + swprintf(debug_wbuf, L".db $%02X", GetMem(addr)); + wcscat(debug_wstr, debug_wbuf); + + int db = 1; + for (; db < 8 && IsData(addr + db); db++) + { // TOOD: Label-respecting logic. But then the whole "array" naming convetion gets obnoxious. + // append data bytes to current line + swprintf(debug_wbuf, L", $%02X", GetMem(addr + db)); + wcscat(debug_wstr, debug_wbuf); + } + + // MEGA jank + if (symbDebugEnabled) + disassembly_operands.resize(i + 1); + + // TODO: Move this to a function so we can fall back to the existing copy of this junk. + // Although, we couldn't just grab size from opsize anymore. + line_count++; + addr += db; + + wcscat(debug_wstr, L"\n"); + + // Break if we reached end of address space + if (addr > 0xFFFF) + break; + + continue; + } + if (symbDebugEnabled) disassembly_operands.resize(i + 1); @@ -787,6 +859,7 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) if (addr > 0xFFFF) break; } + printf("\nUpdating view...\n"); UpdateDisassembleView(hWnd, id, lines, true); // fill the left panel data From 97b0f83d6b7ad01683ae75c76f89271faf8983f3 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 02:11:42 -0400 Subject: [PATCH 089/103] move some logic to asm.cpp --- src/asm.cpp | 34 +++++++++++++++++++ src/asm.h | 1 + src/drivers/win/debugger.cpp | 63 ++++++++++-------------------------- 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/src/asm.cpp b/src/asm.cpp index 4a41968b5..a5fc4d463 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -596,3 +596,37 @@ char *DisassembleData(int addr, uint8 *opcode, bool showTrace, bool showRomOffse } return str; } + +/// Disassembles a data block of the given length, regardless of any cdlogger info. +char *DisassembleDataBlock(int addr, int length, bool showTrace, bool showRomOffsets) { + static char str[64] = { 0 }, chr[25] = { 0 }; + int size; + + // TODO: Split out address formatter method + if (addr >= 0x8000) + { + if (showRomOffsets && GetNesFileAddress(addr) != -1) + { + sprintf(str, " %06X: ", GetNesFileAddress(addr)); + } + else + { + sprintf(str, "%02X:%04X: ", getBank(addr), addr); + } + } + else + { + sprintf(str, " :%04X: ", addr); + } + + + sprintf(chr, ".db $%02X", GetMem(addr)); + strcat(str, chr); + + for (int i = addr + 1; i < addr + length && i < 0x10000; i++) { + sprintf(chr, ", $%02X", GetMem(i)); + strcat(str, chr); + } + + return str; +} diff --git a/src/asm.h b/src/asm.h index 82c20f8b4..232dcc767 100644 --- a/src/asm.h +++ b/src/asm.h @@ -4,3 +4,4 @@ int Assemble(unsigned char *output, int addr, char *str); char *Disassemble(int addr, uint8 *opcode, bool showTrace = false); char *DisassembleLine(int addr, bool showTrace = false, bool showRomOffsets = false); char *DisassembleData(int addr, uint8 *opcode, bool showTrace = false, bool showRomOffsets = false); +char *DisassembleDataBlock(int addr, int length, bool showTrace = false, bool showRomOffsets = false); diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index d4ef50ecf..6003fdfee 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -634,22 +634,17 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) bool IsData(unsigned int addr) { - printf("Checking CDL for $%04X...\n", addr); if (cdloggerdataSize) { unsigned int romAddr = GetNesFileAddress(addr) - 16; // minus iNES header - printf("ROM[%04X], CDL[%04X]\n", romAddr + 16, romAddr); - if (romAddr >= 0 && romAddr < cdloggerdataSize) - { - printf("CDL data: %02X\n", cdloggerdata[romAddr]); return (cdloggerdata[romAddr] & 3) == 2; // Data only - } } - printf("CDL inactive.\n"); return false; } +#define MAX_DB_LEN 8 + /** * Disassembles to the debugger window using the existing address scroll info. * Assumes that either SetScroll or the overload that takes address and offset was called. @@ -764,51 +759,32 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) // Add address disassembly_addresses.push_back(addr); + if (symbDebugEnabled) + disassembly_operands.resize(i + 1); + + static char bufferForDisassemblyWithPlentyOfStuff[64 + NL_MAX_NAME_LEN * 10]; //"plenty" if (IsData(addr)) { + // TOOD: Label-respecting logic. But then the whole "array" naming convetion gets obnoxious. - // TODO: Split out address formatter method - if (addr >= 0x8000) - { - /*if (showRomOffsets && GetNesFileAddress(addr) != -1) - { - sprintf(str, " %06X: ", GetNesFileAddress(addr)); - } - else*/ - //{ - swprintf(debug_wbuf, L"%02X:%04X: ", getBank(addr), addr); - //} - } - else - { - swprintf(debug_wbuf, L" :%04X: ", addr); - } - - wcscat(debug_wstr, debug_wbuf); + // Determine data block length + int db = 1; + for (; db < MAX_DB_LEN && IsData(addr + db); db++); - swprintf(debug_wbuf, L".db $%02X", GetMem(addr)); - wcscat(debug_wstr, debug_wbuf); + char *_a = DisassembleDataBlock(addr, db, debuggerShowTraceInfo, debuggerDisplayROMoffsets); + strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); - int db = 1; - for (; db < 8 && IsData(addr + db); db++) - { // TOOD: Label-respecting logic. But then the whole "array" naming convetion gets obnoxious. - // append data bytes to current line - swprintf(debug_wbuf, L", $%02X", GetMem(addr + db)); - wcscat(debug_wstr, debug_wbuf); - } + // Everything in this block below this point is mostly copied from belower. + // There's got to be some way to merge the executions flows. - // MEGA jank - if (symbDebugEnabled) - disassembly_operands.resize(i + 1); + // append the disassembly to current line + swprintf(debug_wbuf, L"%S\n", bufferForDisassemblyWithPlentyOfStuff); + wcscat(debug_wstr, debug_wbuf); - // TODO: Move this to a function so we can fall back to the existing copy of this junk. - // Although, we couldn't just grab size from opsize anymore. line_count++; addr += db; - wcscat(debug_wstr, L"\n"); - // Break if we reached end of address space if (addr > 0xFFFF) break; @@ -816,10 +792,6 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) continue; } - if (symbDebugEnabled) - disassembly_operands.resize(i + 1); - - static char bufferForDisassemblyWithPlentyOfStuff[64+NL_MAX_NAME_LEN*10]; //"plenty" char* _a = DisassembleLine(addr, debuggerShowTraceInfo, debuggerDisplayROMoffsets); strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); @@ -859,7 +831,6 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) if (addr > 0xFFFF) break; } - printf("\nUpdating view...\n"); UpdateDisassembleView(hWnd, id, lines, true); // fill the left panel data From e92e84d60fa1375a9ddfd26298803c31d337e5bb Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 02:51:08 -0400 Subject: [PATCH 090/103] further cleanup --- src/asm.cpp | 39 +++++++------------ src/drivers/win/debugger.cpp | 75 +++++++++++++++--------------------- 2 files changed, 43 insertions(+), 71 deletions(-) diff --git a/src/asm.cpp b/src/asm.cpp index a5fc4d463..ae20c2516 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -543,27 +543,30 @@ char *DisassembleLine(int addr, bool showTrace, bool showRomOffsets) { return DisassembleData(addr, instruction, showTrace, showRomOffsets); } -char *DisassembleData(int addr, uint8 *opcode, bool showTrace, bool showRomOffsets) { - static char str[64] = { 0 }, chr[25] = { 0 }; - char *c; - int size, j; - - // TODO: Split out address formatter method +int formatAddress(char *str, int addr, bool showRomOffsets) { if (addr >= 0x8000) { if (showRomOffsets && GetNesFileAddress(addr) != -1) { - sprintf(str, " %06X: ", GetNesFileAddress(addr)); + return sprintf(str, " %06X: ", GetNesFileAddress(addr)); } else { - sprintf(str, "%02X:%04X: ", getBank(addr), addr); + return sprintf(str, "%02X:%04X: ", getBank(addr), addr); } } else { - sprintf(str, " :%04X: ", addr); + return sprintf(str, " :%04X: ", addr); } +} + +char *DisassembleData(int addr, uint8 *opcode, bool showTrace, bool showRomOffsets) { + static char str[64] = { 0 }, chr[25] = { 0 }; + char *c; + int size, j; + + formatAddress(str, addr, showRomOffsets); size = opsize[opcode[0]]; if (size == 0) @@ -602,23 +605,7 @@ char *DisassembleDataBlock(int addr, int length, bool showTrace, bool showRomOff static char str[64] = { 0 }, chr[25] = { 0 }; int size; - // TODO: Split out address formatter method - if (addr >= 0x8000) - { - if (showRomOffsets && GetNesFileAddress(addr) != -1) - { - sprintf(str, " %06X: ", GetNesFileAddress(addr)); - } - else - { - sprintf(str, "%02X:%04X: ", getBank(addr), addr); - } - } - else - { - sprintf(str, " :%04X: ", addr); - } - + formatAddress(str, addr, showRomOffsets); sprintf(chr, ".db $%02X", GetMem(addr)); strcat(str, chr); diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 6003fdfee..4e343034a 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -769,62 +769,47 @@ void DisassembleToWindow(HWND hWnd, int id, int scrollid) // TOOD: Label-respecting logic. But then the whole "array" naming convetion gets obnoxious. // Determine data block length - int db = 1; - for (; db < MAX_DB_LEN && IsData(addr + db); db++); + for (size = 1; size < MAX_DB_LEN && IsData(addr + size); size++); - char *_a = DisassembleDataBlock(addr, db, debuggerShowTraceInfo, debuggerDisplayROMoffsets); + char *_a = DisassembleDataBlock(addr, size, debuggerShowTraceInfo, debuggerDisplayROMoffsets); + strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); + } else + { + char* _a = DisassembleLine(addr, debuggerShowTraceInfo, debuggerDisplayROMoffsets); strcpy(bufferForDisassemblyWithPlentyOfStuff, _a); - // Everything in this block below this point is mostly copied from belower. - // There's got to be some way to merge the executions flows. - - // append the disassembly to current line - swprintf(debug_wbuf, L"%S\n", bufferForDisassemblyWithPlentyOfStuff); - wcscat(debug_wstr, debug_wbuf); - - line_count++; - addr += db; - - // Break if we reached end of address space - if (addr > 0xFFFF) - break; + if (symbDebugEnabled) + { // TODO: This will add in both the default name and custom name if you have inlineAddresses enabled. + if (symbRegNames) + replaceRegNames(bufferForDisassemblyWithPlentyOfStuff); + replaceNames(ramBankNames, bufferForDisassemblyWithPlentyOfStuff, &disassembly_operands[i]); + for (int p = 0; p Date: Tue, 23 Aug 2022 03:40:30 -0400 Subject: [PATCH 091/103] add toggle to show unlogged bytes as data --- src/drivers/win/debugger.cpp | 13 ++++++++++++- src/drivers/win/res.rc | 1 + src/drivers/win/resource.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 4e343034a..49af7b663 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -76,6 +76,7 @@ bool debuggerIDAFont = false; unsigned int IDAFontSize = 16; bool debuggerDisplayROMoffsets = false; bool debuggerShowTraceInfo = true; +bool debuggerUnloggedBytesAsData = false; static wchar_t* debug_wstr; static char* debug_cdl_str; @@ -638,7 +639,12 @@ bool IsData(unsigned int addr) { unsigned int romAddr = GetNesFileAddress(addr) - 16; // minus iNES header if (romAddr >= 0 && romAddr < cdloggerdataSize) - return (cdloggerdata[romAddr] & 3) == 2; // Data only + { + uint8 cdlData = cdloggerdata[romAddr] & 3; + return cdlData == 0 + ? debuggerUnloggedBytesAsData + : cdlData == 2; // Only data, not code + } } return false; } @@ -1726,6 +1732,7 @@ inline void UpdateOptionsPopup(HMENU optionsPopup) CheckMenuItem(optionsPopup, ID_DEBUGGER_IDA_FONT, CheckedFlag(debuggerIDAFont)); CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_ROM_OFFSETS, CheckedFlag(debuggerDisplayROMoffsets)); CheckMenuItem(optionsPopup, ID_DEBUGGER_SHOW_TRACE_INFO, CheckedFlag(debuggerShowTraceInfo)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_UNLOGGED_AS_DATA, CheckedFlag(debuggerUnloggedBytesAsData)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_BAD_OPCODES, CheckedFlag(FCEUI_Debugger().badopbreak)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_CODE, CheckedFlag(break_on_unlogged_code)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_DATA, CheckedFlag(break_on_unlogged_data)); @@ -2000,6 +2007,10 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) debuggerShowTraceInfo ^= 1; UpdateDebugger(false); break; + case ID_DEBUGGER_UNLOGGED_AS_DATA: + debuggerUnloggedBytesAsData ^= 1; + UpdateDebugger(false); + break; case ID_DEBUGGER_SHOW_ROM_OFFSETS: debuggerDisplayROMoffsets ^= 1; UpdateDebugger(false); diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index db35c6003..4432e7a7a 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3045,6 +3045,7 @@ BEGIN MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED + MENUITEM "Show Unlogged Bytes as Data" ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED MENUITEM SEPARATOR MENUITEM "Break on Unofficial Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED MENUITEM "Break on Unlogged Code", ID_DEBUGGER_BREAK_UNLOGGED_CODE, CHECKED diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index c93d4fe23..d283867cb 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1219,6 +1219,7 @@ #define ID_DEBUGGER_BREAK_UNLOGGED_CODE 45555 #define ID_DEBUGGER_BREAK_UNLOGGED_DATA 45556 #define IDR_DEBUGGER_ACCELERATOR 45557 +#define ID_DEBUGGER_UNLOGGED_AS_DATA 45558 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From 883b542789e27c4509661ce70aad2eb317328f92 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 03:44:27 -0400 Subject: [PATCH 092/103] add comma I'm actually not sure if this matters... --- src/drivers/win/res.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 4432e7a7a..8d8a249f9 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3045,7 +3045,7 @@ BEGIN MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED - MENUITEM "Show Unlogged Bytes as Data" ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED + MENUITEM "Show Unlogged Bytes as Data", ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED MENUITEM SEPARATOR MENUITEM "Break on Unofficial Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED MENUITEM "Break on Unlogged Code", ID_DEBUGGER_BREAK_UNLOGGED_CODE, CHECKED From 5d5963a4ae8361aa65c0a9e604016d9397ba5a22 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 16:59:45 -0400 Subject: [PATCH 093/103] make InstructionUp and InstructionDown respect data blocks --- src/drivers/win/debugger.cpp | 59 +++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 49af7b663..4cfe67e83 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -254,12 +254,30 @@ unsigned int AddBreak(HWND hwndDlg) return 0; } +#define MAX_DB_LEN 8 + typedef struct { int address; int commentOffset; } AddrScrollInfo; +bool IsData(unsigned int addr) +{ + if (cdloggerdataSize) + { + unsigned int romAddr = GetNesFileAddress(addr) - 16; // minus iNES header + if (romAddr >= 0 && romAddr < cdloggerdataSize) + { + uint8 cdlData = cdloggerdata[romAddr] & 3; + return cdlData == 0 + ? debuggerUnloggedBytesAsData + : cdlData == 2; // Only data, not code + } + } + return false; +} + // Tells you how many lines the comments and label name take for a given address. // Used for smoothly scrolling through comments. static int NumAnnotationLines(int addr) @@ -288,9 +306,18 @@ static int NumAnnotationLines(int addr) // This function is for "smart" scrolling. // It attempts to scroll up by a whole instruction heuristically. // Should we add the label-respecting logic from dumper.cpp? -// TOOD: Check IsData and scroll by up to 8. +// Always attempting the full data block size can lead to weird results. Maybe cut it on multiples of 8? int InstructionUp(int from) { + if (IsData(from - 1)) + { + // Scroll past the beginning of the data block, up to MAX_DB_LEN bytes. + int i = from - 2; + for (; i >= from - MAX_DB_LEN && IsData(i); i--); + + return i + 1; + } + int i = std::min(16, from), j; while (i > 0) @@ -317,14 +344,22 @@ int InstructionUp(int from) return 0; // of course, if we can't scroll up, just return 0! } -// TOOD: Check IsData and scroll by up to 8. int InstructionDown(int from) { + if (IsData(from)) + { + // Scroll past the end of the data block, up to MAX_DB_LEN bytes. + int i = from + 1; + for (; i < from + MAX_DB_LEN && IsData(i); i++); + + return i; + } + int tmp = opsize[GetMem(si.nPos)]; if ((tmp)) return from + tmp; else - return from + 1; // this is data or undefined instruction + return from + 1; // this is an undefined instruction } // Updates the scroll address and comment offset, and sends that info to the debugger window. @@ -633,24 +668,6 @@ void UpdateDisassembleView(HWND hWnd, UINT id, int lines, bool text = false) SendDlgItemMessage(hWnd, id, EM_SETEVENTMASK, 0, eventMask); } -bool IsData(unsigned int addr) -{ - if (cdloggerdataSize) - { - unsigned int romAddr = GetNesFileAddress(addr) - 16; // minus iNES header - if (romAddr >= 0 && romAddr < cdloggerdataSize) - { - uint8 cdlData = cdloggerdata[romAddr] & 3; - return cdlData == 0 - ? debuggerUnloggedBytesAsData - : cdlData == 2; // Only data, not code - } - } - return false; -} - -#define MAX_DB_LEN 8 - /** * Disassembles to the debugger window using the existing address scroll info. * Assumes that either SetScroll or the overload that takes address and offset was called. From c90cc26206d34887b776e54662bcd056383ad5d3 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 17:00:20 -0400 Subject: [PATCH 094/103] gray out CDL-related options if CDL is inactive --- src/drivers/win/debugger.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 4cfe67e83..b8ff5f7c6 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1753,6 +1753,11 @@ inline void UpdateOptionsPopup(HMENU optionsPopup) CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_BAD_OPCODES, CheckedFlag(FCEUI_Debugger().badopbreak)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_CODE, CheckedFlag(break_on_unlogged_code)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_DATA, CheckedFlag(break_on_unlogged_data)); + + // Gray out potentially irrelavant options + EnableMenuItem(optionsPopup, ID_DEBUGGER_UNLOGGED_AS_DATA, EnabledFlag(cdloggerdataSize)); + EnableMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_CODE, EnabledFlag(cdloggerdataSize)); + EnableMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_DATA, EnabledFlag(cdloggerdataSize)); } inline void UpdateSymbolsPopup(HMENU symbolsPopup) From 9f9354a59a5a9995417fbb27ae6b6ef4feeac29e Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 18:04:40 -0400 Subject: [PATCH 095/103] fix accidental fallthrough Uh-oh! --- src/drivers/win/debugger.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index b8ff5f7c6..c708dd2cc 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2625,6 +2625,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP break; } } + break; case WM_INITMENUPOPUP: DebuggerInitMenuPopup(hwndDlg, (HMENU)wParam, LOWORD(lParam), HIWORD(lParam)); break; From 3457863d53e74ec195f3300e7f2c05b80cd6835d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 18:05:54 -0400 Subject: [PATCH 096/103] add a submenu for CDL flags --- src/drivers/win/res.rc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 8d8a249f9..1f3e94096 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3045,11 +3045,14 @@ BEGIN MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED - MENUITEM "Show Unlogged Bytes as Data", ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED + POPUP "Code/Data Logger" + BEGIN + MENUITEM "Show Unlogged &Bytes as Data\tCtrl+D", ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED + MENUITEM "Break on Unlogged Code", ID_DEBUGGER_BREAK_UNLOGGED_CODE, CHECKED + MENUITEM "Break on Unlogged Data", ID_DEBUGGER_BREAK_UNLOGGED_DATA, CHECKED + END MENUITEM SEPARATOR MENUITEM "Break on Unofficial Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED - MENUITEM "Break on Unlogged Code", ID_DEBUGGER_BREAK_UNLOGGED_CODE, CHECKED - MENUITEM "Break on Unlogged Data", ID_DEBUGGER_BREAK_UNLOGGED_DATA, CHECKED MENUITEM SEPARATOR MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE END From 935061868d87c334b2a8fe75098659eb8d3cf9f7 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 18:06:17 -0400 Subject: [PATCH 097/103] add some accelerators --- src/drivers/win/debugger.cpp | 2 ++ src/drivers/win/res.rc | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index c708dd2cc..66b5c1bee 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2560,6 +2560,8 @@ void DebuggerAccelerator(HWND hwndDlg, uint16 accId) case IDC_DEBUGGER_STEP_OVER: case IDC_DEBUGGER_RUN: case IDC_DEBUGGER_SEEK_PC: + case ID_DEBUGGER_UNLOGGED_AS_DATA: + case ID_DEBUGGER_SHOW_ROM_OFFSETS: DebuggerBnClicked(hwndDlg, accId, NULL); break; case IDC_DEBUGGER_VAL_PCSEEK: diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 1f3e94096..fe60f7bc0 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3043,7 +3043,7 @@ BEGIN MENUITEM "Restore Defaults", ID_DEBUGGER_DEFCOLOR END MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED - MENUITEM "ROM Offsets", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED + MENUITEM "&ROM Offsets\tAlt+A", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED POPUP "Code/Data Logger" BEGIN @@ -3141,6 +3141,8 @@ BEGIN VK_F5, IDC_DEBUGGER_RUN, VIRTKEY "A", IDC_DEBUGGER_VAL_PCSEEK, VIRTKEY, CONTROL "P", IDC_DEBUGGER_SEEK_PC, VIRTKEY, CONTROL + "A", ID_DEBUGGER_SHOW_ROM_OFFSETS, VIRTKEY, ALT + "D", ID_DEBUGGER_UNLOGGED_AS_DATA, VIRTKEY, CONTROL END From d4f7de38a807eb0de6854575064bd7ec9df9cf16 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 23 Aug 2022 19:22:49 -0400 Subject: [PATCH 098/103] clean up syntax highlighter --- src/drivers/win/debugger.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 66b5c1bee..4e4ea56c9 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -583,6 +583,7 @@ void HighlightSyntax(HWND hWnd, int lines) wordbreak = SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_FINDWORDBREAK, (WPARAM)WB_RIGHT, (LPARAM)newline.chrg.cpMin + 21); for (int ch = newline.chrg.cpMin; ; ch++) { + // Lots of highlighting glitches for labels like @loop or table-1. Need to forbid these characters in labels or interlace this with the disassembly process. if (debug_wstr[ch] == L'=' || debug_wstr[ch] == L'@' || debug_wstr[ch] == L'\n' || debug_wstr[ch] == L'-' || debug_wstr[ch] == L';') { opbreak = ch; @@ -597,24 +598,28 @@ void HighlightSyntax(HWND hWnd, int lines) if(newline.chrg.cpMin == 0) break; if (!commentline) { - // symbolic address + // We checked for semicolons first because otherwise this would detect comments ending in a colon. if (debug_wstr[newline.chrg.cpMin - 2] == L':') { + // Named label line. SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)oldline, (LPARAM)newline.chrg.cpMin); SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgSym)); continue; } SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgMnem)); } - // comment + // Comment or code. NOT label. if (opbreak < newline.chrg.cpMin) { SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)opbreak, (LPARAM)newline.chrg.cpMin); if (commentline) + { SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgComm)); - else + continue; + } else { - if (debug_wstr[opbreak] == L'-') // TODO: Gets confused if dashes in label name! + // RTS/RTI dash. Gets confused by dashes in label names! + if (debug_wstr[opbreak] == L'-') SendDlgItemMessage(hWnd, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)PPCF(DbgRts)); else @@ -630,8 +635,6 @@ void HighlightSyntax(HWND hWnd, int lines) } } } - if (commentline) - continue; // operand num.chrg.cpMin = wordbreak; num.chrg.cpMax = wordbreak + 6; From 959a3fd4d2e0bb025c6d926e2e26d4e93a9b3dab Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 24 Aug 2022 03:30:38 -0400 Subject: [PATCH 099/103] futz with the menu --- src/drivers/win/res.rc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index fe60f7bc0..e36a95334 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3043,15 +3043,16 @@ BEGIN MENUITEM "Restore Defaults", ID_DEBUGGER_DEFCOLOR END MENUITEM "IDA Font", ID_DEBUGGER_IDA_FONT, CHECKED + MENUITEM SEPARATOR MENUITEM "&ROM Offsets\tAlt+A", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED + MENUITEM SEPARATOR POPUP "Code/Data Logger" BEGIN MENUITEM "Show Unlogged &Bytes as Data\tCtrl+D", ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED MENUITEM "Break on Unlogged Code", ID_DEBUGGER_BREAK_UNLOGGED_CODE, CHECKED MENUITEM "Break on Unlogged Data", ID_DEBUGGER_BREAK_UNLOGGED_DATA, CHECKED END - MENUITEM SEPARATOR MENUITEM "Break on Unofficial Opcodes", ID_DEBUGGER_BREAK_BAD_OPCODES, CHECKED MENUITEM SEPARATOR MENUITEM "Reset Window Size", ID_DEBUGGER_RESTORE_SIZE From bd3b4df82736c909304286273fcebd29e80ca4c2 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 24 Aug 2022 04:04:42 -0400 Subject: [PATCH 100/103] add option to toggle PC following --- src/drivers/win/debugger.cpp | 8 +++++++- src/drivers/win/res.rc | 2 ++ src/drivers/win/resource.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 4e4ea56c9..70fddca2e 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -77,6 +77,7 @@ unsigned int IDAFontSize = 16; bool debuggerDisplayROMoffsets = false; bool debuggerShowTraceInfo = true; bool debuggerUnloggedBytesAsData = false; +bool debuggerFollowPc = true; static wchar_t* debug_wstr; static char* debug_cdl_str; @@ -1756,6 +1757,7 @@ inline void UpdateOptionsPopup(HMENU optionsPopup) CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_BAD_OPCODES, CheckedFlag(FCEUI_Debugger().badopbreak)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_CODE, CheckedFlag(break_on_unlogged_code)); CheckMenuItem(optionsPopup, ID_DEBUGGER_BREAK_UNLOGGED_DATA, CheckedFlag(break_on_unlogged_data)); + CheckMenuItem(optionsPopup, ID_DEBUGGER_FOLLOW_PC, CheckedFlag(debuggerFollowPc)); // Gray out potentially irrelavant options EnableMenuItem(optionsPopup, ID_DEBUGGER_UNLOGGED_AS_DATA, EnabledFlag(cdloggerdataSize)); @@ -2049,6 +2051,9 @@ void DebuggerBnClicked(HWND hwndDlg, uint16 btnId, HWND hwndBtn) case ID_DEBUGGER_BREAK_UNLOGGED_DATA: break_on_unlogged_data ^= 1; break; + case ID_DEBUGGER_FOLLOW_PC: + debuggerFollowPc ^= 1; + break; case ID_DEBUGGER_RESTORE_SIZE: RestoreSize(hwndDlg); break; @@ -2565,6 +2570,7 @@ void DebuggerAccelerator(HWND hwndDlg, uint16 accId) case IDC_DEBUGGER_SEEK_PC: case ID_DEBUGGER_UNLOGGED_AS_DATA: case ID_DEBUGGER_SHOW_ROM_OFFSETS: + case ID_DEBUGGER_FOLLOW_PC: DebuggerBnClicked(hwndDlg, accId, NULL); break; case IDC_DEBUGGER_VAL_PCSEEK: @@ -2717,7 +2723,7 @@ void DoDebug(uint8 halt) updateGameDependentMenusDebugger(); if (GameInfo) - UpdateDebugger(true); + UpdateDebugger(debuggerFollowPc); } } diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index e36a95334..6a18bff47 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3046,6 +3046,7 @@ BEGIN MENUITEM SEPARATOR MENUITEM "&ROM Offsets\tAlt+A", ID_DEBUGGER_SHOW_ROM_OFFSETS, CHECKED MENUITEM "Show Trace Info", ID_DEBUGGER_SHOW_TRACE_INFO, CHECKED + MENUITEM "Follow Program Counter\tAlt+F", ID_DEBUGGER_FOLLOW_PC, CHECKED MENUITEM SEPARATOR POPUP "Code/Data Logger" BEGIN @@ -3144,6 +3145,7 @@ BEGIN "P", IDC_DEBUGGER_SEEK_PC, VIRTKEY, CONTROL "A", ID_DEBUGGER_SHOW_ROM_OFFSETS, VIRTKEY, ALT "D", ID_DEBUGGER_UNLOGGED_AS_DATA, VIRTKEY, CONTROL + "F", ID_DEBUGGER_FOLLOW_PC, VIRTKEY, ALT END diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index d283867cb..8ce6e43e0 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -1220,6 +1220,7 @@ #define ID_DEBUGGER_BREAK_UNLOGGED_DATA 45556 #define IDR_DEBUGGER_ACCELERATOR 45557 #define ID_DEBUGGER_UNLOGGED_AS_DATA 45558 +#define ID_DEBUGGER_FOLLOW_PC 45559 #define MW_VALUELABEL2 65423 #define MW_VALUELABEL1 65426 #define IDC_STATIC_SLASHTEXT 65442 From 3cf3379975fdd5e995eced02cc6a353377e3bd84 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 24 Aug 2022 04:04:57 -0400 Subject: [PATCH 101/103] change accelerator --- src/drivers/win/res.rc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 6a18bff47..aad2574e4 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -3050,7 +3050,7 @@ BEGIN MENUITEM SEPARATOR POPUP "Code/Data Logger" BEGIN - MENUITEM "Show Unlogged &Bytes as Data\tCtrl+D", ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED + MENUITEM "Show Unlogged &Bytes as Data\tAlt+D", ID_DEBUGGER_UNLOGGED_AS_DATA, CHECKED MENUITEM "Break on Unlogged Code", ID_DEBUGGER_BREAK_UNLOGGED_CODE, CHECKED MENUITEM "Break on Unlogged Data", ID_DEBUGGER_BREAK_UNLOGGED_DATA, CHECKED END @@ -3144,7 +3144,7 @@ BEGIN "A", IDC_DEBUGGER_VAL_PCSEEK, VIRTKEY, CONTROL "P", IDC_DEBUGGER_SEEK_PC, VIRTKEY, CONTROL "A", ID_DEBUGGER_SHOW_ROM_OFFSETS, VIRTKEY, ALT - "D", ID_DEBUGGER_UNLOGGED_AS_DATA, VIRTKEY, CONTROL + "D", ID_DEBUGGER_UNLOGGED_AS_DATA, VIRTKEY, ALT "F", ID_DEBUGGER_FOLLOW_PC, VIRTKEY, ALT END From 56c1fcd769d88aa8093dc1fe37af2bd6d4152c10 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 24 Aug 2022 04:05:11 -0400 Subject: [PATCH 102/103] comment --- src/drivers/win/debugger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 70fddca2e..c2001dfab 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -307,7 +307,7 @@ static int NumAnnotationLines(int addr) // This function is for "smart" scrolling. // It attempts to scroll up by a whole instruction heuristically. // Should we add the label-respecting logic from dumper.cpp? -// Always attempting the full data block size can lead to weird results. Maybe cut it on multiples of 8? +// Always attempting the full data block size can lead to weird results. Maybe cut it when address is a multiple of 8? int InstructionUp(int from) { if (IsData(from - 1)) From 44b8295c59ea70660dff37a41bb2f90090f0fd84 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Wed, 24 Aug 2022 04:30:06 -0400 Subject: [PATCH 103/103] remove jankyHandle This was only here because a previous programmer had gotten confused over the WM_MOUSEWHEEL event parameters. See 6b004b448291b61d740cf18143b47251e4a6bfac --- src/drivers/win/debugger.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index c2001dfab..f47a9d67f 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -2390,7 +2390,7 @@ void DebuggerVScroll(HWND hwndDlg, uint16 eventType, uint16 scrollPos, HWND hwnd } } -void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 cursorY, uint16 vkeyFlags, LPARAM jankyHandle) +void DebuggerMouseWheel(HWND hwndDlg, int16 rotAmt, uint16 cursorX, uint16 cursorY, uint16 vkeyFlags) { // None of these events can be processed without a game loaded. if (!GameInfo) @@ -2647,7 +2647,7 @@ INT_PTR CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP DebuggerVScroll(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); break; case WM_MOUSEWHEEL: - DebuggerMouseWheel(hwndDlg, HIWORD(wParam), LOWORD(lParam), HIWORD(lParam), LOWORD(wParam), lParam); + DebuggerMouseWheel(hwndDlg, HIWORD(wParam), LOWORD(lParam), HIWORD(lParam), LOWORD(wParam)); break; case WM_CONTEXTMENU: DebuggerContextMenu(hwndDlg, (HWND)wParam, LOWORD(lParam), HIWORD(lParam));