Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
audetto committed Jan 6, 2022
2 parents e8fe81c + aa4af5e commit f557566
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 72 deletions.
2 changes: 1 addition & 1 deletion source/Debugger/Debug.cpp
Expand Up @@ -3361,7 +3361,7 @@ Update_t CmdDisk ( int nArgs)
if (nArgs > 2)
return HelpLastCommand();

char buffer[200] = "";
char buffer[200] = ""; // HACK: Magic number TODO: Should be MAX_CONSOLE_WIDTH*2
ConsoleBufferPushFormat(buffer, "FW%2d: D%d at T$%s, phase $%s, offset $%X, mask $%02X, extraCycles %.2f, %s",
diskCard.GetCurrentFirmware(),
diskCard.GetCurrentDrive() + 1,
Expand Down
1 change: 1 addition & 0 deletions source/Debugger/Debugger_Assembler.cpp
Expand Up @@ -509,6 +509,7 @@ int _6502_GetOpmodeOpbyte ( const int nBaseAddress, int & iOpmode_, int & nOpby
case NOP_BYTE_2: nOpbyte_ = 2; iOpmode_ = AM_M; break;
case NOP_BYTE_4: nOpbyte_ = 4; iOpmode_ = AM_M; break;
case NOP_BYTE_8: nOpbyte_ = 8; iOpmode_ = AM_M; break;
case NOP_FAC : nOpbyte_ = 5; iOpmode_ = AM_M; break;
case NOP_WORD_1: nOpbyte_ = 2; iOpmode_ = AM_M; break;
case NOP_WORD_2: nOpbyte_ = 4; iOpmode_ = AM_M; break;
case NOP_WORD_4: nOpbyte_ = 8; iOpmode_ = AM_M; break;
Expand Down
1 change: 1 addition & 0 deletions source/Debugger/Debugger_Assembler.h
Expand Up @@ -100,6 +100,7 @@
,NUM_ASM_W_DIRECTIVES
};

// NOTE: Keep in sync! AsmCustomDirective_e g_aAssemblerDirectives
enum AsmCustomDirective_e
{
ASM_DEFINE_BYTE
Expand Down
4 changes: 2 additions & 2 deletions source/Debugger/Debugger_Commands.cpp
Expand Up @@ -140,15 +140,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
{TEXT("DW2") , CmdDisasmDataDefWord2 , CMD_DEFINE_DATA_WORD2, "Define address array, display 2 words/line" },
{TEXT("DW4") , CmdDisasmDataDefWord4 , CMD_DEFINE_DATA_WORD4, "Define address array, display 4 words/line" },
{TEXT("ASC") , CmdDisasmDataDefString , CMD_DEFINE_DATA_STR , "Define text string" }, // 2.7.0.26 Changed: DS to ASC because DS is used as "Define Space" assembler directive
// {TEXT("DF") , CmdDisasmDataDefFloat , CMD_DEFINE_DATA_FLOAT, "Define AppleSoft (packed) Float" },
{TEXT("DF") , CmdDisasmDataDefFloat , CMD_DEFINE_DATA_FLOAT, "Define AppleSoft (packed) Float" },
// {TEXT("DFX") , CmdDisasmDataDefFloatUnpack , CMD_DEFINE_DATA_FLOAT2,"Define AppleSoft (unpacked) Float" },
// with symbol lookup
// {TEXT("DA<>") , CmdDisasmDataDefAddress8HL , CMD_DEFINE_ADDR_8_HL , "Define split array of addresses, high byte section followed by low byte section" },
// {TEXT("DA><") , CmdDisasmDataDefAddress8LH , CMD_DEFINE_ADDR_8_LH , "Define split array of addresses, low byte section followed by high byte section" },
// {TEXT("DA<") , CmdDisasmDataDefAddress8H , CMD_DEFINE_ADDR_BYTE_H , "Define array of high byte addresses" },
// {TEXT("DB>") , CmdDisasmDataDefAddress8L , CMD_DEFINE_ADDR_BYTE_L , "Define array of low byte addresses" }
{TEXT("DA") , CmdDisasmDataDefAddress16 , CMD_DEFINE_ADDR_WORD , "Define array of word addresses" },
// TODO: Rename config cmd: DISASM
// TODO: Rename config cmd: DISASM or ID (Interactive Disassembly)
// {TEXT("UA") , CmdDisasmDataSmart , CMD_SMART_DISASSEMBLE, "Analyze opcodes to determine if code or data" },
// Disk
{TEXT("DISK") , CmdDisk , CMD_DISK , "Access Disk Drive Functions" },
Expand Down
184 changes: 122 additions & 62 deletions source/Debugger/Debugger_Disassembler.cpp
Expand Up @@ -466,92 +466,152 @@ void FormatOpcodeBytes(WORD nBaseAddress, DisasmLine_t& line_)
}
}

struct FAC_t
{
uint8_t negative;
int8_t exponent;
uint32_t mantissa;

bool isZero;
};

void FAC_Unpack(WORD nAddress, FAC_t& fac_)
{
BYTE e0 = *(LPBYTE)(mem + nAddress + 0);
BYTE m1 = *(LPBYTE)(mem + nAddress + 1);
BYTE m2 = *(LPBYTE)(mem + nAddress + 2);
BYTE m3 = *(LPBYTE)(mem + nAddress + 3);
BYTE m4 = *(LPBYTE)(mem + nAddress + 4);

// sign
// EB82:A5 9D SIGN LDA FAC
// EB84:F0 09 BEQ SIGN3 ; zero
// EB86:A5 A2 SIGN1 LDA FAC.SIGN
// EB88:2A SIGN2 ROL
// EB89:A9 FF LDA #$FF ; negative
// EB8B:B0 02 BCS SIGN3
// EB8D:A9 01 LDA #$01 ; positive
// EB8F:60 SIGN3

fac_.exponent = e0 - 0x80;
fac_.negative =(m1 & 0x80) >> 7; // EBAF:46 A2 ABS LSR FAC.SIGN
fac_.mantissa = 0
| ((m1 | 0x80) << 24) // implicit 1.0, EB12: ORA #$80, STA FAC+1
| ((m2 ) << 16)
| ((m3 ) << 8)
| ((m4 ) << 0);

fac_.isZero = (e0 == 0); // TODO: need to check mantissa?
}


// Formats Target string with bytes,words, string, etc...
//===========================================================================
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)
if (iByte < line_.nOpbyte)
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_FAC:
{
FAC_t fac;
FAC_Unpack( nBaseAddress, fac );
const char aSign[2] = { '+', '-' };
if (fac.isZero)
sprintf( pDst, "0" );
else
{
*pDst++ = ',';
double f = fac.mantissa * pow( 2.0, fac.exponent - 32 );
//sprintf( "s%1X m%04X e%02X", fac.negative, fac.mantissa, fac.exponent );
sprintf( pDst, "%c%f", aSign[ fac.negative ], f );
}
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++ = ',';
iByte += 5;
break;
}
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
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++ = '.';
*pDst++ = '.';
*pDst++ = '.';
*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
{
*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 f557566

Please sign in to comment.