1 /*****************************************************************************/
5 /* Opcode and addressing mode definitions */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
46 /*****************************************************************************/
48 /*****************************************************************************/
52 /* Definitions for the possible opcodes */
127 OPC_COUNT /* Number of opcodes available */
130 /* Addressing modes (bitmapped). */
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 */
146 /* Branch conditions */
159 #define OF_NONE 0x0000U /* No additional information */
160 #define OF_UBRA 0x0001U /* Unconditional branch */
161 #define OF_CBRA 0x0002U /* Conditional branch */
162 #define OF_ZBRA 0x0004U /* Branch on zero flag condition */
163 #define OF_FBRA 0x0008U /* Branch on cond set by a load */
164 #define OF_LBRA 0x0010U /* Jump/branch is long */
165 #define OF_RET 0x0020U /* Return from function */
166 #define OF_LOAD 0x0040U /* Register load */
167 #define OF_XFR 0x0080 /* Transfer instruction */
168 #define OF_BRA (OF_UBRA|OF_CBRA) /* Operation is a jump/branch */
169 #define OF_DEAD (OF_UBRA|OF_RET) /* Dead end - no exec behind this point */
171 /* Opcode description */
173 opc_t OPC; /* Opcode */
174 char Mnemo[4]; /* Mnemonic */
175 unsigned char Size; /* Size, 0 = check addressing mode */
176 unsigned char Use; /* Registers used by this insn */
177 unsigned char Chg; /* Registers changed by this insn */
178 unsigned char Info; /* Additional information */
181 /* Opcode description table */
182 extern const OPCDesc OPCTable[OPC_COUNT];
186 /*****************************************************************************/
188 /*****************************************************************************/
192 const OPCDesc* FindOpcode (const char* OPC);
193 /* Find the given opcode and return the opcode description. If the opcode was
194 * not found, NULL is returned.
197 unsigned GetInsnSize (opc_t OPC, am_t AM);
198 /* Return the size of the given instruction */
200 #if defined(HAVE_INLINE)
201 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
202 /* Get an opcode description */
204 /* Return the description */
205 return &OPCTable [OPC];
208 # define GetOPCDesc(OPC) (&OPCTable [(OPC)])
211 #if defined(HAVE_INLINE)
212 INLINE unsigned char GetOPCInfo (opc_t OPC)
213 /* Get opcode information */
215 /* Return the info */
216 return OPCTable[OPC].Info;
219 # define GetOPCInfo(OPC) (OPCTable[(OPC)].Info)
222 unsigned char GetAMUseInfo (am_t AM);
223 /* Get usage info for the given addressing mode (addressing modes that use
224 * index registers return REG_r info for these registers).
227 opc_t GetInverseBranch (opc_t OPC);
228 /* Return a branch that reverse the condition of the branch given in OPC */
230 opc_t MakeShortBranch (opc_t OPC);
231 /* Return the short version of the given branch. If the branch is already
232 * a short branch, return the opcode unchanged.
235 opc_t MakeLongBranch (opc_t OPC);
236 /* Return the long version of the given branch. If the branch is already
237 * a long branch, return the opcode unchanged.
240 bc_t GetBranchCond (opc_t OPC);
241 /* Get the condition for the conditional branch in OPC */
243 bc_t GetInverseCond (bc_t BC);
244 /* Return the inverse condition of the given one */
248 /* End of opcodes.h */