]> git.sur5r.net Git - cc65/blobdiff - src/ld65/config.c
Finish support for .BANK.
[cc65] / src / ld65 / config.c
index c4a9f3d9cb83a8683b3625e61beb8486d25204d4..54d88e6b8a0e8401e30e58fae97225fc9d166618 100644 (file)
@@ -47,6 +47,7 @@
 #include "bitops.h"
 #include "check.h"
 #include "print.h"
+#include "segdefs.h"
 #include "xmalloc.h"
 #include "xsprintf.h"
 
@@ -1816,6 +1817,9 @@ unsigned CfgProcess (void)
            /* Get the segment */
            SegDesc* S = CollAtUnchecked (&M->SegList, J);
 
+            /* Remember the start address before handling this segment */
+            unsigned long StartAddr = Addr;
+
             /* Some actions depend on wether this is the load or run memory
              * area.
              */
@@ -1866,11 +1870,11 @@ unsigned CfgProcess (void)
                     Addr = NewAddr;
                 }
 
-                /* If the segment has .BANK expressions referring to it, it 
-                 * must be placed into a memory area that has the bank 
+                /* If the segment has .BANK expressions referring to it, it
+                 * must be placed into a memory area that has the bank
                  * attribute.
                  */
-                if (S->Seg->BankRef && M->BankExpr == 0) {
+                if ((S->Seg->Flags & SEG_FLAG_BANKREF) != 0 && M->BankExpr == 0) {
                     CfgError (GetSourcePos (S->LI),
                               "Segment `%s' is refered to by .BANK, but the "
                               "memory area `%s' it is placed into has no BANK "
@@ -1931,6 +1935,11 @@ unsigned CfgProcess (void)
            /* Calculate the new address */
            Addr += S->Seg->Size;
 
+            /* If this segment goes out to the file, increase the file size */
+            if ((S->Flags & SF_BSS) == 0 && S->Load == M) {
+                M->F->Size += Addr - StartAddr;
+            }
+
        }
 
        /* If requested, define symbols for start, size and offset of the
@@ -1963,11 +1972,11 @@ unsigned CfgProcess (void)
             SB_Done (&Buf);
        }
 
-        /* Grow the file by the size of the memory area */
-        if (M->Flags & MF_FILL) {
-            M->F->Size += M->Size;
-        } else {
-            M->F->Size += M->FillLevel;
+        /* If we didn't have an overflow and are requested to fill the memory
+         * area, acount for that in the file size.
+         */
+        if ((M->Flags & MF_OVERFLOW) == 0 && (M->Flags & MF_FILL) != 0) {
+            M->F->Size += (M->Size - M->FillLevel);
         }
     }