home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Name KBREADY -- Return a character and scan code if one is
- ; ready in the keyboard buffer.
- ;
- ; Synopsis isrdy = kbready (pch, pscan);
- ;
- ; int isrdy 1 if a character is in the buffer,
- ; 0 if not.
- ;
- ; char *pch If a character is ready, the character
- ; is returned.
- ;
- ; int *pscan If a character is ready, its scan code
- ; is returned.
- ;
- ; Description This function returns the character and scan code of the
- ; next character in the BIOS type-ahead buffer if one is
- ; ready. If the buffer is empty, the values of *pch and
- ; *pscan are both undefined.
- ;
- ; If the global variable b_kbusex is set to KB_USE_EXTEND
- ; and if the extended BIOS keyboard services are
- ; available, then they are used. Otherwise the
- ; traditional keyboard service is used.
- ;
- ; KBREADY is similar to KBGETKEY, but the latter suspends
- ; execution until the buffer has an available character.
- ; Moreover, KBGETKEY removes the waiting character from
- ; the buffer, while KBREADY leaves the character waiting
- ; to be read again.
- ;
- ; Returns isrdy Character ready flag: 1 if ready, 0 if not.
- ; *pch Next character in buffer.
- ; *pscan Next scan code in the buffer.
- ;
- ; Version 6.00 (C)Copyright Blaise Computing Inc. 1987,1989
- ;
-
- include beginasm.mac
-
- extProc kbequip
- extSym b_kbusex,word
- extSym b_kbxten,word
-
- KB_USE_NORMAL equ 0 ;Values for b_kbusex.
- KB_USE_EXTEND equ 1
-
- KB_NOEXTENDED equ 0 ;Values for b_kbxten.
- KB_EXTENDED equ 1
-
- beginProg kbready
-
- if longData
- pch equ dword ptr [bp + stkoff + 0] ; Address of pch
- pscan equ dword ptr [bp + stkoff + 4] ; Address of pscan
- else
- pch equ word ptr [bp + stkoff + 0] ; Address of pch
- pscan equ word ptr [bp + stkoff + 2] ; Address of pscan
- endif
-
- ; Beginning of actual code
-
- push bp
- mov bp, sp
- cld
- pushf
-
- mov ch,1 ; BIOS keyboard function 1: test for key
-
- ; Check whether extended services requested.
- mov dx,ds ; (Save DS.)
- mov ax,seg b_kbusex@
- mov ds,ax
- assume ds:nothing
- cmp ds:b_kbusex@,KB_USE_NORMAL ; Extended services requested?
- mov ds,dx ; (Restore DS.)
- je after_check ; If not, use function 1.
-
- call kbequip@ ; Sense presence of extended services.
- cmp ax,KB_EXTENDED ; If extended services absent,
- jne after_check ; just use function 1.
-
- mov ch,11h ; Use extended service 11h
-
- after_check:
-
- mov ah,ch
- int 16h
-
- jz nochar ; Skip getting the char if there is
- ; not one to get.
- if longData
- push es
- les bx, pch ; Set up address, get character code.
- mov byte ptr es:[bx], al
- mov al, ah
- xor ah, ah
- les bx, pscan ; Set up address, get scan code.
- mov word ptr es:[bx], ax
- pop es
- else
- mov bx, pch ; Set up address, get character code.
- mov byte ptr [bx], al
- mov al, ah
- xor ah, ah
- mov bx, pscan ; Set up address, get scan code.
- mov word ptr [bx], ax
- endif
-
- mov ax, 1 ; Return a success code.
- jmp short endf
-
- nochar:
- mov ax, 0 ; Return a failure code.
-
- endf:
- popff
- pop bp
- ret
-
- endProg kbready
- end