X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=parmode.h;h=38f6f94b6c787f5143c40bb98cdc0e7f806c8a0f;hp=4637d72dda1bca9613a2484de82f4bf68ffb9f4c;hb=52cea8604f22cf5281dbc66fcae5fea37d038e0f;hpb=3385b366632d03745033fa6b19faabf60219bc6b diff --git a/parmode.h b/parmode.h index 4637d72..38f6f94 100644 --- a/parmode.h +++ b/parmode.h @@ -3,7 +3,7 @@ // PARMODE.C - Addressing Modes Parser Include // Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 -// Source Utilised with the Kind Permission of Landon Dyer +// Source utilised with the kind permission of Landon Dyer // // This file is included (twice) to parse two addressing modes, into slightly @@ -24,12 +24,18 @@ } else if (*tok == '#') { - ++tok; + tok++; + if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) return ERROR; 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]) @@ -44,7 +50,7 @@ // ([bd,PC,Xn],od) else if (*tok == '(') { - ++tok; + tok++; if ((*tok >= KW_A0) && (*tok <= KW_A7)) { @@ -52,11 +58,11 @@ if (*tok == ')') { - ++tok; + tok++; if (*tok == '+') { - ++tok; + tok++; AMn = APOSTINC; } else @@ -70,7 +76,7 @@ } else if (*tok == KW_PC) { // (PC,Xn[.siz][*scale]) - ++tok; + tok++; AMn = PCINDEXED; // Common index handler; enter here with `tok' pointing at the comma. @@ -93,13 +99,13 @@ switch ((int)*tok) { // Index reg size: | .W | .L case DOTW: - ++tok; + tok++; default: AnIXSIZ = 0; break; case DOTL: AnIXSIZ = 0x0800; - ++tok; + tok++; break; case DOTB: // .B not allowed here... goto badmode; @@ -107,7 +113,8 @@ if (*tok == '*') { // scale: *1, *2, *4, *8 - ++tok; + tok++; + if (*tok++ != CONST || *tok > 8) goto badmode; @@ -143,13 +150,22 @@ 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 == ')') + { + tok++; + goto CHK_FOR_DISPn; + } + + // Otherwise, check for PC & etc displacements... if (*tok++ != ',') goto badmode; if ((*tok >= KW_A0) && (*tok <= KW_A7)) { AnREG = *tok & 7; - ++tok; + tok++; if (*tok == ',') { @@ -159,7 +175,7 @@ else if (*tok == ')') { AMn = ADISP; - ++tok; + tok++; goto AnOK; } else @@ -175,7 +191,7 @@ else if (*tok == ')') { AMn = PCDISP; // expr(PC) - ++tok; + tok++; goto AnOK; } else @@ -194,19 +210,19 @@ else if (*tok == KW_CCR) { AMn = AM_CCR; - ++tok; + tok++; goto AnOK; } else if (*tok == KW_SR) { AMn = AM_SR; - ++tok; + tok++; goto AnOK; } else if (*tok == KW_USP) { AMn = AM_USP; - ++tok; + tok++; goto AnOK; } // expr @@ -221,30 +237,35 @@ if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) return ERROR; +CHK_FOR_DISPn: if (*tok == DOTW) - { // expr.W - ++tok; + { + // expr.W + tok++; AMn = ABSW; goto AnOK; } else if (*tok != '(') - { // expr[.L] + { + // expr[.L] AMn = ABSL; - // Defined, absolute values from $FFFF8000..$00007FFF get optimized to absolute short + // Defined, absolute values from $FFFF8000..$00007FFF get optimized + // to absolute short if ((AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL + 0x8000) < 0x10000) AMn = ABSW; + // Is .L forced here? if (*tok == DOTL) - { // force .L - ++tok; + { + tok++; AMn = ABSL; } goto AnOK; } - ++tok; + tok++; if ((*tok >= KW_A0) && (*tok <= KW_A7)) { @@ -253,7 +274,7 @@ if (*tok == ')') { AMn = ADISP; - ++tok; + tok++; goto AnOK; } @@ -265,7 +286,7 @@ if (*++tok == ')') { AMn = PCDISP; - ++tok; + tok++; goto AnOK; } @@ -281,7 +302,7 @@ ; } -// Cleanup dirty little macros +// Clean up dirty little macros #undef AnOK #undef AMn #undef AnREG @@ -296,3 +317,4 @@ #undef AnESYM #undef AMn_IX0 #undef AMn_IXN +#undef CHK_FOR_DISPn