home *** CD-ROM | disk | FTP | other *** search
-
- /* FastVid.C version 1.0 May 30, 1987 */
- /* */
- /* Written by, Scott Friedman */
-
-
- #include <dos.h>
- #include "fastvid.h"
-
-
- typedef unsigned char ( far *VIDMEM );
- #define MONOMEM ( ( VIDMEM ) ( 0xB000L << 16 ) )
- #define CGAMEM ( ( VIDMEM ) ( 0xB800L << 16 ) )
-
- static int RowTable [ 25 ] = { 0x000, 0x0A0, 0x140, 0x1E0, 0x280,
- 0x320, 0x3C0, 0x460, 0x500, 0x5A0,
- 0x640, 0x6E0, 0x780, 0x820, 0x8C0,
- 0x960, 0xA00, 0xAA0, 0xB40, 0xBE0,
- 0xC80, 0xD20, 0xDC0, 0xE60, 0xF00 };
-
- _F Frame [ 4 ] = { { '\xC4','\xB3','\xDA','\xBF','\xC0','\xD9','\xC2','\xC1','\xC3','\xB4' },
- { '\xCD','\xB3','\xD5','\xB8','\xD4','\xBE','\xD1','\xCF','\xC6','\xB5' },
- { '\xC4','\xBA','\xD6','\xB7','\xD3','\xBD','\xD2','\xD0','\xC7','\xB6' },
- { '\xCD','\xBA','\xC9','\xBB','\xC8','\xBC','\xCB','\xCA','\xCC','\xB9' } };
-
- static struct {
- VIDMEM Display; /* Display Segment */
- int StatusPort; /* Status Port Address */
- int UseBios; /* Use BIOS routines ? */
- int HaveSnow; /* Lousy Display Board ? */
- int MonoCard; /* Monochrome Installed ? */
- int EgaCard; /* Ega Card Installed ? */
- byte Page; /* Current Video Board Page */
- byte Attribute; /* Current Text Attribute */
- int NumRows; /* Number of Rows on Display */
- int NumCols; /* Number of Columns */
- int Row; /* Current Row */
- int Col; /* Current Column */
- } Video;
-
-
- void InitText ( void ) {
- Video.MonoCard = ( GetVideoMode() == 7 );
- SetVideoMode( 3 );
- Video.NumRows = 25;
- Video.NumCols = 80;
- Video.EgaCard = EgaInstalled();
- Video.Display = ( Video.MonoCard ? MONOMEM : CGAMEM );
- Video.StatusPort = ( Video.MonoCard ? 0x3BA : 0x3DA );
- Video.UseBios = NO;
- Video.HaveSnow = NO;
- SetPage ( Video.Page = 0 );
- SetAttribute ( Attr ( WHITE, BLACK ) );
- Cls ( Video.Attribute );
- Gotoxy ( 0, 0 );
- }
-
-
- void UseBios ( byte YN ) {
- Video.UseBios = YN;
- }
-
-
- void HaveSnow ( byte YN ) {
- Video.HaveSnow = YN;
- }
-
-
- int EgaInstalled ( void ) {
- _AX = 0x1200;
- _BX = 0x0010;
- _CX = 0xFFFF;
- geninterrupt ( 0x10 );
- return ( ( _CX == 0xFFFF ) ? YES : NO );
- }
-
-
- void SetCursor ( byte Start, byte End ) {
- _AH = 0x01;
- _CH = Start;
- _CL = End;
- geninterrupt ( 0x10 );
- }
-
-
- void HideCursor ( void ) {
- GotoxyB ( 0, 25 );
- }
-
-
- void ShowCursor ( void ) {
- GotoxyB ( Video.Col, Video.Row );
- }
-
-
- int GetVideoMode ( void ) {
- _AH = 0x0F;
- geninterrupt ( 0x10 );
- return ( _AL );
- }
-
-
- void SetVideoMode ( byte Mode ) {
- _AH = 0x00;
- _AL = Mode;
- geninterrupt ( 0x10 );
- }
-
-
- int IsxyOk ( int Col, int Row ) {
- if ( ( Col >= 0 ) && ( Col < Video.NumCols ) )
- if ( ( Row >= 0 ) && ( Row < Video.NumRows ) )
- return ( YES );
- return ( NO );
- }
-
-
- int Gotoxy ( int Col, int Row ) {
- if ( IsxyOk ( Col, Row ) ) {
- Video.Col = Col;
- Video.Row = Row;
- return ( YES );
- }
- return ( NO );
- }
-
-
- void GotoxyB ( int Col, int Row ) {
- _AH = 0x02;
- _BH = Video.Page;
- _DH = Row;
- _DL = Col;
- geninterrupt ( 0x10 );
- }
-
-
- void Getxy ( int *Col, int *Row ) {
- *Col = Video.Col;
- *Row = Video.Row;
- }
-
-
- void GetxyB ( int *Col, int *Row ) {
-
- _AH = 0x03;
- _BH = Video.Page;
- geninterrupt ( 0x10 );
- *Col = _DL;
- *Row = _DH;
- }
-
-
- byte Attr ( byte Foreground, byte Background ) {
- return ( ( ( Background << 4 ) + Foreground ) & 127 );
- }
-
-
- void SetAttribute ( byte Attribute ) {
- Video.Attribute = Attribute;
- }
-
-
- byte GetAttribute ( void ) {
- return ( Video.Attribute );
- }
-
-
- void FlipAttribute ( byte Attribute, int Number ) {
- unsigned long Offset = 0L;
-
- Offset = ( RowTable [ Video.Row ] + ( Video.Col << 1 ) ) + 1;
- while ( ( Number-- ) != 0 ) {
- if ( Video.HaveSnow ) {
- while ( ( inp ( Video.StatusPort ) & 0x01 ) != 0 );
- while ( ( inp ( Video.StatusPort ) & 0x01 ) == 0 );
- }
- *( Video.Display + Offset ) = Attribute;
- Offset += 2;
- }
- }
-
-
- void AtFlipAttribute ( int Col, int Row, byte Attribute, int Number ) {
- Gotoxy ( Col, Row );
- FlipAttribute ( Attribute, Number );
- }
-
-
- void SetPage ( byte Page ) {
- if ( ! Video.MonoCard ) {
- _AH = 0x05;
- _AL = Page;
- geninterrupt ( 0x10 );
- Video.Page = Page;
- }
- }
-
-
- byte GetPage ( void ) {
- return ( Video.Page );
- }
-
-
- void SetBorder ( byte Color ) {
- _AH = 0x0B;
- _BH = 0x00;
- _BL = Color;
- geninterrupt ( 0x10 );
- }
-
-
- void Scroll ( byte Direction, byte NumOfLines, byte Attribute, int x1, int y1, int x2, int y2 ) {
- _AH = Direction;
- _AL = NumOfLines;
- _BH = Attribute;
- _CH = y1;
- _CL = x1;
- _DH = y2;
- _DL = x2;
- geninterrupt ( 0x10 );
- }
-
-
- void Cls ( byte Attribute ) {
- Scroll ( UP, 0, Attribute, 0, 0, Video.NumCols, Video.NumRows );
- }
-
-
- void Box ( int Left, int Top, int Right, int Bottom, byte Style ) {
- AtSayCN ( Left, Top, Frame[ Style ].Horiz, ( Right - Left ) + 1 );
- AtSayCN ( Left, Bottom, Frame[ Style ].Horiz, ( Right - Left ) + 1 );
- AtSayCNV ( Left, Top, Frame[ Style ].Vert, ( Bottom - Top ) + 1 );
- AtSayCNV ( Right, Top, Frame[ Style ].Vert, ( Bottom - Top ) + 1 );
- AtSayC ( Left, Top, Frame[ Style ].UpLeft );
- AtSayC ( Left, Bottom, Frame[ Style ].LoLeft );
- AtSayC ( Right, Top, Frame[ Style ].UpRight );
- AtSayC ( Right, Bottom, Frame[ Style ].LoRight );
- }
-
-
- void Say ( char *Text ) {
- unsigned long Offset = 0L;
-
- if ( Video.UseBios ) {
- while ( *Text != NULL ) {
- GotoxyB ( Video.Col++, Video.Row );
- _AH = 0x09;
- _AL = *Text;
- _BH = Video.Page;
- _BL = Video.Attribute;
- _CX = 0x01;
- geninterrupt ( 0x10 );
- Text++;
- }
- } else {
- Offset = ( RowTable[ Video.Row ] + ( Video.Col << 1 ) );
- while ( *Text != NULL ) {
- Video.Col++;
- if ( Video.HaveSnow ) {
- while ( ( inp ( Video.StatusPort ) & 0x01 ) != 0 );
- while ( ( inp ( Video.StatusPort ) & 0x01 ) == 0 );
- }
- *( Video.Display + Offset++ ) = *Text;
- *( Video.Display + Offset++ ) = Video.Attribute;
- Text++;
- }
- }
- }
-
-
- void SayA ( char *Text, byte Attribute ) {
- byte TempAttr;
-
- TempAttr = GetAttribute ();
- SetAttribute ( Attribute );
- Say ( Text );
- SetAttribute ( TempAttr );
- }
-
-
- void AtSay ( int Col, int Row, char *Text ) {
- if ( Gotoxy ( Col, Row ) )
- Say ( Text );
- }
-
-
- void AtSayA ( int Col, int Row, char *Text, byte Attribute ) {
- byte TempAttr;
-
- TempAttr = GetAttribute ();
- SetAttribute ( Attribute );
- AtSay ( Col, Row, Text );
- SetAttribute ( TempAttr );
- }
-
-
- void SayC ( char Character ) {
- char TempStr [ 2 ];
-
- TempStr [ 0 ] = Character;
- TempStr [ 1 ] = NULL;
- Say ( TempStr );
- }
-
-
- void AtSayC ( int Col, int Row, char Character ) {
- Gotoxy ( Col, Row );
- SayC ( Character );
- }
-
-
- void SayCN ( char Character, int Number ) {
- register i;
- char TempStr [ 2 ];
-
- TempStr [ 0 ] = Character;
- TempStr [ 1 ] = NULL;
- for ( i=0; i<Number; i++ )
- Say ( TempStr );
- }
-
-
- void AtSayCN ( int Col, int Row, char Character, int Number ) {
- Gotoxy ( Col, Row );
- SayCN ( Character, Number );
- }
-
-
- void AtSayCNV ( int Col, int Row, char Character, int Number ) {
- register i;
-
- for ( i=0; i<Number; i++ )
- AtSayC ( Col, Row + i, Character );
- }
-
-