;       SCCSID = @(#)kbdgets.asm	6.1 91/02/15
;	SCCSID = @(#)kbdgets.asm	6.2 90/01/22
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
	Page	60,132
;
;	Modification History
;
;	14-Aug-86 (billme) Change status flag to use cs segment
;	19-Aug-86 (billme): change to new scheme (see kbdstrng.asm)
;
;	15-Jan-87 (billme): Replace initial pushes and final pops
;	with calls to __api_begin and __api_end resp.  This will
;	reduce the size of FAPI and allow support for signals.
;
;/*************** START OF SPECIFICATIONS ******************************/
;/*								       */
;/* SUBROUTINE NAME:  KbdGetStatus				       */
;/*								       */
;/* DESCRIPTIVE NAME:  Get the current state of the keyboard.	       */
;/*								       */
;/* FUNCTION:  This function allows the user to query the current state*/
;/*	       of the keyboard.					       */
;/*								       */
;/* NOTES:  KbdHandle is ignored for Version 1.0.		       */
;/*								       */
;/* ENTRY POINT:						       */
;/*	    LINKAGE:  EXTRN KbdGetStatus:FAR			       */
;/*								       */
;/* INPUT:	      push@ OTHER Structure			       */
;/*		      push  WORD  KbdHandle			       */
;/*		      call  KbdGetStatus			       */
;/*								       */
;/* EXIT-NORMAL:  AX = 0					       */
;/*								       */
;/* EXIT-ERROR:	 AX = Error Code				       */
;/*								       */
;/* EFFECTS:							       */
;/*								       */
;/* INTERNAL REFERENCES:					       */
;/*    ROUTINES:						       */
;/*								       */
;/* EXTERNAL REFERENCES:					       */
;/*    ROUTINES:						       */
;/*								       */
;/*************** END OF SPECIFICATIONS ********************************/

	.xlist
	include kbdfapi.inc
	include error2.inc
	.list

	EXTRN	__api_begin:near
	EXTRN	__api_end:near

_TEXT	SEGMENT BYTE	PUBLIC	'CODE'
_TEXT	ENDS


KBDSTAT STRUC			; stack frame snap shot

		dw	?	; BP
		dw	?	; IP
		dw	?	; CS
		dw	?	; dummy keyboard handle (0)
	Buffer	dd	?	; Structure address

KBDSTAT ENDS


DSEG	SEGMENT BYTE	PUBLIC	'DATA'

DSEG	ENDS

	EXTRN	StatusFlag:BYTE
	EXTRN	kbd_prep:NEAR

	PUBLIC	KBDGETSTATUS


_TEXT	segment byte public 'CODE'
	assume	CS:_TEXT,DS:NOTHING


KBDGETSTATUS	PROC	FAR

IFDEF api_debug_pause
	int	3	; included ONLY IF api_debug_pause is defined
ENDIF

	call	_TEXT:__api_begin	; init bp and save bp,ds,bx,cx,dx,si,di,es
				; required to save: bp,bx,ds,es

		lds	bx,[bp].Buffer		; get buffer address
		mov	ax,BUFFER_LEN
		cmp	[bx].KbdStatLength,ax	; user struc large enough?
		jae	RetLength		; Yes
		mov	ax,ERROR_KBD_INVALID_LENGTH
		jmp	short KbdGetexit
RetLength:
		mov	[bx].KbdStatLength,ax	; return actual length
KbdGetprocess:
		mov	ax,BIOS_SEGMENT
		mov	es,ax			; get current shift state
		mov	ax,es:[KBDFLAG]		; bios keyboard i/o
		mov	[bx].Shift_State,ax	; return shift state
		mov	[bx].TA_Char,TURNAROUNDCHAR ; TurnAround character
		mov	[bx].Interim_Char,NULL	; return interim character flag
		mov	[bx].NLS_Shift_State,NULL; return NLS shift state
RetStatusFlag:
		mov	al,cs:StatusFlag	; get status flag content
		xor	ah,ah			; reserved mask bits
		mov	[bx].KbdStatMask,ax	; return current status
		xor	ax,ax			; no error
KbdGetexit:

	call	_TEXT:__api_end	; check sigs & restore es,di,si,dx,cx,bx,ds,bp

		ret	6			; clear stack frame

KBDGETSTATUS	ENDP

_TEXT	ends
	END
