]> git.sur5r.net Git - cc65/blob - src/cc65/opcodes.h
Avoid a copy of the line contents
[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_ABS,                   /* absolute */
173     AM65_ABSX,                  /* absolute,X */
174     AM65_ABSY,                  /* absolute,Y */
175     AM65_ZPX_IND,               /* (zeropage,x) */
176     AM65_ZP_INDY,               /* (zeropage),y */
177     AM65_ZP_IND,                /* (zeropage) */
178     AM65_BRA                    /* branch */
179 } am_t;
180
181 /* Branch conditions */
182 typedef enum {
183     BC_CC,
184     BC_CS,
185     BC_EQ,
186     BC_MI,
187     BC_NE,
188     BC_PL,
189     BC_VC,
190     BC_VS
191 } bc_t;
192
193 /* Opcode info */
194 #define OF_NONE         0x0000U /* No additional information */
195 #define OF_CPU_6502     0x0000U /* 6502 opcode */
196 #define OF_CPU_VM       0x0001U /* Virtual machine opcode */
197 #define OF_MASK_CPU     0x0001U /* Mask for the cpu field */
198 #define OF_UBRA         0x0010U /* Unconditional branch */
199 #define OF_CBRA         0x0020U /* Conditional branch */
200 #define OF_ZBRA         0x0040U /* Branch on zero flag condition */
201 #define OF_FBRA         0x0080U /* Branch on cond set by a load */
202 #define OF_LBRA         0x0100U /* Jump/branch is long */
203 #define OF_RET          0x0200U /* Return from function */
204 #define OF_LOAD         0x0400U /* Register load */
205 #define OF_XFR          0x0800U /* Transfer instruction */
206 #define OF_CALL         0x1000U /* A subroutine call */
207
208 /* Combined infos */
209 #define OF_BRA  (OF_UBRA | OF_CBRA)     /* Operation is a jump/branch */
210 #define OF_DEAD (OF_UBRA | OF_RET)      /* Dead end - no exec behind this point */
211
212 /* Opcode description */
213 typedef struct {
214     opc_t           OPC;                /* Opcode */
215     char            Mnemo[9];           /* Mnemonic */
216     unsigned char   Size;               /* Size, 0 = check addressing mode */
217     unsigned char   Use;                /* Registers used by this insn */
218     unsigned char   Chg;                /* Registers changed by this insn */
219     unsigned short  Info;               /* Additional information */
220 } OPCDesc;
221
222 /* Opcode description table */
223 extern const OPCDesc OPCTable[OPCODE_COUNT];
224
225
226
227 /*****************************************************************************/
228 /*                                   Code                                    */
229 /*****************************************************************************/
230
231
232
233 const OPCDesc* FindOP65 (const char* OPC);
234 /* Find the given opcode and return the opcode description. If the opcode was
235  * not found, NULL is returned.
236  */
237
238 unsigned GetInsnSize (opc_t OPC, am_t AM);
239 /* Return the size of the given instruction */
240
241 #if defined(HAVE_INLINE)
242 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
243 /* Get an opcode description */
244 {
245     /* Return the description */
246     return &OPCTable [OPC];
247 }
248 #else
249 #  define GetOPCDesc(OPC)       (&OPCTable [(OPC)])
250 #endif
251
252 #if defined(HAVE_INLINE)
253 INLINE unsigned GetOPCInfo (opc_t OPC)
254 /* Get opcode information */
255 {
256     /* Return the info */
257     return OPCTable[OPC].Info;
258 }
259 #else
260 #  define GetOPCInfo(OPC)       (OPCTable[(OPC)].Info)
261 #endif
262
263 unsigned char GetAMUseInfo (am_t AM);
264 /* Get usage info for the given addressing mode (addressing modes that use
265  * index registers return REG_r info for these registers).
266  */
267
268 opc_t GetInverseBranch (opc_t OPC);
269 /* Return a branch that reverse the condition of the branch given in OPC */
270
271 opc_t MakeShortBranch (opc_t OPC);
272 /* Return the short version of the given branch. If the branch is already
273  * a short branch, return the opcode unchanged.
274  */
275
276 opc_t MakeLongBranch (opc_t OPC);
277 /* Return the long version of the given branch. If the branch is already
278  * a long branch, return the opcode unchanged.
279  */
280
281 bc_t GetBranchCond (opc_t OPC);
282 /* Get the condition for the conditional branch in OPC */
283
284 bc_t GetInverseCond (bc_t BC);
285 /* Return the inverse condition of the given one */
286
287
288
289 /* End of opcodes.h */
290 #endif
291
292
293