www.pudn.com > DBG8051.rar > Dbgclass.pas
unit DbgClass;
interface
implementation
uses WinTypes, WinProcs, Objects, Strings, Win31, BWCC, DbgZmTypy, DbgAsm;
const
HOfsTyp=0; HOfsAdr=2; HOfsAkt=4;
Tabul:array[0..2] of word=(50,115,170);
MoverString:PChar=
'8051 ADD Debugger home page:'#13'http://www.amwaw.edu.pl/~adybkows'#13#13#13#13+
'CREDITS:'#13'--------------'#13'Adam Dybkowski'#13'Adam Augustyn'#13'Tadeusz Studnik'#13+
#13'FiDoNet Poland'#13#13'and the others...'#13#13#13#13#13#13#13#13#13#13#13#13#13;
type
PPorty=^TPorty;
TPorty=array[0..7] of record
a:byte;
p:word;
end;
PTerminalTekst=^TTerminalTekst;
TTerminalTekst=array[0..24,0..79] of char;
var
redr:byte;
OrygLB:TWndClass;
procedure RysujROM(Okno:HWnd;auto:boolean);
var
Paint:TPaintStruct;
b:HBitmap;
orgDC,DC:HDC;
R:TRect;
n,a:byte;
maxy:shortint;
i:string[40];
is:array[0..40] of char;
adrespocz,adresakt,adres,adreslin:word;
l,szerwys:word;
begin
if auto then orgDC:=BeginPaint(Okno,Paint) else orgDC:=GetDC(Okno);
GetClientRect(Okno,R);
Dec(R.right,WindaSzer); Dec(R.bottom,WindaWys);
b:=CreateCompatibleBitmap(orgDC,R.right,R.bottom);
DC:=CreateCompatibleDC(orgDC);
SelectObject(DC,b);
SelectObject(DC,GetStockObject(BLACK_BRUSH));
SelectObject(DC,GetStockObject(BLACK_PEN));
SelectObject(DC,CzcionkaOEM);
SetBkMode(DC,TRANSPARENT);
Rectangle(DC,R.left,R.top,R.right,R.bottom); {wypełniamy na czarno}
maxy:=((R.bottom-R.top) div FontOEMwys)-1;
if maxy<1 then maxy:=1;
l:=GetWindowWord(Okno,HOfsTyp);
adrespocz:=GetWindowWord(Okno,HOfsAdr);
adresakt:=GetWindowWord(Okno,HOfsAkt);
adreslin:=adresakt and $FFF8;
if l=0 then { widok pamieci EPROM }
begin
SetTextColor(DC,$00ffff00); { $00bbggrr - blue,green,red }
adres:=adrespocz;
for a:=0 to maxy do
begin
i:=WtoHEX(adres)+': ';
for n:=0 to 7 do i:=i+BtoHEX(Mem[selROM:adres+n])+' ';
for n:=0 to 7 do i:=i+char(Mem[selROM:adres+n]);
for n:=1 to Length(i) do if (i[n]=#0) or (i[n]=#255) then i[n]:=' ';
TextOut(DC,2,a*FontOEMwys,StrPCopy(is,i),38);
if adres=adreslin then
begin
szerwys:=GetTextExtent(DC,is,(adresakt and 7)*3+6);
SetTextColor(DC,$000000ff);
TextOut(DC,2+LoWord(szerwys),((adreslin-adrespocz) div 8)*FontOEMwys,
is+(adresakt and 7)*3+6,2);
SetTextColor(DC,$00ffff00);
end;
if adres=$FFF8 then break;
adres:=adres+8;
end;
end else
if l=1 then { widok pamieci zewnetrznej RAM }
begin
SetTextColor(DC,$0000ffff);
adres:=adrespocz;
for a:=0 to maxy do
begin
i:=WtoHEX(adres)+': ';
for n:=0 to 7 do i:=i+BtoHEX(Mem[selRAM:adres+n])+' ';
for n:=0 to 7 do i:=i+char(Mem[selRAM:adres+n]);
for n:=1 to Length(i) do if (i[n]=#0) or (i[n]=#255) then i[n]:=' ';
TextOut(DC,2,a*FontOEMwys,StrPCopy(is,i),38);
if adres=adreslin then
begin
szerwys:=GetTextExtent(DC,is,(adresakt and 7)*3+6);
SetTextColor(DC,$000000ff);
TextOut(DC,2+LoWord(szerwys),((adreslin-adrespocz) div 8)*FontOEMwys,
is+(adresakt and 7)*3+6,2);
SetTextColor(DC,$0000ffff);
end;
if adres=$FFF8 then break;
adres:=adres+8;
end;
end else
if l=2 then { widok pamieci wewnetrznej RAM i rejestrow }
begin
SetTextColor(DC,$0000ff00);
adres:=adrespocz;
for a:=0 to maxy do
begin
i:=WtoHEX(adres)+': ';
if bigmem and (adres>=128) then
begin
for n:=0 to 7 do i:=i+BtoHEX(Mem[selRAMInt:adres+n+128])+' ';
for n:=0 to 7 do i:=i+char(Mem[selRAMInt:adres+n+128]);
end else
begin
for n:=0 to 7 do i:=i+BtoHEX(Mem[selRAMInt:adres+n])+' ';
for n:=0 to 7 do i:=i+char(Mem[selRAMInt:adres+n]);
end;
for n:=1 to Length(i) do if (i[n]=#0) or (i[n]=#255) then i[n]:=' ';
TextOut(DC,2,a*FontOEMwys,StrPCopy(is,i),38);
if adres=adreslin then
begin
szerwys:=GetTextExtent(DC,is,(adresakt and 7)*3+6);
SetTextColor(DC,$000000ff);
TextOut(DC,2+LoWord(szerwys),((adreslin-adrespocz) div 8)*FontOEMwys,
is+(adresakt and 7)*3+6,2);
SetTextColor(DC,$0000ff00);
end;
if adres=$F8 then break;
adres:=(adres+8) and $FF;
end;
end;
BitBlt(orgDC,1,0,R.right-1,R.bottom,DC,1,0,SrcCopy);
DeleteDC(DC);
DeleteObject(b);
if auto then EndPaint(Okno,Paint) else ReleaseDC(Okno,orgDC);
end;
procedure PrzewinHex(Okno:HWnd;wScrollCode,nPos:word;hwndCtl:HWnd);
var
R:TRect;
l,adrpocz,adrakt,adrlin,adrkon,mas,maxy8:word;
maxy:shortint;
begin
GetClientRect(Okno,R);
Dec(R.right,WindaSzer); Dec(R.bottom,WindaWys);
maxy:=((R.bottom-R.top) div FontOEMwys)-1;
if maxy<1 then maxy:=1;
maxy8:=maxy*8;
l:=GetWindowWord(Okno,HOfsTyp);
adrpocz:=GetWindowWord(Okno,HOfsAdr);
adrakt:=GetWindowWord(Okno,HOfsAkt);
if l=2 then mas:=$F8 else mas:=$FFF8;
adrlin:=adrakt and mas;
if longint(adrpocz)+maxy8>mas then adrkon:=mas else adrkon:=adrpocz+maxy8;
case wScrollCode of
sb_LineUp : if adrlin>adrpocz then Dec(adrakt,8) else
if adrpocz>0 then begin Dec(adrpocz,8); Dec(adrakt,8) end;
sb_LineDown : if adraktadrpocz then adrakt:=adrpocz or (adrakt and 7) else
begin
if adrpocz>maxy8+8 then Dec(adrpocz,maxy8+8) else adrpocz:=0;
adrakt:=adrpocz or (adrakt and 7);
end;
sb_PageDown : if adraktadrkon then adrpocz:=adrlin-maxy8;
if adrpocz>mas-maxy8 then adrpocz:=mas-maxy8;
adrakt:=adrlin or (adrakt and 7);
end;
end;
SetWindowWord(Okno,HOfsAdr,adrpocz);
SetWindowWord(Okno,HOfsAkt,adrakt);
if l=2 then
SetScrollPos(hwndCtl,sb_Ctl,adrakt and $FFF8,true) else
SetScrollPos(hwndCtl,sb_Ctl,(adrakt and $FFF8) div 4,true);
InvalidateRect(Okno,@R,false);
end;
procedure PrzewinHoriz(Okno:HWnd;wScrollCode,nPos:word;hwndCtl:HWnd);
var
adrakt:word;
R:TRect;
begin
adrakt:=GetWindowWord(Okno,HOfsAkt);
case wScrollCode of
sb_LineUp : if (adrakt and 7)>0 then Dec(adrakt);
sb_LineDown : if (adrakt and 7)<7 then Inc(adrakt);
sb_PageUp : adrakt:=adrakt and $FFF8;
sb_PageDown : adrakt:=adrakt or 7;
sb_ThumbTrack : adrakt:=(adrakt and $FFF8) or nPos;
end;
SetWindowWord(Okno,HOfsAkt,adrakt);
SetScrollPos(hwndCtl,sb_Ctl,adrakt and 7,true);
GetClientRect(Okno,R);
Dec(R.right,WindaSzer); Dec(R.bottom,WindaWys);
InvalidateRect(Okno,@R,false);
end;
procedure SkokHex(Okno:HWnd);
var
code,b:integer;
l,adrpocz,adrakt,off:word;
R:TRect;
begin
l:=GetWindowWord(Okno,HOfsTyp);
b:=PokazDialog('ADRSKOKU',@FunOffset);
if b<>1 then Exit;
if wynik='' then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(66),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if (wynik='PC') and (l=0) then off:=RejPC else
begin
Val('$'+wynik,off,code);
if code<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
end;
if (l=2) and (off>$FF) then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(8),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
adrakt:=off;
adrpocz:=off and $FFF8;
if (l=2) and (adrpocz>$C0) then adrpocz:=$C0;
if (l<2) and (adrpocz>$FFC0) then adrpocz:=$FFC0;
SetWindowWord(Okno,HOfsAdr,adrpocz);
SetWindowWord(Okno,HOfsAkt,adrakt);
if l=2 then
SetScrollPos(GetDlgItem(Okno,500),sb_Ctl,(adrakt and $FFF8),true) else
SetScrollPos(GetDlgItem(Okno,500),sb_Ctl,(adrakt and $FFF8) div 4,true);
SetScrollPos(GetDlgItem(Okno,501),sb_Ctl,adrakt and 7,true);
GetClientRect(Okno,R);
Dec(R.right,WindaSzer); Dec(R.bottom,WindaWys);
InvalidateRect(Okno,@R,false);
end;
procedure ClickHex(Okno:HWnd;xPos,yPos:word);
var
R:TRect;
nx,ny,adrpocz,adrakt,l:word;
begin
if (xPos<6*FontOEMszer+2) or (xPos>30*FontOEMszer+2) then Exit;
nx:=(xPos-2-6*FontOEMszer) div (FontOEMszer*3);
ny:=yPos div FontOEMwys;
l:=GetWindowWord(Okno,HOfsTyp);
adrpocz:=GetWindowWord(Okno,HOfsAdr);
adrakt:=adrpocz+nx+8*ny;
SetWindowWord(Okno,HOfsAkt,adrakt);
if l=2 then
SetScrollPos(GetDlgItem(Okno,500),sb_Ctl,adrakt and $FFF8,true) else
SetScrollPos(GetDlgItem(Okno,500),sb_Ctl,(adrakt and $FFF8) div 4,true);
SetScrollPos(GetDlgItem(Okno,501),sb_Ctl,adrakt and 7,true);
GetClientRect(Okno,R);
Dec(R.right,WindaSzer); Dec(R.bottom,WindaWys);
InvalidateRect(Okno,@R,false);
end;
procedure DblClickHex(Okno:HWnd;xPos,yPos:word);
var
R:TRect;
l,adrpocz,adrakt,newad:word;
maxy:shortint;
begin
if (xPos<6*FontOEMszer+2) or (xPos>30*FontOEMszer+2) then Exit;
GetClientRect(Okno,R);
Dec(R.right,WindaSzer); Dec(R.bottom,WindaWys);
maxy:=((R.bottom-R.top) div FontOEMwys)-1;
if maxy<1 then maxy:=1;
l:=GetWindowWord(Okno,HOfsTyp);
adrpocz:=GetWindowWord(Okno,HOfsAdr);
adrakt:=GetWindowWord(Okno,HOfsAkt);
case l of
0: begin
BajtyWstaw(Okno,selROM,adrakt,$FFFF,newad);
OdrysujOkna(0); {Instr}
OdrysujOkna(3); {HEX ROM}
end;
1: begin
BajtyWstaw(Okno,selRAM,adrakt,$FFFF,newad);
OdrysujOkna(4); {HEX RAM}
end;
2: begin
BajtyWstaw(Okno,selRAMInt,adrakt,$FF,newad);
OdrysujOkna(1); {Rej}
OdrysujOkna(2); {Bit}
OdrysujOkna(5); {HEX RAM Int}
OdrysujOkna(9); {Porty}
end;
end;
OdrysujOkna(6); {Symb}
adrakt:=newad;
SetWindowWord(Okno,HOfsAkt,adrakt);
if adrakt>adrpocz+maxy*8+7 then
begin
adrpocz:=(adrakt-maxy*8) and $FFF8;
if l=2 then adrpocz:=adrpocz and $F8;
SetWindowWord(Okno,HOfsAdr,adrpocz);
end else
if adrakt0) then
RysujROM(Okno,false);
us_ZmienRozmiary: ZmienWielkoscHex(Okno,LoWord(LParam),HiWord(LParam));
end;
else FunHexView:=DefWindowProc(Okno,Kod_meldunku,wParam,LParam);
end;
end;
procedure RysujBitki(Okno:HWnd;auto:boolean);
var
Paint:TPaintStruct;
DC:HDC;
x,y:integer;
p:longint;
n,ad,oldad:byte;
a:string[5];
is:array[0..5] of char;
begin
if auto then DC:=BeginPaint(Okno,Paint) else DC:=GetDC(Okno);
SelectObject(DC,GetStockObject(LTGRAY_BRUSH));
SelectObject(DC,CzcionkaOEM);
SetBkColor(DC,$00C0C0C0);
y:=0; oldad:=$88;
p:=0;
for n:=0 to 39 do
begin
ad:=HEXtoB(Copy(RejBity[n],1,2));
if ad<>oldad then Inc(y,FontOEMwys+4);
x:=byte(RejBity[n,3])-48;
if (Mem[selRAMInt:ad] and Maski[x])=0 then
begin
if p<>$00808080 then
begin
SetTextColor(DC,$00808080);
p:=$00808080;
end;
end else
if p<>$000000ff then
begin
SetTextColor(DC,$000000ff);
p:=$000000ff;
end;
a:=Copy(Copy(RejBity[n],4,255)+' ',1,3);
StrPCopy(is,a);
TextOut(DC,(7-x)*(3*FontOEMszer+2),y,is,Length(a));
oldad:=ad;
end;
if auto then EndPaint(Okno,Paint) else ReleaseDC(Okno,DC);
end;
procedure ZmienBitki(x,y:word;Okno:HWnd);
var
w:byte;
R:TRect;
begin
w:=RejBityA[y div (FontOEMwys+4)];
Mem[selRAMInt:w]:=Mem[selRAMInt:w] xor Maski[7-x div (3*FontOEMszer+2)];
SetRect(R,x-(3*FontOEMszer+2),y-(FontOEMwys+4),x+(3*FontOEMszer+2),y+(FontOEMwys+4));
InvalidateRect(Okno,@R,false);
OdrysujOkna(1); {Rej}
OdrysujOkna(2); {Bit}
OdrysujOkna(5); {HEX RAM Int}
OdrysujOkna(6); {Symb}
OdrysujOkna(9); {Porty}
end;
function FunBitView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
begin
FunBitView := 0;
case Kod_meldunku of
wm_Paint : RysujBitki(Okno,true);
wm_LButtonDown : ZmienBitki(LoWord(LParam),HiWord(LParam),GetParent(Okno));
wm_Command : if wParam=us_OdnowWidok then RysujBitki(Okno,false);
else FunBitView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure RysujMover(Okno:HWnd);
var
Paint:TPaintStruct;
DC:HDC;
R:TRect;
begin
GetClientRect(Okno,R);
DC:=BeginPaint(Okno,Paint);
BitBlt(DC,0,0,R.right+1,R.bottom+1,HDC(GetWindowWord(Okno,4)),0,0,SRCCOPY);
EndPaint(Okno,Paint);
end;
procedure CzasMover(Okno:HWnd);
var
DC,mdc:HDC;
szer:word;
R:TRect;
zn:word;
akt,tmp:PChar;
a:array[0..40] of char;
li:byte;
begin
li:=GetWindowWord(Okno,8);
zn:=GetWindowWord(Okno,10);
GetClientRect(Okno,R);
DC:=GetDC(Okno);
mdc:=GetWindowWord(Okno,4);
BitBlt(mdc,0,0,R.right+1,R.bottom+32,mdc,0,1,SRCCOPY);
BitBlt(DC,0,0,R.right+1,R.bottom+1,mdc,0,0,SRCCOPY);
akt:=MoverString+zn;
if li<20 then Inc(li) else
begin
li:=0;
tmp:=StrScan(akt,#13);
if tmp=nil then zn:=0 else
begin
if tmp<>akt then
begin
StrLCopy(a,akt,tmp-akt);
szer:=LoWord(GetTextExtent(mdc,a,StrLen(a)));
TextOut(mdc,(R.right+1-szer) div 2,R.bottom+1,a,StrLen(a));
end else li:=10;
zn:=tmp-MoverString+1;
end;
end;
ReleaseDC(Okno,DC);
SetWindowWord(Okno,8,li);
SetWindowWord(Okno,10,zn);
end;
function FunMoverView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
var
DC,mdc:HDC;
b:HBitmap;
f:HFont;
R:TRect;
begin
FunMoverView:=0;
case Kod_meldunku of
wm_Create : begin
GetClientRect(Okno,R);
DC:=GetDC(Okno);
b:=CreateCompatibleBitmap(DC,R.right+1,R.bottom+33);
mdc:=CreateCompatibleDC(DC);
SelectObject(mdc,b);
SelectObject(mdc,GetStockObject(LTGRAY_BRUSH));
SetBkColor(mdc,$00C0C0C0);
SetTextColor(mdc,$800080);
Rectangle(mdc,-1,-1,R.right+1,R.bottom+34);
ReleaseDC(Okno,DC);
f:=CreateFont(18,0,0,0,FW_BOLD,0,0,0,0,0,0,0,
VARIABLE_PITCH or FF_SWISS,'Times New Roman');
SelectObject(mdc,f);
SetWindowWord(Okno,0,SetTimer(Okno,1,30,nil));
SetWindowWord(Okno,2,b);
SetWindowWord(Okno,4,mdc);
SetWindowWord(Okno,6,f);
SetWindowWord(Okno,8,19); {li=19}
SetWindowWord(Okno,10,0); {zn=0}
end;
wm_Destroy : begin
KillTimer(Okno,GetWindowWord(Okno,0));
DeleteDC(GetWindowWord(Okno,4));
DeleteObject(GetWindowWord(Okno,2));
DeleteObject(GetWindowWord(Okno,6));
DefWindowProc(Okno,wm_Destroy,WParam,LParam);
end;
wm_Paint : RysujMover(Okno);
wm_Timer : CzasMover(Okno);
else FunMoverView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure RysujStan(Okno:HWnd;auto:boolean);
var
Paint:TPaintStruct;
DC,m:HDC;
txt:string[10];
a:array[0..19] of char;
b:HBitmap;
begin
if auto then DC:=BeginPaint(Okno,Paint) else DC:=GetDC(Okno);
m:=CreateCompatibleDC(DC);
b:=LoadBitmap(hInstance,'INTSTATE');
SelectObject(m,b);
SetBkColor(DC,$00c0c0c0);
SetTextColor(DC,0);
SelectObject(DC,CzcionkaOEM);
StrPCopy(a,'PC: '+WtoHEX(RejPC)+' ');
TextOut(DC,2,1,a,9);
if licznikcykli<0 then licznikcykli:=0;
Str(licznikcykli,txt);
StrCopy(a,Napis1(82));
StrPCopy(@a[StrLen(a)],': '+txt+' ');
SetTextColor(DC,$000000ff);
TextOut(DC,36+FontOEMszer*8,1,a,StrLen(a));
BitBlt(DC,6+FontOEMszer*8,2,26,29,m,intflipflop*26,0,SrcCopy);
DeleteDC(m);
DeleteObject(b);
if auto then EndPaint(Okno,Paint) else ReleaseDC(Okno,DC);
end;
procedure DblClickStan(Okno:HWnd;xPos:word);
var
b:integer;
off:word;
begin
if xPos>70 then
begin
if xPos>100 then
begin
licznikcykli:=0;
OdrysujOkna(7); {Stan}
end;
Exit;
end;
b:=PokazDialog('REJESTR',@FunOffset);
if (b<>1) or (wynik='') then Exit;
Val('$'+wynik,off,b);
if b<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
RejPC:=off;
OdrysujOkna(0); {Instr}
OdrysujOkna(7); {Stan}
end;
function FunStanView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
begin
FunStanView:=0;
case Kod_meldunku of
wm_Paint : RysujStan(Okno,true);
wm_LButtonDblClk : DblClickStan(Okno,LoWord(LParam));
wm_Command : if (wParam=us_OdnowWidok) or
(wParam=us_ZmianaJez) then RysujStan(Okno,false);
else FunStanView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure OdnowReje(Okno:HWnd);
var
Reje:HWnd;
i,a,poczr:byte;
tmp:array[0..50] of char;
aktb:string[2];
begin
Reje:=GetWindow(Okno,gw_Child);
if SendMessage(Reje,lb_GetCount,0,0)<>0 then SendMessage(Reje,lb_ResetContent,0,0);
for i:=0 to 19 do
begin
a:=HEXtoB(Copy(Rejestry[i],1,2));
aktb:=BtoHEX(Mem[selRAMInt:a]);
StrPCopy(tmp,' '+Copy(Rejestry[i],5,255)+#9'= '+aktb);
Move(aktb[1],Rejestry[i,3],2);
SendMessage(Reje,lb_AddString,0,longint(@tmp));
end;
poczr:=Mem[selRAMInt:$D0] and $18; { bity: RS0 i RS1 }
for i:=20 to 27 do { rejestry R0..R7 }
begin
a:=HEXtoB(Copy(Rejestry[i],1,2))+poczr;
aktb:=BtoHEX(Mem[selRAMInt:a]);
StrPCopy(tmp,' '+Copy(Rejestry[i],5,255)+#9'= '+aktb);
Move(aktb[1],Rejestry[i,3],2);
SendMessage(Reje,lb_AddString,0,longint(@tmp));
end;
end;
procedure ZmianaRej(Okno:HWnd);
var
Reje:HWnd;
b:integer;
off,i:word;
poczr:byte;
begin
Reje:=GetWindow(Okno,gw_Child);
i:=SendMessage(Reje,lb_GetCurSel,0,0);
b:=PokazDialog('REJESTR',@FunOffset);
if (b<>1) or (Length(wynik)>2) or (wynik='') then Exit;
Val('$'+wynik,off,b);
if b<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if off>255 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(9),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if i>19 then
poczr:=Mem[selRAMInt:$D0] and $18 else poczr:=0; { czy R0..R7 ? }
Mem[selRAMInt:poczr+HEXtoB(Copy(Rejestry[i],1,2))]:=off;
OdnowReje(Okno);
OdrysujOkna(1); {Reg}
OdrysujOkna(2); {Bit}
OdrysujOkna(5); {HEX RAM Int}
OdrysujOkna(6); {Symb}
OdrysujOkna(9); {Porty}
end;
function FunRegsView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
const TabuR:integer=24;
var Reje:HWnd;
begin
FunRegsView:=0;
case Kod_meldunku of
wm_Create : begin
Reje:=CreateWindow('KLASALISTB','',ws_Child or ws_Visible or
ws_Border or lbs_UseTabStops or lbs_MultiColumn or lbs_Notify,
0,0,190,226,Okno,500,hInstance,nil);
SendMessage(Reje,lb_SetTabStops,1,longint(@TabuR));
SendMessage(Reje,lb_SetColumnWidth,100,0);
OdnowReje(Okno);
end;
wm_Command : case wParam of
500 : if HiWord(LParam)=lbn_DblClk then ZmianaRej(Okno);
us_OdnowWidok : begin
OdnowReje(Okno);
UpdateWindow(Okno);
end;
end;
wm_VKeyToItem : if (HWnd(LoWord(LParam))=GetDlgItem(Okno,500)) and (wParam=VK_RETURN)
then begin
ZmianaRej(Okno);
FunRegsView:=-2;
end else FunRegsView:=-1;
else FunRegsView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure OdnowSymb(Okno:HWnd);
var
Symb,ok:HWnd;
kol:PStrCollection;
l,i:word;
b:char;
s:string[40];
a:array[0..40] of char;
begin
Symb:=GetWindow(Okno,gw_Child);
l:=GetWindowWord(Okno,0);
for i:=0 to 3 do
begin
ok:=GetDlgItem(Okno,501+i);
if l=i then EnableWindow(ok,false) else EnableWindow(ok,true);
end;
SendMessage(Symb,wm_SetRedraw,0,0);
if SendMessage(Symb,lb_GetCount,0,0)<>0 then SendMessage(Symb,lb_ResetContent,0,0);
case l of
0: kol:=SymbROM;
1: kol:=SymbRAM;
2: kol:=SymbReg;
3: kol:=SymbBit;
end;
if l=0 then
begin
if kol^.Count>0 then
for i:=0 to kol^.Count-1 do
begin
s:=StrPas(kol^.At(i));
StrPCopy(a,Copy(s,1,4)+#9#9+Copy(s,5,255));
SendMessage(Symb,lb_AddString,0,longint(@a));
end;
end else if l=1 then
begin
if kol^.Count>0 then
for i:=0 to kol^.Count-1 do
begin
s:=StrPas(kol^.At(i));
StrPCopy(a,Copy(s,1,4)+#9+BtoHEX(Mem[selRAM:HEXtoW(Copy(s,1,4))])+#9+Copy(s,5,255));
SendMessage(Symb,lb_AddString,0,longint(@a));
end;
end else if l=2 then
begin
if kol^.Count>0 then
for i:=0 to kol^.Count-1 do
begin
s:=StrPas(kol^.At(i));
StrPCopy(a,Copy(s,3,2)+#9+BtoHEX(Mem[selRAMInt:HEXtoB(Copy(s,3,2))])+#9+Copy(s,5,255));
SendMessage(Symb,lb_AddString,0,longint(@a));
end;
end else if l=3 then
if kol^.Count>0 then
for i:=0 to kol^.Count-1 do
begin
s:=StrPas(kol^.At(i));
if (Mem[selRAMInt:HEXtoW(Copy(s,3,2))] and Maski[HEXtoB(s[2])])=0 then
b:='0' else b:='1';
StrPCopy(a,Copy(s,3,2)+'.'+s[2]+#9+b+#9+Copy(s,5,255));
SendMessage(Symb,lb_AddString,0,longint(@a));
end;
SendMessage(Symb,wm_SetRedraw,1,0);
end;
function DodajSymb(Okno:HWnd;zmiana:boolean):boolean;
var
Symb:HWnd;
bitnr:byte;
l,adr,j:word;
b:integer;
kol:PStrCollection;
nap:string[44];
begin
Symb:=GetWindow(Okno,gw_Child);
l:=GetWindowWord(Okno,0);
case l of
0: kol:=SymbROM;
1: kol:=SymbRAM;
2: kol:=SymbReg;
3: kol:=SymbBit;
end;
if zmiana=false then
begin
buforzn1[0]:=#0; buforzn2[0]:=#0; buforzn3[0]:=#0;
if l=3 then
b:=PokazDialog('NOWYBIT',@FunSymBit) else
b:=PokazDialog('NOWYSYM',@FunSymbol);
end
else if l=3 then
b:=PokazDialog('ZMIENBIT',@FunSymBit) else
b:=PokazDialog('ZMIENSYM',@FunSymbol);
DodajSymb:=true;
if b<>1 then Exit;
if (wynik='') or (wynik1='') then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(64),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if (Pos(' ',wynik)>0) or (Pos(',',wynik)>0) or (Pos(':',wynik)>0) then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(5),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if (l=3) and (wynik2='') then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(65),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
adr:=HEXtoW(wynik1);
if codeconv<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if ((l=2) or (l=3)) and (adr>$FF) then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(8),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if l=3 then
begin
bitnr:=HEXtoB(wynik2);
if (codeconv<>0) or ((codeconv=0) and (bitnr>7)) then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(65),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
StrPCopy(buforzn1,BtoHEX(bitnr)+BtoHEX(adr)+wynik);
end
else StrPCopy(buforzn1,WtoHEX(adr)+wynik);
DodajSymb:=false;
if zmiana then Exit;
kol^.Insert(StrNew(buforzn1));
OdnowSymb(Okno);
SetFocus(Symb);
j:=SendMessage(Symb,lb_GetCaretIndex,0,0);
SendMessage(Symb,lb_SetCurSel,j,0);
OdrysujOkna(6); {Symb}
if l=0 then
begin
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
end;
end;
procedure UsunSymb(Okno:HWnd);
var
Symb:HWnd;
l,j:word;
kol:PStrCollection;
begin
Symb:=GetWindow(Okno,gw_Child);
l:=GetWindowWord(Okno,0);
case l of
0: kol:=SymbROM;
1: kol:=SymbRAM;
2: kol:=SymbReg;
3: kol:=SymbBit;
end;
if kol^.Count=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
j:=SendMessage(Symb,lb_GetCaretIndex,0,0);
if SendMessage(Symb,lb_GetSel,j,0)=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
SendMessage(Symb,lb_DeleteString,j,0);
kol^.AtDelete(j);
OdrysujOkna(6); {Symb}
if l=0 then
begin
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
end;
SetFocus(Symb);
j:=SendMessage(Symb,lb_GetCaretIndex,0,0);
SendMessage(Symb,lb_SetCurSel,j,0);
end;
procedure ZmienSymb(Okno:HWnd);
var
Symb:HWnd;
l,j:word;
n:byte;
kol:PStrCollection;
Bufor:array[0..63] of char;
linia:string[63];
linia1,adres:string[4];
bitnr:char;
begin
Symb:=GetWindow(Okno,gw_Child);
l:=GetWindowWord(Okno,0);
case l of
0: kol:=SymbROM;
1: kol:=SymbRAM;
2: kol:=SymbReg;
3: kol:=SymbBit;
end;
if kol^.Count=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
j:=SendMessage(Symb,lb_GetCaretIndex,0,0);
if SendMessage(Symb,lb_GetSel,j,0)=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
SendMessage(Symb,lb_GetText,j,longint(@Bufor));
linia:=StrPas(Bufor);
n:=Pos(#9,linia);
linia1:=Copy(linia,1,n-1);
Delete(linia,1,n);
if l<3 then adres:=linia1 else
begin
adres:=Copy(linia1,1,2);
bitnr:=linia1[4];
end;
n:=Pos(#9,linia);
Delete(linia,1,n);
StrPCopy(buforzn1,linia);
StrPCopy(buforzn2,adres);
if l=3 then StrPCopy(buforzn3,bitnr);
if DodajSymb(Okno,true) then
begin
SetFocus(Symb);
j:=SendMessage(Symb,lb_GetCaretIndex,0,0);
SendMessage(Symb,lb_SetCurSel,j,0);
Exit;
end;
kol^.AtDelete(j);
kol^.Insert(StrNew(buforzn1));
OdrysujOkna(6); {Symb}
if l=0 then
begin
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
end;
SetFocus(Symb);
j:=SendMessage(Symb,lb_GetCaretIndex,0,0);
SendMessage(Symb,lb_SetCurSel,j,0);
end;
procedure UsunAllSymb(Okno:HWnd);
var
l:word;
kol:PStrCollection;
begin
l:=GetWindowWord(Okno,0);
case l of
0: kol:=SymbROM;
1: kol:=SymbRAM;
2: kol:=SymbReg;
3: kol:=SymbBit;
end;
if kol^.Count=0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(Okno,Napis1(6),'Debugger 8051',mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if BWCCMessageBox(Okno,Napis1(7),'Debugger 8051',mb_OKCancel or mb_TaskModal or
mb_IconQuestion)<>1 then Exit;
kol^.DeleteAll;
OdrysujOkna(6); {Symb}
if l=0 then
begin
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
end;
end;
procedure ZmienJezykSymb(Okno:HWnd);
begin
SetWindowText(GetDlgItem(Okno,505),Napis1(60));
SetWindowText(GetDlgItem(Okno,506),Napis1(61));
SetWindowText(GetDlgItem(Okno,507),Napis1(62));
SetWindowText(GetDlgItem(Okno,508),Napis1(63));
end;
function FunSymbView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
const
TabuS:array[0..1] of integer=(23,36);
NazwyB:array[0..3] of PChar=('EPROM','RAM','REG','BIT');
var
Symb:HWnd;
i:word;
begin
FunSymbView:=0;
case Kod_meldunku of
wm_Create : begin
SetWindowWord(Okno,0,0);
Symb:=CreateWindow('LISTBOX','',ws_Child or ws_Visible or lbs_Standard
or lbs_UseTabStops or lbs_WantKeyboardInput,0,0,270,226,Okno,500,
hInstance,nil);
SendMessage(Symb,lb_SetTabStops,2,longint(@TabuS));
for i:=0 to 3 do
CreateWindow('BUTTON',NazwyB[i],ws_Child or ws_Visible,
271,i*25,95,25,Okno,501+i,hInstance,nil);
for i:=0 to 3 do
CreateWindow('BUTTON',Napis1(60+i),ws_Child or ws_Visible,
271,100+i*25,95,25,Okno,505+i,hInstance,nil);
OdnowSymb(Okno);
end;
wm_Command : case wParam of
500: if HiWord(LParam)=lbn_DblClk then ZmienSymb(Okno);
501..504 : begin
SetWindowWord(Okno,0,wParam-501);
OdnowSymb(Okno);
end;
505 : DodajSymb(Okno,false);
506 : UsunSymb(Okno);
507 : UsunAllSymb(Okno);
508 : ZmienSymb(Okno);
us_ZmianaJez : ZmienJezykSymb(Okno);
us_OdnowWidok : begin
OdnowSymb(Okno);
UpdateWindow(Okno);
end;
end;
wm_VKeyToItem : if (HWnd(LoWord(LParam))=GetDlgItem(Okno,500)) and (wParam=VK_RETURN)
then begin
ZmienSymb(Okno);
FunSymbView:=-2;
end else FunSymbView:=-1;
else FunSymbView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure OdnowInstr(Okno:HWnd);
var
o:HWnd;
adr:PAdresy;
begin
o:=GetDlgItem(Okno,500);
adr:=pointer(GetWindowLong(Okno,0));
SendMessage(o,wm_SetRedraw,0,0);
redr:=0;
SendMessage(o,lb_ResetContent,0,0);
WypelnijInstr(o,pointer(GetWindowLong(Okno,0)));
SendMessage(o,wm_SetRedraw,1,0);
redr:=1;
SendMessage(o,lb_SetCurSel,GetWindowWord(Okno,4),0);
SetScrollPos(GetDlgItem(Okno,501),sb_Ctl,adr^[1] shr 2,true);
InvalidateRect(GetDlgItem(Okno,503),nil,false);
UpdateWindow(GetDlgItem(Okno,503));
end;
procedure SkokGora(Okno,Suw:HWnd;hurt:boolean);
var
q:string[30];
dl:byte;
z,off,sta:word;
adr:PAdresy;
begin
z:=GetWindowWord(Okno,4);
if z>0 then
begin
Dec(z);
SetWindowWord(Okno,4,z);
if not hurt then SendMessage(GetDlgItem(Okno,500),lb_SetCurSel,z,0);
Exit;
end;
adr:=pointer(GetWindowLong(Okno,0));
off:=adr^[1];
if off=0 then Exit;
sta:=off;
q:=Deasm(off-1);
dl:=1;
if q[1]<>#1 then
begin
q:=Deasm(off-2);
if q[1]=#2 then dl:=2 else
begin
q:=Deasm(off-3);
if q[1]=#3 then dl:=3;
end;
end;
if longint(off)-dl<0 then Exit;
adr^[1]:=off-dl;
if (adr^[1]<>sta) and (hurt=false) then OdnowInstr(Okno);
end;
procedure SkokDol(Okno,Suw:HWnd;hurt:boolean);
var
Inst:HWnd;
z,off,ile:word;
code:integer;
q:string[30];
w:string[50];
e:array[0..50] of char;
tmp:array[1..19] of word;
dl,x:byte;
adr:PAdresy;
begin
z:=GetWindowWord(Okno,4);
Inst:=GetDlgItem(Okno,500);
ile:=SendMessage(Inst,lb_GetCount,0,0);
if z65535 then Exit;
Move(adr^[2],tmp,SizeOf(tmp));
Move(tmp,adr^[1],SizeOf(tmp));
Inc(off,byte(q[1]));
adr^[20]:=off;
if hurt then Exit;
q:=Deasm(off);
dl:=byte(q[1]);
Delete(q,1,1);
w:=WtoHEX(off)+':'#9;
for x:=1 to dl do
begin
w:=w+BtoHEX(Mem[selROM:off+x-1]);
if x1) or (wynik='') then
begin
SetFocus(Inst);
Exit;
end;
q:=Reasm(ad,wynik);
if q='' then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(3),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
SetFocus(Inst);
Exit;
end;
if Copy(q,1,4)='GOGO' then
begin
adr^[1]:=256*byte(q[6])+byte(q[5]);
SetWindowWord(Okno,4,0);
OdrysujOkna(0); {Instr}
OdrysujOkna(3); {HEX ROM}
OdnowInstr(Okno);
SetFocus(Inst);
PostMessage(Okno,wm_Command,500,MakeLong(0,lbn_DblClk));
Exit;
end;
if longint(ad)+Length(q)>65536 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(4),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
SetFocus(Inst);
Exit;
end;
for b:=0 to Length(q)-1 do Mem[selROM:ad+b]:=byte(q[b+1]);
if longint(ad)+Length(q)>65535 then
begin
OdrysujOkna(0); {Instr}
OdrysujOkna(3); {HEX ROM}
SetFocus(Inst);
Exit;
end;
if z<19 then Inc(z) else adr^[1]:=adr^[2];
SetWindowWord(Okno,4,z);
OdrysujOkna(0); {Instr}
OdrysujOkna(3); {HEX ROM}
OdnowInstr(Okno);
PostMessage(Okno,wm_Command,500,MakeLong(0,lbn_DblClk));
end;
procedure SkokInstr(Okno:HWnd);
var
code,b:integer;
off:word;
adr:PAdresy;
begin
b:=PokazDialog('ADRSKOKU',@FunOffset);
if b<>1 then Exit;
if wynik='' then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(66),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if wynik='PC' then off:=RejPC else
begin
Val('$'+wynik,off,code);
if code<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
end;
adr:=pointer(GetWindowLong(Okno,0));
adr^[1]:=off;
SetWindowWord(Okno,4,0);
OdnowInstr(Okno);
end;
procedure LecimyInstr(Okno:HWnd);
var
adr:PAdresy;
i,ile:byte;
off:word;
Inst:HWnd;
begin
adr:=pointer(GetWindowLong(Okno,0));
Inst:=GetDlgItem(Okno,500);
ile:=SendMessage(Inst,lb_GetCount,0,0);
if (RejPCadr^[ile]) then
begin
adr^[1]:=RejPC;
SetWindowWord(Okno,4,0);
Exit;
end;
for i:=1 to ile do
if RejPC=adr^[i] then
begin
SetWindowWord(Okno,4,i-1);
Exit;
end;
adr^[1]:=RejPC;
SetWindowWord(Okno,4,0);
end;
procedure NarysujLinie(Okno:HWnd;lpdis:PDrawItemStruct);
const Kolory:array[0..7] of longint=(0,$ffffff,$ffffff,$800000,$ffffff,$ff,$ffffff,$ff00ff);
var
buf:array[0..63] of char;
br:HBrush;
adr:PAdresy;
i:byte;
b:HBitmap;
DC:HDC;
R:TRect;
begin
if redr=0 then Exit;
R:=lpdis^.rcItem;
OffsetRect(R,-R.left,-R.top);
b:=CreateCompatibleBitmap(lpdis^.HDC,R.right,R.bottom);
DC:=CreateCompatibleDC(lpdis^.HDC);
SelectObject(DC,b);
SetBkMode(DC,TRANSPARENT);
adr:=pointer(GetWindowLong(Okno,0));
if (lpdis^.itemState and ods_Selected)=0 then i:=0 else i:=2;
if ZnajdzSymb(SymbBrk,WtoHEX(adr^[lpdis^.itemID+1]))<>-1 then i:=i+4;
SetTextColor(DC,Kolory[i]);
SetBkColor(DC,Kolory[i+1]);
br:=CreateSolidBrush(Kolory[i+1]);
FillRect(DC,R,br);
DeleteObject(br);
SendMessage(lpdis^.hwndItem,lb_GetText,lpdis^.itemID,longint(@buf));
TabbedTextOut(DC,0,0,buf,StrLen(buf),3,Tabul,0);
if (lpdis^.itemState and ods_Focus)<>0 then DrawFocusRect(DC,R);
BitBlt(lpdis^.HDC,lpdis^.rcItem.left,lpdis^.rcItem.top,R.right,R.bottom,DC,0,0,SrcCopy);
DeleteDC(DC);
DeleteObject(b);
end;
function FunInstrView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
var
Ins,Suw:HWnd;
adr:PAdresy;
off:word;
i:integer;
Info:PMeasureItemStruct;
begin
FunInstrView:=0;
case Kod_meldunku of
wm_Create : begin
GetMem(adr,40); {pamięć na tablicę adresów}
adr^[1]:=RejPC;
SetWindowLong(Okno,0,longint(adr));
Ins:=CreateWindow('KLASALISTB','',ws_Child or ws_Visible or lbs_HasStrings or
lbs_Notify or lbs_OwnerDrawFixed or lbs_UseTabStops or
lbs_WantKeyboardInput,120,0,319,320,Okno,500,hInstance,nil);
SendMessage(Ins,lb_SetTabStops,3,longint(@Tabul));
Suw:=CreateWindow('SCROLLBAR','',ws_Child or ws_Visible or sbs_LeftAlign or
sbs_Vert,440,0,16,304,Okno,501,hInstance,nil);
SetScrollRange(Suw,sb_Ctl,0,16383,true);
CreateWindow('BUTTON','',ws_Child or ws_Visible,440,304,16,16,Okno,
502,hInstance,nil);
SetWindowWord(Okno,4,0); {nr aktywnej linii}
CreateWindow('KLASAETYPC','',ws_Child or ws_Visible,0,0,119,320,Okno,
503,hInstance,nil);
end;
wm_Destroy : FreeMem(pointer(GetWindowLong(Okno,0)),40);
wm_VScroll : if runprog>0 then EnableWindow(GetDlgItem(Okno,501),false) else
begin
EnableWindow(GetDlgItem(Okno,501),true);
PrzewinInstr(Okno,wParam,LoWord(LParam),HWnd(HiWord(LParam)));
end;
wm_Command : case wParam of
500: if runprog=0 then
case HiWord(LParam) of
lbn_SelChange : SetWindowWord(Okno,4,SendMessage(LoWord(LParam),
lb_GetCurSel,0,0));
lbn_DblClk : DblClickInstr(Okno);
end;
502: if runprog=0 then SkokInstr(Okno);
us_OdnowWidok : begin
if (runprog>0) and (GetParent(Okno)=OknoInstr) then
LecimyInstr(Okno);
InvalidateRect(Okno,nil,false);
OdnowInstr(Okno);
UpdateWindow(Okno);
end;
us_OdnowCoTrzeba : LecimyInstr(Okno);
us_ZmienPulapke : begin
adr:=pointer(GetWindowLong(Okno,0));
off:=adr^[GetWindowWord(Okno,4)+1];
i:=ZnajdzSymb(SymbBrk,WtoHEX(off));
if i=-1 then
begin
StrPCopy(buforzn1,WtoHEX(off));
SymbBrk^.Insert(StrNew(buforzn1));
end
else SymbBrk^.AtDelete(i);
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
end;
us_PodajAdres0 : begin
adr:=pointer(GetWindowLong(Okno,0));
off:=adr^[GetWindowWord(Okno,4)+1];
SendMessage(GetParent(Klient),wm_Command,
us_PodajAdres1,off);
end;
end;
wm_VKeyToItem : if (runprog=0) and (HWnd(LoWord(LParam))=GetDlgItem(Okno,500)) then
begin
FunInstrView:=-1;
if (HiWord(LParam)=0) and (wParam=VK_UP) then
begin
SkokGora(Okno,GetDlgItem(Okno,501),false);
FunInstrView:=-2;
end;
if (HiWord(LParam)=19) and (wParam=VK_DOWN) then
begin
SkokDol(Okno,GetDlgItem(Okno,501),false);
FunInstrView:=-2;
end;
if wParam=VK_PRIOR then
begin
SkokSGora(Okno,GetDlgItem(Okno,501));
FunInstrView:=-2;
end;
if wParam=VK_NEXT then
begin
SkokSDol(Okno,GetDlgItem(Okno,501));
FunInstrView:=-2;
end;
if wParam=VK_RETURN then
begin
DblClickInstr(Okno);
FunInstrView:=-2;
end;
end;
wm_MeasureItem: begin
Info:=pointer(LParam);
Info^.itemWidth:=319;
Info^.itemHeight:=16;
FunInstrView:=1;
end;
wm_DrawItem: NarysujLinie(Okno,pointer(LParam));
else FunInstrView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure RysujEtyPC(Okno:HWnd);
var
Master:HWnd;
orgDC,DC,m:HDC;
Paint:TPaintStruct;
R:TRect;
b,bPC:HBitmap;
i,ile,n:integer;
adr:PAdresy;
s:string[63];
juz:boolean;
begin
orgDC:=BeginPaint(Okno,Paint);
b:=CreateCompatibleBitmap(orgDC,119,320);
DC:=CreateCompatibleDC(orgDC);
SelectObject(DC,b);
SelectObject(DC,GetStockObject(SYSTEM_FONT));
SetBkColor(DC,$00ffffff);
SetTextColor(DC,$000000ff);
SetRect(R,0,0,119,320);
FillRect(DC,R,GetStockObject(WHITE_BRUSH));
Master:=GetParent(Okno);
ile:=SendMessage(GetDlgItem(Master,500),lb_GetCount,0,0);
adr:=pointer(GetWindowLong(Master,0));
if SymbROM^.Count>0 then
begin
for i:=1 to ile do
begin
n:=ZnajdzSymb(SymbROM,WtoHEX(adr^[i]));
if n<>-1 then
begin
s:=Copy(StrPas(SymbROM^.At(n)),5,255)+':';
TextOut(DC,0,i*16-16,StrPCopy(buforzn1,s),Length(s));
end;
end;
end;
if (RejPC>=adr^[1]) and (RejPC<=adr^[ile]) then
begin
m:=CreateCompatibleDC(DC);
bPC:=LoadBitmap(hInstance,'PC');
SelectObject(m,bPC);
i:=1;
juz:=false;
repeat
if adr^[i]=RejPC then
begin
BitBlt(DC,103,i*16-16,16,13,m,0,0,SrcCopy);
juz:=true;
end;
Inc(i);
until juz or (i>ile);
DeleteDC(m);
DeleteObject(bPC);
end;
BitBlt(orgDC,0,0,119,320,DC,0,0,SrcCopy);
EndPaint(Okno,Paint);
DeleteDC(DC);
DeleteObject(b);
end;
function FunEtyPCView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
begin
FunEtyPCView:=0;
case Kod_meldunku of
wm_Paint : RysujEtyPC(Okno);
else FunEtyPCView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
function FunListb(Okno:HWnd;Kod_meldunku,wParam:word;LParam:longint):longint; EXPORT;
var buf:array[0..15] of char;
begin
if Kod_meldunku=wm_EraseBkgnd then
begin
GetClassName(GetParent(Okno),buf,15);
if (StrComp(StrUpper(buf),'KLASAINSTR')=0) and
(CallWindowProc(OrygLB.lpfnWndProc,Okno,lb_GetCount,0,0)<20) then
FunListb:=CallWindowProc(OrygLB.lpfnWndProc,Okno,Kod_meldunku,wParam,LParam);
end
else FunListb:=CallWindowProc(OrygLB.lpfnWndProc,Okno,Kod_meldunku,wParam,LParam);
end;
procedure OdnowPulapki(Okno:HWnd);
var
Brk:HWnd;
i,nr:integer;
s:string[40];
a:array[0..40] of char;
begin
Brk:=GetWindow(Okno,gw_Child);
SendMessage(Brk,wm_SetRedraw,0,0);
if SendMessage(Brk,lb_GetCount,0,0)<>0 then SendMessage(Brk,lb_ResetContent,0,0);
if SymbBrk^.Count>0 then
for i:=0 to SymbBrk^.Count-1 do
begin
s:=StrPas(SymbBrk^.At(i));
nr:=ZnajdzSymb(SymbROM,s);
if nr<>-1 then s:=s+#9+Copy(StrPas(SymbROM^.At(nr)),5,255);
StrPCopy(a,s);
SendMessage(Brk,lb_AddString,0,longint(@a));
end;
SendMessage(Brk,wm_SetRedraw,1,0);
end;
function DodajPulapke(Okno:HWnd;zmiana:boolean):boolean;
var
Brk:HWnd;
adr,j:word;
b:integer;
begin
Brk:=GetWindow(Okno,gw_Child);
if zmiana=false then buforzn1[0]:=#0;
b:=PokazDialog('OFFSET',@FunOffsetChg);
DodajPulapke:=true;
if b<>1 then Exit;
if wynik='' then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(66),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
adr:=HEXtoW(wynik);
if codeconv<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
StrPCopy(buforzn1,WtoHEX(adr));
DodajPulapke:=false;
if zmiana then Exit;
SymbBrk^.Insert(StrNew(buforzn1));
OdnowPulapki(Okno);
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
SetFocus(Brk);
j:=SendMessage(Brk,lb_GetCaretIndex,0,0);
SendMessage(Brk,lb_SetCurSel,j,0);
end;
procedure UsunPulapke(Okno:HWnd);
var
Brk:HWnd;
j:word;
begin
Brk:=GetWindow(Okno,gw_Child);
if SymbBrk^.Count=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
j:=SendMessage(Brk,lb_GetCaretIndex,0,0);
if SendMessage(Brk,lb_GetSel,j,0)=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
SendMessage(Brk,lb_DeleteString,j,0);
SymbBrk^.AtDelete(j);
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
SetFocus(Brk);
j:=SendMessage(Brk,lb_GetCaretIndex,0,0);
SendMessage(Brk,lb_SetCurSel,j,0);
end;
procedure ZmienPulapke(Okno:HWnd);
var
Brk:HWnd;
j:word;
Bufor:array[0..63] of char;
adres:string[4];
begin
Brk:=GetWindow(Okno,gw_Child);
if SymbBrk^.Count=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
j:=SendMessage(Brk,lb_GetCaretIndex,0,0);
if SendMessage(Brk,lb_GetSel,j,0)=0 then
begin
MessageBeep(mb_IconHand);
Exit;
end;
SendMessage(Brk,lb_GetText,j,longint(@Bufor));
adres:=Copy(StrPas(Bufor),1,4);
StrPCopy(buforzn1,adres);
if DodajPulapke(Okno,true) then
begin
SetFocus(Brk);
j:=SendMessage(Brk,lb_GetCaretIndex,0,0);
SendMessage(Brk,lb_SetCurSel,j,0);
Exit;
end;
SymbBrk^.AtDelete(j);
SymbBrk^.Insert(StrNew(buforzn1));
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
SetFocus(Brk);
j:=SendMessage(Brk,lb_GetCaretIndex,0,0);
SendMessage(Brk,lb_SetCurSel,j,0);
end;
procedure UsunAllPulapki(Okno:HWnd);
begin
if SymbBrk^.Count=0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(Okno,Napis1(68),'Debugger 8051',mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if BWCCMessageBox(Okno,Napis1(69),'Debugger 8051',mb_OKCancel or mb_TaskModal or
mb_IconQuestion)<>1 then Exit;
SymbBrk^.DeleteAll;
OdrysujOkna(0); {Instr}
OdrysujOkna(8); {Brk}
end;
function FunBreakView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
const TabuS:integer=23;
var
Brk:HWnd;
i:word;
begin
FunBreakView:=0;
case Kod_meldunku of
wm_Create : begin
Brk:=CreateWindow('LISTBOX','',ws_Child or ws_Visible or lbs_Standard
or lbs_UseTabStops or lbs_WantKeyboardInput,0,0,270,226,Okno,500,
hInstance,nil);
SendMessage(Brk,lb_SetTabStops,1,longint(@TabuS));
for i:=0 to 3 do
CreateWindow('BUTTON',Napis1(60+i),ws_Child or ws_Visible,
271,i*25,95,25,Okno,505+i,hInstance,nil);
OdnowPulapki(Okno);
end;
wm_Command : case wParam of
500: if HiWord(LParam)=lbn_DblClk then ZmienPulapke(Okno);
505 : DodajPulapke(Okno,false);
506 : UsunPulapke(Okno);
507 : UsunAllPulapki(Okno);
508 : ZmienPulapke(Okno);
us_ZmianaJez : ZmienJezykSymb(Okno);
us_OdnowWidok : if runprog=0 then
begin
OdnowPulapki(Okno);
UpdateWindow(Okno);
end;
end;
wm_VKeyToItem : if (HWnd(LoWord(LParam))=GetDlgItem(Okno,500)) and (wParam=VK_RETURN)
then begin
ZmienPulapke(Okno);
FunBreakView:=-2;
end else FunBreakView:=-1;
else FunBreakView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure RysujPorty(Okno:HWnd;auto:boolean);
var
Paint:TPaintStruct;
DC:HDC;
re,gr:HBrush;
c,b,i:byte;
R:TRect;
t:PPorty;
nazwa:array[0..6] of char;
begin
if auto then DC:=BeginPaint(Okno,Paint) else DC:=GetDC(Okno);
re:=CreateSolidBrush($00ffff00);
gr:=GetStockObject(GRAY_BRUSH);
SelectObject(DC,GetStockObject(OEM_FIXED_FONT));
SetBkColor(DC,$00c0c0c0);
t:=pointer(GetWindowLong(Okno,0));
for b:=0 to 7 do
begin
StrPCopy(nazwa,Copy(BtoREG(t^[b].a)+' ',1,5));
TextOut(DC,3,2+15*b,nazwa,StrLen(nazwa));
if t^[b].p<>0 then StrPCopy(nazwa,WtoHEX(t^[b].p)+'h') else StrCopy(nazwa,' - ');
TextOut(DC,110,2+15*b,nazwa,5);
SetRect(R,57,3+b*15,62,13+b*15);
c:=Mem[selRAMInt:t^[b].a];
if t^[b].p<>0 then Port[t^[b].p]:=c;
for i:=0 to 7 do
begin
if (c and 128)=0 then FillRect(DC,R,gr) else FillRect(DC,R,re);
OffsetRect(R,6,0);
c:=c shl 1;
end;
end;
DeleteObject(re);
if auto then EndPaint(Okno,Paint) else ReleaseDC(Okno,DC);
end;
procedure ZmienAdresP(Okno:HWnd;t:PPorty;n:byte);
var
b:integer;
a:word;
begin
b:=PokazDialog('ZMIENADRP',@FunOffset);
if b<>1 then Exit;
if wynik='' then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(73),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
a:=HEXtoW(wynik);
if codeconv<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
t^[n].p:=a;
InvalidateRect(Okno,nil,false);
end;
procedure DblClickPorty(Okno:HWnd;x,y:word);
var
t:PPorty;
n,adr:byte;
b:integer;
begin
t:=pointer(GetWindowLong(Okno,0));
n:=(y-3) div 15;
if n>7 then Exit;
if x>110 then ZmienAdresP(Okno,t,n);
if x>50 then Exit;
buforzn1[0]:=#0; buforzn2[0]:=#0;
b:=PokazDialog('ZMIENPORT',@FunSymbol);
if b<>1 then Exit;
if (wynik='') and (wynik1='') then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(71),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
if wynik<>'' then
begin
adr:=JestRej(UpCaseStr(wynik));
if adr=255 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(72),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
end
else
begin
adr:=HEXtoB(wynik1);
if codeconv<>0 then
begin
MessageBeep(mb_IconHand);
BWCCMessageBox(0,Napis1(1),Napis2(2),mb_OK or mb_TaskModal or mb_IconExclamation);
Exit;
end;
end;
t^[n].a:=adr;
if (adr<>$80) and (adr<>$90) and (adr<>$a0) and (adr<>$b0) then t^[n].p:=0;
InvalidateRect(Okno,nil,false);
end;
procedure ZmienBitPortu(Okno:HWnd;x,y:word);
var
t:PPorty;
n,adr:byte;
begin
if (y<3) or (y>118) or (x<57) or (x>104) then Exit;
n:=(y-3) div 15;
if n>7 then Exit;
x:=(x-57) div 6;
if x>7 then Exit;
t:=pointer(GetWindowLong(Okno,0));
adr:=t^[n].a;
Mem[selRAMInt:adr]:=Mem[selRAMInt:adr] xor Maski[7-x];
InvalidateRect(Okno,nil,false);
OdrysujOkna(1); {Rej}
OdrysujOkna(2); {Bit}
OdrysujOkna(5); {HEX RAM Int}
OdrysujOkna(6); {Symb}
OdrysujOkna(9); {Porty}
end;
function FunPortyView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
const PortyDefault:TPorty=((a:$80;p:0),(a:$90;p:0),(a:$a0;p:0),(a:$b0;p:0),
(a:$e0;p:0),(a:$f0;p:0),(a:$83;p:0),(a:$82;p:0));
var t:PPorty;
begin
FunPortyView:=0;
case Kod_meldunku of
wm_Create : begin
GetMem(t,SizeOf(TPorty));
t^:=PortyDefault;
SetWindowLong(Okno,0,longint(t));
end;
wm_Destroy : FreeMem(pointer(GetWindowLong(Okno,0)),SizeOf(TPorty));
wm_Paint : RysujPorty(Okno,true);
wm_LButtonDblClk : DblClickPorty(Okno,LoWord(LParam),HiWord(LParam));
wm_LButtonDown : ZmienBitPortu(Okno,LoWord(LParam),HiWord(LParam));
wm_Command : if wParam=us_OdnowWidok then RysujPorty(Okno,false);
else FunPortyView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
function FunCalcView(Okno:HWnd;Kod_meldunku,WParam:word;LParam:longint):longint; EXPORT;
var
a,a1,a2,a3:array[0..40] of char;
b:PChar;
tmp:string[40];
zn:char;
ii:longint;
liczba:word;
code:integer;
ok:boolean;
begin
FunCalcView:=0;
case Kod_meldunku of
wm_Create : begin
CreateWindow('EDIT','',ws_Child or ws_Visible or ws_Border or
es_Left,0,0,DialogSzer(74)-2,DialogWys(10),Okno,500,hInstance,nil);
CreateWindow('EDIT','',ws_Child or ws_Visible or ws_Border or
ws_Disabled or es_Left or es_ReadOnly,DialogSzer(14),DialogWys(10),
DialogSzer(60)-2,DialogWys(10),Okno,501,hInstance,nil);
CreateWindow('EDIT','',ws_Child or ws_Visible or ws_Border or
ws_Disabled or es_Left or es_ReadOnly,DialogSzer(14),DialogWys(20),
DialogSzer(60)-2,DialogWys(10),Okno,502,hInstance,nil);
CreateWindow('EDIT','',ws_Child or ws_Visible or ws_Border or
ws_Disabled or es_Left or es_ReadOnly,DialogSzer(14),DialogWys(30),
DialogSzer(60)-2,DialogWys(10)-1,Okno,503,hInstance,nil);
CreateWindow('STATIC','dec',ws_Child or ws_Visible or ss_Left,
0,DialogWys(10),DialogSzer(14),DialogWys(10),Okno,504,hInstance,nil);
CreateWindow('STATIC','hex',ws_Child or ws_Visible or ss_Left,
0,DialogWys(20),DialogSzer(14),DialogWys(10),Okno,505,hInstance,nil);
CreateWindow('STATIC','bin',ws_Child or ws_Visible or ss_Left,
0,DialogWys(30),DialogSzer(14),DialogWys(10),Okno,506,hInstance,nil);
end;
wm_Command : case wParam of
500: if HiWord(LParam)=en_Change then
if GetDlgItemText(Okno,500,a,40)<>0 then
begin
zn:=a[StrLen(a)-1];
ok:=true;
case zn of
'0'..'9': begin
b:=@a;
while b^='0' do Inc(b);
if b^=#0 then Dec(b);
Val(StrPas(b),ii,code);
if (StrLen(b)>5) or (code<>0) or (ii<0) or
(ii>65535) then ok:=false else liczba:=ii;
end;
'h','H': begin
a[StrLen(a)-1]:=#0;
b:=@a;
while b^='0' do Inc(b);
if b^=#0 then Dec(b);
Val('$'+StrPas(b),ii,code);
if (StrLen(b)>4) or (code<>0) or (ii<0) or
(ii>65535) then ok:=false else liczba:=ii;
end;
'b','B': begin
a[StrLen(a)-1]:=#0;
b:=@a;
while b^='0' do Inc(b);
if b^=#0 then Dec(b);
liczba:=BINtoW(StrPas(b));
if (StrLen(b)>16) or (codeconv<>0) then ok:=false;
end;
else ok:=false;
end;
if not ok then
begin
StrCopy(a1,'- - -');
StrCopy(a2,'- - -');
StrCopy(a3,'- - -');
end else
begin
Str(liczba,tmp);
StrPCopy(a1,tmp);
StrPCopy(a2,WtoHEX(liczba));
StrPCopy(a3,WtoBIN(liczba));
end;
SetDlgItemText(Okno,501,a1);
SetDlgItemText(Okno,502,a2);
SetDlgItemText(Okno,503,a3);
end else
begin
a[0]:=#0;
SetDlgItemText(Okno,501,a);
SetDlgItemText(Okno,502,a);
SetDlgItemText(Okno,503,a);
end;
end;
else FunCalcView:=DefWindowProc(Okno,Kod_meldunku,WParam,LParam);
end;
end;
procedure RysujTerminal(Okno:HWnd;auto:boolean);
var
Paint:TPaintStruct;
DC:HDC;
w:word;
txt:PTerminalTekst;
a:array[0..80] of char;
begin
if auto then DC:=BeginPaint(Okno,Paint) else DC:=GetDC(Okno);
SelectObject(DC,CzcionkaOEM);
SetBkMode(DC,OPAQUE);
SetTextColor(DC,$00ffffff);
SetBkColor(DC,0);
txt:=pointer(GetWindowLong(Okno,0));
for w:=0 to 24 do
begin
Move(txt^[w,0],a,80);
a[80]:=#0;
TextOut(DC,0,w*FontOEMwys,a,80);
end;
if auto then EndPaint(Okno,Paint) else ReleaseDC(Okno,DC);
end;
procedure NowyZnakTerm(Okno:HWnd;co:byte);
var
txt:PTerminalTekst;
R:TRect;
xy,x,y,ox,oy,maxx,maxy:word;
DC:HDC;
jeden:boolean;
begin
GetClientRect(Okno,R);
maxx:=((R.right+1) div FontOEMszer)-1; maxy:=((R.bottom+1) div FontOEMwys)-1;
txt:=pointer(GetWindowLong(Okno,0));
xy:=GetWindowWord(Okno,4);
x:=Lo(xy); y:=Hi(xy);
if x>maxx then x:=maxx;
if y>maxy then y:=maxy;
jeden:=false;
case co of
13: x:=0;
10: if y0 then Dec(x) else if y>0 then begin Dec(y); x:=maxx; end;
else
begin
ox:=x; oy:=y;
if co=0 then co:=32; {spacja zamiast #0}
txt^[y,x]:=char(co);
if x