1 /*
2  * AS-Portierung
3  *
4  * AS-Codegeneratormodul fuer die Texas Instruments TMS320C5x-Familie
5  *
6  */
7 
8 #include "stdinc.h"
9 #include <string.h>
10 #include <ctype.h>
11 
12 #include "nls.h"
13 #include "bpemu.h"
14 #include "strutil.h"
15 #include "chunks.h"
16 #include "errmsg.h"
17 #include "asmdef.h"
18 #include "asmsub.h"
19 #include "asmpars.h"
20 #include "asmitree.h"
21 #include "codepseudo.h"
22 #include "codevars.h"
23 #include "tipseudo.h"
24 #include "endian.h"
25 #include "errmsg.h"
26 
27 #include "code3205x.h"
28 
29 /* ---------------------------------------------------------------------- */
30 
31 typedef struct
32 {
33   CPUVar MinCPU;
34   Word Code;
35 } FixedOrder;
36 
37 typedef struct
38 {
39   CPUVar MinCPU;
40   Word Code;
41   Boolean Cond;
42 } JmpOrder;
43 
44 typedef struct
45 {
46   const char *Name;
47   CPUVar MinCPU;
48   Word Mode;
49 } tAdrMode;
50 
51 typedef struct
52 {
53   const char *Name;
54   CPUVar MinCPU;
55   Word CodeAND;
56   Word CodeOR;
57   Byte IsZL;
58   Byte IsC;
59   Byte IsV;
60   Byte IsTP;
61 } Condition;
62 
63 typedef struct
64 {
65   const char *name;
66   CPUVar MinCPU;
67   Word Code;
68 } tBitTable;
69 
70 #define NOCONDITION 0xffff
71 
72 static FixedOrder *FixedOrders;
73 #define FixedOrderCnt 45
74 static FixedOrder *AdrOrders;
75 #define AdrOrderCnt 32
76 static JmpOrder *JmpOrders;
77 #define JmpOrderCnt 11
78 static FixedOrder *PluOrders;
79 #define PluOrderCnt 7
80 static tAdrMode *AdrModes;
81 #define AdrModeCnt 10
82 static Condition *Conditions;
83 #define CondCnt 15
84 static tBitTable *BitTable;
85 #define BitCnt 9
86 
87 static Word AdrMode;
88 
89 static CPUVar CPU320203;
90 static CPUVar CPU32050;
91 static CPUVar CPU32051;
92 static CPUVar CPU32053;
93 
94 /* ---------------------------------------------------------------------- */
95 
EvalARExpression(const tStrComp * pArg,Boolean * OK)96 static Word EvalARExpression(const tStrComp *pArg, Boolean *OK)
97 {
98   *OK = True;
99 
100   if ((as_toupper(pArg->Str[0]) == 'A')
101    && (as_toupper(pArg->Str[1]) == 'R')
102    && (pArg->Str[2] >= '0')
103    && (pArg->Str[2] <= '7')
104    && (pArg->Str[3] <= '\0'))
105      return pArg->Str[2] - '0';
106   return EvalStrIntExpression(pArg, UInt3, OK);
107 }
108 
109 /* ---------------------------------------------------------------------- */
110 
DecodeAdr(const tStrComp * pArg,int MinArgCnt,int aux,Boolean Must1)111 static Boolean DecodeAdr(const tStrComp *pArg, int MinArgCnt, int aux, Boolean Must1)
112 {
113   Word h;
114   tAdrMode *pAdrMode = AdrModes;
115   tEvalResult EvalResult;
116 
117   /* Annahme: nicht gefunden */
118 
119   Boolean AdrOK = False;
120 
121   /* Adressierungsmodus suchen */
122 
123   while (pAdrMode->Name && as_strcasecmp(pAdrMode->Name, pArg->Str))
124    pAdrMode++;
125 
126   /* nicht gefunden: dann absolut */
127 
128   if (!pAdrMode->Name)
129   {
130     /* ARn-Register darf dann nicht vorhanden sein */
131 
132     if (aux <= ArgCnt)
133     {
134       (void)ChkArgCnt(MinArgCnt, aux - 1);
135       return False;
136     }
137 
138     /* Adresse berechnen */
139 
140     h = EvalStrIntExpressionWithResult(pArg, Int16, &EvalResult);
141     if (!EvalResult.OK)
142       return False;
143     AdrOK = True;
144 
145     /* Adresslage pruefen */
146 
147     if (Must1 && (h >= 0x80) && !mFirstPassUnknown(EvalResult.Flags))
148     {
149       WrError(ErrNum_UnderRange);
150       return False;
151     }
152 
153     /* nur untere 7 Bit gespeichert */
154 
155     AdrMode = h & 0x7f;
156     ChkSpace(SegData, EvalResult.AddrSpaceMask);
157   }
158 
159   /* ansonsten evtl. noch Adressregister dazu */
160 
161   else
162   {
163     /* auf dieser CPU nicht erlaubter Modus ? */
164 
165     if (!ChkMinCPUExt(pAdrMode->MinCPU, ErrNum_AddrModeNotSupported))
166       return False;
167 
168     AdrMode = pAdrMode->Mode;
169     if (aux <= ArgCnt)
170     {
171       h = EvalARExpression(&ArgStr[aux], &AdrOK);
172       if (AdrOK) AdrMode |= 0x8 | h;
173     }
174     else
175       AdrOK = True;
176   }
177 
178   return AdrOK;
179 }
180 
181 /* ---------------------------------------------------------------------- */
182 
DecodeCond(int argp)183 static Word DecodeCond(int argp)
184 {
185   Condition *pCondition;
186   Byte cntzl = 0, cntc = 0, cntv = 0, cnttp = 0;
187   Word ret = 0x300;
188 
189   while (argp <= ArgCnt)
190   {
191     for (pCondition = Conditions; pCondition->Name && as_strcasecmp(pCondition->Name, ArgStr[argp].Str); pCondition++);
192 
193     if (!pCondition->Name)
194     {
195       WrError(ErrNum_UndefCond);
196       return ret;
197     }
198     ret &= pCondition->CodeAND;
199     ret |= pCondition->CodeOR;
200     cntzl += pCondition->IsZL;
201     cntc += pCondition->IsC;
202     cntv += pCondition->IsV;
203     cnttp += pCondition->IsTP;
204     argp++;
205   }
206 
207   if ((cnttp > 1) || (cntzl > 1) || (cntv > 1) || (cntc > 1))
208     WrStrErrorPos(ErrNum_UndefCond, &ArgStr[argp]);
209 
210   return ret;
211 }
212 
213 /* ---------------------------------------------------------------------- */
214 
DecodeShift(const tStrComp * pArg,Boolean * OK)215 static Word DecodeShift(const tStrComp *pArg, Boolean *OK)
216 {
217   Word Shift;
218   tSymbolFlags Flags;
219 
220   Shift = EvalStrIntExpressionWithFlags(pArg, UInt5, OK, &Flags);
221   if (*OK)
222   {
223     if (mFirstPassUnknown(Flags)) Shift &= 15;
224     *OK = ChkRange(Shift, 0, 16);
225   }
226   return Shift;
227 }
228 
229 /* ---------------------------------------------------------------------- */
230 
DecodeFixed(Word Index)231 static void DecodeFixed(Word Index)
232 {
233   const FixedOrder *pOrder = FixedOrders + Index;
234 
235   if (ChkArgCnt(0, 0)
236    && ChkMinCPU(pOrder->MinCPU))
237   {
238     CodeLen = 1;
239     WAsmCode[0] = pOrder->Code;
240   }
241 }
242 
DecodeCmdAdr(Word Index)243 static void DecodeCmdAdr(Word Index)
244 {
245   const FixedOrder *pOrder = AdrOrders + Index;
246 
247   if (ChkArgCnt(1, 2)
248    && ChkMinCPU(pOrder->MinCPU)
249    && DecodeAdr(&ArgStr[1], 1, 2, False))
250   {
251     CodeLen = 1;
252     WAsmCode[0] = pOrder->Code | AdrMode;
253   }
254 }
255 
DecodeCmdJmp(Word Index)256 static void DecodeCmdJmp(Word Index)
257 {
258   const JmpOrder *pOrder = JmpOrders + Index;
259 
260   if (ChkMinCPU(pOrder->MinCPU)
261    && ChkArgCnt(1, pOrder->Cond ? ArgCntMax : 3))
262   {
263     Boolean OK;
264 
265     AdrMode  =  0;
266     if (pOrder->Cond)
267     {
268       AdrMode = DecodeCond(2);
269       OK = AdrMode != NOCONDITION;
270     }
271     else if (ArgCnt > 1)
272     {
273       OK = DecodeAdr(&ArgStr[2], 1, 3, False);
274       if ((AdrMode < 0x80) && (OK))
275       {
276         WrError(ErrNum_InvAddrMode);
277         OK = FALSE;
278       }
279       AdrMode &= 0x7f;
280     }
281     else
282       OK = TRUE;
283 
284     if (OK)
285     {
286       WAsmCode[1] = EvalStrIntExpression(&ArgStr[1], Int16, &OK);
287       if (OK)
288       {
289         CodeLen = 2;
290         WAsmCode[0] = pOrder->Code | AdrMode;
291       }
292     }
293   }
294 }
295 
DecodeCmdPlu(Word Index)296 static void DecodeCmdPlu(Word Index)
297 {
298   Boolean OK;
299   const FixedOrder *pOrder = PluOrders + Index;
300 
301   if (!ChkMinCPU(pOrder->MinCPU));
302   else if (*ArgStr[1].Str == '#')
303   {
304     if (ChkArgCnt(2, 3))
305     {
306       WAsmCode[1] = EvalStrIntExpressionOffs(&ArgStr[1], 1, Int16, &OK);
307       if ((OK) && (DecodeAdr(&ArgStr[2], 2, 3, False)))
308       {
309         CodeLen = 2;
310         WAsmCode[0] = pOrder->Code | 0x0400 | AdrMode;
311       }
312     }
313   }
314   else if (strlen(OpPart.Str) == 4) WrError(ErrNum_OnlyImmAddr);
315   else
316   {
317     if (ChkArgCnt(1, 2))
318     {
319       if (DecodeAdr(&ArgStr[1], 1, 2, False))
320       {
321         CodeLen = 1;
322         WAsmCode[0] = pOrder->Code | AdrMode;
323       }
324     }
325   }
326 }
327 
DecodeADDSUB(Word Index)328 static void DecodeADDSUB(Word Index)
329 {
330   Word Shift;
331   LongInt AdrLong;
332   Boolean OK;
333 
334   if (ChkArgCnt(1, 3))
335   {
336     if (*ArgStr[1].Str == '#')
337     {
338       if (ChkArgCnt(1, 2))
339       {
340         OK = True;
341         Shift = (ArgCnt == 1) ? 0 : EvalStrIntExpression(&ArgStr[2], UInt4, &OK);
342         if (OK)
343         {
344           AdrLong = EvalStrIntExpressionOffs(&ArgStr[1], 1, UInt16, &OK);
345           if (OK)
346           {
347             if ((Shift == 0) && (Hi(AdrLong) == 0))
348             {
349               CodeLen = 1;
350               WAsmCode[0] = (Index << 9) | 0xb800 | (AdrLong & 0xff);
351             }
352             else
353             {
354               CodeLen = 2;
355               WAsmCode[0] = ((Index << 4) + 0xbf90) | (Shift & 0xf);
356               WAsmCode[1] = AdrLong;
357             }
358           }
359         }
360       }
361     }
362     else
363     {
364       if (DecodeAdr(&ArgStr[1], 1, 3, False))
365       {
366         OK = True;
367         Shift = (ArgCnt >= 2) ? DecodeShift(&ArgStr[2], &OK) : 0;
368         if (OK)
369         {
370           CodeLen = 1;
371           if (Shift == 16)
372             WAsmCode[0] = ((Index << 10) | 0x6100) | AdrMode;
373           else
374             WAsmCode[0] = ((Index << 12) | 0x2000) | ((Shift & 0xf) << 8) | AdrMode;
375         }
376       }
377     }
378   }
379 }
380 
DecodeADRSBRK(Word Index)381 static void DecodeADRSBRK(Word Index)
382 {
383   Word adr_word;
384   Boolean OK;
385 
386   if (!ChkArgCnt(1, 1))
387     return;
388 
389   if (*ArgStr[1].Str != '#')
390   {
391     WrError(ErrNum_OnlyImmAddr); /*invalid parameter*/
392     return;
393   }
394 
395   adr_word = EvalStrIntExpressionOffs(&ArgStr[1], 1, UInt8, &OK);
396   if (OK)
397   {
398     CodeLen = 1;
399     WAsmCode[0] = (Index << 10)| 0x7800 | (adr_word & 0xff);
400   }
401 }
402 
DecodeLogic(Word Index)403 static void DecodeLogic(Word Index)
404 {
405   Boolean OK;
406   Word Shift;
407 
408   if (!ChkArgCnt(1, 2));
409   else if (*ArgStr[1].Str == '#')
410   {
411     WAsmCode[1] = EvalStrIntExpressionOffs(&ArgStr[1], 1, UInt16, &OK);
412     if (OK)
413     {
414       OK = True;
415       Shift = (ArgCnt >= 2) ? DecodeShift(&ArgStr[2], &OK) : 0;
416       if (OK)
417       {
418         CodeLen = 2;
419         if (Shift >= 16)
420           WAsmCode[0] = 0xbe80 | Lo(Index);
421         else
422           WAsmCode[0] = 0xbfa0 + ((Index & 3) << 4) + (Shift & 0xf);
423       }
424     }
425   }
426   else
427   {
428     if (DecodeAdr(&ArgStr[1], 1, 2, False))
429     {
430       CodeLen = 1;
431       WAsmCode[0] = (Index & 0xff00) | AdrMode;
432     }
433   }
434 }
435 
DecodeBIT(Word Index)436 static void DecodeBIT(Word Index)
437 {
438   Word bit;
439   Boolean OK;
440   UNUSED(Index);
441 
442   if (ChkArgCnt(2, 3))
443   {
444     bit = EvalStrIntExpression(&ArgStr[2], UInt4, &OK);
445     if ((OK) && (DecodeAdr(&ArgStr[1], 2, 3, False)))
446     {
447       CodeLen = 1;
448       WAsmCode[0] = 0x4000 | AdrMode | ((bit & 0xf) << 8);
449     }
450   }
451 }
452 
DecodeBLDD(Word Index)453 static void DecodeBLDD(Word Index)
454 {
455   Boolean OK;
456   UNUSED(Index);
457 
458   if (!ChkArgCnt(2, 3));
459   else if (!as_strcasecmp(ArgStr[1].Str, "BMAR"))
460   {
461     if (ChkMinCPU(CPU32050))
462     {
463       if (DecodeAdr(&ArgStr[2], 2, 3, False))
464       {
465         CodeLen = 1;
466         WAsmCode[0] = 0xac00 | AdrMode;
467       }
468     }
469   }
470   else if (!as_strcasecmp(ArgStr[2].Str, "BMAR"))
471   {
472     if (ChkMinCPU(CPU32050))
473     {
474       if (DecodeAdr(&ArgStr[1], 2, 3, False))
475       {
476         CodeLen = 1;
477         WAsmCode[0] = 0xad00 | AdrMode;
478       }
479     }
480   }
481   else if (*ArgStr[1].Str == '#')
482   {
483     WAsmCode[1] = EvalStrIntExpressionOffs(&ArgStr[1], 1, Int16, &OK);
484     if ((OK) && (DecodeAdr(&ArgStr[2], 2, 3, False)))
485     {
486       CodeLen = 2;
487       WAsmCode[0] = 0xa800 | AdrMode;
488     }
489   }
490   else if (*ArgStr[2].Str == '#')
491   {
492     WAsmCode[1] = EvalStrIntExpressionOffs(&ArgStr[2], 1, Int16, &OK);
493     if ((OK) && (DecodeAdr(&ArgStr[1], 2, 3, False)))
494     {
495       CodeLen = 2;
496       WAsmCode[0] = 0xa900 | AdrMode;
497     }
498   }
499   else
500     WrError(ErrNum_InvAddrMode); /* invalid addr mode */
501 }
502 
DecodeBLPD(Word Index)503 static void DecodeBLPD(Word Index)
504 {
505   Boolean OK;
506   UNUSED(Index);
507 
508   if (!ChkArgCnt(2, 3));
509   else if (!as_strcasecmp(ArgStr[1].Str, "BMAR"))
510   {
511     if (ChkMinCPU(CPU32050)
512      && DecodeAdr(&ArgStr[2], 2, 3, False))
513     {
514       CodeLen = 1;
515       WAsmCode[0] = 0xa400 | AdrMode;
516     }
517   }
518   else if (*ArgStr[1].Str == '#')
519   {
520     WAsmCode[1] = EvalStrIntExpressionOffs(&ArgStr[1], 1, Int16, &OK);
521     if ((OK) && (DecodeAdr(&ArgStr[2], 2, 3, False)))
522     {
523       CodeLen = 2;
524       WAsmCode[0] = 0xa500 | AdrMode;
525     }
526   }
527   else
528     WrError(ErrNum_InvAddrMode); /* invalid addressing mode */
529 }
530 
DecodeCLRSETC(Word Index)531 static void DecodeCLRSETC(Word Index)
532 {
533   tBitTable *pBitTable;
534 
535   if (ChkArgCnt(1, 1))
536   {
537     WAsmCode[0] = Index;
538     NLS_UpString(ArgStr[1].Str);
539 
540     for (pBitTable = BitTable; pBitTable->name; pBitTable++)
541       if (!strcmp(ArgStr[1].Str, pBitTable->name))
542       {
543         if (ChkMinCPU(pBitTable->MinCPU))
544         {
545           WAsmCode[0] |= pBitTable->Code;
546           CodeLen = 1;
547         }
548         return;
549       }
550     WrStrErrorPos(ErrNum_InvReg, &ArgStr[1]); /* invalid instruction */
551   }
552 }
553 
DecodeCMPRSPM(Word Index)554 static void DecodeCMPRSPM(Word Index)
555 {
556   Boolean OK;
557 
558   if (ChkArgCnt(1, 1))
559   {
560     WAsmCode[0] = Index | (EvalStrIntExpression(&ArgStr[1], UInt2, &OK) & 3);
561     if (OK)
562       CodeLen = 1;
563   }
564 }
565 
DecodeIO(Word Index)566 static void DecodeIO(Word Index)
567 {
568   if (ChkArgCnt(2, 3)
569    && DecodeAdr(&ArgStr[1], 2, 3, False))
570   {
571     tEvalResult EvalResult;
572     WAsmCode[1] = EvalStrIntExpressionWithResult(&ArgStr[2], UInt16, &EvalResult);
573     if (EvalResult.OK)
574     {
575       ChkSpace(SegIO, EvalResult.AddrSpaceMask);
576       CodeLen = 2;
577       WAsmCode[0] = Index | AdrMode;
578     }
579   }
580 }
581 
DecodeINTR(Word Index)582 static void DecodeINTR(Word Index)
583 {
584   Boolean OK;
585   UNUSED(Index);
586 
587   if (ChkArgCnt(1, 1))
588   {
589     WAsmCode[0] = EvalStrIntExpression(&ArgStr[1], UInt5, &OK) | 0xbe60;
590     if (OK)
591       CodeLen = 1;
592   }
593 }
594 
DecodeLACC(Word Index)595 static void DecodeLACC(Word Index)
596 {
597   Boolean OK;
598   LongWord AdrLong;
599   Word Shift;
600   UNUSED(Index);
601 
602   if (!ChkArgCnt(1, 3));
603   else if (*ArgStr[1].Str == '#')
604   {
605     if (ChkArgCnt(1, 2))
606     {
607       AdrLong = EvalStrIntExpressionOffs(&ArgStr[1], 1, Int16, &OK);
608       if (OK)
609       {
610         OK = True;
611         Shift = (ArgCnt > 1) ? EvalStrIntExpression(&ArgStr[2], UInt4, &OK) : 0;
612         if (OK)
613         {
614           CodeLen = 2;
615           WAsmCode[0] = 0xbf80 | (Shift & 0xf);
616           WAsmCode[1] = AdrLong;
617         }
618       }
619     }
620   }
621   else
622   {
623     if (DecodeAdr(&ArgStr[1], 1, 3, False))
624     {
625       OK = True;
626       Shift = (ArgCnt >= 2) ? DecodeShift(&ArgStr[2], &OK) : 0;
627       if (OK)
628       {
629         CodeLen = 1;
630         if (Shift >= 16)
631           WAsmCode[0] = 0x6a00 | AdrMode;
632         else
633           WAsmCode[0] = 0x1000 | ((Shift & 0xf) << 8) | AdrMode;
634       }
635     }
636   }
637 }
638 
DecodeLACL(Word Index)639 static void DecodeLACL(Word Index)
640 {
641   Boolean OK;
642   UNUSED(Index);
643 
644   if (*ArgStr[1].Str == '#')
645   {
646     if (ChkArgCnt(1, 1))
647     {
648       WAsmCode[0] = EvalStrIntExpressionOffs(&ArgStr[1], 1, UInt8, &OK);
649       if (OK)
650       {
651         CodeLen = 1;
652         WAsmCode[0] |= 0xb900;
653       }
654     }
655   }
656   else
657   {
658     if (ChkArgCnt(1, 2))
659     {
660       if (DecodeAdr(&ArgStr[1], 1, 2, False))
661       {
662         WAsmCode[0] = 0x6900 | AdrMode;
663         CodeLen = 1;
664       }
665     }
666   }
667 }
668 
DecodeLAR(Word Index)669 static void DecodeLAR(Word Index)
670 {
671   Word Reg;
672   LongWord AdrLong;
673   Boolean OK;
674   UNUSED(Index);
675 
676   if (ChkArgCnt(2, 3))
677   {
678     Reg = EvalARExpression(&ArgStr[1], &OK);
679     if (OK)
680     {
681       if (*ArgStr[2].Str == '#')
682       {
683         if (!ChkArgCnt(2, 2))
684           return;
685         AdrLong = EvalStrIntExpressionOffs(&ArgStr[2], 1, Int16, &OK) & 0xffff;
686         if (OK)
687         {
688           if (AdrLong > 255)
689           {
690             CodeLen = 2;
691             WAsmCode[0] = 0xbf08 | (Reg & 7);
692             WAsmCode[1] = AdrLong;
693           }
694           else
695           {
696             CodeLen = 1;
697             WAsmCode[0] = 0xb000 | ((Reg & 7) << 8) | (AdrLong & 0xff);
698           }
699         }
700       }
701       else
702       {
703         if (DecodeAdr(&ArgStr[2], 2, 3, False))
704         {
705           CodeLen = 1;
706           WAsmCode[0] = 0x0000 | ((Reg & 7) << 8) | AdrMode;
707         }
708       }
709     }
710   }
711 }
712 
DecodeLDP(Word Index)713 static void DecodeLDP(Word Index)
714 {
715   Word konst;
716   Boolean OK;
717   UNUSED(Index);
718 
719   if (*ArgStr[1].Str == '#')
720   {
721     if (ChkArgCnt(1, 1))
722     {
723       konst = EvalStrIntExpressionOffs(&ArgStr[1], 1, UInt9, &OK);
724       if (OK)
725       {
726         CodeLen = 1;
727         WAsmCode[0] = (konst & 0x1ff) | 0xbc00;
728       }
729     }
730   }
731   else
732   {
733     if (ChkArgCnt(1, 2))
734     {
735       if (DecodeAdr(&ArgStr[1], 1, 2, False))
736       {
737         CodeLen = 1;
738         WAsmCode[0] = 0x0d00 | AdrMode;
739       }
740     }
741   }
742 }
743 
DecodeLSST(Word Index)744 static void DecodeLSST(Word Index)
745 {
746   Word konst;
747   Boolean OK;
748 
749   if (!ChkArgCnt(2, 3));
750   else if (*ArgStr[1].Str != '#') WrError(ErrNum_OnlyImmAddr); /* invalid instruction */
751   else
752   {
753     konst = EvalStrIntExpressionOffs(&ArgStr[1], 1, UInt1, &OK);
754     if ((OK) && (DecodeAdr(&ArgStr[2], 2, 3, Index)))
755     {
756       CodeLen = 1;
757       WAsmCode[0] = 0x0e00 | (Index << 15) | ((konst & 1) << 8) | AdrMode;
758     }
759   }
760 }
761 
DecodeMAC(Word Index)762 static void DecodeMAC(Word Index)
763 {
764   if (ChkArgCnt(2, 3))
765   {
766     tEvalResult EvalResult;
767     WAsmCode[1] = EvalStrIntExpressionWithResult(&ArgStr[1], Int16, &EvalResult);
768 
769     if (EvalResult.OK && DecodeAdr(&ArgStr[2], 2, 3, False))
770     {
771       ChkSpace(SegCode, EvalResult.AddrSpaceMask);
772       CodeLen = 2;
773       WAsmCode[0] = 0xa200 | (Index << 8) | AdrMode;
774     }
775   }
776 }
777 
DecodeMPY(Word Index)778 static void DecodeMPY(Word Index)
779 {
780   LongInt Imm;
781   Boolean OK;
782   tSymbolFlags Flags;
783 
784   if (*ArgStr[1].Str == '#')
785   {
786     if (ChkArgCnt(1, 1))
787     {
788       Imm = EvalStrIntExpressionOffsWithFlags(&ArgStr[1], 1, SInt16, &OK, &Flags);
789       if (mFirstPassUnknown(Flags))
790         Imm &= 0xfff;
791       if (OK)
792       {
793         if ((Imm < -4096) || (Imm > 4095))
794         {
795           if (ChkMinCPU(CPU32050))
796           {
797             CodeLen = 2;              /* What does that mean? */
798             WAsmCode[0] = 0xbe80;
799             WAsmCode[1] = Imm;
800           }
801         }
802         else
803         {
804           CodeLen = 1;
805           WAsmCode[0] = 0xc000 | (Imm & 0x1fff);
806         }
807       }
808     }
809   }
810   else
811   {
812     if (ChkArgCnt(1, 2)
813      && DecodeAdr(&ArgStr[1], 1, 2, Index))
814     {
815       CodeLen = 1;
816       WAsmCode[0] = 0x5400 | AdrMode;
817     }
818   }
819 }
820 
DecodeNORM(Word Index)821 static void DecodeNORM(Word Index)
822 {
823   UNUSED(Index);
824 
825   if (ChkArgCnt(1, 2)
826    && DecodeAdr(&ArgStr[1], 1, 2, False))
827   {
828     if (AdrMode < 0x80) WrError(ErrNum_InvAddrMode);
829     else
830     {
831       CodeLen = 1;
832       WAsmCode[0] = 0xa080 | (AdrMode & 0x7f);
833     }
834   }
835 }
836 
DecodeRETC(Word Index)837 static void DecodeRETC(Word Index)
838 {
839   if (!ChkArgCnt(1, 1));
840   else if (Index && !ChkMinCPU(CPU32050));
841   else
842   {
843     CodeLen = 1;
844     WAsmCode[0] = 0xec00 | (Index << 12) | DecodeCond(1);
845   }
846 }
847 
DecodeRPT(Word Index)848 static void DecodeRPT(Word Index)
849 {
850   Word Imm;
851   Boolean OK;
852   UNUSED(Index);
853 
854   if (*ArgStr[1].Str == '#')
855   {
856     if (ChkArgCnt(1, 1))
857     {
858       Imm = EvalStrIntExpressionOffs(&ArgStr[1], 1, (MomCPU >= CPU32050) ? UInt16 : UInt8, &OK);
859       if (OK)
860       {
861         if (Imm > 255)
862         {
863           CodeLen = 2;
864           WAsmCode[0] = 0xbec4;
865           WAsmCode[1] = Imm;
866         }
867         else
868         {
869           CodeLen = 1;
870           WAsmCode[0] = 0xbb00 | (Imm & 0xff);
871         }
872       }
873     }
874   }
875   else
876   {
877     if (ChkArgCnt(1, 2))
878     {
879       if (DecodeAdr(&ArgStr[1], 1, 2, False))
880       {
881         CodeLen = 1;
882         WAsmCode[0] = 0x0b00 | AdrMode;
883       }
884     }
885   }
886 }
887 
DecodeSAC(Word Index)888 static void DecodeSAC(Word Index)
889 {
890   Boolean OK;
891   Word Shift;
892 
893   if (ChkArgCnt(1, 3))
894   {
895     OK = True;
896     Shift = (ArgCnt >= 2) ? EvalStrIntExpression(&ArgStr[2], UInt3, &OK) : 0;
897 
898     if ((DecodeAdr(&ArgStr[1], 1, 3, False)) && (OK))
899     {
900       CodeLen = 1;
901       WAsmCode[0] = (Index << 11) | 0x9000 | AdrMode | ((Shift & 7) << 8);
902     }
903   }
904 }
905 
DecodeSAR(Word Index)906 static void DecodeSAR(Word Index)
907 {
908   Word Reg;
909   Boolean OK;
910   UNUSED(Index);
911 
912   if (ChkArgCnt(2, 3))
913   {
914     Reg = EvalARExpression(&ArgStr[1], &OK);
915 
916     if ((OK) && (DecodeAdr(&ArgStr[2], 2, 3, False)))
917     {
918       CodeLen = 1;
919       WAsmCode[0] = 0x8000 | ((Reg & 7) << 8) | AdrMode;
920     }
921   }
922 }
923 
DecodeBSAR(Word Index)924 static void DecodeBSAR(Word Index)
925 {
926   Word Shift;
927   Boolean OK;
928   tSymbolFlags Flags;
929 
930   UNUSED(Index);
931 
932   if (ChkArgCnt(1, 1)
933    && ChkMinCPU(CPU32050))
934   {
935     Shift = EvalStrIntExpressionWithFlags(&ArgStr[1], UInt5, &OK, &Flags);
936     if (mFirstPassUnknown(Flags))
937       Shift = 1;
938     if (OK)
939     {
940       if (ChkRange(Shift, 1, 16))
941       {
942         CodeLen = 1;
943         WAsmCode[0] = 0xbfe0 | ((Shift - 1) & 0xf);
944       }
945     }
946   }
947 }
948 
DecodeLSAMM(Word Index)949 static void DecodeLSAMM(Word Index)
950 {
951   if (ChkArgCnt(1, 2)
952    && ChkMinCPU(CPU32050)
953    && DecodeAdr(&ArgStr[1], 1, 2, True))
954   {
955     CodeLen = 1;
956     WAsmCode[0] = 0x0800 | (Index << 15) | AdrMode;
957   }
958 }
959 
DecodeLSMMR(Word Index)960 static void DecodeLSMMR(Word Index)
961 {
962   Boolean OK;
963 
964   if (!ChkArgCnt(2, 3));
965   else if (!ChkMinCPU(CPU32050));
966   else if (ArgStr[2].Str[0] != '#') WrError(ErrNum_OnlyImmAddr);
967   else
968   {
969     WAsmCode[1] = EvalStrIntExpressionOffs(&ArgStr[2], 1, Int16, &OK);
970     if ((OK) && (DecodeAdr(&ArgStr[1], 2, 3, True)))
971     {
972       CodeLen = 2;
973       WAsmCode[0] = 0x0900 | (Index << 15) | AdrMode;
974     }
975   }
976 }
977 
DecodeRPTB(Word Index)978 static void DecodeRPTB(Word Index)
979 {
980   Boolean OK;
981   UNUSED(Index);
982 
983   if (ChkArgCnt(1, 1)
984    && ChkMinCPU(CPU32050))
985   {
986     WAsmCode[1] = EvalStrIntExpression(&ArgStr[1], Int16, &OK);
987     if (OK)
988     {
989       CodeLen = 2;
990       WAsmCode[0] = 0xbec6;
991     }
992   }
993 }
994 
DecodeRPTZ(Word Index)995 static void DecodeRPTZ(Word Index)
996 {
997   Boolean OK;
998   UNUSED(Index);
999 
1000   if (!ChkArgCnt(1, 1));
1001   else if (!ChkMinCPU(CPU32050));
1002   else if (*ArgStr[1].Str != '#') WrError(ErrNum_OnlyImmAddr);
1003   else
1004   {
1005     WAsmCode[1] = EvalStrIntExpressionOffs(&ArgStr[1], 1, Int16, &OK);
1006     if (OK)
1007     {
1008       CodeLen = 2;
1009       WAsmCode[0] = 0xbec5;
1010     }
1011   }
1012 }
1013 
DecodeXC(Word Index)1014 static void DecodeXC(Word Index)
1015 {
1016   Word Mode;
1017   Boolean OK;
1018   tSymbolFlags Flags;
1019 
1020   UNUSED(Index);
1021 
1022   if (ChkArgCnt(2, 2)
1023    && ChkMinCPU(CPU32050))
1024   {
1025     Mode = EvalStrIntExpressionWithFlags(&ArgStr[1], UInt2, &OK, &Flags);
1026     if (OK)
1027     {
1028       if ((Mode != 1) && (Mode != 2) && !mFirstPassUnknown(Flags)) WrError(ErrNum_UnderRange);
1029       else
1030       {
1031         CodeLen = 1;
1032         WAsmCode[0] = (0xd400 + (Mode << 12)) | DecodeCond(2);
1033       }
1034     }
1035   }
1036 }
1037 
DecodePORT(Word Code)1038 static void DecodePORT(Word Code)
1039 {
1040   UNUSED(Code);
1041 
1042   CodeEquate(SegIO, 0, 65535);
1043 }
1044 
1045 /* ---------------------------------------------------------------------- */
1046 
AddFixed(const char * NName,CPUVar MinCPU,Word NCode)1047 static void AddFixed(const char *NName, CPUVar MinCPU, Word NCode)
1048 {
1049   if (InstrZ >= FixedOrderCnt) exit(255);
1050   FixedOrders[InstrZ].MinCPU = MinCPU;
1051   FixedOrders[InstrZ].Code = NCode;
1052   AddInstTable(InstTable, NName, InstrZ++, DecodeFixed);
1053 }
1054 
AddAdr(const char * NName,CPUVar MinCPU,Word NCode)1055 static void AddAdr(const char *NName, CPUVar MinCPU, Word NCode)
1056 {
1057   if (InstrZ >= AdrOrderCnt) exit(255);
1058   AdrOrders[InstrZ].MinCPU = MinCPU;
1059   AdrOrders[InstrZ].Code = NCode;
1060   AddInstTable(InstTable, NName, InstrZ++, DecodeCmdAdr);
1061 }
1062 
AddJmp(const char * NName,CPUVar MinCPU,Word NCode,Boolean NCond)1063 static void AddJmp(const char *NName, CPUVar MinCPU, Word NCode, Boolean NCond)
1064 {
1065   if (InstrZ >= JmpOrderCnt) exit(255);
1066   JmpOrders[InstrZ].MinCPU = MinCPU;
1067   JmpOrders[InstrZ].Code = NCode;
1068   JmpOrders[InstrZ].Cond = NCond;
1069   AddInstTable(InstTable, NName, InstrZ++, DecodeCmdJmp);
1070 }
1071 
AddPlu(const char * NName,CPUVar MinCPU,Word NCode)1072 static void AddPlu(const char *NName, CPUVar MinCPU, Word NCode)
1073 {
1074   if (InstrZ >= PluOrderCnt) exit(255);
1075   PluOrders[InstrZ].MinCPU = MinCPU;
1076   PluOrders[InstrZ].Code = NCode;
1077   AddInstTable(InstTable, NName, InstrZ++, DecodeCmdPlu);
1078 }
1079 
AddAdrMode(const char * NName,CPUVar MinCPU,Word NMode)1080 static void AddAdrMode(const char *NName, CPUVar MinCPU, Word NMode)
1081 {
1082   if (InstrZ >= AdrModeCnt) exit(255);
1083   AdrModes[InstrZ].Name = NName;
1084   AdrModes[InstrZ].MinCPU = MinCPU;
1085   AdrModes[InstrZ++].Mode = NMode;
1086 }
1087 
AddCond(const char * NName,CPUVar MinCPU,Word NCodeAND,Word NCodeOR,Byte NIsZL,Byte NIsC,Byte NIsV,Byte NIsTP)1088 static void AddCond(const char *NName, CPUVar MinCPU, Word NCodeAND, Word NCodeOR, Byte NIsZL,
1089                     Byte NIsC, Byte NIsV, Byte NIsTP)
1090 {
1091   if (InstrZ >= CondCnt) exit(255);
1092   Conditions[InstrZ].Name = NName;
1093   Conditions[InstrZ].MinCPU = MinCPU;
1094   Conditions[InstrZ].CodeAND = NCodeAND;
1095   Conditions[InstrZ].CodeOR = NCodeOR;
1096   Conditions[InstrZ].IsZL = NIsZL;
1097   Conditions[InstrZ].IsC = NIsC;
1098   Conditions[InstrZ].IsV = NIsV;
1099   Conditions[InstrZ++].IsTP = NIsTP;
1100 }
1101 
AddBit(const char * NName,CPUVar MinCPU,Word NCode)1102 static void AddBit(const char *NName, CPUVar MinCPU, Word NCode)
1103 {
1104   if (InstrZ >= BitCnt) exit(255);
1105   BitTable[InstrZ].name = NName;
1106   BitTable[InstrZ].MinCPU = MinCPU;
1107   BitTable[InstrZ++].Code = NCode;
1108 }
1109 
InitFields(void)1110 static void InitFields(void)
1111 {
1112   InstTable = CreateInstTable(203);
1113 
1114   FixedOrders = (FixedOrder *) malloc(sizeof(FixedOrder) * FixedOrderCnt); InstrZ = 0;
1115   AddFixed("ABS",    CPU320203, 0xbe00); AddFixed("ADCB",   CPU32050 , 0xbe11);
1116   AddFixed("ADDB",   CPU32050 , 0xbe10); AddFixed("ANDB",   CPU32050 , 0xbe12);
1117   AddFixed("CMPL",   CPU320203, 0xbe01); AddFixed("CRGT",   CPU32050 , 0xbe1b);
1118   AddFixed("CRLT",   CPU32050 , 0xbe1c); AddFixed("EXAR",   CPU32050 , 0xbe1d);
1119   AddFixed("LACB",   CPU32050 , 0xbe1f); AddFixed("NEG",    CPU320203, 0xbe02);
1120   AddFixed("ORB",    CPU32050 , 0xbe13); AddFixed("ROL",    CPU320203, 0xbe0c);
1121   AddFixed("ROLB",   CPU32050 , 0xbe14); AddFixed("ROR",    CPU320203, 0xbe0d);
1122   AddFixed("RORB",   CPU32050 , 0xbe15); AddFixed("SACB",   CPU32050 , 0xbe1e);
1123   AddFixed("SATH",   CPU32050 , 0xbe5a); AddFixed("SATL",   CPU32050 , 0xbe5b);
1124   AddFixed("SBB",    CPU32050 , 0xbe18); AddFixed("SBBB",   CPU32050 , 0xbe19);
1125   AddFixed("SFL",    CPU320203, 0xbe09); AddFixed("SFLB",   CPU32050 , 0xbe16);
1126   AddFixed("SFR",    CPU320203, 0xbe0a); AddFixed("SFRB",   CPU32050 , 0xbe17);
1127   AddFixed("XORB",   CPU32050 , 0xbe1a); AddFixed("ZAP",    CPU32050 , 0xbe59);
1128   AddFixed("APAC",   CPU320203, 0xbe04); AddFixed("PAC",    CPU320203, 0xbe03);
1129   AddFixed("SPAC",   CPU320203, 0xbe05); AddFixed("ZPR",    CPU32050 , 0xbe58);
1130   AddFixed("BACC",   CPU320203, 0xbe20); AddFixed("BACCD",  CPU32050 , 0xbe21);
1131   AddFixed("CALA",   CPU320203, 0xbe30); AddFixed("CALAD",  CPU32050 , 0xbe3d);
1132   AddFixed("NMI",    CPU320203, 0xbe52); AddFixed("RET",    CPU320203, 0xef00);
1133   AddFixed("RETD",   CPU32050 , 0xff00); AddFixed("RETE",   CPU32050 , 0xbe3a);
1134   AddFixed("RETI",   CPU32050 , 0xbe38); AddFixed("TRAP",   CPU320203, 0xbe51);
1135   AddFixed("IDLE",   CPU320203, 0xbe22); AddFixed("NOP",    CPU320203, 0x8b00);
1136   AddFixed("POP",    CPU320203, 0xbe32); AddFixed("PUSH",   CPU320203, 0xbe3c);
1137   AddFixed("IDLE2",  CPU32050 , 0xbe23);
1138 
1139   AdrOrders = (FixedOrder *) malloc(sizeof(FixedOrder) * AdrOrderCnt); InstrZ = 0;
1140   AddAdr("ADDC",   CPU320203, 0x6000); AddAdr("ADDS",   CPU320203, 0x6200);
1141   AddAdr("ADDT",   CPU320203, 0x6300); AddAdr("LACT",   CPU320203, 0x6b00);
1142   AddAdr("SUBB",   CPU320203, 0x6400); AddAdr("SUBC",   CPU320203, 0x0a00);
1143   AddAdr("SUBS",   CPU320203, 0x6600); AddAdr("SUBT",   CPU320203, 0x6700);
1144   AddAdr("ZALR",   CPU320203, 0x6800); AddAdr("MAR",    CPU320203, 0x8b00);
1145   AddAdr("LPH",    CPU320203, 0x7500); AddAdr("LT",     CPU320203, 0x7300);
1146   AddAdr("LTA",    CPU320203, 0x7000); AddAdr("LTD",    CPU320203, 0x7200);
1147   AddAdr("LTP",    CPU320203, 0x7100); AddAdr("LTS",    CPU320203, 0x7400);
1148   AddAdr("MADD",   CPU32050 , 0xab00); AddAdr("MADS",   CPU32050 , 0xaa00);
1149   AddAdr("MPYA",   CPU320203, 0x5000); AddAdr("MPYS",   CPU320203, 0x5100);
1150   AddAdr("MPYU",   CPU320203, 0x5500); AddAdr("SPH",    CPU320203, 0x8d00);
1151   AddAdr("SPL",    CPU320203, 0x8c00); AddAdr("SQRA",   CPU320203, 0x5200);
1152   AddAdr("SQRS",   CPU320203, 0x5300); AddAdr("BLDP",   CPU32050 , 0x5700);
1153   AddAdr("DMOV",   CPU320203, 0x7700); AddAdr("TBLR",   CPU320203, 0xa600);
1154   AddAdr("TBLW",   CPU320203, 0xa700); AddAdr("BITT",   CPU320203, 0x6f00);
1155   AddAdr("POPD",   CPU320203, 0x8a00); AddAdr("PSHD",   CPU320203, 0x7600);
1156 
1157   JmpOrders = (JmpOrder *) malloc(sizeof(JmpOrder) * JmpOrderCnt); InstrZ = 0;
1158   AddJmp("B",      CPU320203, 0x7980,  False);
1159   AddJmp("BD",     CPU32050 , 0x7d80,  False);
1160   AddJmp("BANZ",   CPU320203, 0x7b80,  False);
1161   AddJmp("BANZD",  CPU32050 , 0x7f80,  False);
1162   AddJmp("BCND",   CPU320203, 0xe000,  True);
1163   AddJmp("BCNDD",  CPU32050 , 0xf000,  True);
1164   AddJmp("CALL",   CPU320203, 0x7a80,  False);
1165   AddJmp("CALLD",  CPU32050 , 0x7e80,  False);
1166   AddJmp("CC",     CPU320203, 0xe800,  True);
1167   AddJmp("CCD",    CPU32050 , 0xf800,  True);
1168 
1169   PluOrders = (FixedOrder *) malloc(sizeof(FixedOrder) * PluOrderCnt); InstrZ = 0;
1170   AddPlu("APL",   CPU32050 , 0x5a00); AddPlu("CPL",   CPU32050 , 0x5b00);
1171   AddPlu("OPL",   CPU32050 , 0x5900); AddPlu("SPLK",  CPU320203, 0xaa00);
1172   AddPlu("XPL",   CPU32050 , 0x5800);
1173 
1174   AdrModes = (tAdrMode *) malloc(sizeof(tAdrMode) * AdrModeCnt); InstrZ = 0;
1175   AddAdrMode( "*-",     CPU320203, 0x90 ); AddAdrMode( "*+",     CPU320203, 0xa0 );
1176   AddAdrMode( "*BR0-",  CPU320203, 0xc0 ); AddAdrMode( "*0-",    CPU320203, 0xd0 );
1177   AddAdrMode( "*AR0-",  CPU32050 , 0xd0 ); AddAdrMode( "*0+",    CPU320203, 0xe0 );
1178   AddAdrMode( "*AR0+",  CPU32050 , 0xe0 ); AddAdrMode( "*BR0+",  CPU320203, 0xf0 );
1179   AddAdrMode( "*",      CPU320203, 0x80 ); AddAdrMode( NULL,     CPU32050 , 0);
1180 
1181   Conditions = (Condition *) malloc(sizeof(Condition) * CondCnt); InstrZ = 0;
1182   AddCond("EQ",  CPU32050 , 0xf33, 0x088, 1, 0, 0, 0);
1183   AddCond("NEQ", CPU32050 , 0xf33, 0x008, 1, 0, 0, 0);
1184   AddCond("LT",  CPU32050 , 0xf33, 0x044, 1, 0, 0, 0);
1185   AddCond("LEQ", CPU32050 , 0xf33, 0x0cc, 1, 0, 0, 0);
1186   AddCond("GT",  CPU32050 , 0xf33, 0x004, 1, 0, 0, 0);
1187   AddCond("GEQ", CPU32050 , 0xf33, 0x08c, 1, 0, 0, 0);
1188   AddCond("NC",  CPU32050 , 0xfee, 0x001, 0, 1, 0, 0);
1189   AddCond("C",   CPU32050 , 0xfee, 0x011, 0, 1, 0, 0);
1190   AddCond("NOV", CPU32050 , 0xfdd, 0x002, 0, 0, 1, 0);
1191   AddCond("OV",  CPU32050 , 0xfdd, 0x022, 0, 0, 1, 0);
1192   AddCond("BIO", CPU32050 , 0x0ff, 0x000, 0, 0, 0, 1);
1193   AddCond("NTC", CPU32050 , 0x0ff, 0x200, 0, 0, 0, 1);
1194   AddCond("TC",  CPU32050 , 0x0ff, 0x100, 0, 0, 0, 1);
1195   AddCond("UNC", CPU32050 , 0x0ff, 0x300, 0, 0, 0, 1);
1196   AddCond(NULL,  CPU32050 , 0xfff, 0x000, 0, 0, 0, 0);
1197 
1198   BitTable = (tBitTable *) malloc(sizeof(tBitTable) * BitCnt); InstrZ = 0;
1199   AddBit("OVM",  CPU320203, 0xbe42 ); AddBit("SXM",  CPU320203, 0xbe46 );
1200   AddBit("HM",   CPU32050 , 0xbe48 ); AddBit("TC",   CPU320203, 0xbe4a );
1201   AddBit("C",    CPU320203, 0xbe4e ); AddBit("XF",   CPU320203, 0xbe4c );
1202   AddBit("CNF",  CPU320203, 0xbe44 ); AddBit("INTM", CPU320203, 0xbe40 );
1203   AddBit(NULL,   CPU32050 , 0     );
1204 
1205   AddInstTable(InstTable, "ADD"  , 0, DecodeADDSUB);
1206   AddInstTable(InstTable, "SUB"  , 1, DecodeADDSUB);
1207   AddInstTable(InstTable, "ADRK" , 0, DecodeADRSBRK);
1208   AddInstTable(InstTable, "SBRK" , 1, DecodeADRSBRK);
1209   AddInstTable(InstTable, "AND"  , 0x6e01, DecodeLogic);
1210   AddInstTable(InstTable, "OR"   , 0x6d02, DecodeLogic);
1211   AddInstTable(InstTable, "XOR"  , 0x6c03, DecodeLogic);
1212   AddInstTable(InstTable, "BIT"  , 0, DecodeBIT);
1213   AddInstTable(InstTable, "BLDD" , 0, DecodeBLDD);
1214   AddInstTable(InstTable, "BLPD" , 0, DecodeBLPD);
1215   AddInstTable(InstTable, "CLRC" , 0, DecodeCLRSETC);
1216   AddInstTable(InstTable, "SETC" , 1, DecodeCLRSETC);
1217   AddInstTable(InstTable, "CMPR" , 0xbf44, DecodeCMPRSPM);
1218   AddInstTable(InstTable, "SPM"  , 0xbf00, DecodeCMPRSPM);
1219   AddInstTable(InstTable, "IN"   , 0xaf00, DecodeIO);
1220   AddInstTable(InstTable, "OUT"  , 0x0c00, DecodeIO);
1221   AddInstTable(InstTable, "INTR" , 0, DecodeINTR);
1222   AddInstTable(InstTable, "LACC" , 0, DecodeLACC);
1223   AddInstTable(InstTable, "LACL" , 0, DecodeLACL);
1224   AddInstTable(InstTable, "LAR"  , 0, DecodeLAR);
1225   AddInstTable(InstTable, "LDP"  , 0, DecodeLDP);
1226   AddInstTable(InstTable, "SST"  , 1, DecodeLSST);
1227   AddInstTable(InstTable, "LST"  , 0, DecodeLSST);
1228   AddInstTable(InstTable, "MAC"  , 0, DecodeMAC);
1229   AddInstTable(InstTable, "MACD" , 1, DecodeMAC);
1230   AddInstTable(InstTable, "MPY"  , 0, DecodeMPY);
1231   AddInstTable(InstTable, "NORM" , 0, DecodeNORM);
1232   AddInstTable(InstTable, "RETC" , 0, DecodeRETC);
1233   AddInstTable(InstTable, "RETCD", 1, DecodeRETC);
1234   AddInstTable(InstTable, "RPT"  , 0, DecodeRPT);
1235   AddInstTable(InstTable, "SACL" , 0, DecodeSAC);
1236   AddInstTable(InstTable, "SACH" , 1, DecodeSAC);
1237   AddInstTable(InstTable, "SAR"  , 0, DecodeSAR);
1238   AddInstTable(InstTable, "BSAR" , 0, DecodeBSAR);
1239   AddInstTable(InstTable, "LAMM" , 0, DecodeLSAMM);
1240   AddInstTable(InstTable, "SAMM" , 1, DecodeLSAMM);
1241   AddInstTable(InstTable, "LMMR" , 1, DecodeLSMMR);
1242   AddInstTable(InstTable, "SMMR" , 0, DecodeLSMMR);
1243   AddInstTable(InstTable, "RPTB" , 0, DecodeRPTB);
1244   AddInstTable(InstTable, "RPTZ" , 0, DecodeRPTZ);
1245   AddInstTable(InstTable, "XC"   , 0, DecodeXC);
1246   AddInstTable(InstTable, "PORT" , 0, DecodePORT);
1247 }
1248 
DeinitFields(void)1249 static void DeinitFields(void)
1250 {
1251   DestroyInstTable(InstTable);
1252   free(FixedOrders);
1253   free(AdrOrders);
1254   free(JmpOrders);
1255   free(PluOrders);
1256   free(AdrModes);
1257   free(Conditions);
1258   free(BitTable);
1259 }
1260 
1261 /* ---------------------------------------------------------------------- */
1262 
MakeCode_3205x(void)1263 static void MakeCode_3205x(void)
1264 {
1265   CodeLen = 0;
1266   DontPrint = False;
1267 
1268   /* zu ignorierendes */
1269 
1270   if (Memo(""))
1271     return;
1272 
1273   /* Pseudoanweisungen */
1274 
1275   if (DecodeTIPseudo())
1276     return;
1277 
1278   /* per Hash-Tabelle */
1279 
1280   if (!LookupInstTable(InstTable, OpPart.Str))
1281     WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
1282 }
1283 
1284 /* ---------------------------------------------------------------------- */
1285 
IsDef_3205x(void)1286 static Boolean IsDef_3205x(void)
1287 {
1288   return Memo("PORT") || IsTIDef();
1289 }
1290 
1291 /* ---------------------------------------------------------------------- */
1292 
SwitchFrom_3205x(void)1293 static void SwitchFrom_3205x(void)
1294 {
1295   DeinitFields();
1296 }
1297 
1298 /* ---------------------------------------------------------------------- */
1299 
SwitchTo_3205x(void)1300 static void SwitchTo_3205x(void)
1301 {
1302   TurnWords = False;
1303   ConstMode = ConstModeIntel;
1304 
1305   PCSymbol = "$";
1306   HeaderID = 0x77;
1307   NOPCode = 0x8b00;
1308   DivideChars = ",";
1309   HasAttrs = False;
1310 
1311   ValidSegs = (1 << SegCode) | (1 << SegData) | (1 << SegIO);
1312   Grans[SegCode] = 2; ListGrans[SegCode] = 2; SegInits[SegCode] = 0;
1313   SegLimits[SegCode] = 0xffff;
1314   Grans[SegData] = 2; ListGrans[SegData] = 2; SegInits[SegData] = 0;
1315   SegLimits[SegData] = 0xffff;
1316   Grans[SegIO  ] = 2; ListGrans[SegIO  ] = 2; SegInits[SegIO  ] = 0;
1317   SegLimits[SegIO  ] = 0xffff;
1318 
1319   MakeCode = MakeCode_3205x;
1320   IsDef = IsDef_3205x;
1321   SwitchFrom = SwitchFrom_3205x;
1322   InitFields();
1323 }
1324 
1325 /* ---------------------------------------------------------------------- */
1326 
code3205x_init(void)1327 void code3205x_init(void)
1328 {
1329   CPU320203 = AddCPU("320C203", SwitchTo_3205x);
1330   CPU32050  = AddCPU("320C50",  SwitchTo_3205x);
1331   CPU32051  = AddCPU("320C51",  SwitchTo_3205x);
1332   CPU32053  = AddCPU("320C53",  SwitchTo_3205x);
1333 
1334   AddCopyright("TMS320C5x-Generator (C) 1995/96 Thomas Sailer");
1335 }
1336