Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1186 savelij 1
/* code9331.c */
2
/*****************************************************************************/
3
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
4
/*                                                                           */
5
/* AS-Portierung                                                             */
6
/*                                                                           */
7
/* Code Generator Toshiba TC9331                                             */
8
/*                                                                           */
9
/*****************************************************************************/
10
 
11
#include "stdinc.h"
12
#include <ctype.h>
13
#include <string.h>
14
 
15
#include "bpemu.h"
16
#include "strutil.h"
17
#include "asmdef.h"
18
#include "asmsub.h"
19
#include "asmpars.h"
20
#include "asmitree.h"
21
#include "headids.h"
22
#include "codevars.h"
23
#include "errmsg.h"
24
 
25
#include "code9331.h"
26
 
27
static CPUVar CPU9331;
28
 
29
static const char *pFNames[] =
30
{
31
  "ZF", "SF", "V0F", "V1F",
32
  "LRF", "GF0", "GF1", "GF2",
33
  "GF3", "IFF0", "IFF1", "IFF2",
34
  NULL
35
};
36
 
37
/* ------------------------------------------------------------------------- */
38
/* Common Subroutines */
39
 
40
static void StripComment(char *pArg)
41
{
42
  char *pStart, *pEnd;
43
 
44
  while (True)
45
  {
46
    pStart = QuotPos(pArg, '(');
47
    if (!pStart)
48
      return;
49
    pEnd = QuotPos(pStart + 1, ')');
50
    if (!pEnd)
51
      return;
52
    strmov(pStart, pEnd + 1);
53
    KillPrefBlanks(pArg);
54
    KillPostBlanks(pArg);
55
  }
56
}
57
 
58
static Boolean DecodeRegList(const char *pNames[], const char *pArg, LongWord *pResult)
59
{
60
  if (!*pArg)
61
  {
62
    *pResult = 0;
63
    return True;
64
  }
65
 
66
  for (*pResult = 0; pNames[*pResult]; (*pResult)++)
67
    if (!as_strcasecmp(pArg, pNames[*pResult]))
68
      return True;
69
 
70
  WrXError(pNames == pFNames ? ErrNum_UndefCond : ErrNum_InvReg, pArg);
71
  return False;
72
}
73
 
74
static Boolean DecodeDSTA(const char *pArg, LongWord *pResult, IntType *pSize)
75
{
76
  static const char *pNames[] =
77
  {
78
    "LC0", "LC1", "CP", "OFP",
79
    "DP0", "DP1", "DP2", "DP3",
80
    "MOD0", "MOD1", "MOD2", "MOD3",
81
    "DF0", "DF1", NULL
82
  };
83
 
84
  if (!*pArg)
85
  {
86
    WrXError(ErrNum_InvReg, pArg);
87
    return False;
88
  }
89
 
90
  if (!DecodeRegList(pNames, pArg, pResult))
91
    return False;
92
 
93
  if (3 == *pResult)
94
    *pSize = UInt6;
95
  else if (2 == *pResult)
96
    *pSize = UInt9;
97
  else
98
    *pSize = (*pResult <= 1) ? UInt8 : UInt7;
99
  return True;
100
}
101
 
102
static Boolean DecodeWRF(const char *pArg, LongWord *pResult)
103
{
104
  static const char *pNames[] =
105
  {
106
    "WF0", "WF1", "WF2", "W1",
107
    NULL
108
  };
109
 
110
  return DecodeRegList(pNames, pArg, pResult);
111
}
112
 
113
static Boolean DecodeDEST(const char *pArg, LongWord *pResult, Boolean AllowAll)
114
{
115
  static const char *pNames[] =
116
  {
117
    "NOP", "X", "W0", "W1",
118
    "Y", "DP", "XAD", "PO",
119
    "SO0", "SO1", "SO2", "XD",
120
    "C", "O", "D", "B",
121
    "XA", "A",
122
    NULL
123
  };
124
  Boolean Result;
125
 
126
  Result = DecodeRegList(pNames, pArg, pResult);
127
  if (!Result)
128
    return Result;
129
 
130
  switch (*pResult)
131
  {
132
    case 17:
133
      if (AllowAll)
134
        *pResult = 14; /* A -> D */
135
      else
136
        Result = False;
137
      break;
138
    case 16:
139
      if (AllowAll)
140
        *pResult = 11; /* XA -> XD */
141
      else
142
        Result = False;
143
      break;
144
    case 15:
145
      if (!AllowAll)
146
        Result = False;
147
      break;
148
    default:
149
      break;
150
  }
151
  if (!Result)
152
    WrXError(ErrNum_InvReg, pArg);
153
  return Result;
154
}
155
 
