]> Shamusworld >> Repos - rmac/blobdiff - parmode.h
In ([bd,An/PC],Xn,od) parsing check for forced .w first and fall back to .l otherwise...
[rmac] / parmode.h
index 13b83fcae05cd27827f94b998d95361ccd89f93a..549f131ea42630df7869042f42bcb3fbd72f8df8 100644 (file)
--- a/parmode.h
+++ b/parmode.h
@@ -1,7 +1,7 @@
 //
 // RMAC - Reboot's Macro Assembler for all Atari computers
 // PARMODE.C - Addressing Modes Parser Include
-// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2020 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
@@ -81,7 +81,7 @@
                }
                else if ((*tok >= KW_D0) && (*tok <= KW_D7))
                {
-                       //Since index register isn't used here, store register number in this field
+                       // Since index register isn't used here, store register number in this field
                        AnIXREG = *tok++ & 7;                                // (Dn)
 
                        if (*tok == ')')
@@ -322,10 +322,10 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                        {
                                expr(AnBEXPR, &AnBEXVAL, &AnBEXATTR, &AnESYM);
 
-                               if (CHECK_OPTS(OPT_BASE_DISP) && AnBEXVAL == 0 && AnEXATTR != 0)
+                               if (CHECK_OPTS(OPT_020_DISP) && (AnBEXVAL == 0) && (AnEXATTR != 0))
                                {
-                                       // bd=0 so let's optimise it out
-                                       AnEXTEN|=EXT_BDSIZE0;
+                                       // bd = 0 so let's optimise it out
+                                       AnEXTEN |= EXT_BDSIZE0;
                                }
                                else if (*tok == DOTL)
                                {
@@ -346,12 +346,14 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                        {
                                                // Defined, absolute values from $FFFF8000..$00007FFF
                                                // get optimized to absolute short
-                                               if (CHECK_OPTS(OPT_ABS_SHORT)
+                                               if (CHECK_OPTS(OPT_020_DISP)
                                                        && ((AnBEXATTR & (TDB | DEFINED)) == DEFINED)
                                                        && (((uint32_t)AnBEXVAL + 0x8000) < 0x10000))
                                                {
                                                        AnEXTEN |= EXT_BDSIZEW;
-                                                       warn("absolute value in base displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
+
+                                                       if (optim_warn_flag)
+                                                               warn("absolute value in base displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
                                                }
                                                else
                                                {
@@ -467,8 +469,7 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                        else if (*tok == ']')
                        {
                                // PC and Xn is suppressed
-                               AnREG = 6 << 3;         // stuff 110 to mode field
-                               //AnEXTEN|=EXT_BS|EXT_IS;
+                               AnREG = 6 << 3;         // stuff 110b to mode field
                                AnEXTEN |= EXT_BS;
                        }
                        else
@@ -479,16 +480,16 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                        // At a crossroads here. We can accept either ([bd,An/PC],... or ([bd,An/PC,Xn*scale],...
                        if (*tok == ']')
                        {
-                               //([bd,An/PC],Xn,od)
+                               // ([bd,An/PC],Xn,od)
                                // Check for Xn
                                tok++;
 
                                if (*tok == ')')
                                {
-                                       //Xn and od are non existent, get out of jail free card
+                                       // Xn and od are non existent, get out of jail free card
                                        tok++;
                                        AMn = MEMPRE;                   // ([bc,An,Xn],od) with no Xn and od
-                                       AnEXTEN |= EXT_IS | EXT_IISPREN;        //Suppress Xn and od
+                                       AnEXTEN |= EXT_IS | EXT_IISPREN;        // Suppress Xn and od
                                        goto AnOK;
                                }
                                else if (*tok != ',')
@@ -510,7 +511,7 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                }
                                else
                                {
-                                       //No index found, suppress it
+                                       // No index found, suppress it
                                        AnEXTEN |= EXT_IS;
                                        tok--;                                  // Rewind tok to point to the comma
                                        goto IS_SUPPRESSEDn;    // https://xkcd.com/292/ - what does he know anyway?
@@ -605,9 +606,9 @@ CHECKODn:
                                if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                        goto badmode;
 
-                               if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0))
+                               if (CHECK_OPTS(OPT_020_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0))
                                {
-                                       // od=0 so optimise it out
+                                       // od = 0 so optimise it out
                                        AMn = MEMPOST;           // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISPOSN; // No outer displacement
                                        tok++;
@@ -615,9 +616,21 @@ CHECKODn:
                                }
 
                                // ([bd,An/PC],Xn,od)
-                               if (*tok == DOTL)
+                                       // Is .W forced here?
+                               if (*tok == DOTW)
                                {
-                                       // expr.L
+                                       tok++;
+                                       // od[.W]
+                                       AnEXTEN |= EXT_IISPOSW; // Word outer displacement
+                                       AMn = MEMPOST;
+                               }
+                               else
+                               {
+                                       // Is .L forced here?
+                                       if (*tok == DOTL)
+                                               tok++;                          // Doesn't matter, we're going for .L anyway
+
+                                       // od.L
                                        if (!(AnEXTEN & EXT_BS))
                                                AnEXTEN |= EXT_IISPOSL; // Long outer displacement
                                        else
@@ -632,36 +645,24 @@ CHECKODn:
                                                {
                                                        AnBEXPR[i] = AnEXPR[i];
                                                        i++;
-                                               }
-                                               while (AnEXPR[i] != 'E');
+                                               } while (AnEXPR[i] != 'E');
 
                                                AnBEXPR[i] = 'E';
                                        }
 
                                        AMn = MEMPOST;
-                                       tok++;
 
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                        // optimized to absolute short
-                                       if (CHECK_OPTS(OPT_ABS_SHORT)
+                                       if (CHECK_OPTS(OPT_020_DISP)
                                                && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
                                                && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                        {
                                                AnEXTEN |= EXT_IISPOSW; // Word outer displacement
                                                AMn = MEMPOST;
-                                               warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
+                                               if (optim_warn_flag)
+                                                       warn("absolute value in outer displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
                                        }
-
-                               }
-                               else
-                               {
-                                       // expr[.W]
-                                       AnEXTEN |= EXT_IISPOSW; // Word outer displacement
-                                       AMn = MEMPOST;
-
-                                       // Is .W forced here?
-                                       if (*tok == DOTW)
-                                               tok++;
                                }
 
                                // Check for final closing parenthesis
@@ -694,7 +695,7 @@ IS_SUPPRESSEDn:
 
                                expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM);
 
-                               if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0))
+                               if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0))
                                {
                                        // od=0 so optimise it out
                                        AMn = MEMPOST;           // let's say it's ([bd,An],Xn,od) with od=0 then
@@ -725,12 +726,13 @@ IS_SUPPRESSEDn:
                                        }
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                        // optimized to absolute short
-                                       else if (CHECK_OPTS(OPT_BASE_DISP)
+                                       else if (CHECK_OPTS(OPT_020_DISP)
                                                && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
                                                && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement with IS suppressed
-                                               warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
+                                               if (optim_warn_flag)
+                                                       warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
                                        }
                                }
 
@@ -858,7 +860,7 @@ IS_SUPPRESSEDn:
                                        if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                                goto badmode;
 
-                                       if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0) && (AnEXATTR & DEFINED))
+                                       if (CHECK_OPTS(OPT_020_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
@@ -889,12 +891,14 @@ IS_SUPPRESSEDn:
 
                                                // Defined, absolute values from $FFFF8000..$00007FFF
                                                // get optimized to absolute short
-                                               if (CHECK_OPTS(OPT_BASE_DISP)
+                                               if (CHECK_OPTS(OPT_020_DISP)
                                                        && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
                                                        && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                                {
                                                        expr_size = EXT_IISPREW;
-                                                       warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
+
+                                                       if (optim_warn_flag)
+                                                               warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
                                                }
                                        }
 
@@ -1169,6 +1173,11 @@ CHK_FOR_DISPn:
                        // expr[.L]
                        AMn = ABSL;
 
+                       // When PC relative is enforced, check for any symbols that aren't
+                       // EQU'd, in this case it's an illegal mode
+                       if ((CHECK_OPTS(OPT_PC_RELATIVE)) && (AnEXATTR & REFERENCED) && (AnEXATTR & DEFINED) && (!(AnEXATTR & EQUATED)))
+                               return error("relocation not allowed");
+
                        // .L is forced here
                        if (*tok == DOTL)
                        {
@@ -1185,7 +1194,7 @@ CHK_FOR_DISPn:
                                {
                                        AMn = ABSW;
 
-                                       if (sbra_flag)
+                                       if (optim_warn_flag)
                                                warn("absolute value from $FFFF8000..$00007FFF optimised to absolute short");
                                }
                        }