⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbms.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	TITLE	USBMS.ASM -- USB Mouse Device Protocol Handler

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (C)Copyright 1985-2002, American Megatrends, Inc.           **;
;**                                                                       **;
;**                          All Rights Reserved.                         **;
;**                                                                       **;
;**                6145-F Northbelt Pkwy, Norcross, GA 30071              **;
;**                                                                       **;
;**                          Phone (770)-246-8600                         **;
;**                                                                       **;
;***************************************************************************;
;***************************************************************************;
;***************************************************************************;
; $Header: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBMS.ASM 5     3/17/03 5:54p Sivagarn $
;
; $Revision: 5 $
;
; $Date: 3/17/03 5:54p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBMS.ASM $
; 
; 5     3/17/03 5:54p Sivagarn
;   - Byte flag 'bUSBInitFlag' is changed to double word 'dUSBInitFlag'
;   - Bug in supporting 3D-mouse (Mouse with the scroll wheel) is
; corrected
; 
; 4     11/08/02 10:50a Sivagarn
; Code added and/or moved to have USB keyboard input support for the
; systems without keyboard controller
; 
; 3     10/29/02 6:57p Sivagarn
; C-type calling convention routines are changed to assembly type calling
; convention routines (as per USBKBD.ASM change)
; 
; 2     10/14/02 9:03p Sivagarn
;  * Code cleanup
; 
; 1     9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
; 
;***************************************************************************;


;----------------------------------------------------------------------------
; 		Global options are defined here
;----------------------------------------------------------------------------
OPTION	PROC:PRIVATE
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Macro and equate files are included here
;----------------------------------------------------------------------------
	INCLUDE	equates.equ
	INCLUDE	usbflag.equ
	INCLUDE	usb.equ
	INCLUDE	usbkbd.equ
	INCLUDE	mbiosequ.equ
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		External data definitions are defined here
;----------------------------------------------------------------------------
	EXTERN	bUSBDeviceList:BYTE
	EXTERN	SavedHCStrucPtr:WORD
	EXTERN	wUSBKBC_StatusFlag:WORD
	EXTERN	bCCB:BYTE
	EXTERN	dUSBInitFlag:DWORD

;----------------------------------------------------------------------------
;		External function definitions are defined here
;----------------------------------------------------------------------------
USBActivateDevicePolling		PROTO NEAR SYSCALL
USBIssueControlTransferWithoutData	PROTO NEAR SYSCALL
USBKBC_SendKBCData	PROTO NEAR C
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Public function definitions are defined here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Function prototype definitions are here
;----------------------------------------------------------------------------
USBMouse_GetFromMouseBuffer	PROTO NEAR C
USBMouse_SendToMouseBuffer	PROTO NEAR SYSCALL

KBC_WriteCommandByte		PROTO NEAR SYSCALL
KBC_SendMouseData		PROTO NEAR SYSCALL
;----------------------------------------------------------------------------


;----------------------------------------------------------------------------
;	C O D E   S E G M E N T
;----------------------------------------------------------------------------
USB_CSEG 	SEGMENT	WORD USE16 PUBLIC 'CODE'
	ASSUME	cs:USB_CSEG
	ASSUME	ds:USB_DSEG

.586p

	PUBLIC	_USBMS_ASM_START
_USBMS_ASM_START	LABEL		BYTE

	PUBLIC	USBMouseDeviceHeader
USBMouseDeviceHeader		LABEL		USB_DEV_HDR
	DB	BIOS_DEV_TYPE_MOUSE
	DW	OFFSET USBMSInitialize
	DW	OFFSET USBMSCheckForMouse
	DW	OFFSET USBMSConfigureMouse
	DW	0					; Disconnect
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMSInitialize
;
; Description:	This routine is called once to initialize the USB mouse data 
;		area.  
;
; Input: 	Nothing
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMSInitialize		PROC NEAR SYSCALL PUBLIC

	push	ax
; Initialize the mouse input buffer head and tail values
	mov	ax, OFFSET pMouseInputBufferStart
	mov	pMouseInputBufferHeadPtr, ax
	mov	pMouseInputBufferTailPtr, ax
	pop	ax
	ret
USBMSInitialize		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMSCheckForMouse
;
; Description:	This routine checks for mouse type device from the 
;		interface data provided
;
; Input: 	DL+	USB base class code
;		DH	USB sub-class code
;		DL	USB protocol code
;
; Output: 	AX	BIOS_DEV_TYPE_MOUSE type on success or 0FFH on error
;
; Modified:	AX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMSCheckForMouse	PROC NEAR SYSCALL PUBLIC

	push	edx

	mov	ax, 0FFh	; Device type unknown