156
static Boolean DecodeSOUR(const char *pArg, LongWord *pResult, Boolean AllowAll)
157
{
158
  static const char *pNames[] =
159
  {
160
    "RND", "X", "W0", "W1",
161
    "", "DP", "", "PI",
162
    "PO", "SI0", "SI1", "RMR",
163
    "C", "O", "D", "B",
164
    "A",
165
    NULL
166
  };
167
  Boolean Result;
168
 
169
  Result = DecodeRegList(pNames, pArg, pResult);
170
  if (!Result)
171
    return Result;
172
 
173
  switch (*pResult)
174
  {
175
    case 16:
176
      if (AllowAll)
177
        *pResult = 14; /* A -> D */
178
      else
179
        Result = False;
180
      break;
181
    case 15:
182
      if (!AllowAll)
183
        Result = False;
184
      break;
185
    default:
186
      break;
187
  }
188
 
189
  if (!Result)
190
    WrXError(ErrNum_InvReg, pArg);
191
  return Result;
192
}
193
 
194
static Boolean DecodeXCNT(const char *pArg, LongWord *pResult)
195
{
196
  static const char *pNames[] =
197
  {
198
    "STBY", "XRD", "WRX", "XREF",
199
    NULL
200
  };
201
 
202
  return DecodeRegList(pNames, pArg, pResult);
203
}
204
 
205
static Boolean DecodeXS(const char *pArg, LongWord *pResult)
206
{
207
  static const char *pNames[] =
208
  {
209
    "X", "W",
210
    NULL
211
  };
212
 
213
  return DecodeRegList(pNames, pArg, pResult);
214
}
215
 
216
static Boolean DecodeYS(const char *pArg, LongWord *pResult)
217
{
218
  static const char *pNames[] =
219
  {
220
    "Y", "X",
221
    NULL
222
  };
223
 
224
  return DecodeRegList(pNames, pArg, pResult);
225
}
226
 
227
static Boolean DecodeZS(const char *pArg, LongWord *pResult)
228
{
229
  static const char *pNames[] =
230
  {
231
    "0", "W", "AC",
232
    NULL
233
  };
234
 
235
  return DecodeRegList(pNames, pArg, pResult);
236
}
237
 
238
static Boolean DecodeWS(const char *pArg, LongWord *pResult)
239
{
240
  static const char *pNames[] =
241
  {
242
    "W0", "W1",
243
    NULL
244
  };
245
 
246
  return DecodeRegList(pNames, pArg, pResult);
247
}
248
 
249
static Boolean DecodeCP(const char *pArg, LongWord *pResult)
250
{
251
  static const char *pNames[] =
252
  {
253
    "NOP", "CP+",
254
    NULL
255
  };
256
 
257
  return DecodeRegList(pNames, pArg, pResult);
258
}
259
 
260
static Boolean DecodeDPS(const char *pArg, LongWord *pResult)
261
{
262
  static const char *pNames[] =
263
  {
264
    "DP0", "DP1", "DP2", "DP3",
265
    NULL
266
  };
267
 
268
  return DecodeRegList(pNames, pArg, pResult);
269
}
270
 
271
static Boolean DecodeMODE(const char *pArg, LongWord *pResult)
272
{
273
  static const char *pNames[] =
274
  {
275
    "NOP", "", "-", "+",
276
    "-DF0", "+DF0", "-DF1", "+DF1",
277
    NULL
278
  };
279
 
280
  return DecodeRegList(pNames, pArg, pResult);
281
}
282
 
283
static Boolean DecodeOFP(const char *pArg, LongWord *pResult)
284
{
285
  static const char *pNames[] =
286
  {
287
    "NOP", "OFP+",
288
    NULL
289
  };
290
 
291
  return DecodeRegList(pNames, pArg, pResult);
292
}
293
 
