;	[]===========================================================[]
;
;	NOTICE: THIS PROGRAM BELONGS TO AWARD SOFTWARE INTERNATIONAL(R)
;	        INC. IT IS CONSIDERED A TRADE SECRET AND IS NOT TO BE 	
;	        DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED	
;	        WRITTEN AUTHORIZATION FROM THE OWNER.
;
; 	[]===========================================================[]
;

;----------------------------------------------------------------------------
;Rev	Date	 Name	Description
;----------------------------------------------------------------------------
;R05	07/20/98 RAX	Added H8 support.
;R04	02/02/98 KGN	Added Defin KeyMatrix_in_XGROUP for matrix table move
;			to XGROUP
;R03	11/14/97 DNL	Rename all keyboard controller file as superkbc.kbc
;R02	11/04/97 JKY	Added new keyboard controller support (M38867)
;R01	04/09/97 DNL	Fixed coding mistake
;R00	12/13/96 DNL	Initial revision


.MODEL  SMALL,BASIC     

.386p
		PAGE	56,132
		TITLE	SUPERKBC.ASM
.XLIST
		INCLUDE	BIOS.CFG
		INCLUDE	COMMON.MAC
		INCLUDE POST.EQU
		INCLUDE	POST.MAC

ifdef	NEW_SUPERKBC_KERNEL
;-----------------------------------------------------------
; Mitsubishi M38802,M38813
;-----------------------------------------------------------
M388XX_KBC	=	0
M38813_KBC	=	0		;R02
M38867_KBC	=	0		;R02
ifdef	KBC_M388XX
M388XX_KBC		=	1
M38813_KBC		=	1	;R02
endif	;KBC_M388XX
ifdef	KBC_M38813			;R02
M388XX_KBC		=	1	;R02
M38813_KBC		=	1	;R02
endif	;KBC_M38813			;R02
ifdef	KBC_M38867			;R02
M388XX_KBC		=	1	;R02
M38867_KBC		=	1	;R02
endif	;KBC_M38867			;R02

;R05 start
H8_KBC		=	0
ifdef	KBC_H8
H8_KBC		=	1
endif	;KBC_H8
;R05 end

	COMPILE_FOR_SUPERKBC_ASM	= 1

;R01	if	KBC_M388XX	NE	0
;R03	if	M388XX_KBC	NE	0	;R01
;R03		include	M388XX.KBC
;R03	endif	;KBC_M388XX
;R03 - start
		include	SUPERKBC.KBC
;R03 - end

endif	;NEW_SUPERKBC_KERNEL

G_RAM		SEGMENT	USE16 AT 0

		ORG	04H*4
		INCLUDE	SEG_0.INC

		ORG	400H
		INCLUDE	G_RAM.INC

G_RAM		ENDS

ifdef	Notebook_Power_Management
SM_RAM		SEGMENT	USE16 AT 0
		INCLUDE	SM_RAM.INC
SM_RAM		ENDS

ZV_Temp_Stack	SEGMENT	USE16 AT 0
		org	1000h
VIDEO_BUFFER	LABEL	WORD
		org	0FFF0h
ZV_STACK_TOP	LABEL	DWORD
ZV_Temp_Stack	ENDS
endif	;Notebook_Power_Management

PM_RAM		SEGMENT	USE16 AT 0 	; define PM RAM segment

		ORG	0
		INCLUDE	PM_RAM.INC

PM_RAM		ENDS

.LIST

DGROUP		GROUP	FCODE
FCODE		SEGMENT	PUBLIC 'CODE'
		ASSUME	CS:DGROUP
FCODE		ENDS

EGROUP		GROUP	ECODE
ECODE		SEGMENT	PUBLIC 'ECODE'
		ASSUME	CS:EGROUP,DS:G_RAM,ES:EGROUP

ifdef	NEW_SUPERKBC_KERNEL

		ALIGN	4
		Public	Wait_IBF_Clear
Wait_IBF_Clear	proc	near

; Read IBF while waiting for RTC update to start, exit if IBF=0
; Then read IBF while waiting for RTC update to end, exit if IBF=0
; Then read IBF while waiting for RTC update to start, exit if IBF=0
; Else exit with carry set

		push	ax			; save this
		clc				; preset no error
@@:
		in	al,64h			; read status
		test	al,2			; test IBF bit
		jz	short WICGood		; if IBF=0 exit

		mov	al,0Ah			; read RTC update bit
		out	70h,al			;
		in	al,71h			;
		test	al,80h			; test bit 7
		jz	short @b		; keep testing until update starts

@@:
		in	al,64h			; read status
		test	al,2			; test IBF bit
		jz	short WICGood		; if IBF=0 exit

		mov	al,0Ah			; read RTC update bit
		out	70h,al			;
		in	al,71h			;
		test	al,80h			; test bit 7
		jnz	short @b		; keep testing until update ends
@@:
		in	al,64h			; read status
		test	al,2			; test IBF bit
		jz	short WICGood		; if IBF=0 exit

		mov	al,0Ah			; read RTC update bit
		out	70h,al			;
		in	al,71h			;
		test	al,80h			; test bit 7
		jz	short @b		; keep testing until update starts

		stc				; carry set indicates timeout
WICGood:
		pop	ax			;
		ret
Wait_IBF_Clear	endp

		Public	Wait_OBF_Full
Wait_OBF_Full	proc	near

; Read OBF while waiting for RTC update to start, exit if OBF=1
; Then read OBF while waiting for RTC update to end, exit if OBF=1
; Then read OBF while waiting for RTC update to start, exit if OBF=1
; Else exit with carry set

		push	ax			; save this
		clc				; preset no error
@@:
		in	al,64h			; read status
		test	al,1			; test IBF bit
		jnz	short WOFGood		; if OBF=1 exit

		mov	al,0Ah			; read RTC update bit
		out	70h,al			;
		in	al,71h			;
		test	al,80h			; test bit 7
		jz	short @b		; keep testing until update starts
@@:
		in	al,64h			; read status
		test	al,1			; test OBF bit
		jnz	short WOFGood		; if OBF=1 exit

		mov	al,0Ah			; read RTC update bit
		out	70h,al			;
		in	al,71h			;
		test	al,80h			; test bit 7
		jnz	short @b		; keep testing until update ends
@@:		
		in	al,64h			; read status
		test	al,1			; test OBF bit
		jnz	short WOFGood		; if OBF=1 exit

		mov	al,0Ah			; read RTC update bit
		out	70h,al			;
		in	al,71h			;
		test	al,80h			; test bit 7
		jz	short @b		; keep testing until update starts

		stc				; carry set indicates timeout
WOFGood:
		pop	ax			;
		ret
Wait_OBF_Full	endp


	COMPILE_FOR_SUPERKBC_ASM	= 2

;R01	if	KBC_M388XX	NE	0
;R03	if	M388XX_KBC	NE	0	;R01
;R03		include	M388XX.KBC
;R03	endif	;KBC_M388XX
;R03 - start
		include	SUPERKBC.KBC
;R03 - end
		
endif	;NEW_SUPERKBC_KERNEL

ECODE		ENDS
;R04 Start
ifdef	KeyMatrix_in_XGROUP
XGROUP		GROUP	XCODE
XCODE		SEGMENT	USE16 PARA PUBLIC 'XCODE'
		ASSUME	CS:XGROUP,DS:G_RAM,ES:XGROUP

	COMPILE_FOR_SUPERKBC_ASM	= 3
		include	SUPERKBC.KBC

XCODE		ENDS
endif	;KeyMatrix_in_XGROUP
;R04 End
		END
