X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=parmode.h;h=549f131ea42630df7869042f42bcb3fbd72f8df8;hp=0c5d66dd655f8005d0d360e6f09dae92a8055e63;hb=d812346ecf7309ee3fb88a8dd1f4bca033121ad5;hpb=0951a3e28907fbaf89a10c5201b71d8080ffe5a8 diff --git a/parmode.h b/parmode.h index 0c5d66d..549f131 100644 --- 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 // @@ -81,7 +81,7 @@ } else if ((*tok >= KW_D0) && (*tok <= KW_D7)) { - //Since index register isn't used here, store register number in this field + // Since index register isn't used here, store register number in this field AnIXREG = *tok++ & 7; // (Dn) if (*tok == ')') @@ -213,12 +213,12 @@ // 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++ != ',') goto badmode; @@ -251,6 +251,7 @@ { if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK) return error("scale factor expression must evaluate"); + switch (scaleval) { case 1: @@ -320,18 +321,21 @@ 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 == DOTL) - { // ([bd.l,... - AnEXTEN |= EXT_BDSIZEL; - tok++; + { + // ([bd.l,... + AnEXTEN |= EXT_BDSIZEL; + tok++; } else - { // ([bd[.w],... or ([bd,... + { + // ([bd[.w],... or ([bd,... // Is .W forced here? if (*tok == DOTW) { @@ -340,14 +344,16 @@ } 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 { @@ -385,24 +391,22 @@ tok++; // Check for size + // ([bd,An/PC],Xn.W/L...) + switch ((int)*tok) { - // ([bd,An/PC],Xn.W/L...) - switch ((int)*tok) - { - // Index reg size: | .W | .L - case DOTW: - tok++; - break; - default: - break; - case DOTL: - AnEXTEN |= EXT_L; - tok++; - break; - case DOTB: - // .B not allowed here... - goto badmode; - } + // Index reg size: | .W | .L + case DOTW: + tok++; + break; + default: + break; + case DOTL: + AnEXTEN |= EXT_L; + tok++; + break; + case DOTB: + // .B not allowed here... + goto badmode; } // Check for scale @@ -465,8 +469,7 @@ 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 @@ -477,16 +480,16 @@ // At a crossroads here. We can accept either ([bd,An/PC],... or ([bd,An/PC,Xn*scale],... if (*tok == ']') { - //([bd,An/PC],Xn,od) + // ([bd,An/PC],Xn,od) // Check for Xn tok++; if (*tok == ')') { - //Xn and od are non existent, get out of jail free card + // Xn and od are non existent, get out of jail free card tok++; AMn = MEMPRE; // ([bc,An,Xn],od) with no Xn and od - AnEXTEN |= EXT_IS | EXT_IISPREN; //Suppress Xn and od + AnEXTEN |= EXT_IS | EXT_IISPREN; // Suppress Xn and od goto AnOK; } else if (*tok != ',') @@ -508,31 +511,29 @@ } else { - //No index found, suppress it + // No index found, suppress it AnEXTEN |= EXT_IS; tok--; // Rewind tok to point to the comma goto IS_SUPPRESSEDn; // https://xkcd.com/292/ - what does he know anyway? } // Check for size + // ([bd,An/PC],Xn.W/L...) + switch ((int)*tok) { - // ([bd,An/PC],Xn.W/L...) - switch ((int)*tok) - { - // Index reg size: | .W | .L - case DOTW: - tok++; - break; - default: - break; - case DOTL: - AnEXTEN |= EXT_L; - tok++; - break; - case DOTB: - // .B not allowed here... - goto badmode; - } + // Index reg size: | .W | .L + case DOTW: + tok++; + break; + default: + break; + case DOTL: + AnEXTEN |= EXT_L; + tok++; + break; + case DOTB: + // .B not allowed here... + goto badmode; } // Check for scale @@ -601,13 +602,13 @@ else tok++; // eat the comma - CHECKODn: +CHECKODn: if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) goto badmode; - if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0)) + if (CHECK_OPTS(OPT_020_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0)) { - // od=0 so optimise it out + // od = 0 so optimise it out AMn = MEMPOST; // let's say it's ([bd,An],Xn,od) with od=0 then AnEXTEN |= EXT_IISPOSN; // No outer displacement tok++; @@ -615,9 +616,21 @@ } // ([bd,An/PC],Xn,od) - if (*tok == DOTL) + // Is .W forced here? + if (*tok == DOTW) { - // expr.L + tok++; + // od[.W] + AnEXTEN |= EXT_IISPOSW; // Word outer displacement + AMn = MEMPOST; + } + else + { + // Is .L forced here? + if (*tok == DOTL) + tok++; // Doesn't matter, we're going for .L anyway + + // od.L if (!(AnEXTEN & EXT_BS)) AnEXTEN |= EXT_IISPOSL; // Long outer displacement else @@ -632,37 +645,23 @@ { AnBEXPR[i] = AnEXPR[i]; i++; - } - while (AnEXPR[i] != 'E'); + } while (AnEXPR[i] != 'E'); AnBEXPR[i] = 'E'; } AMn = MEMPOST; - tok++; // Defined, absolute values from $FFFF8000..$00007FFF get // optimized to absolute short - if (CHECK_OPTS(OPT_ABS_SHORT) + if (CHECK_OPTS(OPT_020_DISP) && ((AnEXATTR & (TDB | DEFINED)) == DEFINED) && (((uint32_t)AnEXVAL + 0x8000) < 0x10000)) { AnEXTEN |= EXT_IISPOSW; // Word outer displacement AMn = MEMPOST; - warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short"); - } - - } - else - { - // expr[.W] - AnEXTEN |= EXT_IISPOSW; // Word outer displacement - AMn = MEMPOST; - - // Is .W forced here? - if (*tok == DOTW) - { - tok++; + if (optim_warn_flag) + warn("absolute value in outer displacement ranging $FFFF8000..$00007FFF optimised to absolute short"); } } @@ -696,7 +695,7 @@ IS_SUPPRESSEDn: expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM); - if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0)) + if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0)) { // od=0 so optimise it out AMn = MEMPOST; // let's say it's ([bd,An],Xn,od) with od=0 then @@ -727,12 +726,13 @@ IS_SUPPRESSEDn: } // Defined, absolute values from $FFFF8000..$00007FFF get // optimized to absolute short - else if (CHECK_OPTS(OPT_BASE_DISP) + else if (CHECK_OPTS(OPT_020_DISP) && ((AnEXATTR & (TDB | DEFINED)) == DEFINED) && (((uint32_t)AnEXVAL + 0x8000) < 0x10000)) { //AnEXTEN|=EXT_IISNOIW; // Word outer displacement with IS suppressed - warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short"); + if (optim_warn_flag) + warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short"); } } @@ -764,35 +764,34 @@ IS_SUPPRESSEDn: } // Check for size + // ([bd,An/PC],Xn.W/L...) + switch ((int)*tok) { - // ([bd,An/PC],Xn.W/L...) - switch ((int)*tok) - { - // Index reg size: | .W | .L - case DOTW: - tok++; - break; - default: - break; - case DOTL: - tok++; - AnEXTEN |= EXT_L; - break; - case DOTB: - // .B not allowed here... - goto badmode; - } + // Index reg size: | .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 == '*') // ([bd,An/PC],Xn*...) - { // scale: *1, *2, *4, *8 + { // 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: @@ -861,7 +860,7 @@ IS_SUPPRESSEDn: if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) goto badmode; - if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0) && (AnEXATTR & DEFINED)) + if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0) && (AnEXATTR & DEFINED)) { // od=0 so optimise it out AMn = MEMPRE; // let's say it's ([bd,An],Xn,od) with od=0 then @@ -892,12 +891,14 @@ IS_SUPPRESSEDn: // Defined, absolute values from $FFFF8000..$00007FFF // get optimized to absolute short - if (CHECK_OPTS(OPT_BASE_DISP) + if (CHECK_OPTS(OPT_020_DISP) && ((AnEXATTR & (TDB | DEFINED)) == DEFINED) && (((uint32_t)AnEXVAL + 0x8000) < 0x10000)) { expr_size = EXT_IISPREW; - warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short"); + + if (optim_warn_flag) + warn("outer displacement absolute value from $FFFF8000..$00007FFF optimised to absolute short"); } } @@ -950,22 +951,25 @@ IS_SUPPRESSEDn: 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... + // 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 + // 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 + // 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; @@ -996,13 +1000,14 @@ IS_SUPPRESSEDn: } // Check for scale if (*tok == '*') // ([bd,An/PC],Xn*...) - { // scale: *1, *2, *4, *8 + { // 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: @@ -1055,7 +1060,7 @@ IS_SUPPRESSEDn: else goto badmode; } - + AMn = AINDEXED; goto AMn_IXN; } @@ -1168,24 +1173,31 @@ CHK_FOR_DISPn: // 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; - - if (sbra_flag) - warn("absolute value from $FFFF8000..$00007FFF optimised to absolute short"); - } + // 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"); - // Is .L forced here? + // .L is forced here if (*tok == DOTL) { 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; }