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 */
129 OPCODE_COUNT /* Number of opcodes available */
132 /* Addressing modes (bitmapped). */
134 AM65_IMP, /* implicit */
135 AM65_ACC, /* accumulator */
136 AM65_IMM, /* immidiate */
137 AM65_ZP, /* zeropage */
138 AM65_ZPX, /* zeropage,X */
139 AM65_ABS, /* absolute */
140 AM65_ABSX, /* absolute,X */
141 AM65_ABSY, /* absolute,Y */
142 AM65_ZPX_IND, /* (zeropage,x) */
143 AM65_ZP_INDY, /* (zeropage),y */
144 AM65_ZP_IND, /* (zeropage) */
145 AM65_BRA /* branch */
148 /* Branch conditions */
161 #define OF_NONE 0x0000U /* No additional information */
162 #define OF_UBRA 0x0001U /* Unconditional branch */
163 #define OF_CBRA 0x0002U /* Conditional branch */
164 #define OF_ZBRA 0x0004U /* Branch on zero flag condition */
165 #define OF_FBRA 0x0008U /* Branch on cond set by a load */
166 #define OF_LBRA 0x0010U /* Jump/branch is long */
167 #define OF_RET 0x0020U /* Return from function */
168 #define OF_LOAD 0x0040U /* Register load */
169 #define OF_XFR 0x0080U /* Transfer instruction */
170 #define OF_CALL 0x0100U /* A subroutine call */
173 #define OF_BRA (OF_UBRA | OF_CBRA) /* Operation is a jump/branch */
174 #define OF_DEAD (OF_UBRA | OF_RET) /* Dead end - no exec behind this point */
176 /* Opcode description */
178 opc_t OPC; /* Opcode */
179 char Mnemo[8]; /* Mnemonic */
180 unsigned char Size; /* Size, 0 = check addressing mode */
181 unsigned char Use; /* Registers used by this insn */
182 unsigned char Chg; /* Registers changed by this insn */
183 unsigned short Info; /* Additional information */
186 /* Opcode description table */
187 extern const OPCDesc OPCTable[OPCODE_COUNT];
191 /*****************************************************************************/
193 /*****************************************************************************/
197 const OPCDesc* FindOpcode (const char* OPC);
198 /* Find the given opcode and return the opcode description. If the opcode was
199 * not found, NULL is returned.
202 unsigned GetInsnSize (opc_t OPC, am_t AM);
203 /* Return the size of the given instruction */
205 #if defined(HAVE_INLINE)
206 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
207 /* Get an opcode description */
209 /* Return the description */
210 return &OPCTable [OPC];
213 # define GetOPCDesc(OPC) (&OPCTable [(OPC)])
216 #if defined(HAVE_INLINE)
217 INLINE unsigned GetOPCInfo (opc_t OPC)
218 /* Get opcode information */
220 /* Return the info */
221 return OPCTable[OPC].Info;
224 # define GetOPCInfo(OPC) (OPCTable[(OPC)].Info)
227 unsigned char GetAMUseInfo (am_t AM);
228 /* Get usage info for the given addressing mode (addressing modes that use
229 * index registers return REG_r info for these registers).
232 opc_t GetInverseBranch (opc_t OPC);
233 /* Return a branch that reverse the condition of the branch given in OPC */
235 opc_t MakeShortBranch (opc_t OPC);
236 /* Return the short version of the given branch. If the branch is already
237 * a short branch, return the opcode unchanged.
240 opc_t MakeLongBranch (opc_t OPC);
241 /* Return the long version of the given branch. If the branch is already
242 * a long branch, return the opcode unchanged.
245 bc_t GetBranchCond (opc_t OPC);
246 /* Get the condition for the conditional branch in OPC */
248 bc_t GetInverseCond (bc_t BC);
249 /* Return the inverse condition of the given one */
253 /* End of opcodes.h */