From: cuz Date: Fri, 21 Jan 2005 10:35:50 +0000 (+0000) Subject: Fixed zeropage segment declaration (syntax had changed some time ago). X-Git-Tag: V2.12.0~466 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c68a75ceb40e50f60cf29fb3aa0a25c23eace377;p=cc65 Fixed zeropage segment declaration (syntax had changed some time ago). Added support for exports. git-svn-id: svn://svn.cc65.org/cc65/trunk@3370 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/co65/convert.c b/src/co65/convert.c index bf50fb539..ef05b6ba0 100644 --- a/src/co65/convert.c +++ b/src/co65/convert.c @@ -101,49 +101,6 @@ static void SetupSegLabels (FILE* F) -static void ConvertImports (FILE* F, const O65Data* D) -/* Convert the imports */ -{ - unsigned I; - - if (CollCount (&D->Imports) > 0) { - for (I = 0; I < CollCount (&D->Imports); ++I) { - - /* Get the next import */ - const O65Import* Import = CollConstAt (&D->Imports, I); - - /* Import it by name */ - fprintf (F, ".import\t%s\n", Import->Name); - } - fprintf (F, "\n"); - } -} - - - -static void ConvertExports (FILE* F, const O65Data* D) -/* Convert the exports */ -{ - unsigned I; - - if (CollCount (&D->Exports) > 0) { - for (I = 0; I < CollCount (&D->Exports); ++I) { - - /* Get the next import */ - const O65Export* Export = CollConstAt (&D->Exports, I); - - /* First define it */ - fprintf (F, "%s = XXX\n", Export->Name); /* ### */ - - /* Then export it by name */ - fprintf (F, ".export\t%s\n", Export->Name); - } - fprintf (F, "\n"); - } -} - - - static const char* LabelPlusOffs (const char* Label, long Offs) /* Generate "Label+xxx" in a static buffer and return a pointer to the buffer */ { @@ -154,19 +111,29 @@ static const char* LabelPlusOffs (const char* Label, long Offs) -static const char* RelocExpr (const O65Data* D, const O65Reloc* R, unsigned long Val) -/* Generate the segment relative relocation expression */ +static const char* RelocExpr (const O65Data* D, unsigned char SegID, + unsigned long Val, const O65Reloc* R) +/* Generate the segment relative relocation expression. R is only used if the + * expression contains am import, and may be NULL if this is an error (which + * is then flagged). + */ { const O65Import* Import; - switch (R->SegID) { + switch (SegID) { case O65_SEGID_UNDEF: - if (R->SymIdx >= CollCount (&D->Imports)) { - Error ("Import index out of range (input file corrupt)"); + if (R) { + if (R->SymIdx >= CollCount (&D->Imports)) { + Error ("Import index out of range (input file corrupt)"); + } + Import = CollConstAt (&D->Imports, R->SymIdx); + return LabelPlusOffs (Import->Name, Val); + } else { + Error ("Relocation references an import which is not allowed here"); + return 0; } - Import = CollConstAt (&D->Imports, R->SymIdx); - return LabelPlusOffs (Import->Name, Val); + break; case O65_SEGID_TEXT: return LabelPlusOffs (CodeLabel, Val - D->Header.tbase); @@ -193,6 +160,51 @@ static const char* RelocExpr (const O65Data* D, const O65Reloc* R, unsigned long +static void ConvertImports (FILE* F, const O65Data* D) +/* Convert the imports */ +{ + unsigned I; + + if (CollCount (&D->Imports) > 0) { + for (I = 0; I < CollCount (&D->Imports); ++I) { + + /* Get the next import */ + const O65Import* Import = CollConstAt (&D->Imports, I); + + /* Import it by name */ + fprintf (F, ".import\t%s\n", Import->Name); + } + fprintf (F, "\n"); + } +} + + + +static void ConvertExports (FILE* F, const O65Data* D) +/* Convert the exports */ +{ + unsigned I; + + if (CollCount (&D->Exports) > 0) { + for (I = 0; I < CollCount (&D->Exports); ++I) { + + /* Get the next import */ + const O65Export* Export = CollConstAt (&D->Exports, I); + + /* First define it */ + fprintf (F, "%s = %s\n", + Export->Name, + RelocExpr (D, Export->SegID, Export->Val, 0)); + + /* Then export it by name */ + fprintf (F, ".export\t%s\n", Export->Name); + } + fprintf (F, "\n"); + } +} + + + static void ConvertSeg (FILE* F, const O65Data* D, const Collection* Relocs, const unsigned char* Data, unsigned long Size) /* Convert one segment */ @@ -222,18 +234,18 @@ static void ConvertSeg (FILE* F, const O65Data* D, const Collection* Relocs, } else { Val = (Data[Byte+1] << 8) + Data[Byte]; Byte += 2; - fprintf (F, "\t.word\t%s\n", RelocExpr (D, R, Val)); + fprintf (F, "\t.word\t%s\n", RelocExpr (D, R->SegID, Val, R)); } break; case O65_RTYPE_HIGH: Val = (Data[Byte++] << 8) + R->Val; - fprintf (F, "\t.byte\t>(%s)\n", RelocExpr (D, R, Val)); + fprintf (F, "\t.byte\t>(%s)\n", RelocExpr (D, R->SegID, Val, R)); break; case O65_RTYPE_LOW: Val = Data[Byte++]; - fprintf (F, "\t.byte\t<(%s)\n", RelocExpr (D, R, Val)); + fprintf (F, "\t.byte\t<(%s)\n", RelocExpr (D, R->SegID, Val, R)); break; case O65_RTYPE_SEGADDR: @@ -245,7 +257,7 @@ static void ConvertSeg (FILE* F, const O65Data* D, const Collection* Relocs, (((unsigned long) Data[Byte+0]) << 0) + R->Val; Byte += 3; - fprintf (F, "\t.faraddr\t%s\n", RelocExpr (D, R, Val)); + fprintf (F, "\t.faraddr\t%s\n", RelocExpr (D, R->SegID, Val, R)); } break; @@ -342,7 +354,7 @@ static void ConvertZeropageSeg (FILE* F, const O65Data* D) fprintf (F, "%s = __ZP_START__\n", ZeropageLabel); } else { /* Header */ - fprintf (F, ".segment\t\"%s\", zeropage\n%s:\n", ZeropageSeg, ZeropageLabel); + fprintf (F, ".segment\t\"%s\": zeropage\n%s:\n", ZeropageSeg, ZeropageLabel); /* Segment data */ fprintf (F, "\t.res\t%lu\n", D->Header.zlen);