annotate src/convert.asm @ 212:5fd93901b735

Merge
author heinrichsweikamp
date Wed, 10 Dec 2014 09:13:49 +0100
parents 11d4fc797f74
children 31088352ee32
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
heinrichsweikamp
parents:
diff changeset
99 output16_3_call:
heinrichsweikamp
parents:
diff changeset
100 bsf show_last3
heinrichsweikamp
parents:
diff changeset
101 output16_call:
heinrichsweikamp
parents:
diff changeset
102 clrf ignore_digits
heinrichsweikamp
parents:
diff changeset
103 incf ignore_digits,F
heinrichsweikamp
parents:
diff changeset
104 clrf WREG
heinrichsweikamp
parents:
diff changeset
105 output16:
heinrichsweikamp
parents:
diff changeset
106 movwf temp4 ; Passed from output16dp macro, cleared by others.
heinrichsweikamp
parents:
diff changeset
107
heinrichsweikamp
parents:
diff changeset
108 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero
heinrichsweikamp
parents:
diff changeset
109
heinrichsweikamp
parents:
diff changeset
110 bsf leading_zeros
heinrichsweikamp
parents:
diff changeset
111 tstfsz temp4 ; Display leading zeros at all?
heinrichsweikamp
parents:
diff changeset
112 bcf leading_zeros
heinrichsweikamp
parents:
diff changeset
113
heinrichsweikamp
parents:
diff changeset
114 bsf DP_done2
heinrichsweikamp
parents:
diff changeset
115 tstfsz temp4
heinrichsweikamp
parents:
diff changeset
116 bcf DP_done2 ; decimal point not yet set
heinrichsweikamp
parents:
diff changeset
117
heinrichsweikamp
parents:
diff changeset
118 movff lo, lo_temp
heinrichsweikamp
parents:
diff changeset
119 movff hi, hi_temp
heinrichsweikamp
parents:
diff changeset
120 bcf pre_zero_flag ; do not display leading zeros
heinrichsweikamp
parents:
diff changeset
121
heinrichsweikamp
parents:
diff changeset
122 movlw b'00010000' ; 10000s
heinrichsweikamp
parents:
diff changeset
123 movwf temp2
heinrichsweikamp
parents:
diff changeset
124 movlw b'00100111'
heinrichsweikamp
parents:
diff changeset
125 movwf temp3
heinrichsweikamp
parents:
diff changeset
126 btfss show_last3 ; display only last three figures?
heinrichsweikamp
parents:
diff changeset
127 rcall DEC2ASCII ; No, show all. Here: 5th order digit
heinrichsweikamp
parents:
diff changeset
128
heinrichsweikamp
parents:
diff changeset
129 movlw b'11101000' ; 1000s
heinrichsweikamp
parents:
diff changeset
130 movwf temp2
heinrichsweikamp
parents:
diff changeset
131 movlw b'00000011'
heinrichsweikamp
parents:
diff changeset
132 movwf temp3
heinrichsweikamp
parents:
diff changeset
133 btfsc DP_done2 ; Is there a decimal point at all?
heinrichsweikamp
parents:
diff changeset
134 bra output16_2 ; no, use normal display mode
heinrichsweikamp
parents:
diff changeset
135
heinrichsweikamp
parents:
diff changeset
136 btfsc all_zeros_flag ; display any zero from here
heinrichsweikamp
parents:
diff changeset
137 bra output16_1 ; there was a figure /zero already
heinrichsweikamp
parents:
diff changeset
138
heinrichsweikamp
parents:
diff changeset
139 bsf pre_zero_flag ; display figure if zero?
heinrichsweikamp
parents:
diff changeset
140 decfsz temp4,W
heinrichsweikamp
parents:
diff changeset
141 bcf pre_zero_flag ; No
heinrichsweikamp
parents:
diff changeset
142
heinrichsweikamp
parents:
diff changeset
143 output16_1:
heinrichsweikamp
parents:
diff changeset
144 btfsc DP_done ; Decimal point set already?
heinrichsweikamp
parents:
diff changeset
145 bsf pre_zero_flag ; Yes, so display the rest
heinrichsweikamp
parents:
diff changeset
146 output16_2:
heinrichsweikamp
parents:
diff changeset
147 btfss show_last3 ; display only last three figures?
heinrichsweikamp
parents:
diff changeset
148 rcall DEC2ASCII ; No, show all. Here: 4th order digit
heinrichsweikamp
parents:
diff changeset
149 bcf show_last3 ; Yes, so display the rest
heinrichsweikamp
parents:
diff changeset
150
heinrichsweikamp
parents:
diff changeset
151 movlw b'01100100' ; 100s
heinrichsweikamp
parents:
diff changeset
152 movwf temp2
heinrichsweikamp
parents:
diff changeset
153 clrf temp3
heinrichsweikamp
parents:
diff changeset
154
heinrichsweikamp
parents:
diff changeset
155 btfsc ignore_digit3 ; Ignore 3rd-5th digit?
heinrichsweikamp
parents:
diff changeset
156 bra output16_5 ; Yes, skip the rest
heinrichsweikamp
parents:
diff changeset
157
heinrichsweikamp
parents:
diff changeset
158 btfsc DP_done2 ; Is there a decimal point at all?
heinrichsweikamp
parents:
diff changeset
159 bra output16_3 ; no, use normal display mode
heinrichsweikamp
parents:
diff changeset
160
heinrichsweikamp
parents:
diff changeset
161 btfsc all_zeros_flag ; display any zero from here
heinrichsweikamp
parents:
diff changeset
162 bra output16_2_1 ; there was a figure /zero already
heinrichsweikamp
parents:
diff changeset
163
heinrichsweikamp
parents:
diff changeset
164 bsf pre_zero_flag ; display figure if zero?
heinrichsweikamp
parents:
diff changeset
165 decfsz temp4,W
heinrichsweikamp
parents:
diff changeset
166 bcf pre_zero_flag ; No
heinrichsweikamp
parents:
diff changeset
167
heinrichsweikamp
parents:
diff changeset
168 output16_2_1:
heinrichsweikamp
parents:
diff changeset
169 btfsc DP_done ; Decimal point set already?
heinrichsweikamp
parents:
diff changeset
170 bsf pre_zero_flag ; Yes, so display the rest
heinrichsweikamp
parents:
diff changeset
171 btfsc DP_done2 ; Is there a decimal point at all?
heinrichsweikamp
parents:
diff changeset
172 bsf pre_zero_flag ; No, so display the rest
heinrichsweikamp
parents:
diff changeset
173 output16_3:
heinrichsweikamp
parents:
diff changeset
174 rcall DEC2ASCII ;3th order digit...
heinrichsweikamp
parents:
diff changeset
175
heinrichsweikamp
parents:
diff changeset
176 movlw b'00001010' ; 10s
heinrichsweikamp
parents:
diff changeset
177 movwf temp2
heinrichsweikamp
parents:
diff changeset
178 clrf temp3
heinrichsweikamp
parents:
diff changeset
179 btfsc DP_done2
heinrichsweikamp
parents:
diff changeset
180 bra output16_4
heinrichsweikamp
parents:
diff changeset
181
heinrichsweikamp
parents:
diff changeset
182 btfsc all_zeros_flag ; display any zero from here
heinrichsweikamp
parents:
diff changeset
183 bra output16_3_1 ; there was a figure /zero already
heinrichsweikamp
parents:
diff changeset
184
heinrichsweikamp
parents:
diff changeset
185 bsf pre_zero_flag
heinrichsweikamp
parents:
diff changeset
186 decfsz temp4,W
heinrichsweikamp
parents:
diff changeset
187 bcf pre_zero_flag
heinrichsweikamp
parents:
diff changeset
188
heinrichsweikamp
parents:
diff changeset
189 output16_3_1:
heinrichsweikamp
parents:
diff changeset
190 btfsc DP_done
heinrichsweikamp
parents:
diff changeset
191 bsf pre_zero_flag
heinrichsweikamp
parents:
diff changeset
192 btfsc DP_done2
heinrichsweikamp
parents:
diff changeset
193 bsf pre_zero_flag
heinrichsweikamp
parents:
diff changeset
194 output16_4:
heinrichsweikamp
parents:
diff changeset
195 btfsc ignore_digit4 ; Ignore 4-5th digit?
heinrichsweikamp
parents:
diff changeset
196 bra output16_5 ; Yes, skip the rest
heinrichsweikamp
parents:
diff changeset
197 rcall DEC2ASCII ; 2nd order digit
heinrichsweikamp
parents:
diff changeset
198
heinrichsweikamp
parents:
diff changeset
199 movlw b'00000001' ; 1s
heinrichsweikamp
parents:
diff changeset
200 movwf temp2
heinrichsweikamp
parents:
diff changeset
201 clrf temp3
heinrichsweikamp
parents:
diff changeset
202 bsf pre_zero_flag
heinrichsweikamp
parents:
diff changeset
203 btfss ignore_digit5 ; Ignore 5th digit?
heinrichsweikamp
parents:
diff changeset
204 rcall DEC2ASCII ; 1st order digit
heinrichsweikamp
parents:
diff changeset
205 bcf ignore_digit5 ; yes, and clear flag
heinrichsweikamp
parents:
diff changeset
206 output16_5:
heinrichsweikamp
parents:
diff changeset
207 bcf ignore_digit4 ; Clear flag
heinrichsweikamp
parents:
diff changeset
208 bcf ignore_digit3 ; Clear flag
heinrichsweikamp
parents:
diff changeset
209 clrf ignore_digits
heinrichsweikamp
parents:
diff changeset
210 incf ignore_digits,F
heinrichsweikamp
parents:
diff changeset
211 bcf DP_done
heinrichsweikamp
parents:
diff changeset
212 RETURN ; Done with convert.asm...
heinrichsweikamp
parents:
diff changeset
213
heinrichsweikamp
parents:
diff changeset
214 DEC2ASCII clrf temp1 ; converts into ASCII code
heinrichsweikamp
parents:
diff changeset
215 DEC2ASCII_2 movf temp3,W
heinrichsweikamp
parents:
diff changeset
216 subwf hi_temp,W
heinrichsweikamp
parents:
diff changeset
217 btfss STATUS,C
heinrichsweikamp
parents:
diff changeset
218 bra DEC2ASCII_4
heinrichsweikamp
parents:
diff changeset
219 bnz DEC2ASCII_3
heinrichsweikamp
parents:
diff changeset
220
heinrichsweikamp
parents:
diff changeset
221 movf temp2,W
heinrichsweikamp
parents:
diff changeset
222 subwf lo_temp,W
heinrichsweikamp
parents:
diff changeset
223 btfss STATUS,C
heinrichsweikamp
parents:
diff changeset
224 bra DEC2ASCII_4
heinrichsweikamp
parents:
diff changeset
225
heinrichsweikamp
parents:
diff changeset
226 DEC2ASCII_3 movf temp3,W
heinrichsweikamp
parents:
diff changeset
227 subwf hi_temp,F
heinrichsweikamp
parents:
diff changeset
228 movf temp2,W
heinrichsweikamp
parents:
diff changeset
229 subwf lo_temp,F
heinrichsweikamp
parents:
diff changeset
230 btfss STATUS,C
heinrichsweikamp
parents:
diff changeset
231 decf hi_temp,F
heinrichsweikamp
parents:
diff changeset
232 incf temp1,F
heinrichsweikamp
parents:
diff changeset
233 bsf pre_zero_flag
heinrichsweikamp
parents:
diff changeset
234 bra DEC2ASCII_2
heinrichsweikamp
parents:
diff changeset
235
heinrichsweikamp
parents:
diff changeset
236 DEC2ASCII_4
heinrichsweikamp
parents:
diff changeset
237 decfsz ignore_digits,F
heinrichsweikamp
parents:
diff changeset
238 return
heinrichsweikamp
parents:
diff changeset
239 incf ignore_digits,F ; so ignore_digits stays zero for the test above
heinrichsweikamp
parents:
diff changeset
240 movlw '0' ; Offset for Ascii-value
heinrichsweikamp
parents:
diff changeset
241 addwf temp1,W
heinrichsweikamp
parents:
diff changeset
242 btfsc pre_zero_flag ; is this a leading zero?
heinrichsweikamp
parents:
diff changeset
243 bra DEC2ASCII_4_1 ; no
heinrichsweikamp
parents:
diff changeset
244 btfsc leftbind
heinrichsweikamp
parents:
diff changeset
245 bra DEC2ASCII_6
heinrichsweikamp
parents:
diff changeset
246 movlw ' ' ; instead of leading zeros a space!
heinrichsweikamp
parents:
diff changeset
247 bra DEC2ASCII_5
heinrichsweikamp
parents:
diff changeset
248 DEC2ASCII_4_1:
heinrichsweikamp
parents:
diff changeset
249 bsf all_zeros_flag ; display any zero from here
heinrichsweikamp
parents:
diff changeset
250 DEC2ASCII_5
heinrichsweikamp
parents:
diff changeset
251 movwf POSTINC2
heinrichsweikamp
parents:
diff changeset
252 DEC2ASCII_6
heinrichsweikamp
parents:
diff changeset
253 decfsz temp4,F ; Set decimal point?
heinrichsweikamp
parents:
diff changeset
254 RETURN ; No
heinrichsweikamp
parents:
diff changeset
255 movlw "." ; Yes
heinrichsweikamp
parents:
diff changeset
256 movwf POSTINC2
heinrichsweikamp
parents:
diff changeset
257 bsf DP_done
heinrichsweikamp
parents:
diff changeset
258 RETURN
heinrichsweikamp
parents:
diff changeset
259
heinrichsweikamp
parents:
diff changeset
260 END