Moved CPU definition into common/

git-svn-id: svn://svn.cc65.org/cc65/trunk@2111 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-05-01 23:24:20 +00:00
parent 8fb90af8ff
commit 986e3779ce
17 changed files with 174 additions and 81 deletions

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2000 Ullrich von Bassewitz */ /* (C) 1998-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* 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 */ /* An array with instruction tables */
static enum CPUType CPU = CPU_6502;
static const InsTable* InsTabs[CPU_COUNT] = { static const InsTable* InsTabs[CPU_COUNT] = {
(const InsTable*) &InsTab6502, (const InsTable*) &InsTab6502,
(const InsTable*) &InsTab65SC02, (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 */ /* Set a new CPU */
{ {
/* Make sure the parameter is correct */ /* 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 the current CPU */
{ {
return CPU; return CPU;

View File

@@ -1,15 +1,15 @@
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* instr.h */ /* instr.h */
/* */ /* */
/* Instruction encoding for the ca65 macroassembler */ /* Instruction encoding for the ca65 macroassembler */
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2000 Ullrich von Bassewitz */ /* (C) 1998-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* 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 /* 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 * 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 * 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 */ /* Set a new CPU */
enum CPUType GetCPU (void); cpu_t GetCPU (void);
/* Return the current CPU */ /* Return the current CPU */
int FindInstruction (const char* Ident); int FindInstruction (const char* Ident);

View File

@@ -609,6 +609,15 @@ int main (int argc, char* argv [])
exit (EXIT_FAILURE); 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 */ /* Intialize the target translation tables */
TgtTranslateInit (); TgtTranslateInit ();

View File

@@ -39,6 +39,7 @@
/* common */ /* common */
#include "check.h" #include "check.h"
#include "cpu.h"
#include "strbuf.h" #include "strbuf.h"
#include "version.h" #include "version.h"
#include "xmalloc.h" #include "xmalloc.h"
@@ -49,7 +50,6 @@
#include "asmlabel.h" #include "asmlabel.h"
#include "casenode.h" #include "casenode.h"
#include "codeseg.h" #include "codeseg.h"
#include "cpu.h"
#include "dataseg.h" #include "dataseg.h"
#include "error.h" #include "error.h"
#include "global.h" #include "global.h"
@@ -189,7 +189,7 @@ void g_preamble (void)
void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime) 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 debug info is enabled, place a file info into the source */
{ {
if (DebugInfo) { if (DebugInfo) {
/* We have to place this into the global text segment, so it will /* We have to place this into the global text segment, so it will
* appear before all .dbg line statements. * appear before all .dbg line statements.

View File

@@ -39,6 +39,7 @@
/* common */ /* common */
#include "abend.h" #include "abend.h"
#include "chartype.h" #include "chartype.h"
#include "cpu.h"
#include "print.h" #include "print.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "xsprintf.h" #include "xsprintf.h"
@@ -58,7 +59,6 @@
#include "coptstore.h" #include "coptstore.h"
#include "coptsub.h" #include "coptsub.h"
#include "copttest.h" #include "copttest.h"
#include "cpu.h"
#include "error.h" #include "error.h"
#include "global.h" #include "global.h"
#include "codeopt.h" #include "codeopt.h"

View File

@@ -33,11 +33,13 @@
/* common */
#include "cpu.h"
/* cc65 */ /* cc65 */
#include "codeent.h" #include "codeent.h"
#include "codeinfo.h" #include "codeinfo.h"
#include "codeopt.h" #include "codeopt.h"
#include "cpu.h"
#include "error.h" #include "error.h"
#include "coptind.h" #include "coptind.h"

View File

@@ -35,10 +35,12 @@
#include <stdlib.h> #include <stdlib.h>
/* common */
#include "cpu.h"
/* cc65 */ /* cc65 */
#include "codeent.h" #include "codeent.h"
#include "codeinfo.h" #include "codeinfo.h"
#include "cpu.h"
#include "coptsize.h" #include "coptsize.h"

View File

@@ -42,6 +42,7 @@
#include "abend.h" #include "abend.h"
#include "chartype.h" #include "chartype.h"
#include "cmdline.h" #include "cmdline.h"
#include "cpu.h"
#include "debugflag.h" #include "debugflag.h"
#include "fname.h" #include "fname.h"
#include "print.h" #include "print.h"
@@ -55,7 +56,6 @@
#include "asmcode.h" #include "asmcode.h"
#include "compile.h" #include "compile.h"
#include "codeopt.h" #include "codeopt.h"
#include "cpu.h"
#include "error.h" #include "error.h"
#include "global.h" #include "global.h"
#include "incpath.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) static void OptCPU (const char* Opt, const char* Arg)
/* Handle the --cpu option */ /* Handle the --cpu option */
{ {
if (strcmp (Arg, "6502") == 0) { CPU = FindCPU (Arg);
CPU = CPU_6502; if (CPU != CPU_6502 && CPU != CPU_65C02) {
} else if (strcmp (Arg, "65C02") == 0) {
CPU = CPU_65C02;
} else {
AbEnd ("Invalid argument for %s: `%s'", Opt, Arg); AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
} }
} }
@@ -795,23 +792,23 @@ int main (int argc, char* argv[])
OutputFile = MakeFilename (InputFile, ".s"); 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! */ /* Go! */
Compile (InputFile); Compile (InputFile);
/* Create the output file if we didn't had any errors */ /* Create the output file if we didn't had any errors */
if (ErrorCount == 0 || Debug) { if (ErrorCount == 0 || Debug) {
FILE* F;
#if 0
/* Optimize the output if requested */
if (Optimize) {
OptDoOpt ();
}
#endif
/* Open the file */ /* Open the file */
F = fopen (OutputFile, "w"); FILE* F = fopen (OutputFile, "w");
if (F == 0) { if (F == 0) {
Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno)); Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
} }

View File

@@ -46,7 +46,6 @@ OBJS = anonname.o \
coptstore.o \ coptstore.o \
coptsub.o \ coptsub.o \
copttest.o \ copttest.o \
cpu.o \
dataseg.o \ dataseg.o \
datatype.o \ datatype.o \
declare.o \ declare.o \

View File

@@ -67,7 +67,6 @@ OBJS = anonname.obj \
coptstore.obj \ coptstore.obj \
coptsub.obj \ coptsub.obj \
copttest.obj \ copttest.obj \
cpu.obj \
dataseg.obj \ dataseg.obj \
datatype.obj \ datatype.obj \
declare.obj \ declare.obj \

View File

@@ -39,10 +39,10 @@
/* common */ /* common */
#include "check.h" #include "check.h"
#include "cpu.h"
/* cc65 */ /* cc65 */
#include "codeinfo.h" #include "codeinfo.h"
#include "cpu.h"
#include "error.h" #include "error.h"
#include "opcodes.h" #include "opcodes.h"

View File

@@ -1,15 +1,15 @@
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* cpu.c */ /* cpu.c */
/* */ /* */
/* CPU type definitions */ /* CPU specifications */
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000 Ullrich von Bassewitz */ /* (C) 2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Römerstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -33,18 +33,55 @@
#include <string.h>
/* common */
#include "cpu.h" #include "cpu.h"
/*****************************************************************************/ /*****************************************************************************/
/* Data */ /* Data */
/*****************************************************************************/ /*****************************************************************************/
/* Current CPU */ /* CPU used */
CPUType CPU = CPU_6502; 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;
}

View File

@@ -1,15 +1,15 @@
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* cpu.h */ /* cpu.h */
/* */ /* */
/* CPU type definitions */ /* CPU specifications */
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000 Ullrich von Bassewitz */ /* (C) 2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Römerstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -39,19 +39,39 @@
/*****************************************************************************/ /*****************************************************************************/
/* Data */ /* Data */
/*****************************************************************************/ /*****************************************************************************/
/* Supported CPUs */ /* CPUs */
typedef enum CPUType { typedef enum {
CPU_UNKNOWN = -1, /* Not specified or invalid target */
CPU_6502, CPU_6502,
CPU_65C02 CPU_65C02,
} CPUType; CPU_65816,
CPU_SUNPLUS, /* Not in the freeware version - sorry */
CPU_COUNT /* Number of different CPUs */
} cpu_t;
/* Current CPU */ /* CPU used */
extern CPUType CPU; 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.
*/

View File

@@ -15,6 +15,7 @@ OBJS = abend.o \
check.o \ check.o \
cmdline.o \ cmdline.o \
coll.o \ coll.o \
cpu.o \
debugflag.o \ debugflag.o \
exprdefs.o \ exprdefs.o \
filepos.o \ filepos.o \

View File

@@ -47,6 +47,7 @@ OBJS = abend.obj \
check.obj \ check.obj \
cmdline.obj \ cmdline.obj \
coll.obj \ coll.obj \
cpu.obj \
debugflag.obj \ debugflag.obj \
exprdefs.obj \ exprdefs.obj \
filepos.obj \ filepos.obj \

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2002 Ullrich von Bassewitz */ /* (C) 2000-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -69,7 +69,30 @@ const char* TargetNames [TGT_COUNT] = {
"geos", "geos",
"lunix", "lunix",
"atmos" "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 */
};

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2002 Ullrich von Bassewitz */ /* (C) 2000-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -38,6 +38,11 @@
/* common */
#include "cpu.h"
/*****************************************************************************/ /*****************************************************************************/
/* Data */ /* Data */
/*****************************************************************************/ /*****************************************************************************/
@@ -71,7 +76,10 @@ typedef enum {
extern target_t Target; extern target_t Target;
/* Table with target names */ /* 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];