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

📄 kbm_cmd.asm

📁 CY7C63743 usb键盘的源码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	db	mouse_ST_init - mouse_ST_base	;(12) M12 - mouse reset response byte 0
	db	mouse_ST_init - mouse_ST_base	;(13) M13 - mouse reset response byte 1
	db	mouse_ST_cmd - mouse_ST_base	;(14) M14 - mouse Get ID command
	db	mouse_ST_resp - mouse_ST_base	;(15) M15 - mouse Get ID command Ack
	db	mouse_ST_id - mouse_ST_base	;(16) M16 - mouse  ID response

mouse_ST_base:
;**********
; mouse_ST_idle - (M0): Mouse idle state.
;	Any received data is assumed to be unsolicited and ignored, other than the fact
;	that it sets the mouse connect flag.
;**********
mouse_ST_idle:
	CHKFLAG	mouse_rcv_flagC	;check for unsolicited receive data
	jz	mi0				;branch if none
	SETFLAG	mouse_conx_flagC	;assume a mouse is connected

mi0:	CHKFLAG	ps2_rfail_flagC	;check for unsolicited receive errors
	jz	mi1				;branch if none
	call	ps2_bus_idle		;release ps/2 bus
	jmp	mouse_end_state

mi1:	CHKFLAG	ps2_timout_flagC	;check for bus timeout
	jnz	m_timout			;branch if so

	jmp	mouse_end_state		;that's all


;*****
; mouse_ST_cmd
;
;	This state is entered when a new command has been transmitted to the mouse.
;	The following code is entered for states 1, 4 and 9.
;	State 1 is used for all PS/2 commands except Reset and Send Data Packet. State 1
;	commands always transition to state 2 upon successful completion of transmission. 
;	State 2 expects to receive an Ack and, if so, transitions to State 3, which in turn
;	transitions to Idle.
;
;	mouse_ST_cmd is entered in State 4 for the Send Data Packet command. State 4
;	transitions to state 5, in which the Ack is received, the to states 6~8 in which
;	the data packet is received.
;
;	mouse_ST_cmd is entered in State 9 to transmit a mouse Reset command. State 9
;	transitions to State 10, where the Ack is received, then to states 11 and 12 where
;	the mouse initialization response (AA 00) is expected.

;	mouse_ST_cmd is entered in State 13 to transmit a mouse ID command. State 13
;	transitions to State 14, where the Ack is received, then to state15 where
;	the mouse id response (XX) is expected.
;
;
;*****
mouse_ST_cmd:
	CHKFLAG	ps2_tfail_flagC	;check for transmission error
	jz	mc1				;branch if not
	call	ps2_bus_idle		;set the bus idle
	mov	a,[mouse_resendV]		;resend on error
	call	ps2_xmit
	jmp	mouse_end_state

mc1:	CHKFLAG	ps2_timout_flagC	;check for ps2 bus timeout
	jnz	m_timout			;branch if so

	CHKFLAG	ps2_tx_flagC	;check for transmit complete
	jz	mouse_end_state		;if not, hold state

;* command transmission complete - go to response state
	call	ps2_bus_idle		;release bus inhibit
	mov	a,ps2_timeoutC		;else, reload timeout counter
	mov	[mouse_mScntV],a
	jmp	mouse_next_state		;go to receive state


;*****
; mouse_ST_resp
;	Expect an Ack response byte. This code is used for states 2, 5 and 10.
;
;*****
mouse_ST_resp:

;* Check for receive failures
	CHKFLAG	ps2_rfail_flagC	;check for receive failure
	jz	mr3				;branch if not
	CLRFLAG	ps2_rfail_flagC	;clear fail flag
	jmp	mr6				;retry command

mr3:	CHKFLAG	ps2_timout_flagC	;check for ps2 bus timeout
	jnz	m_timout			;branch if so

;* no errors, check for new byte
	CHKFLAG	mouse_rcv_flagC	;check for receive complete
	jz	mouse_end_state		;hold state if not

;* Got a complete response byte
	CLRFLAG	mouse_rcv_flagC	;clear flag
	mov	a,[mouse_dataV]		;get response byte
	call	ps2_bus_idle		;release bus
	cmp	a,RESP_AckC			;hope for an Ack
	jnz	mr6				;branch if not

;* Ack response
	SETFLAG	mouse_conx_flagC	;assume a mouse is connected
	jmp	mouse_next_state		;move to next state

;* Any other response results in a resend
mr6:
      jmp   mi7
;	dec	[mouse_stateV]		;*** 1/13/97 fall back to transmit state
;	call	ps2_bus_idle		;set the bus idle
;	mov	a,[mouse_resendV]
;	call	ps2_xmit			;initiate re-transmission
;	jmp	mouse_end_state

;*****
; mouse_ST_go2idle
;	State 3. Transition to idle.
;*****
mouse_ST_go2idle:
	mov	a,mouse_ST_IdleC		;return to idle
	mov	[mouse_stateV],a
	jmp	mouse_end_state


;*****
; mouse_ST_data - States M6 ~ M8
;	Expect a mouse data packet
;
;*****
mouse_ST_data:
	CHKFLAG	ps2_rfail_flagC	;check for receive failure
	jz	md1				;branch if not

;* Receive failure - retransmit command
	CLRFLAG	ps2_rfail_flagC	;clear fail flag
	call	ps2_bus_idle		;set the bus idle
	mov	a,[mouse_resendV]
	call	ps2_xmit			;initiate re-transmission
	mov	a,mouse_ST_PollC		;back to command state
	mov	[mouse_stateV],a
	jmp	mouse_end_state

