;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R28	04/13/99 KEN	Add OHCI USB mouse support.
;R27	12/11/98 KEN	Fixed bug that the mouse cursor is displayed abnormal
;			while using Microsoft IntelliMouse (socalled scroll
;			function or wheel control mouse) in Win98 safe mode,
;			when usb mouse support is enabled and no usb mouse
;			is installed.
;R26	05/21/98 DRS	This function depends on Show_PS2_UnConnect_Message
;			Report PS/2 mouse don't connect message	error message 
;			is "PS/2 Mouse error or no PS/2 mouse present"	
;R25A	01/05/98 KVN	Fixed coding mistake that will cause compiler error in
;			2MB BIOS
;R25	01/03/98 STV	Fixed Mylex DAC960 RAID controller card cannot work
;			successfully while the PS/2 mouse is not plugging,
;			the card will set to disable automatically while 
;			without PS/2 mouse.PS/2 mouse plugging flag isn't
;			config_table+5 ,so change to SYSTEM1_BYTE(bit 2).
;			Config_Table+5 is EBDA flag. See atorgs.asm
;R23A	10/21/97 KVN	Fixed system hang during setup Windows 95 if connect
;			PS2 mouse and plug on TEKRAM DC-390 PCI-SCSI card.
;R24A	10/08/97 KVN	Fixed R24 coding to function normaly
;R24	10/02/97 KVN	Remove MOUSE.ASM to XGROUP from EGROUP to reduce
;			compressed size for 2M BIOS code overflow (i.e. system
;			BIOS compressed code cover to decompress code)
;R23	06/27/97 LAW	added clear PS2 Mouse Buffers, becouase use 2M rom
;			do not clear 80000h - 90000h for adapator rom use
;R22	10/04/95 RCH	IRQ 12 can not turn on too early to fix Buslogic
;			SCSI hang up problem.
;R21	08/25/95 RCH	This file is moved into area E0000-E7FFFH , and the
;			MODBIN should be modified, otherwise referenced 
;			segment is wrong
;R20	08/22/95 DNL	Support BIOS new structure
;R19A	08/21/95 RCH	R19 will cause MS mouse v9.1 drive hang without PS2
;			mouse plugged
;R19	08/04/95 RAY	Fixed for the Keyboard halt when the mouse device
;			is plug after boot without reserving any system RAM.
;R18	07/14/95 RCH	Clear PS2 mouse flag in CONFIG_TABLE if "PS2_Setupable"
;			is available
;R17	06/13/95 KVN	Reduce Post_func_call and F000_call code size
;R15A	04/17/95 RCH	Move "PS2_Setupable" option into POST.ASM
;R16	04/11/95 RCH	Fixed OS2 intstallation failure if PS2 mouse not plug
;R15	03/27/95 DNL	Added "PS2_Setupable" option to turn on/off PS2 mouse
;R11A	02/17/95 RCH	It's no meaning to support hot line pluggin mouse
;R12	08/17/94 RCH	Don't turn on level trigger IRQ 12 for PCI/EISA PS2
;			mouse support
;R11	08/12/94 BEN	Fixed for the Keyboard halt when the mouse device
;			is plug after boot.
;			The IRQ12 must be initial even there is no mouse device.
;R10	08/09/94 BEN	Added 'Clear_8042_OBF_After_Ms_Install' for KB-200
;			in ASI All-In-One.
;R09	02/17/94 RCH	No message require for 4.50G
;R07A	11/17/93 RCH	Fixed in Windows bugs when PM is supported.
;R08	09/10/93 RCH	New KB200 can not find QTRONIX x-30p mouse if system
;			 is cold boot.
;R07	09/01/93 RAY	Add PM hooks as standard features
;R06	08/26/93 RCH	Mouse did not found if keylock is enabled
;R05	10/15/92 RCH	Mouse failure if move mouse dramatically while
;			entering WINDOWS v3.1 in 386 enhance mode
;R04	05/26/92 RCH	Make MOUSE modinable
;R03	05/26/92 RCH	Fixed DOSSHELL hang bug
;R02	04/24/92 RCH	Don't destory BX in routine OUT_AUX
;R01	05/29/91 DC	NF: Added SEMAPHORE to support power management. This
;			semaphore is implemented in an incremental model to
;			support	nested interrupt (e.g. mouse moved while floppy
;			is accessing)
;R00	05/17/91	JJ	Initial revision for 4.2 - from old ver. 1.6
;

		PAGE	60,132
		TITLE	AMOUSE.ASM - PS/2 mouse BIOS driver
