]> git.sur5r.net Git - cc65/blob - src/cc65/opcodes.h
Working on the backend
[cc65] / src / cc65 / opcodes.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 opcodes.h                                 */
4 /*                                                                           */
5 /*                  Opcode and addressing mode definitions                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef OPCODES_H
37 #define OPCODES_H
38
39
40
41 /*****************************************************************************/
42 /*                                   Data                                    */
43 /*****************************************************************************/
44
45
46
47 /* Definitions for the possible opcodes */
48 typedef enum {
49     OPC_ADC,
50     OPC_AND,
51     OPC_ASL,
52     OPC_BCC,
53     OPC_BCS,
54     OPC_BEQ,
55     OPC_BIT,
56     OPC_BMI,
57     OPC_BNE,
58     OPC_BPL,
59     OPC_BRA,
60     OPC_BRK,
61     OPC_BVC,
62     OPC_BVS,
63     OPC_CLC,
64     OPC_CLD,
65     OPC_CLI,
66     OPC_CLV,
67     OPC_CMP,
68     OPC_CPX,
69     OPC_CPY,
70     OPC_DEA,
71     OPC_DEC,
72     OPC_DEX,
73     OPC_DEY,
74     OPC_EOR,
75     OPC_INA,
76     OPC_INC,
77     OPC_INX,
78     OPC_INY,
79     OPC_JCC,
80     OPC_JCS,
81     OPC_JEQ,
82     OPC_JMI,
83     OPC_JMP,
84     OPC_JNE,
85     OPC_JPL,
86     OPC_JSR,
87     OPC_JVC,
88     OPC_JVS,
89     OPC_LDA,
90     OPC_LDX,
91     OPC_LDY,
92     OPC_LSR,
93     OPC_NOP,
94     OPC_ORA,
95     OPC_PHA,
96     OPC_PHP,
97     OPC_PHX,
98     OPC_PHY,
99     OPC_PLA,
100     OPC_PLP,
101     OPC_PLX,
102     OPC_PLY,
103     OPC_ROL,
104     OPC_ROR,
105     OPC_RTI,
106     OPC_RTS,
107     OPC_SBC,
108     OPC_SEC,
109     OPC_SED,
110     OPC_SEI,
111     OPC_STA,
112     OPC_STX,
113     OPC_STY,
114     OPC_TAX,
115     OPC_TAY,
116     OPC_TRB,
117     OPC_TSB,
118     OPC_TSX,
119     OPC_TXA,
120     OPC_TXS,
121     OPC_TYA,
122     OPC_COUNT                           /* Number of opcodes available */
123 } opc_t;
124
125 /* Addressing modes (bitmapped). */
126 typedef enum {
127     AM_IMP      = 0x0001,               /* implicit */
128     AM_ACC      = 0x0002,               /* accumulator */
129     AM_IMM      = 0x0004,               /* immidiate */
130     AM_ZP       = 0x0008,               /* zeropage */
131     AM_ZPX      = 0x0010,               /* zeropage,X */
132     AM_ABS      = 0x0020,               /* absolute */
133     AM_ABSX     = 0x0040,               /* absolute,X */
134     AM_ABSY     = 0x0080,               /* absolute,Y */
135     AM_ZPX_IND  = 0x0100,               /* (zeropage,x) */
136     AM_ZP_INDY  = 0x0200,               /* (zeropage),y */
137     AM_ZP_IND   = 0x0400,               /* (zeropage) */
138     AM_BRA      = 0x0800                /* branch */
139 } am_t;
140
141 /* Branch conditions */
142 typedef enum {
143     BC_CC,
144     BC_CS,
145     BC_EQ,
146     BC_MI,
147     BC_NE,
148     BC_PL,
149     BC_SR,
150     BC_VC,
151     BC_VS
152 } bc_t;
153
154 /* Opcode info */
155 #define OF_NONE 0x0000U                 /* No additional information */
156 #define OF_UBRA 0x0001U                 /* Unconditional branch */
157 #define OF_CBRA 0x0002U                 /* Conditional branch */
158 #define OF_LBRA 0x0004U                 /* Jump/branch is long */
159 #define OF_RET  0x0010U                 /* Return from function */
160 #define OF_LOAD 0x0020U                 /* Register load */
161 #define OF_BRA  (OF_UBRA|OF_CBRA)       /* Operation is a jump/branch */
162 #define OF_DEAD (OF_UBRA|OF_RET)        /* Dead end - no exec behind this point */
163
164 /* Opcode description */
165 typedef struct {
166     opc_t           OPC;                /* Opcode */
167     char            Mnemo[4];           /* Mnemonic */
168     unsigned char   Size;               /* Size, 0 = check addressing mode */
169     unsigned char   Use;                /* Registers used by this insn */
170     unsigned char   Chg;                /* Registers changed by this insn */
171     unsigned char   Info;               /* Additional information */
172 } OPCDesc;
173
174
175
176 /*****************************************************************************/
177 /*                                   Code                                    */
178 /*****************************************************************************/
179
180
181
182 const OPCDesc* FindOpcode (const char* OPC);
183 /* Find the given opcode and return the opcode description. If the opcode was
184  * not found, NULL is returned.
185  */
186
187 unsigned GetInsnSize (opc_t OPC, am_t AM);
188 /* Return the size of the given instruction */
189
190 const OPCDesc* GetOPCDesc (opc_t OPC);
191 /* Get an opcode description */
192
193 unsigned char GetOPCInfo (opc_t OPC);
194 /* Get opcode information */
195
196 unsigned char GetAMUseInfo (am_t AM);
197 /* Get usage info for the given addressing mode (addressing modes that use
198  * index registers return REG_r info for these registers).
199  */
200
201 opc_t GetInverseBranch (opc_t OPC);
202 /* Return a branch that reverse the condition of the branch given in OPC */
203
204 opc_t MakeShortBranch (opc_t OPC);
205 /* Return the short version of the given branch. If the branch is already
206  * a short branch, return the opcode unchanged.
207  */
208
209 opc_t MakeLongBranch (opc_t OPC);
210 /* Return the long version of the given branch. If the branch is already
211  * a long branch, return the opcode unchanged.
212  */
213
214 bc_t GetBranchCond (opc_t OPC);
215 /* Get the condition for the conditional branch in OPC */
216
217 bc_t GetInverseCond (bc_t BC);
218 /* Return the inverse condition of the given one */
219
220 opc_t GetLongBranch (bc_t BC);
221 /* Return a long branch for the given branch condition */
222
223 opc_t GetShortBranch (bc_t BC);
224 /* Return a short branch for the given branch condition */
225
226
227
228 /* End of opcodes.h */
229 #endif
230
231
232