Ejemplo n.º 1
0
static void GenerateLabel (unsigned Flags, unsigned Addr)
/* Generate a label in pass one if requested */
{
    /* Generate labels in pass #1, and only if we don't have a label already */
    if (Pass == 1 && !HaveLabel (Addr) &&
	/* Check if we must create a label */
       	((Flags & flGenLabel) != 0 ||
       	 ((Flags & flUseLabel) != 0 && Addr >= CodeStart && Addr <= CodeEnd))) {

	/* As a special case, handle ranges with tables or similar. Within
	 * such a range with a granularity > 1, do only generate dependent
	 * labels for all addresses but the first one. Be sure to generate
	 * a label for the start of the range, however.
	 */
	attr_t Style         = GetStyleAttr (Addr);
	unsigned Granularity = GetGranularity (Style);

	if (Granularity == 1) {
	    /* Just add the label */
	    AddIntLabel (Addr);
	} else {

            /* THIS CODE IS A MESS AND WILL FAIL ON SEVERAL CONDITIONS! ### */


	    /* Search for the start of the range or the last non dependent
	     * label in the range.
	     */
	    unsigned Offs;
	    attr_t LabelAttr;
	    unsigned LabelAddr = Addr;
	    while (LabelAddr > CodeStart) {

		if (Style != GetStyleAttr (LabelAddr-1)) {
		    /* End of range reached */
		    break;
		}
		--LabelAddr;
		LabelAttr = GetLabelAttr (LabelAddr);
		if ((LabelAttr & (atIntLabel|atExtLabel)) != 0) {
		    /* The address has an internal or external label */
		    break;
		}
	    }

	    /* If the proposed label address doesn't have a label, define one */
	    if ((GetLabelAttr (LabelAddr) & (atIntLabel|atExtLabel)) == 0) {
		AddIntLabel (LabelAddr);
	    }

	    /* Create the label */
	    Offs = Addr - LabelAddr;
	    if (Offs == 0) {
		AddIntLabel (Addr);
	    } else {
	     	AddDepLabel (Addr, atIntLabel, GetLabelName (LabelAddr), Offs);
	    }
	}
    }
}
Ejemplo n.º 2
0
void DefOutOfRangeLabels (void)
/* Output any labels that are out of the loaded code range */
{
    unsigned long Addr;

    SeparatorLine ();

    /* Low range */
    Addr = 0;
    while (Addr < CodeStart) {
        DefOutOfRangeLabel (Addr++);
    }

    /* Skip areas in code range */
    while (Addr <= CodeEnd) {
        if (GetStyleAttr (Addr) == atSkip) {
            DefOutOfRangeLabel (Addr);
        }
        ++Addr;
    }

    /* High range */
    while (Addr < 0x10000) {
        DefOutOfRangeLabel (Addr++);
    }

    SeparatorLine ();
}
Ejemplo n.º 3
0
static unsigned DoTable (attr_t Style, unsigned MemberSize, void (*TableFunc) (unsigned))
/* Output a table of bytes */
{
    unsigned BytesLeft;

    /* Count how many bytes may be output. */
    unsigned Count = GetSpan (Style);

    /* If the count is less than the member size, print a row of Count data
    ** bytes. We assume here that there is no member with a size that is less
    ** than BytesPerLine.
    */
    if (Count < MemberSize) {
        DataByteLine (Count);
        PC += Count;
        return Count;
    }

    /* Make Count an even number of multiples of MemberSize */
    Count &= ~(MemberSize-1);

    /* Output as many data bytes lines as needed */
    BytesLeft = Count;
    while (BytesLeft > 0) {

        /* Calculate the number of bytes for the next line */
        unsigned Chunk = (BytesLeft > BytesPerLine)? BytesPerLine : BytesLeft;

        /* Output a line with these bytes */
        TableFunc (Chunk);

        /* Next line */
        BytesLeft -= Chunk;
        PC        += Chunk;
    }

    /* If the next line is not the same style, add a separator */
    if (CodeLeft() && GetStyleAttr (PC) != Style) {
        SeparatorLine ();
    }

    /* Return the number of bytes output */
    return Count;
}
Ejemplo n.º 4
0
unsigned TextTable (void)
/* Output a table of text messages */
{
    /* Count how many bytes may be output. */
    unsigned ByteCount = GetSpan (atTextTab);

    /* Output as many data bytes lines as needed. */
    unsigned BytesLeft = ByteCount;
    while (BytesLeft > 0) {

        unsigned I;

        /* Count the number of characters that can be output as such */
        unsigned Count = 0;
        while (Count < BytesLeft && Count < BytesPerLine*4-1) {
            unsigned char C = GetCodeByte (PC + Count);
            if (C >= 0x20 && C <= 0x7E && C != '\"') {
                ++Count;
            } else {
                break;
            }
        }

        /* If we have text, output it */
        if (Count > 0) {
            unsigned CBytes;
            Indent (MCol);
            Output (".byte");
            Indent (ACol);
            Output ("\"");
            for (I = 0; I < Count; ++I) {
                Output ("%c", GetCodeByte (PC+I));
            }
            Output ("\"");
            CBytes = Count;
            while (CBytes > 0) {
                unsigned Chunk = CBytes;
                if (Chunk > BytesPerLine) {
                    Chunk = BytesPerLine;
                }
                LineComment (PC, Chunk);
                LineFeed ();
                CBytes -= Chunk;
                PC += Chunk;
            }
            BytesLeft -= Count;
        }

        /* Count the number of bytes that must be output as bytes */
        Count = 0;
        while (Count < BytesLeft && Count < BytesPerLine) {
            unsigned char C = GetCodeByte (PC + Count);
            if (C < 0x20 || C > 0x7E || C == '\"') {
                ++Count;
            } else {
                break;
            }
        }

        /* If we have raw output bytes, print them */
        if (Count > 0) {
            DataByteLine (Count);
            PC += Count;
            BytesLeft -= Count;
        }

    }

    /* If the next line is not a byte table line, add a separator */
    if (CodeLeft() && GetStyleAttr (PC) != atTextTab) {
        SeparatorLine ();
    }

    /* Return the number of bytes output */
    return ByteCount;
}
Ejemplo n.º 5
0
unsigned RtsTable (void)
/* Output a table of RTS addresses (address - 1) */
{
    unsigned long BytesLeft = GetRemainingBytes ();
    unsigned long Start = PC;

    /* Loop while table bytes left and we don't need to create a label at the
    ** current position.
    */
    while (BytesLeft && GetStyleAttr (PC) == atRtsTab) {

        unsigned Addr;

        /* If just one byte is left, define it and bail out */
        if (BytesLeft == 1 || GetStyleAttr (PC+1) != atRtsTab) {
            DataByteLine (1);
            ++PC;
            break;
        }

        /* More than one byte left. Define a forward label if necessary */
        ForwardLabel (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 */
        if (Pass == 1) {
            if (!HaveLabel (Addr)) {
                AddIntLabel (Addr);
            }
        } else {
            const char* Label = GetLabel (Addr, PC);
            if (Label == 0) {
                /* OOPS! Should not happen */
                Internal ("OOPS - Label for address 0x%06X disappeard!", Addr);
            }
            Indent (MCol);
            Output (".word");
            Indent (ACol);
            Output ("%s-1", Label);
            LineComment (PC, 2);
            LineFeed ();
        }

        /* Next table entry */
        PC        += 2;
        BytesLeft -= 2;

        /* If we must define a label here, bail out */
        if (BytesLeft && MustDefLabel (PC)) {
            break;
        }
    }

    /* 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 PC - Start;
}