Version bump for last commit; now at v2.0.23.
[rmac] / parmode.h
index 0c5ca2c0818e01b9ab248016127482dc41c456ce..dd3e1a2b03ee87b6bd58b0a6df3da462ab7bfe2f 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-2017 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
 //
@@ -9,22 +9,27 @@
 // This file is included (twice) to parse two addressing modes, into slightly
 // different var names
 {
+       uint64_t scaleval;                      // Expression's value
+       TOKEN scaleexpr[EXPRSIZE];      // Expression
+       WORD scaleattr;                         // Expression's attribute
+       SYM * scaleesym;                        // External symbol involved in expr
+
        // Dn
        // An
        // # expression
-       if ((*tok.u32 >= KW_D0) && (*tok.u32 <= KW_D7))
+       if ((*tok >= KW_D0) && (*tok <= KW_D7))
        {
                AMn = DREG;
-               AnREG = *tok.u32++ & 7;
+               AnREG = *tok++ & 7;
        }
-       else if ((*tok.u32 >= KW_A0) && (*tok.u32 <= KW_A7))
+       else if ((*tok >= KW_A0) && (*tok <= KW_A7))
        {
                AMn = AREG;
-               AnREG = *tok.u32++ & 7;
+               AnREG = *tok++ & 7;
        }
-       else if (*tok.u32 == '#')
+       else if (*tok == '#')
        {
-               tok.u32++;
+               tok++;
 
                if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                        return ERROR;
        // (d8,An,Xn[.siz][*scale])
        // (d16,PC)
        // (d8,PC,Xn[.siz][*scale])
-       // ([bd,An],Xn,od)
-       // ([bd,An,Xn],od)
-       // ([bd,PC],Xn,od)
-       // ([bd,PC,Xn],od)
-       else if (*tok.u32 == '(')
+       // ([bd,An],Xn[.siz][*scale],od)
+       // ([bd,An,Xn[.siz][*scale]],od)
+       // ([bd,PC],Xn[.siz][*scale],od)
+       // ([bd,PC,Xn[.siz][*scale]],od)
+       else if (*tok == '(')
        {
-               tok.u32++;
+               int ea_PC = 0;                          // Flag that let us know if we have PC or An relative ea
+               tok++;
 
-               if ((*tok.u32 >= KW_A0) && (*tok.u32 <= KW_A7))
+               if ((*tok >= KW_A0) && (*tok <= KW_A7))
                {
-                       AnREG = *tok.u32++ & 7;
+                       AnREG = *tok++ & 7;
 
-                       if (*tok.u32 == ')')
+                       if (*tok == ')')
                        {
-                               tok.u32++;
+                               tok++;
 
-                               if (*tok.u32 == '+')
+                               if (*tok == '+')
                                {
-                                       tok.u32++;
+                                       tok++;
                                        AMn = APOSTINC;
                                }
                                else
                        AMn = AINDEXED;
                        goto AMn_IX0;            // Handle ",Xn[.siz][*scale])"
                }
-               else if ((*tok.u32 >= KW_D0) && (*tok.u32 <= KW_D7))
+               else if ((*tok >= KW_D0) && (*tok <= KW_D7))
                {
-                       //Since index register isn't used here, store register number in this field
-                       AnIXREG = *tok.u32++ & 7;                                // (Dn)
+                       // Since index register isn't used here, store register number in this field
+                       AnIXREG = *tok++ & 7;                                // (Dn)
 
-                       if (*tok.u32 == ')')
+                       if (*tok == ')')
                        {
-                               tok.u32++;
+                               tok++;
                                AnEXTEN |= EXT_FULLWORD;    // Definitely using full extension format, so set bit 8
                                AnEXTEN |= EXT_BS;          // Base register suppressed
                                AnEXTEN |= EXT_BDSIZE0;     // Base displacement null
                                AnREG = 6 << 3;         // stuff 110 to mode field
                                goto AnOK;
                        }
-                       else if (*tok.u32 == 'L')
+                       else if (*tok == 'L')
                        {
-                               // TODO: does DINDL gets used at all?
-                               AMn = DINDL;                                     // (Dn.l)
-                               AnEXTEN = 1 << 1;   // Long index size
-                               tok.u32++;
+                               AMn = DINDL;                                                                     // (Dn.l)
+                               AnEXTEN = 1 << 11;   // Long index size
+                               tok++;
                        }
-                       else if (*tok.u32 == 'W')                                // (Dn.w)
+                       else if (*tok == 'W')                                // (Dn.w)
                        {
-                               // TODO: does DINDW gets used at all?
                                AMn = DINDW;
-                               AnEXTEN = 1 << 1;   // Word index size
-                               tok.u32++;
+                               AnEXTEN = 0 << 11;   // Word index size
+                               tok++;
                        }
-                       else if (*tok.u32 == ',')
+                       else if (*tok == ',')
                        {
                                // ([bd,An],Xn..) without bd, An
                                // Base displacement is suppressed
                                AnEXTEN |= EXT_BS;          // Base register suppressed
                                AnEXTEN |= EXT_BDSIZE0;
                                AnREG = 6 << 3;         // stuff 110 to mode field
-                               tok.u32++;
+                               tok++;
                                goto CHECKODn;
                        }
                        else
                                return error("(Dn) error");
                        }
 
-                       if (*tok.u32 == '*')
+                       if (*tok == '*')
                        {                        // scale: *1, *2, *4, *8
-                               tok.u32++;
+                               tok++;
 
-                               if (*tok.u32 == SYMBOL)
+                               if (*tok == SYMBOL)
                                {
-                                       if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
+                                       if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                return error("scale factor expression must evaluate");
 
-                                       switch (AnEXVAL)
+                                       switch (scaleval)
                                        {
                                        case 1:
                                                break;
                                        case 2:
                                                AnIXSIZ |= TIMES2;
+                                               AnEXTEN |= 1 << 9;
                                                break;
                                        case 4:
                                                AnIXSIZ |= TIMES4;
+                                               AnEXTEN |= 2 << 9;
                                                break;
                                        case 8:
                                                AnIXSIZ |= TIMES8;
+                                               AnEXTEN |= 3 << 9;
                                                break;
                                        default:
                                                goto badmode;
                                        }
                                }
-                               else if (*tok.u32++ != CONST || *tok.u32 > 8)
+                               else if (*tok++ != CONST)
                                        goto badmode;
                                else
                                {
-                                       switch ((int)*tok.u32++)
+                                       switch ((int)*tok++)
                                        {
                                        case 1:
                                                break;
                                        case 2:
                                                AnIXSIZ |= TIMES2;
+                                               AnEXTEN |= 1 << 9;
                                                break;
                                        case 4:
                                                AnIXSIZ |= TIMES4;
+                                               AnEXTEN |= 2 << 9;
                                                break;
                                        case 8:
                                                AnIXSIZ |= TIMES8;
+                                               AnEXTEN |= 3 << 9;
                                                break;
                                        default:
                                                goto badmode;
                                        }
+
+                                       tok++;  // Take into account that constants are 64-bit
                                }
                        }
 
-                       if (*tok.u32 == ')')
+                       if (*tok == ')')
                        {
-                               tok.u32++;
+                               tok++;
                                AnEXTEN |= EXT_FULLWORD;    // Definitely using full extension format, so set bit 8
                                AnEXTEN |= EXT_BS;          // Base register suppressed
                                AnEXTEN |= EXT_BDSIZE0;     // Base displacement null
                                AMn = MEMPOST;
                                goto AnOK;
                        }
-                       else if (*tok.u32 == ',')
+                       else if (*tok == ',')
                        {
-                               tok.u32++;  // eat the comma
+                               tok++;  // eat the comma
                                // It might be (Dn[.wl][*scale],od)
                                // Maybe this is wrong and we have to write some code here
                                // instead of reusing that path...
-                               AnEXTEN |= EXT_BDSIZE0;     // Base displacement null - suppressed
+                               AnEXTEN |= EXT_FULLWORD;        // Definitely using full extension format, so set bit 8
+                               AnEXTEN |= EXT_BS;       // Base displacement null - suppressed
+                               AnEXTEN |= AnIXREG << 12;
                                goto CHECKODn;
                        }
                        else
                                return error("unhandled so far");
                }
-               else if (*tok.u32 == KW_PC)
+               else if (*tok == KW_PC)
                {                            // (PC,Xn[.siz][*scale])
-                       tok.u32++;
+                       tok++;
                        AMn = PCINDEXED;
 
                        // Common index handler; enter here with 'tok' pointing at the
                        // comma.
 
-                       AMn_IX0:                 // Handle indexed with missing expr
+AMn_IX0:                 // Handle indexed with missing expr
 
                        AnEXVAL = 0;
                        AnEXATTR = ABS | DEFINED;
 
-                       AMn_IXN:                 // Handle any indexed (tok -> a comma)
+AMn_IXN:                 // Handle any indexed (tok -> a comma)
 
-                       if (*tok.u32++ != ',')
+                       if (*tok++ != ',')
                                goto badmode;
 
-                       if (*tok.u32 < KW_D0 || *tok.u32 > KW_A7)
+                       if (*tok < KW_D0 || *tok > KW_A7)
                                goto badmode;
 
-                       AnIXREG = *tok.u32++ & 15;
+                       AnIXREG = *tok++ & 15;
 
-                       switch ((int)*tok.u32)
+                       switch ((int)*tok)
                        {                        // Index reg size: <empty> | .W | .L
                        case DOTW:
-                               tok.u32++;
+                               tok++;
                        default:
                                AnIXSIZ = 0;
                                break;
                        case DOTL:
                                AnIXSIZ = 0x0800;
-                               tok.u32++;
+                               tok++;
                                break;
                        case DOTB:               // .B not allowed here...
                                goto badmode;
                        }
 
-                       if (*tok.u32 == '*')
+                       if (*tok == '*')
                        {                        // scale: *1, *2, *4, *8
-                               tok.u32++;
+                               tok++;
 
-                               if (*tok.u32 == SYMBOL)
+                               if (*tok == SYMBOL)
                                {
-                                       if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
+                                       if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                return error("scale factor expression must evaluate");
-                                       switch (AnEXVAL)
+
+                                       switch (scaleval)
                                        {
                                        case 1:
                                                break;
                                                goto badmode;
                                        }
                                }
-                               else if (*tok.u32++ != CONST || *tok.u32 > 8)
+                               else if (*tok++ != CONST)
                                        goto badmode;
                                else
                                {
-                                       switch ((int)*tok.u32++)
+                                       switch ((int)*tok++)
                                        {
                                        case 1:
                                                break;
                                        default:
                                                goto badmode;
                                        }
+
+                                       tok++;  // Take into account that constants are 64-bit
                                }
                        }
 
-                       if (*tok.u32 == ',')
+                       if (*tok == ',')
                        {
                                // If we got here we didn't get any [] stuff
                                // so let's suppress base displacement before
                                // branching off
-                               tok.u32++;
+                               tok++;
                                AnEXTEN |= EXT_BDSIZE0;     // Base displacement null - suppressed
                                goto CHECKODn;
                        }
-                       if (*tok.u32++ != ')')         // final ")"
+                       if (*tok++ != ')')         // final ")"
                                goto badmode;
 
                        goto AnOK;
                }
-               else if (*tok.u32 == '[')
+               else if (*tok == '[')
                {                              // ([...
-                       tok.u32++;
+                       tok++;
                        AnEXTEN |= EXT_FULLWORD;     // Definitely using full extension format, so set bit 8
 
                        // Check to see if base displacement is present
-                       if (*tok.u32 != CONST && *tok.u32 != SYMBOL)
+                       if (*tok != CONST && *tok != SYMBOL)
                        {
                                AnEXTEN |= EXT_BDSIZE0;
                        }
                        else
                        {
                                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.u32 == DOTL)
-                               {                                               // ([bd.l,...
-                                               AnEXTEN |= EXT_BDSIZEL;
-                                               tok.u32++;
+                               else if (*tok == DOTL)
+                               {
+                                       // ([bd.l,...
+                                       AnEXTEN |= EXT_BDSIZEL;
+                                       tok++;
                                }
                                else
-                               {                                               // ([bd[.w],... or ([bd,...
+                               {
+                                       // ([bd[.w],... or ([bd,...
                                        // Is .W forced here?
-                                       if (*tok.u32 == DOTW)
+                                       if (*tok == DOTW)
                                        {
                                                AnEXTEN |= EXT_BDSIZEW;
-                                               tok.u32++;
+                                               tok++;
                                        }
                                        else
                                        {
-                                               // Defined, absolute values from $FFFF8000..$00007FFF get optimized
-                                               // to absolute short
-                                               if (CHECK_OPTS(OPT_ABS_SHORT)
+                                               // Defined, absolute values from $FFFF8000..$00007FFF
+                                               // get optimized to absolute 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
                                                {
                                        }
                                }
 
-                               if (*tok.u32 == ',')
-                                       tok.u32++;
-                               //else
-                               //      return error("Comma expected after base displacement");
+                               if (*tok == ',')
+                                       tok++;
                        }
 
                        // Check for address register or PC, suppress base register
                        // otherwise
 
-                       if (*tok.u32 == KW_PC)
+                       if (*tok == KW_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.u32++;
+                               tok++;
                        }
-                       else if ((*tok.u32 >= KW_A0) && (*tok.u32 <= KW_A7))
+                       else if ((*tok >= KW_A0) && (*tok <= KW_A7))
                        {                                       // ([bd,An,...
-                               AnREG = (6 << 3) | *tok.u32 & 7;
-                               tok.u32++;
+                               AnREG = (6 << 3) | (*tok & 7);
+                               tok++;
                        }
-                       else if ((*tok.u32 >= KW_D0) && (*tok.u32 <= KW_D7))
+                       else if ((*tok >= KW_D0) && (*tok <= KW_D7))
                        {
                                // ([bd,Dn,...
                                AnREG = (6 << 3);
-                               AnEXTEN |= ((*tok.u32 & 7) << 12);
+                               AnEXTEN |= ((*tok & 7) << 12);
                                AnEXTEN |= EXT_D;
                                AnEXTEN |= EXT_BS; // Oh look, a data register! Which means that base register is suppressed
-                               tok.u32++;
+                               tok++;
 
                                // Check for size
-                               {
                                // ([bd,An/PC],Xn.W/L...)
-                               switch ((int)*tok.u32)
+                               switch ((int)*tok)
                                {
                                // Index reg size: <empty> | .W | .L
                                case DOTW:
-                                       tok.u32++;
+                                       tok++;
                                        break;
                                default:
                                        break;
                                case DOTL:
                                        AnEXTEN |= EXT_L;
-                                       tok.u32++;
+                                       tok++;
                                        break;
                                case DOTB:
                                        // .B not allowed here...
                                        goto badmode;
                                }
-                               }
 
                                // Check for scale
-                               if (*tok.u32 == '*')                    // ([bd,An/PC],Xn*...)
+                               if (*tok == '*')                        // ([bd,An/PC],Xn*...)
                                {                           // scale: *1, *2, *4, *8
-                                       tok.u32++;
+                                       tok++;
 
-                                       if (*tok.u32 == SYMBOL)
+                                       if (*tok == SYMBOL)
                                        {
-                                               if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
+                                               if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                        return error("scale factor expression must evaluate");
 
-                                               switch (AnEXVAL)
+                                               switch (scaleval)
                                                {
                                                case 1:
                                                        break;
                                                        goto badmode;
                                }
                                        }
-                                       else if (*tok.u32++ != CONST || *tok.u32 > 8)
+                                       else if (*tok++ != CONST)
                                                goto badmode;
                                        else
                                        {
-                                               switch ((int)*tok.u32++)
+                                               switch ((int)*tok++)
                                                {
                                                case 1:
                                                        break;
                                                default:
                                                        goto badmode;
                                                }
+
+                                               tok++;  // Take into account that constants are 64-bit
                                        }
                                }
-                               if (*tok.u32 == ']')  // ([bd,Dn]...
+                               if (*tok == ']')  // ([bd,Dn]...
                                {
-                                       tok.u32++;
+                                       tok++;
                                        goto IS_SUPPRESSEDn;
                                }
                        }
-                       else if (*tok.u32 == ']')
+                       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
                        }
 
                        // At a crossroads here. We can accept either ([bd,An/PC],... or ([bd,An/PC,Xn*scale],...
-                       if (*tok.u32 == ']')
+                       if (*tok == ']')
                        {
-                               //([bd,An/PC],Xn,od)
+                               // ([bd,An/PC],Xn,od)
                                // Check for Xn
-                               tok.u32++;
+                               tok++;
 
-                               if (*tok.u32 == ')')
+                               if (*tok == ')')
                                {
-                                       //Xn and od are non existent, get out of jail free card
-                                       tok.u32++;
-                                       AMn = MEMPRE;                   // ([bc,An,Xn],od) with no Xn and od
-                                       AnEXTEN |= EXT_IS | EXT_IISPREN;        //Suppress Xn and od
+                                       // Xn and od are non existent, get out of jail free card
+                                       tok++;
+                                       AMn = MEMPRE + ea_PC;                           // ([bc,An,Xn],od) with no Xn and od
+                                       AnEXTEN |= EXT_IS | EXT_IISPREN;        // Suppress Xn and od
                                        goto AnOK;
                                }
-                               else if (*tok.u32 != ',')
+                               else if (*tok != ',')
                                        return error("comma expected after ]");
                                else
-                                       tok.u32++;                              // eat the comma
+                                       tok++;                          // eat the comma
 
-                               if ((*tok.u32 >= KW_A0) && (*tok.u32 <= KW_A7))
+                               if ((*tok >= KW_A0) && (*tok <= KW_A7))
                                {
-                                       AnIXREG = ((*tok.u32 & 7) << 12);
+                                       AnIXREG = ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_A;
-                                       tok.u32++;
+                                       tok++;
                                }
-                               else if ((*tok.u32 >= KW_D0) && (*tok.u32 <= KW_D7))
+                               else if ((*tok >= KW_D0) && (*tok <= KW_D7))
                                {
-                                       AnEXTEN |= ((*tok.u32 & 7) << 12);
+                                       AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_D;
-                                       tok.u32++;
+                                       tok++;
                                }
                                else
                                {
-                                       //No index found, suppress it
+                                       // No index found, suppress it
                                        AnEXTEN |= EXT_IS;
-                                       tok.u32--;                                      // Rewind tok to point to the comma
+                                       tok--;                                  // Rewind tok to point to the comma
                                        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.u32)
-                                       {
-                                       // Index reg size: <empty> | .W | .L
-                                       case DOTW:
-                                               tok.u32++;
-                                               break;
-                                       default:
-                                               break;
-                                       case DOTL:
-                                               AnEXTEN |= EXT_L;
-                                               tok.u32++;
-                                               break;
-                                       case DOTB:
-                                               // .B not allowed here...
-                                               goto badmode;
-                                       }
+                               // Index reg size: <empty> | .W | .L
+                               case DOTW:
+                                       tok++;
+                                       break;
+                               case DOTL:
+                                       AnEXTEN |= EXT_L;
+                                       tok++;
+                                       break;
+                               case DOTB:
+                                       // .B not allowed here...
+                                       goto badmode;
+                               default:
+                                       break;
                                }
 
-                               // Check for scale
-                               if (*tok.u32 == '*')                   // ([bd,An/PC],Xn*...)
+                               // Check for Xn scale
+                               if (*tok == '*')                   // ([bd,An/PC],Xn*...)
                                {                                  // scale: *1, *2, *4, *8
-                                       tok.u32++;
+                                       tok++;
 
-                                       if (*tok.u32 == SYMBOL)
+                                       if (*tok == SYMBOL)
                                        {
-                                               if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
+                                               if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                        return error("scale factor expression must evaluate");
-
-                                               switch (AnEXVAL)
-                                               {
-                                               case 1:
-                                                       break;
-                                               case 2:
-                                                       AnIXSIZ |= TIMES2;
-                                                       break;
-                                               case 4:
-                                                       AnIXSIZ |= TIMES4;
-                                                       break;
-                                               case 8:
-                                                       AnIXSIZ |= TIMES8;
-                                                       break;
-                                               default:
-                                                       goto badmode;
-                                               }
                                        }
-                                       else if (*tok.u32++ != CONST || *tok.u32 > 8)
-                                               goto badmode;
+                                       else if (*tok == CONST)
+                                       {
+                                               scaleval = (int)*tok++;
+                                               tok++;  // Take into account that constants are 64-bit
+                                       }
                                        else
+                                               goto badmode;
+
+                                       switch (scaleval)
                                        {
-                                               switch ((int)*tok.u32++)
-                                               {
-                                               case 1:
-                                                       break;
-                                               case 2:
-                                                       AnIXSIZ |= TIMES2;
-                                                       break;
-                                               case 4:
-                                                       AnIXSIZ |= TIMES4;
-                                                       break;
-                                               case 8:
-                                                       AnIXSIZ |= TIMES8;
-                                                       break;
-                                               default:
-                                                       goto badmode;
-                                               }
+                                       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.u32 == ')')    // ([bd,An/PC],Xn)
+                               if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
-                                       //od is non existant, get out of jail free card
-                                       AMn = MEMPOST;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       // od is non existent, get out of jail free card
+                                       AMn = MEMPOST + ea_PC;  // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISPOSN; // No outer displacement
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
-                               else if (*tok.u32 != ',')
+                               else if (*tok != ',')
                                        return error("comma expected");
                                else
-                                       tok.u32++;      // eat the comma
+                                       tok++;  // eat the comma
 
-                               CHECKODn:
+CHECKODn:
                                if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                        goto badmode;
 
-                               if (CHECK_OPTS(OPT_BASE_DISP) && (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
-                                       tok.u32++;
+                                       // 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)
-                               if (*tok.u32 == DOTL)
+                               // Is .W forced here?
+                               if (*tok == DOTW)
                                {
-                                       // expr.L
-                                       AnEXTEN |= EXT_IISPOSL; // Long outer displacement
-                                       AMn = MEMPOST;
-                                       tok.u32++;
+                                       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))
+                                               od_ea = EXT_IISPOSL; // Long outer displacement
+                                       else
+                                       {
+                                               // bd is suppressed, so sticking the od size in bd
+                                               od_ea = EXT_BDSIZEL;
+                                               // And of course the expression has to be copied to
+                                               // AnBEXPR instead of AnEXPR. Yay. :-/
+                                               int i = 0;
+
+                                               do
+                                               {
+                                                       AnBEXPR[i] = AnEXPR[i];
+                                                       i++;
+                                               }
+                                               while (AnEXPR[i] != 'E');
+
+                                               AnBEXPR[i] = 'E';
+                                       }
+
+                                       AMn = MEMPOST + ea_PC;
 
                                        // 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");
-                                       }
+                                               od_ea = EXT_IISPOSW; // Word outer displacement
+                                               AMn = MEMPOST + ea_PC;
 
-                               }
-                               else
-                               {
-                                       // expr[.W]
-                                       AnEXTEN |= EXT_IISPOSW; // Word outer displacement
-                                       AMn = MEMPOST;
-
-                                       // Is .W forced here?
-                                       if (*tok.u32 == DOTW)
-                                       {
-                                               tok.u32++;
+                                               if (optim_warn_flag)
+                                                       warn("absolute value in outer displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
                                        }
+                                       AnEXTEN |= od_ea;
                                }
 
                                // Check for final closing parenthesis
-                               if (*tok.u32 == ')')
+                               if (*tok == ')')
                                {
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
                                else
 IS_SUPPRESSEDn:
 
                                // Check for od
-                               if (*tok.u32 == ')')    // ([bd,An/PC],Xn)
+                               if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
-                                       //od is non existant, get out of jail free card
-                                       AMn = MEMPOST;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       // od is non existent, get out of jail free card
+                                       AMn = MEMPOST + ea_PC;          // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
-                               else if (*tok.u32!=',')
+                               else if (*tok!=',')
                                        return error("comma expected");
                                else
-                                       tok.u32++;      // eat the comma
+                                       tok++;  // eat the comma
 
-                if ((*tok.u32 != CONST) && (*tok.u32 != SYMBOL))
+                               if ((*tok != CONST) && (*tok != SYMBOL))
                                        goto badmode;
 
                                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
+                                       AMn = MEMPOST + ea_PC;           // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
 
                                // ([bd,An/PC],Xn,od)
-                               if (*tok.u32 == DOTL)
+                               if (*tok == DOTL)
                                {
                                        // expr.L
-                                       tok.u32++;
-                                       AMn = MEMPOST;
+                                       tok++;
+                                       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
-                                       AMn = MEMPRE;
+                                       AMn = MEMPRE + ea_PC;;
 
-                                       if (*tok.u32 == DOTW)
+                                       if (*tok == DOTW)
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement
-                                               AMn = MEMPOST;
-                                               tok.u32++;
+                                               AMn = MEMPOST + ea_PC;
+                                               tok++;
                                        }
                                        // 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");
                                        }
                                }
 
                                // Check for final closing parenthesis
-                               if (*tok.u32 == ')')
+                               if (*tok == ')')
                                {
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
                                else
                                        return error("Closing parenthesis missing on addressing mode");
                        }
-                       else if (*tok.u32 == ',')
+                       else if (*tok == ',')
                        {
-                               *tok.u32++;                     // ([bd,An,Xn.size*scale],od)
+                               tok++;                  // ([bd,An,Xn.size*scale],od)
 
-                               //Check for Xn
-                               if ((*tok.u32 >= KW_A0) && (*tok.u32 <= KW_A7))
+                               // Check for Xn
+                               if ((*tok >= KW_A0) && (*tok <= KW_A7))
                                {
-                                       AnEXTEN |= ((*tok.u32 & 7) << 12);
+                                       AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_A;
-                                       tok.u32++;
+                                       tok++;
                                }
-                               else if ((*tok.u32 >= KW_D0) && (*tok.u32 <= KW_D7))
+                               else if ((*tok >= KW_D0) && (*tok <= KW_D7))
                                {
-                                       AnEXTEN |= ((*tok.u32 & 7) << 12);
+                                       AnEXTEN |= ((*tok & 7) << 12);
                                        AnEXTEN |= EXT_D;
-                                       tok.u32++;
+                                       tok++;
                                }
 
                                // Check for size
-                               {
                                // ([bd,An/PC],Xn.W/L...)
-                               switch ((int)*tok.u32)
+                               switch ((int)*tok)
                                {
                                // Index reg size: <empty> | .W | .L
                                case DOTW:
-                                       tok.u32++;
+                                       tok++;
                                        break;
                                default:
                                        break;
                                case DOTL:
-                                       tok.u32++;
+                                       tok++;
                                        AnEXTEN |= EXT_L;
                                        break;
                                case DOTB:
-                                       // .B not allowed here...
-                                       goto badmode;
-                               }
+                               // .B not allowed here...
+                               goto badmode;
                                }
 
                                // Check for scale
-                               if (*tok.u32 == '*')                    // ([bd,An/PC],Xn*...)
-                               {                           // scale: *1, *2, *4, *8
-                                       tok.u32++;
+                               if (*tok == '*')                                // ([bd,An/PC],Xn*...)
+                               {                                                               // scale: *1, *2, *4, *8
+                                       tok++;
 
-                                       if (*tok.u32 == SYMBOL)
+                                       if (*tok == SYMBOL)
                                        {
-                                               if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
+                                               if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                        return error("scale factor expression must evaluate");
-                                               switch (AnEXVAL)
+
+                                               switch (scaleval)
                                                {
                                                case 1:
                                                        break;
@@ -772,74 +800,78 @@ IS_SUPPRESSEDn:
                                                        goto badmode;
                                                }
                                        }
-                                       else if (*tok.u32++ != CONST || *tok.u32 > 8)
+                                       else if (*tok++ != CONST)
                                                goto badmode;
                                        else
                                        {
-                                               switch ((int)*tok.u32++)
+                                               switch ((int)*tok++)
                                                {
                                                case 1:
                                                        break;
                                                case 2:
                                                        AnIXSIZ |= TIMES2;
+                                                       AnEXTEN |= 1 << 9;
                                                        break;
                                                case 4:
                                                        AnIXSIZ |= TIMES4;
+                                                       AnEXTEN |= 2 << 9;
                                                        break;
                                                case 8:
                                                        AnIXSIZ |= TIMES8;
+                                                       AnEXTEN |= 3 << 9;
                                                        break;
                                                default:
                                                        goto badmode;
                                                }
+
+                                               tok++;  // Take into account that constants are 64-bit
                                        }
                                }
 
-                               //Check for ]
-                               if (*tok.u32 != ']')
+                               // Check for ]
+                               if (*tok != ']')
                                        return error("Expected closing bracket ]");
-                               tok.u32++;                      // Eat the bracket
+                               tok++;                  // Eat the bracket
 
-                               //Check for od
-                               if (*tok.u32 == ')')    // ([bd,An/PC,Xn]...
+                               // Check for od
+                               if (*tok == ')')        // ([bd,An/PC,Xn]...
                                {
-                                       //od is non existant, 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
+                                       // od is non existent, get out of jail free card
+                                       AMn = MEMPRE + ea_PC;                   // let's say it's ([bd,An,Xn],od) with od suppressed then
                                        AnEXTEN |= EXT_IISPREN; // No outer displacement
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
-                else if (*tok.u32++ != ',')
+                               else if (*tok++ != ',')
                                        return error("comma expected after ]");
 
-                               if (*tok.u32 == SYMBOL || *tok.u32 == CONST)
+                               if (*tok == SYMBOL || *tok == CONST)
                                {
                                        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
+                                               AMn = MEMPRE + ea_PC;            // let's say it's ([bd,An],Xn,od) with od=0 then
                                                AnEXTEN |= EXT_IISPRE0; // No outer displacement
-                                               tok.u32++;
+                                               tok++;
                                                goto AnOK;
                                        }
                                }
 
                                // ([bd,An/PC,Xn],od)
-                               if (*tok.u32 == DOTL)
+                               if (*tok == DOTL)
                                {
                                        // expr.L
-                                       AMn = MEMPRE;
-                                       tok.u32++;
+                                       AMn = MEMPRE + ea_PC;
+                                       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)
@@ -849,21 +881,23 @@ 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");
                                                }
                                        }
 
                                        AnEXTEN |= expr_size; // Assume we have a .w value
 
                                        // Is .W forced here?
-                                       if (*tok.u32 == DOTW)
+                                       if (*tok == DOTW)
                                        {
-                                               tok.u32++;
+                                               tok++;
 
                                                if (expr_size == EXT_IISPREL)
                                                        return error("outer displacement value does not fit in .w size");
@@ -871,9 +905,9 @@ IS_SUPPRESSEDn:
                                }
 
                                // Check for final closing parenthesis
-                               if (*tok.u32 == ')')
+                               if (*tok == ')')
                                {
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
                                else
@@ -890,46 +924,155 @@ IS_SUPPRESSEDn:
 
                        // It could be that this is really just an expression prefixing a
                        // register as a displacement...
-                       if (*tok.u32 == ')')
+                       if (*tok == ')')
                        {
-                               tok.u32++;
+                               tok++;
                                goto CHK_FOR_DISPn;
                        }
 
                        // Otherwise, check for PC & etc displacements...
-                       if (*tok.u32++ != ',')
+                       if (*tok++ != ',')
                                goto badmode;
 
-                       if ((*tok.u32 >= KW_A0) && (*tok.u32 <= KW_A7))
+                       if ((*tok >= KW_A0) && (*tok <= KW_A7))
                        {
-                               AnREG = *tok.u32 & 7;
-                               tok.u32++;
+                               AnREG = *tok & 7;
+                               tok++;
 
-                               if (*tok.u32 == ',')
+                               if (*tok == ',')
                                {
+                                       // Check if we're actually doing d8(An,Dn) or
+                                       // (d16,An,Dn[.size][*scale])
+                                       // TODO: not a very clear cut case from what I can think.
+                                       // The only way to distinguish between the two is to check
+                                       // AnEXVAL and see if it's >127 or <-128. But this doesn't
+                                       // work if AnEXVAL isn't defined yet. For now we fall
+                                       // through to d8(An,Dn) but this might bite us in the arse
+                                       // during fixups...
+                                       if ((AnEXATTR & DEFINED) && (AnEXVAL + 0x80 > 0x100))
+                                       {
+                                               // We're going to treat it as a full extension format
+                                               // with no indirect access and no base displacement/
+                                               // index register suppression
+                                               AnEXTEN |= EXT_FULLWORD;        // Definitely using full extension format, so set bit 8
+                                               AnEXTEN |= EXT_IISPRE0;         // No Memory Indirect Action
+                                               AnEXTEN |= EXT_BDSIZEL;         // Base Displacement Size Long
+                                               tok++;                                          // Get past the comma
+
+                                               // Our expression is techically a base displacement,
+                                               // so let's copy it to the relevant variables so
+                                               // eagen0.c can pick it up properly
+                                               AnBEXVAL = AnEXVAL;
+                                               AnBEXATTR = AnEXATTR;
+
+                                               if ((*tok >= KW_D0) && (*tok <= KW_D7))
+                                               {
+                                                       AnEXTEN |= ((*tok++) & 7) << 12;
+                                                       // Check for size
+                                                       {
+                                                               switch ((int)*tok)
+                                                               {
+                                                               // Index reg size: <empty> | .W | .L
+                                                               case DOTW:
+                                                                       tok++;
+                                                                       break;
+                                                               default:
+                                                                       break;
+                                                               case DOTL:
+                                                                       tok++;
+                                                                       AnEXTEN |= EXT_L;
+                                                                       break;
+                                                               case DOTB:
+                                                                       // .B not allowed here...
+                                                                       goto badmode;
+                                                               }
+                                                       }
+                                                       // Check for scale
+                                                       if (*tok == '*')                // (d16,An,Dn[.size][*scale])
+                                                       {                                               // scale: *1, *2, *4, *8
+                                                               tok++;
+
+                                                               if (*tok == SYMBOL)
+                                                               {
+                                                                       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
+                                                               {
+                                                                       switch ((int)*tok++)
+                                                                       {
+                                                                       case 1:
+                                                                               break;
+                                                                       case 2:
+                                                                               AnIXSIZ |= TIMES2;
+                                                                               break;
+                                                                       case 4:
+                                                                               AnIXSIZ |= TIMES4;
+                                                                               break;
+                                                                       case 8:
+                                                                               AnIXSIZ |= TIMES8;
+                                                                               break;
+                                                                       default:
+                                                                               goto badmode;
+                                                                       }
+
+                                                                       tok++;  // Take into account that constants are 64-bit
+                                                               }
+                                                       }
+
+                                                       if (*tok++ != ')')
+                                                               return error("Closing parenthesis missing on addressing mode");
+
+                                                       // Let's say that this is the closest to our case
+                                                       AMn = MEMPOST;
+                                                       goto AnOK;
+                                               }
+                                               else
+                                                       goto badmode;
+                                       }
+
                                        AMn = AINDEXED;
                                        goto AMn_IXN;
                                }
-                               else if (*tok.u32 == ')')
+                               else if (*tok == ')')
                                {
                                        AMn = ADISP;
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
                                else
                                        goto badmode;
                        }
-                       else if (*tok.u32 == KW_PC)
+                       else if (*tok == KW_PC)
                        {
-                               if (*++tok.u32 == ',')
+                               if (*++tok == ',')
                                {                             // expr(PC,Xn...)
                                        AMn = PCINDEXED;
                                        goto AMn_IXN;
                                }
-                               else if (*tok.u32 == ')')
+                               else if (*tok == ')')
                                {
                                        AMn = PCDISP;             // expr(PC)
-                                       tok.u32++;
+                                       tok++;
                                        goto AnOK;
                                }
                                else
@@ -939,56 +1082,56 @@ IS_SUPPRESSEDn:
                                goto badmode;
                }
        }
-       else if (*tok.u32 == '-' && tok.u32[1] == '(' && ((tok.u32[2] >= KW_A0) && (tok.u32[2] <= KW_A7)) && tok.u32[3] == ')')
+       else if (*tok == '-' && tok[1] == '(' && ((tok[2] >= KW_A0) && (tok[2] <= KW_A7)) && tok[3] == ')')
        {
                AMn = APREDEC;
-               AnREG = tok.u32[2] & 7;
-               tok.u32 += 4;
+               AnREG = tok[2] & 7;
+               tok += 4;
        }
-       else if (*tok.u32 == KW_CCR)
+       else if (*tok == KW_CCR)
        {
                AMn = AM_CCR;
-               tok.u32++;
+               tok++;
                goto AnOK;
        }
-       else if (*tok.u32 == KW_SR)
+       else if (*tok == KW_SR)
        {
                AMn = AM_SR;
-               tok.u32++;
+               tok++;
                goto AnOK;
        }
-       else if (*tok.u32 == KW_USP)
+       else if (*tok == KW_USP)
        {
                AMn = AM_USP;
-               tok.u32++;
-               AnREG = 2;      //Added this for the case of USP used in movec (see CREGlut in mach.c). Hopefully nothing gets broken!
+               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.u32 >= KW_IC40) && (*tok.u32 <= KW_BC40))
+       else if ((*tok >= KW_IC40) && (*tok <= KW_BC40))
        {
                AMn = CACHES;
-               AnREG = *tok.u32++ - KW_IC40;
+               AnREG = *tok++ - KW_IC40;
 
                // After a cache keyword only a comma or EOL is allowed
-               if ((*tok.u32 != ',') && (*tok.u32 != EOL))
+               if ((*tok != ',') && (*tok != EOL))
                        return ERROR;
                goto AnOK;
        }
-       else if ((*tok.u32 >= KW_SFC) && (*tok.u32 <= KW_CRP))
+       else if ((*tok >= KW_SFC) && (*tok <= KW_CRP))
        {
                AMn = CREG;
-               AnREG = (*tok.u32++) - KW_SFC;
+               AnREG = (*tok++) - KW_SFC;
                goto AnOK;
        }
-       else if ((*tok.u32 >= KW_FP0) && (*tok.u32 <= KW_FP7))
+       else if ((*tok >= KW_FP0) && (*tok <= KW_FP7))
        {
                AMn = FREG;
-               AnREG = (*tok.u32++ & 7);
+               AnREG = (*tok++ & 7);
        }
-       else if ((*tok.u32 >= KW_FPIAR) && (*tok.u32 <= KW_FPCR))
+       else if ((*tok >= KW_FPIAR) && (*tok <= KW_FPCR))
        {
                AMn = FPSCR;
-               AnREG = (1 << ((*tok.u32++) - KW_FPIAR + 10));
+               AnREG = (1 << ((*tok++) - KW_FPIAR + 10));
        }
        // expr
        // expr.w
@@ -1003,10 +1146,10 @@ IS_SUPPRESSEDn:
                        return ERROR;
 
 CHK_FOR_DISPn:
-               if (*tok.u32 == DOTW)
+               if (*tok == DOTW)
                {
                        // expr.W
-                       tok.u32++;
+                       tok++;
                        AMn = ABSW;
 
                        if (((AnEXATTR & (TDB | DEFINED)) == DEFINED) && (AnEXVAL < 0x10000))
@@ -1014,55 +1157,62 @@ CHK_FOR_DISPn:
 
                        goto AnOK;
                }
-               else if (*tok.u32 != '(')
+               else if (*tok != '(')
                {
                        // expr[.L]
                        AMn = ABSL;
 
-                       // Defined, absolute values from $FFFF8000..$00007FFF get optimized
-                       // to absolute short
-                       if (CHECK_OPTS(OPT_ABS_SHORT)
-                               && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
-                               && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
-                       {
-                               AMn = ABSW;
+                       // 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");
 
-                               if (sbra_flag)
-                                       warn("absolute value from $FFFF8000..$00007FFF optimised to absolute short");
-                       }
-
-                       // Is .L forced here?
-                       if (*tok.u32 == DOTL)
+                       // .L is forced here
+                       if (*tok == DOTL)
                        {
-                               tok.u32++;
+                               tok++;
                                AMn = ABSL;
                        }
+                       else
+                       {
+                               // Defined, absolute values from $FFFF8000..$00007FFF get
+                               // optimized to absolute short
+                               if (CHECK_OPTS(OPT_ABS_SHORT)
+                                       && ((AnEXATTR & (TDB | DEFINED)) == DEFINED)
+                                       && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
+                               {
+                                       AMn = ABSW;
+
+                                       if (optim_warn_flag)
+                                               warn("absolute value from $FFFF8000..$00007FFF optimised to absolute short");
+                               }
+                       }
 
                        goto AnOK;
                }
 
-               tok.u32++;
+               tok++;
 
-               if ((*tok.u32 >= KW_A0) && (*tok.u32 <= KW_A7))
+               if ((*tok >= KW_A0) && (*tok <= KW_A7))
                {
-                       AnREG = *tok.u32++ & 7;
+                       AnREG = *tok++ & 7;
 
-                       if (*tok.u32 == ')')
+                       if (*tok == ')')
                        {
                                AMn = ADISP;
-                               tok.u32++;
+                               tok++;
                                goto AnOK;
                        }
 
                        AMn = AINDEXED;
                        goto AMn_IXN;
                }
-               else if (*tok.u32 == KW_PC)
+               else if (*tok == KW_PC)
                {
-                       if (*++tok.u32 == ')')
+                       if (*++tok == ')')
                        {
                                AMn = PCDISP;
-                               tok.u32++;
+                               tok++;
                                goto AnOK;
                        }