294
static Boolean DecodeER(const char *pArg, LongWord *pResult)
295
{
296
  static const char *pNames[] =
297
  {
298
    "NOP", "ER",
299
    NULL
300
  };
301
 
302
  return DecodeRegList(pNames, pArg, pResult);
303
}
304
 
305
static Boolean DecodeDSTB(const char *pArg, LongWord *pResult)
306
{
307
  static const char *pNames[] =
308
  {
309
    "W1", "X",
310
    NULL
311
  };
312
 
313
  return DecodeRegList(pNames, pArg, pResult);
314
}
315
 
316
static Boolean DecodeFORM(const char *pArg, LongWord *pResult)
317
{
318
  static const char *pNames[] =
319
  {
320
    "L", "R",
321
    NULL
322
  };
323
 
324
  return DecodeRegList(pNames, pArg, pResult);
325
}
326
 
327
static Boolean DecodeGFX(const char *pArg, LongWord *pResult)
328
{
329
  static const char *pNames[] =
330
  {
331
    "GFS", "", "", "GFC",
332
    NULL
333
  };
334
 
335
  if (!*pArg)
336
  {
337
    WrXError(ErrNum_InvReg, pArg);
338
    return False;
339
  }
340
 
341
  return DecodeRegList(pNames, pArg, pResult);
342
}
343
 
344
static Boolean DecodeGF(const char *pArg, LongWord *pResult)
345
{
346
  static const char *pNames[] =
347
  {
348
    "GF0", "GF1", "GF2", "GF3",
349
    "OV0", "OV1", "FCHG", "BNK",
350
    NULL
351
  };
352
 
353
  return DecodeRegList(pNames, pArg, pResult);
354
}
355
 
356
 
357
/* ------------------------------------------------------------------------- */
358
/* Instruction Decoders */
359
 
360
static void DecodeMAIN(Word Code)
361
{
362
  LongWord Xs, Ys, Zs, Wrf, Ws, Cp, Dps, Mode, Dest, Sour, Xcnt, Ofp, Er,
363
           LCode = Lo(Code);
364
  Boolean UseZS = Hi(Code) || False;
365
 
366
  if (!ChkArgCnt(15, 15));
367
  else if (*ArgStr[1].str.p_str) WrError(ErrNum_InvAddrMode);
368
  else if (!DecodeXS(ArgStr[3].str.p_str, &Xs));
369
  else if (!DecodeYS(ArgStr[4].str.p_str, &Ys));
370
  else if (!DecodeZS(ArgStr[5].str.p_str, &Zs));
371
  else if (!DecodeWRF(ArgStr[6].str.p_str, &Wrf));
372
  else if (!DecodeWS(ArgStr[7].str.p_str, &Ws));
373
  else if (!DecodeCP(ArgStr[8].str.p_str, &Cp));
374
  else if (!DecodeDPS(ArgStr[9].str.p_str, &Dps));
375
  else if (!DecodeMODE(ArgStr[10].str.p_str, &Mode));
376
  else if (!DecodeDEST(ArgStr[11].str.p_str, &Dest, True));
377
  else if (!DecodeSOUR(ArgStr[12].str.p_str, &Sour, True));
378
  else if (!DecodeXCNT(ArgStr[13].str.p_str, &Xcnt));
379
  else if (Xcnt == 2) WrStrErrorPos(ErrNum_InvReg, &ArgStr[13]);
380
  else if (!DecodeOFP(ArgStr[14].str.p_str, &Ofp));
381
  else if (!DecodeER(ArgStr[15].str.p_str, &Er));
382
  else
383
  {
384
    Boolean OK = True;
385
    Word Shift;
386
    tSymbolFlags Flags = eSymbolFlag_None;
387
 
388
    Shift = *ArgStr[2].str.p_str ? EvalStrIntExpressionWithFlags(&ArgStr[2], UInt3, &OK, &Flags) : 0;
389
    if (mFirstPassUnknown(Flags))
390
      Shift = 0;
391
 
392
    DAsmCode[0] = (LCode << 26)
393
                | (Xs << 24) | (Ys << 23)
394
                | (Wrf << 20) | (Ws << 22) | (Cp << 16) | (Dps << 13)
395
                | (Mode << 10) | (Dest << 0) | (Sour << 4) | (Xcnt << 8)
396
                | (Ofp << 15) | (Er << 25);
397
    if (UseZS)
398
      DAsmCode[0] |= (Zs << 26);
399
    switch (Shift)
400
    {
401
      case 0:
402
        break;
403
      case 1:
404
        DAsmCode[0] |= 0x00040000ul;
405
        break;
406
      case 4:
407
        DAsmCode[0] |= 0x00080000ul;
408
        break;
409
      default:
410
        WrStrErrorPos(ErrNum_InvShiftArg, &ArgStr[2]);
411
        return;
412
    }
413
 
414
    CodeLen = 1;
415
  }
416
}
417
 
