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