📄 dbgpliki.pas
字号:
unit DbgPliki;
interface
uses WinTypes;
procedure ZapiszBajty(Okno:HWnd;selektor,maxoffset:word);
procedure WczytajEPROM(Okno:HWnd);
procedure ZapiszEPROM(Okno:HWnd);
procedure WczytajEPROMhex(Okno:HWnd);
procedure ZapiszEPROMhex(Okno:HWnd);
procedure ZapiszEPROMDeasm(Okno:HWnd);
procedure WczytajRAM(Okno:HWnd);
procedure ZapiszRAM(Okno:HWnd);
procedure WczytajRAMhex(Okno:HWnd);
procedure ZapiszRAMhex(Okno:HWnd);
procedure WczytajRAMInt(Okno:HWnd);
procedure ZapiszRAMInt(Okno:HWnd);
procedure WczytajRAMInthex(Okno:HWnd);
procedure ZapiszRAMInthex(Okno:HWnd);
procedure SymbWczytaj(Okno:HWnd);
procedure SymbZapisz(Okno:HWnd);
procedure ZapiszRozm(Okno:HWnd);
procedure WczytajRozm(Okno:HWnd);
procedure WczytajPula(Okno:HWnd);
procedure ZapiszPula(Okno:HWnd);
procedure WczytajAutomat(Okno:HWnd;numer:byte);
procedure WczytajListePlikow;
procedure DodajDoListyPlikow(nazwa:PChar;typ:char);
procedure WyczyscListePlikow;
implementation
uses WinProcs, WinDOS, CommDlg, Strings, BWCC, DbgZmTypy, DbgAsm;
procedure ZapiszBajty(Okno:HWnd;selektor,maxoffset:word);
const DefExt = 'asm';
var
OpenFN:TOpenFileName;
Filter:array [0..23] of char;
FileName:array [0..255] of char;
Plik,linia:string;
txt:string[6];
Info:HWnd;
code,b:integer;
off,dlug:word;
d1:longint;
bajt:byte;
wy:text;
litera,nic:boolean;
begin
FillChar(FileName,256,#0);
FillChar(Filter,24,#0);
StrCopy(Filter,Napis1(83));
StrCopy(@Filter[StrLen(Filter)+1],'*.asm');
FillChar(OpenFN,SizeOf(TOpenFileName),#0);
with OpenFN do
begin
hInstance := HInstance;
hwndOwner := Okno;
lpstrDefExt := DefExt;
lpstrFile := FileName;
lpstrFilter := Filter;
lpstrFileTitle:= nil;
flags := ofn_PathMustExist or ofn_HideReadOnly or ofn_OverwritePrompt;
lStructSize := SizeOf(TOpenFileName);
nFilterIndex := 1;
nMaxFile := SizeOf(FileName);
end;
if not GetSaveFileName(OpenFN) then Exit else Plik:=StrPas(FileName);
b:=PokazDialog('OFFSET',@FunOffset);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,off,code);
if code<>0 then Exit;
if off>maxoffset then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(25),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
b:=PokazDialog('DLUGOSC',@FunDlugosc);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,dlug,code);
if code<>0 then Exit;
if dlug=0 then Exit;
if adrost then d1:=longint(dlug)+1-off else d1:=dlug;
Assign(wy,Plik);
{$I-} Rewrite(wy); {$I+}
if IOResult<>0 then Exit;
Info:=CreateDialog(hInstance,Dial('ZAPISUJE'),Okno,nil);
linia:=' db ';
litera:=false;
nic:=true;
repeat
bajt:=Mem[selektor:off];
if (bajt<32) or (bajt=39) or (bajt>126) then
begin
if litera then
begin
litera:=false;
txt:=#39','+StrFunW(bajt);
end else
begin
if nic then
begin
txt:=StrFunW(bajt);
nic:=false;
end
else txt:=','+StrFunW(bajt);
end
end else
if litera then txt:=char(bajt) else
begin
litera:=true;
if nic then
begin
txt:=#39+char(bajt);
nic:=false;
end else txt:=','#39+char(bajt);
end;
if off=maxoffset then d1:=0 else
begin
Inc(off);
Dec(d1);
end;
linia:=linia+txt;
if (Length(linia)>72) or (d1=0) then
begin
if litera then Writeln(wy,linia,#39) else Writeln(wy,linia);
linia:=' db ';
litera:=false;
nic:=true;
end;
until d1=0;
Close(wy);
DestroyWindow(Info);
OdrysujWszystkie;
end;
procedure WczytajAutoEPROM(Okno:HWnd;nazwa:PChar;dodac:boolean); forward;
procedure WczytajEPROM(Okno:HWnd);
const DefExt = 'bin';
var
OpenFN:TOpenFileName;
Filter:array [0..23] of char;
FileName:array [0..255] of char;
begin
FillChar(FileName,256,#0);
FillChar(Filter,24,#0);
StrCopy(Filter,Napis1(21));
StrCopy(@Filter[StrLen(Filter)+1],'*.bin');
FillChar(OpenFN,SizeOf(TOpenFileName),#0);
with OpenFN do
begin
hInstance := HInstance;
hwndOwner := Okno;
lpstrDefExt := DefExt;
lpstrFile := FileName;
lpstrFilter := Filter;
lpstrFileTitle:= nil;
flags := ofn_FileMustExist or ofn_HideReadOnly;
lStructSize := SizeOf(TOpenFileName);
nFilterIndex := 1;
nMaxFile := SizeOf(FileName);
end;
if not GetOpenFileName(OpenFN) then Exit;
WczytajAutoEPROM(Okno,FileName,true);
end;
procedure WczytajAutoEPROM(Okno:HWnd;nazwa:PChar;dodac:boolean);
var
Plik:string;
code,b:integer;
off:word;
Info:HWnd;
d1:longint;
we:file;
begin
Plik:=StrPas(nazwa);
b:=PokazDialog('OFFSET',@FunOffset);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,off,code);
if code<>0 then Exit;
Assign(we,Plik);
{$I-} Reset(we,1); {$I+}
if IOResult<>0 then Exit;
Info:=CreateDialog(hInstance,Dial('CZYTAM'),Okno,nil);
if longint(off)+FileSize(we)>65536 then d1:=65536-off else d1:=FileSize(we);
BlockRead(we,Mem[selROM:off],d1,code);
Close(we);
DestroyWindow(Info);
OdrysujWszystkie;
if dodac then DodajDoListyPlikow(nazwa,'E');
end;
procedure ZapiszEPROM(Okno:HWnd);
const DefExt = 'bin';
var
OpenFN:TOpenFileName;
Filter:array [0..23] of char;
FileName:array [0..255] of char;
Plik:string;
Info:HWnd;
code,b:integer;
off,dlug:word;
d1:longint;
bajt:byte;
wy:file;
begin
FillChar(FileName,256,#0);
FillChar(Filter,24,#0);
StrCopy(Filter,Napis1(21));
StrCopy(@Filter[StrLen(Filter)+1],'*.bin');
FillChar(OpenFN,SizeOf(TOpenFileName),#0);
with OpenFN do
begin
hInstance := HInstance;
hwndOwner := Okno;
lpstrDefExt := DefExt;
lpstrFile := FileName;
lpstrFilter := Filter;
lpstrFileTitle:= nil;
flags := ofn_PathMustExist or ofn_HideReadOnly or ofn_OverwritePrompt;
lStructSize := SizeOf(TOpenFileName);
nFilterIndex := 1;
nMaxFile := SizeOf(FileName);
end;
if not GetSaveFileName(OpenFN) then Exit else Plik:=StrPas(FileName);
b:=PokazDialog('OFFSET',@FunOffset);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,off,code);
if code<>0 then Exit;
b:=PokazDialog('DLUGOSC',@FunDlugosc);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,dlug,code);
if code<>0 then Exit;
if dlug=0 then Exit;
if adrost then dlug:=dlug-off+1;
Assign(wy,Plik);
{$I-} Rewrite(wy,1); {$I+}
if IOResult<>0 then Exit;
Info:=CreateDialog(hInstance,Dial('ZAPISUJE'),Okno,nil);
if longint(off)+dlug>65536 then d1:=65536-off else d1:=dlug;
BlockWrite(wy,Mem[selROM:off],d1,code);
Close(wy);
DestroyWindow(Info);
DodajDoListyPlikow(FileName,'E');
OdrysujWszystkie;
end;
procedure WczytajAutoEPROMhex(Okno:HWnd;nazwa:PChar;dodac:boolean); forward;
procedure WczytajEPROMhex(Okno:HWnd);
const DefExt = 'hex';
var
OpenFN:TOpenFileName;
Filter:array [0..23] of char;
FileName:array [0..255] of char;
begin
FillChar(FileName,256,0);
FillChar(Filter,24,0);
StrCopy(Filter,Napis1(22));
StrCopy(@Filter[StrLen(Filter)+1],'*.hex');
FillChar(OpenFN,SizeOf(TOpenFileName),0);
with OpenFN do
begin
hInstance := HInstance;
hwndOwner := Okno;
lpstrDefExt := DefExt;
lpstrFile := FileName;
lpstrFilter := Filter;
lpstrFileTitle:= nil;
flags := ofn_FileMustExist or ofn_HideReadOnly;
lStructSize := SizeOf(TOpenFileName);
nFilterIndex := 1;
nMaxFile := SizeOf(FileName);
end;
if not GetOpenFileName(OpenFN) then Exit;
WczytajAutoEPROMhex(Okno,FileName,true);
end;
procedure WczytajAutoEPROMhex(Okno:HWnd;nazwa:PChar;dodac:boolean);
var
Info:HWnd;
Plik,linia:string;
off,radr:word;
bajt,rlen,rtyp,x,n:byte;
we:text;
begin
Plik:=StrPas(nazwa);
Assign(we,Plik);
{$I-} Reset(we); {$I+}
if IOResult<>0 then Exit;
rtyp:=0;
off:=65535;
Info:=CreateDialog(hInstance,Dial('CZYTAM'),Okno,nil);
repeat
Readln(we,linia);
if linia[1]=':' then
begin
rlen:=HEXtoB(Copy(linia,2,2));
radr:=HEXtoW(Copy(linia,4,4));
rtyp:=HEXtoB(Copy(linia,8,2));
if off=65535 then off:=radr;
if rtyp=0 then
begin
x:=10;
for n:=1 to rlen do
begin
bajt:=HEXtoB(Copy(linia,x,2));
Mem[selROM:radr]:=bajt;
Inc(x,2);
Inc(radr);
end;
end;
end;
until (rtyp=1) or Eof(we);
Close(we);
DestroyWindow(Info);
OdrysujWszystkie;
if dodac then DodajDoListyPlikow(nazwa,'H');
end;
procedure ZapiszEPROMhex(Okno:HWnd);
const DefExt = 'hex';
var
OpenFN:TOpenFileName;
Filter:array [0..23] of char;
FileName:array [0..255] of char;
Plik:string;
linia:string[80];
Info:HWnd;
off,radr:word;
d1,dlug:longint;
b,code:integer;
rsum,rlen,n:byte;
wy:text;
begin
FillChar(FileName,256,#0);
FillChar(Filter,24,#0);
StrCopy(Filter,Napis1(22));
StrCopy(@Filter[StrLen(Filter)+1],'*.hex');
FillChar(OpenFN,SizeOf(TOpenFileName),#0);
with OpenFN do
begin
hInstance := HInstance;
hwndOwner := Okno;
lpstrDefExt := DefExt;
lpstrFile := FileName;
lpstrFilter := Filter;
lpstrFileTitle:= nil;
flags := ofn_PathMustExist or ofn_HideReadOnly or ofn_OverwritePrompt;
lStructSize := SizeOf(TOpenFileName);
nFilterIndex := 1;
nMaxFile := SizeOf(FileName);
end;
if not GetSaveFileName(OpenFN) then Exit else Plik:=StrPas(FileName);
b:=PokazDialog('OFFSET',@FunOffset);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,off,code);
if code<>0 then Exit;
b:=PokazDialog('DLUGOSC',@FunDlugosc);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,dlug,code);
if code<>0 then Exit;
if dlug=0 then Exit;
if adrost then dlug:=dlug-off+1;
Assign(wy,Plik);
{$I-} Rewrite(wy); {$I+}
if IOResult<>0 then Exit;
if longint(off)+dlug>65536 then d1:=65536-off else d1:=dlug;
Info:=CreateDialog(hInstance,Dial('ZAPISUJE'),Okno,nil);
radr:=off;
repeat
rsum:=0;
if d1>32 then rlen:=32 else rlen:=d1;
linia:=':'+BtoHEX(rlen)+WtoHEX(radr)+'00';
for n:=0 to rlen-1 do
begin
linia:=linia+BtoHEX(Mem[selROM:radr]);
rsum:=rsum+Mem[selROM:radr];
Inc(radr);
Dec(d1);
end;
linia:=linia+BtoHEX(byte(0)-rsum);
Writeln(wy,linia);
until d1=0;
Writeln(wy,':00000001FF');
Close(wy);
DestroyWindow(Info);
DodajDoListyPlikow(FileName,'H');
OdrysujWszystkie;
end;
procedure ZapiszEPROMdeasm(Okno:HWnd);
const DefExt = 'asm';
var
OpenFN:TOpenFileName;
Filter:array [0..23] of char;
FileName:array [0..255] of char;
Plik:String;
Info:HWnd;
adr,off,dlug,koniec,x,aktadresnr,ileadresow:word;
b,code:integer;
bajt,y,z:byte;
wy:text;
mnem,mnem1:KodRozk;
TablicaAdresow:PWordArr;
function JestTakiAdres(jaki:word):boolean;
var l:word;
begin
JestTakiAdres:=true;
if ileadresow>0 then
for l:=0 to ileadresow-1 do
if TablicaAdresow^[l]=jaki then Exit;
JestTakiAdres:=false;
end;
begin
FillChar(FileName,256,#0);
FillChar(Filter,24,#0);
StrCopy(Filter,Napis1(83));
StrCopy(@Filter[StrLen(Filter)+1],'*.asm');
FillChar(OpenFN,SizeOf(TOpenFileName),#0);
with OpenFN do
begin
hInstance := HInstance;
hwndOwner := Okno;
lpstrDefExt := DefExt;
lpstrFile := FileName;
lpstrFilter := Filter;
lpstrFileTitle:= nil;
flags := ofn_PathMustExist or ofn_HideReadOnly or ofn_OverwritePrompt;
lStructSize := SizeOf(TOpenFileName);
nFilterIndex := 1;
nMaxFile := SizeOf(FileName);
end;
if not GetSaveFileName(OpenFN) then Exit else Plik:=StrPas(FileName);
b:=PokazDialog('OFFSET',@FunOffset);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,off,code);
if code<>0 then Exit;
b:=PokazDialog('DLUGOSC',@FunDlugosc);
if b<>1 then Exit;
if (Length(wynik)>4) or (wynik='') then Exit;
Val('$'+wynik,dlug,code);
if (code<>0) or (dlug=0) then Exit;
if adrost then koniec:=dlug else
if longint(off)+dlug>65535 then koniec:=65535 else koniec:=off+dlug-1;
Info:=CreateDialog(hInstance,Dial('ZAPISUJE'),Okno,nil);
GetMem(TablicaAdresow,65520);
aktadresnr:=0;
x:=off;
while (x<=koniec) do
begin
if Mem[selROM:x] IN [1,2,$10,$11,$12,$20,$21,$30,$31,$40,$41,$50,$51,$60,$61,$70,$71,$80,
$81,$91,$A1,$B1,$B4..$BF,$C1,$D1,$D5,$D8..$DF,$E1,$F1] then
begin
mnem:=Deasm(x);
TablicaAdresow^[aktadresnr]:=HEXtoW(Copy(mnem,Length(mnem)-4,4));
Inc(aktadresnr);
end;
y:=TabIleBajtow[bajt];
if longint(x)+y>koniec then break else Inc(x,y);
end;
ileadresow:=aktadresnr;
Assign(wy,Plik);
{$I-} Rewrite(wy); {$I+}
if IOResult<>0 then Exit;
Writeln(wy,'$MOD51'#13#10#13#10' org ',WtoHEX(off),'h'#13#10);
x:=off;
while (x<=koniec) do
begin
if JestTakiAdres(x) then Writeln(wy,'l_',LoCaseStr(WtoHEX(x)),':');
bajt:=Mem[selROM:x];
mnem:=Deasm(x);
y:=byte(mnem[1]);
if (mnem[Length(mnem)]='H') and
(mnem[Length(mnem)-1] IN ['0'..'9','A'..'F']) and
(mnem[Length(mnem)-2] IN ['0'..'9','A'..'F']) and
(mnem[Length(mnem)-3] IN ['0'..'9','A'..'F']) and
(mnem[Length(mnem)-4] IN ['0'..'9','A'..'F']) and
(Pos('DPTR,',mnem)=0) then {to jest rozkaz skoku}
mnem:=Copy(mnem,1,Length(mnem)-5)+'l_'+Copy(mnem,Length(mnem)-4,4);
Delete(mnem,1,1);
mnem:=LoCaseStr(mnem);
z:=Pos(#9,mnem);
if z=0 then Writeln(wy,' ',mnem) else
begin
mnem1:=Copy(mnem,1,z-1);
Delete(mnem,1,z);
Writeln(wy,' ',mnem1,Copy(' ',1,8-z),mnem);
end;
if longint(x)+y>koniec then break else Inc(x,y);
end;
Writeln(wy,#13#10'END');
Close(wy);
FreeMem(TablicaAdresow,65520);
DestroyWindow(Info);
OdrysujWszystkie;
end;
procedure WczytajAutoRAM(Okno:HWnd;nazwa:PChar;dodac:boolean); forward;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -