< -->

Program OutputPorts;
{$D-}
Uses Graph, CRT;
{=============}
Function GetPortByte(NmbPort:Word):Byte;Assembler;
asm
  mov dx, word ptr NmbPort
  in  al, dx
end;
{=============}
Function HexB(b : Byte) : String;
const
  HD: array[0..15] of Char = ('0','1','2','3','4','5','6','7',
  '8','9','A','B','C','D','E','F');
begin
  HexB := HD[b shr 4] + HD[b and $F];
end;
Function HexW(w:WORD) : String;
begin
  HexW := HexB(Hi(w))+HexB(Lo(w));
end;
Procedure ClrScr; Assembler;
asm
 mov  ax, 3
 int  $10
end;
{------------------}
Procedure PutCursor(xx, yy : Byte);Assembler;
asm
   mov ah, 2
   mov dh, Byte Ptr yy
   mov dl, Byte Ptr xx
   dec dh
   dec dl
   mov bh, 0
   int $10
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=}
Procedure Delay(V, W : Word);
begin
 asm
  @1:
    mov      cx, Word Ptr V
    mov      dx, Word Ptr W
    mov      ah, $86
    int      $15
    jc       @1
 end;
end;
{----------------}
Procedure ResetTimer;Assembler;
asm
    mov      cx, 0
    mov      dx, 1
    mov      ah, $86
    int      $15
    jnc       @1
    mov ah, 83h
    mov al, 1
    int 15h
@1:
end;
{------------------}
Function ReadKey : Char; Assembler;
asm
   mov ah, 07h
   int 21h
end;
{------------------------}
Function KeyPressed : Boolean;Assembler;
asm
 mov ah, $0B
 int $21
end;
{------------------}
Procedure CursorOff;Assembler;
asm
 mov ah, 1
 mov ch, $20
 int $10
end;
{------------------}
Procedure CursorOn;Assembler;
asm
 mov ah, 1
 mov ch, 6
 mov cl, 7
 int $10
end;
{------------------}
Procedure PutChr(C:Byte; Col : Byte);
begin
 asm
   mov ah, $09
   mov bh, 0
   mov bl, Byte Ptr Col
   mov al, Byte ptr C
   mov cx, 1
   int $10
 end;
end;
Procedure PortTable(BegPort : Word);
var
  i, j, k : Word;
const
  Npr = 9;
begin
  ClrScr;
  CursorOff;
  for j := 0 to 7 do
  begin
    PutCursor(1,j*3+1);
    for i := BegPort to BegPort+Npr do
      Write(HexW(10*j+i)+'h   ');
  end;
  While True do
  begin
   if KeyPressed then if ReadKey=#27 then Break;
    for j := 0 to 7 do
    begin
     for i := BegPort to BegPort+Npr do
       begin
         k := 10*(j-1)+i;
         Write(HexB(GetPortByte(k))+'h     ');
       end;
     PutCursor(1,j*3+2);
    end;
{   Delay(1, 00000);}
  end;
  CursorOn;
end;
Procedure PortView(k : Word);
var
  Cp, C : Byte;
  x, y, pl : Byte;
begin
  ClrScr;
  CursorOff;
  PutCursor(11, 1);
  Write('Порт ', HexW(k)+'h ');
  C := GetPortByte(k);
  x := 1;
  y := 2;
  pl := 5;
  PutCursor(1, 1);
  Write(HexB(GetPortByte(k))+'h ');
  PutCursor(x, y);
  PutChr(C, $08);
  While True do
  begin
   Cp := C;
   C := GetPortByte(k);
   if C <> Cp then
   begin
     if pl = 1 then pl := 5 else pl := 1;
     PutCursor(pl, 1);
     Write(HexB(C)+'h ');
     PutCursor(x, y);
     PutChr(C, $08);
     inc(x);
     if x > 80 then
     begin
       x := 1;
       inc(y);
     end;
     if y > 25 then y := 2;
   end;
{   Delay(0, 20000);}
   if KeyPressed then if ReadKey=#27 then Break;
  end;
  CursorOn;
end;
Procedure OscilloPort(Npr : Word; Mode : Boolean);
var
  i : Word;
  C, Cp : Byte;
  Ch : Char;
