Mercurial > public > hwos_code
comparison src/compass_ops.asm @ 656:8af5aefbcdaf default tip
Update to 3.31 beta
| author | heinrichsweikamp |
|---|---|
| date | Thu, 27 Nov 2025 18:32:58 +0100 |
| parents | 75e90cd0c2c3 |
| children |
comparison
equal
deleted
inserted
replaced
| 655:c7b7b8a358cd | 656:8af5aefbcdaf |
|---|---|
| 23 | 23 |
| 24 IFDEF _compass | 24 IFDEF _compass |
| 25 | 25 |
| 26 | 26 |
| 27 ; local flags | 27 ; local flags |
| 28 #DEFINE compass_show_cardinal compass_flags,0 ; =1: show the cardinal (N, NE, E, ...) | 28 ;#DEFINE compass_show_cardinal compass_flags,0 ; =1: show the cardinal (N, NE, E, ...) |
| 29 #DEFINE compass_bearing_eq compass_flags,1 ; =1: bearing is in direction, do not show << or >> | 29 ;#DEFINE compass_bearing_eq compass_flags,1 ; =1: bearing is in direction, do not show << or >> |
| 30 #DEFINE compass_bearing_lft compass_flags,2 ; =1: bearing is to the left/<<, =0: to the right/>> | 30 ;#DEFINE compass_bearing_lft compass_flags,2 ; =1: bearing is to the left/<<, =0: to the right/>> |
| 31 #DEFINE compass_bearing_vis compass_flags,3 ; =1: bearing is visible (either ahead or behind/-180°) | 31 ;#DEFINE compass_bearing_vis compass_flags,3 ; =1: bearing is visible (either ahead or behind/-180°) |
| 32 #DEFINE compass_bearing_ahd compass_flags,4 ; =1: bearing is ahead, =0: behind | 32 ;#DEFINE compass_bearing_ahd compass_flags,4 ; =1: bearing is ahead, =0: behind |
| 33 ; compass_flags,5 ; --- unused | 33 ;; compass_flags,5 ; --- unused |
| 34 ; compass_flags,6 ; --- unused | 34 ;; compass_flags,6 ; --- unused |
| 35 ; compass_flags,7 ; --- unused | 35 ;; compass_flags,7 ; --- unused |
| 36 | 36 |
| 37 | 37 |
| 38 ; Make sure symbols from the .inc are available to the C code: | 38 ; Make sure symbols from the .inc are available to the C code: |
| 39 | 39 |
| 40 ; filtered data - Compass | 40 ; filtered data - Compass |
| 220 bsf block_sensor_interrupt ; disable sensor interrupts | 220 bsf block_sensor_interrupt ; disable sensor interrupts |
| 221 call I2C_sleep_compass ; stop compass | 221 call I2C_sleep_compass ; stop compass |
| 222 call TFT_ClearScreen ; clear the screen | 222 call TFT_ClearScreen ; clear the screen |
| 223 ; Mask | 223 ; Mask |
| 224 WIN_STD .16,.0 ; set position | 224 WIN_STD .16,.0 ; set position |
| 225 FONT_COLOR color_greenish ; set font color | 225 FONT_COLOR color_green ; set font color |
| 226 STRCPY_TEXT_PRINT tCompassCalibration | 226 STRCPY_TEXT_PRINT tCompassCalibration |
| 227 btfss switch_right2 ; wait until button (with a moving magnet in some OSTC!) is released | 227 btfss switch_right2 ; wait until button (with a moving magnet in some OSTC!) is released |
| 228 bra $-2 | 228 bra $-2 |
| 229 | 229 |
| 230 ; WIN_SMALL .0,.215 | 230 ; WIN_SMALL .0,.215 |
| 475 ; Mask for Compass in Surface Mode | 475 ; Mask for Compass in Surface Mode |
| 476 ; | 476 ; |
| 477 global TFT_surface_compass_mask | 477 global TFT_surface_compass_mask |
| 478 TFT_surface_compass_mask: | 478 TFT_surface_compass_mask: |
| 479 WIN_SMALL surf_compass_mask_column,surf_compass_mask_row | 479 WIN_SMALL surf_compass_mask_column,surf_compass_mask_row |
| 480 FONT_COLOR_MEMO ; set font color | 480 FONT_COLOR color_green ; set font color |
| 481 STRCPY_TEXT_PRINT tHeading ; print "Heading:" | 481 STRCPY_TEXT_PRINT tHeading ; print "Heading:" |
| 482 return ; done | 482 return ; done |
| 483 | 483 |
| 484 | 484 |
| 485 ;----------------------------------------------------------------------------- | 485 ;----------------------------------------------------------------------------- |
| 528 | 528 |
| 529 | 529 |
| 530 ;----------------------------------------------------------------------------- | 530 ;----------------------------------------------------------------------------- |
| 531 ; Mask for Compass in Dive Mode | 531 ; Mask for Compass in Dive Mode |
| 532 ; | 532 ; |
| 533 global TFT_dive_compass_mask ; draws the white box around the heading tape | 533 global TFT_dive_compass_mask |
| 534 TFT_dive_compass_mask: | 534 TFT_dive_compass_mask: |
| 535 WIN_FRAME_STD dm_custom_compass_graph_row, dm_custom_compass_graph_row+dm_custom_compass_graph_height, .0, .159 | 535 FONT_COLOR_MASK ; select color |
| 536 WIN_TINY dm_custom_compass_mask_column,dm_custom_compass_mask_row | |
| 537 STRCPY_TEXT_PRINT tCompassMenu ; print label | |
| 536 return | 538 return |
| 537 | 539 |
| 538 | 540 |
| 539 ;----------------------------------------------------------------------------- | 541 ;----------------------------------------------------------------------------- |
| 540 ; Compass Display in Dive Mode | 542 ; Compass Display in Dive Mode |
| 541 ; | 543 ; |
| 542 global TFT_dive_compass_heading | 544 global TFT_dive_compass_heading |
| 543 TFT_dive_compass_heading: | 545 TFT_dive_compass_heading: |
| 544 call compass_heading_common ; compute heading | 546 call compass_heading_common ; compute heading |
| 545 | 547 ; Text output |
| 546 ; ; ### for development only, hard-coding the bearing ### | 548 FONT_COLOR_MEMO ; set default / dive-mode standard color |
| 547 ; ; 244° : SW - W | 549 WIN_MEDIUM dm_custom_compass_head_column, dm_custom_compass_head_row |
| 548 ; MOVLI .244,xA ; xA used as temp | 550 MOVII compass_heading_shown,mpr ; get heading to be shown |
| 549 ; MOVII xA,compass_bearing ; compass_bearing is stored in bank isr_backup | 551 bsf leading_zeros |
| 550 | 552 output_999 ; print bearing |
| 551 FONT_SIZE FT_SMALL ; set font size | 553 bcf leading_zeros |
| 552 MOVII compass_heading_shown,xA ; get heading | 554 PRINT ; dump to screen |
| 553 ; 160° viewing angle: add +360 offset if xA <= 292 for non-negative scale | 555 WIN_STD dm_custom_compass_unit_column, dm_custom_compass_unit_row |
| 554 MOVLI .292,sub_a | 556 STRCAT "°" |
| 555 MOVII xA, sub_b | 557 call tft_compass_cardinal ; append cardinal buffer |
| 556 call subU16 ; sub_c = sub_a - sub_b | 558 PRINT |
| 557 btfsc neg_flag ; xA > 292 ? | 559 ; shall show bearing? |
| 558 bra TFT_dive_compass_heading_1 ; YES | |
| 559 ADDLI .360,xA ; NO - add offset | |
| 560 TFT_dive_compass_heading_1: | |
| 561 SUBLI .80,xA ; subtract 80 (left pixel offset from the center) | |
| 562 MOVII xA,xRD ; save result to xRD | |
| 563 ADDLI .160,xA ; add 160 (display with in pixels) | |
| 564 MOVII xA,xRDr ; save result to xRDr | |
| 565 | |
| 566 btfss compass_bearing_set ; is a bearing set? | 560 btfss compass_bearing_set ; is a bearing set? |
| 567 bra TFT_dive_compass_ruler ; NO - skip next calculations | 561 return ; NO - done |
| 568 MOVII xRDr,sub_a ; YES - calculate xRD180 = xRDr - 180 | 562 ; show bearing |
| 569 MOVLI .180,sub_b | 563 WIN_SMALL dm_compass_bear_column,dm_compass_bear_row |
| 570 call subU16 ; sub_c = sub_a - sub_b | 564 FONT_COLOR color_yellow ; set font color |
| 571 MOVII sub_c,xRD180 | 565 MOVII compass_bearing,mpr ; get bearing |
| 572 | 566 goto TFT_compass_helper ; show number and cardinal and return |
| 573 TFT_dive_compass_bearing_1: | |
| 574 ; calculate bearing position and visibility (ahead or behind) | |
| 575 bcf compass_bearing_vis ; default is not-visible | |
| 576 bcf compass_bearing_ahd ; default is behind | |
| 577 MOVII compass_bearing,xA | |
| 578 ADDLI .360,xA ; calculate the bearing virtual display offset | |
| 579 MOVII xA,divA ; save it for reuse for upper/lower turns and ahead/behind checks | |
| 580 | |
| 581 ; check if bearing is ahead | |
| 582 MOVII divA,sub_a ; load the bearing offset into sub_a | |
| 583 MOVII xRD, sub_b ; load the display offset back to sub_b | |
| 584 rcall TFT_dive_compass_bearing_ap | |
| 585 btfsc compass_bearing_vis ; bearing visible? | |
| 586 bra TFT_dive_compass_bearing_dir; YES | |
| 587 | |
| 588 ; check if it is ahead with an upper turn | |
| 589 MOVII divA,sub_a ; load the bearing offset into sub_a | |
| 590 MOVII xRD, sub_b ; load the display offset back to sub_b | |
| 591 ADDLI .360,sub_b | |
| 592 rcall TFT_dive_compass_bearing_ap | |
| 593 btfsc compass_bearing_vis ; bearing visible? | |
| 594 bra TFT_dive_compass_bearing_dir; YES | |
| 595 | |
| 596 ; check if it is ahead with a lower turn | |
| 597 MOVII divA,sub_a ; load the bearing offset into sub_a | |
| 598 ADDLI .360,sub_a | |
| 599 MOVII xRD, sub_b ; load the display offset back to sub_b | |
| 600 rcall TFT_dive_compass_bearing_ap | |
| 601 btfsc compass_bearing_vis ; bearing visible? | |
| 602 bra TFT_dive_compass_bearing_dir; YES | |
| 603 | |
| 604 ; marker is not ahead of us, check if it is behind of us | |
| 605 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display | |
| 606 MOVII xRD180,sub_a ; load the display offset back to sub_a | |
| 607 MOVII divA, sub_b ; load the marker's offset into sub_b | |
| 608 rcall TFT_dive_compass_bearing_bp | |
| 609 btfsc compass_bearing_vis ; bearing behind of us? | |
| 610 bra TFT_dive_compass_bearing_dir; YES | |
| 611 | |
| 612 ; check if it is behind with the upper turn | |
| 613 MOVII xRD180,sub_a | |
| 614 MOVII divA, sub_b | |
| 615 ADDLI .360, sub_b | |
| 616 rcall TFT_dive_compass_bearing_bp | |
| 617 btfsc compass_bearing_vis ; bearing behind of us? | |
| 618 bra TFT_dive_compass_bearing_dir; YES | |
| 619 | |
| 620 ; check if it is behind with the lower turn | |
| 621 MOVII xRD180,sub_a | |
| 622 ADDLI .360, sub_a | |
| 623 MOVII divA, sub_b ; load the marker's offset into sub_b | |
| 624 rcall TFT_dive_compass_bearing_bp | |
| 625 bra TFT_dive_compass_bearing_dir | |
| 626 | |
| 627 TFT_dive_compass_bearing_ap: | |
| 628 ; xCM received in sub_a | |
| 629 ; xRD received in sub_b | |
| 630 ; 1/a. check if it's viewable from the left side | |
| 631 call subU16 ; sub_c = sub_a - sub_b | |
| 632 btfsc neg_flag ; xRD > divA ? | |
| 633 return ; NO - done | |
| 634 MOVII sub_c,xC ; YES - store the RO=RP-RD for drawing | |
| 635 ; 1/b. check if it's viewable from the right side | |
| 636 ADDLI .2,sub_a ; avoid thin mess on the side of the display | |
| 637 ADDLI .158,sub_b ; load the display offset right side into sub_b | |
| 638 call subU16 ; sub_c = sub_a - sub_b | |
| 639 btfss neg_flag ; xRDr > xA(+2) ? | |
| 640 return ; NO - done | |
| 641 ; YES - print the bearing lines on the screen | |
| 642 movff xC+0,xCM | |
| 643 bsf compass_bearing_vis ; set visible | |
| 644 bsf compass_bearing_ahd ; set ahead | |
| 645 return ; done | |
| 646 | |
| 647 TFT_dive_compass_bearing_bp: | |
| 648 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display | |
| 649 ; the marker's offset received in sub_b | |
| 650 ; the xRD180 display offset received in sub_a | |
| 651 ; xRD180 - xCM | |
| 652 call subU16 ; sub_c = sub_a - sub_b | |
| 653 btfsc neg_flag ; CM > xRD180 ? | |
| 654 return ; NO - not on screen, done | |
| 655 ; YES - check 160 - (X) | |
| 656 MOVLI .158, sub_a ; 158 to avoid thin mess on the side of the display | |
| 657 MOVII sub_c,sub_b | |
| 658 call subU16 ; sub_c = sub_a - sub_b | |
| 659 btfsc neg_flag ; X > 160 ? | |
| 660 return ; NO - not on screen, done | |
| 661 ; check if not overflow - this sounds like a double check... | |
| 662 tstfsz sub_c+1 ; high byte = 0 ? | |
| 663 return ; NO - sub_c must be > 160 then, done | |
| 664 movlw d'158' ; YES - load a 158 | |
| 665 cpfslt sub_c+0 ; - low byte < 158 ? | |
| 666 return ; NO - done | |
| 667 movff sub_c+0,xCM ; YES - print the bearing lines on the screen | |
| 668 bsf compass_bearing_vis ; - flag to show bearing lines | |
| 669 return ; - done | |
| 670 | |
| 671 TFT_dive_compass_bearing_dir: | |
| 672 ; check if bearing to heading, and calculate the direction | |
| 673 bcf compass_bearing_eq | |
| 674 btfss compass_bearing_vis | |
| 675 bra TFT_dive_compass_bearing_lr | |
| 676 btfss compass_bearing_ahd | |
| 677 bra TFT_dive_compass_bearing_lr | |
| 678 movff xCM,xA+0 | |
| 679 movlw d'80' | |
| 680 cpfseq xA+0 | |
| 681 bra TFT_dive_compass_bearing_lr | |
| 682 bsf compass_bearing_eq | |
| 683 bra TFT_dive_compass_ruler ; bearing points to heading, no signs are required, go to the ruler | |
| 684 | |
| 685 TFT_dive_compass_bearing_lr: | |
| 686 ; get the bearing virtual display offset | |
| 687 MOVII compass_bearing,xA | |
| 688 ; xA = xA > 292 ? xA : xA+360 | |
| 689 MOVLI .292,sub_a | |
| 690 MOVII xA, sub_b | |
| 691 call subU16 ; sub_c = sub_a - sub_b | |
| 692 btfsc neg_flag ; xA > 292 ? | |
| 693 bra TFT_dive_compass_bearing_lr_1; YES | |
| 694 ADDLI .360,xA ; NO - add 360 | |
| 695 | |
| 696 TFT_dive_compass_bearing_lr_1: | |
| 697 ; 1. calculate whether bearing is to left or to right | |
| 698 bsf compass_bearing_lft ; to the left by default | |
| 699 ; xC: save center value to compare the direction to front value | |
| 700 MOVII xA,xC | |
| 701 ; xB: we need the left side for comparison... left = -180 | |
| 702 MOVII xA, sub_a | |
| 703 MOVLI .180,sub_b | |
| 704 call subU16 ; sub_c = sub_a - sub_b | |
| 705 MOVII sub_c,xB ; xB has the left side of the 180° distance center | |
| 706 ; xA = xRD > (xC+100) ? RD-280 : xRD+80 | |
| 707 MOVII xC, sub_a | |
| 708 ADDLI .100,sub_a | |
| 709 MOVII xRD, sub_b | |
| 710 call subU16 ; sub_c = sub_a - sub_b | |
| 711 btfsc neg_flag ; xRD > xC + 100 ? | |
| 712 bra TFT_dive_compass_bearing_lr_2; YES - xA = xRD - 280 | |
| 713 ; NO - xA = xRD + 80 | |
| 714 MOVII xRD,xA | |
| 715 ADDLI .80,xA | |
| 716 bra TFT_dive_compass_bearing_lr_c | |
| 717 | |
| 718 TFT_dive_compass_bearing_lr_2: | |
| 719 MOVII xRD,sub_a | |
| 720 MOVLI .280,sub_b | |
| 721 call subU16 ; sub_c = sub_a - sub_b | |
| 722 MOVII sub_c,xA | |
| 723 ;bra TFT_dive_compass_bearing_lr_c | |
| 724 | |
| 725 TFT_dive_compass_bearing_lr_c: | |
| 726 ; xB < xA < xC => right, otherwise left (default) | |
| 727 MOVII xA,sub_b | |
| 728 MOVII xB,sub_a | |
| 729 call subU16 ; sub_c = sub_a - sub_b | |
| 730 btfss neg_flag ; xA > xB ? | |
| 731 bra TFT_dive_compass_ruler ; NO - xB >= xA, keep default left | |
| 732 MOVII xA,sub_a | |
| 733 MOVII xC,sub_b | |
| 734 call subU16 ; sub_c = sub_a - sub_b | |
| 735 btfss neg_flag ; xC > xA ? | |
| 736 bra TFT_dive_compass_ruler ; NO - xA >= xC, keep default left | |
| 737 bcf compass_bearing_lft | |
| 738 | |
| 739 TFT_dive_compass_ruler: | |
| 740 ; calculate mod15 for the ticks | |
| 741 MOVII xRD,xA | |
| 742 MOVLI .15,xB | |
| 743 call div16x16 ; xA/xB=xC with xA+0 as remainder | |
| 744 ; check the remainder | |
| 745 movlw d'0' | |
| 746 cpfsgt xA+0 ; mod15 > 0 ? | |
| 747 bra TFT_dive_compass_ruler_1 ; NO - RM = 0 | |
| 748 ; YES - RM = 15 - RDmod15 | |
| 749 movlw d'15' | |
| 750 subfwb xA+0,F | |
| 751 TFT_dive_compass_ruler_1: | |
| 752 movff xA+0,lo ; xA+0 holds the RM, store it to 'lo' | |
| 753 clrf hi ; initialize DD to zero, store it to 'hi' | |
| 754 | |
| 755 TFT_dive_compass_ruler_loop: | |
| 756 ; 1. check if we run out of the display | |
| 757 movlw d'159' ; looks like 159 works because TFT_box limits the display | |
| 758 cpfslt lo,1 | |
| 759 bra TFT_dive_compass_ruler_lend ; xRM >= W | |
| 760 ; 2. Clear the tick area from DD to RM - in segments to avoid blinking | |
| 761 ; don't do a clear if we are at 0 (zero) otherwise it will blink | |
| 762 ; because of the width underflow | |
| 763 movlw d'0' | |
| 764 cpfsgt lo,1 | |
| 765 bra TFT_dive_compass_ruler_loop_zz | |
| 766 rcall TFT_dive_compass_clr_ruler | |
| 767 TFT_dive_compass_ruler_loop_zz: | |
| 768 ; 3. Draw the markers @ RM | |
| 769 ; we receive RM in lo and DD in hi | |
| 770 movlw d'2' | |
| 771 movwf win_bargraph ; set with of ticks | |
| 772 movwf win_width+0 | |
| 773 clrf win_width+1 | |
| 774 movff lo,win_leftx2 ; 0..159 | |
| 775 movlw dm_custom_compass_tick_top_top | |
| 776 movwf win_top ; set position for upper ticks | |
| 777 movlw dm_custom_compass_tick_height | |
| 778 movwf win_height ; set hight of ticks | |
| 779 movf pallet_color_memo,W ; select color | |
| 780 BOX_COLOR ; draw tick | |
| 781 movlw dm_custom_compass_tick_bot_top | |
| 782 movwf win_top ; set position for lower ticks | |
| 783 movlw dm_custom_compass_tick_height | |
| 784 movwf win_height ; set hight of ticks | |
| 785 movf pallet_color_memo,W ; select color | |
| 786 BOX_COLOR ; draw tick | |
| 787 ; 4. If D < 82 and RM > 79: means we put something over the center line, | |
| 788 ; so redraw the center line | |
| 789 movlw d'82' | |
| 790 cpfslt hi,1 | |
| 791 bra TFT_dive_compass_ruler_loop_zz2 | |
| 792 movlw d'79' | |
| 793 cpfsgt lo,1 | |
| 794 bra TFT_dive_compass_ruler_loop_zz2 | |
| 795 ; enough to print center line as bearing marker is not in the ticker area | |
| 796 rcall TFT_dive_compass_c ; draw center line in yellow | |
| 797 TFT_dive_compass_ruler_loop_zz2: | |
| 798 ; 5. set D = RM + 2 : position after the 2px tick | |
| 799 movff lo,hi | |
| 800 movlw d'2' | |
| 801 addwf hi,F | |
| 802 ; 6. set RM = RM + 15 : position to the next tick | |
| 803 movlw d'15' | |
| 804 addwf lo,F | |
| 805 ; 7. loop | |
| 806 bra TFT_dive_compass_ruler_loop | |
| 807 | |
| 808 TFT_dive_compass_ruler_lend: ; loop end | |
| 809 ; 8. clear the rest of the tick area if D < 160 | |
| 810 movlw d'160' | |
| 811 cpfslt hi | |
| 812 bra TFT_dive_compass_labels ; D >= W | |
| 813 ; 9. position left to end of display to clear the remaining area | |
| 814 movlw d'159' | |
| 815 movwf lo | |
| 816 ; 10. clear it | |
| 817 rcall TFT_dive_compass_clr_ruler | |
| 818 | |
| 819 TFT_dive_compass_labels: | |
| 820 ; done with the compass ruler, put the labels on the screen | |
| 821 FONT_COLOR_MEMO ; set dive-mode standard color | |
| 822 clrf hi ; hi stores the display position | |
| 823 movff hi,xHI ; bank-safe clear of xHI | |
| 824 clrf lo ; lo stores the last item's display position | |
| 825 movff lo,xLO ; bank-safe clear of xLO | |
| 826 MOVLI .219,sub_a ; position of the cardinal | |
| 827 MOVII xRD, sub_b ; get the RD back to sub_b | |
| 828 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 829 btfss compass_show_cardinal ; shall show cardinal? | |
| 830 bra dcr_1 ; NO | |
| 831 STRCPY_TEXT_PRINT tSW ; YES - print it | |
| 832 dcr_1: | |
| 833 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 834 MOVLI .267,sub_a ; position of the cardinal | |
| 835 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 836 btfss compass_show_cardinal ; shall show cardinal? | |
| 837 bra dcr_2 ; NO | |
| 838 STRCPY_TEXT_PRINT tW ; YES - print it | |
| 839 dcr_2: | |
| 840 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 841 MOVLI .309,sub_a ; position of the cardinal | |
| 842 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 843 btfss compass_show_cardinal ; shall show cardinal? | |
| 844 bra dcr_3 ; NO | |
| 845 STRCPY_TEXT_PRINT tNW ; YES - print it | |
| 846 dcr_3: | |
| 847 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 848 MOVLI .358,sub_a ; position of the cardinal | |
| 849 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 850 btfss compass_show_cardinal ; shall show cardinal? | |
| 851 bra dcr_4 ; NO | |
| 852 STRCPY_TEXT_PRINT tN ; YES - print it | |
| 853 dcr_4: | |
| 854 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 855 MOVLI .399,sub_a ; position of the cardinal | |
| 856 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 857 btfss compass_show_cardinal ; shall show cardinal? | |
| 858 bra dcr_5 ; NO | |
| 859 STRCPY_TEXT_PRINT tNE ; YES - print it | |
| 860 dcr_5: | |
| 861 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 862 MOVLI .448,sub_a ; position of the cardinal | |
| 863 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 864 btfss compass_show_cardinal ; shall show cardinal? | |
| 865 bra dcr_6 ; NO | |
| 866 STRCPY_TEXT_PRINT tE ; YES - print it | |
| 867 dcr_6: | |
| 868 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 869 MOVLI .489,sub_a ; position of the cardinal | |
| 870 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 871 btfss compass_show_cardinal ; shall show cardinal? | |
| 872 bra dcr_7 ; NO | |
| 873 STRCPY_TEXT_PRINT tSE ; YES - print it | |
| 874 dcr_7: | |
| 875 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 876 MOVLI .538,sub_a ; position of the cardinal | |
| 877 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 878 btfss compass_show_cardinal ; shall show cardinal? | |
| 879 bra dcr_8 ; NO | |
| 880 STRCPY_TEXT_PRINT tS ; YES - print it | |
| 881 dcr_8: | |
| 882 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 883 MOVLI .579,sub_a ; position of the cardinal | |
| 884 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 885 btfss compass_show_cardinal ; shall show cardinal? | |
| 886 bra dcr_9 ; NO | |
| 887 STRCPY_TEXT_PRINT tSW ; YES - print it | |
| 888 dcr_9: | |
| 889 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 890 MOVLI .627,sub_a ; position of the cardinal | |
| 891 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 892 btfss compass_show_cardinal ; shall show cardinal? | |
| 893 bra dcr_10 ; NO | |
| 894 STRCPY_TEXT_PRINT tW ; YES - print it | |
| 895 dcr_10: | |
| 896 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 897 MOVLI .669,sub_a ; position of the cardinal | |
| 898 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 899 btfss compass_show_cardinal ; shall show cardinal? | |
| 900 bra dcr_11 ; NO | |
| 901 STRCPY_TEXT_PRINT tNW ; YES - print it | |
| 902 dcr_11: | |
| 903 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 904 MOVLI .718,sub_a ; position of the cardinal | |
| 905 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
| 906 btfss compass_show_cardinal ; shall show? | |
| 907 bra dcr_12 ; NO | |
| 908 STRCPY_TEXT_PRINT tN ; YES - print it | |
| 909 dcr_12: | |
| 910 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 911 | |
| 912 TFT_dive_compass_label_end: | |
| 913 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 914 ; restore lo and hi for the final cleanup | |
| 915 movff xLO,lo ; xLO and xHI are stored in bank isr_backup | |
| 916 movff xHI,hi | |
| 917 ; clear the rest of the SQ area if there is more space | |
| 918 movlw d'159' | |
| 919 cpfslt hi | |
| 920 bra TFT_dive_compass_label_end2 ; D >= 160, no more space | |
| 921 ; position left to end of display to clear the remaining area | |
| 922 movlw d'158' | |
| 923 movwf lo | |
| 924 ; clear it | |
| 925 rcall TFT_dive_compass_clr_label | |
| 926 TFT_dive_compass_label_end2: | |
| 927 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker | |
| 928 ; do we have bearing set? | |
| 929 btfsc compass_bearing_set ; bearing set? | |
| 930 bra TFT_dive_compass_dir_text ; YES - print the direction (<< or >>) | |
| 931 rcall TFT_dive_compass_dir_lclr ; NO - clear the area (e.g. we had but removed) | |
| 932 rcall TFT_dive_compass_dir_rclr | |
| 933 bra TFT_dive_compass_text | |
| 934 | |
| 935 TFT_dive_compass_dir_text: | |
| 936 ; bearing set, but does it point to heading? | |
| 937 btfss compass_bearing_eq | |
| 938 bra TFT_dive_compass_dir_text_2 ; bearing != heading - go and print the direction | |
| 939 rcall TFT_dive_compass_dir_lclr ; bearing == heading - no need for direction markers | |
| 940 rcall TFT_dive_compass_dir_rclr | |
| 941 bra TFT_dive_compass_text | |
| 942 | |
| 943 TFT_dive_compass_dir_text_2: | |
| 944 FONT_COLOR color_green | |
| 945 btfsc compass_bearing_lft | |
| 946 bra TFT_dive_compass_dir_ldir ; bearing_lft=1, print the left marker | |
| 947 ;TFT_dive_compass_text_rdir: | |
| 948 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 | |
| 949 STRCPY_PRINT ">>" | |
| 950 rcall TFT_dive_compass_dir_lclr ; do not forget to clear the left | |
| 951 bra TFT_dive_compass_text | |
| 952 | |
| 953 TFT_dive_compass_dir_ldir: | |
| 954 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 | |
| 955 STRCPY_PRINT "<<" | |
| 956 rcall TFT_dive_compass_dir_rclr ; do not forget to clear the right | |
| 957 ;bra TFT_dive_compass_text | |
| 958 | |
| 959 TFT_dive_compass_text: | |
| 960 ; Clear some unused space on the right mH | |
| 961 WIN_BOX_BLACK dm_custom_compass_tick_top_bot+.1,dm_custom_compass_tick_bot_top-.1,.158,.159 ; top, bottom, left, right | |
| 962 | |
| 963 ; Text output | |
| 964 WIN_SMALL dm_custom_compass_head_column, dm_custom_compass_head_row | |
| 965 call TFT_surface_compass_heading_com ; show "xxx° N" | |
| 966 return | |
| 967 | |
| 968 TFT_dive_compass_dir_lclr: | |
| 969 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 | |
| 970 STRCPY_PRINT " " | |
| 971 return | |
| 972 | |
| 973 TFT_dive_compass_dir_rclr: | |
| 974 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 | |
| 975 STRCPY_PRINT " " | |
| 976 return | |
| 977 | |
| 978 TFT_dive_compass_label_proc: | |
| 979 movlw d'14' | |
| 980 movwf up ; cardinal width in px | |
| 981 bcf compass_show_cardinal | |
| 982 ; 1/a. check if it's viewable ? sub_a(RP) >= sub_b(RD) ? | |
| 983 ; set the carry flag if sub_b(xRD) is equal to or greater than sub_a(xRP): | |
| 984 MOVII xRD,sub_b | |
| 985 call subU16 ; sub_c = sub_a - sub_b | |
| 986 btfsc neg_flag ; >= 0 ? | |
| 987 return ; NO | |
| 988 ; store the RO=RP-RD for drawing | |
| 989 MOVII sub_c,xC | |
| 990 | |
| 991 ; 1/b. check if it's viewable ? sub_a(RP)+up(width) < sub_b(RD)+160 | |
| 992 ; if already above, no need to process the rest of the labels | |
| 993 movff up,WREG ; take care about the width | |
| 994 addwf sub_a+0,1 | |
| 995 btfsc STATUS, C | |
| 996 incf sub_a+1 | |
| 997 | |
| 998 MOVII xRDr,sub_b | |
| 999 call subU16 ; sub_c = sub_a - sub_b | |
| 1000 btfss neg_flag ; < 0 ? | |
| 1001 bra TFT_dive_compass_label_end ; NO | |
| 1002 | |
| 1003 ; 2. restore RO=RP-RD from 1/a. | |
| 1004 movff xC+0,lo | |
| 1005 | |
| 1006 ; 3. Clear the segment from DD(hi) to lo | |
| 1007 ; don't do a clear if we are at 0 (zero) otherwise it will blink | |
| 1008 ; ?because of the width underflow? | |
| 1009 movlw d'1' | |
| 1010 cpfsgt lo | |
| 1011 bra TFT_dive_compass_label_proc_p | |
| 1012 rcall TFT_dive_compass_clr_label | |
| 1013 TFT_dive_compass_label_proc_p: | |
| 1014 ; 4. print the SQ on the screen | |
| 1015 FONT_COLOR_MEMO | |
| 1016 bsf compass_show_cardinal | |
| 1017 ;TFT_dive_compass_label_print: | |
| 1018 movlw dm_custom_compass_label_row ; set output position | |
| 1019 movff WREG,win_top ; ... | |
| 1020 movff lo,win_leftx2 ; ... | |
| 1021 FONT_SIZE FT_SMALL ; set font size | |
| 1022 ; 6. retain the new display positions | |
| 1023 movff lo,hi | |
| 1024 movff up,WREG | |
| 1025 addwf hi,F | |
| 1026 movff lo,xLO | |
| 1027 movff hi,xHI | |
| 1028 return | |
| 1029 | |
| 1030 TFT_dive_compass_c_mk: | |
| 1031 ; Common task to draw center line and marker | |
| 1032 ; until a proper implementation make it simple: | |
| 1033 rcall TFT_dive_compass_mk | |
| 1034 TFT_dive_compass_c: | |
| 1035 movlw color_yellow | |
| 1036 WIN_BOX_COLOR dm_custom_compass_tick_top_top, dm_custom_compass_tick_bot_bot,.80,.81 ; center line in yellow | |
| 1037 return | |
| 1038 | |
| 1039 TFT_dive_compass_mk: | |
| 1040 ; draw the bearing on the screen if visible and if we just put something over it | |
| 1041 btfss compass_bearing_set ; bearing set? | |
| 1042 return ; NO - done | |
| 1043 btfss compass_bearing_vis ; YES - bearing visible? | |
| 1044 return ; NO - bearing set but not visible, done | |
| 1045 | |
| 1046 ; save lo/hi from trashing | |
| 1047 MOVII mpr,xA | |
| 1048 | |
| 1049 ; did we just update the marker's position? | |
| 1050 ; DD.......DD | |
| 1051 ; CM+2>=DD(old) or CM-2<=DD | |
| 1052 ; ToDo | |
| 1053 | |
| 1054 btfss compass_bearing_ahd | |
| 1055 bra TFT_dive_compass_mk_rear | |
| 1056 ;TFT_dive_compass_mk_front: | |
| 1057 clrf lo | |
| 1058 movff xCM,lo | |
| 1059 bsf compass_show_cardinal ; set=green marker | |
| 1060 rcall TFT_dive_compass_mk_print | |
| 1061 bcf compass_show_cardinal | |
| 1062 bra TFT_dive_compass_mk_end | |
| 1063 | |
| 1064 TFT_dive_compass_mk_rear: | |
| 1065 clrf lo | |
| 1066 movff xCM,lo | |
| 1067 bcf compass_show_cardinal ; set=red marker | |
| 1068 rcall TFT_dive_compass_mk_print | |
| 1069 | |
| 1070 TFT_dive_compass_mk_end: | |
| 1071 MOVII xA,mpr | |
| 1072 return | |
| 1073 | |
| 1074 TFT_dive_compass_mk_print: | |
| 1075 movlw d'1' | |
| 1076 cpfsgt lo | |
| 1077 bra TFT_dive_compass_mk_print_2 ; lo <= 1, skip the first line | |
| 1078 movlw d'2' | |
| 1079 subwf lo,0 | |
| 1080 ; movff WREG,win_leftx2 | |
| 1081 rcall TFT_dive_compass_mk_print_3 | |
| 1082 TFT_dive_compass_mk_print_2: | |
| 1083 ; save hi/lo | |
| 1084 MOVII mpr,divA | |
| 1085 ; clear the middle of the bearing marker | |
| 1086 movff lo,hi | |
| 1087 movlw d'2' | |
| 1088 addwf lo,1 | |
| 1089 rcall TFT_dive_compass_clr_label | |
| 1090 ; restore hi/lo | |
| 1091 MOVII divA,mpr | |
| 1092 ; print a dot on the middle | |
| 1093 movf lo,W | |
| 1094 rcall TFT_dive_compass_mk_print_dot | |
| 1095 ; finally print the right marker line | |
| 1096 movlw d'2' | |
| 1097 addwf lo,0 | |
| 1098 ; rcall TFT_dive_compass_mk_print_3 | |
| 1099 ; return | |
| 1100 TFT_dive_compass_mk_print_3: | |
| 1101 movwf win_leftx2 | |
| 1102 movlw dm_custom_compass_label_row | |
| 1103 movwf win_top | |
| 1104 movlw dm_custom_compass_label_height-.2 | |
| 1105 movwf win_height | |
| 1106 bra TFT_dive_compass_mk_print_4 | |
| 1107 TFT_dive_compass_mk_print_dot: | |
| 1108 movwf win_leftx2 | |
| 1109 movlw dm_custom_compass_label_row + .9 | |
| 1110 movwf win_top | |
| 1111 movlw d'4' | |
| 1112 movwf win_height | |
| 1113 TFT_dive_compass_mk_print_4: | |
| 1114 movlw .158 | |
| 1115 cpfslt win_leftx2 | |
| 1116 bra TFT_dive_compass_mk_print_5 | |
| 1117 movlw d'2' | |
| 1118 movwf win_bargraph | |
| 1119 movwf win_width+0 | |
| 1120 clrf win_width+1 | |
| 1121 movlw color_green | |
| 1122 btfss compass_show_cardinal | |
| 1123 movlw color_red ; select color | |
| 1124 BOX_COLOR ; draw box | |
| 1125 TFT_dive_compass_mk_print_5: | |
| 1126 return | |
| 1127 | |
| 1128 TFT_dive_compass_clr_label: | |
| 1129 movlw dm_custom_compass_label_row-.2 ; set top & height | |
| 1130 movwf win_top | |
| 1131 movlw dm_custom_compass_label_height+.2 | |
| 1132 movwf win_height | |
| 1133 rcall TFT_dive_compass_clear | |
| 1134 return | |
| 1135 | |
| 1136 TFT_dive_compass_clr_ruler: | |
| 1137 ; top tick | |
| 1138 movlw dm_custom_compass_tick_top_top ; set top & height | |
| 1139 movwf win_top | |
| 1140 movlw dm_custom_compass_tick_height | |
| 1141 movwf win_height | |
| 1142 rcall TFT_dive_compass_clear | |
| 1143 ;bottom tick | |
| 1144 movlw dm_custom_compass_tick_bot_top ; set top & height | |
| 1145 movwf win_top | |
| 1146 movlw dm_custom_compass_tick_height | |
| 1147 movwf win_height | |
| 1148 ; rcall TFT_dive_compass_clear | |
| 1149 ; return | |
| 1150 TFT_dive_compass_clear: | |
| 1151 ; we receive RM in lo and DD in hi | |
| 1152 ; calculate width = RM-D | |
| 1153 movf hi,W | |
| 1154 subwf lo,W | |
| 1155 bz TFT_dive_compass_clear3 ; do nothing if there is nothing to do | |
| 1156 movwf win_width+0 ; RM-DD | |
| 1157 movwf win_bargraph | |
| 1158 clrf win_width+1 | |
| 1159 movlw .1 | |
| 1160 cpfsgt win_width+0 | |
| 1161 bra TFT_dive_compass_clear3 ; do not clear a single pixel (or less) | |
| 1162 movff hi,win_leftx2 | |
| 1163 movlw color_black ; select color | |
| 1164 BOX_COLOR ; draw box | |
| 1165 TFT_dive_compass_clear3: | |
| 1166 return | |
| 1167 | 567 |
| 1168 tft_compass_cardinal: | 568 tft_compass_cardinal: |
| 1169 btfsc hi,0 ; heading > 255° ? | 569 btfsc hi,0 ; heading > 255° ? |
| 1170 bra tft_compass_cardinal2 ; YES - must be W, NW or N | 570 bra tft_compass_cardinal2 ; YES - must be W, NW or N |
| 1171 ; NO - must be W, SW, S, SE, E, NE or N | 571 ; NO - must be W, SW, S, SE, E, NE or N |
