]> git.sur5r.net Git - cc65/blobdiff - src/ld65/bin.c
Revert "atari5200: fix COLOR defines' names"
[cc65] / src / ld65 / bin.c
index 568269b39a0d9e4d3c523c5486d43a8bfbe2a8bb..6886224159ac20039af80da801301b2e2bdab7e7 100644 (file)
@@ -106,8 +106,8 @@ static unsigned BinWriteExpr (ExprNode* E, int Signed, unsigned Size,
                               unsigned long Offs attribute ((unused)),
                               void* Data)
 /* Called from SegWrite for an expression. Evaluate the expression, check the
- * range and write the expression value to the file.
- */
+** range and write the expression value to the file.
+*/
 {
     /* There's a predefined function to handle constant expressions */
     return SegWriteConstExpr (((BinDesc*)Data)->F, E, Signed, Size);
@@ -154,7 +154,7 @@ static void BinWriteMem (BinDesc* D, MemoryArea* M)
         SegDesc* S = CollAtUnchecked (&M->SegList, I);
 
         /* Keep the user happy */
-        Print (stdout, 1, "    Writing `%s'\n", GetString (S->Name));
+        Print (stdout, 1, "    Writing '%s'\n", GetString (S->Name));
 
         /* Writes do only occur in the load area and not for BSS segments */
         DoWrite = (S->Flags & SF_BSS) == 0      &&      /* No BSS segment */
@@ -169,24 +169,12 @@ static void BinWriteMem (BinDesc* D, MemoryArea* M)
         PrintNumVal  ("Address", Addr);
         PrintNumVal  ("FileOffs", (unsigned long) ftell (D->F));
 
-        /* Check if the alignment for the segment from the linker config is
-         * a multiple for that of the segment.
-         */
-        if ((S->RunAlignment % S->Seg->Alignment) != 0) {
-            /* Segment requires another alignment than configured
-             * in the linker.
-             */
-            Warning ("Segment `%s' is not aligned properly. Resulting "
-                     "executable may not be functional.",
-                     GetString (S->Name));
-        }
-
         /* If this is the run memory area, we must apply run alignment. If
-         * this is not the run memory area but the load memory area (which
-         * means that both are different), we must apply load alignment.
-         * Beware: DoWrite may be true even if this is the run memory area,
-         * because it may be also the load memory area.
-         */
+        ** this is not the run memory area but the load memory area (which
+        ** means that both are different), we must apply load alignment.
+        ** Beware: DoWrite may be true even if this is the run memory area,
+        ** because it may be also the load memory area.
+        */
         if (S->Run == M) {
 
             /* Handle ALIGN and OFFSET/START */
@@ -205,8 +193,13 @@ static void BinWriteMem (BinDesc* D, MemoryArea* M)
                     NewAddr += M->Start;
                 }
                 if (DoWrite || (M->Flags & MF_FILL) != 0) {
-                    WriteMult (D->F, M->FillVal, NewAddr-Addr);
-                    PrintNumVal ("SF_OFFSET", NewAddr - Addr);
+                    /* Seek in "overwrite" segments */
+                    if (S->Flags & SF_OVERWRITE) {
+                        fseek (D->F, NewAddr - M->Start, SEEK_SET);
+                    } else {
+                        WriteMult (D->F, M->FillVal, NewAddr-Addr);
+                        PrintNumVal ("SF_OFFSET", NewAddr - Addr);
+                    }
                 }
                 Addr = NewAddr;
             }
@@ -227,8 +220,8 @@ static void BinWriteMem (BinDesc* D, MemoryArea* M)
         }
 
         /* Now write the segment to disk if it is not a BSS type segment and
-         * if the memory area is the load area.
-         */
+        ** if the memory area is the load area.
+        */
         if (DoWrite) {
             unsigned long P = ftell (D->F);
             SegWrite (D->Filename, D->F, S->Seg, BinWriteExpr, D);
@@ -263,9 +256,9 @@ static int BinUnresolved (unsigned Name attribute ((unused)), void* D)
 /* Called if an unresolved symbol is encountered */
 {
     /* Unresolved symbols are an error in binary format. Bump the counter
-     * and return zero telling the caller that the symbol is indeed
-     * unresolved.
-     */
+    ** and return zero telling the caller that the symbol is indeed
+    ** unresolved.
+    */
     ((BinDesc*) D)->Undef++;
     return 0;
 }
@@ -281,8 +274,8 @@ void BinWriteTarget (BinDesc* D, struct File* F)
     D->Filename = GetString (F->Name);
 
     /* Check for unresolved symbols. The function BinUnresolved is called
-     * if we get an unresolved symbol.
-     */
+    ** if we get an unresolved symbol.
+    */
     D->Undef = 0;               /* Reset the counter */
     CheckUnresolvedImports (BinUnresolved, D);
     if (D->Undef > 0) {
@@ -293,23 +286,23 @@ void BinWriteTarget (BinDesc* D, struct File* F)
     /* Open the file */
     D->F = fopen (D->Filename, "wb");
     if (D->F == 0) {
-        Error ("Cannot open `%s': %s", D->Filename, strerror (errno));
+        Error ("Cannot open '%s': %s", D->Filename, strerror (errno));
     }
 
     /* Keep the user happy */
-    Print (stdout, 1, "Opened `%s'...\n", D->Filename);
+    Print (stdout, 1, "Opened '%s'...\n", D->Filename);
 
     /* Dump all memory areas */
     for (I = 0; I < CollCount (&F->MemoryAreas); ++I) {
         /* Get this entry */
         MemoryArea* M = CollAtUnchecked (&F->MemoryAreas, I);
-        Print (stdout, 1, "  Dumping `%s'\n", GetString (M->Name));
+        Print (stdout, 1, "  Dumping '%s'\n", GetString (M->Name));
         BinWriteMem (D, M);
     }
 
     /* Close the file */
     if (fclose (D->F) != 0) {
-        Error ("Cannot write to `%s': %s", D->Filename, strerror (errno));
+        Error ("Cannot write to '%s': %s", D->Filename, strerror (errno));
     }
 
     /* Reset the file and filename */