]> git.sur5r.net Git - cc65/blob - src/common/cpu.c
Fixed LinuxDoc Tools issues in some verbatim blocks in the Atari document.
[cc65] / src / common / cpu.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   cpu.c                                   */
4 /*                                                                           */
5 /*                            CPU specifications                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2003-2011, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 /* common */
37 #include "addrsize.h"
38 #include "check.h"
39 #include "cpu.h"
40 #include "strutil.h"
41
42
43
44 /*****************************************************************************/
45 /*                                   Data                                    */
46 /*****************************************************************************/
47
48
49
50 /* CPU used */
51 cpu_t CPU = CPU_UNKNOWN;
52
53 /* Table with target names */
54 const char* CPUNames[CPU_COUNT] = {
55     "none",
56     "6502",
57     "6502X",
58     "65SC02",
59     "65C02",
60     "65816",
61     "sweet16",
62     "huc6280",
63     "m740",
64     "4510",
65 };
66
67 /* Tables with CPU instruction sets */
68 const unsigned CPUIsets[CPU_COUNT] = {
69     CPU_ISET_NONE,
70     CPU_ISET_6502,
71     CPU_ISET_6502 | CPU_ISET_6502X,
72     CPU_ISET_6502 | CPU_ISET_65SC02,
73     CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02,
74     CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02 | CPU_ISET_65816,
75     CPU_ISET_SWEET16,
76     CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02 | CPU_ISET_HUC6280,
77     CPU_ISET_6502 | CPU_ISET_M740,
78     CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02 | CPU_ISET_4510,
79 };
80
81
82
83 /*****************************************************************************/
84 /*                                   Code                                    */
85 /*****************************************************************************/
86
87
88
89 int ValidAddrSizeForCPU (unsigned char AddrSize)
90 /* Check if the given address size is valid for the current CPU */
91 {
92     switch (AddrSize) {
93         case ADDR_SIZE_DEFAULT:
94             /* Always supported */
95             return 1;
96
97         case ADDR_SIZE_ZP:
98             /* Not supported by None and Sweet16 */
99             return (CPU != CPU_NONE && CPU != CPU_SWEET16);
100
101         case ADDR_SIZE_ABS:
102             /* Not supported by None */
103             return (CPU != CPU_NONE);
104
105         case ADDR_SIZE_FAR:
106             /* Only supported by 65816 */
107             return (CPU == CPU_65816);
108
109         case ADDR_SIZE_LONG:
110             /* Not supported by any CPU */
111             return 0;
112
113         default:
114             FAIL ("Invalid address size");
115             /* NOTREACHED */
116             return 0;
117     }
118 }
119
120
121
122 cpu_t FindCPU (const char* Name)
123 /* Find a CPU by name and return the target id. CPU_UNKNOWN is returned if
124 ** the given name is no valid target.
125 */
126 {
127     unsigned I;
128
129     /* Check all CPU names */
130     for (I = 0; I < CPU_COUNT; ++I) {
131         if (StrCaseCmp (CPUNames [I], Name) == 0) {
132             return (cpu_t)I;
133         }
134     }
135
136     /* Not found */
137     return CPU_UNKNOWN;
138 }