.386P

.XLIST

		INCLUDE BIOS.CFG
		INCLUDE BTROMSEG.EQU			;R24A
		INCLUDE	COMMON.EQU
		INCLUDE COMMON.MAC
		INCLUDE POST.MAC

		INCLUDE	ATORGS.EXT			;R04
;R04 IFDEF MOUSE
		INCLUDE	AKBRD.EXT
		INCLUDE	POST.EXT
		INCLUDE MULTISER.EXT

		INCLUDE	MOUSE.EQU
		INCLUDE EXTDATA.EQU

		INCLUDE	8042.EQU
		INCLUDE	8259.EQU

	ifdef   Show_PS2_UnConnect_Message	;R26
                INCLUDE POST.EQU		;R26
	endif	;Show_PS2_UnConnect_Message  	;R26

;R27 - start
ifdef	USB_SUPPORT
ifdef	USB_MOUSE_SUPPORT
		extrn	Determine_Mouse_Trap:near
		extrn	Report_USB_Mouse_Support:near
endif	;USB_MOUSE_SUPPORT
endif	;USB_SUPPORT
;R27 - end

ifdef MOUSE_IN_XGROUP					;R25A
		extrn	F000_Shadow_R:near		;R25A
		extrn	F000_Shadow_W:near		;R25A
else ;MOUSE_IN_XGROUP					;R25A
		extrn	E_F000_Shadow_R:near		;R25
		extrn	E_F000_Shadow_W:near		;R25
endif ;MOUSE_IN_XGROUP					;R25A

		extrn	Irq12:far
		extrn	Out_8042_full1:near
;R15A ;R15 - start
;R15A ifdef	PS2_SETUPABLE
;R15A 		extrn	PS2_select_item:near
;R15A 		extrn	Getitem_value:near
;R15A endif	;PS2_SETUPABLE
;R15A ;R15 - end

		extrn	Do_F000_Shadow:Near			;R16
;R25            extrn	Disable_PS2_Mouse_Flag:near		;R16

		extrn	Dummy_IRQ12_Handler:near		;R19
ifndef MOUSE_IN_XGROUP						;R24
		extrn	F000_Buffer_8042_Full:near		;R20
		extrn	F000_Out_8042_Full:near			;R20
		extrn	F000_Out_8042:near			;R20
endif ;MOUSE_IN_XGROUP						;R24

;R07 IFDEF	POWER_MANAGEMENT
;R07 		INCLUDE PM_GEN.EXT
;R07 ENDIF	;POWER_MANAGEMENT

;R04 ENDIF ;MOUSE
.LIST

G_RAM		SEGMENT	USE16 AT 0H

		ORG	04H*4
		INCLUDE	SEG_0.INC

		ORG	400H
		INCLUDE	G_RAM.INC

G_RAM		ENDS

DGROUP		GROUP	FCODE
FCODE           SEGMENT USE16 PARA PUBLIC 'CODE'
                ASSUME  CS:DGROUP
FCODE           ENDS

;R17		extrn	F000_func_end:Near	;128k
;R17		extrn	F000_VECT:Near		;128k
		extrn	F000_VECT:Near		;R20
		extrn	RET_E_SEG:near		;R20
		extrn	F000_call_proc:near	;R17
;R24 start
ifdef MOUSE_IN_XGROUP
		extrn	Post_call_proc:near
XGROUP		GROUP	XCODE
XCODE		SEGMENT	USE16 PARA PUBLIC 'XCODE'
		ASSUME	CS:XGROUP
else ;MOUSE_IN_XGROUP
;R24 end
EGROUP		GROUP	ECODE
ECODE		SEGMENT	USE16 PARA PUBLIC 'ECODE'
		ASSUME	CS:EGROUP
endif ;MOUSE_IN_XGROUP				;R24

;R09 AUX_MSG:		db	'Installing Mouse',0
;R09 NOT_PRESENT_MSG:	db	'No Mouse Present',0

