📄 finance.mac
字号:
jp compute_month_err
compute_month_9:
clr cf
ld a,(W1_LSD) ;\
add a,(FN_MONTH) ;|
daa a ;|
ld (FN_MONTH),a ;|save result
ld a,(W1_LSD-1) ;|
addc a,(FN_MONTH+1) ;|
daa a ;|
ld (FN_MONTH+1),a ;/
j cc,compute_month_99
jp compute_month_err
compute_month_99:
call w1_clear ;V1.07
ld wa,(FN_MONTH) ;V1.07
ld (W1_LSD),a ;V1.07
ld (W1_LSD-1),w ;V1.20
@KEY_ENABLE
ret
w02_exp_cancel:
ld a,(W2_DP)
j z,w02_exp_cancel_1
ld hl,W2
call stg_sfr47
dec (W2_DP)
jp w02_exp_cancel
w02_exp_cancel_1:
ret
compute_balance:
call cal_rate_puls_1_power_month ;(i+interest)^month
call w2_clear
ld (W2_S),1 ;-- w2=-1
ld (W2_LSD),1 ;/
call fn_calc_add ;[(i+interest)^month-1]
call fpayment_to_w2 ;-- [(i+interest)^month-1]*payment
call fn_calc_mult ;/
call fmthrate_to_w2 ;\
call fn_calc_div ;/ {[(i+interest)^month-1]*payment}/interest
call w1_to_w4 ;
call ftemp_to_w1 ;\
call famount_to_w2 ;|{{[(i+interest)^month-1]*payment}/interest}*[(i+interest)^month]
call fn_calc_mult ;/
call w4_to_w2 ;\
xor (W2_S),1 ;|{{[(i+interest)^month-1]*payment}/interest}*[(i+interest)^month]-{[(i+interest)^month-1]*payment}/interest
call fn_calc_add ;/
ret
;==============================================================================
;Payment (Installment per month) key payment function
;==============================================================================
key_payment:
ld (KEYIN),K_PAYMENT ;V1.25
;V2.03 @BBS (M_HAND,key_paymenthand) ;V1.22
;V2.03 ld (KEYIN),K_MONTH ;V1.22
;V2.03 jp key_monthhand ;V1.22
;V2.03key_paymenthand: ;V1.22
@BBS (F_TNKEY,input_payment)
@BBS (F_FNEABL,input_payment) ;finacial input enable
@BBS (F_MODIFIED,calculate_payment) ;calculate FN_PAYMENT
@BBC (F_FNRECALL,input_payment) ;V1.09
jp recall_payment ;recall FN_PAYMENT
;tenkey -> FN_PAYMENT...................................
input_payment:
call ten_to_w2dp ;tenkey ->W2 follow dp selector
call w2_to_fpayment ;W2 --> FN_PAYMENT
ld (SYM),S_CLR ;SYM= "C "
call w2_print
call w2_to_ten ;V1.10 for display
@SEB (F_MODIFIED)
@SEB (F_PAYMENT)
@CLB (F_AMOUNT)
@CLB (F_INTEREST)
@CLB (F_MONTH)
@CLB (F_FNEABL) ;clear finacial input enable
jp end_sequence
;Recall FN_PAYMENT even it is 0, if no tenkey input
recall_payment:
call fpayment_to_ten
call fpayment_to_w2 ;for printing
ld (SYM),S_CLR ;SYM= "C "
call w2_print ;
@CLB (F_AMOUNT)
@CLB (F_MONTH)
@CLB (F_INTEREST)
@CLB (F_PAYMENT)
jp end_sequence
;Calculate payment.......................................
calculate_payment: ;check whether the FN_INTEREST,FN_MONTH,FN_PAYMENT have data
@BBS (F_PAYMENT,input_payment) ;V1.12
@SEB (F_FINBUSY) ; busy with finacial calculate V5.05
call fn_chk_amount
j z,compute_payment_err ;if FN_INTEREST=0,error occured
call fn_chk_interest
j z,compute_payment_err ;if FN_MONTH=0,error occured
call fn_chk_month
j z,compute_payment_err ;if FN_PAYMENT=0,error occured
call compute_payment
@BBS (F_CALER,compute_payment_err)
ld (SYM),S_ASC
call w1_round_print
call w1_to_ten ;for display
call feed_1
@CLB (F_MODIFIED)
@CLB (F_AMOUNT)
@CLB (F_INTEREST)
@CLB (F_MONTH)
@CLB (F_PAYMENT)
@SEB (F_FNRECALL) ;V1.09
ld (FLG_C),0 ;C_MUL,C_DIV,C_MUP,C_DLTP,C_COST,C_SELL off V4.05
fn_payment02_1:
jp end_sequence
compute_payment_err:
jp finance_error
;Calculate Payment Amount per month(by using Loan Amount,Interest Rate,Number Of Months)
compute_payment:
@KEY_DISABLE
call cal_rate_puls_1_power_month ;(interest+1)^month->FN_TEMP
call ftemp_to_w1 ;FN_TEMP --> W1
call fmthrate_to_w2 ;interest --> W2
call fn_calc_mult ;interest*[(interest+1)^month]
call famount_to_w2 ;
call fn_calc_mult ;amount*interest*[(interest+1)^month]
call w1_to_ftemp1 ;backup result
call w2_clear
;Divider(Down) Part
call ftemp_to_w1 ;
ld (W2),1
ld (W2+7),1 ;W2 <- -1
call fn_calc_add ;{(interest+1)^month-1}
call w1_to_w2 ;
call ftemp1_to_w1 ;restore "amount*interest*[(interest+1)^month]"
call fn_calc_div ;{amount*interest*[(interest+1)^month]}/{(interest+1)^month-1}
call adjust_for_m14_or_m12 ;V1.07
call w1_to_w2 ;
call w2_round ;
call w2_to_fpayment ;
@KEY_ENABLE
ret ;Jump to main routine after calculation
finance_error:
@SEB (F_CALER) ;V1.09
;V1.10 ld (FINANCE_0),0 ;V1.10
;V1.10 ld (FINANCE_1),0 ;V1.10
;V1.10 @CLB (F_FINAL)
;V1.10 @CLB (F_MODIFIED)
;V1.10 @CLB (F_AMOUNT)
;V1.10 @CLB (F_INTEREST)
;V1.10 @CLB (F_MONTH)
;V1.10 @CLB (F_PAYMENT)
;V1.10 @CLB (F_FINBUSY) ; busy with finacial calculate V5.05
ld hl,FN_AMOUNT ;V1.10
ld c,60-1 ;V1.10
ld a,0 ;V1.10
clear_all_fn_register: ;V1.10
ld (hl+c),a ;V1.10
dec c ;V1.10
j f,clear_all_fn_register ;V1.10
@KEY_ENABLE
jp sys_error
fmonth_to_w2:
call w2_clear ;\ ;TEMP_BUF 10byte clear
ld a,(FN_MONTH+1) ;|
ld (W2_LSD-1),a ;|N-->w02
ld a,(FN_MONTH+0) ;|
ld (W2_LSD),a ;/
ret
;Calculate (1+InterestRate/1200)^# of Months
cal_rate_puls_1_power_month:
call fmthrate_to_w1
call w2_clear ;-/ w2<---1
ld (W2_LSD),1 ;/
call fn_calc_add ;w1 = w1 +1= moth_rate+1
call fntemp_clear
call fntemp1_clear
ld (FN_TEMP+7),1
call w1_to_ftemp1 ;W1 --> FN_TEMP1
call month_dec_into_bin ;month convert from decimal into binary
ld e,16 ;2 bytes will be shift
clr cf
power_month_1:
ld wa,(FN_MONTH_H) ;\shift leftt shift leftt
shlca wa ;|cf<--FN_MONTH+0<--cf<--FN_MONTH+0
ld (FN_MONTH_H),a ;|
ld (FN_MONTH_H+1),w ;/
j cc,power_month_2
call ftemp_to_w1 ;
call ftemp1_to_w2 ;
call fn_calc_mult ;
call w1_to_ftemp ;temporary backup result
power_month_2:
dec e
j eq,power_month_3
call ftemp_to_w1 ;FN_TEMP --> W1
call w1_to_w2 ;w1=w1^2
call fn_calc_mult ;
call w1_to_ftemp ;backup result
jp power_month_1
power_month_3:
ret
;====================================================================
fn_chk_amount:
ld hl,FN_AMOUNT
jp _zerock
fn_chk_interest:
ld hl,FN_INTEREST
jp _zerock
fn_chk_payment:
ld hl,FN_PAYMENT
jp _zerock
fn_chk_month:
ld a,(FN_MONTH+0)
or a,(FN_MONTH+1)
ret
;Check Zero routine for zero page
;--------------------------------------------------------
;|hex_mth |
;| function: |
;| HEXA data is created to NO_PLU depends |
;| on BCD data of PLU_NO |
;| input: |
;| none |
;| output: |
;| none |
;| |
;| FN_MONTH FN_MONTH_H |
;|eg: |05|00| ---> |01|F4| |
;| |
;|caution: this routine is limit 3 digit of BCD |
;| (0000d - 9999d) |
;| |
;--------------------------------------------------------
;
month_dec_into_bin:
;----------------------------------------------------deal with 0~9
ld wa,0
ld (FN_MONTH_H),wa ;
ld a,(FN_MONTH) ;\
and a,0x0f ;|keep the low nibble 0~9
ld (FN_MONTH_H),a;/
;----------------------------------------------------deal with 10~99
ld wa,(FN_MONTH_H)
ld b,(FN_MONTH)
and b,0xf0 ;clear (FN_MONTH_H+1)
shrc b ;\
shrc b ;|
shrc b ;|wa=w x a
shrc b ;|
month_dec_to_bin_0:
cmp b,0
j z,month_dec_to_bin_1
clr cf ;
add wa,10 ;\
dec b
jp month_dec_to_bin_0
month_dec_to_bin_1:
;----------------------------------------------------deal with 100~999
ld b,(FN_MONTH+1)
and b,0x0f
month_dec_to_bin_10:
cmp b,0
j z,month_dec_to_bin_2
clr cf
add wa,100
dec b
jp month_dec_to_bin_10
;----------------------------------------------------deal with 1000-9999
month_dec_to_bin_2:
ld b,(FN_MONTH+1)
shrc b ;
shrc b ;
shrc b ;
shrc b ;
month_dec_to_bin_20:
cmp b,0
j eq,month_dec_to_bin_3
clr cf
add wa,1000
dec b
jp month_dec_to_bin_20
;----------------------------------------------------deal with 100~999
month_dec_to_bin_3:
ld (FN_MONTH_H),wa
ret
;==============================================================================;V1.07
adjust_for_m14_or_m12:
@BBS (M14,adjust_for_m14_or_m12_1)
adjust_for_m14_or_m12_0:
@BBC (M10,adjust_for_m10) ;V1.21
ld a,(W1_MSD) ;V1.21
or a,(W1_MSD+1) ;V1.21
jp adjust_for_m12 ;V1.21
adjust_for_m10: ;V1.21
ld a,(W1_MSD)
adjust_for_m12:
cmp a,0
j eq,adjust_for_m14_or_m12_1
cmp (W1_DP),0
j le,finance_error
dec (W1_DP)
ld hl,W1
call stg_sfr47
jp adjust_for_m14_or_m12_0
adjust_for_m14_or_m12_1:
ret ;V1.07
;==============================================================================
;more precision for calculaton with 14 digit operation
;==============================================================================
fn_calc_mult:
set (FINANCE_1).3 ;calculate for finical
call calc_mult
clr (FINANCE_1).3 ;end finical calculate
ret
;--------------------------------
fn_calc_div:
set (FINANCE_1).3 ;calculate for finical
call calc_div
clr (FINANCE_1).3 ;end finical calculate
ret
;--------------------------------
fn_calc_add:
set (FINANCE_1).3 ;calculate for finical
call calc_add
clr (FINANCE_1).3 ;end finical calculate
ret
;==============================================================================
;regist move to w1
;==============================================================================
famount_to_w1:
ld ix,FN_AMOUNT
jp move_to_w1
ftemp_to_w1:
ld ix,FN_TEMP
jp move_to_w1
ftemp1_to_w1:
ld ix,FN_TEMP1
jp move_to_w1
fpayment_to_w1:
ld ix,FN_PAYMENT
jp move_to_w1
fmthrate_to_w1:
ld ix,FN_MTHRATE
jp move_to_w1
finterest_to_w1:
ld ix,FN_INTEREST
jp move_to_w1
w4_to_w1:
ld ix,W4
jp move_to_w1
;==========================================================
;register move to w2
;==========================================================
famount_to_w2:
ld ix,FN_AMOUNT
jp move_to_w2
fpayment_to_w2:
ld ix,FN_PAYMENT
jp move_to_w2
ftemp_to_w2:
ld ix,FN_TEMP
jp move_to_w2
ftemp1_to_w2:
ld ix,FN_TEMP1
jp move_to_w2
finterest_to_w2:
ld ix,FN_INTEREST
jp move_to_w2
fmthrate_to_w2:
ld ix,FN_MTHRATE
jp move_to_w2
w4_to_w2:
ld ix,W4
jp move_to_w2
;==========================================================
;w1 sent out to
;==========================================================
w1_to_fpayment:
ld ix,W1
ld iy,FN_PAYMENT
jp move_9byte
w1_to_fmthrate:
ld ix,W1
ld iy,FN_MTHRATE
jp move_9byte
w1_to_ftemp:
ld ix,W1
ld iy,FN_TEMP
jp move_9byte
w1_to_ftemp1:
ld ix,W1
ld iy,FN_TEMP1
jp move_9byte
w1_to_famount:
ld ix,W1
ld iy,FN_AMOUNT
jp move_9byte
w1_to_finterest:
ld ix,W1
ld iy,FN_INTEREST
jp move_9byte
w1_to_w4:
ld ix,W1
ld iy,W4
jp move_9byte
;==========================================================
;w2 sent out to
;==========================================================
w2_to_famount:
ld ix,W2
ld iy,FN_AMOUNT ;save FN_AMOUNT
jp move_9byte
w2_to_finterest:
ld ix,W2
ld iy,FN_INTEREST
jp move_9byte
w2_to_fpayment:
ld ix,W2
ld iy,FN_PAYMENT ;save FN_AMOUNT
jp move_9byte
w2_to_w4:
ld ix,W2
ld iy,W4
jp move_9byte
;==========================================================
;work register move into tenkey buffer
;==========================================================
finterest_to_ten:
ld ix,FN_INTEREST
jp move_to_ten
famount_to_ten:
ld ix,FN_AMOUNT
jp move_to_ten
fpayment_to_ten:
ld ix,FN_PAYMENT
move_to_ten:
ld iy,TENKEY
jp move_9byte
;==============================================================================
;round
;==============================================================================
w1_round:
ld hl,W1
jp wreg_round
;------------------------------
w2_round:
ld hl,W2
;------------------------------
wreg_round:
call wk_round
ret
;======================================
amount_print:
ld hl,FN_AMOUNT
jp wreg_print
;------------------------------
w1_round_print:
call w1_round
w1_print:
ld hl,W1
jp wreg_print
;------------------------------
w2_round_print:
call w2_round
w2_print:
ld hl,W2
;------------------------------
;==============================
wreg_print:
call wk_print
ret
;======================================
;work register clear
;======================================
fn_register_clear: ;V1.13
ld hl,FN_AMOUNT
call clear_9byte
ld hl,FN_INTEREST
call clear_9byte
ld hl,FN_PAYMENT
call clear_9byte
ld hl,0
ld (FN_MONTH),hl
ret
fntemp_clear:
ld hl,FN_TEMP
jp clear_9byte
fntemp1_clear:
ld hl,FN_TEMP1
jp clear_9byte
;==============================================================================
end_sequence:
@CLB (F_FINBUSY) ;claer flag for finance calculater not in busy
jp function_end
;==============================================================================
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -