{$M $800,0,0 }   { 2K stack, no heap }
{ Ten program po naci˜ni©ciu ` powoduje zapisanie rejestr¢w }
{ karty VGA w pliku dump.txt }
uses Crt, Dos;
const
  title1:String[27]=('Registers of CRT Controller');
  title2:String[33]=('Registers of Attribute Controller');
  title3:String[32]=('Registers of Graphics Controller');
  title4:String[22]=('Registers of Sequencer');
  title5:String[15]=('Register of VGA');
  eol:Word=$0A0D;
var
  number:String[15];
  KbdIntVec : Procedure;
  Control:Byte;
  f1:File;
  pom_nr_reg,nr_reg,Value,Value1:Byte;
  SValue:String[4];
{$F+}

procedure Keyclick; interrupt;
begin
  if Port[$60]=41 then
    { Only click when key is pressed }
    begin
    Control:=Port[$61];
    Port[$61]:=Control or $80;
    Port[$61]:=Control; { Regeneracja sterownika }
    Sound(5000);
    Assign(f1,'dump.txt');
    Rewrite(f1,1);

{rejestry CRT Controller}
    BlockWrite(f1,Title1[1],27);BlockWrite(f1,Eol,2);
    Number:='Reg$00 = ';nr_reg:=0;SValue:='$00';
    Repeat
    BlockWrite(f1,Number[1],Length(Number));
    asm
      mov dx,3D4h
      mov al,nr_reg
      out dx,al
      inc dx
      in  al,dx
      mov value,al
    end;
      IF (Value DIV 16)<10 THEN SValue[2]:=Chr((Value DIV 16)+Ord('0')) ELSE SValue[2]:=Chr((Value DIV 16)-10+Ord('A'));
      Value:=Value-((Value DIV 16)*16);
      IF Value<10 THEN SValue[3]:=Chr(Value+Ord('0')) ELSE SValue[3]:=Chr(Value-10+Ord('A'));
      BlockWrite(f1,SValue[1],Length(SValue));
      BlockWrite(f1,Eol,2);
      inc(nr_reg);
      IF (nr_reg DIV 16)<10 THEN Number[5]:=Chr((nr_reg DIV 16)+Ord('0')) ELSE Number[5]:=Chr((nr_reg DIV 16)-10+Ord('A'));
      pom_nr_reg:=nr_reg-((nr_reg DIV 16)*16);
      IF pom_nr_reg<10 THEN Number[6]:=Chr(pom_nr_reg+Ord('0')) ELSE Number[6]:=Chr(pom_nr_reg-10+Ord('A'));
    Until nr_reg=25;

{rejestry Attribute Controller}
    BlockWrite(f1,Eol,2);
    BlockWrite(f1,Title2[1],33);BlockWrite(f1,Eol,2);
    Number:='Reg$00 = ';nr_reg:=0;SValue:='$00';
    Repeat
    BlockWrite(f1,Number[1],Length(Number));
    asm
      mov dx,3DAh
      in  al,dx
      mov dx,3C0h
      mov al,nr_reg
      out dx,al
      inc dx
      in  al,dx
      mov value,al
      mov dx,3DAh
      in  al,dx
      mov dx,3C0h
      mov al,20h
      out dx,al
    end;
      IF (Value DIV 16)<10 THEN SValue[2]:=Chr((Value DIV 16)+Ord('0')) ELSE SValue[2]:=Chr((Value DIV 16)-10+Ord('A'));
      Value:=Value-((Value DIV 16)*16);
      IF Value<10 THEN SValue[3]:=Chr(Value+Ord('0')) ELSE SValue[3]:=Chr(Value-10+Ord('A'));
      BlockWrite(f1,SValue[1],Length(SValue));
      BlockWrite(f1,Eol,2);
      inc(nr_reg);
      IF (nr_reg DIV 16)<10 THEN Number[5]:=Chr((nr_reg DIV 16)+Ord('0')) ELSE Number[5]:=Chr((nr_reg DIV 16)-10+Ord('A'));
      pom_nr_reg:=nr_reg-((nr_reg DIV 16)*16);
      IF pom_nr_reg<10 THEN Number[6]:=Chr(pom_nr_reg+Ord('0')) ELSE Number[6]:=Chr(pom_nr_reg-10+Ord('A'));
    Until nr_reg=21;

{rejestry Graphics Controller}
    BlockWrite(f1,Eol,2);
    BlockWrite(f1,Title3[1],32);BlockWrite(f1,Eol,2);
    Number:='Reg$00 = ';nr_reg:=0;SValue:='$00';
    Repeat
    BlockWrite(f1,Number[1],Length(Number));
    asm
      mov dx,3CEh
      mov al,nr_reg
      out dx,al
      inc dx
      in  al,dx
      mov value,al
    end;
      IF (Value DIV 16)<10 THEN SValue[2]:=Chr((Value DIV 16)+Ord('0')) ELSE SValue[2]:=Chr((Value DIV 16)-10+Ord('A'));
      Value:=Value-((Value DIV 16)*16);
      IF Value<10 THEN SValue[3]:=Chr(Value+Ord('0')) ELSE SValue[3]:=Chr(Value-10+Ord('A'));
      BlockWrite(f1,SValue[1],Length(SValue));
      BlockWrite(f1,Eol,2);
      inc(nr_reg);
      IF (nr_reg DIV 16)<10 THEN Number[5]:=Chr((nr_reg DIV 16)+Ord('0')) ELSE Number[5]:=Chr((nr_reg DIV 16)-10+Ord('A'));
      pom_nr_reg:=nr_reg-((nr_reg DIV 16)*16);
      IF pom_nr_reg<10 THEN Number[6]:=Chr(pom_nr_reg+Ord('0')) ELSE Number[6]:=Chr(pom_nr_reg-10+Ord('A'));
    Until nr_reg=9;

{rejestry Sequencer}
    BlockWrite(f1,Eol,2);
    BlockWrite(f1,Title4[1],22);BlockWrite(f1,Eol,2);
    Number:='Reg$00 = ';nr_reg:=0;SValue:='$00';
    Repeat
    BlockWrite(f1,Number[1],Length(Number));
    asm
      mov dx,3C4h
      mov al,nr_reg
      out dx,al
      inc dx
      in  al,dx
      mov value,al
    end;
      IF (Value DIV 16)<10 THEN SValue[2]:=Chr((Value DIV 16)+Ord('0')) ELSE SValue[2]:=Chr((Value DIV 16)-10+Ord('A'));
      Value:=Value-((Value DIV 16)*16);
      IF Value<10 THEN SValue[3]:=Chr(Value+Ord('0')) ELSE SValue[3]:=Chr(Value-10+Ord('A'));
      BlockWrite(f1,SValue[1],Length(SValue));
      BlockWrite(f1,Eol,2);
      inc(nr_reg);
      IF (nr_reg DIV 16)<10 THEN Number[5]:=Chr((nr_reg DIV 16)+Ord('0')) ELSE Number[5]:=Chr((nr_reg DIV 16)-10+Ord('A'));
      pom_nr_reg:=nr_reg-((nr_reg DIV 16)*16);
      IF pom_nr_reg<10 THEN Number[6]:=Chr(pom_nr_reg+Ord('0')) ELSE Number[6]:=Chr(pom_nr_reg-10+Ord('A'));
    Until nr_reg=5;

{rejestr VGA}
    BlockWrite(f1,Eol,2);
    BlockWrite(f1,Title5[1],15);BlockWrite(f1,Eol,2);
    Number:='Reg$3C2/$3CC = ';nr_reg:=0;SValue:='$00';
    BlockWrite(f1,Number[1],Length(Number));
    asm
      mov dx,3CCh
      in  al,dx
      mov value,al
    end;
      IF (Value DIV 16)<10 THEN SValue[2]:=Chr((Value DIV 16)+Ord('0')) ELSE SValue[2]:=Chr((Value DIV 16)-10+Ord('A'));
      Value:=Value-((Value DIV 16)*16);
      IF Value<10 THEN SValue[3]:=Chr(Value+Ord('0')) ELSE SValue[3]:=Chr(Value-10+Ord('A'));
      BlockWrite(f1,SValue[1],Length(SValue));
      BlockWrite(f1,Eol,2);

    Close(f1);
    Delay(1);
    Nosound;
    end;
    Port[$20]:=$20;
end;
{$F-}
begin
  { Insert ISR into keyboard chain }
  GetIntVec($8,@KbdIntVec);
  SetIntVec($8,Addr(Keyclick));
  Keep(0); { Terminate, stay resident }
end.

