Multiple fixes for 020+ mode, including:
[rmac] / parmode.h
index 54b584e0fc4f4c58bbbb510f4f1000acef2833d1..89d53a7da60ad32e612259f185b66660171c30c3 100644 (file)
--- a/parmode.h
+++ b/parmode.h
                                {
                                        if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                                return error("scale factor expression must evaluate");
-
                                        switch (AnEXVAL)
                                        {
                                        case 1:
                        tok++;
                        AnEXTEN|=EXT_FULLWORD;     //Definitely using full extension format, so set bit 8
                        // Check to see if base displacement is present
-                       //WARNING("expr will return a bad expression error here but this is expected, it needs to be silenced!");
                        if (*tok!=CONST && *tok !=SYMBOL)
-                       //if (expr(AnBEXPR, &AnBEXVAL, &AnBEXATTR, &AnESYM) != OK)
                        {
                                AnEXTEN|=EXT_BDSIZE0;
-                               //tok++;
-                               //tok--;                 //Rewind tok since expr advances it forward
                        }
                        else
                        {
                                        tok++;
                                        goto AnOK;
                                }
-                               else if (*tok++!=',')
+                else if (*tok++ != ',')
                                        return error("comma expected after ]");
 
-                               WARNING(Put symbol and constant checks here!)
-
+                if (*tok == SYMBOL || *tok == CONST)
+                {
                                if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                        goto badmode;
 
-                               if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0))
+                    if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0) && (AnEXATTR & DEFINED))
                                {
                                        // od=0 so optimise it out
                                        AMn = MEMPRE;            // let's say it's ([bd,An],Xn,od) with od=0 then
                                        tok++;
                                        goto AnOK;
                                }
+                }
 
                                // ([bd,An/PC,Xn],od)
                                if (*tok == DOTL)
                                else
                                {
                                        // expr.[W]
-                                       //tok++;
+                    int expr_size;
 
-                                       AnEXTEN |= EXT_IISPREW;
                                        AMn = MEMPRE;
+                    expr_size = EXT_IISPREW; // Assume we have a .w value
 
-                    // Is .W forced here?
-                                       if (*tok == DOTW)
+                    if ((AnEXVAL + 0x8000) > 0x10000)
                                        {
-                                               tok++;
-                                       }
-
+                        // Long value, so mark it as such for now
+                        expr_size = EXT_IISPREL;
                                        // Defined, absolute values from $FFFF8000..$00007FFF get optimized
                                        // to absolute short
-                                       else if (CHECK_OPTS(OPT_BASE_DISP)
+                        if (CHECK_OPTS(OPT_BASE_DISP)
                                                && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
                                                && ((AnEXVAL + 0x8000) < 0x10000))
                                        {
-                                               AnEXTEN |= EXT_IISPREW;
+                            expr_size = EXT_IISPREW;
                                                warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
                                        }
                                }
 
+                    AnEXTEN |= expr_size; // Assume we have a .w value
+
+                    // Is .W forced here?
+                                       if (*tok == DOTW)
+                                       {
+                                               tok++;
+                        if (expr_size == EXT_IISPREL)
+                            return error("outer displacement value does not fit in .w size");
+                                       }
+
+                               }
+
                                // Check for final closing parenthesis
                                if (*tok == ')')
                                {