1 /*****************************************************************************/
5 /* SWEET16 effective address parsing for the ca65 macroassembler */
9 /* (C) 2004-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 /*****************************************************************************/
53 /* Try to read a register number specified not as a register (Rx) but as a
54 * numeric value between 0 and 15. Return the register number or -1 on
59 ExprNode* Expr = Expression ();
60 if (!IsConstExpr (Expr, &Val) || Val < 0 || Val > 15) {
61 /* Invalid register */
65 /* Free the expression and return the register number */
72 void GetSweet16EA (EffAddr* A)
73 /* Parse an effective address, return the result in A */
77 /* Clear the output struct */
82 /* Parse the effective address */
83 if (TokIsSep (CurTok.Tok)) {
85 A->AddrModeSet = AMSW16_IMP;
87 } else if (CurTok.Tok == TOK_AT) {
89 /* @reg or @regnumber */
90 A->AddrModeSet = AMSW16_IND;
92 if (CurTok.Tok == TOK_REG) {
93 A->Reg = (unsigned) CurTok.IVal;
95 } else if ((Reg = RegNum ()) >= 0) {
97 A->Reg = (unsigned) Reg;
99 ErrorSkip ("Register or register number expected");
103 } else if (CurTok.Tok == TOK_REG) {
105 A->Reg = (unsigned) CurTok.IVal;
108 if (CurTok.Tok == TOK_COMMA) {
112 A->Expr = Expression ();
114 A->AddrModeSet = AMSW16_IMM;
118 A->AddrModeSet = AMSW16_REG;
124 /* OPC ea or: OPC regnum, constant */
125 A->Expr = Expression ();
126 A->AddrModeSet = AMSW16_BRA;
128 /* If the value is a constant between 0 and 15, it may also be a
131 if (IsConstExpr (A->Expr, &Reg) && Reg >= 0 && Reg <= 15) {
133 A->Reg = (unsigned) Reg;
135 /* If a comma follows, it is: OPC Rx, constant */
136 if (CurTok.Tok == TOK_COMMA) {
138 A->Expr = Expression ();
139 A->AddrModeSet = AMSW16_IMM;
142 A->AddrModeSet |= AMSW16_REG;