-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmDisassembly.pas
2211 lines (1976 loc) · 52.7 KB
/
frmDisassembly.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
{
Grundy NewBrain Emulator Pro Made by Despsoft
Copyright (c) 2004, Despoinidis Chris
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON A
NY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
unit frmDisassembly;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, ExtDlgs, Buttons, Tabs, DockTabSet,
OoMisc, AdPort, ADTrmEmu;
Const
cLnSpace=0;
unitname='NEWBRAIN INTERNAL ASSEMBLER / DISASSEMBLER';
type
TInstr=Record
Addr:Integer;
Nob:SmallInt; //no of bytes 1,2,3
Bytes:Array[1..4] of byte;
Instr:String[16];
Comments:String[128];
CommentsPre:String[9];
end;
PInstr=^TInstr;
TInstrList=Class(TList)
private
Procedure New;
protected
function GetInstr(Index: Integer): pInstr;
procedure PutInstr(Index: Integer; Item: PInstr);
public
procedure Clear; override;
Function GetInstrIdxFromAddr(Addr:Integer):Integer;
property Instr[Index: Integer]: pInstr read GetInstr write PutInstr; default;
end;
Tfrmdis = class(TForm)
PageControl1: TPageControl;
TSDis: TTabSheet;
Panel2: TPanel;
pbShow: TPaintBox;
ScrollBar1: TScrollBar;
TSAsm: TTabSheet;
Panel4: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
OpenTextFileDialog1: TOpenTextFileDialog;
SaveTextFileDialog1: TSaveTextFileDialog;
SpeedButton3: TSpeedButton;
PageControl2: TPageControl;
TSSource: TTabSheet;
asmText: TMemo;
TSBinary: TTabSheet;
BinText: TMemo;
TSSymbols: TTabSheet;
memLabels: TMemo;
TSMessages: TTabSheet;
memMessages: TMemo;
StatusBar1: TStatusBar;
Panel3: TPanel;
PbData: TPaintBox;
ScrollBar2: TScrollBar;
Splitter1: TSplitter;
Panel1: TPanel;
Label6: TLabel;
lblCombo: TComboBox;
lblEdit: TEdit;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
TSErrors: TTabSheet;
memErrors: TMemo;
SaveBinFileDialog: TSaveTextFileDialog;
Bevel1: TBevel;
Bevel2: TBevel;
Panel5: TPanel;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Edit4: TEdit;
Panel6: TPanel;
Label3: TLabel;
cbpAGES: TComboBox;
Label1: TLabel;
edStAddr: TEdit;
Label2: TLabel;
edLines: TEdit;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
Label7: TLabel;
edPgLen: TEdit;
DockTabSet1: TDockTabSet;
DockPanel: TPanel;
TSGlob: TTabSheet;
GlobLabels: TMemo;
TSProj: TTabSheet;
ProjText: TMemo;
Bevel3: TBevel;
SpeedButton10: TSpeedButton;
CheckBox1: TCheckBox;
TabSheet1: TTabSheet;
AdTerminal1: TAdTerminal;
ApdComPort1: TApdComPort;
Button1: TButton;
ProgressBar1: TProgressBar;
Edit1: TEdit;
Label8: TLabel;
Label9: TLabel;
Button2: TButton;
Edit2: TEdit;
Button3: TButton;
cominfolabel: TLabel;
TrackBar1: TTrackBar;
Edit5: TEdit;
Button4: TButton;
CheckBox2: TCheckBox;
Button5: TButton;
OpenTextFileDialog2: TOpenTextFileDialog;
Label10: TLabel;
Label11: TLabel;
Button6: TButton;
ListBox1: TListBox;
SpeedButton11: TSpeedButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Shape1: TShape;
Shape2: TShape;
Timer1: TTimer;
Label12: TLabel;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Edit6: TEdit;
Edit7: TEdit;
procedure asmTextKeyPress(Sender: TObject; var Key: Char);
procedure asmTextMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure BinTextKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure cbpAGESChange(Sender: TObject);
procedure DockPanelDockDrop(Sender: TObject; Source: TDragDockObject; X, Y:
Integer);
procedure DockPanelUnDock(Sender: TObject; Client: TControl; NewTarget:
TWinControl; var Allow: Boolean);
procedure DockTabSet1DockOver(Sender: TObject; Source: TDragDockObject; X, Y:
Integer; State: TDragState; var Accept: Boolean);
procedure DoDisassembly;
procedure DoDisAsmPrint;
procedure DoDisasmData;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta:
Integer; MousePos: TPoint; var Handled: Boolean);
procedure lblComboChange(Sender: TObject);
procedure PageControl2Change(Sender: TObject);
procedure PbDataMouseDown(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
procedure PbDataPaint(Sender: TObject);
procedure pbShowClick(Sender: TObject);
procedure pbShowDblClick(Sender: TObject);
procedure pbShowMouseDown(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
procedure pbShowPaint(Sender: TObject);
procedure ScrollBar1Change(Sender: TObject);
procedure ScrollBar2Change(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure StatusBar1DblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure ApdComPort1TriggerAvail(CP: TObject; Count: Word);
procedure SpeedButton11Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure ApdComPort1TriggerModemStatus(Sender: TObject);
procedure ApdComPort1TriggerStatus(CP: TObject; TriggerHandle: Word);
procedure ApdComPort1TriggerTimer(CP: TObject; TriggerHandle: Word);
procedure ApdComPort1PortOpen(Sender: TObject);
procedure ApdComPort1PortClose(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure SpeedButton10Click(Sender: TObject);
private
cx,cy:Integer;
ActMem:TMemo;
ChrX: Integer;
ChrY: Integer;
CommentsChanged: Boolean;
CurFile: string;
DatAddr: Integer;
DataLineBytes: Integer;
DataTopMargin: Integer;
DataVisLines: Integer;
DataWidthBytes: Integer;
DatLen: Integer;
DatPage: Integer;
DatWid: Integer;
Errors: Integer;
fisNewfile: Boolean;
{ Private declarations }
PageNo: Integer;
nLen:Integer;
TotalInstr:Integer;
SelectedLine:Integer;
SelPage: Integer;
procedure DoAftCompile(Sender: TObject; Fname: String);
procedure DoBefCompile(Sender: TObject; Fname: String);
procedure CalcDataVals;
procedure CheckBreak(const pc: Word);
procedure PaintBreakPoints;
procedure AddRemoveBreakPoint(Addr: Integer);
procedure ShowCompErrors;
procedure SetSrcCurrentLine;
procedure DoCompMes(Sender: TObject; msg: String);
procedure ShowCompiledCode;
procedure DoData(Pg, Addr, Leng:Integer);
procedure SetPreComment(com: String);
procedure SetComment(com: String);
function GetDefaultName: String;
procedure PaintInstructions;
procedure Disassembly(PGn, Start, nLength: Integer);
function GetCompleteInstruction(no: Integer): String;
procedure LoadComments(CmnF: TFileName = ''; DestSl: TStringList=Nil);
function LS: Integer;
function PGETYFromLine(L: Integer): Integer;
function PTextHeight: Integer;
function PVisibleLines: Integer;
procedure SaveComments(CmnF: TFileName = '');
function SendChar(c: AnsiChar):boolean;
procedure DoDisAsmPrintToFile;
procedure checkModemStatus;
function DsrReady: boolean;
public
function IsProject: Boolean;
{ Public declarations }
end;
TBreakPointList=Class(TstringList);
Procedure ShowDisassembler;
var
frmdis: Tfrmdis;
Instructions:TInstrList;
BreakPList:TBreakPointList;
implementation
uses unbMemory,ustrings,uDisAsm,math,Printers,uAsm,uNBTypes, New, frmCPUWin,
frmOSWin,uAsmPrj;
{$R *.dfm}
Procedure ShowDisassembler;
Begin
frmdis:= Tfrmdis.create(nil);
frmdis.Show;
end;
procedure Tfrmdis.ApdComPort1PortClose(Sender: TObject);
begin
checkModemStatus;
end;
procedure Tfrmdis.checkModemStatus;
begin
if ApdComPort1.DTR then
SHAPE1.Brush.Color:=clGreen
else
SHAPE1.Brush.Color:=clRed;
if ApdComPort1.DSR then
SHAPE2.Brush.Color:=clGreen
else
SHAPE2.Brush.Color:=clRed;
End;
procedure Tfrmdis.ApdComPort1PortOpen(Sender: TObject);
begin
checkModemStatus
end;
procedure Tfrmdis.ApdComPort1TriggerAvail(CP: TObject; Count: Word);
VAR C:ansiCHAR;
k:integer;
begin
if button11.Tag=1 then exit;
if count=0 then exit;
try
c:= ApdComPort1.PeekChar(1);
k:=ord(c);
listbox1.Items.Add(inttostr(k))
except
end;
end;
procedure Tfrmdis.ApdComPort1TriggerModemStatus(Sender: TObject);
begin
checkModemStatus
end;
procedure Tfrmdis.ApdComPort1TriggerStatus(CP: TObject; TriggerHandle: Word);
begin
checkModemStatus
end;
procedure Tfrmdis.ApdComPort1TriggerTimer(CP: TObject; TriggerHandle: Word);
begin
checkModemStatus
end;
procedure Tfrmdis.asmTextKeyPress(Sender: TObject; var Key: Char);
begin
SetSrcCurrentLine;
end;
procedure Tfrmdis.asmTextMouseMove(Sender: TObject; Shift: TShiftState; X, Y:
Integer);
begin
SetSrcCurrentLine;
end;
Procedure Tfrmdis.Disassembly(PGn,Start,nLength:Integer);
const
aBit: array[1..4] of byte = ($80, $40, $20, $10);
Var Inst:Array[1..4] of byte;
CurAddr:Integer;
NewInstr:String;
Procedure Fill4;
Begin
if pgn<0 then
Begin
Inst[1]:=nbmem.GetRom(CurAddr);
Inst[2]:=nbmem.GetRom(CurAddr+1);
Inst[3]:=nbmem.GetRom(CurAddr+2);
Inst[4]:=nbmem.GetRom(CurAddr+3);
End
Else
Begin
Inst[1]:=nbmem.GetDirectMem(Pgn,CurAddr);
Inst[2]:=nbmem.GetDirectMem(Pgn,CurAddr+1);
Inst[3]:=nbmem.GetDirectMem(Pgn,CurAddr+2);
Inst[4]:=nbmem.GetDirectMem(Pgn,CurAddr+3);
End;
End;
Function GetCurrentInstr:Integer;//returns Inst Length
Var lFound:Boolean;
i,j,nIndex,npos:Integer;
cAux:String;
Begin
//Find Instruction
cAux := '';
for i := 1 to MAX_Z80_INSTR do
begin
with aZ80Instr[i] do
begin
lFound := true;
for j := 1 to nMask and $0F do
if (nMask and aBit[j])<>0 then
begin
if Inst[j]<>aInstr[j-1] then lFound := false;
end
else
begin
cAux := IntToHex(Inst[j], 2)+cAux; //New Byte Add
end; //if end
nIndex := i;
if lFound then
begin
break;
end;//if end
end;//with end
end;//for end
//Return Full Instruction
NewInstr:=aZ80Instr[nIndex].cInstr;
nPos := Pos('##', NewInstr); //Is there an address or number
if nPos<>0 then
begin
NewInstr[nPos+0] := cAux[1];
NewInstr[nPos+1] := cAux[2];
Delete(cAux, 1, 2);
nPos := Pos('##', NewInstr);
if nPos<>0 then
begin
NewInstr[nPos+0] := cAux[1];
NewInstr[nPos+1] := cAux[2];
end;//if end
end;//if end
Result:=(aZ80Instr[nIndex].nMask and $0F);
End; //Function End
Var nbt,i:Integer;
Begin
CurAddr:=Start;
TotalInstr:=1;
Repeat
//Get 4 bytes
Fill4;
nbt:=GetCurrentInstr;
Instructions.New;
Instructions.Instr[TotalInstr].Addr:=CurAddr;
Instructions.Instr[TotalInstr].Nob:=nbt;
for i := 1 to nbt do
Instructions.Instr[TotalInstr].Bytes[i]:=Inst[i];
Instructions.Instr[TotalInstr].Instr:=NewInstr;
CurAddr:=CurAddr+nbt;
if (CurAddr-Start)>nLength then Break;
if curaddr>65535 then Break;
Inc(TotalInstr);
until False;
end;
function Tfrmdis.GetCompleteInstruction(no:Integer):String;
Var i:Integer;
Begin
//Addr
Result:=InttoHex(Instructions[no].Addr,4)+' ';
//Bytes
for i := 1 to Instructions[no].Nob do
Result:=Result+inttohex(Instructions[no].Bytes[i],2)+' ';
for i := Instructions[no].Nob to 5 do
Result:=Result+' ';
//Characters
for i := 1 to Instructions[no].Nob do
if Instructions[no].Bytes[i]>31 then
Result:=Result+chr(Instructions[no].Bytes[i])
Else
Result:=Result+'.';
for i := Instructions[no].Nob to 5 do
Result:=Result+' ';
// Labels
Result:=Result+Instructions[no].CommentsPre;
for i := Length(Instructions[no].CommentsPre) to 9 do
Result:=Result+' ';
//Instruction
Result:=Result+' ';
Result:=Result+Instructions[no].Instr;
for i := Length(Instructions[no].Instr) to 20 do
Result:=Result+' ';
//Comments
Result:=Result+'; ';
Result:=Result+Instructions[no].Comments;
end;
procedure Tfrmdis.DoDisassembly;
Var stad,le:integer;
Begin
if CommentsChanged then
SaveComments;
Instructions.Clear;TotalInstr:=0;
if not GetValidInteger(edStAddr.text,stad) then
GetValidInteger(edStAddr.text+'H',stad);
if not GetValidInteger(edLines.text,le) then
GetValidInteger(edLines.text+'H',le);
// if SelPage=-1 then
// le:=65535-stad
// Else
// le:=nbmem.GetPageLength(SelPage)-stad;
Disassembly(SelPage,stad,le);
Scrollbar1.SetParams(1,1,TotalInstr-PVisibleLines+5);
LoadComments;
pbShow.Repaint;
end;
procedure Tfrmdis.Edit1Change(Sender: TObject);
begin
edit1.Hint:=inttohex(strtoint(edit1.Text),4)+'h';
end;
procedure Tfrmdis.DoDisAsmPrint;
Var i:Integer;
MAxy,y,spc:Integer;
lh:Integer;
Header:String;
TopMargin:Integer;
TotalLines:Integer;
Procedure SetBW;
Begin
printer.Canvas.Brush.Color:=clWhite;
printer.Canvas.Font.Color:=clBlack;
End;
Procedure SetWB;
Begin
printer.Canvas.Brush.Color:=clBlack;
printer.Canvas.Font.Color:=clWhite;
End;
begin
header:='ADDR BYTES ASCII LABELS ASM COMMENTS ';
try
MAxy:=strtoint(edit3.text);
Except
Maxy:=70;
End;
try
spc:=strtoint(edit4.text);
Except
spc:=15;
End;
TopMargin:=40;
y:=1;
Printer.Canvas.Font.Name:='Courier New';
lh:=Printer.canvas.TextHeight('oOoO');
TotalLines:=(Printer.PageHeight-TopMargin) div (lh+spc);
TotalLines:=TotalLines-1;
MaxY:=Min(MAxY, TotalLines);
Edit3.Text:=inttostr(MaxY);
Printer.Title:=unitname+' '+ DateTimeToStr(Now);
Printer.BeginDoc;
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),Printer.Title);
inc(y);
inc(y);
If Pageno<>-1 then
Begin
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),'Page NO:'+inttostr(Pageno));
inc(y);
End
Else
Begin
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),'Starting Address : $'+EdStAddr.text+' ('+Inttostr(HexToInt(EdStAddr.text))+')');
inc(y);
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),'Length Instruct. : $'+InttoHex(TotalInstr,4)+' ('+Inttostr(TotalInstr)+')');
inc(y);
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),'Length Bytes : $'+InttoHex(Strtoint(edLines.text),4)+' ('+edLines.Text+')');
inc(y);
End;
inc(y);
SetWB;
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),Header);
SetBW;
inc(y);
For i:=1 to TotalInstr do
Begin
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),{inttostr(Y)+'. '+}GetCompleteInstruction(i));
if y>=maxy then
Begin
Printer.NewPage;
y:=1;
SetWB;
printer.Canvas.TextOut(40,TopMargin+y*(lh+spc),Header);
SetBW;
End;
inc(y);
End;
Printer.enddoc;
end;
procedure Tfrmdis.DoDisAsmPrintToFile;
Var i:Integer;
y:Integer;
Header:String;
f:TextFile;
fname:string;
begin
header:='ADDR BYTES ASCII LABELS ASM COMMENTS ';
fname:='DisAsmPrint.txt';
assignFile(f,fname);
if fileexists(fname) then
ShowMessage('File '+fname+' will be rewritten.');
Rewrite(f);
WriteLn(f,DateTimeToStr(Now));
WriteLn(f,'');
WriteLn(f,'Starting Address : $'+EdStAddr.text+' ('+Inttostr(HexToInt(EdStAddr.text))+')');
WriteLn(f,'Length Instruct. : $'+InttoHex(TotalInstr,4)+' ('+Inttostr(TotalInstr)+')');
WriteLn(f,'Length Bytes : $'+InttoHex(Strtoint(edLines.text),4)+' ('+edLines.Text+')');
WriteLn(f,'');
WriteLn(f,Header);
WriteLn(f,'');
y:=1;
For i:=1 to TotalInstr do
Begin
WriteLn(f,GetCompleteInstruction(i));
if y>=40 then
Begin
y:=0;
WriteLn(f,'');
WriteLn(f,'');
WriteLn(f,Header);
WriteLn(f,'');
End;
inc(y);
End;
Closefile(f);
end;
procedure Tfrmdis.DoData(Pg,Addr,Leng:Integer);
Begin
DatPage:=Pg;
DatAddr:=Addr;
if SelPage=-1 then
DatLen:=65535-Addr
Else
DatLen:=nbmem.GetPageLength(SelPage)-Addr;
end;
procedure Tfrmdis.DoDisasmData;
Var stad,le:Integer;
begin
if not getValidInteger(edStAddr.text,stad) then
getValidInteger(edStAddr.text+'H',stad);
if not getValidInteger(edLines.text,le)then
getValidInteger(edLines.text+'H',le);
DoData(SelPage,stad,le);
if DatLen<=0 then
begin
showmessage('Error in offset please retry');
exit;
end;
try
Scrollbar2.SetParams(1,1,DatLen);
except
Scrollbar2.SetParams(1,1,1000);
end;
pbData.Repaint;
end;
procedure Tfrmdis.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if CommentsChanged then
SaveComments;
fCPUWin.Tag:=9;
fCPUWin.Close;
fCPUWin.free;
fCPUWin:=nil;
ApdComPort1.Open:=false;
end;
procedure Tfrmdis.FormCreate(Sender: TObject);
Var i:integer;
begin
AdTerminal1.ScrollbackRows:=2000;
label9.Font.Color:=clBlue;
PageNo:=-1;
nLen := 0;
DatPage:=-2;
cbpages.items.Clear;
cbpages.items.Add('-1_NoPaging');
for i:=0 to 255 do
if nbmem.NBPages[i]<>nil then
cbpages.items.Add(Inttostr(nbmem.NBPages[i]^.Page)+'_'+nbmem.NBPages[i]^.Name);
cbpages.ItemIndex:=0;
cbPagesChange(nil);
CommentsChanged:=False;
DoubleBuffered:=true;
PageControl1.DoubleBuffered:=true;
PageControl2.DoubleBuffered:=true;
panel2.DoubleBuffered:=True;
panel3.DoubleBuffered:=True;
PageControl1.ActivePage:=TSDis;
PageControl2.ActivePage:=TSSource;
PageControl2Change(nil);
if not assigned(fCPUWin) then
fCPUWin:= TfCPUWin.create(nil);
fCPUWin.Show;
fCPUWin.Dock(DockTabSet1,Rect(0,0,10,10));
DockPanel.Width:=0;
if not assigned(fOSWin) then
fOSWin:= TfOSWin.create(nil);
fOSWin.show;
fOSWin.Dock(DockTabSet1,Rect(0,0,10,10));
try
ApdComPort1.Open:=true;
except
//may be same port opened by the emulator
end;
end;
procedure Tfrmdis.FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
Var mp:TPoint;
begin
mp:=screentoclient(MousePos);
if PageControl1.ActivePage=TSDis then
Begin
if MP.X<Panel3.Left then
Begin
if wheeldelta<0 then
Scrollbar1.Position:=Scrollbar1.Position+1;
if wheeldelta>0 then
Scrollbar1.Position:=Scrollbar1.Position-1;
pbShow.Repaint;
Handled:=true;
end
Else
Begin
if wheeldelta<0 then
Scrollbar2.Position:=Scrollbar2.Position+DatWid;
if wheeldelta>0 then
Scrollbar2.Position:=Scrollbar2.Position-DatWid;
pbData.Repaint;
Handled:=true;
end;
end;
end;
Function Tfrmdis.GetDefaultName:String;
Begin
Result:='';
if SelPage<>-1 then
Result:=Result+'PG_'+inttostr(SelPage)+'.dbg'
Else
Result:=Result+'NoPaging.dbg';
end;
procedure Tfrmdis.ListBox1DblClick(Sender: TObject);
begin
listbox1.Clear;
end;
procedure Tfrmdis.LoadComments(CmnF: TFileName = ''; DestSl: TStringList=Nil);
Var cf:TStringList;
i:Integer;
s,s1:String;
Begin
if CmnF='' then
CmnF:=GetDefaultName ;
if Not FileExists(AppPath+CmnF) and not assigned(DestSl) then
Begin
ShowMessage('Debug File '+AppPath+cmnf+' does not exists');
Exit;
end;
cf:=TStringList.Create;
try
cf.LoadFromFile(AppPath+Cmnf);
if Assigned(DestSl) then
Destsl.Assign(cf)
Else
For i:=1 to TotalInstr do
Begin
s:=cf.Values[Inttostr(Instructions[i].Addr)];
if s<>'' then
Instructions[i].Comments:=s;
s1:=cf.Values[Inttostr(Instructions[i].Addr)+'_LB'];
if s1<>'' then
Instructions[i].CommentsPre:=s1;
end;
finally
cf.free;
end;
if not assigned(Destsl) then
pbshow.Refresh;
end;
procedure Tfrmdis.PaintInstructions;
Var i,j:Integer;
s:String;
th:Integer;
TLn:Integer;
PS:Integer;
X,Y:Integer;
Canv:TCanvas;
OldColor:integer;
Procedure SetStyle(no:Byte);
Begin
pbShow.Canvas.Font.Style := [fsBold];
pbShow.Canvas.Font.Color:=clBlue;
End;
Procedure ResetStyle;
Begin
with pbShow.Canvas do begin
Brush.Style := BSSOLID;
Brush.Color := CLWHITE;
Font.Name := 'COURIER NEW';
Font.Style := [];
Font.Size := 8;
Font.Color:= clBlack;
Brush.Style := BSCLEAR;
Brush.Color := oldcolor;
End;
End;
Var st,header:String;
Begin
for i := 0 to 200 do
st:=st+' ';
header:='BP ADDR BYTES ASCII LABELS ASM COMMENTS ';
OldColor:=clWhite;
ResetStyle;
Canv:=pbShow.Canvas;
Canv.FillRect(pbShow.ClientRect);
th:= pTextHeight;
TLn:=PVisibleLines;
PS:=Scrollbar1.Position; //According to Scrollbar
TLn:=Min(TLn,TotalInstr-PS);
Canv.Brush.Color := clGreen;
Canv.Font.color:= clYellow;
Canv.Font.Style:=[fsBold];
Canv.TextOut(0,0,header);
ResetStyle;
for i := PS to PS+TLn do
Begin
if SelectedLine=i then
Canv.Brush.Color := CLYellow
Else
Canv.Brush.Color := CLWHITE;
OldColor:=Canv.Brush.Color;
// Y:=LS+(i-PS)*(th+cLnSpace);
y:=PGETYFromLine(i);
Canv.TextOut(0,Y,st);
X:=30;
// s:=GetCompleteInstruction(i);
s:=InttoHex(Instructions[i].Addr,4);
Canv.TextOut(X,Y,s);
X:=X+50;
s:='';
for j := 1 to Instructions[i].Nob do
s:=s+inttohex(Instructions[i].Bytes[j],2)+' ';
Canv.TextOut(X,Y,s);
X:=X+90;
s:='';
for j := 1 to Instructions[i].Nob do
if Instructions[i].Bytes[j]>31 then
s:=s+chr(Instructions[i].Bytes[j])
Else
s:=s+'.';
Canv.TextOut(X,Y,s);
X:=X+40;
s:=Instructions[i].CommentsPre;
if pos(':',s)>0 then
SetStyle(1);
Canv.TextOut(X,Y,s);
ResetStyle;
X:=X+70;
s:=Instructions[i].Instr;
Canv.TextOut(X,Y,s);
X:=X+100;
s:='; '+Instructions[i].Comments;
Canv.TextOut(X,Y,s);
end;
end;
procedure Tfrmdis.PbDataMouseDown(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
begin
ChrX:=X;ChrY:=Y;
pbData.Refresh;
end;
procedure Tfrmdis.CalcDataVals;
Var th,tw:Integer;
Canv:TCanvas;
Begin
Canv:=pbData.canvas;
Canv.Font.Name:='Courier';
Canv.Font.Height:=10;
th:= Canv.TextHeight('HWQ');
tw:= Canv.TextWidth('W');
DataVisLines:=pbData.Height div th;
DataWidthBytes:=pbData.Width div tw - 2;
DataLineBytes:=DataWidthBytes Div 3; //3 chars per byte
try
Scrollbar2.Max:=Round(DatLen / DataLineBytes) - Round(DataVisLines / 2)+2;
except
Scrollbar2.Max:=1000;
end;
end;
procedure Tfrmdis.PbDataPaint(Sender: TObject);
Var th,tw:Integer;
Canv:TCanvas;
i,j:Integer;
b:Byte;
bs,bchrs:String;
MyAddr:Integer;
LnVisDat:Integer;
LnChrSt:Integer;
Selected:Integer;
begin
if DatPage=-2 then
Exit;
Canv:=pbData.canvas;
CalcDataVals;
Canv.Font.Color:=clLime;
Canv.Brush.Color:=clBlack;
pbData.Color:=clBlack;
th:= Canv.TextHeight('HWQ');
tw:= Canv.TextWidth('W');
DataTopMargin:=1;
LnVisDat:=(DataVisLines - DataTopMargin) div 2;
LnChrSt:= LnVisDat * (th);
//MyAddr:=DatAddr+ScrollBar2.Position-1;
MyAddr:=DatAddr+(ScrollBar2.Position-1)*DataLineBytes;
DatWid:= 3; // for scrollbar2 Scroll 3 lines
Selected:=ChrY Div th-DataTopMargin;
if Selected>=LnVisDat then
Selected:=Selected-LnVisDat;
bs:='ADDR 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F';
bs:=Copy(bs,1,5+DataLineBytes*3);
Canv.Brush.Color := clGreen;
Canv.Font.color:= clYellow;
Canv.TextOut(2,0,bs);
Canv.Brush.Color := clWhite;
for j := 0 to LnVisDat - 1 do
Begin
bs:=inttohex(MyAddr,4)+' ';bchrs:=inttohex(MyAddr,4)+' ';
for i := 0 to DataLineBytes - 1 do
Begin