418
static void DecodeLDA(Word Code)
419
{
420
  LongWord DstA, Wrf, Dest, Sour, Xcnt;
421
  IntType IntSize;
422
 
423
  UNUSED(Code);
424
 
425
  if (!ChkArgCnt(7, 7));
426
  else if (*ArgStr[1].str.p_str) WrError(ErrNum_InvAddrMode);
427
  else if (!DecodeDSTA(ArgStr[2].str.p_str, &DstA, &IntSize));
428
  else if (!DecodeWRF(ArgStr[4].str.p_str, &Wrf));
429
  else if (!DecodeDEST(ArgStr[5].str.p_str, &Dest, False));
430
  else if (!DecodeSOUR(ArgStr[6].str.p_str, &Sour, False));
431
  else if (Sour > 14) WrStrErrorPos(ErrNum_InvReg, &ArgStr[6]);
432
  else if (!DecodeXCNT(ArgStr[7].str.p_str, &Xcnt));
433
  else if (Xcnt == 2) WrStrErrorPos(ErrNum_InvReg, &ArgStr[7]);
434
  else
435
  {
436
    Boolean OK;
437
    LongWord Value = EvalStrIntExpression(&ArgStr[3], IntSize, &OK);
438
 
439
    if (OK)
440
    {
441
      DAsmCode[0] = 0x04000000ul
442
                  | (DstA << 22) | (Wrf << 20) | (Dest << 0) | (Sour << 4) | (Xcnt << 8)
443
                  | ((Value << 10) & 0x7fc00);
444
      CodeLen = 1;
445
    }
446
  }
447
}
448
 
449
static void DecodeLDB(Word Code)
450
{
451
  LongWord DstB, Form;
452
 
453
  UNUSED(Code);
454
 
455
  if (!ChkArgCnt(4, 4));
456
  else if (*ArgStr[1].str.p_str) WrError(ErrNum_InvAddrMode);
457
  else if (!DecodeDSTB(ArgStr[2].str.p_str, &DstB));
458
  else if (!DecodeFORM(ArgStr[4].str.p_str, &Form));
459
  else
460
  {
461
    Boolean OK;
462
    LongWord Value = EvalStrIntExpression(&ArgStr[3], UInt24, &OK);
463
 
464
    if (OK)
465
    {
466
      DAsmCode[0] = 0x08000000ul
467
                  | (DstB << 1) | (Form << 0)
468
                  | ((Value & 0xffffff) << 2);
469
      CodeLen = 1;
470
    }
471
  }
472
}
473
 
474
static void DecodeBR(Word Code)
475
{
476
  LongWord Cp, Dps, Mode, Dest, Sour, Xcnt, Ofp;
477
 
478
  if (!ChkArgCnt(9, 9));
479
  else if (*ArgStr[1].str.p_str) WrError(ErrNum_InvAddrMode);
480
  else if (!DecodeCP(ArgStr[3].str.p_str, &Cp));
481
  else if (!DecodeDPS(ArgStr[4].str.p_str, &Dps));
482
  else if (!DecodeMODE(ArgStr[5].str.p_str, &Mode));
483
  else if (!DecodeDEST(ArgStr[6].str.p_str, &Dest, False));
484
  else if (!DecodeSOUR(ArgStr[7].str.p_str, &Sour, False));
485
  else if (!DecodeXCNT(ArgStr[8].str.p_str, &Xcnt));
486
  else if (!DecodeOFP(ArgStr[9].str.p_str, &Ofp));
487
  else
488
  {
489
    Boolean OK;
490
    LongWord Address;
491
    tSymbolFlags Flags;
492
 
493
    Address = EvalStrIntExpressionWithFlags(&ArgStr[2], UInt9, &OK, &Flags);
494
    if (mFirstPassUnknown(Flags))
495
      Address &= 0xff;
496
    if (OK && ChkRange(Address, 0, SegLimits[SegCode]))
497
    {
498
      DAsmCode[0] = (((LongWord)Code) << 26)
499
                  | (Address << 17) | (Cp << 16) | (Dps << 13) | (Mode << 10)
500
                  | (Dest << 0) | (Sour << 4) | (Xcnt << 8) | (Ofp << 15);
501
      CodeLen = 1;
502
    }
503
  }
504
}
505
 
