From d21616ea71f052620186a2fd66a72288da2b188c Mon Sep 17 00:00:00 2001 From: paul moore Date: Sat, 2 Dec 2023 09:16:49 -0800 Subject: [PATCH] initial commit --- src/ca65/global.c | 1 + src/ca65/global.h | 1 + src/ca65/listing.c | 27 +++++++++++++++++++++------ src/ca65/listing.h | 4 +++- src/ca65/main.c | 10 +++++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/ca65/global.c b/src/ca65/global.c index 050d19e09..f31379bbb 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -69,6 +69,7 @@ unsigned char RelaxChecks = 0; /* Relax a few assembler checks */ unsigned char StringEscapes = 0; /* Allow C-style escapes in strings */ unsigned char LongJsrJmpRts = 0; /* Allow JSR/JMP/RTS as alias for JSL/JML/RTL */ unsigned char WarningsAsErrors = 0; /* Error if any warnings */ +unsigned char SegList = 0; /* Emulation features */ unsigned char DollarIsPC = 0; /* Allow the $ symbol as current PC */ diff --git a/src/ca65/global.h b/src/ca65/global.h index b3de99df5..508cf8e02 100644 --- a/src/ca65/global.h +++ b/src/ca65/global.h @@ -71,6 +71,7 @@ extern unsigned char RelaxChecks; /* Relax a few assembler checks */ extern unsigned char StringEscapes; /* Allow C-style escapes in strings */ extern unsigned char LongJsrJmpRts; /* Allow JSR/JMP/RTS as alias for JSL/JML/RTL */ extern unsigned char WarningsAsErrors; /* Error if any warnings */ +extern unsigned char SegList; /* Emulation features */ extern unsigned char DollarIsPC; /* Allow the $ symbol as current PC */ diff --git a/src/ca65/listing.c b/src/ca65/listing.c index 9f2396612..4dbce881c 100644 --- a/src/ca65/listing.c +++ b/src/ca65/listing.c @@ -73,7 +73,7 @@ static unsigned ListBytes = 12; /* Number of bytes to list for one line /* Switch the listing on/off */ static int ListingEnabled = 1; /* Enabled if > 0 */ - +static int EverReloc = 0; /*****************************************************************************/ @@ -105,6 +105,7 @@ void NewListingLine (const StrBuf* Line, unsigned char File, unsigned char Depth L->Next = 0; L->FragList = 0; L->FragLast = 0; + L->Seg = ActiveSeg->Num; L->PC = GetPC (); L->Reloc = GetRelocMode (); L->File = File; @@ -121,6 +122,7 @@ void NewListingLine (const StrBuf* Line, unsigned char File, unsigned char Depth LineLast->Next = L; } LineLast = L; + EverReloc = EverReloc || L->Reloc; } } @@ -181,6 +183,7 @@ void InitListingLine (void) L = L->Next; /* Set the values for this line */ CHECK (L != 0); + L->Seg = ActiveSeg->Num; L->PC = GetPC (); L->Reloc = GetRelocMode (); L->Output = (ListingEnabled > 0); @@ -191,6 +194,7 @@ void InitListingLine (void) /* Set the values for this line */ CHECK (LineCur != 0); + LineCur->Seg = ActiveSeg->Num; LineCur->PC = GetPC (); LineCur->Reloc = GetRelocMode (); LineCur->Output = (ListingEnabled > 0); @@ -276,7 +280,7 @@ static char* MakeLineHeader (char* H, const ListLine* L) { char Mode; char Depth; - + unsigned Offset = 0; /* Setup the PC mode */ Mode = (L->Reloc)? 'r' : ' '; @@ -284,8 +288,18 @@ static char* MakeLineHeader (char* H, const ListLine* L) Depth = (L->Depth < 10)? L->Depth + '0' : '+'; /* Format the line */ - sprintf (H, "%06lX%c %c", L->PC, Mode, Depth); - memset (H+9, ' ', LINE_HEADER_LEN-9); + if (!SegList) { + Offset = 9; + sprintf (H, "%06lX%c %c", L->PC, Mode, Depth); + }else if (L->Reloc){ + Offset = 12; + sprintf (H, "%02X.%06lX%c %c",L->Seg, L->PC, Mode, Depth); + } else { + Offset = 12; + sprintf (H, " %06lX%c %c", L->PC, Mode, Depth); + + } + memset (H + Offset, ' ', LINE_HEADER_LEN - Offset - (SegList?0:3)); /* Return the buffer */ return H; @@ -314,7 +328,8 @@ void CreateListing (void) PrintPageHeader (F, LineList); /* Terminate the header buffer. The last byte will never get overwritten */ - HeaderBuf [LINE_HEADER_LEN] = '\0'; + + HeaderBuf [(SegList ? LINE_HEADER_LEN : LINE_HEADER_LEN -3)] = '\0'; /* Walk through all listing lines */ L = LineList; @@ -426,7 +441,7 @@ void CreateListing (void) L->PC += Chunk; /* Copy the bytes into the line */ - P = HeaderBuf + 11; + P = HeaderBuf + (SegList?14: 11); for (I = 0; I < Chunk; ++I) { *P++ = *B++; *P++ = *B++; diff --git a/src/ca65/listing.h b/src/ca65/listing.h index b1ae44291..466fa9c6a 100644 --- a/src/ca65/listing.h +++ b/src/ca65/listing.h @@ -60,7 +60,8 @@ struct StrBuf; /* Length of the header of a listing line */ -#define LINE_HEADER_LEN 24 +#define LINE_HEADER_LEN 27 +static unsigned LineHeaderLen = 24; /* One listing line as it is stored in memory */ typedef struct ListLine ListLine; @@ -68,6 +69,7 @@ struct ListLine { ListLine* Next; /* Pointer to next line */ Fragment* FragList; /* List of fragments for this line */ Fragment* FragLast; /* Last entry in fragment list */ + unsigned Seg; /* Which segment this line targets */ unsigned long PC; /* Program counter for this line */ unsigned char Reloc; /* Relocatable mode? */ unsigned char File; /* From which file is the line? */ diff --git a/src/ca65/main.c b/src/ca65/main.c index 3ec6c84ee..3c9ee1f50 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -661,7 +661,12 @@ static void OptVersion (const char* Opt attribute ((unused)), exit(EXIT_SUCCESS); } - +static void OptSeglist (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) + /* Enable segment listing */ +{ + SegList = 1; +} static void OptWarningsAsErrors (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) @@ -1069,6 +1074,9 @@ int main (int argc, char* argv []) case 'W': WarnLevel = atoi (GetArg (&I, 2)); break; + case 'S': + OptSeglist (Arg, 0); + break; default: UnknownOption (Arg);