annotate src/convert.asm @ 235:23311219dacc

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