Add local labels to listings

This commit is contained in:
drmortalwombat 2023-03-09 21:04:56 +01:00
parent efff725745
commit 5bd4f4e9a5
4 changed files with 62 additions and 12 deletions

View File

@ -684,6 +684,15 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba
AsmInsData d = DecInsData[opcode];
int addr = 0;
if (proc && proc->mLinkerObject)
{
int i = 0;
while (i < proc->mLinkerObject->mRanges.Size() && iip - start != proc->mLinkerObject->mRanges[i].mOffset)
i++;
if (i < proc->mLinkerObject->mRanges.Size())
fprintf(file, ".%s:\n", proc->mLinkerObject->mRanges[i].mIdent->mString);
}
if (bank)
fprintf(file, "%02x:", bank);
@ -698,29 +707,29 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba
break;
case ASMIM_ZERO_PAGE:
addr = memory[ip++];
fprintf(file, "%04x : %02x %02x __ %s %s %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x __ %s %s %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker));
break;
case ASMIM_ZERO_PAGE_X:
addr = memory[ip++];
fprintf(file, "%04x : %02x %02x __ %s %s,x %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x __ %s %s,x %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker));
break;
case ASMIM_ZERO_PAGE_Y:
addr = memory[ip++];
fprintf(file, "%04x : %02x %02x __ %s %s,y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x __ %s %s,y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker));
break;
case ASMIM_ABSOLUTE:
addr = memory[ip] + 256 * memory[ip + 1];
fprintf(file, "%04x : %02x %02x %02x %s $%04x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x %02x %s $%04x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker));
ip += 2;
break;
case ASMIM_ABSOLUTE_X:
addr = memory[ip] + 256 * memory[ip + 1];
fprintf(file, "%04x : %02x %02x %02x %s $%04x,x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x %02x %s $%04x,x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker));
ip += 2;
break;
case ASMIM_ABSOLUTE_Y:
addr = memory[ip] + 256 * memory[ip + 1];
fprintf(file, "%04x : %02x %02x %02x %s $%04x,y %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x %02x %s $%04x,y %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker));
ip += 2;
break;
case ASMIM_INDIRECT:
@ -730,11 +739,11 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba
break;
case ASMIM_INDIRECT_X:
addr = memory[ip++];
fprintf(file, "%04x : %02x %02x __ %s (%s,x) %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x __ %s (%s,x) %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker));
break;
case ASMIM_INDIRECT_Y:
addr = memory[ip++];
fprintf(file, "%04x : %02x %02x __ %s (%s),y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker));
fprintf(file, "%04x : %02x %02x __ %s (%s),y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker));
break;
case ASMIM_RELATIVE:
addr = memory[ip++];
@ -742,18 +751,24 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba
addr = addr + ip - 256;
else
addr = addr + ip;
fprintf(file, "%04x : %02x %02x __ %s $%04x\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], addr);
fprintf(file, "%04x : %02x %02x __ %s $%04x %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker));
break;
}
}
}
const char* NativeCodeDisassembler::AddrName(int addr, char* buffer, Linker* linker)
const char* NativeCodeDisassembler::AddrName(int addr, char* buffer, InterCodeProcedure* proc, Linker* linker)
{
if (linker)
{
LinkerObject* obj = linker->FindObjectByAddr(addr);
LinkerObject* obj;
if (proc && proc->mLinkerObject && addr >= proc->mLinkerObject->mAddress && addr < proc->mLinkerObject->mAddress + proc->mLinkerObject->mSize)
obj = proc->mLinkerObject;
else
obj = linker->FindObjectByAddr(addr);
if (obj && obj->mIdent)
{
int i = 0;

View File

@ -31,7 +31,7 @@ public:
void DumpMemory(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident* ident, Linker* linker, LinkerObject * lobj);
protected:
const char* TempName(uint8 tmp, char* buffer, InterCodeProcedure* proc, Linker* linker);
const char* AddrName(int addr, char* buffer, Linker* linker);
const char* AddrName(int addr, char* buffer, InterCodeProcedure* proc, Linker* linker);
};

View File

@ -965,19 +965,41 @@ bool Linker::WriteMlbFile(const char* filename)
if ((obj->mFlags & LOBJF_REFERENCED) && obj->mIdent && obj->mSize > 0)
{
if (obj->mSection->mType == LST_BSS)
{
if (obj->mRanges.Size() > 0)
{
for(int i=0; i<obj->mRanges.Size(); i++)
fprintf(file, "R:%04x-%04x:%s@%s\n", obj->mAddress + obj->mRanges[i].mOffset, obj->mAddress + obj->mRanges[i].mOffset + obj->mRanges[i].mSize - 1, obj->mIdent->mString, obj->mRanges[i].mIdent->mString);
}
fprintf(file, "R:%04x-%04x:%s\n", obj->mAddress, obj->mAddress + obj->mSize - 1, obj->mIdent->mString);
}
else if (obj->mType == LOT_DATA)
{
if (!obj->mRegion->mCartridgeBanks)
{
if (obj->mRanges.Size() > 0)
{
for (int i = 0; i < obj->mRanges.Size(); i++)
fprintf(file, "P:%04x-%04x:%s@%s\n", obj->mAddress + obj->mRanges[i].mOffset - 0x8000, obj->mAddress + obj->mRanges[i].mOffset + obj->mRanges[i].mSize - 0x8000 - 1, obj->mIdent->mString, obj->mRanges[i].mIdent->mString);
}
fprintf(file, "P:%04x-%04x:%s\n", obj->mAddress - 0x8000, obj->mAddress - 0x8000 + obj->mSize - 1, obj->mIdent->mString);
}
}
else if (obj->mType == LOT_NATIVE_CODE)
{
if (!obj->mRegion->mCartridgeBanks)
{
if (obj->mRanges.Size() > 0)
{
for (int i = 0; i < obj->mRanges.Size(); i++)
fprintf(file, "P:%04x:%s@%s\n", obj->mAddress + obj->mRanges[i].mOffset - 0x8000, obj->mIdent->mString, obj->mRanges[i].mIdent->mString);
}
fprintf(file, "P:%04x:%s\n", obj->mAddress - 0x8000, obj->mIdent->mString);
}
}
}
}
fclose(file);

View File

@ -37227,7 +37227,20 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc)
uint8* data = proc->mLinkerObject->AddSpace(total);
for (int i = 0; i < placement.Size(); i++)
{
LinkerObjectRange range;
char buffer[100];
if (placement[i]->mLoopHead)
sprintf_s(buffer, "l%d", placement[i]->mIndex);
else
sprintf_s(buffer, "s%d", placement[i]->mIndex);
range.mIdent = Ident::Unique(buffer);
range.mOffset = placement[i]->mOffset;
range.mSize = placement[i]->mSize;
proc->mLinkerObject->mRanges.Push(range);
placement[i]->CopyCode(this, data);
}
for (int i = 0; i < mRelocations.Size(); i++)