home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / EGA43.ZIP / EGA43.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1987-02-14  |  5.6 KB  |  185 lines

  1. program Ega43LineMode;
  2.   {-EGA43.PAS, version 1.0, 2/7/86}
  3.   {-Demonstrates use of the EGA's 43-line mode}
  4.  
  5.   {$C-}
  6.  
  7. (*
  8.     Notes for EGA43.PAS:
  9.     ====================
  10.     The routines included here should provide everything you need in order to
  11.     deal with the EGA's 43-line mode. With them you can
  12.  
  13.        - test for the presence of the EGA
  14.        - determine whether or not 43-line mode is currently in effect
  15.        - switch in and out of 43-line mode
  16.        - determine the size of the cursor box currently in use by the EGA
  17.        - toggle the EGA's emulation of the CGA cursor on or off
  18.  
  19.     Since PC-DOS versions of Turbo Pascal prior to 3.02A do not allow text
  20.     windows larger than 25 rows, use of these routines under Turbo 3.00B and
  21.     3.01A requires that you make a simple patch to the compiler (shown below).
  22.  
  23.     Contrary to popular fears, you don't need any special screen-writing
  24.     routines for 43-line mode. As the demo program shows, Write and WriteLn
  25.     (and ClrScr, and GotoXY, etc.) work fine once you've made the necessary
  26.     preparations, and routines that write directly to video memory (such as
  27.     those in my FASTWR.PAS and Bela Lubkin's WINDOW.PAS) behave just as they
  28.     would in 25-line mode.
  29.  
  30.     Caveat:
  31.     =======
  32.     EgaIn43LineMode and EgaCursorSize were developed and tested only on an EGA
  33.     clone (a Vega). Please let me know ASAP if they fail for your adapter. The
  34.     other routines (based on code written by Kim Kokkonen) have been tested on
  35.     a wide variety of EGA cards.
  36.  
  37.  
  38.     Please refer all comments, problems, etc. to:
  39.  
  40.     Brian Foley [76317,3247]
  41.     TurboPower Software
  42. *)
  43.  
  44. (*
  45.     Patches for Turbo 3.01A and 3.00B to allow text windows > 25 rows:
  46.     ==================================================================
  47.     Enter "DEBUG TURBO.COM" at the DOS prompt, then execute the four commands
  48.     shown below. For Turbo 3.01A (with or without BCD or 8087):
  49.  
  50.     E 38F
  51.     2B
  52.     W
  53.     Q
  54.  
  55.     The patch for Turbo 3.00B (with or without BCD or 8087) is the same except
  56.     for the first command, which should be "E 372". After the patch has been
  57.     applied, all compiled programs will accept text windows as large as 43
  58.     ($2B) rows.
  59. *)
  60.  
  61.   {the following global type declaration is needed by EGA43.INC:}
  62.   type
  63.     Registers = record
  64.                   case Integer of
  65.                     1 : (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags : Integer);
  66.                     2 : (AL, AH, BL, BH, CL, CH, DL, DH : Byte);
  67.                 end;
  68.  
  69.   (*** begin EGA43.INC ***)
  70.  
  71.   function EgaInstalled : Boolean;
  72.     {-Return True if EGA is present}
  73.   var
  74.     Regs : Registers;
  75.   begin
  76.     Regs.AX := $1200;
  77.     Regs.BX := $10;
  78.     Regs.CX := $FFFF;
  79.     Intr($10, Regs);
  80.     EgaInstalled := (Regs.CX <> $FFFF);
  81.   end;
  82.  
  83.   procedure SetCursor(Starting, Ending : Byte);
  84.     {-Set the starting and ending scan lines for the cursor. Not specific to
  85.      the EGA.}
  86.   var
  87.     Regs : Registers;
  88.   begin
  89.     Regs.AH := 1;
  90.     Regs.CH := Starting;
  91.     Regs.CL := Ending;
  92.     Intr($10, Regs);
  93.   end;
  94.  
  95.   procedure EgaCursorEmulation(Off : Boolean);
  96.     {-Toggle EGA cursor emulation on or off. Due to a flaw in the EGA BIOS, a
  97.     normal cursor (starting = 6, ending = 7) will be hidden after switching to
  98.     43-line mode if emulation is left on.}
  99.   var
  100.     Emulation : Byte absolute $40 : $87; {only bit 0 is relevant here}
  101.   begin
  102.     if Off then
  103.       begin
  104.         {turn emulation off and reset cursor}
  105.         Emulation := Emulation or 1;
  106.         SetCursor(5, 7);      {set normal cursor}
  107.       end
  108.     else
  109.       begin
  110.         {turn emulation on and reset cursor}
  111.         Emulation := Emulation and $FFFE;
  112.         SetCursor(6, 7);      {set normal cursor}
  113.       end;
  114.   end;
  115.  
  116.   function EgaIn43LineMode : Boolean;
  117.     {-Return True if EGA is in 43-line mode}
  118.   begin
  119.     EgaIn43LineMode := (Mem[$40 : $84] = 42);
  120.   end;
  121.  
  122.   procedure Ega43LineMode(On : Boolean);
  123.     {-Toggle 43-line mode on or off}
  124.   var
  125.     Regs : Registers;
  126.   begin
  127.     Regs.AX := $1111+Ord(On); {AX of $1112 = on, $1111 = off}
  128.     Regs.BL := 0;
  129.     Intr($10, Regs);
  130.     EgaCursorEmulation(On);
  131.   end;
  132.  
  133.   function EgaCursorSize : Byte;
  134.     {-Return size, in scan lines, of cursor box used by EGA}
  135.   begin
  136.     EgaCursorSize := Mem[$40 : $85];
  137.   end;
  138.  
  139.   (*** end EGA43.INC ***)
  140.  
  141.   (*** Demonstration Program ***)
  142. var
  143.   I : Integer;
  144. const
  145.   Ega43LineModeArray : array[False..True] of string[33] =
  146.     ('The EGA is now in 25-line mode.',
  147.      'The EGA is now in 43-line mode.');
  148.  
  149. begin
  150.   NormVideo;
  151.  
  152.   {check for presence of EGA}
  153.   if not EgaInstalled then
  154.     begin
  155.       WriteLn('This program requires an EGA!');
  156.       Halt(1);
  157.     end;
  158.  
  159.   {increase window to 43 rows, switch to 43-line mode, and clear screen}
  160.   Window(1, 1, 80, 43);
  161.   Ega43LineMode(True);
  162.   ClrScr;
  163.  
  164.   {show status info about the EGA and verify that 43-line mode works}
  165.   WriteLn( Ega43LineModeArray[EgaIn43LineMode] );
  166.   WriteLn('The EGA is now using a cursor that is ', EgaCursorSize,
  167.     ' scan lines high.');
  168.   LowVideo;
  169.   for I := 1 to 43 do
  170.     WriteLn('This is an example of the EGA''s 43-line mode...');
  171.   Delay(1000);
  172.  
  173.   {reset for smaller window, switch to 25-line mode, and get cursor back}
  174.   Window(1, 1, 80, 25);
  175.   Ega43LineMode(False);
  176.   GoToXY(1, 25);              {get the cursor back on the screen}
  177.   WriteLn;
  178.  
  179.   {show revised status info}
  180.   NormVideo;
  181.   WriteLn( Ega43LineModeArray[EgaIn43LineMode] );
  182.   WriteLn('The EGA is now using a cursor that is ', EgaCursorSize,
  183.     ' scan lines high.');
  184. end.
  185.