506
static void DecodeJC(Word Code)
507
{
508
  LongWord F, Cp, Dps, Mode, Dest, Sour, Xcnt, Ofp;
509
 
510
  if (!ChkArgCnt(10, 10));
511
  else if (*ArgStr[1].str.p_str) WrError(ErrNum_InvAddrMode);
512
  else if (!DecodeRegList(pFNames, ArgStr[3].str.p_str, &F));
513
  else if (!DecodeCP(ArgStr[4].str.p_str, &Cp));
514
  else if (!DecodeDPS(ArgStr[5].str.p_str, &Dps));
515
  else if (!DecodeMODE(ArgStr[6].str.p_str, &Mode));
516
  else if (!DecodeDEST(ArgStr[7].str.p_str, &Dest, False));
517
  else if (!DecodeSOUR(ArgStr[8].str.p_str, &Sour, False));
518
  else if (!DecodeXCNT(ArgStr[9].str.p_str, &Xcnt));
519
  else if (!DecodeOFP(ArgStr[10].str.p_str, &Ofp));
520
  else
521
  {
522
    Boolean OK;
523
    LongWord Address;
524
    tSymbolFlags Flags;
525
 
526
    Address = EvalStrIntExpressionWithFlags(&ArgStr[2], UInt9, &OK, &Flags);
527
    if (mFirstPassUnknown(Flags))
528
      Address &= 0xff;
529
    if (OK && ChkRange(Address, 0, SegLimits[SegCode]))
530
    {
531
      F = (F << 2) + ((LongWord)Code);
532
      DAsmCode[0] = (F << 24)
533
                  | (Address << 17) | (Cp << 16) | (Dps << 13) | (Mode << 10)
534
                  | (Dest << 0) | (Sour << 4) | (Xcnt << 8) | (Ofp << 15);
535
      CodeLen = 1;
536
    }
537
  }
538
}
539
 
540
static void DecodeRET(Word Code)
541
{
542
  LongWord Xs, Ys, Wrf, Ws, Cp, Dps, Mode, Dest, Sour, Xcnt, Ofp;
543
 
544
  UNUSED(Code);
545
 
546
  if (!ChkArgCnt(13, 13));
547
  else if (*ArgStr[1].str.p_str) WrError(ErrNum_InvAddrMode);
548
  else if (!DecodeXS(ArgStr[3].str.p_str, &Xs));
549
  else if (!DecodeYS(ArgStr[4].str.p_str, &Ys));
550
  else if (!DecodeWRF(ArgStr[5].str.p_str, &Wrf));
551
  else if (!DecodeWS(ArgStr[6].str.p_str, &Ws));
552
  else if (!DecodeCP(ArgStr[7].str.p_str, &Cp));
553
  else if (!DecodeDPS(ArgStr[8].str.p_str, &Dps));
554
  else if (!DecodeMODE(ArgStr[9].str.p_str, &Mode));
555
  else if (!DecodeDEST(ArgStr[10].str.p_str, &Dest, True));
556
  else if (!DecodeSOUR(ArgStr[11].str.p_str, &Sour, True));
557
  else if (!DecodeXCNT(ArgStr[12].str.p_str, &Xcnt));
558
  else if (Xcnt == 2) WrStrErrorPos(ErrNum_InvReg, &ArgStr[12]);
559
  else if (!DecodeOFP(ArgStr[13].str.p_str, &Ofp));
560
  else
561
  {
562
    Boolean OK = True;
563
    Word Shift;
564
    tSymbolFlags Flags = eSymbolFlag_None;
565
 
566
    Shift = *ArgStr[2].str.p_str ? EvalStrIntExpressionWithFlags(&ArgStr[2], UInt3, &OK, &Flags) : 0;
567
    if (mFirstPassUnknown(Flags))
568
      Shift = 0;
569
 
570
    DAsmCode[0] = 0xc4000000ul
571
                | (Xs << 24) | (Ys << 23)
572
                | (Wrf << 20) | (Ws << 22) | (Cp << 16) | (Dps << 13)
573
                | (Mode << 10) | (Dest << 0) | (Sour << 4) | (Xcnt << 8)
574
                | (Ofp << 15);
575
    switch (Shift)
576
    {
577
      case 0:
578
        break;
579
      case 1:
580
        DAsmCode[0] |= 0x00040000ul;
581
        break;
582
      case 4:
583
        DAsmCode[0] |= 0x00080000ul;
584
        break;
585
      default:
586
        WrStrErrorPos(ErrNum_InvShiftArg, &ArgStr[2]);
587
        return;
588
    }
589
 
590
    /* ??? */
591
 
592
    if ((Sour == 15) || (Dest == 15))
593
      DAsmCode[0] |= 0x00020000;
594
 
595
    CodeLen = 1;
596
  }
597
}
598
 
