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

📄 keylogo.asm

📁 cypressusb2.0.zip
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	iowr end0_mode		; function is not supported
	ret

endp_status:
	mov A, [endpoint_stall]
	cmp A, endpoint_stalled
	jnz endp_stalled_status
	mov A, 6Ah
	mov [data_start], A
	mov A, [endp0_dmabuff6]
	mov [data_count], A
	call control_read
	ret
	endp_stalled_status:
	mov A, 6Ch
	mov [data_start], A
	mov A, [endp0_dmabuff6]
	mov [data_count], A
	call control_read
	ret

get_desc:
	mov A, [endp0_dmabuff3]
	cmp A, device
	jz device_desc

	mov A, [endp0_dmabuff3]
	cmp A, configuration
	jz config_desc

	mov A, [endp0_dmabuff3]
	cmp A, report
	jz hid_report_descriptor

	mov A, stall		; send a stall to indicate that the requested
	iowr end0_mode		; function is not supported
	ret
 
;***********stage three..determine descriptor type (descriptor)

dev_status:
	mov A, 66h
	mov [data_start], A
	mov A, [endp0_dmabuff6]
	mov [data_count], A
	call control_read
	ret

device_desc:
	mov A, 00h
	mov [data_start], A
	mov A, [endp0_dmabuff6]
	mov [data_count], A
	call control_read
	ret

config_desc:
	mov A, 12h
	mov [data_start], A
	mov A, [endp0_dmabuff6]
	mov [data_count], A
	call control_read
	ret

hid_report_descriptor:
	mov A, 34h
	mov [data_start], A
	mov A, [endp0_dmabuff6]
	mov [data_count], A
	call control_read

	;******** get ready for endpoint 1!!!!! *********

	mov A, 00h		; clear movement
	mov [endp1_dmabuff1], A	; registers
	mov A, 00h		; so mouse doesn't move
	mov [endp1_dmabuff2], A	; on plug-in

	mov A, in_ack		; respond to IN on endpoint 1, enable, 3 bytes
	iowr end1_mode
	mov A, 03h
	iowr end1_count

	ret			

;*******************************************************
;
;	Interrupt handler: endpoint_one
;	Purpose: This interrupt routine handles the specially
;		 reserved data endpoint 1 (for a mouse).  This
;		 interrupt happens every time a host sends an
;		 IN on endpoint 1.  The data to send (NAK or 3
;		 byte packet) is already loaded, so this routine
;		 just prepares the dma buffers for the next packet
;
;*******************************************************

endpoint_one:
	push A				; store A register

	iord end1_mode
	cmp a, 16 + in_nak		; ACK,in_nak mode
	jnz error
	mov A, [endp1_data_toggle]	; change endpoint 1
	xor A, 80h			; data toggle
	and A, 80h
	mov [endp1_data_toggle], A


	mov A, 00h			; clear data from the dma buffer
	mov [endp1_dmabuff0], A
	mov [endp1_dmabuff1], A
	mov [endp1_dmabuff2], A


	pop A				; restore A register

	reti
	
;*******************************************************
;
;	Function: gpio
;
;	Purpose: moves mouse cursor in "USB" pattern
;
;*******************************************************

gpio:

	mov A, [logo_position]		; get x displacement
	index usb_table
	mov [endp1_dmabuff1], A

	inc [logo_position]	

	mov A, [logo_position]		; get y displacement
	index usb_table
	mov [endp1_dmabuff2], A

	inc [logo_position]	
	
	mov A, in_ack
	iowr end1_mode
	mov A, 03h
	or A, [endp1_data_toggle]
	iowr end1_count


	mov A, [logo_position]
	cmp A, 6Eh    			;compare to 110
	jnz wait_mouse_data_sent

	reset_usb_table:		; reset table if at end
	mov A, 00h
	mov [logo_position], A

;@@@stop responding to host, check if re-enumerated
iowr end1_mode
iowr usb_address
	
   wait_mouse_data_sent:
	iord usb_address	; if address = 0 a bus reset has occured
	cmp A,80h			; jump to wait loop
	jz wait
					; wait for data to be sent 
	iord end1_mode			; before loading registers
	and A, 01h			; again
	jnz wait_mouse_data_sent

	jmp gpio

;**********USB library main routines*******************


