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 */
130 /* Number of opcodes available */
133 /* Several other opcode information constants */
134 OP65_FIRST = OP65_ADC,
135 OP65_LAST = OP65_TYA,
136 OP65_COUNT = OP65_LAST - OP65_FIRST + 1
139 /* Addressing modes */
142 /* Addressing modes of the virtual stack machine */
148 /* 65XX addressing modes */
149 AM65_IMP, /* implicit */
150 AM65_ACC, /* accumulator */
151 AM65_IMM, /* immidiate */
152 AM65_ZP, /* zeropage */
153 AM65_ZPX, /* zeropage,X */
154 AM65_ZPY, /* zeropage,Y */
155 AM65_ABS, /* absolute */
156 AM65_ABSX, /* absolute,X */
157 AM65_ABSY, /* absolute,Y */
158 AM65_ZPX_IND, /* (zeropage,x) */
159 AM65_ZP_INDY, /* (zeropage),y */
160 AM65_ZP_IND, /* (zeropage) */
161 AM65_BRA /* branch */
164 /* Branch conditions */
177 #define OF_NONE 0x0000U /* No additional information */
178 #define OF_UBRA 0x0001U /* Unconditional branch */
179 #define OF_CBRA 0x0002U /* Conditional branch */
180 #define OF_ZBRA 0x0004U /* Branch on zero flag condition */
181 #define OF_FBRA 0x0008U /* Branch on cond set by a load */
182 #define OF_LBRA 0x0010U /* Jump/branch is long */
183 #define OF_RET 0x0020U /* Return from function */
184 #define OF_LOAD 0x0040U /* Register load */
185 #define OF_STORE 0x0080U /* Register store */
186 #define OF_XFR 0x0100U /* Transfer instruction */
187 #define OF_CALL 0x0200U /* A subroutine call */
188 #define OF_REG_INCDEC 0x0400U /* A register increment or decrement */
189 #define OF_SETF 0x0800U /* Insn will set all load flags (not carry) */
190 #define OF_CMP 0x1000U /* A compare A/X/Y instruction */
193 #define OF_BRA (OF_UBRA | OF_CBRA) /* Operation is a jump/branch */
194 #define OF_DEAD (OF_UBRA | OF_RET) /* Dead end - no exec behind this point */
196 /* Opcode description */
198 opc_t OPC; /* Opcode */
199 char Mnemo[9]; /* Mnemonic */
200 unsigned char Size; /* Size, 0 = check addressing mode */
201 unsigned short Use; /* Registers used by this insn */
202 unsigned short Chg; /* Registers changed by this insn */
203 unsigned short Info; /* Additional information */
206 /* Opcode description table */
207 extern const OPCDesc OPCTable[OPCODE_COUNT];
211 /*****************************************************************************/
213 /*****************************************************************************/
217 const OPCDesc* FindOP65 (const char* OPC);
218 /* Find the given opcode and return the opcode description. If the opcode was
219 * not found, NULL is returned.
222 unsigned GetInsnSize (opc_t OPC, am_t AM);
223 /* Return the size of the given instruction */
225 #if defined(HAVE_INLINE)
226 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
227 /* Get an opcode description */
229 /* Return the description */
230 return &OPCTable [OPC];
233 # define GetOPCDesc(OPC) (&OPCTable [(OPC)])
236 #if defined(HAVE_INLINE)
237 INLINE unsigned GetOPCInfo (opc_t OPC)
238 /* Get opcode information */
240 /* Return the info */
241 return OPCTable[OPC].Info;
244 # define GetOPCInfo(OPC) (OPCTable[(OPC)].Info)
247 unsigned char GetAMUseInfo (am_t AM);
248 /* Get usage info for the given addressing mode (addressing modes that use
249 * index registers return REG_r info for these registers).
252 opc_t GetInverseBranch (opc_t OPC);
253 /* Return a branch that reverse the condition of the branch given in OPC */
255 opc_t MakeShortBranch (opc_t OPC);
256 /* Return the short version of the given branch. If the branch is already
257 * a short branch, return the opcode unchanged.
260 opc_t MakeLongBranch (opc_t OPC);
261 /* Return the long version of the given branch. If the branch is already
262 * a long branch, return the opcode unchanged.
265 bc_t GetBranchCond (opc_t OPC);
266 /* Get the condition for the conditional branch in OPC */
268 bc_t GetInverseCond (bc_t BC);
269 /* Return the inverse condition of the given one */
273 /* End of opcodes.h */