1 /*****************************************************************************/
5 /* Segment handling for da65 */
9 /* (C) 2007-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 /*****************************************************************************/
48 /*****************************************************************************/
50 /*****************************************************************************/
54 /* Hash definitions */
57 /* Segment definition */
58 typedef struct Segment Segment;
60 Segment* NextStart; /* Pointer to next segment */
63 char Name[1]; /* Name, dynamically allocated */
66 /* Table containing the segments. A segment is inserted using its hash
67 ** value. Collisions are handled by single-linked lists.
69 static Segment* StartTab[HASH_SIZE]; /* Table containing segment starts */
73 /*****************************************************************************/
75 /*****************************************************************************/
79 void AddAbsSegment (unsigned Start, unsigned End, const char* Name)
80 /* Add an absolute segment to the segment table */
82 /* Get the length of the name */
83 unsigned Len = strlen (Name);
85 /* Create a new segment */
86 Segment* S = xmalloc (sizeof (Segment) + Len);
88 /* Fill in the data */
90 S->AddrSize = ADDR_SIZE_ABS;
91 memcpy (S->Name, Name, Len + 1);
93 /* Insert the segment into the hash table */
94 S->NextStart = StartTab[Start % HASH_SIZE];
95 StartTab[Start % HASH_SIZE] = S;
97 /* Mark start and end of the segment */
98 MarkAddr (Start, atSegmentStart);
99 MarkAddr (End, atSegmentEnd);
101 /* Mark the addresses within the segment */
102 MarkRange (Start, End, atSegment);
107 char* GetSegmentStartName (unsigned Addr)
108 /* Return the name of the segment which starts at the given address */
110 Segment* S = StartTab[Addr % HASH_SIZE];
112 /* Search the collision list for the exact address */
114 if (S->Start == Addr) {
125 unsigned GetSegmentAddrSize (unsigned Addr)
126 /* Return the address size of the segment which starts at the given address */
128 Segment* S = StartTab[Addr % HASH_SIZE];
130 /* Search the collision list for the exact address */
132 if (S->Start == Addr) {