Mercurial > public > hwos_code
diff src/convert.asm @ 582:b455b31ce022
work on 2.97 stable
author | heinrichsweikamp |
---|---|
date | Mon, 26 Feb 2018 16:40:28 +0100 |
parents | a5fc007634c5 |
children | ca4556fb60b9 |
line wrap: on
line diff
--- a/src/convert.asm Sun Feb 25 18:25:38 2018 +0100 +++ b/src/convert.asm Mon Feb 26 16:40:28 2018 +0100 @@ -1,6 +1,6 @@ ;============================================================================= ; -; File convert.asm +; File convert.asm ## V2.98 ; ; Converts register values to string ; @@ -11,298 +11,270 @@ ; 2010-12-10 : [jDG] Optimize macro size ; -#include "hwos.inc" ; Mandatory header +#include "hwos.inc" ; Mandatory header + +basic CODE ;============================================================================= - CBLOCK tmp+0x09 ; space for aa_wordprocessor - temp3 - temp4 - cvt_flags2 - ; Reserved to tmp+0x11... - ENDC - -#define pre_zero_flag cvt_flags2,0 -#define all_zeros_flag cvt_flags2,1 -#define DP_done cvt_flags2,2 -#define DP_done2 cvt_flags2,3 -#define show_last3 cvt_flags2,4 -#define leading_zeros cvt_flags2,5 -#define show_last4 cvt_flags2,6 - -basic CODE - -;============================================================================= - global output99_call + global output99_call output99_call: clrf ignore_digits incf ignore_digits,F - clrf temp4 + clrf cvt_temp4 - global output99 + + global output99 output99: movlw d'99' cpfslt lo movwf lo ; Limit to 99 - movff lo,lo_temp + movff lo,lo_temp clrf hi_temp - bcf pre_zero_flag ; do not display leading zeros + bcf pre_zero_flag ; do not display leading zeros -LCD_val99_2: - movlw b'00001010' ; 10 - movwf temp2 - clrf temp3 +LCD_val99_2: + movlw .10 ; 10 + movwf cvt_temp2 + clrf cvt_temp3 rcall DEC2ASCII - movlw b'00000001' ; 1 - movwf temp2 - clrf temp3 - bsf pre_zero_flag ; last figure, display zero (0) + movlw .1 ; 1 + movwf cvt_temp2 + clrf cvt_temp3 + bsf pre_zero_flag ; last figure, display zero (0) rcall DEC2ASCII - RETURN + return global output99x_call - output99x_call: clrf ignore_digits incf ignore_digits,F - clrf temp4 + clrf cvt_temp4 movlw d'99' cpfslt lo movwf lo ; Limit to 99 - movff lo, lo_temp + movff lo, lo_temp clrf hi_temp - bsf pre_zero_flag ; display leading zeros - bra LCD_val99_2 - + bsf pre_zero_flag ; display leading zeros + bra LCD_val99_2 + + global output8_call - -output8_call: - clrf ignore_digits +output8_call: + clrf ignore_digits incf ignore_digits,F - clrf temp4 + clrf cvt_temp4 output8: - movff lo, lo_temp + movff lo, lo_temp clrf hi_temp - bcf pre_zero_flag ; do not display leading zeros - - movlw b'01100100' ; 100 - movwf temp2 - clrf temp3 + bcf pre_zero_flag ; do not display leading zeros + movlw .100 ; 100 + movwf cvt_temp2 + clrf cvt_temp3 rcall DEC2ASCII - bra LCD_val99_2 + bra LCD_val99_2 + global output16_4_call -output16_4_call: ; limit to 9999 +output16_4_call: ; limit to 9999 bsf show_last4 - ; 9999 = 27 0F = [39][15] - movlw .40 - cpfslt hi ; hi < 40 ? - bra output16_4_call_2 ; No, hi >= 40, do limit - ; Yes, hi <= 39 - movlw .39 - cpfseq hi ; hi = 39 ? - bra output16_4_call_3 ; No, hi < 39, no limit needed - ; Yes, hi = 39 - movlw .15 - cpfslt lo ; lo < 15 - movwf lo ; No, lo >= 15, set lo = 15. - ; Yes, lo <= 14 or lo set to =15 - bra output16_4_call_3 ; done. -output16_4_call_2: ; Set to 9999 - movlw LOW .9999 - movwf lo - movlw HIGH .9999 - movwf hi + ; 9999 = 27 0F = [39][15] + movlw .40 + cpfslt hi ; hi < 40 ? + bra output16_4_call_2 ; No, hi >= 40, do limit + ; Yes, hi <= 39 + movlw .39 + cpfseq hi ; hi = 39 ? + bra output16_4_call_3 ; No, hi < 39, no limit needed + ; Yes, hi = 39 + movlw .15 + cpfslt lo ; lo < 15 + movwf lo ; No, lo >= 15, set lo = 15. + ; Yes, lo <= 14 or lo set to =15 + bra output16_4_call_3 ; done. +output16_4_call_2: ; Set to 9999 + movlw LOW .9999 + movwf lo + movlw HIGH .9999 + movwf hi output16_4_call_3: - bra output16_call + bra output16_call global output16_3_call global output16_call global output16 -output16_3_call: ; limit to 999 +output16_3_call: ; limit to 999 bsf show_last3 - ; Limit to 3 - movlw .4 - cpfslt hi - bra output16_3_call_2 - movlw .3 - cpfseq hi ; =3? - bra output16_3_call_3 ; No, done. - movlw .231 ; Limit to 231(+768=999...) - cpfslt lo - movwf lo - bra output16_3_call_3 ; done. -output16_3_call_2: ; Set to .999 - movlw LOW .999 - movwf lo - movlw HIGH .999 - movwf hi + ; Limit to 3 + movlw .4 + cpfslt hi + bra output16_3_call_2 + movlw .3 + cpfseq hi ; =3? + bra output16_3_call_3 ; No, done. + movlw .231 ; Limit to 231(+768=999...) + cpfslt lo + movwf lo + bra output16_3_call_3 ; done. +output16_3_call_2: ; Set to .999 + movlw LOW .999 + movwf lo + movlw HIGH .999 + movwf hi output16_3_call_3: output16_call: clrf ignore_digits incf ignore_digits,F clrf WREG output16: - movwf temp4 ; Passed from output16dp macro, cleared by others. - - bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero - + movwf cvt_temp4 ; Passed from output16dp macro, cleared by others. + bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero bsf leading_zeros - tstfsz temp4 ; Display leading zeros at all? + tstfsz cvt_temp4 ; Display leading zeros at all? bcf leading_zeros - - bsf DP_done2 - tstfsz temp4 - bcf DP_done2 ; decimal point not yet set - - movff lo, lo_temp - movff hi, hi_temp - bcf pre_zero_flag ; do not display leading zeros - - movlw b'00010000' ; 10000s - movwf temp2 + bsf DP_done2 + tstfsz cvt_temp4 + bcf DP_done2 ; decimal point not yet set + movff lo, lo_temp + movff hi, hi_temp + bcf pre_zero_flag ; do not display leading zeros + movlw b'00010000' ; 10000s + movwf cvt_temp2 movlw b'00100111' - movwf temp3 - btfsc show_last3 ; display only last three figures? - bra output16_sk5 - btfsc show_last4 ; display only last four figures? - bra output16_sk5 - rcall DEC2ASCII ; No, show all. Here: 5th order digit + movwf cvt_temp3 + btfsc show_last3 ; display only last three figures? + bra output16_sk5 + btfsc show_last4 ; display only last four figures? + bra output16_sk5 + rcall DEC2ASCII ; No, show all. Here: 5th order digit output16_sk5: - bcf show_last4 - movlw b'11101000' ; 1000s - movwf temp2 + bcf show_last4 + movlw b'11101000' ; 1000s + movwf cvt_temp2 movlw b'00000011' - movwf temp3 - btfsc DP_done2 ; Is there a decimal point at all? - bra output16_2 ; no, use normal display mode + movwf cvt_temp3 + btfsc DP_done2 ; Is there a decimal point at all? + bra output16_2 ; no, use normal display mode - btfsc all_zeros_flag ; display any zero from here - bra output16_1 ; there was a figure /zero already + btfsc all_zeros_flag ; display any zero from here + bra output16_1 ; there was a figure /zero already - bsf pre_zero_flag ; display figure if zero? - decfsz temp4,W - bcf pre_zero_flag ; No + bsf pre_zero_flag ; display figure if zero? + decfsz cvt_temp4,W + bcf pre_zero_flag ; No output16_1: - btfsc DP_done ; Decimal point set already? - bsf pre_zero_flag ; Yes, so display the rest + btfsc DP_done ; Decimal point set already? + bsf pre_zero_flag ; Yes, so display the rest output16_2: - btfss show_last3 ; display only last three figures? - rcall DEC2ASCII ; No, show all. Here: 4th order digit - bcf show_last3 ; Yes, so display the rest - - movlw b'01100100' ; 100s - movwf temp2 - clrf temp3 - - btfsc ignore_digit3 ; Ignore 3rd-5th digit? - bra output16_5 ; Yes, skip the rest - - btfsc DP_done2 ; Is there a decimal point at all? - bra output16_3 ; no, use normal display mode - - btfsc all_zeros_flag ; display any zero from here - bra output16_2_1 ; there was a figure /zero already - - bsf pre_zero_flag ; display figure if zero? - decfsz temp4,W - bcf pre_zero_flag ; No + btfss show_last3 ; display only last three figures? + rcall DEC2ASCII ; No, show all. Here: 4th order digit + bcf show_last3 ; Yes, so display the rest + movlw b'01100100' ; 100s + movwf cvt_temp2 + clrf cvt_temp3 + btfsc ignore_digit3 ; Ignore 3rd-5th digit? + bra output16_5 ; Yes, skip the rest + btfsc DP_done2 ; Is there a decimal point at all? + bra output16_3 ; no, use normal display mode + btfsc all_zeros_flag ; display any zero from here + bra output16_2_1 ; there was a figure /zero already + bsf pre_zero_flag ; display figure if zero? + decfsz cvt_temp4,W + bcf pre_zero_flag ; No output16_2_1: - btfsc DP_done ; Decimal point set already? - bsf pre_zero_flag ; Yes, so display the rest - btfsc DP_done2 ; Is there a decimal point at all? - bsf pre_zero_flag ; No, so display the rest + btfsc DP_done ; Decimal point set already? + bsf pre_zero_flag ; Yes, so display the rest + btfsc DP_done2 ; Is there a decimal point at all? + bsf pre_zero_flag ; No, so display the rest output16_3: - rcall DEC2ASCII ;3th order digit... - - movlw b'00001010' ; 10s - movwf temp2 - clrf temp3 - btfsc DP_done2 - bra output16_4 - - btfsc all_zeros_flag ; display any zero from here - bra output16_3_1 ; there was a figure /zero already - + rcall DEC2ASCII ; 3th order digit... + movlw b'00001010' ; 10s + movwf cvt_temp2 + clrf cvt_temp3 + btfsc DP_done2 + bra output16_4 + btfsc all_zeros_flag ; display any zero from here + bra output16_3_1 ; there was a figure /zero already bsf pre_zero_flag - decfsz temp4,W + decfsz cvt_temp4,W bcf pre_zero_flag output16_3_1: - btfsc DP_done + btfsc DP_done + bsf pre_zero_flag + btfsc DP_done2 bsf pre_zero_flag - btfsc DP_done2 - bsf pre_zero_flag output16_4: - btfsc ignore_digit4 ; Ignore 4-5th digit? - bra output16_5 ; Yes, skip the rest - rcall DEC2ASCII ; 2nd order digit + btfsc ignore_digit4 ; Ignore 4-5th digit? + bra output16_5 ; Yes, skip the rest + rcall DEC2ASCII ; 2nd order digit - movlw b'00000001' ; 1s - movwf temp2 - clrf temp3 + movlw b'00000001' ; 1s + movwf cvt_temp2 + clrf cvt_temp3 bsf pre_zero_flag - btfss ignore_digit5 ; Ignore 5th digit? - rcall DEC2ASCII ; 1st order digit - bcf ignore_digit5 ; yes, and clear flag + btfss ignore_digit5 ; Ignore 5th digit? + rcall DEC2ASCII ; 1st order digit + bcf ignore_digit5 ; yes, and clear flag output16_5: - bcf ignore_digit4 ; Clear flag - bcf ignore_digit3 ; Clear flag + bcf ignore_digit4 ; Clear flag + bcf ignore_digit3 ; Clear flag clrf ignore_digits incf ignore_digits,F bcf DP_done - RETURN ; Done with convert.asm... - -DEC2ASCII clrf temp1 ; converts into ASCII code -DEC2ASCII_2 movf temp3,W + RETURN ; Done with convert.asm... + + +DEC2ASCII: + clrf cvt_temp1 ; converts into ASCII code +DEC2ASCII_2: + movf cvt_temp3,W subwf hi_temp,W - btfss STATUS,C - bra DEC2ASCII_4 - bnz DEC2ASCII_3 - - movf temp2,W + btfss STATUS,C + bra DEC2ASCII_4 + bnz DEC2ASCII_3 + movf cvt_temp2,W subwf lo_temp,W btfss STATUS,C bra DEC2ASCII_4 - -DEC2ASCII_3 movf temp3,W +DEC2ASCII_3: + movf cvt_temp3,W subwf hi_temp,F - movf temp2,W + movf cvt_temp2,W subwf lo_temp,F btfss STATUS,C decf hi_temp,F - incf temp1,F + incf cvt_temp1,F bsf pre_zero_flag bra DEC2ASCII_2 - -DEC2ASCII_4 +DEC2ASCII_4: decfsz ignore_digits,F return - incf ignore_digits,F ; so ignore_digits stays zero for the test above - movlw '0' ; Offset for Ascii-value - addwf temp1,W - btfsc pre_zero_flag ; is this a leading zero? - bra DEC2ASCII_4_1 ; no + incf ignore_digits,F ; so ignore_digits stays zero for the test above + movlw '0' ; Offset for ASCII-value + addwf cvt_temp1,W + btfsc pre_zero_flag ; is this a leading zero? + bra DEC2ASCII_4_1 ; no btfsc leftbind bra DEC2ASCII_6 - movlw ' ' ; instead of leading zeros a space! + movlw ' ' ; instead of leading zeros a space! bra DEC2ASCII_5 DEC2ASCII_4_1: - bsf all_zeros_flag ; display any zero from here -DEC2ASCII_5 + bsf all_zeros_flag ; display any zero from here +DEC2ASCII_5: movwf POSTINC2 -DEC2ASCII_6 - decfsz temp4,F ; Set decimal point? - RETURN ; No - movlw "." ; Yes +DEC2ASCII_6: + decfsz cvt_temp4,F ; Set decimal point? + RETURN ; No + movlw "." ; Yes movwf POSTINC2 bsf DP_done - RETURN - - END \ No newline at end of file + return + + END