]> git.sur5r.net Git - cc65/blobdiff - src/ld65/xex.c
Only write full ATARI XEX header in the first chunk.
[cc65] / src / ld65 / xex.c
index 71065ea5755f26c742b63b2ac4f560f83cc7b521..9d373fb36324517ebc5e9839ffb69c604eef7e91 100644 (file)
@@ -64,6 +64,7 @@ struct XexDesc {
     unsigned    Undef;          /* Count of undefined externals */
     FILE*       F;              /* Output file */
     const char* Filename;       /* Name of output file */
+    Import*     RunAd;          /* Run Address */
 };
 
 
@@ -84,6 +85,7 @@ XexDesc* NewXexDesc (void)
     D->Undef    = 0;
     D->F        = 0;
     D->Filename = 0;
+    D->RunAd    = 0;
 
     /* Return the created struct */
     return D;
@@ -99,6 +101,14 @@ void FreeXexDesc (XexDesc* D)
 
 
 
+void XexSetRunAd (XexDesc* D, Import *RunAd)
+/* Set the RUNAD export */
+{
+    D->RunAd = RunAd;
+}
+
+
+
 static unsigned XexWriteExpr (ExprNode* E, int Signed, unsigned Size,
                               unsigned long Offs attribute ((unused)),
                               void* Data)
@@ -173,7 +183,8 @@ static void XexWriteMem (XexDesc* D, MemoryArea* M)
     }
 
     /* Write header */
-    Write16(D->F, 0xFFFF);
+    if (ftell (D->F) == 0)
+        Write16(D->F, 0xFFFF);
     Write16(D->F, M->Start);
     Write16(D->F, Addr-1);
 
@@ -273,6 +284,7 @@ static void XexWriteMem (XexDesc* D, MemoryArea* M)
         WriteMult (D->F, M->FillVal, ToFill);
         M->FillLevel = M->Size;
     }
+
 }
 
 
@@ -325,6 +337,13 @@ void XexWriteTarget (XexDesc* D, struct File* F)
         XexWriteMem (D, M);
     }
 
+    /* Write RUNAD at file end */
+    if (D->RunAd) {
+        Write16 (D->F, 0x2E0);
+        Write16 (D->F, 0x2E1);
+        Write16 (D->F, GetExportVal (D->RunAd->Exp));
+    }
+
     /* Close the file */
     if (fclose (D->F) != 0) {
         Error ("Cannot write to `%s': %s", D->Filename, strerror (errno));