]> Shamusworld >> Repos - rmac/blobdiff - parmode.h
Version bump for last commit. :-)
[rmac] / parmode.h
index b03787eab6170f3260e04c656abff077b27a545c..27863d08c69f65f0886ec64c2ad6cd736cf03ecc 100644 (file)
--- a/parmode.h
+++ b/parmode.h
@@ -1,7 +1,7 @@
 //
 //
-// RMAC - Reboot's Macro Assembler for all Atari computers
+// RMAC - Renamed Macro Assembler for all Atari computers
 // PARMODE.C - Addressing Modes Parser Include
 // PARMODE.C - Addressing Modes Parser Include
-// Copyright (C) 199x Landon Dyer, 2011-2020 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
        // Dn
        // An
        // # expression
        // Dn
        // An
        // # expression
-       if ((*tok >= KW_D0) && (*tok <= KW_D7))
+       if ((*tok >= REG68_D0) && (*tok <= REG68_D7))
        {
                AMn = DREG;
                AnREG = *tok++ & 7;
        }
        {
                AMn = DREG;
                AnREG = *tok++ & 7;
        }
-       else if ((*tok >= KW_A0) && (*tok <= KW_A7))
+       else if ((*tok >= REG68_A0) && (*tok <= REG68_A7))
        {
                AMn = AREG;
                AnREG = *tok++ & 7;
        {
                AMn = AREG;
                AnREG = *tok++ & 7;
                AMn = IMMED;
        }
 
                AMn = IMMED;
        }
 
