1 /*****************************************************************************/
5 /* Segment handling for da65 */
9 /* (C) 2007 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 */
61 Segment* NextEnd; /* Pointer to next segment */
65 char Name[1]; /* Name, dynamically allocated */
68 /* Tables containing the segments. A segment is inserted using it's hash
69 * value. Collision is done by single linked lists.
71 static Segment* StartTab[HASH_SIZE]; /* Table containing segment starts */
72 static Segment* EndTab[HASH_SIZE]; /* Table containing segment ends */
76 /*****************************************************************************/
78 /*****************************************************************************/
82 void AddAbsSegment (unsigned Start, unsigned End, const char* Name)
83 /* Add an absolute segment to the segment table */
85 /* Get the length of the name */
86 unsigned Len = strlen (Name);
88 /* Create a new segment */
89 Segment* S = xmalloc (sizeof (Segment) + Len);
91 /* Fill in the data */
94 S->AddrSize = ADDR_SIZE_ABS;
95 memcpy (S->Name, Name, Len + 1);
97 /* Insert the segment into the hash tables */
98 S->NextStart = StartTab[Start % HASH_SIZE];
99 StartTab[Start % HASH_SIZE] = S;
100 S->NextEnd = EndTab[End % HASH_SIZE];
101 EndTab[End % HASH_SIZE] = S;
103 /* Mark start and end of the segment */
104 MarkAddr (Start, atSegmentChange);
105 MarkAddr (End, atSegmentChange);
107 /* Mark the addresses within the segment */
108 MarkRange (Start, End, atSegment);