;******************************************************
;
;	function:  Control_read
;	Purpose:   Performs the control read operation
;		   as defined by the USB specification
;	SETUP-IN-IN-IN...OUT
;
;	data_start: must be set to the descriptors info
;		    as an offset from the beginning of the
;		    control_read_table
;	data_count: must be set to the size of the 
;		    descriptor 
;******************************************************

control_read: 

	mov X, 00h
	mov A, 00h
	mov [endp0_data_toggle], A
cr_wr:
	mov A, nak			;clear PID bits, leave in nak mode
	iowr end0_mode
	iord end0_mode
	cmp A, nak
	jnz cr_wr

   control_read_data_stage:
	mov X, 00h
	mov A, 00h
	mov [loop_counter], A	
crds_wr:
	mov A, con_rd_nak		;clear PID bits, leave in nak mode
	iowr end0_mode	
	iord end0_mode
	cmp A, con_rd_nak
	jnz crds_wr

	mov A, [data_count]
	cmp A, 00h
	jz control_read_status_stage

      dma_load_loop:			; loop to load data into the data buffer
	mov A, [data_start]
	index control_read_table
	mov [X + endp0_dmabuff0], A	; load dma buffer
	inc [data_start]
	inc X
	inc [loop_counter]
	dec [data_count]		; exit if descriptor
	jz dma_load_done		; is done
	mov A, [loop_counter]		; or 8 bytes sent
	cmp A, 08h
	jnz dma_load_loop

      dma_load_done:

	iord end0_count
	mov A, [endp0_data_toggle]
	xor A, 80h
	mov [endp0_data_toggle], A
	or A, [loop_counter]
	iowr end0_count

cr_wr_ack:
	mov A, con_rd_ack
	iowr end0_mode
	iord end0_mode
	and A, 0Fh
	cmp A, con_rd_ack
	jnz cr_wr_ack

      wait_control_read:
	iord end0_mode			; wait for the data to be
	and A, 01h     		        ; transfered
	jz control_read_data_stage
	iord end0_mode
    	and A, A0h             	 	; check if out/setup was sent by host
	jnz control_read_status_stage
	jmp wait_control_read

	jmp control_read_data_stage

   control_read_status_stage:		; OUT at end of data transfer
	ret

;******************************************************
;
;	function: control_write
;	purpose:  performs the control write operaion
;		  as defined by the USB specification
;	SETUP-OUT-OUT-OUT...IN
;******************************************************

control_write:

; not implemented with a mouse, but may be needed for
; other devices

	ret

;******************************************************
;
;	function: no_data_control
;	purpose: performs the no-data control operation
;		 as defined by the USB specification
;	SETUP-IN
;******************************************************

no_data_control:

	mov A, con_wr_stall	; setup for status stage IN
	iowr end0_mode
	iord end0_mode
	cmp A,con_wr_stall
	jnz no_data_control

  wait_nodata_sent:
	iord end0_mode 		; wait for the IN to be
	and A, 40h		; transfered
	jz wait_nodata_sent

	ret


;*********************************************************
;                   rom lookup tables
;*********************************************************

