home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 3 / FreeSoftwareCollection3pd199x-jp.img / pao / ms_dos / wild / src / kyb.c < prev    next >
Text File  |  1980-01-02  |  3KB  |  121 lines

  1. /******************************************************************************
  2. **
  3. **        KEY.LIB << MSC V5.1 >>
  4. **
  5. **        <HISTORY>
  6. **        1990.07.03 : CREATE
  7. **
  8. **        Programed by Y.HIRATA Nifty-ID (NAB03321)
  9. **
  10. ******************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <dos.h>
  16. #include <conio.h>
  17. #include "kyb.h"
  18.  
  19. /****************************  10us 単位でのWAIT  ****************************/
  20. void soft_time( unsigned short waitcount )
  21. {
  22.     union    REGS    regs ;
  23.  
  24.     regs.x.cx = waitcount ;
  25.  
  26.     int86( 0xFD,®s,®s ) ;
  27.  
  28.     return ;
  29. }
  30.  
  31. /******************************************************************************
  32.     KEY_read : 一文字入力(キーボード)
  33.     < RETURN >
  34.     文字コード, 入力なしの場合には 0 を返す。
  35. ******************************************************************************/
  36. unsigned    KEY_read( waitsw, encode )
  37. unsigned    waitsw ;    /*  キー入力待ち指定 : 0 - 入力待ち                */
  38.                         /*                     : 1 - 入力待ちなし            */
  39. unsigned    *encode ;    /*  エンコード情報                                */
  40. {
  41.     union    REGS    regs ;
  42.  
  43.     regs.h.ah = 0x09 ;
  44.     regs.h.al = waitsw ;
  45.  
  46.     int86( KEY_INT,®s,®s ) ;
  47.  
  48.     if ( regs.h.ah==0x00 ) {
  49.         if ( regs.h.dh==0xff ) {            /*  入力文字なし    */
  50.             *encode = 0 ;
  51.             return(0) ;
  52.         } else {                            /*  入力文字あり    */
  53.             *encode = regs.x.bx ;
  54.             return( regs.h.dl ) ;
  55.         }
  56.     }
  57.     *encode = 0 ;
  58.     return(0) ;
  59. }
  60.  
  61. /******************************************************************************
  62.     KEY_matrix : マトリクス入力
  63. ******************************************************************************/
  64. int        KEY_matrix( matrix )
  65. char    *matrix ;        /*  マトリクス情報( 16 バイト )                    */
  66. {
  67.     union    REGS    regs ;
  68.     struct    SREGS    sregs ;
  69.     char    matx[16] ;
  70.  
  71.     regs.h.ah = 0x0A ;
  72.     regs.h.al = 0x00 ;
  73.     regs.x.di = (unsigned int)matx ;
  74.  
  75.     segread( &sregs ) ;
  76.     int86x( KEY_INT,®s,®s,&sregs ) ;
  77.  
  78.     memcpy( matrix,matx,16 ) ;
  79.  
  80.     return( regs.h.ah ) ;
  81. }
  82.  
  83. /******************************************************************************
  84.     KEY_test : マトリクスからキーが押されているかどうかをチェックする。
  85. ******************************************************************************/
  86. int        KEY_test( matrix,keyadrs )
  87. char    *matrix ;        /*  マトリクス情報( 16 バイト )                    */
  88. char    keyadrs ;        /*  キーアドレス                                */
  89. {
  90.     unsigned char    testbit ;
  91.     int        c ;
  92.  
  93.     testbit = 0x01 ;
  94.     for ( c=0; c<(keyadrs%8); c++ ) testbit <<= 1 ;
  95.     if ( (matrix[keyadrs/8] & testbit) == testbit ) return( TRUE ) ;
  96.  
  97.     return( FALSE ) ;
  98. }
  99.  
  100. /******************************************************************************
  101.     KEY_bufcls : バッファクリア
  102. ******************************************************************************/
  103. int        KEY_bufcls()
  104. {
  105.     union    REGS    regs ;
  106.  
  107.     regs.h.ah = 0x06 ;
  108.     regs.h.al = 0x00 ;
  109.  
  110.     int86( KEY_INT,®s,®s ) ;
  111.  
  112.     return( regs.h.ah ) ;
  113. }
  114.  
  115. /***************************  ^C を受け付けない入力  *************************/
  116. int inkey()
  117. {
  118.     return( bdos(6,0xFF,0x00) & 0x00ff ) ;
  119. }
  120.  
  121.