📄 scalesen.asm
字号:
;=================================================
; File name : ScaleSen.asm
; For PSX2 PF113X GamePad
; Input Data :
; Return :
;=================================================
scalesen:
movf FSR,W ; save FSR
movwf sc_tmp3
movlw square_val
movwf sc_tmp1
movlw square_null
movwf FSR
movlw d'12'
movwf byte_count
scalesen_lp1:
movf INDF,W
movwf vr_null
movf FSR,W ; save FSR
movwf sc_tmp2
movf sc_tmp1,W
movwf FSR
movf INDF,W
movwf vr_value
call adj_senser
sublw 0xff
movwf INDF
movf sc_tmp2,W ; restore FSR
movwf FSR
incf FSR,F
incf sc_tmp1,F
decfsz byte_count,F
goto scalesen_lp1
movf sc_tmp3,W
movwf FSR ; restore FSR
;====================================
;conver key
movlw 0x0f
iorwf pb_raw1
movlw 0xff
movwf pb_raw0 ; clr up,dn,rt,lf
right_bit:
movf right_val,W
btfss STATUS,Z
bcf pb_raw1,BIT_RT
left_bit:
movf left_val,W
btfss STATUS,Z
bcf pb_raw1,BIT_LT
up_bit:
movf up_val,W
btfss STATUS,Z
bcf pb_raw1,BIT_UP
down_bit:
movf down_val,W
btfss STATUS,Z
bcf pb_raw1,BIT_DN
tri_bit:
movf tri_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_TRI
O_bit:
movf O_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_CIR
X_bit:
movf X_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_CRO
square_bit:
movf square_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_SQU
L1_bit:
movf L1_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_L1
R1_bit:
movf R1_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_R1
L2_bit:
movf L2_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_L2
R2_bit:
movf R2_val,W
btfss STATUS,Z
bcf pb_raw0,BIT_R2
btfsc pb_raw0,BIT_L2
goto end_convert_key
btfsc pb_raw0,BIT_R1
goto end_convert_key
btfsc pb_raw0,BIT_CIR
goto end_convert_key
bsf f_reset_ram
end_convert_key:
return
;===============================================
; Adject Senser value
; (Value - min x FF)/(null-min)=new value
; 0-----min--------value--------null----FF
; range:10----------------------null
;==============================================
adj_senser:
subwf vr_null,W ;Value > Null ?
btfsc STATUS,C ;-ve ?
goto adj_senser1 ;No
movlw 0xff ;Yes. Out FF
goto end_adj_senser
adj_senser1:
btfss STATUS,Z ;Value=Null?
goto adj_senser2 ;No
movlw 0xff ;Yes. Out FF
goto end_adj_senser
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
goto end_adj_senser
adj_senser3:
btfss STATUS,Z ;Value=min 0?
goto adj_senser4
movlw 0x00 ;Yes, Out 00
goto end_adj_senser
adj_senser4:
movlw 0xff
movwf lo_byte
movlw MAX_SEN
subwf vr_value,W
movwf hi_byte
bsf PCLATH,3
call umul
bcf PCLATH,3
movlw MAX_SEN
subwf vr_null,W
movwf divisor
bsf PCLATH,3
call udiv
bcf PCLATH,3
movf lo_byte,W
end_adj_senser:
return
;----------------------------
;set_sen_null
; reset the null value
;----------------------------
set_sen_null:
call read_sen
movlw square_null
movwf temp_buf1
movlw square_val
movwf FSR
movlw d'12'
movwf byte_count
sen_null_lp:
movlw 0x80
btfss INDF,7
goto null_too_small
movlw NULL_OFFSET ; OFFSET
subwf INDF,W
null_too_small:
movwf temp_buf3
movf FSR,W ; save FSR
movwf temp_buf2
movf temp_buf1,W
movwf FSR
movf temp_buf3,W
movwf INDF
movf temp_buf2,W ; restore FSR
movwf FSR
incf FSR,F
incf temp_buf1,F
decfsz byte_count,F
goto sen_null_lp
return
;---------------------------------
;adj_40_sen:
;adjust the scale from command 40
;usage : put the
;---------------------------------
adj_4_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
movf FSR,W ; save FSR
movwf sc_tmp2
movlw HIGH map_sc_table
movwf PCLATH
movlw ana_sen_1
subwf sc_tmp2,W
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 0x80 ; 01
xorwf sc_tmp3,W
btfss STATUS,Z
goto chk_scale_2
movlw d'125'
goto scale_40_exe
chk_scale_2:
movlw 0x40 ; 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
bsf PCLATH,3
call umul
bcf PCLATH,3
movlw d'100'
movwf divisor
bsf PCLATH,3
call udiv
bcf PCLATH,3
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
incf FSR,F
decfsz byte_count,F
goto adj_sen_lp1
return
map_sc_table:
addwf PCL,F
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -