home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / ktools / source / utextscr.pas < prev    next >
Pascal/Delphi Source File  |  1994-11-11  |  7KB  |  371 lines

  1. Unit UTextScr;
  2. { gestion de l'écran en mode texte }
  3. { K.B. octobre 1994 }
  4.  
  5. INTERFACE
  6.  
  7. Uses Dos;
  8.  
  9. Const
  10.  { Constantes définissant le curseur texte }
  11.  BlankCursor  = $2000;
  12.  NormalCursor = $0607;
  13.  CarreCursor  = $0407;
  14.  RectCursor   = $0107;
  15.  
  16. Const
  17.  { Constantes pour cadres }
  18.  HGS='┌'; HGD='╔'; HGM='╒';
  19.  THS='─'; THD='═';
  20.  TVS='│'; TVD='║';
  21.  HDS='┐'; HDD='╗'; HDM='╕';
  22.  BGS='└'; BGD='╚'; BGM='╘';
  23.  BDS='┘'; BDD='╝'; BDM='╛';
  24.  SDS='├'; SDD='╠'; SDM='╞';
  25.  SGS='┤'; SGD='╣'; SGM='╡';
  26.  CrS='┼'; CrD='╬'; CrM='╪';
  27.  TTS='┬'; TTD='╦'; TTM='╤';
  28.  TIS='┴'; TID='╩'; TIM='╧';
  29.  
  30. Type
  31.  TCursorState=record
  32.   Typ: Word;
  33.   x,y:Byte;
  34.   End;
  35.  
  36.  PWordBuffer=^TWordBuffer;
  37.  TWordBuffer=Array[0..2047] of Word;    { type mémoire écran }
  38.  
  39. Var
  40.  { tableau pointant sur 4 pages de la mémoire écran }
  41.  Screen  : array[0..3] of TWordBuffer Absolute $B800:0000;
  42.  PageCourante : Byte;   { Page écran utilisée }
  43.  
  44. { Couleurs }
  45.  
  46. Procedure ToggleBlink(OnOff:boolean);
  47.  
  48. { Ecran texte }
  49.  
  50. Procedure SetActivePage(Page:Byte);
  51.  
  52. Procedure ScrollWindowUp(NoLines,Attrib,ColUL,RowUL,ColLR,RowLR:Byte);
  53.  
  54. Procedure ScrollWindowDn(NoLines,Attrib,ColUL,RowUL,ColLR,RowLR:Byte);
  55.  
  56. Function  GetCharAttrib:Word;
  57. { renvoie le caractère et la couleur de la position courante }
  58.  
  59. Procedure PutCharAttrib(CharAttrib:Word; NbChar:Word);
  60. { écrit NbChar caractères Char avec la couleur Attrib }
  61.  
  62. Procedure WriteXY(attrib,X,Y:Byte;S:String);
  63. { écrit S à la position (X,Y) avec la couleur attrib }
  64.  
  65. Procedure WriteXYCh(attrib,X,Y,c:Byte);
  66.  
  67. Procedure FillScreen(CharAttrib:Word);
  68. { remplit l'écran }
  69.  
  70. Procedure CopyPage(n1,n2:Byte);
  71. { copie de la page écran n1 dans la page écran n2 }
  72.  
  73. { Fenêtres }
  74.  
  75. Procedure Frame(X1,Y1,X2,Y2,c:Byte;Title:String);
  76.  
  77. Procedure Shadow (X1,Y1,X2,Y2,cc:Byte);
  78. { ombre d'une fenêtre }
  79.  
  80. Procedure ScreenToBuf(x1,y1,x2,y2:Byte;Var B:TWordBuffer);
  81. { sauve le contenu d'un rectangle }
  82.  
  83. Procedure BufToScreen(x1,y1,x2,y2:Byte;B:TWordBuffer);
  84. { restitue le contenu d'un rectangle }
  85.  
  86. { Curseur }
  87.  
  88. Procedure SetCursorPos(Column, Row: Byte);
  89. { fixe la position du curseur texte, remplace gotoxy }
  90.  
  91. Procedure GetCursorPos(Var Column, Row: Byte);
  92. { renvoie la position du curseur texte }
  93.  
  94. Procedure SetCursorType(ctype: Word);
  95. { fixe le type du curseur texte }
  96.  
  97. Function  GetCursorType:Word;
  98. { renvoie le type du curseur texte }
  99.  
  100. Procedure GetCursorState(Var C:TCursorState);
  101.  
  102. Procedure SetCursorState(C:TCursorState);
  103.  
  104. IMPLEMENTATION
  105.  
  106. Const
  107. { numéros d'interruptions BIOS }
  108.  VIO = $10;  (* BIOS Video *)
  109.  
  110. Var
  111.  Reg : Registers;
  112.  
  113. { activation/désactivation du clignotement du fond }
  114. Procedure ToggleBlink(OnOff:boolean); assembler;
  115. Asm
  116.  mov ax,1003h
  117.  mov bl,OnOff
  118.  int 10h
  119. End;
  120.  
  121. { Curseur }
  122. Procedure GetCursorPos (Var Column, Row: Byte);
  123. Var p, X, Y: Byte;
  124. Begin
  125.  p := PageCourante;
  126.  Asm
  127.    MOV AH, $03
  128.    MOV BH, p
  129.    Int VIO
  130.    MOV X, DL
  131.    MOV Y, DH
  132.  End;
  133.  Column := X;
  134.  Row := Y;
  135. End;
  136.  
  137. Function GetCursorType : Word;
  138. Begin
  139.   Asm
  140.     MOV AH, $03;
  141.     MOV BH, PageCourante
  142.     Int VIO
  143.     MOV @Result, CX
  144.   End;
  145. End;
  146.  
  147. Procedure SetCursorPos (Column, Row: Byte);
  148. Begin
  149.   Asm
  150.     MOV AH, $02
  151.     MOV BH, PageCourante
  152.     MOV DH, Row
  153.     MOV DL, Column
  154.     Int VIO
  155.   End;
  156. End;
  157.  
  158. Procedure SetCursorType(ctype: Word);
  159. Begin
  160.  Reg.AX:=$0100;
  161.  Reg.CX:=ctype;
  162.  intr(VIO,Reg);
  163. End;
  164.  
  165. Procedure GetCursorState(Var C:TCursorState);
  166. Begin
  167.  with C do
  168.   begin
  169.    Typ:=GetCursorType;
  170.    GetCursorPos(x,y);
  171.   end;
  172. End;
  173.  
  174. Procedure SetCursorState(C:TCursorState);
  175. Begin
  176.  with C do
  177.   begin
  178.    SetCursorType(Typ);
  179.    SetCursorPos(x,y);
  180.   end;
  181. End;
  182.  
  183. { Ecran }
  184. Function x80(y:word):word;
  185. { utilitaire de calcul d'adresse }
  186. Begin
  187.   asm
  188.     MOV AX,y
  189.     MOV BX,AX
  190.     MOV CL,4
  191.     SHL BX,CL
  192.     MOV CL,6
  193.     SHL AX,CL
  194.     ADD AX,BX
  195.     MOV @Result, AX
  196.   end
  197. End;
  198.  
  199. Function x80p(y,x: word):word;
  200. { utilitaire de calcul d'adresse }
  201. Begin
  202.   asm
  203.     MOV AX,y
  204.     MOV BX,AX
  205.     MOV CL,4
  206.     SHL BX,CL
  207.     MOV CL,6
  208.     SHL AX,CL
  209.     ADD AX,BX
  210.     ADD AX,x
  211.     MOV @Result, AX
  212.   end
  213. End;
  214.  
  215. Procedure PutCharAttrib (CharAttrib: Word; NbChar: Word);
  216. Begin
  217.   Asm
  218.     MOV AX, CharAttrib
  219.     MOV BL, AH
  220.     MOV AH, $09
  221.     MOV BH, PageCourante
  222.     MOV CX, NbChar
  223.     Int VIO
  224.   End;
  225. End;
  226.  
  227. Procedure FillScreen(CharAttrib:Word);
  228. Begin
  229.  SetCursorPos(0,0);
  230.  PutCharAttrib(CharAttrib,25*80);
  231. End;
  232.  
  233. Function GetCharAttrib : Word;
  234. Begin
  235.   Asm
  236.     MOV AH, $08
  237.     MOV BH, PageCourante
  238.     Int VIO
  239.     MOV @Result, AX
  240.   End;
  241. End;
  242.  
  243. Function GetCharAttribXY(X, Y:Byte):Word;
  244. Begin
  245.  GetCharAttribXY:=Screen[PageCourante][x80p(Y,X)];
  246. End;
  247.  
  248. Procedure ScrollWindowUp(NoLines, Attrib, ColUL, RowUL, ColLR, RowLR: Byte);
  249.   Assembler;
  250. Asm
  251.   MOV AH, $06
  252.   MOV AL, NoLines
  253.   MOV BH, Attrib
  254.   MOV CH, RowUL
  255.   MOV CL, ColUL
  256.   MOV DH, RowLR
  257.   MOV DL, ColLR
  258.   Int VIO
  259. End;
  260.  
  261. Procedure ScrollWindowDn(NoLines, Attrib, ColUL, RowUL, ColLR, RowLR: Byte);
  262. Begin
  263.   Asm
  264.     MOV AH, $07
  265.     MOV AL, NoLines
  266.     MOV BH, Attrib
  267.     MOV CH, RowUL
  268.     MOV CL, ColUL
  269.     MOV DH, RowLR
  270.     MOV DL, ColLR
  271.     Int VIO
  272.   End;
  273. End;
  274.  
  275. Procedure SetActivePage(Page: Byte);
  276. Begin
  277.  Reg.AH:=$05;
  278.  Reg.AL:=Page;
  279.  intr(VIO,Reg);
  280.  PageCourante:=Page;
  281. End;
  282.  
  283. Procedure WriteXYCh(attrib,X,Y,c:Byte);
  284. Begin
  285.  Screen[PageCourante][x80p(Y,X)]:=(attrib ShL 8)+c;
  286. End;
  287.  
  288. Procedure WriteXY(attrib,X,Y:Byte; S:String);
  289. Var i: byte;
  290. Begin
  291.  if S[0]<>#0
  292.     then begin
  293.           for i:=1 to length(S)
  294.            do Screen[PageCourante][x80p(Y,X+Pred(i))]:=
  295.               (attrib shl 8)+Ord(S[i]);
  296.          end;
  297. End;
  298.  
  299. Procedure CopyPage(n1,n2:Byte);
  300. { copie de la page écran n1 dans la page écran n2 }
  301. Begin
  302.  move(Screen[n1],Screen[n2],4000);
  303. End;
  304.  
  305. { Fenêtres }
  306. Procedure Frame(X1,Y1,X2,Y2,c:Byte; Title:String);
  307. Var x,y:Byte;
  308. Begin
  309.  ScrollWindowUP(0,c,X1,Y1,X2,Y2);
  310.  for x:=X1 To X2
  311.   do begin
  312.       WriteXYCh(c,X,Y1,196);
  313.       WriteXYCh(c,X,Y2,196);
  314.      end;
  315.  for y:=Y1 To Y2
  316.   do begin
  317.       WriteXYCh(c,X1,Y,179);
  318.       WriteXYCh(c,X2,Y,179);
  319.      end;
  320.  WriteXYCh(c,X1,Y1,218);
  321.  WriteXYCh(c,X2,Y1,191);
  322.  WriteXYCh(c,X1,Y2,192);
  323.  WriteXYCh(c,X2,Y2,217);
  324.  If title <> ''
  325.     then WriteXY(c,X1+(X2-X1-length(Title)) div 2, Y1, Title);
  326. End;
  327.  
  328. Procedure Shadow(X1,Y1,X2,Y2,cc:Byte);
  329. Var x,y,xmax,ymax:Byte;
  330.     w:Word;
  331. Begin
  332.  xmax:=succ(x2);
  333.  if xmax>79 then xmax:=79;
  334.  ymax:=succ(y2);
  335.  if ymax>24 then ymax:=24;
  336.  For y:=succ(y1) to ymax
  337.   do begin
  338.       SetCursorPos(succ(X2),y);
  339.       W:=GetCharAttrib;
  340.       W:=W mod 256 + 256*cc;
  341.       PutCharAttrib(W,1);
  342.      end;
  343.  For x:=succ(x1) to xmax
  344.   do begin
  345.       SetCursorPos(x,succ(Y2));
  346.       W:=GetCharAttrib;
  347.       W:=W mod 256 + 256*cc;
  348.       PutCharAttrib(W,1);
  349.      end;
  350. End;
  351.  
  352. Procedure ScreenToBuf(x1,y1,x2,y2:Byte; Var B:TWordBuffer);
  353. Var y:Word;
  354. Begin
  355.  for y:=y1 to y2 do
  356.   Move(Screen[PageCourante][y*80+x1],
  357.        B[(y-y1)*(x2-x1+1)],2*(x2-x1+1));
  358. End;
  359.  
  360. Procedure BufToScreen(x1,y1,x2,y2:Byte; B:TWordBuffer);
  361. Var y:Word;
  362. Begin
  363.  for y:=y1 to y2 do
  364.   Move(B[(y-y1)*(x2-x1+1)],
  365.        Screen[PageCourante][y*80+x1],2*(x2-x1+1));
  366. End;
  367.  
  368. END.
  369.  
  370. {                        Fin du fichier UTextScr.Pas                        }
  371.