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 */
148 /* Number of opcodes available */
151 /* Several other opcode information constants */
152 OP65_FIRST = OP65_ADC,
153 OP65_LAST = OP65_TYA,
154 OP65_COUNT = OP65_LAST - OP65_FIRST + 1
157 /* Addressing modes */
160 /* Addressing modes of the virtual stack machine */
166 /* 65XX addressing modes */
167 AM65_IMP, /* implicit */
168 AM65_ACC, /* accumulator */
169 AM65_IMM, /* immidiate */
170 AM65_ZP, /* zeropage */
171 AM65_ZPX, /* zeropage,X */
172 AM65_ZPY, /* zeropage,Y */
173 AM65_ABS, /* absolute */
174 AM65_ABSX, /* absolute,X */
175 AM65_ABSY, /* absolute,Y */
176 AM65_ZPX_IND, /* (zeropage,x) */
177 AM65_ZP_INDY, /* (zeropage),y */
178 AM65_ZP_IND, /* (zeropage) */
179 AM65_BRA /* branch */
182 /* Branch conditions */
195 #define OF_NONE 0x0000U /* No additional information */
196 #define OF_CPU_6502 0x0000U /* 6502 opcode */
197 #define OF_CPU_VM 0x0001U /* Virtual machine opcode */
198 #define OF_MASK_CPU 0x0001U /* Mask for the cpu field */
199 #define OF_UBRA 0x0010U /* Unconditional branch */
200 #define OF_CBRA 0x0020U /* Conditional branch */
201 #define OF_ZBRA 0x0040U /* Branch on zero flag condition */
202 #define OF_FBRA 0x0080U /* Branch on cond set by a load */
203 #define OF_LBRA 0x0100U /* Jump/branch is long */
204 #define OF_RET 0x0200U /* Return from function */
205 #define OF_LOAD 0x0400U /* Register load */
206 #define OF_XFR 0x0800U /* Transfer instruction */
207 #define OF_CALL 0x1000U /* A subroutine call */
210 #define OF_BRA (OF_UBRA | OF_CBRA) /* Operation is a jump/branch */
211 #define OF_DEAD (OF_UBRA | OF_RET) /* Dead end - no exec behind this point */
213 /* Opcode description */
215 opc_t OPC; /* Opcode */
216 char Mnemo[9]; /* Mnemonic */
217 unsigned char Size; /* Size, 0 = check addressing mode */
218 unsigned char Use; /* Registers used by this insn */
219 unsigned char Chg; /* Registers changed by this insn */
220 unsigned short Info; /* Additional information */
223 /* Opcode description table */
224 extern const OPCDesc OPCTable[OPCODE_COUNT];
228 /*****************************************************************************/
230 /*****************************************************************************/
234 const OPCDesc* FindOP65 (const char* OPC);
235 /* Find the given opcode and return the opcode description. If the opcode was
236 * not found, NULL is returned.
239 unsigned GetInsnSize (opc_t OPC, am_t AM);
240 /* Return the size of the given instruction */
242 #if defined(HAVE_INLINE)
243 INLINE const OPCDesc* GetOPCDesc (opc_t OPC)
244 /* Get an opcode description */
246 /* Return the description */
247 return &OPCTable [OPC];
250 # define GetOPCDesc(OPC) (&OPCTable [(OPC)])
253 #if defined(HAVE_INLINE)
254 INLINE unsigned GetOPCInfo (opc_t OPC)
255 /* Get opcode information */
257 /* Return the info */
258 return OPCTable[OPC].Info;
261 # define GetOPCInfo(OPC) (OPCTable[(OPC)].Info)
264 unsigned char GetAMUseInfo (am_t AM);
265 /* Get usage info for the given addressing mode (addressing modes that use
266 * index registers return REG_r info for these registers).
269 opc_t GetInverseBranch (opc_t OPC);
270 /* Return a branch that reverse the condition of the branch given in OPC */
272 opc_t MakeShortBranch (opc_t OPC);
273 /* Return the short version of the given branch. If the branch is already
274 * a short branch, return the opcode unchanged.
277 opc_t MakeLongBranch (opc_t OPC);
278 /* Return the long version of the given branch. If the branch is already
279 * a long branch, return the opcode unchanged.
282 bc_t GetBranchCond (opc_t OPC);
283 /* Get the condition for the conditional branch in OPC */
285 bc_t GetInverseCond (bc_t BC);
286 /* Return the inverse condition of the given one */
290 /* End of opcodes.h */