;*****************************************************************************
; Procedure Name:	ms_instal
;	Test PS/2 pointing device installed and initialize
; Saves:
; Inputs:	none
; Output:	none
; Destroy:	none
; Author:	Ken Chen
; Date: 	06/21/90
;
; Rev	| Name	| Date		| TPR#	| Description
; ------+-------+---------------+-------+-------------------------------------
; R06	| TIM   | 02-Oct-90  	| Added SILENT_POST option to only print
;				  messages when there is an error
; 1.00	| Ken	| 06/21/90	| NEW	| Initial revision
;
;*****************************************************************************

		PUBLIC	MS_INSTAL
MS_INSTAL	PROC	NEAR

;R27 - start
ifdef	USB_SUPPORT
ifdef	USB_MOUSE_SUPPORT
ifdef	MOUSE_IN_XGROUP
ifdef	SMIHANDLE_IN_XGROUP				;R28
		call	Determine_Mouse_Trap		;R28
else	;SMIHANDLE_IN_XGROUP				;R28
		post_func_call	Determine_Mouse_Trap
endif	;SMIHANDLE_IN_XGROUP				;R28
else	;MOUSE_IN_XGROUP
ifdef	SMIHANDLE_IN_XGROUP				;R28
		Xcall	Determine_Mouse_Trap		;R28
else	;SMIHANDLE_IN_XGROUP				;R28
		call	Determine_Mouse_Trap
endif	;SMIHANDLE_IN_XGROUP				;R28
endif	;MOUSE_IN_XGROUP
endif	;USB_MOUSE_SUPPORT
endif	;USB_SUPPORT
;R27 - end

;R21		mov	ax,DGROUP
		mov	ax,0F000H			;R21
		mov	ds,ax
		assume	ds:DGROUP
		test	DGROUP:SYSTEM4_BYTE,PS2_MOUSE	;ps2 mouse support;R04
;R08		jz	short exit_ms_instal   				  ;R04
		jnz	short @F					;R08
		jmp	Exit_Ms_Instal					;R08
@@:									;R08
;R15A ;R15 - start
;R15A ifdef	PS2_SETUPABLE
;R15A 		mov	si,offset PS2_select_item
;R15A 		F000_call	GetItem_Value
;R15A 		or	al,al				;PS2 mouse enable
;R15A 		jz	Exit_Ms_Instal			;No
;R15A endif	;PS2_SETUPABLE
;R15A ;R15 - end

		mov	ax,G_RAM
		mov	ds,ax
		ASSUME	DS:G_RAM

;R25 start
	;Enable PS2 mouse and EBDA flag to assume PS2 mouse is present
		mov	bl,1				;set flag
		call	Set_PS2_Mouse_Flag
;R25 end

ifndef	NO_QUICK_MOUSE_INSTAL
check_input_buffer:
		cli
		mov	al,0adh
		out	stat8042,AL
;R20		F000_call	Buffer_8042_Full
		call	F000_Buffer_8042_Full		;R20
		in	al,data8042
		NEWIODELAY
;R28 - start
ifdef	IOTRAP_SUPPORT
ifdef	OHCI
	; Write command byte to let the USB SMI kernel set
	; external IRQ12 SMI enabled
		mov	al, 060h
		out	64h, al
		call	F000_Buffer_8042_Full
		mov	al, 55h
		out	60h, al
		call	F000_Buffer_8042_Full
endif	;OHCI
endif	;IOTRAP_SUPPORT
;R28 - end

		mov	bl,4			;retry number		;R08
ReSend_D4:								;R08
		dec	bl						;R08
		jz	short no_aux_installed				;R08

		in	al,DATA8042
		mov	al,0d4h 		; now write it back
		out	stat8042,al
;R20		F000_call	Buffer_8042_Full
		call	F000_Buffer_8042_Full		;R20
		mov	al,0ffh
		out	DATA8042,al
;R20		F000_call	Buffer_8042_Full
		call	F000_Buffer_8042_Full		;R20

;***********************

ifdef   Show_PS2_UnConnect_Message			;R26
		; Turn OFF errors			;R26
		mov	byte ptr MOUSE_ERROR[bp], 0	;R26	
