Subversion Repositories pentevo

Rev

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

  1. /* code9900.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Portierung                                                             */
  6. /*                                                                           */
  7. /* Codegenerator TMS99xx(x)                                                  */
  8. /*                                                                           */
  9. /*****************************************************************************/
  10.  
  11. #include "stdinc.h"
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. #include "strutil.h"
  16. #include "be_le.h"
  17. #include "bpemu.h"
  18. #include "nls.h"
  19. #include "chunks.h"
  20. #include "asmdef.h"
  21. #include "asmsub.h"
  22. #include "asmpars.h"
  23. #include "asmcode.h"
  24. #include "asmallg.h"
  25. #include "onoff_common.h"
  26. #include "asmitree.h"
  27. #include "codepseudo.h"
  28. #include "codevars.h"
  29. #include "ibmfloat.h"
  30. #include "chartrans.h"
  31. #include "errmsg.h"
  32.  
  33. #include "code9900.h"
  34.  
  35. #define CKPT_NOTHING 16
  36.  
  37. enum
  38. {
  39.   eCoreNone = 0,
  40.   eCore990_10  = 1 << 0,
  41.   eCore990_12  = 1 << 1,
  42.   eCore9900    = 1 << 2,
  43.   eCore9940    = 1 << 3,
  44.   eCore9995    = 1 << 4,
  45.   eCore99105   = 1 << 5,
  46.   eCore99110   = 1 << 6,
  47.   eCoreAll     = eCore990_10 | eCore990_12 | eCore9900 | eCore9940 | eCore9995 | eCore99105 | eCore99110,
  48.  
  49.   eCoreFlagSupMode = 1 << 7
  50. };
  51.  
  52. typedef struct
  53. {
  54.   const char *pName;
  55.   Byte CoreFlags;
  56. } tCPUProps;
  57.  
  58. typedef struct
  59. {
  60.   Word Code;
  61.   Byte Flags;
  62. } tOrder;
  63.  
  64. static const tCPUProps *pCurrCPUProps;
  65. static tOrder *SingOrders, *ImmOrders, *FixedOrders, *RegOrders,
  66.               *Type11Orders, *Type11aOrders, *Type12Orders, *Type15Orders,
  67.               *Type16Orders, *Type17Orders, *Type20Orders;
  68. static Boolean IsWord;
  69. static Word AdrVal, AdrPart, DefCkpt;
  70.  
  71. /*-------------------------------------------------------------------------*/
  72. /* Adressparser */
  73.  
  74. static Boolean DecodeReg(const tStrComp *pArg, Word *Erg)
  75. {
  76.   Boolean OK;
  77.   *Erg = EvalStrIntExpression(pArg, UInt4, &OK);
  78.   return OK;
  79. }
  80.  
  81. static char *HasDisp(char *Asc)
  82. {
  83.   char *p;
  84.   int Lev, Len = strlen(Asc);
  85.  
  86.   if ((Len >= 2) && (Asc[Len - 1] == ')'))
  87.   {
  88.     p = Asc + Len - 2; Lev = 0;
  89.     while ((p >= Asc) && (Lev != -1))
  90.     {
  91.       switch (*p)
  92.       {
  93.         case '(': Lev--; break;
  94.         case ')': Lev++; break;
  95.       }
  96.       if (Lev != -1) p--;
  97.     }
  98.     if (Lev != -1)
  99.     {
  100.       WrError(ErrNum_BrackErr);
  101.       p = NULL;
  102.     }
  103.   }
  104.   else
  105.     p = NULL;
  106.  
  107.   return p;
  108. }
  109.  
  110. static Boolean DecodeAdr(const tStrComp *pArg)
  111. {
  112.   Boolean IncFlag;
  113.   Boolean OK;
  114.   char *p;
  115.  
  116.   AdrCnt = 0;
  117.  
  118.   if (*pArg->str.p_str == '*')
  119.   {
  120.     tStrComp IArg;
  121.  
  122.     StrCompRefRight(&IArg, pArg, 1);
  123.     if (IArg.str.p_str[strlen(IArg.str.p_str) - 1] == '+')
  124.     {
  125.       IncFlag = True;
  126.       StrCompShorten(&IArg, 1);
  127.     }
  128.     else
  129.       IncFlag = False;
  130.     if (DecodeReg(&IArg, &AdrPart))
  131.     {
  132.       AdrPart += 0x10 + (Ord(IncFlag) << 5);
  133.       return True;
  134.     }
  135.     return False;
  136.   }
  137.  
  138.   if (*pArg->str.p_str == '@')
  139.   {
  140.     tStrComp IArg;
  141.  
  142.     StrCompRefRight(&IArg, pArg, 1);
  143.     p = HasDisp(IArg.str.p_str);
  144.     if (!p)
  145.     {
  146.       tSymbolFlags Flags;
  147.  
  148.       AdrVal = EvalStrIntExpressionWithFlags(&IArg, UInt16, &OK, &Flags);
  149.       if (OK)
  150.       {
  151.         AdrPart = 0x20;
  152.         AdrCnt = 1;
  153.         if (!mFirstPassUnknown(Flags) && IsWord && Odd(AdrVal))
  154.           WrError(ErrNum_AddrNotAligned);
  155.         return True;
  156.       }
  157.     }
  158.     else
  159.     {
  160.       tStrComp Disp, Reg;
  161.  
  162.       StrCompSplitRef(&Disp, &Reg, &IArg, p);
  163.       StrCompShorten(&Reg, 1);
  164.       if (DecodeReg(&Reg, &AdrPart))
  165.       {
  166.         if (AdrPart == 0) WrStrErrorPos(ErrNum_InvReg, &Reg);
  167.         else
  168.         {
  169.           AdrVal = EvalStrIntExpression(&Disp, Int16, &OK);
  170.           if (OK)
  171.           {
  172.             AdrPart += 0x20;
  173.             AdrCnt = 1;
  174.             return True;
  175.           }
  176.         }
  177.       }
  178.     }
  179.     return False;
  180.   }
  181.  
  182.   if (DecodeReg(pArg, &AdrPart))
  183.     return True;
  184.   else
  185.   {
  186.     WrError(ErrNum_InvAddrMode);
  187.     return False;
  188.   }
  189. }
  190.  
  191. static Boolean DecodeBitField(tStrComp *pArg, Word *pResult)
  192. {
  193.   tStrComp Arg, Start, Count;
  194.   Boolean OK1, OK2;
  195.   char *pSep;
  196.  
  197.   if (!IsIndirect(pArg->str.p_str))
  198.   {
  199.     WrStrErrorPos(ErrNum_InvBitField, pArg);
  200.     return False;
  201.   }
  202.   StrCompRefRight(&Arg, pArg, 1);
  203.   StrCompShorten(&Arg, 1);
  204.   pSep = strchr(Arg.str.p_str, ',');
  205.   if (!pSep)
  206.   {
  207.     WrStrErrorPos(ErrNum_InvBitField, pArg);
  208.     return False;
  209.   }
  210.   StrCompSplitRef(&Start, &Count, &Arg, pSep);
  211.   *pResult = EvalStrIntExpression(&Count, UInt4, &OK1)
  212.            | (EvalStrIntExpression(&Start, UInt4, &OK2) << 12);
  213.   return OK1 && OK2;
  214. }
  215.  
  216. static void PutByte(Byte Value)
  217. {
  218.   if ((CodeLen & 1) && !HostBigEndian)
  219.   {
  220.     BAsmCode[CodeLen] = BAsmCode[CodeLen - 1];
  221.     BAsmCode[CodeLen - 1] = Value;
  222.   }
  223.   else
  224.   {
  225.     BAsmCode[CodeLen] = Value;
  226.   }
  227.   CodeLen++;
  228. }
  229.  
  230. static Boolean EvalDist(const tStrComp *pArg, Word *pResult, Word InstrLen)
  231. {
  232.   Boolean OK;
  233.   Integer AdrInt;
  234.   tSymbolFlags Flags;
  235.  
  236.   AdrInt = EvalStrIntExpressionOffsWithFlags(pArg, !!(*pArg->str.p_str == '@'), UInt16, &OK, &Flags) - (EProgCounter() + InstrLen);
  237.   if (OK && !mSymbolQuestionable(Flags) && Odd(AdrInt))
  238.   {
  239.     WrStrErrorPos(ErrNum_DistIsOdd, pArg);
  240.     OK = False;
  241.   }
  242.   if (OK && !mSymbolQuestionable(Flags) && ((AdrInt < -256) || (AdrInt > 254)))
  243.   {
  244.     WrStrErrorPos(ErrNum_JmpDistTooBig, pArg);
  245.     OK = False;
  246.   }
  247.   if (OK)
  248.     *pResult = (AdrInt / 2) & 0xff;
  249.   return OK;
  250. }
  251.  
  252. static Boolean DecodeCond(const tStrComp *pArg, Word *pResult)
  253. {
  254.   const char *pConds[] =
  255.     { "EQ", "NE", "HE", "L", "GE", "LT", "LE", "H", "LTE", "GT", NULL },
  256.   **pRun;
  257.  
  258.   for (pRun = pConds; *pRun; pRun++)
  259.     if (!as_strcasecmp(pArg->str.p_str, *pRun))
  260.     {
  261.       *pResult = pRun - pConds;
  262.       return True;
  263.     }
  264.   WrStrErrorPos(ErrNum_UndefCond, pArg);
  265.   return False;
  266. }
  267.  
  268. /*-------------------------------------------------------------------------*/
  269. /* Code Generators */
  270.  
  271. static void CheckSupMode(void)
  272. {
  273.   if (!SupAllowed && (pCurrCPUProps->CoreFlags & eCoreFlagSupMode))
  274.     WrError(ErrNum_PrivOrder);
  275. }
  276.  
  277. static Boolean CheckCore(Byte CoreReqFlags)
  278. {
  279.   if (!(CoreReqFlags & pCurrCPUProps->CoreFlags))
  280.   {
  281.     WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  282.     return False;
  283.   }
  284.   else
  285.     return True;
  286. }
  287.  
  288. static Boolean CheckNotMode3(const tStrComp *pArg)
  289. {
  290.   if ((AdrPart & 0x30) == 0x30)
  291.   {
  292.     WrStrErrorPos(ErrNum_InvAddrMode, pArg);
  293.     return False;
  294.   }
  295.   else
  296.     return True;
  297. }
  298.  
  299. static void DecodeTwo(Word Code)
  300. {
  301.   Word HPart;
  302.  
  303.   if (ChkArgCnt(2, 2)
  304.    && DecodeAdr(&ArgStr[1]))
  305.   {
  306.     WAsmCode[0] = AdrPart;
  307.     WAsmCode[1] = AdrVal;
  308.     HPart = AdrCnt;
  309.     if (DecodeAdr(&ArgStr[2]))
  310.     {
  311.       WAsmCode[0] += AdrPart << 6;
  312.       WAsmCode[1 + HPart] = AdrVal;
  313.       CodeLen = (1 + HPart + AdrCnt) << 1;
  314.       WAsmCode[0] += Code;
  315.     }
  316.   }
  317. }
  318.  
  319. static void DecodeType11(Word Index)
  320. {
  321.   const tOrder *pOrder = &Type11Orders[Index];
  322.   Word AdrCnt1;
  323.  
  324.   if (ChkArgCnt(2, (pCurrCPUProps->CoreFlags & eCore990_12) ? 3 : 2)
  325.    && CheckCore(pOrder->Flags & eCoreAll)
  326.    && DecodeAdr(&ArgStr[1]))
  327.   {
  328.     Word Count;
  329.     Boolean OK;
  330.  
  331.     if (ArgCnt == 3)
  332.       Count = EvalStrIntExpression(&ArgStr[3], UInt4, &OK);
  333.     else
  334.     {
  335.       Count = 4;
  336.       OK = True;
  337.     }
  338.     if (OK)
  339.     {
  340.       WAsmCode[0] = pOrder->Code;
  341.       WAsmCode[1] = (Count << 12) | AdrPart;
  342.       WAsmCode[2] = AdrVal;
  343.       AdrCnt1 = AdrCnt;
  344.       if (DecodeAdr(&ArgStr[2]))
  345.       {
  346.         WAsmCode[1] |= AdrPart << 6;
  347.         WAsmCode[2 + AdrCnt1] = AdrVal;
  348.         CodeLen = (2 + AdrCnt1 + AdrCnt) << 1;
  349.       }
  350.     }
  351.   }
  352. }
  353.  
  354. static void DecodeType11a(Word Index)
  355. {
  356.   const tOrder *pOrder = &Type11aOrders[Index];
  357.   Word AdrCnt1;
  358.  
  359.   if (ChkArgCnt(2, 2)
  360.    && CheckCore(pOrder->Flags & eCoreAll)
  361.    && DecodeAdr(&ArgStr[1]))
  362.   {
  363.     WAsmCode[0] = pOrder->Code;
  364.     WAsmCode[1] = AdrPart;
  365.     WAsmCode[2] = AdrVal;
  366.     AdrCnt1 = AdrCnt;
  367.     if (DecodeAdr(&ArgStr[2]))
  368.     {
  369.       WAsmCode[1] |= AdrPart << 6;
  370.       WAsmCode[2 + AdrCnt1] = AdrVal;
  371.       CodeLen = (2 + AdrCnt1 + AdrCnt) << 1;
  372.     }
  373.   }
  374. }
  375.  
  376. static void DecodeType12(Word Index)
  377. {
  378.   const tOrder *pOrder = &Type12Orders[Index];
  379.   Word AdrCnt1, Count, Ckpt;
  380.   Boolean OK;
  381.  
  382.   if (!ChkArgCnt(2, 4)
  383.    || !CheckCore(pOrder->Flags & eCoreAll)
  384.    || !DecodeAdr(&ArgStr[1]))
  385.     return;
  386.   WAsmCode[0] = pOrder->Code;
  387.   WAsmCode[1] =  AdrPart;
  388.   WAsmCode[2] = AdrVal;
  389.   AdrCnt1 = AdrCnt;
  390.  
  391.   if (!DecodeAdr(&ArgStr[2]))
  392.     return;
  393.   WAsmCode[1] |= AdrPart << 6;
  394.   WAsmCode[2 + AdrCnt1] = AdrVal;
  395.  
  396.   if ((ArgCnt < 3) || !*ArgStr[3].str.p_str)
  397.   {
  398.     Count = 0;
  399.     OK = True;
  400.   }
  401.   else
  402.     Count = EvalStrIntExpression(&ArgStr[3], UInt4, &OK);
  403.   if (!OK)
  404.     return;
  405.   WAsmCode[1] |= Count << 12;
  406.  
  407.   if ((ArgCnt < 4) || !*ArgStr[4].str.p_str)
  408.   {
  409.     if (DefCkpt >= 16)
  410.     {
  411.       WrError(ErrNum_NoDefCkptReg);
  412.       OK = False;
  413.     }
  414.     else
  415.     {
  416.       Ckpt = DefCkpt;
  417.       OK = True;
  418.     }
  419.   }
  420.   else
  421.     OK = DecodeReg(&ArgStr[4], &Ckpt);
  422.   if (!OK)
  423.     return;
  424.   WAsmCode[0] |= Ckpt;
  425.   CodeLen = (2 + AdrCnt1 + AdrCnt) << 1;
  426. }
  427.  
  428. static void DecodeOne(Word Code)
  429. {
  430.   if (ChkArgCnt(2, 2)
  431.    && DecodeAdr(&ArgStr[1]))
  432.   {
  433.     Word HPart;
  434.  
  435.     WAsmCode[0] = AdrPart;
  436.     WAsmCode[1] = AdrVal;
  437.     if (DecodeReg(&ArgStr[2], &HPart))
  438.     {
  439.       WAsmCode[0] += (HPart << 6) + (Code << 10);
  440.       CodeLen = (1 + AdrCnt) << 1;
  441.     }
  442.   }
  443. }
  444.  
  445. static void DecodeType15(Word Index)
  446. {
  447.   const tOrder *pOrder = &Type15Orders[Index];
  448.   Word BitField;
  449.  
  450.   if (ChkArgCnt(2, 2)
  451.    && CheckCore(pOrder->Flags & eCoreAll)
  452.    && DecodeAdr(&ArgStr[1])
  453.    && DecodeBitField(&ArgStr[2], &BitField))
  454.   {
  455.     WAsmCode[0] = pOrder->Code | (BitField & 0x000f);
  456.     WAsmCode[1] = (BitField & 0xf000) | AdrPart;
  457.     WAsmCode[2] = AdrVal;
  458.     CodeLen = (2 + AdrCnt) << 1;
  459.   }
  460. }
  461.  
  462. static void DecodeType16(Word Index)
  463. {
  464.   const tOrder *pOrder = &Type16Orders[Index];
  465.   Word BitField;
  466.  
  467.   if (ChkArgCnt(3, 3)
  468.    && CheckCore(pOrder->Flags & eCoreAll)
  469.    && DecodeAdr(&ArgStr[1])
  470.    && DecodeBitField(&ArgStr[3], &BitField))
  471.   {
  472.     Word AdrCnt1 = AdrCnt;
  473.  
  474.     WAsmCode[0] = pOrder->Code | (BitField & 0x000f);
  475.     WAsmCode[1] = (BitField & 0xf000) | AdrPart;
  476.     WAsmCode[2] = AdrVal;
  477.     if (DecodeAdr(&ArgStr[2]))
  478.     {
  479.       WAsmCode[1] |= (AdrPart << 6);
  480.       WAsmCode[2 + AdrCnt1] = AdrVal;
  481.       CodeLen = (2 + AdrCnt + AdrCnt1) << 1;
  482.     }
  483.   }
  484. }
  485.  
  486. static void DecodeMOVA(Word Code)
  487. {
  488.   if (ChkArgCnt(2, 2)
  489.    && CheckCore(eCore990_12)
  490.    && DecodeAdr(&ArgStr[1]))
  491.   {
  492.     Word AdrCnt1 = AdrCnt;
  493.  
  494.     WAsmCode[0] = Code;
  495.     WAsmCode[1] = AdrPart;
  496.     WAsmCode[2] = AdrVal;
  497.     if (DecodeAdr(&ArgStr[2]))
  498.     {
  499.       WAsmCode[1] |= (AdrPart << 6);
  500.       WAsmCode[2 + AdrCnt1] = AdrVal;
  501.       CodeLen = (2 + AdrCnt + AdrCnt1) << 1;
  502.     }
  503.   }
  504. }
  505.  
  506. static void DecodeType20(Word Index)
  507. {
  508.   const tOrder *pOrder = &Type20Orders[Index];
  509.   Word Condition;
  510.  
  511.   if (ChkArgCnt(3, 3)
  512.    && CheckCore(pOrder->Flags & eCoreAll)
  513.    && DecodeCond(&ArgStr[1], &Condition)
  514.    && DecodeAdr(&ArgStr[2]))
  515.   {
  516.     Word AdrCnt1 = AdrCnt;
  517.  
  518.     WAsmCode[0] = pOrder->Code;
  519.     WAsmCode[1] = AdrPart | (Condition << 12);
  520.     WAsmCode[2] = AdrVal;
  521.     if (DecodeAdr(&ArgStr[3]))
  522.     {
  523.       WAsmCode[1] |= (AdrPart << 6);
  524.       WAsmCode[2 + AdrCnt1] = AdrVal;
  525.       CodeLen = (2 + AdrCnt + AdrCnt1) << 1;
  526.     }
  527.   }
  528. }
  529.  
  530. static void DecodeType17(Word Index)
  531. {
  532.   const tOrder *pOrder = &Type17Orders[Index];
  533.   Word Reg;
  534.  
  535.   if (ChkArgCnt(2, 3)
  536.    && DecodeReg(&ArgStr[ArgCnt], &Reg))
  537.   {
  538.     Word Delta, Dist;
  539.     Boolean OK;
  540.  
  541.     if ((ArgCnt == 3) && *ArgStr[2].str.p_str)
  542.       Delta = EvalStrIntExpression(&ArgStr[2], UInt4, &OK);
  543.     else
  544.     {
  545.       Delta = 1;
  546.       OK = True;
  547.     }
  548.     if (OK && EvalDist(&ArgStr[1], &Dist, 4))
  549.     {
  550.       WAsmCode[0] = pOrder->Code;
  551.       WAsmCode[1] = (Dist & 0xff) | (Reg << 8) | (Delta << 12);
  552.       CodeLen = 4;
  553.     }
  554.   }
  555. }
  556.  
  557. static void DecodeEP(Word Code)
  558. {
  559.   if (ChkArgCnt(4, 4)
  560.    && CheckCore(eCore990_12)
  561.    && DecodeAdr(&ArgStr[1]))
  562.   {
  563.     Word AdrCnt1 = AdrCnt, SrcCount, DestCount;
  564.     Boolean DestOK, SrcOK;
  565.  
  566.     WAsmCode[0] = Code;
  567.     WAsmCode[1] = AdrPart;
  568.     WAsmCode[2] = AdrVal;
  569.  
  570.     SrcCount = EvalStrIntExpression(&ArgStr[3], UInt4, &SrcOK);
  571.     DestCount = EvalStrIntExpression(&ArgStr[4], UInt4, &DestOK);
  572.  
  573.     if (SrcOK && DestOK && DecodeAdr(&ArgStr[2]))
  574.     {
  575.       WAsmCode[0] |= DestCount;
  576.       WAsmCode[1] |= (AdrPart << 6) | (SrcCount << 12);
  577.       WAsmCode[2 + AdrCnt1] = AdrVal;
  578.       CodeLen = (2 + AdrCnt + AdrCnt1) << 1;
  579.     }
  580.   }
  581. }
  582.  
  583. static void DecodeLDCR_STCR(Word Code)
  584. {
  585.   if (ChkArgCnt(2, 2)
  586.    && DecodeAdr(&ArgStr[1]))
  587.   {
  588.     Word HPart;
  589.     Boolean OK;
  590.     tSymbolFlags Flags;
  591.  
  592.     WAsmCode[0] = Code + AdrPart;
  593.     WAsmCode[1] = AdrVal;
  594.     HPart = EvalStrIntExpressionWithFlags(&ArgStr[2], UInt5, &OK, &Flags);
  595.     if (mFirstPassUnknown(Flags))
  596.       HPart = 1;
  597.     if (OK)
  598.     {
  599.       if (ChkRange(HPart, 1, 16))
  600.       {
  601.         WAsmCode[0] += (HPart & 15) << 6;
  602.         CodeLen = (1 + AdrCnt) << 1;
  603.       }
  604.     }
  605.   }
  606.   return;
  607. }
  608.  
  609. static void DecodeShift(Word Code)
  610. {
  611.   if (ChkArgCnt(2, 2)
  612.    && DecodeReg(&ArgStr[1], WAsmCode + 0))
  613.   {
  614.     Word HPart;
  615.  
  616.     if (DecodeReg(&ArgStr[2], &HPart))
  617.     {
  618.       WAsmCode[0] += (HPart << 4) + (Code << 8);
  619.       CodeLen = 2;
  620.     }
  621.   }
  622. }
  623.  
  624. static void DecodeSLAM_SRAM(Word Code)
  625. {
  626.   Word HPart;
  627.  
  628.   if (ChkArgCnt(2, 2)
  629.    && CheckCore(eCore990_12 | eCore99105 | eCore99110)
  630.    && DecodeReg(&ArgStr[2], &HPart)
  631.    && DecodeAdr(&ArgStr[1]))
  632.   {
  633.     WAsmCode[0] = Code;
  634.     WAsmCode[1] = 0x4000 | (HPart << 6) | AdrPart;
  635.     WAsmCode[2] = AdrVal;
  636.     CodeLen = (2 + AdrCnt) << 1;
  637.   }
  638. }
  639.  
  640. static void DecodeImm(Word Index)
  641. {
  642.   const tOrder *pOrder = &ImmOrders[Index];
  643.  
  644.   if (ChkArgCnt(2, 2)
  645.    && CheckCore(pOrder->Flags & eCoreAll)
  646.    && DecodeReg(&ArgStr[1], WAsmCode + 0))
  647.   {
  648.     Boolean OK;
  649.  
  650.     WAsmCode[1] = EvalStrIntExpression(&ArgStr[2], Int16, &OK);
  651.     if (OK)
  652.     {
  653.       WAsmCode[0] |= pOrder->Code;
  654.       CodeLen = 4;
  655.     }
  656.   }
  657. }
  658.  
  659. static void DecodeLIIM(Word Code)
  660. {
  661.   if (ChkArgCnt(1, 1)
  662.    && CheckCore(eCore9940))
  663.   {
  664.     Boolean OK;
  665.  
  666.     WAsmCode[0] = EvalStrIntExpression(&ArgStr[1], UInt2, &OK);
  667.     if (OK)
  668.     {
  669.       WAsmCode[0] |= Code;
  670.       CodeLen = 2;
  671.     }
  672.   }
  673. }
  674.  
  675. static void DecodeRegOrder(Word Index)
  676. {
  677.   const tOrder *pOrder = &RegOrders[Index];
  678.  
  679.   if (ChkArgCnt(1, 1)
  680.    && CheckCore(pOrder->Flags & eCoreAll)
  681.    && DecodeReg(&ArgStr[1], WAsmCode + 0))
  682.   {
  683.     WAsmCode[0] |= pOrder->Code;
  684.     CodeLen = 2;
  685.   }
  686. }
  687.  
  688. static void DecodeLMF(Word Code)
  689. {
  690.   UNUSED(Code);
  691.  
  692.   if (ChkArgCnt(2, 2)
  693.    && CheckCore(eCore990_10 | eCore990_12 | eCore99105 | eCore99110)
  694.    && DecodeReg(&ArgStr[1], WAsmCode + 0))
  695.   {
  696.     Boolean OK;
  697.  
  698.     WAsmCode[0] += 0x320 + (EvalStrIntExpression(&ArgStr[2], UInt1, &OK) << 4);
  699.     if (OK)
  700.       CodeLen = 2;
  701.     CheckSupMode();
  702.   }
  703. }
  704.  
  705. static void DecodeMPYS_DIVS(Word Code)
  706. {
  707.   if (ChkArgCnt(1, 1)
  708.    && CheckCore(eCore990_12 | eCore9995 | eCore99105 | eCore99110)
  709.    && DecodeAdr(&ArgStr[1]))
  710.   {
  711.     WAsmCode[0] = Code + AdrPart;
  712.     WAsmCode[1] = AdrVal;
  713.     CodeLen = (1 + AdrCnt) << 1;
  714.   }
  715. }
  716.  
  717. static void DecodeSBit(Word Code)
  718. {
  719.   if (ChkArgCnt(1, 1))
  720.   {
  721.     Boolean OK;
  722.  
  723.     WAsmCode[0] = EvalStrIntExpression(&ArgStr[1], SInt8, &OK);
  724.     if (OK)
  725.     {
  726.       WAsmCode[0] = (WAsmCode[0] & 0xff) | Code;
  727.       CodeLen = 2;
  728.     }
  729.   }
  730. }
  731.  
  732. static void DecodeBit(Word Code)
  733. {
  734.   if (ChkArgCnt(2, 2)
  735.    && CheckCore(eCore990_12 | eCore99105 | eCore99110)
  736.    && DecodeAdr(&ArgStr[1])
  737.    && CheckNotMode3(&ArgStr[1]))
  738.   {
  739.     Boolean OK;
  740.  
  741.     WAsmCode[1] = (EvalStrIntExpression(&ArgStr[2], UInt4, &OK) << 6) | AdrPart;
  742.     if (OK)
  743.     {
  744.       WAsmCode[0] = Code;
  745.       WAsmCode[2] = AdrVal;
  746.       CodeLen = (2 + AdrCnt) << 1;
  747.     }
  748.   }
  749. }
  750.  
  751. static void DecodeJmp(Word Code)
  752. {
  753.   Word Dist;
  754.  
  755.   if (ChkArgCnt(1, 1)
  756.    && EvalDist(&ArgStr[1], &Dist, 2))
  757.   {
  758.     WAsmCode[0] = Code | Dist;
  759.     CodeLen = 2;
  760.   }
  761. }
  762.  
  763. static void DecodeLWPI_LIMI(Word Code)
  764. {
  765.   if (ChkArgCnt(1, 1))
  766.   {
  767.     Boolean OK;
  768.  
  769.     WAsmCode[1] = EvalStrIntExpression(&ArgStr[1], UInt16, &OK);
  770.     if (OK)
  771.     {
  772.       WAsmCode[0] = Code & 0x7fff;
  773.       CodeLen = 4;
  774.       if (Code & 0x8000)
  775.         CheckSupMode();
  776.     }
  777.   }
  778. }
  779.  
  780. static void DecodeSing(Word Index)
  781. {
  782.   const tOrder *pOrder = &SingOrders[Index];
  783.  
  784.   if (ChkArgCnt(1, 1)
  785.    && CheckCore(pOrder->Flags & eCoreAll)
  786.    && DecodeAdr(&ArgStr[1]))
  787.   {
  788.     WAsmCode[0] = pOrder->Code | AdrPart;
  789.     WAsmCode[1] = AdrVal;
  790.     CodeLen = (1 + AdrCnt) << 1;
  791.     if (pOrder->Flags & eCoreFlagSupMode)
  792.       CheckSupMode();
  793.   }
  794. }
  795.  
  796. static void DecodeFixed(Word Index)
  797. {
  798.   const tOrder *pOrder = &FixedOrders[Index];
  799.  
  800.   if (ChkArgCnt(0, 0)
  801.    && CheckCore(pOrder->Flags & eCoreAll))
  802.   {
  803.     WAsmCode[0] = pOrder->Code;
  804.     CodeLen = 2;
  805.     if (pOrder->Flags & eCoreFlagSupMode)
  806.       CheckSupMode();
  807.   }
  808. }
  809.  
  810. static void DecodeRTWP(Word Code)
  811. {
  812.   Word Variant;
  813.   Word MaxVariant = (((pCurrCPUProps->CoreFlags & eCoreAll) == eCore99105)
  814.                   || ((pCurrCPUProps->CoreFlags & eCoreAll) == eCore99110)) ? 4 : 0;
  815.   tEvalResult EvalResult;
  816.  
  817.   switch (ArgCnt)
  818.   {
  819.     case 0:
  820.       Variant = 0;
  821.       EvalResult.OK = True;
  822.       break;
  823.     case 1:
  824.       Variant = EvalStrIntExpressionWithResult(&ArgStr[1], UInt3, &EvalResult);
  825.       if (!EvalResult.OK)
  826.         return;
  827.       if (mFirstPassUnknown(EvalResult.Flags))
  828.         Variant = 0;
  829.       else if (Variant > MaxVariant)
  830.       {
  831.         WrStrErrorPos(ErrNum_OverRange, &ArgStr[1]);
  832.         return;
  833.       }
  834.       else if (Variant == 3)
  835.       {
  836.         WrStrErrorPos(ErrNum_InvArg, &ArgStr[1]);
  837.         return;
  838.       }
  839.       break;
  840.     default:
  841.       (void)ChkArgCnt(0,1);
  842.       return;
  843.   }
  844.   if (EvalResult.OK)
  845.   {
  846.     WAsmCode[CodeLen >> 1] = Code + Variant;
  847.     CodeLen += 2;
  848.   }
  849. }
  850.  
  851. static void DecodeBYTE(Word Code)
  852. {
  853.   TempResult t;
  854.  
  855.   UNUSED(Code);
  856.  
  857.   as_tempres_ini(&t);
  858.   if (ChkArgCnt(1, ArgCntMax))
  859.   {
  860.     Boolean OK = True;
  861.     tStrComp *pArg;
  862.  
  863.     forallargs(pArg, OK)
  864.     {
  865.       KillBlanks(pArg->str.p_str);
  866.       EvalStrExpression(pArg, &t);
  867.       switch (t.Typ)
  868.       {
  869.         case TempInt:
  870.           if (mFirstPassUnknown(t.Flags))
  871.             t.Contents.Int &= 0xff;
  872.           if (!RangeCheck(t.Contents.Int, Int8)) WrStrErrorPos(ErrNum_OverRange, pArg);
  873.           else if (SetMaxCodeLen(CodeLen + 1))
  874.           {
  875.             WrStrErrorPos(ErrNum_CodeOverflow, pArg);
  876.             OK = False;
  877.           }
  878.           else
  879.             PutByte(t.Contents.Int);
  880.           break;
  881.         case TempString:
  882.           if (SetMaxCodeLen(t.Contents.str.len + CodeLen))
  883.           {
  884.             WrStrErrorPos(ErrNum_CodeOverflow, pArg);
  885.             OK = False;
  886.           }
  887.           else
  888.           {
  889.             char *p, *pEnd;
  890.  
  891.             if (as_chartrans_xlate_nonz_dynstr(CurrTransTable->p_table, &t.Contents.str, pArg))
  892.               OK = False;
  893.             else
  894.             {
  895.               pEnd = t.Contents.str.p_str + t.Contents.str.len;
  896.               for (p = t.Contents.str.p_str; p < pEnd; PutByte(*(p++)));
  897.             }
  898.           }
  899.           break;
  900.         case TempFloat:
  901.           WrStrErrorPos(ErrNum_StringOrIntButFloat, pArg);
  902.           /* fall-through */
  903.         default:
  904.           OK = False;
  905.       }
  906.     }
  907.     if (!OK)
  908.       CodeLen = 0;
  909.   }
  910.   as_tempres_free(&t);
  911. }
  912.  
  913. static void DecodeWORD(Word Code)
  914. {
  915.   int z;
  916.   Boolean OK;
  917.   Word HVal16;
  918.  
  919.   UNUSED(Code);
  920.  
  921.   if (ChkArgCnt(1, ArgCntMax))
  922.   {
  923.     z = 1;
  924.     OK = True;
  925.     do
  926.     {
  927.       HVal16 = EvalStrIntExpression(&ArgStr[z], Int16, &OK);
  928.       if (OK)
  929.       {
  930.         WAsmCode[CodeLen >> 1] = HVal16;
  931.         CodeLen += 2;
  932.       }
  933.       z++;
  934.     }
  935.     while ((z <= ArgCnt) && (OK));
  936.     if (!OK)
  937.       CodeLen = 0;
  938.   }
  939. }
  940.  
  941. static void DecodeFLOAT(Word DestLen)
  942. {
  943.   int z;
  944.   Boolean OK;
  945.   double FVal;
  946.  
  947.   if (ChkArgCnt(1, ArgCntMax))
  948.   {
  949.     z = 1;
  950.     OK = True;
  951.     do
  952.     {
  953.       FVal = EvalStrFloatExpression(&ArgStr[z], Float64, &OK);
  954.       if (OK)
  955.       {
  956.         SetMaxCodeLen(CodeLen + DestLen);
  957.         if (Double2IBMFloat(&WAsmCode[CodeLen >> 1], FVal, DestLen == 8))
  958.           CodeLen += DestLen;
  959.       }
  960.       z++;
  961.     }
  962.     while ((z <= ArgCnt) && (OK));
  963.     if (!OK)
  964.       CodeLen = 0;
  965.   }
  966. }
  967.  
  968. static void DecodeBSS(Word Code)
  969. {
  970.   Boolean OK;
  971.   Word HVal16;
  972.   tSymbolFlags Flags;
  973.  
  974.   UNUSED(Code);
  975.  
  976.   if (ChkArgCnt(1, 1))
  977.   {
  978.     HVal16 = EvalStrIntExpressionWithFlags(&ArgStr[1], Int16, &OK, &Flags);
  979.     if (mFirstPassUnknown(Flags)) WrError(ErrNum_FirstPassCalc);
  980.     else if (OK)
  981.     {
  982.       if (!HVal16) WrError(ErrNum_NullResMem);
  983.       DontPrint = True;
  984.       CodeLen = HVal16;
  985.       BookKeeping();
  986.     }
  987.   }
  988. }
  989.  
  990. static void DecodeCKPT(Word Code)
  991. {
  992.   UNUSED(Code);
  993.  
  994.   if (ChkArgCnt(1, 1)
  995.    && CheckCore(eCore990_12))
  996.   {
  997.     Word NewDefCkpt;
  998.  
  999.     if (!as_strcasecmp(ArgStr[1].str.p_str, "NOTHING"))
  1000.       DefCkpt = CKPT_NOTHING;
  1001.     else
  1002.       if (DecodeReg(&ArgStr[1], &NewDefCkpt))
  1003.         DefCkpt = NewDefCkpt;
  1004.   }
  1005. }
  1006.  
  1007. /*-------------------------------------------------------------------------*/
  1008. /* dynamische Belegung/Freigabe Codetabellen */
  1009.  
  1010. static void AddTwo(const char *NName16, const char *NName8, Word NCode)
  1011. {
  1012.   AddInstTable(InstTable, NName16, (NCode << 13)         , DecodeTwo);
  1013.   AddInstTable(InstTable, NName8,  (NCode << 13) + 0x1000, DecodeTwo);
  1014. }
  1015.  
  1016. static void AddOne(const char *NName, Word NCode)
  1017. {
  1018.   AddInstTable(InstTable, NName, NCode, DecodeOne);
  1019. }
  1020.  
  1021. static void AddSing(const char *NName, Word NCode, Byte Flags)
  1022. {
  1023.   order_array_rsv_end(SingOrders, tOrder);
  1024.   SingOrders[InstrZ].Code = NCode;
  1025.   SingOrders[InstrZ].Flags = Flags;
  1026.   AddInstTable(InstTable, NName, InstrZ++, DecodeSing);
  1027. }
  1028.  
  1029. static void AddSBit(const char *NName, Word NCode)
  1030. {
  1031.   AddInstTable(InstTable, NName, NCode << 8, DecodeSBit);
  1032. }
  1033.  
  1034. static void AddBit(const char *NName, Word NCode)
  1035. {
  1036.   AddInstTable(InstTable, NName, NCode, DecodeBit);
  1037. }
  1038.  
  1039. static void AddJmp(const char *NName, Word NCode)
  1040. {
  1041.   AddInstTable(InstTable, NName, NCode << 8, DecodeJmp);
  1042. }
  1043.  
  1044. static void AddShift(const char *NName, Word NCode)
  1045. {
  1046.   AddInstTable(InstTable, NName, NCode, DecodeShift);
  1047. }
  1048.  
  1049. static void AddImm(const char *NName, Word NCode, Word Flags)
  1050. {
  1051.   order_array_rsv_end(ImmOrders, tOrder);
  1052.   ImmOrders[InstrZ].Code = NCode << 4;
  1053.   ImmOrders[InstrZ].Flags = Flags;
  1054.   AddInstTable(InstTable, NName, InstrZ++, DecodeImm);
  1055. }
  1056.  
  1057. static void AddReg(const char *NName, Word NCode, Word Flags)
  1058. {
  1059.   order_array_rsv_end(RegOrders, tOrder);
  1060.   RegOrders[InstrZ].Code = NCode << 4;
  1061.   RegOrders[InstrZ].Flags = Flags;
  1062.   AddInstTable(InstTable, NName, InstrZ++, DecodeRegOrder);
  1063. }
  1064.  
  1065. static void AddFixed(const char *NName, Word NCode, Word Flags)
  1066. {
  1067.   order_array_rsv_end(FixedOrders, tOrder);
  1068.   FixedOrders[InstrZ].Code = NCode;
  1069.   FixedOrders[InstrZ].Flags = Flags;
  1070.   AddInstTable(InstTable, NName, InstrZ++, DecodeFixed);
  1071. }
  1072.  
  1073. static void AddType11(const char *NName, Word NCode, Word Flags)
  1074. {
  1075.   order_array_rsv_end(Type11Orders, tOrder);
  1076.   Type11Orders[InstrZ].Code = NCode;
  1077.   Type11Orders[InstrZ].Flags = Flags;
  1078.   AddInstTable(InstTable, NName, InstrZ++, DecodeType11);
  1079. }
  1080.  
  1081. static void AddType11a(const char *NName, Word NCode, Word Flags)
  1082. {
  1083.   order_array_rsv_end(Type11aOrders, tOrder);
  1084.   Type11aOrders[InstrZ].Code = NCode;
  1085.   Type11aOrders[InstrZ].Flags = Flags;
  1086.   AddInstTable(InstTable, NName, InstrZ++, DecodeType11a);
  1087. }
  1088.  
  1089. static void AddType12(const char *NName, Word NCode, Word Flags)
  1090. {
  1091.   order_array_rsv_end(Type12Orders, tOrder);
  1092.   Type12Orders[InstrZ].Code = NCode;
  1093.   Type12Orders[InstrZ].Flags = Flags;
  1094.   AddInstTable(InstTable, NName, InstrZ++, DecodeType12);
  1095. }
  1096.  
  1097. static void AddType15(const char *NName, Word NCode, Word Flags)
  1098. {
  1099.   order_array_rsv_end(Type15Orders, tOrder);
  1100.   Type15Orders[InstrZ].Code = NCode;
  1101.   Type15Orders[InstrZ].Flags = Flags;
  1102.   AddInstTable(InstTable, NName, InstrZ++, DecodeType15);
  1103. }
  1104.  
  1105. static void AddType16(const char *NName, Word NCode, Word Flags)
  1106. {
  1107.   order_array_rsv_end(Type16Orders, tOrder);
  1108.   Type16Orders[InstrZ].Code = NCode;
  1109.   Type16Orders[InstrZ].Flags = Flags;
  1110.   AddInstTable(InstTable, NName, InstrZ++, DecodeType16);
  1111. }
  1112.  
  1113. static void AddType17(const char *NName, Word NCode, Word Flags)
  1114. {
  1115.   order_array_rsv_end(Type17Orders, tOrder);
  1116.   Type17Orders[InstrZ].Code = NCode;
  1117.   Type17Orders[InstrZ].Flags = Flags;
  1118.   AddInstTable(InstTable, NName, InstrZ++, DecodeType17);
  1119. }
  1120.  
  1121. static void AddType20(const char *NName, Word NCode, Word Flags)
  1122. {
  1123.   order_array_rsv_end(Type20Orders, tOrder);
  1124.   Type20Orders[InstrZ].Code = NCode;
  1125.   Type20Orders[InstrZ].Flags = Flags;
  1126.   AddInstTable(InstTable, NName, InstrZ++, DecodeType20);
  1127. }
  1128.  
  1129. static void InitFields(void)
  1130. {
  1131.   InstTable = CreateInstTable(203);
  1132.   AddInstTable(InstTable, "LDCR", 0x3000, DecodeLDCR_STCR);
  1133.   AddInstTable(InstTable, "STCR", 0x3400, DecodeLDCR_STCR);
  1134.   AddInstTable(InstTable, "LMF", 0, DecodeLMF);
  1135.   AddInstTable(InstTable, "MPYS", 0x01c0, DecodeMPYS_DIVS);
  1136.   AddInstTable(InstTable, "DIVS", 0x0180, DecodeMPYS_DIVS);
  1137.   AddInstTable(InstTable, "LWPI", 0x02e0, DecodeLWPI_LIMI);
  1138.   AddInstTable(InstTable, "LIMI", 0x8300, DecodeLWPI_LIMI);
  1139.   AddInstTable(InstTable, "WORD", 0, DecodeWORD);
  1140.   AddInstTable(InstTable, "SINGLE", 4, DecodeFLOAT);
  1141.   AddInstTable(InstTable, "DOUBLE", 8, DecodeFLOAT);
  1142.   AddInstTable(InstTable, "CKPT", 0, DecodeCKPT);
  1143.  
  1144.   AddTwo("A"   , "AB"   , 5); AddTwo("C"   , "CB"   , 4); AddTwo("S"   , "SB"   , 3);
  1145.   AddTwo("SOC" , "SOCB" , 7); AddTwo("SZC" , "SZCB" , 2); AddTwo("MOV" , "MOVB" , 6);
  1146.  
  1147.   AddOne("COC" , 0x08); AddOne("CZC" , 0x09); AddOne("XOR" , 0x0a);
  1148.   AddOne("MPY" , 0x0e); AddOne("DIV" , 0x0f); AddOne("XOP" , 0x0b);
  1149.  
  1150.   InstrZ = 0;
  1151.   AddSing("B"   , 0x0440, eCoreAll);
  1152.   AddSing("BL"  , 0x0680, eCoreAll);
  1153.   AddSing("BLWP", 0x0400, eCoreAll);
  1154.   AddSing("CLR" , 0x04c0, eCoreAll);
  1155.   AddSing("SETO", 0x0700, eCoreAll);
  1156.   AddSing("INV" , 0x0540, eCoreAll);
  1157.   AddSing("NEG" , 0x0500, eCoreAll);
  1158.   AddSing("ABS" , 0x0740, eCoreAll);
  1159.   AddSing("SWPB", 0x06c0, eCoreAll);
  1160.   AddSing("INC" , 0x0580, eCoreAll);
  1161.   AddSing("INCT", 0x05c0, eCoreAll);
  1162.   AddSing("DEC" , 0x0600, eCoreAll);
  1163.   AddSing("DECT", 0x0640, eCoreAll);
  1164.   AddSing("X"   , 0x0480, eCoreAll);
  1165.   AddSing("LDS" , 0x0780, eCoreFlagSupMode | eCore990_10 | eCore990_12 | eCore99110);
  1166.   AddSing("LDD" , 0x07c0, eCoreFlagSupMode | eCore990_10 | eCore990_12 | eCore99110);
  1167.   AddSing("DCA" , 0x2c00, eCore9940);
  1168.   AddSing("DCS" , 0x2c40, eCore9940);
  1169.   AddSing("BIND", 0x0140, eCore990_12 | eCore99105 | eCore99110);
  1170.   AddSing("AR"  , 0x0c40, eCore990_12 | eCore99110);
  1171.   AddSing("SR"  , 0x0cc0, eCore990_12 | eCore99110);
  1172.   AddSing("MR"  , 0x0d00, eCore990_12 | eCore99110);
  1173.   AddSing("DR"  , 0x0d40, eCore990_12 | eCore99110);
  1174.   AddSing("LR"  , 0x0d80, eCore990_12 | eCore99110);
  1175.   AddSing("STR" , 0x0dc0, eCore990_12 | eCore99110);
  1176.   AddSing("CIR" , 0x0c80, eCore990_12 | eCore99110);
  1177.   AddSing("EVAD", 0x0100, eCore99105 | eCore99110);
  1178.   AddSing("AD"  , 0x0e40, eCore990_12);
  1179.   AddSing("CID" , 0x0e80, eCore990_12);
  1180.   AddSing("SD"  , 0x0ec0, eCore990_12);
  1181.   AddSing("MD"  , 0x0f00, eCore990_12);
  1182.   AddSing("DD"  , 0x0f40, eCore990_12);
  1183.   AddSing("LD"  , 0x0f80, eCore990_12);
  1184.   AddSing("STD" , 0x0fc0, eCore990_12);
  1185.  
  1186.   AddSBit("SBO" , 0x1d); AddSBit("SBZ", 0x1e); AddSBit("TB" , 0x1f);
  1187.  
  1188.   AddJmp("JEQ", 0x13); AddJmp("JGT", 0x15); AddJmp("JH" , 0x1b);
  1189.   AddJmp("JHE", 0x14); AddJmp("JL" , 0x1a); AddJmp("JLE", 0x12);
  1190.   AddJmp("JLT", 0x11); AddJmp("JMP", 0x10); AddJmp("JNC", 0x17);
  1191.   AddJmp("JNE", 0x16); AddJmp("JNO", 0x19); AddJmp("JOC", 0x18);
  1192.   AddJmp("JOP", 0x1c);
  1193.  
  1194.   AddShift("SLA", 0x0a); AddShift("SRA", 0x08);
  1195.   AddShift("SRC", 0x0b); AddShift("SRL", 0x09);
  1196.  
  1197.   InstrZ = 0;
  1198.   AddImm("AI"  , 0x022, eCoreAll);
  1199.   AddImm("ANDI", 0x024, eCoreAll);
  1200.   AddImm("CI"  , 0x028, eCoreAll);
  1201.   AddImm("LI"  , 0x020, eCoreAll);
  1202.   AddImm("ORI" , 0x026, eCoreAll);
  1203.   AddImm("BLSK", 0x00b, eCore990_12 | eCore99105 | eCore99110);
  1204.  
  1205.   InstrZ = 0;
  1206.   AddType11("AM"  , 0x002a, eCore990_12 | eCore99105 | eCore99110);
  1207.   AddType11("SM"  , 0x0029, eCore990_12 | eCore99105 | eCore99110);
  1208.   AddType11("NRM" , 0x0c08, eCore990_12);
  1209.   AddType11("RTO" , 0x001e, eCore990_12);
  1210.   AddType11("LTO" , 0x001f, eCore990_12);
  1211.   AddType11("CNTO", 0x0020, eCore990_12);
  1212.   AddType11("BDC" , 0x0023, eCore990_12);
  1213.   AddType11("DBC" , 0x0024, eCore990_12);
  1214.   AddType11("SWPM", 0x0025, eCore990_12);
  1215.   AddType11("XORM", 0x0026, eCore990_12);
  1216.   AddType11("ORM" , 0x0027, eCore990_12);
  1217.   AddType11("ANDM", 0x0028, eCore990_12);
  1218.  
  1219.   InstrZ = 0;
  1220.   AddType11a("CR"  , 0x0301, eCore99110);
  1221.   AddType11a("MM"  , 0x0302, eCore99110);
  1222.  
  1223.   AddInstTable(InstTable, "SLAM", 0x001d, DecodeSLAM_SRAM);
  1224.   AddInstTable(InstTable, "SRAM", 0x001c, DecodeSLAM_SRAM);
  1225.  
  1226.   InstrZ = 0;
  1227.   AddReg("STST", 0x02c, eCoreAll);
  1228.   AddReg("LST" , 0x008, eCore9995 | eCore99105 | eCore99110 | eCore990_12);
  1229.   AddReg("STWP", 0x02a, eCoreAll);
  1230.   AddReg("LWP" , 0x009, eCore9995 | eCore99105 | eCore99110 | eCore990_12);
  1231.   AddReg("STPC", 0x003, eCore990_12);
  1232.   AddReg("LIM" , 0x007, eCore990_12);
  1233.   AddReg("LCS" , 0x00a, eCore990_12);
  1234.  
  1235.   AddBit("TMB" , 0x0c09);
  1236.   AddBit("TCMB", 0x0c0a);
  1237.   AddBit("TSMB", 0x0c0b);
  1238.  
  1239.   InstrZ = 0;
  1240.   AddInstTable(InstTable, "RTWP", 0x0380, DecodeRTWP);
  1241.   AddFixed("IDLE", 0x0340, eCoreFlagSupMode | eCoreAll);
  1242.   AddFixed("RSET", 0x0360, eCoreFlagSupMode | (eCoreAll & ~eCore9940));
  1243.   AddFixed("CKOF", 0x03c0, eCoreFlagSupMode | (eCoreAll & ~eCore9940));
  1244.   AddFixed("CKON", 0x03a0, eCoreFlagSupMode | (eCoreAll & ~eCore9940));
  1245.   AddFixed("LREX", 0x03e0, eCoreFlagSupMode | (eCoreAll & ~eCore9940));
  1246.   AddFixed("CER" , 0x0c06, eCore990_12 | eCore99110);
  1247.   AddFixed("CRE" , 0x0c04, eCore990_12 | eCore99110);
  1248.   AddFixed("NEGR", 0x0c02, eCore990_12 | eCore99110);
  1249.   AddFixed("CRI" , 0x0c00, eCore990_12 | eCore99110);
  1250.   AddFixed("EMD" , 0x002d, eCore990_12);
  1251.   AddFixed("EINT", 0x002e, eCore990_12);
  1252.   AddFixed("DINT", 0x002f, eCore990_12);
  1253.   AddFixed("CDI" , 0x0c01, eCore990_12);
  1254.   AddFixed("NEGD", 0x0c03, eCore990_12);
  1255.   AddFixed("CDE" , 0x0c05, eCore990_12);
  1256.   AddFixed("CED" , 0x0c07, eCore990_12);
  1257.   AddFixed("XIT" , 0x0c0e, eCore990_12);
  1258.  
  1259.   InstrZ = 0;
  1260.   AddType12("SNEB", 0x0e10, eCore990_12);
  1261.   AddType12("CRC" , 0x0e20, eCore990_12);
  1262.   AddType12("TS"  , 0x0e30, eCore990_12);
  1263.   AddType12("CS"  , 0x0040, eCore990_12);
  1264.   AddType12("SEQB", 0x0050, eCore990_12);
  1265.   AddType12("MOVS", 0x0060, eCore990_12);
  1266.   AddType12("MVSR", 0x00c0, eCore990_12);
  1267.   AddType12("MVSK", 0x00d0, eCore990_12);
  1268.   AddType12("POPS", 0x00e0, eCore990_12);
  1269.   AddType12("PSHS", 0x00f0, eCore990_12);
  1270.  
  1271.   InstrZ = 0;
  1272.   AddType15("IOF" , 0x0e00, eCore990_12);
  1273.  
  1274.   InstrZ = 0;
  1275.   AddType16("INSF", 0x0c10, eCore990_12);
  1276.   AddType16("XV"  , 0x0c30, eCore990_12);
  1277.   AddType16("XF"  , 0x0c20, eCore990_12);
  1278.  
  1279.   InstrZ = 0;
  1280.   AddType17("SRJ" , 0x0c0c, eCore990_12);
  1281.   AddType17("ARJ" , 0x0c0d, eCore990_12);
  1282.  
  1283.   AddInstTable(InstTable, "MOVA", 0x002b, DecodeMOVA);
  1284.  
  1285.   InstrZ = 0;
  1286.   AddType20("SLSL", 0x0021, eCore990_12);
  1287.   AddType20("SLSP", 0x0020, eCore990_12);
  1288.  
  1289.   AddInstTable(InstTable, "EP" , 0x03f0, DecodeEP);
  1290.  
  1291.   AddInstTable(InstTable, "LIIM", 0x2c80, DecodeLIIM);
  1292. }
  1293.  
  1294. static void DeinitFields(void)
  1295. {
  1296.   DestroyInstTable(InstTable);
  1297.   order_array_free(SingOrders);
  1298.   order_array_free(ImmOrders);
  1299.   order_array_free(FixedOrders);
  1300.   order_array_free(RegOrders);
  1301.   order_array_free(Type11Orders);
  1302.   order_array_free(Type11aOrders);
  1303.   order_array_free(Type12Orders);
  1304.   order_array_free(Type15Orders);
  1305.   order_array_free(Type16Orders);
  1306.   order_array_free(Type17Orders);
  1307.   order_array_free(Type20Orders);
  1308. }
  1309.  
  1310. /*-------------------------------------------------------------------------*/
  1311.  
  1312. static void MakeCode_9900(void)
  1313. {
  1314.   CodeLen = 0;
  1315.   DontPrint = False;
  1316.   IsWord = False;
  1317.  
  1318.   /* to be ignored */
  1319.  
  1320.   if (Memo("")) return;
  1321.  
  1322.   /* may be aligned arbitrarily */
  1323.  
  1324.   if (Memo("BYTE"))
  1325.   {
  1326.     DecodeBYTE(0);
  1327.     return;
  1328.   }
  1329.   if (Memo("BSS"))
  1330.   {
  1331.     DecodeBSS(0);
  1332.     return;
  1333.   }
  1334.  
  1335.   /* For all other (pseudo) instructions, optionally pad to even */
  1336.  
  1337.   if (Odd(EProgCounter()))
  1338.   {
  1339.     if (DoPadding)
  1340.       InsertPadding(1, False);
  1341.     else
  1342.       WrError(ErrNum_AddrNotAligned);
  1343.   }
  1344.  
  1345.   if (!LookupInstTable(InstTable, OpPart.str.p_str))
  1346.     WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
  1347. }
  1348.  
  1349. static Boolean IsDef_9900(void)
  1350. {
  1351.   return False;
  1352. }
  1353.  
  1354. static void InternSymbol_9900(char *Asc, TempResult*Erg)
  1355. {
  1356.   Boolean OK;
  1357.   char *h = Asc;
  1358.   LargeInt Num;
  1359.  
  1360.   as_tempres_set_none(Erg);
  1361.   if ((strlen(Asc) >= 2) && (as_toupper(*Asc) == 'R'))
  1362.     h = Asc + 1;
  1363.   else if ((strlen(Asc) >= 3) && (as_toupper(*Asc) == 'W') && (as_toupper(Asc[1]) == 'R'))
  1364.     h = Asc + 2;
  1365.  
  1366.   Num = ConstLongInt(h, &OK, 10);
  1367.   if (!OK || (Num < 0) || (Num > 15))
  1368.     return;
  1369.  
  1370.   as_tempres_set_int(Erg, Num);
  1371. }
  1372.  
  1373. static void SwitchTo_9900(void *pUser)
  1374. {
  1375.   TurnWords = True;
  1376.   SetIntConstMode(eIntConstModeIntel);
  1377.  
  1378.   PCSymbol = "$";
  1379.   HeaderID = 0x48;
  1380.   NOPCode = 0x0000;
  1381.   DivideChars = ",";
  1382.   HasAttrs = False;
  1383.  
  1384.   ValidSegs = 1 << SegCode;
  1385.   Grans[SegCode] = 1; ListGrans[SegCode] = 2; SegInits[SegCode] = 0;
  1386.   SegLimits[SegCode] = 0xffff;
  1387.  
  1388.   pCurrCPUProps = (const tCPUProps*)pUser;
  1389.  
  1390.   MakeCode = MakeCode_9900;
  1391.   IsDef = IsDef_9900;
  1392.   SwitchFrom = DeinitFields;
  1393.   InternSymbol = InternSymbol_9900;
  1394.   AddONOFF(DoPaddingName, &DoPadding , DoPaddingName , False);
  1395.   onoff_supmode_add();
  1396.  
  1397.   InitFields();
  1398. }
  1399.  
  1400. static void InitCode_TI990(void)
  1401. {
  1402.   DefCkpt = CKPT_NOTHING; /* CKPT NOTHING */
  1403. }
  1404.  
  1405. static const tCPUProps CPUProps[] =
  1406. {
  1407.   { "TI990/4"  , eCore9900                      },
  1408.   { "TI990/10" , eCore990_10 | eCoreFlagSupMode },
  1409.   { "TI990/12" , eCore990_12 | eCoreFlagSupMode },
  1410.   { "TMS9900"  , eCore9900                      },
  1411.   { "TMS9940"  , eCore9940                      },
  1412.   { "TMS9995"  , eCore9995                      },
  1413.   { "TMS99105" , eCore99105  | eCoreFlagSupMode },
  1414.   { "TMS99110" , eCore99110  | eCoreFlagSupMode },
  1415.   { NULL       , eCoreNone                      },
  1416. };
  1417.  
  1418. void code9900_init(void)
  1419. {
  1420.   const tCPUProps *pProp;
  1421.  
  1422.   for (pProp = CPUProps; pProp->pName; pProp++)
  1423.     (void)AddCPUUser(pProp->pName, SwitchTo_9900, (void*)pProp, NULL);
  1424.  
  1425.   AddInitPassProc(InitCode_TI990);
  1426. }
  1427.