2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // PARMODE.C - Addressing Modes Parser Include
4 // Copyright (C) 199x Landon Dyer, 2017 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source utilised with the kind permission of Landon Dyer
9 // This file is included (twice) to parse two addressing modes, into slightly
10 // different var names
15 if ((*tok >= KW_D0) && (*tok <= KW_D7))
20 else if ((*tok >= KW_A0) && (*tok <= KW_A7))
29 if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
35 // Small problem with this is that the opening parentheses might be an
36 // expression that's part of a displacement; this code will falsely flag
41 // (An,Xn[.siz][*scale])
42 // (PC,Xn[.siz][*scale])
44 // (d8,An,Xn[.siz][*scale])
46 // (d8,PC,Xn[.siz][*scale])
55 if ((*tok >= KW_A0) && (*tok <= KW_A7))
75 goto AMn_IX0; // Handle ",Xn[.siz][*scale])"
77 else if (*tok == KW_PC)
78 { // (PC,Xn[.siz][*scale])
82 // Common index handler; enter here with 'tok' pointing at the
85 AMn_IX0: // Handle indexed with missing expr
88 AnEXATTR = ABS | DEFINED;
90 AMn_IXN: // Handle any indexed (tok -> a comma)
95 if (*tok < KW_D0 || *tok > KW_A7)
98 AnIXREG = *tok++ & 15;
101 { // Index reg size: <empty> | .W | .L
111 case DOTB: // .B not allowed here...
116 { // scale: *1, *2, *4, *8
119 if (*tok++ != CONST || *tok > 8)
140 if (*tok++ != ')') // final ")"
145 else if (*tok == '[')
151 if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
154 // It could be that this is really just an expression prefixing a
155 // register as a displacement...
162 // Otherwise, check for PC & etc displacements...
166 if ((*tok >= KW_A0) && (*tok <= KW_A7))
176 else if (*tok == ')')
185 else if (*tok == KW_PC)
192 else if (*tok == ')')
194 AMn = PCDISP; // expr(PC)
205 else if (*tok == '-' && tok[1] == '(' && ((tok[2] >= KW_A0) && (tok[2] <= KW_A7)) && tok[3] == ')')
211 else if (*tok == KW_CCR)
217 else if (*tok == KW_SR)
223 else if (*tok == KW_USP)
238 if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
248 if ((AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL < 0x10000))
249 AnEXVAL = (int32_t)(int16_t)AnEXVAL; // Sign extend value
253 else if (*tok != '(')
258 // Defined, absolute values from $FFFF8000..$00007FFF get optimized
260 if (optim_flags[OPT_ABS_SHORT] && (AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL + 0x8000) < 0x10000)
265 warn("absolute value from $FFFF8000..$00007FFF optimised to absolute short");
268 // Is .L forced here?
280 if ((*tok >= KW_A0) && (*tok <= KW_A7))
294 else if (*tok == KW_PC)
309 // Addressing mode OK
315 // Clean up dirty little macros