599
static void DecodeGMAx(Word Code)
600
{
601
  LongWord Gfx, Gf, Wrf, Ws, Cp, Dps, Mode, Dest, Sour, Xcnt, Ofp;
602
 
603
  if (!ChkArgCnt(12, 12));
604
  else if (*ArgStr[1].str.p_str) WrError(ErrNum_InvAddrMode);
605
  else if (!DecodeGFX(ArgStr[2].str.p_str, &Gfx));
606
  else if (!DecodeGF(ArgStr[3].str.p_str, &Gf));
607
  else if (!DecodeWRF(ArgStr[4].str.p_str, &Wrf));
608
  else if (!DecodeWS(ArgStr[5].str.p_str, &Ws));
609
  else if (!DecodeCP(ArgStr[6].str.p_str, &Cp));
610
  else if (!DecodeDPS(ArgStr[7].str.p_str, &Dps));
611
  else if (!DecodeMODE(ArgStr[8].str.p_str, &Mode));
612
  else if (!DecodeDEST(ArgStr[9].str.p_str, &Dest, True));
613
  else if (!DecodeSOUR(ArgStr[10].str.p_str, &Sour, True));
614
  else if (!DecodeXCNT(ArgStr[11].str.p_str, &Xcnt));
615
  else if (Xcnt == 2) WrStrErrorPos(ErrNum_InvReg, &ArgStr[11]);
616
  else if (!DecodeOFP(ArgStr[12].str.p_str, &Ofp));
617
  else
618
  {
619
    DAsmCode[0] = 0x0c000000ul | (((LongWord)Code) << 16)
620
                | (Gfx << 28) | (Gf << 23)
621
                | (Wrf << 20) | (Ws << 22) | (Cp << 16) | (Dps << 13)
622
                | (Mode << 10) | (Dest << 0) | (Sour << 4) | (Xcnt << 8)
623
                | (Ofp << 15);
624
 
625
    /* ??? */
626
 
627
    if ((Sour == 15) || (Dest == 15))
628
      DAsmCode[0] |= 0x00020000;
629
 
630
    CodeLen = 1;
631
  }
632
}
633
 
634
/* ------------------------------------------------------------------------- */
635
/* Dynamic Code Table Handling */
636
 
