]> git.sur5r.net Git - cc65/commitdiff
More segment support stuff.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 2 Sep 2007 19:49:12 +0000 (19:49 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 2 Sep 2007 19:49:12 +0000 (19:49 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3806 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/da65/attrtab.c
src/da65/attrtab.h
src/da65/data.c
src/da65/labels.c
src/da65/main.c
src/da65/output.c
src/da65/output.h
src/da65/segment.c

index 277ee8b0e9ec083e0c94280e4030dc84518dd9ca..61ed6b440fefdf6f129c6bbcd30297bb114518c9 100644 (file)
@@ -75,7 +75,19 @@ int SegmentDefined (unsigned Start, unsigned End)
         }
     }
     return 0;
-}            
+}
+
+
+
+int HaveSegmentChange (unsigned Addr)
+/* Return true if the segment change attribute is set for the given address */
+{
+    /* Check the given address */
+    AddrCheck (Addr);
+
+    /* Return the attribute */
+    return (AttrTab[Addr] & atSegmentChange) != 0;
+}
 
 
 
@@ -133,6 +145,18 @@ void MarkAddr (unsigned Addr, attr_t Attr)
 
 
 
+attr_t GetAttr (unsigned Addr)
+/* Return the attribute for the given address */
+{
+    /* Check the given address */
+    AddrCheck (Addr);
+
+    /* Return the attribute */
+    return AttrTab[Addr];
+}
+
+
+
 attr_t GetStyleAttr (unsigned Addr)
 /* Return the style attribute for the given address */
 {
index 23413abed09969e36e36cd6e0bbeedea63755234..40a414c2ee855256d12ce49cd4e3831a0956ec57 100644 (file)
@@ -73,6 +73,7 @@ typedef enum attr_t {
 
     /* Segment */
     atSegment       = 0x0100,   /* Code is in a segment */
+    atSegmentChange = 0x0200,   /* Either segment start or segment end */
 } attr_t;
 
 
@@ -89,6 +90,9 @@ void AddrCheck (unsigned Addr);
 int SegmentDefined (unsigned Start, unsigned End);
 /* Return true if the atSegment bit is set somewhere in the given range */
 
+int HaveSegmentChange (unsigned Addr);
+/* Return true if the segment change attribute is set for the given address */
+
 unsigned GetGranularity (attr_t Style);
 /* Get the granularity for the given style */
 
@@ -98,6 +102,9 @@ void MarkRange (unsigned Start, unsigned End, attr_t Attr);
 void MarkAddr (unsigned Addr, attr_t Attr);
 /* Mark an address with an attribute */
 
+attr_t GetAttr (unsigned Addr);
+/* Return the attribute for the given address */
+
 attr_t GetStyleAttr (unsigned Addr);
 /* Return the style attribute for the given address */
 
index 1569f7aee9150d4c41a03f4290fcc5718a35bd52..bafd14e23e8fa2f0fb96e79780e6a0d440743eb9 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2004 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/* (C) 2000-2007 Ullrich von Bassewitz                                       */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
@@ -57,14 +57,22 @@ static unsigned GetSpan (attr_t Style)
     unsigned RemainingBytes = GetRemainingBytes ();
 
     /* Count how many bytes are available. This number is limited by the
-     * number of remaining bytes, a label, or the end of the given Style
-     * attribute.
+     * number of remaining bytes, a label, a segment change, or the end of
+     * the given Style attribute.
      */
     unsigned Count = 1;
     while (Count < RemainingBytes) {
-       if (MustDefLabel(PC+Count) || GetStyleAttr (PC+Count) != Style) {
+        attr_t Attr;
+               if (MustDefLabel(PC+Count)) {
            break;
-       }
+       }           
+        Attr = GetAttr (PC+Count);
+        if ((Attr & atStyleMask) != Style) {
+            break;
+        }
+        if ((Attr & atSegmentChange)) {
+            break;
+        }
        ++Count;
     }
 
index 20f93a98d3a32d2b0f84a929c720c1caaa944721..59c571b499516b581cb772e4445d29152b832d39 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2006      Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/* (C) 2006-2007 Ullrich von Bassewitz                                       */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
@@ -378,7 +378,7 @@ static void DefOutOfRangeLabel (unsigned long Addr)
 
         case atIntLabel:
         case atExtLabel:
-            DefineConst (SymTab[Addr], GetComment (Addr), Addr);
+            DefConst (SymTab[Addr], GetComment (Addr), Addr);
             break;
 
         case atUnnamedLabel:
index a43c564d30c9251f55424ceb67d87b0f20c3590b..83b1784e8b7f62abab9d97115d70f42ab41b4496 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2006 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/* (C) 1998-2007 Ullrich von Bassewitz                                       */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
@@ -385,7 +385,7 @@ static void OneOpcode (unsigned RemainingBytes)
        } else {
            unsigned I;
            for (I = 1; I < D->Size; ++I) {
-               if (HaveLabel (PC+I)) {
+               if (HaveLabel (PC+I) || HaveSegmentChange (PC+I)) {
                    Style = atIllegal;
                    MarkAddr (PC, Style);
                    break;
index 5b68eae880c877424b22f057f808c94576c289b6..3b4ffe47fd39753bd1122a1ec21810fa34ebd864 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2006 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/* (C) 2000-2007 Ullrich von Bassewitz                                       */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
@@ -40,6 +40,7 @@
 #include <errno.h>
 
 /* common */
+#include "addrsize.h"
 #include "cpu.h"
 #include "version.h"
 
@@ -199,7 +200,7 @@ void DefForward (const char* Name, const char* Comment, unsigned Offs)
 
 
 
-void DefineConst (const char* Name, const char* Comment, unsigned Addr)
+void DefConst (const char* Name, const char* Comment, unsigned Addr)
 /* Define an address constant */
 {
     if (Pass == PassCount) {
@@ -216,6 +217,23 @@ void DefineConst (const char* Name, const char* Comment, unsigned Addr)
 
 
 
+void StartSegment (const char* Name, unsigned AddrSize)
+/* Start a segment */
+{
+    if (Pass == PassCount) {
+        Output (".segment");
+        Indent (ACol);
+        if (AddrSize == ADDR_SIZE_DEFAULT) {
+            Output ("\"%s\"", Name);
+        } else {
+            Output ("\"%s\": %s", Name, AddrSizeToStr (AddrSize));
+        }
+        LineFeed ();
+    }
+}
+
+
+
 void DataByteLine (unsigned ByteCount)
 /* Output a line with bytes */
 {
index 8aba0ff87710d7604d6d9093d7ae4532d5466d1b..37c0915c8d68ee97196f079aad6d40cfbe0c25dc 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2003 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/* (C) 2000-2007 Ullrich von Bassewitz                                       */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
@@ -67,13 +67,19 @@ void LineFeed (void);
 void DefLabel (const char* Name);
 /* Define a label with the given name */
 
-void DefForward (const char* Name, const char* Comment, unsigned Offs);                
+void DefForward (const char* Name, const char* Comment, unsigned Offs);
 /* Define a label as "* + x", where x is the offset relative to the
  * current PC.
  */
 
-void DefineConst (const char* Name, const char* Comment, unsigned Addr);
+void DefConst (const char* Name, const char* Comment, unsigned Addr);
 /* Define an address constant */
+        
+void StartSegment (const char* Name, unsigned AddrSize);
+/* Start a segment */
+
+void EndSegment (void);
+/* End a segment */
 
 void OneDataByte (void);
 /* Output a .byte line with the current code byte */
index e648a36184d5ae7dfc0abb6353d5d05acc0df5a7..1098efdc4d5ed81c78fbd50b69e3d35806c0a63e 100644 (file)
@@ -52,8 +52,7 @@
 
 
 /* Hash definitions */
-#define HASH_SIZE       64              /* Must be power of two */
-#define HASH_MASK       (HASH_SIZE-1)
+#define HASH_SIZE       53
 
 /* Segment definition */
 typedef struct Segment Segment;
@@ -96,10 +95,14 @@ void AddAbsSegment (unsigned Start, unsigned End, const char* Name)
     memcpy (S->Name, Name, Len + 1);
 
     /* Insert the segment into the hash tables */
-    S->NextStart = StartTab[Start & HASH_MASK];
-    StartTab[Start & HASH_MASK] = S;
-    S->NextEnd = EndTab[End & HASH_MASK];
-    EndTab[End & HASH_MASK] = S;
+    S->NextStart = StartTab[Start % HASH_SIZE];
+    StartTab[Start % HASH_SIZE] = S;
+    S->NextEnd = EndTab[End % HASH_SIZE];
+    EndTab[End % HASH_SIZE] = S;
+
+    /* Mark start and end of the segment */
+    MarkAddr (Start, atSegmentChange);
+    MarkAddr (End, atSegmentChange);
 
     /* Mark the addresses within the segment */
     MarkRange (Start, End, atSegment);