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");
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;
}
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");
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;
}