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