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