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

📄 kbm_cmd.asm

📁 CY7C63743 usb键盘的源码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;========================================================================
; 02/08/99    bth  added 3d mouse support
;
;
; 010/15/98   bth
;
; made several changes to fix bugs.
;
;
; changed ps2_init to force the initial state of mouse_machine to mouse_ST_idleC.
; ps2_init used to set this variable to mouse_ST_ResetC, which was an attempt
; to set up the state machine to receive the "AA 00" initialization string
; of the mouse when it was plugged in -- but this did not work.  Now, we
; make no attempt to catch the initialization string, so we can set mouse_machine's
; initial state to idle.
;
; changed mouse_status to return the state of mouse_machine.  mouse_status is
; now used in the mouse's portion of the 1msec ISR to determine if mouse_machine
; is stuck in a state other than idle for a period longer than the timeout interval.
; 

;========================================================================
; 01/14/98	 v0.1		hth
;========================================================================

;##### START Module kb_cmd #####
;## Rev 0.10


;**********
; ps2_init
;  Called from Keyboard Main code to initialize the PS/2 mouse port.
;  ps2_init must be called within 500mS of power-on.
;	Parameters:		None.
;	Returns:		None.
;	Side effects:	Register A destroyed. 
;**********

ps2_init:
	push	a

	call	ps2_bus_idle		;init ps/2 bus
	mov	a,mouse_ST_IdleC		;init mouse state for power-on
	mov	[mouse_stateV],a
	mov	a,ps2_timeoutC		;init timeout counter
	mov	[mouse_mScntV],a
	mov	a,mouse_reset_timoutC
	mov	[mouse_work0V],a		;init reset timer

	pop	a
	ret


;**********
; mouse_reset
;	Initiate a mouse reset command
;**********

mouse_reset:
	push	a

	mov	a,CMD_ResetC
	call	ps2_xmit			;send reset command
	mov	a,mouse_ST_ResetC
	mov	[mouse_stateV],a		;set mouse state
	mov	a,mouse_reset_timoutC
	mov	[mouse_work0V],a		;set reset timer

	pop	a
	ret



;**********
; mouse_init
;	Initialize the mouse. This function pends here while two commands are executed,
;	to place the mouse in remote mode and enable it. As such, depending upon the response
;	time of the mouse, several milliseconds could pass before this command returns.
;**********
XPAGEOFF

;bth
;added the following table of command bytes to send to the mouse to determine
;if it is a 3-d mouse or not
cmd_tbl:
  db CMD_RemoteC        ;put mouse in remote mode
  db 0f3h,0c8h          ;set sampling rate to 200 hz
  db 0f3h,064h          ;set sampling rate to 100 hz
  db  0f3h,050h         ;set sampling rate to 80 hz
end_cmd_tbl:
XPAGEON
mouse_init:
	push  a                             ;save a and x
    push  x

    mov   x,(end_cmd_tbl - cmd_tbl)     ;init x to length of command table
    mov   a,0                           ;init a to index into table
.mx0:
    push  a                             ;save table index
    index cmd_tbl                       ;get command to send
    call  mouse_cmd                     ;send the command to the mouse
.mxlp:
    call  mouse_machine                 ;babysit the mouse until done
    jc    .mxlp
    pop   a                             ;restore index
    inc   a                             ;increment it
    dec   x                             ;decrement command count
    jnz   .mx0

	mov	a,0f2h			                ;now send command to fetch mouse id
	call	mouse_id
.mx1:
	call	mouse_machine		        ;wait for command complete
	jc	.mx1

	mov	a,[mouse_dataV]		            ;get id byte
    cmp   a,MOUSE_3D_ID                 ;if we're using a 3d mouse
    mov   a,MOUSE_3D_PACKET_LEN         ;set packet length accordingly
    jz    .mx4
    sub   a,1                           ;else subtract 1 from the length
.mx4:
    mov   [mouse_packet_lenV],a         ;save the packet length


	mov	a,CMD_EnblC			            ;enable mouse
	call	mouse_cmd
mx2:	call	mouse_machine
	jc	mx2

	pop	a
    pop   x
	ret

;========================================================================
; Clear mouse RAM variables
;========================================================================

mouse_init_module:
    push a
    push x
    mov A,ps2_clkC
    iowr Port3_Interrupt	; enable interrupts on ps2 clock (bit 6 of Port 3)

    CLEARRAM mouse_RAM_baseC,mouse_ramsizeC
    mov  A,MOUSE_REPORT_ID
    mov [mouse_idV],A
    pop a
    pop x
    ret

