]> git.sur5r.net Git - cc65/blob - src/da65/attrtab.c
add gotox, gotoy, and gotoxy
[cc65] / src / da65 / attrtab.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 attrtab.c                                 */
4 /*                                                                           */
5 /*                       Disassembler attribute table                        */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2006 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 /* da65 */
37 #include "error.h"
38 #include "attrtab.h"
39
40
41
42 /*****************************************************************************/
43 /*                                   Data                                    */
44 /*****************************************************************************/
45
46
47
48 /* Attribute table */
49 static unsigned short AttrTab[0x10000];
50
51
52
53 /*****************************************************************************/
54 /*                                   Code                                    */
55 /*****************************************************************************/
56
57
58
59 void AddrCheck (unsigned Addr)
60 /* Check if the given address has a valid range */
61 {
62     if (Addr >= 0x10000) {
63         Error ("Address out of range: %08X", Addr);
64     }
65 }
66
67
68
69 int SegmentDefined (unsigned Start, unsigned End)
70 /* Return true if the atSegment bit is set somewhere in the given range */
71 {
72     while (Start <= End) {
73         if (AttrTab[Start++] & atSegment) {
74             return 1;
75         }
76     }
77     return 0;
78 }
79
80
81
82 int HaveSegmentChange (unsigned Addr)
83 /* Return true if the segment change attribute is set for the given address */
84 {
85     /* Check the given address */
86     AddrCheck (Addr);
87
88     /* Return the attribute */
89     return (AttrTab[Addr] & atSegmentChange) != 0;
90 }
91
92
93
94 unsigned GetGranularity (attr_t Style)
95 /* Get the granularity for the given style */
96 {
97     switch (Style) {
98         case atDefault:  return 1;
99         case atCode:     return 1;
100         case atIllegal:  return 1;
101         case atByteTab:  return 1;
102         case atDByteTab: return 2;
103         case atWordTab:  return 2;
104         case atDWordTab: return 4;
105         case atAddrTab:  return 2;
106         case atRtsTab:   return 2;
107         case atTextTab:  return 1;
108
109         case atSkip:
110         default:
111             Internal ("GetGraularity called for style = %d", Style);
112             return 0;
113     }
114 }
115
116
117
118 void MarkRange (unsigned Start, unsigned End, attr_t Attr)
119 /* Mark a range with the given attribute */
120 {
121     /* Do it easy here... */
122     while (Start <= End) {
123         MarkAddr (Start++, Attr);
124     }
125 }
126
127
128
129 void MarkAddr (unsigned Addr, attr_t Attr)
130 /* Mark an address with an attribute */
131 {
132     /* Check the given address */
133     AddrCheck (Addr);
134
135     /* We must not have more than one style bit */
136     if (Attr & atStyleMask) {
137         if (AttrTab[Addr] & atStyleMask) {
138             Error ("Duplicate style for address %04X", Addr);
139         }
140     }
141
142     /* Set the style */
143     AttrTab[Addr] |= Attr;
144 }
145
146
147
148 attr_t GetAttr (unsigned Addr)
149 /* Return the attribute for the given address */
150 {
151     /* Check the given address */
152     AddrCheck (Addr);
153
154     /* Return the attribute */
155     return AttrTab[Addr];
156 }
157
158
159
160 attr_t GetStyleAttr (unsigned Addr)
161 /* Return the style attribute for the given address */
162 {
163     /* Check the given address */
164     AddrCheck (Addr);
165
166     /* Return the attribute */
167     return (AttrTab[Addr] & atStyleMask);
168 }
169
170
171
172 attr_t GetLabelAttr (unsigned Addr)
173 /* Return the label attribute for the given address */
174 {
175     /* Check the given address */
176     AddrCheck (Addr);
177
178     /* Return the attribute */
179     return (AttrTab[Addr] & atLabelMask);
180 }
181
182
183