endif	;Show_PS2_UnConnect_Message  			;R26

		call	Out_Mouse_Full
		or	ax,ax
		jz	short Detect_Mouse_Exit
		in	al,DATA8042		;GET 1TH CODE.

		cmp	al,0feh			;resend command?	;R08
		je	short ReSend_D4					;R08

		cmp	al,0fah
		jne	short no_aux_installed
;		jne	short Detect_Mouse_Exit

		call	Out_Mouse_Full
		or	ax,ax			;R06
		jz	short Detect_Mouse_Exit
		in	al,DATA8042		;GET 2TH CODE.

		call	Out_Mouse_Full
		in	al,DATA8042		;GET 3TH CODE.
		jmp	short Mouse_Yes
Detect_Mouse_Exit:
		jmp	short Aux_Error
Mouse_Yes:
else;	NO_QUICK_MOUSE_INSTAL

check_input_buffer:
;R20		F000_call	Buffer_8042_Full
		call	F000_Buffer_8042_Full		;R20
		jnz	short kc_error

; disable keyboard interface

disable_kb:
		mov	al,DISABLE_KBRD		; disable kb interface
;R20		F000_call	Out_8042
		Call	F000_Out_8042		;R20
		jnz	short kc_error		; skip if IBF=1

; reset auxiliary device

reset_aux:
		mov	al,MS_RESET
		F000_call	Out_Aux
		jnz	short kc_error		; skip if IBF=1

; wait for auxiliary device to response

; ** NOTICE **
; if auxiliary device installed and can't be detected, try to add CX value.
; Normally please set CX with minimum value. Because, if auxiliary device
; no installed, it shill consume a long time to detect auxiliary device.

		mov	cx,1			; long loop
wait_aux_response:
		push	cx
		F000_call	Out_Aux_Full		; check aux output buffer full
		pop	cx
		jnz	short get_aux_response	; get aux output buffer full

		loop	short wait_aux_response
		jmp	short no_aux_installed

;
;	Receive auxiliary device response data
;

get_aux_response:
		in	al,DATA8042
;		cmp	al,RSCODE		; resend code FE
;		je	reset_aux

		cmp	al,ERRCODE		; error code FC
		je	short reset_aux

		cmp	al,ACKCODE		; auxiliary acknowledge
		jne	short no_aux_installed

;
; 	Check for self-test success code
;

		F000_call	Out_Aux_Full
		jz	short aux_error

		in	al,DATA8042
		cmp	al,SUCCODE		; AA - self test successfully
		jne	short aux_error
endif;	NO_QUICK_MOUSE_INSTAL

;
;	Mouse passed: Print 'Passed' and push success status
;

Pass_Detect_Mouse:				;R27
		clc
		pushf				; save cc = pass
		jmp	short clear_remainder

; Begin Not Installed change
;
;	Mouse error: Print 'Failed' and push failed status
;
no_aux_installed:

;R27 - start
ifdef	USB_SUPPORT
ifdef	USB_MOUSE_SUPPORT
ifdef	MOUSE_IN_XGROUP
ifdef	SMIHANDLE_IN_XGROUP				;R28
		call	Report_USB_Mouse_Support	;R28
else	;SMIHANDLE_IN_XGROUP				;R28
		post_func_call	Report_USB_Mouse_Support
endif	;SMIHANDLE_IN_XGROUP				;R28
else	;MOUSE_IN_XGROUP
ifdef	SMIHANDLE_IN_XGROUP				;R28
		Xcall	Report_USB_Mouse_Support	;R28
else	;SMIHANDLE_IN_XGROUP				;R28
		call	Report_USB_Mouse_Support
endif	;SMIHANDLE_IN_XGROUP				;R28
endif	;MOUSE_IN_XGROUP
		jnc	short Pass_Detect_Mouse
endif	;USB_MOUSE_SUPPORT
endif	;USB_SUPPORT
;R27 - end

;R26 -start
ifdef   Show_PS2_UnConnect_Message		
		or	byte ptr MOUSE_ERROR[bp], MOUSE_NO_DETECT
		or	byte ptr CMOS_STATUS[bp], EQUIP_STATUS
endif	;Show_PS2_UnConnect_Message  		
;R26 -end

;R11A aux_error:								;R11
;R11A 		mov	al,ENABLE_KBRD	; enable kb interface		;R11
;R11A 		F000_call	out_8042					;R11
;R11A 		call	Set_Ms		; install IRQ, 40: area, etc.	;R11
;R11A 		and	byte ptr g_ram:Hardware,11111011b;assume no mouse;R11
;R11A 		jmp	short exit_ms_instal				;R11
;R11		jmp	short set_error

;R19 - starts
 		mov	al,ENABLE_KBRD	; enable kb interface
;R20		F000_call	Out_8042
		Call	F000_Out_8042		;R20
		xor	bl,bl
 		call	Set_Ms
 		and	byte ptr g_ram:Hardware,11111011b
;R22 - start
;Disable IRQ 12 , but it will enable after option ROMs initialization
		in	al,B8259+1
		or	al,10H 			; mask IRQ 12
		out	B8259+1,al
		NEWIODELAY
;R22 - end

		call	Clear_Ps2Mouse_Flag			;R19A
 		jmp	short exit_ms_instal
;R19 - ends

kc_error:
aux_error:								;R11A

;R27 - start
ifdef	USB_SUPPORT
ifdef	USB_MOUSE_SUPPORT
ifdef	MOUSE_IN_XGROUP
ifdef	SMIHANDLE_IN_XGROUP				;R28
		call	Report_USB_Mouse_Support	;R28
else	;SMIHANDLE_IN_XGROUP				;R28
		post_func_call	Report_USB_Mouse_Support
endif	;SMIHANDLE_IN_XGROUP				;R28
else	;MOUSE_IN_XGROUP
ifdef	SMIHANDLE_IN_XGROUP				;R28
		Xcall	Report_USB_Mouse_Support	;R28
else	;SMIHANDLE_IN_XGROUP				;R28
		call	Report_USB_Mouse_Support
endif	;SMIHANDLE_IN_XGROUP				;R28
endif	;MOUSE_IN_XGROUP
		jnc	short Pass_Detect_Mouse
endif	;USB_MOUSE_SUPPORT
endif	;USB_SUPPORT
;R27 - end

;R11aux_error:
;R11set_error:
;R16 - start
;R18 ;Disable mouse flag in CONFIG_TABLE , otherwise OS2 installation failure
;R18 ;if PS2 mouse not plugged
;R18 		push	ds
;R18 		push	es
;R18 		pusha
;R18                 lea	si,Disable_PS2_Mouse_Flag
;R18 		F000_call	Do_F000_Shadow
;R18 		popa
;R18 		pop	es
;R18 		pop	ds
		call	Clear_Ps2Mouse_Flag			;R18
;R16 - end
		stc
		pushf				; save cs = fail

;
;	Clear output buffer before leaving
;


Clear_Remainder:

;R10 - Begin
ifdef	Clear_8042_OBF_After_Ms_Install
;
; Clear 8042 OBF ..........
;
		mov	bl,10
	@@:
		mov	ah,1
		F000_call	Out_8042_full1
		jz	short @F
		in	al,data8042
		dec	bl
		jnz	short @B
	@@:
endif	;Clear_8042_OBF_After_Ms_Install
;R10 - End

ifdef	NO_QUICK_MOUSE_INSTAL
		mov	cx,10
Clear_Buffer:
		push	cx
		F000_call	out_aux_full
		pop	cx
		jz	short enable_kb
		in	al,data8042		; get remainder
		NEWIODELAY
		loop	short clear_buffer
endif;	NO_QUICK_MOUSE_INSTAL

;
;	Reenable keyboard controller interface
;
enable_kb:
		mov	al,ENABLE_KBRD		; enable kb interface
;R20		F000_call	Out_8042
		Call	F000_Out_8042		;R20

		popf						; c: set=fail, clear=fail
		jc	short exit_ms_instal	    		; fail...

		mov	bl,1				;R19
		call	Set_Ms					; install IRQ, 40: area, etc.

exit_ms_instal:
		ret
MS_INSTAL	ENDP

;R18 - start
;Disable mouse flag in CONFIG_TABLE , otherwise OS2 installation failure
;if PS2 mouse not plugged
		public	Clear_Ps2Mouse_Flag
Clear_Ps2Mouse_Flag	proc	near
		push	ds
		push	es
		pusha
;R25            lea	si,Disable_PS2_Mouse_Flag
;R25		F000_call	Do_F000_Shadow
		xor	bl,bl			;clear flag	;R25
                call	Set_PS2_Mouse_Flag			;R25
		popa
		pop	es
		pop	ds
		ret
Clear_Ps2Mouse_Flag	endp
;R18 - end

;R25 - start
;-------------------------------------------------------------------------
;Set_PS2_Mouse_Flag
;Input	:	Bl = 1 PS2 Mouse Flag & system config (CONFIG_TABLE+5) to set Enable
;		     0 PS2 Mouse Flag & system config (CONFIG_TABLE+5) to set Disable
;
;Output	:	NONE
;-------------------------------------------------------------------------
		public	Set_PS2_Mouse_Flag
Set_PS2_Mouse_Flag:

		pusha
		push	ds

		xor	bh,bh	     		;for clear flag

		or	bl,bl	     		;set flag ?
		jz	short @F     		;no
		mov	bh,04H	     		;set flag
@@:

		push	0F000H
		pop	ds			;DS = F000H

		push	bx
ifdef MOUSE_IN_XGROUP				;R25A
		F000_call	F000_Shadow_W	;R25A
else ;MOUSE_IN_XGROUP				;R25A
		call	E_F000_Shadow_W
endif ;MOUSE_IN_XGROUP				;R25A
		pop	bx

		mov	si,offset SYSTEM1_BYTE	;mouse flag
		and	byte ptr [si],NOT 04H
		or	byte ptr [si],bh	;mark PS2 mouse flag

		mov	si,offset CONFIG_TABLE	;EBDA flag
		and	byte ptr [si+5],NOT 04H
		or	byte ptr [si+5],bh	;mark EBDA flag

ifdef MOUSE_IN_XGROUP				;R25A
		F000_call	F000_Shadow_R	;R25A
else ;MOUSE_IN_XGROUP				;R25A
		call	E_F000_Shadow_R
endif ;MOUSE_IN_XGROUP				;R25A

		pop	ds
		popa
		ret
;R25 - end

;*****************************************************************************
; Procedure Name:	set_ms
;	Check if auxiliary device installed, then
;	Setup INT74 vector, enable aux device interface, enable IRQ12
; Saves:
; Inputs:	none
; Output:	none
; Destroy:	none
; Author:	Ken Chen
; Date: 	06/21/90
;
; Rev	| Name	| Date		| TPR#	| Description
; ------+-------+---------------+-------+-------------------------------------
; 1.00	| Ken	| 06/21/90	| NEW	| Initial revision
;
;*****************************************************************************

		PUBLIC	SET_MS
SET_MS		PROC	NEAR

		mov	ax,G_RAM
		mov	ds,ax
		assume	ds:G_RAM

		and	byte ptr g_ram:Hardware,11111011b	;assume no mouse

		cli
		mov	al,READ_CMD		; get kc command byte
;R20		F000_call	Out_8042
		Call	F000_Out_8042		;R20
;R20		F000_call	out_8042_full
		call	F000_out_8042_full	;R20
;R20		jz	short exit_set_ms_1
		jz	exit_set_ms_1		;R20
		in	al,DATA8042

		or	al,00000010b		; enable aux output buffer
						; full interrupt
		and	al,11011111b		; enable aux interface

		push	ax
		mov	al,WRITE_CMD		; set command byte
;R20		F000_call	Out_8042
		Call	F000_Out_8042		;R20
		pop	ax
		jnz	short exit_set_ms_1

		out	DATA8042,al

; check extended BIOS data area, maybe other driver already set address

		or	byte ptr g_ram:Hardware,00000100b	; PS/2 spec.

		or	word ptr g_ram:Ext_Segment,0
		jnz	short set_vect

; set extended BIOS data area segment address

		test	bl,1				;R19
		jz	short set_vect			;R19

		call	Reserve_Ebda_1Kb		;R19


