comparison code_part1/OSTC_code_asm_part1/menu_logbook.asm @ 147:a1960295433b

Make loogbook search twice faster. + Cleanup inc/dec eeprom_address macros. + Cleanup loop menu_logbook2. + Make 2 bytes steps
author JeanDo
date Sun, 09 Jan 2011 16:04:02 +0100
parents c09b0be2e1e6
children c3ac603ba248
comparison
equal deleted inserted replaced
146:c09b0be2e1e6 147:a1960295433b
47 WIN_INVERT .0 47 WIN_INVERT .0
48 clrf divemins+0 ; Here: used as temp variables 48 clrf divemins+0 ; Here: used as temp variables
49 clrf divemins+1 49 clrf divemins+1
50 call I2CReset ; Reset I2C Bus 50 call I2CReset ; Reset I2C Bus
51 call get_free_EEPROM_location ; search from "here" backwards through the external memory 51 call get_free_EEPROM_location ; search from "here" backwards through the external memory
52 clrf temp1 ; max. 32KB
53 clrf temp2
54 52
55 movlw d'5' 53 movlw d'5'
56 movwf menupos ; Here: stores current position on display (5-x) 54 movwf menupos ; Here: stores current position on display (5-x)
57 55
56 ;-----------------------------------------------------------------------------
57 ; search external EEPROM backwards from eeprom_address
58 ; for 0xFA, 0xFA (store 1st. 0xFA position for next search)
59 ; read header data and display it
60 ; wait for user to confirm/exit
61 ; recopy data to search from here
62
58 menu_logbook1b: 63 menu_logbook1b:
59 ; search external EEPROM backwards from eeprom_address
60 ; for 0xFA, 0xFA (store 1st. 0xFA position for next search)
61 ; read header data and display it
62 ; wait for user to confirm/exit
63 ; recopy data to search from here
64 WIN_INVERT .1 64 WIN_INVERT .1
65 DISPLAYTEXT .12 ;" Wait.." 65 DISPLAYTEXT .12 ;" Wait.."
66 WIN_INVERT .0 66 WIN_INVERT .0
67 bcf first_FA ; clear flags 67
68 bcf second_FA 68 ;---- fast loop: check every other byte ----------------------------------
69
70 menu_logbook2: 69 menu_logbook2:
71 movlw d'1' ; increase 16Bit value 70 infsnz divemins+0,F ; increase 16Bit value
72 addwf divemins+0,F 71 incf divemins+1,F
73 movlw d'0' 72 infsnz divemins+0,F ; increase 16Bit value, twice
74 addwfc divemins+1,F 73 incf divemins+1,F
75 74
76 btfsc divemins+1,7 ; At 0x8000? 75 btfsc divemins+1,7 ; At 0x8000?
77 bra menu_logbook_reset ; yes, restart (if not empty) 76 bra menu_logbook_reset ; yes, restart (if not empty)
78 77
79 decf_eeprom_address d'1' ; Macro, that subtracts 8Bit from eeprom_address:2 with banking at 0x8000 78 decf_eeprom_address d'2' ; +2 to eeprom address.
80 79
81 call I2CREAD ; reads one byte (Slow! Better use Blockread!) 80 call I2CREAD ; reads one byte (Slow! Better use Blockread!)
82 81
83 btfsc first_FA ; 82 movlw 0xFA ; That was a FA ?
84 bra test_2nd_FA
85
86 bsf first_FA ; Found 1st. 0xFA?
87 movlw 0xFA
88 cpfseq SSPBUF 83 cpfseq SSPBUF
89 bcf first_FA ; No, clear flag 84 bra menu_logbook2 ; No: continue the fast loop...
90 bra menu_logbook3 ; and continue search 85
91 86 ;---- Slow check : was it before or after that one ? ---------------------
92 test_2nd_FA: 87
93 btfsc second_FA 88 incf_eeprom_address d'1' ; Been one step too far ?
94 bra test_FA_DONE 89 call I2CREAD ; reads one byte (Slow! Better use Blockread!)
95 90 movlw 0xFA ; That was a FA ?
96 bsf second_FA ; found 2nd 0xFA? 91 xorwf SSPBUF,W
97 movlw 0xFA 92 bz menu_loop_tooFar ; Got it !
98 cpfseq SSPBUF 93
99 rcall no_second_FA ; No, clear both flags! 94 decf_eeprom_address d'2' ; Instead, not far enough ?
100 bra menu_logbook3 ; and continue search 95 call I2CREAD ; reads one byte (Slow! Better use Blockread!)
96 infsnz divemins+0,F ; Keep in sync (-1+2 == +1)
97 incf divemins+1,F
98 movlw 0xFA ; It was the second FA ?
99 xorwf SSPBUF,W
100 bz test_FA_DONE
101 bra menu_logbook2 ; No: continue the fast loop...
102
103 menu_loop_tooFar;
104 movlw -.1 ; Correct counter too,
105 addwf divemins+0 ; by doing a 16bit decrement.
106 movlw 0
107 addwfc divemins+1
101 108
102 test_FA_DONE: ; Found 0xFA 0xFA! 109 test_FA_DONE: ; Found 0xFA 0xFA!
103 movff eeprom_address+0,eeprom_header_address+0 ; store current address into temp register 110 movff eeprom_address+0,eeprom_header_address+0 ; store current address into temp register
104 movff eeprom_address+1,eeprom_header_address+1 ; we must continue search here later 111 movff eeprom_address+1,eeprom_header_address+1 ; we must continue search here later
105 incf divenumber,F ; new header found, increase divenumber 112 incf divenumber,F ; new header found, increase divenumber
106 bra menu_logbook4 ; Done with searching, display the header! 113 bra menu_logbook4 ; Done with searching, display the header!
107
108 no_second_FA: ; discard both flags!
109 bcf second_FA
110 bcf first_FA
111 return
112
113
114 menu_logbook3:
115 movlw d'1' ; increase global counter
116 addwf temp1,F
117 movlw d'0'
118 addwfc temp2,F
119
120 btfsc temp2,7 ; 32KB searched?
121 bra menu_logbook3b ; Yes
122 bra menu_logbook2 ; No, not now
123
124 114
125 menu_logbook3b: 115 menu_logbook3b:
126 btfss logbook_page_not_empty ; Was there at least one dive? 116 btfss logbook_page_not_empty ; Was there at least one dive?
127 goto menu ; Not a single header was found, leave logbook. 117 goto menu ; Not a single header was found, leave logbook.
128 bra menu_logbook_display_loop2 ; rcall of get_free_eeprom_location not required here (faster) 118 bra menu_logbook_display_loop2 ; rcall of get_free_eeprom_location not required here (faster)
136 bra menu_logbook_display_loop2 ; rcall of get_free_eeprom_location not required here (faster) 126 bra menu_logbook_display_loop2 ; rcall of get_free_eeprom_location not required here (faster)
137 127
138 128
139 menu_logbook4: 129 menu_logbook4:
140 ; Adjust eeprom_address to set pointer on first headerbyte 130 ; Adjust eeprom_address to set pointer on first headerbyte
141 incf_eeprom_address d'3' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 131 incf_eeprom_address d'2' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
142 132
143 btfss logbook_profile_view ; Display profile (search routine is used in profileview, too) 133 btfss logbook_profile_view ; Display profile (search routine is used in profileview, too)
144 bra menu_logbook_display_loop ; No, display overwiev list 134 bra menu_logbook_display_loop ; No, display overwiev list
145 135
146 movf divesecs,W ; divenumber that is searched 136 movf divesecs,W ; divenumber that is searched
163 movff divenumber,mintemp+0 ; store all registered required to rebuilt the current logbookpage after the detail/profile view 153 movff divenumber,mintemp+0 ; store all registered required to rebuilt the current logbookpage after the detail/profile view
164 movff eeprom_header_address+0,decodata+0 ; several registers are used as temp registers here 154 movff eeprom_header_address+0,decodata+0 ; several registers are used as temp registers here
165 movff eeprom_header_address+1,decodata+1 155 movff eeprom_header_address+1,decodata+1
166 movff divemins+0,max_pressure+0 156 movff divemins+0,max_pressure+0
167 movff divemins+1,max_pressure+1 157 movff divemins+1,max_pressure+1
168 movff temp1,logbook_temp6
169 movff temp2,samplesecs
170 158
171 movlw d'3' 159 movlw d'3'
172 addwf decodata+0,F 160 addwf decodata+0,F
173 movlw d'0' 161 movlw d'0'
174 addwfc decodata+1,F ; Re-Adjust pointer again 162 addwfc decodata+1,F ; Re-Adjust pointer again
629 bra profile_view_get_depth_new1 ; no 0xFD 617 bra profile_view_get_depth_new1 ; no 0xFD
630 bsf second_FD ; End found! Set Flag! Skip remaining pixels! 618 bsf second_FD ; End found! Set Flag! Skip remaining pixels!
631 return 619 return
632 620
633 profile_view_get_depth_new1: 621 profile_view_get_depth_new1:
634 ;bra profile_view_get_depth_new1_1 ; Skip all data to ignore...
635
636 ; decfsz divisor_deco,F ; Check divisor
637 ; bra profile_view_get_depth_new1_1 ; Divisor not zero...
638 ;
639 ;; tstfsz timeout_counter2 ; Any bytes to ignore
640 ;; bra profile_view_get_depth_new2 ; Yes (1-127)
641 ;; return ; No (0)
642 ;
643 ; movff logbook_temp2,divisor_deco ; Restore divisor value!
644 ;; check for event byte and the extra informations
645 ; btfss event_occured
646 ; bra profile_view_get_depth_new2 ; No event!
647 ;
648 ; call I2CREAD2 ; read event byte
649 ; decf timeout_counter2,F ; Reduce number of bytes to ignore
650 ;
651 ; movlw d'0' ; Extra bytes to ignore because of event
652 ; btfsc SSPBUF,4
653 ; addlw d'2' ; two bytes for manual gas set
654 ; btfsc SSPBUF,5
655 ; addlw d'1' ; one byte for gas change
656 ; movwf logbook_temp5 ; store extra bytes to ignore
657 ;
658 ; tstfsz logbook_temp5 ; Anything to ignore?
659 ; bra profile_view_get_depth_new1_2 ; Yes
660 ; bra profile_view_get_depth_new2 ; No, continue with normal routine
661 ;
662 ;profile_view_get_depth_new1_2:
663 ; call I2CREAD2 ; ignore byte
664 ; decf timeout_counter2,F ; Reduce number of bytes to ignore
665 ; decfsz logbook_temp5,F ; reduce extra bytes ignore counter
666 ; bra profile_view_get_depth_new1_2 ; loop
667 ;
668 ;profile_view_get_depth_new2:
669 ; movlw d'4' ; Temp (2) and Deko (2) in the sample?
670 ; cpfseq timeout_counter2
671 ; bra profile_view_get_depth_new2_2 ; No
672 ; ; Yes, skip Temp!
673 ; call I2CREAD2 ; ignore byte
674 ; decf timeout_counter2,F ; Reduce number of bytes to ignore
675 ; call I2CREAD2 ; ignore byte
676 ; decf timeout_counter2,F ; Reduce number of bytes to ignore
677 ;
678 ;profile_view_get_depth_new2_2:
679 ; call I2CREAD2 ; ignore byte
680 ;
681 ; decfsz timeout_counter2,F ; reduce counter
682 ; bra profile_view_get_depth_new2_2; Loop
683 ; return
684
685 profile_view_get_depth_new1_1:
686 tstfsz timeout_counter2 ; Any bytes to ignore 622 tstfsz timeout_counter2 ; Any bytes to ignore
687 bra profile_view_get_depth_new3 ; Yes (1-127) 623 bra profile_view_get_depth_new3 ; Yes (1-127)
688 return ; No (0) 624 return ; No (0)
689 625
690 ; timeout_counter2 now holds the number of additional bytes to ignore (0-127) 626 ; timeout_counter2 now holds the number of additional bytes to ignore (0-127)
700 movff decodata+0,eeprom_address+0 636 movff decodata+0,eeprom_address+0
701 movff decodata+1,eeprom_address+1 637 movff decodata+1,eeprom_address+1
702 movff max_pressure+0,divemins+0 638 movff max_pressure+0,divemins+0
703 movff max_pressure+1,divemins+1 639 movff max_pressure+1,divemins+1
704 movff mintemp+0, divenumber 640 movff mintemp+0, divenumber
705 movff logbook_temp6,temp1
706 movff samplesecs,temp2
707 decf divenumber,F 641 decf divenumber,F
708 bcf all_dives_shown 642 bcf all_dives_shown
709 643
710 decf menupos2,F 644 decf menupos2,F
711 645
824 movff SSPBUF,hi 758 movff SSPBUF,hi
825 bsf leftbind 759 bsf leftbind
826 output_16 ; Divetime minutes 760 output_16 ; Divetime minutes
827 STRCAT_PRINT "'" ; Display header-row in list 761 STRCAT_PRINT "'" ; Display header-row in list
828 return 762 return
829
830
831 ;profileview_menu:
832 ; movlw d'1'
833 ; movwf menupos
834 ;profileview_menu1:
835 ; call PLED_clear_divemode_menu
836 ; call PLED_profileview_menu ; Displays Menu
837 ;profileview_menu2:
838 ; call PLED_divemenu_cursor
839 ; bcf sleepmode ; clear some flags
840 ; bcf menubit2
841 ; bcf menubit3
842 ; bcf switch_right
843 ; bcf switch_left
844 ; clrf timeout_counter2
845 ;
846 ;profileview_menu_loop:
847 ; call check_switches_logbook
848 ;
849 ; btfsc menubit3 ; SET/MENU?
850 ; bra profileview_menu_move_cursor; Move Cursor
851 ; btfsc menubit2 ; ENTER?
852 ; bra profileview_menu_do ; Do task
853 ;
854 ; btfsc onesecupdate
855 ; call timeout_surfmode ; timeout
856 ; btfsc onesecupdate
857 ; call set_dive_modes ; check, if divemode must be entered
858 ; bcf onesecupdate ; one second update
859 ; btfsc sleepmode ; Timeout?
860 ; bra exit_profileview ; back to list
861 ; btfsc divemode
862 ; goto restart ; Enter Divemode if required
863 ;
864 ; bra profileview_menu_loop ; wait for something to do
865 ;
866 ;profileview_menu_do:
867 ; dcfsnz menupos,F
868 ; bra exit_profileview ; back to list, quit profileview menu
869 ; dcfsnz menupos,F
870 ; bra profileview_menu_delete ; Delete Dive from external EEPROM
871 ;; dcfsnz menupos,F
872 ;; bra profileview_menu_format ; Delete all Dives from external EEPROM
873 ;;
874 ;profileview_menu_move_cursor:
875 ; incf menupos,F
876 ; movlw d'3' ; number of menu options+1
877 ; cpfseq menupos ; =limit?
878 ; bra profileview_menu_move_cursor2 ; No!
879 ; movlw d'1' ; Yes, reset to position 1!
880 ; movwf menupos
881 ;profileview_menu_move_cursor2:
882 ; bra profileview_menu2 ; Return to Profile Menu, also updates cursor
883
884 ;profileview_menu_format:
885 ; call PLED_confirmbox ; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK!
886 ;
887 ; movwf menupos ; Used as temp
888 ; tstfsz menupos
889 ; bra profileview_menu_format_loop2 ; Format now!
890 ;
891 ; bra exit_profileview ; back to list, quit profileview menu
892 ;
893 ;profileview_menu_format_loop2: ; Do now format!
894 ; call PLED_ClearScreen
895 ; DISPLAYTEXT .12 ; "Wait.."
896 ; call reset_external_eeprom ; delete profile memory
897 ; goto menu ; Return to Menu
898
899 ;profileview_menu_delete:
900 ; call PLED_confirmbox ; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK!
901 ; movwf menupos ; Used as temp
902 ; tstfsz menupos
903 ; bra profileview_menu_delete_loop2 ; Delete now!
904 ;
905 ; bra exit_profileview ; back to list, quit profileview menu
906 ;
907 ;profileview_menu_delete_loop2: ; Do now delete
908 ; call PLED_ClearScreen
909 ; DISPLAYTEXT .12 ; "Wait.."
910 ;
911 ;; eeprom_address:2 is set to the second byte after the ending 0xFD 0xFD
912 ;; eeprom_address:2 - 1 -> set to the last byte after the 0xFD 0xFD of the current dive
913 ;
914 ;; Set pointer to Byte after the final "0xFD 0xFD"
915 ; decf_eeprom_address d'1' ; Macro, that subtracts 8Bit from eeprom_address:2 with banking at 0x8000
916 ; movff eeprom_address+0,divemins+0
917 ; movff eeprom_address+1,divemins+1
918 ;
919 ;; eeprom_header_address:2 + 1 -> set to the first 0xFA of the 0xFA 0xFA start bytes of the header
920 ; movlw d'1' ;
921 ; addwf eeprom_header_address+0,F
922 ; movlw d'0'
923 ; addwfc eeprom_header_address+1,F ; eeprom_header_address:2 + 1
924 ; btfsc eeprom_header_address+1,7 ; at 7FFF?
925 ; clrf eeprom_header_address+0 ; Yes, clear address (+0 first!)
926 ; btfsc eeprom_header_address+1,7 ; at 7FFF?
927 ; clrf eeprom_header_address+1 ; Yes, clear address
928 ;
929 ; movff divemins+0,eeprom_address+0
930 ; movff divemins+1,eeprom_address+1 ; Read source
931 ; call I2CREAD ; reads one byte (Slow! Better use Blockread!)
932 ; movwf profile_temp+0
933 ; movlw 0xFE
934 ; cpfseq profile_temp+0
935 ; bra profileview_menu_delete_notlast ; we're not deleting the last dive....
936 ;
937 ;; Just move the 0xFE after the dive and delete the rest with 0xFF
938 ; movff eeprom_header_address+0, eeprom_address+0
939 ; movff eeprom_header_address+1, eeprom_address+1 ; Write target
940 ; movlw 0xFE
941 ; call I2CWRITE ; Write the byte
942 ;
943 ;; Now, delete everything _between_ eeprom_header_address and divemins:2+2 with 0xFF
944 ; movlw d'1' ;
945 ; addwf eeprom_header_address+0,F
946 ; movlw d'0'
947 ; addwfc eeprom_header_address+1,F ; eeprom_header_address:2 + 1
948 ; btfsc eeprom_header_address+1,7 ; at 7FFF?
949 ; clrf eeprom_header_address+0 ; Yes, clear address (+0 first!)
950 ; btfsc eeprom_header_address+1,7 ; at 7FFF?
951 ; clrf eeprom_header_address+1 ; Yes, clear address
952 ;
953 ; movff eeprom_header_address+0,eeprom_address+0
954 ; movff eeprom_header_address+1,eeprom_address+1
955 ;
956 ; movlw d'1' ;
957 ; addwf divemins+0,F
958 ; movlw d'0'
959 ; addwfc divemins+1,F ; divemins:2 + 1
960 ; btfss divemins+1,7 ; at 7FFF?
961 ; bra profileview_menu_delete_loop2a ; Skip
962 ; clrf divemins+0 ; Yes, clear address
963 ; clrf divemins+1
964 ;
965 ;; movff eeprom_header_address+0,eeprom_address+0
966 ;; movff eeprom_header_address+1,eeprom_address+1
967 ;
968 ;
969 ;profileview_menu_delete_loop2a:
970 ; movlw 0xFF
971 ; call I2CWRITE ; Write the byte
972 ;
973 ; incf_eeprom_address d'1' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
974 ;
975 ; movff divemins+0,sub_a+0
976 ; movff divemins+1,sub_a+1
977 ; movff eeprom_address+0,sub_b+0
978 ; movff eeprom_address+1,sub_b+1
979 ; call sub16 ; sub_c = sub_a - sub_b
980 ; tstfsz sub_c+0 ; Done (Result=Zero?) ?
981 ; bra profileview_menu_delete_loop2a ; No, continue
982 ; tstfsz sub_c+1 ; Done (Result=Zero?) ?
983 ; bra profileview_menu_delete_loop2a ; No, continue
984 ; goto menu_logbook ; Return to list when done deleting
985 ;
986 ;profileview_menu_delete_notlast:
987 ;; Move everything byte-wise from divemins:2 to eeprom_header_address:2 until 0xFD 0xFD 0xFE is found and were moved
988 ; call get_free_EEPROM_location ; Searches 0xFD, 0xFD, 0xFE and sets Pointer to 0xFE
989 ;
990 ; incf_eeprom_address d'2' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
991 ; movff eeprom_address+0,profile_temp+0
992 ; movff eeprom_address+1,profile_temp+1
993 ;; holds now address of 0xFE + 2 (Abort condition....)
994 ; decf_eeprom_address d'2' ; Macro, that subtracts 8Bit from eeprom_address:2 with banking at 0x8000
995 ;; holds now address of 0xFE again
996 ; movff eeprom_address+0,divemins+0
997 ; movff eeprom_address+1,divemins+1 ; Copy to working read registers
998 ;
999 ;profileview_menu_delete_loop3:
1000 ; movff divemins+0,eeprom_address+0
1001 ; movff divemins+1,eeprom_address+1 ; Read source
1002 ; call I2CREAD ; reads one byte (Slow! Better use Blockread!)
1003 ; movff eeprom_header_address+0, eeprom_address+0
1004 ; movff eeprom_header_address+1, eeprom_address+1 ; Write target
1005 ; call I2CWRITE ; Write the byte
1006 ;
1007 ; movff divemins+0,eeprom_address+0
1008 ; movff divemins+1,eeprom_address+1 ; Set to source again
1009 ; movlw 0xFF
1010 ; call I2CWRITE ; Delete the source....
1011 ;
1012 ; movlw d'1'
1013 ; addwf divemins+0,F ; Increase source (Divemins:2)
1014 ; movlw d'0'
1015 ; addwfc divemins+1,F
1016 ; btfsc divemins+1,7 ; at 0x8000?
1017 ; clrf divemins+0 ; Yes, clear address (+0 first!)
1018 ; btfsc divemins+1,7 ; at 0x8000?
1019 ; clrf divemins+1 ; Yes, clear address
1020 ;
1021 ; movlw d'1' ; Increase target (eeprom_header_address:2)
1022 ; addwf eeprom_header_address+0,F
1023 ; movlw d'0'
1024 ; addwfc eeprom_header_address+1,F ; eeprom_header_address:2 + 1
1025 ; btfsc eeprom_header_address+1,7 ; at 7FFF?
1026 ; clrf eeprom_header_address+0 ; Yes, clear address (+0 first!)
1027 ; btfsc eeprom_header_address+1,7 ; at 7FFF?
1028 ; clrf eeprom_header_address+1 ; Yes, clear address
1029 ;
1030 ; movff divemins+0,sub_a+0
1031 ; movff divemins+1,sub_a+1
1032 ; movff profile_temp+0,sub_b+0
1033 ; movff profile_temp+1,sub_b+1
1034 ; call sub16 ; sub_c = sub_a - sub_b
1035 ; tstfsz sub_c+0 ; Done (Result=Zero?) ?
1036 ; bra profileview_menu_delete_loop3 ; No, continue
1037 ; tstfsz sub_c+1 ; Done (Result=Zero?) ?
1038 ; bra profileview_menu_delete_loop3 ; No, continue
1039 ;
1040 ; goto menu_logbook ; Return to list when done deleting
1041
1042
1043