IFNDEF _BBLK_
	test	dUSBInitFlag, USB_LEGACY_MOUSE_BIT
	jz	UCM_Done
ENDIF

; Check the BaseClass, SubClass and Protocol for a HID/Boot/Mouse device.
	cmp	dh, SUB_CLASS_BOOT_DEVICE
	jne	UCM_Done		;Br if this interface is not a boot device

	cmp	dl, PROTOCOL_MOUSE
	jne	UCM_Done		;Br if this interface is not a mouse

	shr	edx, 8

	cmp	dh, BASE_CLASS_HID
	jne	UCM_Done		;Br if this interface is not a HID device

	mov	ax, BIOS_DEV_TYPE_MOUSE
UCM_Done:
	pop	edx
	ret
USBMSCheckForMouse		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMSConfigureMouse
;
; Description:	This routine checks an interface descriptor of the USB device
;		detected to see if it describes a HID/Boot/Mouse device.
;		If the device matches the above criteria, then the device is 
;		configured and initialized
;
; Input: 	BX	Device information structure pointer
;		DI	Pointer to the descriptor structure
;		CX	End offset of the device descriptor
;
; Output: 	ZR	On error
;		NZ	On success
;			BX - New DeviceInfo structure
;
; Modified:	BX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMSConfigureMouse	PROC NEAR SYSCALL PUBLIC

	push	ax
	push	ebx

	mov	(DeviceInfo PTR [bx]).pPollTDPtr, 0
	mov	(DeviceInfo PTR [bx]).pDevDriverPtr, \
					OFFSET USBMouseDeviceHeader

; Set the BiosDeviceType field in DeviceInfo[0].  This serves as a flag
; that indicates a usable interface has been found in the current configuration.
; This is needed so we can check for other usable interfaces in the current
; configuration (i.e. composite device), but not try to search in other
; configurations.

	mov     (DeviceInfo ptr [bx]).bDeviceType, BIOS_DEV_TYPE_MOUSE
	mov     (DeviceInfo ptr [bx]).pDeviceCallback, \
					OFFSET cs:USBMSProcessMouseData

; Set mouse flag
	or	bUSBDeviceList, USB_TYPE_MOUSE

; Send the set protocol command
; wValue = 0 (Boot protocol)
	movzx	ebx, bx			; Clear EBX+
	mov	eax, (HID_RQ_SET_PROTOCOL SHL 16)
	call	USBIssueControlTransferWithoutData
	jz	UCM_Done

; Start polling the new device's interrupt endpoint.
; BX - DeviceInfo structure
	call	USBActivateDevicePolling

	or	(DeviceInfo PTR [bx]).bFlag, (DEV_INFO_VALID_STRUC OR DEV_INFO_DEV_PRESENT)

; Return success
	or	sp, sp		; Clear zero flag
UCM_Done:

	pop	ebx
	pop	ax
	ret
USBMSConfigureMouse		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMSUpdateMouseInterface
;
; Description:	This routine is called to enable or disable the mouse
;		interface 
;
; Input: 	Nothing
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMSUpdateMouseInterface	PROC NEAR C PUBLIC USES AX
	mov	al, 0A8h		; Enable mouse interface
	test	bMouseStatusFlag, MOUSE_DATA_READY_BIT_MASK
	jnz	UMUMI_SendCommand

	push	ax
	mov	ax, pMouseInputBufferHeadPtr
	cmp	ax, pMouseInputBufferTailPtr
	pop	ax
	jz	UMUMI_SendCommand

	mov	al, 0A7h			; Disable mouse interface
UMUMI_SendCommand:
	call	KBC_WriteCommandByte		; Send command to KBC

	ret
USBMSUpdateMouseInterface	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMSSendMouseData
;
; Description:	This routine is called to send the mouse data to the KB
;		controller
;
; Input: 	Nothing
;
; Output: 	AL	0FFh data processed
;			0 data not processed
;
; Modified:	AL
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMSSendMouseData	PROC NEAR C PUBLIC

	test	bMouseStatusFlag, MOUSE_DATA_READY_BIT_MASK
	jz	UKSKD_MouseDataNotReady	; USB mouse data buffer is empty

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -