;--------------------------------------------------------------------------------------
;Function:
;Description: Convert OP4 mantissa(BCD) to OP1 mantissa(Binary)
;Input: OP4 and R_Op1Count
;Output: OP1
;affect:OP2,R_RamTemp1
;--------------------------------------------------------------------------------------
F_Bcd2Binary:
;---------R_Op1Exp=R_Op4Exp---------
lda R_Op4Exp ;
sta R_Op1Exp ;
jsr F_ClearOP1
lda #0
sta R_RamTemp1 ;loop counter
clc
L_GetBinary:
jsr F_ClearOp2
lda R_RamTemp1
ror a
tax
lda R_Op4Number+1,x
bcc L_GetLowNibble
;L_GetHighNibble:
ror a
ror a
ror a
ror a
L_GetLowNibble:
and #0fh
sta R_Op2Number+1
ldx R_RamTemp1 ;digit 0 pass directly
beq L_EndOfMulTen ;
L_MulTenLoop:
jsr F_OP2MulTen ;OP2=a*10^b
dex ;
bne L_MulTenLoop ;
L_EndOfMulTen:
jsr F_OP1_ADD_OP2
inc R_RamTemp1
lda R_RamTemp1
cmp R_Op1Count ;R_Op1Count=total digits
bcc L_GetBinary
;L_EndOfBcd2Binary:
jsr F_NormalizeOP1 ;用于调整(去除)小数点后面(非零数字)的零
rts
;--------------------------------------------------------------------------------------
;Function:
;Description: Convert OP1(Binary) to OP4(Binary)
;input:OP1
;output:OP4,R_Op1Count
;affect:OP2,R_RamTemp1
;--------------------------------------------------------------------------------------
F_Binary2Bcd: ;;;;乘法出错时,需修改
;;;;R_OperTemp ;可暂存OP4高位
;;;;R_Op2Regter ;可暂存OP2高位
;;;;BcdCodeLength 改为16
jsr F_ClearOp4_E
jsr F_ClearOper ;;zl
lda #0
sta R_RamTemp1 ;loop counter
L_AdjustBCD:
jsr F_ClearOp2 ;clear OP2 first!
;;------------------------------;zl change
lda R_Op1NumberTemp ;
cmp #2 ;
bne L_Op1Div10 ;
;jsr F_ClearOp2Reg ;;zl
jsr F_OP1Div10Remainder2 ;Remainder=OP2,OP1=OP1/10
jmp L_rere ;
L_Op1Div10: ;
;;------------------------------;
jsr F_OP1Div10Remainder ;Remainder=OP2,OP1=OP1/10
L_rere:
lda R_RamTemp1 ;
clc
ror a ;
tax ;
lda R_Op4Number+1,x ;
sta R_RamTemp2 ;
lda R_Op2Number+1 ;
bcc L_AddToBcdLowNibble ;
rol a ;
rol a ;
rol a ;
rol a ;
and #0f0h ;
ora R_RamTemp2 ;
L_AddToBcdLowNibble: ;
sta R_Op4Number+1,x ;
inc R_RamTemp1 ;
jsr F_CmpOP1Zero ;
bne L_AdjustBCD ;
;--------adjust Exp part--------
lda R_Op1Exp
sta R_Op4Exp
;-----adjust R_Op1Count------
lda #BcdCodeLength-1
sta R_Op1Count
;;------------------------------;zl change
lda R_Op1NumberTemp ;
cmp #2 ;
bne L_CheckOp1CountLoop ;
lda #BcdCodeLength*2-1 ;
sta R_Op1Count ;
;;------------------------------;
L_CheckOp1CountLoop:
lda R_Op1Count
clc
ror a
tax
lda R_Op4Number+1,x
bcc L_CheckLow
and #0f0h
beq L_AdjustOperandCount1