]> git.sur5r.net Git - cc65/commitdiff
Working
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 1 May 2003 22:38:47 +0000 (22:38 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 1 May 2003 22:38:47 +0000 (22:38 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@2110 b7a2c559-68d2-44c3-8de9-860c34a00d81

20 files changed:
src/sim65/addrspace.c [new file with mode: 0644]
src/sim65/addrspace.h [new file with mode: 0644]
src/sim65/cfgdata.c
src/sim65/cfgdata.h
src/sim65/chip.c
src/sim65/chip.h
src/sim65/chipif.h
src/sim65/chips/ram.c
src/sim65/config.c
src/sim65/cpucore.h
src/sim65/cputype.c
src/sim65/cputype.h
src/sim65/error.c
src/sim65/error.h
src/sim65/global.c
src/sim65/global.h
src/sim65/location.c [new file with mode: 0644]
src/sim65/location.h [new file with mode: 0644]
src/sim65/make/gcc.mak
src/sim65/simdata.h

diff --git a/src/sim65/addrspace.c b/src/sim65/addrspace.c
new file mode 100644 (file)
index 0000000..1eda9f7
--- /dev/null
@@ -0,0 +1,190 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                addrspace.c                                */
+/*                                                                           */
+/*                 CPU address space for the 6502 simulator                  */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2003      Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
+/*                                                                           */
+/*                                                                           */
+/* 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.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* common */
+#include "check.h"
+#include "xmalloc.h"
+
+/* sim65 */
+#include "chip.h"
+#include "cpucore.h"
+#include "error.h"
+#include "addrspace.h"
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+AddressSpace* NewAddressSpace (unsigned Size)
+/* Allocate a new address space and return it */
+{
+    unsigned I;
+
+    /* Allocate memory */
+    AddressSpace* AS = xmalloc (sizeof (AddressSpace) +
+                                (Size - 1) * sizeof (ChipInstance*));
+
+    /* Initialize the struct */
+    AS->CPU  = 0;
+    AS->Size = Size;
+    for (I = 0; I < Size; ++I) {
+        AS->Data[I] = 0;
+    }
+
+    /* Return the new struct */
+    return AS;
+}
+
+
+
+void ASWrite (AddressSpace* AS, unsigned Addr, unsigned char Val)
+/* Write a byte to a given location */
+{
+    const ChipInstance* CI;
+
+    /* Make sure, the addresses are in a valid range */
+    PRECONDITION (Addr < AS->Size);
+
+    /* Get the instance of the chip at this address */
+    CI = AS->Data[Addr];
+
+    /* Check if the memory is mapped */
+    if (CI == 0) {
+        Break ("Writing to unassigned memory at $%06X", Addr);
+    } else {
+        CI->C->Data->Write (CI->Data, Addr - CI->Addr, Val);
+    }
+}
+
+
+
+unsigned char ASRead (AddressSpace* AS, unsigned Addr)
+/* Read a byte from a location */
+{
+    const ChipInstance* CI;
+
+    /* Make sure, the addresses are in a valid range */
+    PRECONDITION (Addr < AS->Size);
+
+    /* Get the instance of the chip at this address */
+    CI = AS->Data[Addr];
+
+    /* Check if the memory is mapped */
+    if (CI == 0) {
+        Break ("Reading from unassigned memory at $%06X", Addr);
+        return 0xFF;
+    } else {
+        return CI->C->Data->Read (CI->Data, Addr - CI->Addr);
+    }
+}
+
+
+
+void ASWriteCtrl (AddressSpace* AS, unsigned Addr, unsigned char Val)
+/* Write a byte to a given location */
+{
+    const ChipInstance* CI;
+
+    /* Make sure, the addresses are in a valid range */
+    PRECONDITION (Addr < AS->Size);
+
+    /* Get the instance of the chip at this address */
+    CI = AS->Data[Addr];
+
+    /* Check if the memory is mapped */
+    if (CI == 0) {
+        Break ("Writing to unassigned memory at $%06X", Addr);
+    } else {
+        CI->C->Data->WriteCtrl (CI->Data, Addr - CI->Addr, Val);
+    }
+}
+
+
+
+unsigned char ASReadCtrl (AddressSpace* AS, unsigned Addr)
+/* Read a byte from a location */
+{
+    const ChipInstance* CI;
+
+    /* Make sure, the addresses are in a valid range */
+    PRECONDITION (Addr < AS->Size);
+
+    /* Get the instance of the chip at this address */
+    CI = AS->Data[Addr];
+
+    /* Check if the memory is mapped */
+    if (CI == 0) {
+        Break ("Reading from unassigned memory at $%06X", Addr);
+        return 0xFF;
+    } else {
+        return CI->C->Data->ReadCtrl (CI->Data, Addr - CI->Addr);
+    }
+}
+
+
+void ASAssignChip (AddressSpace* AS, ChipInstance* CI,
+                   unsigned Addr, unsigned Range)
+/* Assign a chip instance to memory locations */
+{
+    /* Make sure, the addresses are in a valid range */
+    PRECONDITION (Addr + Range <= AS->Size);
+
+    /* Assign the chip instance */
+    while (Range--) {
+        CHECK (AS->Data[Addr] == 0);
+        AS->Data[Addr++] = CI;
+    }
+
+    /* Set the backpointer to us */
+    CI->AS = AS;
+}
+
+
+ChipInstance* ASGetChip (const AddressSpace* AS, unsigned Addr)
+/* Get the chip that is located at the given address (may return NULL). */
+{
+    /* Make sure, the addresses are in a valid range */
+    PRECONDITION (Addr < AS->Size);
+
+    /* Return the chip instance */
+    return AS->Data[Addr];
+}
+
+
+
diff --git a/src/sim65/addrspace.h b/src/sim65/addrspace.h
new file mode 100644 (file)
index 0000000..b353068
--- /dev/null
@@ -0,0 +1,99 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                addrspace.h                                */
+/*                                                                           */
+/*                 CPU address space for the 6502 simulator                  */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2003      Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
+/*                                                                           */
+/*                                                                           */
+/* 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.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef ADDRSPACE_H
+#define ADDRSPACE_H
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+/* Forwards */
+struct CPUData;
+struct ChipInstance;
+
+/* Forwards */
+typedef struct AddressSpace AddressSpace;
+struct AddressSpace {
+
+    struct CPU*                 CPU;      /* Backpointer to CPU */
+    unsigned                    Size;     /* Address space size */
+    struct ChipInstance*        Data[1];  /* Pointer to chips, dynamically! */
+
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+AddressSpace* NewAddressSpace (unsigned Size);
+/* Allocate a new address space and return it */
+
+void ASWrite (AddressSpace* AS, unsigned Addr, unsigned char Val);
+/* Write a byte to a given location */
+
+unsigned char ASRead (AddressSpace* AS, unsigned Addr);
+/* Read a byte from a location */
+
+void ASWriteCtrl (AddressSpace* AS, unsigned Addr, unsigned char Val);
+/* Write a byte to a given location */
+
+unsigned char ASReadCtrl (AddressSpace* AS, unsigned Addr);
+/* Read a byte from a location */
+
+void ASAssignChip (AddressSpace* AS, struct ChipInstance* CI,
+                   unsigned Addr, unsigned Range);
+/* Assign a chip instance to memory locations */
+
+struct ChipInstance* ASGetChip (const AddressSpace* AS, unsigned Addr);
+/* Get the chip that is located at the given address (may return NULL). */
+
+
+
+/* End of addrspace.h */
+
+#endif
+
+
+
+
index f603c8e28119e2eb038ddb603d7c10e82299750f..fc1d428bdfc8da30220510fb60471063689a48a7 100644 (file)
@@ -40,6 +40,7 @@
 #include "xmalloc.h"
 
 /* sim65 */
+#include "error.h"
 #include "scanner.h"
 #include "cfgdata.h"
 
@@ -87,6 +88,19 @@ void FreeCfgData (CfgData* D)
 
 
 
+void CfgDataCheckType (const CfgData* D, unsigned Type)
+/* Check the config data type and print an error message if it has the wrong
+ * type.
+ */
+{
+    if (D->Type != Type) {
+        Error ("%s(%u): Attribute `%s' has invalid type",
+               CfgGetName (), D->Line, D->Attr);
+    }
+}
+
+
+
 int CfgDataFind (const Collection* Attributes, const char* AttrName)
 /* Find the attribute with the given name and return its index. Return -1 if
  * the attribute was not found.
@@ -108,7 +122,7 @@ int CfgDataFind (const Collection* Attributes, const char* AttrName)
     }
 
     /* Not found */
-    return -1;         
+    return -1;
 }
 
 
index b31234e648a8209e13b724f69f0860a6e5e60362..c86522f724fcdd82a3f382c2700c5ac843a1e3e1 100644 (file)
@@ -82,6 +82,11 @@ CfgData* NewCfgData (void);
 void FreeCfgData (CfgData* D);
 /* Free a config data structure */
 
+void CfgDataCheckType (const CfgData* D, unsigned Type);
+/* Check the config data type and print an error message if it has the wrong
+ * type.
+ */
+
 int CfgDataFind (const Collection* Attributes, const char* AttrName);
 /* Find the attribute with the given name and return its index. Return -1 if
  * the attribute was not found.
index 80dd42cb8dc492bbbc535547e1bcb5708968df87..5d33c141badbc8c6baeb5cea218b4b77c4d7b0dd 100644 (file)
@@ -246,7 +246,7 @@ static Chip* NewChip (ChipLibrary* Library, const ChipData* Data)
     Chip* C = xmalloc (sizeof (Chip));
 
     /* Initialize the fields */
-    C->Library   = Library;
+    C->Lib       = Library;
     C->Data      = Data;
     C->Instances = EmptyCollection;
 
@@ -275,6 +275,7 @@ ChipInstance* NewChipInstance (const char* ChipName, unsigned Addr,
 
     /* Initialize the fields */
     CI->C    = C;
+    CI->AS   = 0;
     CI->Addr = Addr;
     CI->Size = Size;
     CI->Data = C->Data->InitInstance (Addr, Size, Attributes);
index 12817b28c4ffc915185b1f573359b319f8e0aa86..f614c0ced045bfe72ba4047c566b8c293850f600 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -54,6 +54,7 @@
 
 
 /* Forwards */
+struct AddressSpace;
 struct CfgData;
 typedef struct ChipInstance ChipInstance;
 typedef struct Chip Chip;
@@ -61,17 +62,18 @@ typedef struct ChipLibrary ChipLibrary;
 
 /* One instance of a chip */
 struct ChipInstance {
-    Chip*               C;              /* Pointer to corresponding chip */
-    unsigned            Addr;           /* Start address of range */
-    unsigned            Size;           /* Size of range */
-    void*               Data;           /* Chip instance data */
+    Chip*                   C;          /* Pointer to corresponding chip */
+    struct AddressSpace*    AS;         /* Pointer to address space */
+    unsigned                Addr;       /* Start address of range */
+    unsigned                Size;       /* Size of range */
+    void*                   Data;       /* Chip instance data */
 };
 
 /* Chip structure */
 struct Chip {
-    struct ChipLibrary* Library;        /* Pointer to library data structure */
-    const ChipData*     Data;           /* Chip data as given by the library */
-    Collection          Instances;      /* Pointer to chip instances */
+    struct ChipLibrary*     Lib;        /* Pointer to library data structure */
+    const ChipData*         Data;       /* Chip data as given by the library */
+    Collection              Instances;  /* Pointer to chip instances */
 };
 
 /* ChipLibrary structure */
index 1badc3696b5283c988e1e5394af91c4e020e1c73..c9111aeb7d1577606ec00a079d923b1f2c7e3429 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
index 5a77bc7448995b0808a63f503f3511812cf972dd..91ebc421f65ce48b2fb7a6f0370c4be20e66ad66 100644 (file)
@@ -148,6 +148,8 @@ static int InitChip (const struct SimData* Data)
 static void* InitInstance (unsigned Addr, unsigned Range, void* CfgInfo)
 /* Initialize a new chip instance */
 {
+    long Val;
+
     /* Allocate a new instance structure */
     InstanceData* D = Sim->Malloc (sizeof (InstanceData));
 
@@ -157,9 +159,22 @@ static void* InitInstance (unsigned Addr, unsigned Range, void* CfgInfo)
     D->MemAttr  = Sim->Malloc (Range * sizeof (D->MemAttr[0]));
     D->Mem      = Sim->Malloc (Range * sizeof (D->Mem[0]));
 
-    /* Clear the RAM and attribute memory */
+    /* Check if a value is given that should be used to clear the RAM.
+     * Otherwise use random values.
+     */
+    if (Sim->GetCfgNum (CfgInfo, "fill", &Val) == 0) {
+        /* No "fill" attribute */
+        unsigned I;
+        for (I = 0; I < Range; ++I) {
+            D->Mem[I] = (unsigned char) rand ();
+        }
+    } else {
+        /* Got a "fill" attribute */
+        memset (D->Mem, (int) Val, Range);
+    }
+
+    /* Clear the attribute memory */
     memset (D->MemAttr, 0, Range * sizeof (D->MemAttr[0]));
-    memset (D->Mem, 0, Range * sizeof (D->Mem[0]));
 
     /* Done, return the instance data */
     return D;
index ce1a272f843afeac74f6fd032b3856682cfd0cd1..764319297e1614a244e2d0c71adb562c4e8c701c 100644 (file)
 #include "error.h"
 #include "global.h"
 #include "memory.h"
+#include "location.h"
 #include "scanner.h"
 #include "config.h"
 
 
 
-/*****************************************************************************/
-/*                                   Data                                    */
-/*****************************************************************************/
-
-
-
-/* List of all memory locations */
-static Collection Locations;
-
-/* One memory location */
-typedef struct Location Location;
-struct Location {
-    unsigned    Start;          /* Start of memory location */
-    unsigned    End;            /* End memory location */
-    Collection  Attributes;     /* Attributes given */
-    unsigned    Line;           /* Line in config file */
-    unsigned    Col;            /* Column in config file */
-};
-
-
-
-/*****************************************************************************/
-/*                             struct CfgData                               */
-/*****************************************************************************/
-
-
-
-static void CfgDataCheckType (const CfgData* D, unsigned Type)
-/* Check the config data type */
-{
-    if (D->Type != Type) {
-        Error ("%s(%u): Attribute `%s' has invalid type",
-               CfgGetName (), D->Line, D->Attr);
-    }
-}
-
-
-
-/*****************************************************************************/
-/*                              struct Location                              */
-/*****************************************************************************/
-
-
-
-static Location* NewLocation (unsigned long Start, unsigned long End)
-/* Create a new location, initialize and return it */
-{
-    /* Allocate memory */
-    Location* L = xmalloc (sizeof (Location));
-
-    /* Initialize the fields */
-    L->Start      = Start;
-    L->End        = End;
-    L->Attributes = EmptyCollection;
-    L->Line       = CfgErrorLine;
-    L->Col        = CfgErrorCol;
-
-    /* Return the new struct */
-    return L;
-}
-
-
-
-static int CmpLocations (void* Data attribute ((unused)),
-                        const void* lhs, const void* rhs)
-/* Compare function for CollSort */
-{
-    /* Cast the object pointers */
-    const Location* Left  = (const Location*) rhs;
-    const Location* Right = (const Location*) lhs;
-
-    /* Do the compare */
-    if (Left->Start < Right->Start) {
-        return 1;
-    } else if (Left->Start > Right->Start) {
-        return -1;
-    } else {
-        return 0;
-    }
-}
-
-
-
-static int LocationGetAttr (const Location* L, const char* AttrName)
-/* Find the attribute with the given name and return it. Call Error() if the
- * attribute was not found.
- */
-{
-    int I = CfgDataFind (&L->Attributes, AttrName);
-    if (I < 0) {
-        Error ("%s(%u): Attribute `%s' missing", CfgGetName(), L->Line, AttrName);
-    }
-    return I;
-}
-
-
-
-static int LocationIsMirror (const Location* L)
-/* Return true if the given location is a mirror of another one. */
-{
-    /* Find the "mirror" attribute */
-    return (CfgDataFind (&L->Attributes, "mirror") >= 0);
-}
-
-
-
 /*****************************************************************************/
 /*                                          Code                                    */
 /*****************************************************************************/
@@ -172,7 +67,6 @@ static void ParseMemory (void)
 /* Parse a MEMORY section */
 {
     unsigned I;
-    const Location* Last;
 
 
     while (CfgTok == CFGTOK_INTCON) {
@@ -245,37 +139,10 @@ static void ParseMemory (void)
     }
 
     /* Sort all memory locations */
-    CollSort (&Locations, CmpLocations, 0);
-
-    /* Check for overlaps and other problems */
-    Last = 0;
-    for (I = 0; I < CollCount (&Locations); ++I) {
+    LocationSort (&Locations);
 
-        /* Get this location */
-        const Location* L = CollAtUnchecked (&Locations, I);
-
-        /* Check for an overlap with the following location */
-        if (Last && Last->End >= L->Start) {
-            Error ("%s(%u): Address range overlap (overlapping entry is in line %u)",
-                   CfgGetName(), L->Line, Last->Line);
-        }
-
-        /* If the location is a mirror, it must not have other attributes,
-         * and the mirror attribute must be an integer.
-         */
-        if (LocationIsMirror (L)) {
-            const CfgData* D;
-            if (CollCount (&L->Attributes) > 1) {
-                Error ("%s(%u): Location at address $%06X is a mirror "
-                       "but has attributes", CfgGetName(), L->Line, L->Start);
-            }
-            D = CollConstAt (&L->Attributes, 0);
-            CfgDataCheckType (D, CfgDataNumber);
-        }
-
-        /* Remember this entry */
-        Last = L;
-    }
+    /* Check the locations for overlaps and other problems */
+    LocationCheck (&Locations);
 
     /* Now create the chip instances. Since we can only mirror existing chips,
      * we will first create all real chips and the mirrors in a second run.
index f44431199a5bb864ca7e59102c4aeb035b3be848..6d98ea9acabebd77391da020495cfe23a2e06254 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
index 76903a17484d3ddbd5b12b3881f2a4fe0dce8e70..5d56557f45da941414292a99f9cdb36d826d51c6 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
index c83e0e6fa26eb5b1f307314efb09b8847e96c599..b66b060f70b60f4fea101523d858aea2ca19c9dd 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -61,4 +61,4 @@ extern CPUType        CPU;
 
 
 
-                 
+
index 99d460da90fd1c52f5acb311d6c5b30609779478..d5b9524b830d1f78337b700b1c9a393792492ade 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
index e67036d3723d00c6072c0eb007f2f0071ebcf300..92d4cb253caee05c9d20bd6724aa678b425b74c6 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
index dac0c27b499b6aef2d1ddcfea3c53467ca5392a5..d52d506f1e1cea8e5d4393ace36c6c7b0ba9579d 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
index 5d08aaeb1c1b5d51b956365a69cebbce9501ef43..29c22aa29c36ce04d855e727a89f898ec2ac97f4 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
diff --git a/src/sim65/location.c b/src/sim65/location.c
new file mode 100644 (file)
index 0000000..f235bd9
--- /dev/null
@@ -0,0 +1,174 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                location.c                                 */
+/*                                                                           */
+/*                        Memory location description                        */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2003      Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
+/*                                                                           */
+/*                                                                           */
+/* 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.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* common.h */
+#include "coll.h"
+#include "xmalloc.h"
+
+/* sim65 */
+#include "cfgdata.h"
+#include "error.h"
+#include "scanner.h"
+#include "location.h"
+
+
+
+/*****************************************************************************/
+/*                                     Data                                  */
+/*****************************************************************************/
+
+
+
+/* List of all memory locations */
+Collection Locations = STATIC_COLLECTION_INITIALIZER;
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+Location* NewLocation (unsigned long Start, unsigned long End)
+/* Create a new location, initialize and return it */
+{
+    /* Allocate memory */
+    Location* L = xmalloc (sizeof (Location));
+
+    /* Initialize the fields */
+    L->Start      = Start;
+    L->End        = End;
+    L->Attributes = EmptyCollection;
+    L->Line       = CfgErrorLine;
+    L->Col        = CfgErrorCol;
+
+    /* Return the new struct */
+    return L;
+}
+
+
+
+static int CmpLocations (void* Data attribute ((unused)),
+                        const void* lhs, const void* rhs)
+/* Compare function for CollSort */
+{
+    /* Cast the object pointers */
+    const Location* Left  = (const Location*) rhs;
+    const Location* Right = (const Location*) lhs;
+
+    /* Do the compare */
+    if (Left->Start < Right->Start) {
+        return 1;
+    } else if (Left->Start > Right->Start) {
+        return -1;
+    } else {
+        return 0;
+    }
+}
+
+
+
+int LocationGetAttr (const Location* L, const char* AttrName)
+/* Find the attribute with the given name and return it. Call Error() if the
+ * attribute was not found.
+ */
+{
+    int I = CfgDataFind (&L->Attributes, AttrName);
+    if (I < 0) {
+        Error ("%s(%u): Attribute `%s' missing", CfgGetName(), L->Line, AttrName);
+    }
+    return I;
+}
+
+
+
+int LocationIsMirror (const Location* L)
+/* Return true if the given location is a mirror of another one. */
+{
+    /* Find the "mirror" attribute */
+    return (CfgDataFind (&L->Attributes, "mirror") >= 0);
+}
+
+
+
+void LocationSort (Collection* Locations)
+/* Sort all locations by address */
+{
+    /* Sort all memory locations */
+    CollSort (Locations, CmpLocations, 0);
+}
+
+
+
+void LocationCheck (const Collection* Locations)
+/* Check all locations for problems */
+{
+    unsigned I;
+
+    /* Check for overlaps and other problems */
+    const Location* Last = 0;
+    for (I = 0; I < CollCount (Locations); ++I) {
+
+        /* Get this location */
+        const Location* L = CollConstAt (Locations, I);
+
+        /* Check for an overlap with the following location */
+        if (Last && Last->End >= L->Start) {
+            Error ("%s(%u): Address range overlap (overlapping entry is in line %u)",
+                   CfgGetName(), L->Line, Last->Line);
+        }
+
+        /* If the location is a mirror, it must not have other attributes,
+         * and the mirror attribute must be an integer.
+         */
+        if (LocationIsMirror (L)) {
+            const CfgData* D;
+            if (CollCount (&L->Attributes) > 1) {
+                Error ("%s(%u): Location at address $%06X is a mirror "
+                       "but has attributes", CfgGetName(), L->Line, L->Start);
+            }
+            D = CollConstAt (&L->Attributes, 0);
+            CfgDataCheckType (D, CfgDataNumber);
+        }
+
+        /* Remember this entry */
+        Last = L;
+    }
+}
+
+
+
+
diff --git a/src/sim65/location.h b/src/sim65/location.h
new file mode 100644 (file)
index 0000000..a695bf2
--- /dev/null
@@ -0,0 +1,97 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                location.h                                 */
+/*                                                                           */
+/*                        Memory location description                        */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2003      Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
+/*                                                                           */
+/*                                                                           */
+/* 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.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef LOCATION_H
+#define LOCATION_H
+
+
+
+/* common.h */
+#include "coll.h"
+
+
+
+/*****************************************************************************/
+/*                                     Data                                  */
+/*****************************************************************************/
+
+
+
+/* List of all memory locations */
+extern Collection Locations;
+
+/* One memory location */
+typedef struct Location Location;
+struct Location {
+    unsigned    Start;          /* Start of memory location */
+    unsigned    End;            /* End memory location */
+    Collection  Attributes;     /* Attributes given */
+    unsigned    Line;           /* Line in config file */
+    unsigned    Col;            /* Column in config file */
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+Location* NewLocation (unsigned long Start, unsigned long End);
+/* Create a new location, initialize and return it */
+
+int LocationGetAttr (const Location* L, const char* AttrName);
+/* Find the attribute with the given name and return it. Call Error() if the
+ * attribute was not found.
+ */
+
+int LocationIsMirror (const Location* L);
+/* Return true if the given location is a mirror of another one. */
+
+void LocationSort (Collection* Locations);
+/* Sort all locations by address */
+
+void LocationCheck (const Collection* Locations);
+/* Check all locations for problems */
+
+
+
+/* End of location.h */
+
+#endif
+
+
+
index b51eecf3c7b81f5c11d2c769f82f925b194a4fcd..b4ccf2c2abb2841a29064f4041fcdc3d4c9572af 100644 (file)
@@ -10,7 +10,8 @@ CC    = gcc
 EBIND  = emxbind
 LDFLAGS        =
 
-OBJS =         cfgdata.o       \
+OBJS =         addrspace.o     \
+        cfgdata.o       \
         chip.o          \
         chippath.o      \
         config.o        \
@@ -18,6 +19,7 @@ OBJS =        cfgdata.o       \
        cputype.o       \
         error.o         \
        global.o        \
+        location.o      \
        main.o          \
         memory.o        \
         scanner.o
index c4d80ccb1438e61f5a7553820e7ac085209086c9..3a727b9756b049d164bf84e81f1c41895eb21b2f 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2002-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */