;       SCCSID = @(#)kbdpeek.asm	6.1 91/02/15
;      SCCSID = @(#)kbdpeek.asm	6.3 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
;
;	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:  KbdPeek					       */
;/*								       */
;/* DESCRIPTIVE NAME:  Keyboard Peek at a character / scan code.       */
;/*								       */
;/* FUNCTION:  Return a keystroke in the input buffer without removing */
;/*	       it.						       */
;/*								       */
;/* NOTES:  Status can only be 0 or 40H.  No interim character support.*/
;/*	    KbdHandle is ignored for Version 1.0.		       */
;/*								       */
;/* ENTRY POINT:						       */
;/*	    LINKAGE:  EXTRN KbdPeek:FAR				       */
;/*								       */
;/* INPUT:	      push@ OTHER structure			       */
;/*		      push  WORD  KbdHandle			       */
;/*		      call  KbdRegister				       */
;/*								       */
;/* EXIT-NORMAL:  AX = 0					       */
;/*								       */
;/* EXIT-ERROR:	 none						       */
;/*								       */
;/* EFFECTS:							       */
;/*								       */
;/* INTERNAL REFERENCES:					       */
;/*    ROUTINES:						       */
;/*								       */
;/* EXTERNAL REFERENCES:					       */
;/*    ROUTINES:						       */
;/*								       */
;/*************** END OF SPECIFICATIONS ********************************/

	.xlist
	include kbdfapi.inc

	EXTRN	__api_begin:near
	EXTRN	__api_end:near
	EXTRN	KbdType:BYTE	; cpd12 (p1082)
	.list

PEEK	STRUC			; stack frame snap shot

		dw	?	; BP
		dw	?	; IP
		dw	?	; CS
		dw	?	; dummy keyboard handle (0)
	Char_D	dd	?	; CharData address

PEEK	ENDS


DSEG	SEGMENT BYTE	PUBLIC	'DATA'

DSEG	ENDS


	PUBLIC	KBDPEEK

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

KBDPEEK		PROC	FAR

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

		lds	bx,[bp].Char_D
		mov	ah,1			; input waiting?
		add	ah,cs:[KbdType]		; cpd12 (p1082)
		int	16h			; BIOS keyboard I/O
		jnz	KbdPeekchar		; code available
		mov	[bx].status,NULL	; no code available
		jmp	short KbdPeekexit
KbdPeekchar:
		mov	[bx].char,al		; return character
		mov	[bx].scan,ah		; return scan code
		mov	ax,BIOS_SEGMENT
		mov	es,ax			; get current shift state
		mov	ax,es:[KBDFLAG]		;   from BIOS
		mov	[bx].Shifts,ax
		mov	ah,2CH			; get time
		int	21H			; pc/dos call
		mov	[bx].hours,ch		; return time
		mov	[bx].minutes,cl
		mov	[bx].seconds,dh
		mov	[bx].tenths,dl
		mov	[bx].Status,CHAR_AVAIL	; return status
		mov	[bx].NLS_Shift,NULL	; NLS shift state
KbdPeekExit:
		xor	ax,ax			; no errors returned

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

		ret	6			; clear stack frame
KBDPEEK		ENDP

_TEXT	ends
	END
