1 /* natpseudo.c */
2 /*****************************************************************************/
3 /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
4 /*                                                                           */
5 /* AS-Port                                                                   */
6 /*                                                                           */
7 /* Pseudo Instructions used for National Semiconductor CPUs                  */
8 /*                                                                           */
9 /*****************************************************************************/
10 
11 /*****************************************************************************
12  * Includes
13  *****************************************************************************/
14 
15 #include "stdinc.h"
16 #include <string.h>
17 #include "bpemu.h"
18 
19 #include "asmdef.h"
20 #include "asmsub.h"
21 #include "asmpars.h"
22 #include "asmitree.h"
23 #include "codepseudo.h"
24 #include "intpseudo.h"
25 #include "errmsg.h"
26 
27 #include "natpseudo.h"
28 
29 /*****************************************************************************
30  * Global Functions
31  *****************************************************************************/
32 
DecodeSFR(Word Code)33 static void DecodeSFR(Word Code)
34 {
35   UNUSED(Code);
36   CodeEquate(SegData, 0, 0xff);
37 }
38 
DecodeDSx(Word Shift)39 static void DecodeDSx(Word Shift)
40 {
41   if (ChkArgCnt(1, 1))
42   {
43     tSymbolFlags Flags;
44     Boolean ValOK;
45     Word Size = EvalStrIntExpressionWithFlags(&ArgStr[1], UInt16, &ValOK, &Flags) << Shift;
46 
47     if (mFirstPassUnknown(Flags)) WrError(ErrNum_FirstPassCalc);
48     else if (ValOK)
49     {
50       DontPrint = True;
51       if (!Size) WrError(ErrNum_NullResMem);
52       CodeLen = Size;
53       BookKeeping();
54     }
55   }
56 }
57 
DecodeFx(Word Shift)58 static void DecodeFx(Word Shift)
59 {
60   if (ChkArgCnt(2, 2))
61   {
62     tSymbolFlags Flags;
63     Boolean ValOK;
64     Word Size = EvalStrIntExpressionWithFlags(&ArgStr[1], UInt16, &ValOK, &Flags);
65 
66     if (mFirstPassUnknown(Flags)) WrError(ErrNum_FirstPassCalc);
67     else if (ValOK)
68     {
69       if (SetMaxCodeLen(Size << Shift)) WrError(ErrNum_CodeOverflow);
70       else
71       {
72         Word Value = EvalStrIntExpression(&ArgStr[2], Shift ? Int16 : Int8, &ValOK);
73 
74         if (ValOK)
75         {
76           Word z;
77 
78           for (z = 0; z < Size; z++)
79           {
80             BAsmCode[CodeLen++] = Lo(Value);
81             if (Shift)
82               BAsmCode[CodeLen++] = Hi(Value);
83           }
84         }
85       }
86     }
87   }
88 }
89 
DecodeNatPseudo(void)90 Boolean DecodeNatPseudo(void)
91 {
92   static PInstTable InstTable = NULL;
93 
94   if (!InstTable)
95   {
96     InstTable = CreateInstTable(31);
97 
98     AddInstTable(InstTable, "SFR"  , 0     , DecodeSFR);
99     AddInstTable(InstTable, "ADDR" , True  , DecodeIntelDB);
100     AddInstTable(InstTable, "ADDRW", True  , DecodeIntelDW);
101     AddInstTable(InstTable, "BYTE" , False , DecodeIntelDB);
102     AddInstTable(InstTable, "WORD" , False , DecodeIntelDW);
103     AddInstTable(InstTable, "DSB"  , 0     , DecodeDSx);
104     AddInstTable(InstTable, "DSW"  , 1     , DecodeDSx);
105     AddInstTable(InstTable, "FB"   , 0     , DecodeFx);
106     AddInstTable(InstTable, "FW"   , 1     , DecodeFx);
107   }
108 
109   return LookupInstTable(InstTable, OpPart.Str);
110 }
111