Mercurial > public > hwos_code
annotate src/convert.asm @ 655:c7b7b8a358cd default tip
hwOS tech 3.22 release
author | heinrichsweikamp |
---|---|
date | Mon, 29 Apr 2024 13:05:18 +0200 |
parents | 75e90cd0c2c3 |
children |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File convert.asm combined next generation V3.09.4l |
0 | 4 ; |
5 ; Converts register values to string | |
6 ; | |
654 | 7 ; Copyright (c) 2011, Matthias Heinrichs, heinrichs weikamp gmbh, all right reserved. |
0 | 8 ;============================================================================= |
9 ; HISTORY | |
10 ; 2007-10-07 : [MH] Creation for OSTC sources | |
11 ; 2010-12-10 : [jDG] Optimize macro size | |
12 ; | |
13 | |
634 | 14 #include "hwos.inc" |
15 #include "math.inc" | |
16 #include "strings.inc" | |
582 | 17 |
0 | 18 |
19 ;============================================================================= | |
634 | 20 convert1 CODE |
21 ;============================================================================= | |
0 | 22 |
634 | 23 |
24 ;----------------------------------------------------------------------------- | |
25 ; Print last two Digits or double-dots if zero - big Font | |
26 ; | |
628 | 27 global output99DD_call |
28 output99DD_call: | |
29 tstfsz lo ; value = 0 ? | |
30 bra output99_call ; NO - do normal output | |
31 movlw " " ; YES - print a space | |
32 movwf POSTINC2 ; - ... | |
634 | 33 bra print_doubledots ; - continue printing two dots |
628 | 34 |
35 | |
634 | 36 ;----------------------------------------------------------------------------- |
37 ; Print last two Digits or double-dots if zero - small Font | |
38 ; | |
628 | 39 global output99dd_call |
40 output99dd_call: | |
41 tstfsz lo ; value = 0 ? | |
42 bra output99_call ; NO - do normal output | |
634 | 43 bra print_doubledots ; YES - continue printing two dots |
44 | |
45 | |
46 ;----------------------------------------------------------------------------- | |
47 ; Helper Function - Print two Dots | |
48 ; | |
49 print_doubledots: | |
50 movlw "." ; load a '.' | |
51 movwf POSTINC2 ; print 1st dot | |
52 movwf POSTINC2 ; print 2nd dot | |
53 bra output_common_finish ; clean-up and return | |
54 | |
55 | |
56 ;----------------------------------------------------------------------------- | |
57 ; Print last Digit from a 8 bit Integer (0-9) | |
58 ; | |
59 global output9_call | |
60 output9_call: | |
61 bsf hide_digit2 ; do not print digit 5, 4, 3 and 2 | |
62 bra output8_common ; continue with common part | |
63 | |
64 | |
65 ;----------------------------------------------------------------------------- | |
66 ; Print only last two Digits from a 8 bit Integer, with leading zero (00-99) | |
67 ; | |
68 global output99x_call | |
69 output99x_call: | |
70 bsf leading_zeros ; print leading zeros | |
71 ;bra output99_call ; continue with output99_call | |
72 | |
73 | |
74 ;----------------------------------------------------------------------------- | |
75 ; Print last two Digits from a 8 bit Integer (0-99) | |
76 ; | |
77 global output99_call | |
78 output99_call: | |
79 bsf hide_digit3 ; do not print digit 5, 4 and 3 | |
80 ;bra output8_common ; continue with common part | |
81 | |
82 | |
83 ;----------------------------------------------------------------------------- | |
84 ; Print 8 bit Integer (0-255) | |
85 ; | |
86 global output256_call | |
87 output256_call: | |
88 ;bra output8_common ; continue with common part | |
89 | |
90 | |
91 ;----------------------------------------------------------------------------- | |
92 ; Helper Function - common Part for Printing 8 Bit Integers | |
93 ; | |
94 output8_common: | |
95 bcf output_overflow ; clear overflow flag | |
96 movff lo,bin_lo ; copy value to show | |
97 rcall convert_bin8bcd ; compute bcd_hi (1 digit) and bcd_lo (2 digits) | |
98 btfsc hide_digit2 ; shall hide digit 2 ? | |
99 bsf hide_digit3 ; YES - hide digit 3 then, too | |
100 bra output_common_d3 ; start printing with digit 3 | |
101 | |
102 | |
103 ;----------------------------------------------------------------------------- | |
104 ; Print last four Digits from a 16 bit Value (0-9999) | |
105 ; | |
106 global output9999_call | |
107 output9999_call: | |
108 bsf hide_digit5 ; do not print digit 5 | |
109 bra output16_common ; continue with common part | |
110 | |
111 | |
112 ;----------------------------------------------------------------------------- | |
113 ; Print last three Digits from a 16 bit Value (0-999) | |
114 ; | |
115 global output999_call | |
116 output999_call: | |
117 bsf hide_digit4 ; do not print digit 4 and 5 | |
118 ;bra output16_common ; continue with common part | |
119 | |
120 | |
121 ;----------------------------------------------------------------------------- | |
122 ; Print a full 16 bit Value (0-65535) | |
123 ; | |
124 global output65535_call | |
125 output65535_call: | |
126 ;bra output16_common ; continue with common part | |
127 | |
128 | |
129 ;----------------------------------------------------------------------------- | |
130 ; Helper Function - common Part for Printing 16 Bit Integers | |
131 ; | |
132 output16_common: | |
133 bcf output_overflow ; clear overflow flag | |
134 movff lo,bin_lo ; copy value to show | |
135 movff hi,bin_hi ; ... | |
136 rcall convert_bin16bcd ; compute bcd_up (1 digit), bcd_hi (2 digits) and bcd_lo (2 digits) | |
137 btfsc hide_digit2 ; shall hide digit 2 ? | |
138 bsf hide_digit3 ; YES - hide digit 3 then, too | |
139 btfsc hide_digit3 ; shall hide digit 3 ? | |
140 bsf hide_digit4 ; YES - hide digit 4 then, too | |
141 btfsc hide_digit4 ; shall hide digit 4 ? | |
142 bsf hide_digit5 ; YES - hide digit 5 then, too | |
143 ;bra output_common_d5 ; start printing with digit 5 | |
144 | |
145 | |
146 ;----------------------------------------------------------------------------- | |
147 ; Helper Function - common Part for Printing 8 and 16 Bit Integers | |
148 ; | |
149 output_common_d5: | |
150 ; digit 5 | |
151 btfss hide_digit5 ; shall hide digit 5 ? | |
152 bra output_common_d5p ; NO - print digit 5 | |
153 movf bcd_up,W ; YES - get lower nibble (digit 5) into WREG | |
154 andlw 0x0F ; - is it zero? | |
155 bnz print_9999 ; NO - print '9999' | |
156 bra output_common_d4 ; YES - continue with digit 4 | |
157 output_common_d5p: | |
158 movf bcd_up,W ; copy 5th digit to lower nibble of WREG | |
159 rcall print_digit ; print the digit | |
160 | |
161 output_common_d4: | |
162 ; between digit 5 and 4 | |
163 btfsc decimal_digit3 ; shall print a decimal point in front of digit 3 ? | |
164 bsf leading_zeros ; YES - allow printing of zeros now | |
165 | |
166 ; digit 4 | |
167 btfss hide_digit4 ; shall hide digit 4 ? | |
168 bra output_common_d4p ; NO - print digit 4 | |
169 swapf bcd_hi,W ; YES - get upper nibble (digit 4) into WREG | |
170 andlw 0x0F ; - is it zero? | |
171 bnz print_999 ; NO - print '999' | |
172 bra output_common_d3 ; YES - continue with digit 3 | |
173 output_common_d4p: | |
174 swapf bcd_hi,W ; copy 4th digit to lower nibble of WREG | |
175 rcall print_digit ; print the digit | |
176 | |
177 output_common_d3: | |
178 ; between digit 4 and 3 | |
179 btfsc decimal_digit3 ; shall print a decimal point in front of digit 3 ? | |
180 rcall print_decimal ; YES - print a decimal pint now | |
181 btfsc decimal_digit2 ; shall print a decimal point in front of digit 2 ? | |
182 bsf leading_zeros ; YES - allow printing of zeros now | |
183 btfsc omit_digit_2 ; shall omit digits 2 and 1 ? | |
184 bsf leading_zeros ; YES - allow printing of zeros now | |
185 | |
186 ; digit 3 | |
187 btfss hide_digit3 ; shall hide digit 3 ? | |
188 bra output_common_d3p ; NO - print digit 3 | |
189 movf bcd_hi,W ; YES - get lower nibble (digit 3) into WREG | |
190 andlw 0x0F ; - is it zero? | |
191 bnz print_99 ; NO - print '99' | |
192 bra output_common_d2 ; YES - continue with digit 2 | |
193 output_common_d3p: | |
194 movf bcd_hi,W ; copy 3rd digit to lower nibble of WREG | |
195 rcall print_digit ; print the digit | |
196 | |
197 output_common_d2: | |
198 ; between digit 3 and 2 | |
199 btfsc decimal_digit2 ; shall print a decimal point in front of digit 2 ? | |
200 rcall print_decimal ; YES - print a decimal pint now | |
201 btfsc decimal_digit1 ; shall print a decimal point in front of digit 1 ? | |
202 bsf leading_zeros ; YES - allow printing of zeros now | |
203 btfsc omit_digit_1 ; shall omit digit 1 ? | |
204 bsf leading_zeros ; YES - allow printing of zeros now | |
205 | |
206 ; digit 2 | |
207 btfss hide_digit2 ; shall hide digit 2 ? | |
208 bra output_common_d2p ; NO - print digit 2 | |
209 swapf bcd_lo,W ; YES - get upper nibble (digit 2) into WREG | |
210 andlw 0x0F ; - is it zero? | |
211 bnz print_9 ; NO - print '9' | |
212 bra output_common_d1 ; YES - continue with digit 2 | |
213 output_common_d2p: | |
214 btfsc omit_digit_2 ; shall omit digit 2 ? | |
215 bra output_common_finish ; YES - finish output | |
216 swapf bcd_lo,W ; NO - copy 2nd digit to lower nibble of WREG | |
217 rcall print_digit ; - print the digit | |
218 | |
219 output_common_d1: | |
220 ; between digit 2 and 1 | |
221 btfsc decimal_digit1 ; shall print a decimal point in front of digit 1 ? | |
222 rcall print_decimal ; YES - print a decimal pint now | |
223 bsf leading_zeros ; allow printing of zeros now | |
224 | |
225 ; digit 1 | |
226 btfsc omit_digit_1 ; shall omit digit 1 ? | |
227 bra output_common_finish ; YES - finish output | |
228 movf bcd_lo,W ; NO - copy 1st digit to lower nibble of WREG | |
229 rcall print_digit ; - print the digit | |
230 | |
231 output_common_finish: | |
232 clrf INDF2 ; place a terminator at the current buffer position | |
233 clrf CVT_flags1 ; clear output format command flags | |
234 clrf CVT_flags2 ; ... | |
235 return ; done | |
236 | |
237 | |
238 ;----------------------------------------------------------------------------- | |
239 ; Helper Function - print a Digit or a decimal Point | |
240 ; | |
241 ; Input: lower nibble of WREG BCD code of digit | |
242 ; leading_zeros =1: print (leading) zeros | |
243 ; leftbind =1: do not print leading spaces | |
244 ; | |
245 print_digit: | |
246 andlw 0x0F ; keep only the lower nibble, is it zero? | |
247 bnz print_digit_digit ; NO - print in any case | |
248 btfsc leading_zeros ; YES - printing of zeros allowed? | |
249 bra print_digit_digit ; YES - print a zero | |
250 btfsc leftbind ; NO - shall print left-aligned? | |
251 return ; YES - done | |
252 movlw ' ' ; NO - load ASCII code of a space char | |
253 bra print_digit_print ; - print it | |
254 print_digit_digit: | |
255 bsf leading_zeros ; allow printing of zeros now | |
256 addlw '0' ; add ASCII code of '0' to BCD code to get final ASCII code | |
257 print_digit_print: | |
258 movwf POSTINC2 ; print the digit or char | |
259 return ; done | |
260 | |
261 print_decimal: | |
262 movlw '.' ; load ASCII code of a dot | |
263 bra print_digit_print ; print it | |
264 | |
265 | |
266 ;----------------------------------------------------------------------------- | |
267 ; Helper Function - print '9999' or '999' or '99' or '9' | |
268 ; | |
269 print_9999: | |
270 movlw '9' ; load a '9' digit | |
271 movwf POSTINC2 ; print digit 4 | |
272 print_999: | |
273 movlw '9' ; load a '9' digit (for those embarked lately) | |
274 movwf POSTINC2 ; print digit 3 | |
275 print_99: | |
276 movlw '9' ; load a '9' digit (for those embarked lately) | |
277 movwf POSTINC2 ; print digit 2 | |
278 print_9: | |
279 movlw '9' ; load a '9' digit (for those embarked lately) | |
280 movwf POSTINC2 ; print digit 1 | |
281 clrf INDF2 ; place a terminator at the current buffer position | |
282 clrf CVT_flags1 ; clear output format command flags | |
283 clrf CVT_flags2 ; ... | |
284 bsf output_overflow ; set overflow flag | |
285 return ; done | |
286 | |
287 | |
288 ;----------------------------------------------------------------------------- | |
289 ; Convert an 8 Bit Integer to BCD | |
290 ; | |
291 ; Input: bin_lo 8 bit integer | |
292 ; Output: bcd_hi,bcd_lo 3 BCD digits | |
293 ; | |
294 convert_bin8bcd: | |
295 clrf bcd_lo ; clear result variables | |
296 clrf bcd_hi ; ... | |
297 bsf bcd_hi,0 ; set loop counter to 8 | |
298 convert_bin8bcd_loop: | |
299 ; get MSB bit from binary | |
300 rlcf bin_lo,F ; shift-out MSB to CARRY | |
301 ; lower two BCDs | |
302 movf bcd_lo,W ; get lower BCDs to WREG | |
303 addwfc bcd_lo,W ; WREG = 2 * WREG + CARRY | |
304 daw ; decimal-adjust BCDs in WREG | |
305 movwf bcd_lo ; copy back WREG to lower BCDs | |
306 ; higher one BCD | |
307 rlcf bcd_hi ; higher BCD = 2*(higher BCD) + CARRY (special version for 1 BCD only) | |
308 ; loop control | |
309 bnc convert_bin8bcd_loop ; all 8 bits done? NO -> loop | |
310 return ; YES -> done | |
311 | |
312 | |
313 ;----------------------------------------------------------------------------- | |
314 ; Convert a 16 Bit Integer to BCD | |
315 ; | |
316 ; Input: bin_hi,bin_lo 16 bit integer | |
317 ; Output: bcd_up,bcd_hi,bcd_lo 5 BCD digits | |
318 ; | |
319 convert_bin16bcd: | |
320 clrf bcd_lo ; clear result variables | |
321 clrf bcd_hi ; ... | |
322 clrf bcd_up ; ... | |
323 movlw .16 ; 16 bits to do | |
324 movwf math_loop ; load loop counter | |
325 convert_bin16bcd_loop: | |
326 ; get MSB bit from binary | |
327 rlcf bin_lo,F ; shift-out MSB to CARRY | |
328 rlcf bin_hi,F ; ... | |
329 ; lower two BCDs | |
330 movf bcd_lo,W ; get lower BCDs to WREG | |
331 addwfc bcd_lo,W ; WREG = 2 * WREG + CARRY | |
332 daw ; decimal-adjust BCDs in WREG | |
333 movwf bcd_lo ; copy back WREG to lower BCDs | |
334 ; higher two BCDs | |
335 movf bcd_hi,W ; repeat for higher BCDs | |
336 addwfc bcd_hi,W ; ... | |
337 daw ; ... | |
338 movwf bcd_hi ; ... | |
339 ; upper one BCD | |
340 ; movf bcd_up,W ; repeat for upper BCD | |
341 ; addwfc bcd_up,W ; ... | |
342 ; daw ; ... | |
343 ; movwf bcd_up ; ... | |
344 rlcf bcd_up ; upper BCD = 2*(upper BCD) + CARRY (special version for 1 BCD only) | |
345 ; loop control | |
346 decfsz math_loop ; decrement bit counter, all done? | |
347 bra convert_bin16bcd_loop ; NO - loop | |
348 return ; YES - done | |
349 | |
350 | |
351 ;============================================================================= | |
352 convert2 CODE | |
353 ;============================================================================= | |
354 | |
355 | |
356 ;----------------------------------------------------------------------------- | |
357 ; Print Value in WREG as hex Number (00-FF) | |
358 ; | |
359 global outputHEX_call | |
360 outputHEX_call: | |
361 movwf bin_lo ; make a backup | |
362 swapf WREG,W ; swap nibbles to process upper nibble first | |
363 rcall outputHEX_nibble ; print nibble as ASCII | |
364 movf bin_lo,W ; recall backup | |
365 outputHEX_nibble: | |
366 andlw 0x0F ; isolate lower nibble | |
367 addlw +0x36 ; add 0x36 so that numbers >= decimal 10 will become >= 0x40 | |
368 btfss WREG,6 ; WREG >= 0x40 ? | |
369 addlw -0x07 ; NO - number is < 10, move back by offset between ASCII codes for 'A' and '9' | |
370 addlw +0x01 ; make final common move forward to align with ASCII code | |
371 movwf POSTINC2 ; write ASCII code to output buffer | |
372 clrf INDF2 ; place a terminator at the current buffer position | |
373 return ; done | |
374 | |
375 | |
376 ;============================================================================= | |
377 convert3 CODE | |
378 ;============================================================================= | |
379 | |
380 | |
381 ;----------------------------------------------------------------------------- | |
382 ; Convert signed 16 Bit to unsigned 16 Bit and put a '-' into the buffer if negative | |
383 ; | |
384 ; Input / Output: mpr:2 | |
385 ; | |
386 global convert_signed_16bit | |
387 convert_signed_16bit: | |
388 bcf neg_flag ; clear flag for negative number by default | |
389 btfss hi,7 ; negative number? | |
390 return ; NO - done | |
391 bsf neg_flag ; YES - set flag for negative number | |
392 comf hi ; - complement hi:lo | |
393 negf lo ; - ... | |
394 btfsc STATUS,C ; - ... | |
395 incf hi ; - ... | |
396 movlw '-' ; - print a minus sign | |
628 | 397 movwf POSTINC2 ; - ... |
398 return ; - done | |
399 | |
400 | |
634 | 401 ;============================================================================= |
402 convert4 CODE | |
403 ;============================================================================= | |
0 | 404 |
582 | 405 |
634 | 406 ;----------------------------------------------------------------------------- |
407 ; Convert Pressure in [mbar] to Depth in [cm] | |
408 ; | |
409 ; Input: mpr:2 pressure [mbar] | |
410 ; Output: mpr:2 depth [cm] | |
411 ; Destroys: up | |
412 ; | |
413 global convert_pres_to_depth | |
414 convert_pres_to_depth: | |
415 btfsc sensor_override_active ; in pressure sensor override (simulator) mode? | |
416 return ; YES - convert with factor 1.0, i.e. make [mbar] = [cm] | |
417 | |
418 movff opt_salinity,WREG ; get salinity setting (0 - 4 %, see option_table.asm) | |
419 addlw d'100' ; add density of fresh water (1.00 kg/l) | |
420 movwf up ; store salinity factor in up | |
0 | 421 |
634 | 422 movlw .101+salinity_max ; load (upper limit + 1) |
423 cpfslt up ; current setting > upper limit? | |
424 bra convert_fix_salinity ; YES - fix salinity setting | |
425 | |
426 movlw .99+salinity_min ; load (lower limit - 1) | |
427 cpfsgt up ; current setting > lower limit? | |
428 bra convert_fix_salinity ; YES - fix salinity setting | |
0 | 429 |
634 | 430 convert_pres_to_depth_1: |
431 MOVII mpr, xA ; get pressure in [mbar] | |
432 MOVLI .102,xB ; conversion factor x 100 for fresh water (1.02 cm per each 1 mbar) | |
433 call mult16x16 ; xC:4 = xA:2 * xB:2 | |
434 movff up,xB+0 ; get salinity in [%] | |
435 clrf xB+1 ; ... | |
436 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder | |
437 MOVII xC,mpr ; copy back result as depth in [cm] | |
582 | 438 return |
0 | 439 |
634 | 440 convert_fix_salinity: |
441 movlw .100 ; reset to 100%, i.e. set salinity to 0% | |
442 movwf up ; fix value in up | |
443 bra convert_pres_to_depth_1 ; continue | |
444 | |
445 | |
446 ;============================================================================= | |
447 convert5 CODE | |
448 ;============================================================================= | |
449 | |
0 | 450 |
634 | 451 ;----------------------------------------------------------------------------- |
452 ; Convert Depth in [cm] to Depth in [feet] | |
453 ; | |
454 ; Input: mpr:2 depth in [cm] | |
455 ; Output: mpr:2 depth in [ft] | |
456 ; | |
457 global convert_cm_to_feet | |
458 convert_cm_to_feet: | |
459 MOVII mpr, xA ; depth in [cm] | |
460 btfsc sensor_override_active ; in pressure sensor override (simulator) mode? | |
461 bra convert_meter_to_feet_1 ; YES - convert with 334feet/100m | |
462 MOVLI .328,xB ; NO - convert with 328feet/100m | |
463 bra convert_common_to_feet ; - continue with common part | |
582 | 464 |
465 | |
634 | 466 ;----------------------------------------------------------------------------- |
467 ; Convert Depth in [m] to Depth in [feet] | |
468 ; | |
469 ; Input: lo depth in [m] | |
470 ; Output: mpr:2 depth in [ft] | |
471 ; | |
472 global convert_meter_to_feet | |
473 convert_meter_to_feet: | |
474 movf lo,W ; depth in [m] | |
475 mullw .100 ; factor to convert [m] to [cm] | |
476 MOVII PRODL,xA ; copy depth in [cm] to xA | |
477 convert_meter_to_feet_1: | |
478 MOVLI .334, xB ; convert with 334feet/100m to have 10ft, 20ft, 30ft, ... for stop depths | |
479 ;bra convert_common_to_feet ; continue with common part | |
0 | 480 |
634 | 481 |
482 ;----------------------------------------------------------------------------- | |
483 ; Helper Function to convert_cm_to_feet and convert_meter_to_feet | |
484 ; | |
485 convert_common_to_feet: | |
486 call mult16x16 ; xC = xA * xB = depth in [cm] * 334 feet/100 m = depth in 0.0001 feet | |
487 MOVLI .10000,xB ; divide by 10000 to turn into full feet | |
488 call div32x16 ; xC = xC / xB with xA as remainder | |
489 MOVII xC,mpr ; store result | |
490 return ; done | |
582 | 491 |
0 | 492 |
634 | 493 ;============================================================================= |
494 convert6 CODE | |
495 ;============================================================================= | |
496 | |
623 | 497 |
634 | 498 ;----------------------------------------------------------------------------- |
499 ; Convert Temperature in Celsius to Fahrenheit | |
500 ; | |
501 ; Input: mpr:2 temperature in [0.1 °C] | |
502 ; Output: mpr:2 temperature in [0.1 °F] | |
503 ; | |
504 global convert_celsius_to_fahrenheit | |
505 convert_celsius_to_fahrenheit: | |
506 MOVII mpr,xA ; temperature in 1/10 of °C | |
507 ADDLI .1000,xA ; add offset of 1000 to get out of any negative numbers | |
508 ; adjust scaling: 1°C = 1.8°F: | |
509 MOVLI .18,xB ; multiply with 18: | |
510 call mult16x16 ; ... | |
511 MOVLI .10,xB ; divide by 10 | |
512 call div32x16 ; ... | |
513 SUBLI .1480,xC ; subtract above offset (1000 * 1.8 = 1800) and add Fahrenheit-Offset (32 * 10 = 320) => subtract 1480 | |
514 MOVII xC,mpr ; store result in mpr:2 | |
515 return ; done | |
516 | |
517 | |
518 ;============================================================================= | |
519 convert7 CODE | |
520 ;============================================================================= | |
300
5ad479f2a868
Merged Screen layout mod #1 into Screen layout work #3
Janos Kovacs <kovjanos@gmail.com>
parents:
275
diff
changeset
|
521 |
623 | 522 |
634 | 523 ;----------------------------------------------------------------------------- |
524 ; Convert Minutes to Hours and Minutes / Seconds to Minutes and Seconds | |
525 ; | |
526 ; Input: hi:lo minutes / seconds | |
527 ; Output: up:hi hours / minutes | |
528 ; lo minutes / seconds | |
529 ; | |
530 ; trashes xA, xB, xC | |
531 ; | |
532 global convert_time | |
533 convert_time: | |
534 movff lo,xA+0 ; copy hi:lo to xA | |
535 movff hi,xA+1 ; ... | |
536 movlw d'60' ; set divisor to 60 | |
537 movwf xB+0 ; write 60 to xB | |
538 clrf xB+1 ; ... | |
539 call div16x16 ; xC = xA / xB with xA as remainder | |
540 movff xC+1,up ; result is hours / minutes, copy to up (high byte) | |
541 movff xC+0,hi ; result is hours / minutes, copy to hi (low byte) | |
542 movff xA+0,lo ; remainder is minutes / seconds, copy to lo | |
543 return ; done | |
0 | 544 |
545 | |
634 | 546 ;============================================================================= |
547 convert8 CODE | |
548 ;============================================================================= | |
582 | 549 |
550 | |
634 | 551 ;----------------------------------------------------------------------------- |
552 ; Print full Date | |
553 ; | |
554 ; Input: lo year | |
555 ; hi month | |
556 ; up day | |
557 ; | |
558 ; Output format depends on value of option opt_dateformat: | |
559 ; 0: MM.DD.YY | |
560 ; 1: DD.MM.YY | |
561 ; 2: YY.MM.DD | |
562 ; | |
563 ; Destroyed: hy | |
564 ; | |
565 global output_date | |
566 output_date: | |
567 movff opt_dateformat,EEDATA ; get format (EEDATA used as temp here) | |
568 tstfsz EEDATA ; shall use format 0 ? | |
569 bra TFT_convert_date_1 ; NO - check for format 1 or 2 | |
570 ; YES - use format 0: MM.DD.YY | |
571 movff lo,hy ; - backup year to hy | |
572 movff hi,lo ; - copy month to lo | |
573 movff up,hi ; - copy day to hi | |
574 movff hy,up ; - copy year to up | |
575 bra TFT_convert_date_common ; - start output | |
576 TFT_convert_date_1: | |
577 decfsz EEDATA,F ; shall use format 1 ? | |
578 bra TFT_convert_date_common ; NO - use format 2: YY.MM.DD - can print directly | |
579 ; YES - use format 1: DD.MM.YY | |
580 movff lo,hy ; - backup year to hy | |
581 movff up,lo ; - copy day to lo | |
582 movff hy,up ; - copy year to up | |
583 | |
584 TFT_convert_date_common: | |
585 call output99x_call ; print lo (00-99) | |
586 PUTC '.' ; print spacing dot | |
587 movff hi,lo ; print hi (00-99) | |
588 call output99x_call ; ... | |
589 PUTC '.' ; print spacing dot | |
590 movff up,lo ; print up (00-99) | |
591 call output99x_call ; ... | |
592 return ; done | |
593 | |
594 | |
595 ;============================================================================= | |
596 convert9 CODE | |
597 ;============================================================================= | |
582 | 598 |
604 | 599 |
634 | 600 ;----------------------------------------------------------------------------- |
601 ; Print Date by Month & Day | |
602 ; | |
603 ; Input: hi month | |
604 ; up day | |
605 ; | |
606 ; Output format depends on value of option opt_dateformat: | |
607 ; 0: MM.DD | |
608 ; 1: DD.MM | |
609 ; 2: MM.DD | |
610 ; | |
611 ; Destroyed: lo | |
612 ; | |
613 global output_date_short | |
614 output_date_short: | |
615 movff opt_dateformat,EEDATA ; get format (EEDATA used as temp here) | |
616 tstfsz EEDATA ; shall use format 0 ? | |
617 bra TFT_convert_date_short2 ; NO - check for format 1 or 2 | |
618 TFT_convert_date_short1: ; YES - use format 0: MMDD | |
619 movff hi,lo ; - copy month to lo | |
620 movff up,hi ; - copy day to hi | |
621 bra TFT_convert_date_short3 ; - start output | |
622 TFT_convert_date_short2: | |
623 decfsz EEDATA,F ; format 1 ? | |
624 bra TFT_convert_date_short1 ; NO - use format 2: MMDD (here its like format 0) | |
625 ; YES - use format 1: DDMM | |
626 movff up,lo ; - copy day to lo, | |
627 ; - month is already in hi | |
628 TFT_convert_date_short3: | |
629 call output99x_call ; print lo (00-99) | |
630 PUTC '.' ; print spacing dot | |
631 movff hi,lo ; print hi (00-99) | |
632 call output99x_call ; ... | |
633 return ; done | |
604 | 634 |
635 | |
634 | 636 ;============================================================================= |
637 convert10 CODE | |
638 ;============================================================================= | |
639 | |
640 | |
641 global output_secs_as_days_hours | |
642 output_secs_as_days_hours: | |
643 MOVLI .3600,xB ; one hour = 3600s | |
644 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder -> xC+1:xC+0 holds full hours | |
645 MOVII xC, xA ; transfer result to xA | |
646 MOVLI .24,xB ; one day = 24 hours | |
647 call div16x16 ; xC:2 = xA:2 / xB:2 with xA as remainder -> xC+1:xC+0 holds full days, xA holds full hours | |
648 MOVII xC,mpr ; copy full days into hi:lo | |
649 call output99_call ; print days (0-99) | |
650 PUTC "d" ; append unit | |
651 movff xA+0,lo ; get full hours | |
652 call output99x_call ; print full hours (00-99) | |
653 PUTC "h" ; append unit | |
654 return ; done | |
655 | |
656 | |
657 ;----------------------------------------------------------------------------- | |
658 | |
582 | 659 END |