Mercurial > public > hwos_code
annotate src/convert.asm @ 620:cd986267a5ca
potential compass bug "fixed"
author | heinrichsweikamp |
---|---|
date | Fri, 22 Feb 2019 16:30:05 +0100 |
parents | ca4556fb60b9 |
children | c40025d8e750 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File convert.asm ## V2.98c |
0 | 4 ; |
5 ; Converts register values to string | |
6 ; | |
7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2007-10-07 : [MH] Creation for OSTC sources | |
11 ; 2010-12-10 : [jDG] Optimize macro size | |
12 ; | |
13 | |
582 | 14 #include "hwos.inc" ; Mandatory header |
15 | |
604 | 16 convert CODE |
0 | 17 |
18 ;============================================================================= | |
19 | |
582 | 20 global output99_call |
0 | 21 output99_call: |
22 clrf ignore_digits | |
23 incf ignore_digits,F | |
582 | 24 clrf cvt_temp4 |
0 | 25 |
582 | 26 |
27 global output99 | |
0 | 28 output99: |
29 movlw d'99' | |
30 cpfslt lo | |
604 | 31 movwf lo ; limit to 99 |
582 | 32 movff lo,lo_temp |
0 | 33 clrf hi_temp |
582 | 34 bcf pre_zero_flag ; do not display leading zeros |
0 | 35 |
582 | 36 LCD_val99_2: |
37 movlw .10 ; 10 | |
38 movwf cvt_temp2 | |
39 clrf cvt_temp3 | |
0 | 40 rcall DEC2ASCII |
41 | |
582 | 42 movlw .1 ; 1 |
43 movwf cvt_temp2 | |
44 clrf cvt_temp3 | |
45 bsf pre_zero_flag ; last figure, display zero (0) | |
0 | 46 rcall DEC2ASCII |
582 | 47 return |
0 | 48 |
49 global output99x_call | |
50 output99x_call: | |
51 clrf ignore_digits | |
52 incf ignore_digits,F | |
582 | 53 clrf cvt_temp4 |
0 | 54 |
55 movlw d'99' | |
56 cpfslt lo | |
604 | 57 movwf lo ; limit to 99 |
582 | 58 movff lo, lo_temp |
0 | 59 clrf hi_temp |
582 | 60 bsf pre_zero_flag ; display leading zeros |
61 bra LCD_val99_2 | |
62 | |
63 | |
0 | 64 global output8_call |
582 | 65 output8_call: |
66 clrf ignore_digits | |
0 | 67 incf ignore_digits,F |
582 | 68 clrf cvt_temp4 |
0 | 69 |
70 output8: | |
582 | 71 movff lo, lo_temp |
0 | 72 clrf hi_temp |
582 | 73 bcf pre_zero_flag ; do not display leading zeros |
74 movlw .100 ; 100 | |
75 movwf cvt_temp2 | |
76 clrf cvt_temp3 | |
0 | 77 rcall DEC2ASCII |
582 | 78 bra LCD_val99_2 |
79 | |
0 | 80 |
300
5ad479f2a868
Merged Screen layout mod #1 into Screen layout work #3
Janos Kovacs <kovjanos@gmail.com>
parents:
275
diff
changeset
|
81 global output16_4_call |
582 | 82 output16_4_call: ; limit to 9999 |
300
5ad479f2a868
Merged Screen layout mod #1 into Screen layout work #3
Janos Kovacs <kovjanos@gmail.com>
parents:
275
diff
changeset
|
83 bsf show_last4 |
582 | 84 ; 9999 = 27 0F = [39][15] |
85 movlw .40 | |
86 cpfslt hi ; hi < 40 ? | |
604 | 87 bra output16_4_call_2 ; NO - hi >= 40, do limit |
582 | 88 ; Yes, hi <= 39 |
89 movlw .39 | |
90 cpfseq hi ; hi = 39 ? | |
604 | 91 bra output16_4_call_3 ; NO - hi < 39, no limit needed |
582 | 92 ; Yes, hi = 39 |
93 movlw .15 | |
94 cpfslt lo ; lo < 15 | |
604 | 95 movwf lo ; NO - lo >= 15, set lo = 15. |
582 | 96 ; Yes, lo <= 14 or lo set to =15 |
604 | 97 bra output16_4_call_3 ; done |
98 output16_4_call_2: ; set to 9999 | |
582 | 99 movlw LOW .9999 |
100 movwf lo | |
101 movlw HIGH .9999 | |
102 movwf hi | |
300
5ad479f2a868
Merged Screen layout mod #1 into Screen layout work #3
Janos Kovacs <kovjanos@gmail.com>
parents:
275
diff
changeset
|
103 output16_4_call_3: |
582 | 104 bra output16_call |
300
5ad479f2a868
Merged Screen layout mod #1 into Screen layout work #3
Janos Kovacs <kovjanos@gmail.com>
parents:
275
diff
changeset
|
105 |
0 | 106 global output16_3_call |
107 global output16_call | |
108 global output16 | |
582 | 109 output16_3_call: ; limit to 999 |
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
0
diff
changeset
|
110 bsf show_last3 |
582 | 111 ; Limit to 3 |
112 movlw .4 | |
113 cpfslt hi | |
114 bra output16_3_call_2 | |
115 movlw .3 | |
604 | 116 cpfseq hi ; = 3 ? |
117 bra output16_3_call_3 ; NO - done | |
118 movlw .231 ; limit to 231(+768=999...) | |
582 | 119 cpfslt lo |
120 movwf lo | |
604 | 121 bra output16_3_call_3 ; done |
122 output16_3_call_2: ; set to .999 | |
582 | 123 movlw LOW .999 |
124 movwf lo | |
125 movlw HIGH .999 | |
126 movwf hi | |
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
0
diff
changeset
|
127 output16_3_call_3: |
0 | 128 output16_call: |
129 clrf ignore_digits | |
130 incf ignore_digits,F | |
131 clrf WREG | |
132 output16: | |
604 | 133 movwf cvt_temp4 ; passed from output16dp macro, cleared by others. |
582 | 134 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero |
0 | 135 bsf leading_zeros |
604 | 136 tstfsz cvt_temp4 ; display leading zeros at all? |
0 | 137 bcf leading_zeros |
582 | 138 bsf DP_done2 |
139 tstfsz cvt_temp4 | |
140 bcf DP_done2 ; decimal point not yet set | |
141 movff lo, lo_temp | |
142 movff hi, hi_temp | |
143 bcf pre_zero_flag ; do not display leading zeros | |
144 movlw b'00010000' ; 10000s | |
145 movwf cvt_temp2 | |
0 | 146 movlw b'00100111' |
582 | 147 movwf cvt_temp3 |
148 btfsc show_last3 ; display only last three figures? | |
149 bra output16_sk5 | |
150 btfsc show_last4 ; display only last four figures? | |
151 bra output16_sk5 | |
604 | 152 rcall DEC2ASCII ; NO - show all, here: 5th order digit |
300
5ad479f2a868
Merged Screen layout mod #1 into Screen layout work #3
Janos Kovacs <kovjanos@gmail.com>
parents:
275
diff
changeset
|
153 |
5ad479f2a868
Merged Screen layout mod #1 into Screen layout work #3
Janos Kovacs <kovjanos@gmail.com>
parents:
275
diff
changeset
|
154 output16_sk5: |
582 | 155 bcf show_last4 |
156 movlw b'11101000' ; 1000s | |
157 movwf cvt_temp2 | |
0 | 158 movlw b'00000011' |
582 | 159 movwf cvt_temp3 |
604 | 160 btfsc DP_done2 ; is there a decimal point at all? |
161 bra output16_2 ; NO - use normal display mode | |
0 | 162 |
582 | 163 btfsc all_zeros_flag ; display any zero from here |
164 bra output16_1 ; there was a figure /zero already | |
0 | 165 |
582 | 166 bsf pre_zero_flag ; display figure if zero? |
167 decfsz cvt_temp4,W | |
604 | 168 bcf pre_zero_flag ; NO |
0 | 169 |
170 output16_1: | |
604 | 171 btfsc DP_done ; decimal point set already? |
172 bsf pre_zero_flag ; YES - so display the rest | |
0 | 173 output16_2: |
582 | 174 btfss show_last3 ; display only last three figures? |
604 | 175 rcall DEC2ASCII ; NO - show all. Here: 4th order digit |
176 bcf show_last3 ; YES - so display the rest | |
582 | 177 movlw b'01100100' ; 100s |
178 movwf cvt_temp2 | |
179 clrf cvt_temp3 | |
604 | 180 btfsc ignore_digit3 ; ignore 3rd-5th digit? |
181 bra output16_5 ; YES - skip the rest | |
182 btfsc DP_done2 ; is there a decimal point at all? | |
183 bra output16_3 ; NO - use normal display mode | |
582 | 184 btfsc all_zeros_flag ; display any zero from here |
185 bra output16_2_1 ; there was a figure /zero already | |
186 bsf pre_zero_flag ; display figure if zero? | |
187 decfsz cvt_temp4,W | |
604 | 188 bcf pre_zero_flag ; NO |
0 | 189 |
190 output16_2_1: | |
604 | 191 btfsc DP_done ; decimal point set already? |
192 bsf pre_zero_flag ; YES - so display the rest | |
193 btfsc DP_done2 ; is there a decimal point at all? | |
194 bsf pre_zero_flag ; NO - so display the rest | |
0 | 195 output16_3: |
582 | 196 rcall DEC2ASCII ; 3th order digit... |
197 movlw b'00001010' ; 10s | |
198 movwf cvt_temp2 | |
199 clrf cvt_temp3 | |
200 btfsc DP_done2 | |
201 bra output16_4 | |
202 btfsc all_zeros_flag ; display any zero from here | |
203 bra output16_3_1 ; there was a figure /zero already | |
0 | 204 bsf pre_zero_flag |
582 | 205 decfsz cvt_temp4,W |
0 | 206 bcf pre_zero_flag |
207 | |
208 output16_3_1: | |
582 | 209 btfsc DP_done |
210 bsf pre_zero_flag | |
211 btfsc DP_done2 | |
0 | 212 bsf pre_zero_flag |
213 output16_4: | |
604 | 214 btfsc ignore_digit4 ; ignore 4-5th digit? |
215 bra output16_5 ; YES - skip the rest | |
582 | 216 rcall DEC2ASCII ; 2nd order digit |
0 | 217 |
582 | 218 movlw b'00000001' ; 1s |
219 movwf cvt_temp2 | |
220 clrf cvt_temp3 | |
0 | 221 bsf pre_zero_flag |
604 | 222 btfss ignore_digit5 ; ignore 5th digit? |
582 | 223 rcall DEC2ASCII ; 1st order digit |
604 | 224 bcf ignore_digit5 ; YES - clear flag |
0 | 225 output16_5: |
604 | 226 bcf ignore_digit4 ; clear flag |
227 bcf ignore_digit3 ; clear flag | |
0 | 228 clrf ignore_digits |
229 incf ignore_digits,F | |
230 bcf DP_done | |
604 | 231 return ; done with convert.asm... |
582 | 232 |
233 | |
234 DEC2ASCII: | |
604 | 235 clrf cvt_temp1 ; converts into ASCII code |
582 | 236 DEC2ASCII_2: |
237 movf cvt_temp3,W | |
0 | 238 subwf hi_temp,W |
582 | 239 btfss STATUS,C |
240 bra DEC2ASCII_4 | |
241 bnz DEC2ASCII_3 | |
242 movf cvt_temp2,W | |
0 | 243 subwf lo_temp,W |
244 btfss STATUS,C | |
245 bra DEC2ASCII_4 | |
582 | 246 DEC2ASCII_3: |
247 movf cvt_temp3,W | |
0 | 248 subwf hi_temp,F |
582 | 249 movf cvt_temp2,W |
0 | 250 subwf lo_temp,F |
251 btfss STATUS,C | |
252 decf hi_temp,F | |
582 | 253 incf cvt_temp1,F |
0 | 254 bsf pre_zero_flag |
255 bra DEC2ASCII_2 | |
582 | 256 DEC2ASCII_4: |
0 | 257 decfsz ignore_digits,F |
258 return | |
582 | 259 incf ignore_digits,F ; so ignore_digits stays zero for the test above |
604 | 260 movlw '0' ; offset for ASCII-value |
582 | 261 addwf cvt_temp1,W |
262 btfsc pre_zero_flag ; is this a leading zero? | |
604 | 263 bra DEC2ASCII_4_1 ; NO |
0 | 264 btfsc leftbind |
265 bra DEC2ASCII_6 | |
582 | 266 movlw ' ' ; instead of leading zeros a space! |
0 | 267 bra DEC2ASCII_5 |
268 DEC2ASCII_4_1: | |
582 | 269 bsf all_zeros_flag ; display any zero from here |
270 DEC2ASCII_5: | |
0 | 271 movwf POSTINC2 |
582 | 272 DEC2ASCII_6: |
604 | 273 decfsz cvt_temp4,F ; set decimal point? |
274 RETURN ; NO | |
275 movlw "." ; YES | |
0 | 276 movwf POSTINC2 |
277 bsf DP_done | |
582 | 278 return |
279 | |
604 | 280 |
281 global outputHEX_call | |
282 outputHEX_call: ; coverts 8 Bit integer into two hex digits | |
283 movwf cvt_temp1 ; copy byte to process from WREG to local temp | |
284 swapf cvt_temp1,F ; swap nibbles to process upper nibble first | |
285 rcall outputHEX_nibble ; print nibble as ASCII | |
286 swapf cvt_temp1,F ; swap back to process lower nibble | |
287 outputHEX_nibble: | |
288 movff cvt_temp1,cvt_temp2 ; create a working copy | |
289 movlw 0x0F ; mask for lower nibble | |
290 andwf cvt_temp2,F ; isolate lower nibble | |
291 movlw 0x30 ; offset from binary 0 to ASCII code for "0" | |
292 addwf cvt_temp2,F ; add offset | |
293 movlw 0x39 ; ASCII code for "9" | |
294 cpfsgt cvt_temp2 ; character code in cvt_temp2 pointing to something after "9"? | |
295 bra outputHEX_1 ; NO - character code represents "0"..."9", can be printed | |
296 movlw 0x07 ; YES - offset from ASCII code for character after "9" to character "A" | |
297 addwf cvt_temp2,F ; - add offset, character code now represents "A"..."F", can be printed now | |
298 outputHEX_1: | |
299 movff cvt_temp2,POSTINC2 ; copy character code to output buffer | |
300 return | |
301 | |
302 | |
582 | 303 END |