-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 */
{
-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);
+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 */
} 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:
(((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;
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);