]> git.sur5r.net Git - cc65/blobdiff - src/sim65/chip.c
Working
[cc65] / src / sim65 / chip.c
index 57e920616bc5c00460412ea2bc92caa83608495e..80dd42cb8dc492bbbc535547e1bcb5708968df87 100644 (file)
 /* sim65 */
 #include "cfgdata.h"
 #include "chipdata.h"
+#include "cpucore.h"
 #include "error.h"
 #include "chip.h"
 
 
 
+/*****************************************************************************/
+/*                                 Forwards                                  */
+/*****************************************************************************/
+
+
+
+static int GetCfgId (void* CfgInfo, const char* Name, char** Id);
+/* Search CfgInfo for an attribute with the given name and type "id". If
+ * found, remove it from the configuration, pass a pointer to a dynamically
+ * allocated string containing the value to Id, and return true. If not
+ * found, return false. The memory passed in Id must be free by a call to
+ * Free();
+ */
+
+static int GetCfgStr (void* CfgInfo, const char* Name, char** S);
+/* Search CfgInfo for an attribute with the given name and type "id". If
+ * found, remove it from the configuration, pass a pointer to a dynamically
+ * allocated string containing the value to Id, and return true. If not
+ * found, return false. The memory passed in S must be free by a call to
+ * Free();
+ */
+
+static int GetCfgNum (void* CfgInfo, const char* Name, long* Val);
+/* Search CfgInfo for an attribute with the given name and type "number".
+ * If found, remove it from the configuration, copy it into Val and return
+ * true. If not found, return false.
+ */
+
+
+
 /*****************************************************************************/
 /*                                     Data                                  */
 /*****************************************************************************/
@@ -71,9 +102,10 @@ static const SimData Sim65Data = {
     Warning,
     Error,
     Internal,
-    CfgDataGetId,
-    CfgDataGetStr,
-    CfgDataGetNum
+    Break,
+    GetCfgId,
+    GetCfgStr,
+    GetCfgNum
 };
 
 
@@ -84,6 +116,43 @@ static const SimData Sim65Data = {
 
 
 
+static int GetCfgId (void* CfgInfo, const char* Name, char** Id)
+/* Search CfgInfo for an attribute with the given name and type "id". If
+ * found, remove it from the configuration, pass a pointer to a dynamically
+ * allocated string containing the value to Id, and return true. If not
+ * found, return false. The memory passed in Id must be free by a call to
+ * Free();
+ */
+{
+    return CfgDataGetId (CfgInfo, Name, Id);
+}
+
+
+
+static int GetCfgStr (void* CfgInfo, const char* Name, char** S)
+/* Search CfgInfo for an attribute with the given name and type "id". If
+ * found, remove it from the configuration, pass a pointer to a dynamically
+ * allocated string containing the value to Id, and return true. If not
+ * found, return false. The memory passed in S must be free by a call to
+ * Free();
+ */
+{
+    return CfgDataGetStr (CfgInfo, Name, S);
+}
+
+
+
+static int GetCfgNum (void* CfgInfo, const char* Name, long* Val)
+/* Search CfgInfo for an attribute with the given name and type "number".
+ * If found, remove it from the configuration, copy it into Val and return
+ * true. If not found, return false.
+ */
+{
+    return CfgDataGetNum (CfgInfo, Name, Val);
+}
+
+
+
 static int CmpChips (void* Data attribute ((unused)),
                     const void* lhs, const void* rhs)
 /* Compare function for CollSort */
@@ -312,7 +381,7 @@ void LoadChipLibrary (const char* LibName)
         const ChipData* D = Data + I;
 
         /* Check if the chip data has the correct version */
-        if (Data->MajorVersion != CHIPDATA_VER_MAJOR) {
+        if (D->MajorVersion != CHIPDATA_VER_MAJOR) {
             Warning ("Version mismatch for `%s' (%s), expected %u, got %u",
                      D->ChipName, L->LibName,
                      CHIPDATA_VER_MAJOR, D->MajorVersion);
@@ -320,6 +389,9 @@ void LoadChipLibrary (const char* LibName)
             continue;
         }
 
+       /* Initialize the chip passing the simulator data */
+       D->InitChip (&Sim65Data);
+
         /* Generate a new chip */
         C = NewChip (L, D);
 
@@ -328,10 +400,11 @@ void LoadChipLibrary (const char* LibName)
 
         /* Output chip name and version to keep the user happy */
         Print (stdout, 1,
-               "  Found `%s', version %u.%u in library `%s'\n",
-               Data->ChipName,
-               Data->MajorVersion,
-               Data->MinorVersion,
+               "  Found %s `%s', version %u.%u in library `%s'\n",
+              (D->Type == CHIPDATA_TYPE_CHIP)? "chip" : "cpu",
+               D->ChipName,
+               D->MajorVersion,
+               D->MinorVersion,
                L->LibName);
     }
 }