home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / SCPGCUR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  5.1 KB  |  173 lines

  1. /**
  2. *
  3. * Name        scpgcur -- Set the cursor size on current display page
  4. *
  5. * Synopsis    scur = scpgcur(off,high,low,adjust);
  6. *
  7. *        int scur      Value of "off" parameter
  8. *        int off       Cursor off indicator (0 = on)
  9. *        int high      The cursor upper scan line
  10. *        int low       The cursor lower scan line
  11. *        int adjust      CUR_ADJUST if cursor scan lines are
  12. *                  to be adjusted to fit into limits
  13. *                  imposed by current video device;
  14. *                  CUR_NO_ADJUST if not.
  15. *
  16. * Description    This function sets the size and on/off state of the
  17. *        cursor on the current display page.  (The change will
  18. *        not appear on the screen until this page is active
  19. *        (displayed).)
  20. *
  21. *        The cursor size is determined by the upper and lower
  22. *        scan lines, whose values can be between 0 and 13 for the
  23. *        Monochrome Adapter, and 0 and 7 for the Color/Graphics
  24. *        Adapter.  If off is nonzero, the cursor is turned off
  25. *        (no display); otherwise it is on.
  26. *
  27. *        If no cursor size has yet been requested for the other
  28. *        display pages on the current video adapter, the cursor
  29. *        size requested for the current page is also recorded for
  30. *        the other pages.  However, the changes in the other
  31. *        pages' cursors will not take effect until those other
  32. *        pages are displayed using SCACTPG.
  33. *
  34. * Returns    scur          Value of "off" parameter (0 = on)
  35. *
  36. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  37. *
  38. * Version    3.02 March 24, 1987
  39. *        Prevented adjustment of INFO byte in cases when we're
  40. *            not going to touch the physical cursor.
  41. *
  42. **/
  43.  
  44. #include <bscreen.h>
  45.  
  46.                       /* Cursor type for each display */
  47. CUR_TYPE b_curtype[MAX_DEVICES][MAX_PAGES] = {0};         /* page. */
  48.  
  49. int b_curoff[MAX_DEVICES][MAX_PAGES] = {0};  /* Cursor on/off state   */
  50.                          /* for each display page */
  51.  
  52. int b_curknown[MAX_DEVICES] = {0};    /* Internal flag:  zero means   */
  53.                       /* cooresponding row of          */
  54.                       /* b_curtype[][] and b_curoff[] */
  55.                       /* are not yet initialized.     */
  56.  
  57. int scpgcur(off,high,low,adjust)
  58. int off;
  59. int high;
  60. int low;
  61. int adjust;
  62. {
  63.     int ax,bx,cx,dx,flags;          /* General registers          */
  64.  
  65.     int dev,mode,columns,act_page;
  66.     int page;
  67.  
  68.     static ADS INFO_ads = {0x0087,0x0040};
  69.     char       info;
  70.     ADS        info_ads;
  71.     int        changed_info,truncate;
  72.  
  73.     dev = scmode(&mode,&columns,&act_page);
  74.  
  75.     changed_info = 0;
  76.     if (adjust == CUR_NO_ADJUST)
  77.     {
  78.  
  79.     /* In the unnatural case where there are 43 text lines and EGA    */
  80.     /* cursor compensation is enabled, disable the compensation and   */
  81.     /* restore it at exit.                          */
  82.  
  83.     if (   b_curpage == act_page
  84.         && scrows()  == 43)
  85.     {
  86.         utabsptr(&info,&info_ads);
  87.         utslmove(&INFO_ads,&info_ads,1);
  88.         if (0 == (info & 1))      /* If compensation enabled,     */
  89.         {
  90.         info |= 1;          /* disable compensation.          */
  91.         utslmove(&info_ads,&INFO_ads,1);
  92.         changed_info = 1;
  93.         }
  94.     }
  95.     }
  96.     else
  97.     {
  98.  
  99.     /* We may need to adjust the requested scan lines to fit into the */
  100.     /* 0-7 range.  This is needed if a scan line exceeds 7 and if one */
  101.     /* of the following is true:                      */
  102.     /*                                      */
  103.     /*      1) this is the Color/Graphics Adapter;              */
  104.     /*      2) this is 43-line mode (there are only 8 scan lines);      */
  105.     /*      3) EGA cursor compensation is being performed in a 14-scan- */
  106.     /*         line environment.                          */
  107.  
  108.     high = utlonyb(high);
  109.     low  = utlonyb(low);
  110.     if (   dev    != MONO
  111.         || scrows() == 43)
  112.     {
  113.         scequip();
  114.         if (dev == b_ega && scrows() == 25)
  115.         {              /* If EGA, truncate scan lines only if  */
  116.                   /* BIOS cursor compensation is enabled  */
  117.                   /* (i.e., bit 1 of INFO is off).          */
  118.         utabsptr(&info,&info_ads);
  119.         utslmove(&INFO_ads,&info_ads,1);
  120.         truncate = (0 == (info & 1));
  121.         }
  122.         else
  123.         truncate = 1;
  124.  
  125.         if (truncate)
  126.         {
  127.         if (high > 7)
  128.             high = (7 * high) / 13;
  129.         if (low > 7)
  130.             low  = (7 * low) / 13;
  131.         }
  132.     }
  133.     }
  134.  
  135.     if (!b_curknown[dev])          /* If b_curtype[dev][] is not   */
  136.                       /* initialized, fill it with    */
  137.                       /* requested cursor state.      */
  138.     {
  139.     for (page = 0; page < MAX_PAGES; page++)
  140.     {
  141.         b_curoff [dev][page]      = off;
  142.         b_curtype[dev][page].high = high;
  143.         b_curtype[dev][page].low  = low;
  144.     }
  145.     b_curknown[dev] = 1;          /* Now b_curtype[dev][] is      */
  146.     }                      /* valid.               */
  147.     else
  148.     {                      /* Record new cursor type.      */
  149.     b_curoff [dev][b_curpage]      = off;
  150.     b_curtype[dev][b_curpage].high = high;
  151.     b_curtype[dev][b_curpage].low  = low;
  152.     }
  153.  
  154.     if (b_curpage == act_page)          /* Change physical cursor if    */
  155.                       /* current page is active.      */
  156.     {
  157.     if (off)              /* Set bits 4 and 5 if turning  */
  158.        high |= 0x0030;          /* cursor off.              */
  159.     ax = 0x0100;
  160.     cx = utbyword(high,low);
  161.     bios(16,&ax,&bx,&cx,&dx,&flags);
  162.     }
  163.  
  164.     if (changed_info)
  165.     {
  166.     info &= ~1;              /* Clear compensation bit (turn */
  167.                       /* compensation back on).       */
  168.     utslmove(&info_ads,&INFO_ads,1);
  169.     }
  170.  
  171.     return(off);
  172. }
  173.