From 32ee96fb8b68399307dd30bba30849480ce7975a Mon Sep 17 00:00:00 2001 From: michaelangel007 Date: Thu, 6 Jan 2022 08:24:55 -0800 Subject: [PATCH] Debugger: Cleanup FormatNopcodeBytes() --- source/Debugger/Debugger_Disassembler.cpp | 128 +++++++++++----------- 1 file changed, 66 insertions(+), 62 deletions(-) diff --git a/source/Debugger/Debugger_Disassembler.cpp b/source/Debugger/Debugger_Disassembler.cpp index 7f7372122..c68e898e5 100644 --- a/source/Debugger/Debugger_Disassembler.cpp +++ b/source/Debugger/Debugger_Disassembler.cpp @@ -473,85 +473,89 @@ void FormatNopcodeBytes(WORD nBaseAddress, DisasmLine_t& line_) char* pDst = line_.sTarget; const char* pSrc = 0; DWORD nStartAddress = line_.pDisasmData->nStartAddress; - DWORD nEndAddress = line_.pDisasmData->nEndAddress; + DWORD nEndAddress = line_.pDisasmData->nEndAddress; // int nDataLen = nEndAddress - nStartAddress + 1 ; int nDisplayLen = nEndAddress - nBaseAddress + 1; // *inclusive* KEEP IN SYNC: _CmdDefineByteRange() CmdDisasmDataList() _6502_GetOpmodeOpbyte() FormatNopcodeBytes() int len = nDisplayLen; for (int iByte = 0; iByte < line_.nOpbyte; ) { - BYTE nTarget8 = *(LPBYTE)(mem + nBaseAddress + iByte); + BYTE nTarget8 = *(LPBYTE)(mem + nBaseAddress + iByte); WORD nTarget16 = *(LPWORD)(mem + nBaseAddress + iByte); switch (line_.iNoptype) { - case NOP_BYTE_1: - case NOP_BYTE_2: - case NOP_BYTE_4: - case NOP_BYTE_8: - sprintf(pDst, "%02X", nTarget8); // sBytes+strlen(sBytes) - pDst += 2; - iByte++; - if (line_.iNoptype == NOP_BYTE_1) + case NOP_BYTE_1: + case NOP_BYTE_2: + case NOP_BYTE_4: + case NOP_BYTE_8: + sprintf(pDst, "%02X", nTarget8); // sBytes+strlen(sBytes) + pDst += 2; + iByte++; + if (line_.iNoptype == NOP_BYTE_1) + if (iByte < line_.nOpbyte) + { + *pDst++ = ','; + } + break; + + case NOP_WORD_1: + case NOP_WORD_2: + case NOP_WORD_4: + sprintf(pDst, "%04X", nTarget16); // sBytes+strlen(sBytes) + pDst += 4; + iByte += 2; if (iByte < line_.nOpbyte) { *pDst++ = ','; } - break; - case NOP_WORD_1: - case NOP_WORD_2: - case NOP_WORD_4: - sprintf(pDst, "%04X", nTarget16); // sBytes+strlen(sBytes) - pDst += 4; - iByte += 2; - if (iByte < line_.nOpbyte) - { - *pDst++ = ','; - } - break; - case NOP_ADDRESS: - // Nothing to do, already handled :-) - iByte += 2; - break; - case NOP_STRING_APPLESOFT: - iByte = line_.nOpbyte; - strncpy(pDst, (const char*)(mem + nBaseAddress), iByte); - pDst += iByte; - *pDst = 0; - case NOP_STRING_APPLE: - iByte = line_.nOpbyte; // handle all bytes of text - pSrc = (const char*)mem + nStartAddress; - - if (len > (DISASM_DISPLAY_MAX_IMMEDIATE_LEN - 2)) // does "text" fit? - { - if (len > DISASM_DISPLAY_MAX_IMMEDIATE_LEN) // no; need extra characters for ellipsis? - len = (DISASM_DISPLAY_MAX_IMMEDIATE_LEN - 3); // ellipsis = true - - // DISPLAY: text_longer_18... - FormatCharCopy(pDst, pSrc, len); // BUG: #251 v2.8.0.7: ASC #:# with null byte doesn't mark up properly - - if (nDisplayLen > len) // ellipsis + break; + + case NOP_ADDRESS: + // Nothing to do, already handled :-) + iByte += 2; + break; + + case NOP_STRING_APPLESOFT: + iByte = line_.nOpbyte; + strncpy(pDst, (const char*)(mem + nBaseAddress), iByte); + pDst += iByte; + *pDst = 0; + case NOP_STRING_APPLE: + iByte = line_.nOpbyte; // handle all bytes of text + pSrc = (const char*)mem + nStartAddress; + + if (len > (DISASM_DISPLAY_MAX_IMMEDIATE_LEN - 2)) // does "text" fit? { - *pDst++ = '.'; - *pDst++ = '.'; - *pDst++ = '.'; + if (len > DISASM_DISPLAY_MAX_IMMEDIATE_LEN) // no; need extra characters for ellipsis? + len = (DISASM_DISPLAY_MAX_IMMEDIATE_LEN - 3); // ellipsis = true + + // DISPLAY: text_longer_18... + FormatCharCopy(pDst, pSrc, len); // BUG: #251 v2.8.0.7: ASC #:# with null byte doesn't mark up properly + + if (nDisplayLen > len) // ellipsis + { + *pDst++ = '.'; + *pDst++ = '.'; + *pDst++ = '.'; + } + } + else { // DISPLAY: "max_18_char" + *pDst++ = '"'; + pDst = FormatCharCopy(pDst, pSrc, len); // BUG: #251 v2.8.0.7: ASC #:# with null byte doesn't mark up properly + *pDst++ = '"'; } - } - else { // DISPLAY: "max_18_char" - *pDst++ = '"'; - pDst = FormatCharCopy(pDst, pSrc, len); // BUG: #251 v2.8.0.7: ASC #:# with null byte doesn't mark up properly - *pDst++ = '"'; - } - *pDst = 0; - break; - default: -#if _DEBUG // Unhandled data disassembly! - int* FATAL = 0; - *FATAL = 0xDEADC0DE; -#endif - iByte++; - break; + *pDst = 0; + break; + + default: + #if _DEBUG // Unhandled data disassembly! + int* FATAL = 0; + *FATAL = 0xDEADC0DE; + #endif + iByte++; + break; } } }