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

📄 scalesen.asm

📁 VCP201_CODE is a FPGA source code.
💻 ASM
字号:
;=================================================
; File name : ScaleSen.asm
; For PSX2 PF113X GamePad
; Input Data : 
; Return :
;=================================================

scalesen:
	movf	FSR,W		; save FSR
	movwf	sc_tmp3

	movlw	d'14'		;14h
        bsf	STATUS,RP0
	movwf	count
	movf	sen_null,W
        bcf	STATUS,RP0
	movwf	vr_null

	movlw	square_val
	movwf	FSR
	
scalesen_lp1:
	bcf	STATUS,RP0
	movf	INDF,W
	movwf	vr_value


	call	adj_sen

	sublw	0xff
	movwf	INDF
	incf	FSR,F

	bsf	STATUS,RP0
	decfsz	count,F
	goto	scalesen_lp1


;====================================
;convert key
	bcf	STATUS,RP0

	movlw	0x3f
	iorwf	pb_raw1,F
	movlw	0xff
	movwf	pb_raw0	; clr up,dn,rt,lf

left_to_E2_bit:
	movlw	b'11111110'
	movwf	sc_tmp1
	movlw	d'6'
	movwf	sc_tmp2

	movlw	left_val
	movwf	FSR

pb_button_lp1:	
	movf	INDF,W
	btfsc	STATUS,Z
	goto	pb_button_next1
	
	movf	sc_tmp1,W
	andwf	pb_raw1,F
pb_button_next1:	
	incf	FSR,F
	bsf	STATUS,C
	rlf	sc_tmp1,F
	decfsz	sc_tmp2,F
	goto	pb_button_lp1
	
square_to_L2_bit:
	movlw	b'11111110'
	movwf	sc_tmp1

	movlw	square_val
	movwf	FSR

pb_button_lp2:	

	movf	INDF,W
	btfsc	STATUS,Z
	goto	pb_button_next2
	
	movf	sc_tmp1,W
	andwf	pb_raw0,F

pb_button_next2:	
	incf	FSR,F
	bsf	STATUS,C
	rlf	sc_tmp1,F
	btfsc	STATUS,C
	goto	pb_button_lp2

end_convert_key:
	bcf	STATUS,RP0
	movf	sc_tmp3,W	;restore FSR
	movwf	FSR		


	return


;===============================================
; Adject Senser value
; (Value - min x FF)/(null-min)=new value
; 0-----min--------value--------null----FF
; range:max_sen----------------null
;==============================================
adj_sen:
	subwf	vr_null,W	;Value > Null ?
        btfsc	STATUS,C    	;-ve ?
        goto	adj_senser1   	;No
	movlw	0xff     	;Yes. Out FF
        return

adj_senser1:
	btfss	STATUS,Z	;Value=Null?
        goto	adj_senser2   	;No
	movlw	0xff         	;Yes. Out FF
	return

adj_senser2:
	movlw	MAX_SEN        	;Value < min?
	subwf	vr_value,W

	btfsc	STATUS,C	;-ve?
	goto	adj_senser3	;No
	movlw	0x00		;Yes. return min 00	
	return

adj_senser3:
	btfss	STATUS,Z      	;Value=min 0?
        goto	adj_senser4
        movlw	0x00   		;Yes, Out 00  	
	return

adj_senser4:
	movlw	0xff
        movwf	lo_byte

	movlw	MAX_SEN
	subwf	vr_value,W

        movwf	hi_byte
        call	umul

	movlw	MAX_SEN
	subwf	vr_null,W

	bsf	STATUS,RP0
        movwf	divisor
        bcf	STATUS,RP0

        call	udiv
        movf	lo_byte,W

	return






;---------------------------------------
;adj_40_sen:
;adjust the scale from command 40
;usage : 0 : x1.5,  	1 : x1.25
;	 2 : x1.125, 	3 : x1
;----------------------------------------
adj_40_sen:
	movlw	square_val
	movwf	sc_tmp1
	movlw	ana_sen_1
	movwf	FSR	
	movlw	d'12'
	movwf	byte_count

adj_sen_lp1:
	movf	INDF,W
	movwf	sc_tmp3		; scale value
	btfsc	byte_count,0
	swapf	sc_tmp3,F
	movlw	0x0f		;
	andwf	sc_tmp3,F
	
	movf	FSR,W		; save FSR (scale val pointer)
	movwf	sc_tmp2

	movlw	HIGH map_sc_table
	movwf	PCLATH

	movf	byte_count,W
	sublw	d'12'		;PBMAX

	call	map_sc_table

	addwf	sc_tmp1,W
	movwf	FSR
	movf	INDF,W
	movwf	lo_byte		; vr_value

	movf	sc_tmp3,W
	btfss	STATUS,Z
	goto	chk_scale_1
	movlw	d'150'
	goto	scale_40_exe
	
chk_scale_1:
	movlw	0x01		; 01
	xorwf	sc_tmp3,W
	btfss	STATUS,Z
	goto	chk_scale_2
	movlw	d'125'
	goto	scale_40_exe
	
chk_scale_2:
	movlw	0x02		; 02
	xorwf	sc_tmp3,W
	btfss	STATUS,Z	
	goto	chk_scale_3
	movlw	d'113'
	goto	scale_40_exe
	
chk_scale_3:
	movlw	d'100'
	
scale_40_exe:
	movwf	hi_byte
	call	umul
        	
	bsf	STATUS,RP0
	movlw	d'100'
	movwf	divisor
        bcf	STATUS,RP0
	call	udiv

	movf	hi_byte,W
	movlw	0xff		; not affect Z
	btfsc	STATUS,Z
	movf	lo_byte,W
	movwf	INDF

scale_40_exe_done:	
	movf	sc_tmp2,W	; restore FSR
	movwf	FSR
	
	btfsc	byte_count,0	; inc scale-val ptr
	incf	FSR,F		; every two lp

	decfsz	byte_count,F
	goto	adj_sen_lp1

	return
	

map_sc_table:
	addwf	PCL,F
        nop
	retlw	d'10'		; right
	retlw	d'8'		; left
	retlw	d'11'		; up
	retlw	d'9'		; down
	retlw	d'3'		; triangle
	retlw	d'2'		; O
	retlw	d'1'		; X
	retlw	d'0'		; square
	retlw	d'5'		; L1
	retlw	d'4'		; R1
	retlw	d'6'		; R2
	retlw	d'7'		; L2

	retlw	d'0'		; dummy

	return

;----------------------------------------
;set_sen_null
; reset the null value
; find the min value and save to sen_null
; if < 0x80, then preset to 0x80
;----------------------------------------
set_sen_null:
        call	read_sen

	movlw	0xff		; place max value to null
	movwf	vr_null
	
	movlw	square_val
	movwf	FSR
	
	movlw	d'14'		;max no of key =14 count
	movwf	byte_count
	
sen_null_lp:
	movf	INDF,W
	subwf	vr_null,W	; compare with sen_null
	btfss	STATUS,C
	goto	sen_null_next
	movf	INDF,W
	movwf	vr_null		; > sen_null, place to sen_null

sen_null_next:
	incf	FSR,F	
	decfsz	byte_count,F
	goto	sen_null_lp


	movlw	MIN_OFFSET
	btfss	vr_null,7
	goto	null_too_small
	movlw	NULL_OFFSET	; OFFSET
	subwf	vr_null,W

null_too_small:
	bsf	STATUS,RP0
	movwf	sen_null
        bcf	STATUS,RP0
	
	return




⌨️ 快捷键说明

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