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 */
55 /* Opcodes for the virtual stack machine */
143 /* Number of opcodes available */
146 /* Several other opcode information constants */
147 OP65_FIRST = OP65_ADC,
148 OP65_LAST = OP65_TYA,
149 OP65_COUNT = OP65_LAST - OP65_FIRST + 1
152 /* Addressing modes */
155 /* Addressing modes of the virtual stack machine */
161 /* 65XX addressing modes */
162 AM65_IMP, /* implicit */
163 AM65_ACC, /* accumulator */
164 AM65_IMM, /* immidiate */
165 AM65_ZP, /* zeropage */
166 AM65_ZPX, /* zeropage,X */
167 AM65_ABS, /* absolute */
168 AM65_ABSX, /* absolute,X */
169 AM65_ABSY, /* absolute,Y */
170 AM65_ZPX_IND, /* (zeropage,x) */
171 AM65_ZP_INDY, /* (zeropage),y */
172 AM65_ZP_IND, /* (zeropage) */
173 AM65_BRA /* branch */
176 /* Branch conditions */
189 #define OF_NONE 0x0000U /* No additional information */
190 #define OF_CPU_6502 0x0000U /* 6502 opcode */
191 #define OF_CPU_VM 0x0001U /* Virtual machine opcode */
192 #define OF_MASK_CPU 0x0001U /* Mask for the cpu field */
193 #define OF_UBRA 0x0010U /* Unconditional branch */
194 #define OF_CBRA 0x0020U /* Conditional branch */
195 #define OF_ZBRA 0x0040U /* Branch on zero flag condition */
196 #define OF_FBRA 0x0080U /* Branch on cond set by a load */
197 #define OF_LBRA 0x0100U /* Jump/branch is long */
198 #define OF_RET 0x0200U /* Return from function */
199 #define OF_LOAD 0x0400U /* Register load */
200 #define OF_XFR 0x0800U /* Transfer instruction */
201 #define OF_CALL 0x1000U /* A subroutine call */
204 #define OF_BRA (OF_UBRA | OF_CBRA) /* Operation is a jump/branch */
205 #define OF_DEAD (OF_UBRA | OF_RET) /* Dead end - no exec behind this point */
207 /* Opcode description */
209 opc_t OPC; /* Opcode */
210 char Mnemo[9]; /* Mnemonic */
211 unsigned char Size; /* Size, 0 = check addressing mode */
212 unsigned char Use; /* Registers used by this insn */
213 unsigned char Chg; /* Registers changed by this insn */
214 unsigned short Info; /* Additional information */
217 /* Opcode description table */
218 extern const OPCDesc OPCTable[OPCODE_COUNT];
222 /*****************************************************************************/
224 /*****************************************************************************/
228 const OPCDesc* FindOP65 (const char* OPC);
229 /* Find the given opcode and return the opcode description. If the opcode was
230 * not found, NULL is returned.
233 unsigned GetInsnSize (opc_t OPC, am_t AM);
234 /* Return the size of the given instruction */
236 #if defined(HAVE_INLINE)
237 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
238 /* Get an opcode description */
240 /* Return the description */
241 return &OPCTable [OPC];
244 # define GetOPCDesc(OPC) (&OPCTable [(OPC)])
247 #if defined(HAVE_INLINE)
248 INLINE unsigned GetOPCInfo (opc_t OPC)
249 /* Get opcode information */
251 /* Return the info */
252 return OPCTable[OPC].Info;
255 # define GetOPCInfo(OPC) (OPCTable[(OPC)].Info)
258 unsigned char GetAMUseInfo (am_t AM);
259 /* Get usage info for the given addressing mode (addressing modes that use
260 * index registers return REG_r info for these registers).
263 opc_t GetInverseBranch (opc_t OPC);
264 /* Return a branch that reverse the condition of the branch given in OPC */
266 opc_t MakeShortBranch (opc_t OPC);
267 /* Return the short version of the given branch. If the branch is already
268 * a short branch, return the opcode unchanged.
271 opc_t MakeLongBranch (opc_t OPC);
272 /* Return the long version of the given branch. If the branch is already
273 * a long branch, return the opcode unchanged.
276 bc_t GetBranchCond (opc_t OPC);
277 /* Get the condition for the conditional branch in OPC */
279 bc_t GetInverseCond (bc_t BC);
280 /* Return the inverse condition of the given one */
284 /* End of opcodes.h */