1 /*****************************************************************************/
5 /* Interface for the chip plugins */
9 /* (C) 2002 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 /*****************************************************************************/
51 /*****************************************************************************/
53 /*****************************************************************************/
57 /* Sorted list of all chip data structures */
58 static Collection Chips = STATIC_COLLECTION_INITIALIZER;
60 /* SimData instance */
61 static const SimData Sim65Data = {
64 xmalloc, /* void* (*Malloc) (size_t Size); */
65 Warning, /* void (*Warning) (const char* Format, ...); */
66 Error /* void (*Error) (const char* Format, ...); */
71 /*****************************************************************************/
72 /* Helper functions */
73 /*****************************************************************************/
77 static int CmpChips (void* Data attribute ((unused)),
78 const void* lhs, const void* rhs)
79 /* Compare function for CollSort */
81 /* Cast the object pointers */
82 const Chip* Left = (const Chip*) rhs;
83 const Chip* Right = (const Chip*) lhs;
86 return strcmp (Left->Data->ChipName, Right->Data->ChipName);
91 /*****************************************************************************/
93 /*****************************************************************************/
97 static Chip* NewChip (ChipLibrary* Library, const ChipData* Data)
98 /* Allocate a new chip structure, initialize and return it */
100 /* Allocate memory */
101 Chip* C = xmalloc (sizeof (Chip));
103 /* Initialize the fields */
104 C->Library = Library;
106 C->Instances = EmptyCollection;
108 /* Return the structure */
115 static void FreeChip (Chip* C)
116 /* ## Free the given chip structure */
118 /* Free the structure itself */
125 void LoadChips (void)
126 /* Load all chips from all libraries */
130 /* Walk through all libraries */
131 for (I = 0; I < CollCount (&ChipLibraries); ++I) {
133 /* Get the library entry */
134 ChipLibrary* L = CollAt (&ChipLibraries, I);
136 /* Create the chips */
137 for (J = 0; J < L->ChipCount; ++J) {
139 /* Get a pointer to the chip data */
140 const ChipData* Data = L->Data + J;
142 /* Check if the chip data has the correct version */
143 if (Data->MajorVersion != CHIPDATA_VER_MAJOR) {
144 Warning ("Version mismatch for `%s' (%s), expected %u, got %u",
145 Data->ChipName, L->LibName,
146 CHIPDATA_VER_MAJOR, Data->MajorVersion);
147 /* Ignore this chip */
151 /* Generate a new chip and insert it into the collection */
152 CollAppend (&Chips, NewChip (L, Data));
154 /* Output chip name and version to keep the user happy */
156 "Found chip `%s' version %u.%u\n",
163 /* Last act: Sort the chips by name */
164 CollSort (&Chips, CmpChips, 0);
169 const Chip* FindChip (const char* Name)
170 /* Find a chip by name. Returns the Chip data structure or NULL if the chip
171 * could not be found.
176 /* ## We do a linear search for now */
177 for (I = 0; I < CollCount (&Chips); ++I) {
179 /* Get the chip at this position */
180 const Chip* C = CollConstAt (&Chips, I);
182 /* Compare the name */
183 if (strcmp (Name, C->Data->ChipName) == 0) {