AttrTab and RtsTab were not able to handle label within data gracefully. This

should be fixed now (report by Stefan Haubenthal).
Bumped the copyright year.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3593 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2005-08-27 21:33:43 +00:00
parent a7476505a8
commit 7b2cd44f8a
2 changed files with 69 additions and 49 deletions

View File

@@ -158,38 +158,43 @@ unsigned DWordTable (void)
unsigned AddrTable (void) unsigned AddrTable (void)
/* Output a table of addresses */ /* Output a table of addresses */
{ {
unsigned BytesLeft; unsigned long BytesLeft = GetRemainingBytes ();
unsigned long Start = PC;
/* Count how many bytes may be output. */ /* Loop while table bytes left and we don't need to create a label at the
unsigned Count = GetSpan (atAddrTab); * current position.
/* Handle Count == 1 */
if (Count == 1) {
ByteTable ();
}
/* Make the given number even */
Count &= ~1U;
/* Output as many data bytes lines as needed. For addresses, each line
* will hold just one address.
*/ */
BytesLeft = Count; while (BytesLeft && GetStyleAttr (PC) == atAddrTab) {
while (BytesLeft > 0) {
/* Get the address */ unsigned Addr;
unsigned Addr = GetCodeWord (PC);
/* If just one byte is left, define it and bail out */
if (BytesLeft == 1 || GetStyleAttr (PC+1) != atAddrTab) {
DataByteLine (1);
break;
}
/* More than one byte left. Check if there is a label defined within
* the address word.
*/
if (MustDefLabel (PC+1)) {
/* Define the label */
DefineConst (GetLabel (PC+1), GetComment (PC+1), PC+1);
}
/* Now get the address from the PC */
Addr = GetCodeWord (PC);
/* In pass 1, define a label, in pass 2 output the line */ /* In pass 1, define a label, in pass 2 output the line */
if (Pass == 1) { if (Pass == 1) {
if (!HaveLabel (Addr)) { if (!HaveLabel (Addr)) {
AddIntLabel (Addr); AddIntLabel (Addr);
} }
} else { } else {
const char* Label = GetLabel (Addr); const char* Label = GetLabel (Addr);
if (Label == 0) { if (Label == 0) {
/* OOPS! Should not happen */ /* OOPS! Should not happen */
Internal ("OOPS - Label for address 0x%06X disappeard!", Addr); Internal ("OOPS - Label for address 0x%06X disappeard!", Addr);
} }
Indent (MIndent); Indent (MIndent);
Output (".addr"); Output (".addr");
@@ -199,18 +204,23 @@ unsigned AddrTable (void)
LineFeed (); LineFeed ();
} }
/* Next line */ /* Next table entry */
PC += 2; PC += 2;
BytesLeft -= 2; BytesLeft -= 2;
/* If we must define a label here, bail out */
if (MustDefLabel (PC)) {
break;
}
} }
/* If the next line is not a byte table line, add a separator */ /* If the next line is not an address table line, add a separator */
if (CodeLeft() && GetStyleAttr (PC) != atAddrTab) { if (CodeLeft() && GetStyleAttr (PC) != atAddrTab) {
SeparatorLine (); SeparatorLine ();
} }
/* Return the number of bytes output */ /* Return the number of bytes output */
return Count; return PC - Start;
} }
@@ -218,38 +228,43 @@ unsigned AddrTable (void)
unsigned RtsTable (void) unsigned RtsTable (void)
/* Output a table of RTS addresses (address - 1) */ /* Output a table of RTS addresses (address - 1) */
{ {
unsigned BytesLeft; unsigned long BytesLeft = GetRemainingBytes ();
unsigned long Start = PC;
/* Count how many bytes may be output. */ /* Loop while table bytes left and we don't need to create a label at the
unsigned Count = GetSpan (atRtsTab); * current position.
/* Handle Count == 1 */
if (Count == 1) {
ByteTable ();
}
/* Make the given number even */
Count &= ~1U;
/* Output as many data bytes lines as needed. For addresses, each line
* will hold just one address.
*/ */
BytesLeft = Count; while (BytesLeft && GetStyleAttr (PC) == atRtsTab) {
while (BytesLeft > 0) {
/* Get the address */ unsigned Addr;
unsigned Addr = (GetCodeWord (PC) + 1) & 0xFFFF;
/* If just one byte is left, define it and bail out */
if (BytesLeft == 1 || GetStyleAttr (PC+1) != atRtsTab) {
DataByteLine (1);
break;
}
/* More than one byte left. Check if there is a label defined within
* the address word.
*/
if (MustDefLabel (PC+1)) {
/* Define the label */
DefineConst (GetLabel (PC+1), GetComment (PC+1), PC+1);
}
/* Now get the address from the PC */
Addr = (GetCodeWord (PC) + 1) & 0xFFFF;
/* In pass 1, define a label, in pass 2 output the line */ /* In pass 1, define a label, in pass 2 output the line */
if (Pass == 1) { if (Pass == 1) {
if (!HaveLabel (Addr)) { if (!HaveLabel (Addr)) {
AddIntLabel (Addr); AddIntLabel (Addr);
} }
} else { } else {
const char* Label = GetLabel (Addr); const char* Label = GetLabel (Addr);
if (Label == 0) { if (Label == 0) {
/* OOPS! Should not happen */ /* OOPS! Should not happen */
Internal ("OOPS - Label for address 0x%06X disappeard!", Addr); Internal ("OOPS - Label for address 0x%06X disappeard!", Addr);
} }
Indent (MIndent); Indent (MIndent);
Output (".word"); Output (".word");
@@ -259,18 +274,23 @@ unsigned RtsTable (void)
LineFeed (); LineFeed ();
} }
/* Next line */ /* Next table entry */
PC += 2; PC += 2;
BytesLeft -= 2; BytesLeft -= 2;
/* If we must define a label here, bail out */
if (MustDefLabel (PC)) {
break;
}
} }
/* If the next line is not a byte table line, add a separator */ /* If the next line is not a return address table line, add a separator */
if (CodeLeft() && GetStyleAttr (PC) != atRtsTab) { if (CodeLeft() && GetStyleAttr (PC) != atRtsTab) {
SeparatorLine (); SeparatorLine ();
} }
/* Return the number of bytes output */ /* Return the number of bytes output */
return Count; return PC - Start;
} }

View File

@@ -232,7 +232,7 @@ static void OptVersion (const char* Opt attribute ((unused)),
/* Print the disassembler version */ /* Print the disassembler version */
{ {
fprintf (stderr, fprintf (stderr,
"da65 V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n", "da65 V%u.%u.%u - (C) Copyright 2005 Ullrich von Bassewitz\n",
VER_MAJOR, VER_MINOR, VER_PATCH); VER_MAJOR, VER_MINOR, VER_PATCH);
} }