Skip to content

Commit

Permalink
Debugger: Cleanup FormatNopcodeBytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaelangel007 committed Jan 6, 2022
1 parent 7c4855e commit 32ee96f
Showing 1 changed file with 66 additions and 62 deletions.
128 changes: 66 additions & 62 deletions source/Debugger/Debugger_Disassembler.cpp
Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 32ee96f

Please sign in to comment.