{*Determiner si la carte est couleur ou n&b (si mem[0040:004E]=3B4, n&b;
  couleur sinon. Vseg:=$B000 si n&b; Vseg:=B800 sinon.)
 *Putchar(ligne,col,char,coul); coul:7-4:fond;3-0:char.
 *Highlight(ligne, colstart, colend); }

Unit U2580V10;

Interface

Const Normal = $07;
      Clair  = $0F;
      Noir   = $00;

      Bleu         = $01;
      Vert         = $02;
      Cyan         = $03;
      Rouge        = $04;
      Magenta      = $05;
      Brun         = $06;
      GrisClair    = $07;
      GrisFonce    = $08;
      BleuClair    = $09;
      VertClair    = $0A;
      CyanClair    = $0B;
      RougeClair   = $0C;
      MagentaClair = $0D;
      Jaune        = $0E;
      Blanc        = $0F;

Var   Vseg         : word;

Procedure Putchar(ligne,colonne:byte;ch:char;attrib:byte);
Function  Getchar(ligne,colonne:byte):word;
Procedure Invligne(ligne,colstart,colend:byte);
Procedure Cls;
Procedure Putstr(ligne,col:byte;str:string;attrib:byte);
Procedure clrlgn(ligne:byte);
Procedure curson;
Procedure cursoff;
Function tohexstr(nombre:longint) : string;


Implementation
Var {Sauveecran  :array[0..2000] of Word;}
    Sauvesortie :pointer;
    I           :word;

Procedure Putchar(ligne,colonne:byte;ch:char;attrib:byte);
Begin
 memw[Vseg:ligne*160+colonne*2]:=attrib shl 8 + ord(ch);
End;

Function Getchar(ligne,colonne:byte):word;
Begin
 Getchar:=memw[Vseg:ligne*160+colonne*2];
End;

Procedure invligne(ligne,colstart,colend:byte);
Var H,L,A,I,attrib:byte;
    ch:word;
Begin
 If colend < colstart then
 Begin
  A:=colend;
  colend:=colstart;
  colstart:=A;
 End;
 For I:=colstart to colend do
 Begin
  ch:=Getchar(ligne,I);
  L:=(ch shr 8) and $F;
  H:=ch shr 12;
  ch:=ch and $FF;
  Putchar(ligne,I,chr(ch),H+L shl 4);
 End;
End;

Procedure Cls;
Var I:word;
Begin
For I:=0 to 2000 do memw[Vseg:2*I]:=$0720;
End;

Procedure Putstr(ligne,col:byte;str:string;attrib:byte);
Var I:byte;
Begin
For I:=1 to length(str) do Putchar(ligne,col+I-1,str[I],attrib);
End;

Procedure clrlgn(ligne:byte);
Var I:byte;
Begin
 For I:=0 to 79 do putchar(ligne,I,' ',normal);
End;

Procedure curson; assembler;
asm
 mov ah,01
 mov cx,$0607
 int $10
end;

Procedure cursoff; assembler;
asm
 mov ah,01
 mov cx,$1400
 int $10
end;

Function tohexstr(nombre:longint):string;
Var S,St : string;
    Q,R  : longint;
Begin
 Q:=nombre;
 S:='';
 Repeat
  R:= Q mod 16;
  Q:= Q div 16;
  If R<10 then S:=S+chr(ord('0')+R) else S:=S+chr(ord('A')+R-10);
 Until Q=0;
 St:='';
 For R:=length(S) downto 1 do St:=St+S[R];
 tohexstr:=St;
End;


{$F+}
Procedure Masortie; {$F-}
Var I:word;
Begin
{For I:=1 to 2000 do memw[Vseg:2*I]:=Sauveecran[I];}
Exitproc:=sauvesortie;
End;


Begin
If memw[$40:$4E]=$3b4 then Vseg:=$B000 else Vseg:=$B800;
{For I:=1 to 2000 do Sauveecran[I]:=memw[Vseg:2*I];}
sauvesortie:=Exitproc;
Exitproc:=@Masortie;
End.