home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / turbo4 / mcdisply.pas < prev    next >
Pascal/Delphi Source File  |  1987-12-08  |  8KB  |  336 lines

  1.  
  2. {           Copyright (c) 1985, 87 by Borland International, Inc.            }
  3.  
  4. unit MCDISPLY;
  5.  
  6. interface
  7.  
  8. uses Crt, Dos, MCVars, MCUtil;
  9.  
  10. var
  11.   InsCursor, ULCursor, NoCursor, OldCursor : Word;
  12.  
  13. procedure MoveToScreen(var Source, Dest; Len : Word);
  14. { Kopieren in den Bildspeicher }
  15. procedure MoveFromScreen(var Source, Dest; Len : Word);
  16. { Kopieren aus dem Bildspeicher }
  17.  
  18. procedure WriteXY(S : String; Col, Row : Word);
  19. { Ausgabe für eine Zelle }
  20.  
  21. procedure MoveText(OldX1, OldY1, OldX2, OldY2, NewX1, NewY1 : Word);
  22. { Kopieren von Text }
  23.  
  24. procedure Scroll(Direction, Lines, X1, Y1, X2, Y2, Attrib : Word);
  25. { Rollt einen Bereich des Bildschirms }
  26.  
  27. function GetCursor : Word;
  28. { Liefert die momentan gesetzte Cursorform }
  29. procedure SetCursor(NewCursor : Word);
  30. { Setzt eine neue Form des Cursors }
  31. function GetSetCursor(NewCursor : Word) : Word;
  32. { Setzt eine neue Cursorform & liefert die alte zurück }
  33.  
  34. procedure SetColor(Color : Word);
  35. { Setzt Vorder- und Hintergrundfarbe (beide in Color übergeben) }
  36.  
  37. procedure PrintCol;  { Gibt die Spaltentitel aus }
  38. procedure PrintRow;  { Gibt die Zeilentitel aus }
  39.  
  40. procedure ClearInput; { Löscht die Eingabezeile }
  41.  
  42. procedure ChangeCursor(InsMode : Boolean);
  43. { Setzt die Form des Cursors abhängig vom Eingabemodus }
  44.  
  45. procedure ShowCellType;   { Gibt einen Zelltyp und -inhalt aus }
  46. procedure PrintFreeMem;   { Gibt den freien Speicherplatz aus }
  47. procedure ErrorMsg(S : String);
  48. { Gibt eine Fehlermeldung in der untersten Bildschirmzeile aus }
  49. procedure WritePrompt(Prompt : String); { Gibt einen Anforderungstext aus }
  50.  
  51. function EGAInstalled : Boolean;  { Prüft, ob eine EGA-Karte vorhanden ist }
  52.  
  53. {****************************************************}
  54. {****************************************************}
  55. implementation
  56.  
  57. const
  58.   MaxLines = 43;
  59.  
  60. type
  61.   ScreenType = array[1..MaxLines, 1..80] of Word;
  62.   ScreenPtr = ^ScreenType;
  63.  
  64. var
  65.   DisplayPtr : ScreenPtr;
  66.  
  67. procedure MoveToScreen; external;   { in MCMVSMEM.OBJ }
  68. procedure MoveFromScreen; external; { dito }
  69. {$L MCMVSMEM.OBJ}
  70.  
  71. procedure WriteXY;
  72. begin
  73.   GotoXY(Col, Row);
  74.   Write(S);
  75. end;
  76.  
  77. procedure MoveText;
  78. var
  79.   Counter, Len : Word;
  80. begin
  81.   Len := Succ(OldX2 - OldX1) shl 1;
  82.   if NewY1 < OldY1 then
  83.   begin
  84.     for Counter := 0 to OldY2 - OldY1 do
  85.       MoveFromScreen(DisplayPtr^[OldY1 + Counter, OldX1],
  86.                      DisplayPtr^[NewY1 + Counter, NewX1], Len)
  87.   end
  88.   else begin
  89.     for Counter := OldY2 - OldY1 downto 0 do
  90.       MoveFromScreen(DisplayPtr^[OldY1 + Counter, OldX1],
  91.                      DisplayPtr^[NewY1 + Counter, NewX1], Len)
  92.   end;
  93. end;
  94.  
  95. procedure Scroll;
  96. begin
  97.   if Lines = 0 then
  98.     Window(X1, Y1, X2, Y2)
  99.   else begin
  100.     case Direction of
  101.       UP : begin
  102.              MoveText(X1, Y1 + Lines, X2, Y2, X1, Y1);
  103.              Window(X1, Succ(Y2 - Lines), X2, Y2);
  104.           end;
  105.       DOWN : begin
  106.                MoveText(X1, Y1, X2, Y2 - Lines, X1, Y1 + Lines);
  107.                Window(X1, Y1, X2, Pred(Y1 + Lines));
  108.              end;
  109.       LEFT : begin
  110.                MoveText(X1 + Lines, Y1, X2, Y2, X1, Y1);
  111.                Window(Succ(X2 - Lines), Y1, X2, Y2);
  112.             end;
  113.       RIGHT : begin
  114.                 MoveText(X1, Y1, X2 - Lines, Y2, X1 + Lines, Y1);
  115.                 Window(X1, Y1, Pred(X1 + Lines), Y2);
  116.               end;
  117.     end; { case }
  118.   end;
  119.   SetColor(Attrib);
  120.   ClrScr;
  121.   Window(1, 1, 80, ScreenRows + 5);
  122. end;
  123.  
  124. function GetCursor;
  125. var
  126.   Reg : Registers;
  127. begin
  128.   with Reg do
  129.   begin
  130.     AH := 3; BH := 0;
  131.     Intr($10, Reg);
  132.     GetCursor := CX;
  133.   end; { with Reg }
  134. end;
  135.  
  136. procedure SetCursor;
  137. var
  138.   Reg : Registers;
  139. begin
  140.   with Reg do
  141.   begin
  142.     AH := 1;  BH := 0;
  143.     CX := NewCursor;
  144.     Intr($10, Reg);
  145.   end; { with Reg }
  146. end;
  147.  
  148. function GetSetCursor;
  149. begin
  150.   GetSetCursor := GetCursor;
  151.   SetCursor(NewCursor);
  152. end;
  153.  
  154. procedure SetColor;
  155. begin
  156.   TextAttr := ColorTable[Color];
  157. end;
  158.  
  159. procedure InitColorTable(BlackWhite : Boolean);
  160. { Initialisiert die Farb-Tabelle }
  161. var
  162.   Color, FG, BG, FColor, BColor : Word;
  163. begin
  164.   if not BlackWhite then
  165.   begin
  166.     for Color := 0 to 255 do
  167.       ColorTable[Color] := Color;
  168.   end
  169.   else begin
  170.     for FG := Black to White do
  171.     begin
  172.       case FG of
  173.         Black : FColor := Black;
  174.         Blue..LightGray : FColor := LightGray;
  175.         DarkGray..White : FColor := White;
  176.       end; { case }
  177.       for BG := Black to LightGray do
  178.       begin
  179.         if BG = Black then
  180.           BColor := Black
  181.         else begin
  182.           if FColor = White then
  183.             FColor := Black;
  184.           BColor := LightGray;
  185.         end;
  186.         ColorTable[FG + (BG shl 4)] := FColor + (BColor shl 4);
  187.       end;
  188.     end;
  189.     for FG := 128 to 255 do
  190.       ColorTable[FG] := ColorTable[FG - 128] or $80;
  191.   end;
  192. end;
  193.  
  194. procedure PrintCol;
  195. var
  196.   Col : Word;
  197. begin
  198.   Scroll(UP, 0, 1, 2, 80, 2, HEADERCOLOR);
  199.   for Col := LeftCol to RightCol do
  200.     WriteXY(CenterColString(Col), ColStart[Succ(Col - LeftCol)], 2);
  201. end;
  202.  
  203. procedure PrintRow;
  204. var
  205.   Row : Word;
  206. begin
  207.   SetColor(HEADERCOLOR);
  208.   for Row := 0 to Pred(ScreenRows) do
  209.     WriteXY(Pad(WordToString(Row + TopRow, 1), LEFTMARGIN), 1, Row + 3);
  210. end;
  211.  
  212. procedure ClearInput;
  213. begin
  214.   SetColor(TXTCOLOR);
  215.   GotoXY(1, ScreenRows + 5);
  216.   ClrEol;
  217. end;
  218.  
  219. procedure ChangeCursor;
  220. begin
  221.   if InsMode then SetCursor(InsCursor) { Block }
  222.   else SetCursor(ULCursor);           { Unterstrich }
  223. end;
  224.  
  225. procedure ShowCellType;
  226. var
  227.   ColStr : String[2];
  228.   S : IString;
  229.   Color : Word;
  230. begin
  231.   FormDisplay := not FormDisplay;
  232.   S := CellString(CurCol, CurRow, Color, NOFORMAT);
  233.   ColStr := ColString(CurCol);
  234.   SetColor(CELLTYPECOLOR);
  235.   GotoXY(1, ScreenRows + 3);
  236.   if CurCell = Nil then
  237.     Write(ColStr, CurRow, ' ', MSGEMPTY, ' ':10)
  238.   else begin
  239.     case CurCell^.Attrib of
  240.     TXT :
  241.       Write(ColStr, CurRow, ' ', MSGTEXT, ' ':10);
  242.     VALUE :
  243.       Write(ColStr, CurRow, ' ', MSGVALUE, ' ':10);
  244.     FORMULA :
  245.       Write(ColStr, CurRow, ' ', MSGFORMULA, ' ':10);
  246.     end; { case }
  247.   end;
  248.   SetColor(CELLCONTENTSCOLOR);
  249.   WriteXY(Pad(S, 80), 1, ScreenRows + 4);
  250.   FormDisplay := not FormDisplay;
  251. end;
  252.  
  253. procedure PrintFreeMem;
  254. begin
  255.   SetColor(MEMORYCOLOR);
  256.   GotoXY(Length(MSGMEMORY) + 2, 1);
  257.   Write(MemAvail:6);
  258. end;
  259.  
  260. procedure ErrorMsg;
  261. var
  262.   Ch : Char;
  263. begin
  264.   Sound(1000); Delay(500); NoSound;  { Brriieeep! }
  265.   SetColor(ERRORCOLOR);
  266.   WriteXY(S + '  ' + MSGKEYPRESS, 1, ScreenRows + 5);
  267.   GotoXY(Length(S) + Length(MSGKEYPRESS) + 3, ScreenRows + 5);
  268.   Ch := ReadKey;
  269.   ClearInput;
  270. end;
  271.  
  272. procedure WritePrompt;
  273. begin
  274.   SetColor(PROMPTCOLOR);
  275.   GotoXY(1, ScreenRows + 4);
  276.   ClrEol;
  277.   Write(Prompt);
  278. end;
  279.  
  280. procedure InitDisplay;
  281. { Initialisierung diverser globaler Variablen - muß vor der Benutzung
  282.   der restlichen Funktionen/Prozeduren aufgerufen werden }
  283. var
  284.   Reg : Registers;
  285. begin
  286.   Reg.AH := 15;
  287.   Intr($10, Reg);
  288.   ColorCard := Reg.AL <> 7;
  289.   if ColorCard then
  290.     DisplayPtr := Ptr($B800, 0)
  291.   else
  292.     DisplayPtr := Ptr($B000, 0);
  293.   InitColorTable((not ColorCard) or (Reg.AL = 0) or (Reg.AL = 2));
  294. end;
  295.  
  296. function EGAInstalled;
  297. var
  298.   Reg : Registers;
  299. begin
  300.   with Reg do begin
  301.     AX := $1200; BX := $0010; CX := $FFFF;
  302.     Intr($10, Reg);
  303.     EGAInstalled := CX <> $FFFF;
  304.   end; { with Reg }
  305. end;
  306.  
  307. { ********************************************************** }
  308. { ********************************************************** }
  309. begin
  310.   InitDisplay;
  311.   NoCursor := $2000;
  312.   OldCursor := GetSetCursor(NoCursor);
  313.   OldMode := LastMode;
  314.   if (LastMode and Font8x8) <> 0 then ScreenRows := 38
  315.    else ScreenRows := 20;
  316.   Window(1, 1, 80, ScreenRows + 5);
  317.   if ColorCard then
  318.   begin
  319.     ULCursor := $0607;
  320.     InsCursor := $0507;
  321.   end
  322.   else begin
  323.     ULCursor := $0B0C;
  324.     InsCursor := $090C;
  325.   end;
  326.   if EGAInstalled then
  327.   begin
  328.     UCommandString := UCOMMAND;
  329.     UMenuString := UMNU;
  330.   end
  331.   else begin
  332.     UCommandString := Copy(UCOMMAND, 1, 2);
  333.     UMenuString := Copy(UMNU, 1, 23);
  334.   end;
  335. end.
  336.