;R19		mov	ax,g_ram:Size_Sysram
;R19		dec	ax				; reduce 1K memory
;R19		mov	word ptr g_ram:Size_Sysram,ax
;R19		shl	ax,6				; translate to segment
;R19		mov	word ptr g_ram:Ext_Segment,ax
;R19
;R19		mov	es,ax
;R19;R23A start
;R19;
;R19;	Clear PS2 Mouse Buffers
;R19;
;R19		xor	di,di		;offset = 0
;R19		xor	ax,ax		;data = 0
;R19		mov	cx,200h		;size = 1K / 2 (for word)
;R19		cld
;R19		rep	stosw		;clear buffer
;R19;R23A end
;R19		mov	byte ptr es:EXTSIZE,01
;R19
;R23A;R23 - start
;R23A;
;R23A;	Clear PS2 Mouse Buffers (9fc0h 1K byte)
;R23A;
;R23A		pushad
;R23A		push	es
;R23A		mov	ax,9fc0h
;R23A		mov	es,ax
;R23A		xor	di,di
;R23A		cld
;R23A		xor	ax,ax
;R23A		mov	cx,200h
;R23A		rep	stosw
;R23A		pop	es
;R23A		popad
;R23A;R23 - end

; setup new 74 interrupt vector

set_vect:
;R21		mov	ax,DGROUP
		mov	ax,0F000H			;R21
;R19		mov	word ptr g_ram:int74,offset irq12
;R19 - starts
		test	bl,1
		mov	bx,offset irq12
		jnz	short _htnbr
		mov	bx,offset Dummy_IRQ12_Handler
	_htnbr:
		mov	word ptr g_ram:int74,bx
;R19 - ends
		mov	word ptr g_ram:int74+2,ax

IF BUS_TYPE EQ EISA_BUS
; set port 4D1 bit 5 to 1, means IRQ12 occur with level trigger
ifndef	PCI_BUS						;R12

		mov	dx,4d1h
		in	al,dx
		NEWIODELAY
		or	al,10h
		out	dx,al
		NEWIODELAY
endif;	PCI_BUS						;R12
ENDIF ;BUS_TYPE

; enable slave 8259 chanel 4 (IRQ 12)

		in	al,B8259+1
		and	al,0efh 		; mask bit 4
		NEWIODELAY
		out	B8259+1,al
		NEWIODELAY
exit_set_ms_1:
		sti
exit_set_ms:
		ret
SET_MS		ENDP

;R19 - start
;Function : Reserve 1Kb EBDA and also clear the content of this area.
;Input    : DS = G_RAM
;Output   : none
	public	Reserve_Ebda_1Kb
Reserve_Ebda_1Kb	proc	near
                ASSUME  DS:G_RAM
		mov	ax,g_ram:Size_Sysram
		dec	ax				; reduce 1K memory
		mov	word ptr g_ram:Size_Sysram,ax
		shl	ax,6				; translate to segment
		mov	word ptr g_ram:Ext_Segment,ax

		mov	es,ax

;
;	Clear EBDA Buffers
;
		xor	di,di		;offset = 0
		xor	ax,ax		;data = 0
		mov	cx,200h		;size = 1K / 2 (for word)
		cld
		rep	stosw		;clear buffer

		mov	byte ptr es:EXTSIZE,01
		ret
Reserve_Ebda_1Kb	endp
;R19 - end

ifndef	NO_QUICK_MOUSE_INSTAL
OUT_MOUSE_FULL	 PROC	 NEAR
; Check for 8042 output buffer full
; AX	=	0 if OutputBufferFull bit never goes on (timeout)
; AX	=	nonzero if OBF bit goes on

		mov	ah,3		;FIXED HI SPEED SYSTEM THAT DETECT;R40
Otrck1: 	xor	cx,cx		;MOUSE NOT FOUND PROBLEM.

Inrck1: 	in	al,STAT8042
		test	al,01H
		jnz	short Onret1
		jmp	short Counter_1
Onret1:
		test	al,20h
		jnz	short Onret2
		in	al,DATA8042	;GET KEY BOARD VALUE
Counter_1:
		NEWIODELAY		;R40
		loop	short Inrck1

		dec	ah
		jnz	short Otrck1
Onret2:
		ret

OUT_MOUSE_FULL	 ENDP
endif;	NO_QUICK_MOUSE_INSTAL

;R24 start
ifdef MOUSE_IN_XGROUP
F000_Buffer_8042_Full:
	F000_call	Buffer_8042_Full
	ret

F000_Out_8042_Full:
	F000_call	Out_8042_Full
	ret

F000_Out_8042:
	F000_call	Out_8042
	ret

XCODE		ENDS
else ;MOUSE_IN_XGROUP
;R24 end

ECODE		ENDS
endif ;MOUSE_IN_XGROUP				;R24

		END
