home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FASTWR_2.ZIP / VID-TYPE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1986-11-06  |  7.0 KB  |  149 lines

  1. {=============================================================================
  2.  
  3.           Handy-Dandy Turbo Pascal Routines (C) 1986 by Doug Senalik
  4.  
  5.      VID-TYPE.PAS     V1.0  10/25/86
  6.                       V1.1   11/6/86 - Don't do trial write for 40x25 or
  7.                                        graphics modes, it would cause the
  8.                                        erasing of a char. on the screen, and
  9.                                        we can't do direct write to screen in
  10.                                        those modes anyway.
  11.  
  12. Check to see if can write directly to video memory.
  13.  
  14. Requires the following include files: none
  15.  
  16. Functions: VideoDisplayType: integer
  17. Procedures: SnowOff (boolean)
  18. =============================================================================}
  19.  
  20.  
  21. const _VidWriteMode_: integer = -1;  { Storage to remember the video state }
  22.                                      { so we don't have to go through the  }
  23.                                      { whole function every time, just     }
  24.                                      { return this value. }
  25. var VideoBufferSeg: integer;         { This variable can be used to con-   }
  26.                                      { veniently supply the video buffer   }
  27.                                      { segment, it is set by VideoDisplay- }
  28.                                      { Type.  It will be left as a $F000   }
  29.                                      { if BIOS use is indicated. }
  30.  
  31. function VideoDisplayType: integer;
  32.  
  33. { Returns an integer describing the type of video setup currently in }
  34. { effect, mainly so we can decide if we can write directly to video  }
  35. { memory.  If you want to insist on BIOS writing even when direct    }
  36. { screen writing is possible, simply set    _VidWriteMode_ := 0      }
  37. { in your program, and set back to -1 to restore to fast method.  If }
  38. { you anticipate using graphics modes or switching between a color   }
  39. { and monochrome monitor, always set   _VidWriteMode_ := -1   when   }
  40. { switching video modes so you don't end up writing to video memory  }
  41. { when you can't. }
  42.  
  43. { Meaning of VideoDisplayType result:   }
  44. { 0 = Use BIOS for writing to display   }
  45. { 1 = Mono card, video memory at $B000  }
  46. { 2 = Color card, video memory at $B800 }
  47. { (for 1 & 2, the video memory segment  }
  48. { is pointed to by VideoBufferSeg).     }
  49.  
  50. type Registers = record          {For intr or msdos procedure}
  51.                    AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: integer;
  52.                  end;
  53. var Reg: Registers;
  54.     PrevX,           {Store original cursor position while we do stuff}
  55.     PrevY,           {"}
  56.     Store: integer;  {Store orig. char. on screen while we do test write}
  57.  
  58. begin
  59.   if _VidWriteMode_ = -1 then  { If -1, then this is the first time this has  }
  60.     with Reg do                { been called, so go through the determination }
  61.       begin                    { procedure to determine video writing method. }
  62.                                { This will only be done ONCE.                 }
  63.         PrevX:=wherex;  {Save cursor position}
  64.         PrevY:=wherey;
  65.         VideoBufferSeg := $F000;  {Point to ROM where writing can't do any harm}
  66.  
  67.         AX:=$0F00;  {Determine current display mode}
  68.         intr ($10, Reg);
  69.  
  70.         {We will be able to do a direct read or write to video memory only}
  71.         {in 80x25 text modes, so if not one of those, skip the test}
  72.  
  73.         if lo(AX) in [2,3,7] then
  74.           begin
  75.             { Now do a test write to the display, and see if we can read what }
  76.             { we wrote by looking at the video buffer.  If not, use BIOS for  }
  77.             { all screen writing, otherwise we can write directly to memory.  }
  78.             { We go through this mess rather than just assume modes 2 and 3   }
  79.             { indicate color graphics adaptor, and 7 indicates monochrome     }
  80.             { adaptor, because of the fact that some not so compatible PC     }
  81.             { compatibles are not so compatible.  This method should be sure  }
  82.             { to get the correct result.  Well, let's hope so, anyway.        }
  83.             AX:=$0200;  {Set cursor position}
  84.             BX:=$0000;  {Display page 0}
  85.             DX:=$0303;  {Row 3 column 3}
  86.             intr ($10, Reg);
  87.             AX:=$0800;  {Read char (AL) and attrib (AH) at current cursor position}
  88.             BX:=$0000;  {Display page 0}
  89.             intr ($10, Reg);
  90.             Store := AX;  {Save character so we can restore it later}
  91.             { Now write an uncommon character in black on black (so it is not }
  92.             { visible).  The character will be present for only milliseconds, }
  93.             { so you probably would not have seen it on the screen anyway.    }
  94.             AX:=$099E;  {Write one of the more obscure characters (Pt)}
  95.             BX:=$0000;  {BH=page, BL=attribute - Write in black on black }
  96.             CX:=$0001;  {Write one character}
  97.             intr ($10, Reg);
  98.  
  99.             { See if either of the normal video buffers contains the expected }
  100.             { character.  If it does, then we will assume that we can write   }
  101.             { directly to video memory.  If not, _VidWriteMode_ will remain   }
  102.             { at 0, indicating the need to use BIOS routines.                 }
  103.             _VidWriteMode_ := 0;  {BIOS assumed unless we determine otherwise}
  104.             if memw[$B000:$01E6] = $009E then  {Row 3 col 3 memory location}
  105.               begin
  106.                 _VidWriteMode_ := 1;  {Monochrome buffer in effect}
  107.                 VideoBufferSeg := $B000;
  108.               end;
  109.             if memw[$B800:$01E6] = $009E then  {Row 3 col 3 memory location}
  110.               begin
  111.                 _VidWriteMode_ := 2;  {Color buffer in effect}
  112.                 VideoBufferSeg := $B800;
  113.               end;
  114.  
  115.             { Restore the display to its original state }
  116.             AX:=$0900 + lo(Store);  {Put original character (in AL) back}
  117.             BX:={0000 +}hi(Store);  {and attribute (BL), display page 0 (BH)}
  118.             CX:=$0001;  {Write one character}
  119.             intr ($10, Reg);
  120.             gotoxy (PrevX, PrevY);  {Restore cursor position}
  121.           end;  {if lo(AX) in [2,3,7]}
  122.  
  123.       end;  {with Reg}
  124.  
  125.   VideoDisplayType := _VidWriteMode_;
  126.  
  127. end;  {VideoDisplayType}
  128.  
  129.  
  130. procedure SnowOff (TurnOff: boolean);
  131. { Turns video on or off to avoid read/write snow on Color Graphics Adaptor. }
  132. { All other monitor types do not have this problem, so this procedure will  }
  133. { not do anything unless VideoDisplayType = 2 }
  134.  
  135. const VideoEnableOn  = $08;  { Video Signal Enable Bit }
  136.       VideoEnableOff = $F7;  { and its inverse }
  137. var CrtAdapter: integer absolute $0040:$0063;  { ADDR_6845 in BIOS data area }
  138.     VideoMode: byte absolute $0040:$0065;   { CRT_MODE_SET in BIOS data area }
  139.  
  140. begin
  141.   if VideoDisplayType = 2 then  {Only do anything if using CGA}
  142.     if TurnOff then
  143.       port[CRTAdapter+4] := VideoMode and VideoEnableOff
  144.     else  {TurnOff = false}
  145.       port[CRTAdapter+4] := VideoMode or VideoEnableOn;
  146. end;  {SnowOff}
  147.  
  148.  
  149. {End of file}