-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmxass.c
3200 lines (3026 loc) · 87.1 KB
/
mxass.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
/*
19.04.96: 01:06:23:34
20.04.96: 01:07:35:17
01:34:42:49
00:50:45:32
00:51:53:51
->(05:31:19:83)
21.04.96: 00:39:00:24
22.04.96: 00:38:50:35 64NET-Transfer
00:03:50:42 wirkliche Zeilennummern
00:03:41:69
18.05.96: 00:01:45:51 Ausgabe von Start- und Endadresse
27.05.96 00:02:46:78 Bugfix: Spaces bei Rechenausdrücken
29.05.96: 01:03:35:51 lokale Labels (beginnen mit "+" oder "-")
30.05.96: 00:06:57:44 Bugfix bei lokalen Labels und "array scan"-Ausdrücken
->(08:06)
30.05.96: 00:35:08:28 Kommandozeilenparameter, Env.Var., SaveAs, Transfer
00:01:41:52 Weglassen von Erweiterung beim Filenamen möglich
00:00:52:01 Bugfix
00:57:24:74 (bis zum Stromausfall...)
01:13:24:46 Geschwindigkeitsoptimierung um 37%
00:35:01:84 Geschwindigkeitsoptimierung um weitere 9% (insg.: 42%)
00:26:46:54 SaveAs P00, N64
00:11:31:63 Rechnen mit lokalen Labels
01.06.96: 00:08:51:10 Bugfix bei lokalen Labels ohne Namen
01:15:43:43 Include, .SYM-Datei
00:23:46:33 Makros
00:47:06:84 numerische Variablen bei Makros
00:38:04:86 verschiedene Bugfixes
06.07.96 00:13:06:50 Speicheroptimierung (32KB weniger)
verschiedene Bugfixes
08.07.96 00:08:21:34 Errorstop bei "Byte > 8 Bit" bei "immediate" etc.
00:02:21:69 Zu viele Parameter bei ".br"
10.08.96 00:36:21:38 Optimierung der 64NET-Routinen
18.08.96 00:30:19:36 Übertragung per PC64-Kabel
25.09.96 01:10:24:90 Umschreiben in Pascal...
26.09.96 02:00:04:39 ...
27.09.96 00:46:10:15 ...
00:45:29:70 ...
28.09.96 00:47:37:03 ...
01:07:15:26 ... (Debugging)
01:36:46:75 ... (Debugging)
29.09.96 00:14:33:34 ...
01:35:13:96 ...
->(21:18)
00:13:38:07 ...
08.11.96 01:18:55:66 ..., dynamische Speicherverwaltung
10.11.96 00:42:58:67 Eintippen der 65816-Opcodes
13.11.96 00:46:06:19 ...
00:25:59:23 Anpassung an 65816
16.11.96 00:21:25:70 ...
17.11.96 02:03:04:81 ...
00:25:49:70 ...
00:23:07:74 Unterstützung von 16-Bit-Akku und -Index
18.11.96 01:01:41:45 illegale 6502-Opcodes
21.12.96 00:03:03:25 Portangabe als const
24.01.97 00:14:58:80
00:20:58:18 .LO, Linken von Datenfiles (nur PC64)
00:10:34:57 .TS, Text als Screencode ablegen
25.01.97 00:01:07:47 File-not-found bei .LO-Dateien
01.02.97 00:01:53:47 Tastendruck vor Transfer
00:01:33:31 ...
09.03.97 00:11:03:98 64NET: Bugfix, .LO
->(29:56)
21.05.97 00:21:31:26 Opcodes-Datei als EXE-Overlay
00:20:42:57 LOs auch im Ass-Verz.
22.05.97 00:19:24:50 Labels in Zeile mit Mnemo; Line/sec
00:27:59:24 Eintippen der Z80-Opcodes
00:24:52:95 Z80-Assembler
28.05.97 01:22:37:35 ...
00:35:56:84 ...
29.05.97 01:07:35:38 ...
01:10:07:47 ...
00:08:50:24 Z80-Bugfix
30.05.97 00:53:17:40 Umstrukturierung,Pseudo-Statements in Makros,Z80-Makros
00:35:24:08 Z80: ix,iy-Register
00:00:45:82 Bugfix
00:23:48:22 Hilfestellung
00:13:21:45 Z80-Opcodes-Datei als EXE-Overlay
00:09:50:20 Verbesserung des SHOW-Modus
00:06:22:97 ...
25.06.97 00:06:30:22 Bugfix bei Pseudo-Opcodes
02.07.97 00:02:23:89 Anzeigen der übertragenen Dateien
00:06:28:21 Bug bei .LA mit Leerzeichen behoben
16.08.97 01:09:10:58 Kompatibilität zu anderen Assemblern: #, DC, EQU
00:23:34:89 ...
17.08.97 00:40:31:78 GEQU,DS,ANOP,65816 ON/OFF,START,END,LONGA/I (WDC-Ass)
18.08.97 00:19:07:08 .EQU, .DB, .DW, .ORG (Table Assembler)
05.03.98 00:12:05:65 Bugfix: Punkte in/Länge von Datei/Verzeichnisnamen
06.03.98 00:06:03:82 .start (Giga-Ass)
00:07:37:75 .eq, .te, .ds (Giga-Ass)
11.03.98 00:07:31:53 '=' wie EQU, .setpc, .b, .w (Professional Ass)
14.03.98 00:19:31:23 .ob wie -PRG, mit variablem Dateinamen (Hypra-Ass)
00:13:59:10 .en als Ende des Quelltexts (Hypra-Ass)
15.03.98 00:16:16:48 .lo "filename",address
00:22:04:37 * als aktuelle Adresse, .ds > 255, .ds=0-Bugfix
00:10:03:25 *-Bugfix
17.03.98 00:15:46:94 Base-Definition über *=$C000 (Turbo Ass)
00:15:01:20 Bugifx: = ohne Space davor
00:05:20:05 Bugfix bei Spaces in Rechenausdrücken
00:13:30:67 .comment - .en; .if wert=wert - .en
21.03.98 00:02:35:83 .ds-Bugifx
00:00:27:43 .ds-Bugfix #2
05.04.98 00:01:28:14 bessere ASCII-PETSCII-Konversion
11.04.98 00:03:25:47 Bug in Opcodeliste: ldx abs,y
19.05.98 00:10:52:48 Bugfix: Labels in Makros
20.05.98 00:30:33:27 geosSym.asm, geosMac.asm
21.05.98 00:37:30:85 Timeout bei PC64 Übertragung
00:18:00:88 Timeout bei 64NET Übertragung (untested)
00:01:59:60 Bugfix
23.05.98 00:03:10:36 -KEY, -KEY-
00:06:31:37 "Trying to establish connection"
27.05.98 00:21:20:76 Secret message
01.06.98 00:35:37:99 GoDot StartUp...
05.06.98 00:03:21:24 LONGA/LONGI/65816 bugfix
00:20:45:82 multiple bases...
06.06.98 00:44:35:69 ...
00:11:33:18 ...!
31.01.08 02:00:00:00 Port to C...
02.02.08 04:29:00:00 ...
01:53:00:00 ... (Debugging)
01:10:00:00 ...
00:25:00:00 ...
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef int numbertype;
typedef int boolean;
typedef unsigned short uint16_t;
#define _FNSIZE 256
#define false 0
#define true (!false)
#define MNEMOS 107 /* Anzahl der bekannten Mnemos */
#define ADDMODES 23
#define Z80MNEMOS 78
#define MAXNAMELENGTH 25
#define SOURCEMEM 65535L /* Bytes für Quelltext */
#define MAXLINES 3000
#define MAXLABELS 490 /* Maximale Anzahl der Labels */
#define MAXFILES 10 /* Maximale Anzahl der Quelldateien */
#define MAXMACROS 10 /* Maximale Anzahl der Makros */
#define MAXMACROLENGTH 512 /* Bytes für Makroquelltext */
#define MAXMACPARA 10 /* Maximale Anzahl von Makroparametern */
#define MAXOCODE 15000 /* Maximale Größe des ObjectCodes */
#define QUOTE '"'
#define CR "\015\n"
#define SPACES "\t "
#define SEMICOLON ';'
#define COLON ':'
#define HEXDIGITS "0123456789ABCDEF"
#define DECDIGITS "0123456789"
#define NUL '\0'
#define PLUSMINUS "+-"
#define SEP "\001\002\003\004\005\006\007\b\t\n\013\f\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !#&'*+,-./:;=?@[\\]^`{|}~\177"
#define CALCSEP "\001\002\003\004\005\006\007\b\t\n\013\f\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037!#&'*+,-./:;=?@[\\]^`{|}~\177"
#define NOOPERATOR '\0'
#define NONE8 0xff
#define NONE16 0xffffL
#define BIT8MODES "\001\002\003\004\b\t\015\020\021\023\024"
#define BIT16MODES "\005\006\007\n\017\022"
#define BIT24MODES "\f\016"
#define BYTE2MODES (BIT8MODES "\013")
#define BYTE3MODES (BIT16MODES "\025\026")
#define BYTE4MODES BIT24MODES
#define Z80REGS 8
/* zweites L ist ein Dummy, wird nie übereinstimmen */
#define Z80REG8S 8
#define Z80REG16S 4
#define Z80REG162S 4
#define Z80REG816S 12
#define Z80CONDS 8
#define PORT 0x378 /* LPT1 */
#define OPCODESFILENAME "OPCODES.A18"
#define OPCODESFILENAMEZ80 "OPZ80.A23"
#define OPCODESFILELENGTH 5350
#define OPCODESFILELENGTHZ80 546
#define SAVE_AS_NONE 0
#define SAVE_AS_OCODE 1
#define SAVE_AS_PRG 2
#define SAVE_AS_P00 3
#define SAVE_AS_D64 4
#define SAVE_AS_T64 5
#define SAVE_AS_C64 6
/* Arrays */
char STR1[14];
char STR3[10];
char Z80REG[Z80REGS][5] = {
"B", "C", "D", "E", "H", "L", "L", "A"
};
char Z80REG8[Z80REG8S][5] = {
"B", "C", "D", "E", "H", "L", "(HL)", "A"
};
char Z80REG16[Z80REG16S][3] = {
"BC", "DE", "HL", "SP"
};
char Z80REG162[Z80REG162S][3] = {
"BC", "DE", "HL", "AF"
};
char Z80REG816[Z80REG816S][5] = {
"B", "BC", "C", "D", "DE", "E", "H", "HL", "L", "(HL)", "SP", "A"
};
char Z80COND[Z80CONDS][3] = {
"NZ", "Z", "NC", "C", "PO", "PE", "P", "M"
};
unsigned char Z80REGCONV1[Z80REG8S] = {
0, 2, 3, 5, 6, 8, 9, 0xb
};
unsigned char Z80REGCONV2[Z80REG162S] = {
1, 4, 7, 0xff
};
unsigned char Z80OPCODECONV[Z80REG816S] = {
0, 0x6, 0x8, 0x10, 0x16, 0x18, 0x20, 0x26, 0x28, 0x30, 0x36, 0x38
};
char *SourceText;
unsigned short reallinenumber[MAXLINES + 1];
unsigned short belongstoFile[MAXLINES + 1];
char Mnemo[MNEMOS][4];
unsigned short Opcode[MNEMOS][ADDMODES];
char Z80Mnemo[Z80MNEMOS][5];
unsigned char Z80Addmode[Z80MNEMOS];
uint16_t Z80Opcode[Z80MNEMOS];
unsigned char RegisterInvolved[MNEMOS];
char xLabel[MAXLABELS + 1][MAXNAMELENGTH + 1];
unsigned short Value[MAXLABELS + 1];
unsigned short LValue[MAXLABELS + 1];
char SourceFile[MAXFILES + 1][256];
char MacroName[MAXMACROS + 1][MAXNAMELENGTH + 1];
char MacroSourceText[MAXMACROS + 1][MAXMACROLENGTH];
unsigned short MacroSourceEnd[MAXMACROS + 1];
char MacroOperand[MAXMACROS + 1][256];
char MacroLabel[MAXMACPARA + 1][MAXNAMELENGTH + 1];
unsigned short MacroValue[MAXMACPARA + 1];
unsigned char ocode[MAXOCODE + 1];
/* Variablen */
char Loads[256]; /* TODO: Must be done with arrays */
//char StoreAddresses[256]; /* TODO: Must be done with arrays */
#define MAXStoreAddresses 200
struct {
uint16_t ocodeindex;
uint16_t memoryaddress;
} StoreAddresses[MAXStoreAddresses];
int nStoreAddresses;
unsigned short LoadAddress, Time; /* TODO absolute $40:$6C; */
unsigned short StartTime;
double AssemblyTime;
boolean Show;
char PrintLine[256];
unsigned short Labels, MacroLabels;
boolean MacroError;
char actl[256];
unsigned char Pass;
boolean unknown;
unsigned char AsciiFlag, Cpu;
boolean CpuIllegal;
unsigned short opaddress, oldopaddress, startjumpaddress, currentline;
char Filename[256];
unsigned char SaveAs;
char SaveName[256];
boolean Symbols;
unsigned short SourceFiles, lines, reallines;
char Pseudo[256], Operand[256];
numbertype number, number2;
unsigned short startaddress, times, insold;
char a[256];
unsigned short Macros;
unsigned char ShowIndex;
/* neu hinzugefügte Variablen */
unsigned short i;
unsigned char j, ins, ins2;
char SwitchParameter[11];
FILE *OpcodesFile;
char* CurL;
char actMacroName[256];
char actMacroOperand[256];
unsigned short help, ArrayScan;
boolean ArrayFound, PseudoOK;
unsigned short ocodeIndex, SourceIndex, SourceEnd, MacroSourceIndex;
FILE *SaveFile;
FILE *SymbolsFile;
boolean SizeAccu, SizeIndex;
boolean IgnoreNextEnd;
boolean TransErr;
char SaveFile_NAME[_FNSIZE];
char SymbolsFile_NAME[_FNSIZE];
/* Store in "ret" the substring of length "len" starting from "pos" (1-based).
Store a shorter or null string if out-of-range. Return "ret". */
char *strsub(ret, s, pos, len)
register char *ret, *s;
register int pos, len;
{
register char *s2;
if (--pos < 0 || len <= 0) {
*ret = 0;
return ret;
}
while (pos > 0) {
if (!*s++) {
*ret = 0;
return ret;
}
pos--;
}
s2 = ret;
while (--len >= 0) {
if (!(*s2++ = *s++))
return ret;
}
*s2 = 0;
return ret;
}
/* Return the index of the first occurrence of "pat" as a substring of "s",
starting at index "pos" (1-based). Result is 1-based, 0 if not found. */
int strpos2(s, pat, pos)
char *s;
register char *pat;
register int pos;
{
register char *cp, ch;
register int slen;
if (--pos < 0)
return 0;
slen = strlen(s) - pos;
cp = s + pos;
if (!(ch = *pat++))
return 0;
pos = strlen(pat);
slen -= pos;
while (--slen >= 0) {
if (*cp++ == ch && !strncmp(cp, pat, pos))
return cp - s;
}
return 0;
}
/* neue Funktionen/Prozeduren für Pascal */
char *
UpCaseStr(Result, S_)
char *Result;
char *S_;
{
char S[256];
unsigned char i, FORLIM;
strcpy(S, S_);
FORLIM = strlen(S);
for (i = 0; i < FORLIM; i++)
S[i] = toupper(S[i]);
return strcpy(Result, S);
}
char *
Trim(Result, S_)
char *Result;
char *S_;
{
//printf("Trim: '%s'\n", S_);
char S[256];
char STR4[256];
strcpy(S, S_);
if (*S == '\0')
return strcpy(Result, S);
/* Spaces links löschen */
while ((S[0] == ' ' || S[0] == '\t') && *S != '\0') {
strcpy(STR4, S + 1);
strcpy(S, STR4);
}
/* Spaces rechts löschen */
while (S[strlen(S) - 1] == ' ' || S[strlen(S) - 1] == '\t')
S[strlen(S) - 1] = '\0';
return strcpy(Result, S);
}
char *
Hex(Result, a, decimals)
char *Result;
unsigned short a;
unsigned char decimals;
{
unsigned char i;
char s[256];
char STR4[256];
char STR5[256];
*s = '\0';
for (i = 1; i <= decimals; i++) {
sprintf(s, "%s%s",
strsub(STR4, HEXDIGITS, (a & 15) + 1, 1), strcpy(STR5, s));
a >>= 4;
}
return strcpy(Result, s);
}
unsigned char
HiHi(number)
long number;
{
return (((unsigned long) number) >> 16);
}
char *
Right4(Result, A)
char *Result;
unsigned short A;
{
char S[256];
char STR4[256];
sprintf(S, "%u", A);
while (strlen(S) < 4)
sprintf(S, " %s", strcpy(STR4, S));
return strcpy(Result, S);
}
unsigned char
FindAny(Sub, Main)
char *Sub, *Main;
{
//printf("FindAny: Sub='%s', Main='%s'\n", Sub, Main);
unsigned char l, FORLIM;
char STR4[256];
FORLIM = strlen(Main);
for (l = 1; l <= FORLIM; l++) {
sprintf(STR4, "%c", Main[l - 1]);
if (strpos2(Sub, STR4, 1) > 0)
return l;
}
return 0;
}
char *
KillQuotes(Result, T_)
char *Result;
char *T_;
{
char T[256];
unsigned char ins1, ins2, l;
char STR4[256];
char STR5[256];
strcpy(T, T_);
do {
sprintf(STR4, "%c", QUOTE);
ins1 = strpos2(T, STR4, 1);
/* alles innerhalb von "" übermalen (einschl.) */
if (ins1 == 0)
goto _LBreak;
sprintf(STR4, "%c", QUOTE);
ins2 = strpos2(strcpy(STR5, T + ins1), STR4, 1);
if (ins2 == 0)
ins2 = strlen(T);
else
ins2 += ins1;
for (l = ins1 - 1; l < ins2; l++)
T[l] = 'X';
} while (true);
_LBreak:
return strcpy(Result, T);
}
unsigned char
FindSeparator(S)
char *S;
{
char STR4[256];
return (FindAny(SEP, KillQuotes(STR4, S)));
}
unsigned char
FindCalcSeparator(S)
char *S;
{
char STR4[256];
return (FindAny(CALCSEP, KillQuotes(STR4, S)));
}
boolean
FindFile(Filename)
char *Filename;
{
printf("ERROR: asm1!\n");
exit(1);
/*
* Filename:=Filename+#0; SeF:=Seg(Filename); OfF:=Ofs(Filename)+1;
* asm push ds mov ax, SeF mov ds, ax mov dx, OfF mov ah, 4Eh mov cx,
* 20h int 21h jnc @@NoError mov @Result, FALSE jmp @@FindEnd
* @@NoError: mov @Result, TRUE @@FindEnd: pop ds end;
*/
}
/* Funktionen/Prozeduren */
int
TrimSourceText(char *Filename_, int i)
{
char Filename[256];
FILE *actSourcefile;
unsigned short actReallinenumber;
char Line[256], Line2[256];
unsigned char ins, ins2;
char IncFile[256];
boolean IncFound, NextLineInBuffer;
char testequ[256];
char STR4[256];
char STR5[256], STR6[256];
char *TEMP;
char STR7[256];
char STR9[256];
strcpy(Filename, Filename_);
actSourcefile = NULL;
strcpy(SourceFile[SourceFiles], Filename);
SourceFiles++;
if (!(actSourcefile = fopen(Filename, "r"))) {
printf("File \"%s\" not found!\n", Filename);
exit(1);
}
actReallinenumber = 0;
NextLineInBuffer = false;
do {
actReallinenumber++;
if (NextLineInBuffer)
strcpy(Line, Line2);
else {
if (!fgets(Line, 256, actSourcefile)) break;
if ((TEMP = strchr(Line, '\n')))
*TEMP = 0;
if ((TEMP = strchr(Line, '\r')))
*TEMP = 0;
}
sprintf(STR5, "%c", SEMICOLON);
ins = strpos2(Line, STR5, 1);
if (ins > 0) { /* REMs löschen */
Line[ins - 1] = '\0';
}
/* Zeile mit Label und Mnemo aufspalten */
if (*Line != '\0' && Line[0] != ' ' && Line[0] != '\t' &&
Line[0] != '.' && Line[0] != '#' && NextLineInBuffer == false) { /* ^ Pseudo-Opcodes
* dürfen weiterhin an
* 1. Stelle stehen */
ins = strpos2(Line, " ", 1);
if (ins == 0)
ins = 255;
ins2 = strpos2(Line, "\t", 1);
if (ins2 == 0)
ins2 = 255;
if (ins2 < ins)
ins = ins2;
sprintf(STR4, "%.4s", Trim(STR6, strcpy(STR7, Line + ins)));
UpCaseStr(testequ, STR4);
sprintf(STR4, "%.3s", testequ);
if (!strcmp(STR4, "EQU") || !strcmp(testequ, "GEQU") ||
!strcmp(testequ, ".EQU") || testequ[0] == '=' && *testequ != '\0')
goto _LEQU;
if (ins != 255) {
if (Line[ins - 2] == '=') {
sprintf(STR7, "%.*s %s", ins - 2, Line, Line + ins - 2);
/*
* für =-Routine von später ein Space
* einfügen
*/
strcpy(Line, STR7);
goto _LEQU;
}
strcpy(Line2, Line + ins);
Line[ins - 1] = '\0';
/* p2c: ASS29.PAS, line 444:
* Note: Modification of string length may translate incorrectly [146] */
if (Line[strlen(Line) - 1] != COLON)
sprintf(Line + strlen(Line), "%c", COLON);
NextLineInBuffer = true;
/*
* -> Line wird abgelegt, Line2 beim nächsten
* Durchlauf
*/
} else {
*Line2 = '\0';
if (Line[strlen(Line) - 1] != COLON)
sprintf(Line + strlen(Line), "%c", COLON);
NextLineInBuffer = true;
}
} else {
_LEQU:
NextLineInBuffer = false;
}
strcpy(Line, Trim(STR7, Line));
if (*Line != '\0') {
if (!strcmp(UpCaseStr(STR7, strsub(STR4, Line, 2, 7)), "INCLUDE") &&
(Line[0] == '.' || Line[0] == '#')) {
Trim(IncFile, strcpy(STR5, Line + 8));
if (IncFile[0] == QUOTE) { /* Quotes weg */
strcpy(STR5, IncFile + 1);
strcpy(IncFile, STR5);
}
if (IncFile[strlen(IncFile) - 1] == QUOTE)
IncFile[strlen(IncFile) - 1] = '\0';
IncFound = false;
if (strpos2(IncFile, ".", 1) == 0) {
sprintf(STR5, "%s.ASM", IncFile);
if (FindFile(STR5)) {
strcat(IncFile, ".ASM");
IncFound = true;
}
sprintf(STR5, "%s.INC", IncFile);
if (FindFile(STR5)) {
strcat(IncFile, ".INC");
IncFound = true;
}
} else {
if (FindFile(IncFile))
IncFound = true;
}
if (!strcmp(UpCaseStr(STR5, Filename), UpCaseStr(STR6, IncFile))) {
printf("Recursive \".include\" in file %s, line %u!\n",
UpCaseStr(STR9, Filename), actReallinenumber);
exit(1);
}
printf(" Reading include \"%s\"\n", UpCaseStr(STR6, IncFile));
TrimSourceText(IncFile, i);
printf(" Continuing \"%s\"\n", UpCaseStr(STR9, Filename));
} else {
if (SourceIndex + strlen(Line) >= SOURCEMEM) {
printf("Sourcetext too big!\n");
exit(1);
}
/* Zeile in Quelltextspeicher kopieren */
memcpy(SourceText+SourceIndex, Line, strlen(Line));
//printf("memcpy(%x, %x, %d)\n", SourceText+SourceIndex, Line, strlen(Line));
//printf("'%c','%c','%c'\n", Line[0], Line[1], Line[2]);
SourceIndex += strlen(Line) + 1;
SourceText[SourceIndex - 1] = 0; //zero terminate
reallinenumber[i] = actReallinenumber;
belongstoFile[i] = SourceFiles - 1;
i++;
if (i > MAXLINES) {
printf("Too many lines!\n");
exit(1);
}
}
}
} while (!(feof(actSourcefile) && NextLineInBuffer == false));
fclose(actSourcefile);
SourceFiles--; /* dem Aufrufer wieder die richtige Ebene übergeben */
return i;
}
void
Errorstop(S)
char *S;
{
printf("Line %u: %s\n", currentline, S);
puts(CurL);
exit(1);
}
long
HexDec(H_)
char *H_;
{
/* hex -> dezimal */
char H[256];
unsigned char i;
numbertype number;
char d;
unsigned char ins;
char STR4[256];
unsigned char FORLIM;
strcpy(H, H_);
strcpy(H, UpCaseStr(STR4, H));
number = 0;
FORLIM = strlen(H);
for (i = 1; i <= FORLIM; i++) {
d = H[i - 1];
sprintf(STR4, "%c", d);
ins = strpos2(HEXDIGITS, STR4, 1);
if (ins == 0)
Errorstop("Wrong hex number!");
ins--;
number += (long) ((double) (ins << (strlen(H) - i) * 4));
}
return number;
}
unsigned short
BinDec(H)
char *H;
{
/* bin -> dezimal */
unsigned char i;
unsigned short number;
unsigned char d, FORLIM;
number = 0;
FORLIM = strlen(H);
for (i = 1; i <= FORLIM; i++) {
d = H[i - 1] - 48;
if (d > 1)
Errorstop("Wrong bin number!");
number += d << (strlen(H) - i);
}
return number;
}
char
Petscii(S)
char S;
{
/* wandelt einzelnes Zeichen von ASCII nach PETSCII */
unsigned char a;
a = S;
if (a > 64 && a < 91)
return (a + 128);
if (a > 96 && a < 123)
return (a - 32);
return S;
}
char *
SPetscii(Result, A)
char *Result;
char *A;
{
/* wandelt String von ASCII nach PETSCII */
int i;
for (i=0; i<strlen(A); i++) {
Result[i] = Petscii(A[i]);
}
Result[i] = 0;
return Result;
}
char *
SScrCode(Result, A)
char *Result;
char *A;
{
/* wandelt Str PETSCII nach Screencode */
printf("ERROR: asm3!\n");
exit(1);
/*
* SegA:=Seg(A); OfsA:=Ofs(A)+1; LenA:=Length(A); asm push ds mov ax,
* SegA mov ds, ax mov es, ax mov si, OfsA mov di, si mov cl, LenA
* mov ch, 0 @@scrloop: lodsb cmp al, $20 jae @@scr1 add al, $80 jmp
* @@scrend @@scr1: cmp al, $40 jb @@scrend cmp al, $60 jae @@scr2
* sub al, $40 jmp @@scrend @@scr2: cmp al, $80 jae @@scr3 sub al,
* $20 jmp @@scrend @@scr3: cmp al, $A0 jae @@scr4 add al, $40 jmp
* @@scrend @@scr4: cmp al, $C0 jae @@scr5 sub al, $40 jmp @@scrend
* @@scr5: cmp al, $FF je @@scr6 sub al, $80 jmp @@scrend @@scr6: mov
* al, $5E { Pi } @@scrend: stosb loop @@scrloop pop ds end;
*/
return strcpy(Result, A);
}
long
GetNumber(S_)
char *S_;
{
char S[256];
boolean locallabelflag;
char realS[256];
char S2[256];
numbertype number, number2;
unsigned char ins;
char Operator;
unsigned char i;
char a;
short ValCode;
unsigned short LLabels, oldfound, ArrayScan, help;
boolean Labelfound, OperatorOK;
char STR4[256];
char STR5[256];
unsigned short FORLIM;
short TEMP;
strcpy(S, Trim(STR4, S_));
if (!*S) Errorstop("Expression expected!");
if (S[0] == '+' || S[0] == '-') { /* lokales Label */
locallabelflag = true;
strcpy(realS, S);
strcpy(STR4, S + 1);
strcpy(S, STR4);
} else
locallabelflag = false;
if (S[0] == '*') {
if (strlen(S) > 1)
ins = FindCalcSeparator(strcpy(STR4, S + 1)) + 1;
else
ins = 0;
} else
ins = FindCalcSeparator(S);
if (ins > 0) { /* komplexer Ausdruck mit Operator */
strcpy(S2, S + ins);
number2 = GetNumber(S2); /* rekursiv! */
Operator = S[ins - 1];
if (locallabelflag) {
sprintf(STR5, "%.*s", ins, realS);
Trim(S, STR5); /* echtes Label wiederherstellen */
} else {
sprintf(STR4, "%.*s", ins - 1, S);
strcpy(S, Trim(STR5, STR4));
}
} else {
Operator = NOOPERATOR;
if (locallabelflag)
strcpy(S, realS);
}
switch(S[0]) {
case '*': /* aktuelle Assembly-Adresse */
number = opaddress;
break;
case '$': /* hex-Konstante */
number = HexDec(S+1);
break;
case '%': /* bin-Konstante */
number = BinDec(S+1);
break;
case '"': /* ASCII-Konstante */
if (S[2] != QUOTE)
Errorstop("ASCII constant too long!");
number = S[1];
if (AsciiFlag == 0)
number = Petscii(number);
break;
case '<': /* Low-Byte */
number = GetNumber(S+1) & 255;
break;
case '>': /* High-Byte */
number = ((unsigned long) GetNumber(S+1)) >> 8;
break;
case '(': /* Ausdruck in Klammern */
if (S[strlen(S) - 1] != ')')
Errorstop("Brackets error!");
number = GetNumber(strsub(STR5, S, 2, (int) (strlen(S) - 2)));
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
/* dezimale Konstante */
ValCode = (sscanf(S, "%ld", &number) == 0); /* ! ValCode auswerten! */
break;
default: /* Label */
strcpy(S, UpCaseStr(STR5, S));
if (locallabelflag) { /* lokales Label */
if (Pass == 1)
unknown = true;
else {
if (S[0] == '+') /* nur Vorwärtsverweise erlaubt */
number = 0xFFFF;
else /* '-' */
number = 0;
ArrayFound = 0;
for (ArrayScan = 0; ArrayScan < Labels; ArrayScan++)
if (!strcmp(xLabel[ArrayScan], S))
if (((S[0] == '+') && (Value[ArrayScan] > opaddress && number > Value[ArrayScan])) ||
(Value[ArrayScan] <= opaddress && number < Value[ArrayScan])) {
number = Value[ArrayScan];
ArrayFound = 1;
}
if (!ArrayFound)
Errorstop("Local label not found!");
/* Nebeneffekt: lokales Label darf nicht Werte 0 bzw. 0xFFFF haben */
}
} else { /* globales Label */
ArrayFound = false;
for (ArrayScan = 0; ArrayScan < Labels; ArrayScan++) {
if (!strcmp(xLabel[ArrayScan], S)) {
help = ArrayScan;
ArrayFound = true;
break;
}
}
if (ArrayFound) {
number = Value[help];
} else { /* Label nicht gefunden - vielleicht ein Makro-Parameter? */
Labelfound = false;
if (MacroLabels > 0) {
ArrayFound = false;
if (MacroLabels > 0) {
for (ArrayScan = 0; ArrayScan < MacroLabels; ArrayScan++) {
if (!strcmp(MacroLabel[ArrayScan], S)) {
help = ArrayScan;
ArrayFound = true;
break;
}
}
}
if (ArrayFound) {
number = MacroValue[help];
Labelfound = true;
}
}
if (!Labelfound) {
if (Pass == 1)
unknown = true;
else
Errorstop("Label not found!");
}
}
}
}
OperatorOK = false;
if (Operator == '+') {
number += number2;
OperatorOK = true;
}
if (Operator == '-') {
number -= number2;
OperatorOK = true;
}
if (Operator == '*') {
number *= number2;
OperatorOK = true;
}
if (Operator == '/') {
number /= number2;