]> git.sur5r.net Git - cc65/blob - src/ca65/ea.c
Added condes tables to c64 config
[cc65] / src / ca65 / ea.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   ea.c                                    */
4 /*                                                                           */
5 /*           Effective address parsing for the ca65 macroassembler           */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2000 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
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 #include "error.h"
37 #include "expr.h"
38 #include "instr.h"
39 #include "nexttok.h"
40 #include "ea.h"
41
42
43
44 /*****************************************************************************/
45 /*                                   Code                                    */
46 /*****************************************************************************/
47
48
49
50 void GetEA (unsigned long* AddrMode, ExprNode** Expr, ExprNode** Bank)
51 /* Parse an effective address, return the possible modes in AddrMode, and the
52  * expression involved (if any) in Expr.
53  */
54 {
55     /* Clear the expressions */
56     *Bank = *Expr = 0;
57
58
59     if (Tok == TOK_SEP) {
60
61         *AddrMode = AM_IMPLICIT;
62
63     } else if (Tok == TOK_HASH) {
64
65         /* #val */
66         NextTok ();
67         *Expr = Expression ();
68         *AddrMode = AM_IMM;
69
70     } else if (Tok == TOK_A) {
71
72         NextTok ();
73         *AddrMode = AM_ACCU;
74
75     } else if (Tok == TOK_LBRACK) {
76
77         /* [dir] or [dir],y */
78         NextTok ();
79         *Expr = Expression ();
80         Consume (TOK_RBRACK, ERR_RBRACK_EXPECTED);
81         if (Tok == TOK_COMMA) {
82             /* [dir],y */
83             NextTok ();
84             Consume (TOK_Y, ERR_Y_EXPECTED);
85             *AddrMode = AM_DIR_IND_LONG_Y;
86         } else {
87             /* [dir] */
88             *AddrMode = AM_DIR_IND_LONG;
89         }
90
91     } else if (Tok == TOK_LPAREN) {
92
93         /* One of the indirect modes */
94         NextTok ();
95         *Expr = Expression ();
96
97         if (Tok == TOK_COMMA) {
98
99             /* (expr,X) or (rel,S),y */
100             NextTok ();
101             if (Tok == TOK_X) {
102                 /* (adr,x) */
103                 NextTok ();
104                 *AddrMode = AM_ABS_X_IND | AM_DIR_X_IND;
105                 ConsumeRParen ();
106             } else if (Tok == TOK_S) {
107                 /* (rel,s),y */
108                 NextTok ();
109                 *AddrMode = AM_STACK_REL_IND_Y;
110                 ConsumeRParen ();
111                 ConsumeComma ();
112                 Consume (TOK_Y, ERR_Y_EXPECTED);
113             } else {
114                 Error (ERR_SYNTAX);
115             }
116
117         } else {
118
119             /* (adr) or (adr),y */
120             ConsumeRParen ();
121             if (Tok == TOK_COMMA) {
122                 /* (adr),y */
123                 NextTok ();
124                 Consume (TOK_Y, ERR_Y_EXPECTED);
125                 *AddrMode = AM_DIR_IND_Y;
126             } else {
127                 /* (adr) */
128                 *AddrMode = AM_ABS_IND | AM_DIR_IND;
129             }
130         }
131
132     } else {
133
134         /* Remaining stuff:
135          *
136          * adr
137          * bank.adr
138          * adr,x
139          * bank.adr,x
140          * adr,y
141          * adr,s
142          */
143         *Expr = Expression ();
144
145         if (Tok == TOK_DOT) {
146
147             /* Expr was a bank specification: bank.adr or bank.adr,x */
148             *Bank = *Expr;
149             NextTok ();
150             *Expr = Expression ();
151             if (Tok == TOK_COMMA) {
152                 /* bank.adr,x */
153                 NextTok ();
154                 Consume (TOK_X, ERR_X_EXPECTED);
155                 *AddrMode = AM_ABS_LONG_X;
156             } else {
157                 /* bank.adr */
158                 *AddrMode = AM_ABS_LONG;
159             }
160
161         } else {
162
163             if (Tok == TOK_COMMA) {
164
165                 NextTok ();
166                 switch (Tok) {
167
168                     case TOK_X:
169                         *AddrMode = AM_ABS_X | AM_DIR_X;
170                         NextTok ();
171                         break;
172
173                     case TOK_Y:
174                         *AddrMode = AM_ABS_Y | AM_DIR_Y;
175                         NextTok ();
176                         break;
177
178                     case TOK_S:
179                         *AddrMode = AM_STACK_REL;
180                         NextTok ();
181                         break;
182
183                     default:
184                         Error (ERR_SYNTAX);
185
186                 }
187
188             } else {
189
190                 *AddrMode = AM_ABS | AM_DIR;
191
192             }
193         }
194     }
195 }
196
197
198