]> git.sur5r.net Git - cc65/commitdiff
Moved CPU definition into common/
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 1 May 2003 23:24:20 +0000 (23:24 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 1 May 2003 23:24:20 +0000 (23:24 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@2111 b7a2c559-68d2-44c3-8de9-860c34a00d81

19 files changed:
src/ca65/instr.c
src/ca65/instr.h
src/ca65/main.c
src/cc65/codegen.c
src/cc65/codeopt.c
src/cc65/coptind.c
src/cc65/coptsize.c
src/cc65/cpu.c [deleted file]
src/cc65/cpu.h [deleted file]
src/cc65/main.c
src/cc65/make/gcc.mak
src/cc65/make/watcom.mak
src/cc65/opcodes.c
src/common/cpu.c [new file with mode: 0644]
src/common/cpu.h [new file with mode: 0644]
src/common/make/gcc.mak
src/common/make/watcom.mak
src/common/target.c
src/common/target.h

index 4586e21e1b6b7a3d86e635e6a5e884400eb190ff..942650816841d226222af21b2b15e6957596b14d 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-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       */
@@ -331,8 +331,7 @@ static const struct {
 
 
 
-/* The current CPU and an array with instruction tables */
-static enum CPUType CPU = CPU_6502;
+/* An array with instruction tables */
 static const InsTable* InsTabs[CPU_COUNT] = {
     (const InsTable*) &InsTab6502,
     (const InsTable*) &InsTab65SC02,
@@ -676,7 +675,7 @@ static int CmpName (const void* Key, const void* Instr)
 
 
 
-void SetCPU (enum CPUType NewCPU)
+void SetCPU (cpu_t NewCPU)
 /* Set a new CPU */
 {
     /* Make sure the parameter is correct */
@@ -693,7 +692,7 @@ void SetCPU (enum CPUType NewCPU)
 
 
 
-enum CPUType GetCPU (void)
+cpu_t GetCPU (void)
 /* Return the current CPU */
 {
     return CPU;
index a23d25fe9fa5414fb74d15f16a0b5a0c75c22291..23627f29ea2b90a682c33c130328ca45125a2ccb 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 instr.h                                  */
+/*                                 instr.h                                  */
 /*                                                                           */
 /*            Instruction encoding for the ca65 macroassembler              */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-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       */
 
 
 
+/* common */
+#include "cpu.h"
+
+
+
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                          Data                                    */
 /*****************************************************************************/
 
 
 
-/* Supported CPUs */
-enum CPUType {
-    CPU_6502,
-    CPU_65C02,
-    CPU_65816,
-    CPU_SUNPLUS,       /* Not in the freeware version - sorry */
-    CPU_COUNT          /* Count of different CPUs */
-};
-
 /* Constants for the addressing mode. If an opcode is available in zero page
  * and absolut adressing mode, both bits are set. When checking for valid
  * modes, the zeropage bit is checked first. Similar, the implicit bit is set
@@ -134,10 +130,10 @@ extern unsigned char ExtBytes [AMI_COUNT];
 
 
 
-void SetCPU (enum CPUType NewCPU);
+void SetCPU (cpu_t NewCPU);
 /* Set a new CPU */
 
-enum CPUType GetCPU (void);
+cpu_t GetCPU (void);
 /* Return the current CPU */
 
 int FindInstruction (const char* Ident);
index 4fac8117cf07ea782a9f9cb368d90e1618d18701..e7738d1530ee07d73823a00ae4cd90fc8e6dfa0a 100644 (file)
@@ -609,6 +609,15 @@ int main (int argc, char* argv [])
        exit (EXIT_FAILURE);
     }
 
+    /* If no CPU given, use the default CPU for the target */
+    if (GetCPU () == CPU_UNKNOWN) { 
+        if (Target != TGT_UNKNOWN) {
+            SetCPU (DefaultCPU[Target]);
+        } else {
+            SetCPU (CPU_6502);
+        }
+    }
+
     /* Intialize the target translation tables */
     TgtTranslateInit ();
 
index d3ec179c310af3779807ddfeedbbd7e26d4225b8..90f3c3ebca80ec4e124434a49f7dacaff9e144c3 100644 (file)
@@ -39,6 +39,7 @@
 
 /* common */
 #include "check.h"
+#include "cpu.h"
 #include "strbuf.h"
 #include "version.h"
 #include "xmalloc.h"
@@ -49,7 +50,6 @@
 #include "asmlabel.h"
 #include "casenode.h"
 #include "codeseg.h"
-#include "cpu.h"
 #include "dataseg.h"
 #include "error.h"
 #include "global.h"
@@ -189,7 +189,7 @@ void g_preamble (void)
 
 void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime)
 /* If debug info is enabled, place a file info into the source */
-{   
+{
     if (DebugInfo) {
        /* We have to place this into the global text segment, so it will
         * appear before all .dbg line statements.
index 92bd1da94855696f15f78f9174b12eb0d408e4f2..4c4cb31a6ba8e5a819dfa0b9aef2254fc33aa9fa 100644 (file)
@@ -39,6 +39,7 @@
 /* common */
 #include "abend.h"
 #include "chartype.h"
+#include "cpu.h"
 #include "print.h"
 #include "xmalloc.h"
 #include "xsprintf.h"
@@ -58,7 +59,6 @@
 #include "coptstore.h"
 #include "coptsub.h"
 #include "copttest.h"
-#include "cpu.h"
 #include "error.h"
 #include "global.h"
 #include "codeopt.h"
index 0ffbf9e2f8a58b962fe75b3e354248dac558e46e..b14b27ed941b4566d1497e60d7c4acf4ea68cd15 100644 (file)
 
 
 
+/* common */
+#include "cpu.h"
+
 /* cc65 */
 #include "codeent.h"
 #include "codeinfo.h"
 #include "codeopt.h"
-#include "cpu.h"
 #include "error.h"
 #include "coptind.h"
 
index c39838da796ad90674b3bb7167ca6e6c03196274..9ab398ff6f82dfc63807f6fb062efc8840526a97 100644 (file)
 
 #include <stdlib.h>
 
+/* common */
+#include "cpu.h"
+
 /* cc65 */
 #include "codeent.h"
 #include "codeinfo.h"
-#include "cpu.h"
 #include "coptsize.h"
 
 
diff --git a/src/cc65/cpu.c b/src/cc65/cpu.c
deleted file mode 100644 (file)
index 98e92e3..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                  cpu.c                                   */
-/*                                                                           */
-/*                          CPU type definitions                            */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2000     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 "cpu.h"
-
-
-
-/*****************************************************************************/
-/*                                  Data                                    */
-/*****************************************************************************/
-
-
-
-/* Current CPU */
-CPUType        CPU = CPU_6502;
-
-
-
diff --git a/src/cc65/cpu.h b/src/cc65/cpu.h
deleted file mode 100644 (file)
index 003bce9..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                  cpu.h                                   */
-/*                                                                           */
-/*                          CPU type definitions                            */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2000     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.                                                          */
-/*                                                                           */
-/*****************************************************************************/
-
-
-
-#ifndef CPU_H
-#define CPU_H
-
-
-
-/*****************************************************************************/
-/*                                  Data                                    */
-/*****************************************************************************/
-
-
-
-/* Supported CPUs */
-typedef enum CPUType {
-    CPU_6502,
-    CPU_65C02
-} CPUType;
-
-/* Current CPU */
-extern CPUType CPU;
-
-
-
-/* End of cpu.h */
-
-#endif
-
-
-
index 19fb4db413c812b3d8473a40996fecfbdcb472bc..a79bc98839e81376727c8007046cdbf04e140504 100644 (file)
@@ -42,6 +42,7 @@
 #include "abend.h"
 #include "chartype.h"
 #include "cmdline.h"
+#include "cpu.h"
 #include "debugflag.h"
 #include "fname.h"
 #include "print.h"
@@ -55,7 +56,6 @@
 #include "asmcode.h"
 #include "compile.h"
 #include "codeopt.h"
-#include "cpu.h"
 #include "error.h"
 #include "global.h"
 #include "incpath.h"
@@ -378,11 +378,8 @@ static void OptCreateDep (const char* Opt attribute ((unused)),
 static void OptCPU (const char* Opt, const char* Arg)
 /* Handle the --cpu option */
 {
-    if (strcmp (Arg, "6502") == 0) {
-               CPU = CPU_6502;
-    } else if (strcmp (Arg, "65C02") == 0) {
-       CPU = CPU_65C02;
-    } else {
+    CPU = FindCPU (Arg);
+    if (CPU != CPU_6502 && CPU != CPU_65C02) {
                AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
     }
 }
@@ -795,23 +792,23 @@ int main (int argc, char* argv[])
        OutputFile = MakeFilename (InputFile, ".s");
     }
 
+    /* If no CPU given, use the default CPU for the target */
+    if (CPU == CPU_UNKNOWN) {
+        if (Target != TGT_UNKNOWN) {
+            CPU = DefaultCPU[Target];
+        } else {
+            CPU = CPU_6502;
+        }
+    }
+
     /* Go! */
     Compile (InputFile);
 
     /* Create the output file if we didn't had any errors */
     if (ErrorCount == 0 || Debug) {
 
-       FILE* F;
-
-#if 0
-       /* Optimize the output if requested */
-       if (Optimize) {
-           OptDoOpt ();
-       }
-#endif
-
        /* Open the file */
-       F = fopen (OutputFile, "w");
+       FILE* F = fopen (OutputFile, "w");
        if (F == 0) {
            Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
        }
index c52ad65fee1330f0b62e1154cec0619317d2ee66..968a20b236c1c0b011b2a6c281173825a564079b 100644 (file)
@@ -46,7 +46,6 @@ OBJS =        anonname.o      \
         coptstore.o     \
        coptsub.o       \
        copttest.o      \
-       cpu.o           \
        dataseg.o       \
        datatype.o      \
        declare.o       \
index cef4d0e8ac4b55245f7991ffe3f681d311a6b4ca..fceb1963c156597e5fe3af85209c4f7304327dea 100644 (file)
@@ -67,7 +67,6 @@ OBJS =        anonname.obj    \
         coptstore.obj   \
        coptsub.obj     \
        copttest.obj    \
-       cpu.obj         \
        dataseg.obj     \
        datatype.obj    \
        declare.obj     \
index 55afbe7257aef603b971858787395274d2130320..7bd8b50322eb887eb4dfc1ae9e858b3107c21e68 100644 (file)
 
 /* common */
 #include "check.h"
+#include "cpu.h"
 
 /* cc65 */
 #include "codeinfo.h"
-#include "cpu.h"
 #include "error.h"
 #include "opcodes.h"
 
diff --git a/src/common/cpu.c b/src/common/cpu.c
new file mode 100644 (file)
index 0000000..81f285e
--- /dev/null
@@ -0,0 +1,87 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                   cpu.c                                 */
+/*                                                                           */
+/*                            CPU specifications                             */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (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.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#include <string.h>
+
+/* common */              
+#include "cpu.h"
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+/* CPU used */
+cpu_t CPU = CPU_UNKNOWN;
+
+/* Table with target names */
+const char* CPUNames [CPU_COUNT] = {
+    "6502"
+    "65C02",
+    "65816",
+    "sunplus",
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+cpu_t FindCPU (const char* Name)
+/* Find a CPU by name and return the target id. CPU_UNKNOWN is returned if
+ * the given name is no valid target.
+ */
+{
+    unsigned I;
+
+    /* Check all CPU names */
+    for (I = 0; I < CPU_COUNT; ++I) {
+       if (strcmp (CPUNames [I], Name) == 0) {
+           return (cpu_t)I;
+       }
+    }
+
+    /* Not found */
+    return CPU_UNKNOWN;
+}
+
+
+
diff --git a/src/common/cpu.h b/src/common/cpu.h
new file mode 100644 (file)
index 0000000..05f07b3
--- /dev/null
@@ -0,0 +1,83 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                   cpu.h                                   */
+/*                                                                           */
+/*                            CPU specifications                             */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (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 CPU_H
+#define CPU_H
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+/* CPUs */
+typedef enum {
+    CPU_UNKNOWN = -1,           /* Not specified or invalid target */
+    CPU_6502,
+    CPU_65C02,
+    CPU_65816,
+    CPU_SUNPLUS,               /* Not in the freeware version - sorry */
+    CPU_COUNT                  /* Number of different CPUs */
+} cpu_t;
+
+/* CPU used */
+extern cpu_t CPU;
+
+/* Table with target names */
+extern const char* CPUNames [CPU_COUNT];
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+cpu_t FindCPU (const char* Name);
+/* Find a CPU by name and return the target id. CPU_UNKNOWN is returned if
+ * the given name is no valid target.
+ */
+
+
+
+/* End of cpu.h */
+
+#endif
+
+
+
index 42d3483b156eaed3037ba14a0ce1c5ac11b94ef0..732c7c95bce2b64809ce0ddef131dee2f31f6a0e 100644 (file)
@@ -15,6 +15,7 @@ OBJS =        abend.o         \
        check.o         \
        cmdline.o       \
        coll.o          \
+        cpu.o           \
         debugflag.o     \
        exprdefs.o      \
        filepos.o       \
index ff351c4bd4b94ee429cb85f6c2d9adee40919622..04d05d91173c1fa9a8ee4d95bd32d9433d52a536 100644 (file)
@@ -47,6 +47,7 @@ OBJS =        abend.obj       \
        check.obj       \
        cmdline.obj     \
        coll.obj        \
+        cpu.obj         \
         debugflag.obj   \
        exprdefs.obj    \
        filepos.obj     \
index 89dc49380efb99bd186636460330166ffed04610..5a513d758be47c44765f63ad0a02372976e253ff 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-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       */
@@ -69,7 +69,30 @@ const char* TargetNames [TGT_COUNT] = {
     "geos",
     "lunix",
     "atmos"
-};        
+};
+
+
+
+/* Table with default CPUs per target */
+const cpu_t DefaultCPU[TGT_COUNT] = {
+    CPU_6502,           /* none */
+    CPU_6502,           /* module */
+    CPU_6502,           /* atari */
+    CPU_6502,           /* vic20 */
+    CPU_6502,           /* c16 */
+    CPU_6502,           /* c64 */
+    CPU_6502,           /* c128 */
+    CPU_6502,           /* ace */
+    CPU_6502,           /* plus4 */
+    CPU_6502,           /* cbm510 */
+    CPU_6502,           /* cbm610 */
+    CPU_6502,           /* pet */
+    CPU_6502,           /* bbc */
+    CPU_6502,           /* apple2 */
+    CPU_6502,           /* geos */
+    CPU_6502,           /* lunix */
+    CPU_6502,           /* atmos */
+};
 
 
 
index 2ceca1726060fbb206efc822a55e270552bd2499..8809b724a11658ea7fe9a09d80109002b3956890 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-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       */
 
 
 
+/* common */
+#include "cpu.h"
+
+
+
 /*****************************************************************************/
 /*                                          Data                                    */
 /*****************************************************************************/
@@ -71,7 +76,10 @@ typedef enum {
 extern target_t                Target;
 
 /* Table with target names */
-extern const char* TargetNames [TGT_COUNT];
+extern const char* TargetNames[TGT_COUNT];
+
+/* Table with default CPUs per target */
+extern const cpu_t DefaultCPU[TGT_COUNT];