home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / SCPGCUR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  4.1 KB  |  149 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.  No action will be
  18. *        taken unless this page is active (displayed).
  19. *
  20. *        The cursor size is determined by the upper and lower
  21. *        scan lines, whose values can be between 0 and 13 for the
  22. *        Monochrome Adapter, and 0 and 7 for the Color/Graphics
  23. *        Adapter.  If off is nonzero, the cursor is turned off
  24. *        (no display); otherwise it is on.
  25. *
  26. *        Blaise C TOOLS do not record cursor sizes and on/off
  27. *        states for inactive display pages.  That is, the cursor
  28. *        size for the active page also applies to all inactive
  29. *        pages.
  30. *
  31. * Returns    scur          Value of "off" parameter (0 = on)
  32. *
  33. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986-1989
  34. *
  35. **/
  36.  
  37. #include <dos.h>
  38.  
  39. #include <bscreens.h>
  40.  
  41. int scpgcur(off,high,low,adjust)
  42. int off;
  43. int high;
  44. int low;
  45. int adjust;
  46. {
  47.     union REGS inregs,outregs;          /* General registers          */
  48.  
  49.     int  dev,mode,act_page,columns;
  50.     unsigned int max_scan_line;
  51.  
  52.                   /* Address of BIOS INFO byte.          */
  53. #define  INFO_LOC  (uttofar(0x0040,0x0087,unsigned char))
  54.  
  55.     char info;
  56.     int  changed_info,truncate;
  57.  
  58.     dev = scmode(&mode,&columns,&act_page);
  59.  
  60.     if (b_curpage == act_page)          /* Change physical cursor if    */
  61.     {                      /* current page is active.      */
  62.     scequip();
  63.     if (dev == b_mdpa)
  64.         max_scan_line = 13;
  65.     else if (dev == b_cga || dev == b_pgc || b_pcmodel == IBM_JR)
  66.         max_scan_line = 7;
  67.     else
  68.     {
  69.         inregs.x.ax = 0x1130;
  70.         inregs.h.bh = 0;
  71.         int86(SC_BIOS_INT,&inregs,&outregs);
  72.         max_scan_line = outregs.x.cx - 1;
  73.     }
  74.  
  75.     changed_info = 0;
  76.     if (adjust == CUR_NO_ADJUST)
  77.     {
  78.  
  79.     /* In the unnatural case where there are 43 or more text lines and*/
  80.     /* cursor compensation is enabled, disable the compensation and   */
  81.     /* restore it at exit.                          */
  82.  
  83.         if (max_scan_line > 7)
  84.         {
  85.         info = utpeekb(INFO_LOC);
  86.         if (0 == (info & 1))  /* If compensation enabled,     */
  87.         {
  88.             info |= 1;          /* disable compensation.          */
  89.             utpokeb(INFO_LOC,info);
  90.             changed_info = 1;
  91.         }
  92.         }
  93.     }
  94.     else
  95.     {
  96.  
  97.     /* We may need to adjust the requested scan lines to fit into the */
  98.     /* 0-7 range.  This is needed if a scan line exceeds 7 and if one */
  99.     /* of the following is true:                      */
  100.     /*                                      */
  101.     /*      1) this is the Color/Graphics Adapter;              */
  102.     /*      2) this is 43-line mode (there are only 8 scan lines);      */
  103.     /*      3) EGA cursor compensation is being performed in a 14-scan- */
  104.     /*         line environment.                          */
  105.  
  106.         high = utlonyb(high);
  107.         low  = utlonyb(low);
  108.         if (   dev        != SC_MONO
  109.         || max_scan_line <= 7)
  110.         {
  111.         if (   (dev == b_ega || dev == b_vga || dev == b_mcga)
  112.             && max_scan_line > 7)
  113.         {          /* If EGA, truncate scan lines only if  */
  114.                   /* BIOS cursor compensation is enabled  */
  115.                   /* (i.e., bit 1 of INFO is off).          */
  116.             info = utpeekb(INFO_LOC);
  117.             truncate = (0 == (info & 1));
  118.         }
  119.         else
  120.             truncate = 1;
  121.  
  122.         if (truncate)
  123.         {
  124.             if (high > max_scan_line)
  125.             high = (max_scan_line * high) / 13;
  126.             if (low > max_scan_line)
  127.             low  = (max_scan_line * low) / 13;
  128.         }
  129.         }
  130.     }
  131.  
  132.     if (off)              /* Set bits 4 and 5 if turning  */
  133.        high |= 0x0030;          /* cursor off.              */
  134.     inregs.h.ah = 1;
  135.     inregs.h.ch = (unsigned char) high;
  136.     inregs.h.cl = (unsigned char) low;
  137.     int86(16,&inregs,&outregs);
  138.  
  139.     if (changed_info)
  140.     {
  141.         info &= ~1;           /* Clear compensation bit (turn */
  142.                       /* compensation back on).       */
  143.         utpokeb(INFO_LOC,info);
  144.     }
  145.     }
  146.  
  147.     return(off);
  148. }
  149.