]> git.sur5r.net Git - cc65/blobdiff - src/da65/attrtab.c
add gotox, gotoy, and gotoxy
[cc65] / src / da65 / attrtab.c
index d19b474fbbe4ad4dfb81580641ed47b3505739a2..07a47b72e7210d9da194a813e03a3b6a9843d219 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                attrtab.c                                 */
+/*                                 attrtab.c                                 */
 /*                                                                           */
-/*                      Disassembler attribute table                        */
+/*                       Disassembler attribute table                        */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-2006 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 
-#include <stdio.h>
-#include <string.h>
-
-/* common */
-#include "xmalloc.h"
-#include "xsprintf.h"
-
 /* da65 */
 #include "error.h"
 #include "attrtab.h"
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
 
 /* Attribute table */
-static unsigned char AttrTab [0x10000];
-
-/* Symbol table */
-static const char* SymTab [0x10000];
+static unsigned short AttrTab[0x10000];
 
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -70,107 +60,123 @@ void AddrCheck (unsigned Addr)
 /* Check if the given address has a valid range */
 {
     if (Addr >= 0x10000) {
-       Error ("Address out of range: %08X", Addr);
+        Error ("Address out of range: %08X", Addr);
     }
 }
 
 
 
-void MarkRange (unsigned Start, unsigned End, attr_t Attr)
-/* Mark a range with the given attribute */
+int SegmentDefined (unsigned Start, unsigned End)
+/* Return true if the atSegment bit is set somewhere in the given range */
 {
-    /* Do it easy here... */
     while (Start <= End) {
-       MarkAddr (Start++, Attr);
+        if (AttrTab[Start++] & atSegment) {
+            return 1;
+        }
     }
+    return 0;
 }
 
 
 
-void MarkAddr (unsigned Addr, attr_t Attr)
-/* Mark an address with an attribute */
+int HaveSegmentChange (unsigned Addr)
+/* Return true if the segment change attribute is set for the given address */
 {
     /* Check the given address */
     AddrCheck (Addr);
 
-    /* We must not have more than one style bit */
-    if (Attr & atStyleMask) {
-       if (AttrTab[Addr] & atStyleMask) {
-           Error ("Duplicate style for address %04X", Addr);
-       }
-    }
+    /* Return the attribute */
+    return (AttrTab[Addr] & atSegmentChange) != 0;
+}
 
-    /* Set the style */
-    AttrTab[Addr] |= Attr;
+
+
+unsigned GetGranularity (attr_t Style)
+/* Get the granularity for the given style */
+{
+    switch (Style) {
+        case atDefault:  return 1;
+        case atCode:     return 1;
+        case atIllegal:  return 1;
+        case atByteTab:  return 1;
+        case atDByteTab: return 2;
+        case atWordTab:  return 2;
+        case atDWordTab: return 4;
+        case atAddrTab:  return 2;
+        case atRtsTab:   return 2;
+        case atTextTab:  return 1;
+
+        case atSkip:
+        default:
+            Internal ("GetGraularity called for style = %d", Style);
+            return 0;
+    }
 }
 
 
 
-const char* MakeLabelName (unsigned Addr)
-/* Make the default label name from the given address and return it in a
- * static buffer.
- */
+void MarkRange (unsigned Start, unsigned End, attr_t Attr)
+/* Mark a range with the given attribute */
 {
-    static char LabelBuf [32];
-    xsprintf (LabelBuf, sizeof (LabelBuf), "L%04X", Addr);
-    return LabelBuf;
+    /* Do it easy here... */
+    while (Start <= End) {
+        MarkAddr (Start++, Attr);
+    }
 }
 
 
 
-void AddLabel (unsigned Addr, const char* Name)
-/* Add a label */
+void MarkAddr (unsigned Addr, attr_t Attr)
+/* Mark an address with an attribute */
 {
     /* Check the given address */
     AddrCheck (Addr);
 
-    /* Must not have two symbols for one address */
-    if (SymTab[Addr] != 0) {
-       if (strcmp (SymTab[Addr], Name) == 0) {
-           /* Allow label if it has the same name */
-           return;
-       }
-       Error ("Duplicate label for address %04X: %s/%s", Addr, SymTab[Addr], Name);
+    /* We must not have more than one style bit */
+    if (Attr & atStyleMask) {
+        if (AttrTab[Addr] & atStyleMask) {
+            Error ("Duplicate style for address %04X", Addr);
+        }
     }
 
-    /* Create a new label */
-    SymTab[Addr] = xstrdup (Name);        
+    /* Set the style */
+    AttrTab[Addr] |= Attr;
 }
 
 
 
-int HaveLabel (unsigned Addr)
-/* Check if there is a label for the given address */
+attr_t GetAttr (unsigned Addr)
+/* Return the attribute for the given address */
 {
     /* Check the given address */
     AddrCheck (Addr);
 
-    /* Check for a label */
-    return (SymTab[Addr] != 0);
+    /* Return the attribute */
+    return AttrTab[Addr];
 }
 
 
 
-const char* GetLabel (unsigned Addr)
-/* Return the label for an address */
+attr_t GetStyleAttr (unsigned Addr)
+/* Return the style attribute for the given address */
 {
     /* Check the given address */
     AddrCheck (Addr);
 
-    /* Return the label if any */
-    return SymTab[Addr];
+    /* Return the attribute */
+    return (AttrTab[Addr] & atStyleMask);
 }
 
 
 
-unsigned char GetStyle (unsigned Addr)
-/* Return the style attribute for the given address */
+attr_t GetLabelAttr (unsigned Addr)
+/* Return the label attribute for the given address */
 {
     /* Check the given address */
     AddrCheck (Addr);
 
     /* Return the attribute */
-    return (AttrTab[Addr] & atStyleMask);
+    return (AttrTab[Addr] & atLabelMask);
 }