2002-04-06 22:11:09 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* chip.c */
|
|
|
|
/* */
|
|
|
|
/* Interface for the chip plugins */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* (C) 2002 Ullrich von Bassewitz */
|
|
|
|
/* Wacholderweg 14 */
|
|
|
|
/* D-70597 Stuttgart */
|
|
|
|
/* EMail: uz@musoftware.de */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* common */
|
|
|
|
#include "coll.h"
|
2002-04-07 13:42:45 +00:00
|
|
|
#include "print.h"
|
2002-04-06 22:11:09 +00:00
|
|
|
#include "xmalloc.h"
|
|
|
|
|
|
|
|
/* sim65 */
|
2002-04-07 20:00:39 +00:00
|
|
|
#include "chipdata.h"
|
|
|
|
#include "chiplib.h"
|
2002-04-06 22:11:09 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "chip.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Sorted list of all chip data structures */
|
|
|
|
static Collection Chips = STATIC_COLLECTION_INITIALIZER;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Helper functions */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-07 13:42:45 +00:00
|
|
|
static int CmpChips (void* Data attribute ((unused)),
|
2002-04-06 22:11:09 +00:00
|
|
|
const void* lhs, const void* rhs)
|
|
|
|
/* Compare function for CollSort */
|
|
|
|
{
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Cast the object pointers */
|
|
|
|
const Chip* Left = (const Chip*) rhs;
|
|
|
|
const Chip* Right = (const Chip*) lhs;
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Do the compare */
|
|
|
|
return strcmp (Left->Data->ChipName, Right->Data->ChipName);
|
2002-04-06 22:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
static Chip* NewChip (ChipLibrary* Library, const ChipData* Data)
|
2002-04-06 22:11:09 +00:00
|
|
|
/* Allocate a new chip structure, initialize and return it */
|
|
|
|
{
|
|
|
|
/* Allocate memory */
|
|
|
|
Chip* C = xmalloc (sizeof (Chip));
|
|
|
|
|
|
|
|
/* Initialize the fields */
|
2002-04-07 20:00:39 +00:00
|
|
|
C->Library = Library;
|
|
|
|
C->Data = Data;
|
|
|
|
C->Instances = EmptyCollection;
|
2002-04-06 22:11:09 +00:00
|
|
|
|
|
|
|
/* Return the structure */
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void FreeChip (Chip* C)
|
|
|
|
/* ## Free the given chip structure */
|
2002-04-06 22:11:09 +00:00
|
|
|
{
|
|
|
|
/* Free the structure itself */
|
|
|
|
xfree (C);
|
2002-04-07 20:00:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
2002-04-06 22:11:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
void LoadChips (void)
|
|
|
|
/* Load all chips from all libraries */
|
2002-04-06 22:11:09 +00:00
|
|
|
{
|
2002-04-07 20:00:39 +00:00
|
|
|
unsigned I, J;
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Walk through all libraries */
|
|
|
|
for (I = 0; I < CollCount (&ChipLibraries); ++I) {
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Get the library entry */
|
|
|
|
ChipLibrary* L = CollAt (&ChipLibraries, I);
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Create the chips */
|
|
|
|
for (J = 0; J < L->ChipCount; ++J) {
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Get a pointer to the chip data */
|
|
|
|
const ChipData* Data = L->Data + J;
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Check if the chip data has the correct version */
|
|
|
|
if (Data->MajorVersion != CHIPDATA_VER_MAJOR) {
|
|
|
|
Warning ("Version mismatch for `%s' (%s), expected %u, got %u",
|
|
|
|
Data->ChipName, L->LibName,
|
|
|
|
CHIPDATA_VER_MAJOR, Data->MajorVersion);
|
|
|
|
/* Ignore this chip */
|
|
|
|
continue;
|
|
|
|
}
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Generate a new chip and insert it into the collection */
|
|
|
|
CollAppend (&Chips, NewChip (L, Data));
|
|
|
|
}
|
|
|
|
}
|
2002-04-06 22:11:09 +00:00
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* Last act: Sort the chips by name */
|
2002-04-06 22:11:09 +00:00
|
|
|
CollSort (&Chips, CmpChips, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-07 13:42:45 +00:00
|
|
|
const Chip* FindChip (const char* Name)
|
2002-04-06 22:11:09 +00:00
|
|
|
/* Find a chip by name. Returns the Chip data structure or NULL if the chip
|
|
|
|
* could not be found.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|