-       // Small problem with this is that the opening parentheses might be an
-       // expression that's part of a displacement; this code will falsely flag
-       // that as an error.
-
        // (An)
        // (An)+
        // (An,Xn[.siz][*scale])
        // (An)
        // (An)+
        // (An,Xn[.siz][*scale])
        // ([bd,PC,Xn[.siz][*scale]],od)
        else if (*tok == '(')
        {
        // ([bd,PC,Xn[.siz][*scale]],od)
        else if (*tok == '(')
        {
+               int ea_PC = 0;                          // Flag that let us know if we have PC or An relative ea
                tok++;
 
                tok++;
 
-               if ((*tok >= KW_A0) && (*tok <= KW_A7))
+               if ((*tok >= REG68_A0) && (*tok <= REG68_A7))
                {
                        AnREG = *tok++ & 7;
 
                {
                        AnREG = *tok++ & 7;
 
@@ -79,7 +76,7 @@
                        AMn = AINDEXED;
                        goto AMn_IX0;            // Handle ",Xn[.siz][*scale])"
                }
                        AMn = AINDEXED;
                        goto AMn_IX0;            // Handle ",Xn[.siz][*scale])"
                }
-               else if ((*tok >= KW_D0) && (*tok <= KW_D7))
+               else if ((*tok >= REG68_D0) && (*tok <= REG68_D7))
                {
                        // Since index register isn't used here, store register number in this field
                        AnIXREG = *tok++ & 7;                                // (Dn)
                {
                        // Since index register isn't used here, store register number in this field
                        AnIXREG = *tok++ & 7;                                // (Dn)
                        else
                                return error("unhandled so far");
                }
                        else
                                return error("unhandled so far");
                }
-               else if (*tok == KW_PC)
+               else if (*tok == REG68_PC)
                {                            // (PC,Xn[.siz][*scale])
                        tok++;
                        AMn = PCINDEXED;
                {                            // (PC,Xn[.siz][*scale])
                        tok++;
                        AMn = PCINDEXED;
@@ -223,7 +220,7 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                        if (*tok++ != ',')
                                goto badmode;
 
                        if (*tok++ != ',')
                                goto badmode;
 
-                       if (*tok < KW_D0 || *tok > KW_A7)
+                       if (*tok < REG68_D0 || *tok > REG68_A7)
                                goto badmode;
 
                        AnIXREG = *tok++ & 15;
                                goto badmode;
 
                        AnIXREG = *tok++ & 15;
@@ -322,10 +319,10 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                        {
                                expr(AnBEXPR, &AnBEXVAL, &AnBEXATTR, &AnESYM);
 
                        {
                                expr(AnBEXPR, &AnBEXVAL, &AnBEXATTR, &AnESYM);
 
-                               if (CHECK_OPTS(OPT_020_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)
                                {
                                }
                                else if (*tok == DOTL)
                                {
@@ -351,8 +348,9 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                                        && (((uint32_t)AnBEXVAL + 0x8000) < 0x10000))
                                                {
                                                        AnEXTEN |= EXT_BDSIZEW;
                                                        && (((uint32_t)AnBEXVAL + 0x8000) < 0x10000))
                                                {
                                                        AnEXTEN |= EXT_BDSIZEW;
+
                                                        if (optim_warn_flag)
                                                        if (optim_warn_flag)
-                                                               warn("absolute value in base displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
+                                                               warn("o5: absolute value in base displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
                                                }
                                                else
                                                {
                                                }
                                                else
                                                {
@@ -363,24 +361,24 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
 
                                if (*tok == ',')
                                        tok++;
 
                                if (*tok == ',')
                                        tok++;
-                               //else
-                               //      return error("Comma expected after base displacement");
                        }
 
                        // Check for address register or PC, suppress base register
                        // otherwise
 
                        }
 
                        // Check for address register or PC, suppress base register
                        // otherwise
 
-                       if (*tok == KW_PC)
+                       if (*tok == REG68_PC)
                        {                                       // ([bd,PC,...
                        {                                       // ([bd,PC,...
+                               ea_PC = 3;                              // Set flag in order to set proper value to AMn below when we can make a decision on ea
+                                                                               // (why "3"? Well, MEMPOST is 3 away from PCMPOST, etc. Have a look at amode.h)
                                AnREG = (7 << 3) | 3;   // PC is special case - stuff 011 to register field and 111 to the mode field
                                tok++;
                        }
                                AnREG = (7 << 3) | 3;   // PC is special case - stuff 011 to register field and 111 to the mode field
                                tok++;
                        }
-                       else if ((*tok >= KW_A0) && (*tok <= KW_A7))
+                       else if ((*tok >= REG68_A0) && (*tok <= REG68_A7))
                        {                                       // ([bd,An,...
                                AnREG = (6 << 3) | (*tok & 7);
                                tok++;
                        }
                        {                                       // ([bd,An,...
                                AnREG = (6 << 3) | (*tok & 7);
                                tok++;
                        }
-                       else if ((*tok >= KW_D0) && (*tok <= KW_D7))
+                       else if ((*tok >= REG68_D0) && (*tok <= REG68_D7))
                        {
                                // ([bd,Dn,...
                                AnREG = (6 << 3);
                        {
                                // ([bd,Dn,...
                                AnREG = (6 << 3);
@@ -487,7 +485,7 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                {
                                        // Xn and od are non existent, get out of jail free card
                                        tok++;
                                {
                                        // Xn and od are non existent, get out of jail free card
                                        tok++;
-                                       AMn = MEMPRE;                   // ([bc,An,Xn],od) with no Xn and od
+                                       AMn = MEMPRE + ea_PC;                           // ([bc,An,Xn],od) with no Xn and od
                                        AnEXTEN |= EXT_IS | EXT_IISPREN;        // Suppress Xn and od
                                        goto AnOK;
                                }
                                        AnEXTEN |= EXT_IS | EXT_IISPREN;        // Suppress Xn and od
                                        goto AnOK;
                                }
@@ -496,13 +494,13 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                else
                                        tok++;                          // eat the comma
 
                                else
                                        tok++;                          // eat the comma
 
-                               if ((*tok >= KW_A0) && (*tok <= KW_A7))
+                               if ((*tok >= REG68_A0) && (*tok <= REG68_A7))
                                {
                                        AnIXREG = ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_A;
                                        tok++;
                                }
                                {
                                        AnIXREG = ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_A;
                                        tok++;
                                }
-                               else if ((*tok >= KW_D0) && (*tok <= KW_D7))
+                               else if ((*tok >= REG68_D0) && (*tok <= REG68_D7))
                                {
                                        AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_D;
                                {
                                        AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_D;
@@ -516,7 +514,7 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                        goto IS_SUPPRESSEDn;    // https://xkcd.com/292/ - what does he know anyway?
                                }
 
                                        goto IS_SUPPRESSEDn;    // https://xkcd.com/292/ - what does he know anyway?
                                }
 
-                               // Check for size
+                               // Check for Xn size
                                // ([bd,An/PC],Xn.W/L...)
                                switch ((int)*tok)
                                {
                                // ([bd,An/PC],Xn.W/L...)
                                switch ((int)*tok)
                                {
@@ -524,8 +522,6 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                case DOTW:
                                        tok++;
                                        break;
                                case DOTW:
                                        tok++;
                                        break;
-                               default:
-                                       break;
                                case DOTL:
                                        AnEXTEN |= EXT_L;
                                        tok++;
                                case DOTL:
                                        AnEXTEN |= EXT_L;
                                        tok++;
@@ -533,9 +529,11 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                case DOTB:
                                        // .B not allowed here...
                                        goto badmode;
                                case DOTB:
                                        // .B not allowed here...
                                        goto badmode;
+                               default:
+                                       break;
                                }
 
                                }
 
-                               // Check for scale
+                               // Check for Xn scale
                                if (*tok == '*')                   // ([bd,An/PC],Xn*...)
                                {                                  // scale: *1, *2, *4, *8
                                        tok++;
                                if (*tok == '*')                   // ([bd,An/PC],Xn*...)
                                {                                  // scale: *1, *2, *4, *8
                                        tok++;
@@ -544,54 +542,39 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                        {
                                                if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                        return error("scale factor expression must evaluate");
                                        {
                                                if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                        return error("scale factor expression must evaluate");
-
-                                               switch (scaleval)
-                                               {
-                                               case 1:
-                                                       break;
-                                               case 2:
-                                                       AnIXSIZ |= TIMES2;
-                                                       break;
-                                               case 4:
-                                                       AnIXSIZ |= TIMES4;
-                                                       break;
-                                               case 8:
-                                                       AnIXSIZ |= TIMES8;
-                                                       break;
-                                               default:
-                                                       goto badmode;
-                                               }
                                        }
                                        }
-                                       else if (*tok++ != CONST)
-                                               goto badmode;
-                                       else
+                                       else if (*tok == CONST)
                                        {
                                        {
-                                               switch ((int)*tok++)
-                                               {
-                                               case 1:
-                                                       break;
-                                               case 2:
-                                                       AnIXSIZ |= TIMES2;
-                                                       break;
-                                               case 4:
-                                                       AnIXSIZ |= TIMES4;
-                                                       break;
-                                               case 8:
-                                                       AnIXSIZ |= TIMES8;
-                                                       break;
-                                               default:
-                                                       goto badmode;
-                                               }
-
+                                               scaleval = (int)*tok++;
                                                tok++;  // Take into account that constants are 64-bit
                                        }
                                                tok++;  // Take into account that constants are 64-bit
                                        }
+                                       else
+                                               goto badmode;
+
+                                       switch (scaleval)
+                                       {
+                                       case 1:
+                                               break;
+                                       case 2:
+                                               AnIXSIZ |= TIMES2;
+                                               break;
+                                       case 4:
+                                               AnIXSIZ |= TIMES4;
+                                               break;
+                                       case 8:
+                                               AnIXSIZ |= TIMES8;
+                                               break;
+                                       default:
+                                               goto badmode;
+                                       }
+
                                }
 
                                // Check for od
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
                                }
 
                                // Check for od
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
-                                       AMn = MEMPOST;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       AMn = MEMPOST + ea_PC;  // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISPOSN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISPOSN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -607,23 +590,37 @@ CHECKODn:
 
                                if (CHECK_OPTS(OPT_020_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0))
                                {
 
                                if (CHECK_OPTS(OPT_020_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0))
                                {
-                                       // 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
+                                       // od = 0 so optimise it out
+                                       AMn = MEMPOST + ea_PC;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       AnEXTEN |= EXT_IISPOSN;         // No outer displacement
                                        tok++;
                                        goto AnOK;
                                }
 
                                // ([bd,An/PC],Xn,od)
                                        tok++;
                                        goto AnOK;
                                }
 
                                // ([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 + ea_PC;
+                               }
+                               else
+                               {
+                                       // Is .L forced here?
+                                       if (*tok == DOTL)
+                                               tok++;                          // Doesn't matter, we're going for .L anyway
+
+                                       WORD od_ea = 0;
+
+                                       // od.L
                                        if (!(AnEXTEN & EXT_BS))
                                        if (!(AnEXTEN & EXT_BS))
-                                               AnEXTEN |= EXT_IISPOSL; // Long outer displacement
+                                               od_ea = EXT_IISPOSL; // Long outer displacement
                                        else
                                        {
                                                // bd is suppressed, so sticking the od size in bd
                                        else
                                        {
                                                // bd is suppressed, so sticking the od size in bd
-                                               AnEXTEN |= EXT_BDSIZEL;
+                                               od_ea = EXT_BDSIZEL;
                                                // And of course the expression has to be copied to
                                                // AnBEXPR instead of AnEXPR. Yay. :-/
                                                int i = 0;
                                                // And of course the expression has to be copied to
                                                // AnBEXPR instead of AnEXPR. Yay. :-/
                                                int i = 0;
@@ -638,8 +635,7 @@ CHECKODn:
                                                AnBEXPR[i] = 'E';
                                        }
 
                                                AnBEXPR[i] = 'E';
                                        }
 
-                                       AMn = MEMPOST;
-                                       tok++;
+                                       AMn = MEMPOST + ea_PC;
 
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                        // optimized to absolute short
 
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                        // optimized to absolute short
@@ -647,22 +643,13 @@ CHECKODn:
                                                && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
                                                && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                        {
                                                && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
                                                && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                        {
-                                               AnEXTEN |= EXT_IISPOSW; // Word outer displacement
-                                               AMn = MEMPOST;
+                                               od_ea = EXT_IISPOSW; // Word outer displacement
+                                               AMn = MEMPOST + ea_PC;
+
                                                if (optim_warn_flag)
                                                if (optim_warn_flag)
-                                                       warn("absolute value in outer displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
+                                                       warn("o5: 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++;
+                                       AnEXTEN |= od_ea;
                                }
 
                                // Check for final closing parenthesis
                                }
 
                                // Check for final closing parenthesis
@@ -680,7 +667,7 @@ IS_SUPPRESSEDn:
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
-                                       AMn = MEMPOST;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       AMn = MEMPOST + ea_PC;          // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -698,7 +685,7 @@ IS_SUPPRESSEDn:
                                if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0))
                                {
                                        // od=0 so optimise it out
                                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
+                                       AMn = MEMPOST + ea_PC;           // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -709,19 +696,19 @@ IS_SUPPRESSEDn:
                                {
                                        // expr.L
                                        tok++;
                                {
                                        // expr.L
                                        tok++;
-                                       AMn = MEMPOST;
+                                       AMn = MEMPOST + ea_PC;
                                        AnEXTEN |= EXT_IISNOIL; // Long outer displacement with IS suppressed
                                }
                                else
                                {
                                        // expr[.W][]
                                        AnEXTEN |= EXT_IISNOIW; // Word outer displacement with IS suppressed
                                        AnEXTEN |= EXT_IISNOIL; // Long outer displacement with IS suppressed
                                }
                                else
                                {
                                        // expr[.W][]
                                        AnEXTEN |= EXT_IISNOIW; // Word outer displacement with IS suppressed
-                                       AMn = MEMPRE;
+                                       AMn = MEMPRE + ea_PC;;
 
                                        if (*tok == DOTW)
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement
 
                                        if (*tok == DOTW)
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement
-                                               AMn = MEMPOST;
+                                               AMn = MEMPOST + ea_PC;
                                                tok++;
                                        }
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                                tok++;
                                        }
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
@@ -732,7 +719,7 @@ IS_SUPPRESSEDn:
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement with IS suppressed
                                                if (optim_warn_flag)
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement with IS suppressed
                                                if (optim_warn_flag)
-                                                       warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
+                                                       warn("o5: outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
                                        }
                                }
 
                                        }
                                }
 
@@ -750,13 +737,13 @@ IS_SUPPRESSEDn:
                                tok++;                  // ([bd,An,Xn.size*scale],od)
 
                                // Check for Xn
                                tok++;                  // ([bd,An,Xn.size*scale],od)
 
                                // Check for Xn
-                               if ((*tok >= KW_A0) && (*tok <= KW_A7))
+                               if ((*tok >= REG68_A0) && (*tok <= REG68_A7))
                                {
                                        AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_A;
                                        tok++;
                                }
                                {
                                        AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_A;
                                        tok++;
                                }
-                               else if ((*tok >= KW_D0) && (*tok <= KW_D7))
+                               else if ((*tok >= REG68_D0) && (*tok <= REG68_D7))
                                {
                                        AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_D;
                                {
                                        AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_D;
@@ -846,8 +833,7 @@ IS_SUPPRESSEDn:
                                if (*tok == ')')        // ([bd,An/PC,Xn]...
                                {
                                        // od is non existent, get out of jail free card
                                if (*tok == ')')        // ([bd,An/PC,Xn]...
                                {
                                        // od is non existent, get out of jail free card
-                                       //AnEXVAL=0;            // zero outer displacement
-                                       AMn = MEMPRE;                   // let's say it's ([bd,An,Xn],od) with od suppressed then
+                                       AMn = MEMPRE + ea_PC;                   // let's say it's ([bd,An,Xn],od) with od suppressed then
                                        AnEXTEN |= EXT_IISPREN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISPREN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -863,7 +849,7 @@ IS_SUPPRESSEDn:
                                        if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0) && (AnEXATTR & DEFINED))
                                        {
                                                // od=0 so optimise it out
                                        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
+                                               AMn = MEMPRE + ea_PC;            // let's say it's ([bd,An],Xn,od) with od=0 then
                                                AnEXTEN |= EXT_IISPRE0; // No outer displacement
                                                tok++;
                                                goto AnOK;
                                                AnEXTEN |= EXT_IISPRE0; // No outer displacement
                                                tok++;
                                                goto AnOK;
@@ -874,14 +860,14 @@ IS_SUPPRESSEDn:
                                if (*tok == DOTL)
                                {
                                        // expr.L
                                if (*tok == DOTL)
                                {
                                        // expr.L
-                                       AMn = MEMPRE;
+                                       AMn = MEMPRE + ea_PC;
                                        tok++;
                                        AnEXTEN |= EXT_IISPREL;
                                }
                                else
                                {
                                        // expr.[W]
                                        tok++;
                                        AnEXTEN |= EXT_IISPREL;
                                }
                                else
                                {
                                        // expr.[W]
-                                       AMn = MEMPRE;
+                                       AMn = MEMPRE + ea_PC;
                                        int expr_size = EXT_IISPREW; // Assume we have a .w value
 
                                        if ((AnEXVAL + 0x8000) > 0x10000)
                                        int expr_size = EXT_IISPREW; // Assume we have a .w value
 
                                        if ((AnEXVAL + 0x8000) > 0x10000)
@@ -896,8 +882,9 @@ IS_SUPPRESSEDn:
                                                        && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                                {
                                                        expr_size = EXT_IISPREW;
                                                        && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                                {
                                                        expr_size = EXT_IISPREW;
+
                                                        if (optim_warn_flag)
                                                        if (optim_warn_flag)
-                                                               warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
+                                                               warn("o5: outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short");
                                                }
                                        }
 
                                                }
                                        }
 
@@ -928,14 +915,72 @@ IS_SUPPRESSEDn:
                else
                {
                        // (expr...
                else
                {
                        // (expr...
+                       // We have an aliasing problem here, because a couple of differenct cases end up here:
+                       // (a0), 0(a0,d0), (-288,a0,d0.l) can be easily detected and parsed.
+                       // But what about (160*150)+4(A1)? With the old scheme, i.e. skip past the left parenthesis and try to parse the inside
+                       // tokens will only parse (160*150) and everything else is assumed that it's part of the ea, i.e. +4(a1). This would produce
+                       // an error since the parser would expect (a1). The way to work around this used to be to wrap all the displacement in
+                       // parenthesis, ((160*150)+4)(a1). But that's something the user really doesn't want to think about.
+                       // What we can do is to peek ahead in the token stream and see if we have something that reminds of an expression
+                       // (i.e. no register tokens or commas) until we hit an open parenthesis plus a register (parenthesis balance during the scan
+                       // has to be maintained of course, otherwise we might be led into false conclusions).
+                       TOKEN *look_ahead = tok;
+                       int parenthesis_level = 1;      // We count the opening parenthesis so we're not at level 0
+                       int this_is_an_expression = 0;
+                       while (1)
+                       {
+                               if (*look_ahead == EOL)
+                               {
+                                       // Something really bad happened, abort
+                                       return error("reached end of line while parsing expression");
+                               }
+                               if (*look_ahead == '(')
+                               {
+                                       if (parenthesis_level == 0)
+                                       {
+                                               if (look_ahead[1] == EOL)
+                                               {
+                                                       return error("reached end of line while parsing expression");
+                                               }
+                                               if ((look_ahead[1] >= REG68_A0 && look_ahead[1] <= REG68_A7) || look_ahead[1] == REG68_PC)
+                                               {
+                                                       tok--;                                          // Rewind token pointer to start of parenthesis
+                                                       this_is_an_expression = 1;
+                                                       break;
+                                               }
+                                       }
+                                       parenthesis_level++;
+                                       look_ahead++;
+                                       continue;
+                               }
+                               if (*look_ahead == ',' || (*look_ahead >= REG68_A0 && *look_ahead <= REG68_A7))
+                               {
+                                       // Nope, this is a different case, abort
+                                       break;
+                               }
+                               if (*look_ahead == ')')
+                               {
+                                       parenthesis_level--;
+                                       if (parenthesis_level < 0) return error("unbalanced parenthesis in expression");
+                                       look_ahead++;
+                                       continue;
+                               }
+                               if (*look_ahead == ACONST||*look_ahead==FCONST)
+                               {
+                                       look_ahead += 3;        // Skip all the data associated with ACONST
+                                       continue;
+                               }
+
+                               look_ahead++;
+                       }
+
                        if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                return ERROR;
 
                        // It could be that this is really just an expression prefixing a
                        // register as a displacement...
                        if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                return ERROR;
 
                        // It could be that this is really just an expression prefixing a
                        // register as a displacement...
-                       if (*tok == ')')
+                       if (*tok == '(')
                        {
                        {
-                               tok++;
                                goto CHK_FOR_DISPn;
                        }
 
                                goto CHK_FOR_DISPn;
                        }
 
@@ -943,7 +988,7 @@ IS_SUPPRESSEDn:
                        if (*tok++ != ',')
                                goto badmode;
 
                        if (*tok++ != ',')
                                goto badmode;
 
-                       if ((*tok >= KW_A0) && (*tok <= KW_A7))
+                       if ((*tok >= REG68_A0) && (*tok <= REG68_A7))
                        {
                                AnREG = *tok & 7;
                                tok++;
                        {
                                AnREG = *tok & 7;
                                tok++;
@@ -971,11 +1016,10 @@ IS_SUPPRESSEDn:
                                                // Our expression is techically a base displacement,
                                                // so let's copy it to the relevant variables so
                                                // eagen0.c can pick it up properly
                                                // Our expression is techically a base displacement,
                                                // so let's copy it to the relevant variables so
                                                // eagen0.c can pick it up properly
-                                               //AnBEXPR = AnEXPR;
                                                AnBEXVAL = AnEXVAL;
                                                AnBEXATTR = AnEXATTR;
 
                                                AnBEXVAL = AnEXVAL;
                                                AnBEXATTR = AnEXATTR;
 
-                                               if ((*tok >= KW_D0) && (*tok <= KW_D7))
+                                               if ((*tok >= REG68_D0) && (*tok <= REG68_D7))
                                                {
                                                        AnEXTEN |= ((*tok++) & 7) << 12;
                                                        // Check for size
                                                {
                                                        AnEXTEN |= ((*tok++) & 7) << 12;
                                                        // Check for size
@@ -998,7 +1042,7 @@ IS_SUPPRESSEDn:
                                                                }
                                                        }
                                                        // Check for scale
                                                                }
                                                        }
                                                        // Check for scale
-                                                       if (*tok == '*')                // ([bd,An/PC],Xn*...)
+                                                       if (*tok == '*')                // (d16,An,Dn[.size][*scale])
                                                        {                                               // scale: *1, *2, *4, *8
                                                                tok++;
 
                                                        {                                               // scale: *1, *2, *4, *8
                                                                tok++;
 
@@ -1072,7 +1116,7 @@ IS_SUPPRESSEDn:
                                else
                                        goto badmode;
                        }
                                else
                                        goto badmode;
                        }
-                       else if (*tok == KW_PC)
+                       else if (*tok == REG68_PC)
                        {
                                if (*++tok == ',')
                                {                             // expr(PC,Xn...)
                        {
                                if (*++tok == ',')
                                {                             // expr(PC,Xn...)
@@ -1092,56 +1136,56 @@ IS_SUPPRESSEDn:
                                goto badmode;
                }
        }
                                goto badmode;
                }
        }
-       else if (*tok == '-' && tok[1] == '(' && ((tok[2] >= KW_A0) && (tok[2] <= KW_A7)) && tok[3] == ')')
+       else if (*tok == '-' && tok[1] == '(' && ((tok[2] >= REG68_A0) && (tok[2] <= REG68_A7)) && tok[3] == ')')
        {
                AMn = APREDEC;
                AnREG = tok[2] & 7;
                tok += 4;
        }
        {
                AMn = APREDEC;
                AnREG = tok[2] & 7;
                tok += 4;
        }
-       else if (*tok == KW_CCR)
+       else if (*tok == REG68_CCR)
        {
                AMn = AM_CCR;
                tok++;
                goto AnOK;
        }
        {
                AMn = AM_CCR;
                tok++;
                goto AnOK;
        }
-       else if (*tok == KW_SR)
+       else if (*tok == REG68_SR)
        {
                AMn = AM_SR;
                tok++;
                goto AnOK;
        }
        {
                AMn = AM_SR;
                tok++;
                goto AnOK;
        }
-       else if (*tok == KW_USP)
+       else if (*tok == REG68_USP)
        {
                AMn = AM_USP;
                tok++;
                AnREG = 2;      // Added this for the case of USP used in movec (see CREGlut in mach.c). Hopefully nothing gets broken!
                goto AnOK;
        }
        {
                AMn = AM_USP;
                tok++;
                AnREG = 2;      // Added this for the case of USP used in movec (see CREGlut in mach.c). Hopefully nothing gets broken!
                goto AnOK;
        }
-       else if ((*tok >= KW_IC40) && (*tok <= KW_BC40))
+       else if ((*tok >= REG68_IC40) && (*tok <= REG68_BC40))
        {
                AMn = CACHES;
        {
                AMn = CACHES;
-               AnREG = *tok++ - KW_IC40;
+               AnREG = *tok++ - REG68_IC40;
 
                // After a cache keyword only a comma or EOL is allowed
                if ((*tok != ',') && (*tok != EOL))
                        return ERROR;
                goto AnOK;
        }
 
                // After a cache keyword only a comma or EOL is allowed
                if ((*tok != ',') && (*tok != EOL))
                        return ERROR;
                goto AnOK;
        }
-       else if ((*tok >= KW_SFC) && (*tok <= KW_CRP))
+       else if ((*tok >= REG68_SFC) && (*tok <= REG68_CRP))
        {
                AMn = CREG;
        {
                AMn = CREG;
-               AnREG = (*tok++) - KW_SFC;
+               AnREG = (*tok++) - REG68_SFC;
                goto AnOK;
        }
                goto AnOK;
        }
-       else if ((*tok >= KW_FP0) && (*tok <= KW_FP7))
+       else if ((*tok >= REG68_FP0) && (*tok <= REG68_FP7))
        {
                AMn = FREG;
                AnREG = (*tok++ & 7);
        }
        {
                AMn = FREG;
                AnREG = (*tok++ & 7);
        }
-       else if ((*tok >= KW_FPIAR) && (*tok <= KW_FPCR))
+       else if ((*tok >= REG68_FPIAR) && (*tok <= REG68_FPCR))
        {
                AMn = FPSCR;
        {
                AMn = FPSCR;
-               AnREG = (1 << ((*tok++) - KW_FPIAR + 10));
+               AnREG = (1 << ((*tok++) - REG68_FPIAR + 10));
        }
        // expr
        // expr.w
        }
        // expr
        // expr.w
@@ -1172,19 +1216,15 @@ CHK_FOR_DISPn:
                        // expr[.L]
                        AMn = ABSL;
 
                        // 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))
-                               if (AnEXATTR & REFERENCED)
-                                       if (AnEXATTR & DEFINED)
-                                               if (!(AnEXATTR & EQUATED))
-                                                       return error("relocation not allowed");
-
                        // .L is forced here
                        if (*tok == DOTL)
                        {
                        // .L is forced here
                        if (*tok == DOTL)
                        {
+                               // 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 & (DEFINED | REFERENCED | EQUATED)) == (DEFINED | REFERENCED)))
+                                       return error("relocation not allowed when o30 is enabled");
+
                                tok++;
                                tok++;
-                               AMn = ABSL;
                        }
                        else
                        {
                        }
                        else
                        {
@@ -1197,7 +1237,7 @@ CHK_FOR_DISPn:
                                        AMn = ABSW;
 
                                        if (optim_warn_flag)
                                        AMn = ABSW;
 
                                        if (optim_warn_flag)
-                                               warn("absolute value from $FFFF8000..$00007FFF optimised to absolute short");
+                                               warn("o0: absolute value from $FFFF8000..$00007FFF optimised to absolute short");
                                }
                        }
 
                                }
                        }
 
@@ -1206,7 +1246,7 @@ CHK_FOR_DISPn:
 
                tok++;
 
 
                tok++;
 
-               if ((*tok >= KW_A0) && (*tok <= KW_A7))
+               if ((*tok >= REG68_A0) && (*tok <= REG68_A7))
                {
                        AnREG = *tok++ & 7;
 
                {
                        AnREG = *tok++ & 7;
 
@@ -1220,7 +1260,7 @@ CHK_FOR_DISPn:
                        AMn = AINDEXED;
                        goto AMn_IXN;
                }
                        AMn = AINDEXED;
                        goto AMn_IXN;
                }
-               else if (*tok == KW_PC)
+               else if (*tok == REG68_PC)
                {
                        if (*++tok == ')')
                        {
                {
                        if (*++tok == ')')
                        {