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

📄 usbms.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; bCCB - Command control block value
	test	bCCB, 020h
	jz	UKDSK_MouseEnabled

	mov	pMouseInputBufferHeadPtr, OFFSET pMouseInputBufferStart
	mov	pMouseInputBufferTailPtr, OFFSET pMouseInputBufferStart

; No data send dummy command
UKSKD_KBDisabled:
	xor	al, al
	jmp	SHORT UKSKD_Exit

UKDSK_MouseEnabled:

	push	ds
	push	0
	pop	ds
	mov	ds, ds:[40eh]
	mov	al, ds:[26h]
	and	al, 7
	pop	ds
	jnz	UKSKD_KBDisabled	; PS/2 mouse data packet not over

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

UKSKD_MouseDataNotReady:

	INVOKE	USBMouse_GetFromMouseBuffer

; Send the data to mouse
	call	KBC_SendMouseData		; AL - Data

; Flag indicates data from USB mouse
	or	bMouseStatusFlag, MOUSE_DATA_FROM_USB_BIT_MASK
; Indicate that first byte already sent
	and	bMouseStatusFlag, NOT MOUSE_DATA_READY_BIT_MASK

	push	ax
	mov	ax,pMouseInputBufferHeadPtr
	cmp	ax,pMouseInputBufferTailPtr
	pop	ax
	jnz	UKSKD_Exit

	INVOKE	USBMSUpdateMouseInterface	; Enable/disable mouse I/F

	mov	al, 0FFh
UKSKD_Exit:
	ret
USBMSSendMouseData	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure:	USBMSProcessMouseData
;
; Description:	This function is called at regular intervals with USB mouse 
;		report data. This function handles the translation of USB 
;		mouse data into PS/2 mouse data, and makes the PS/2 data 
;		available to software using ports 60/64 to communicate with 
;		a PS/2 mouse.
;
; Input: 	SI	Pointer to HCStruc
;		BX	Pointer to device information structure
;		DI	Pointer to the data buffer
;
; Output: 	Nothing
;
; Modified:	Nothing
;
; Notes:	The format of 3 byte data packet is as follow:
;		     Byte              Description
;		-----------------------------------------------------------
;			0	Bit		Description
;				-------------------------------------------
;				 0		If set, button 1 is pressed
;				 1		If set, button 2 is pressed
;				 2		If set, button 3 is pressed
;				 3-7		Reserved
;				-------------------------------------------
;			1	X displacement value
;			2	Y displacement value
;		-----------------------------------------------------------
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMSProcessMouseData		PROC NEAR SYSCALL PUBLIC USES AX BX CX SI DI

; Check whether mouse is present
	push	ds
	push	40h
	pop	ds
	test	BYTE PTR ds:[10h], 04h
	pop	ds
	jz	UHPMD_Exit

; Save the device info pointer for later use
	mov	SavedHCStrucPtr, si

; Check whether port 60/64h trapping is active 
	test	wUSBKBC_StatusFlag, KBC_PORT6064_TRAP_BIT_MASK
	jz	UHPMD_TrappingDisabled

; Check whether mouse support is enabled or disabled
	test	bMouseStatusFlag, MOUSE_ENABLED_BIT_MASK
	jz	UHPMD_Exit		; Mouse is disabled

UHPMD_TrappingDisabled:

; Mouse is enabled and trapping is disabled. Process mouse data

; Check mouse data availability
	mov	ax, pMouseInputBufferHeadPtr
	cmp	ax, pMouseInputBufferTailPtr
	jne	UHPMD_SendData			; Buffer has data

; At this point, mouse input buffer is empty and KBC password is disabled.
; Process the mouse data received and put it in the mouse buffer

; Get mouse status byte and prepare it.
; Bit 2, 1, 0 = Middle, right and left button status
; Bit 3 is always 1
	mov	al, BYTE PTR [di]
	and	al, 007h
	or	al, 008h

; Get mouse X, Y position
	mov	cx, WORD PTR [di+1]
	neg	ch			; Y data is opposite in USB than PS2

; Enable the following piece of code to scale X & Y position
	shl	cl, 1			; X * 2
	shl	ch, 1			; Y * 2

; Verify the direction of X-axis movement
	or	cl, cl
	jns	UHPMD_PositiveX
	or	al, 10h			; Negative X-axis movement
UHPMD_PositiveX:

; Verify the direction of Y-axis movement
	or	ch, ch
	jns	UHPMD_PositiveY
	or	al, 20h			; Negative Y-axis movement
UHPMD_PositiveY:

; Send status byte
	call	USBMouse_SendToMouseBuffer	; Data in AL
; Send X-axis information
	mov	al, cl
	call	USBMouse_SendToMouseBuffer	; Data in AL
; Send Y-axis information
	mov	al, ch
	call	USBMouse_SendToMouseBuffer	; Data in AL

