comparison src/tft_outputs.asm @ 255:ad62dff7739a

add bearing option to compass
author heinrichsweikamp
date Mon, 23 Mar 2015 17:07:57 +0100
parents d912fb71d606
children 5b4ef0b9090d
comparison
equal deleted inserted replaced
254:5fe7aff622f3 255:ad62dff7739a
1478 return 1478 return
1479 1479
1480 global TFT_dive_compass_heading 1480 global TFT_dive_compass_heading
1481 TFT_dive_compass_heading: 1481 TFT_dive_compass_heading:
1482 rcall compass_heading_common 1482 rcall compass_heading_common
1483 ; ; ToDo - these are for development only, hardcoding the bearing position
1484 ; ; 244° : SW - W
1485 ; movlw low(d'244')
1486 ; movff WREG,compass_bearing+0
1487 ; movlw high(d'244')
1488 ; movff WREG,compass_bearing+1
1483 1489
1484 movff compass_heading_shown+0,xA+0 1490 movff compass_heading_shown+0,xA+0
1485 movff compass_heading_shown+1,xA+1 1491 movff compass_heading_shown+1,xA+1
1486 1492 ; xRD and xRDlft
1487 ; 1. 160°: +360 offset for non-negative scale 1493 ; 1. 160° viewing angle: +360 offset if xA<=292; for non-negative scale
1494 movlw high(d'292')
1495 movff WREG,sub_a+1
1496 movlw low(d'292')
1497 movff WREG,sub_a+0
1498 movff xA+1,sub_b+1
1499 movff xA+0,sub_b+0
1500 call subU16 ; sub_c = sub_a - sub_b
1501 btfsc neg_flag ; xA>292
1502 bra TFT_dive_compass_heading_1 ;yes
1503 ; no, xA<=292
1488 movlw high(d'360') 1504 movlw high(d'360')
1489 addwf xA+1,1 1505 addwf xA+1,1
1490 movlw low(d'360') 1506 movlw low(d'360')
1491 addwf xA+0,1 1507 addwf xA+0,1
1492 btfsc STATUS,C 1508 btfsc STATUS,C
1493 incf xA+1 1509 incf xA+1
1510 TFT_dive_compass_heading_1:
1494 ; 2. -80: left pixel offset from the center 1511 ; 2. -80: left pixel offset from the center
1495 movlw low( d'80' ) 1512 movlw low( d'80' )
1496 subwf xA+0,1 1513 subwf xA+0,1
1497 btfss STATUS,C 1514 btfss STATUS,C
1498 decf xA+1 1515 decf xA+1
1499 ; 3. save it to RD 1516 ; 3. save it to xRD
1500 movff xA+0,xRD+0 1517 movff xA+0,xRD+0
1501 movff xA+1,xRD+1 1518 movff xA+1,xRD+1
1502 1519 ; 4. add 160 (display px width)
1520 movlw high(d'160')
1521 addwf xA+1,1
1522 movlw low(d'160')
1523 addwf xA+0,1
1524 btfsc STATUS,C
1525 incf xA+1
1526 ; 5. save it to xRDr
1527 movff xA+0,xRDr+0
1528 movff xA+1,xRDr+1
1529
1530 ; ; Bearing ?
1531 ; ; We can skip this xRD180 calculation if no bearing is set
1532 ; bcf compass_bearing_set
1533 ; movff compass_bearing+0,sub_a+0
1534 ; movff compass_bearing+1,sub_a+1
1535 ; movlw d'0'
1536 ; cpfseq sub_a+1
1537 ; bra TFT_dive_compass_bearing ; something set, calculate xRD180
1538 ; movlw d'0'
1539 ; cpfseq sub_a+0
1540 ; bra TFT_dive_compass_bearing ; something set, calculate xRD180
1541 ; bra TFT_dive_compass_ruler ; no value in the bearing, skip calc
1542 ;
1543 ;TFT_dive_compass_bearing:
1544 ; bsf compass_bearing_set
1545
1546 btfss compass_bearing_set
1547 bra TFT_dive_compass_ruler ; no value in the bearing, skip calc
1548
1549 ; we have bearing set, we will need xRD180 calculated
1550 ; xRD180 is xRDr-180
1551 movff xRDr+1,sub_a+1
1552 movff xRDr+0,sub_a+0
1553 movlw high(d'180')
1554 movff WREG,sub_b+1
1555 movlw low(d'180')
1556 movff WREG,sub_b+0
1557 call subU16 ; sub_c = sub_a - sub_b
1558 movff sub_c+1,xRD180+1
1559 movff sub_c+0,xRD180+0
1560
1561 ; get the bearing virtual display offset, store it to divA
1562 movff compass_bearing+0,xA+0
1563 movff compass_bearing+1,xA+1
1564 ; divA =IF (U10>292;U10;U10+360)
1565 movlw high(d'292')
1566 movff WREG,sub_a+1
1567 movlw low(d'292')
1568 movff WREG,sub_a+0
1569 movff xA+1,sub_b+1
1570 movff xA+0,sub_b+0
1571 call subU16 ; sub_c = sub_a - sub_b
1572 btfsc neg_flag ; xA>292
1573 bra TFT_dive_compass_bearing_1 ;yes
1574 ; no, xA<=292
1575 movlw high(d'360')
1576 addwf xA+1,1
1577 movlw low(d'360')
1578 addwf xA+0,1
1579 btfsc STATUS,C
1580 incf xA+1
1581 ; save it for the direction (<< or >>) calculation
1582 movff xA+1,divA+1
1583 movff xA+0,divA+0
1584
1585 TFT_dive_compass_bearing_1:
1586 ; calculate bearing position and visibility (ahead or behind)
1587 bcf compass_bearing_vis ; default is not-visibly
1588 bcf compass_bearing_ahd ; default is behind
1589 ; check if it's ahead
1590 ; load the bearing offset into sub_a
1591 movff divA+1,sub_a+1
1592 movff divA+0,sub_a+0
1593 ; load the display offset back to sub_b
1594 movff xRD+0,sub_b+0
1595 movff xRD+1,sub_b+1
1596 rcall TFT_dive_compass_bearing_ap
1597 ;test if we found it
1598 btfsc compass_bearing_vis
1599 bra TFT_dive_compass_bearing_dir
1600
1601 ; check if it's ahead with a furr turn
1602 ; load the bearing offset into sub_a
1603 movff divA+1,sub_a+1
1604 movff divA+0,sub_a+0
1605 ; load the display offset back to sub_b
1606 movff xRD+0,sub_b+0
1607 movff xRD+1,sub_b+1
1608 movlw high(d'360')
1609 addwf sub_b+1,1
1610 movlw low(d'360')
1611 addwf sub_b+0,1
1612 btfsc STATUS,C
1613 incf sub_b+1
1614 rcall TFT_dive_compass_bearing_ap
1615 ;test if we found it
1616 btfsc compass_bearing_vis
1617 bra TFT_dive_compass_bearing_dir
1618
1619 ; marker is not ahead of us, check if it's behind us
1620 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display
1621 ; load the display offset back to sub_a
1622 movff xRD180+0,sub_a+0
1623 movff xRD180+1,sub_a+1
1624 ; load the marker's offset into sub_b
1625 movff divA+0,sub_b+0
1626 movff divA+1,sub_b+1
1627 rcall TFT_dive_compass_bearing_bp
1628 ;test if we found it
1629 btfsc compass_bearing_vis
1630 bra TFT_dive_compass_bearing_dir
1631
1632 ;check if it's behind with the lower turn
1633 movff xRD180+0,sub_a+0
1634 movff xRD180+1,sub_a+1
1635 movlw high(d'360')
1636 addwf sub_a+1,1
1637 movlw low(d'360')
1638 addwf sub_a+0,1
1639 btfsc STATUS,C
1640 incf sub_a+1
1641 ; load the marker's offset into sub_b
1642 movff divA+0,sub_b+0
1643 movff divA+1,sub_b+1
1644 rcall TFT_dive_compass_bearing_bp
1645 ;test if we found it
1646 btfsc compass_bearing_vis
1647 bra TFT_dive_compass_bearing_dir
1648
1649 ; check if it's behind with the upper turn
1650 movff divA+1,sub_b+1
1651 movff divA+0,sub_b+0
1652 movlw high(d'360')
1653 addwf sub_b+1,1
1654 movlw low(d'360')
1655 addwf sub_b+0,1
1656 btfsc STATUS,C
1657 incf sub_b+1
1658 rcall TFT_dive_compass_bearing_bp
1659 bra TFT_dive_compass_bearing_dir
1660
1661 TFT_dive_compass_bearing_ap:
1662 ; xCM received in sub_a
1663 ; xRD received in sub_b
1664 ; 1/a. check if it's viewable from the left side
1665 call subU16 ; sub_c = sub_a - sub_b
1666 btfsc neg_flag ; xRD>divA
1667 return ;no,
1668 ; yes, store the RO=RP-RD for drawing
1669 movff sub_c+0,xC+0
1670 movff sub_c+1,xC+1
1671 ; 1/b. check if it's viewable from the right side?
1672 movlw d'2' ; avoid thin mess on the side of the display
1673 addwf sub_a+0,1
1674 btfsc STATUS, C
1675 incf sub_a+1
1676 ; load the display offset right side into sub_b
1677 movlw high(d'160')
1678 addwf sub_b+1,1
1679 movlw low(d'160')
1680 addwf sub_b+0,1
1681 btfsc STATUS,C
1682 incf sub_b+1
1683 call subU16 ; sub_c = sub_a - sub_b
1684 btfss neg_flag ; xRDr>xA(+2)
1685 return ; no,
1686 ; print the bearing lines on the screen
1687 movff xC+0,xCM
1688 bsf compass_bearing_vis ; set visible
1689 bsf compass_bearing_ahd ; set ahead
1690 return ; done,
1691
1692 TFT_dive_compass_bearing_bp:
1693 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display
1694 ; the marker's offset received in sub_b
1695 ; the xRD180 display offset received in sub_a
1696 ; xRD180 - xCM
1697 call subU16 ; sub_c = sub_a - sub_b
1698 btfsc neg_flag ; CM>xRD180
1699 return ; no, not on screen
1700 ; 160 - (X)
1701 movlw high(d'160')
1702 movff WREG,sub_a+1
1703 movlw low(d'160')
1704 movff WREG,sub_a+0
1705 movff sub_c+1,sub_b+1
1706 movff sub_c+0,sub_b+0
1707 call subU16 ; sub_c = sub_a - sub_b
1708 btfsc neg_flag ; X>160
1709 return ; no, not on screen
1710 ; check if not overflow - this sounds a double check...
1711 movlw d'1'
1712 cpfslt sub_c+1
1713 return ; high set, >160
1714 movlw d'160'
1715 cpfslt sub_c+0
1716 return ; low >160
1717 ; print the bearing lines on the screen
1718 movff sub_c+0,xCM
1719 bsf compass_bearing_vis
1720 return ; done
1721
1722 TFT_dive_compass_bearing_dir:
1723 ; check if bearing to heading, and calculate the direction
1724 bcf compass_bearing_eq
1725 btfss compass_bearing_vis
1726 bra TFT_dive_compass_bearing_lr
1727 btfss compass_bearing_ahd
1728 bra TFT_dive_compass_bearing_lr
1729 movff xCM,xA+0
1730 movlw d'80'
1731 cpfseq xA+0
1732 bra TFT_dive_compass_bearing_lr
1733 bsf compass_bearing_eq
1734 bra TFT_dive_compass_ruler ; bearing points to heading, no signs are required, go to the ruler
1735
1736 TFT_dive_compass_bearing_lr:
1737 ; 1. calculate whether bearing is to left or to right
1738 bsf compass_bearing_lft ; to the left by default
1739 ; get the bearing offset back
1740 movff divA+1,xA+1
1741 movff divA+0,xA+0
1742 ; xC: save center value to compare the direction to front value
1743 movff xA+1,xC+1
1744 movff xA+0,xC+0
1745 ; xB: we need the left side for comparism... left = -180
1746 movff xA+1,sub_a+1
1747 movff xA+0,sub_a+0
1748 movlw high(d'180')
1749 movff WREG,sub_b+1
1750 movlw low(d'180')
1751 movff WREG,sub_b+0
1752 call subU16 ; sub_c = sub_a - sub_b
1753 movff sub_c+1,xB+1 ; xB has the left side of the 180° distance center
1754 movff sub_c+0,xB+0
1755 ; xA = IF(xRD>(xC+100);xRD-280;xRD+80)
1756 movff xC+1,sub_a+1
1757 movff xC+0,sub_a+0
1758 movlw d'100'
1759 addwf sub_a+0,1
1760 btfsc STATUS,C
1761 incf sub_a+1
1762 movff xRD+1,sub_b+1
1763 movff xRD+0,sub_b+0
1764 call subU16 ; sub_c = sub_a - sub_b
1765 btfsc neg_flag ; xRD>xC+100
1766 bra TFT_dive_compass_bearing_lr_2 ; yes, xA=xRD-280
1767 ; no, xA = xRD+80
1768 movff xRD+1,xA+1
1769 movff xRD+0,xA+0
1770 movlw d'80'
1771 addwf xA+0,1
1772 btfsc STATUS,C
1773 incf xA+1
1774 bra TFT_dive_compass_bearing_lr_c
1775
1776 TFT_dive_compass_bearing_lr_2:
1777 ; xA=xRD-280
1778 movff xRD+1,sub_a+1
1779 movff xRD+0,sub_a+0
1780 movlw high(d'280')
1781 movff WREG,sub_b+1
1782 movlw low(d'280')
1783 movff WREG,sub_b+0
1784 call subU16 ; sub_c = sub_a - sub_b
1785 movff sub_c+1,xA+1
1786 movff sub_c+0,xA+0
1787 ;bra TFT_dive_compass_bearing_lr_c
1788
1789 TFT_dive_compass_bearing_lr_c:
1790 ; xB < xA < xC => right, otherwise left (default)
1791 movff xA+1,sub_b+1
1792 movff xA+0,sub_b+0
1793 movff xB+1,sub_a+1
1794 movff xB+0,sub_a+0
1795 call subU16 ; sub_c = sub_a - sub_b
1796 btfss neg_flag ; xA>xB ?
1797 bra TFT_dive_compass_ruler ; No, xB >= xA, keep default left
1798 movff xA+1,sub_a+1
1799 movff xA+0,sub_a+0
1800 movff xC+1,sub_b+1
1801 movff xC+0,sub_b+0
1802 call subU16 ; sub_c = sub_a - sub_b
1803 btfss neg_flag ; xC>xA ?
1804 bra TFT_dive_compass_ruler ; No, xA >= xC, keep default left
1805 bcf compass_bearing_lft
1806
1807 TFT_dive_compass_ruler:
1503 ; calculate mod15 for the ticks 1808 ; calculate mod15 for the ticks
1809 movff xRD+0,xA+0
1810 movff xRD+1,xA+1
1504 movlw d'15' 1811 movlw d'15'
1505 movwf xB+0 1812 movwf xB+0
1506 clrf xB+1 1813 clrf xB+1
1507 call div16x16 ;xA/xB=xC with xA+0 as remainder 1814 call div16x16 ;xA/xB=xC with xA+0 as remainder
1508 ; check xA+0, it has the remainder 1815 ; check xA+0, it has the remainder
1509 movlw d'0' 1816 movlw d'0'
1510 cpfsgt xA+0 ; mod15 > 0 1817 cpfsgt xA+0 ; mod15 > 0
1511 bra TFT_dive_compass_ruler ; no, RM = 0 1818 bra TFT_dive_compass_ruler_1 ; no, RM = 0
1512 ; yes RM = 15 - RDmod15 1819 ; yes RM = 15 - RDmod15
1513 movlw d'15' 1820 movlw d'15'
1514 subfwb xA+0,1 1821 subfwb xA+0,1
1515 TFT_dive_compass_ruler: 1822 TFT_dive_compass_ruler_1:
1516 ; xA+0 holds the RM, store it to 'lo' 1823 ; xA+0 holds the RM, store it to 'lo'
1517 movff xA+0,lo 1824 movff xA+0,lo
1518 ; init DD to zero, store it to 'hi' 1825 ; init DD to zero, store it to 'hi'
1519 movlw d'0' 1826 movlw d'0'
1520 movff WREG,hi 1827 movff WREG,hi
1564 movwf lo 1871 movwf lo
1565 ; 10. clear it 1872 ; 10. clear it
1566 rcall TFT_dive_compass_clr_ruler 1873 rcall TFT_dive_compass_clr_ruler
1567 1874
1568 TFT_dive_compass_ruler_lend2: 1875 TFT_dive_compass_ruler_lend2:
1876 rcall TFT_dive_compass_c_mk
1569 ; done with the compass ruler, put the labels on the screen 1877 ; done with the compass ruler, put the labels on the screen
1570 ; get the RD abck to sub_b 1878 ; get the RD abck to sub_b
1571 movff xRD+0,sub_b+0 1879 movff xRD+0,sub_b+0
1572 movff xRD+1,sub_b+1 1880 movff xRD+1,sub_b+1
1573 ; hi stores the display position 1881 ; hi stores the display position
1578 movwf lo 1886 movwf lo
1579 bcf print_compass_label 1887 bcf print_compass_label
1580 1888
1581 movlw d'14' 1889 movlw d'14'
1582 movwf up ; up stores the width of hte label 1890 movwf up ; up stores the width of hte label
1891 movlw low( d'219' ) ; position of the label
1892 movwf sub_a+0
1893 movlw high( d'219' )
1894 movwf sub_a+1
1895 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1896 btfss print_compass_label ; Yes?
1897 bra dcr_1
1898 STRCPY_TEXT_PRINT tSW ; yes - print it
1899 dcr_1:
1900 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1901
1902 movlw d'7'
1903 movwf up ; up stores the width of hte label
1904 movlw low( d'267' ) ; position of the label
1905 movwf sub_a+0
1906 movlw high( d'267' )
1907 movwf sub_a+1
1908 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1909 btfss print_compass_label ; Yes?
1910 bra dcr_2
1911 STRCPY_TEXT_PRINT tW ; yes - print it
1912 dcr_2:
1913 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1914
1915 movlw d'14'
1916 movwf up ; up stores the width of hte label
1583 movlw low( d'309' ) ; position of the label 1917 movlw low( d'309' ) ; position of the label
1584 movwf sub_a+0 1918 movwf sub_a+0
1585 movlw high( d'309' ) 1919 movlw high( d'309' )
1586 movwf sub_a+1 1920 movwf sub_a+1
1587 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 1921 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1588 btfss print_compass_label ; Yes? 1922 btfss print_compass_label ; Yes?
1589 bra dcr_1 1923 bra dcr_3
1590 STRCPY_TEXT_PRINT tNW ; yes - print it 1924 STRCPY_TEXT_PRINT tNW ; yes - print it
1591 dcr_1: 1925 dcr_3:
1592 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 1926 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1593 1927
1594 movlw d'6' 1928 movlw d'6'
1595 movwf up ; up stores the width of hte label 1929 movwf up ; up stores the width of hte label
1596 movlw low( d'358' ) ; position of the label 1930 movlw low( d'358' ) ; position of the label
1597 movwf sub_a+0 1931 movwf sub_a+0
1598 movlw high( d'358' ) 1932 movlw high( d'358' )
1599 movwf sub_a+1 1933 movwf sub_a+1
1600 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 1934 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1601 btfss print_compass_label ; Yes? 1935 btfss print_compass_label ; Yes?
1602 bra dcr_2 1936 bra dcr_4
1603 STRCPY_TEXT_PRINT tN ; yes - print it 1937 STRCPY_TEXT_PRINT tN ; yes - print it
1604 dcr_2: 1938 dcr_4:
1605 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 1939 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1606 1940
1607 movlw d'13' 1941 movlw d'13'
1608 movwf up ; up stores the width of hte label 1942 movwf up ; up stores the width of hte label
1609 movlw low( d'399' ) ; position of the label 1943 movlw low( d'399' ) ; position of the label
1610 movwf sub_a+0 1944 movwf sub_a+0
1611 movlw high( d'399' ) 1945 movlw high( d'399' )
1612 movwf sub_a+1 1946 movwf sub_a+1
1613 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 1947 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1614 btfss print_compass_label ; Yes? 1948 btfss print_compass_label ; Yes?
1615 bra dcr_3 1949 bra dcr_5
1616 STRCPY_TEXT_PRINT tNE ; yes - print it 1950 STRCPY_TEXT_PRINT tNE ; yes - print it
1617 dcr_3: 1951 dcr_5:
1618 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 1952 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1619 1953
1620 movlw d'6' 1954 movlw d'6'
1621 movwf up ; up stores the width of hte label 1955 movwf up ; up stores the width of hte label
1622 movlw low( d'448' ) ; position of the label 1956 movlw low( d'448' ) ; position of the label
1623 movwf sub_a+0 1957 movwf sub_a+0
1624 movlw high( d'448' ) 1958 movlw high( d'448' )
1625 movwf sub_a+1 1959 movwf sub_a+1
1626 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 1960 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1627 btfss print_compass_label ; Yes? 1961 btfss print_compass_label ; Yes?
1628 bra dcr_4 1962 bra dcr_6
1629 STRCPY_TEXT_PRINT tE ; yes - print it 1963 STRCPY_TEXT_PRINT tE ; yes - print it
1630 dcr_4: 1964 dcr_6:
1631 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 1965 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1632 1966
1633 movlw d'13' 1967 movlw d'13'
1634 movwf up ; up stores the width of hte label 1968 movwf up ; up stores the width of hte label
1635 movlw low( d'489' ) ; position of the label 1969 movlw low( d'489' ) ; position of the label
1636 movwf sub_a+0 1970 movwf sub_a+0
1637 movlw high( d'489' ) 1971 movlw high( d'489' )
1638 movwf sub_a+1 1972 movwf sub_a+1
1639 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 1973 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1640 btfss print_compass_label ; Yes? 1974 btfss print_compass_label ; Yes?
1641 bra dcr_5 1975 bra dcr_7
1642 STRCPY_TEXT_PRINT tSE ; yes - print it 1976 STRCPY_TEXT_PRINT tSE ; yes - print it
1643 dcr_5: 1977 dcr_7:
1644 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 1978 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1645 1979
1646 movlw d'6' 1980 movlw d'6'
1647 movwf up ; up stores the width of hte label 1981 movwf up ; up stores the width of hte label
1648 movlw low( d'538' ) ; position of the label 1982 movlw low( d'538' ) ; position of the label
1649 movwf sub_a+0 1983 movwf sub_a+0
1650 movlw high( d'538' ) 1984 movlw high( d'538' )
1651 movwf sub_a+1 1985 movwf sub_a+1
1652 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 1986 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1653 btfss print_compass_label ; Yes? 1987 btfss print_compass_label ; Yes?
1654 bra dcr_6 1988 bra dcr_8
1655 STRCPY_TEXT_PRINT tS ; yes - print it 1989 STRCPY_TEXT_PRINT tS ; yes - print it
1656 dcr_6: 1990 dcr_8:
1657 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 1991 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1658 1992
1659 movlw d'14' 1993 movlw d'14'
1660 movwf up ; up stores the width of hte label 1994 movwf up ; up stores the width of hte label
1661 movlw low( d'579' ) ; position of the label 1995 movlw low( d'579' ) ; position of the label
1662 movwf sub_a+0 1996 movwf sub_a+0
1663 movlw high( d'579' ) 1997 movlw high( d'579' )
1664 movwf sub_a+1 1998 movwf sub_a+1
1665 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 1999 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1666 btfss print_compass_label ; Yes? 2000 btfss print_compass_label ; Yes?
1667 bra dcr_7 2001 bra dcr_9
1668 STRCPY_TEXT_PRINT tSW ; yes - print it 2002 STRCPY_TEXT_PRINT tSW ; yes - print it
1669 dcr_7: 2003 dcr_9:
1670 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 2004 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1671 2005
1672 movlw d'7' 2006 movlw d'7'
1673 movwf up ; up stores the width of hte label 2007 movwf up ; up stores the width of hte label
1674 movlw low( d'627' ) ; position of the label 2008 movlw low( d'627' ) ; position of the label
1675 movwf sub_a+0 2009 movwf sub_a+0
1676 movlw high( d'627' ) 2010 movlw high( d'627' )
1677 movwf sub_a+1 2011 movwf sub_a+1
1678 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 2012 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1679 btfss print_compass_label ; Yes? 2013 btfss print_compass_label ; Yes?
1680 bra dcr_8 2014 bra dcr_10
1681 STRCPY_TEXT_PRINT tW ; yes - print it 2015 STRCPY_TEXT_PRINT tW ; yes - print it
1682 dcr_8: 2016 dcr_10:
1683 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 2017 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1684 2018
1685 movlw d'14' 2019 movlw d'14'
1686 movwf up ; up stores the width of hte label 2020 movwf up ; up stores the width of hte label
1687 movlw low( d'669' ) ; position of the label 2021 movlw low( d'669' ) ; position of the label
1688 movwf sub_a+0 2022 movwf sub_a+0
1689 movlw high( d'669' ) 2023 movlw high( d'669' )
1690 movwf sub_a+1 2024 movwf sub_a+1
1691 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 2025 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1692 btfss print_compass_label ; Yes? 2026 btfss print_compass_label ; Yes?
1693 bra dcr_9 2027 bra dcr_11
1694 STRCPY_TEXT_PRINT tNW ; yes - print it 2028 STRCPY_TEXT_PRINT tNW ; yes - print it
1695 dcr_9: 2029 dcr_11:
1696 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 2030 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1697 2031
1698 movlw d'6' 2032 movlw d'6'
1699 movwf up ; up stores the width of hte label 2033 movwf up ; up stores the width of hte label
1700 movlw low( d'718' ) ; position of the label 2034 movlw low( d'718' ) ; position of the label
1701 movwf sub_a+0 2035 movwf sub_a+0
1702 movlw high( d'718' ) 2036 movlw high( d'718' )
1703 movwf sub_a+1 2037 movwf sub_a+1
1704 rcall TFT_dive_compass_label_proc ; check if the label should be on screen 2038 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1705 btfss print_compass_label ; Yes? 2039 btfss print_compass_label ; Yes?
1706 bra dcr_10 2040 bra dcr_12
1707 STRCPY_TEXT_PRINT tN ; yes - print it 2041 STRCPY_TEXT_PRINT tN ; yes - print it
1708 dcr_10: 2042 dcr_12:
1709 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 2043 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1710 2044
1711 movlw d'13' 2045 TFT_dive_compass_label_end:
1712 movwf up ; up stores the width of hte label
1713 movlw low( d'759' ) ; position of the label
1714 movwf sub_a+0
1715 movlw high( d'759' )
1716 movwf sub_a+1
1717 rcall TFT_dive_compass_label_proc ; check if the label should be on screen
1718 btfss print_compass_label ; Yes?
1719 bra dcr_11
1720 STRCPY_TEXT_PRINT tNE ; yes - print it
1721 dcr_11:
1722 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker 2046 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1723
1724 TFT_dive_compass_label_end:
1725 ; restore lo and hi for the final cleanup 2047 ; restore lo and hi for the final cleanup
1726 movff xLO,lo 2048 movff xLO,lo
1727 movff xHI,hi 2049 movff xHI,hi
1728 ; clear the rest of the SQ area if there are more space 2050 ; clear the rest of the SQ area if there are more space
1729 movlw d'160' 2051 movlw d'160'
1732 ; position left to end of display to clear the remaining area 2054 ; position left to end of display to clear the remaining area
1733 movlw d'160' 2055 movlw d'160'
1734 movff WREG,lo 2056 movff WREG,lo
1735 ; clear it 2057 ; clear it
1736 rcall TFT_dive_compass_clr_label 2058 rcall TFT_dive_compass_clr_label
1737 rcall TFT_dive_compass_c_mk ; this is not required until marker implemented...
1738 TFT_dive_compass_label_end2: 2059 TFT_dive_compass_label_end2:
1739 clrf WREG 2060 rcall TFT_dive_compass_c_mk ; check if label is on the center line or the marker
1740 ;TFT_dive_compass_text: 2061 ; do we have bearing set?
2062 btfsc compass_bearing_set
2063 bra TFT_dive_compass_dir_text ; bearing_set=1 - go and print the dir (<< or >>)
2064 rcall TFT_dive_compass_dir_lclr ; no, clear the area (e.g. we had but removed)
2065 rcall TFT_dive_compass_dir_rclr
2066 bra TFT_dive_compass_text
2067
2068 TFT_dive_compass_dir_text:
2069 ; bearing set, but does it point to heading?
2070 btfss compass_bearing_eq
2071 bra TFT_dive_compass_dir_text_2 ; bearing != heading - go and print the dir
2072 rcall TFT_dive_compass_dir_lclr ; bearing = heading, no need for direction markers
2073 rcall TFT_dive_compass_dir_rclr
2074 bra TFT_dive_compass_text
2075
2076 TFT_dive_compass_dir_text_2:
2077 btfsc compass_bearing_lft
2078 bra TFT_dive_compass_dir_ldir ; bearing_lft=1, print the left marker
2079 ;TFT_dive_compass_text_rdir:
2080 movlw color_green
2081 call TFT_set_color
2082 WIN_SMALL dive_compass_rdir_column,dive_compass_head_row
2083 STRCPY_PRINT ">>"
2084 ; do not forget to clear the left
2085 rcall TFT_dive_compass_dir_lclr
2086 bra TFT_dive_compass_text
2087
2088 TFT_dive_compass_dir_ldir:
2089 movlw color_green
2090 call TFT_set_color
2091 WIN_SMALL dive_compass_ldir_column,dive_compass_head_row
2092 STRCPY_PRINT "<<"
2093 ; do not forget to clear the right
2094 rcall TFT_dive_compass_dir_rclr
2095 ;bra TFT_dive_compass_text
2096
2097 TFT_dive_compass_text:
1741 ; Text output 2098 ; Text output
2099 call TFT_standard_color
1742 WIN_SMALL dive_compass_head_column,dive_compass_head_row 2100 WIN_SMALL dive_compass_head_column,dive_compass_head_row
1743 call TFT_standard_color
1744 rcall TFT_surface_compass_heading_com ; Show "000° N" 2101 rcall TFT_surface_compass_heading_com ; Show "000° N"
2102 return
2103
2104 TFT_dive_compass_dir_lclr:
2105 WIN_SMALL dive_compass_ldir_column,dive_compass_head_row
2106 STRCPY_PRINT " "
2107 return
2108
2109 TFT_dive_compass_dir_rclr:
2110 WIN_SMALL dive_compass_rdir_column,dive_compass_head_row
2111 STRCPY_PRINT " "
1745 return 2112 return
1746 2113
1747 TFT_dive_compass_label_proc: 2114 TFT_dive_compass_label_proc:
1748 ; Input: 2115 ; Input:
1749 ; hi: DD - display current position 2116 ; xHI: DD - display'a current position
1750 ; sub_b: RD - ruler display offset 2117 ; xRD: RD - ruler display offset
1751 ; sub_a: RP - item's ruler display offset 2118 ; sub_a: RP - item's ruler display offset
1752 ; get the RD abck to sub_b 2119 ; get the RD abck to sub_b
1753 movff xRD+0,sub_b+0
1754 movff xRD+1,sub_b+1
1755 movff xHI,hi 2120 movff xHI,hi
1756 bcf print_compass_label 2121 bcf print_compass_label
1757 ; 1/a. check if it's viewable ? sub_a(RP) >= sub_b(RD) ? 2122 ; 1/a. check if it's viewable ? sub_a(RP) >= sub_b(RD) ?
1758 ; set the carry flag if sub_b(xRD) is equal to or greater than sub_a(xRP): 2123 ; set the carry flag if sub_b(xRD) is equal to or greater than sub_a(xRP):
2124 movff xRD+0,sub_b+0
2125 movff xRD+1,sub_b+1
1759 call subU16 ; sub_c = sub_a - sub_b 2126 call subU16 ; sub_c = sub_a - sub_b
1760 btfsc neg_flag ; >=0? 2127 btfsc neg_flag ; >=0?
1761 return ; No 2128 return ; No
1762 ; store the RO=RP-RD for drawing 2129 ; store the RO=RP-RD for drawing
1763 movff sub_c+0,xC+0 2130 movff sub_c+0,xC+0
1769 movlw d'2' ; .. but still avoid thin mess on the side of the display 2136 movlw d'2' ; .. but still avoid thin mess on the side of the display
1770 addwf sub_a+0,1 2137 addwf sub_a+0,1
1771 btfsc STATUS, C 2138 btfsc STATUS, C
1772 incf sub_a+1 2139 incf sub_a+1
1773 2140
1774 movlw d'160' 2141 movff xRDr+0,sub_b+0
1775 addwf sub_b+0,1 2142 movff xRDr+1,sub_b+1
1776 btfsc STATUS, C
1777 incf sub_b+1
1778 call subU16 ; sub_c = sub_a - sub_b 2143 call subU16 ; sub_c = sub_a - sub_b
1779 btfss neg_flag ; ? <0 2144 btfss neg_flag ; ? <0
1780 bra TFT_dive_compass_label_end ; No 2145 bra TFT_dive_compass_label_end ; No
1781 ;return ; instead of simple return go tho the end and
1782 ; skip the rest of the labels to speed up the process
1783 2146
1784 ; 2. restore RO=RP-RD from 1/a. 2147 ; 2. restore RO=RP-RD from 1/a.
1785 movff xC+0,lo 2148 movff xC+0,lo
1786 2149
1787 ; 3. Clear the segment from DD(hi) to lo 2150 ; 3. Clear the segment from DD(hi) to lo
1814 return 2177 return
1815 2178
1816 TFT_dive_compass_c_mk: 2179 TFT_dive_compass_c_mk:
1817 ; Common task to draw center line and marker 2180 ; Common task to draw center line and marker
1818 ; until a proper implementation make it simple: 2181 ; until a proper implementation make it simple:
2182 rcall TFT_dive_compass_mk
1819 rcall TFT_dive_compass_cline 2183 rcall TFT_dive_compass_cline
2184 return
2185
2186 TFT_dive_compass_mk:
2187 ; draw the bearing on the screen if visible and if we just put something over it
2188 btfss compass_bearing_set
2189 return ; bearing_set=0 nothing to display
2190
2191 btfss compass_bearing_vis
2192 return ; bearing set but not visible
2193
2194 ; save lo/hi from trashing
2195 movff lo,xA+0
2196 movff hi,xA+1
2197
2198 ; did we just update the marker's position?
2199 ; DD.......DD
2200 ; CM+2>=DD(old) or CM-2<=DD
2201 ; ToDo
2202
2203 btfss compass_bearing_ahd
2204 bra TFT_dive_compass_mk_rear
2205 ;TFT_dive_compass_mk_front:
2206 clrf lo
2207 movff xCM,lo
2208 bsf print_compass_label ; set=green marker
2209 rcall TFT_dive_compass_mk_print
2210 bcf print_compass_label
2211 bra TFT_dive_compass_mk_end
2212
2213 TFT_dive_compass_mk_rear:
2214 clrf lo
2215 movff xCM,lo
2216 bcf print_compass_label ; set=red marker
2217 rcall TFT_dive_compass_mk_print
2218
2219 TFT_dive_compass_mk_end:
2220 movff xA+0,lo
2221 movff xA+1,hi
2222 return
2223
2224 TFT_dive_compass_mk_print:
2225 movlw d'1'
2226 cpfsgt lo
2227 bra TFT_dive_compass_mk_print_2 ; lo<1, skip the first line
2228 movlw d'2'
2229 subwf lo,0
2230 movff WREG,win_leftx2
2231 rcall TFT_dive_compass_mk_print_3
2232 TFT_dive_compass_mk_print_2:
2233 movlw d'2'
2234 addwf lo,0
2235 movff WREG,win_leftx2
2236 rcall TFT_dive_compass_mk_print_3
2237 return
2238 TFT_dive_compass_mk_print_3:
2239 movlw dive_compass_label_row
2240 movff WREG,win_top
2241 movlw dive_compass_label_height-.2
2242 movff WREG,win_height
2243 movlw d'2'
2244 movff WREG,win_width
2245 movlw d'2'
2246 movff WREG,win_bargraph
2247 movlw color_green
2248 btfss print_compass_label
2249 movlw color_red
2250 call TFT_set_color
2251 call TFT_box
1820 return 2252 return
1821 2253
1822 TFT_dive_compass_clr_label: 2254 TFT_dive_compass_clr_label:
1823 movlw dive_compass_label_row-.2 ; set top & height 2255 movlw dive_compass_label_row-.2 ; set top & height
1824 movff WREG,win_top 2256 movff WREG,win_top
1825 movlw dive_compass_label_height+.2 2257 movlw dive_compass_label_height+.2
1826 movff WREG,win_height 2258 movff WREG,win_height
1827 call TFT_dive_compass_clear 2259 rcall TFT_dive_compass_clear
1828 return 2260 return
1829 2261
1830 TFT_dive_compass_clr_ruler: 2262 TFT_dive_compass_clr_ruler:
1831 ; top tick 2263 ; top tick
1832 movlw dive_compass_tick_top_top ; set top & height 2264 movlw dive_compass_tick_top_top ; set top & height