home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / CLIBSRC3.ZIP / SCREEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  5.0 KB  |  174 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - screen.c
  3.  *
  4.  * function(s)
  5.  *        screenpos  - returns the current CP
  6.  *        moveto     - moves the CP to (x,y)
  7.  *        bios       - moves a block of screen data through bios
  8.  *        __screenio - moves a block of screen data
  9.  *        __validatexy - checks the validity of the window coordinates
  10.  *-----------------------------------------------------------------------*/
  11.  
  12. /*
  13.  *      C/C++ Run Time Library - Version 5.0
  14.  *
  15.  *      Copyright (c) 1987, 1992 by Borland International
  16.  *      All Rights Reserved.
  17.  *
  18.  */
  19.  
  20.  
  21. #include <_video.h>
  22. #include <dos.h>
  23. #include <conio.h>
  24. #include <string.h>
  25.  
  26. /*---------------------------------------------------------------------*
  27.  
  28. Name            screenpos - returns the current CP
  29.  
  30. Usage           static unsigned near pascal screenpos(void far *ptr);
  31.  
  32. Return value    current row/column in higher/lower byte
  33.  
  34. *---------------------------------------------------------------------*/
  35. static unsigned near pascal screenpos(void far *ptr)
  36. {
  37.         register unsigned offset;
  38.         unsigned char row, col;
  39.  
  40.         offset = FP_OFF(ptr) >> 1;
  41.         row = (unsigned char)(offset / _video.screenwidth);
  42.         col = (unsigned char)(offset - row * _video.screenwidth);
  43.  
  44.         _AH = row;
  45.         _AL = col;
  46.         return _AX;
  47. }
  48.  
  49.  
  50. /*---------------------------------------------------------------------*
  51.  
  52. Name            moveto - moves the CP to (x,y)
  53.  
  54. Usage           static void pascal moveto(unsigned *newpos, unsigned *oldpos);
  55.  
  56. Return value    None
  57.  
  58. *---------------------------------------------------------------------*/
  59. static void near pascal moveto(unsigned *newpos, unsigned *oldpos)
  60. {
  61.         _DX = *newpos;
  62.         if (_DX != *oldpos)
  63.         {
  64.                 _BH = 0;
  65.                 _AH = 2;
  66.                 _VideoInt();
  67.                 *oldpos = _DX;
  68.         }
  69.         _DL++;
  70.         if (_DL >= _video.screenwidth)
  71.         {
  72.                 _DH++;
  73.                 _DL = 0;
  74.         }
  75.         *newpos = _DX;
  76. }
  77.  
  78.  
  79.  
  80. /*---------------------------------------------------------------------*
  81.  
  82. Name            bios - moves a block of screen data through bios
  83.  
  84. Usage           static void near pascal bios(void far *dst, void far *src,
  85.                                              int len);
  86.  
  87. Return value    None
  88.  
  89. *---------------------------------------------------------------------*/
  90. static void near pascal bios(void far *dst, void far *src, int len)
  91. {
  92.         register unsigned charcell;
  93.         unsigned dstpos, srcpos, cursorpos;
  94.         int originalpos, dstvram, srcvram;
  95.  
  96.         cursorpos = originalpos = _wherexy();
  97.  
  98.         if ((dstvram = (FP_SEG(dst) == _video.displayptr.u.seg)) != 0)
  99.                 dstpos = screenpos(dst);
  100.  
  101.         if ((srcvram = (FP_SEG(src) == _video.displayptr.u.seg)) != 0)
  102.                 srcpos = screenpos(src);
  103.  
  104.         while (len--)
  105.         {
  106.  
  107.                 if (srcvram)
  108.                 {
  109.                         moveto(&srcpos, &cursorpos);
  110.                         _BH = 0;
  111.                         _AH = 8;
  112.                         _VideoInt();
  113.                         charcell = _AX;
  114.                 }
  115.                 else
  116.                         charcell = *((unsigned far *)src)++;
  117.  
  118.                 if (dstvram)
  119.                 {
  120.                         moveto(&dstpos, &cursorpos);
  121.                         _AX = charcell;
  122.                         _BL = _AH;
  123.                         _CX = 1;
  124.                         _BH = 0;
  125.                         _AH = 9;
  126.                         _VideoInt();
  127.                 }
  128.                 else
  129.                         *((unsigned far *)dst)++ = charcell;
  130.         }
  131.  
  132.         _DX = originalpos;
  133.         _BH = 0;
  134.         _AH = 2;
  135.         _VideoInt();
  136. }
  137.  
  138.  
  139. /*---------------------------------------------------------------------*
  140.  
  141. Name            __screenio -  moves a block of screen data
  142.  
  143. Usage           void pascal __screenio(void far *dst, void far *src, int len);
  144.  
  145. Return value    None
  146.  
  147. *---------------------------------------------------------------------*/
  148. void pascal near __screenio(void far *dst, void far *src, int len)
  149. {
  150.         if (!_video.graphicsmode && directvideo)
  151.                 __vram(dst, src, len);
  152.         else
  153.                 bios(dst, src, len);
  154. }
  155.  
  156.  
  157. /*---------------------------------------------------------------------*
  158.  
  159. Name            __validatexy - checks the validity of the screen coordinates
  160.  
  161. Usage           int pascal __validatexy(int x1, int y1, int x2, int y2);
  162.  
  163. Return value    __validatexy returns zero if the coordinates are invalid
  164.  
  165. *---------------------------------------------------------------------*/
  166. int pascal near __validatexy(int x1, int y1, int x2, int y2)
  167. {
  168.         _CX = _video.screenwidth;
  169.         _DX = _video.screenheight;
  170.         return !(x1 > _CX || x2 > _CX || x1 > x2 ||
  171.                  y1 > _DX || y2 > _DX || y1 > y2 ||
  172.                  x1 <= 0  || x2 <= 0  || y1 <= 0 || y2 <= 0);
  173. }
  174.