comparison src/tft.asm @ 432:929feb0da4f5

hunting a bug in the logbook (Day 2)
author heinrichsweikamp
date Wed, 22 Jun 2016 12:36:15 +0200
parents 9500b2d3e32b
children a001f170a1f7
comparison
equal deleted inserted replaced
431:9500b2d3e32b 432:929feb0da4f5
504 ; Inputs: win_leftx2 504 ; Inputs: win_leftx2
505 ; Outputs: win_color:2 505 ; Outputs: win_color:2
506 ; Trashed: WREG, PROD 506 ; Trashed: WREG, PROD
507 global init_pixel_write 507 global init_pixel_write
508 init_pixel_write: 508 init_pixel_write:
509 movff win_leftx2,WREG 509 movf win_leftx2,W
510 mullw 2 510 mullw 2
511 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 511 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
512 setf WREG 512 setf WREG
513 bra TFT_set_color 513 bra TFT_set_color
514 514
516 ; Writes two half-pixels at position (win_top,win_leftx2) 516 ; Writes two half-pixels at position (win_top,win_leftx2)
517 ; Inputs: win_leftx2, win_top, win_color:2 517 ; Inputs: win_leftx2, win_top, win_color:2
518 ; Trashed: WREG, PROD 518 ; Trashed: WREG, PROD
519 global pixel_write 519 global pixel_write
520 pixel_write: 520 pixel_write:
521 movff win_leftx2,WREG 521 movf win_leftx2,W
522 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL 522 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL
523 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 523 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
524 rcall half_pixel_write ; Write this half-one. 524 rcall half_pixel_write ; Write this half-one.
525 525
526 movff win_leftx2,WREG ; Address of next one 526 movf win_leftx2,W ; Address of next one
527 mullw 2 527 mullw 2
528 infsnz PRODL ; +1 528 infsnz PRODL ; +1
529 incf PRODH 529 incf PRODH
530 rcall pixel_write_col320 530 rcall pixel_write_col320
531 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because 531 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because
560 ; Writes one half-pixel at position (win_top,win_leftx2). 560 ; Writes one half-pixel at position (win_top,win_leftx2).
561 ; Inputs: win_leftx2, win_top, win_color:2 561 ; Inputs: win_leftx2, win_top, win_color:2
562 ; Trashed: WREG, PROD 562 ; Trashed: WREG, PROD
563 global half_pixel_write 563 global half_pixel_write
564 half_pixel_write: 564 half_pixel_write:
565 movff win_top,WREG ; d'0' ... d'239' 565 movf win_top,W ; d'0' ... d'239'
566 ; Variant with Y position in WREG. 566 ; Variant with Y position in WREG.
567 half_pixel_write_1: 567 half_pixel_write_1:
568 btfss flip_screen ; 180° rotation? 568 btfss flip_screen ; 180° rotation?
569 sublw .239 ; 239-Y --> Y 569 sublw .239 ; 239-Y --> Y
570 mullw 1 ; Copy row to PRODL (PRODH=0) 570 mullw 1 ; Copy row to PRODL (PRODH=0)
586 global half_vertical_line 586 global half_vertical_line
587 half_vertical_line: 587 half_vertical_line:
588 clrf TABLAT ; Loop index. 588 clrf TABLAT ; Loop index.
589 589
590 half_vertical_line_loop: 590 half_vertical_line_loop:
591 movff win_leftx2,WREG ; Init X position. 591 movf win_leftx2,W ; Init X position.
592 mullw 2 592 mullw 2
593 movf TABLAT,W ; Get loop index 593 movf TABLAT,W ; Get loop index
594 andlw 1 ; Just low bit 594 andlw 1 ; Just low bit
595 xorwf PRODL,F ; And use it to jitter current X position 595 xorwf PRODL,F ; And use it to jitter current X position
596 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 596 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
597 597
598 movff win_height,WREG ; Index reached height (Bank0 read) ? 598 movf win_height,W ; Index reached height (Bank0 read) ?
599 xorwf TABLAT,W 599 xorwf TABLAT,W
600 btfsc STATUS,Z ; Equals ? 600 btfsc STATUS,Z ; Equals ?
601 return ; Yes: done. 601 return ; Yes: done.
602 movff win_top,WREG ; Y = top + index (Bank0 read) 602 movf win_top,W ; Y = top + index (Bank0 read)
603 addwf TABLAT,W 603 addwf TABLAT,W
604 rcall half_pixel_write_1 604 rcall half_pixel_write_1
605 incf TABLAT,F ; index++ 605 incf TABLAT,F ; index++
606 bra half_vertical_line_loop 606 bra half_vertical_line_loop
607 607
612 global half_horizontal_line 612 global half_horizontal_line
613 half_horizontal_line: 613 half_horizontal_line:
614 clrf TABLAT ; Loop index. 614 clrf TABLAT ; Loop index.
615 615
616 half_horizontal_line_loop: 616 half_horizontal_line_loop:
617 movff win_leftx2,WREG ; Init X position. 617 movf win_leftx2,W ; Init X position.
618 mullw 2 618 mullw 2
619 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 619 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
620 movff win_width,WREG ; Index reached height (Bank0 read) ? 620 movf win_width,W ; Index reached height (Bank0 read) ?
621 xorwf TABLAT,W 621 xorwf TABLAT,W
622 btfsc STATUS,Z ; Equals ? 622 btfsc STATUS,Z ; Equals ?
623 return ; Yes: done. 623 return ; Yes: done.
624 movff win_top,WREG ; Y = top + index (Bank0 read) 624 movf win_top,W ; Y = top + index (Bank0 read)
625 addwf TABLAT,W 625 addwf TABLAT,W
626 rcall half_pixel_write_1 626 rcall half_pixel_write_1
627 incf TABLAT,F ; index++ 627 incf TABLAT,F ; index++
628 bra half_horizontal_line_loop 628 bra half_horizontal_line_loop
629 629
634 global TFT_DataWrite_PROD 634 global TFT_DataWrite_PROD
635 TFT_DataWrite_PROD: 635 TFT_DataWrite_PROD:
636 ; RD_H ; Keep high 636 ; RD_H ; Keep high
637 RS_H ; Data 637 RS_H ; Data
638 movff PRODH,PORTA ; Move high byte to PORTA 638 movff PRODH,PORTA ; Move high byte to PORTA
639 movff PRODL,PORTH ; Move low byte to PORTH 639 movff PRODL,PORTH ; Move low byte to PORTH
640 WR_L 640 WR_L
641 WR_H ; Tick 641 WR_H ; Tick
642 return 642 return
643 643
644 TFT_DataRead_PROD: 644 TFT_DataRead_PROD:
674 ; Output : PortA/PortH commands. 674 ; Output : PortA/PortH commands.
675 ; Trashed: PROD 675 ; Trashed: PROD
676 ; 676 ;
677 global TFT_box_write 677 global TFT_box_write
678 TFT_box_write: 678 TFT_box_write:
679 movff win_leftx2,WREG ; Compute left = 2*leftx2 --> PROD 679 movf win_leftx2,W ; Compute left = 2*leftx2 --> PROD
680 mullw 2 680 mullw 2
681 681
682 global TFT_box_write_16bit_win_left 682 global TFT_box_write_16bit_win_left
683 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH 683 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH
684 btfsc screen_type ; display1? 684 btfsc screen_type ; display1?
685 bra TFT_box_write_16bit_win_left_d1 ; Yes 685 bra TFT_box_write_16bit_win_left_d1 ; Yes
691 btfss flip_screen ; 180° rotation? 691 btfss flip_screen ; 180° rotation?
692 bra DISP_box_flip_H ; No for d1 692 bra DISP_box_flip_H ; No for d1
693 ; Yes for d1 693 ; Yes for d1
694 TFT_box_write_16bit_win_left_com: 694 TFT_box_write_16bit_win_left_com:
695 ;---- Normal horizontal window --------------------------------------- 695 ;---- Normal horizontal window ---------------------------------------
696 Index_out 0x52 ; Window Vertical Start Address 696 Index_out 0x52 ; Window Vertical Start Address
697 rcall TFT_DataWrite_PROD ; Output left 697 rcall TFT_DataWrite_PROD ; Output left
698 Index_out 0x21 ; Frame Memory Vertical Address 698 Index_out 0x21 ; Frame Memory Vertical Address
699 rcall TFT_DataWrite_PROD ; Output left 699 rcall TFT_DataWrite_PROD ; Output left
700 700
701 movff win_width+0,WREG ; right = left + width - 1 701 movf win_width+0,W ; right = left + width - 1
702 addwf PRODL,F 702 addwf PRODL,F
703 movff win_width+1,WREG 703 movf win_width+1,W
704 addwfc PRODH,F 704 addwfc PRODH,F
705 decf PRODL,F ; decrement result 705 decf PRODL,F ; decrement result
706 btfss STATUS,C 706 btfss STATUS,C
707 decf PRODH,F 707 decf PRODH,F
708 708
709 Index_out 0x53 ; Window Vertical End Address 709 Index_out 0x53 ; Window Vertical End Address
710 rcall TFT_DataWrite_PROD 710 rcall TFT_DataWrite_PROD
711 bra DISP_box_noflip_H 711 bra DISP_box_noflip_H
712 712
713 ;---- Flipped horizontal window -------------------------------------- 713 ;---- Flipped horizontal window --------------------------------------
714 DISP_box_flip_H: 714 DISP_box_flip_H:
715 movf PRODL,W ; 16bits 319 - PROD --> PROD 715 movf PRODL,W ; 16bits 319 - PROD --> PROD
716 sublw LOW(.319) ; 319-W --> W 716 sublw LOW(.319) ; 319-W --> W
719 btfss STATUS,C ; Borrow = /CARRY 719 btfss STATUS,C ; Borrow = /CARRY
720 incf WREG 720 incf WREG
721 sublw HIGH(.319) 721 sublw HIGH(.319)
722 movwf PRODH 722 movwf PRODH
723 723
724 Index_out 0x53 ; Window Vertical Start Address 724 Index_out 0x53 ; Window Vertical Start Address
725 rcall TFT_DataWrite_PROD ; Output left 725 rcall TFT_DataWrite_PROD ; Output left
726 Index_out 0x21 ; Frame Memory Vertical Address 726 Index_out 0x21 ; Frame Memory Vertical Address
727 rcall TFT_DataWrite_PROD ; Output left 727 rcall TFT_DataWrite_PROD ; Output left
728 728
729 movff win_width+0,WREG ; 16bits PROD - width --> PROD 729 movf win_width+0,W ; 16bits PROD - width --> PROD
730 subwf PRODL,F ; PRODL - WREG --> PRODL 730 subwf PRODL,F ; PRODL - WREG --> PRODL
731 movff win_width+1,WREG 731 movf win_width+1,W
732 subwfb PRODH,F 732 subwfb PRODH,F
733 infsnz PRODL ; PROD+1 --> PROD 733 infsnz PRODL ; PROD+1 --> PROD
734 incf PRODH 734 incf PRODH
735 735
736 Index_out 0x52 ; Window Vertical End Address 736 Index_out 0x52 ; Window Vertical End Address
737 rcall TFT_DataWrite_PROD 737 rcall TFT_DataWrite_PROD
738 738
739 DISP_box_noflip_H: 739 DISP_box_noflip_H:
740 btfss flip_screen ; 180° rotation ? 740 btfss flip_screen ; 180° rotation ?
741 bra TFT_box_noflip_V ; No. 741 bra TFT_box_noflip_V ; No.
742 742
743 ;---- Flipped vertical window ----------------------------------------- 743 ;---- Flipped vertical window -----------------------------------------
744 movff win_top,PRODH ; top --> PRODH (first byte) 744 movff win_top,PRODH ; top --> PRODH (first byte)
745 movff win_height,WREG 745 movf win_height,W
746 addwf PRODH,W 746 addwf PRODH,W
747 decf WREG 747 decf WREG
748 movwf PRODL ; top+height-1 --> PRODL (second byte) 748 movwf PRODL ; top+height-1 --> PRODL (second byte)
749 749
750 Index_out 0x50 ; Window Horizontal Start Address 750 Index_out 0x50 ; Window Horizontal Start Address
751 movf PRODH,W 751 movf PRODH,W
752 rcall TFT_DataWrite ; Lower (and tick) 752 rcall TFT_DataWrite ; Lower (and tick)
753 753
754 Index_out 0x51 ; Window Horizontal End Address 754 Index_out 0x51 ; Window Horizontal End Address
755 movf PRODL,W 755 movf PRODL,W
756 rcall TFT_DataWrite ; Lower (and tick) 756 rcall TFT_DataWrite ; Lower (and tick)
757 757
758 Index_out 0x20 ; Frame Memory Horizontal Address 758 Index_out 0x20 ; Frame Memory Horizontal Address
759 movf PRODH,W 759 movf PRODH,W
760 bra TFT_DataWrite ; Lower (and tick) and return 760 bra TFT_DataWrite ; Lower (and tick) and return
761 ; return 761 ; return
762 762
763 763
764 TFT_box_noflip_V: 764 TFT_box_noflip_V:
765 ;---- Normal vertical window ---------------------------------------- 765 ;---- Normal vertical window ----------------------------------------
766 movff win_top,PRODL 766 movff win_top,PRODL
767 movff win_height,WREG 767 movf win_height,W
768 addwf PRODL,W 768 addwf PRODL,W
769 sublw .240 ; 240 - top - height 769 sublw .240 ; 240 - top - height
770 movwf PRODH ; First byte 770 movwf PRODH ; First byte
771 771
772 movf PRODL,W 772 movf PRODL,W
773 sublw .239 ; 239-top 773 sublw .239 ; 239-top
774 movwf PRODL ; --> second byte. 774 movwf PRODL ; --> second byte.
775 775
776 Index_out 0x50 ; Window Horizontal Start Address 776 Index_out 0x50 ; Window Horizontal Start Address
777 movf PRODH,W 777 movf PRODH,W
778 rcall TFT_DataWrite ; Lower (and tick) 778 rcall TFT_DataWrite ; Lower (and tick)
779 779
780 Index_out 0x51 ; Window Horizontal End Address 780 Index_out 0x51 ; Window Horizontal End Address
781 movf PRODL,W 781 movf PRODL,W
782 rcall TFT_DataWrite ; Lower (and tick) 782 rcall TFT_DataWrite ; Lower (and tick)
783 783
784 Index_out 0x20 ; Frame Memory Horizontal Address 784 Index_out 0x20 ; Frame Memory Horizontal Address
785 movf PRODL,W 785 movf PRODL,W
786 bra TFT_DataWrite ; Lower (and tick) and return 786 bra TFT_DataWrite ; Lower (and tick) and return
787 ;return 787 ; return
788
789 788
790 ;============================================================================= 789 ;=============================================================================
791 ; TFT_frame : draw a frame around current box with current color. 790 ; TFT_frame : draw a frame around current box with current color.
792 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 791 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2
793 ; Outputs: (none) 792 ; Outputs: (none)
799 movff win_leftx2,save_left 798 movff win_leftx2,save_left
800 movff win_width,save_width 799 movff win_width,save_width
801 800
802 ;---- TOP line ----------------------------------------------------------- 801 ;---- TOP line -----------------------------------------------------------
803 movlw 1 ; row ~ height=1 802 movlw 1 ; row ~ height=1
804 movff WREG,win_height 803 movwf win_height
805 rcall TFT_box 804 rcall TFT_box
806 805
807 ;---- BOTTOM line -------------------------------------------------------- 806 ;---- BOTTOM line --------------------------------------------------------
808 movff save_top,PRODL ; Get back top, 807 movff save_top,PRODL ; Get back top,
809 movff save_height,WREG ; and height 808 movff save_height,WREG ; and height
810 addwf PRODL,W ; top+height 809 addwf PRODL,W ; top+height
811 decf WREG ; top+height-1 810 decf WREG ; top+height-1
812 movff WREG,win_top ; top+height-1 --> top 811 movwf win_top ; top+height-1 --> top
813 rcall TFT_box 812 rcall TFT_box
814 813
815 ;---- LEFT column -------------------------------------------------------- 814 ;---- LEFT column --------------------------------------------------------
816 movff save_top,win_top ; Restore top/height. 815 movff save_top,win_top ; Restore top/height.
817 movff save_height,win_height 816 movff save_height,win_height
818 movlw 1 ; column ~ width=1 817 movlw 1 ; column ~ width=1
819 movff WREG,win_width 818 movwf win_width+0
820 rcall TFT_box 819 rcall TFT_box
821 820
822 ;---- RIGHT column ------------------------------------------------------- 821 ;---- RIGHT column -------------------------------------------------------
823 movff save_left,WREG 822 movff save_left,WREG
824 movff save_width,PRODL 823 movff save_width,PRODL
825 addwf PRODL,W 824 addwf PRODL,W
826 decf WREG 825 decf WREG
827 movff WREG,win_leftx2 826 movwf win_leftx2
828 rcall TFT_box 827 rcall TFT_box
829 828
830 ;---- Restore everything ------------------------------------------------- 829 ;---- Restore everything -------------------------------------------------
831 movff save_left,win_leftx2 830 movff save_left,win_leftx2
832 movff save_width,win_width 831 movff save_width,win_width
833 return 832 return
839 ; Trashed: WREG, PROD 838 ; Trashed: WREG, PROD
840 global TFT_box 839 global TFT_box
841 840
842 TFT_box: 841 TFT_box:
843 ;---- Define Window ------------------------------------------------------ 842 ;---- Define Window ------------------------------------------------------
844 ; movf win_width+0,W 843 bcf STATUS,C
845 ; bcf STATUS,C 844 rlcf win_width+0,F
846 ; rlcf WREG 845 rlcf win_width+1,F ; x2
847 ; movwf win_width+0 846 rcall TFT_box_write ; Setup box
848 bcf STATUS,C
849 rlcf win_width+0,F
850 movlw 0
851 rlcf WREG
852 movwf win_width+1
853 rcall TFT_box_write ; Setup box
854 847
855 global TFT_box_16bit_win_left 848 global TFT_box_16bit_win_left
856 TFT_box_16bit_win_left: 849 TFT_box_16bit_win_left:
857 bcf STATUS,C 850 bcf STATUS,C
858 rrcf win_width+1,F ; width /= 2 851 rrcf win_width+1,F ; width /= 2
859 rrcf win_width+0,F 852 rrcf win_width+0,F
860 ; movwf win_width
861 853
862 ;---- Fill Window -------------------------------------------------------- 854 ;---- Fill Window --------------------------------------------------------
863 Index_out 0x22 ; Frame Memory Data Write start 855 Index_out 0x22 ; Frame Memory Data Write start
864 856
865 clrf PRODH ; Column counter. 857 clrf PRODH ; Column counter.
866 RS_H ; Data 858 RS_H ; Data
867 859
868 TFT_box2: ; Loop height times 860 TFT_box2: ; Loop height times
869 movff win_height,PRODL 861 movff win_height,PRODL
870 862
871 TFT_box3: ; loop width times 863 TFT_box3: ; loop width times
878 ; movff win_color2,PORTH ; Lower 870 ; movff win_color2,PORTH ; Lower
879 WR_L 871 WR_L
880 WR_H ; Tick 872 WR_H ; Tick
881 873
882 decfsz PRODL,F ; row loop finished ? 874 decfsz PRODL,F ; row loop finished ?
883 bra TFT_box3 ; No: continue. 875 bra TFT_box3 ; No: continue.
884 876
885 incf PRODH,F ; column count ++ 877 incf PRODH,F ; column count ++
886 878
887 movff win_bargraph,WREG ; current column == bargraph ? 879 movf win_bargraph,W ; current column == bargraph ?
888 cpfseq PRODH 880 cpfseq PRODH
889 bra TFT_box4 ; No: just loop. 881 bra TFT_box4 ; No: just loop.
890 882 ; Yes: switch to black
891 clrf WREG ; Yes: switch to black 883 clrf win_color1
892 movff WREG,win_color1 884 clrf win_color2
893 movff WREG,win_color2
894 TFT_box4: 885 TFT_box4:
895 886 movf win_width+0,W ; compare ?
896 movff win_width+0,WREG ; compare ?
897 xorwf PRODH,W 887 xorwf PRODH,W
898 bnz TFT_box2 ; Loop not finished. 888 bnz TFT_box2 ; Loop not finished.
899 889
900 movlw 0x00 ; NOP, to stop window mode 890 movlw 0x00 ; NOP, to stop window mode
901 rcall TFT_CmdWrite 891 rcall TFT_CmdWrite
902 892
903 setf WREG ; Reset bargraph mode... 893 ; Reset bargraph mode...
904 movff WREG,win_bargraph 894 setf win_bargraph
905 895 return
906 return
907 896
908 ;============================================================================= 897 ;=============================================================================
909 ;Converts 8Bit RGB b'RRRGGGBB' into 16Bit RGB b'RRRRRGGGGGGBBBBB' 898 ;Converts 8Bit RGB b'RRRGGGBB' into 16Bit RGB b'RRRRRGGGGGGBBBBB'
910 global TFT_set_color 899 global TFT_set_color
911 900
955 944
956 rrcf tft_temp4,F 945 rrcf tft_temp4,F
957 rrcf tft_temp3,F 946 rrcf tft_temp3,F
958 947
959 rrcf tft_temp4,F 948 rrcf tft_temp4,F
960 rrcf tft_temp3,F ; tft_temp3 (b'GGGBBBBB') done. 949 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done.
950 movwf win_color2 ; Set Color registers...
961 951
962 movff tft_temp1, tft_temp2 ; Copy 952 movff tft_temp1, tft_temp2 ; Copy
963 clrf tft_temp1 953 clrf tft_temp1
964 954
965 rrcf tft_temp4,F 955 rrcf tft_temp4,F
1009 999
1010 rrcf tft_temp4,F 1000 rrcf tft_temp4,F
1011 rrcf tft_temp1,F 1001 rrcf tft_temp1,F
1012 1002
1013 rrcf tft_temp4,F 1003 rrcf tft_temp4,F
1014 rrcf tft_temp1,F ; Red done. 1004 rrcf tft_temp1,W ; Red done.
1015 1005 movwf win_color1 ; Set Color registers...
1016 movff tft_temp1,win_color1
1017 movff tft_temp3,win_color2 ; Set Bank0 Color registers...
1018 return 1006 return
1019 1007
1020 ;============================================================================= 1008 ;=============================================================================
1021 ; Dump screen contents to the UART 1009 ; Dump screen contents to the UART
1022 1010