Mercurial > public > hwos_code
comparison 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 |
comparison
equal
deleted
inserted
replaced
581:f5de1ff88814 | 582:b455b31ce022 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File convert.asm | 3 ; File convert.asm ## V2.98 |
4 ; | 4 ; |
5 ; Converts register values to string | 5 ; Converts register values to string |
6 ; | 6 ; |
7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
9 ; HISTORY | 9 ; HISTORY |
10 ; 2007-10-07 : [MH] Creation for OSTC sources | 10 ; 2007-10-07 : [MH] Creation for OSTC sources |
11 ; 2010-12-10 : [jDG] Optimize macro size | 11 ; 2010-12-10 : [jDG] Optimize macro size |
12 ; | 12 ; |
13 | 13 |
14 #include "hwos.inc" ; Mandatory header | 14 #include "hwos.inc" ; Mandatory header |
15 | |
16 basic CODE | |
15 | 17 |
16 ;============================================================================= | 18 ;============================================================================= |
17 | 19 |
18 CBLOCK tmp+0x09 ; space for aa_wordprocessor | 20 global output99_call |
19 temp3 | |
20 temp4 | |
21 cvt_flags2 | |
22 ; Reserved to tmp+0x11... | |
23 ENDC | |
24 | |
25 #define pre_zero_flag cvt_flags2,0 | |
26 #define all_zeros_flag cvt_flags2,1 | |
27 #define DP_done cvt_flags2,2 | |
28 #define DP_done2 cvt_flags2,3 | |
29 #define show_last3 cvt_flags2,4 | |
30 #define leading_zeros cvt_flags2,5 | |
31 #define show_last4 cvt_flags2,6 | |
32 | |
33 basic CODE | |
34 | |
35 ;============================================================================= | |
36 global output99_call | |
37 output99_call: | 21 output99_call: |
38 clrf ignore_digits | 22 clrf ignore_digits |
39 incf ignore_digits,F | 23 incf ignore_digits,F |
40 clrf temp4 | 24 clrf cvt_temp4 |
41 | 25 |
42 global output99 | 26 |
27 global output99 | |
43 output99: | 28 output99: |
44 movlw d'99' | 29 movlw d'99' |
45 cpfslt lo | 30 cpfslt lo |
46 movwf lo ; Limit to 99 | 31 movwf lo ; Limit to 99 |
47 movff lo,lo_temp | 32 movff lo,lo_temp |
48 clrf hi_temp | 33 clrf hi_temp |
49 bcf pre_zero_flag ; do not display leading zeros | 34 bcf pre_zero_flag ; do not display leading zeros |
50 | 35 |
51 LCD_val99_2: | 36 LCD_val99_2: |
52 movlw b'00001010' ; 10 | 37 movlw .10 ; 10 |
53 movwf temp2 | 38 movwf cvt_temp2 |
54 clrf temp3 | 39 clrf cvt_temp3 |
55 rcall DEC2ASCII | 40 rcall DEC2ASCII |
56 | 41 |
57 movlw b'00000001' ; 1 | 42 movlw .1 ; 1 |
58 movwf temp2 | 43 movwf cvt_temp2 |
59 clrf temp3 | 44 clrf cvt_temp3 |
60 bsf pre_zero_flag ; last figure, display zero (0) | 45 bsf pre_zero_flag ; last figure, display zero (0) |
61 rcall DEC2ASCII | 46 rcall DEC2ASCII |
62 RETURN | 47 return |
63 | 48 |
64 global output99x_call | 49 global output99x_call |
65 | |
66 output99x_call: | 50 output99x_call: |
67 clrf ignore_digits | 51 clrf ignore_digits |
68 incf ignore_digits,F | 52 incf ignore_digits,F |
69 clrf temp4 | 53 clrf cvt_temp4 |
70 | 54 |
71 movlw d'99' | 55 movlw d'99' |
72 cpfslt lo | 56 cpfslt lo |
73 movwf lo ; Limit to 99 | 57 movwf lo ; Limit to 99 |
74 movff lo, lo_temp | 58 movff lo, lo_temp |
75 clrf hi_temp | 59 clrf hi_temp |
76 bsf pre_zero_flag ; display leading zeros | 60 bsf pre_zero_flag ; display leading zeros |
77 bra LCD_val99_2 | 61 bra LCD_val99_2 |
78 | 62 |
63 | |
79 global output8_call | 64 global output8_call |
80 | 65 output8_call: |
81 output8_call: | 66 clrf ignore_digits |
82 clrf ignore_digits | 67 incf ignore_digits,F |
83 incf ignore_digits,F | 68 clrf cvt_temp4 |
84 clrf temp4 | |
85 | 69 |
86 output8: | 70 output8: |
87 movff lo, lo_temp | 71 movff lo, lo_temp |
88 clrf hi_temp | 72 clrf hi_temp |
89 bcf pre_zero_flag ; do not display leading zeros | 73 bcf pre_zero_flag ; do not display leading zeros |
90 | 74 movlw .100 ; 100 |
91 movlw b'01100100' ; 100 | 75 movwf cvt_temp2 |
92 movwf temp2 | 76 clrf cvt_temp3 |
93 clrf temp3 | |
94 rcall DEC2ASCII | 77 rcall DEC2ASCII |
95 bra LCD_val99_2 | 78 bra LCD_val99_2 |
79 | |
96 | 80 |
97 global output16_4_call | 81 global output16_4_call |
98 output16_4_call: ; limit to 9999 | 82 output16_4_call: ; limit to 9999 |
99 bsf show_last4 | 83 bsf show_last4 |
100 ; 9999 = 27 0F = [39][15] | 84 ; 9999 = 27 0F = [39][15] |
101 movlw .40 | 85 movlw .40 |
102 cpfslt hi ; hi < 40 ? | 86 cpfslt hi ; hi < 40 ? |
103 bra output16_4_call_2 ; No, hi >= 40, do limit | 87 bra output16_4_call_2 ; No, hi >= 40, do limit |
104 ; Yes, hi <= 39 | 88 ; Yes, hi <= 39 |
105 movlw .39 | 89 movlw .39 |
106 cpfseq hi ; hi = 39 ? | 90 cpfseq hi ; hi = 39 ? |
107 bra output16_4_call_3 ; No, hi < 39, no limit needed | 91 bra output16_4_call_3 ; No, hi < 39, no limit needed |
108 ; Yes, hi = 39 | 92 ; Yes, hi = 39 |
109 movlw .15 | 93 movlw .15 |
110 cpfslt lo ; lo < 15 | 94 cpfslt lo ; lo < 15 |
111 movwf lo ; No, lo >= 15, set lo = 15. | 95 movwf lo ; No, lo >= 15, set lo = 15. |
112 ; Yes, lo <= 14 or lo set to =15 | 96 ; Yes, lo <= 14 or lo set to =15 |
113 bra output16_4_call_3 ; done. | 97 bra output16_4_call_3 ; done. |
114 output16_4_call_2: ; Set to 9999 | 98 output16_4_call_2: ; Set to 9999 |
115 movlw LOW .9999 | 99 movlw LOW .9999 |
116 movwf lo | 100 movwf lo |
117 movlw HIGH .9999 | 101 movlw HIGH .9999 |
118 movwf hi | 102 movwf hi |
119 output16_4_call_3: | 103 output16_4_call_3: |
120 bra output16_call | 104 bra output16_call |
121 | 105 |
122 global output16_3_call | 106 global output16_3_call |
123 global output16_call | 107 global output16_call |
124 global output16 | 108 global output16 |
125 output16_3_call: ; limit to 999 | 109 output16_3_call: ; limit to 999 |
126 bsf show_last3 | 110 bsf show_last3 |
127 ; Limit to 3 | 111 ; Limit to 3 |
128 movlw .4 | 112 movlw .4 |
129 cpfslt hi | 113 cpfslt hi |
130 bra output16_3_call_2 | 114 bra output16_3_call_2 |
131 movlw .3 | 115 movlw .3 |
132 cpfseq hi ; =3? | 116 cpfseq hi ; =3? |
133 bra output16_3_call_3 ; No, done. | 117 bra output16_3_call_3 ; No, done. |
134 movlw .231 ; Limit to 231(+768=999...) | 118 movlw .231 ; Limit to 231(+768=999...) |
135 cpfslt lo | 119 cpfslt lo |
136 movwf lo | 120 movwf lo |
137 bra output16_3_call_3 ; done. | 121 bra output16_3_call_3 ; done. |
138 output16_3_call_2: ; Set to .999 | 122 output16_3_call_2: ; Set to .999 |
139 movlw LOW .999 | 123 movlw LOW .999 |
140 movwf lo | 124 movwf lo |
141 movlw HIGH .999 | 125 movlw HIGH .999 |
142 movwf hi | 126 movwf hi |
143 output16_3_call_3: | 127 output16_3_call_3: |
144 output16_call: | 128 output16_call: |
145 clrf ignore_digits | 129 clrf ignore_digits |
146 incf ignore_digits,F | 130 incf ignore_digits,F |
147 clrf WREG | 131 clrf WREG |
148 output16: | 132 output16: |
149 movwf temp4 ; Passed from output16dp macro, cleared by others. | 133 movwf cvt_temp4 ; Passed from output16dp macro, cleared by others. |
150 | 134 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero |
151 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero | |
152 | |
153 bsf leading_zeros | 135 bsf leading_zeros |
154 tstfsz temp4 ; Display leading zeros at all? | 136 tstfsz cvt_temp4 ; Display leading zeros at all? |
155 bcf leading_zeros | 137 bcf leading_zeros |
156 | 138 bsf DP_done2 |
157 bsf DP_done2 | 139 tstfsz cvt_temp4 |
158 tstfsz temp4 | 140 bcf DP_done2 ; decimal point not yet set |
159 bcf DP_done2 ; decimal point not yet set | 141 movff lo, lo_temp |
160 | 142 movff hi, hi_temp |
161 movff lo, lo_temp | 143 bcf pre_zero_flag ; do not display leading zeros |
162 movff hi, hi_temp | 144 movlw b'00010000' ; 10000s |
163 bcf pre_zero_flag ; do not display leading zeros | 145 movwf cvt_temp2 |
164 | |
165 movlw b'00010000' ; 10000s | |
166 movwf temp2 | |
167 movlw b'00100111' | 146 movlw b'00100111' |
168 movwf temp3 | 147 movwf cvt_temp3 |
169 btfsc show_last3 ; display only last three figures? | 148 btfsc show_last3 ; display only last three figures? |
170 bra output16_sk5 | 149 bra output16_sk5 |
171 btfsc show_last4 ; display only last four figures? | 150 btfsc show_last4 ; display only last four figures? |
172 bra output16_sk5 | 151 bra output16_sk5 |
173 rcall DEC2ASCII ; No, show all. Here: 5th order digit | 152 rcall DEC2ASCII ; No, show all. Here: 5th order digit |
174 | 153 |
175 output16_sk5: | 154 output16_sk5: |
176 bcf show_last4 | 155 bcf show_last4 |
177 movlw b'11101000' ; 1000s | 156 movlw b'11101000' ; 1000s |
178 movwf temp2 | 157 movwf cvt_temp2 |
179 movlw b'00000011' | 158 movlw b'00000011' |
180 movwf temp3 | 159 movwf cvt_temp3 |
181 btfsc DP_done2 ; Is there a decimal point at all? | 160 btfsc DP_done2 ; Is there a decimal point at all? |
182 bra output16_2 ; no, use normal display mode | 161 bra output16_2 ; no, use normal display mode |
183 | 162 |
184 btfsc all_zeros_flag ; display any zero from here | 163 btfsc all_zeros_flag ; display any zero from here |
185 bra output16_1 ; there was a figure /zero already | 164 bra output16_1 ; there was a figure /zero already |
186 | 165 |
187 bsf pre_zero_flag ; display figure if zero? | 166 bsf pre_zero_flag ; display figure if zero? |
188 decfsz temp4,W | 167 decfsz cvt_temp4,W |
189 bcf pre_zero_flag ; No | 168 bcf pre_zero_flag ; No |
190 | 169 |
191 output16_1: | 170 output16_1: |
192 btfsc DP_done ; Decimal point set already? | 171 btfsc DP_done ; Decimal point set already? |
193 bsf pre_zero_flag ; Yes, so display the rest | 172 bsf pre_zero_flag ; Yes, so display the rest |
194 output16_2: | 173 output16_2: |
195 btfss show_last3 ; display only last three figures? | 174 btfss show_last3 ; display only last three figures? |
196 rcall DEC2ASCII ; No, show all. Here: 4th order digit | 175 rcall DEC2ASCII ; No, show all. Here: 4th order digit |
197 bcf show_last3 ; Yes, so display the rest | 176 bcf show_last3 ; Yes, so display the rest |
198 | 177 movlw b'01100100' ; 100s |
199 movlw b'01100100' ; 100s | 178 movwf cvt_temp2 |
200 movwf temp2 | 179 clrf cvt_temp3 |
201 clrf temp3 | 180 btfsc ignore_digit3 ; Ignore 3rd-5th digit? |
202 | 181 bra output16_5 ; Yes, skip the rest |
203 btfsc ignore_digit3 ; Ignore 3rd-5th digit? | 182 btfsc DP_done2 ; Is there a decimal point at all? |
204 bra output16_5 ; Yes, skip the rest | 183 bra output16_3 ; no, use normal display mode |
205 | 184 btfsc all_zeros_flag ; display any zero from here |
206 btfsc DP_done2 ; Is there a decimal point at all? | 185 bra output16_2_1 ; there was a figure /zero already |
207 bra output16_3 ; no, use normal display mode | 186 bsf pre_zero_flag ; display figure if zero? |
208 | 187 decfsz cvt_temp4,W |
209 btfsc all_zeros_flag ; display any zero from here | 188 bcf pre_zero_flag ; No |
210 bra output16_2_1 ; there was a figure /zero already | |
211 | |
212 bsf pre_zero_flag ; display figure if zero? | |
213 decfsz temp4,W | |
214 bcf pre_zero_flag ; No | |
215 | 189 |
216 output16_2_1: | 190 output16_2_1: |
217 btfsc DP_done ; Decimal point set already? | 191 btfsc DP_done ; Decimal point set already? |
218 bsf pre_zero_flag ; Yes, so display the rest | 192 bsf pre_zero_flag ; Yes, so display the rest |
219 btfsc DP_done2 ; Is there a decimal point at all? | 193 btfsc DP_done2 ; Is there a decimal point at all? |
220 bsf pre_zero_flag ; No, so display the rest | 194 bsf pre_zero_flag ; No, so display the rest |
221 output16_3: | 195 output16_3: |
222 rcall DEC2ASCII ;3th order digit... | 196 rcall DEC2ASCII ; 3th order digit... |
223 | 197 movlw b'00001010' ; 10s |
224 movlw b'00001010' ; 10s | 198 movwf cvt_temp2 |
225 movwf temp2 | 199 clrf cvt_temp3 |
226 clrf temp3 | 200 btfsc DP_done2 |
227 btfsc DP_done2 | 201 bra output16_4 |
228 bra output16_4 | 202 btfsc all_zeros_flag ; display any zero from here |
229 | 203 bra output16_3_1 ; there was a figure /zero already |
230 btfsc all_zeros_flag ; display any zero from here | 204 bsf pre_zero_flag |
231 bra output16_3_1 ; there was a figure /zero already | 205 decfsz cvt_temp4,W |
232 | |
233 bsf pre_zero_flag | |
234 decfsz temp4,W | |
235 bcf pre_zero_flag | 206 bcf pre_zero_flag |
236 | 207 |
237 output16_3_1: | 208 output16_3_1: |
238 btfsc DP_done | 209 btfsc DP_done |
239 bsf pre_zero_flag | 210 bsf pre_zero_flag |
240 btfsc DP_done2 | 211 btfsc DP_done2 |
241 bsf pre_zero_flag | 212 bsf pre_zero_flag |
242 output16_4: | 213 output16_4: |
243 btfsc ignore_digit4 ; Ignore 4-5th digit? | 214 btfsc ignore_digit4 ; Ignore 4-5th digit? |
244 bra output16_5 ; Yes, skip the rest | 215 bra output16_5 ; Yes, skip the rest |
245 rcall DEC2ASCII ; 2nd order digit | 216 rcall DEC2ASCII ; 2nd order digit |
246 | 217 |
247 movlw b'00000001' ; 1s | 218 movlw b'00000001' ; 1s |
248 movwf temp2 | 219 movwf cvt_temp2 |
249 clrf temp3 | 220 clrf cvt_temp3 |
250 bsf pre_zero_flag | 221 bsf pre_zero_flag |
251 btfss ignore_digit5 ; Ignore 5th digit? | 222 btfss ignore_digit5 ; Ignore 5th digit? |
252 rcall DEC2ASCII ; 1st order digit | 223 rcall DEC2ASCII ; 1st order digit |
253 bcf ignore_digit5 ; yes, and clear flag | 224 bcf ignore_digit5 ; yes, and clear flag |
254 output16_5: | 225 output16_5: |
255 bcf ignore_digit4 ; Clear flag | 226 bcf ignore_digit4 ; Clear flag |
256 bcf ignore_digit3 ; Clear flag | 227 bcf ignore_digit3 ; Clear flag |
257 clrf ignore_digits | 228 clrf ignore_digits |
258 incf ignore_digits,F | 229 incf ignore_digits,F |
259 bcf DP_done | 230 bcf DP_done |
260 RETURN ; Done with convert.asm... | 231 RETURN ; Done with convert.asm... |
261 | 232 |
262 DEC2ASCII clrf temp1 ; converts into ASCII code | 233 |
263 DEC2ASCII_2 movf temp3,W | 234 DEC2ASCII: |
235 clrf cvt_temp1 ; converts into ASCII code | |
236 DEC2ASCII_2: | |
237 movf cvt_temp3,W | |
264 subwf hi_temp,W | 238 subwf hi_temp,W |
265 btfss STATUS,C | 239 btfss STATUS,C |
266 bra DEC2ASCII_4 | 240 bra DEC2ASCII_4 |
267 bnz DEC2ASCII_3 | 241 bnz DEC2ASCII_3 |
268 | 242 movf cvt_temp2,W |
269 movf temp2,W | |
270 subwf lo_temp,W | 243 subwf lo_temp,W |
271 btfss STATUS,C | 244 btfss STATUS,C |
272 bra DEC2ASCII_4 | 245 bra DEC2ASCII_4 |
273 | 246 DEC2ASCII_3: |
274 DEC2ASCII_3 movf temp3,W | 247 movf cvt_temp3,W |
275 subwf hi_temp,F | 248 subwf hi_temp,F |
276 movf temp2,W | 249 movf cvt_temp2,W |
277 subwf lo_temp,F | 250 subwf lo_temp,F |
278 btfss STATUS,C | 251 btfss STATUS,C |
279 decf hi_temp,F | 252 decf hi_temp,F |
280 incf temp1,F | 253 incf cvt_temp1,F |
281 bsf pre_zero_flag | 254 bsf pre_zero_flag |
282 bra DEC2ASCII_2 | 255 bra DEC2ASCII_2 |
283 | 256 DEC2ASCII_4: |
284 DEC2ASCII_4 | |
285 decfsz ignore_digits,F | 257 decfsz ignore_digits,F |
286 return | 258 return |
287 incf ignore_digits,F ; so ignore_digits stays zero for the test above | 259 incf ignore_digits,F ; so ignore_digits stays zero for the test above |
288 movlw '0' ; Offset for Ascii-value | 260 movlw '0' ; Offset for ASCII-value |
289 addwf temp1,W | 261 addwf cvt_temp1,W |
290 btfsc pre_zero_flag ; is this a leading zero? | 262 btfsc pre_zero_flag ; is this a leading zero? |
291 bra DEC2ASCII_4_1 ; no | 263 bra DEC2ASCII_4_1 ; no |
292 btfsc leftbind | 264 btfsc leftbind |
293 bra DEC2ASCII_6 | 265 bra DEC2ASCII_6 |
294 movlw ' ' ; instead of leading zeros a space! | 266 movlw ' ' ; instead of leading zeros a space! |
295 bra DEC2ASCII_5 | 267 bra DEC2ASCII_5 |
296 DEC2ASCII_4_1: | 268 DEC2ASCII_4_1: |
297 bsf all_zeros_flag ; display any zero from here | 269 bsf all_zeros_flag ; display any zero from here |
298 DEC2ASCII_5 | 270 DEC2ASCII_5: |
299 movwf POSTINC2 | 271 movwf POSTINC2 |
300 DEC2ASCII_6 | 272 DEC2ASCII_6: |
301 decfsz temp4,F ; Set decimal point? | 273 decfsz cvt_temp4,F ; Set decimal point? |
302 RETURN ; No | 274 RETURN ; No |
303 movlw "." ; Yes | 275 movlw "." ; Yes |
304 movwf POSTINC2 | 276 movwf POSTINC2 |
305 bsf DP_done | 277 bsf DP_done |
306 RETURN | 278 return |
307 | 279 |
308 END | 280 END |