637
static void InitFields(void)
638
{
639
  InstTable = CreateInstTable(107);
640
 
641
  AddInstTable(InstTable, "NOP",  0x0000, DecodeMAIN);
642
  AddInstTable(InstTable, "AND",  0x0004, DecodeMAIN);
643
  AddInstTable(InstTable, "OR",   0x0005, DecodeMAIN);
644
  AddInstTable(InstTable, "XOR",  0x0006, DecodeMAIN);
645
  AddInstTable(InstTable, "NOT",  0x0007, DecodeMAIN);
646
  AddInstTable(InstTable, "SUB",  0x0108, DecodeMAIN);
647
  AddInstTable(InstTable, "ABS",  0x000b, DecodeMAIN);
648
  AddInstTable(InstTable, "CMP",  0x010c, DecodeMAIN);
649
  AddInstTable(InstTable, "WCL",  0x0010, DecodeMAIN);
650
  AddInstTable(InstTable, "WRS",  0x0011, DecodeMAIN);
651
  AddInstTable(InstTable, "ACS",  0x0012, DecodeMAIN);
652
  AddInstTable(InstTable, "MAD",  0x0114, DecodeMAIN);
653
  AddInstTable(InstTable, "MADS", 0x0118, DecodeMAIN);
654
  AddInstTable(InstTable, "DMAD", 0x001e, DecodeMAIN);
655
  AddInstTable(InstTable, "DMAS", 0x001f, DecodeMAIN);
656
  AddInstTable(InstTable, "LDA", 0, DecodeLDA);
657
  AddInstTable(InstTable, "LDB", 0, DecodeLDB);
658
  AddInstTable(InstTable, "JMP0", 0x20, DecodeBR);
659
  AddInstTable(InstTable, "JMP1", 0x21, DecodeBR);
660
  AddInstTable(InstTable, "JNZ0", 0x22, DecodeBR);
661
  AddInstTable(InstTable, "JNZ1", 0x23, DecodeBR);
662
  AddInstTable(InstTable, "JZ0",  0x32, DecodeBR);
663
  AddInstTable(InstTable, "JZ1",  0x33, DecodeBR);
664
  AddInstTable(InstTable, "CALL", 0x30, DecodeBR);
665
  AddInstTable(InstTable, "JC", 0xd0, DecodeJC);
666
  AddInstTable(InstTable, "JNC", 0x90, DecodeJC);
667
  AddInstTable(InstTable, "RET", 0, DecodeRET);
668
  AddInstTable(InstTable, "GMA" , 0, DecodeGMAx);
669
  AddInstTable(InstTable, "GMAD", 4, DecodeGMAx);
670
  AddInstTable(InstTable, "GMAS", 8, DecodeGMAx);
671
}
672
 
673
static void DeinitFields(void)
674
{
675
  DestroyInstTable(InstTable);
676
}
677
 
678
/* ------------------------------------------------------------------------- */
679
/* Adaptors */
680
 
681
static void MakeCode_9331(void)
682
{
683
  int z;
684
 
685
  /* TC9331 knows default instructions: may be NOP or GF command */
686
 
687
  if (Memo(""))
688
  {
689
    switch (ArgCnt)
690
    {
691
      case 12:
692
        strmaxcpy(OpPart.str.p_str, "GMA", sizeof(OpPart));
693
        break;
694
      case 15:
695
        strmaxcpy(OpPart.str.p_str, "NOP", sizeof(OpPart));
696
        break;
697
      case 0:
698
        return;
699
      default:
700
        WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
701
        return;
702
    }
703
  }
704
 
705
  /* Toshiba assembler treats parts in ( ) as comments - trim them
706
     out of the arguments.  This will also break more complex formulas,
707
     but you are not going to use them on a processor of 320 words
708
     of program space anyway... */
709
 
710
  for (z = 1; z < ArgCnt; z++)
711
    StripComment(ArgStr[z].str.p_str);
712
 
713
  if (!LookupInstTable(InstTable, OpPart.str.p_str))
714
    WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
715
}
716
 
717
static Boolean IsDef_9331(void)
718
{
719
  return False;
720
}
721
 
722
static void SwitchFrom_9331(void)
723
{
724
  DeinitFields();
725
}
726
 
727
static void SwitchTo_9331(void)
728
{
729
  const TFamilyDescr *pDescr;
730
 
731
  pDescr = FindFamilyByName("TC9331");
732
 
733
  TurnWords = False;
734
  SetIntConstMode(eIntConstModeIntel);
735
 
736
  PCSymbol = "$";
737
  HeaderID = pDescr->Id;
738
  NOPCode = 0x00000000;
739
  DivideChars = ",";
740
  HasAttrs = False;
741
 
742
  ValidSegs = 1 << SegCode;
743
  Grans[SegCode] = 4; ListGrans[SegCode] = 4; SegInits[SegCode] = 0;
744
  SegLimits[SegCode] = 319;
745
 
746
  MakeCode = MakeCode_9331;
747
  IsDef = IsDef_9331;
748
  SwitchFrom = SwitchFrom_9331;
749
  InitFields();
750
}
751
 
752
extern void code9331_init(void)
753
{
754
  CPU9331 = AddCPU("TC9331", SwitchTo_9331);
755
}