-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdagood.pas
1649 lines (1558 loc) · 49.9 KB
/
dagood.pas
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
{$I-}
unit DAGood;
interface uses DAtable;
const
RealDataLoc: boolean = False;
Type8085 : boolean = False;
UndoCode : boolean = False;
DataBlock : boolean = False;
LabelShow : boolean = False;
RemEnable : boolean = True;
RemLast : boolean = False;
SizeDB = 4;
MaxLabels = 1000;
MaxBlocks = 8;
BIOSenabled : boolean = True;
BIOShigh : word = $159;
MaxFol = 10;
LinesCount = 22; { Number of visible disasm lines, upper limit for LineNo }
type
LabelType = string[8];
ByteArray = array[0..65535-1] of byte;
PByteArray = ^ByteArray;
LabelArray = array[1..MaxLabels] of LabelType;
PLabelArray = ^LabelArray;
var
FileName : string; { Source file name }
FileLength : longint;
PrgMem, ShadowH, ShadowL : PByteArray;
Labels : PLabelArray;
PrgType, PrgStart, PrgBegin, PrgLength, PrgData : word;
PLow, PHigh : word;
LabelNum, TinyLabels : word;
MemPos, DumpPos, RealPos, OriginPos, CallerPos : word;
LineNo : integer; { Current line number for disasm view }
GreedCall : array[1..10] of word;
DumpChar : boolean; { Memory view mode }
ProcQ : array[1..1000] of word;
Proc : array[1..5000] of word;
ProcNum, TotalProcs : integer;
Follow : array[1..MaxFol] of word;
FolNum : byte;
FindString, FControl : string;
FindPos : word;
KeyReg : array[1..10] of word; { Bookmarks }
Z80 : boolean;
FirstZ80 : boolean;
LongCode : boolean;
Remark : boolean;
RemarkDec : boolean;
RemarkEnable : boolean;
CharDec : byte;
PageByte : word;
Adds : array[1..LinesCount] of word;
ILength : byte;
LabelNo : integer;
ErrorMessage: string;
ErrorAttrs: byte;
function Hex2(b:byte):string;
function Hex4(w:word):string;
function AsmFormat: string; { Get string describing current CPU options }
function DisAsm(addr: word): string; { Disasm using the current CPU options }
function LabelExist(addr: word): boolean; { If label exists, returns True and set LabelNo }
procedure DAGoodInit;
procedure SaveEnvir; { Save .WRK file }
procedure LoadEnvir; { Load .WRK file }
procedure SaveAsmFile; { Generate the ASM file }
procedure MakeData(w1, w2: word); { Mark this area as byte data }
procedure MakeCode(w1, w2: word); { Mark this area as code }
procedure MakeWord(w1, w2: word); { Mark this area as word data }
procedure MakeAddress(w1, w2: word);
procedure SetLabelName(ad:word; s:string);
procedure DeleteLabel(ad: word);
procedure MarkGreedCall(addr: word); { Mark/unmark Greed Call }
procedure ImportSymbols;
procedure ImportControl;
implementation
const
Version : string[8] = 'v(1.12) '; {DAO version}
ParamS : string[14]=('/*#?&%~^@!|"`'); { - must be last}
HexChar : string[16]=('0123456789ABCDEF');
IndexName : array[1..2] of string[2]=('IX','IY');
IndexVar : array[1..2] of string[8]=('(IX|)','(IY|)');
{ IndexName8: array[1..2] of string[2]=('di','si');}
IndexVar8 : array[1..2] of string[8]=('[di|]','[si|]');
SegName : array[0..1] of string[2]=('ds','cs');
DAAval : array[0..1] of string[3]=('daa','das');
Z80SName : array[0..1] of string[1]=('','>');
WrkHeader : string[16]='DA_WorkFile V1.0';
Format : array[False..True] of string[5]=('8080 ','Z80 ');
TabSize : byte = 10;
InterSize : byte = 4;
BCode = 1;
BData = 2;
LCode = 1;
LData = 2;
LTable = 3;
var
IndexNo, SegmentNo : byte;
IndexOfs : shortint;
CurHeader : string[16];
ErrorLine : byte;
OldDump, sadr : word;
DAttr : boolean;
IPtr : word;
ldw : boolean; { Flag indicating we have the .WRK file and need to load it }
LongCodeS : string;
push1 : byte;
push2 : byte;
push3 : byte;
push4 : byte;
f : file;
a : char;
function ReadKey: char; {STUB for Crt}
begin end;
function KeyPressed: boolean; {STUB for Crt}
begin end;
function WhereX: integer; {STUB for Crt}
begin end;
function WhereY: integer; {STUB for Crt}
begin end;
procedure SetError(Msg: string; Attrs: byte);
begin
ErrorMessage := Msg;
ErrorAttrs := Attrs;
end;
function Hex2(b:byte):string;
begin
Hex2:=HexChar[b shr 4+1]+HexChar[b and $F+1]
end;
function Hex4(w:word):string;
begin
Hex4:=HexChar[w shr 12+1]+HexChar[(w shr 8) and $F+1]+
HexChar[(w shr 4) and $F+1]+HexChar[w and $F+1];
end;
function DataByte(b:byte):string;
begin
DataByte:='0'+HexChar[b shr 4+1]+HexChar[b and $F+1]+'h';
end;
function Index(b:shortint):string;
var sgn:char; bb:byte;
begin
if b<0 then begin bb:=-b; sgn:='-' end else begin bb:=b;sgn:='+';end;
Index:=Sgn+'0'+HexChar[bb shr 4+1]+HexChar[bb and $F+1]+'h';
end;
function DataWord(w:word):string;
begin
DataWord:='0'+HexChar[w shr 12+1]+HexChar[(w shr 8) and $F+1]+
HexChar[(w shr 4) and $F+1]+HexChar[w and $F+1]+'h';
end;
function SStr(w:word;d:byte):string;
var s:string;
begin
Str(w:d,s);
SStr:=s;
end;
function Strg(ch : char; Num : byte) : string;
var a : String;
begin
a[0] := char(num);
fillchar(a[1],num,ch);
Strg := a;
end;
function GetByte(addr:word):string;
var b:byte;
begin
b:=PrgMem^[addr];
GetByte:='0'+HexChar[b shr 4+1]+HexChar[b and $F+1]+'h';
end;
function GetWord(addr:word):string;
var w:word;
begin
w:=PrgMem^[addr+1] shl 8+PrgMem^[addr];
GetWord:='0'+HexChar[w shr 12+1]+HexChar[(w shr 8) and $F+1]+
HexChar[(w shr 4) and $F+1]+HexChar[w and $F+1]+'h';
end;
function GetHex4(addr:word):string;
var w:word;
begin
w:=PrgMem^[addr+1] shl 8+PrgMem^[addr];
GetHex4:=HexChar[w shr 12+1]+HexChar[(w shr 8) and $F+1]+
HexChar[(w shr 4) and $F+1]+HexChar[w and $F+1];
end;
procedure WriteTo(s:string;x,y,attr:byte);
begin
{TODO: Remove}
end;
function Space(l:byte):string;
var i:byte; s:string;
begin
s:='';for i:=1 to l do s:=s+' ';Space:=s
end;
function Strng(l:byte;ch:char):string;
var i:byte; s:string;
begin
s:='';for i:=1 to l do s:=s+ch;Strng:=s
end;
procedure Suck(var s:string);
var i:integer;
begin
i:=1; while i<=Length(s) do if s[i]=' ' then Delete(s, i, 1) else Inc(i);
end;
procedure Replace(var Dest:string;Source:string;p:byte);
begin
Delete(Dest,p,1); Insert(Source, Dest, p);
end;
function UpString(s:string):string;
var i:byte;
begin
UpString:=s;
for i:=1 to Length(s) do UpString[i]:=UpCase(s[i]);
end;
function CutString(var d:word;var s:string):boolean;
var i:integer;ls:string;
begin
ls:='XXXX';for i:=1 to 4 do ls[i]:=s[i];
Delete(s, 1, 5); Val('$'+ls,d,i);
if i>0 then CutString:=False else CutString:=True;
end;
function AsmFormat: string;
var Fmt: string;
begin
if Type8085 then Format[False] := '8085' else Format[False] := '8080';
Fmt := Format[Z80];
if (not Z80) and (UndoCode) then Fmt := Fmt + '+' else Fmt := Fmt + ' ';
AsmFormat := Fmt;
end;
function LabelExist(addr:word):boolean;
var w:word;
begin
LabelExist:=True;
{ if ShadowH^[addr] and $10>0 then begin LabelNo:=0; Exit end;}
w:=(ShadowH^[addr] and $7) shl 8+ShadowL^[addr];
if w>0 then begin LabelNo:=w end else LabelExist:=False;
end;
{========================== „¨§ áᥬ¡«¥à z80 ==========================}
function DisAsmZ80(addr:word):string;
var dt,lb:byte; LNo, ad:word; r:boolean;
function Instruction:string;
var s:string;c,p:byte;
begin
IndexNo:=0; IndexOfs:=0;
s:=Instr[PrgMem^[iptr]];
SegmentNo:=(ShadowH^[iptr] shr 5) and 1;
repeat
for c:=1 to Length(ParamS) do
begin
p:=Pos(Params[c], s);
if p>0 then break;
end;
if c=Length(ParamS) then c:=0;
if c>0 then
case ParamS[c] of
'/' : Replace(s,Space(InterSize-p+3), p);
'*' : begin
Inc(ILength,2);
case ShadowH^[iptr+1] shr 6 of
00, 01, 02 : Replace(s, GetWord(iptr+1), p);
03 : begin
ad:=PrgMem^[iptr+1]+PrgMem^[iptr+2] shl 8;
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, {'offset '+}Labels^[LabelNo], p); r:=true; end;
if not r then Replace(s, {'offset L'}'L'+Hex4(ad), p);
end;
end;
end;
'#' : begin
Inc(ILength, 1);
if IndexNo>0 then Inc(iptr);
Replace(s, GetByte(iptr+1), p);
end;
'&' : begin
ad:=PrgMem^[iptr+1]+PrgMem^[iptr+2] shl 8;
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, Labels^[LabelNo], p); r:=true; end;
if not r then Replace(s, 'L'+Hex4(ad), p);
Inc(ILength, 2);
end;
'?' : begin
ad:=iptr+shortint(PrgMem^[iptr+1])+2;
Inc(ILength, 1);
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, Labels^[LabelNo], p); r:=true; end;
if not r then Replace(s, 'L'+Hex4(ad), p);
end;
'%' : begin
ad:=PrgMem^[iptr+1]+PrgMem^[iptr+2] shl 8;
Inc(ILength, 2);
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, Labels^[LabelNo], p); r:=true; end;
if not r and (ad>=PrgData) then begin Replace(s, DataWord(ad), p);r:=true end;
if not r then Replace(s, Hex4(ad), p);
end;
'~' : if IndexNo>0 then
begin
Replace(s,IndexVar[IndexNo],p);
Inc(ILength);
end else Replace(s, '(HL)', p);
'"' : Replace(s, Z80SName[SegmentNo],p);
'|' : begin
Replace(s,Index(IndexOfs),p);
end;
'^' : if IndexNo>0 then
begin
Replace(s, IndexName[IndexNo], p);
end else Replace(s, 'HL', p);
'!' : Replace(s, 'Bad opcode', p);
'@' : begin
Inc(ILength);Inc(iptr);
case s[p+1] of
{CB} '0' : if IndexNo>0 then
begin
{Inc(iptr);
Inc(ILength);}
s:=InstrCB[PrgMem^[iptr+1]]
end else s:=InstrCB[PrgMem^[iptr]];
{ED} '1' : s:=InstrED[PrgMem^[iptr]];
{DD} '2' : begin {IX}
IndexNo:=1;
s:=Instr[PrgMem^[iptr]];
IndexOfs:=shortint(PrgMem^[iptr+1]);
end;
{FD} '3' : begin {IX}
IndexNo:=2;
s:=Instr[PrgMem^[iptr]];
IndexOfs:=shortint(PrgMem^[iptr+1]);
end;
end;
end;
end;
{ if Keypressed then a:=ReadKey;}
until (a=#27) or (p=0);
Instruction:=s;
end;
function ByteBlock:string;
var s:string;Done:boolean;i:byte;w,l:word;
begin
Done:=False;w:=iptr;s:='';i:=0;
repeat
s:=s+DataByte(PrgMem^[w]); Inc(w); Inc(i);
l:=ShadowH^[w] shl 8+ShadowL^[w];
if (ShadowH^[w]<>$40) or (l and $3FFF>$0) or (i>3) or (DataBlock) then Done:=True else if i<4 then s:=s+',';
if not Done then Inc(ILength);
until Done;
ByteBlock:='.db'+Space(InterSize)+s;
end;
function WordBlock:string;
begin
Inc(ILength);
WordBlock:='.dw'+Space(InterSize)+DataWord(PrgMem^[iptr]+PrgMem^[iptr+1] shl 8);
end;
function Address:string;
begin
Inc(ILength);
ad:=PrgMem^[iptr]+PrgMem^[iptr+1] shl 8;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Address:='.dw'+Space(InterSize)+{'offset '+}Labels^[LabelNo]; Exit end;
Address:='.dw'+Space(InterSize)+{'offset }'L'+Hex4(ad);
end;
var s:string;
begin
if Remark then begin
DisAsmZ80:=Instruction;
exit;
end;
LongCode:=false;
iptr:=addr;
ILength:=1;
LNo:=(ShadowH^[iptr] and $7) shl 8+ShadowL^[iptr];
dt:=ShadowH^[iptr] shr 6;{only 2 high bits}
lb:=(ShadowH^[iptr] shr 4) and $3;
case dt of
00 : s:=Instruction;
01 : s:=ByteBlock;
02 : s:=WordBlock;
03 : s:=Address;
end;
if LNo>0 then s:=Labels^[LNo]+':'+Space(TabSize-Length(Labels^[LNo])-1)+s
else if ShadowH^[addr] and $10>0
then s:='L'+Hex4(addr)+':'+Space(TabSize-6)+s
else s:=Space(TabSize)+s;
while Length(s)<46 do s:=s+' ';
DisAsmZ80:=s;
end;
{========================= „¨§ áᥬ¡«¥à i8080 =========================}
function DisAsm8088(addr:word):string;
var dt,lb:byte; LNo, ad:word; r:boolean;
iptrPM: word;
function Instruction:string;
var s:string;c,p:byte;
ss : string;
LenCodeS :byte;
procedure LongCodeWork;
var c:byte;
begin
LongCode:=true;
s:=''; LenCodeS:=Length(LongCodeS);
for c:=1 to LenCodeS do begin
ss:=Copy(LongCodeS,c,1);
if ss='\' then begin
LongCodeS:=Copy(LongCodeS,c+1,LenCodeS-c);
break;
end else s:=s+ss;
end;
if c=LenCodeS then begin
LongCode:=false;
end;
end;
begin
if LongCode then LongCodeWork else begin
IndexNo:=0; IndexOfs:=0;
s:=Instr8088[PrgMem^[iptr]];
end;
SegmentNo:=(ShadowH^[iptr] shr 5) and 1;
repeat
for c:=1 to Length(ParamS) do
begin
p:=Pos(Params[c], s);
if p>0 then break;
end;
if c=Length(ParamS) then c:=0;
if c>0 then
case ParamS[c] of
'/' : Replace(s,Space(InterSize-p+3), p);
'*' : begin
Inc(ILength,2);
case ShadowH^[iptr+1] shr 6 of
00, 01, 02 : Replace(s, GetWord(iptr+1), p);
03 : begin
ad:=PrgMem^[iptr+1]+PrgMem^[iptr+2] shl 8;
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, {'offset '+}Labels^[LabelNo], p); r:=true; end;
if not r then Replace(s, {'offset L'}'L'+Hex4(ad), p);
end;
end;
end;
'#' : begin
Inc(ILength, 1);
Replace(s, GetByte(iptr+1), p);
if IndexNo>0 then Inc(iptr);
end;
'&' : begin
ad:=PrgMem^[iptr+1]+PrgMem^[iptr+2] shl 8;
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, Labels^[LabelNo], p); r:=true; end;
if not r then Replace(s, 'L'+Hex4(ad), p);
Inc(ILength, 2);
end;
'?' : begin
ad:=iptr+shortint(PrgMem^[iptr+1])+2;
Inc(ILength, 1);
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, Labels^[LabelNo], p); r:=true; end;
if not r then Replace(s, 'L'+Hex4(ad), p);
end;
'%' : begin
ad:=PrgMem^[iptr+1]+PrgMem^[iptr+2] shl 8;
Inc(ILength, 2);
r:=False;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Replace(s, Labels^[LabelNo], p); r:=true; end;
if not r and ((ad>PrgBegin+PrgLength) or (ad<PrgBegin)) then begin Replace(s, DataWord(ad), p);r:=true end;
if not r then
if (PrgMem^[iptr] in [$3A,$32])
then begin Insert('byte ptr ',s,p-3); Replace(s, 'L'+Hex4(ad), p+9); end
else begin Insert('word ptr ',s,p-3); Replace(s, 'L'+Hex4(ad), p+9); end;
end;
'~' : if IndexNo>0 then
begin
Replace(s,IndexVar8[IndexNo],p);
Inc(ILength);
end{ else Replace(s, '[bx]', p)};
'"' : Replace(s, SegName[SegmentNo],p);
'`' : Replace(s, DAAval[SegmentNo],p);
'|' : begin
Replace(s,Index(IndexOfs),p);
end;
'^' : if IndexNo>0 then
begin
Replace(s, IndexName[IndexNo], p);
end {else Replace(s, 'bx', p)};
'!' : if FirstZ80 then begin
Remark:=RemEnable;
RemarkDec:=false;
case PrgMem^[iptr] of
{EXXA} $08 : begin
LongCodeS:='push/h\push/psw\lhld/AF\xthl\shld/AF\pop/psw\pop/h';
LongCodeWork;
end;
{DJNZ} $10 : begin
LongCodeS:='push/psw\dcr/b\jz/$+7\pop/psw\jmp/?\pop/psw';
LongCodeWork;
end;
$18 : s:='jmp/?';
$20 : s:='jnz/?';
$28 : s:='jz/?';
$30 : s:='jnc/?';
$38 : s:='jc/?';
$CB : begin
RemarkDec:=true;
Inc(ILength); Inc(iptr);
if IndexNo>0 then s:=InstrCB8088[PrgMem^[iptr+1]]
else s:=InstrCB8088[PrgMem^[iptr]];
LongCodeS:=s; LongCodeWork;
end;
{EXX} $D9 : begin
LongCodeS:='push/h\lhld/DE\xchg\shld/DE\push/b\lhld/BC\xthl\shld/BC\pop/B\lhld/HL\xthl\shld/HL\pop/h';
LongCodeWork;
end;
$ED : begin
RemarkDec:=true;
Inc(ILength); Inc(iptr);
iptrPM:=PrgMem^[iptr];
if iptrPM<$40 then s:='nop/nop' else
if iptrPM<$80 then s:=InstrED8088_2[iptrPM-$40] else
if iptrPM<$A0 then s:='nop/nop' else
if iptrPM<$BC then s:=InstrED8088_4[iptrPM-$A0] else
s:='nop/nop';
LongCodeS:=s; LongCodeWork;
end;
$DD : begin
RemarkDec:=true;
Inc(ILength); Inc(iptr); IndexNo:=1;
iptrPM:=PrgMem^[iptr];
if iptrPM<$40 then s:=InstrDD8088_1[iptrPM] else
if iptrPM<$80 then s:=InstrDD8088_2[iptrPM-$40] else
if iptrPM<$C0 then s:=InstrDD8088_3[iptrPM-$80] else
if iptrPM<$FA then s:=InstrDD8088_4[iptrPM-$C0] else
s:='!';
IndexOfs:=shortint(PrgMem^[iptr+1]);
LongCodeS:=s; LongCodeWork;
end;
$FD : begin
RemarkDec:=true;
Inc(ILength); Inc(iptr); IndexNo:=2;
iptrPM:=PrgMem^[iptr];
if iptrPM<$40 then s:=InstrDD8088_1[iptrPM] else
if iptrPM<$80 then s:=InstrDD8088_2[iptrPM-$40] else
if iptrPM<$C0 then s:=InstrDD8088_3[iptrPM-$80] else
if iptrPM<$FA then s:=InstrDD8088_4[iptrPM-$C0] else
s:='!';
IndexOfs:=shortint(PrgMem^[iptr+1]);
LongCodeS:=s; LongCodeWork;
end
else
Replace(s, '.db'+Space(InterSize)+GetByte(iptr)+Space(InterSize)+'; Bad opcode', p)
end
end
else begin
if UndoCode then if PrgMem^[iptr] in [$08,$10,$18,$20,$28,$30,$38] then s:='nop' else
if PrgMem^[iptr]=$CB then s:='jmp/&' else
if PrgMem^[iptr]=$D9 then s:='ret' else
if PrgMem^[iptr] in [$DD,$ED,$FD] then s:='call/&';
if Type8085 then if PrgMem^[iptr]=$20 then s:='rim' else
if PrgMem^[iptr]=$30 then s:='sim';
if s='!' then Replace(s, '.db'+Space(InterSize)+GetByte(iptr)+Space(InterSize)+'; Bad opcode', p);
end;
end;
{ if KeyPressed then a:=ReadKey;}
until (a=#27) or (p=0);
Instruction:=s;
end;
function ByteBlock:string;
var s:string;Done:boolean;i:byte;w,l:word;
begin
Done:=False;w:=iptr;s:='';i:=0;
repeat
s:=s+DataByte(PrgMem^[w]); Inc(w); Inc(i);
l:=ShadowH^[w] shl 8+ShadowL^[w];
if (ShadowH^[w]<>$40) or (l and $3FFF>$0) or (i>SizeDB-1) or (DataBlock) then Done:=True else if i<SizeDB then s:=s+',';
if not Done then Inc(ILength);
until Done;
ByteBlock:='.db'+Space(InterSize)+s;
end;
function WordBlock:string;
begin
Inc(ILength);
WordBlock:='.dw'+Space(InterSize)+DataWord(PrgMem^[iptr]+PrgMem^[iptr+1] shl 8);
end;
function Address:string;
begin
Inc(ILength);
ad:=PrgMem^[iptr]+PrgMem^[iptr+1] shl 8;
if (ad>=PLow) and (ad<=PHigh) then
if LabelExist(ad)
then begin Address:='.dw'+Space(InterSize)+{'offset '+}Labels^[LabelNo]; Exit end;
Address:='.dw'+Space(InterSize)+{'offset }'L'+Hex4(ad);
end;
var s:string;
begin
if not LongCode then begin
iptr:=addr;
ILength:=1;
LabelShow:=true;
end else LabelShow:=false;
LNo:=(ShadowH^[addr] and $7) shl 8+ShadowL^[addr];
dt:=ShadowH^[addr] shr 6;{only 2 high bits}
lb:=(ShadowH^[addr] shr 4) and $3;
case dt of
00 : s:=Instruction;
01 : s:=ByteBlock;
02 : s:=WordBlock;
03 : s:=Address;
end;
if LNo>0 then s:=Labels^[LNo]+':'+Space(TabSize-Length(Labels^[LNo])-1)+s
else if (ShadowH^[addr] and $10>0) and LabelShow
then s:='L'+Hex4(addr)+':'+Space(TabSize-6)+s
else s:=Space(TabSize)+s;
while Length(s)<26 do s:=s+' ';
if Remark then begin
push1:=ILength;
push2:=IndexNo;
push3:=IndexOfs;
push4:=SegmentNo;
{ push5:=iptr;}
if RemarkDec then Dec(iptr);
s:=s+'; '+DisasmZ80(iptr);
Remark:=false;
{ iptr:=push5;}
SegmentNo:=push4;
IndexOfs:=push3;
IndexNo:=push2;
ILength:=push1;
end
else if (RemEnable) and (RemLast) then s:=s+'; ';
RemLast:=LongCode;
while Length(s)<46 do s:=s+' ';
DisAsm8088:=s;
end;
function DisAsm(addr: word): string;
begin
if Z80 then DisAsm := DisAsmZ80(addr) else DisAsm := DisAsm8088(addr);
end;
{======================================================================}
procedure SetTinyLabel(addr:word);{1-code, 2-data, 3-table }
var l:word;
begin
if (addr<PLow) or (addr>PHigh) then Exit;
l:=ShadowH^[addr] shr 8+ShadowL^[addr];
if l and $1FFF=0 then
begin
ShadowH^[addr]:=ShadowH^[addr] or $10;
Inc(TinyLabels);
WriteTo('Tiny labels : '+Hex4(TinyLabels),58,18,$30);
end;
end;
procedure ScanProc(addr:word);
var ip,w:word;Done:boolean;b,st:byte;IL,l:byte;i:integer;
procedure AddNewProc(addr:word);
var i:integer;
begin
if BIOSenabled and (addr<=BIOShigh) then Exit;
if (addr<PrgBegin) or (addr>PrgBegin+PrgLength) then
begin
WriteTo('Call beyond program area: '+Hex4(addr),49,6,$1F);
WriteTo('at '+Hex4(ip)+': (A)bort or (I)gnore? ',49,7,$1F);
repeat
case upCase(readkey) of
'A' : halt(2000);
'I' : begin
WriteTo(Strg(' ',30),49,6,$30);
WriteTo(Strg(' ',30),49,7,$30);
Exit;
end;
end;
until false;
end;
for i:=1 to TotalProcs+1 do
if (i<=TotalProcs) and (Proc[i]=addr) then
begin
break
end;
if i>TotalProcs then
begin
Inc(TotalProcs); Proc[TotalProcs]:=addr;
Inc(ProcNum); ProcQ[ProcNum]:=addr;
WriteTo('Entry points : '+Hex4(TotalProcs),58,17,$30);
end;
end;
begin
Done:=False;
ip:=addr;
repeat
b:=Stat[PrgMem^[ip]]; IL:=1;
ShadowH^[ip]:=ShadowH^[ip] and $3F;
st:=b shr 4; l:=b and 7;
Inc(IL, l);
case st of
0 : {ordinary command};
3 : {(HL)-oriented command};
1,2,10 :
begin {Load reg16, data }
w:=PrgMem^[ip+1]+PrgMem^[ip+2] shl 8;
if (w>=PLow) and (w<=PHigh) then
begin
SetTinyLabel(w);
ShadowH^[ip+1]:=ShadowH^[ip+1] or $C0;
ShadowH^[ip+2]:=ShadowH^[ip+2] or $C0;
end;
end;
5 : begin {CB prefix}
Inc(IL);
end;
6 : begin {ED prefix}
Inc(ip);
b:=StatED[PrgMem^[ip]];
Inc(IL, b and 7);
end;
7,8 : begin {DD,FD-prefix}
if PrgMem^[ip+1]=$CB then
begin
ShadowH^[ip+1]:=ShadowH^[ip+1] and $3F;
inc(IL,3);
end else
if Stat[PrgMem^[ip+1]] and $F0=$30 then
begin
Inc(IL,Stat[PrgMem^[ip+1]] and $7);
Inc(IL,2);
end;
end;
11 : begin {JR}
w:=ip+shortint(PrgMem^[ip+1])+2;
SetTinyLabel(w);
AddNewProc(w);
Done:=True;
end;
12 : begin {JR conditional}
w:=ip+shortint(PrgMem^[ip+1])+2;
SetTinyLabel(w);
AddNewProc(w);
end;
9 : begin {JP}
w:=PrgMem^[ip+1]+PrgMem^[ip+2] shl 8;
SetTinyLabel(w);
AddNewProc(w);
Done:=True;
end;
14 : begin {call}
w:=PrgMem^[ip+1]+PrgMem^[ip+2] shl 8;
for i:=1 to 10 do
if GreedCall[i]=w then
begin
Done:=True;
end;
SetTinyLabel(w);
AddNewProc(w);
end;
13 : begin {JP conditional, CALL conditional }
w:=PrgMem^[ip+1]+PrgMem^[ip+2] shl 8;
SetTinyLabel(w);
AddNewProc(w);
end;
15 : begin {RET or JP (HL)}
Done:=True;
end;
else Halt(3000)
end;
Inc(ip, IL);
if not ((ip>=PLow) or (ip<=PHigh)) then Done:=True;
until Done;
end;
procedure Scan(addr:word);
var cp:word;i:integer;
begin
WriteTo('[Scanning area]',60,16,$3F);
SetTinyLabel(addr);
ProcNum:=0;
Inc(ProcNum); ProcQ[ProcNum]:=addr;
while ProcNum>0 do
begin
cp:=ProcQ[1];
if ProcNum>1 then
begin
for i:=2 to ProcNum do ProcQ[i-1]:=ProcQ[i];
ProcQ[i]:=0;
end;
Dec(ProcNum);
ScanProc(cp);
end;
WriteTo(Strng(15,'Í'),60,16,$3F);
end;
{======================================================================}
procedure TypeError(No:word);
var attr:byte;
begin
case No of
0 : attr:=$33;
1..31 : attr:=$44;
50 : attr:=$55;
else attr:=$11;
end;
case No of {0-must ne free}
1 : SetError('Bad header in WorkFile!', $4C);
2 : SetError('Error while rewrite WorkFile!', $4C);
3 : SetError('Error while write WorkFile!', $4C);
4 : SetError('Error while read WorkFile!', $4C);
5 : SetError('Such WorkFile does not exist!', $4C);
6 : SetError('Bad WorkFile contents!', $4C);
10 : SetError('Can''t make ASM file!', $4C);
11 : SetError('Can''t write to ASM file!', $4C);
29 : SetError('Label not found!', $4C);
32 : SetError('Search string not found!', $1B);
33 : SetError('CodeSeg bit not found!', $4C);
40 : SetError('WorkFile saved normally!', $1B);
41 : SetError('WorkFile loaded OK!', $1B);
50 : SetError('ASM file saved OK!', $5F);
53 : SetError('ASM file saving aborted.', $4B);
58 : SetError('SYM file loaded.', $1B);
59 : SetError('CTL file loaded.', $1B);
60 : SetError('Can''t open SYM file.', $1B);
61 : SetError('Can''t open CTL file.', $1B);
100: SetError('Real Data Offsets OFF', $1B);
101: SetError('Real Data Offsets ON', $1B);
102: SetError('Type processor i8085 OFF', $1B);
103: SetError('Type processor i8085 ON', $1B);
(* 104: SetError('Using undocument code OFF', $1B);
105: SetError('Using undocument code ON', $1B);*)
106: SetError('Comment Z80 code OFF', $1B);
107: SetError('Comment Z80 code ON', $1B);
end;
ErrorLine:=7;
end;
procedure LoadFile;
var i,p,l:byte; tf:file;
code :integer;
begin
if ParamCount<1 then Halt(1);
FileName:=ParamStr(1);
Assign(f, FileName); ReSet(f, 1); if IOresult>0 then Halt(2);
if ParamCount=1 then begin
BlockRead(f, PrgType, 2);
BlockRead(f, PrgStart, 2);
Z80:=True;
if PrgType=$4241 then begin
if FileSize(f)>16384 then PrgLength:=32768 else PrgLength:=16384;
PrgBegin:=PrgStart and $C000;
end else begin
PrgLength:=FileSize(f);
PrgBegin:=0;
PrgStart:=PrgBegin;
end;
end
else
if ParamCount=2 then begin
Z80:=true;
if ParamStr(2)='/m' then begin
if FileSize(f)>16384 then PrgLength:=32768 else PrgLength:=16384;
PrgBegin:=$C000;
PrgStart:=PrgBegin;
end else begin
PrgLength:=FileSize(f);
Val(Copy(ParamStr(2),1,Length(ParamStr(2))),PrgBegin,Code);
PrgStart:=PrgBegin;
end;
end
else
if ParamCount=3 then begin
if ParamStr(3)='/m' then begin
Z80:=true;
if FileSize(f)>16384 then PrgLength:=32768 else PrgLength:=16384;
end else
if ParamStr(3)='/i' then begin
Z80:=false;
PrgLength:=FileSize(f);
end;
Val(Copy(ParamStr(2),1,Length(ParamStr(2))),PrgBegin,Code);
PrgStart:=PrgBegin;
end
else Halt(1);
FirstZ80:=Z80;
Seek(f, 0);
BlockRead(f, PrgMem^[PrgBegin], PrgLength);
Close(f);
PLow:=PrgBegin; PHigh:=PrgBegin+PrgLength;
PrgData:=$E000;
p:=0;l:=0;
for i:=1 to Length(FileName) do
begin
FileName[i]:=UpCase(FileName[i]);
if FileName[i]='.' then p:=i;
if (FileName[i] in ['A'..'Z','0'..'9','-']) and (l=0) then l:=i;
if FileName[i]='\' then l:=0;
end;
Delete(FileName,p+1,3);
Delete(FileName,1,l-1);
Assign(tf, FileName+'WRK'); Reset(tf,1);
if IOresult=0 then begin ldw:=True; Close(tf); end else ldw:=False;
if IOresult>0 then ;
end;
procedure MakeCode(w1, w2: word);
var (*w1, w2:word;*) i:longint;
begin
(* w1:=RealPos; w2:=RealPos;
if not EnterRange(w1, w2) then Exit;*)
for i:=0 to (w2-w1) do
ShadowH^[w1+i]:=$00 or (ShadowH^[w1+i] and $3F);
end;
procedure MakeData(w1, w2: word);
var (*w1, w2:word;*) i:longint;
begin
(* w1:=RealPos; w2:=RealPos;
if not EnterRange(w1, w2) then Exit;*)
for i:=0 to (w2-w1) do
ShadowH^[w1+i]:=$40 or (ShadowH^[w1+i] and $3F);
end;
procedure MakeWord(w1, w2: word);
var (*w1, w2:word;*) i:longint;
begin
(* w1:=RealPos; w2:=RealPos;
if not EnterRange(w1, w2) then Exit;*)
for i:=0 to (w2-w1) do
ShadowH^[w1+i]:=$80 or (ShadowH^[w1+i] and $3F);
end;
procedure MakeAddress(w1, w2: word);
var (*w1, w2:word;*) i:longint;
begin
(* w1:=RealPos; w2:=RealPos;
if not EnterRange(w1, w2) then Exit;*)