1 /*****************************************************************************/
5 /* Disassembler attribute table */
9 /* (C) 2000-2014, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
42 /*****************************************************************************/
44 /*****************************************************************************/
49 static unsigned short AttrTab[0x10000];
53 /*****************************************************************************/
55 /*****************************************************************************/
59 void AddrCheck (unsigned Addr)
60 /* Check if the given address has a valid range */
62 if (Addr >= 0x10000) {
63 Error ("Address out of range: %08X", Addr);
69 attr_t GetAttr (unsigned Addr)
70 /* Return the attribute for the given address */
72 /* Check the given address */
75 /* Return the attribute */
81 int SegmentDefined (unsigned Start, unsigned End)
82 /* Return true if the atSegment bit is set somewhere in the given range */
84 while (Start <= End) {
85 if (AttrTab[Start++] & atSegment) {
94 int IsSegmentEnd (unsigned Addr)
95 /* Return true if a segment ends at the given address */
97 return (GetAttr (Addr) & atSegmentEnd) != 0x0000;
102 int IsSegmentStart (unsigned Addr)
103 /* Return true if a segment starts at the given address */
105 return (GetAttr (Addr) & atSegmentStart) != 0x0000;
110 int HaveSegmentChange (unsigned Addr)
111 /* Return true if the segment change attributes are set for the given address */
113 return (GetAttr (Addr) & (atSegmentStart | atSegmentEnd)) != 0x0000;
118 unsigned GetGranularity (attr_t Style)
119 /* Get the granularity for the given style */
122 case atDefault: return 1;
123 case atCode: return 1;
124 case atIllegal: return 1;
125 case atByteTab: return 1;
126 case atDByteTab: return 2;
127 case atWordTab: return 2;
128 case atDWordTab: return 4;
129 case atAddrTab: return 2;
130 case atRtsTab: return 2;
131 case atTextTab: return 1;
135 Internal ("GetGraularity called for style = %d", Style);
142 void MarkRange (unsigned Start, unsigned End, attr_t Attr)
143 /* Mark a range with the given attribute */
145 /* Do it easy here... */
146 while (Start <= End) {
147 MarkAddr (Start++, Attr);
153 void MarkAddr (unsigned Addr, attr_t Attr)
154 /* Mark an address with an attribute */
156 /* Check the given address */
159 /* We must not have more than one style bit */
160 if (Attr & atStyleMask) {
161 if (AttrTab[Addr] & atStyleMask) {
162 Error ("Duplicate style for address %04X", Addr);
167 AttrTab[Addr] |= Attr;
172 attr_t GetStyleAttr (unsigned Addr)
173 /* Return the style attribute for the given address */
175 /* Check the given address */
178 /* Return the attribute */
179 return (AttrTab[Addr] & atStyleMask);
184 attr_t GetLabelAttr (unsigned Addr)
185 /* Return the label attribute for the given address */
187 /* Check the given address */
190 /* Return the attribute */
191 return (AttrTab[Addr] & atLabelMask);