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