]> git.sur5r.net Git - cc65/blob - src/cc65/opcodes.h
Squashed one more bug in the switch statement
[cc65] / src / cc65 / opcodes.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 opcodes.h                                 */
4 /*                                                                           */
5 /*                  Opcode and addressing mode definitions                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
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 #ifndef OPCODES_H
37 #define OPCODES_H
38
39
40
41 /* common */
42 #include "inline.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Data                                    */
48 /*****************************************************************************/
49
50
51
52 /* Definitions for the possible opcodes */
53 typedef enum {
54
55     /* Opcodes for the virtual stack machine */
56     OPC_CALL,
57     OPC_ENTER,
58     OPC_JMP,
59     OPC_LDA,
60     OPC_LDAX,
61     OPC_LDEAX,
62     OPC_LEA,
63     OPC_LEAVE,
64     OPC_PHA,
65     OPC_PHAX,
66     OPC_PHEAX,
67     OPC_RET,
68     OPC_SPACE,
69     OPC_STA,
70     OPC_STAX,
71     OPC_STEAX,
72
73     /* 65XX opcodes */
74     OP65_ADC,
75     OP65_AND,
76     OP65_ASL,
77     OP65_BCC,
78     OP65_BCS,
79     OP65_BEQ,
80     OP65_BIT,
81     OP65_BMI,
82     OP65_BNE,
83     OP65_BPL,
84     OP65_BRA,
85     OP65_BRK,
86     OP65_BVC,
87     OP65_BVS,
88     OP65_CLC,
89     OP65_CLD,
90     OP65_CLI,
91     OP65_CLV,
92     OP65_CMP,
93     OP65_CPX,
94     OP65_CPY,
95     OP65_DEA,
96     OP65_DEC,
97     OP65_DEX,
98     OP65_DEY,
99     OP65_EOR,
100     OP65_INA,
101     OP65_INC,
102     OP65_INX,
103     OP65_INY,
104     OP65_JCC,
105     OP65_JCS,
106     OP65_JEQ,
107     OP65_JMI,
108     OP65_JMP,
109     OP65_JNE,
110     OP65_JPL,
111     OP65_JSR,
112     OP65_JVC,
113     OP65_JVS,
114     OP65_LDA,
115     OP65_LDX,
116     OP65_LDY,
117     OP65_LSR,
118     OP65_NOP,
119     OP65_ORA,
120     OP65_PHA,
121     OP65_PHP,
122     OP65_PHX,
123     OP65_PHY,
124     OP65_PLA,
125     OP65_PLP,
126     OP65_PLX,
127     OP65_PLY,
128     OP65_ROL,
129     OP65_ROR,
130     OP65_RTI,
131     OP65_RTS,
132     OP65_SBC,
133     OP65_SEC,
134     OP65_SED,
135     OP65_SEI,
136     OP65_STA,
137     OP65_STX,
138     OP65_STY,
139     OP65_TAX,
140     OP65_TAY,
141     OP65_TRB,
142     OP65_TSB,
143     OP65_TSX,
144     OP65_TXA,
145     OP65_TXS,
146     OP65_TYA,
147
148     /* Number of opcodes available */
149     OPCODE_COUNT,
150
151     /* Several other opcode information constants */
152     OP65_FIRST = OP65_ADC,
153     OP65_LAST  = OP65_TYA,
154     OP65_COUNT = OP65_LAST - OP65_FIRST + 1
155 } opc_t;
156
157 /* Addressing modes */
158 typedef enum {
159
160     /* Addressing modes of the virtual stack machine */
161     AM_IMP,
162     AM_IMM,
163     AM_STACK,
164     AM_ABS,
165
166     /* 65XX addressing modes */
167     AM65_IMP,                   /* implicit */
168     AM65_ACC,                   /* accumulator */
169     AM65_IMM,                   /* immidiate */
170     AM65_ZP,                    /* zeropage */
171     AM65_ZPX,                   /* zeropage,X */
172     AM65_ZPY,                   /* zeropage,Y */
173     AM65_ABS,                   /* absolute */
174     AM65_ABSX,                  /* absolute,X */
175     AM65_ABSY,                  /* absolute,Y */
176     AM65_ZPX_IND,               /* (zeropage,x) */
177     AM65_ZP_INDY,               /* (zeropage),y */
178     AM65_ZP_IND,                /* (zeropage) */
179     AM65_BRA                    /* branch */
180 } am_t;
181
182 /* Branch conditions */
183 typedef enum {
184     BC_CC,
185     BC_CS,
186     BC_EQ,
187     BC_MI,
188     BC_NE,
189     BC_PL,
190     BC_VC,
191     BC_VS
192 } bc_t;
193
194 /* Opcode info */
195 #define OF_NONE         0x0000U /* No additional information */
196 #define OF_CPU_6502     0x0000U /* 6502 opcode */
197 #define OF_CPU_VM       0x0001U /* Virtual machine opcode */
198 #define OF_MASK_CPU     0x0001U /* Mask for the cpu field */
199 #define OF_UBRA         0x0010U /* Unconditional branch */
200 #define OF_CBRA         0x0020U /* Conditional branch */
201 #define OF_ZBRA         0x0040U /* Branch on zero flag condition */
202 #define OF_FBRA         0x0080U /* Branch on cond set by a load */
203 #define OF_LBRA         0x0100U /* Jump/branch is long */
204 #define OF_RET          0x0200U /* Return from function */
205 #define OF_LOAD         0x0400U /* Register load */
206 #define OF_STORE        0x0800U /* Register store */
207 #define OF_XFR          0x1000U /* Transfer instruction */
208 #define OF_CALL         0x2000U /* A subroutine call */
209
210 /* Combined infos */
211 #define OF_BRA  (OF_UBRA | OF_CBRA)     /* Operation is a jump/branch */
212 #define OF_DEAD (OF_UBRA | OF_RET)      /* Dead end - no exec behind this point */
213
214 /* Opcode description */
215 typedef struct {
216     opc_t           OPC;                /* Opcode */
217     char            Mnemo[9];           /* Mnemonic */
218     unsigned char   Size;               /* Size, 0 = check addressing mode */
219     unsigned char   Use;                /* Registers used by this insn */
220     unsigned char   Chg;                /* Registers changed by this insn */
221     unsigned short  Info;               /* Additional information */
222 } OPCDesc;
223
224 /* Opcode description table */
225 extern const OPCDesc OPCTable[OPCODE_COUNT];
226
227
228
229 /*****************************************************************************/
230 /*                                   Code                                    */
231 /*****************************************************************************/
232
233
234
235 const OPCDesc* FindOP65 (const char* OPC);
236 /* Find the given opcode and return the opcode description. If the opcode was
237  * not found, NULL is returned.
238  */
239
240 unsigned GetInsnSize (opc_t OPC, am_t AM);
241 /* Return the size of the given instruction */
242
243 #if defined(HAVE_INLINE)
244 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
245 /* Get an opcode description */
246 {
247     /* Return the description */
248     return &OPCTable [OPC];
249 }
250 #else
251 #  define GetOPCDesc(OPC)       (&OPCTable [(OPC)])
252 #endif
253
254 #if defined(HAVE_INLINE)
255 INLINE unsigned GetOPCInfo (opc_t OPC)
256 /* Get opcode information */
257 {
258     /* Return the info */
259     return OPCTable[OPC].Info;
260 }
261 #else
262 #  define GetOPCInfo(OPC)       (OPCTable[(OPC)].Info)
263 #endif
264
265 unsigned char GetAMUseInfo (am_t AM);
266 /* Get usage info for the given addressing mode (addressing modes that use
267  * index registers return REG_r info for these registers).
268  */
269
270 opc_t GetInverseBranch (opc_t OPC);
271 /* Return a branch that reverse the condition of the branch given in OPC */
272
273 opc_t MakeShortBranch (opc_t OPC);
274 /* Return the short version of the given branch. If the branch is already
275  * a short branch, return the opcode unchanged.
276  */
277
278 opc_t MakeLongBranch (opc_t OPC);
279 /* Return the long version of the given branch. If the branch is already
280  * a long branch, return the opcode unchanged.
281  */
282
283 bc_t GetBranchCond (opc_t OPC);
284 /* Get the condition for the conditional branch in OPC */
285
286 bc_t GetInverseCond (bc_t BC);
287 /* Return the inverse condition of the given one */
288
289
290
291 /* End of opcodes.h */
292 #endif
293
294
295