Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. /* code1750.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Portierung                                                             */
  6. /*                                                                           */
  7. /* Code Generator MIL-STD-1750                                               */
  8. /*                                                                           */
  9. /* This generator is heavily based on the as1750 assembler written by        */
  10. /* Oliver M. Kellogg, Dornier Satellite Systems.  Yes, I know, it's been     */
  11. /* floating around on my hard drive for almost two decades before I got my   */
  12. /* a** up to finally do it.  But maybe someone still reads it...             */
  13. /*                                                                           */
  14. /*****************************************************************************/
  15.  
  16. #include "stdinc.h"
  17. #include <string.h>
  18. #include <ctype.h>
  19.  
  20. #include "bpemu.h"
  21. #include "strutil.h"
  22. #include "asmdef.h"
  23. #include "asmsub.h"
  24. #include "asmpars.h"
  25. #include "asmitree.h"
  26. #include "codepseudo.h"
  27. #include "fourpseudo.h"
  28. #include "codevars.h"
  29. #include "headids.h"
  30. #include "be_le.h"
  31. #include "ieeefloat.h"
  32. #include "errmsg.h"
  33.  
  34. #include "code1750.h"
  35.  
  36. /*-------------------------------------------------------------------------*/
  37.  
  38. typedef struct
  39. {
  40.   const char *pName;
  41.   Word Code;
  42. } tCondition;
  43.  
  44. static CPUVar CPU1750;
  45. static Word AdrReg, AdrWord;
  46.  
  47. /*-------------------------------------------------------------------------*/
  48. /* Utility Functions */
  49.  
  50. static void PutCode(Word Code)
  51. {
  52.   WAsmCode[CodeLen++] = Code;
  53. }
  54.  
  55. static Boolean DecodeReg(const char *pAsc, Word *pResult)
  56. {
  57.   if (toupper(*pAsc) != 'R')
  58.     return False;
  59.   pAsc++;
  60.  
  61.   *pResult = 0;
  62.   while (*pAsc)
  63.   {
  64.     if (!isdigit(*pAsc))
  65.       return False;
  66.     *pResult = (*pResult * 10) + (*pAsc - '0');
  67.     if (*pResult > 15)
  68.       return False;
  69.     pAsc++;
  70.   }
  71.   return True;
  72. }
  73.  
  74. static Boolean DecodeBaseReg(const char *pAsc, Word *pResult)
  75. {
  76.   if ((toupper(*pAsc) != 'R') && (toupper(*pAsc) != 'B'))
  77.     return False;
  78.   pAsc++;
  79.  
  80.   *pResult = 0;
  81.   while (*pAsc)
  82.   {
  83.     if (!isdigit(*pAsc))
  84.       return False;
  85.     *pResult = (*pResult * 10) + (*pAsc - '0');
  86.     if (*pResult > 15)
  87.       return False;
  88.     pAsc++;
  89.   }
  90.   if (*pResult < 12)
  91.     return False;
  92.   *pResult -= 12;
  93.   return True;
  94. }
  95.  
  96. static Boolean DecodeArgReg(unsigned Index, Word *pResult)
  97. {
  98.   Boolean Result = DecodeReg(ArgStr[Index].str.p_str, pResult);
  99.  
  100.   if (!Result)
  101.     WrStrErrorPos(ErrNum_InvReg, &ArgStr[Index]);
  102.   return Result;
  103. }
  104.  
  105. static Boolean DecodeArgBaseReg(unsigned Index, Word *pResult)
  106. {
  107.   Boolean Result = DecodeBaseReg(ArgStr[Index].str.p_str, pResult);
  108.  
  109.   if (!Result)
  110.     WrStrErrorPos(ErrNum_InvReg, &ArgStr[Index]);
  111.   return Result;
  112. }
  113.  
  114. static Boolean DecodeAdr(int StartIdx, int StopIdx)
  115. {
  116.   Boolean OK;
  117.  
  118.   AdrWord = EvalStrIntExpression(&ArgStr[StartIdx], Int16, &OK);
  119.   if (!OK)
  120.     return False;
  121.  
  122.   if (StopIdx > StartIdx)
  123.   {
  124.     OK = False;
  125.     if (!DecodeArgReg(StartIdx + 1, &AdrReg));
  126.     else if (AdrReg == 0)
  127.       WrXErrorPos(ErrNum_InvAddrMode, "!R0", &ArgStr[StartIdx + 1].Pos);
  128.     else
  129.       OK = True;
  130.     return OK;
  131.   }
  132.   else
  133.     AdrReg = 0;
  134.   return OK;
  135. }
  136.  
  137. static Boolean DecodeCondition(const char *pAsc, Word *pResult)
  138. {
  139.   static const tCondition Conditions[] =
  140.   {
  141.     { "LT",  0x1 },             /* 0001 */
  142.     { "LZ",  0x1 },             /* 0001 */
  143.     { "EQ",  0x2 },             /* 0010 */
  144.     { "EZ",  0x2 },             /* 0010 */
  145.     { "LE",  0x3 },             /* 0011 */
  146.     { "LEZ", 0x3 },             /* 0011 */
  147.     { "GT",  0x4 },             /* 0100 */
  148.     { "GTZ", 0x4 },             /* 0100 */
  149.     { "NE",  0x5 },             /* 0101 */
  150.     { "NZ",  0x5 },             /* 0101 */
  151.     { "GE",  0x6 },             /* 0110 */
  152.     { "GEZ", 0x6 },             /* 0110 */
  153.     { "ALL", 0x7 },             /* 0111 */
  154.     { "CY",  0x8 },             /* 1000 */
  155.     { "CLT", 0x9 },             /* 1001 */
  156.     { "CEQ", 0xA },             /* 1010 */
  157.     { "CEZ", 0xA },             /* 1010 */
  158.     { "CLE", 0xB },             /* 1011 */
  159.     { "CGT", 0xC },             /* 1100 */
  160.     { "CNZ", 0xD },             /* 1101 */
  161.     { "CGE", 0xE },             /* 1110 */
  162.     { "UC",  0xF },             /* 1111 */
  163.     { NULL,  0x0 },
  164.   };
  165.   const tCondition *pCond;
  166.  
  167.   for (pCond = Conditions; pCond->pName; pCond++)
  168.     if (!as_strcasecmp(pAsc, pCond->pName))
  169.     {
  170.       *pResult = pCond->Code;
  171.       return True;
  172.     }
  173.   return False;
  174. }
  175.  
  176. static Boolean DecodeArgCondition(unsigned Index, Word *pResult)
  177. {
  178.   Boolean Result = DecodeCondition(ArgStr[Index].str.p_str, pResult);
  179.  
  180.   if (!Result)
  181.     WrStrErrorPos(ErrNum_UndefCond, &ArgStr[Index]);
  182.   return Result;
  183. }
  184.  
  185. static Boolean DecodeArgXIOCmd(unsigned Index, Word *pResult)
  186. {
  187.   static const tCondition XIO[] =
  188.   {
  189.     { "SMK",  0x2000 },
  190.     { "CLIR", 0x2001 },
  191.     { "ENBL", 0x2002 },
  192.     { "DSBL", 0x2003 },
  193.     { "RPI",  0x2004 },
  194.     { "SPI",  0x2005 },
  195.     { "OD",   0x2008 },
  196.     { "RNS",  0x200A },
  197.     { "WSW",  0x200E },
  198.     { "CO",   0x4000 },
  199.     { "CLC",  0x4001 },
  200.     { "MPEN", 0x4003 },
  201.     { "ESUR", 0x4004 },
  202.     { "DSUR", 0x4005 },
  203.     { "DMAE", 0x4006 },
  204.     { "DMAD", 0x4007 },
  205.     { "TAS",  0x4008 },
  206.     { "TAH",  0x4009 },
  207.     { "OTA",  0x400A },
  208.     { "GO",   0x400B },
  209.     { "TBS",  0x400C },
  210.     { "TBH",  0x400D },
  211.     { "OTB",  0x400E },
  212.     { "LMP",  0x5000 },
  213.     { "WIPR", 0x5100 },
  214.     { "WOPR", 0x5200 },
  215.     { "RMP",  0xD000 },
  216.     { "RIPR", 0xD100 },
  217.     { "ROPR", 0xD200 },
  218.     { "RMK",  0xA000 },
  219.     { "RIC1", 0xA001 },
  220.     { "RIC2", 0xA002 },
  221.     { "RPIR", 0xA004 },
  222.     { "RDOR", 0xA008 },
  223.     { "RDI",  0xA009 },
  224.     { "TPIO", 0xA00B },
  225.     { "RMFS", 0xA00D },
  226.     { "RSW",  0xA00E },
  227.     { "RCFR", 0xA00F },
  228.     { "CI",   0xC000 },
  229.     { "RCS",  0xC001 },
  230.     { "ITA",  0xC00A },
  231.     { "ITB",  0xC00E },
  232.     { NULL,   0xFFFF }
  233.   };
  234.   const tCondition *pRun;
  235.   Boolean OK;
  236.  
  237.   if (isalpha(ArgStr[Index].str.p_str[0]))
  238.   {
  239.     for (pRun = XIO; pRun->pName; pRun++)
  240.       if (!as_strcasecmp(ArgStr[Index].str.p_str, pRun->pName))
  241.       {
  242.         *pResult = pRun->Code;
  243.         return True;
  244.       }
  245.   }
  246.   *pResult = EvalStrIntExpression(&ArgStr[Index], UInt16, &OK);
  247.   return OK;
  248. }
  249.  
  250. /*-------------------------------------------------------------------------*/
  251. /* Code Generators */
  252.  
  253. static void DecodeNone(Word Code)
  254. {
  255.   if (ChkArgCnt(0, 0))
  256.     PutCode(Code);
  257. }
  258.  
  259. static void DecodeR(Word Code)
  260. {
  261.   Word Ra, Rb;
  262.  
  263.   if (ChkArgCnt(2, 2)
  264.    && DecodeArgReg(1, &Ra)
  265.    && DecodeArgReg(2, &Rb))
  266.     PutCode(Code | (Ra << 4) | Rb);
  267. }
  268.  
  269. static void DecodeRImm(Word Code)
  270. {
  271.   Word N, Rb;
  272.   Boolean OK;
  273.  
  274.   if (ChkArgCnt(2, 2) && DecodeArgReg(1, &Rb))
  275.   {
  276.     N = EvalStrIntExpression(&ArgStr[2], UInt4, &OK);
  277.     if (OK)
  278.       PutCode(Code | (N << 4) | Rb);
  279.   }
  280. }
  281.  
  282. static void DecodeIS(Word Code)
  283. {
  284.   Word N, Ra;
  285.   Boolean OK;
  286.   tSymbolFlags Flags;
  287.  
  288.   if (ChkArgCnt(2, 2) && DecodeArgReg(1, &Ra))
  289.   {
  290.     N = EvalStrIntExpressionWithFlags(&ArgStr[2], UInt5, &OK, &Flags);
  291.     if (OK && mFirstPassUnknown(Flags))
  292.       N = 1;
  293.     if (OK && ChkRange(N, 1, 16))
  294.       PutCode(Code | (Ra << 4) | (N - 1));
  295.   }
  296. }
  297.  
  298. static void DecodeMem(Word Code)
  299. {
  300.   Word Ra;
  301.  
  302.   if (ChkArgCnt(2, 3)
  303.    && DecodeArgReg(1, &Ra)
  304.    && DecodeAdr(2, ArgCnt))
  305.   {
  306.     PutCode(Code | (Ra << 4) | AdrReg);
  307.     PutCode(AdrWord);
  308.   }
  309. }
  310.  
  311. static void DecodeImOcx(Word Code)
  312. {
  313.   Word Ra;
  314.  
  315.   if (ChkArgCnt(2, 2) && DecodeArgReg(1, &Ra))
  316.   {
  317.     Boolean OK;
  318.     Word ImmVal = EvalStrIntExpression(&ArgStr[2], Int16, &OK);
  319.  
  320.     if (OK)
  321.     {
  322.       PutCode(Code | (Ra << 4));
  323.       PutCode(ImmVal);
  324.     }
  325.   }
  326. }
  327.  
  328. static void DecodeB(Word Code)
  329. {
  330.   Word Br;
  331.  
  332.   if (ChkArgCnt(2, 2) && DecodeArgBaseReg(1, &Br))
  333.   {
  334.     Boolean OK;
  335.     Word LoByte = EvalStrIntExpression(&ArgStr[2], UInt8, &OK);
  336.  
  337.     if (OK)
  338.       PutCode(Code | (Br << 8) | LoByte);
  339.   }
  340. }
  341.  
  342. static void DecodeBX(Word Code)
  343. {
  344.   Word Br, Rx;
  345.  
  346.   if (!ChkArgCnt(2, 2));
  347.   else if (!DecodeArgBaseReg(1, &Br));
  348.   else if (!DecodeArgReg(2, &Rx));
  349.   else if (0 == Rx) WrXErrorPos(ErrNum_InvAddrMode, "!R0", &ArgStr[2].Pos);
  350.   else
  351.     PutCode(Code | (Br << 8) | Rx);
  352. }
  353.  
  354. static void DecodeICR(Word Code)
  355. {
  356.   if (ChkArgCnt(1, 1))
  357.   {
  358.     Boolean OK;
  359.     tSymbolFlags Flags;
  360.     LargeInt Diff = EvalStrIntExpressionWithFlags(&ArgStr[1], UInt16, &OK, &Flags) - EProgCounter();
  361.  
  362.     if (OK)
  363.     {
  364.       if (!mSymbolQuestionable(Flags) && ((Diff < -128) || (Diff > 127))) WrError(ErrNum_JmpDistTooBig);
  365.       else
  366.         PutCode(Code | (Diff & 0xff));
  367.     }
  368.   }
  369. }
  370.  
  371. static void DecodeS(Word Code)
  372. {
  373.   if (ChkArgCnt(1, 1))
  374.   {
  375.     Boolean OK;
  376.     Word Value = EvalStrIntExpression(&ArgStr[1], UInt4, &OK);
  377.  
  378.     if (OK)
  379.       PutCode(Code | Value);
  380.   }
  381. }
  382.  
  383. static void DecodeIM1_16(Word Code)
  384. {
  385.   if (ChkArgCnt(2, 3) && DecodeAdr(2, ArgCnt))
  386.   {
  387.     Boolean OK;
  388.     Word N;
  389.     tSymbolFlags Flags;
  390.  
  391.     N = EvalStrIntExpressionWithFlags(&ArgStr[1], UInt5, &OK, &Flags);
  392.     if (OK && mFirstPassUnknown(Flags))
  393.       N = 1;
  394.  
  395.     if (OK && ChkRange(N, 1, 16))
  396.     {
  397.       PutCode(Code | ((N - 1) << 4) | AdrReg);
  398.       PutCode(AdrWord);
  399.     }
  400.   }
  401. }
  402.  
  403. static void DecodeXMem(Word Code)
  404. {
  405.   Word Ra;
  406.  
  407.   if (ChkArgCnt(2, 3)
  408.    && DecodeArgReg(1, &Ra)
  409.    && DecodeAdr(2, ArgCnt))
  410.   {
  411.     PutCode(Code | (Ra << 4) | AdrReg);
  412.     PutCode(AdrWord);
  413.   }
  414. }
  415.  
  416. static void DecodeImmR(Word Code)
  417. {
  418.   Word Rb, N;
  419.   Boolean OK;
  420.  
  421.   if (ChkArgCnt(2, 2) && DecodeArgReg(2, &Rb))
  422.   {
  423.     N = EvalStrIntExpression(&ArgStr[1], UInt4, &OK);
  424.  
  425.     if (OK)
  426.       PutCode(Code | (N << 4) | Rb);
  427.   }
  428. }
  429.  
  430. static void DecodeJump(Word Code)
  431. {
  432.   Word Cond;
  433.  
  434.   if (ChkArgCnt(2, 3)
  435.    && DecodeArgCondition(1, &Cond)
  436.    && DecodeAdr(2, ArgCnt))
  437.   {
  438.     PutCode(Code | (Cond << 4) | AdrReg);
  439.     PutCode(AdrWord);
  440.   }
  441. }
  442.  
  443. static void DecodeAddr(Word Code)
  444. {
  445.   if (ChkArgCnt(1, 2) && DecodeAdr(1, ArgCnt))
  446.   {
  447.     PutCode(Code | AdrReg);
  448.     PutCode(AdrWord);
  449.   }
  450. }
  451.  
  452. static void DecodeIM_0_15(Word Code)
  453. {
  454.   if (ChkArgCnt(2, 3) && DecodeAdr(2, ArgCnt))
  455.   {
  456.     Boolean OK;
  457.     Word N = EvalStrIntExpression(&ArgStr[1], UInt4, &OK);
  458.  
  459.     if (OK)
  460.     {
  461.       PutCode(Code | (N << 4) | AdrReg);
  462.       PutCode(AdrWord);
  463.     }
  464.   }
  465. }
  466.  
  467. static void DecodeSR(Word Code)
  468. {
  469.   Word R;
  470.  
  471.   if (ChkArgCnt(1, 1)  && DecodeArgReg(1, &R))
  472.     PutCode(Code | (R << 4));
  473. }
  474.  
  475. static void DecodeXIO(Word Code)
  476. {
  477.   Word Ra, Cmd;
  478.  
  479.   if (ChkArgCnt(2, 3)
  480.    && DecodeArgReg(1, &Ra)
  481.    && DecodeArgXIOCmd(2, &Cmd))
  482.   {
  483.     if (ArgCnt == 3)
  484.     {
  485.       Word Ri;
  486.  
  487.       if (!DecodeArgReg(3, &Ri));
  488.       else if (Ri == 0) WrXErrorPos(ErrNum_InvAddrMode, "!R0", &ArgStr[3].Pos);
  489.       else
  490.       {
  491.         PutCode(Code | (Ra << 4) | Ri);
  492.         PutCode(Cmd);
  493.       }
  494.     }
  495.     else
  496.     {
  497.       PutCode(Code | (Ra << 4));
  498.       PutCode(Cmd);
  499.     }
  500.   }
  501. }
  502.  
  503. static void ShiftMantRight(Byte Field[8])
  504. {
  505.   int Index;
  506.  
  507.   for (Index = 7; Index >= 1; Index--)
  508.     Field[Index] = ((Field[Index] >> 1) & 0x7f) | ((Field[Index - 1] & 1) << 7);
  509. }
  510.  
  511. static void ShiftMantLeft(Byte Field[8])
  512. {
  513.   int Index;
  514.  
  515.   for (Index = 1; Index <= 7; Index++)
  516.   {
  517.     Field[Index] = ((Field[Index] & 0x7f) << 1);
  518.     if (Index < 7)
  519.       Field[Index] |= (Field[Index + 1] >> 7) & 0x01;
  520.   }
  521. }
  522.  
  523. static void DecodeFLOAT(Word Extended)
  524. {
  525.   int z;
  526.   Boolean OK;
  527.   Double Value;
  528.   Byte Field[8];
  529.   Byte Sign;
  530.   Word Exponent, Word0, Word1, Word2;
  531.   Integer SignedExponent;
  532.  
  533.   if (!ChkArgCnt(1, ArgCntMax))
  534.     return;
  535.  
  536.   for (z = 1; z <= ArgCnt; z++)
  537.   {
  538.     Value = EvalStrFloatExpression(&ArgStr[z], Float64, &OK);
  539.     if (!OK)
  540.       break;
  541.  
  542.     /* get binary representation, big endian */
  543.  
  544.     Double_2_ieee8(Value, Field, True);
  545. #if 0
  546.     printf("Field 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
  547.            Field[0], Field[1], Field[2], Field[3], Field[4], Field[5], Field[6], Field[7]);
  548. #endif
  549.  
  550.     /* split off sign & exponent */
  551.  
  552.     Sign = (Field[0] > 0x7f);
  553.     Exponent = (((Word) Field[0] & 0x7f) << 4) + (Field[1] >> 4);
  554.     Field[0] = 0;
  555.     Field[1] &= 0x0f;
  556.  
  557. #if 0
  558.     printf("Sign %u Exponent %u Mantissa 0x%02x%02x%02x%02x%02x%02x%02x\n", Sign, Exponent,
  559.            Field[1], Field[2], Field[3], Field[4], Field[5], Field[6], Field[7]);
  560. #endif
  561.  
  562.     /* 1750 format has no implicit leading one in mantissa; i.e. mantissa can only
  563.        represent values of 1 > mant >= -1. If number is not denormalized, we have to
  564.        increase the exponent and shift the mantissa by one to the right: */
  565.  
  566.     if (Exponent > 0)
  567.     {
  568.       Field[1] |= 0x10; /* make leading one explicit */
  569.       Exponent++;
  570.       ShiftMantRight(Field);
  571.     }
  572.  
  573.     /* If exponent is too small to represent, shift down mantissa
  574.        until exponent is large enough, or mantissa is all-zeroes: */
  575.  
  576.     while (Exponent < 1023 - 128)
  577.     {
  578.       Exponent++;
  579.       ShiftMantRight(Field);
  580.       /* todo: regord only relevant bits of mantissa */
  581.       if (!(Field[1] | Field[2] | Field[3] | Field[4] | Field[5] | Field[6] | Field[7]))
  582.       {
  583.         Exponent = 0;
  584.         break;
  585.       }
  586.     }
  587.     SignedExponent = Exponent - 1023;
  588.  
  589.     /* exponent overflow? */
  590.  
  591.     if (SignedExponent > 127)
  592.     {
  593.       WrError(ErrNum_OverRange);
  594.       break;
  595.     }
  596.  
  597. #if 0
  598.     printf("Sign %u SignedExponent %d Mantissa 0x%02x%02x%02x%02x%02x%02x%02x\n", Sign, SignedExponent,
  599.            Field[1], Field[2], Field[3], Field[4], Field[5], Field[6], Field[7]);
  600. #endif
  601.  
  602.     /* form 2s complement of mantissa when sign is set */
  603.  
  604.     if (Sign)
  605.     {
  606.       /* 2s complement range is asymmetric: we can represent -1.0 in the
  607.          mantissa, but not +1.0.  So if the mantissa is +0.5, and the
  608.          exponent is not at minimum, convert it to +1.0 and decrement the
  609.          exponent: */
  610.  
  611.       if ((Field[1] == 0x08) && !Field[2] && !Field[3] && !Field[4]
  612.        && !Field[5] && !Field[6] && !Field[7] && (SignedExponent > -127))
  613.       {
  614.         ShiftMantLeft(Field);
  615.         SignedExponent--;
  616.       }
  617.  
  618.       Field[7] ^= 0xff;
  619.       Field[6] ^= 0xff;
  620.       Field[5] ^= 0xff;
  621.       Field[4] ^= 0xff;
  622.       Field[3] ^= 0xff;
  623.       Field[2] ^= 0xff;
  624.       Field[1] ^= 0x1f;
  625.       if (!(++Field[7]))
  626.         if (!(++Field[6]))
  627.           if (!(++Field[5]))
  628.             if (!(++Field[4]))
  629.               if (!(++Field[3]))
  630.                 if (!(++Field[2]))
  631.                   Field[1] = (Field[1] + 1) & 0x1f;
  632.     }
  633.  
  634.     /* assemble mantissa */
  635.     /* TODO: mantissa rounding? */
  636.  
  637.     Word0 = ((Word)(Field[1] & 0x1f) << 11) | ((Word)Field[2] << 3) | ((Field[3] >> 5) & 0x07);
  638.     Word1 = ((Word)(Field[3] & 0x1f) << 11) | ((Word)(Field[4] & 0xe0) << 3);
  639.     if (Extended)
  640.       Word2 = ((Word)(Field[4] & 0x1f) << 11) | ((Word)Field[5] << 3) | ((Field[6] >> 5) & 0x07);
  641.     else
  642.       Word2 = 0;
  643.  
  644.     /* zero mantissa means zero exponent */
  645.  
  646.     if (!Word0 && !Word1 && !Word2);
  647.     else
  648.       Word1 |= (SignedExponent & 0xff);
  649.  
  650.     /* now copy the mantissa to the destination */
  651.  
  652.     PutCode(Word0);
  653.     PutCode(Word1);
  654.     if (Extended)
  655.       PutCode(Word2);
  656.   }
  657. }
  658.  
  659. static void DecodeDATA_1750(Word Code)
  660. {
  661.   UNUSED(Code);
  662.  
  663.   DecodeDATA(UInt16, UInt16);
  664. }
  665.  
  666. /*-------------------------------------------------------------------------*/
  667. /* dynamic code table handling */
  668.  
  669. static void InitFields(void)
  670. {
  671.   InstTable = CreateInstTable(403);
  672.  
  673.   AddInstTable(InstTable, "AISP", 0xA200, DecodeIS);
  674.   AddInstTable(InstTable, "AIM",  0x4A01, DecodeImOcx);
  675.   AddInstTable(InstTable, "AR",   0xA100, DecodeR);
  676.   AddInstTable(InstTable, "A",    0xA000, DecodeMem);
  677.   AddInstTable(InstTable, "ANDM", 0x4A07, DecodeImOcx);
  678.   AddInstTable(InstTable, "ANDR", 0xE300, DecodeR);
  679.   AddInstTable(InstTable, "AND",  0xE200, DecodeMem);
  680.   AddInstTable(InstTable, "ABS",  0xA400, DecodeR);
  681.   AddInstTable(InstTable, "AB",   0x1000, DecodeB);
  682.   AddInstTable(InstTable, "ANDB", 0x3400, DecodeB);
  683.   AddInstTable(InstTable, "ABX",  0x4040, DecodeBX);
  684.   AddInstTable(InstTable, "ANDX", 0x40E0, DecodeBX);
  685.   AddInstTable(InstTable, "BEZ",  0x7500, DecodeICR);
  686.   AddInstTable(InstTable, "BNZ",  0x7A00, DecodeICR);
  687.   AddInstTable(InstTable, "BGT",  0x7900, DecodeICR);
  688.   AddInstTable(InstTable, "BLE",  0x7800, DecodeICR);
  689.   AddInstTable(InstTable, "BGE",  0x7B00, DecodeICR);
  690.   AddInstTable(InstTable, "BLT",  0x7600, DecodeICR);
  691.   AddInstTable(InstTable, "BR",   0x7400, DecodeICR);
  692.   AddInstTable(InstTable, "BEX",  0x7700, DecodeS);
  693.   AddInstTable(InstTable, "BPT",  0xFFFF, DecodeNone);
  694.   AddInstTable(InstTable, "BIF",  0x4F00, DecodeS);
  695.   AddInstTable(InstTable, "CISP", 0xF200, DecodeIS);
  696.   AddInstTable(InstTable, "CIM",  0x4A0A, DecodeImOcx);
  697.   AddInstTable(InstTable, "CR",   0xF100, DecodeR);
  698.   AddInstTable(InstTable, "C",    0xF000, DecodeMem);
  699.   AddInstTable(InstTable, "CISN", 0xF300, DecodeIS);
  700.   AddInstTable(InstTable, "CB",   0x3800, DecodeB);
  701.   AddInstTable(InstTable, "CBL",  0xF400, DecodeMem);
  702.   AddInstTable(InstTable, "CBX",  0x40C0, DecodeBX);
  703.   AddInstTable(InstTable, "DLR",  0x8700, DecodeR);
  704.   AddInstTable(InstTable, "DL",   0x8600, DecodeMem);
  705.   AddInstTable(InstTable, "DST",  0x9600, DecodeMem);
  706.   AddInstTable(InstTable, "DSLL", 0x6500, DecodeRImm);
  707.   AddInstTable(InstTable, "DSRL", 0x6600, DecodeRImm);
  708.   AddInstTable(InstTable, "DSRA", 0x6700, DecodeRImm);
  709.   AddInstTable(InstTable, "DSLC", 0x6800, DecodeRImm);
  710.   AddInstTable(InstTable, "DSLR", 0x6D00, DecodeR);
  711.   AddInstTable(InstTable, "DSAR", 0x6E00, DecodeR);
  712.   AddInstTable(InstTable, "DSCR", 0x6F00, DecodeR);
  713.   AddInstTable(InstTable, "DECM", 0xB300, DecodeIM1_16);
  714.   AddInstTable(InstTable, "DAR",  0xA700, DecodeR);
  715.   AddInstTable(InstTable, "DA",   0xA600, DecodeMem);
  716.   AddInstTable(InstTable, "DSR",  0xB700, DecodeR);
  717.   AddInstTable(InstTable, "DS",   0xB600, DecodeMem);
  718.   AddInstTable(InstTable, "DMR",  0xC700, DecodeR);
  719.   AddInstTable(InstTable, "DM",   0xC600, DecodeMem);
  720.   AddInstTable(InstTable, "DDR",  0xD700, DecodeR);
  721.   AddInstTable(InstTable, "DD",   0xD600, DecodeMem);
  722.   AddInstTable(InstTable, "DCR",  0xF700, DecodeR);
  723.   AddInstTable(InstTable, "DC",   0xF600, DecodeMem);
  724.   AddInstTable(InstTable, "DLB",  0x0400, DecodeB);
  725.   AddInstTable(InstTable, "DSTB", 0x0C00, DecodeB);
  726.   AddInstTable(InstTable, "DNEG", 0xB500, DecodeR);
  727.   AddInstTable(InstTable, "DABS", 0xA500, DecodeR);
  728.   AddInstTable(InstTable, "DR",   0xD500, DecodeR);
  729.   AddInstTable(InstTable, "D",    0xD400, DecodeMem);
  730.   AddInstTable(InstTable, "DISP", 0xD200, DecodeIS);
  731.   AddInstTable(InstTable, "DIM",  0x4A05, DecodeImOcx);
  732.   AddInstTable(InstTable, "DISN", 0xD300, DecodeIS);
  733.   AddInstTable(InstTable, "DVIM", 0x4A06, DecodeImOcx);
  734.   AddInstTable(InstTable, "DVR",  0xD100, DecodeR);
  735.   AddInstTable(InstTable, "DV",   0xD000, DecodeMem);
  736.   AddInstTable(InstTable, "DLI",  0x8800, DecodeMem);
  737.   AddInstTable(InstTable, "DSTI", 0x9800, DecodeMem);
  738.   AddInstTable(InstTable, "DB",   0x1C00, DecodeB);
  739.   AddInstTable(InstTable, "DBX",  0x4070, DecodeBX);
  740.   AddInstTable(InstTable, "DLBX", 0x4010, DecodeBX);
  741.   AddInstTable(InstTable, "DSTX", 0x4030, DecodeBX);
  742.   AddInstTable(InstTable, "DLE",  0xDF00, DecodeXMem);
  743.   AddInstTable(InstTable, "DSTE", 0xDD00, DecodeXMem);
  744.   AddInstTable(InstTable, "EFL",  0x8A00, DecodeMem);
  745.   AddInstTable(InstTable, "EFST", 0x9A00, DecodeMem);
  746.   AddInstTable(InstTable, "EFCR", 0xFB00, DecodeR);
  747.   AddInstTable(InstTable, "EFC",  0xFA00, DecodeMem);
  748.   AddInstTable(InstTable, "EFAR", 0xAB00, DecodeR);
  749.   AddInstTable(InstTable, "EFA",  0xAA00, DecodeMem);
  750.   AddInstTable(InstTable, "EFSR", 0xBB00, DecodeR);
  751.   AddInstTable(InstTable, "EFS",  0xBA00, DecodeMem);
  752.   AddInstTable(InstTable, "EFMR", 0xCB00, DecodeR);
  753.   AddInstTable(InstTable, "EFM",  0xCA00, DecodeMem);
  754.   AddInstTable(InstTable, "EFDR", 0xDB00, DecodeR);
  755.   AddInstTable(InstTable, "EFD",  0xDA00, DecodeMem);
  756.   AddInstTable(InstTable, "EFLT", 0xEB00, DecodeR);
  757.   AddInstTable(InstTable, "EFIX", 0xEA00, DecodeR);
  758.   AddInstTable(InstTable, "FAR",  0xA900, DecodeR);
  759.   AddInstTable(InstTable, "FA",   0xA800, DecodeMem);
  760.   AddInstTable(InstTable, "FSR",  0xB900, DecodeR);
  761.   AddInstTable(InstTable, "FS",   0xB800, DecodeMem);
  762.   AddInstTable(InstTable, "FMR",  0xC900, DecodeR);
  763.   AddInstTable(InstTable, "FM",   0xC800, DecodeMem);
  764.   AddInstTable(InstTable, "FDR",  0xD900, DecodeR);
  765.   AddInstTable(InstTable, "FD",   0xD800, DecodeMem);
  766.   AddInstTable(InstTable, "FCR",  0xF900, DecodeR);
  767.   AddInstTable(InstTable, "FC",   0xF800, DecodeMem);
  768.   AddInstTable(InstTable, "FABS", 0xAC00, DecodeR);
  769.   AddInstTable(InstTable, "FIX",  0xE800, DecodeR);
  770.   AddInstTable(InstTable, "FLT",  0xE900, DecodeR);
  771.   AddInstTable(InstTable, "FNEG", 0xBC00, DecodeR);
  772.   AddInstTable(InstTable, "FAB",  0x2000, DecodeB);
  773.   AddInstTable(InstTable, "FABX", 0x4080, DecodeBX);
  774.   AddInstTable(InstTable, "FSB",  0x2400, DecodeB);
  775.   AddInstTable(InstTable, "FSBX", 0x4090, DecodeBX);
  776.   AddInstTable(InstTable, "FMB",  0x2800, DecodeB);
  777.   AddInstTable(InstTable, "FMBX", 0x40A0, DecodeBX);
  778.   AddInstTable(InstTable, "FDB",  0x2C00, DecodeB);
  779.   AddInstTable(InstTable, "FDBX", 0x40B0, DecodeBX);
  780.   AddInstTable(InstTable, "FCB",  0x3C00, DecodeB);
  781.   AddInstTable(InstTable, "FCBX", 0x40D0, DecodeBX);
  782.   AddInstTable(InstTable, "INCM", 0xA300, DecodeIM1_16);
  783.   AddInstTable(InstTable, "JC",   0x7000, DecodeJump);
  784.   AddInstTable(InstTable, "J",    0x7400, DecodeICR);   /* TBD (GAS) */
  785.   AddInstTable(InstTable, "JEZ",  0x7500, DecodeICR);   /* TBD (GAS) */
  786.   AddInstTable(InstTable, "JLE",  0x7800, DecodeICR);   /* TBD (GAS) */
  787.   AddInstTable(InstTable, "JGT",  0x7900, DecodeICR);   /* TBD (GAS) */
  788.   AddInstTable(InstTable, "JNZ",  0x7A00, DecodeICR);   /* TBD (GAS) */
  789.   AddInstTable(InstTable, "JGE",  0x7B00, DecodeICR);   /* TBD (GAS) */
  790.   AddInstTable(InstTable, "JLT",  0x7600, DecodeICR);   /* TBD (GAS) */
  791.   AddInstTable(InstTable, "JCI",  0x7100, DecodeJump);
  792.   AddInstTable(InstTable, "JS",   0x7200, DecodeMem);
  793.   AddInstTable(InstTable, "LISP", 0x8200, DecodeIS);
  794.   AddInstTable(InstTable, "LIM",  0x8500, DecodeMem);
  795.   AddInstTable(InstTable, "LR",   0x8100, DecodeR);
  796.   AddInstTable(InstTable, "L",    0x8000, DecodeMem);
  797.   AddInstTable(InstTable, "LISN", 0x8300, DecodeIS);
  798.   AddInstTable(InstTable, "LB",   0x0000, DecodeB);
  799.   AddInstTable(InstTable, "LBX",  0x4000, DecodeBX);
  800.   AddInstTable(InstTable, "LSTI", 0x7C00, DecodeAddr);
  801.   AddInstTable(InstTable, "LST",  0x7D00, DecodeAddr);
  802.   AddInstTable(InstTable, "LI",   0x8400, DecodeMem);
  803.   AddInstTable(InstTable, "LM",   0x8900, DecodeIM_0_15);
  804.   AddInstTable(InstTable, "LUB",  0x8B00, DecodeMem);
  805.   AddInstTable(InstTable, "LLB",  0x8C00, DecodeMem);
  806.   AddInstTable(InstTable, "LUBI", 0x8D00, DecodeMem);
  807.   AddInstTable(InstTable, "LLBI", 0x8E00, DecodeMem);
  808.   AddInstTable(InstTable, "LE",   0xDE00, DecodeXMem);
  809.   AddInstTable(InstTable, "MISP", 0xC200, DecodeIS);
  810.   AddInstTable(InstTable, "MSIM", 0x4A04, DecodeImOcx);
  811.   AddInstTable(InstTable, "MSR",  0xC100, DecodeR);
  812.   AddInstTable(InstTable, "MS",   0xC000, DecodeMem);
  813.   AddInstTable(InstTable, "MISN", 0xC300, DecodeIS);
  814.   AddInstTable(InstTable, "MIM",  0x4A03, DecodeImOcx);
  815.   AddInstTable(InstTable, "MR",   0xC500, DecodeR);
  816.   AddInstTable(InstTable, "M",    0xC400, DecodeMem);
  817.   AddInstTable(InstTable, "MOV",  0x9300, DecodeR);
  818.   AddInstTable(InstTable, "MB",   0x1800, DecodeB);
  819.   AddInstTable(InstTable, "MBX",  0x4060, DecodeBX);
  820.   AddInstTable(InstTable, "NEG",  0xB400, DecodeR);
  821.   AddInstTable(InstTable, "NOP",  0xFF00, DecodeNone);
  822.   AddInstTable(InstTable, "NIM",  0x4A0B, DecodeImOcx);
  823.   AddInstTable(InstTable, "NR",   0xE700, DecodeR);
  824.   AddInstTable(InstTable, "N",    0xE600, DecodeMem);
  825.   AddInstTable(InstTable, "ORIM", 0x4A08, DecodeImOcx);
  826.   AddInstTable(InstTable, "ORR",  0xE100, DecodeR);
  827.   AddInstTable(InstTable, "OR",   0xE000, DecodeMem);
  828.   AddInstTable(InstTable, "ORB",  0x3000, DecodeB);
  829.   AddInstTable(InstTable, "ORBX", 0x40F0, DecodeBX);
  830.   AddInstTable(InstTable, "PSHM", 0x9F00, DecodeR);
  831.   AddInstTable(InstTable, "POPM", 0x8F00, DecodeR);
  832.   AddInstTable(InstTable, "RBR",  0x5400, DecodeImmR);
  833.   AddInstTable(InstTable, "RVBR", 0x5C00, DecodeR);
  834.   AddInstTable(InstTable, "RB",   0x5300, DecodeIM_0_15);
  835.   AddInstTable(InstTable, "RBI",  0x5500, DecodeIM_0_15);
  836.   AddInstTable(InstTable, "ST",   0x9000, DecodeMem);
  837.   AddInstTable(InstTable, "STC",  0x9100, DecodeIM_0_15);
  838.   AddInstTable(InstTable, "SISP", 0xB200, DecodeIS);
  839.   AddInstTable(InstTable, "SIM",  0x4A02, DecodeImOcx);
  840.   AddInstTable(InstTable, "SR",   0xB100, DecodeR);
  841.   AddInstTable(InstTable, "S",    0xB000, DecodeMem);
  842.   AddInstTable(InstTable, "SLL",  0x6000, DecodeRImm);
  843.   AddInstTable(InstTable, "SRL",  0x6100, DecodeRImm);
  844.   AddInstTable(InstTable, "SRA",  0x6200, DecodeRImm);
  845.   AddInstTable(InstTable, "SLC",  0x6300, DecodeRImm);
  846.   AddInstTable(InstTable, "SLR",  0x6A00, DecodeR);
  847.   AddInstTable(InstTable, "SAR",  0x6B00, DecodeR);
  848.   AddInstTable(InstTable, "SCR",  0x6C00, DecodeR);
  849.   AddInstTable(InstTable, "SJS",  0x7E00, DecodeMem);
  850.   AddInstTable(InstTable, "STB",  0x0800, DecodeB);
  851.   AddInstTable(InstTable, "SBR",  0x5100, DecodeImmR);
  852.   AddInstTable(InstTable, "SB",   0x5000, DecodeIM_0_15);
  853.   AddInstTable(InstTable, "SVBR", 0x5A00, DecodeR);
  854.   AddInstTable(InstTable, "SOJ",  0x7300, DecodeMem);
  855.   AddInstTable(InstTable, "SBB",  0x1400, DecodeB);
  856.   AddInstTable(InstTable, "STBX", 0x4020, DecodeBX);
  857.   AddInstTable(InstTable, "SBBX", 0x4050, DecodeBX);
  858.   AddInstTable(InstTable, "SBI",  0x5200, DecodeIM_0_15);
  859.   AddInstTable(InstTable, "STZ",  0x9100, DecodeAddr);
  860.   AddInstTable(InstTable, "STCI", 0x9200, DecodeIM_0_15);
  861.   AddInstTable(InstTable, "STI",  0x9400, DecodeMem);
  862.   AddInstTable(InstTable, "SFBS", 0x9500, DecodeR);
  863.   AddInstTable(InstTable, "SRM",  0x9700, DecodeMem);
  864.   AddInstTable(InstTable, "STM",  0x9900, DecodeIM_0_15);
  865.   AddInstTable(InstTable, "STUB", 0x9B00, DecodeMem);
  866.   AddInstTable(InstTable, "STLB", 0x9C00, DecodeMem);
  867.   AddInstTable(InstTable, "SUBI", 0x9D00, DecodeMem);
  868.   AddInstTable(InstTable, "SLBI", 0x9E00, DecodeMem);
  869.   AddInstTable(InstTable, "STE",  0xDC00, DecodeXMem);
  870.   AddInstTable(InstTable, "TBR",  0x5700, DecodeImmR);
  871.   AddInstTable(InstTable, "TB",   0x5600, DecodeIM_0_15);
  872.   AddInstTable(InstTable, "TBI",  0x5800, DecodeIM_0_15);
  873.   AddInstTable(InstTable, "TSB",  0x5900, DecodeIM_0_15);
  874.   AddInstTable(InstTable, "TVBR", 0x5E00, DecodeR);
  875.   AddInstTable(InstTable, "URS",  0x7F00, DecodeSR);
  876.   AddInstTable(InstTable, "UAR",  0xAD00, DecodeR);
  877.   AddInstTable(InstTable, "UA",   0xAE00, DecodeMem);
  878.   AddInstTable(InstTable, "USR",  0xBD00, DecodeR);
  879.   AddInstTable(InstTable, "US",   0xBE00, DecodeMem);
  880.   AddInstTable(InstTable, "UCIM", 0xF500, DecodeImOcx);
  881.   AddInstTable(InstTable, "UCR",  0xFC00, DecodeR);
  882.   AddInstTable(InstTable, "UC",   0xFD00, DecodeMem);
  883.   AddInstTable(InstTable, "VIO",  0x4900, DecodeMem);
  884.   AddInstTable(InstTable, "XORR", 0xE500, DecodeR);
  885.   AddInstTable(InstTable, "XORM", 0x4A09, DecodeImOcx);
  886.   AddInstTable(InstTable, "XOR",  0xE400, DecodeMem);
  887.   AddInstTable(InstTable, "XWR",  0xED00, DecodeR);
  888.   AddInstTable(InstTable, "XBR",  0xEC00, DecodeSR);
  889.   AddInstTable(InstTable, "XIO",  0x4800, DecodeXIO);
  890.  
  891.   AddInstTable(InstTable, "FLOAT", 0, DecodeFLOAT);
  892.   AddInstTable(InstTable, "EXTENDED", 1, DecodeFLOAT);
  893.   AddInstTable(InstTable, "DATA", 0, DecodeDATA_1750);
  894. }
  895.  
  896. static void DeinitFields(void)
  897. {
  898.   DestroyInstTable(InstTable);
  899. }
  900.  
  901. /*-------------------------------------------------------------------------*/
  902. /* interface to common layer */
  903.  
  904. static void MakeCode_1750(void)
  905. {
  906.   CodeLen = 0; DontPrint = False;
  907.  
  908.   /* zu ignorierendes */
  909.  
  910.   if (Memo(""))
  911.     return;
  912.  
  913.   if (!LookupInstTable(InstTable, OpPart.str.p_str))
  914.     WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
  915. }
  916.  
  917. static Boolean IsDef_1750(void)
  918. {
  919.   return Memo("BIT");
  920. }
  921.  
  922. static void SwitchFrom_1750(void)
  923. {
  924.   DeinitFields();
  925. }
  926.  
  927. static void SwitchTo_1750(void)
  928. {
  929.   const TFamilyDescr *pDescr;
  930.  
  931.   pDescr = FindFamilyByName("1750");
  932.  
  933.   TurnWords = False;
  934.   SetIntConstMode(eIntConstModeIntel);
  935.  
  936.   PCSymbol = "$";
  937.   HeaderID = pDescr->Id;
  938.   NOPCode = 0xff00;
  939.   DivideChars = ",";
  940.   HasAttrs = False;
  941.  
  942.   ValidSegs = 1 << SegCode;
  943.   Grans[SegCode] = 2; ListGrans[SegCode] = 2; SegInits[SegCode] = 0;
  944.   SegLimits[SegCode] = 0xffff;
  945.  
  946.   ASSUMERecCnt = 0;
  947.  
  948.   MakeCode = MakeCode_1750;
  949.   IsDef = IsDef_1750;
  950.   SwitchFrom = SwitchFrom_1750; InitFields();
  951. }
  952.  
  953. void code1750_init(void)
  954. {
  955.   CPU1750 = AddCPU("1750", SwitchTo_1750);
  956.   AddCopyright("MIL-STD 1750 Generator also (C) 2019 Oliver Kellogg");
  957. }
  958.