; Check for 4-byte mouse data
	test	bMouseStatusFlag, MOUSE_4BYTE_DATA_BIT_MASK
	jz	UHPMD_DataDone

; Send the 4th dummy data
	xor	al, al
	call	USBMouse_SendToMouseBuffer	; Data in AL

UHPMD_DataDone:

; Set flag to indicate mouse data ready
	or	bMouseStatusFlag, MOUSE_DATA_READY_BIT_MASK

UHPMD_SendData:
	INVOKE	USBKBC_SendKBCData

UHPMD_Exit:
	ret
USBMSProcessMouseData		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMouse_SendToMouseBuffer
;
; Description:	This routine puts a byte into the mouse input buffer. 
;		Mouse input buffer pointers are also updated
;
; Input: 	AL	Byte to be put in the mouse input buffer
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMouse_SendToMouseBuffer	PROC NEAR SYSCALL PUBLIC

	push	ax
	push	bx

	mov	bx, pMouseInputBufferHeadPtr
	mov	BYTE PTR [bx], al	; Put the byte in the buffer
	inc	bx			; Advance the buffer pointer
; Check whether the buffer end is reached
	cmp	bx, OFFSET pMouseInputBufferEnd
	jnz	UMSTMB_BufferPtrOkay

; Buffer end reached position the buffer pointer to the start
	mov	bx, OFFSET pMouseInputBufferStart

UMSTMB_BufferPtrOkay:

; Adjust the input buffer head
	mov	pMouseInputBufferHeadPtr, bx

	pop	bx
	pop	ax
	ret
USBMouse_SendToMouseBuffer	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMouse_GetFromMouseBuffer
;
; Description:	This routine retrieves a byte from the mouse input buffer.
;		Mouse input buffer pointers are also updated
;
; Input: 	Nothing
;
; Output: 	AL	Byte taken from the mouse input buffer
;
; Modified:	AL
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMouse_GetFromMouseBuffer	PROC NEAR C PUBLIC USES BX

	mov	bx, pMouseInputBufferTailPtr
	xor	al, al
	xchg	al, BYTE PTR [bx]	; Get mouse data from the buffer
	inc	bx			; Advance the buffer pointer

; Check for buffer end condition
	cmp	bx, OFFSET pMouseInputBufferEnd
	jnz	UMGFMB_BufferOkay
; End reached. Wrap around to the start ..
	mov	bx, OFFSET pMouseInputBufferStart

UMGFMB_BufferOkay:
; Update the pointer
	mov	pMouseInputBufferTailPtr, bx

	ret
USBMouse_GetFromMouseBuffer	ENDP

	PUBLIC	_USBMS_ASM_END
_USBMS_ASM_END	LABEL		BYTE

;----------------------------------------------------------------------------
	ASSUME	ds:NOTHING
	ASSUME	cs:NOTHING

USB_CSEG	ENDS

;----------------------------------------------------------------------------
;	D A T A   S E G M E N T
;----------------------------------------------------------------------------
USB_DSEG 		SEGMENT WORD PUBLIC 'DATA'
;----------------------------------------------------------------------------
		PUBLIC	USBMSDataStart
USBMSDataStart	LABEL		BYTE
;----------------------------------------------------------------------------
; Mouse input buffer start and end addresses
	PUBLIC	pMouseInputBufferStart
pMouseInputBufferStart		DB	15 DUP (?)
pMouseInputBufferEnd		LABEL		WORD

; Mouse input buffer head and tail pointers
	PUBLIC	pMouseInputBufferHeadPtr
pMouseInputBufferHeadPtr	DW	?
	PUBLIC	pMouseInputBufferTailPtr
pMouseInputBufferTailPtr	DW	?
;----------------------------------------------------------------------------
		PUBLIC	bMouseStatusFlag
bMouseStatusFlag	DB	?	; USB mouse status flag
					; Bit 7   : Mouse enabled bit (1/0)
					; Bit 6   : Mouse data ready (1/0)
					; BIT 5   : Mouse data from USB (1/0)
					; BIT 4   : 4-byte mouse data (1/0)
					; Bit 3-0 : Reserved

;----------------------------------------------------------------------------
		PUBLIC	USBMSDataEnd
USBMSDataEnd		LABEL		BYTE
USB_DSEG		ENDS

	END
;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (C)Copyright 1985-2002, American Megatrends, Inc.           **;
;**                                                                       **;
;**                          All Rights Reserved.                         **;
;**                                                                       **;
;**                6145-F Northbelt Pkwy, Norcross, GA 30071              **;
;**                                                                       **;
;**                          Phone (770)-246-8600                         **;
;**                                                                       **;
;***************************************************************************;
;***************************************************************************;

⌨️ 快捷键说明

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