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