comparison code_part1/OSTC_code_asm_part1/menu_custom.asm @ 573:77c8ff191cd7

Preparations for third bank of Custom Functions
author heinrichsweikamp
date Sat, 21 Apr 2012 12:09:37 +0200
parents fd8266b511cc
children 101fec6a6137
comparison
equal deleted inserted replaced
572:80a1d2d5a9ee 573:77c8ff191cd7
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>. 15 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17 17
18 ; Menu "Custom Functions", Custom Functions checker (Displays permanent warning if critical custom functions are altered) 18 ; Menu "Custom Functions", Custom Functions checker (Displays permanent warning if critical custom functions are altered)
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com 19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
20 ; written: 05/10/30 20 ; written: 051030
21 ; last updated: 2010/12/11 21 ; last updated: 120421
22 ; known bugs: 22 ; known bugs:
23 ; ToDo: 23 ; ToDo:
24 24
25 ;First Bank of Custom Functions: 25 ;First Bank of Custom Functions:
26 ; The custom functions are stored in the internal EEPROM after 0x80 26 ; The custom functions are stored in the internal EEPROM after 0x80
32 ; get values with GETCUSTOM8 .x with x=0...32 for 8 Bit values (stored in WREG) 32 ; get values with GETCUSTOM8 .x with x=0...32 for 8 Bit values (stored in WREG)
33 ; or with GETCUSTOM15 .x with x=0...32 for 15 Bit values (stored in lo and hi) 33 ; or with GETCUSTOM15 .x with x=0...32 for 15 Bit values (stored in lo and hi)
34 34
35 ;Second Bank of Custom Functions: 35 ;Second Bank of Custom Functions:
36 ; The custom functions are stored in the internal EEPROM after 0x180 36 ; The custom functions are stored in the internal EEPROM after 0x180
37 ; any custom function occupies 4 byte:
38 ; 2 byte (low:high) store the default value, reset from menu "reset"
39 ; if bit16=1 then the custrom function is 15bit value, if not it's a 8bit value
40 ; 2 byte (low:high) store the actual value
41 ; defaults for custom functions are in menu "reset"
42 ; get values with GETCUSTOM8 .x with x=0...32 for 8 Bit values (stored in WREG)
43 ; or with GETCUSTOM15 .x with x=0...32 for 15 Bit values (stored in lo and hi)
44
45 ;Third Bank of Custom Functions:
46 ; The custom functions are stored in the internal EEPROM after 0x280
37 ; any custom function occupies 4 byte: 47 ; any custom function occupies 4 byte:
38 ; 2 byte (low:high) store the default value, reset from menu "reset" 48 ; 2 byte (low:high) store the default value, reset from menu "reset"
39 ; if bit16=1 then the custrom function is 15bit value, if not it's a 8bit value 49 ; if bit16=1 then the custrom function is 15bit value, if not it's a 8bit value
40 ; 2 byte (low:high) store the actual value 50 ; 2 byte (low:high) store the actual value
41 ; defaults for custom functions are in menu "reset" 51 ; defaults for custom functions are in menu "reset"
66 ; 76 ;
67 CF_INT15 EQU 0x80; Default display. Flag for 15bit, typeless values. 77 CF_INT15 EQU 0x80; Default display. Flag for 15bit, typeless values.
68 78
69 ;============================================================================= 79 ;=============================================================================
70 ; Overlay our tmp data in ACCESS0 bank 80 ; Overlay our tmp data in ACCESS0 bank
71 CBLOCK 0x010 ; Keep space for aa_wordprocessor module. 81 CBLOCK tmp ; Into safe (from C library) area.
72 cf32_x4 ; CF# modulus 32, time 4. 82 cf32_x4 ; CF# modulus 32, time 4.
73 cf_type ; Type of the edited CF 83 cf_type ; Type of the edited CF
74 cf_default:2 84 cf_default:2
75 cf_value:2 85 cf_value:2
76 cf_min 86 cf_min
77 cf_max 87 cf_max
78 cf_step ; Value ad add/substract: 1, 10, 100 88 cf_step ; Value ad add/substract: 1, 10, 100
89 cf_page_number ; CF page number (0: 0-31, 1: 32-63)
90 cf_title_text ; # of text for title
91 cf_descriptor_text ; # of descriptor text offset
79 ENDC 92 ENDC
80 93
81 ;============================================================================= 94 ;=============================================================================
82 95
83 GETCUSTOM8 macro custom8 96 GETCUSTOM8 macro custom8
85 call getcustom8_1 98 call getcustom8_1
86 endm 99 endm
87 100
88 getcustom8_1: 101 getcustom8_1:
89 ; # number of requested custom function in wreg 102 ; # number of requested custom function in wreg
90 movwf customfunction_temp2 103 movwf customfunction_temp1
91 104
105 clrf EEADRH
92 movlw d'31' 106 movlw d'31'
93 cpfsgt customfunction_temp2 107 cpfsgt customfunction_temp1
94 bra getcustom8_2 ; Lower bank 108 bra getcustom8_3 ; bank 0
95 109
96 movlw d'1' ; Upper Bank 110 movlw d'1'
97 movwf EEADRH 111 movwf EEADRH ; bank 1
98 movlw d'32' 112 movlw d'32'
99 subwf customfunction_temp2,F 113 subwf customfunction_temp1,F
100 bra getcustom8_3 114 movlw d'63'
101 115 cpfsgt customfunction_temp1
102 getcustom8_2: 116 bra getcustom8_3 ; bank 1
103 clrf EEADRH 117
118 movlw d'2'
119 movwf EEADRH ; bank 2
120 movlw d'64'
121 subwf customfunction_temp1,F
104 getcustom8_3: 122 getcustom8_3:
105 movf customfunction_temp2,W 123 movf customfunction_temp1,W
106 mullw d'4' 124 mullw d'4'
107 movf PRODL,W ; x4 for adress 125 movf PRODL,W ; x4 for adress
108 addlw d'130' 126 addlw d'130'
109 movwf EEADR ; +130 for LOW Byte of value 127 movwf EEADR ; +130 for LOW Byte of value
110 call read_eeprom ; Lowbyte 128 call read_eeprom ; Lowbyte
118 endm 136 endm
119 137
120 global getcustom15 138 global getcustom15
121 getcustom15: 139 getcustom15:
122 ; # number of requested custom function in wreg 140 ; # number of requested custom function in wreg
123 movwf customfunction_temp2 141 movwf customfunction_temp1
124 142
143 clrf EEADRH
125 movlw d'31' 144 movlw d'31'
126 cpfsgt customfunction_temp2 145 cpfsgt customfunction_temp1
127 bra getcustom15_2 ; Lower bank 146 bra getcustom15_3 ; bank 0
128 147
129 movlw d'1' ; Upper Bank 148 movlw d'1'
130 movwf EEADRH 149 movwf EEADRH ; bank 1
131 movlw d'32' 150 movlw d'32'
132 subwf customfunction_temp2,F 151 subwf customfunction_temp1,F
133 bra getcustom15_3 152 movlw d'63'
134 getcustom15_2: 153 cpfsgt customfunction_temp1
135 clrf EEADRH 154 bra getcustom15_3 ; bank 1
155
156 movlw d'2'
157 movwf EEADRH ; bank 2
158 movlw d'64'
159 subwf customfunction_temp1,F
136 getcustom15_3: 160 getcustom15_3:
137 movf customfunction_temp2,W 161 movf customfunction_temp1,W
138 mullw d'4' 162 mullw d'4'
139 movf PRODL,W ; x4 for adress 163 movf PRODL,W ; x4 for adress
140 addlw d'130' 164 addlw d'130'
141 movwf EEADR ; +130 for LOW Byte of value 165 movwf EEADR ; +130 for LOW Byte of value
142 call read_eeprom ; Lowbyte 166 call read_eeprom ; Lowbyte
146 movff EEDATA,hi 170 movff EEDATA,hi
147 clrf EEADRH 171 clrf EEADRH
148 return ; return 172 return ; return
149 173
150 menu_custom_functions_page2: 174 menu_custom_functions_page2:
151 movlw d'154' ; start of custom function descriptors 175 movlw .1
152 movwf customfunction_temp1 176 movff WREG,cf_page_number ; CF page number (0: 0-31, 1: 32-63)
153 bsf customfunction_page ; Use Page II... 177 movlw .186
178 movff WREG,cf_title_text ; # of text for title
179 movlw .154
180 movff WREG,cf_descriptor_text ; # of descriptor text offset
154 bra menu_custom_functions0 181 bra menu_custom_functions0
155 182
156 menu_custom_functions: 183 menu_custom_functions:
157 movlw d'36' ; start of custom function descriptors 184 movlw .36
158 movwf customfunction_temp1 185 movff WREG,cf_descriptor_text ; # of descriptor text offset
159 bcf customfunction_page ; Use Page I... 186 movlw .27
187 movff WREG,cf_title_text ; # of text for title
188 movlw .0
189 movff WREG,cf_page_number ; CF page number (0: 0-31, 1: 32-63)
190
160 191
161 menu_custom_functions0: 192 menu_custom_functions0:
162 bsf leftbind 193 bsf leftbind
163 call PLED_ClearScreen 194 call PLED_ClearScreen
164 movlw d'1' 195 movlw d'1'
173 movlw 1 ; Stepsize: 1, 10, or 100. 204 movlw 1 ; Stepsize: 1, 10, or 100.
174 movwf cf_step 205 movwf cf_step
175 206
176 call PLED_topline_box 207 call PLED_topline_box
177 WIN_INVERT .1 ; Init new Wordprocessor 208 WIN_INVERT .1 ; Init new Wordprocessor
178 209 movff cf_title_text,WREG ; Title text in low bank
179 btfss customfunction_page ; 210 call displaytext_1_low
180 bra menu_custom_functions10
181 DISPLAYTEXT .186 ; Custom FunctionsII
182 bra menu_custom_functions11
183
184 menu_custom_functions10:
185 DISPLAYTEXT .27 ; Custom FunctionsI
186
187 menu_custom_functions11:
188 WIN_INVERT .0 ; Init new Wordprocessor 211 WIN_INVERT .0 ; Init new Wordprocessor
189 212
190 menu_custom_functions1: 213 menu_custom_functions1:
191 call PLED_standard_color ; Trash EEADRH... 214 call PLED_standard_color ; Trash EEADRH...
192 215
193 movlw d'1' ; So restore it ! 216 movff cf_page_number,EEADRH ; CF page number (0: 0-31, 1: 32-63)
194 btfss customfunction_page ; Use Page II ?
195 movlw d'0' ; NO: this is page 1.
196 movwf EEADRH
197 217
198 clrf timeout_counter2 218 clrf timeout_counter2
199 bcf menubit2 219 bcf menubit2
200 bcf menubit3 220 bcf menubit3
201 WIN_LEFT .20 221 WIN_LEFT .20
202 WIN_TOP .35 222 WIN_TOP .35
203 lfsr FSR2,letter 223 lfsr FSR2,letter
204 movff decodata+0,lo ; decodata == CF number % 32 224 movff decodata+0,lo ; decodata == CF number % 32
205 225
206 movlw d'0' 226 movff cf_page_number,WREG ; CF page number (0: 0-31, 1: 32-63)
207 btfsc customfunction_page ; Add offset for display in CF menu II 227 mullw .32 ; CF page number * 32 -> PRODL:PRODH
208 movlw d'32' 228 movf PRODL,W
209 addwf lo,F 229 addwf lo,F ; Add offset for display in CF menu
210 230
211 output_99x 231 output_99x
212 STRCAT_PRINT ": " 232 STRCAT_PRINT ": "
213 233 movff cf_descriptor_text,WREG ; start of custom function descriptors
214 movf customfunction_temp1,W ; start of custom function descriptors
215 addwf decodata+0,W ; add # of current custom function, place result in wreg 234 addwf decodata+0,W ; add # of current custom function, place result in wreg
216 call displaytext_1_low ; shows descriptor 235 call displaytext_1_low ; shows descriptor
217 236
218 ; Read default, type and min/max from reset table. 237 ; Read default, type and min/max from reset table.
219 rcall cf_read_default 238 rcall cf_read_default
343 bra customfunctions_loop 362 bra customfunctions_loop
344 363
345 ;----------------------------------------------------------------------------- 364 ;-----------------------------------------------------------------------------
346 ; Read default value, type, and constraints 365 ; Read default value, type, and constraints
347 ; 366 ;
348 ; Input: customfunction_page, cf32_x4 367 ; Input: cf32_x4
349 ; Output: cf_default, cf_type, cf_min, cf_max. 368 ; Output: cf_default, cf_type, cf_min, cf_max.
350 ; Trashes: TBLPTR 369 ; Trashes: TBLPTR
351 370
352 cf_read_default: 371 cf_read_default:
353 movlw LOW(cf_default_table0) ; Get 24bit PROM pointer. SKIP 372 movlw LOW(cf_default_table0) ; Get 24bit PROM pointer. SKIP
355 movlw HIGH(cf_default_table0) 374 movlw HIGH(cf_default_table0)
356 movwf TBLPTRH 375 movwf TBLPTRH
357 movlw UPPER(cf_default_table0) 376 movlw UPPER(cf_default_table0)
358 movwf TBLPTRU 377 movwf TBLPTRU
359 378
360 movlw 0 379 movff cf_page_number,WREG ; CF page number (0: 0-31, 1: 32-63)
361 btfsc customfunction_page ; Page II CF# ? 380 mullw 0x80 ; CF page number * 0x80 -> PRODL:PRODH
362 movlw 0x80 ; YES: add 128 to ptr. 381
382 movf PRODL,W
363 addwf cf32_x4,W ; Add 4 x (CF index modulus 32) 383 addwf cf32_x4,W ; Add 4 x (CF index modulus 32)
364 addwf TBLPTRL,F ; And to a 8+16 add into TBLPTR 384 addwf TBLPTRL,F ; And to a 8+16 add into TBLPTR
365 movlw 0 ; (keep carry) 385 movf PRODH,W
366 addwfc TBLPTRH,F ; Propagate to 16bit (but not 24bits). 386 addwfc TBLPTRH,F ; Propagate to 16bit (but not 24bits).
367 387
368 tblrd*+ 388 tblrd*+
369 movff TABLAT,cf_default+0 ; Low byte 389 movff TABLAT,cf_default+0 ; Low byte
370 tblrd*+ 390 tblrd*+
647 bra cf_fill_line 667 bra cf_fill_line
648 668
649 ;----------------------------------------------------------------------------- 669 ;-----------------------------------------------------------------------------
650 670
651 do_customfunction: 671 do_customfunction:
652 CLRF EEADRH 672 movff cf_page_number,EEADRH ; CF page number (0: 0-31, 1: 32-63)
653 movlw d'1'
654 btfsc customfunction_page
655 movwf EEADRH ; Reset EEADRH correct (Was adjusted in check_timeout...)
656 673
657 dcfsnz menupos,F 674 dcfsnz menupos,F
658 bra next_customfunction 675 bra next_customfunction
659 dcfsnz menupos,F 676 dcfsnz menupos,F
660 bra toggle_plusminus 677 bra toggle_plusminus
666 bra adjust_cfn_value 683 bra adjust_cfn_value
667 684
668 ;----------------------------------------------------------------------------- 685 ;-----------------------------------------------------------------------------
669 686
670 exit_customfunctions: 687 exit_customfunctions:
671 movlw d'2' ; Return to correct list entry 688 movff cf_page_number,menupos ; CF page number (0: 0-31, 1: 32-63)
672 btfss customfunction_page 689 incf menupos,F
673 movlw d'1'
674 movwf menupos ;
675 clrf EEADRH ; Clear EEADRH ! 690 clrf EEADRH ; Clear EEADRH !
676 goto setup_menu2 ; exit... 691 goto setup_menu2 ; exit...
677 692
678 ;----------------------------------------------------------------------------- 693 ;-----------------------------------------------------------------------------
679 694
820 ; 835 ;
821 ; Note: the trick here is to do two sweep over the 64 CF values, to make sure 836 ; Note: the trick here is to do two sweep over the 64 CF values, to make sure
822 ; they are all ok. 837 ; they are all ok.
823 838
824 check_customfunctions: 839 check_customfunctions:
825 ; Did we finished the two sweeps ? 840 movlw max_custom_number+1 ; Defined in definitions.asm
826 btfsc cf_checker_counter,7 ; Already at position 128 ? 841 cpfseq cf_checker_counter ; All tested?
827 return ; YES: just do nothing. 842 bra check_customfunctions1 ; No, continue
828 843 clrf cf_checker_counter ; clear counter
829 ; Setup cf32_x4 and cf page bit: 844 return ; YES: just do nothing.
845
846 check_customfunctions1:
847 ; Setup cf_page_number
848 movlw .0
849 movff WREG,cf_page_number
850 movlw d'31'
851 cpfsgt cf_checker_counter
852 bra check_customfunctions2 ; CF I
853
854 movlw .1
855 movff WREG,cf_page_number
856 movlw d'63'
857 cpfsgt cf_checker_counter
858 bra check_customfunctions2 ; CF II
859
860 movlw .2
861 movff WREG,cf_page_number ; CF III
862
863 check_customfunctions2:
864 ; Setup cf32_x4
830 movf cf_checker_counter,W 865 movf cf_checker_counter,W
831 rlcf WREG ; x4 866 rlcf WREG ; x4
832 rlcf WREG 867 rlcf WREG
833 bcf customfunction_page
834 btfsc WREG,7
835 bsf customfunction_page ; Setup CF page bit.
836 andlw 4*.31 868 andlw 4*.31
837 movwf cf32_x4 869 movwf cf32_x4
838 870
839 ; Do the check 871 ; Do the check
840 rcall check_one_cf 872 rcall check_one_cf
841 iorwf WREG ; Test return value. 873 iorwf WREG ; Test return value.
842 bz check_failed ; 0 == FAILED. 874 bz check_failed ; 0 == FAILED.
843 875
844 ; Passed: Simple loop until 128 is reached: 876 ; Passed: Simple loop until 128 is reached:
845 incf cf_checker_counter ; Next CF to check. 877 incf cf_checker_counter,F ; Next CF to check.
846 bra check_customfunctions ; And loop until 128 reached (ie twice) 878 bra check_customfunctions ; And loop until 128 reached (ie twice)
847 879
848 check_failed: 880 check_failed:
849 movlw .63 ; Make sure number is back to range 0..63 881 movlw .63 ; Make sure number is back to range 0..63
850 andwf cf_checker_counter,F 882 andwf cf_checker_counter,F