-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
code3203x.c
1558 lines (1433 loc) · 47.5 KB
/
code3203x.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* code3203x.c */
/*****************************************************************************/
/* AS-Portierung */
/* */
/* Codegenerator TMS320C3x-Familie */
/* */
/* Historie: 12.12.1996 Grundsteinlegung */
/* 7. 7.1998 Fix Zugriffe auf CharTransTable wg. signed chars */
/* 18. 8.1998 BookKeeping-Aufruf in RES */
/* 3. 1.1998 ChkPC-Anpassung */
/* 9. 3.2000 'ambiguous else'-Warnungen beseitigt */
/* */
/*****************************************************************************/
/* $Id: code3203x.c,v 1.6 2010/04/17 13:14:19 alfred Exp $ */
/*****************************************************************************
* $Log: code3203x.c,v $
* Revision 1.6 2010/04/17 13:14:19 alfred
* - address overlapping strcpy()
*
* Revision 1.5 2008/11/23 10:39:16 alfred
* - allow strings with NUL characters
*
* Revision 1.4 2007/11/24 22:48:03 alfred
* - some NetBSD changes
*
* Revision 1.3 2005/10/02 10:00:44 alfred
* - ConstLongInt gets default base, correct length check on KCPSM3 registers
*
* Revision 1.2 2005/09/08 17:31:03 alfred
* - add missing include
*
* Revision 1.1 2003/11/06 02:49:19 alfred
* - recreated
*
* Revision 1.4 2003/05/02 21:23:09 alfred
* - strlen() updates
*
* Revision 1.3 2002/08/14 18:17:35 alfred
* - warn about NULL allocation
*
* Revision 1.2 2002/07/14 18:39:58 alfred
* - fixed TempAll-related warnings
*
*****************************************************************************/
#include "stdinc.h"
#include <ctype.h>
#include <string.h>
#include "nls.h"
#include "endian.h"
#include "bpemu.h"
#include "strutil.h"
#include "chunks.h"
#include "asmdef.h"
#include "asmsub.h"
#include "asmpars.h"
#include "asmcode.h"
#include "asmitree.h"
#include "codepseudo.h"
#include "codevars.h"
#define ConditionCount 28
#define FixedOrderCount 3
#define RotOrderCount 4
#define StkOrderCount 4
#define GenOrderCount 41
#define ParOrderCount 8
#define SingOrderCount 3
typedef struct
{
char *Name;
Byte Code;
} Condition;
typedef struct
{
char *Name;
LongWord Code;
} FixedOrder;
typedef struct
{
char *Name;
int NameLen;
Boolean May1,May3;
Byte Code,Code3;
Boolean OnlyMem;
Boolean SwapOps;
Boolean ImmFloat;
Byte ParMask,Par3Mask;
Byte PCodes[8],P3Codes[8];
} GenOrder;
typedef struct
{
char *Name;
LongWord Code;
Byte Mask;
} SingOrder;
static CPUVar CPU32030,CPU32031;
static SimpProc SaveInitProc;
static Boolean NextPar,ThisPar;
static Byte PrevARs,ARs;
static char PrevOp[7];
static int z2;
static ShortInt PrevSrc1Mode,PrevSrc2Mode,PrevDestMode;
static ShortInt CurrSrc1Mode,CurrSrc2Mode,CurrDestMode;
static Word PrevSrc1Part,PrevSrc2Part,PrevDestPart;
static Word CurrSrc1Part,CurrSrc2Part,CurrDestPart;
static Condition *Conditions;
static FixedOrder *FixedOrders;
static char **RotOrders;
static char **StkOrders;
static GenOrder *GenOrders;
static char **ParOrders;
static SingOrder *SingOrders;
static LongInt DPValue;
/*-------------------------------------------------------------------------*/
/* Befehlstabellenverwaltung */
static void AddCondition(char *NName, Byte NCode)
BEGIN
if (InstrZ>=ConditionCount) exit(255);
Conditions[InstrZ].Name=NName;
Conditions[InstrZ++].Code=NCode;
END
static void AddFixed(char *NName, LongWord NCode)
BEGIN
if (InstrZ>=FixedOrderCount) exit(255);
FixedOrders[InstrZ].Name=NName;
FixedOrders[InstrZ++].Code=NCode;
END
static void AddSing(char *NName, LongWord NCode, Byte NMask)
BEGIN
if (InstrZ>=SingOrderCount) exit(255);
SingOrders[InstrZ].Name=NName;
SingOrders[InstrZ].Code=NCode;
SingOrders[InstrZ++].Mask=NMask;
END
static void AddGen(char *NName, Boolean NMay1, Boolean NMay3,
Byte NCode, Byte NCode3,
Boolean NOnly, Boolean NSwap, Boolean NImm,
Byte NMask1, Byte NMask3,
Byte C20, Byte C21, Byte C22, Byte C23, Byte C24,
Byte C25, Byte C26, Byte C27, Byte C30, Byte C31,
Byte C32, Byte C33, Byte C34, Byte C35, Byte C36,
Byte C37)
BEGIN
if (InstrZ>=GenOrderCount) exit(255);
GenOrders[InstrZ].Name=NName;
GenOrders[InstrZ].NameLen=strlen(NName);
GenOrders[InstrZ].May1=NMay1; GenOrders[InstrZ].May3=NMay3;
GenOrders[InstrZ].Code=NCode; GenOrders[InstrZ].Code3=NCode3;
GenOrders[InstrZ].OnlyMem=NOnly; GenOrders[InstrZ].SwapOps=NSwap;
GenOrders[InstrZ].ImmFloat=NImm;
GenOrders[InstrZ].ParMask=NMask1; GenOrders[InstrZ].Par3Mask=NMask3;
GenOrders[InstrZ].PCodes[0]=C20; GenOrders[InstrZ].PCodes[1]=C21;
GenOrders[InstrZ].PCodes[2]=C22; GenOrders[InstrZ].PCodes[3]=C23;
GenOrders[InstrZ].PCodes[4]=C24; GenOrders[InstrZ].PCodes[5]=C25;
GenOrders[InstrZ].PCodes[6]=C26; GenOrders[InstrZ].PCodes[7]=C27;
GenOrders[InstrZ].P3Codes[0]=C30; GenOrders[InstrZ].P3Codes[1]=C31;
GenOrders[InstrZ].P3Codes[2]=C32; GenOrders[InstrZ].P3Codes[3]=C33;
GenOrders[InstrZ].P3Codes[4]=C34; GenOrders[InstrZ].P3Codes[5]=C35;
GenOrders[InstrZ].P3Codes[6]=C36; GenOrders[InstrZ++].P3Codes[7]=C37;
END
static void InitFields(void)
BEGIN
Conditions=(Condition *) malloc(sizeof(Condition)*ConditionCount); InstrZ=0;
AddCondition("U" ,0x00); AddCondition("LO" ,0x01);
AddCondition("LS" ,0x02); AddCondition("HI" ,0x03);
AddCondition("HS" ,0x04); AddCondition("EQ" ,0x05);
AddCondition("NE" ,0x06); AddCondition("LT" ,0x07);
AddCondition("LE" ,0x08); AddCondition("GT" ,0x09);
AddCondition("GE" ,0x0a); AddCondition("Z" ,0x05);
AddCondition("NZ" ,0x06); AddCondition("P" ,0x09);
AddCondition("N" ,0x07); AddCondition("NN" ,0x0a);
AddCondition("NV" ,0x0c); AddCondition("V" ,0x0d);
AddCondition("NUF",0x0e); AddCondition("UF" ,0x0f);
AddCondition("NC" ,0x04); AddCondition("C" ,0x01);
AddCondition("NLV",0x10); AddCondition("LV" ,0x11);
AddCondition("NLUF",0x12);AddCondition("LUF",0x13);
AddCondition("ZUF",0x14); AddCondition("" ,0x00);
FixedOrders=(FixedOrder *) malloc(sizeof(FixedOrder)*FixedOrderCount); InstrZ=0;
AddFixed("IDLE",0x06000000); AddFixed("SIGI",0x16000000);
AddFixed("SWI" ,0x66000000);
RotOrders=(char **) malloc(sizeof(char *)*RotOrderCount); InstrZ=0;
RotOrders[InstrZ++]="ROL"; RotOrders[InstrZ++]="ROLC";
RotOrders[InstrZ++]="ROR"; RotOrders[InstrZ++]="RORC";
StkOrders=(char **) malloc(sizeof(char *)*StkOrderCount); InstrZ=0;
StkOrders[InstrZ++]="POP"; StkOrders[InstrZ++]="POPF";
StkOrders[InstrZ++]="PUSH"; StkOrders[InstrZ++]="PUSHF";
GenOrders=(GenOrder *) malloc(sizeof(GenOrder)*GenOrderCount); InstrZ=0;
/* Name May3 Cd3 Swap PM1 PCodes3 */
/* May1 Cd1 OMem ImmF PM3 PCodes1 */
AddGen("ABSF" ,True ,False,0x00,0xff,False,False,True , 4, 0,
0xff,0xff,0x04,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("ABSI" ,True ,False,0x01,0xff,False,False,False, 8, 0,
0xff,0xff,0xff,0x05,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("ADDC" ,False,True ,0x02,0x00,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("ADDF" ,False,True ,0x03,0x01,False,False,True , 0, 4,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0x06,0xff,0xff,0xff,0xff,0xff);
AddGen("ADDI" ,False,True ,0x04,0x02,False,False,False, 0, 8,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x07,0xff,0xff,0xff,0xff);
AddGen("AND" ,False,True ,0x05,0x03,False,False,False, 0, 8,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x08,0xff,0xff,0xff,0xff);
AddGen("ANDN" ,False,True ,0x06,0x04,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("ASH" ,False,True ,0x07,0x05,False,False,False, 0, 8,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x09,0xff,0xff,0xff,0xff);
AddGen("CMPF" ,False,True ,0x08,0x06,False,False,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("CMPI" ,False,True ,0x09,0x07,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("FIX" ,True ,False,0x0a,0xff,False,False,True , 8, 0,
0xff,0xff,0xff,0x0a,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("FLOAT",True ,False,0x0b,0xff,False,False,False, 4, 0,
0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("LDE" ,False,False,0x0d,0xff,False,False,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("LDF" ,False,False,0x0e,0xff,False,False,True , 5, 0,
0x02,0xff,0x0c,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("LDFI" ,False,False,0x0f,0xff,True ,False,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("LDI" ,False,False,0x10,0xff,False,False,False,10, 0,
0xff,0x03,0xff,0x0d,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("LDII" ,False,False,0x11,0xff,True ,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("LDM" ,False,False,0x12,0xff,False,False,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("LSH" ,False,True ,0x13,0x08,False,False,False, 0, 8,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x0e,0xff,0xff,0xff,0xff);
AddGen("MPYF" ,False,True ,0x14,0x09,False,False,True , 0,52,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0x0f,0xff,0x00,0x01,0xff,0xff);
AddGen("MPYI" ,False,True ,0x15,0x0a,False,False,False, 0,200,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x10,0xff,0xff,0x02,0x03);
AddGen("NEGB" ,True ,False,0x16,0xff,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("NEGF" ,True ,False,0x17,0xff,False,False,True , 4, 0,
0xff,0xff,0x11,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("NEGI" ,True ,False,0x18,0xff,False,False,False, 8, 0,
0xff,0xff,0xff,0x12,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("NORM" ,True ,False,0x1a,0xff,False,False,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("NOT" ,True ,False,0x1b,0xff,False,False,False, 8, 0,
0xff,0xff,0xff,0x13,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("OR" ,False,True ,0x20,0x0b,False,False,False, 0, 8,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x14,0xff,0xff,0xff,0xff);
AddGen("RND" ,True ,False,0x22,0xff,False,False,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("STF" ,False,False,0x28,0xff,True ,True ,True , 4, 0,
0xff,0xff,0x00,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("STFI" ,False,False,0x29,0xff,True ,True ,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("STI" ,False,False,0x2a,0xff,True ,True ,False, 8, 0,
0xff,0xff,0xff,0x01,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("STII" ,False,False,0x2b,0xff,True ,True ,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("SUBB" ,False,True ,0x2d,0x0c,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("SUBC" ,False,False,0x2e,0xff,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("SUBF" ,False,True ,0x2f,0x0d,False,False,True , 0, 4,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0x15,0xff,0xff,0xff,0xff,0xff);
AddGen("SUBI" ,False,True ,0x30,0x0e,False,False,False, 0, 8,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x16,0xff,0xff,0xff,0xff);
AddGen("SUBRB",False,False,0x31,0xff,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("SUBRF",False,False,0x32,0xff,False,False,True , 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("SUBRI",False,False,0x33,0xff,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("TSTB" ,False,True ,0x34,0x0f,False,False,False, 0, 0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff);
AddGen("XOR" ,False,True ,0x35,0x10,False,False,False, 0, 8,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x17,0xff,0xff,0xff,0xff);
ParOrders=(char **) malloc(sizeof(char *)*ParOrderCount); InstrZ=0;
ParOrders[InstrZ++]="LDF"; ParOrders[InstrZ++]="LDI";
ParOrders[InstrZ++]="STF"; ParOrders[InstrZ++]="STI";
ParOrders[InstrZ++]="ADDF3"; ParOrders[InstrZ++]="SUBF3";
ParOrders[InstrZ++]="ADDI3"; ParOrders[InstrZ++]="SUBI3";
SingOrders=(SingOrder *) malloc(sizeof(SingOrder)*SingOrderCount); InstrZ=0;
AddSing("IACK",0x1b000000,6);
AddSing("NOP" ,0x0c800000,5);
AddSing("RPTS",0x139b0000,15);
END
static void DeinitFields(void)
BEGIN
free(Conditions);
free(FixedOrders);
free(RotOrders);
free(StkOrders);
free(GenOrders);
free(ParOrders);
free(SingOrders);
END
/*-------------------------------------------------------------------------*/
/* Gleitkommawandler */
static void SplitExt(Double Inp, LongInt *Expo, LongWord *Mant)
BEGIN
Byte Field[8];
Boolean Sign;
int z;
Double_2_ieee8(Inp,Field,False);
Sign=(Field[7]>0x7f);
*Expo=(((LongWord) Field[7]&0x7f)<<4)+(Field[6]>>4);
*Mant=Field[6]&0x0f; if (*Expo!=0) *Mant|=0x10;
for (z=5; z>2; z--) *Mant=((*Mant)<<8)|Field[z];
*Mant=((*Mant)<<3)+(Field[2]>>5);
*Expo-=0x3ff;
if (Sign) *Mant=0xffffffff-(*Mant);
*Mant=(*Mant)^0x80000000;
END
static Boolean ExtToShort(Double Inp, Word *Erg)
BEGIN
LongInt Expo;
LongWord Mant;
if (Inp==0) *Erg=0x8000;
else
BEGIN
SplitExt(Inp,&Expo,&Mant);
if (abs(Expo)>7)
BEGIN
WrError((Expo>0)?1320:1315);
return False;
END
*Erg=((Expo << 12) & 0xf000) | ((Mant >> 20) & 0xfff);
END
return True;
END
static Boolean ExtToSingle(Double Inp, LongWord *Erg)
BEGIN
LongInt Expo;
LongWord Mant;
if (Inp==0) *Erg=0x80000000;
else
BEGIN
SplitExt(Inp,&Expo,&Mant);
if (abs(Expo)>127)
BEGIN
WrError((Expo>0)?1320:1315);
return False;
END
*Erg=((Expo << 24) & 0xff000000)+(Mant >> 8);
END
return True;
END
static Boolean ExtToExt(Double Inp, LongWord *ErgL, LongWord *ErgH)
BEGIN
LongInt Exp;
if (Inp==0)
BEGIN
*ErgH=0x80; *ErgL=0x00000000;
END
else
BEGIN
SplitExt(Inp,&Exp,ErgL);
if (abs(Exp)>127)
BEGIN
WrError((Exp>0)?1320:1315);
return False;
END
*ErgH=Exp&0xff;
END
return True;
END
/*-------------------------------------------------------------------------*/
/* Adressparser */
#define ModNone (-1)
#define ModReg 0
#define MModReg (1 << ModReg)
#define ModDir 1
#define MModDir (1 << ModDir)
#define ModInd 2
#define MModInd (1 << ModInd)
#define ModImm 3
#define MModImm (1 << ModImm)
static ShortInt AdrMode;
static LongInt AdrPart;
static Boolean DecodeReg(char *Asc, Byte *Erg)
BEGIN
#define RegCnt 12
#define RegStart 0x10
static char *Regs[RegCnt]=
{"DP","IR0","IR1","BK","SP","ST","IE","IF","IOF","RS","RE","RC"};
Boolean Err;
if ((mytoupper(*Asc)=='R') AND (strlen(Asc)<=3) AND (strlen(Asc)>=2))
BEGIN
*Erg=ConstLongInt(Asc+1,&Err,10);
if ((Err) AND (*Erg<=0x1b)) return True;
END
if ((strlen(Asc)==3) AND (mytoupper(*Asc)=='A') AND (mytoupper(Asc[1])=='R') AND (Asc[2]>='0') AND (Asc[2]<='7'))
BEGIN
*Erg=Asc[2]-'0'+8; return True;
END
*Erg=0;
while ((*Erg<RegCnt) AND (strcasecmp(Regs[*Erg],Asc)!=0)) (*Erg)++;
if (*Erg<RegCnt)
BEGIN
*Erg+=RegStart; return True;
END
return False;
END
static void ChkAdr(Byte Erl)
BEGIN
if ((AdrMode!=ModNone) AND ((Erl & (1 << AdrMode))==0))
BEGIN
AdrMode=ModNone; WrError(1350);
END
END
static void DecodeAdr(char *Asc, Byte Erl, Boolean ImmFloat)
BEGIN
Byte HReg;
Integer Disp;
char *p;
int l;
Double f;
Word fi;
LongInt AdrLong;
Boolean BitRev,Circ;
String NDisp;
Boolean OK;
enum {ModBase,ModAdd,ModSub,ModPreInc,ModPreDec,ModPostInc,ModPostDec} Mode;
KillBlanks(Asc);
AdrMode=ModNone;
/* I. Register? */
if (DecodeReg(Asc,&HReg))
BEGIN
AdrMode=ModReg; AdrPart=HReg; ChkAdr(Erl); return;
END
/* II. indirekt ? */
if (*Asc=='*')
BEGIN
/* II.1. Erkennungszeichen entfernen */
Asc++;
/* II.2. Extrawuerste erledigen */
BitRev=False; Circ=False;
if (mytoupper(Asc[strlen(Asc)-1])=='B')
BEGIN
BitRev=True; Asc[strlen(Asc)-1]='\0';
END
else if (Asc[strlen(Asc)-1]=='%')
BEGIN
Circ=True; Asc[strlen(Asc)-1]='\0';
END
/* II.3. Displacement entfernen und auswerten:
0..255-->Displacement
-1,-2 -->IR0,IR1
-3 -->Default */
p=QuotPos(Asc,'(');
if (p!=Nil)
BEGIN
if (Asc[strlen(Asc)-1]!=')')
BEGIN
WrError(1350); return;
END
*p='\0'; strmaxcpy(NDisp,p+1,255); NDisp[strlen(NDisp)-1]='\0';
if (strcasecmp(NDisp,"IR0")==0) Disp=(-1);
else if (strcasecmp(NDisp,"IR1")==0) Disp=(-2);
else
BEGIN
Disp=EvalIntExpression(NDisp,UInt8,&OK);
if (NOT OK) return;
END
END
else Disp=(-3);
/* II.4. Addieren/Subtrahieren mit/ohne Update? */
l=strlen(Asc);
if (*Asc=='-')
BEGIN
if (Asc[1]=='-')
BEGIN
Mode=ModPreDec; Asc += 2;
END
else
BEGIN
Mode=ModSub; Asc++;
END
END
else if (*Asc=='+')
BEGIN
if (Asc[1]=='+')
BEGIN
Mode=ModPreInc; Asc += 2;
END
else
BEGIN
Mode=ModAdd; Asc++;
END
END
else if (Asc[l-1]=='-')
BEGIN
if (Asc[l-2]=='-')
BEGIN
Mode=ModPostDec; Asc[l-2]='\0';
END
else
BEGIN
WrError(1350); return;
END
END
else if (Asc[l-1]=='+')
BEGIN
if (Asc[l-2]=='+')
BEGIN
Mode=ModPostInc; Asc[l-2]='\0';
END
else
BEGIN
WrError(1350); return;
END
END
else Mode=ModBase;
/* II.5. Rest muss Basisregister sein */
if ((NOT DecodeReg(Asc,&HReg)) OR (HReg<8) OR (HReg>15))
BEGIN
WrError(1350); return;
END
HReg-=8;
if ((ARs & (1l << HReg))==0) ARs+=1l << HReg;
else WrXError(210,Asc);
/* II.6. Default-Displacement explizit machen */
if (Disp==-3)
Disp=(Mode==ModBase) ? 0 : 1;
/* II.7. Entscheidungsbaum */
switch (Mode)
BEGIN
case ModBase:
case ModAdd:
if ((Circ) OR (BitRev)) WrError(1350);
else
BEGIN
switch (Disp)
BEGIN
case -2: AdrPart=0x8000; break;
case -1: AdrPart=0x4000; break;
case 0: AdrPart=0xc000; break;
default: AdrPart=Disp;
END
AdrPart+=((Word)HReg) << 8; AdrMode=ModInd;
END
break;
case ModSub:
if ((Circ) OR (BitRev)) WrError(1350);
else
BEGIN
switch (Disp)
BEGIN
case -2: AdrPart=0x8800; break;
case -1: AdrPart=0x4800; break;
case 0: AdrPart=0xc000; break;
default: AdrPart=0x0800+Disp;
END
AdrPart+=((Word)HReg) << 8; AdrMode=ModInd;
END
break;
case ModPreInc:
if ((Circ) OR (BitRev)) WrError(1350);
else
BEGIN
switch (Disp)
BEGIN
case -2: AdrPart=0x9000; break;
case -1: AdrPart=0x5000; break;
default: AdrPart=0x1000+Disp;
END
AdrPart+=((Word)HReg) << 8; AdrMode=ModInd;
END
break;
case ModPreDec:
if ((Circ) OR (BitRev)) WrError(1350);
else
BEGIN
switch (Disp)
BEGIN
case -2: AdrPart=0x9800; break;
case -1: AdrPart=0x5800; break;
default: AdrPart=0x1800+Disp;
END
AdrPart+=((Word)HReg) << 8; AdrMode=ModInd;
END
break;
case ModPostInc:
if (BitRev)
BEGIN
if (Disp!=-1) WrError(1350);
else
BEGIN
AdrPart=0xc800+(((Word)HReg) << 8); AdrMode=ModInd;
END
END
else
BEGIN
switch (Disp)
BEGIN
case -2: AdrPart=0xa000; break;
case -1: AdrPart=0x6000; break;
default: AdrPart=0x2000+Disp;
END
if (Circ) AdrPart+=0x1000;
AdrPart+=((Word)HReg) << 8; AdrMode=ModInd;
END
break;
case ModPostDec:
if (BitRev) WrError(1350);
else
BEGIN
switch (Disp)
BEGIN
case -2: AdrPart=0xa800; break;
case -1: AdrPart=0x6800; break;
default: AdrPart=0x2800+Disp; break;
END
if (Circ) AdrPart+=0x1000;
AdrPart+=((Word)HReg) << 8; AdrMode=ModInd;
END
break;
END
ChkAdr(Erl); return;
END
/* III. absolut */
if (*Asc=='@')
BEGIN
AdrLong=EvalIntExpression(Asc+1,UInt24,&OK);
if (OK)
BEGIN
if ((DPValue!=-1) AND ((AdrLong >> 16)!=DPValue)) WrError(110);
AdrMode=ModDir; AdrPart=AdrLong & 0xffff;
END
ChkAdr(Erl); return;
END
/* IV. immediate */
if (ImmFloat)
BEGIN
f=EvalFloatExpression(Asc,Float64,&OK);
if (OK)
if (ExtToShort(f,&fi))
BEGIN
AdrPart=fi; AdrMode=ModImm;
END
END
else
BEGIN
AdrPart=EvalIntExpression(Asc,Int16,&OK);
if (OK)
BEGIN
AdrPart&=0xffff; AdrMode=ModImm;
END
END
ChkAdr(Erl);
END
static Word EffPart(Byte Mode, Word Part)
BEGIN
switch (Mode)
BEGIN
case ModReg: return Lo(Part);
case ModInd: return Hi(Part);
default: WrError(10000); return 0;
END
END
/*-------------------------------------------------------------------------*/
/* Code-Erzeugung */
static Boolean DecodePseudo(void)
BEGIN
#define ASSUME3203Count 1
static ASSUMERec ASSUME3203s[ASSUME3203Count]=
{{"DP", &DPValue, -1, 0xff, 0x100}};
Boolean OK;
int z;
LongInt Size;
Double f;
TempResult t;
if (Memo("ASSUME"))
BEGIN
CodeASSUME(ASSUME3203s,ASSUME3203Count);
return True;
END
if (Memo("SINGLE"))
BEGIN
if (ArgCnt==0) WrError(1110);
else
BEGIN
OK=True;
for (z=1; z<=ArgCnt; z++)
if (OK)
BEGIN
f=EvalFloatExpression(ArgStr[z],Float64,&OK);
if (OK)
OK=OK AND ExtToSingle(f,DAsmCode+(CodeLen++));
END
if (NOT OK) CodeLen=0;
END
return True;
END
if (Memo("EXTENDED"))
BEGIN
if (ArgCnt==0) WrError(1110);
else
BEGIN
OK=True;
for (z=1; z<=ArgCnt; z++)
if (OK)
BEGIN
f=EvalFloatExpression(ArgStr[z],Float64,&OK);
if (OK)
OK=OK AND ExtToExt(f,DAsmCode+CodeLen+1,DAsmCode+CodeLen);
CodeLen+=2;
END
if (NOT OK) CodeLen=0;
END
return True;
END
if (Memo("WORD"))
BEGIN
if (ArgCnt==0) WrError(1110);
else
BEGIN
OK=True;
for (z=1; z<=ArgCnt; z++)
if (OK) DAsmCode[CodeLen++]=EvalIntExpression(ArgStr[z],Int32,&OK);
if (NOT OK) CodeLen=0;
END
return True;
END
if (Memo("DATA"))
BEGIN
if (ArgCnt==0) WrError(1110);
else
BEGIN
OK=True;
for (z=1; z<=ArgCnt; z++)
if (OK)
BEGIN
EvalExpression(ArgStr[z],&t);
switch (t.Typ)
BEGIN
case TempInt:
#ifdef HAS64
if (NOT RangeCheck(t.Contents.Int,Int32))
BEGIN
OK=False; WrError(1320);
END
else
#endif
DAsmCode[CodeLen++]=t.Contents.Int;
break;
case TempFloat:
if (NOT ExtToSingle(t.Contents.Float,DAsmCode+(CodeLen++))) OK=False;
break;
case TempString:
{
unsigned z2;
for (z2 = 0; z2 < t.Contents.Ascii.Length; z2++)
{
if (!(z2 & 3))
DAsmCode[CodeLen++] = 0;
DAsmCode[CodeLen - 1] |=
(((LongWord)CharTransTable[((usint)t.Contents.Ascii.Contents[z2]) & 0xff])) << (8 *(3 - (z2 & 3)));
}
break;
}
default:
OK=False;
END
END
if (NOT OK) CodeLen=0;
END
return True;
END
if (Memo("BSS"))
BEGIN
if (ArgCnt!=1) WrError(1110);
else
BEGIN
FirstPassUnknown=False;
Size=EvalIntExpression(ArgStr[1],UInt24,&OK);
if (FirstPassUnknown) WrError(1820);
if ((OK) AND (NOT FirstPassUnknown))
BEGIN
DontPrint=True;
if (!Size) WrError(290);
CodeLen=Size;
BookKeeping();
END
END
return True;
END
return False;
END
static void JudgePar(GenOrder *Prim, int Sec, Byte *ErgMode, Byte *ErgCode)
BEGIN
if (Sec>3) *ErgMode=3;
else if (Prim->May3) *ErgMode=1;
else *ErgMode=2;
if (*ErgMode==2) *ErgCode=Prim->PCodes[Sec];
else *ErgCode=Prim->P3Codes[Sec];
END
static LongWord EvalAdrExpression(char *Asc, Boolean *OK)
BEGIN
if (*Asc=='@') Asc++;
return EvalIntExpression(Asc,UInt24,OK);
END
static void SwapMode(ShortInt *M1, ShortInt *M2)
BEGIN
AdrMode=(*M1); *M1=(*M2); *M2=AdrMode;
END
static void SwapPart(Word *P1, Word *P2)
BEGIN
AdrPart=(*P1); *P1=(*P2); *P2=AdrPart;
END
static void MakeCode_3203X(void)
BEGIN
Boolean OK,Is3;
Byte HReg,HReg2,Sum;
int z,z3,l;
LongInt AdrLong,DFlag,Disp;
String HOp,Form;
CodeLen=0; DontPrint=False;
ThisPar=(strcmp(LabPart,"||")==0);
if ((strlen(OpPart)>2) AND (strncmp(OpPart,"||",2)==0))
BEGIN
ThisPar=True; strmov(OpPart,OpPart+2);
END
if ((NOT NextPar) AND (ThisPar))
BEGIN
WrError(1950); return;
END
ARs=0;
/* zu ignorierendes */
if (Memo("")) return;
/* Pseudoanweisungen */
if (DecodePseudo()) return;
/* ohne Argument */
for (z=0; z<FixedOrderCount; z++)
if (Memo(FixedOrders[z].Name))
BEGIN
if (ArgCnt!=0) WrError(1110);
else if (ThisPar) WrError(1950);
else
BEGIN
DAsmCode[0]=FixedOrders[z].Code; CodeLen=1;
END
NextPar=False; return;
END
/* Arithmetik/Logik */
for (z=0; z<GenOrderCount; z++)
if ((strncmp(OpPart,GenOrders[z].Name,GenOrders[z].NameLen)==0)
AND ((OpPart[GenOrders[z].NameLen]=='\0') OR (OpPart[GenOrders[z].NameLen]=='3')))
BEGIN
NextPar=False;
/* Argumentzahl abgleichen */
if (ArgCnt==1)
BEGIN
if (GenOrders[z].May1)
BEGIN
ArgCnt=2; strcpy(ArgStr[2],ArgStr[1]);
END
else
BEGIN
WrError(1110); return;
END
END
if ((ArgCnt==3) AND (OpPart[strlen(OpPart)-1]!='3')) strcat(OpPart,"3");
Is3=(OpPart[strlen(OpPart)-1]=='3');
if ((GenOrders[z].SwapOps) AND (NOT Is3))
BEGIN
strcpy(ArgStr[3],ArgStr[1]);
strcpy(ArgStr[1],ArgStr[2]);
strcpy(ArgStr[2],ArgStr[3]);
END
if ((Is3) AND (ArgCnt==2))
BEGIN
ArgCnt=3; strcpy(ArgStr[3],ArgStr[2]);
END
if ((ArgCnt<2) OR (ArgCnt>3) OR ((Is3) AND (NOT GenOrders[z].May3)))
BEGIN
WrError(1110); return;
END
/* Argumente parsen */
if (Is3)
BEGIN
if (Memo("TSTB3"))
BEGIN
CurrDestMode=ModReg; CurrDestPart=0;
END
else
BEGIN
DecodeAdr(ArgStr[3],MModReg,GenOrders[z].ImmFloat);
if (AdrMode==ModNone) return;
CurrDestMode=AdrMode; CurrDestPart=AdrPart;
END
DecodeAdr(ArgStr[2],MModReg+MModInd,GenOrders[z].ImmFloat);
if (AdrMode==ModNone) return;
if ((AdrMode==ModInd) AND ((AdrPart & 0xe000)==0) AND (Lo(AdrPart)!=1))
BEGIN
WrError(1350); return;
END
CurrSrc2Mode=AdrMode; CurrSrc2Part=AdrPart;
DecodeAdr(ArgStr[1],MModReg+MModInd,GenOrders[z].ImmFloat);
if (AdrMode==ModNone) return;
if ((AdrMode==ModInd) AND ((AdrPart & 0xe000)==0) AND (Lo(AdrPart)!=1))
BEGIN
WrError(1350); return;
END
CurrSrc1Mode=AdrMode; CurrSrc1Part=AdrPart;
END
else /* NOT Is3 */
BEGIN
DecodeAdr(ArgStr[1],MModDir+MModInd+((GenOrders[z].OnlyMem)?0:MModReg+MModImm),GenOrders[z].ImmFloat);