home *** CD-ROM | disk | FTP | other *** search
/ Teach Yourself Game Programming in 21 Days / TYGAMES_R.ISO / source / day_07 / graph7k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-16  |  1.7 KB  |  68 lines

  1.  
  2. // I N C L U D E S ///////////////////////////////////////////////////////////
  3.  
  4. #include <dos.h>
  5. #include <bios.h>
  6. #include <stdio.h>
  7. #include <math.h>
  8. #include <conio.h>
  9. #include "graph7k.h"
  10.  
  11. // F U N C T I O N S /////////////////////////////////////////////////////////
  12.  
  13. unsigned char Get_Ascii_Key(void)
  14.  
  15. {
  16.  
  17. // if there is a normal ascii key waiting then return it, else return 0
  18.  
  19. if (_bios_keybrd(_KEYBRD_READY))
  20.  return(_bios_keybrd(_KEYBRD_READ));
  21. else return(0);
  22.  
  23. } // end Get_Ascii_Key
  24.  
  25. //////////////////////////////////////////////////////////////////////////////
  26.  
  27. unsigned int Get_Control_Keys(unsigned int mask)
  28. {
  29. // return the status of all the requested control key
  30.  
  31. return(mask & _bios_keybrd(_KEYBRD_SHIFTSTATUS));
  32.  
  33. } // end Get_Control_Keys
  34.  
  35. //////////////////////////////////////////////////////////////////////////////
  36.  
  37. unsigned char Get_Scan_Code(void)
  38. {
  39. // get the scan code of a key press, since we have to look at status bits
  40. // let's use the inline assembler
  41.  
  42.  
  43. // is a key ready?
  44.  
  45. __asm
  46.     {
  47.     mov ah,01h          ; function 1: is a key ready?
  48.     int 16h             ; call the interrupt
  49.     jz empty            ; there was no key so exit
  50.     mov ah,00h          ; function 0: get the scan code please
  51.     int 16h             ; call the interrupt
  52.     mov al,ah           ; result was in ah so put into al
  53.     xor ah,ah           ; zero out ah
  54.     jmp done            ; data's in ax...let's blaze!
  55.  
  56. empty:
  57.      xor ax,ax          ; clear out ax i.e. 0 means no key
  58. done:
  59.  
  60.     } // end asm
  61.  
  62. // since data is in ax it will be returned properly
  63.  
  64. } // end Get_Scan_Code
  65.  
  66. //////////////////////////////////////////////////////////////////////////////
  67.  
  68.