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

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