home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / VIDEO1.C < prev    next >
C/C++ Source or Header  |  1991-09-23  |  11KB  |  429 lines

  1. /*
  2.  * File......: VIDEO1.C
  3.  * Author....: Robert A. DiFalco
  4.  * CIS ID....: 71610,1705
  5.  * Date......: $Date:   23 Sep 1991 01:07:12  $
  6.  * Revision..: $Revision:   1.4  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/video1.c_v  $
  8.  * 
  9.  * This function is an original work by Robert A. DiFalco and is placed
  10.  * in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/video1.c_v  $
  16.  * 
  17.  *    Rev 1.4   23 Sep 1991 01:07:12   GLENN
  18.  * Mark Lussier corrected a bug in the doc for FT_SETATTR() in the example.
  19.  * For Bright White on Magenta, the value should be 95, not 165.
  20.  * 
  21.  *    Rev 1.3   15 Aug 1991 23:29:26   GLENN
  22.  * Robert made, in his words, some "big ol hairy ass changes" which 
  23.  * included using the Clipper internals _gtPreExt() and _gtPostExt()
  24.  * to avoid conflict with dispBegin() and dispEnd() display buffers.
  25.  *  
  26.  * Forest's documentation was left unscathed. 
  27.  *  
  28.  * 
  29.  *    Rev 1.2   15 Aug 1991 23:08:40   GLENN
  30.  * Forest Belt proofread/edited/cleaned up doc
  31.  * 
  32.  *    Rev 1.1   23 May 1991 02:22:16   GLENN
  33.  * Change to internal function _ftscrptr().
  34.  * 
  35.  *    Rev 1.0   01 Apr 1991 01:03:02   GLENN
  36.  * Nanforum Toolkit
  37.  * 
  38.  *
  39.  */
  40.  
  41.  
  42. #include <extend.h>
  43.  
  44. #define VIDMODE  *(unsigned char far *) 0x00449lu
  45. #define MONO     0xB000
  46. #define COLOR    0xB800
  47. #define VIDSEG   ((7 == VIDMODE) ? MONO : COLOR )
  48.  
  49. #define MK_FP(seg,ofs)  ((void far *) (((unsigned long)(seg) << 16) | \
  50.                         (unsigned)(ofs)));
  51.  
  52. /*
  53.  *    INTERNALS WARNING! INTERNALS WARNING!
  54.  *    _gtMaxRow() and _gtMaxCol() are internals.  Use with caution.
  55.  *
  56.  */
  57.  
  58. int _gtMaxRow(void);
  59. int _gtMaxCol(void);
  60.  
  61.  
  62. /*  $DOC$
  63.  *  $FUNCNAME$
  64.  *     FT_VIDSTR()
  65.  *  $CATEGORY$
  66.  *     Video
  67.  *  $ONELINER$
  68.  *     Display string on screen in specified attribute
  69.  *  $SYNTAX$
  70.  *     FT_VIDSTR( <nRow>, <nCol>, <cString> [, <nColor> ] ) -> NIL
  71.  *  $ARGUMENTS$
  72.  *     <nRow> and <nCol> are the screen coordinates.
  73.  *
  74.  *     <cString> is the string to be printed on the screen.
  75.  *
  76.  *     <nColor> is an integer representing the color attribute.
  77.  *     The formula is:
  78.  *
  79.  *       nFore + ( nBack * 16 )
  80.  *
  81.  *     FT_VIDSTR() will display the string in the current color if
  82.  *     <nColor> is not passed.
  83.  *  $RETURNS$
  84.  *     NIL
  85.  *  $DESCRIPTION$
  86.  *     This is a high speed function to display a string of any ASCII
  87.  *     characters on screen in a specified color attribute.  This function
  88.  *     is useful for constructing screens with a lot of text or repetitive
  89.  *     screen prints where speed is important.
  90.  *  $EXAMPLES$
  91.  *     FT_VIDSTR( 10, 20, "Enter Name :", 165 )
  92.  *             
  93.  *     This example will print the specified text at coordinates 10, 20
  94.  *     in bright white on top of Magenta.
  95.  *
  96.  *  $END$
  97.  */
  98.  
  99.  
  100. CLIPPER FT_VIDSTR(void)
  101. {
  102.    char far *scrPtr;
  103.    int i, j;
  104.  
  105.    int vidSeg  = VIDSEG;
  106.    int numCols = _gtMaxCol() + 1;
  107.  
  108.    int iTRow   = _parni(1);
  109.    int iLCol   = _parni(2);
  110.    char *cStr  = _parc(3);
  111.    int iLen    = _parclen(3);
  112.    int iAttr   = _parni(4);
  113.    int iIsAttr = ISNUM(4);
  114.  
  115.    _gtPreExt();
  116.  
  117.    for ( i = 0, j = iLCol; i < iLen; ++i, ++j ) {
  118.       scrPtr = MK_FP( vidSeg, ( ( iTRow * numCols ) + j ) * 2 );
  119.       *scrPtr++ = cStr[i];
  120.    
  121.       if ( iIsAttr )
  122.          *scrPtr = (unsigned char) iAttr;
  123.    }
  124.    
  125.    _gtPostExt();
  126.    _ret();
  127.    return;
  128. }
  129.  
  130.  
  131. /*  $DOC$
  132.  *  $FUNCNAME$
  133.  *     FT_WRTCHR()
  134.  *  $CATEGORY$
  135.  *     Video
  136.  *  $ONELINER$
  137.  *     Display character on screen
  138.  *  $SYNTAX$
  139.  *     FT_WRTCHR( <nRow>, <nCol>, <cChar>, <nColor> ) -> NIL
  140.  *  $ARGUMENTS$
  141.  *     <nRow> and <nCol> are the screen coordinates.
  142.  *
  143.  *     <cChar> is the single character to print on the screen.
  144.  *
  145.  *     <nColor> is an integer representing the color attribute.
  146.  *     The formula is:
  147.  *
  148.  *        nFore + ( nBack * 16 )
  149.  *  $RETURNS$
  150.  *     NIL
  151.  *  $DESCRIPTION$
  152.  *     This is a high speed function to display a single ASCII character
  153.  *     on screen in a specified color attribute.  This function is useful
  154.  *     for constructing screens with a lot of text or repetitive screen prints
  155.  *     where speed is important.  It is faster and requires less memory than
  156.  *     FT_VIDSTR().  A working example is contained in ClrTable.Prg.
  157.  *  $EXAMPLES$
  158.  *      FOR nX = 1 to MaxRow()
  159.  *         FOR nY = 1 to MaxCol()
  160.  *            FT_PRNTCHR( nX, nY, "∙", (nX - 1)+(nY * 16) )
  161.  *         NEXT
  162.  *      NEXT
  163.  *
  164.  *      This example will write the ASCII character 249 to every location
  165.  *      on screen in every possible color combination.  It will recognize
  166.  *      the status of SetBlink().  It uses direct video writes for speed.
  167.  *
  168.  *  $END$
  169.  */
  170.  
  171. CLIPPER FT_WRTCHR(void)
  172. {
  173.    char far *scrPtr;
  174.    
  175.    int  iTRow  = _parni(1);
  176.    int  iLCol  = _parni(2);
  177.    char *cChar = _parc(3);
  178.    int  iAttr  = _parni(4);
  179.  
  180.    _gtPreExt();
  181.    scrPtr = MK_FP( VIDSEG, ( ( iTRow * _gtMaxCol()+1 ) + iLCol ) * 2 );
  182.    *scrPtr++ = cChar[0];
  183.    
  184.    if( ISNUM( 4 ) )
  185.       *scrPtr = (unsigned char) iAttr;
  186.  
  187.    _gtPostExt();
  188.    _ret();
  189.    return;
  190. }
  191.  
  192.  
  193. /*  $DOC$
  194.  *  $FUNCNAME$
  195.  *     FT_CLS()
  196.  *  $CATEGORY$
  197.  *     Video
  198.  *  $ONELINER$
  199.  *     Clear screen
  200.  *  $SYNTAX$
  201.  *     FT_CLS( <nTRow>, <nLCol>, <nBRow>, <nRCol>, <nColor> ) -> NIL
  202.  *  $ARGUMENTS$
  203.  *     <nTRow>, <nLCol>, <nBRow> and  <nRCol> are the screen coordinates
  204.  *     to clear.
  205.  *
  206.  *     <nColor> is an integer representing the color attribute.
  207.  *     The formula is:
  208.  *
  209.  *       nFore + ( nBack * 16 )
  210.  *
  211.  *     The default is black.
  212.  *  $RETURNS$
  213.  *     NIL
  214.  *  $DESCRIPTION$
  215.  *     This is a high speed function to clear the screen at the given
  216.  *     coordinates with the given color attribute.  This does not change
  217.  *     Clipper's color settings.  It uses direct video writes for speed.
  218.  *
  219.  *  $EXAMPLES$
  220.  *     FT_CLS( 0, 0, MaxRow(), MaxCol(), 165 )
  221.  * 
  222.  *     This example will clear the entire screen with the colors
  223.  *     bright white on magenta.
  224.  *  $END$
  225.  */
  226.  
  227. CLIPPER FT_CLS(void)
  228. {
  229.    char far *scptr;
  230.    int i, j;
  231.    
  232.    int vidSeg  = VIDSEG;
  233.    int numCols = _gtMaxCol() + 1;
  234.  
  235.    int iTRow = ISNUM(1) ? _parni(1) : 0;
  236.    int iLCol = ISNUM(2) ? _parni(2) : 0;
  237.    int iBRow = ISNUM(3) ? _parni(3) : _gtMaxRow();
  238.    int iRCol = ISNUM(4) ? _parni(4) : _gtMaxCol();
  239.    int iAttr = _parni(5);
  240.    
  241.    int fIsAttr = ISNUM(5);
  242.  
  243.    _gtPreExt();
  244.    for (i = iTRow; i <= iBRow; ++i) {
  245.       scptr = MK_FP( vidSeg, ( ( i * numCols ) + iLCol ) * 2 );
  246.       
  247.       for (j = iLCol; j <= iRCol; ++j) {
  248.          *scptr++ = 32;
  249.    
  250.          if( fIsAttr )
  251.             *scptr++ = (unsigned char) iAttr;
  252.          else
  253.             *scptr++;
  254.        }
  255.    }
  256.    _gtPostExt();
  257.    _ret();
  258.    return;
  259.  
  260. }
  261.  
  262.  
  263.  
  264. /*  $DOC$
  265.  *  $FUNCNAME$
  266.  *     FT_SETATTR()
  267.  *  $CATEGORY$
  268.  *     Video
  269.  *  $ONELINER$
  270.  *     Change color attributes of screen region
  271.  *  $SYNTAX$
  272.  *     FT_SETATTR( <nTRow>, <nLCol>, <nBRow>, <nRCol>, <nColor> ) -> NIL
  273.  *  $ARGUMENTS$
  274.  *     <nTRow>, <nLCol>, <nBRow>, and <nRCol> are the coordinates of the
  275.  *     screen region.
  276.  *
  277.  *     <nColor> is an integer representing the new color attribute.
  278.  *     The formula is:
  279.  *
  280.  *         nFore + ( nBack * 16 )
  281.  *  $RETURNS$
  282.  *     NIL
  283.  *  $DESCRIPTION$
  284.  *     This is a high speed function to change the colors of a specified
  285.  *     region of the screen without disturbing any text.  Uses direct
  286.  *     video writes.
  287.  *  $EXAMPLES$
  288.  *     FT_SETATTR( 0, 0, MaxRow(), MaxCol(), 95 )
  289.  * 
  290.  *     This example will change the entire screen's colors to bright white on
  291.  *     magenta without changing or overwriting any text on the screen.
  292.  *  $END$
  293.  */
  294.  
  295. CLIPPER FT_SETATTR(void)
  296. {
  297.    char far *scptr;
  298.    int    i, j;
  299.    
  300.    int iTRow = ISNUM(1) ? _parni(1) : 0;
  301.    int iLCol = ISNUM(2) ? _parni(2) : 0;
  302.    int iBRow = ISNUM(3) ? _parni(3) : _gtMaxRow();
  303.    int iRCol = ISNUM(4) ? _parni(4) : _gtMaxCol();
  304.  
  305.    int iAttr = _parni(5);
  306.  
  307.    int vidSeg  = VIDSEG;
  308.    int numCols = _gtMaxCol() + 1;
  309.  
  310.    _gtPreExt();
  311.   
  312.    for (i = iTRow; i <= iBRow; ++i) {
  313.       scptr = MK_FP( vidSeg, ( ( i * numCols ) + iLCol ) * 2 );
  314.       scptr++;
  315.  
  316.       for (j = iLCol; j <= iRCol; ++j) {
  317.          *scptr = (unsigned char) iAttr;
  318.          scptr += 2;
  319.       }
  320.    }
  321.  
  322.    _gtPostExt();
  323.    _ret();
  324.    return;
  325. }
  326.  
  327.  
  328.  
  329. /*  $DOC$
  330.  *  $FUNCNAME$
  331.  *     FT_REVATTR()
  332.  *  $CATEGORY$
  333.  *     Video
  334.  *  $ONELINER$
  335.  *     Reverse colors of specified screen coordinates
  336.  *  $SYNTAX$
  337.  *     FT_REVATTR( <nTRow>, <nLCol>, <nBRow>, <nRCol> ) -> NIL
  338.  *  $ARGUMENTS$
  339.  *     <nTRow>, <nLCol>, <nBRow>, and <nRCol> are the coordinates of the
  340.  *     screen region.
  341.  *  $RETURNS$
  342.  *     NIL
  343.  *  $DESCRIPTION$
  344.  *     This is a high speed function to reverse the color of a specified
  345.  *     screen region without disturbing any text on the screen.  This
  346.  *     function will correctly reverse the color attributes in a region
  347.  *     containing multiple color combinations.
  348.  *  $EXAMPLES$
  349.  *     FT_REVATTR( 0, 0, MaxRow(), MaxCol() )
  350.  *  
  351.  *     This example will change the entire screen's colors to their reverse
  352.  *     attributes without changing  or overwriting any text.
  353.  *  $END$
  354.  */
  355.  
  356.  
  357. CLIPPER FT_REVATTR(void)
  358. {
  359.    char far *scrPtr;
  360.    int i, j;
  361.    
  362.    int iTRow = ISNUM(1) ? _parni(1) : 0;
  363.    int iLCol = ISNUM(2) ? _parni(2) : 0;
  364.    int iBRow = ISNUM(3) ? _parni(3) : _gtMaxRow();
  365.    int iRCol = ISNUM(4) ? _parni(4) : _gtMaxCol();
  366.  
  367.    int vidSeg  = VIDSEG;
  368.    int numCols = _gtMaxCol() + 1;
  369.  
  370.    _gtPreExt();
  371.    for (i = iTRow; i <= iBRow; ++i) {
  372.       scrPtr = MK_FP( vidSeg, ( ( i * numCols ) + iLCol ) * 2 );
  373.       scrPtr++;
  374.  
  375.       for (j = iLCol; j <= iRCol; ++j) {
  376.         *scrPtr = (*scrPtr>>4)|((*scrPtr&0x07)<<4)|
  377.                  (*scrPtr&0x08)|(*scrPtr&128);
  378.         scrPtr += 2;
  379.       }
  380.    }
  381.    _gtPostExt();
  382.    _ret();
  383.    return;
  384. }
  385.  
  386. /*  $DOC$
  387.  *  $FUNCNAME$
  388.  *     FT_REVCHR()
  389.  *  $CATEGORY$
  390.  *     Video
  391.  *  $ONELINER$
  392.  *     Reverse the color of a single character on the screen
  393.  *  $SYNTAX$
  394.  *     FT_REVCHR( <nTRow>, <nLCol> ) -> NIL
  395.  *  $ARGUMENTS$
  396.  *     <nTRow>, <nLCol> are the screen coordinates of the character.
  397.  *  $RETURNS$
  398.  *     NIL
  399.  *  $DESCRIPTION$
  400.  *     This is a high speed function to reverse the color of a single
  401.  *     character on the screen without changing the character itself.
  402.  *     This function is the same as FT_REVATTR() except that it changes
  403.  *     only one character on screen and hence is faster and uses less memory.
  404.  *  $EXAMPLES$
  405.  *     FT_REVCHR( 10, 20 )
  406.  * 
  407.  *     This example will change the text and background at 10, 20 to it's
  408.  *     reverse color attributes without changing or overwriting the
  409.  *     character itself.
  410.  *  $END$
  411.  */
  412.  
  413. CLIPPER FT_REVCHR(void)
  414. {
  415.    char far *scrPtr;
  416.    
  417.    int iTRow = _parni(1);
  418.    int iLCol = _parni(2);
  419.  
  420.    _gtPreExt();
  421.    scrPtr = MK_FP( VIDSEG, ( ( iTRow * _gtMaxCol()+1 ) + iLCol ) * 2 );
  422.    scrPtr++;
  423.    *scrPtr = (*scrPtr>>4)|((*scrPtr&0x07)<<4)|(*scrPtr&0x08)|(*scrPtr&128);
  424.    _gtPostExt();
  425.    _ret();
  426. }
  427.  
  428.  
  429.