Mercurial > public > hwos_code
annotate src/compass_ops.asm @ 631:185ba2f91f59
3.09 beta 1 release
author | heinrichsweikamp |
---|---|
date | Fri, 28 Feb 2020 15:45:07 +0100 |
parents | 237931377539 |
children | 4050675965ea |
rev | line source |
---|---|
582 | 1 ;============================================================================= |
2 ; | |
631 | 3 ; File compass_ops.asm combined next generation V3.08.8 |
582 | 4 ; |
5 ; Compass Operations | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 | |
10 #include "hwos.inc" | |
11 #include "i2c.inc" | |
12 #include "tft_outputs.inc" | |
147 | 13 #include "tft.inc" |
14 #include "strings.inc" | |
623 | 15 #include "wait.inc" |
582 | 16 #include "surfmode.inc" |
17 #include "divemode.inc" | |
18 #include "math.inc" | |
19 #include "convert.inc" | |
631 | 20 #include "start.inc" |
147 | 21 |
0 | 22 |
623 | 23 IFDEF _compass |
24 | |
25 | |
26 ; local flags | |
27 #DEFINE compass_show_cardinal compass_flags,0 ; =1: show the cardinal (N, NE, E, ...) | |
28 #DEFINE compass_bearing_eq compass_flags,1 ; =1: bearing is in direction, do not show << or >> | |
29 #DEFINE compass_bearing_lft compass_flags,2 ; =1: bearing is to the left/<<, =0: to the right/>> | |
30 #DEFINE compass_bearing_vis compass_flags,3 ; =1: bearing is visible (either ahead or behind/-180°) | |
31 #DEFINE compass_bearing_ahd compass_flags,4 ; =1: bearing is ahead, =0: behind | |
32 ; compass_flags,5 ; --- unused | |
33 ; compass_flags,6 ; --- unused | |
34 ; compass_flags,7 ; --- unused | |
35 | |
36 | |
0 | 37 ; Make sure symbols from the .inc are available to the C code: |
623 | 38 |
39 ; filtered data - Compass | |
582 | 40 global compass_DX_f |
41 global compass_DY_f | |
42 global compass_DZ_f | |
0 | 43 |
623 | 44 ; filtered Data - Accelerometer |
582 | 45 global accel_DX_f |
46 global accel_DY_f | |
47 global accel_DZ_f | |
48 | |
623 | 49 ; Calibration Data |
582 | 50 global compass_CX_f |
51 global compass_CY_f | |
52 global compass_CZ_f | |
0 | 53 |
623 | 54 ; Temporary Values to pass Q15 Arithmetics around |
582 | 55 global compass_a |
56 global compass_b | |
0 | 57 |
582 | 58 ; Result |
623 | 59 global compass_heading_new |
0 | 60 |
147 | 61 |
582 | 62 extern compass |
63 extern compass_reset_calibration | |
64 extern compass_add_calibration | |
65 extern compass_solve_calibration | |
623 | 66 |
631 | 67 extern option_check_and_store_all |
582 | 68 |
337
508d7fb98b34
cleanup menu, add "Auto SP" option (Not working yet), minor layout change in compass menu
heinrichsweikamp
parents:
300
diff
changeset
|
69 |
623 | 70 compass_ops code |
582 | 71 |
72 ;============================================================================= | |
73 | |
0 | 74 ;----------------------------------------------------------------------------- |
75 ; Filter compass values | |
76 ; | |
77 ; Apply linear filtering to input parameters. | |
78 | |
582 | 79 ; Apply filtering formula: reg_f += (reg - reg_f) / 4 |
80 FILTER16 MACRO reg, reg_f | |
81 movf reg_f+0,W | |
82 subwf reg+0,W | |
83 movwf PRODL | |
84 movf reg_f+1,W | |
85 subwfb reg+1,W | |
86 rcall filter_16_common | |
87 addwf reg_f+0,F | |
88 movf PRODH,W | |
89 addwfc reg_f+1,F | |
90 ENDM | |
148 | 91 |
92 filter_16_common: | |
582 | 93 movwf PRODH |
623 | 94 bcf STATUS,C ; copy sign bit into carry |
582 | 95 btfsc PRODH,7 |
96 bsf STATUS,C | |
623 | 97 rrcf PRODH,F ; 16 bit shift right |
582 | 98 rrcf PRODL,F |
623 | 99 bcf STATUS,C ; copy sign bit into carry |
582 | 100 btfsc PRODH,7 |
101 bsf STATUS,C | |
623 | 102 rrcf PRODH,F ; 16 bit shift right |
582 | 103 rrcf PRODL,W |
104 return | |
0 | 105 |
623 | 106 |
582 | 107 global compass_filter |
0 | 108 compass_filter: |
623 | 109 banksel compass_DX ; select bank common2 |
582 | 110 FILTER16 compass_DX, compass_DX_f |
111 FILTER16 compass_DY, compass_DY_f | |
112 FILTER16 compass_DZ, compass_DZ_f | |
113 FILTER16 accel_DX, accel_DX_f | |
114 FILTER16 accel_DY, accel_DY_f | |
115 FILTER16 accel_DZ, accel_DZ_f | |
623 | 116 banksel common ; back to bank common |
582 | 117 return |
0 | 118 |
119 ;----------------------------------------------------------------------------- | |
120 | |
121 compass_filter_init: | |
623 | 122 MOVII compass_DX,compass_DX_f |
123 MOVII compass_DY,compass_DY_f | |
124 MOVII compass_DZ,compass_DZ_f | |
125 | |
126 MOVII accel_DX,accel_DX_f | |
127 MOVII accel_DY,accel_DY_f | |
128 MOVII accel_DZ,accel_DZ_f | |
582 | 129 return |
0 | 130 |
131 ;----------------------------------------------------------------------------- | |
132 ; Q15 fractional numbers: a * b / 2**16 (UNSIGNED) | |
133 ; | |
623 | 134 ; Uses 16x16->16 multiply, for positive integers, keeping only the most |
135 ; relevant bits. | |
0 | 136 ; |
137 ; Used to multiply two Q15 numbers, in the range 0..1, | |
138 ; represented as 0..32767, that is a / 2**15. | |
139 ; | |
140 ; (a/2**15) * (b/2**15) = a*b / 2**30 = (a*b/2**16) / 2**14. | |
141 ; So to get back a Q15 number, we need a shift-left... | |
623 | 142 |
143 global compass_umul ; called from compass.c | |
0 | 144 compass_umul: |
623 | 145 banksel compass_a ; select bank common2 |
582 | 146 rcall compass_mul_16 |
0 | 147 |
148 ; The 2x time, by left-shifting inserting the missing bit: | |
149 compass_mul_2: | |
623 | 150 rlcf compass_r+2,F ; missing bit into carry |
582 | 151 rlcf compass_r+0,F |
152 rlcf compass_r+1,F | |
623 | 153 MOVII compass_r,PROD ; return value into PROD |
582 | 154 return |
0 | 155 |
156 ; The 16x16-> multiply: | |
157 compass_mul_16: | |
623 | 158 movf compass_a+1,W ; block ah*bh |
582 | 159 mulwf compass_b+1 |
160 movff PRODL,compass_r+0 ; and copy | |
161 movff PRODH,compass_r+1 | |
0 | 162 |
623 | 163 movf compass_a+0,W ; block al*bl |
164 mulwf compass_b+0 | |
165 movff PRODH,compass_r+2 ; into fraction byte | |
0 | 166 |
623 | 167 movf compass_a+1,W ; block ah*bl |
582 | 168 mulwf compass_b+0 |
169 movf PRODL,W | |
623 | 170 addwf compass_r+2,F ; fraction part to carry |
582 | 171 movf PRODH,W ; and add16 |
172 addwfc compass_r+0,F | |
173 movlw 0 | |
628 | 174 addwfc compass_r+1,F |
0 | 175 |
623 | 176 movf compass_a+0,W ; block al*bh |
582 | 177 mulwf compass_b+1 |
178 movf PRODL,W | |
623 | 179 addwf compass_r+2,F ; fraction part to carry |
582 | 180 movf PRODH,W ; and add16 |
181 addwfc compass_r+0,F | |
182 movlw 0 | |
183 addwfc compass_r+1,F | |
0 | 184 |
582 | 185 return |
0 | 186 |
187 ;----------------------------------------------------------------------------- | |
188 ; Q15 fractional numbers: a * b / 2**16 (SIGNED) | |
189 | |
623 | 190 global compass_imul ; called from compass.c |
0 | 191 compass_imul: |
623 | 192 banksel compass_a ; select bank common2 |
582 | 193 rcall compass_mul_16 |
0 | 194 |
582 | 195 btfss compass_b+1,7 |
196 bra compass_mul_3 | |
0 | 197 |
582 | 198 movf compass_a+0,W |
199 subwf compass_r+0,F | |
200 movf compass_a+1,W | |
201 subwfb compass_r+1,F | |
0 | 202 |
203 compass_mul_3: | |
582 | 204 btfss compass_a+1,7 |
205 bra compass_mul_4 | |
0 | 206 |
582 | 207 movf compass_b+0,W |
208 subwf compass_r+0,F | |
209 movf compass_b+1,W | |
623 | 210 subwfb compass_r+1,F |
0 | 211 |
212 compass_mul_4: | |
628 | 213 bcf compass_r+1,6 ; copy bit 7 to 6, so keep it after 2x |
582 | 214 btfsc compass_r+1,7 |
215 bsf compass_r+1,6 | |
216 bra compass_mul_2 | |
0 | 217 |
628 | 218 ;----------------------------------------------------------------------------- |
623 | 219 |
582 | 220 global compass_calibration_loop |
628 | 221 compass_calibration_loop: ; compass calibration |
222 bsf block_sensor_interrupt ; disable sensor interrupts | |
223 call I2C_sleep_compass ; stop compass | |
582 | 224 call TFT_ClearScreen |
225 ; Mask | |
226 WIN_COLOR color_greenish | |
227 WIN_SMALL .16,.0 | |
228 STRCPY_TEXT_PRINT tCompassMenu | |
628 | 229 btfss switch_right2 ; wait until button is released |
623 | 230 bra $-2 |
147 | 231 |
582 | 232 call TFT_standard_color |
233 ; WIN_SMALL .0,.215 | |
234 ; STRCPY_TEXT_PRINT tExit | |
235 WAITMS d'255' | |
236 WAITMS d'255' | |
147 | 237 |
628 | 238 call request_speed_fastest ; request CPU speed change to fastest speed |
623 | 239 |
628 | 240 movlw .7 ; initialize gain |
582 | 241 movff WREG,opt_compass_gain |
428 | 242 |
628 | 243 movlw .60 ; initialize timeout to 60 seconds |
244 movwf isr_timeout_reload ; copy WREG to isr_timeout_reload | |
245 bsf reset_timeout ; request ISR to reset the timeout | |
246 bcf trigger_timeout ; clear any pending timeout trigger | |
247 compass_calibration_gainset: ; reduce the gain, set bank here! | |
248 banksel opt_compass_gain ; select bank options table | |
249 decf opt_compass_gain,F ; reduce by one | |
250 btfsc STATUS,N ; < 0 ? | |
251 clrf opt_compass_gain ; YES - keep at zero | |
252 btfsc STATUS,N ; < 0 ? | |
253 bra compass_calibration_loop1 ; YES - skip gain stuff (Would hang here in case of compass failure) | |
254 banksel common ; bank to bank common | |
623 | 255 |
582 | 256 call I2C_init_compass |
257 | |
628 | 258 btfsc compass_type3 ; compass type 3 ? |
259 bra compass_calibration_loop1 ; YES - skip gain stuff | |
260 btfsc compass_type2 ; compass type 2 ? | |
261 bra compass_calibration_loop1 ; YES - skip gain stuff | |
582 | 262 |
628 | 263 rcall TFT_compass_show_gain ; show the current compass gain |
147 | 264 |
582 | 265 WAITMS d'250' |
628 | 266 WAITMS d'250' ; wait for first reading... |
147 | 267 |
628 | 268 movlw .60 ; calibration shall run for 60 seconds |
269 call reset_timeout_time ; set timeout | |
147 | 270 |
628 | 271 call I2C_RX_compass ; read compass |
272 call I2C_RX_accelerometer ; read accelerometer | |
147 | 273 |
582 | 274 ; Test all axes for +4096 (Hi byte=16) |
628 | 275 banksel compass_DX ; select bank common2 |
582 | 276 movlw .16 |
277 cpfseq compass_DX+1 | |
278 bra $+4 | |
279 bra compass_calibration_gainset | |
280 cpfseq compass_DY+1 | |
281 bra $+4 | |
282 bra compass_calibration_gainset | |
283 cpfseq compass_DZ+1 | |
284 bra $+4 | |
285 bra compass_calibration_gainset | |
147 | 286 |
582 | 287 ; Test all axes for -4096 (Hi byte=240) |
288 movlw .240 | |
289 cpfseq compass_DX+1 | |
290 bra $+4 | |
291 bra compass_calibration_gainset | |
292 cpfseq compass_DY+1 | |
293 bra $+4 | |
294 bra compass_calibration_gainset | |
295 cpfseq compass_DZ+1 | |
296 bra $+4 | |
297 bra compass_calibration_gainset | |
147 | 298 |
628 | 299 compass_calibration_loop1: ; done with gain |
300 banksel common ; bank to bank common | |
301 rcall compass_filter_init ; set DX_f values | |
302 call compass_reset_calibration ; reset CX_f values (C-code) | |
303 banksel common ; back to bank common | |
147 | 304 |
305 compass_calibration_loop2: | |
628 | 306 call I2C_RX_compass ; read compass |
307 call I2C_RX_accelerometer ; test accelerometer | |
308 rcall compass_filter ; filter compass raw data | |
147 | 309 |
582 | 310 ; Twice |
628 | 311 call I2C_RX_compass ; read compass |
312 call I2C_RX_accelerometer ; test accelerometer | |
313 rcall compass_filter ; filter compass raw data | |
582 | 314 |
628 | 315 ; btfsc compass_type1 ; compass1? |
316 ; bra compass_calibration_loop3 ; YES - skip gain stuff | |
147 | 317 |
582 | 318 ; Test all axes for +4096 (Hi byte=16) |
628 | 319 banksel compass_DX ; select bank common2 |
582 | 320 movlw .16 |
321 cpfseq compass_DX+1 | |
322 bra $+4 | |
323 bra compass_calibration_gainset | |
324 cpfseq compass_DY+1 | |
325 bra $+4 | |
326 bra compass_calibration_gainset | |
327 cpfseq compass_DZ+1 | |
328 bra $+4 | |
329 bra compass_calibration_gainset | |
147 | 330 |
582 | 331 ; Test all axes for -4096 (Hi byte=240) |
332 movlw .240 | |
333 cpfseq compass_DX+1 | |
334 bra $+4 | |
335 bra compass_calibration_gainset | |
336 cpfseq compass_DY+1 | |
337 bra $+4 | |
338 bra compass_calibration_gainset | |
339 cpfseq compass_DZ+1 | |
340 bra $+4 | |
341 bra compass_calibration_gainset | |
628 | 342 banksel common ; back to bank common |
147 | 343 ; |
582 | 344 ; ; Three |
628 | 345 ; call I2C_RX_compass ; read compass |
346 ; call I2C_RX_accelerometer ; test accelerometer | |
347 ; call compass_filter ; filter compass raw data | |
147 | 348 ; |
582 | 349 ; ; Four times to get cleaner values |
628 | 350 ; call I2C_RX_compass ; read compass |
351 ; call I2C_RX_accelerometer ; test accelerometer | |
352 ; call compass_filter ; filter compass raw data | |
147 | 353 |
428 | 354 compass_calibration_loop3: |
623 | 355 ; and register only one value out of four: |
628 | 356 call compass_add_calibration ; check and store new max/min values (C-code) |
357 banksel common ; back to bank common | |
147 | 358 |
628 | 359 rcall TFT_compass_fast ; show values |
360 btfsc trigger_timeout ; timeout (calibration done)? | |
361 bra compass_calibration_exit ; YES - done | |
362 btfss trigger_full_second ; NO - new second begun? | |
631 | 363 bra compass_calibration_loop2 ; NO - loop |
628 | 364 bcf trigger_full_second ; YES - clear flag |
365 rcall TFT_show_timeout_testmode ; - show remaining time | |
366 bra compass_calibration_loop2 ; - loop | |
147 | 367 |
368 compass_calibration_exit: | |
628 | 369 bcf block_sensor_interrupt ; re-enable sensor interrupts |
623 | 370 |
628 | 371 call compass_solve_calibration ; calculate calibration factors (C-code) |
372 banksel common ; back to bank common | |
373 | |
374 call request_speed_normal ; request CPU speed change to normal speed | |
623 | 375 |
631 | 376 bsf options_changed ; flag that option values have changed |
377 bsf restart_fast ; request to skip logos and waits on restart | |
378 | |
379 movlw .6 ; coding for surface compass view | |
380 movff WREG,customview_surfmode ; set to compass view to show | |
381 | |
382 goto restart ; done | |
623 | 383 |
628 | 384 ;----------------------------------------------------------------------------- |
147 | 385 |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
386 TFT_compass_fast: |
628 | 387 WIN_TINY .0,.50 |
388 STRCPY "Cx:" | |
623 | 389 MOVII compass_DX,mpr |
628 | 390 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required |
391 output_16 | |
392 STRCAT " Cy:" | |
393 MOVII compass_DY,mpr | |
394 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | |
395 output_16 | |
396 STRCAT " Cz:" | |
397 MOVII compass_DZ,mpr | |
398 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | |
582 | 399 output_16 |
628 | 400 STRCAT_PRINT " " |
401 | |
402 WIN_TINY .0,.104 | |
403 STRCPY "Ax:" | |
404 MOVII accel_DX,mpr | |
405 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | |
582 | 406 output_16 |
628 | 407 STRCAT " Ay:" |
408 MOVII accel_DY,mpr | |
409 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | |
410 output_16 | |
411 STRCAT " Az:" | |
412 MOVII accel_DZ,mpr | |
413 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | |
582 | 414 output_16 |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
415 STRCAT_PRINT " " |
582 | 416 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
417 |
623 | 418 TFT_show_timeout_testmode: |
628 | 419 WIN_TINY .0,.68 |
582 | 420 STRCPY "T:" |
623 | 421 movff isr_timeout_timer,lo |
582 | 422 bsf leftbind |
628 | 423 output_8 ; display remaining time |
582 | 424 bcf leftbind |
425 STRCAT_PRINT "s " | |
426 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
427 |
628 | 428 TFT_compass_show_gain: ; show the current compass gain |
429 ; movff opt_compass_gain,lo ; 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) | |
582 | 430 ; tstfsz lo |
628 | 431 ; return ; do not show unless gain=0 |
432 WIN_TINY .0,.86 | |
582 | 433 STRCPY_TEXT tCompassGain |
628 | 434 movff opt_compass_gain,lo ; 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) |
582 | 435 bsf leftbind |
436 output_8 | |
437 bcf leftbind | |
438 STRCAT_PRINT "" | |
439 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
440 |
628 | 441 ;----------------------------------------------------------------------------- |
623 | 442 |
582 | 443 global TFT_surface_compass_mask |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
444 TFT_surface_compass_mask: |
582 | 445 WIN_SMALL surf_compass_mask_column,surf_compass_mask_row |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
446 call TFT_standard_color |
628 | 447 STRCPY_TEXT_PRINT tHeading ; print "Heading:" |
582 | 448 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
449 |
623 | 450 |
628 | 451 global TFT_dive_compass_mask ; draws the white box around the heading tape |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
452 TFT_dive_compass_mask: |
582 | 453 WIN_FRAME_STD dm_custom_compass_graph_row, dm_custom_compass_graph_row+dm_custom_compass_graph_height, .0, .159 |
454 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
455 |
623 | 456 |
582 | 457 global TFT_surface_compass_heading |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
458 TFT_surface_compass_heading: |
582 | 459 rcall compass_heading_common |
460 WIN_STD surf_compass_head_column,surf_compass_head_row | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
461 call TFT_standard_color |
628 | 462 TFT_surface_compass_heading_com: ; show "000° N" |
463 movff compass_heading_new+1,WREG ; get upper byte of actual heading | |
464 btfsc WREG,7 ; compass calibrated? | |
465 bra TFT_compass_uncalibrated ; NO | |
466 MOVII compass_heading_shown,mpr ; get heading to be shown | |
467 rcall TFT_compass_helper ; show heading and its cardinal | |
468 btfsc divemode ; in dive mode? | |
469 return ; YES - done for dive mode | |
470 ; in surface mode - shall show bearing? | |
471 btfss compass_bearing_set ; is a bearing set? | |
472 return ; NO - done | |
473 btfsc compass_menu ; is the "set bearing" selection shown? | |
474 return ; YES - done | |
475 ; show bearing | |
476 WIN_SMALL surf_compass_bear_column,surf_compass_bear_row | |
477 call TFT_attention_color | |
478 MOVII compass_bearing,mpr ; get bearing | |
479 ;bra TFT_compass_helper ; show number and cardinal and return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
480 |
628 | 481 TFT_compass_helper: |
582 | 482 bsf leftbind |
628 | 483 output_16dp .2 ; result is "0.000" in buffer |
582 | 484 bcf leftbind |
485 ; rearrange figures to "000" | |
486 movff buffer+2,buffer+0 | |
487 movff buffer+3,buffer+1 | |
488 movff buffer+4,buffer+2 | |
489 lfsr FSR2,buffer+3 | |
490 STRCAT "° " | |
628 | 491 rcall tft_compass_cardinal ; add cardinal to POSTINC2 |
492 STRCAT_PRINT "" ; finalize output | |
493 return ; done | |
494 | |
495 TFT_compass_uncalibrated: | |
496 STRCAT_PRINT "---°" ; print "---°" | |
497 return ; done | |
382 | 498 |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
499 |
582 | 500 global TFT_dive_compass_heading |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
501 TFT_dive_compass_heading: |
582 | 502 rcall compass_heading_common |
628 | 503 WIN_FONT FT_SMALL ; set font size |
504 | |
623 | 505 ; ; ### for development only, hard-coding the bearing ### |
582 | 506 ; ; 244° : SW - W |
628 | 507 ; MOVLI .244,xA ; xA used as temp |
508 ; MOVII xA,compass_bearing ; compass_bearing is stored in bank isr_backup | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
509 |
623 | 510 MOVII compass_heading_shown,xA |
511 ; 160° viewing angle: add +360 offset if xA <= 292 for non-negative scale | |
512 MOVLI .292,sub_a | |
513 MOVII xA, sub_b | |
628 | 514 call subU16 ; sub_c = sub_a - sub_b |
515 btfsc neg_flag ; xA > 292 ? | |
516 bra TFT_dive_compass_heading_1 ; YES | |
517 ADDLI .360,xA ; NO - add offset | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
518 TFT_dive_compass_heading_1: |
628 | 519 SUBLI .80,xA ; subtract 80 (left pixel offset from the center) |
520 MOVII xA,xRD ; save result to xRD | |
521 ADDLI .160,xA ; add 160 (display with in pixels) | |
522 MOVII xA,xRDr ; save result to xRDr | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
523 |
628 | 524 btfss compass_bearing_set ; is a bearing set? |
525 bra TFT_dive_compass_ruler ; NO - skip next calculations | |
526 MOVII xRDr,sub_a ; YES - calculate xRD180 = xRDr - 180 | |
623 | 527 MOVLI .180,sub_b |
628 | 528 call subU16 ; sub_c = sub_a - sub_b |
623 | 529 MOVII sub_c,xRD180 |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
530 |
258 | 531 TFT_dive_compass_bearing_1: |
582 | 532 ; calculate bearing position and visibility (ahead or behind) |
628 | 533 bcf compass_bearing_vis ; default is not-visible |
534 bcf compass_bearing_ahd ; default is behind | |
623 | 535 MOVII compass_bearing,xA |
628 | 536 ADDLI .360,xA ; calculate the bearing virtual display offset |
537 MOVII xA,divA ; save it for reuse for upper/lower turns and ahead/behind checks | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
538 |
623 | 539 ; check if bearing is ahead |
628 | 540 MOVII divA,sub_a ; load the bearing offset into sub_a |
541 MOVII xRD, sub_b ; load the display offset back to sub_b | |
582 | 542 rcall TFT_dive_compass_bearing_ap |
628 | 543 btfsc compass_bearing_vis ; bearing visible? |
544 bra TFT_dive_compass_bearing_dir; YES | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
545 |
628 | 546 ; check if it is ahead with an upper turn |
547 MOVII divA,sub_a ; load the bearing offset into sub_a | |
548 MOVII xRD, sub_b ; load the display offset back to sub_b | |
623 | 549 ADDLI .360,sub_b |
582 | 550 rcall TFT_dive_compass_bearing_ap |
628 | 551 btfsc compass_bearing_vis ; bearing visible? |
552 bra TFT_dive_compass_bearing_dir; YES | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
553 |
628 | 554 ; check if it is ahead with a lower turn |
555 MOVII divA,sub_a ; load the bearing offset into sub_a | |
623 | 556 ADDLI .360,sub_a |
628 | 557 MOVII xRD, sub_b ; load the display offset back to sub_b |
582 | 558 rcall TFT_dive_compass_bearing_ap |
628 | 559 btfsc compass_bearing_vis ; bearing visible? |
560 bra TFT_dive_compass_bearing_dir; YES | |
258 | 561 |
623 | 562 ; marker is not ahead of us, check if it is behind of us |
582 | 563 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display |
628 | 564 MOVII xRD180,sub_a ; load the display offset back to sub_a |
565 MOVII divA, sub_b ; load the marker's offset into sub_b | |
582 | 566 rcall TFT_dive_compass_bearing_bp |
628 | 567 btfsc compass_bearing_vis ; bearing behind of us? |
568 bra TFT_dive_compass_bearing_dir; YES | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
569 |
628 | 570 ; check if it is behind with the upper turn |
623 | 571 MOVII xRD180,sub_a |
572 MOVII divA, sub_b | |
573 ADDLI .360, sub_b | |
574 rcall TFT_dive_compass_bearing_bp | |
628 | 575 btfsc compass_bearing_vis ; bearing behind of us? |
576 bra TFT_dive_compass_bearing_dir; YES | |
623 | 577 |
628 | 578 ; check if it is behind with the lower turn |
623 | 579 MOVII xRD180,sub_a |
580 ADDLI .360, sub_a | |
628 | 581 MOVII divA, sub_b ; load the marker's offset into sub_b |
582 | 582 rcall TFT_dive_compass_bearing_bp |
583 bra TFT_dive_compass_bearing_dir | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
584 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
585 TFT_dive_compass_bearing_ap: |
582 | 586 ; xCM received in sub_a |
587 ; xRD received in sub_b | |
588 ; 1/a. check if it's viewable from the left side | |
628 | 589 call subU16 ; sub_c = sub_a - sub_b |
590 btfsc neg_flag ; xRD > divA ? | |
591 return ; NO - done | |
592 MOVII sub_c,xC ; YES - store the RO=RP-RD for drawing | |
623 | 593 ; 1/b. check if it's viewable from the right side |
628 | 594 ADDLI .2,sub_a ; avoid thin mess on the side of the display |
595 ADDLI .158,sub_b ; load the display offset right side into sub_b | |
596 call subU16 ; sub_c = sub_a - sub_b | |
597 btfss neg_flag ; xRDr > xA(+2) ? | |
598 return ; NO - done | |
599 ; YES - print the bearing lines on the screen | |
582 | 600 movff xC+0,xCM |
628 | 601 bsf compass_bearing_vis ; set visible |
602 bsf compass_bearing_ahd ; set ahead | |
603 return ; done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
604 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
605 TFT_dive_compass_bearing_bp: |
582 | 606 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display |
607 ; the marker's offset received in sub_b | |
608 ; the xRD180 display offset received in sub_a | |
609 ; xRD180 - xCM | |
628 | 610 call subU16 ; sub_c = sub_a - sub_b |
611 btfsc neg_flag ; CM > xRD180 ? | |
612 return ; NO - not on screen, done | |
613 ; YES - check 160 - (X) | |
614 MOVLI .158, sub_a ; 158 to avoid thin mess on the side of the display | |
623 | 615 MOVII sub_c,sub_b |
628 | 616 call subU16 ; sub_c = sub_a - sub_b |
617 btfsc neg_flag ; X > 160 ? | |
618 return ; NO - not on screen, done | |
623 | 619 ; check if not overflow - this sounds like a double check... |
628 | 620 tstfsz sub_c+1 ; high byte = 0 ? |
621 return ; NO - sub_c must be > 160 then, done | |
622 movlw d'158' ; YES - load a 158 | |
623 cpfslt sub_c+0 ; - low byte < 158 ? | |
624 return ; NO - done | |
625 movff sub_c+0,xCM ; YES - print the bearing lines on the screen | |
626 bsf compass_bearing_vis ; - flag to show bearing lines | |
627 return ; - done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
628 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
629 TFT_dive_compass_bearing_dir: |
582 | 630 ; check if bearing to heading, and calculate the direction |
631 bcf compass_bearing_eq | |
632 btfss compass_bearing_vis | |
633 bra TFT_dive_compass_bearing_lr | |
634 btfss compass_bearing_ahd | |
635 bra TFT_dive_compass_bearing_lr | |
636 movff xCM,xA+0 | |
637 movlw d'80' | |
638 cpfseq xA+0 | |
639 bra TFT_dive_compass_bearing_lr | |
640 bsf compass_bearing_eq | |
628 | 641 bra TFT_dive_compass_ruler ; bearing points to heading, no signs are required, go to the ruler |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
642 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
643 TFT_dive_compass_bearing_lr: |
582 | 644 ; get the bearing virtual display offset |
623 | 645 MOVII compass_bearing,xA |
646 ; xA = xA > 292 ? xA : xA+360 | |
647 MOVLI .292,sub_a | |
648 MOVII xA, sub_b | |
628 | 649 call subU16 ; sub_c = sub_a - sub_b |
650 btfsc neg_flag ; xA > 292 ? | |
651 bra TFT_dive_compass_bearing_lr_1; YES | |
652 ADDLI .360,xA ; NO - add 360 | |
623 | 653 |
258 | 654 TFT_dive_compass_bearing_lr_1: |
582 | 655 ; 1. calculate whether bearing is to left or to right |
628 | 656 bsf compass_bearing_lft ; to the left by default |
582 | 657 ; xC: save center value to compare the direction to front value |
623 | 658 MOVII xA,xC |
582 | 659 ; xB: we need the left side for comparison... left = -180 |
623 | 660 MOVII xA, sub_a |
661 MOVLI .180,sub_b | |
628 | 662 call subU16 ; sub_c = sub_a - sub_b |
663 MOVII sub_c,xB ; xB has the left side of the 180° distance center | |
623 | 664 ; xA = xRD > (xC+100) ? RD-280 : xRD+80 |
665 MOVII xC, sub_a | |
666 ADDLI .100,sub_a | |
667 MOVII xRD, sub_b | |
628 | 668 call subU16 ; sub_c = sub_a - sub_b |
669 btfsc neg_flag ; xRD > xC + 100 ? | |
670 bra TFT_dive_compass_bearing_lr_2; YES - xA = xRD - 280 | |
671 ; NO - xA = xRD + 80 | |
623 | 672 MOVII xRD,xA |
673 ADDLI .80,xA | |
582 | 674 bra TFT_dive_compass_bearing_lr_c |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
675 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
676 TFT_dive_compass_bearing_lr_2: |
623 | 677 MOVII xRD,sub_a |
678 MOVLI .280,sub_b | |
628 | 679 call subU16 ; sub_c = sub_a - sub_b |
623 | 680 MOVII sub_c,xA |
582 | 681 ;bra TFT_dive_compass_bearing_lr_c |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
682 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
683 TFT_dive_compass_bearing_lr_c: |
582 | 684 ; xB < xA < xC => right, otherwise left (default) |
623 | 685 MOVII xA,sub_b |
686 MOVII xB,sub_a | |
628 | 687 call subU16 ; sub_c = sub_a - sub_b |
688 btfss neg_flag ; xA > xB ? | |
689 bra TFT_dive_compass_ruler ; NO - xB >= xA, keep default left | |
623 | 690 MOVII xA,sub_a |
691 MOVII xC,sub_b | |
628 | 692 call subU16 ; sub_c = sub_a - sub_b |
693 btfss neg_flag ; xC > xA ? | |
694 bra TFT_dive_compass_ruler ; NO - xA >= xC, keep default left | |
582 | 695 bcf compass_bearing_lft |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
696 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
697 TFT_dive_compass_ruler: |
582 | 698 ; calculate mod15 for the ticks |
623 | 699 MOVII xRD,xA |
700 MOVLI .15,xB | |
628 | 701 call div16x16 ; xA/xB=xC with xA+0 as remainder |
623 | 702 ; check the remainder |
582 | 703 movlw d'0' |
628 | 704 cpfsgt xA+0 ; mod15 > 0 ? |
705 bra TFT_dive_compass_ruler_1 ; NO - RM = 0 | |
706 ; YES - RM = 15 - RDmod15 | |
582 | 707 movlw d'15' |
623 | 708 subfwb xA+0,F |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
709 TFT_dive_compass_ruler_1: |
628 | 710 movff xA+0,lo ; xA+0 holds the RM, store it to 'lo' |
711 clrf hi ; initialize DD to zero, store it to 'hi' | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
712 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
713 TFT_dive_compass_ruler_loop: |
623 | 714 ; 1. check if we run out of the display |
628 | 715 movlw d'159' ; looks like 159 works because TFT_box limits the display |
582 | 716 cpfslt lo,1 |
628 | 717 bra TFT_dive_compass_ruler_lend ; xRM >= W |
582 | 718 ; 2. Clear the tick area from DD to RM - in segments to avoid blinking |
719 ; don't do a clear if we are at 0 (zero) otherwise it will blink | |
720 ; because of the width underflow | |
721 movlw d'0' | |
722 cpfsgt lo,1 | |
723 bra TFT_dive_compass_ruler_loop_zz | |
724 rcall TFT_dive_compass_clr_ruler | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
725 TFT_dive_compass_ruler_loop_zz: |
582 | 726 ; 3. Draw the markers @ RM |
727 ; we receive RM in lo and DD in hi | |
728 movlw d'2' | |
628 | 729 movwf win_bargraph ; set with of ticks |
582 | 730 movwf win_width+0 |
731 clrf win_width+1 | |
628 | 732 movff lo,win_leftx2 ; 0..159 |
733 movlw dm_custom_compass_tick_top_top | |
734 movwf win_top ; set position for upper ticks | |
582 | 735 movlw dm_custom_compass_tick_height |
628 | 736 movwf win_height ; set hight of ticks |
737 call TFT_standard_color ; set color | |
738 call TFT_box ; draw tick | |
739 movlw dm_custom_compass_tick_bot_top | |
740 movwf win_top ; set position for lower ticks | |
741 movlw dm_custom_compass_tick_height | |
742 movwf win_height ; set hight of ticks | |
743 call TFT_standard_color ; color in WREG is trashed, must be set again! | |
744 call TFT_box ; draw tick | |
745 ; 4. If D < 82 and RM > 79: means we put something over the center line, | |
746 ; so redraw the center line | |
582 | 747 movlw d'82' |
748 cpfslt hi,1 | |
749 bra TFT_dive_compass_ruler_loop_zz2 | |
750 movlw d'79' | |
751 cpfsgt lo,1 | |
752 bra TFT_dive_compass_ruler_loop_zz2 | |
623 | 753 ; enough to print center line as bearing marker is not in the ticker area |
628 | 754 rcall TFT_dive_compass_c ; draw center line in yellow |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
755 TFT_dive_compass_ruler_loop_zz2: |
582 | 756 ; 5. set D = RM + 2 : position after the 2px tick |
757 movff lo,hi | |
758 movlw d'2' | |
759 addwf hi,F | |
760 ; 6. set RM = RM + 15 : position to the next tick | |
761 movlw d'15' | |
762 addwf lo,F | |
763 ; 7. loop | |
764 bra TFT_dive_compass_ruler_loop | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
765 |
628 | 766 TFT_dive_compass_ruler_lend: ; loop end |
767 ; 8. clear the rest of the tick area if D < 160 | |
582 | 768 movlw d'160' |
769 cpfslt hi | |
628 | 770 bra TFT_dive_compass_labels ; D >= W |
582 | 771 ; 9. position left to end of display to clear the remaining area |
772 movlw d'159' | |
773 movwf lo | |
774 ; 10. clear it | |
775 rcall TFT_dive_compass_clr_ruler | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
776 |
628 | 777 TFT_dive_compass_labels: |
582 | 778 ; done with the compass ruler, put the labels on the screen |
628 | 779 clrf hi ; hi stores the display position |
780 movff hi,xHI ; bank-safe clear of xHI | |
781 clrf lo ; lo stores the last item's display position | |
782 movff lo,xLO ; bank-safe clear of xLO | |
783 MOVLI .219,sub_a ; position of the cardinal | |
784 MOVII xRD, sub_b ; get the RD back to sub_b | |
785 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
786 btfss compass_show_cardinal ; shall show cardinal? | |
787 bra dcr_1 ; NO | |
788 STRCPY_TEXT_PRINT tSW ; YES - print it | |
582 | 789 dcr_1: |
628 | 790 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
791 MOVLI .267,sub_a ; position of the cardinal | |
792 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
793 btfss compass_show_cardinal ; shall show cardinal? | |
794 bra dcr_2 ; NO | |
795 STRCPY_TEXT_PRINT tW ; YES - print it | |
582 | 796 dcr_2: |
628 | 797 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
798 MOVLI .309,sub_a ; position of the cardinal | |
799 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
800 btfss compass_show_cardinal ; shall show cardinal? | |
801 bra dcr_3 ; NO | |
802 STRCPY_TEXT_PRINT tNW ; YES - print it | |
582 | 803 dcr_3: |
628 | 804 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
805 MOVLI .358,sub_a ; position of the cardinal | |
806 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
807 btfss compass_show_cardinal ; shall show cardinal? | |
808 bra dcr_4 ; NO | |
809 STRCPY_TEXT_PRINT tN ; YES - print it | |
582 | 810 dcr_4: |
628 | 811 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
812 MOVLI .399,sub_a ; position of the cardinal | |
813 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
814 btfss compass_show_cardinal ; shall show cardinal? | |
815 bra dcr_5 ; NO | |
816 STRCPY_TEXT_PRINT tNE ; YES - print it | |
582 | 817 dcr_5: |
628 | 818 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
819 MOVLI .448,sub_a ; position of the cardinal | |
820 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
821 btfss compass_show_cardinal ; shall show cardinal? | |
822 bra dcr_6 ; NO | |
823 STRCPY_TEXT_PRINT tE ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
824 dcr_6: |
628 | 825 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
826 MOVLI .489,sub_a ; position of the cardinal | |
827 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
828 btfss compass_show_cardinal ; shall show cardinal? | |
829 bra dcr_7 ; NO | |
830 STRCPY_TEXT_PRINT tSE ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
831 dcr_7: |
628 | 832 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
833 MOVLI .538,sub_a ; position of the cardinal | |
834 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
835 btfss compass_show_cardinal ; shall show cardinal? | |
836 bra dcr_8 ; NO | |
837 STRCPY_TEXT_PRINT tS ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
838 dcr_8: |
628 | 839 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
840 MOVLI .579,sub_a ; position of the cardinal | |
841 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
842 btfss compass_show_cardinal ; shall show cardinal? | |
843 bra dcr_9 ; NO | |
844 STRCPY_TEXT_PRINT tSW ; YES - print it | |
582 | 845 dcr_9: |
628 | 846 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
847 MOVLI .627,sub_a ; position of the cardinal | |
848 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
849 btfss compass_show_cardinal ; shall show cardinal? | |
850 bra dcr_10 ; NO | |
851 STRCPY_TEXT_PRINT tW ; YES - print it | |
582 | 852 dcr_10: |
628 | 853 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
854 MOVLI .669,sub_a ; position of the cardinal | |
855 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
856 btfss compass_show_cardinal ; shall show cardinal? | |
857 bra dcr_11 ; NO | |
858 STRCPY_TEXT_PRINT tNW ; YES - print it | |
582 | 859 dcr_11: |
628 | 860 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
861 MOVLI .718,sub_a ; position of the cardinal | |
862 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
863 btfss compass_show_cardinal ; shall show? | |
864 bra dcr_12 ; NO | |
865 STRCPY_TEXT_PRINT tN ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
866 dcr_12: |
628 | 867 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
868 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
869 TFT_dive_compass_label_end: |
628 | 870 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
582 | 871 ; restore lo and hi for the final cleanup |
628 | 872 movff xLO,lo ; xLO and xHI are stored in bank isr_backup |
582 | 873 movff xHI,hi |
628 | 874 ; clear the rest of the SQ area if there is more space |
582 | 875 movlw d'159' |
876 cpfslt hi | |
628 | 877 bra TFT_dive_compass_label_end2 ; D >= 160, no more space |
582 | 878 ; position left to end of display to clear the remaining area |
879 movlw d'158' | |
880 movwf lo | |
881 ; clear it | |
882 rcall TFT_dive_compass_clr_label | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
883 TFT_dive_compass_label_end2: |
628 | 884 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
582 | 885 ; do we have bearing set? |
628 | 886 btfsc compass_bearing_set ; bearing set? |
887 bra TFT_dive_compass_dir_text ; YES - print the direction (<< or >>) | |
888 rcall TFT_dive_compass_dir_lclr ; NO - clear the area (e.g. we had but removed) | |
582 | 889 rcall TFT_dive_compass_dir_rclr |
890 bra TFT_dive_compass_text | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
891 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
892 TFT_dive_compass_dir_text: |
582 | 893 ; bearing set, but does it point to heading? |
894 btfss compass_bearing_eq | |
628 | 895 bra TFT_dive_compass_dir_text_2 ; bearing != heading - go and print the direction |
896 rcall TFT_dive_compass_dir_lclr ; bearing == heading - no need for direction markers | |
582 | 897 rcall TFT_dive_compass_dir_rclr |
898 bra TFT_dive_compass_text | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
899 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
900 TFT_dive_compass_dir_text_2: |
582 | 901 movlw color_green |
902 call TFT_set_color | |
903 btfsc compass_bearing_lft | |
628 | 904 bra TFT_dive_compass_dir_ldir ; bearing_lft=1, print the left marker |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
905 ;TFT_dive_compass_text_rdir: |
582 | 906 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 |
907 STRCPY_PRINT ">>" | |
628 | 908 rcall TFT_dive_compass_dir_lclr ; do not forget to clear the left |
582 | 909 bra TFT_dive_compass_text |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
910 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
911 TFT_dive_compass_dir_ldir: |
582 | 912 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 |
913 STRCPY_PRINT "<<" | |
628 | 914 rcall TFT_dive_compass_dir_rclr ; do not forget to clear the right |
582 | 915 ;bra TFT_dive_compass_text |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
916 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
917 TFT_dive_compass_text: |
582 | 918 ; Clear some unused space on the right mH |
919 WIN_BOX_BLACK dm_custom_compass_tick_top_bot+.1,dm_custom_compass_tick_bot_top-.1,.158,.159 ; top, bottom, left, right | |
371 | 920 |
582 | 921 ; Text output |
922 call TFT_standard_color | |
923 WIN_SMALL dm_custom_compass_head_column, dm_custom_compass_head_row | |
628 | 924 rcall TFT_surface_compass_heading_com ; show "xxx° N" |
582 | 925 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
926 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
927 TFT_dive_compass_dir_lclr: |
582 | 928 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 |
929 STRCPY_PRINT " " | |
930 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
931 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
932 TFT_dive_compass_dir_rclr: |
582 | 933 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 |
934 STRCPY_PRINT " " | |
935 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
936 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
937 TFT_dive_compass_label_proc: |
582 | 938 movlw d'14' |
628 | 939 movwf up ; cardinal width in px |
623 | 940 bcf compass_show_cardinal |
582 | 941 ; 1/a. check if it's viewable ? sub_a(RP) >= sub_b(RD) ? |
942 ; set the carry flag if sub_b(xRD) is equal to or greater than sub_a(xRP): | |
623 | 943 MOVII xRD,sub_b |
628 | 944 call subU16 ; sub_c = sub_a - sub_b |
945 btfsc neg_flag ; >= 0 ? | |
946 return ; NO | |
582 | 947 ; store the RO=RP-RD for drawing |
623 | 948 MOVII sub_c,xC |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
949 |
582 | 950 ; 1/b. check if it's viewable ? sub_a(RP)+up(width) < sub_b(RD)+160 |
951 ; if already above, no need to process the rest of the labels | |
628 | 952 movff up,WREG ; take care about the width |
582 | 953 addwf sub_a+0,1 |
954 btfsc STATUS, C | |
955 incf sub_a+1 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
956 |
623 | 957 MOVII xRDr,sub_b |
628 | 958 call subU16 ; sub_c = sub_a - sub_b |
959 btfss neg_flag ; < 0 ? | |
960 bra TFT_dive_compass_label_end ; NO | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
961 |
582 | 962 ; 2. restore RO=RP-RD from 1/a. |
963 movff xC+0,lo | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
964 |
582 | 965 ; 3. Clear the segment from DD(hi) to lo |
966 ; don't do a clear if we are at 0 (zero) otherwise it will blink | |
967 ; ?because of the width underflow? | |
968 movlw d'1' | |
969 cpfsgt lo | |
970 bra TFT_dive_compass_label_proc_p | |
971 rcall TFT_dive_compass_clr_label | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
972 TFT_dive_compass_label_proc_p: |
582 | 973 ; 4. print the SQ on the screen |
974 call TFT_standard_color | |
623 | 975 bsf compass_show_cardinal |
257
5dd0f39d05d4
minor speed and size improvements for the compass routine
heinrichsweikamp
parents:
256
diff
changeset
|
976 ;TFT_dive_compass_label_print: |
582 | 977 movlw dm_custom_compass_label_row |
978 movff WREG,win_top | |
979 movff lo,win_leftx2 | |
623 | 980 WIN_FONT FT_SMALL |
582 | 981 ; 6. retain the new display positions |
982 movff lo,hi | |
983 movff up,WREG | |
984 addwf hi,F | |
985 movff lo,xLO | |
986 movff hi,xHI | |
987 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
988 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
989 TFT_dive_compass_c_mk: |
582 | 990 ; Common task to draw center line and marker |
991 ; until a proper implementation make it simple: | |
992 rcall TFT_dive_compass_mk | |
628 | 993 TFT_dive_compass_c: |
582 | 994 movlw color_yellow |
995 WIN_BOX_COLOR dm_custom_compass_tick_top_top, dm_custom_compass_tick_bot_bot,.80,.81 ; center line in yellow | |
996 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
997 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
998 TFT_dive_compass_mk: |
582 | 999 ; draw the bearing on the screen if visible and if we just put something over it |
628 | 1000 btfss compass_bearing_set ; bearing set? |
1001 return ; NO - done | |
1002 btfss compass_bearing_vis ; YES - bearing visible? | |
1003 return ; NO - bearing set but not visible, done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1004 |
582 | 1005 ; save lo/hi from trashing |
623 | 1006 MOVII mpr,xA |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1007 |
582 | 1008 ; did we just update the marker's position? |
1009 ; DD.......DD | |
1010 ; CM+2>=DD(old) or CM-2<=DD | |
1011 ; ToDo | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1012 |
582 | 1013 btfss compass_bearing_ahd |
1014 bra TFT_dive_compass_mk_rear | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1015 ;TFT_dive_compass_mk_front: |
582 | 1016 clrf lo |
1017 movff xCM,lo | |
628 | 1018 bsf compass_show_cardinal ; set=green marker |
582 | 1019 rcall TFT_dive_compass_mk_print |
623 | 1020 bcf compass_show_cardinal |
582 | 1021 bra TFT_dive_compass_mk_end |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1022 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1023 TFT_dive_compass_mk_rear: |
582 | 1024 clrf lo |
1025 movff xCM,lo | |
628 | 1026 bcf compass_show_cardinal ; set=red marker |
582 | 1027 rcall TFT_dive_compass_mk_print |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1028 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1029 TFT_dive_compass_mk_end: |
623 | 1030 MOVII xA,mpr |
582 | 1031 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1032 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1033 TFT_dive_compass_mk_print: |
582 | 1034 movlw d'1' |
1035 cpfsgt lo | |
628 | 1036 bra TFT_dive_compass_mk_print_2 ; lo <= 1, skip the first line |
582 | 1037 movlw d'2' |
1038 subwf lo,0 | |
1039 ; movff WREG,win_leftx2 | |
1040 rcall TFT_dive_compass_mk_print_3 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1041 TFT_dive_compass_mk_print_2: |
582 | 1042 ; save hi/lo |
623 | 1043 MOVII mpr,divA |
582 | 1044 ; clear the middle of the bearing marker |
1045 movff lo,hi | |
1046 movlw d'2' | |
1047 addwf lo,1 | |
1048 rcall TFT_dive_compass_clr_label | |
1049 ; restore hi/lo | |
623 | 1050 MOVII divA,mpr |
582 | 1051 ; print a dot on the middle |
623 | 1052 movf lo,W |
582 | 1053 rcall TFT_dive_compass_mk_print_dot |
1054 ; finally print the right marker line | |
1055 movlw d'2' | |
1056 addwf lo,0 | |
1057 ; rcall TFT_dive_compass_mk_print_3 | |
1058 ; return | |
257
5dd0f39d05d4
minor speed and size improvements for the compass routine
heinrichsweikamp
parents:
256
diff
changeset
|
1059 TFT_dive_compass_mk_print_3: |
582 | 1060 movwf win_leftx2 |
1061 movlw dm_custom_compass_label_row | |
1062 movwf win_top | |
1063 movlw dm_custom_compass_label_height-.2 | |
1064 movwf win_height | |
1065 bra TFT_dive_compass_mk_print_4 | |
264
9dbdb060d44c
Fix compass ruler's missing bottom ticks; Clear between the bearing marker lines and draw a dot.
janos_kovacs <kovjanos@gmail.com>
parents:
259
diff
changeset
|
1066 TFT_dive_compass_mk_print_dot: |
582 | 1067 movwf win_leftx2 |
1068 movlw dm_custom_compass_label_row + .9 | |
1069 movwf win_top | |
1070 movlw d'4' | |
1071 movwf win_height | |
264
9dbdb060d44c
Fix compass ruler's missing bottom ticks; Clear between the bearing marker lines and draw a dot.
janos_kovacs <kovjanos@gmail.com>
parents:
259
diff
changeset
|
1072 TFT_dive_compass_mk_print_4: |
582 | 1073 movlw .158 |
1074 cpfslt win_leftx2 | |
1075 bra TFT_dive_compass_mk_print_5 | |
1076 movlw d'2' | |
623 | 1077 movwf win_bargraph |
582 | 1078 movwf win_width+0 |
1079 clrf win_width+1 | |
1080 movlw color_green | |
623 | 1081 btfss compass_show_cardinal |
582 | 1082 movlw color_red |
1083 call TFT_set_color | |
1084 call TFT_box | |
371 | 1085 TFT_dive_compass_mk_print_5: |
582 | 1086 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1087 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1088 TFT_dive_compass_clr_label: |
582 | 1089 movlw dm_custom_compass_label_row-.2 ; set top & height |
623 | 1090 movwf win_top |
582 | 1091 movlw dm_custom_compass_label_height+.2 |
623 | 1092 movwf win_height |
582 | 1093 rcall TFT_dive_compass_clear |
1094 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1095 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1096 TFT_dive_compass_clr_ruler: |
582 | 1097 ; top tick |
1098 movlw dm_custom_compass_tick_top_top ; set top & height | |
623 | 1099 movwf win_top |
582 | 1100 movlw dm_custom_compass_tick_height |
623 | 1101 movwf win_height |
582 | 1102 rcall TFT_dive_compass_clear |
1103 ;bottom tick | |
1104 movlw dm_custom_compass_tick_bot_top ; set top & height | |
623 | 1105 movwf win_top |
582 | 1106 movlw dm_custom_compass_tick_height |
623 | 1107 movwf win_height |
582 | 1108 ; rcall TFT_dive_compass_clear |
1109 ; return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1110 TFT_dive_compass_clear: |
582 | 1111 ; we receive RM in lo and DD in hi |
1112 ; calculate width = RM-D | |
623 | 1113 movf hi,W |
582 | 1114 subwf lo,W |
623 | 1115 bz TFT_dive_compass_clear3 ; do nothing if there is nothing to do |
582 | 1116 movwf win_width+0 ; RM-DD |
1117 movwf win_bargraph | |
1118 clrf win_width+1 | |
1119 movlw .1 | |
1120 cpfsgt win_width+0 | |
623 | 1121 bra TFT_dive_compass_clear3 ; do not clear a single pixel (or less) |
582 | 1122 movff hi,win_leftx2 |
1123 movlw color_black | |
1124 call TFT_set_color | |
1125 call TFT_box | |
370 | 1126 TFT_dive_compass_clear3: |
582 | 1127 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1128 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1129 tft_compass_cardinal: |
623 | 1130 btfsc hi,0 ; heading > 255° ? |
1131 bra tft_compass_cardinal2 ; YES - must be W, NW or N | |
1132 ; NO - must be W, SW, S, SE, E, NE or N | |
582 | 1133 movlw .23 |
1134 subwf lo,W | |
1135 btfss STATUS,C | |
1136 bra tft_compass_cardinal_N | |
1137 movlw .68 | |
1138 subwf lo,W | |
1139 btfss STATUS,C | |
1140 bra tft_compass_cardinal_NE | |
1141 movlw .113 | |
1142 subwf lo,W | |
1143 btfss STATUS,C | |
1144 bra tft_compass_cardinal_E | |
1145 movlw .158 | |
1146 subwf lo,W | |
1147 btfss STATUS,C | |
1148 bra tft_compass_cardinal_SE | |
1149 movlw .203 | |
1150 subwf lo,W | |
1151 btfss STATUS,C | |
1152 bra tft_compass_cardinal_S | |
1153 movlw .248 | |
1154 subwf lo,W | |
1155 btfss STATUS,C | |
1156 bra tft_compass_cardinal_SW | |
1157 bra tft_compass_cardinal_W | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1158 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1159 tft_compass_cardinal2: |
582 | 1160 movlw .37 |
1161 subwf lo,W | |
1162 btfss STATUS,C | |
1163 bra tft_compass_cardinal_W | |
1164 movlw .82 | |
1165 subwf lo,W | |
1166 btfss STATUS,C | |
1167 bra tft_compass_cardinal_NW | |
1168 ; bra tft_compass_cardinal_N | |
1169 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1170 tft_compass_cardinal_N: |
582 | 1171 STRCAT_TEXT tN |
1172 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1173 tft_compass_cardinal_NE: |
582 | 1174 STRCAT_TEXT tNE |
1175 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1176 tft_compass_cardinal_E: |
582 | 1177 STRCAT_TEXT tE |
1178 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1179 tft_compass_cardinal_SE: |
582 | 1180 STRCAT_TEXT tSE |
1181 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1182 tft_compass_cardinal_S: |
582 | 1183 STRCAT_TEXT tS |
1184 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1185 tft_compass_cardinal_SW: |
582 | 1186 STRCAT_TEXT tSW |
1187 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1188 tft_compass_cardinal_W: |
582 | 1189 STRCAT_TEXT tW |
1190 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1191 tft_compass_cardinal_NW: |
582 | 1192 STRCAT_TEXT tNW |
1193 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1194 |
628 | 1195 ;----------------------------------------------------------------------------- |
623 | 1196 |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1197 compass_heading_common: |
623 | 1198 btfss compass_enabled ; compass enabled? |
628 | 1199 bra compass_heading_common_zero ; NO |
623 | 1200 |
628 | 1201 ; Get an averaged new heading |
623 | 1202 movlw compass_averaging ; number of averaging cycles |
1203 movwf up ; initialize loop counter | |
628 | 1204 compass_heading_common_1: |
623 | 1205 call I2C_RX_compass ; test compass |
1206 call I2C_RX_accelerometer ; test accelerometer | |
1207 call compass_filter ; filter raw compass + accelerometer readings | |
1208 decfsz up,F ; decrement loop counter, done? | |
628 | 1209 bra compass_heading_common_1 ; NO - loop |
623 | 1210 |
628 | 1211 call compass ; do compass correction (C-code) |
623 | 1212 banksel common ; back to bank common |
1213 | |
628 | 1214 ; Check for calibration and change |
1215 MOVII compass_heading_shown,sub_a ; transfer shown heading to sub_a | |
1216 MOVII compass_heading_new, sub_b ; transfer new heading to sub_b | |
623 | 1217 |
1218 btfsc sub_b+1,7 ; valid compass calibration? | |
628 | 1219 bra compass_heading_common_zero ; NO |
1220 | |
1221 movf sub_a+0,W ; get shown heading, low byte | |
1222 cpfseq sub_b+0 ; compare with new heading, low byte, equal? | |
1223 bra compass_heading_common_2 ; NO - not equal | |
1224 movf sub_a+1,W ; get shown heading, high byte | |
1225 cpfseq sub_b+1 ; compare with new heading, high byte, equal? | |
1226 bra compass_heading_common_2 ; NO - not equal | |
1227 return ; YES - done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1228 |
628 | 1229 compass_heading_common_2: |
1230 ; turn both headings such that compass_heading_new points to 0° | |
1231 call subU16 ; sub_c = compass_heading_shown - compass_heading_new | |
1232 btfss neg_flag ; was compass_heading_new in 1st halve? | |
1233 bra compass_heading_common_3 ; YES - check where compass_heading_shown is now | |
1234 MOVLI .360, sub_a ; NO - overturned, need to turn back to match 360° | |
1235 MOVII sub_c,sub_b ; - move overturned compass_heading_new to sub_b | |
1236 call subU16 ; - sub_c = angle between overturned compass_heading_shown and 360° | |
1237 compass_heading_common_3: | |
1238 ; check if turned compass_heading_shown is in 1st or 2nd halve | |
1239 MOVII sub_c,sub_a ; sub_a = turned compass_heading_shown | |
1240 MOVLI .180, sub_b ; sub_b = begin of 2nd halve | |
1241 call cmpU16 ; check (turned compass_heading_shown) - 180° | |
1242 btfss neg_flag ; result negative? | |
1243 bra compass_heading_common_5 ; NO - in 2nd halve, increment towards compass_heading_new | |
1244 ;bra compass_heading_common_4 ; YES - in 1st halve, decrement towards compass_heading_new | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1245 |
628 | 1246 compass_heading_common_4: |
1247 ; decrement compass_heading_shown towards compass_heading_new | |
1248 rcall compass_heading_stepsize_2 ; calculate step size and put it into sub_b | |
1249 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a | |
1250 call subU16 ; decrement heading: sub_c = compass_heading_shown - step size | |
1251 btfss neg_flag ; did an under-run occur? | |
1252 bra compass_heading_common_6 ; NO - store result | |
1253 MOVLI .360, sub_a ; YES - wrap around 360° | |
1254 MOVII sub_c,sub_b ; - transfer decrement result to sub_b | |
1255 call subU16 ; - wrap decrement result around | |
1256 bra compass_heading_common_6 ; - store wrapped result | |
1257 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1258 |
628 | 1259 compass_heading_common_5: |
1260 ; increment compass_heading_shown towards compass_heading_new | |
1261 rcall compass_heading_stepsize_1 ; calculate step size and put it into sub_b | |
1262 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a | |
1263 call addU16 ; increment heading: sub_c = compass_heading_shown + step size | |
1264 MOVII sub_c,sub_a ; transfer increment result to sub_a | |
1265 MOVLI .360, sub_b ; load wrap-around threshold | |
1266 call subU16 ; calculate if over-run occurred | |
1267 btfss neg_flag ; did an over-run occur? | |
1268 bra compass_heading_common_6 ; YES - store already wrapped-around result | |
1269 MOVII sub_a,sub_c ; NO - retrieve former straight increment result | |
1270 bra compass_heading_common_6 ; - store wrapped result | |
1271 | |
1272 compass_heading_common_zero: | |
1273 CLRI sub_c ; set heading to 0° | |
1274 ;bra compass_heading_common_6 ; store heading | |
1275 | |
1276 compass_heading_common_6: | |
1277 MOVII sub_c,compass_heading_shown ; store new shown heading | |
1278 return ; done | |
1279 | |
1280 compass_heading_stepsize_1: | |
1281 ; turn heading difference (180...359) into a step size | |
1282 MOVLI .360, sub_a ; load 360° | |
1283 MOVII sub_c,sub_b ; load difference | |
1284 call subU16 ; sub_c = 360 - difference (i.e. 1...180 now) | |
1285 compass_heading_stepsize_2: | |
1286 ; turn heading difference (1...180) into a step size | |
1287 bcf STATUS,C ; clear carry | |
1288 rrcf sub_c+0 ; heading difference /= 2 | |
1289 bcf STATUS,C ; clear carry | |
1290 rrcf sub_c+0 ; heading difference /= 2, total /= 4 now | |
1291 incf sub_c+0,f ; final += 1 to have one increment / decrement at least | |
1292 MOVII sub_c,sub_b ; transfer result to sub_b | |
1293 return | |
1294 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1295 |
623 | 1296 ENDIF ; _compass |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1297 |
582 | 1298 END |