md1:	CHKFLAG	ps2_timout_flagC	;check for ps2 bus timeout
	jnz	m_timout			;branch if so

	CHKFLAG	mouse_rcv_flagC	;check for receive complete
	jz	mouse_end_state		;if not, hold state

;* received a new byte
	CLRFLAG	mouse_rcv_flagC	;clear flag
	mov	a,[mouse_stateV]		;get current state
	sub	a,mouse_ST_DataC		;subtract for response byte #
	mov	x,a				;move index to x
	mov	a,[mouse_dataV]		;get response byte
	mov	[x+mouse_packetV],a	;add to RAM buffer
	call	ps2_bus_idle		;release bus inhibit
	SETFLAG	mouse_conx_flagC	;assume a mouse is connected
	mov	a,x				;get index back in a
      inc   a
	cmp	a,[mouse_packet_lenV]	      ;last byte?
	jnz	mouse_next_state		;if not, go to next state
	mov	a,mouse_ST_IdleC		;else, go to idle
	mov	[mouse_stateV],a
	jmp	mouse_end_state



;*****
; mouse_ST_init
;
;	Handle Reset response (AA, 00). States M11 ~ M12
;*****
mouse_ST_init:

	CHKFLAG	ps2_rfail_flagC	;check for receive failure
	jz	mt1				;branch if not
	call	ps2_bus_idle		;set the bus idle
	mov	a,[mouse_resendV]
	call	ps2_xmit			;initiate re-transmission
	mov	a,mouse_ST_ResetC		;back to Reset state
	mov	[mouse_stateV],a
	jmp	mouse_end_state


mt1:	CHKFLAG	ps2_timout_flagC	;check for ps2 bus timeout
	jz	mt2				;branch if not

	dec	[mouse_work0V]		;decrement reset timout count
	jz	m_timout			;if time's up.... no mouse
	mov	a,ps2_timeoutC		;else, reload timeout counter
	mov	[mouse_mScntV],a
	CLRFLAG	ps2_timout_flagC	;clear timeout flag
	jmp	mouse_end_state		;keep waiting

mt2:	CHKFLAG	mouse_rcv_flagC	;check for receive complete
	jz	mouse_end_state		;if not, hold state

;* Got a complete response byte
	CLRFLAG	mouse_rcv_flagC	;clear flag
	mov	a,[mouse_stateV]		;get current state
	sub	a,mouse_ST_InitC		;subtract for response byte #
	mov	x,a				;move index to x
	mov	a,[mouse_dataV]		;get response byte
	mov	[x+mouse_packetV],a	;add to RAM buffer
	call	ps2_bus_idle		;release bus
	SETFLAG	mouse_conx_flagC	;assume a mouse is connected
	mov	a,x				;get index back in a
	cmp	a,1				;last byte?
	jnz	mouse_next_state		;if not, go to next state
	mov	a,mouse_ST_IdleC		;else, go to idle
	mov	[mouse_stateV],a
	jmp	mouse_end_state
	
;*****
; mouse_ST_id
;	Expect an id response byte. ;
;*****
mouse_ST_id:


;* Check for receive failures
	CHKFLAG	ps2_rfail_flagC	;check for receive failure
	jz	mi3				;branch if not
	CLRFLAG	ps2_rfail_flagC	;clear fail flag
	jmp	mi6				;retry command

mi3:	CHKFLAG	ps2_timout_flagC	;check for ps2 bus timeout
	jnz	m_timout			;branch if so

;* no errors, check for new byte
	CHKFLAG	mouse_rcv_flagC	;check for receive complete
	jz	mouse_end_state		;hold state if not

;* Got a complete response byte
	CLRFLAG	mouse_rcv_flagC	;clear flag
	call	ps2_bus_idle		;release bus
	mov	a,mouse_ST_IdleC		;go to idle
	mov	[mouse_stateV],a
	jmp	mouse_end_state
;* Ack response
;	SETFLAG	mouse_conx_flagC	;assume a mouse is connected
;	jmp	mouse_next_state		;move to next state

;* Any other response results in a resend
mi6:
    dec   [mouse_stateV]
mi7:
	dec	[mouse_stateV]		;*** 1/13/97 fall back to transmit state
	call	ps2_bus_idle		;set the bus idle
	mov	a,[mouse_resendV]
	call	ps2_xmit			;initiate re-transmission
	jmp	mouse_end_state


;****
;**** PS/2 bus timeout handling
m_timout:

	CLRFLAG	mouse_conx_flagC	;assume the mouse is gone
;	mov	a, 8
;	mov	[plugin], a			; clear plugin flag
	call	ps2_bus_idle		;set the bus idle
	mov	a,mouse_ST_IdleC		;set idle mouse state
	mov	[mouse_stateV],a
	jmp	mouse_end_state

mouse_next_state:
	inc	[mouse_stateV]		;increment state

;* mouse_machine always finally exits through this code. The C-bit is returned set
;* if mouse_machine is busy, or clear if mouse_machine is at Idle state.
;*** JK C-bit also cleared if mouse has since been unplugged
mouse_end_state:
	mov	a,[mouse_stateV]
	cmp	a,mouse_ST_IdleC			;check for idle
	jz	mm9					;branch if idle (C-bit clear)
	SETC						;so we should set C
mm9:	pop	x
	pop	a	
	ret

;##
;##### END Module kb_cmd #####

⌨️ 快捷键说明

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