1 /*****************************************************************************/
5 /* 65XX effective address parsing for the ca65 macroassembler */
9 /* (C) 1998-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
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 void GetEA (EffAddr* A)
53 /* Parse an effective address, return the result in A */
55 unsigned long Restrictions;
57 /* Clear the output struct */
61 /* Handle an addressing size override */
64 Restrictions = AM65_DIR | AM65_DIR_X | AM65_DIR_Y;
68 case TOK_OVERRIDE_ABS:
69 Restrictions = AM65_ABS | AM65_ABS_X | AM65_ABS_Y;
73 case TOK_OVERRIDE_FAR:
74 Restrictions = AM65_ABS_LONG | AM65_ABS_LONG_X;
79 Restrictions = ~0UL; /* None */
83 /* Parse the effective address */
84 if (TokIsSep (CurTok.Tok)) {
86 A->AddrModeSet = AM65_IMPLICIT;
88 } else if (CurTok.Tok == TOK_HASH) {
92 A->Expr = Expression ();
93 A->AddrModeSet = AM65_IMM;
95 } else if (CurTok.Tok == TOK_A) {
98 A->AddrModeSet = AM65_ACCU;
100 } else if (CurTok.Tok == TOK_LBRACK) {
102 /* [dir] or [dir],y */
104 A->Expr = Expression ();
105 Consume (TOK_RBRACK, "']' expected");
106 if (CurTok.Tok == TOK_COMMA) {
109 Consume (TOK_Y, "`Y' expected");
110 A->AddrModeSet = AM65_DIR_IND_LONG_Y;
113 A->AddrModeSet = AM65_DIR_IND_LONG;
116 } else if (CurTok.Tok == TOK_LPAREN) {
118 /* One of the indirect modes */
120 A->Expr = Expression ();
122 if (CurTok.Tok == TOK_COMMA) {
124 /* (expr,X) or (rel,S),y */
126 if (CurTok.Tok == TOK_X) {
129 A->AddrModeSet = AM65_ABS_X_IND | AM65_DIR_X_IND;
131 } else if (CurTok.Tok == TOK_S) {
134 A->AddrModeSet = AM65_STACK_REL_IND_Y;
137 Consume (TOK_Y, "`Y' expected");
139 Error ("Syntax error");
144 /* (adr) or (adr),y */
146 if (CurTok.Tok == TOK_COMMA) {
149 Consume (TOK_Y, "`Y' expected");
150 A->AddrModeSet = AM65_DIR_IND_Y;
153 A->AddrModeSet = AM65_ABS_IND | AM65_DIR_IND;
166 A->Expr = Expression ();
168 if (CurTok.Tok == TOK_COMMA) {
171 switch (CurTok.Tok) {
174 A->AddrModeSet = AM65_ABS_LONG_X | AM65_ABS_X | AM65_DIR_X;
179 A->AddrModeSet = AM65_ABS_Y | AM65_DIR_Y;
184 A->AddrModeSet = AM65_STACK_REL;
189 Error ("Syntax error");
195 A->AddrModeSet = AM65_ABS_LONG | AM65_ABS | AM65_DIR;
200 /* Apply addressing mode overrides */
201 A->AddrModeSet &= Restrictions;