1 /*****************************************************************************/
5 /* Effective address parsing for the ca65 macroassembler */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 /*****************************************************************************/
44 /*****************************************************************************/
46 /*****************************************************************************/
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.
55 /* Clear the expressions */
61 *AddrMode = AM_IMPLICIT;
63 } else if (Tok == TOK_HASH) {
67 *Expr = Expression ();
70 } else if (Tok == TOK_A) {
75 } else if (Tok == TOK_LBRACK) {
77 /* [dir] or [dir],y */
79 *Expr = Expression ();
80 Consume (TOK_RBRACK, ERR_RBRACK_EXPECTED);
81 if (Tok == TOK_COMMA) {
84 Consume (TOK_Y, ERR_Y_EXPECTED);
85 *AddrMode = AM_DIR_IND_LONG_Y;
88 *AddrMode = AM_DIR_IND_LONG;
91 } else if (Tok == TOK_LPAREN) {
93 /* One of the indirect modes */
95 *Expr = Expression ();
97 if (Tok == TOK_COMMA) {
99 /* (expr,X) or (rel,S),y */
104 *AddrMode = AM_ABS_X_IND | AM_DIR_X_IND;
106 } else if (Tok == TOK_S) {
109 *AddrMode = AM_STACK_REL_IND_Y;
112 Consume (TOK_Y, ERR_Y_EXPECTED);
119 /* (adr) or (adr),y */
121 if (Tok == TOK_COMMA) {
124 Consume (TOK_Y, ERR_Y_EXPECTED);
125 *AddrMode = AM_DIR_IND_Y;
128 *AddrMode = AM_ABS_IND | AM_DIR_IND;
143 *Expr = Expression ();
145 if (Tok == TOK_DOT) {
147 /* Expr was a bank specification: bank.adr or bank.adr,x */
150 *Expr = Expression ();
151 if (Tok == TOK_COMMA) {
154 Consume (TOK_X, ERR_X_EXPECTED);
155 *AddrMode = AM_ABS_LONG_X;
158 *AddrMode = AM_ABS_LONG;
163 if (Tok == TOK_COMMA) {
169 *AddrMode = AM_ABS_X | AM_DIR_X;
174 *AddrMode = AM_ABS_Y | AM_DIR_Y;
179 *AddrMode = AM_STACK_REL;
190 *AddrMode = AM_ABS | AM_DIR;