home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / INPUTPC.C < prev    next >
C/C++ Source or Header  |  1996-01-17  |  4KB  |  228 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <dos.h>
  4.  
  5. #include "input.h"
  6. #include "graph.h"
  7. #include "view.h"
  8.  
  9. #define    TRUE    1
  10. #define    FALSE    0
  11.  
  12. int        MouseX = 0, MouseY = 0 ;
  13. int        MouseLeft = 0, MouseRight = 0 ;
  14. int        MouseMove = FALSE ;
  15. int        KeyCode = 0 ;
  16. int        ShiftStat = 0 ;
  17.  
  18. static    int        Cx, Cy ;
  19. static    int        Cursor ;
  20.  
  21. static    int        KeySense( void );
  22. static    int        KeyIn( void );
  23. static    void    MouseON( int, int );
  24. static    void    MouseOFF( int, int );
  25.  
  26.  
  27. void    InitInput()
  28. {
  29.     union    REGS    regs ;
  30.  
  31.     Cx = Cy = 0 ;
  32.     CursorOFF();
  33.  
  34.     /*    mouse    */
  35.     regs.x.ax = 0x0000 ;
  36.     int86( 0x33, ®s, ®s );
  37.  
  38.     regs.x.ax = 0x0007 ;
  39.     regs.x.cx = 0 ;
  40.     regs.x.dx = Cols * 8 - 1 ;
  41.     int86( 0x33, ®s, ®s );
  42.  
  43.     regs.x.ax = 0x0008 ;
  44.     regs.x.cx = 0 ;
  45.     regs.x.dx = Lines * 16 - 1 ;
  46.     int86( 0x33, ®s, ®s );
  47. }
  48.  
  49. void    ExitInput()
  50. {
  51. }
  52.  
  53. /*    コンソール入力    */
  54. static    int        FuncKeyCode[] = { 0,
  55.     0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44,
  56.     0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D,
  57.     0x51, 0x49, 0x52, 0x53, 0x48, 0x4B, 0x4D, 0x50,
  58.     0x00, 0x00, 0x47, 0x00,
  59.     0xFF };
  60.  
  61. void    WaitInput()
  62. {
  63.     int        col, key ;
  64.     union    REGS    regs ;
  65.     static    int        selectcol ;
  66.     static    int        msw ;
  67.  
  68.     MouseON( MouseX, MouseY );
  69.  
  70.     do
  71.     {
  72.         /* key */
  73.         key = KeySense();
  74.  
  75.         /* mouse */
  76.         regs.x.ax = 0x0003 ;
  77.         int86( 0x33, ®s, ®s );
  78.  
  79.         /* select color */
  80.         selectcol = ( selectcol + 1 ) & 0xFFFF ;
  81.         col = ( selectcol >> 3 ) & 511 ;
  82.         if ( col >= 256 )
  83.             col = 511 - col ;
  84.         graph_palet( SELECT_COLOR, 255, 255-col, col );
  85.     }
  86.     while (msw == regs.x.bx && key == 0
  87.      && (regs.x.bx == 0 || (regs.x.cx == MouseX && regs.x.dx == MouseY)));
  88. #if 0
  89.     while( msw == 0 && regs.x.bx == 0 && regs.x.cx == MouseX && regs.x.dx == MouseY && key == 0 );
  90. #endif
  91. /*    while( regs.x.bx == msw && regs.x.cx == MouseX && regs.x.dx == MouseY && key == 0 );*/
  92.  
  93.     MouseOFF( MouseX, MouseY );
  94.  
  95.     MouseMove = ( regs.x.cx != MouseX ) || ( regs.x.dx != MouseY );
  96.     MouseX = regs.x.cx ;
  97.     MouseY = regs.x.dx ;
  98.     if ( key )
  99.         KeyCode = KeyIn();
  100.     else
  101.         KeyCode = 0 ;
  102.     ShiftStat = ShiftSense();
  103.     msw = regs.x.bx ;
  104.     MouseLeft = regs.x.bx & 1 ;
  105.     MouseRight = ( regs.x.bx & 2 ) >> 1 ;
  106. }
  107.  
  108. void    FlushKey()
  109. {
  110.     while( KeySense() )
  111.         KeyIn();
  112. }
  113.  
  114. static    int        ShiftSense()
  115. {
  116.     int        ret ;
  117.     union    REGS    regs ;
  118.  
  119.     regs.h.ah = 0x02 ;
  120.     int86( 0x16, ®s, ®s );
  121.  
  122.     ret = 0 ;
  123.     if ( regs.h.al & 0x03 )
  124.         ret |= 1 ;
  125.     if ( regs.h.al & 0x04 )
  126.         ret |= 2 ;
  127.     return ret ;
  128. }
  129.  
  130. static    int        KeySense()
  131. {
  132.     union    REGS    regs ;
  133.  
  134.     regs.h.ah = 0x01 ;
  135.     int86( 0x16, ®s, ®s );
  136.     return ( ( regs.x.flags & 0x040 ) == 0 );
  137. }
  138.  
  139. static    int        KeyIn()
  140. {
  141.     int        i ;
  142.     union    REGS    regs ;
  143.  
  144.     regs.h.ah = 0x00 ;
  145.     int86( 0x16, ®s, ®s );
  146.     if ( regs.h.al == 0 )
  147.     {
  148.         for( i = 0 ; FuncKeyCode[i] != 0xff ; i++ )
  149.         {
  150.             if ( FuncKeyCode[i] == regs.h.ah )
  151.                 return 0x8000 + i ;
  152.         }
  153.         return 0 ;
  154.     }
  155.     else
  156.         return regs.h.al ;
  157. }
  158.  
  159. /*
  160.  *  * *
  161.  *  * * * *
  162.  *    * * * * *
  163.  *    * * * * * * *
  164.  *      * * * * * * * *
  165.  *      * * * * * * * * * *
  166.  *        * * * * * * * * * * *
  167.  *        * * * * * * * * * * * * *
  168.  *          * * * * * * * * * * * 
  169.  *          * * * * * * * * * * 
  170.  *            * * * * * * * * 
  171.  *            * * * * * * * 
  172.  *              * * * * * 
  173.  *              * * * * 
  174.  *                * * 
  175.  *                * 
  176.  */
  177. static    short    MousePattern[16] = {
  178.     0xc000, 0xf000, 0x7c00, 0x7f00, 0x3fc0, 0x3ff0, 0x1ffc, 0x1fff,
  179.     0x0ffe, 0x0ffc, 0x07f8, 0x07f0, 0x03e0, 0x03c0, 0x0180, 0x0100 };
  180.  
  181. static    void    MouseON( x, y )
  182. int        x, y ;
  183. {
  184.     graph_pattern_xor( x, y, 0x1f, MousePattern, 16, 16 );
  185. }
  186.  
  187. static    void    MouseOFF( x, y )
  188. int        x, y ;
  189. {
  190.     graph_pattern_xor( x, y, 0x1f, MousePattern, 16, 16 );
  191. }
  192.  
  193. void    Locate( x, y )
  194. int        x, y ;
  195. {
  196.     Cx = x ;
  197.     Cy = y ;
  198.  
  199.     if ( Cursor )
  200.     {
  201.     }
  202. }
  203.  
  204. void    CursorON()
  205. {
  206.     Cursor = TRUE ;
  207.     Locate( Cx, Cy );
  208.  
  209. }
  210.  
  211. void    CursorOFF()
  212. {
  213.     Cursor = FALSE ;
  214. }
  215.  
  216. void    Bell()
  217. {
  218.     bdos( 6, 7, 0 );
  219. }
  220.  
  221. void    GetCursor( xp, yp )
  222. int        *xp, *yp ;
  223. {
  224.     *xp = Cx ;
  225.     *yp = Cy ;
  226. }
  227.  
  228.