begin
  ClearDevice;
  While Keypressed do ReadKey;
  SetColor(LightGray);
  i := 0;
  C:=GetPortByte(Npr);
  MoveTo(i, 480-Round(C*1.875));
  While True do
   begin
    Cp := C;
    C:=GetPortByte(Npr);
    if KeyPressed then if ReadKey=#27 then Break;
    if C<>Cp then
    begin
      SetColor(Black);
      Line(i, 0, i, 639);
      SetColor(LightGray);
      case Mode of
       False:
         LineTo(i, 480-Round(C*1.875));
       True:
         PutPixel(i, 480-Round(C*1.875), LightRed);
       end;
      inc(i);
      if i >=639 then
      begin
       SetColor(Black);
       Line(i, 0, i, 639);
       SetColor(LightGray);
       i := 0;
       C:=GetPortByte(Npr);
       MoveTo(i, 480-Round(C*1.875));
      end;
    end;
   end;
  While Keypressed do Ch:=ReadKey;
end;
Function WordByAddress(Segm, Ofs : Word) : Word;Assembler;
asm
  push ds
  mov ax, word ptr Segm
  mov ds, ax
  mov bx, Ofs
  mov ax, word ptr [bx]
  pop ds
end;
{-=-=-=-=-=--=-}
var
  i, j, k : Word;
  C, Cp : Byte;
  D ,R : Integer;
  S : String;
  NmbsPortAr : Array[1..200] of Word;
  VarPortAr: Array[1..200] of Word;
  N : Word;
  Mode : Boolean;
begin
  ResetTimer;
  ClrScr;
{  WriteLn('Подождите, ищу максимальное число портов...');
  N := 0;
  for i := 1 to 100 do
  begin
   j := 0;
   for k := 0 to $FFFF do
    begin
     C := GetPortByte(k);
     if (C<>$FF) and ((C<>0) or (GetPortByte(k)<>0) or (GetPortByte(k)<>0)) then
     begin
       inc(j);
       NmbsPortAr[j]:=k;
     end;
    end;
    if N < j then N := j;
  PutCursor(1, 2);
  WriteLn('Всего таких портов: ', N);
  end;
  WriteLn('Подождите, составляю таблицу для ', N, ' портов...');
  for i := 1 to N do Write(HexW(NmbsPortAr[i])+'h ' : 8);
  WriteLn;
  WriteLn('Ищу изменчивые порты...');
  k := 0;
  for i := 1 to N do
    begin
     C := GetPortByte(NmbsPortAr[i]);
     for j := 0 to 65535 do
     begin
      Cp := C;
      C := GetPortByte(NmbsPortAr[i]);
      if C<>Cp then
      begin
       inc(k);
       VarPortAr[k]:=NmbsPortAr[i];
       Break;
      end;
     end;
    end;
  for i := 1 to k do Write(HexW(VarPortAr[i])+'h ' : 8);
  WriteLn;
  WriteLn(k, ' штук');
  ReadKey;}
  Repeat
{  ReadLn(j, Byte(Mode));}
{  k := $42;}
{  Delay(5, 60000);}
{  PortTable(j);
  PortView(j);}
{  k := $0;}
{  k := WordByAddress($0040,$0000);}
  D := Detect;
  InitGraph(D, R, '');
  SetColor(Green);
  i := 0;
  While True do
  begin
   j := 0;
   for k := 0 to $FFFF do
    begin
     C := GetPortByte(k);
     if (C<>$FF) and ((C<>0) or (GetPortByte(k)<>0) or (GetPortByte(k)<>0)) then
     begin
       inc(j);
     end;
    end;
   if i >= 639 then
   begin
     i := 0;
     SetColor(Black);
     Line(0, 0, 0, 639);
     MoveTo(i, 700-(j-90)*20);
   end;
   inc(i);
   SetColor(Black);
   Line(i, 0, i, 639);
   SetColor(Green);
   LineTo(i, 700-(j-90)*20);
   PutPixel(i, 700-(j-90)*20, Yellow);
   if (i mod 30=0) then
   begin
     SetColor(LightRed);
     Str(j, S);
     OutText(S);
     MoveTo(i, 700-(j-90)*20);
   end;
    if Keypressed then if ReadKey = #27 then Break;
  end;
{  C := GetPortByte($60);
  Cp := GetPortByte($60);
  While C = Cp do Cp := GetPortByte($60);
  k := Cp;
  k := k shl 2 + C;
  Sound(k);}
  OscilloPort({^$40-$43}1016, Mode);
{  NoSound;}
  CloseGraph;
   if Keypressed then if ReadKey = #27 then Break;
  Until {j =$FFFF}KeyPressed;
end.

Назад