From 7b2cd44f8ab3024defb5ca0fa686f19f23abeb2f Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 27 Aug 2005 21:33:43 +0000 Subject: [PATCH] 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 --- src/da65/data.c | 108 ++++++++++++++++++++++++++++-------------------- src/da65/main.c | 2 +- 2 files changed, 65 insertions(+), 45 deletions(-) diff --git a/src/da65/data.c b/src/da65/data.c index 98f303d62..2d68816e5 100644 --- a/src/da65/data.c +++ b/src/da65/data.c @@ -158,38 +158,43 @@ unsigned DWordTable (void) unsigned AddrTable (void) /* Output a table of addresses */ { - unsigned BytesLeft; + unsigned long BytesLeft = GetRemainingBytes (); + unsigned long Start = PC; - /* Count how many bytes may be output. */ - unsigned Count = GetSpan (atAddrTab); + /* Loop while table bytes left and we don't need to create a label at the + * current position. + */ + while (BytesLeft && GetStyleAttr (PC) == atAddrTab) { - /* Handle Count == 1 */ - if (Count == 1) { - ByteTable (); - } + unsigned Addr; - /* Make the given number even */ - Count &= ~1U; + /* If just one byte is left, define it and bail out */ + if (BytesLeft == 1 || GetStyleAttr (PC+1) != atAddrTab) { + DataByteLine (1); + break; + } - /* Output as many data bytes lines as needed. For addresses, each line - * will hold just one address. - */ - BytesLeft = Count; - while (BytesLeft > 0) { + /* 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); + } - /* Get the address */ - unsigned Addr = GetCodeWord (PC); + /* Now get the address from the PC */ + Addr = GetCodeWord (PC); /* In pass 1, define a label, in pass 2 output the line */ if (Pass == 1) { if (!HaveLabel (Addr)) { - AddIntLabel (Addr); + AddIntLabel (Addr); } } else { const char* Label = GetLabel (Addr); if (Label == 0) { - /* OOPS! Should not happen */ - Internal ("OOPS - Label for address 0x%06X disappeard!", Addr); + /* OOPS! Should not happen */ + Internal ("OOPS - Label for address 0x%06X disappeard!", Addr); } Indent (MIndent); Output (".addr"); @@ -199,18 +204,23 @@ unsigned AddrTable (void) LineFeed (); } - /* Next line */ + /* Next table entry */ PC += 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) { SeparatorLine (); } /* Return the number of bytes output */ - return Count; + return PC - Start; } @@ -218,38 +228,43 @@ unsigned AddrTable (void) unsigned RtsTable (void) /* 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. */ - unsigned Count = GetSpan (atRtsTab); + /* Loop while table bytes left and we don't need to create a label at the + * current position. + */ + while (BytesLeft && GetStyleAttr (PC) == atRtsTab) { - /* Handle Count == 1 */ - if (Count == 1) { - ByteTable (); - } + unsigned Addr; - /* Make the given number even */ - Count &= ~1U; + /* If just one byte is left, define it and bail out */ + if (BytesLeft == 1 || GetStyleAttr (PC+1) != atRtsTab) { + DataByteLine (1); + break; + } - /* Output as many data bytes lines as needed. For addresses, each line - * will hold just one address. - */ - BytesLeft = Count; - while (BytesLeft > 0) { + /* 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); + } - /* Get the address */ - unsigned Addr = (GetCodeWord (PC) + 1) & 0xFFFF; + /* Now get the address from the PC */ + Addr = (GetCodeWord (PC) + 1) & 0xFFFF; /* In pass 1, define a label, in pass 2 output the line */ if (Pass == 1) { if (!HaveLabel (Addr)) { - AddIntLabel (Addr); + AddIntLabel (Addr); } } else { const char* Label = GetLabel (Addr); if (Label == 0) { - /* OOPS! Should not happen */ - Internal ("OOPS - Label for address 0x%06X disappeard!", Addr); + /* OOPS! Should not happen */ + Internal ("OOPS - Label for address 0x%06X disappeard!", Addr); } Indent (MIndent); Output (".word"); @@ -259,18 +274,23 @@ unsigned RtsTable (void) LineFeed (); } - /* Next line */ + /* Next table entry */ PC += 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) { SeparatorLine (); } /* Return the number of bytes output */ - return Count; + return PC - Start; } diff --git a/src/da65/main.c b/src/da65/main.c index 1051c7488..673cf868f 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -232,7 +232,7 @@ static void OptVersion (const char* Opt attribute ((unused)), /* Print the disassembler version */ { 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); } -- 2.39.5