control_read_table:
   device_desc_table:
	db	12h		; size of descriptor (18 bytes)
	db	01h		; descriptor type (device descriptor)
	db	00h, 01h	; USB spec release (ver 1.0)
	db	00h		; class code (each interface specifies class information)
	db	00h		; device sub-class (must be set to 0 because class code is 0)
	db	00h		; device protocol (no class specific protocol)
	db	08h		; maximum packet size (8 bytes)
	db	5Eh, 04h	; vendor ID (note Microsoft vendor ID)
	db	11h, 11h	; product ID (Microsoft USB mouse product ID)
	db	14h, 00h	; device release number 
	db	00h		; index of manufacturer string (not supported)
	db	00h		; index of product string (not supported)
	db	00h		; index of serial number string (not supported)
	db	01h		; number of configurations (1)
   config_desc_table:
	db	09h		; length of descriptor (9 bytes)
	db	02h		; descriptor type (CONFIGURATION)
	db	22h, 00h	; total length of descriptor (34 bytes)
	db	01h		; number of interfaces to configure (1)
	db	01h		; configuration value (1)
	db	00h		; configuration string index (not supported)
	db	80h		; configuration attributes (bus powered...or will be in future
	db	32h		; maximum power (100mA)
	db	09h		; length of descriptor (9 bytes)
	db	04h		; descriptor type (INTERFACE)
	db	00h		; interface number (0)
	db	00h		; alternate setting (0)
	db	01h		; number of endpoints (1)
	db	03h		; interface class (3..defined by USB spec)
	db	01h		; interface sub-class (1..defined by USB spec)
	db	02h		; interface protocol (2..defined by USB spec)
	db	00h		; interface string index (not supported)
	db	07h		; descriptor length (7 bytes)
	db	05h		; descriptor type (ENDPOINT)
	db	81h		; endpoint address (IN endpoint, endpoint 1)
	db	03h		; endpoint attributes (interrupt)
	db	03h, 00h	; maximum packet size (3 bytes)
	db	0Ah		; polling interval (10ms)
	db	09h		; descriptor size (9 bytes)
	db	21h		; descriptor type (HID)
	db	00h, 01h	; class specification (1.00)	
	db	00h		; hardware target country (US)
	db	01h		; number of HID class descriptors to follow (1)
	db	22h		; report descriptor type (HID)
	db	32h, 00h	; total length of report descriptor			; 
   hid_report_desc_table:
	db	05h, 01h	; usage page (generic desktop)
	db	09h, 02h	; usage (mouse)
	db	A1h, 01h	; collection (application)
	db	09h, 01h	; usage (pointer)
	db	A1h, 00h	; collection (linked)
	db	05h, 09h	; usage page (buttons)
	db	19h, 01h	; usage minimum (1)
	db	29h, 03h	; usage maximum (3)
	db	15h, 00h	; logical minimum (0)
	db	25h, 01h	; logical maximum (1)
	db	95h, 03h	; report count (3 bytes)
	db	75h, 01h	; report size (1)
	db	81h, 02h	; input (3 button bits)
	db	95h, 01h	; report count (1)
	db	75h, 05h	; report size (5)
	db	81h, 01h	; input (constant 5 bit padding)
	db	05h, 01h	; usage page (generic desktop)
	db	09h, 30h	; usage (X)
	db	09h, 31h	; usage (Y)
	db	15h, 81h	; logical minimum (-127)
	db	25h, 7Fh	; logical maximum (127)
	db	75h, 08h	; report size (8)
	db	95h, 02h	; report count (2)
	db	81h, 06h	; input (2 position bytes X & Y)
	db	C0h, C0h	; end collection, end collection
   get_dev_status_table:
	db	00h, 00h	; bus powered, no remote wakeup
   get_config_table:
	db	01h		; configuration 1
   get_interface_table:
	db	00h		; interface 0
   get_endp_status_table:
	db	00h, 00h	; endpoint not stalled
   get_endp_stalled_status_table:
	db	01h, 00h	; endpoint stalled

;************************
   usb_table:

;	    x    y
;---------------------------
	db 00h, 05h	;1
	db 00h, 05h	;2
	db 00h, 05h	;3
	db 00h, 05h	;4
	db 00h, 05h	;5
	db 05h, 05h	;6
	db 05h, 00h	;7
	db 05h, 00h	;8
	db 05h, FBh	;9
	db 00h, FBh	;10
	db 00h, FBh	;11
	db 00h, FBh	;12
	db 00h, FBh	;13
	db 00h, FBh	;14
	db 23h, 05h	;15
	db FBh, FBh	;16
	db FBh, 00h	;17
	db FBh, 00h	;18
	db FBh, 05h	;19
	db 00h, 05h	;20
	db 05h, 05h	;21
	db 05h, 00h	;22
	db 05h, 00h	;23
	db 05h, 05h	;24
	db 00h, 05h	;25
	db FBh, 05h	;26
	db FBh, 00h	;27
	db FBh, 00h	;28
	db FBh, FBh	;29
	db 05h, 05h	;30
	db 1Eh, 00h	;31
	db 05h, 00h	;32
	db 05h, 00h	;33
	db 05h, 00h	;34
	db 05h, FBh	;35
	db 00h, FBh	;36
	db FBh, FBh	;37
	db FBh, 00h	;38
	db FBh, 00h	;39
	db FBh, 00h	;40
	db 0Fh, 00h	;41
	db 05h, FBh	;42
	db 00h, FBh	;43
	db FBh, FBh	;44
	db FBh, 00h	;45
	db FBh, 00h	;46
	db FBh, 00h	;47
	db 00h, 05h	;48
	db 00h, 05h	;49
	db 00h, 05h	;50
	db 00h, 05h	;51
	db 00h, 05h	;52
	db 00h, 05h	;53
	db 00h, E2h	;54
	db BAh, 00h	;55

⌨️ 快捷键说明

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