home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / fastvid2 / fastvid.c next >
Encoding:
C/C++ Source or Header  |  1988-03-08  |  8.4 KB  |  337 lines

  1.  
  2. /*  FastVid.C   version 1.0   May 30, 1987  */
  3. /*                        */
  4. /*        Written by, Scott Friedman        */
  5.  
  6.  
  7. #include <dos.h>
  8. #include "fastvid.h"
  9.  
  10.  
  11. typedef unsigned char ( far *VIDMEM );
  12. #define   MONOMEM   ( ( VIDMEM ) ( 0xB000L << 16 ) )
  13. #define   CGAMEM    ( ( VIDMEM ) ( 0xB800L << 16 ) )
  14.  
  15. static int RowTable [ 25 ] = { 0x000, 0x0A0, 0x140, 0x1E0, 0x280,
  16.                                0x320, 0x3C0, 0x460, 0x500, 0x5A0,
  17.                                0x640, 0x6E0, 0x780, 0x820, 0x8C0,
  18.                                0x960, 0xA00, 0xAA0, 0xB40, 0xBE0,
  19.                                0xC80, 0xD20, 0xDC0, 0xE60, 0xF00 };
  20.  
  21. _F Frame [ 4 ]  =  { { '\xC4','\xB3','\xDA','\xBF','\xC0','\xD9','\xC2','\xC1','\xC3','\xB4' },
  22.                      { '\xCD','\xB3','\xD5','\xB8','\xD4','\xBE','\xD1','\xCF','\xC6','\xB5' },
  23.                      { '\xC4','\xBA','\xD6','\xB7','\xD3','\xBD','\xD2','\xD0','\xC7','\xB6' },
  24.                      { '\xCD','\xBA','\xC9','\xBB','\xC8','\xBC','\xCB','\xCA','\xCC','\xB9' } };
  25.  
  26. static struct {
  27.      VIDMEM    Display;                      /*  Display Segment           */
  28.      int       StatusPort;                   /*  Status Port Address       */
  29.      int       UseBios;                      /*  Use BIOS routines ?       */
  30.      int       HaveSnow;                     /*  Lousy Display Board ?     */
  31.      int       MonoCard;                     /*  Monochrome Installed ?    */
  32.      int       EgaCard;                      /*  Ega Card Installed ?      */
  33.      byte      Page;                         /*  Current Video Board Page  */
  34.      byte      Attribute;                    /*  Current Text Attribute    */
  35.      int       NumRows;                      /*  Number of Rows on Display */
  36.      int       NumCols;                      /*  Number of Columns         */
  37.      int       Row;                          /*  Current Row               */
  38.      int       Col;                          /*  Current Column            */
  39. } Video;
  40.  
  41.  
  42. void InitText ( void ) {
  43.      Video.MonoCard = ( GetVideoMode() == 7 );
  44.      SetVideoMode( 3 );
  45.      Video.NumRows = 25;
  46.      Video.NumCols = 80;
  47.      Video.EgaCard = EgaInstalled();
  48.      Video.Display = ( Video.MonoCard ? MONOMEM : CGAMEM );
  49.      Video.StatusPort = ( Video.MonoCard ? 0x3BA : 0x3DA );
  50.      Video.UseBios = NO;
  51.      Video.HaveSnow = NO;
  52.      SetPage ( Video.Page = 0 );
  53.      SetAttribute ( Attr ( WHITE, BLACK ) );
  54.      Cls ( Video.Attribute );
  55.      Gotoxy ( 0, 0 );
  56. }
  57.  
  58.  
  59. void UseBios ( byte YN ) {
  60.      Video.UseBios = YN;
  61. }
  62.  
  63.  
  64. void HaveSnow ( byte YN ) {
  65.      Video.HaveSnow = YN;
  66. }
  67.  
  68.  
  69. int EgaInstalled ( void ) {
  70.      _AX = 0x1200;
  71.      _BX = 0x0010;
  72.      _CX = 0xFFFF;
  73.      geninterrupt ( 0x10 );
  74.      return ( ( _CX == 0xFFFF ) ? YES : NO );
  75. }
  76.  
  77.  
  78. void SetCursor ( byte Start, byte End ) {
  79.      _AH = 0x01;
  80.      _CH = Start;
  81.      _CL = End;
  82.      geninterrupt ( 0x10 );
  83. }
  84.  
  85.  
  86. void HideCursor ( void ) {
  87.      GotoxyB ( 0, 25 );
  88. }
  89.  
  90.  
  91. void ShowCursor ( void ) {
  92.      GotoxyB ( Video.Col, Video.Row );
  93. }
  94.  
  95.  
  96. int GetVideoMode ( void ) {
  97.      _AH = 0x0F;
  98.      geninterrupt ( 0x10 );
  99.      return ( _AL );
  100. }
  101.  
  102.  
  103. void SetVideoMode ( byte Mode ) {
  104.      _AH = 0x00;
  105.      _AL = Mode;
  106.      geninterrupt ( 0x10 );
  107. }
  108.  
  109.  
  110. int IsxyOk ( int Col, int Row ) {
  111.      if ( ( Col >= 0 ) && ( Col < Video.NumCols ) )
  112.           if ( ( Row >= 0 ) && ( Row < Video.NumRows ) )
  113.                return ( YES );
  114.      return ( NO );
  115. }
  116.  
  117.  
  118. int Gotoxy ( int Col, int Row ) {
  119.      if ( IsxyOk ( Col, Row ) ) {
  120.           Video.Col = Col;
  121.           Video.Row = Row;
  122.           return ( YES );
  123.      }
  124.      return ( NO );
  125. }
  126.  
  127.  
  128. void GotoxyB ( int Col, int Row ) {
  129.      _AH = 0x02;
  130.      _BH = Video.Page;
  131.      _DH = Row;
  132.      _DL = Col;
  133.      geninterrupt ( 0x10 );
  134. }
  135.  
  136.  
  137. void Getxy ( int *Col, int *Row ) {
  138.      *Col = Video.Col;
  139.      *Row = Video.Row;
  140. }
  141.  
  142.  
  143. void GetxyB ( int *Col, int *Row ) {
  144.  
  145.      _AH = 0x03;
  146.      _BH = Video.Page;
  147.      geninterrupt ( 0x10 );
  148.      *Col = _DL;
  149.      *Row = _DH;
  150. }
  151.  
  152.  
  153. byte Attr ( byte Foreground, byte Background ) {
  154.      return ( ( ( Background << 4 ) + Foreground ) & 127 );
  155. }
  156.  
  157.  
  158. void SetAttribute ( byte Attribute ) {
  159.      Video.Attribute = Attribute;
  160. }
  161.  
  162.  
  163. byte GetAttribute ( void ) {
  164.      return ( Video.Attribute );
  165. }
  166.  
  167.  
  168. void FlipAttribute ( byte Attribute, int Number ) {
  169.      unsigned long Offset = 0L;
  170.  
  171.      Offset = ( RowTable [ Video.Row ] + ( Video.Col << 1 ) ) + 1;
  172.      while ( ( Number-- ) != 0 ) {
  173.           if ( Video.HaveSnow ) {
  174.                while ( ( inp ( Video.StatusPort ) & 0x01 ) != 0 );
  175.                while ( ( inp ( Video.StatusPort ) & 0x01 ) == 0 );
  176.           }
  177.           *( Video.Display + Offset ) = Attribute;
  178.           Offset += 2;
  179.      }
  180. }
  181.  
  182.  
  183. void AtFlipAttribute ( int Col, int Row, byte Attribute, int Number ) {
  184.      Gotoxy ( Col, Row );
  185.      FlipAttribute ( Attribute, Number );
  186. }
  187.  
  188.  
  189. void SetPage ( byte Page ) {
  190.      if ( ! Video.MonoCard ) {
  191.           _AH = 0x05;
  192.           _AL = Page;
  193.           geninterrupt ( 0x10 );
  194.           Video.Page = Page;
  195.      }
  196. }
  197.  
  198.  
  199. byte GetPage ( void ) {
  200.      return ( Video.Page );
  201. }
  202.  
  203.  
  204. void SetBorder ( byte Color ) {
  205.      _AH = 0x0B;
  206.      _BH = 0x00;
  207.      _BL = Color;
  208.      geninterrupt ( 0x10 );
  209. }
  210.  
  211.  
  212. void Scroll ( byte Direction, byte NumOfLines, byte Attribute, int x1, int y1, int x2, int y2 ) {
  213.      _AH = Direction;
  214.      _AL = NumOfLines;
  215.      _BH = Attribute;
  216.      _CH = y1;
  217.      _CL = x1;
  218.      _DH = y2;
  219.      _DL = x2;
  220.      geninterrupt ( 0x10 );
  221. }
  222.  
  223.  
  224. void Cls ( byte Attribute ) {
  225.      Scroll ( UP, 0, Attribute, 0, 0, Video.NumCols, Video.NumRows );
  226. }
  227.  
  228.  
  229. void Box ( int Left, int Top, int Right, int Bottom, byte Style ) {
  230.      AtSayCN ( Left, Top, Frame[ Style ].Horiz, ( Right - Left ) + 1 );
  231.      AtSayCN ( Left, Bottom, Frame[ Style ].Horiz, ( Right - Left ) + 1 );
  232.      AtSayCNV ( Left, Top, Frame[ Style ].Vert, ( Bottom - Top ) + 1 );
  233.      AtSayCNV ( Right, Top, Frame[ Style ].Vert, ( Bottom - Top ) + 1 );
  234.      AtSayC ( Left, Top, Frame[ Style ].UpLeft );
  235.      AtSayC ( Left, Bottom, Frame[ Style ].LoLeft );
  236.      AtSayC ( Right, Top, Frame[ Style ].UpRight );
  237.      AtSayC ( Right, Bottom, Frame[ Style ].LoRight );
  238. }
  239.  
  240.  
  241. void Say ( char *Text ) {
  242.      unsigned long Offset = 0L;
  243.  
  244.      if ( Video.UseBios ) {
  245.           while ( *Text != NULL ) {
  246.                GotoxyB ( Video.Col++, Video.Row );
  247.                _AH = 0x09;
  248.                _AL = *Text;
  249.                _BH = Video.Page;
  250.                _BL = Video.Attribute;
  251.                _CX = 0x01;
  252.                geninterrupt ( 0x10 );
  253.                Text++;
  254.           }
  255.      } else {
  256.           Offset = ( RowTable[ Video.Row ] + ( Video.Col << 1 ) );
  257.           while ( *Text != NULL ) {
  258.                Video.Col++;
  259.                if ( Video.HaveSnow ) {
  260.                     while ( ( inp ( Video.StatusPort ) & 0x01 ) != 0 );
  261.                     while ( ( inp ( Video.StatusPort ) & 0x01 ) == 0 );
  262.                }
  263.                *( Video.Display + Offset++ ) = *Text;
  264.                *( Video.Display + Offset++ ) = Video.Attribute;
  265.                Text++;
  266.           }
  267.      }
  268. }
  269.  
  270.  
  271. void SayA ( char *Text, byte Attribute ) {
  272.      byte TempAttr;
  273.  
  274.      TempAttr = GetAttribute ();
  275.      SetAttribute ( Attribute );
  276.      Say ( Text );
  277.      SetAttribute ( TempAttr );
  278. }
  279.  
  280.  
  281. void AtSay ( int Col, int Row, char *Text ) {
  282.      if ( Gotoxy ( Col, Row ) )
  283.           Say ( Text );
  284. }
  285.  
  286.  
  287. void AtSayA ( int Col, int Row, char *Text, byte Attribute ) {
  288.      byte TempAttr;
  289.  
  290.      TempAttr = GetAttribute ();
  291.      SetAttribute ( Attribute );
  292.      AtSay ( Col, Row, Text );
  293.      SetAttribute ( TempAttr );
  294. }
  295.  
  296.  
  297. void SayC ( char Character ) {
  298.      char TempStr [ 2 ];
  299.  
  300.      TempStr [ 0 ] = Character;
  301.      TempStr [ 1 ] = NULL;
  302.      Say ( TempStr );
  303. }
  304.  
  305.  
  306. void AtSayC ( int Col, int Row, char Character ) {
  307.      Gotoxy ( Col, Row );
  308.      SayC ( Character );
  309. }
  310.  
  311.  
  312. void SayCN ( char Character, int Number ) {
  313.      register i;
  314.      char TempStr [ 2 ];
  315.  
  316.      TempStr [ 0 ] = Character;
  317.      TempStr [ 1 ] = NULL;
  318.      for ( i=0; i<Number; i++ )
  319.           Say ( TempStr );
  320. }
  321.  
  322.  
  323. void AtSayCN ( int Col, int Row, char Character, int Number ) {
  324.      Gotoxy ( Col, Row );
  325.      SayCN ( Character, Number );
  326. }
  327.  
  328.  
  329. void AtSayCNV ( int Col, int Row, char Character, int Number ) {
  330.      register i;
  331.  
  332.      for ( i=0; i<Number; i++ )
  333.           AtSayC ( Col, Row + i, Character );
  334. }
  335.  
  336.  
  337.