home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / LIB / KEYPOLL.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-10-09  |  1.6 KB  |  80 lines

  1. ;
  2. ;  A keyboard polling routine written by Jason Nunn
  3. ;
  4. ;
  5. .386
  6. .model flat
  7. .code
  8.  
  9. public key_pressed,get_key
  10.  
  11.  
  12. ;*********************************************************************
  13. ;funciton:       key_pressed
  14. ;
  15. ;Description:   Detects if the BIOS keyboad buffer is empty.
  16. ;
  17. ;Returns:       Carry = 0 if key is empty
  18. ;               Carry = 1 if key is not empty
  19. ;*********************************************************************
  20.  
  21. ;*********************************************************************
  22. ;funciton:       get_key
  23. ;
  24. ;Description:    gets the next key from the BIOS keyboad buffer.
  25. ;                if not availible then waits for one.
  26. ;Returns:       AL = ascii code
  27. ;               AH = scan code
  28. ;*********************************************************************
  29.  
  30. key_pressed Proc
  31.   push   esi
  32.   mov    esi,[Zero_Addr]
  33.   test   esi,esi
  34.   jz     @@fixup_Zero_Addr
  35. @@fixed_Zero_Addr:
  36.  
  37.   add    esi,41ah
  38.   mov    ax,[esi]
  39.   cmp    ax,[word ptr esi+2]
  40.   jne    @@w
  41.   pop    esi
  42.   clc
  43.   ret
  44. @@w:
  45.   movzx  eax,ax
  46.   add    eax,400h
  47.   add    eax,[Zero_Addr]
  48.   mov    ax,[word ptr eax]
  49.   pop    esi
  50.   stc
  51.   ret
  52.  
  53. @@fixup_Zero_Addr:      ; get zero address
  54.   pushad
  55.   mov ax,0ee02h
  56.   int 31h
  57.   neg ebx
  58.   mov [Zero_Addr],ebx
  59.   popad
  60.   mov    esi,[Zero_Addr]
  61.  jmp @@fixed_Zero_Addr
  62. endp
  63.  
  64. Align 4
  65. get_key Proc
  66. @@l:
  67.   call   key_pressed
  68.   jnc    @@l
  69.   mov    eax,0
  70.   int    16h
  71.   mov    [last_get_key],al
  72.   ret
  73. endp
  74.  
  75. Align 4
  76. Zero_Addr             dd 0      ; contains address of linear address 0
  77. last_get_key          db ?
  78.  
  79. end