]> git.sur5r.net Git - cc65/blob - src/cc65/opcodes.h
Polishing and minor corrections
[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     OPC_ADC,
55     OPC_AND,
56     OPC_ASL,
57     OPC_BCC,
58     OPC_BCS,
59     OPC_BEQ,
60     OPC_BIT,
61     OPC_BMI,
62     OPC_BNE,
63     OPC_BPL,
64     OPC_BRA,
65     OPC_BRK,
66     OPC_BVC,
67     OPC_BVS,
68     OPC_CLC,
69     OPC_CLD,
70     OPC_CLI,
71     OPC_CLV,
72     OPC_CMP,
73     OPC_CPX,
74     OPC_CPY,
75     OPC_DEA,
76     OPC_DEC,
77     OPC_DEX,
78     OPC_DEY,
79     OPC_EOR,
80     OPC_INA,
81     OPC_INC,
82     OPC_INX,
83     OPC_INY,
84     OPC_JCC,
85     OPC_JCS,
86     OPC_JEQ,
87     OPC_JMI,
88     OPC_JMP,
89     OPC_JNE,
90     OPC_JPL,
91     OPC_JSR,
92     OPC_JVC,
93     OPC_JVS,
94     OPC_LDA,
95     OPC_LDX,
96     OPC_LDY,
97     OPC_LSR,
98     OPC_NOP,
99     OPC_ORA,
100     OPC_PHA,
101     OPC_PHP,
102     OPC_PHX,
103     OPC_PHY,
104     OPC_PLA,
105     OPC_PLP,
106     OPC_PLX,
107     OPC_PLY,
108     OPC_ROL,
109     OPC_ROR,
110     OPC_RTI,
111     OPC_RTS,
112     OPC_SBC,
113     OPC_SEC,
114     OPC_SED,
115     OPC_SEI,
116     OPC_STA,
117     OPC_STX,
118     OPC_STY,
119     OPC_TAX,
120     OPC_TAY,
121     OPC_TRB,
122     OPC_TSB,
123     OPC_TSX,
124     OPC_TXA,
125     OPC_TXS,
126     OPC_TYA,
127     OPC_COUNT                           /* Number of opcodes available */
128 } opc_t;
129
130 /* Addressing modes (bitmapped). */
131 typedef enum {
132     AM_IMP      = 0x0001,               /* implicit */
133     AM_ACC      = 0x0002,               /* accumulator */
134     AM_IMM      = 0x0004,               /* immidiate */
135     AM_ZP       = 0x0008,               /* zeropage */
136     AM_ZPX      = 0x0010,               /* zeropage,X */
137     AM_ABS      = 0x0020,               /* absolute */
138     AM_ABSX     = 0x0040,               /* absolute,X */
139     AM_ABSY     = 0x0080,               /* absolute,Y */
140     AM_ZPX_IND  = 0x0100,               /* (zeropage,x) */
141     AM_ZP_INDY  = 0x0200,               /* (zeropage),y */
142     AM_ZP_IND   = 0x0400,               /* (zeropage) */
143     AM_BRA      = 0x0800                /* branch */
144 } am_t;
145
146 /* Branch conditions */
147 typedef enum {
148     BC_CC,
149     BC_CS,
150     BC_EQ,
151     BC_MI,
152     BC_NE,
153     BC_PL,
154     BC_SR,
155     BC_VC,
156     BC_VS
157 } bc_t;
158
159 /* Opcode info */
160 #define OF_NONE 0x0000U                 /* No additional information */
161 #define OF_UBRA 0x0001U                 /* Unconditional branch */
162 #define OF_CBRA 0x0002U                 /* Conditional branch */
163 #define OF_ZBRA 0x0004U                 /* Branch on zero flag condition */
164 #define OF_FBRA 0x0008U                 /* Branch on cond set by a load */
165 #define OF_LBRA 0x0010U                 /* Jump/branch is long */
166 #define OF_RET  0x0020U                 /* Return from function */
167 #define OF_LOAD 0x0040U                 /* Register load */
168 #define OF_XFR  0x0080                  /* Transfer instruction */
169 #define OF_BRA  (OF_UBRA|OF_CBRA)       /* Operation is a jump/branch */
170 #define OF_DEAD (OF_UBRA|OF_RET)        /* Dead end - no exec behind this point */
171
172 /* Opcode description */
173 typedef struct {
174     opc_t           OPC;                /* Opcode */
175     char            Mnemo[4];           /* Mnemonic */
176     unsigned char   Size;               /* Size, 0 = check addressing mode */
177     unsigned char   Use;                /* Registers used by this insn */
178     unsigned char   Chg;                /* Registers changed by this insn */
179     unsigned char   Info;               /* Additional information */
180 } OPCDesc;
181
182 /* Opcode description table */
183 extern const OPCDesc OPCTable[OPC_COUNT];
184
185
186
187 /*****************************************************************************/
188 /*                                   Code                                    */
189 /*****************************************************************************/
190
191
192
193 const OPCDesc* FindOpcode (const char* OPC);
194 /* Find the given opcode and return the opcode description. If the opcode was
195  * not found, NULL is returned.
196  */
197
198 unsigned GetInsnSize (opc_t OPC, am_t AM);
199 /* Return the size of the given instruction */
200
201 #if defined(HAVE_INLINE)
202 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
203 /* Get an opcode description */
204 {
205     /* Return the description */
206     return &OPCTable [OPC];
207 }
208 #else
209 #  define GetOPCDesc(OPC)       (&OPCTable [(OPC)])
210 #endif
211
212 #if defined(HAVE_INLINE)
213 INLINE unsigned char GetOPCInfo (opc_t OPC)
214 /* Get opcode information */
215 {
216     /* Return the info */
217     return OPCTable[OPC].Info;
218 }
219 #else
220 #  define GetOPCInfo(OPC)       (OPCTable[(OPC)].Info)
221 #endif
222
223 unsigned char GetAMUseInfo (am_t AM);
224 /* Get usage info for the given addressing mode (addressing modes that use
225  * index registers return REG_r info for these registers).
226  */
227
228 opc_t GetInverseBranch (opc_t OPC);
229 /* Return a branch that reverse the condition of the branch given in OPC */
230
231 opc_t MakeShortBranch (opc_t OPC);
232 /* Return the short version of the given branch. If the branch is already
233  * a short branch, return the opcode unchanged.
234  */
235
236 opc_t MakeLongBranch (opc_t OPC);
237 /* Return the long version of the given branch. If the branch is already
238  * a long branch, return the opcode unchanged.
239  */
240
241 bc_t GetBranchCond (opc_t OPC);
242 /* Get the condition for the conditional branch in OPC */
243
244 bc_t GetInverseCond (bc_t BC);
245 /* Return the inverse condition of the given one */
246
247 opc_t GetLongBranch (bc_t BC);
248 /* Return a long branch for the given branch condition */
249
250 opc_t GetShortBranch (bc_t BC);
251 /* Return a short branch for the given branch condition */
252
253
254
255 /* End of opcodes.h */
256 #endif
257
258
259