Subversion Repositories pentevo

Rev

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

  1. /* codest7.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Portierung                                                             */
  6. /*                                                                           */
  7. /* Codegenerator SGS-Thomson ST7/STM8                                        */
  8. /*                                                                           */
  9. /*****************************************************************************/
  10.  
  11. #include "stdinc.h"
  12.  
  13. #include <ctype.h>
  14. #include <string.h>
  15. #include <assert.h>
  16.  
  17. #include "bpemu.h"
  18. #include "strutil.h"
  19. #include "nls.h"
  20. #include "asmdef.h"
  21. #include "asmsub.h"
  22. #include "asmpars.h"
  23. #include "asmitree.h"
  24. #include "asmstructs.h"
  25. #include "asmallg.h"
  26. #include "codepseudo.h"
  27. #include "motpseudo.h"
  28. #include "codevars.h"
  29. #include "errmsg.h"
  30.  
  31. #include "codest7.h"
  32.  
  33. typedef enum
  34. {
  35.   eModNone = -1,
  36.   eModImm = 0,        /* #byte */
  37.   eModAbs8,           /* shortmem */
  38.   eModAbs16,          /* longmem */
  39.   eModAbs24,          /* extmem */
  40.   eModIX,             /* (X) */
  41.   eModIX8,            /* (shortoff,X) */
  42.   eModIX16,           /* (longoff,X) */
  43.   eModIX24,           /* (extoff,X) */
  44.   eModIY,             /* (Y) */
  45.   eModIY8,            /* (shortoff,Y) */
  46.   eModIY16,           /* (longoff,Y) */
  47.   eModIY24,           /* (extoff,Y) */
  48.   eModISP8,           /* (shortoff,SP) (STM8 only) */
  49.   eModIAbs8,          /* [shortptr.b] (ST7 only) */
  50.   eModIAbs16,         /* [shortptr.w] */
  51.   eModI16Abs16,       /* [longptr.w] (STM8 only) */
  52.   eModI16Abs24,       /* [longptr.e] (STM8 only) */
  53.   eModIXAbs8,         /* ([shortptr.b],X) */
  54.   eModIXAbs16,        /* ([<longptr.w],X) */
  55.   eModI16XAbs16,      /* ([>longptr.w],X) (STM8 only) */
  56.   eModI16XAbs24,      /* ([>longptr.e],X) (STM8 only) */
  57.   eModIYAbs8,         /* ([shortptr.b],Y) */
  58.   eModIYAbs16,        /* ([<longptr.w],Y) */
  59.   eModI16YAbs24,      /* ([>longptr.e],Y) (STM8 only) */
  60.   eModA,              /* A */
  61.   eModX,              /* X */
  62.   eModXL,             /* XL (STM8 only) */
  63.   eModXH,             /* XH (STM8 only) */
  64.   eModY,              /* Y */
  65.   eModYL,             /* YL (STM8 only) */
  66.   eModYH,             /* YH (STM8 only) */
  67.   eModS               /* SP */
  68.   /* bit mask is full, 32 modes! */
  69. } tAdrMode;
  70.  
  71. #define MModImm (1ul << eModImm)
  72. #define MModAbs8 (1ul << eModAbs8)
  73. #define MModAbs16 (1ul << eModAbs16)
  74. #define MModAbs24 (1ul << eModAbs24)
  75. #define MModIX (1ul << eModIX)
  76. #define MModIX8 (1ul << eModIX8)
  77. #define MModIX16 (1ul << eModIX16)
  78. #define MModIX24 (1ul << eModIX24)
  79. #define MModIY (1ul << eModIY)
  80. #define MModIY8 (1ul << eModIY8)
  81. #define MModIY16 (1ul << eModIY16)
  82. #define MModIY24 (1ul << eModIY24)
  83. #define MModISP8 (1ul << eModISP8)
  84. #define MModIAbs8 (1ul << eModIAbs8)
  85. #define MModIAbs16 (1ul << eModIAbs16)
  86. #define MModI16Abs16 (1ul << eModI16Abs16)
  87. #define MModI16Abs24 (1ul << eModI16Abs24)
  88. #define MModIXAbs8 (1ul << eModIXAbs8)
  89. #define MModIXAbs16 (1ul << eModIXAbs16)
  90. #define MModI16XAbs16 (1ul << eModI16XAbs16)
  91. #define MModI16XAbs24 (1ul << eModI16XAbs24)
  92. #define MModIYAbs8 (1ul << eModIYAbs8)
  93. #define MModIYAbs16 (1ul << eModIYAbs16)
  94. #define MModI16YAbs24 (1ul << eModI16YAbs24)
  95. #define MModA (1ul << eModA)
  96. #define MModX (1ul << eModX)
  97. #define MModXL (1ul << eModXL)
  98. #define MModXH (1ul << eModXH)
  99. #define MModY (1ul << eModY)
  100. #define MModYL (1ul << eModYL)
  101. #define MModYH (1ul << eModYH)
  102. #define MModS (1ul << eModS)
  103.  
  104. typedef enum
  105. {
  106.   eCoreST7,
  107.   eCoreSTM8
  108. } tCPUCore;
  109.  
  110. typedef struct
  111. {
  112.   const char *pName;
  113.   IntType AddrIntType;
  114.   tCPUCore Core;
  115. } tCPUProps;
  116.  
  117. typedef struct
  118. {
  119.   tAdrMode Mode;
  120.   Byte Part;
  121.   unsigned Cnt;
  122.   Byte Vals[3];
  123. } tAdrVals;
  124.  
  125. static const tCPUProps *pCurrCPUProps;
  126. static tSymbolSize OpSize;
  127. static Byte PrefixCnt;
  128.  
  129. /*--------------------------------------------------------------------------*/
  130.  
  131. /*!------------------------------------------------------------------------
  132.  * \fn     ResetAdrVals(tAdrVals *pAdrVals)
  133.  * \brief  clear AdrVals structure
  134.  * \param  pAdrVals struct to clear/reset
  135.  * ------------------------------------------------------------------------ */
  136.  
  137. static void ResetAdrVals(tAdrVals *pAdrVals)
  138. {
  139.   pAdrVals->Mode = eModNone;
  140.   pAdrVals->Part = 0;
  141.   pAdrVals->Cnt = 0;
  142. }
  143.  
  144. static void FillAdrVals(tAdrVals *pAdrVals, LongWord Value, tSymbolSize Size)
  145. {
  146.   pAdrVals->Cnt = 0;
  147.   switch (Size)
  148.   {
  149.     case eSymbolSize24Bit:
  150.       pAdrVals->Vals[pAdrVals->Cnt++] = (Value >> 16) & 255;
  151.       /* fall-through */
  152.     case eSymbolSize16Bit:
  153.       pAdrVals->Vals[pAdrVals->Cnt++] = (Value >> 8) & 255;
  154.       /* fall-through */
  155.     case eSymbolSize8Bit:
  156.       pAdrVals->Vals[pAdrVals->Cnt++] = Value & 255;
  157.       /* fall-through */
  158.     default:
  159.       break;
  160.   }
  161. }
  162.  
  163. static void ExtendAdrVals(tAdrVals *pAdrVals)
  164. {
  165.   switch (pAdrVals->Mode)
  166.   {
  167.     case eModAbs8:
  168.       pAdrVals->Mode = eModAbs16;
  169.       pAdrVals->Vals[1] = pAdrVals->Vals[0];
  170.       pAdrVals->Vals[0] = 0;
  171.       pAdrVals->Cnt = 2;
  172.       break;
  173.     default:
  174.       break;
  175.   }
  176. }
  177.  
  178. /*!------------------------------------------------------------------------
  179.  * \fn     AddPrefix(Byte Pref)
  180.  * \brief  add another prefix byte
  181.  * \param  Pref prefix to add
  182.  * ------------------------------------------------------------------------ */
  183.  
  184. static void AddPrefix(Byte Pref)
  185. {
  186.   BAsmCode[PrefixCnt++] = Pref;
  187. }
  188.  
  189. /*!------------------------------------------------------------------------
  190.  * \fn     ModeInMask(LongWord Mask, tAdrMode Mode)
  191.  * \brief  check whether certain addressing mode is set in mask
  192.  * \param  Mask list of allowed modes
  193.  * \param  Mode addressing mode to check
  194.  * ------------------------------------------------------------------------ */
  195.  
  196. static Boolean ModeInMask(LongWord Mask, tAdrMode Mode)
  197. {
  198.   return !!((Mask >> Mode) & 1);
  199. }
  200.  
  201. /*!------------------------------------------------------------------------
  202.  * \fn     CutSizeSuffix(tStrComp *pArg)
  203.  * \brief  cut off possible size suffix (.b .w .e) from argument
  204.  * \param  pArg argument
  205.  * \return deduced size or unknown if no known suffix
  206.  * ------------------------------------------------------------------------ */
  207.  
  208. static tSymbolSize CutSizeSuffix(const tStrComp *pArg)
  209. {
  210.   int l = strlen(pArg->str.p_str);
  211.  
  212.   if ((l >= 3) && (pArg->str.p_str[l - 2] == '.'))
  213.   {
  214.     switch (as_toupper(pArg->str.p_str[l - 1]))
  215.     {
  216.       case 'B':
  217.         pArg->str.p_str[l - 2] = '\0';
  218.         return eSymbolSize8Bit;
  219.       case 'W':
  220.         pArg->str.p_str[l - 2] = '\0';
  221.         return eSymbolSize16Bit;
  222.       case 'E':
  223.         pArg->str.p_str[l - 2] = '\0';
  224.         return eSymbolSize24Bit;
  225.       default:
  226.         break;
  227.     }
  228.   }
  229.   return eSymbolSizeUnknown;
  230. }
  231.  
  232. /*!------------------------------------------------------------------------
  233.  * \fn     DecideSize(LongWord Mask, const tStrComp *pArg, tAdrMode Mode8, tAdrMode Mode16, tAdrMode Mode24, Byte Part8, Byte Part16, Byte Part24, Boolean IsCode, tAdrVals *pAdrVals)
  234.  * \brief  decide about length of absolute or indexed operand
  235.  * \param  Mask bit mask of allowed modes
  236.  * \param  pArg address argument
  237.  * \param  Mode8 AdrMode for 8-bit address/displacement
  238.  * \param  Mode16 AdrMode for 16-bit address/displacement
  239.  * \param  Mode24 AdrMode for 24-bit address/displacement
  240.  * \param  Part8 AdrPart for 8-bit address/displacement
  241.  * \param  Part16 AdrPart for 16-bit address/displacement
  242.  * \param  Part24 AdrPart for 24-bit address/displacement
  243.  * \param  IsCode Address is in code space (check for same page)
  244.  * \param  pAdrVals destination to fill out
  245.  * ------------------------------------------------------------------------ */
  246.  
  247. static void DecideSize(LongWord Mask, const tStrComp *pArg, tAdrMode Mode8, tAdrMode Mode16, tAdrMode Mode24, Byte Part8, Byte Part16, Byte Part24, Boolean IsCode, tAdrVals *pAdrVals)
  248. {
  249.   tSymbolSize Size = eSymbolSizeUnknown;
  250.   IntType SizeType;
  251.   LongWord Value;
  252.   Boolean OK;
  253.   tSymbolFlags Flags;
  254.  
  255.   if ((Mode8 != eModNone) && !ModeInMask(Mask, Mode8))
  256.     Mode8 = eModNone;
  257.   if ((Mode16 != eModNone) && !ModeInMask(Mask, Mode16))
  258.     Mode16 = eModNone;
  259.   if ((Mode24 != eModNone) && !ModeInMask(Mask, Mode24))
  260.     Mode24 = eModNone;
  261.  
  262.   Size = CutSizeSuffix(pArg);
  263.   switch (Size)
  264.   {
  265.     case eSymbolSize8Bit:
  266.       if (Mode8 == eModNone)
  267.         goto InvSize;
  268.       break;
  269.     case eSymbolSize16Bit:
  270.       if (Mode16 == eModNone)
  271.         goto InvSize;
  272.       break;
  273.     case eSymbolSize24Bit:
  274.       if (Mode24 == eModNone)
  275.         goto InvSize;
  276.       break;
  277.     default:
  278.       break;
  279.     InvSize:
  280.       WrStrErrorPos(ErrNum_InvAddrMode, pArg);
  281.       return;
  282.   }
  283.  
  284.   if (IsCode)
  285.     SizeType = pCurrCPUProps->AddrIntType;
  286.   else switch (Size)
  287.   {
  288.     case eSymbolSize24Bit:
  289.       SizeType = Int24;
  290.       break;
  291.     case eSymbolSize16Bit:
  292.       SizeType = Int16;
  293.       break;
  294.     case eSymbolSize8Bit:
  295.       SizeType = Int8;
  296.       break;
  297.     default:
  298.       if (Mode24 != eModNone)
  299.         SizeType = Int24;
  300.       else if (Mode16 != eModNone)
  301.         SizeType = Int16;
  302.       else
  303.         SizeType = Int8;
  304.       break;
  305.   }
  306.   Value = EvalStrIntExpressionWithFlags(pArg, SizeType, &OK, &Flags);
  307.  
  308.   if (OK)
  309.   {
  310.     LongWord SrcAddress = IsCode ? EProgCounter() + 3 : 0;
  311.  
  312.     if (Size == eSymbolSizeUnknown)
  313.     {
  314.       if ((Value <= 0xff) && (Mode8 != eModNone))
  315.         Size = eSymbolSize8Bit;
  316.       else if (((Value >> 16) == (SrcAddress >> 16)) && (Mode16 != eModNone))
  317.         Size = eSymbolSize16Bit;
  318.       else
  319.         Size = eSymbolSize24Bit;
  320.     }
  321.  
  322.     /* this may only happen if SizeTypes was forced to 24 Bit because of code addessing: */
  323.  
  324.     if ((Size == eSymbolSize24Bit) && (Mode24 == eModNone) && !mSymbolQuestionable(Flags))
  325.     {
  326.       WrStrErrorPos(ErrNum_TargOnDiffSection, pArg);
  327.       return;
  328.     }
  329.  
  330.     FillAdrVals(pAdrVals, Value, Size);
  331.     switch (Size)
  332.     {
  333.       case eSymbolSize8Bit:
  334.         pAdrVals->Part = Part8;
  335.         pAdrVals->Mode = Mode8;
  336.         break;
  337.       case eSymbolSize16Bit:
  338.         pAdrVals->Part = Part16;
  339.         pAdrVals->Mode = Mode16;
  340.         break;
  341.       case eSymbolSize24Bit:
  342.         pAdrVals->Part = Part24;
  343.         pAdrVals->Mode = Mode24;
  344.         break;
  345.       default:
  346.         assert(0);
  347.     }
  348.   }
  349. }
  350.  
  351. /*!------------------------------------------------------------------------
  352.  * \fn     DecideIndirectSize(LongWord Mask, const tStrComp *pArg,
  353.                               tAdrMode Mode8_8, tAdrMode Mode8_16, tAdrMode Mode16_16, tAdrMode Mode16_24,
  354.                               Byte Part8_8, Byte Part8_16, Byte Part16_16, Byte Part16_24,
  355.                               tAdrVals *pAdrVals)
  356.  * \brief  address mode decision for indirect operands []
  357.  * \param  Mask bit mask of allowed modes
  358.  * \param  pArg expression
  359.  * \param  Mode8_8 requested mode for 8-bit pointer on 8-bit address
  360.  * \param  Mode8_16 requested mode for 16-bit pointer on 8-bit address
  361.  * \param  Mode16_16 requested mode for 16-bit pointer on 16-bit address
  362.  * \param  Mode16_24 requested mode for 24-bit pointer on 16-bit address
  363.  * \param  Part8_8 Address part for 8-bit pointer on 8-bit address
  364.  * \param  Part8_16 Address part for 16-bit pointer on 8-bit address
  365.  * \param  Part16_16 Address part for 16-bit pointer on 16-bit address
  366.  * \param  Part16_24 Address part for 24-bit pointer on 16-bit address
  367.  * \param  pAdrVals destination to fill out
  368.  * \return True if successfully parsed
  369.  * ------------------------------------------------------------------------ */
  370.  
  371. static Boolean DecideIndirectSize(LongWord Mask, const tStrComp *pArg,
  372.                                   tAdrMode Mode8_8, tAdrMode Mode8_16, tAdrMode Mode16_16, tAdrMode Mode16_24,
  373.                                   Byte Part8_8, Byte Part8_16, Byte Part16_16, Byte Part16_24,
  374.                                   tAdrVals *pAdrVals)
  375. {
  376.   Boolean OK;
  377.   int Offset;
  378.   tSymbolSize AddrSize = eSymbolSizeUnknown,
  379.               PtrSize = eSymbolSizeUnknown;
  380.   IntType SizeType;
  381.   Word Address;
  382.   tSymbolFlags Flags;
  383.  
  384.   if ((Mode8_8 != eModNone) && !ModeInMask(Mask, Mode8_8))
  385.     Mode8_8 = eModNone;
  386.   if ((Mode8_16 != eModNone) && !ModeInMask(Mask, Mode8_16))
  387.     Mode8_16 = eModNone;
  388.   if ((Mode16_16 != eModNone) && !ModeInMask(Mask, Mode16_16))
  389.     Mode16_16 = eModNone;
  390.   if ((Mode16_24 != eModNone) && !ModeInMask(Mask, Mode16_24))
  391.     Mode16_24 = eModNone;
  392.  
  393.   /* Cut off address byte size, signified by leading '<' or '>': */
  394.  
  395.   switch (*pArg->str.p_str)
  396.   {
  397.     case '>':
  398.       Offset = 1;
  399.       AddrSize = eSymbolSize16Bit;
  400.       break;
  401.     case '<':
  402.       Offset = 1;
  403.       AddrSize = eSymbolSize8Bit;
  404.       break;
  405.     default:
  406.       Offset = 0;
  407.       AddrSize = eSymbolSizeUnknown;
  408.   }
  409.  
  410.   /* Cut off pointer size, signified by trailing '.w/.e' if 16/24 bit: */
  411.  
  412.   PtrSize = CutSizeSuffix(pArg);
  413.  
  414.   /* if no pointer size given, assume the smallest possible one: */
  415.  
  416.   if (PtrSize == eSymbolSizeUnknown)
  417.   {
  418.     if (Mode8_8 != eModNone)
  419.       PtrSize = eSymbolSize8Bit;
  420.     else if ((Mode8_16 != eModNone) || (Mode16_16 != eModNone))
  421.       PtrSize = eSymbolSize16Bit;
  422.     else
  423.       PtrSize = eSymbolSize24Bit;
  424.   }
  425.  
  426.   switch (AddrSize)
  427.   {
  428.     case eSymbolSize16Bit:
  429.       SizeType = Int16;
  430.       break;
  431.     case eSymbolSize8Bit:
  432.       SizeType = Int8;
  433.       break;
  434.     default:
  435.       if ((Mode16_16 != eModNone) || (Mode16_24 != eModNone))
  436.         SizeType = Int16;
  437.       else
  438.         SizeType = Int8;
  439.       break;
  440.   }
  441.  
  442.   Address = EvalStrIntExpressionOffsWithFlags(pArg, Offset, SizeType, &OK, &Flags);
  443.   if (mFirstPassUnknown(Flags) && (Mode16_16 == eModNone) && (Mode16_24 == eModNone))
  444.     Address &= 0xff;
  445.  
  446.   if (OK)
  447.   {
  448.     /* Finally decide about address size: */
  449.  
  450.     if (eSymbolSizeUnknown == AddrSize)
  451.     {
  452.       if ((Address <= 0xff) && (PtrSize == eSymbolSize8Bit) && (Mode8_8 != eModNone))
  453.         AddrSize = eSymbolSize8Bit;
  454.       else if ((Address <= 0xff) && (PtrSize == eSymbolSize16Bit) && (Mode8_16 != eModNone))
  455.         AddrSize = eSymbolSize8Bit;
  456.       else
  457.         AddrSize = eSymbolSize16Bit;
  458.     }
  459.  
  460.     FillAdrVals(pAdrVals, Address, AddrSize);
  461.     if (eSymbolSize16Bit == AddrSize)
  462.     {
  463.       if (PtrSize == eSymbolSize24Bit)
  464.       {
  465.         pAdrVals->Part = Part16_24;
  466.         pAdrVals->Mode = Mode16_24;
  467.       }
  468.       else
  469.       {
  470.         pAdrVals->Part = Part16_16;
  471.         pAdrVals->Mode = Mode16_16;
  472.       }
  473.     }
  474.     else
  475.     {
  476.       if (PtrSize == eSymbolSize16Bit)
  477.       {
  478.         pAdrVals->Part = Part8_16;
  479.         pAdrVals->Mode = Mode8_16;
  480.       }
  481.       else
  482.       {
  483.         pAdrVals->Part = Part8_8;
  484.         pAdrVals->Mode = Mode8_8;
  485.       }
  486.     }
  487.   }
  488.   return OK;
  489. }
  490.  
  491. /*!------------------------------------------------------------------------
  492.  * \fn     ChkAdrMode(tAdrMode *pAdrMode, LongWord Mask, tErrorNum ErrorNum, const tStrComp *pArg)
  493.  * \brief  check for allowed addressing mode
  494.  * \param  pAdrMode parsed addressing mode (in/out)
  495.  * \param  Mask list of allowed modes
  496.  * \param  ErrorNum error message to emit if not allowed
  497.  * \param  pArg offending arg
  498.  * \return True if mode is OK
  499.  * ------------------------------------------------------------------------ */
  500.  
  501. static Boolean ChkAdrMode(tAdrMode *pAdrMode, LongWord Mask, tErrorNum ErrorNum, const tStrComp *pArg)
  502. {
  503.   if ((*pAdrMode != eModNone) && (!(Mask & (1ul << *pAdrMode))))
  504.   {
  505.     WrStrErrorPos(ErrorNum, pArg);
  506.     *pAdrMode = eModNone;
  507.     return False;
  508.   }
  509.   return True;
  510. }
  511.  
  512. /*!------------------------------------------------------------------------
  513.  * \fn     ChkAdrValsMode(tAdrVals *pAdrVals, LongWord Mask, tErrorNum ErrorNum, const tStrComp *pArg)
  514.  * \brief  check for allowed addressing mode
  515.  * \param  pAdrVals parsed addressing mode (in/out)
  516.  * \param  Mask list of allowed modes
  517.  * \param  ErrorNum error message to emit if not allowed
  518.  * \param  pArg offending arg
  519.  * \return True if mode is OK
  520.  * ------------------------------------------------------------------------ */
  521.  
  522. static Boolean ChkAdrValsMode(tAdrVals *pAdrVals, LongWord Mask, tErrorNum ErrorNum, const tStrComp *pArg)
  523. {
  524.   if (!ChkAdrMode(&pAdrVals->Mode, Mask, ErrorNum, pArg))
  525.   {
  526.     pAdrVals->Cnt = 0;
  527.     return False;
  528.   }
  529.   return True;
  530. }
  531.  
  532. /*!------------------------------------------------------------------------
  533.  * \fn     DecodeRegCore(const tStrComp *pArg, tAdrMode *pResult)
  534.  * \brief  check whether argument is a CPU register
  535.  * \param  pArg argument to check
  536.  * \param  pResult resulting mode if it is a register
  537.  * \return True if argument is a register
  538.  * ------------------------------------------------------------------------ */
  539.  
  540. static Boolean DecodeRegCore(const tStrComp *pArg, tAdrMode *pResult)
  541. {
  542.   *pResult = eModNone;
  543.  
  544.   if (!as_strcasecmp(pArg->str.p_str, "A"))
  545.   {
  546.     *pResult = eModA;
  547.     return True;
  548.   }
  549.  
  550.   if (!as_strcasecmp(pArg->str.p_str, "X"))
  551.   {
  552.     *pResult = eModX;
  553.     return True;
  554.   }
  555.   if (!as_strcasecmp(pArg->str.p_str, "XL"))
  556.   {
  557.     *pResult = eModXL;
  558.     return True;
  559.   }
  560.   if (!as_strcasecmp(pArg->str.p_str, "XH"))
  561.   {
  562.     *pResult = eModXH;
  563.     return True;
  564.   }
  565.  
  566.   if (!as_strcasecmp(pArg->str.p_str, "Y"))
  567.   {
  568.     *pResult = eModY;
  569.     return True;
  570.   }
  571.   if (!as_strcasecmp(pArg->str.p_str, "YL"))
  572.   {
  573.     *pResult = eModYL;
  574.     return True;
  575.   }
  576.   if (!as_strcasecmp(pArg->str.p_str, "YH"))
  577.   {
  578.     *pResult = eModYH;
  579.     return True;
  580.   }
  581.  
  582.   if ((!as_strcasecmp(pArg->str.p_str, "S"))
  583.    || ((pCurrCPUProps->Core == eCoreSTM8) && !as_strcasecmp(pArg->str.p_str, "SP")))
  584.   {
  585.     *pResult = eModS;
  586.     return True;
  587.   }
  588.  
  589.   return False;
  590. }
  591.  
  592. /*!------------------------------------------------------------------------
  593.  * \fn     DecodeReg(const tStrComp *pArg, tAdrMode *pResult, LongWord Mask)
  594.  * \brief  decode addressing expression, registers-only
  595.  * \param  pArg argument
  596.  * \param  pResult resulting mode
  597.  * \param  Mask list of allowed modes
  598.  * \return True if argument is a CPU register
  599.  * ------------------------------------------------------------------------ */
  600.  
  601. static Boolean DecodeReg(const tStrComp *pArg, tAdrMode *pResult, LongWord Mask)
  602. {
  603.   return DecodeRegCore(pArg, pResult)
  604.       && ChkAdrMode(pResult, Mask, ErrNum_InvReg, pArg);
  605. }
  606.  
  607. /*!------------------------------------------------------------------------
  608.  * \fn     DecodeAdr(const tStrComp *pArg, LongWord Mask, Boolean IsCode, tAdrVals *pAdrVals)
  609.  * \brief  decode addressing expression
  610.  * \param  pArg argument
  611.  * \param  Mask list of allowed masks
  612.  * \param  IsCode is expression a jump/call address?
  613.  * \param  pAdrVals destination to fill out
  614.  * \return True if successfully parsed
  615.  * ------------------------------------------------------------------------ */
  616.  
  617. static Boolean DecodeAdr(const tStrComp *pArg, LongWord Mask, Boolean IsCode, tAdrVals *pAdrVals)
  618. {
  619.   Boolean OK;
  620.   int ArgLen;
  621.  
  622.   ArgLen = strlen(pArg->str.p_str);
  623.  
  624.   ResetAdrVals(pAdrVals);
  625.  
  626.   /* Register ? */
  627.  
  628.   if (DecodeRegCore(pArg, &pAdrVals->Mode))
  629.   {
  630.     switch (pAdrVals->Mode)
  631.     {
  632.       case eModY:
  633.       case eModYL:
  634.       case eModYH:
  635.         AddPrefix(0x90);
  636.         break;
  637.       default:
  638.         break;
  639.     }
  640.     goto chk;
  641.   }
  642.  
  643.   /* immediate ? */
  644.  
  645.   if (*pArg->str.p_str == '#')
  646.   {
  647.     Word Value = EvalStrIntExpressionOffs(pArg, 1, (OpSize == eSymbolSize16Bit) ? Int16 : Int8, &OK);
  648.     if (OK)
  649.     {
  650.       pAdrVals->Mode = eModImm;
  651.       pAdrVals->Part = 0xa;
  652.       FillAdrVals(pAdrVals, Value, OpSize);
  653.     }
  654.     goto chk;
  655.   }
  656.  
  657.   /* speicherindirekt ? */
  658.  
  659.   if ((*pArg->str.p_str == '[') && (pArg->str.p_str[ArgLen - 1] == ']'))
  660.   {
  661.     tStrComp Comp;
  662.     Boolean OK;
  663.  
  664.     StrCompRefRight(&Comp, pArg, 1);
  665.     Comp.str.p_str[ArgLen - 2] = '\0'; Comp.Pos.Len--;
  666.     OK = DecideIndirectSize(Mask, &Comp, eModIAbs8, eModIAbs16, eModI16Abs16, eModI16Abs24, 0xb, 0xc, 0xc, 0xb, pAdrVals);
  667.     Comp.str.p_str[ArgLen - 2] = ']';
  668.     if (OK)
  669.       AddPrefix((pAdrVals->Mode == eModI16Abs16) ? 0x72: 0x92);
  670.     goto chk;
  671.   }
  672.  
  673.   /* sonstwie indirekt ? */
  674.  
  675.   if (IsIndirect(pArg->str.p_str))
  676.   {
  677.     tStrComp Comp, Left, Right;
  678.     Boolean YReg = False, SPReg = False;
  679.     char *p;
  680.  
  681.     StrCompRefRight(&Comp, pArg, 1);
  682.     StrCompShorten(&Comp, 1);
  683.  
  684.     /* ein oder zwei Argumente ? */
  685.  
  686.     p = QuotPos(Comp.str.p_str, ',');
  687.     if (!p)
  688.     {
  689.       pAdrVals->Part = 0xf;
  690.       if (!as_strcasecmp(Comp.str.p_str, "X")) pAdrVals->Mode = eModIX;
  691.       else if (!as_strcasecmp(Comp.str.p_str, "Y"))
  692.       {
  693.         pAdrVals->Mode = eModIY;
  694.         AddPrefix(0x90);
  695.       }
  696.       else WrStrErrorPos(ErrNum_InvReg, &Comp);
  697.       goto chk;
  698.     }
  699.  
  700.     StrCompSplitRef(&Left, &Right, &Comp, p);
  701.  
  702.     if (!as_strcasecmp(Left.str.p_str, "X"))
  703.       Left = Right;
  704.     else if (!as_strcasecmp(Right.str.p_str, "X"));
  705.     else if (!as_strcasecmp(Left.str.p_str, "Y"))
  706.     {
  707.       Left = Right;
  708.       YReg = True;
  709.     }
  710.     else if (!as_strcasecmp(Right.str.p_str, "Y"))
  711.       YReg = True;
  712.     else if (!as_strcasecmp(Left.str.p_str, "SP"))
  713.     {
  714.       Left = Right;
  715.       SPReg = True;
  716.     }
  717.     else if (!as_strcasecmp(Right.str.p_str, "SP"))
  718.       SPReg = True;
  719.     else
  720.     {
  721.       WrStrErrorPos(ErrNum_InvAddrMode, &Comp);
  722.       return False;
  723.     }
  724.  
  725.     /* speicherindirekt ? */
  726.  
  727.     ArgLen = strlen(Left.str.p_str);
  728.     if ((*Left.str.p_str == '[') && (Left.str.p_str[ArgLen - 1] == ']'))
  729.     {
  730.       StrCompRefRight(&Right, &Left, 1);
  731.       StrCompShorten(&Right, 1);
  732.       if (YReg)
  733.       {
  734.         if (DecideIndirectSize(Mask, &Right, eModIYAbs8, eModIYAbs16, eModNone, eModI16YAbs24, 0xe, 0xd, 0x0, 0xa, pAdrVals))
  735.           AddPrefix(0x91);
  736.       }
  737.       else
  738.       {
  739.         if (DecideIndirectSize(Mask, &Right, eModIXAbs8, eModIXAbs16, eModI16XAbs16, eModI16YAbs24, 0xe, 0xd, 0xd, 0xa, pAdrVals))
  740.           AddPrefix((pAdrVals->Mode == eModI16XAbs16) ? 0x72 : 0x92);
  741.       }
  742.     }
  743.     else
  744.     {
  745.       if (YReg) DecideSize(Mask, &Left, eModIY8, eModIY16, eModIY24, 0xe, 0xd, 0xa, IsCode, pAdrVals);
  746.       else if (SPReg) DecideSize(Mask, &Left, eModISP8, eModNone, eModNone, 0x1, 0x0, 0x0, IsCode, pAdrVals);
  747.       else DecideSize(Mask, &Left, eModIX8, eModIX16, eModIX24, 0xe, 0xd, 0xa, IsCode, pAdrVals);
  748.       if ((pAdrVals->Mode != eModNone) && YReg) AddPrefix(0x90);
  749.     }
  750.  
  751.     goto chk;
  752.   }
  753.  
  754.   /* dann absolut */
  755.  
  756.   DecideSize(Mask, pArg, eModAbs8, eModAbs16, eModAbs24, 0xb, 0xc, 0xb, IsCode, pAdrVals);
  757.  
  758. chk:
  759.   return ChkAdrValsMode(pAdrVals, Mask, ErrNum_InvAddrMode, pArg);
  760. }
  761.  
  762. /*!------------------------------------------------------------------------
  763.  * \fn     ConstructMask(LongWord TotMask, tSymbolSize OpSize)
  764.  * \brief  construct actual bit mask of allowed addressing modes from overall list
  765.  * \param  TotMask overall list
  766.  * \param  OpSize operand size in use (8/16/unknown)
  767.  * \return actual mask
  768.  * ------------------------------------------------------------------------ */
  769.  
  770. static LongWord ConstructMask(LongWord TotMask, tSymbolSize OpSize)
  771. {
  772.   if (pCurrCPUProps->Core == eCoreST7)
  773.   {
  774.     /* not present on ST7 */
  775.  
  776.     TotMask &= ~(MModISP8 | MModI16Abs16 | MModI16XAbs16 | MModXL | MModYL | MModXH | MModYH);
  777.  
  778.     /* SP/X/Y are 8 bits wide on ST7 */
  779.  
  780.     if (OpSize == eSymbolSize16Bit)
  781.       TotMask &= ~(MModX | MModY | MModS);
  782.   }
  783.  
  784.   if (pCurrCPUProps->Core == eCoreSTM8)
  785.   {
  786.     /* removed on STM8 */
  787.  
  788.     TotMask &= ~(MModIAbs8 | MModIXAbs8 | MModIYAbs8);
  789.  
  790.     /* SP/X/Y changed to 16 bits on STM8 */
  791.  
  792.     if (OpSize == eSymbolSize8Bit)
  793.       TotMask &= ~(MModX | MModY | MModS);
  794.   }
  795.  
  796.   return TotMask;
  797. }
  798.  
  799. /*--------------------------------------------------------------------------*/
  800. /* Bit Symbol Handling */
  801.  
  802. /*
  803.  * Compact representation of bits in symbol table:
  804.  * bits 0..2: bit position
  805.  * bits 3...10/18: register address in memory space (first 256/64K)
  806.  */
  807.  
  808. /*!------------------------------------------------------------------------
  809.  * \fn     EvalBitPosition(const tStrComp *pArg, Boolean *pOK)
  810.  * \brief  evaluate bit position
  811.  * \param  bit position argument (with or without #)
  812.  * \param  pOK parsing OK?
  813.  * \return numeric bit position
  814.  * ------------------------------------------------------------------------ */
  815.  
  816. static LongWord EvalBitPosition(const tStrComp *pArg, Boolean *pOK)
  817. {
  818.   return EvalStrIntExpressionOffs(pArg, !!(*pArg->str.p_str == '#'), UInt3, pOK);
  819. }
  820.  
  821. /*!------------------------------------------------------------------------
  822.  * \fn     AssembleBitSymbol(Byte BitPos, Word Address)
  823.  * \brief  build the compact internal representation of a bit symbol
  824.  * \param  BitPos bit position in word
  825.  * \param  Address register address
  826.  * \return compact representation
  827.  * ------------------------------------------------------------------------ */
  828.  
  829. static LongWord AssembleBitSymbol(Byte BitPos, Word Address)
  830. {
  831.   return (BitPos & 7)
  832.        | (((LongWord)Address & 0xffff) << 3);
  833. }
  834.  
  835. /*!------------------------------------------------------------------------
  836.  * \fn     DecodeBitArg2(LongWord *pResult, const tStrComp *pRegArg, const tStrComp *pBitArg)
  837.  * \brief  encode a bit symbol, address & bit position separated
  838.  * \param  pResult resulting encoded bit
  839.  * \param  pRegArg register argument
  840.  * \param  pBitArg bit argument
  841.  * \return True if success
  842.  * ------------------------------------------------------------------------ */
  843.  
  844. static Boolean DecodeBitArg2(LongWord *pResult, const tStrComp *pRegArg, const tStrComp *pBitArg)
  845. {
  846.   Boolean OK;
  847.   LongWord Addr;
  848.   Byte BitPos;
  849.  
  850.   BitPos = EvalBitPosition(pBitArg, &OK);
  851.   if (!OK)
  852.     return False;
  853.  
  854.   Addr = EvalStrIntExpression(pRegArg, (pCurrCPUProps->Core == eCoreSTM8) ? UInt16 : UInt8, &OK);
  855.   if (!OK)
  856.     return False;
  857.  
  858.   *pResult = AssembleBitSymbol(BitPos, Addr);
  859.  
  860.   return True;
  861. }
  862.  
  863. /*!------------------------------------------------------------------------
  864.  * \fn     DecodeBitArg(LongWord *pResult, int Start, int Stop)
  865.  * \brief  encode a bit symbol from instruction argument(s)
  866.  * \param  pResult resulting encoded bit
  867.  * \param  Start first argument
  868.  * \param  Stop last argument
  869.  * \return True if success
  870.  * ------------------------------------------------------------------------ */
  871.  
  872. static Boolean DecodeBitArg(LongWord *pResult, int Start, int Stop)
  873. {
  874.   *pResult = 0;
  875.  
  876.   /* Just one argument -> parse as bit argument */
  877.  
  878.   if (Start == Stop)
  879.   {
  880.     tEvalResult EvalResult;
  881.  
  882.     *pResult = EvalStrIntExpressionWithResult(&ArgStr[Start], (pCurrCPUProps->Core == eCoreSTM8) ? UInt19 : UInt11, &EvalResult);
  883.     if (EvalResult.OK)
  884.       ChkSpace(SegBData, EvalResult.AddrSpaceMask);
  885.     return EvalResult.OK;
  886.   }
  887.  
  888.   /* register & bit position are given as separate arguments */
  889.  
  890.   else if (Stop == Start + 1)
  891.     return DecodeBitArg2(pResult, &ArgStr[Start], &ArgStr[Stop]);
  892.  
  893.   /* other # of arguments not allowed */
  894.  
  895.   else
  896.   {
  897.     WrError(ErrNum_WrongArgCnt);
  898.     return False;
  899.   }
  900. }
  901.  
  902. /*!------------------------------------------------------------------------
  903.  * \fn     DissectBitSymbol(LongWord BitSymbol, Word *pAddress, Byte *pBitPos)
  904.  * \brief  transform compact representation of bit (field) symbol into components
  905.  * \param  BitSymbol compact storage
  906.  * \param  pAddress (I/O) register address
  907.  * \param  pBitPos (start) bit position
  908.  * \return constant True
  909.  * ------------------------------------------------------------------------ */
  910.  
  911. static Boolean DissectBitSymbol(LongWord BitSymbol, Word *pAddress, Byte *pBitPos)
  912. {
  913.   *pAddress = (BitSymbol >> 3) & 0xffff;
  914.   *pBitPos = BitSymbol & 7;
  915.   return True;
  916. }
  917.  
  918. /*!------------------------------------------------------------------------
  919.  * \fn     DissectBit_ST7(char *pDest, size_t DestSize, LargeWord Inp)
  920.  * \brief  dissect compact storage of bit (field) into readable form for listing
  921.  * \param  pDest destination for ASCII representation
  922.  * \param  DestSize destination buffer size
  923.  * \param  Inp compact storage
  924.  * ------------------------------------------------------------------------ */
  925.  
  926. static void DissectBit_ST7(char *pDest, size_t DestSize, LargeWord Inp)
  927. {
  928.   Byte BitPos;
  929.   Word Address;
  930.  
  931.   DissectBitSymbol(Inp, &Address, &BitPos);
  932.  
  933.   as_snprintf(pDest, DestSize, "$%x.%u", (unsigned)Address, (unsigned)BitPos);
  934. }
  935.  
  936. /*!------------------------------------------------------------------------
  937.  * \fn     ExpandST7Bit(const tStrComp *pVarName, const struct sStructElem *pStructElem, LargeWord Base)
  938.  * \brief  expands bit definition when a structure is instantiated
  939.  * \param  pVarName desired symbol name
  940.  * \param  pStructElem element definition
  941.  * \param  Base base address of instantiated structure
  942.  * ------------------------------------------------------------------------ */
  943.  
  944. static void ExpandST7Bit(const tStrComp *pVarName, const struct sStructElem *pStructElem, LargeWord Base)
  945. {
  946.   LongWord Address = Base + pStructElem->Offset;
  947.  
  948.   if (pInnermostNamedStruct)
  949.   {
  950.     PStructElem pElem = CloneStructElem(pVarName, pStructElem);
  951.  
  952.     if (!pElem)
  953.       return;
  954.     pElem->Offset = Address;
  955.     AddStructElem(pInnermostNamedStruct->StructRec, pElem);
  956.   }
  957.   else
  958.   {
  959.     if (!ChkRange(Address, 0, (pCurrCPUProps->Core == eCoreSTM8) ? 0xffff : 0xff)
  960.      || !ChkRange(pStructElem->BitPos, 0, 7))
  961.       return;
  962.  
  963.     PushLocHandle(-1);
  964.     EnterIntSymbol(pVarName, AssembleBitSymbol(pStructElem->BitPos, Address), SegBData, False);
  965.     PopLocHandle();
  966.     /* TODO: MakeUseList? */
  967.   }
  968. }
  969.  
  970. /*!------------------------------------------------------------------------
  971.  * \fn     DecodeBitAdrWithIndir(int Start, int Stop, Byte *pBitPos, tAdrVals *pAdrVals)
  972.  * \brief  decode bit expression, regarding indirect mode on ST7
  973.  * \param  Start 1st argument of bit expression
  974.  * \param  Stop 2nd argument of bit expression
  975.  * \param  pAdrVals result to fill
  976.  * \return True if parsing OK
  977.  * ------------------------------------------------------------------------ */
  978.  
  979. static Boolean DecodeBitAdrWithIndir(int Start, int Stop, Byte *pBitPos, tAdrVals *pAdrVals)
  980. {
  981.   Boolean OK;
  982.  
  983.   if (Start == Stop)
  984.   {
  985.     LongWord BitSym;
  986.     Word Address;
  987.  
  988.     if (!DecodeBitArg(&BitSym, Start, Stop))
  989.       return False;
  990.     DissectBitSymbol(BitSym, &Address, pBitPos);
  991.     if (pCurrCPUProps->Core == eCoreSTM8)
  992.     {
  993.       FillAdrVals(pAdrVals, Address, eSymbolSize16Bit);
  994.       pAdrVals->Mode = eModAbs16;
  995.     }
  996.     else
  997.     {
  998.       FillAdrVals(pAdrVals, Address, eSymbolSize8Bit);
  999.       pAdrVals->Mode = eModAbs8;
  1000.     }
  1001.     PrefixCnt = 0;
  1002.     return True;
  1003.   }
  1004.   else if (Start + 1 == Stop)
  1005.   {
  1006.     *pBitPos = EvalBitPosition(&ArgStr[Stop], &OK);
  1007.     if (!OK)
  1008.       return False;
  1009.     return DecodeAdr(&ArgStr[Start], (pCurrCPUProps->Core == eCoreSTM8) ? MModAbs16 : (MModAbs8 | MModIAbs8), False, pAdrVals);
  1010.   }
  1011.   else
  1012.     return False;
  1013. }
  1014.  
  1015. /*!------------------------------------------------------------------------
  1016.  * \fn     CompleteCode(const tAdrVals *pAdrVals)
  1017.  * \brief  assemble instruction from prefixes, opcode and address values
  1018.  * \param  pAdrVals values to append to code
  1019.  * ------------------------------------------------------------------------ */
  1020.  
  1021. static void CompleteCode(const tAdrVals *pAdrVals)
  1022. {
  1023.   memcpy(BAsmCode + PrefixCnt + 1, pAdrVals->Vals, pAdrVals->Cnt);
  1024.   CodeLen = PrefixCnt + 1 + pAdrVals->Cnt;
  1025. }
  1026.  
  1027. /*!------------------------------------------------------------------------
  1028.  * \fn     WriteMOV(tAdrVals *pDestAdrVals, tAdrVals *pSrcAdrVals)
  1029.  * \brief  core of writing code of MOV instruction
  1030.  * \param  pDestAdrVals parsed destination operand
  1031.  * \param  pSrcAdrVals parsed source operand
  1032.  * ------------------------------------------------------------------------ */
  1033.  
  1034. static void WriteMOV(tAdrVals *pDestAdrVals, tAdrVals *pSrcAdrVals)
  1035. {
  1036.   if ((pDestAdrVals->Mode == eModAbs16)
  1037.    || (pSrcAdrVals->Mode == eModAbs16)
  1038.    || (pSrcAdrVals->Mode == eModImm))
  1039.   {
  1040.     ExtendAdrVals(pSrcAdrVals);
  1041.     ExtendAdrVals(pDestAdrVals);
  1042.   }
  1043.   switch (pSrcAdrVals->Mode)
  1044.   {
  1045.     case eModImm:
  1046.       BAsmCode[0] = 0x35;
  1047.       break;
  1048.     case eModAbs8:
  1049.       BAsmCode[0] = 0x45;
  1050.       break;
  1051.     case eModAbs16:
  1052.       BAsmCode[0] = 0x55;
  1053.       break;
  1054.     default:
  1055.       break;
  1056.   }
  1057.   memcpy(&BAsmCode[1], pSrcAdrVals->Vals, pSrcAdrVals->Cnt);
  1058.   memcpy(&BAsmCode[1 + pSrcAdrVals->Cnt], pDestAdrVals->Vals, pDestAdrVals->Cnt);
  1059.   CodeLen = 1 + pSrcAdrVals->Cnt + pDestAdrVals->Cnt;
  1060. }
  1061.  
  1062. /*--------------------------------------------------------------------------*/
  1063. /* Code Generators */
  1064.  
  1065. /*!------------------------------------------------------------------------
  1066.  * \fn     DecodeFixed(Word Code)
  1067.  * \brief  decode instructions without argument
  1068.  * \param  per-instruction context
  1069.  * ------------------------------------------------------------------------ */
  1070.  
  1071. static void DecodeFixed(Word Code)
  1072. {
  1073.   if (!ChkArgCnt(0, 0));
  1074.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1075.   else if (Hi(Code) && (pCurrCPUProps->Core != eCoreSTM8)) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1076.   else
  1077.   {
  1078.     if (Hi(Code) >= 2)
  1079.       AddPrefix(Hi(Code));
  1080.     BAsmCode[PrefixCnt] = Lo(Code);
  1081.     CodeLen = PrefixCnt + 1;
  1082.   }
  1083. }
  1084.  
  1085. /*!------------------------------------------------------------------------
  1086.  * \fn     DecodeLD(Word Code)
  1087.  * \brief  decode LD instruction
  1088.  * ------------------------------------------------------------------------ */
  1089.  
  1090. static void DecodeLD(Word Code)
  1091. {
  1092.   LongWord Mask;
  1093.   tAdrVals DestAdrVals, SrcAdrVals;
  1094.  
  1095.   UNUSED(Code);
  1096.  
  1097.   if (!ChkArgCnt(2, 2));
  1098.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1099.   else
  1100.   {
  1101.     /* NOTE: Set eSymbolSizeUnknown so we get X/Y/S also in STM8 mode.
  1102.              LD will work like LDW in thi case. */
  1103.  
  1104.     Mask = ConstructMask(MModA | MModX | MModY | MModS |  MModXL | MModYL | MModXH | MModYH
  1105.                        | MModImm | MModAbs8 | MModAbs16
  1106.                        | MModIX | MModIX8 | MModIX16 | MModIY | MModIY8 | MModIY16 | MModISP8
  1107.                        | MModIAbs8 | MModIAbs16 | MModI16Abs16
  1108.                        | MModIXAbs8 | MModIXAbs16 | MModI16XAbs16 | MModIYAbs8 | MModIYAbs16, eSymbolSizeUnknown);
  1109.     if (DecodeAdr(&ArgStr[1], Mask, False, &DestAdrVals))
  1110.     switch (DestAdrVals.Mode)
  1111.     {
  1112.       case eModA:
  1113.         Mask = ConstructMask(MModImm | MModX | MModY | MModS | MModXL | MModYL | MModXH | MModYH | MModAbs8 | MModAbs16
  1114.              | MModIX | MModIX8 | MModIX16 | MModIY | MModIY8 | MModIY16 | MModISP8
  1115.              | MModIAbs8 | MModIAbs16 | MModI16Abs16
  1116.              | MModIXAbs8 | MModIXAbs16 | MModI16XAbs16 | MModIYAbs8 | MModIYAbs16, eSymbolSize8Bit);
  1117.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1118.         switch (SrcAdrVals.Mode)
  1119.         {
  1120.           case eModX: case eModXL:
  1121.           case eModY: case eModYL:
  1122.             BAsmCode[PrefixCnt] = 0x9f;
  1123.             CodeLen = PrefixCnt + 1;
  1124.             break;
  1125.           case eModXH: case eModYH:
  1126.             BAsmCode[PrefixCnt] = 0x9e;
  1127.             CodeLen = PrefixCnt + 1;
  1128.             break;
  1129.           case eModS:
  1130.             BAsmCode[PrefixCnt] = 0x9e;
  1131.             CodeLen = PrefixCnt + 1;
  1132.             break;
  1133.           case eModISP8: /* irregular, cannot use default case */
  1134.             BAsmCode[PrefixCnt] = 0x7b;
  1135.             CompleteCode(&SrcAdrVals);
  1136.             break;
  1137.           default:
  1138.             BAsmCode[PrefixCnt] = 0x06 + (SrcAdrVals.Part << 4);
  1139.             CompleteCode(&SrcAdrVals);
  1140.         }
  1141.         break;
  1142.       case eModX:
  1143.         if (pCurrCPUProps->Core == eCoreSTM8)
  1144.           OpSize = eSymbolSize16Bit;
  1145.         Mask = ConstructMask(MModA | MModY | MModS | MModImm
  1146.                            | MModAbs8 | MModAbs16
  1147.                            | MModIX | MModIX8 | MModIX16 | MModISP8
  1148.                            | MModIAbs8 | MModIAbs16 | MModI16Abs16
  1149.                            | MModIXAbs8 | MModIXAbs16 | MModI16XAbs16, OpSize);
  1150.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1151.         switch (SrcAdrVals.Mode)
  1152.         {
  1153.           case eModA:
  1154.             BAsmCode[PrefixCnt] = 0x97;
  1155.             CodeLen = PrefixCnt + 1;
  1156.             break;
  1157.           case eModY:
  1158.             BAsmCode[0] = 0x93;
  1159.             CodeLen = 1;
  1160.             break;
  1161.           case eModS:
  1162.             BAsmCode[PrefixCnt] = 0x96;
  1163.             CodeLen = PrefixCnt + 1;
  1164.             break;
  1165.           default:
  1166.             BAsmCode[PrefixCnt] = 0x0e + (SrcAdrVals.Part << 4); /* ANSI :-O */
  1167.             CompleteCode(&SrcAdrVals);
  1168.         }
  1169.         break;
  1170.       case eModXL:
  1171.       case eModYL:
  1172.         if (DecodeAdr(&ArgStr[2], MModA, False, &SrcAdrVals))
  1173.         {
  1174.           BAsmCode[PrefixCnt] = 0x97;
  1175.           CodeLen = PrefixCnt + 1;
  1176.         }
  1177.         break;
  1178.       case eModXH:
  1179.       case eModYH:
  1180.         if (DecodeAdr(&ArgStr[2], MModA, False, &SrcAdrVals))
  1181.         {
  1182.           BAsmCode[PrefixCnt] = 0x95;
  1183.           CodeLen = PrefixCnt + 1;
  1184.         }
  1185.         break;
  1186.       case eModY:
  1187.         PrefixCnt = 0;
  1188.         if (pCurrCPUProps->Core == eCoreSTM8)
  1189.           OpSize = eSymbolSize16Bit;
  1190.         Mask = ConstructMask(MModA | MModX | MModS | MModImm
  1191.                            | MModAbs8 | MModAbs16
  1192.                            | MModIY | MModIY8 | MModIY16 | MModISP8
  1193.                            | MModIAbs8 | MModIAbs16 | MModIYAbs8 | MModIYAbs16, OpSize);
  1194.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1195.         switch (SrcAdrVals.Mode)
  1196.         {
  1197.           case eModA:
  1198.             AddPrefix(0x90);
  1199.             BAsmCode[PrefixCnt] = 0x97;
  1200.             CodeLen = PrefixCnt + 1;
  1201.             break;
  1202.           case eModX:
  1203.             AddPrefix(0x90);
  1204.             BAsmCode[PrefixCnt] = 0x93;
  1205.             CodeLen = PrefixCnt + 1;
  1206.             break;
  1207.           case eModS:
  1208.             AddPrefix(0x90);
  1209.             BAsmCode[PrefixCnt] = 0x96;
  1210.             CodeLen = PrefixCnt + 1;
  1211.             break;
  1212.           case eModISP8:
  1213.             BAsmCode[PrefixCnt] = 0x16;
  1214.             goto common;
  1215.           default:
  1216.             if (PrefixCnt == 0) AddPrefix(0x90);
  1217.             if (BAsmCode[0] == 0x92) BAsmCode[0]--;
  1218.             BAsmCode[PrefixCnt] = 0x0e + (SrcAdrVals.Part << 4); /* ANSI :-O */
  1219.           common:
  1220.             CompleteCode(&SrcAdrVals);
  1221.         }
  1222.         break;
  1223.       case eModS:
  1224.         if (DecodeAdr(&ArgStr[2], MModA | MModX | MModY, False, &SrcAdrVals))
  1225.         switch (SrcAdrVals.Mode)
  1226.         {
  1227.           case eModA:
  1228.             BAsmCode[PrefixCnt] = 0x95;
  1229.             CodeLen = PrefixCnt + 1;
  1230.             break;
  1231.           case eModX:
  1232.           case eModY:
  1233.             BAsmCode[PrefixCnt] = 0x94;
  1234.             CodeLen = PrefixCnt + 1;
  1235.             break;
  1236.           default:
  1237.             break;
  1238.         }
  1239.         break;
  1240.       default:
  1241.       {
  1242.         Boolean Result;
  1243.         unsigned SavePrefixCnt = PrefixCnt;
  1244.  
  1245.         /* set unknown size to allow X&Y also on STM8 if LD is written instead of LDW */
  1246.         Mask = ConstructMask(MModA | MModX | MModY, eSymbolSizeUnknown);
  1247.         /* aliases for MOV */
  1248.         if (pCurrCPUProps->Core == eCoreSTM8)
  1249.           switch (DestAdrVals.Mode)
  1250.           {
  1251.             case eModAbs16:
  1252.               Mask |= MModAbs16 | MModImm;
  1253.               break;
  1254.             case eModAbs8:
  1255.               Mask |= MModAbs8 | MModAbs16 | MModImm;
  1256.               break;
  1257.             default:
  1258.               break;
  1259.           }
  1260.         Result = DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals);
  1261.         PrefixCnt = SavePrefixCnt;
  1262.         if (Result)
  1263.         switch (SrcAdrVals.Mode)
  1264.         {
  1265.           case eModA:
  1266.             Mask = ConstructMask(MModAbs8 | MModAbs16
  1267.                                | MModIX | MModIX8 | MModIX16 | MModIY | MModIY8 | MModIY16 | MModISP8
  1268.                                | MModIAbs8 | MModIAbs16 | MModI16Abs16 | MModIXAbs8 | MModIXAbs16 | MModI16XAbs16 | MModIYAbs8 | MModIYAbs16, eSymbolSize8Bit);
  1269.             if (ChkAdrValsMode(&DestAdrVals, Mask, ErrNum_InvAddrMode, &ArgStr[1]))
  1270.             {
  1271.               BAsmCode[PrefixCnt] = (DestAdrVals.Mode == eModISP8) ? 0x6b : (0x07 + (DestAdrVals.Part << 4));
  1272.               CompleteCode(&DestAdrVals);
  1273.             }
  1274.             break;
  1275.           case eModX:
  1276.             Mask = MModAbs8 | MModAbs16 | MModIAbs16;
  1277.             if (pCurrCPUProps->Core == eCoreST7)
  1278.               Mask |= MModIX | MModIX8 | MModIX16 | MModIAbs8 | MModIXAbs8 | MModIXAbs16;
  1279.             if (pCurrCPUProps->Core == eCoreSTM8)
  1280.               Mask |= MModIY | MModIY8 | MModIY16 | MModIYAbs16 | MModISP8 | MModI16Abs16;
  1281.             if (ChkAdrValsMode(&DestAdrVals, Mask, ErrNum_InvAddrMode, &ArgStr[1]))
  1282.             {
  1283.               BAsmCode[PrefixCnt] = 0x0f + (DestAdrVals.Part << 4);
  1284.               CompleteCode(&DestAdrVals);
  1285.             }
  1286.             break;
  1287.           case eModY:
  1288.             Mask = MModAbs8 | MModAbs16 | MModIAbs16;
  1289.             if (pCurrCPUProps->Core == eCoreST7)
  1290.               Mask |= MModIY | MModIY8 | MModIY16 | MModIAbs8 | MModIYAbs8 | MModIYAbs16;
  1291.             if (pCurrCPUProps->Core == eCoreSTM8)
  1292.               Mask |= MModIX | MModIX8 | MModIX16 | MModIXAbs16 | MModI16XAbs16 | MModISP8;
  1293.             if (ChkAdrValsMode(&DestAdrVals, Mask, ErrNum_InvAddrMode, &ArgStr[1]))
  1294.             switch (DestAdrVals.Mode)
  1295.             {
  1296.               case eModISP8:
  1297.                 PrefixCnt = 0;
  1298.                 BAsmCode[PrefixCnt] = 0x07 + (DestAdrVals.Part << 4);
  1299.                 goto common_ysrc2;
  1300.               case eModIX:
  1301.               case eModIX8:
  1302.               case eModIX16:
  1303.                 PrefixCnt = 0;
  1304.                 goto common_ysrc;
  1305.               case eModIXAbs16:
  1306.                 goto common_ysrc;
  1307.               default:
  1308.                 if (PrefixCnt == 0) AddPrefix(0x90);
  1309.                 if (BAsmCode[0] == 0x92) BAsmCode[0]--;
  1310.               common_ysrc:
  1311.                 BAsmCode[PrefixCnt] = 0x0f + (DestAdrVals.Part << 4);
  1312.               common_ysrc2:
  1313.                 CompleteCode(&DestAdrVals);
  1314.             }
  1315.             break;
  1316.           case eModImm: /* MOV aliases: only possible if Dest = Abs8/16 */
  1317.           case eModAbs8:
  1318.           case eModAbs16:
  1319.             WriteMOV(&DestAdrVals, &SrcAdrVals);
  1320.             break;
  1321.           default:
  1322.             break;
  1323.         }
  1324.       }
  1325.     }
  1326.   }
  1327. }
  1328.  
  1329. /*!------------------------------------------------------------------------
  1330.  * \fn     DecodeLDW(Word Code)
  1331.  * \brief  decode LDW instruction
  1332.  * ------------------------------------------------------------------------ */
  1333.  
  1334. static void DecodeLDW(Word Code)
  1335. {
  1336.   tAdrVals DestAdrVals, SrcAdrVals;
  1337.   LongWord Mask;
  1338.  
  1339.   UNUSED(Code);
  1340.   if (!ChkArgCnt(2, 2));
  1341.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1342.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1343.   else
  1344.   {
  1345.     Mask = ConstructMask(MModX | MModY | MModS
  1346.                        | MModAbs8 | MModAbs16
  1347.                        | MModIX | MModIX8 | MModIX16 | MModIY | MModIY8 | MModIY16 | MModISP8
  1348.                        | MModIAbs16 | MModI16Abs16 | MModIXAbs16 | MModI16XAbs16 | MModIYAbs16, OpSize = eSymbolSize16Bit);
  1349.     if (DecodeAdr(&ArgStr[1], Mask, False, &DestAdrVals))
  1350.     switch (DestAdrVals.Mode)
  1351.     {
  1352.       case eModX:
  1353.         Mask = ConstructMask(MModY | MModS | MModImm
  1354.                            | MModAbs8 | MModAbs16
  1355.                            | MModIX | MModIX8 | MModIX16 | MModISP8
  1356.                            | MModIAbs16 | MModI16Abs16 | MModIXAbs16 | MModI16XAbs16, eSymbolSize16Bit);
  1357.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1358.         switch (SrcAdrVals.Mode)
  1359.         {
  1360.           case eModY:
  1361.             PrefixCnt = 0;
  1362.             BAsmCode[PrefixCnt] = 0x93;
  1363.             CodeLen = PrefixCnt + 1;
  1364.             break;
  1365.           case eModS:
  1366.             BAsmCode[PrefixCnt] = 0x96;
  1367.             CodeLen = PrefixCnt + 1;
  1368.             break;
  1369.           default:
  1370.             BAsmCode[PrefixCnt] = 0x0e | (SrcAdrVals.Part << 4);
  1371.             CompleteCode(&SrcAdrVals);
  1372.             break;
  1373.         }
  1374.         break;
  1375.       case eModY:
  1376.         PrefixCnt = 0;
  1377.         Mask = ConstructMask(MModX | MModS | MModImm
  1378.                            | MModAbs8 | MModAbs16
  1379.                            | MModIY | MModIY8 | MModIY16 | MModISP8
  1380.                            | MModIAbs16 | MModIYAbs16, eSymbolSize16Bit);
  1381.         DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals);
  1382.         if (!PrefixCnt)
  1383.           AddPrefix(0x90);
  1384.         if (SrcAdrVals.Mode != eModNone)
  1385.         switch (SrcAdrVals.Mode)
  1386.         {
  1387.           case eModX:
  1388.             BAsmCode[PrefixCnt] = 0x93;
  1389.             CodeLen = PrefixCnt + 1;
  1390.             break;
  1391.           case eModS:
  1392.             BAsmCode[PrefixCnt] = 0x96;
  1393.             CodeLen = PrefixCnt + 1;
  1394.             break;
  1395.           case eModISP8:
  1396.             PrefixCnt = 0;
  1397.             BAsmCode[PrefixCnt] = 0x16;
  1398.             goto common_x;
  1399.           case eModIAbs16:
  1400.             PrefixCnt = 0;
  1401.             AddPrefix(0x91);
  1402.             /* fall-through */
  1403.           default:
  1404.             BAsmCode[PrefixCnt] = 0x0e | (SrcAdrVals.Part << 4);
  1405.           common_x:
  1406.             CompleteCode(&SrcAdrVals);
  1407.             break;
  1408.         }
  1409.         break;
  1410.       case eModS:
  1411.         Mask = ConstructMask(MModX | MModY, eSymbolSize16Bit);
  1412.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1413.         {
  1414.           BAsmCode[PrefixCnt] = 0x94;
  1415.           CodeLen = PrefixCnt + 1;
  1416.         }
  1417.         break;
  1418.       default:
  1419.       {
  1420.         Mask = ConstructMask(MModX | MModY, eSymbolSize16Bit);
  1421.         if (DecodeReg(&ArgStr[2], &SrcAdrVals.Mode, Mask))
  1422.         switch (DestAdrVals.Mode)
  1423.         {
  1424.           case eModIAbs16:
  1425.             if (eModY == SrcAdrVals.Mode)
  1426.             {
  1427.               PrefixCnt = 0;
  1428.               AddPrefix(0x91);
  1429.             }
  1430.             goto common_y2;
  1431.           case eModISP8:
  1432.             BAsmCode[PrefixCnt] = (eModY == SrcAdrVals.Mode) ? 0x17 : 0x1f;
  1433.             goto common_y;
  1434.           case eModAbs8:
  1435.           case eModAbs16:
  1436.             if (eModY == SrcAdrVals.Mode)
  1437.               AddPrefix(0x90);
  1438.             /* fall-through */
  1439.           default:
  1440.           common_y2:
  1441.             BAsmCode[PrefixCnt] = 0x0f | (DestAdrVals.Part << 4);
  1442.           common_y:
  1443.             CompleteCode(&DestAdrVals);
  1444.             break;
  1445.         }
  1446.         break;
  1447.       }
  1448.     }
  1449.   }
  1450. }
  1451.  
  1452. /*!------------------------------------------------------------------------
  1453.  * \fn     DecodeLDF(Word Code)
  1454.  * \brief  decode LDF instruction
  1455.  * ------------------------------------------------------------------------ */
  1456.  
  1457. static void DecodeLDF(Word Code)
  1458. {
  1459.   tAdrVals AdrVals;
  1460.  
  1461.   UNUSED(Code);
  1462.   if (!ChkArgCnt(2, 2));
  1463.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1464.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1465.   else if (DecodeAdr(&ArgStr[1], MModA | MModAbs24 | MModIX24 | MModIY24 | MModI16XAbs24 | MModI16YAbs24 | MModI16Abs24, False, &AdrVals))
  1466.   switch (AdrVals.Mode)
  1467.   {
  1468.     case eModA:
  1469.       if (DecodeAdr(&ArgStr[2], MModAbs24 | MModIX24 | MModIY24 | MModI16XAbs24 | MModI16YAbs24 | MModI16Abs24, False, &AdrVals))
  1470.       {
  1471.         switch (AdrVals.Mode)
  1472.         {
  1473.           case eModAbs24:
  1474.           case eModI16Abs24:
  1475.             BAsmCode[PrefixCnt] = 0x0c | (AdrVals.Part << 4);
  1476.             break;
  1477.           case eModIX24:
  1478.           case eModIY24:
  1479.           case eModI16XAbs24:
  1480.           case eModI16YAbs24:
  1481.             BAsmCode[PrefixCnt] = 0x0f | (AdrVals.Part << 4);
  1482.             break;
  1483.           default:
  1484.             break;
  1485.         }
  1486.         CompleteCode(&AdrVals);
  1487.       }
  1488.       break;
  1489.     default:
  1490.     {
  1491.       tAdrMode RegMode;
  1492.  
  1493.       if (DecodeReg(&ArgStr[2], &RegMode, MModA))
  1494.       {
  1495.         switch (AdrVals.Mode)
  1496.         {
  1497.           case eModAbs24:
  1498.           case eModI16Abs24:
  1499.             BAsmCode[PrefixCnt] = 0x0d | (AdrVals.Part << 4);
  1500.             break;
  1501.           case eModIX24:
  1502.           case eModIY24:
  1503.           case eModI16XAbs24:
  1504.           case eModI16YAbs24:
  1505.             BAsmCode[PrefixCnt] = 0x07 | (AdrVals.Part << 4);
  1506.             break;
  1507.           default:
  1508.             break;
  1509.         }
  1510.         CompleteCode(&AdrVals);
  1511.       }
  1512.       break;
  1513.     }
  1514.   }
  1515. }
  1516.  
  1517. /*!------------------------------------------------------------------------
  1518.  * \fn     DecodeMOV(Word Code)
  1519.  * \brief  decode MOV instruction
  1520.  * ------------------------------------------------------------------------ */
  1521.  
  1522. static void DecodeMOV(Word Code)
  1523. {
  1524.   tAdrVals SrcAdrVals, DestAdrVals;
  1525.  
  1526.   UNUSED(Code);
  1527.   if (!ChkArgCnt(2, 2));
  1528.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1529.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1530.   else if (DecodeAdr(&ArgStr[2], MModImm | MModAbs8 | MModAbs16, False, &SrcAdrVals))
  1531.   {
  1532.     if (DecodeAdr(&ArgStr[1], ((SrcAdrVals.Mode == eModAbs8) ? MModAbs8 : 0) | MModAbs16, False, &DestAdrVals))
  1533.       WriteMOV(&DestAdrVals, &SrcAdrVals);
  1534.   }
  1535. }
  1536.  
  1537. /*!------------------------------------------------------------------------
  1538.  * \fn     DecodePUSH_POP(Word Code)
  1539.  * \brief  decode PUSH(W)/POP(W) instructions
  1540.  * \param  Code instruction context
  1541.  * ------------------------------------------------------------------------ */
  1542.  
  1543. static void DecodePUSH_POP(Word Code)
  1544. {
  1545.   if (!ChkArgCnt(1, 1));
  1546.   else if (Hi(Code) && (pCurrCPUProps->Core != eCoreSTM8)) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1547.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1548.   else
  1549.   {
  1550.     LongWord Mask;
  1551.     tAdrVals AdrVals;
  1552.  
  1553.     Mask = MModX | MModY | (Hi(Code) ? 0 : MModA);
  1554.     if (pCurrCPUProps->Core == eCoreSTM8)
  1555.     {
  1556.       Mask |= MModAbs16;
  1557.       if (Lo(Code))
  1558.         Mask |= MModImm;
  1559.     }
  1560.     if (!as_strcasecmp(ArgStr[1].str.p_str, "CC"))
  1561.     {
  1562.       BAsmCode[PrefixCnt] = 0x86 + Lo(Code);
  1563.       CodeLen = PrefixCnt + 1;
  1564.     }
  1565.     else if (DecodeAdr(&ArgStr[1], Mask, False, &AdrVals))
  1566.     {
  1567.       switch (AdrVals.Mode)
  1568.       {
  1569.         case eModA:
  1570.           BAsmCode[PrefixCnt] = 0x84 + Lo(Code);
  1571.           break;
  1572.         case eModX:
  1573.         case eModY:
  1574.           BAsmCode[PrefixCnt] = 0x85 + Lo(Code);
  1575.           break;
  1576.         case eModAbs16:
  1577.           BAsmCode[PrefixCnt] = Lo(Code) ? 0x4b : 0x32;
  1578.           break;
  1579.         case eModImm:
  1580.           BAsmCode[PrefixCnt] = 0x4b;
  1581.           break;
  1582.         default:
  1583.           break;
  1584.       }
  1585.       CompleteCode(&AdrVals);
  1586.     }
  1587.   }
  1588. }
  1589.  
  1590. /*!------------------------------------------------------------------------
  1591.  * \fn     DecodeCP(Word Code)
  1592.  * \brief  decode CP(W) instructions
  1593.  * \param  IsCPW 1 if CPW
  1594.  * ------------------------------------------------------------------------ */
  1595.  
  1596. static void DecodeCP(Word IsCPW)
  1597. {
  1598.   LongWord Mask;
  1599.  
  1600.   if (!ChkArgCnt(2, 2));
  1601.   else if (IsCPW && (pCurrCPUProps->Core != eCoreSTM8)) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1602.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1603.   else
  1604.   {
  1605.     tAdrVals SrcAdrVals;
  1606.     tAdrMode DestMode;
  1607.  
  1608.     if (DecodeReg(&ArgStr[1], &DestMode, (IsCPW ? 0 : MModA) | MModX | MModY))
  1609.     switch (DestMode)
  1610.     {
  1611.       case eModA:
  1612.         Mask = ConstructMask(MModImm | MModAbs8 | MModAbs16
  1613.                            | MModIX | MModIX8 | MModIX16 | MModIY | MModIY8 | MModIY16 | MModISP8
  1614.                            | MModIAbs8 | MModIAbs16 | MModI16Abs16
  1615.                            | MModIXAbs8 | MModIXAbs16 | MModI16XAbs16 | MModIYAbs8 | MModIYAbs16, eSymbolSize8Bit);
  1616.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1617.         {
  1618.           BAsmCode[PrefixCnt] = 0x01 + (SrcAdrVals.Part << 4);
  1619.           CompleteCode(&SrcAdrVals);
  1620.         }
  1621.         break;
  1622.       case eModX:
  1623.         Mask = MModImm | MModAbs8 | MModAbs16 | MModIAbs16;
  1624.         if (pCurrCPUProps->Core == eCoreST7)
  1625.           Mask |= MModIAbs8 | MModIXAbs8 | MModIX | MModIX8 | MModIX16 | MModIXAbs16;
  1626.         if (pCurrCPUProps->Core == eCoreSTM8)
  1627.         {
  1628.           Mask |= MModIY | MModIY8 | MModIY16 | MModISP8 | MModI16Abs16 | MModIYAbs16;
  1629.           OpSize = eSymbolSize16Bit;
  1630.         }
  1631.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1632.         {
  1633.           BAsmCode[PrefixCnt] = 0x03 + (SrcAdrVals.Part << 4);
  1634.           CompleteCode(&SrcAdrVals);
  1635.         }
  1636.         break;
  1637.       case eModY:
  1638.         PrefixCnt = 0;
  1639.         Mask = MModImm | MModAbs8 | MModAbs16 | MModIAbs16;
  1640.         if (pCurrCPUProps->Core == eCoreST7)
  1641.           Mask |= MModIAbs8 | MModIYAbs8 | MModIY | MModIY8 | MModIY16 | MModIYAbs16;
  1642.         if (pCurrCPUProps->Core == eCoreSTM8)
  1643.         {
  1644.           Mask |= MModIX | MModIX8 | MModIX16 | MModIXAbs16 | MModI16XAbs16;
  1645.           OpSize = eSymbolSize16Bit;
  1646.         }
  1647.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1648.         switch (SrcAdrVals.Mode)
  1649.         {
  1650.           case eModIXAbs16:
  1651.           case eModIX:
  1652.           case eModIX8:
  1653.           case eModIX16:
  1654.             goto common;
  1655.           default:
  1656.             if (PrefixCnt == 0) AddPrefix(0x90);
  1657.             if (BAsmCode[0] == 0x92) BAsmCode[0]--;
  1658.           common:
  1659.             BAsmCode[PrefixCnt] = 0x03 + (SrcAdrVals.Part << 4);
  1660.             CompleteCode(&SrcAdrVals);
  1661.         }
  1662.         break;
  1663.       default:
  1664.         break;
  1665.     }
  1666.   }
  1667. }
  1668.  
  1669. /*!------------------------------------------------------------------------
  1670.  * \fn     DecodeAri16(Word Code)
  1671.  * \brief  decode 16-bit arithmetic/logic instructions with two operands
  1672.  * \param  Code instruction code
  1673.  * ------------------------------------------------------------------------ */
  1674.  
  1675. static void DecodeAri16(Word Code)
  1676. {
  1677.   tAdrVals SrcAdrVals, DestAdrVals;
  1678.  
  1679.   if (!ChkArgCnt(2, 2));
  1680.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1681.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1682.   else if (DecodeAdr(&ArgStr[1], MModX | MModY | MModS, False, &DestAdrVals))
  1683.   switch (DestAdrVals.Mode)
  1684.   {
  1685.     case eModX:
  1686.     case eModY:
  1687.       OpSize = eSymbolSize16Bit;
  1688.       if (DecodeAdr(&ArgStr[2], MModImm | MModAbs16 | MModISP8, False, &SrcAdrVals))
  1689.       switch (SrcAdrVals.Mode)
  1690.       {
  1691.         case eModImm:
  1692.           if (PrefixCnt)
  1693.           {
  1694.             BAsmCode[PrefixCnt - 1] = 0x72;
  1695.             BAsmCode[PrefixCnt] = 0xa0 | Hi(Code);
  1696.           }
  1697.           else
  1698.             BAsmCode[PrefixCnt] = 0x1d - !!Lo(Code);
  1699.           goto common;
  1700.         case eModAbs16:
  1701.           if (PrefixCnt)
  1702.           {
  1703.             BAsmCode[PrefixCnt - 1] = 0x72;
  1704.             BAsmCode[PrefixCnt] = 0xb0 | Hi(Code);
  1705.           }
  1706.           else
  1707.           {
  1708.             BAsmCode[PrefixCnt++] = 0x72;
  1709.             BAsmCode[PrefixCnt] = 0xb0 | Lo(Code);
  1710.           }
  1711.           goto common;
  1712.         case eModISP8:
  1713.           if (PrefixCnt)
  1714.           {
  1715.             BAsmCode[PrefixCnt - 1] = 0x72;
  1716.             BAsmCode[PrefixCnt] = 0xf0 | Hi(Code);
  1717.           }
  1718.           else
  1719.           {
  1720.             BAsmCode[PrefixCnt++] = 0x72;
  1721.             BAsmCode[PrefixCnt] = 0xf0 | Lo(Code);
  1722.           }
  1723.           goto common;
  1724.         common:
  1725.           CompleteCode(&SrcAdrVals);
  1726.           break;
  1727.         default:
  1728.           break;
  1729.       }
  1730.       break;
  1731.     case eModS:
  1732.       OpSize = eSymbolSize8Bit;
  1733.       if (DecodeAdr(&ArgStr[2], MModImm, False, &SrcAdrVals))
  1734.       {
  1735.         BAsmCode[0] = 0x52 | Lo(Code);
  1736.         BAsmCode[1] = SrcAdrVals.Vals[0];
  1737.         CodeLen = 2;
  1738.       }
  1739.       break;
  1740.     default:
  1741.       break;
  1742.   }
  1743. }
  1744.  
  1745. /*!------------------------------------------------------------------------
  1746.  * \fn     DecodeAri(Word Code)
  1747.  * \brief  decode 8-bit arithmetic/logic instructions with two operands
  1748.  * \param  Code instruction code
  1749.  * ------------------------------------------------------------------------ */
  1750.  
  1751. static void DecodeAri(Word Code)
  1752. {
  1753.   tAdrVals SrcAdrVals, DestAdrVals;
  1754.   LongWord Mask;
  1755.   Word Code16 = 0;
  1756.  
  1757.   if (!ChkArgCnt(2, 2));
  1758.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1759.   else
  1760.   {
  1761.     Mask = MModA;
  1762.     if (pCurrCPUProps->Core == eCoreSTM8)
  1763.       switch (Lo(Code))
  1764.       {
  1765.         case 0x00: /* SUB->SUBW */
  1766.           Code16 = 0x0200;
  1767.           Mask |= MModS | MModX | MModY;
  1768.           break;
  1769.         case 0x0b: /* ADD->ADDW */
  1770.           Code16 = 0x090b;
  1771.           Mask |= MModS | MModX | MModY;
  1772.           break;
  1773.       }
  1774.     if (DecodeAdr(&ArgStr[1], Mask, False, &DestAdrVals))
  1775.     switch (DestAdrVals.Mode)
  1776.     {
  1777.       case eModA:
  1778.         Mask = MModAbs8 | MModAbs16 | MModIX | MModIX8 | MModIX16 | MModIY |
  1779.                MModIY8 | MModIY16 | MModIAbs16 | MModIXAbs16 | MModIYAbs16;
  1780.         if (pCurrCPUProps->Core == eCoreST7)
  1781.           Mask |= MModIAbs8 | MModIXAbs8 | MModIYAbs8;
  1782.         if (pCurrCPUProps->Core == eCoreSTM8)
  1783.           Mask |= MModISP8 | MModI16Abs16 | MModI16XAbs16;
  1784.         if (Hi(Code)) Mask |= MModImm;
  1785.         if (DecodeAdr(&ArgStr[2], Mask, False, &SrcAdrVals))
  1786.         {
  1787.           BAsmCode[PrefixCnt] = Lo(Code) + (SrcAdrVals.Part << 4);
  1788.           CompleteCode(&SrcAdrVals);
  1789.         }
  1790.         break;
  1791.       case eModS:
  1792.       case eModX:
  1793.       case eModY:
  1794.         PrefixCnt = 0;
  1795.         DecodeAri16(Code16);
  1796.       default:
  1797.         break;
  1798.     }
  1799.   }
  1800. }
  1801.  
  1802. /*!------------------------------------------------------------------------
  1803.  * \fn     DecodeRMW(Word Code)
  1804.  * \brief  decode 8-bit read/modify/write instructions with one operand
  1805.  * \param  Code instruction code
  1806.  * ------------------------------------------------------------------------ */
  1807.  
  1808. static void DecodeRMW(Word Code)
  1809. {
  1810.   Boolean IsW = Hi(Code);
  1811.  
  1812.   Code = Lo(Code);
  1813.   if (!ChkArgCnt(1, 1));
  1814.   else if (IsW && (pCurrCPUProps->Core != eCoreSTM8)) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1815.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1816.   else
  1817.   {
  1818.     LongWord Mask;
  1819.     tAdrVals AdrVals;
  1820.  
  1821.     Mask = MModX | MModY;
  1822.     if (!IsW)
  1823.     {
  1824.       Mask |= MModA |  MModAbs8
  1825.             | MModIX | MModIX8 | MModIY | MModIY8;
  1826.       if (pCurrCPUProps->Core == eCoreST7)
  1827.         Mask |= MModIAbs8 | MModIXAbs8 | MModIYAbs8;
  1828.       if (pCurrCPUProps->Core == eCoreSTM8)
  1829.         Mask |= MModAbs16 | MModIX16 | MModIY16 | MModISP8
  1830.               | MModIAbs16 | MModI16Abs16 | MModIXAbs16 | MModI16XAbs16 | MModIYAbs16;
  1831.     }
  1832.     if (DecodeAdr(&ArgStr[1], Mask, False, &AdrVals))
  1833.     switch (AdrVals.Mode)
  1834.     {
  1835.       case eModA:
  1836.         BAsmCode[PrefixCnt] = 0x40 + Code;
  1837.         CodeLen = PrefixCnt + 1;
  1838.         break;
  1839.       case eModX:
  1840.       case eModY:
  1841.         BAsmCode[PrefixCnt] = 0x50 + Code;
  1842.         CodeLen = PrefixCnt + 1;
  1843.         break;
  1844.       case eModAbs16:
  1845.         BAsmCode[PrefixCnt++] = 0x72;
  1846.         BAsmCode[PrefixCnt] = 0x50 | Code;
  1847.         goto common;
  1848.       case eModIX16:
  1849.         BAsmCode[PrefixCnt++] = 0x72;
  1850.         BAsmCode[PrefixCnt] = 0x40 | Code;
  1851.         goto common;
  1852.       case eModIY16:
  1853.         BAsmCode[PrefixCnt] = 0x40 | Code;
  1854.         goto common;
  1855.       case eModISP8:
  1856.         BAsmCode[PrefixCnt] = 0x00 | Code;
  1857.         goto common;
  1858.       case eModIAbs16:
  1859.       case eModI16Abs16:
  1860.         BAsmCode[PrefixCnt] = 0x30 | Code;
  1861.         goto common;
  1862.       case eModIXAbs16:
  1863.       case eModI16XAbs16:
  1864.       case eModIYAbs16:
  1865.         BAsmCode[PrefixCnt] = 0x60 | Code;
  1866.         goto common;
  1867.       default:
  1868.         BAsmCode[PrefixCnt] = Code + ((AdrVals.Part - 8) << 4);
  1869.         /* fall-through */
  1870.       common:
  1871.         CompleteCode(&AdrVals);
  1872.     }
  1873.   }
  1874. }
  1875.  
  1876. /*!------------------------------------------------------------------------
  1877.  * \fn     DecodeMUL(Word Code)
  1878.  * \brief  decode MUL instruction
  1879.  * ------------------------------------------------------------------------ */
  1880.  
  1881. static void DecodeMUL(Word Code)
  1882. {
  1883.   UNUSED(Code);
  1884.  
  1885.   if (!ChkArgCnt(2, 2));
  1886.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1887.   else
  1888.   {
  1889.     tAdrMode SrcMode;
  1890.     tAdrVals DestVals;
  1891.  
  1892.     if (DecodeReg(&ArgStr[2], &SrcMode, MModA)
  1893.      && DecodeAdr(&ArgStr[1], MModX | MModY, False, &DestVals))
  1894.     {
  1895.       BAsmCode[PrefixCnt] = 0x42;
  1896.       CodeLen = PrefixCnt + 1;
  1897.     }
  1898.   }
  1899. }
  1900.  
  1901. /*!------------------------------------------------------------------------
  1902.  * \fn     DecodeDIV(Word Code)
  1903.  * \brief  decode DIV(W) instructions
  1904.  * \param  IsW True if DIVW
  1905.  * ------------------------------------------------------------------------ */
  1906.  
  1907. static void DecodeDIV(Word IsW)
  1908. {
  1909.   tAdrVals DestAdrVals, SrcAdrVals;
  1910.  
  1911.   if (!ChkArgCnt(2, 2));
  1912.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1913.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1914.   else if (DecodeAdr(&ArgStr[1], MModX | (IsW ? 0 : MModY), False, &DestAdrVals)
  1915.         && DecodeAdr(&ArgStr[2], MModY | (IsW ? 0 : MModA), False, &SrcAdrVals))
  1916.   {
  1917.     BAsmCode[PrefixCnt] = (SrcAdrVals.Mode == eModA) ? 0x62 : 0x65;
  1918.     CodeLen = PrefixCnt + 1;
  1919.   }
  1920. }
  1921.  
  1922. /*!------------------------------------------------------------------------
  1923.  * \fn     DecodeEXG(Word Code)
  1924.  * \brief  decode EXG(W) instructions
  1925.  * \param  IsW True if EXGW
  1926.  * ------------------------------------------------------------------------ */
  1927.  
  1928. static void DecodeEXG(Word IsW)
  1929. {
  1930.   tAdrVals DestAdrVals, SrcAdrVals;
  1931.  
  1932.   if (!ChkArgCnt(2, 2));
  1933.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  1934.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  1935.   else if (DecodeAdr(&ArgStr[1], (IsW ? 0 : (MModA | MModXL | MModYL | MModAbs16)) | MModX | MModY, False, &DestAdrVals))
  1936.   switch (DestAdrVals.Mode)
  1937.   {
  1938.     case eModA:
  1939.       if (DecodeAdr(&ArgStr[2], MModXL | MModYL | MModAbs16, False, &SrcAdrVals))
  1940.       switch (SrcAdrVals.Mode)
  1941.       {
  1942.         case eModXL:
  1943.           BAsmCode[0] = 0x41;
  1944.           CodeLen = 1;
  1945.           break;
  1946.         case eModYL:
  1947.           BAsmCode[0] = 0x61;
  1948.           CodeLen = 1;
  1949.           break;
  1950.         case eModAbs16:
  1951.           BAsmCode[0] = 0x31;
  1952.           CompleteCode(&SrcAdrVals);
  1953.           break;
  1954.         default:
  1955.           break;
  1956.       }
  1957.       break;
  1958.     case eModXL:
  1959.       if (DecodeAdr(&ArgStr[2], MModA, False, &SrcAdrVals))
  1960.       {
  1961.         BAsmCode[0] = 0x41;
  1962.         CodeLen = 1;
  1963.       }
  1964.       break;
  1965.     case eModYL:
  1966.       if (DecodeAdr(&ArgStr[2], MModA, False, &SrcAdrVals))
  1967.       {
  1968.         BAsmCode[0] = 0x61;
  1969.         CodeLen = 1;
  1970.       }
  1971.       break;
  1972.     case eModAbs16:
  1973.       if (DecodeAdr(&ArgStr[2], MModA, False, &SrcAdrVals))
  1974.       {
  1975.         BAsmCode[0] = 0x31;
  1976.         memcpy(&BAsmCode[1], SrcAdrVals.Vals, SrcAdrVals.Cnt);
  1977.         CodeLen = 3;
  1978.       }
  1979.       break;
  1980.     case eModX:
  1981.       if (DecodeAdr(&ArgStr[2], MModY, False, &SrcAdrVals))
  1982.       {
  1983.         BAsmCode[0] = 0x51;
  1984.         CodeLen = 1;
  1985.       }
  1986.       break;
  1987.     case eModY:
  1988.       if (DecodeAdr(&ArgStr[2], MModX, False, &SrcAdrVals))
  1989.       {
  1990.         BAsmCode[0] = 0x51;
  1991.         CodeLen = 1;
  1992.       }
  1993.       break;
  1994.     default:
  1995.       break;
  1996.   }
  1997. }
  1998.  
  1999. /*!------------------------------------------------------------------------
  2000.  * \fn     DecodeBitOp(Word Code)
  2001.  * \brief  decode bit operation instructions
  2002.  * \param  Code instruction code
  2003.  * ------------------------------------------------------------------------ */
  2004.  
  2005. static void DecodeBitOp(Word Code)
  2006. {
  2007.   Byte BitPos;
  2008.   tAdrVals AdrVals;
  2009.  
  2010.   if (!ChkArgCnt(1, 2));
  2011.   else if ((Hi(Code == 0x90)) && (pCurrCPUProps->Core != eCoreSTM8)) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  2012.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  2013.   else if (DecodeBitAdrWithIndir(1, ArgCnt, &BitPos, &AdrVals))
  2014.   {
  2015.     if (pCurrCPUProps->Core == eCoreSTM8)
  2016.     {
  2017.       PrefixCnt = 0;
  2018.       AddPrefix(Hi(Code));
  2019.       BAsmCode[PrefixCnt] = 0x10 | (BitPos << 1) | (Code & 1);
  2020.     }
  2021.     else
  2022.       BAsmCode[PrefixCnt] = Lo(Code) + (BitPos << 1);
  2023.     CompleteCode(&AdrVals);
  2024.   }
  2025. }
  2026.  
  2027. /*!------------------------------------------------------------------------
  2028.  * \fn     DecodeBTJF_BTJT(Word Code)
  2029.  * \brief  decode BTJF/BTJT instructions
  2030.  * \param  Code instruction code
  2031.  * ------------------------------------------------------------------------ */
  2032.  
  2033. static void DecodeBTJF_BTJT(Word Code)
  2034. {
  2035.   Byte BitPos;
  2036.   tAdrVals AdrVals;
  2037.  
  2038.   if (!ChkArgCnt(2, 3));
  2039.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  2040.   else if (DecodeBitAdrWithIndir(1, ArgCnt - 1, &BitPos, &AdrVals))
  2041.   {
  2042.     Integer AdrInt;
  2043.     Boolean OK;
  2044.     tSymbolFlags Flags;
  2045.  
  2046.     if (pCurrCPUProps->Core == eCoreSTM8)
  2047.     {
  2048.       PrefixCnt = 0;
  2049.       AddPrefix(0x72);
  2050.     }
  2051.     BAsmCode[PrefixCnt] = Code + (BitPos << 1);
  2052.     memcpy(BAsmCode + 1 + PrefixCnt, AdrVals.Vals, AdrVals.Cnt);
  2053.     AdrInt = EvalStrIntExpressionWithFlags(&ArgStr[3], pCurrCPUProps->AddrIntType, &OK, &Flags) - (EProgCounter() + PrefixCnt + 1 + AdrVals.Cnt + 1);
  2054.     if (OK)
  2055.     {
  2056.       if (!mSymbolQuestionable(Flags) && ((AdrInt < -128) || (AdrInt > 127))) WrStrErrorPos(ErrNum_JmpDistTooBig, &ArgStr[3]);
  2057.       else
  2058.       {
  2059.         BAsmCode[PrefixCnt + 1 + AdrVals.Cnt] = AdrInt & 0xff;
  2060.         CodeLen = PrefixCnt + 1 + AdrVals.Cnt + 1;
  2061.       }
  2062.     }
  2063.   }
  2064. }
  2065.  
  2066. /*!------------------------------------------------------------------------
  2067.  * \fn     DecodeJP_CALL(Word Code)
  2068.  * \brief  decode JP/CALL instructions
  2069.  * \param  Code instruction code
  2070.  * ------------------------------------------------------------------------ */
  2071.  
  2072. static void DecodeJP_CALL(Word Code)
  2073. {
  2074.   if (!ChkArgCnt(1, 1));
  2075.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  2076.   else
  2077.   {
  2078.     LongWord Mask;
  2079.     tAdrVals AdrVals;
  2080.  
  2081.     Mask = ConstructMask(MModAbs8 | MModAbs16 | MModIX | MModIX8 | MModIX16 | MModIY
  2082.                        | MModIY8 | MModIY16 | MModIAbs8 | MModIAbs16 | MModI16Abs16
  2083.                        | MModIXAbs8 | MModIXAbs16 | MModI16XAbs16 | MModIYAbs8 | MModIYAbs16,
  2084.                          eSymbolSizeUnknown);
  2085.     if (DecodeAdr(&ArgStr[1], Mask, True, &AdrVals))
  2086.     {
  2087.       BAsmCode[PrefixCnt] = Code + (AdrVals.Part << 4);
  2088.       CompleteCode(&AdrVals);
  2089.     }
  2090.   }
  2091. }
  2092.  
  2093. /*!------------------------------------------------------------------------
  2094.  * \fn     DecodeJPF_CALLF(Word Code)
  2095.  * \brief  decode JPF/CALLF instructions
  2096.  * \param  Code instruction code
  2097.  * ------------------------------------------------------------------------ */
  2098.  
  2099. static void DecodeJPF_CALLF(Word Code)
  2100. {
  2101.   tAdrVals AdrVals;
  2102.  
  2103.   if (!ChkArgCnt(1, 1));
  2104.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  2105.   else if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  2106.   else if (DecodeAdr(&ArgStr[1], MModAbs24 | MModI16Abs24, True, &AdrVals))
  2107.   {
  2108.     BAsmCode[PrefixCnt] = Code;
  2109.     CompleteCode(&AdrVals);
  2110.   }
  2111. }
  2112.  
  2113. /*!------------------------------------------------------------------------
  2114.  * \fn     DecodeRel(Word Code)
  2115.  * \brief  decode relative branch instructions
  2116.  * \param  instruction code
  2117.  * ------------------------------------------------------------------------ */
  2118.  
  2119. static void DecodeRel(Word Code)
  2120. {
  2121.   if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  2122.   else if (!Code) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  2123.   else if (!ChkArgCnt(1, 1));
  2124.   else if (*ArgStr[1].str.p_str == '[')
  2125.   {
  2126.     if (pCurrCPUProps->Core != eCoreST7) WrStrErrorPos(ErrNum_InvAddrMode, &ArgStr[1]);
  2127.     else
  2128.     {
  2129.       tAdrVals AdrVals;
  2130.  
  2131.       if (DecodeAdr(&ArgStr[1], MModIAbs8, False, &AdrVals))
  2132.       {
  2133.         BAsmCode[PrefixCnt] = Lo(Code);
  2134.         CompleteCode(&AdrVals);
  2135.       }
  2136.     }
  2137.   }
  2138.   else
  2139.   {
  2140.     Boolean OK;
  2141.     Integer AdrInt;
  2142.     tSymbolFlags Flags;
  2143.  
  2144.     if (Hi(Code))
  2145.       BAsmCode[PrefixCnt++] = Hi(Code);
  2146.     AdrInt = EvalStrIntExpressionWithFlags(&ArgStr[1], pCurrCPUProps->AddrIntType, &OK, &Flags) - (EProgCounter() + 2 + PrefixCnt);
  2147.     if (OK)
  2148.     {
  2149.       if (!mSymbolQuestionable(Flags) && ((AdrInt < -128) || (AdrInt > 127))) WrStrErrorPos(ErrNum_JmpDistTooBig, &ArgStr[1]);
  2150.       else
  2151.       {
  2152.         BAsmCode[PrefixCnt] = Lo(Code);
  2153.         BAsmCode[PrefixCnt + 1] = AdrInt & 0xff;
  2154.         CodeLen = PrefixCnt + 2;
  2155.       }
  2156.     }
  2157.   }
  2158. }
  2159.  
  2160. /*!------------------------------------------------------------------------
  2161.  * \fn     DecodeRxWA(Word Code)
  2162.  * \brief  decode RLWA/RRWA instructions
  2163.  * \param  Code instruction code
  2164.  * ------------------------------------------------------------------------ */
  2165.  
  2166. static void DecodeRxWA(Word Code)
  2167. {
  2168.   tAdrMode SrcMode;
  2169.   tAdrVals DestAdrVals;
  2170.  
  2171.   if (*AttrPart.str.p_str) WrStrErrorPos(ErrNum_UseLessAttr, &AttrPart);
  2172.   else if (!ChkArgCnt(1, 2));
  2173.   else if (pCurrCPUProps->Core != eCoreSTM8) WrStrErrorPos(ErrNum_InstructionNotSupported, &OpPart);
  2174.   else if (((ArgCnt == 1) || DecodeReg(&ArgStr[2], &SrcMode, MModA)) && DecodeAdr(&ArgStr[1], MModX | MModY, False, &DestAdrVals))
  2175.   {
  2176.     BAsmCode[PrefixCnt] = Code;
  2177.     CodeLen = PrefixCnt + 1;
  2178.   }
  2179. }
  2180.  
  2181. /*!------------------------------------------------------------------------
  2182.  * \fn     DecodeBIT(Word Code)
  2183.  * \brief  decode BIT instruction
  2184.  * ------------------------------------------------------------------------ */
  2185.  
  2186. static void DecodeBIT(Word Code)
  2187. {
  2188.   LongWord BitSpec;
  2189.  
  2190.   UNUSED(Code);
  2191.  
  2192.   /* if in structure definition, add special element to structure */
  2193.  
  2194.   if (ActPC == StructSeg)
  2195.   {
  2196.     Boolean OK;
  2197.     Byte BitPos;
  2198.     PStructElem pElement;
  2199.  
  2200.     if (!ChkArgCnt(2, 2))
  2201.       return;
  2202.     BitPos = EvalBitPosition(&ArgStr[2], &OK);
  2203.     if (!OK)
  2204.       return;
  2205.     pElement = CreateStructElem(&LabPart);
  2206.     if (!pElement)
  2207.       return;
  2208.     pElement->pRefElemName = as_strdup(ArgStr[1].str.p_str);
  2209.     pElement->OpSize = eSymbolSize8Bit;
  2210.     pElement->BitPos = BitPos;
  2211.     pElement->ExpandFnc = ExpandST7Bit;
  2212.     AddStructElem(pInnermostNamedStruct->StructRec, pElement);
  2213.   }
  2214.   else
  2215.   {
  2216.     if (DecodeBitArg(&BitSpec, 1, ArgCnt))
  2217.     {
  2218.       *ListLine = '=';
  2219.       DissectBit_ST7(ListLine + 1, STRINGSIZE - 3, BitSpec);
  2220.       PushLocHandle(-1);
  2221.       EnterIntSymbol(&LabPart, BitSpec, SegBData, False);
  2222.       PopLocHandle();
  2223.       /* TODO: MakeUseList? */
  2224.     }
  2225.   }
  2226. }
  2227.  
  2228. /*--------------------------------------------------------------------------*/
  2229.  
  2230. /*!------------------------------------------------------------------------
  2231.  * \fn     InitFields(void)
  2232.  * \brief  build up hash table of instructions
  2233.  * ------------------------------------------------------------------------ */
  2234.  
  2235. static void AddFixed(const char *NName, Word NCode)
  2236. {
  2237.   AddInstTable(InstTable, NName, NCode, DecodeFixed);
  2238. }
  2239.  
  2240. static void AddAri(const char *NName, Word NCode, Boolean NMay)
  2241. {
  2242.   AddInstTable(InstTable, NName, NCode | (NMay << 8), DecodeAri);
  2243. }
  2244.  
  2245. static void AddAri16(const char *NName, Word NCode)
  2246. {
  2247.   AddInstTable(InstTable, NName, NCode, DecodeAri16);
  2248. }
  2249.  
  2250. static void AddRMW(const char *NName, Byte NCode)
  2251. {
  2252.   char WName[10];
  2253.  
  2254.   AddInstTable(InstTable, NName, NCode, DecodeRMW);
  2255.   as_snprintf(WName, sizeof(WName), "%sW", NName);
  2256.   AddInstTable(InstTable, WName, NCode | 0x100, DecodeRMW);
  2257. }
  2258.  
  2259. static void AddRel(const char *NName, Word NCode)
  2260. {
  2261.   AddInstTable(InstTable, NName, NCode, DecodeRel);
  2262. }
  2263.  
  2264. static void InitFields(void)
  2265. {
  2266.   InstTable = CreateInstTable(201);
  2267.   SetDynamicInstTable(InstTable);
  2268.   AddInstTable(InstTable, "LD", 0, DecodeLD);
  2269.   AddInstTable(InstTable, "LDF", 0, DecodeLDF);
  2270.   AddInstTable(InstTable, "LDW", 0, DecodeLDW);
  2271.   AddInstTable(InstTable, "MOV", 0, DecodeMOV);
  2272.   AddInstTable(InstTable, "PUSH", 0x0004, DecodePUSH_POP);
  2273.   AddInstTable(InstTable, "POP", 0x0000, DecodePUSH_POP);
  2274.   AddInstTable(InstTable, "PUSHW", 0x0104, DecodePUSH_POP);
  2275.   AddInstTable(InstTable, "POPW", 0x0100, DecodePUSH_POP);
  2276.   AddInstTable(InstTable, "CP", 0, DecodeCP);
  2277.   AddInstTable(InstTable, "CPW", 1, DecodeCP);
  2278.   AddInstTable(InstTable, "MUL", 0, DecodeMUL);
  2279.   AddInstTable(InstTable, "DIV", 0, DecodeDIV);
  2280.   AddInstTable(InstTable, "DIVW", 1, DecodeDIV);
  2281.   AddInstTable(InstTable, "EXG", 0, DecodeEXG);
  2282.   AddInstTable(InstTable, "EXGW", 1, DecodeEXG);
  2283.   AddInstTable(InstTable, "RLWA", 0x02, DecodeRxWA);
  2284.   AddInstTable(InstTable, "RRWA", 0x01, DecodeRxWA);
  2285.   AddInstTable(InstTable, "BCCM", 0x9001, DecodeBitOp);
  2286.   AddInstTable(InstTable, "BCPL", 0x9000, DecodeBitOp);
  2287.   AddInstTable(InstTable, "BRES", 0x7211, DecodeBitOp);
  2288.   AddInstTable(InstTable, "BSET", 0x7210, DecodeBitOp);
  2289.   AddInstTable(InstTable, "BTJF", 0x01, DecodeBTJF_BTJT);
  2290.   AddInstTable(InstTable, "BTJT", 0x00, DecodeBTJF_BTJT);
  2291.   AddInstTable(InstTable, "JP", 0x0c, DecodeJP_CALL);
  2292.   AddInstTable(InstTable, "CALL", 0x0d, DecodeJP_CALL);
  2293.   AddInstTable(InstTable, "JPF", 0xac, DecodeJPF_CALLF);
  2294.   AddInstTable(InstTable, "CALLF", 0x8d, DecodeJPF_CALLF);
  2295.   AddInstTable(InstTable, "BIT", 0, DecodeBIT);
  2296.  
  2297.   AddFixed("HALT" , 0x8e); AddFixed("IRET" , 0x80); AddFixed("NOP"  , 0x9d);
  2298.   AddFixed("RCF"  , 0x98); AddFixed("RET"  , 0x81); AddFixed("RIM"  , 0x9a);
  2299.   AddFixed("RSP"  , 0x9c); AddFixed("SCF"  , 0x99); AddFixed("SIM"  , 0x9b);
  2300.   AddFixed("TRAP" , 0x83); AddFixed("WFI"  , 0x8f); AddFixed("BREAK", 0x018b);
  2301.   AddFixed("WFE"  , 0x728f); AddFixed("RVF"  , 0x019c); AddFixed("RETF", 0x0187);
  2302.   AddFixed("CCF"  , 0x018c);
  2303.  
  2304.   AddAri("ADC" , 0x09, True ); AddAri("ADD" , 0x0b, True ); AddAri("AND" , 0x04, True );
  2305.   AddAri("BCP" , 0x05, True ); AddAri("OR"  , 0x0a, True ); AddAri("SBC" , 0x02, True );
  2306.   AddAri("SUB" , 0x00, True ); AddAri("XOR" , 0x08, True );
  2307.  
  2308.   AddAri16("ADDW", 0x090b); AddAri16("SUBW", 0x0200);
  2309.  
  2310.   AddRMW("CLR" , 0x0f); AddRMW("CPL" , 0x03); AddRMW("DEC" , 0x0a);
  2311.   AddRMW("INC" , 0x0c); AddRMW("NEG" , 0x00); AddRMW("RLC" , 0x09);
  2312.   AddRMW("RRC" , 0x06); AddRMW("SLA" , 0x08); AddRMW("SLL" , 0x08);
  2313.   AddRMW("SRA" , 0x07); AddRMW("SRL" , 0x04); AddRMW("SWAP", 0x0e);
  2314.   AddRMW("TNZ" , 0x0d);
  2315.  
  2316.   AddRel("CALLR", 0xad);
  2317.   AddRel("JRA"  , 0x20);
  2318.   AddRel("JRC"  , 0x25);
  2319.   AddRel("JREQ" , 0x27);
  2320.   AddRel("JRF"  , 0x21);
  2321.   AddRel("JRH"  , (pCurrCPUProps->Core == eCoreSTM8) ? 0x9029 : 0x29);
  2322.   AddRel("JRIH" , (pCurrCPUProps->Core == eCoreSTM8) ? 0x902f : 0x2f);
  2323.   AddRel("JRIL" , (pCurrCPUProps->Core == eCoreSTM8) ? 0x902e : 0x2e);
  2324.   AddRel("JRM"  , (pCurrCPUProps->Core == eCoreSTM8) ? 0x902d : 0x2d);
  2325.   AddRel("JRMI" , 0x2b);
  2326.   AddRel("JRNC" , 0x24);
  2327.   AddRel("JRNE" , 0x26);
  2328.   AddRel("JRNH" , (pCurrCPUProps->Core == eCoreSTM8) ? 0x9028 : 0x28);
  2329.   AddRel("JRNM" , (pCurrCPUProps->Core == eCoreSTM8) ? 0x902c : 0x2c);
  2330.   AddRel("JRNV" , (pCurrCPUProps->Core == eCoreSTM8) ? 0x28 : 0x00);
  2331.   AddRel("JRPL" , 0x2a);
  2332.   AddRel("JRSGE", (pCurrCPUProps->Core == eCoreSTM8) ? 0x2e : 0x00);
  2333.   AddRel("JRSGT", (pCurrCPUProps->Core == eCoreSTM8) ? 0x2c : 0x00);
  2334.   AddRel("JRSLE", (pCurrCPUProps->Core == eCoreSTM8) ? 0x2d : 0x00);
  2335.   AddRel("JRSLT", (pCurrCPUProps->Core == eCoreSTM8) ? 0x2f : 0x00);
  2336.   AddRel("JRT"  , 0x20);
  2337.   AddRel("JRUGE", 0x24);
  2338.   AddRel("JRUGT", 0x22);
  2339.   AddRel("JRULE", 0x23);
  2340.   AddRel("JRULT", 0x25);
  2341.   AddRel("JRV"  , (pCurrCPUProps->Core == eCoreSTM8) ? 0x29 : 0x00);
  2342.  
  2343.   init_moto8_pseudo(InstTable, e_moto_8_be);
  2344. }
  2345.  
  2346. /*!------------------------------------------------------------------------
  2347.  * \fn     DeinitFields(void)
  2348.  * \brief  tear down instruction hash table
  2349.  * ------------------------------------------------------------------------ */
  2350.  
  2351. static void DeinitFields(void)
  2352. {
  2353.   DestroyInstTable(InstTable);
  2354. }
  2355.  
  2356. /*!------------------------------------------------------------------------
  2357.  * \fn     MakeCode_ST7(void)
  2358.  * \brief  entry point to decode machine instructions
  2359.  * ------------------------------------------------------------------------ */
  2360.  
  2361. static Boolean DecodeAttrPart_ST7(void)
  2362. {
  2363.   if (strlen(AttrPart.str.p_str) > 1)
  2364.   {
  2365.     WrStrErrorPos(ErrNum_UndefAttr, &AttrPart);
  2366.     return False;
  2367.   }
  2368.   return DecodeMoto16AttrSize(*AttrPart.str.p_str, &AttrPartOpSize[0], False);
  2369. }
  2370.  
  2371. static void MakeCode_ST7(void)
  2372. {
  2373.   CodeLen = 0;
  2374.   DontPrint = False;
  2375.   OpSize = (AttrPartOpSize[0] != eSymbolSizeUnknown) ? AttrPartOpSize[0] : eSymbolSize8Bit;
  2376.   PrefixCnt = 0;
  2377.  
  2378.   /* zu ignorierendes */
  2379.  
  2380.   if (Memo("")) return;
  2381.  
  2382.   /* Pseudoanweisungen */
  2383.  
  2384.   if (DecodeMoto16Pseudo(OpSize,True)) return;
  2385.  
  2386.   if (!LookupInstTable(InstTable, OpPart.str.p_str))
  2387.     WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
  2388. }
  2389.  
  2390. /*!------------------------------------------------------------------------
  2391.  * \fn     IsDef_ST7(void)
  2392.  * \brief  does instruction consume label field?
  2393.  * \return true if to be consumed
  2394.  * ------------------------------------------------------------------------ */
  2395.  
  2396. static Boolean IsDef_ST7(void)
  2397. {
  2398.   return Memo("BIT");
  2399. }
  2400.  
  2401. /*!------------------------------------------------------------------------
  2402.  * \fn     SwitchTo_ST7(void)
  2403.  * \brief  switch to target
  2404.  * ------------------------------------------------------------------------ */
  2405.  
  2406. static void SwitchTo_ST7(void *pUser)
  2407. {
  2408.   pCurrCPUProps = (const tCPUProps*)pUser;
  2409.   TurnWords = False;
  2410.   SetIntConstMode(eIntConstModeMoto);
  2411.  
  2412.   PCSymbol = "PC"; HeaderID = 0x33; NOPCode = 0x9d;
  2413.   DivideChars = ","; HasAttrs = True; AttrChars = ".";
  2414.  
  2415.  
  2416.   ValidSegs = 1 << SegCode;
  2417.   Grans[SegCode] = 1; ListGrans[SegCode] = 1; SegInits[SegCode] = 0;
  2418.   SegLimits[SegCode] = IntTypeDefs[pCurrCPUProps->AddrIntType].Max;
  2419.  
  2420.   DecodeAttrPart = DecodeAttrPart_ST7;
  2421.   MakeCode = MakeCode_ST7;
  2422.   IsDef = IsDef_ST7;
  2423.   SwitchFrom = DeinitFields;
  2424.   DissectBit = DissectBit_ST7;
  2425.   InitFields();
  2426.   AddMoto16PseudoONOFF(False);
  2427. }
  2428.  
  2429. /*!------------------------------------------------------------------------
  2430.  * \fn     codest7_init(void)
  2431.  * \brief  register ST7/STM8 target
  2432.  * ------------------------------------------------------------------------ */
  2433.  
  2434. static const tCPUProps CPUProps[] =
  2435. {
  2436.   { "ST7"         ,  Int16, eCoreST7  },
  2437.   { "ST7232AK1"   ,  Int16, eCoreST7  },
  2438.   { "ST7232AK2"   ,  Int16, eCoreST7  },
  2439.   { "ST7232AJ1"   ,  Int16, eCoreST7  },
  2440.   { "ST7232AJ2"   ,  Int16, eCoreST7  },
  2441.   { "ST72251G1"   ,  Int16, eCoreST7  },
  2442.   { "ST72251G2"   ,  Int16, eCoreST7  },
  2443.   { "ST72311J2"   ,  Int16, eCoreST7  },
  2444.   { "ST72311J4"   ,  Int16, eCoreST7  },
  2445.   { "ST72321BR6"  ,  Int16, eCoreST7  },
  2446.   { "ST72321BR7"  ,  Int16, eCoreST7  },
  2447.   { "ST72321BR9"  ,  Int16, eCoreST7  },
  2448.   { "ST72324J6"   ,  Int16, eCoreST7  },
  2449.   { "ST72324K6"   ,  Int16, eCoreST7  },
  2450.   { "ST72324J4"   ,  Int16, eCoreST7  },
  2451.   { "ST72324K4"   ,  Int16, eCoreST7  },
  2452.   { "ST72324J2"   ,  Int16, eCoreST7  },
  2453.   { "ST72324K2"   ,  Int16, eCoreST7  },
  2454.   { "ST72325S4"   ,  Int16, eCoreST7  },
  2455.   { "ST72325S6"   ,  Int16, eCoreST7  },
  2456.   { "ST72325J7"   ,  Int16, eCoreST7  },
  2457.   { "ST72325R9"   ,  Int16, eCoreST7  },
  2458.   { "ST72344K2"   ,  Int16, eCoreST7  },
  2459.   { "ST72344K4"   ,  Int16, eCoreST7  },
  2460.   { "ST72345C4"   ,  Int16, eCoreST7  },
  2461.   { "ST72521BR6"  ,  Int16, eCoreST7  },
  2462.   { "ST72521BM9"  ,  Int16, eCoreST7  },
  2463.   { "ST72361AR4"  ,  Int16, eCoreST7  },
  2464.   { "ST72361AR6"  ,  Int16, eCoreST7  },
  2465.   { "ST72361AR7"  ,  Int16, eCoreST7  },
  2466.   { "ST72361AR9"  ,  Int16, eCoreST7  },
  2467.   { "ST7FOXK1"    ,  Int16, eCoreST7  },
  2468.   { "ST7FOXK2"    ,  Int16, eCoreST7  },
  2469.   { "ST7LITES2Y0" ,  Int16, eCoreST7  },
  2470.   { "ST7LITES5Y0" ,  Int16, eCoreST7  },
  2471.   { "ST7LITE02Y0" ,  Int16, eCoreST7  },
  2472.   { "ST7LITE05Y0" ,  Int16, eCoreST7  },
  2473.   { "ST7LITE09Y0" ,  Int16, eCoreST7  },
  2474.   { "ST7LITE10F1" ,  Int16, eCoreST7  },
  2475.   { "ST7LITE15F1" ,  Int16, eCoreST7  },
  2476.   { "ST7LITE19F1" ,  Int16, eCoreST7  },
  2477.   { "ST7LITE10BF0",  Int16, eCoreST7  },
  2478.   { "ST7LITE15BF0",  Int16, eCoreST7  },
  2479.   { "ST7LITE15BF1",  Int16, eCoreST7  },
  2480.   { "ST7LITE19BF0",  Int16, eCoreST7  },
  2481.   { "ST7LITE19BF1",  Int16, eCoreST7  },
  2482.   { "ST7LITE20F2" ,  Int16, eCoreST7  },
  2483.   { "ST7LITE25F2" ,  Int16, eCoreST7  },
  2484.   { "ST7LITE29F2" ,  Int16, eCoreST7  },
  2485.   { "ST7LITE30F2" ,  Int16, eCoreST7  },
  2486.   { "ST7LITE35F2" ,  Int16, eCoreST7  },
  2487.   { "ST7LITE39F2" ,  Int16, eCoreST7  },
  2488.   { "ST7LITE49K2" ,  Int16, eCoreST7  },
  2489.   { "ST7MC1K2"    ,  Int16, eCoreST7  },
  2490.   { "ST7MC1K4"    ,  Int16, eCoreST7  },
  2491.   { "ST7MC2N6"    ,  Int16, eCoreST7  },
  2492.   { "ST7MC2S4"    ,  Int16, eCoreST7  },
  2493.   { "ST7MC2S6"    ,  Int16, eCoreST7  },
  2494.   { "ST7MC2S7"    ,  Int16, eCoreST7  },
  2495.   { "ST7MC2S9"    ,  Int16, eCoreST7  },
  2496.   { "ST7MC2R6"    ,  Int16, eCoreST7  },
  2497.   { "ST7MC2R7"    ,  Int16, eCoreST7  },
  2498.   { "ST7MC2R9"    ,  Int16, eCoreST7  },
  2499.   { "ST7MC2M9"    ,  Int16, eCoreST7  },
  2500.  
  2501.   { "STM8"        ,  Int24, eCoreSTM8 },
  2502.   { "STM8S001J3"  ,  Int16, eCoreSTM8 },
  2503.   { "STM8S003F3"  ,  Int16, eCoreSTM8 },
  2504.   { "STM8S003K3"  ,  Int16, eCoreSTM8 },
  2505.   { "STM8S005C6"  ,  Int16, eCoreSTM8 },
  2506.   { "STM8S005K6"  ,  Int16, eCoreSTM8 },
  2507.   { "STM8S007C8"  ,  Int24, eCoreSTM8 },
  2508.   { "STM8S103F2"  ,  Int16, eCoreSTM8 },
  2509.   { "STM8S103F3"  ,  Int16, eCoreSTM8 },
  2510.   { "STM8S103K3"  ,  Int16, eCoreSTM8 },
  2511.   { "STM8S105C4"  ,  Int16, eCoreSTM8 },
  2512.   { "STM8S105C6"  ,  Int16, eCoreSTM8 },
  2513.   { "STM8S105K4"  ,  Int16, eCoreSTM8 },
  2514.   { "STM8S105K6"  ,  Int16, eCoreSTM8 },
  2515.   { "STM8S105S4"  ,  Int16, eCoreSTM8 },
  2516.   { "STM8S105S6"  ,  Int16, eCoreSTM8 },
  2517.   { "STM8S207MB"  ,  Int24, eCoreSTM8 },
  2518.   { "STM8S207M8"  ,  Int24, eCoreSTM8 },
  2519.   { "STM8S207RB"  ,  Int24, eCoreSTM8 },
  2520.   { "STM8S207R8"  ,  Int24, eCoreSTM8 },
  2521.   { "STM8S207R6"  ,  Int16, eCoreSTM8 },
  2522.   { "STM8S207CB"  ,  Int24, eCoreSTM8 },
  2523.   { "STM8S207C8"  ,  Int24, eCoreSTM8 },
  2524.   { "STM8S207C6"  ,  Int16, eCoreSTM8 },
  2525.   { "STM8S207SB"  ,  Int24, eCoreSTM8 },
  2526.   { "STM8S207S8"  ,  Int24, eCoreSTM8 },
  2527.   { "STM8S207S6"  ,  Int16, eCoreSTM8 },
  2528.   { "STM8S207K8"  ,  Int24, eCoreSTM8 },
  2529.   { "STM8S207K6"  ,  Int16, eCoreSTM8 },
  2530.   { "STM8S208MB"  ,  Int24, eCoreSTM8 },
  2531.   { "STM8S208RB"  ,  Int24, eCoreSTM8 },
  2532.   { "STM8S208R8"  ,  Int24, eCoreSTM8 },
  2533.   { "STM8S208R6"  ,  Int24, eCoreSTM8 },
  2534.   { "STM8S208CB"  ,  Int24, eCoreSTM8 },
  2535.   { "STM8S208C8"  ,  Int24, eCoreSTM8 },
  2536.   { "STM8S208C6"  ,  Int16, eCoreSTM8 },
  2537.   { "STM8S208SB"  ,  Int24, eCoreSTM8 },
  2538.   { "STM8S208S8"  ,  Int24, eCoreSTM8 },
  2539.   { "STM8S208S6"  ,  Int16, eCoreSTM8 },
  2540.   { "STM8S903K3"  ,  Int16, eCoreSTM8 },
  2541.   { "STM8S903F3"  ,  Int16, eCoreSTM8 },
  2542.   { "STM8L050J3"  ,  Int16, eCoreSTM8 },
  2543.   { "STM8L051F3"  ,  Int16, eCoreSTM8 },
  2544.   { "STM8L052C6"  ,  Int16, eCoreSTM8 },
  2545.   { "STM8L052R8"  ,  Int24, eCoreSTM8 },
  2546.   { "STM8L001J3"  ,  Int16, eCoreSTM8 },
  2547.   { "STM8L101F1"  ,  Int16, eCoreSTM8 },
  2548.   { "STM8L101F2"  ,  Int16, eCoreSTM8 },
  2549.   { "STM8L101G2"  ,  Int16, eCoreSTM8 },
  2550.   { "STM8L101F3"  ,  Int16, eCoreSTM8 },
  2551.   { "STM8L101G3"  ,  Int16, eCoreSTM8 },
  2552.   { "STM8L101K3"  ,  Int16, eCoreSTM8 },
  2553.   { "STM8L151C2"  ,  Int16, eCoreSTM8 },
  2554.   { "STM8L151K2"  ,  Int16, eCoreSTM8 },
  2555.   { "STM8L151G2"  ,  Int16, eCoreSTM8 },
  2556.   { "STM8L151F2"  ,  Int16, eCoreSTM8 },
  2557.   { "STM8L151C3"  ,  Int16, eCoreSTM8 },
  2558.   { "STM8L151K3"  ,  Int16, eCoreSTM8 },
  2559.   { "STM8L151G3"  ,  Int16, eCoreSTM8 },
  2560.   { "STM8L151F3"  ,  Int16, eCoreSTM8 },
  2561.   { "STM8L151C4"  ,  Int16, eCoreSTM8 },
  2562.   { "STM8L151C6"  ,  Int16, eCoreSTM8 },
  2563.   { "STM8L151K4"  ,  Int16, eCoreSTM8 },
  2564.   { "STM8L151K6"  ,  Int16, eCoreSTM8 },
  2565.   { "STM8L151G4"  ,  Int16, eCoreSTM8 },
  2566.   { "STM8L151G6"  ,  Int16, eCoreSTM8 },
  2567.   { "STM8L152C4"  ,  Int16, eCoreSTM8 },
  2568.   { "STM8L152C6"  ,  Int16, eCoreSTM8 },
  2569.   { "STM8L152K4"  ,  Int16, eCoreSTM8 },
  2570.   { "STM8L152K6"  ,  Int16, eCoreSTM8 },
  2571.   { "STM8L151R6"  ,  Int16, eCoreSTM8 },
  2572.   { "STM8L151C8"  ,  Int24, eCoreSTM8 },
  2573.   { "STM8L151M8"  ,  Int16, eCoreSTM8 },
  2574.   { "STM8L151R8"  ,  Int24, eCoreSTM8 },
  2575.   { "STM8L152R6"  ,  Int16, eCoreSTM8 },
  2576.   { "STM8L152C8"  ,  Int24, eCoreSTM8 },
  2577.   { "STM8L152K8"  ,  Int24, eCoreSTM8 },
  2578.   { "STM8L152M8"  ,  Int24, eCoreSTM8 },
  2579.   { "STM8L152R8"  ,  Int24, eCoreSTM8 },
  2580.   { "STM8L162M8"  ,  Int24, eCoreSTM8 },
  2581.   { "STM8L162R8"  ,  Int24, eCoreSTM8 },
  2582.   { "STM8AF6366"  ,  Int16, eCoreSTM8 },
  2583.   { "STM8AF6388"  ,  Int24, eCoreSTM8 },
  2584.   { "STM8AF6213"  ,  Int16, eCoreSTM8 },
  2585.   { "STM8AF6223"  ,  Int16, eCoreSTM8 },
  2586.   { "STM8AF6226"  ,  Int16, eCoreSTM8 },
  2587.   { "STM8AF6246"  ,  Int16, eCoreSTM8 },
  2588.   { "STM8AF6248"  ,  Int16, eCoreSTM8 },
  2589.   { "STM8AF6266"  ,  Int16, eCoreSTM8 },
  2590.   { "STM8AF6268"  ,  Int16, eCoreSTM8 },
  2591.   { "STM8AF6269"  ,  Int16, eCoreSTM8 },
  2592.   { "STM8AF6286"  ,  Int24, eCoreSTM8 },
  2593.   { "STM8AF6288"  ,  Int24, eCoreSTM8 },
  2594.   { "STM8AF6289"  ,  Int24, eCoreSTM8 },
  2595.   { "STM8AF628A"  ,  Int24, eCoreSTM8 },
  2596.   { "STM8AF62A6"  ,  Int24, eCoreSTM8 },
  2597.   { "STM8AF62A8"  ,  Int24, eCoreSTM8 },
  2598.   { "STM8AF62A9"  ,  Int24, eCoreSTM8 },
  2599.   { "STM8AF62AA"  ,  Int24, eCoreSTM8 },
  2600.   { "STM8AF5268"  ,  Int16, eCoreSTM8 },
  2601.   { "STM8AF5269"  ,  Int16, eCoreSTM8 },
  2602.   { "STM8AF5286"  ,  Int24, eCoreSTM8 },
  2603.   { "STM8AF5288"  ,  Int24, eCoreSTM8 },
  2604.   { "STM8AF5289"  ,  Int24, eCoreSTM8 },
  2605.   { "STM8AF528A"  ,  Int24, eCoreSTM8 },
  2606.   { "STM8AF52A6"  ,  Int24, eCoreSTM8 },
  2607.   { "STM8AF52A8"  ,  Int24, eCoreSTM8 },
  2608.   { "STM8AF52A9"  ,  Int24, eCoreSTM8 },
  2609.   { "STM8AF52AA"  ,  Int24, eCoreSTM8 },
  2610.   { "STM8AL3136"  ,  Int16, eCoreSTM8 },
  2611.   { "STM8AL3138"  ,  Int16, eCoreSTM8 },
  2612.   { "STM8AL3146"  ,  Int16, eCoreSTM8 },
  2613.   { "STM8AL3148"  ,  Int16, eCoreSTM8 },
  2614.   { "STM8AL3166"  ,  Int16, eCoreSTM8 },
  2615.   { "STM8AL3168"  ,  Int16, eCoreSTM8 },
  2616.   { "STM8AL3L46"  ,  Int16, eCoreSTM8 },
  2617.   { "STM8AL3L48"  ,  Int16, eCoreSTM8 },
  2618.   { "STM8AL3L66"  ,  Int16, eCoreSTM8 },
  2619.   { "STM8AL3L68"  ,  Int16, eCoreSTM8 },
  2620.   { "STM8AL3188"  ,  Int24, eCoreSTM8 },
  2621.   { "STM8AL3189"  ,  Int24, eCoreSTM8 },
  2622.   { "STM8AL318A"  ,  Int24, eCoreSTM8 },
  2623.   { "STM8AL3L88"  ,  Int24, eCoreSTM8 },
  2624.   { "STM8AL3L89"  ,  Int24, eCoreSTM8 },
  2625.   { "STM8AL3L8A"  ,  Int24, eCoreSTM8 },
  2626.   { "STM8TL52F4"  ,  Int16, eCoreSTM8 },
  2627.   { "STM8TL52G4"  ,  Int16, eCoreSTM8 },
  2628.   { "STM8TL53C4"  ,  Int16, eCoreSTM8 },
  2629.   { "STM8TL53F4"  ,  Int16, eCoreSTM8 },
  2630.   { "STM8TL53G4"  ,  Int16, eCoreSTM8 },
  2631.   { NULL          ,  UInt1, eCoreST7  },
  2632. };
  2633.  
  2634. void codest7_init(void)
  2635. {
  2636.   const tCPUProps *pProp;
  2637.  
  2638.   for (pProp = CPUProps; pProp->pName; pProp++)
  2639.     (void)AddCPUUser(pProp->pName, SwitchTo_ST7, (void*)pProp, NULL);
  2640. }
  2641.