;**********
; mouse_cmd
;
;	Initiate a mouse command.
;	a = command byte value.
;**********
mouse_cmd:
	push	a

	call	ps2_xmit		;transmit command byte
	mov	a,mouse_ST_CmdC
	mov	[mouse_stateV],a	;set mouse to command state

	pop	a
	ret
;**********
; mouse_cmd
;
;	Initiate a mouse command.
;	a = command byte value.
;**********
mouse_id:
	push	a

	call	ps2_xmit		;transmit command byte
	mov	a,mouse_ST_IdC
	mov	[mouse_stateV],a	;set mouse to command state

	pop	a
	ret



;**********
; mouse_poll
;
;	Initiate a mouse data poll command.
;**********
mouse_poll:
	push	a

	mov	a,CMD_PollC
	call	ps2_xmit			;start transmit
	mov	a,mouse_ST_PollC
	mov	[mouse_stateV],a		;set mouse state machine to poll

	pop	a
	ret


;**********
; mouse_status
;
;	Returns the state of mouse_machine state variable mouse_stateV in A.
;**********
mouse_status:
    mov a,[mouse_stateV]
mst1:	ret



;**********
; mouse_suspend
;
;	Places mouse in stream mode prior to entering suspend. In stream mode, any mouse
;	activity will result in a mouse_int interrupt.
;**********
mouse_suspend:
	push	a
    CHKFLAG mouse_conx_flagC	; check to see if the mouse is there
	jz .no_mouse
	mov	a,CMD_StreamC
	call	mouse_cmd			;issue command
.msu1:	call	mouse_machine		;wait for completion
	jc	.msu1
	SETFLAG	mouse_suspend_flagC	;set suspend flag
.no_mouse:
	pop	a
	ret

mouse_resume:
    push a
    CHKFLAG mouse_conx_flagC	; check to see if the mouse is there
	jz .no_mouse
	mov	a,CMD_RemoteC           ;put mouse back in remote mode
	call	mouse_cmd			;issue command
.msu1:	call	mouse_machine	;wait for completion
	jc	.msu1
.no_mouse:
	pop	a
	ret

;********************
;********************
; mouse_machine
;
;	This is the main entry point to the top-level mouse byte-processing state machine.
;	This routine should be called on a regular basis (at least every few milliseconds)
;	from the main processing loop in order to drive the high-level state machine.
;********************
;********************
mouse_machine:
	push	a				;save stuff
	push	x

	mov	a,[mouse_stateV]		;read state variable into a
	index	mouse_ST_tbl		;a <- table value = offset to state code
	jacc	mouse_ST_base		;jump to proper state code

;*** Mouse state defines
mouse_ST_IdleC:	equ	0		;mouse state machine idle state
mouse_ST_CmdC:	equ	1		;mouse command state
mouse_ST_PollC:	equ	4		;mouse data-poll command state
mouse_ST_DataC:	equ	6		;mouse data response base state
mouse_ST_ResetC:	equ	10          ;mouse reset command
mouse_ST_InitC:	equ	12		;mouse reset response base state
mouse_ST_IdC:	equ	14		;mouse Id response base state


;*** Mouse state jump table
mouse_ST_tbl:
	db	mouse_ST_idle - mouse_ST_base	;(0) M0 - mouse idle
	db	mouse_ST_cmd - mouse_ST_base	;(1) M1 - mouse command
	db	mouse_ST_resp - mouse_ST_base	;(2) M2 - mouse response
	db	mouse_ST_go2idle - mouse_ST_base	;(3) M3 - go to idle after response
	db	mouse_ST_cmd - mouse_ST_base	;(4) M4 - mouse data poll command
	db	mouse_ST_resp - mouse_ST_base	;(5) M5 - mouse poll command Ack
	db	mouse_ST_data - mouse_ST_base	;(6) M6 - mouse data poll response byte 0
	db	mouse_ST_data - mouse_ST_base	;(7) M7 - mouse data poll response byte 1
	db	mouse_ST_data - mouse_ST_base	;(8) M8 - mouse data poll response byte 2
	db	mouse_ST_data - mouse_ST_base	;(9) M9 - mouse data poll response byte 2
	db	mouse_ST_cmd - mouse_ST_base	;(10) M10 - mouse Reset command
	db	mouse_ST_resp - mouse_ST_base	;(11) M11 - mouse Reset command Ack

⌨️ 快捷键说明

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