home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / SAMPLES / CPPTUTOR / OOD / MISC.CP$ / MISC
Encoding:
Text File  |  1992-02-21  |  5.0 KB  |  244 lines

  1. // FILE: MISC.CPP
  2.  
  3. #include "misc.h"
  4.  
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include <dos.h>
  8.  
  9. /********************************************************************
  10.  
  11.  Screen::showChar
  12.  
  13.  This function displays the specified character at the specified
  14.  position.
  15.  
  16. ********************************************************************/
  17.  
  18.  
  19. void Screen::showChar( Point loc, char chr, unsigned char attr )
  20. {
  21.     union REGS regs;
  22.  
  23.     regs.h.ah = 2;
  24.     regs.h.bh = 0;
  25.     regs.h.dh = --loc.y;
  26.     regs.h.dl = --loc.x;
  27.  
  28.     int86( 0x10, ®s, ®s );
  29.  
  30.     regs.h.ah = 9;
  31.     regs.h.al = (int)chr;
  32.     regs.h.bh = 0;
  33.     regs.h.bl = (int)attr;
  34.     regs.x.cx = 1;
  35.     int86( 0x10, ®s, ®s );
  36. }
  37.  
  38. /********************************************************************
  39.  
  40.  Screen::setCurPos
  41.  
  42.  This function moves the screen cursor to the specified position.
  43.  
  44. ********************************************************************/
  45.  
  46. void Screen::setCurPos( Point loc )
  47. {
  48.     union REGS regs;
  49.  
  50.     regs.h.ah = 2;
  51.     regs.h.bh = 0;
  52.     regs.h.dh = --loc.y;
  53.     regs.h.dl = --loc.x;
  54.  
  55.     int86( 0x10, ®s, ®s );
  56. }
  57.  
  58. /********************************************************************
  59.  
  60.  Screen::cursorOff
  61.  
  62.  This function hides the screen cursor.
  63.  
  64. ********************************************************************/
  65.  
  66. void Screen::cursorOff()
  67. {
  68.     union REGS regs;
  69.  
  70.     regs.h.ah = 3;
  71.     regs.h.bh = 0;
  72.  
  73.     int86( 0x10, ®s, ®s );
  74.  
  75.     cursorShape = regs.x.cx;
  76.  
  77.     regs.h.ah = 1;
  78.     regs.x.cx = 0x2000;
  79.     int86( 0x10, ®s, ®s );
  80. }
  81.  
  82. /********************************************************************
  83.  
  84.  Screen::cursorOn
  85.  
  86.  This function displays the screen cursor.
  87.  
  88. ********************************************************************/
  89.  
  90. void Screen::cursorOn()
  91. {
  92.     union REGS regs;
  93.  
  94.     regs.h.ah = 1;
  95.     regs.x.cx = cursorShape;
  96.  
  97.     int86( 0x10, ®s, ®s );
  98. }
  99.  
  100.  
  101. Screen theScreen;  // global Screen object
  102.  
  103. /********************************************************************
  104.  
  105.  Mouse::Mouse
  106.  
  107.  This function checks whether a mouse exists and sets the
  108.  existence flag accordingly.
  109.  
  110. ********************************************************************/
  111.  
  112. Mouse::Mouse()
  113. {
  114.  
  115.     if( reset() )
  116.     {
  117.         show();
  118.         exists = 1;
  119.     }
  120.     else
  121.         exists = 0;
  122. }
  123.  
  124.  
  125. /********************************************************************
  126.  
  127.  Mouse::reset
  128.  
  129.  This function resets the mouse.
  130.  
  131. ********************************************************************/
  132.  
  133. int Mouse::reset()
  134. {
  135.     union REGS regs;
  136.  
  137.     regs.x.ax = 0;               // Mouse function 0: reset
  138.     int86( 0x33, ®s, ®s );
  139.     return regs.x.ax;
  140. }
  141.  
  142.  
  143. /********************************************************************
  144.  
  145.  Mouse::show
  146.  
  147.  This function displays the mouse cursor.
  148.  
  149. ********************************************************************/
  150.  
  151. int Mouse::show()
  152. {
  153.     union REGS regs;
  154.  
  155.     if( exists )
  156.     {
  157.         regs.x.ax = 1;           // Mouse Function 1: show cursor
  158.         int86( 0x33, ®s, ®s );
  159.         return 1;
  160.     }
  161.     else return 0;
  162. }
  163.  
  164. /********************************************************************
  165.  
  166.  Mouse::hide
  167.  
  168.  This function hides the mouse cursor.
  169.  
  170. ********************************************************************/
  171.  
  172. int Mouse::hide()
  173. {
  174.     union REGS regs;
  175.  
  176.     if( exists )
  177.     {
  178.         regs.x.ax = 2;               // Mouse function 2: hide cursor
  179.         int86( 0x33, ®s, ®s );
  180.         return 1;
  181.     }
  182.     else return 0;
  183. }
  184.  
  185. /********************************************************************
  186.  
  187.  Mouse::read
  188.  
  189.  This function reads the current position of the mouse cursor and
  190.  the current status of the mouse buttons, whether or not any
  191.  mouse event occurred.
  192.  
  193. ********************************************************************/
  194.  
  195. int Mouse::read( MouseStatus *status )
  196. {
  197.     union REGS regs;
  198.  
  199.     if( exists )
  200.     {
  201.         regs.x.ax = 3;               // Mouse function 3: get status
  202.         int86( 0x33, ®s, ®s );
  203.  
  204.         status->position.x = (regs.x.cx >> 3) + 1;
  205.         status->position.y = (regs.x.dx >> 3) + 1;
  206.         status->button = regs.x.bx;
  207.  
  208.         return 1;
  209.     }
  210.     else return 0;
  211. }
  212.  
  213. /********************************************************************
  214.  
  215.  Mouse::move
  216.  
  217.  This function moves the mouse cursor to the specified position.
  218.  
  219. ********************************************************************/
  220.  
  221. int Mouse::move( Point position )
  222. {
  223.     union REGS regs;
  224.  
  225.     if( exists )
  226.     {
  227.         position.x--;        // adjust column,row to virtual x,y coords
  228.         position.y--;
  229.         position.x <<= 3;
  230.         position.y <<= 3;
  231.  
  232.         regs.x.ax = 4;             // Mouse function 4: move cursor
  233.         regs.x.cx = position.x;
  234.         regs.x.dx = position.y;
  235.         int86( 0x33, ®s, ®s );
  236.         return 1;
  237.     }
  238.     else return 0;
  239. }
  240.  
  241.  
  242. Mouse theMouse;   // global Mouse object
  243.  
  244.