1 /*****************************************************************************/
5 /* Disassembler attribute table */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
59 static unsigned char AttrTab [0x10000];
62 static const char* SymTab [0x10000];
66 /*****************************************************************************/
68 /*****************************************************************************/
72 void AddrCheck (unsigned Addr)
73 /* Check if the given address has a valid range */
75 if (Addr >= 0x10000) {
76 Error ("Address out of range: %08X", Addr);
82 void MarkRange (unsigned Start, unsigned End, attr_t Attr)
83 /* Mark a range with the given attribute */
85 /* Do it easy here... */
86 while (Start <= End) {
87 MarkAddr (Start++, Attr);
93 void MarkAddr (unsigned Addr, attr_t Attr)
94 /* Mark an address with an attribute */
96 /* Check the given address */
99 /* We must not have more than one style bit */
100 if (Attr & atStyleMask) {
101 if (AttrTab[Addr] & atStyleMask) {
102 Error ("Duplicate style for address %04X", Addr);
107 AttrTab[Addr] |= Attr;
112 const char* MakeLabelName (unsigned Addr)
113 /* Make the default label name from the given address and return it in a
117 static char LabelBuf [32];
118 xsprintf (LabelBuf, sizeof (LabelBuf), "L%04X", Addr);
124 void AddLabel (unsigned Addr, attr_t Attr, const char* Name)
127 /* Get an existing label attribute */
128 attr_t ExistingAttr = GetLabelAttr (Addr);
130 /* Must not have two symbols for one address */
131 if (ExistingAttr != atNoLabel) {
132 /* Allow redefinition if identical */
133 if (ExistingAttr == Attr && strcmp (SymTab[Addr], Name) == 0) {
136 Error ("Duplicate label for address %04X: %s/%s", Addr, SymTab[Addr], Name);
139 /* Create a new label */
140 SymTab[Addr] = xstrdup (Name);
142 /* Remember the attribute */
143 AttrTab[Addr] |= Attr;
148 int HaveLabel (unsigned Addr)
149 /* Check if there is a label for the given address */
151 /* Check the given address */
154 /* Check for a label */
155 return (SymTab[Addr] != 0);
160 int MustDefLabel (unsigned Addr)
161 /* Return true if we must define a label for this address, that is, if there
162 * is a label at this address, and it is an external or internal label.
165 /* Get the label attribute */
166 attr_t A = GetLabelAttr (Addr);
168 /* Check for an internal or external label */
169 return (A == atExtLabel || A == atIntLabel);
174 const char* GetLabel (unsigned Addr)
175 /* Return the label for an address */
177 /* Check the given address */
180 /* Return the label if any */
186 unsigned char GetStyleAttr (unsigned Addr)
187 /* Return the style attribute for the given address */
189 /* Check the given address */
192 /* Return the attribute */
193 return (AttrTab[Addr] & atStyleMask);
198 unsigned char GetLabelAttr (unsigned Addr)
199 /* Return the label attribute for the given address */
201 /* Check the given address */
204 /* Return the attribute */
205 return (AttrTab[Addr] & atLabelMask);
210 static void DefineConst (unsigned Addr)
211 /* Define an address constant */
213 Output ("%s", SymTab [Addr]);
215 Output ("= $%04X", Addr);
221 void DefOutOfRangeLabels (void)
222 /* Output any labels that are out of the loaded code range */
229 for (Addr = 0; Addr < CodeStart; ++Addr) {
230 if (MustDefLabel (Addr)) {
236 for (Addr = CodeEnd+1; Addr < 0x10000; ++Addr) {
237 if (MustDefLabel (Addr)) {