From 986e3779ce593cf75dcc143db83808d7d42ece5c Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 1 May 2003 23:24:20 +0000 Subject: [PATCH] Moved CPU definition into common/ git-svn-id: svn://svn.cc65.org/cc65/trunk@2111 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/instr.c | 15 +++++------ src/ca65/instr.h | 30 +++++++++------------ src/ca65/main.c | 9 +++++++ src/cc65/codegen.c | 4 +-- src/cc65/codeopt.c | 2 +- src/cc65/coptind.c | 4 ++- src/cc65/coptsize.c | 4 ++- src/cc65/main.c | 29 +++++++++----------- src/cc65/make/gcc.mak | 1 - src/cc65/make/watcom.mak | 1 - src/cc65/opcodes.c | 2 +- src/{cc65 => common}/cpu.c | 55 +++++++++++++++++++++++++++++++------- src/{cc65 => common}/cpu.h | 46 ++++++++++++++++++++++--------- src/common/make/gcc.mak | 1 + src/common/make/watcom.mak | 1 + src/common/target.c | 33 +++++++++++++++++++---- src/common/target.h | 18 +++++++++---- 17 files changed, 174 insertions(+), 81 deletions(-) rename src/{cc65 => common}/cpu.c (65%) rename src/{cc65 => common}/cpu.h (66%) diff --git a/src/ca65/instr.c b/src/ca65/instr.c index 4586e21e1..942650816 100644 --- a/src/ca65/instr.c +++ b/src/ca65/instr.c @@ -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; diff --git a/src/ca65/instr.h b/src/ca65/instr.h index a23d25fe9..23627f29e 100644 --- a/src/ca65/instr.h +++ b/src/ca65/instr.h @@ -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 */ @@ -38,21 +38,17 @@ +/* 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); diff --git a/src/ca65/main.c b/src/ca65/main.c index 4fac8117c..e7738d153 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -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 (); diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index d3ec179c3..90f3c3ebc 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -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. diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index 92bd1da94..4c4cb31a6 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -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" diff --git a/src/cc65/coptind.c b/src/cc65/coptind.c index 0ffbf9e2f..b14b27ed9 100644 --- a/src/cc65/coptind.c +++ b/src/cc65/coptind.c @@ -33,11 +33,13 @@ +/* common */ +#include "cpu.h" + /* cc65 */ #include "codeent.h" #include "codeinfo.h" #include "codeopt.h" -#include "cpu.h" #include "error.h" #include "coptind.h" diff --git a/src/cc65/coptsize.c b/src/cc65/coptsize.c index c39838da7..9ab398ff6 100644 --- a/src/cc65/coptsize.c +++ b/src/cc65/coptsize.c @@ -35,10 +35,12 @@ #include +/* common */ +#include "cpu.h" + /* cc65 */ #include "codeent.h" #include "codeinfo.h" -#include "cpu.h" #include "coptsize.h" diff --git a/src/cc65/main.c b/src/cc65/main.c index 19fb4db41..a79bc9883 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -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)); } diff --git a/src/cc65/make/gcc.mak b/src/cc65/make/gcc.mak index c52ad65fe..968a20b23 100644 --- a/src/cc65/make/gcc.mak +++ b/src/cc65/make/gcc.mak @@ -46,7 +46,6 @@ OBJS = anonname.o \ coptstore.o \ coptsub.o \ copttest.o \ - cpu.o \ dataseg.o \ datatype.o \ declare.o \ diff --git a/src/cc65/make/watcom.mak b/src/cc65/make/watcom.mak index cef4d0e8a..fceb1963c 100644 --- a/src/cc65/make/watcom.mak +++ b/src/cc65/make/watcom.mak @@ -67,7 +67,6 @@ OBJS = anonname.obj \ coptstore.obj \ coptsub.obj \ copttest.obj \ - cpu.obj \ dataseg.obj \ datatype.obj \ declare.obj \ diff --git a/src/cc65/opcodes.c b/src/cc65/opcodes.c index 55afbe725..7bd8b5032 100644 --- a/src/cc65/opcodes.c +++ b/src/cc65/opcodes.c @@ -39,10 +39,10 @@ /* common */ #include "check.h" +#include "cpu.h" /* cc65 */ #include "codeinfo.h" -#include "cpu.h" #include "error.h" #include "opcodes.h" diff --git a/src/cc65/cpu.c b/src/common/cpu.c similarity index 65% rename from src/cc65/cpu.c rename to src/common/cpu.c index 98e92e3a4..81f285e94 100644 --- a/src/cc65/cpu.c +++ b/src/common/cpu.c @@ -1,15 +1,15 @@ /*****************************************************************************/ /* */ -/* cpu.c */ +/* cpu.c */ /* */ -/* CPU type definitions */ +/* CPU specifications */ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (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 */ @@ -33,18 +33,55 @@ +#include + +/* common */ #include "cpu.h" /*****************************************************************************/ -/* Data */ +/* Data */ +/*****************************************************************************/ + + + +/* CPU used */ +cpu_t CPU = CPU_UNKNOWN; + +/* Table with target names */ +const char* CPUNames [CPU_COUNT] = { + "6502" + "65C02", + "65816", + "sunplus", +}; + + + +/*****************************************************************************/ +/* Code */ /*****************************************************************************/ -/* Current CPU */ -CPUType CPU = CPU_6502; +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/cc65/cpu.h b/src/common/cpu.h similarity index 66% rename from src/cc65/cpu.h rename to src/common/cpu.h index 003bce908..05f07b38b 100644 --- a/src/cc65/cpu.h +++ b/src/common/cpu.h @@ -1,15 +1,15 @@ /*****************************************************************************/ /* */ -/* cpu.h */ +/* cpu.h */ /* */ -/* CPU type definitions */ +/* CPU specifications */ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (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 */ @@ -39,19 +39,39 @@ /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ -/* Supported CPUs */ -typedef enum CPUType { +/* CPUs */ +typedef enum { + CPU_UNKNOWN = -1, /* Not specified or invalid target */ CPU_6502, - CPU_65C02 -} CPUType; + CPU_65C02, + CPU_65816, + CPU_SUNPLUS, /* Not in the freeware version - sorry */ + CPU_COUNT /* Number of different CPUs */ +} cpu_t; -/* Current CPU */ -extern CPUType CPU; +/* 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. + */ diff --git a/src/common/make/gcc.mak b/src/common/make/gcc.mak index 42d3483b1..732c7c95b 100644 --- a/src/common/make/gcc.mak +++ b/src/common/make/gcc.mak @@ -15,6 +15,7 @@ OBJS = abend.o \ check.o \ cmdline.o \ coll.o \ + cpu.o \ debugflag.o \ exprdefs.o \ filepos.o \ diff --git a/src/common/make/watcom.mak b/src/common/make/watcom.mak index ff351c4bd..04d05d911 100644 --- a/src/common/make/watcom.mak +++ b/src/common/make/watcom.mak @@ -47,6 +47,7 @@ OBJS = abend.obj \ check.obj \ cmdline.obj \ coll.obj \ + cpu.obj \ debugflag.obj \ exprdefs.obj \ filepos.obj \ diff --git a/src/common/target.c b/src/common/target.c index 89dc49380..5a513d758 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -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 */ +}; diff --git a/src/common/target.h b/src/common/target.h index 2ceca1726..8809b724a 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -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 */ @@ -38,6 +38,11 @@ +/* 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]; -- 2.39.5