/
asmallg.c
1603 lines (1451 loc) · 40.1 KB
/
asmallg.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
/* codeallg.c */
/*****************************************************************************/
/* AS-Portierung */
/* */
/* von allen Codegeneratoren benutzte Pseudobefehle */
/* */
/* Historie: 10. 5.1996 Grundsteinlegung */
/* 24. 6.1998 CODEPAGE-Kommando */
/* 17. 7.1998 CHARSET ohne Argumente */
/* 17. 8.1998 BookKeeping-Aufruf bei ALIGN */
/* 18. 8.1998 RADIX-Kommando */
/* 2. 1.1999 Standard-ChkPC-Routine */
/* 9. 1.1999 BINCLUDE gefixt... */
/* 30. 5.1999 OUTRADIX-Kommando */
/* 12. 7.1999 EXTERN-Kommando */
/* 8. 3.2000 'ambigious else'-Warnungen beseitigt */
/* 1. 6.2000 reset error flag before checks in BINCLUDE */
/* added NESTMAX instruction */
/* 26. 6.2000 added EXPORT instruction */
/* 6. 7.2000 unknown symbol in EXPORT triggers repassing */
/* 30.10.2000 EXTERN also works for symbols without a segment spec*/
/* 1.11.2000 added ASEG/RSEG */
/* 14. 1.2001 silenced warnings about unused parameters */
/* use SegInits also when segment hasn't been used up */
/* to now */
/* */
/*****************************************************************************/
/* $Id: asmallg.c,v 1.11 2012-05-26 13:49:19 alfred Exp $ */
/*****************************************************************************
* $Log: asmallg.c,v $
* Revision 1.11 2012-05-26 13:49:19 alfred
* - MSP additions, make implicit macro parameters always case-insensitive
*
* Revision 1.10 2012-01-16 19:31:18 alfred
* - regard symbol name expansion in arguments for SHARED
*
* Revision 1.9 2010/08/27 14:52:41 alfred
* - some more overlapping strcpy() cleanups
*
* Revision 1.8 2010/04/17 13:14:19 alfred
* - address overlapping strcpy()
*
* Revision 1.7 2008/11/23 10:39:15 alfred
* - allow strings with NUL characters
*
* Revision 1.6 2007/11/24 22:48:02 alfred
* - some NetBSD changes
*
* Revision 1.5 2007/04/30 18:37:51 alfred
* - add weird integer coding
*
* Revision 1.4 2006/08/05 18:26:32 alfred
* - remove static string
*
* Revision 1.3 2005/10/02 10:00:43 alfred
* - ConstLongInt gets default base, correct length check on KCPSM3 registers
*
* Revision 1.2 2005/08/07 10:29:24 alfred
* - remove mnemonic conflict with MICO8
*
* Revision 1.1 2003/11/06 02:49:18 alfred
* - recreated
*
* Revision 1.12 2003/05/02 21:23:08 alfred
* - strlen() updates
*
* Revision 1.11 2003/02/06 07:38:09 alfred
* - add missing 'else'
*
* Revision 1.10 2003/02/02 12:05:01 alfred
* - limit BINCLUDE transfer size to 256 bytes
*
* Revision 1.9 2002/11/23 15:53:27 alfred
* - SegLimits are unsigned now
*
* Revision 1.8 2002/11/20 20:25:04 alfred
* - added unions
*
* Revision 1.7 2002/11/17 16:09:12 alfred
* - added DottedStructs
*
* Revision 1.6 2002/11/16 20:51:15 alfred
* - adapted to structure changes
*
* Revision 1.5 2002/11/11 21:13:37 alfred
* - add structure storage
*
* Revision 1.4 2002/11/11 19:24:57 alfred
* - new module for structs
*
* Revision 1.3 2002/11/04 19:18:00 alfred
* - add DOTS option for structs
*
* Revision 1.2 2002/07/14 18:39:57 alfred
* - fixed TempAll-related warnings
*
*****************************************************************************/
#include "stdinc.h"
#include <string.h>
#include <ctype.h>
#include "nls.h"
#include "strutil.h"
#include "stringlists.h"
#include "bpemu.h"
#include "cmdarg.h"
#include "chunks.h"
#include "asmdef.h"
#include "asmsub.h"
#include "asmpars.h"
#include "asmmac.h"
#include "asmstructs.h"
#include "asmcode.h"
#include "asmrelocs.h"
#include "asmitree.h"
#include "codepseudo.h"
/*--------------------------------------------------------------------------*/
static char *PseudoStrs[3]={Nil,Nil,Nil};
static PInstTable PseudoTable=Nil,ONOFFTable;
/*--------------------------------------------------------------------------*/
static Boolean DefChkPC(LargeWord Addr)
BEGIN
if (((1 << ActPC) & ValidSegs) == 0) return False;
else return (Addr <= SegLimits[ActPC]);
END
void SetCPU(CPUVar NewCPU, Boolean NotPrev)
{
LongInt HCPU;
char *z, *dest;
Boolean ECPU;
char s[11];
PCPUDef Lauf;
Lauf = FirstCPUDef;
while ((Lauf) && (Lauf->Number != NewCPU))
Lauf = Lauf->Next;
if (!Lauf)
return;
strmaxcpy(MomCPUIdent, Lauf->Name, 11);
MomCPU = Lauf->Orig;
MomVirtCPU = Lauf->Number;
strmaxcpy(s, MomCPUIdent, 11);
for (z = dest = s; *z; z++)
if (isxdigit(*z))
*(dest++) = (*z);
*dest = '\0';
for (z = s; *z != '\0'; z++)
if (isdigit(*z))
break;
if (*z) strmov(s, z);
strprep(s, "$");
HCPU = ConstLongInt(s, &ECPU, 10);
if (ParamCount != 0)
{
EnterIntSymbol(MomCPUName, HCPU, SegNone, True);
EnterStringSymbol(MomCPUIdentName, MomCPUIdent, True);
}
InternSymbol = Default_InternSymbol;
ChkPC = DefChkPC;
if (!NotPrev) SwitchFrom();
Lauf->SwitchProc();
DontPrint = True;
}
Boolean SetNCPU(char *Name, Boolean NoPrev)
BEGIN
PCPUDef Lauf;
Lauf = FirstCPUDef;
while ((Lauf != Nil) AND (strcmp(Name, Lauf->Name) != 0))
Lauf = Lauf->Next;
if (Lauf == Nil) WrXError(1430, Name);
else SetCPU(Lauf->Number, NoPrev);
return (Lauf != Nil);
END
static void SetNSeg(Byte NSeg)
BEGIN
if ((ActPC != NSeg) OR (NOT PCsUsed[ActPC]))
BEGIN
ActPC = NSeg;
if (NOT PCsUsed[ActPC]) PCs[ActPC] = SegInits[ActPC];
PCsUsed[ActPC] = True;
DontPrint = True;
END
END
static void IntLine(char *pDest, LongInt Inp)
{
switch (ConstMode)
{
case ConstModeIntel:
sprintf(pDest, "%sH", HexString(Inp, 0));
if (*pDest > '9') strmaxprep(pDest, "0", 255);
break;
case ConstModeMoto:
sprintf(pDest, "$%s", HexString(Inp, 0));
break;
case ConstModeC:
sprintf(pDest, "0x%s", HexString(Inp, 0));
break;
case ConstModeWeird:
sprintf(pDest, "x'%s'", HexString(Inp, 0));
break;
}
}
static void CodeSECTION(Word Index)
BEGIN
PSaveSection Neu;
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else if (ExpandSymbol(ArgStr[1]))
BEGIN
if (NOT ChkSymbName(ArgStr[1])) WrXError(1020,ArgStr[1]);
else if ((PassNo==1) AND (GetSectionHandle(ArgStr[1],False,MomSectionHandle)!=-2)) WrError(1483);
else
BEGIN
Neu=(PSaveSection) malloc(sizeof(TSaveSection));
Neu->Next=SectionStack;
Neu->Handle=MomSectionHandle;
Neu->LocSyms=Nil; Neu->GlobSyms=Nil; Neu->ExportSyms=Nil;
SetMomSection(GetSectionHandle(ArgStr[1],True,MomSectionHandle));
SectionStack=Neu;
END
END
END
static void CodeENDSECTION_ChkEmptList(PForwardSymbol *Root)
BEGIN
PForwardSymbol Tmp;
while (*Root!=Nil)
BEGIN
WrXError(1488,(*Root)->Name);
free((*Root)->Name);
Tmp=(*Root); *Root=Tmp->Next; free(Tmp);
END
END
static void CodeENDSECTION(Word Index)
BEGIN
PSaveSection Tmp;
UNUSED(Index);
if (ArgCnt>1) WrError(1110);
else if (SectionStack==Nil) WrError(1487);
else if ((ArgCnt==0) OR (ExpandSymbol(ArgStr[1])))
BEGIN
if ((ArgCnt==1) AND (GetSectionHandle(ArgStr[1],False,SectionStack->Handle)!=MomSectionHandle)) WrError(1486);
else
BEGIN
Tmp=SectionStack; SectionStack=Tmp->Next;
CodeENDSECTION_ChkEmptList(&(Tmp->LocSyms));
CodeENDSECTION_ChkEmptList(&(Tmp->GlobSyms));
CodeENDSECTION_ChkEmptList(&(Tmp->ExportSyms));
TossRegDefs(MomSectionHandle);
if (ArgCnt==0)
sprintf(ListLine,"[%s]",GetSectionName(MomSectionHandle));
SetMomSection(Tmp->Handle);
free(Tmp);
END
END
END
static void CodeCPU(Word Index)
BEGIN
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else if (*AttrPart!='\0') WrError(1100);
else
BEGIN
NLS_UpString(ArgStr[1]);
if (SetNCPU(ArgStr[1], False))
SetNSeg(SegCode);
END
END
static void CodeSETEQU(Word Index)
{
TempResult t;
Boolean MayChange;
Integer DestSeg;
UNUSED(Index);
FirstPassUnknown = False;
MayChange = ((!Memo("EQU")) && (!Memo("=")));
if (*AttrPart != '\0') WrError(1100);
else if ((ArgCnt < 1) || (ArgCnt > 2)) WrError(1110);
else
{
EvalExpression(ArgStr[1],&t);
if (!FirstPassUnknown)
{
if (ArgCnt == 1) DestSeg = SegNone;
else
{
NLS_UpString(ArgStr[2]);
if (!strcmp(ArgStr[2], "MOMSEGMENT")) DestSeg = ActPC;
else if (*ArgStr[2] == '\0') DestSeg = SegNone;
else
{
for (DestSeg = 0; DestSeg <= PCMax; DestSeg++)
if (!strcmp(ArgStr[2], SegNames[DestSeg]))
break;
}
}
if (DestSeg > PCMax) WrXError(1961,ArgStr[2]);
else
{
SetListLineVal(&t);
PushLocHandle(-1);
switch (t.Typ)
{
case TempInt:
EnterIntSymbol(LabPart, t.Contents.Int, DestSeg, MayChange);
break;
case TempFloat:
EnterFloatSymbol(LabPart, t.Contents.Float, MayChange);
break;
case TempString:
EnterDynStringSymbol(LabPart, &t.Contents.Ascii, MayChange);
break;
default:
break;
}
PopLocHandle();
}
}
}
}
static void CodeORG(Word Index)
BEGIN
LargeInt HVal;
Boolean ValOK;
UNUSED(Index);
FirstPassUnknown=False;
if (*AttrPart!='\0') WrError(1100);
else if (ArgCnt!=1) WrError(1110);
else
BEGIN
#ifndef HAS64
HVal=EvalIntExpression(ArgStr[1],UInt32,&ValOK);
#else
HVal=EvalIntExpression(ArgStr[1],Int64,&ValOK);
#endif
if (FirstPassUnknown) WrError(1820);
if ((ValOK) AND (NOT FirstPassUnknown))
BEGIN
PCs[ActPC]=HVal; DontPrint=True;
END
END
END
static void CodeSHARED_BuildComment(char *c)
BEGIN
switch (ShareMode)
BEGIN
case 1: sprintf(c,"(* %s *)",CommPart); break;
case 2: sprintf(c,"/* %s */",CommPart); break;
case 3: sprintf(c,"; %s",CommPart); break;
END
END
static void CodeSHARED(Word Index)
{
int z;
Boolean ValOK;
LargeInt HVal;
Double FVal;
String s,c;
UNUSED(Index);
if (ShareMode == 0) WrError(30);
else if ((ArgCnt == 0) && (*CommPart!='\0'))
{
CodeSHARED_BuildComment(c);
errno = 0; fprintf(ShareFile, "%s\n", c); ChkIO(10004);
}
else
for (z = 1; z <= ArgCnt; z++)
{
if (!ExpandSymbol(ArgStr[z]))
continue;
if (!ChkSymbName(ArgStr[z]))
{
WrXError(1020, ArgStr[z]);
continue;
}
if (IsSymbolString(ArgStr[z]))
{
ValOK = GetStringSymbol(ArgStr[z], s);
if (ShareMode == 1)
{
strmaxprep(s, "\'", 255); strmaxcat(s, "\'", 255);
}
else
{
strmaxprep(s, "\"", 255); strmaxcat(s, "\"", 255);
}
}
else if (IsSymbolFloat(ArgStr[z]))
{
ValOK = GetFloatSymbol(ArgStr[z], &FVal);
sprintf(s, "%0.17g", FVal);
}
else
{
ValOK = GetIntSymbol(ArgStr[z], &HVal, NULL);
switch (ShareMode)
{
case 1: sprintf(s, "$%s", HexString(HVal, 0)); break;
case 2: sprintf(s, "0x%s", HexString(HVal, 0)); break;
case 3: IntLine(s, HVal); break;
}
}
if (ValOK)
{
if ((z == 1) && (*CommPart != '\0'))
{
CodeSHARED_BuildComment(c); strmaxprep(c, " ", 255);
}
else
*c = '\0';
errno = 0;
switch (ShareMode)
{
case 1:
fprintf(ShareFile, "%s = %s;%s\n", ArgStr[z], s, c); break;
case 2:
fprintf(ShareFile, "#define %s %s%s\n", ArgStr[z], s, c); break;
case 3:
strmaxprep(s, IsSymbolChangeable(ArgStr[z]) ? "set " : "equ ", 255);
fprintf(ShareFile, "%s %s%s\n", ArgStr[z], s, c); break;
}
ChkIO(10004);
}
else if (PassNo == 1)
{
Repass = True;
if ((MsgIfRepass) && (PassNo >= PassNoForMessage)) WrXError(170, ArgStr[z]);
}
}
}
static void CodeEXPORT(Word Index)
BEGIN
int z;
LargeInt Value;
PRelocEntry Relocs;
UNUSED(Index);
for (z = 1; z <= ArgCnt; z++)
BEGIN
FirstPassUnknown = True;
if (GetIntSymbol(ArgStr[z], &Value, &Relocs))
BEGIN
if (Relocs == NULL)
AddExport(ArgStr[z], Value, 0);
else if ((Relocs->Next != NULL) OR (strcmp(Relocs->Ref, RelName_SegStart) != 0))
WrXError(1156, ArgStr[z]);
else
AddExport(ArgStr[z], Value, RelFlag_Relative);
END
else
BEGIN
Repass = True;
if ((MsgIfRepass) AND (PassNo >= PassNoForMessage))
WrXError(170,ArgStr[z]);
END
END
END
static void CodePAGE(Word Index)
BEGIN
Integer LVal,WVal;
Boolean ValOK;
UNUSED(Index);
if ((ArgCnt!=1) AND (ArgCnt!=2)) WrError(1110);
else if (*AttrPart!='\0') WrError(1100);
else
BEGIN
LVal=EvalIntExpression(ArgStr[1],UInt8,&ValOK);
if (ValOK)
BEGIN
if ((LVal<5) AND (LVal!=0)) LVal=5;
if (ArgCnt==1)
BEGIN
WVal=0; ValOK=True;
END
else WVal=EvalIntExpression(ArgStr[2],UInt8,&ValOK);
if (ValOK)
BEGIN
if ((WVal<5) AND (WVal!=0)) WVal=5;
PageLength=LVal; PageWidth=WVal;
END
END
END
END
static void CodeNEWPAGE(Word Index)
BEGIN
ShortInt HVal8;
Boolean ValOK;
UNUSED(Index);
if (ArgCnt>1) WrError(1110);
else if (*AttrPart!='\0') WrError(1100);
else
BEGIN
if (ArgCnt==0)
BEGIN
HVal8=0; ValOK=True;
END
else HVal8=EvalIntExpression(ArgStr[1],Int8,&ValOK);
if ((ValOK) OR (ArgCnt==0))
BEGIN
if (HVal8>ChapMax) HVal8=ChapMax;
else if (HVal8<0) HVal8=0;
NewPage(HVal8,True);
END
END
END
static void CodeString(Word Index)
BEGIN
String tmp;
Boolean OK;
if (ArgCnt!=1) WrError(1110);
else
BEGIN
EvalStringExpression(ArgStr[1],&OK,tmp);
if (NOT OK) WrError(1970); else strmaxcpy(PseudoStrs[Index],tmp,255);
END
END
static void CodePHASE(Word Index)
BEGIN
Boolean OK;
LongInt HVal;
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else if (ActPC==StructSeg) WrError(1553);
else
BEGIN
HVal=EvalIntExpression(ArgStr[1],Int32,&OK);
if (OK) Phases[ActPC]=HVal-ProgCounter();
END
END
static void CodeDEPHASE(Word Index)
BEGIN
UNUSED(Index);
if (ArgCnt!=0) WrError(1110);
else if (ActPC==StructSeg) WrError(1553);
else Phases[ActPC]=0;
END
static void CodeWARNING(Word Index)
BEGIN
String mess;
Boolean OK;
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else
BEGIN
EvalStringExpression(ArgStr[1],&OK,mess);
if (NOT OK) WrError(1970);
else WrErrorString(mess,"",True,False);
END
END
static void CodeMESSAGE(Word Index)
BEGIN
String mess;
Boolean OK;
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else
BEGIN
EvalStringExpression(ArgStr[1],&OK,mess);
if (NOT OK) WrError(1970);
printf("%s%s\n",mess,ClrEol);
if (strcmp(LstName,"/dev/null")!=0) WrLstLine(mess);
END
END
static void CodeERROR(Word Index)
BEGIN
String mess;
Boolean OK;
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else
BEGIN
EvalStringExpression(ArgStr[1],&OK,mess);
if (NOT OK) WrError(1970);
else WrErrorString(mess,"",False,False);
END
END
static void CodeFATAL(Word Index)
BEGIN
String mess;
Boolean OK;
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else
BEGIN
EvalStringExpression(ArgStr[1],&OK,mess);
if (NOT OK) WrError(1970);
else WrErrorString(mess,"",False,True);
END
END
static void CodeCHARSET(Word Index)
BEGIN
TempResult t;
FILE *f;
unsigned char tfield[256];
LongWord Start,l,TStart,Stop,z;
Boolean OK;
UNUSED(Index);
if (ArgCnt>3) WrError(1110);
else if (ArgCnt==0)
BEGIN
for (z=0; z<256; z++) CharTransTable[z]=z;
END
else
BEGIN
FirstPassUnknown=False; EvalExpression(ArgStr[1],&t);
switch (t.Typ)
BEGIN
case TempInt:
if (FirstPassUnknown) t.Contents.Int&=255;
if (ChkRange(t.Contents.Int,0,255))
BEGIN
if (ArgCnt<2) WrError(1110);
else
BEGIN
Start=t.Contents.Int;
FirstPassUnknown=False; EvalExpression(ArgStr[2],&t);
switch (t.Typ)
BEGIN
case TempInt: /* Übersetzungsbereich als Character-Angabe */
if (FirstPassUnknown) t.Contents.Int&=255;
if (ArgCnt==2)
BEGIN
Stop=Start; TStart=t.Contents.Int;
OK=ChkRange(TStart,0,255);
END
else
BEGIN
Stop=t.Contents.Int; OK=ChkRange(Stop,Start,255);
if (OK) TStart=EvalIntExpression(ArgStr[3],UInt8,&OK);
else TStart=0;
END
if (OK)
for (z=Start; z<=Stop; z++) CharTransTable[z]=TStart+(z-Start);
break;
case TempString:
l = t.Contents.Ascii.Length; /* Uebersetzungsstring ab Start */
if (Start +l > 256) WrError(1320);
else
for (z = 0; z < l; z++)
CharTransTable[Start + z] = t.Contents.Ascii.Contents[z];
break;
case TempFloat:
WrError(1135);
break;
default:
break;
END
END
END
break;
case TempString:
if (ArgCnt!=1) WrError(1110); /* Tabelle von Datei lesen */
else
BEGIN
String Tmp;
DynString2CString(Tmp, &t.Contents.Ascii, sizeof(Tmp));
f=fopen(Tmp, OPENRDMODE);
if (f==Nil) ChkIO(10001);
if (fread(tfield,sizeof(char),256,f)!=256) ChkIO(10003);
fclose(f); memcpy(CharTransTable,tfield,sizeof(char)*256);
END
break;
case TempFloat:
WrError(1135);
break;
default:
break;
END
END
END
static void CodePRSET(Word Index)
BEGIN
int z,z2;
UNUSED(Index);
for (z=0; z<16; z++)
BEGIN
for (z2=0; z2<16; z2++) printf(" %02x",CharTransTable[z*16+z2]);
printf(" ");
for (z2=0; z2<16; z2++) printf("%c",CharTransTable[z*16+z2]>' ' ? CharTransTable[z*16+z2] : '.');
putchar('\n');
END
END
static void CodeCODEPAGE(Word Index)
BEGIN
PTransTable Prev,Run,New,Source;
int erg=0;
UNUSED(Index);
if ((ArgCnt!=1) AND (ArgCnt!=2)) WrError(1110);
else if (NOT ChkSymbName(ArgStr[1])) WrXError(1020,ArgStr[1]);
else
BEGIN
if (NOT CaseSensitive)
BEGIN
UpString(ArgStr[1]);
if (ArgCnt==2) UpString(ArgStr[2]);
END
if (ArgCnt==1) Source=CurrTransTable;
else
for (Source=TransTables; Source!=Nil; Source=Source->Next)
if (strcmp(Source->Name,ArgStr[2])==0) break;
if (Source==Nil) WrXError(1610,ArgStr[2]);
else
BEGIN
for (Prev=Nil,Run=TransTables; Run!=Nil; Prev=Run,Run=Run->Next)
if ((erg=strcmp(ArgStr[1],Run->Name))<=0) break;
if ((Run==Nil) OR (erg<0))
BEGIN
New=(PTransTable) malloc(sizeof(TTransTable));
New->Next=Run;
New->Name=strdup(ArgStr[1]);
New->Table=(unsigned char *) malloc(256*sizeof(char));
memcpy(New->Table,Source->Table,256*sizeof(char));
if (Prev==Nil) TransTables=New; else Prev->Next=New;
CurrTransTable=New;
END
else CurrTransTable=Run;
END
END
END
static void CodeFUNCTION(Word Index)
BEGIN
String FName;
Boolean OK;
int z;
UNUSED(Index);
if (ArgCnt<2) WrError(1110);
else
BEGIN
OK=True; z=1;
do
BEGIN
OK=(OK AND ChkMacSymbName(ArgStr[z]));
if (NOT OK) WrXError(1020,ArgStr[z]);
z++;
END
while ((z<ArgCnt) AND (OK));
if (OK)
BEGIN
strmaxcpy(FName,ArgStr[ArgCnt],255);
for (z=1; z<ArgCnt; z++)
CompressLine(ArgStr[z],z,FName,CaseSensitive);
EnterFunction(LabPart,FName,ArgCnt-1);
END
END
END
static void CodeSAVE(Word Index)
BEGIN
PSaveState Neu;
UNUSED(Index);
if (ArgCnt!=0) WrError(1110);
else
BEGIN
Neu=(PSaveState) malloc(sizeof(TSaveState));
Neu->Next=FirstSaveState;
Neu->SaveCPU=MomCPU;
Neu->SavePC=ActPC;
Neu->SaveListOn=ListOn;
Neu->SaveLstMacroEx=LstMacroEx;
Neu->SaveTransTable=CurrTransTable;
FirstSaveState=Neu;
END
END
static void CodeRESTORE(Word Index)
BEGIN
PSaveState Old;
UNUSED(Index);
if (ArgCnt!=0) WrError(1110);
else if (FirstSaveState==Nil) WrError(1450);
else
BEGIN
Old=FirstSaveState; FirstSaveState=Old->Next;
if (Old->SavePC!=ActPC)
BEGIN
ActPC=Old->SavePC; DontPrint=True;
END
if (Old->SaveCPU!=MomCPU) SetCPU(Old->SaveCPU,False);
EnterIntSymbol(ListOnName,ListOn=Old->SaveListOn,0,True);
SetFlag(&LstMacroEx,LstMacroExName,Old->SaveLstMacroEx);
CurrTransTable=Old->SaveTransTable;
free(Old);
END
END
static void CodeSEGMENT(Word Index)
BEGIN
Byte SegZ;
Word Mask;
Boolean Found;
UNUSED(Index);
if (ArgCnt != 1) WrError(1110);
else
BEGIN
Found = False; NLS_UpString(ArgStr[1]);
for (SegZ = 1,Mask = 2; SegZ <= PCMax; SegZ++,Mask <<= 1)
if (((ValidSegs&Mask) != 0) AND (strcmp(ArgStr[1], SegNames[SegZ]) == 0))
BEGIN
Found = True;
SetNSeg(SegZ);
END
if (NOT Found) WrXError(1961, ArgStr[1]);
END
END
static void CodeLABEL(Word Index)
BEGIN
LongInt Erg;
Boolean OK;
UNUSED(Index);
FirstPassUnknown=False;
if (ArgCnt!=1) WrError(1110);
else
BEGIN
Erg=EvalIntExpression(ArgStr[1],Int32,&OK);
if ((OK) AND (NOT FirstPassUnknown))
BEGIN
char s[40];
PushLocHandle(-1);
EnterIntSymbol(LabPart,Erg,SegCode,False);
IntLine(s,Erg);
sprintf(ListLine,"=%s",s);
PopLocHandle();
END
END
END
static void CodeREAD(Word Index)
{
String Exp;
TempResult Erg;
Boolean OK;
LongInt SaveLocHandle;
UNUSED(Index);
if ((ArgCnt != 1) && (ArgCnt != 2)) WrError(1110);
else
{
if (ArgCnt == 2) EvalStringExpression(ArgStr[1], &OK, Exp);
else
{
sprintf(Exp,"Read %s ? ",ArgStr[1]); OK=True;
}
if (OK)
{
setbuf(stdout, Nil); printf("%s", Exp);
fgets(Exp, 255, stdin); UpString(Exp);
FirstPassUnknown = False;
EvalExpression(Exp, &Erg);
if (OK)
{
SetListLineVal(&Erg);
SaveLocHandle = MomLocHandle; MomLocHandle = -1;
if (FirstPassUnknown) WrError(1820);
else switch (Erg.Typ)
{
case TempInt:
EnterIntSymbol(ArgStr[ArgCnt], Erg.Contents.Int, SegNone, True);
break;
case TempFloat:
EnterFloatSymbol(ArgStr[ArgCnt], Erg.Contents.Float, True);
break;
case TempString:
{
String Tmp;
DynString2CString(Tmp, &Erg.Contents.Ascii, sizeof(Tmp));
EnterStringSymbol(ArgStr[ArgCnt], Tmp, True);
break;
}
default:
break;
}
MomLocHandle = SaveLocHandle;
}
}
}
}
static void CodeRADIX(Word Index)
BEGIN
Boolean OK;
LargeWord tmp;
if (ArgCnt!=1) WrError(1110);
else
BEGIN
tmp = ConstLongInt(ArgStr[1], &OK, 10);
if (NOT OK) WrError(1135);
else if (ChkRange(tmp,2,36))
BEGIN
if (Index == 1) OutRadixBase = tmp;
else RadixBase = tmp;
END
END
END
static void CodeALIGN(Word Index)
BEGIN
Word Dummy;
Boolean OK;
LongInt NewPC;
UNUSED(Index);
if (ArgCnt!=1) WrError(1110);
else
BEGIN
FirstPassUnknown=False;
Dummy=EvalIntExpression(ArgStr[1],Int16,&OK);
if (OK)
BEGIN
if (FirstPassUnknown) WrError(1820);
else
BEGIN
NewPC=ProgCounter()+Dummy-1;
NewPC-=NewPC%Dummy;