home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / KBREADY.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-03-31  |  3.1 KB  |  123 lines

  1. ;
  2. ; Name        KBREADY -- Return a character and scan code if one is
  3. ;               ready in the keyboard buffer.
  4. ;
  5. ; Synopsis    isrdy = kbready (pch, pscan);
  6. ;
  7. ;        int  isrdy      1 if a character is in the buffer,
  8. ;                  0 if not.
  9. ;
  10. ;        char *pch      If a character is ready, the character
  11. ;                  is returned.
  12. ;
  13. ;        int  *pscan      If a character is ready, its scan code
  14. ;                  is returned.
  15. ;
  16. ; Description    This function returns the character and scan code of the
  17. ;        next character in the BIOS type-ahead buffer if one is
  18. ;        ready.    If the buffer is empty, the values of *pch and
  19. ;        *pscan are both undefined.
  20. ;
  21. ;        If the global variable b_kbusex is set to KB_USE_EXTEND
  22. ;        and if the extended BIOS keyboard services are
  23. ;        available, then they are used.    Otherwise the
  24. ;        traditional keyboard service is used.
  25. ;
  26. ;        KBREADY is similar to KBGETKEY, but the latter suspends
  27. ;        execution until the buffer has an available character.
  28. ;        Moreover, KBGETKEY removes the waiting character from
  29. ;        the buffer, while KBREADY leaves the character waiting
  30. ;        to be read again.
  31. ;
  32. ; Returns    isrdy          Character ready flag:  1 if ready, 0 if not.
  33. ;        *pch          Next character in buffer.
  34. ;        *pscan          Next scan code in the buffer.
  35. ;
  36. ; Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  37. ;
  38.  
  39.     include beginasm.mac
  40.  
  41.     extProc kbequip
  42.     extSym    b_kbusex,word
  43.     extSym    b_kbxten,word
  44.  
  45. KB_USE_NORMAL    equ 0        ;Values for b_kbusex.
  46. KB_USE_EXTEND    equ 1
  47.  
  48. KB_NOEXTENDED    equ 0        ;Values for b_kbxten.
  49. KB_EXTENDED    equ 1
  50.  
  51.     beginProg kbready
  52.  
  53.     if longData
  54.         pch   equ dword ptr [bp + stkoff + 0]  ; Address of pch
  55.         pscan equ dword ptr [bp + stkoff + 4]  ; Address of pscan
  56.     else
  57.         pch   equ word ptr [bp + stkoff + 0]  ; Address of pch
  58.         pscan equ word ptr [bp + stkoff + 2]  ; Address of pscan
  59.     endif
  60.  
  61.     ;   Beginning of actual code
  62.  
  63.     push    bp
  64.     mov    bp, sp
  65.     cld
  66.     pushf
  67.  
  68.     mov    ch,1           ; BIOS keyboard function 1:    test for key
  69.  
  70.                    ; Check whether extended services requested.
  71.     mov    dx,ds           ; (Save DS.)
  72.     mov    ax,seg b_kbusex@
  73.     mov    ds,ax
  74.     assume    ds:nothing
  75.     cmp    ds:b_kbusex@,KB_USE_NORMAL  ; Extended services requested?
  76.     mov    ds,dx                ; (Restore DS.)
  77.     je    after_check            ; If not, use function 1.
  78.  
  79.     call    kbequip@        ; Sense presence of extended services.
  80.     cmp    ax,KB_EXTENDED        ; If extended services absent,
  81.     jne    after_check        ; just use function 1.
  82.  
  83.     mov    ch,11h            ; Use extended service 11h
  84.  
  85. after_check:
  86.  
  87.     mov    ah,ch
  88.     int    16h
  89.  
  90.     jz    nochar           ; Skip getting the char if there is
  91.                    ; not one to get.
  92.     if     longData
  93.         push es
  94.         les  bx, pch       ; Set up address, get character code.
  95.         mov  byte ptr es:[bx], al
  96.         mov  al, ah
  97.         xor  ah, ah
  98.         les  bx, pscan       ; Set up address, get scan code.
  99.         mov  word ptr es:[bx], ax
  100.         pop  es
  101.     else
  102.         mov  bx, pch       ; Set up address, get character code.
  103.         mov  byte ptr [bx], al
  104.         mov  al, ah
  105.         xor  ah, ah
  106.         mov  bx, pscan       ; Set up address, get scan code.
  107.         mov  word ptr [bx], ax
  108.     endif
  109.  
  110.     mov    ax, 1           ; Return a success code.
  111.     jmp    short endf
  112.  
  113. nochar:
  114.     mov    ax, 0           ; Return a failure code.
  115.  
  116. endf:
  117.     popff
  118.     pop    bp
  119.     ret
  120.  
  121.     endProg kbready
  122.     end
  123.