comparison src/options.asm @ 631:185ba2f91f59

3.09 beta 1 release
author heinrichsweikamp
date Fri, 28 Feb 2020 15:45:07 +0100
parents cd58f7fc86db
children 4050675965ea
comparison
equal deleted inserted replaced
630:4cd81bdbf15c 631:185ba2f91f59
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File options.asm next combined generation V3.04.3 3 ; File options.asm next combined generation V3.08.8
4 ; 4 ;
5 ; Manage all options data. 5 ; Manage all options data.
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
20 #include "shared_definitions.h" 20 #include "shared_definitions.h"
21 #include "gaslist.inc" 21 #include "gaslist.inc"
22 22
23 extern write_eeprom 23 extern write_eeprom
24 extern read_eeprom 24 extern read_eeprom
25 extern eeprom_serial_save,eeprom_opt_backup
26 extern option_table_begin,option_table_end 25 extern option_table_begin,option_table_end
27 extern convert_meter_to_feet 26 extern convert_meter_to_feet
28 27
29 options CODE 28 options CODE
30 29
31 ;============================================================================= 30 ;=============================================================================
32 ; Reset all options to factory defaults 31 ; Reset all options to factory defaults (in memory only)
33 ; 32 ;
34 ; INPUT: none 33 ; INPUT: none
35 ; OUTPUT: none 34 ; OUTPUT: none
36 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 35 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
37 ; 36 ;
38 global option_reset_all ; reset all options to factory default 37 global option_reset_all ; reset all options to factory default
39 option_reset_all: 38 option_reset_all:
40 clrf EEADRH 39 call eeprom_total_dives_read ; read total number of dives
41 read_int_eeprom .2 40 tstfsz mpr+0 ; number of total dives, low byte = 0 ?
42 tstfsz EEDATA ; number of total dives = 0 ? 41 bra option_reset_all_1 ; NO - skip resetting logbook
43 bra option_reset_all2 ; NO - skip resetting logbook 42 tstfsz mpr+1 ; number of total dives, high byte = 0 ?
44 read_int_eeprom .3 43 bra option_reset_all_1 ; NO - skip resetting logbook
45 tstfsz EEDATA ; number of total dives = 0 ? 44
46 bra option_reset_all2 ; NO - skip resetting logbook 45 ; reset logbook
47 46 call erase_complete_logbook ; erase complete logbook
48 clrf EEDATA 47
49 write_int_eeprom .4 48 ; reset logbook offset
50 write_int_eeprom .5 49 CLRI mpr ; set logbook offset to zero
51 write_int_eeprom .6 50 call eeprom_log_offset_write ; store logbook offset
52 write_int_eeprom .2 ; delete total dive counter, too 51
53 write_int_eeprom .3
54 call ext_flash_erase_logbook ; complete logbook
55
56 option_reset_all2:
57 clrf lo
58 clrf hi
59 call do_logoffset_common_write ; reset logbook offset
60 movlw LOW(option_table_begin) ; point to option table begin
61 movwf FSR0L
62 movlw HIGH(option_table_begin)
63 movwf FSR0H
64 option_reset_all_1: 52 option_reset_all_1:
65 movlw LOW(option_table_end) ; get low byte of end of table address 53 lfsr FSR0,option_table_begin ; point to start of option definition table
66 cpfseq FSR0L ; does it equal the current pointer position? 54 option_reset_all_loop:
67 bra option_reset_all_2 ; NO - more options to process 55 rcall option_reset ; reset option
68 movlw HIGH(option_table_end) ; get high byte of end of table address 56 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ?
69 cpfseq FSR0H ; does it equal the current pointer position? 57 bra option_reset_all_loop ; NO - do next option
70 bra option_reset_all_2 ; NO - more options to process 58 return ; YES - done
71 return ; YES to both - end of option table reached, done 59
72 option_reset_all_2:
73 rcall option_reset ; reset one option...
74 bra option_reset_all_1 ; ... and loop
75
76 ;=============================================================================
77 ; Check all option and reset option if out of min/max boundary
78 ;
79 ; INPUT: none
80 ; OUTPUT: none
81 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
82 ;
83 global option_check_all ; check all option and reset option if out of min/max boundary
84 option_check_all:
85 bcf option_repaired ; no option needed repair up to now
86 movlw LOW(option_table_begin) ; point to option table begin
87 movwf FSR0L
88 movlw HIGH(option_table_begin)
89 movwf FSR0H
90 option_check_all_1:
91 movlw LOW(option_table_end) ; get low byte of end of table address
92 cpfseq FSR0L ; does it equal the current pointer position?
93 bra option_check_all_2 ; NO - more options to process
94 movlw HIGH(option_table_end) ; get high byte of end of table address
95 cpfseq FSR0H ; does it equal the current pointer position?
96 bra option_check_all_2 ; NO - more options to process
97 bra option_check_all_3 ; YES to both - end of option table reached
98 option_check_all_2:
99 rcall option_check ; check one option...
100 bra option_check_all_1 ; ... and loop
101 option_check_all_3:
102 bsf is_diluent_menu ; setup checking diluents
103 call gaslist_cleanup_list ; check and correct multiple or none First diluent
104 bcf is_diluent_menu ; setup checking gases
105 call gaslist_cleanup_list ; check and correct multiple or none First gas
106 IFNDEF _gauge_mode
107 call option_cleanup_gauge ; check and correct Gauge mode
108 ENDIF
109 IFDEF _ccr_pscr
110 call option_cleanup_oCCRMode ; check and correct CCR / pSCR mode
111 ENDIF
112 call option_cleanup_GF ; check and correct GFlow <= GFhigh
113 return ; all done
114
115
116
117 ;=============================================================================
118 ; Read option handle
119 ; INPUT: FSR0 = option handle
120 ; OUTPUT: FSR1 = address of variable.
121 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
122 ;
123 option_read:
124 movff FSR0L,TBLPTRL ; set memory address of option data set, low byte
125 movlw HIGH(option_table_begin) ; get table begin address, high byte
126 andlw 0xF0 ; keep only the upper nibble
127 iorwf FSR0H,W ; add the memory address of the option data set, high byte
128 movwf TBLPTRH ; set the resulting memory address, high byte
129 movlw UPPER(option_table_begin) ; get table begin address, upper byte
130 movwf TBLPTRU ; set memory address of option data set, upper byte
131
132 ; Read type, default and register from table
133 tblrd*+
134 movff TABLAT,opt_type
135 tblrd*+
136 movff TABLAT,opt_default
137 tblrd*+
138 movff TABLAT,opt_inc
139 tblrd*+
140 movff TABLAT,opt_min
141 tblrd*+
142 movff TABLAT,opt_max
143 tblrd*+
144 movff TABLAT,opt_eeprom
145 tblrd*+
146 movff TABLAT,opt_unit+0
147 tblrd*+
148 movff TABLAT,opt_unit+1
149 tblrd*+
150 movff TABLAT,FSR1L
151 tblrd*+
152 movff TABLAT,FSR1H
153 movff TBLPTRL,FSR0L ; advance handle to next option data set (used for reset_all)
154 movff TBLPTRH,FSR0H
155 return
156
157 ;=============================================================================
158 ; Check one option and reset if it's out of it's min/max boundaries
159 ; INPUT: FSR0 = option handle
160 ; OUTPUT: none
161 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2, lo
162 ;
163 option_check:
164 ; Read type, default and register from table
165 rcall option_read
166
167 ; Switch on type
168 movf opt_type,W ; get option type
169 xorlw .2 ; type == STRING ?
170 bz option_check_string ; YES
171 movf opt_type,W ; get option type (again)
172 xorlw .1 ; type == ENUM8 ?
173 bz option_check_enum8 ; YES - check if lower then max. value only
174 ; NO to all - must be integer then
175 tstfsz opt_min ; opt_min = 0 ?
176 bra option_check_both ; NO - check it
177 bra option_check_enum8 ; check max only
178
179 option_check_both:
180 decf opt_min,W ; check against minimum value
181 cpfsgt INDF1 ; bigger than opt_min - 1 ?
182 bra option_check_reset ; NO - reset option
183 option_check_enum8: ; check against maximum value
184 infsnz opt_max,W ; max = 255?
185 return ; YES - ignore the max. test
186 cpfslt INDF1 ; NO - smaller then opt_max + 1 ?
187 bra option_check_reset ; NO - reset option
188 return ; YES - within range, return
189
190 option_check_reset:
191 movff opt_default,INDF1 ; reset option to default
192 bsf option_repaired ; flag that an option was repaired
193 return ; done
194
195 option_check_string:
196 return
197 60
198 ;============================================================================= 61 ;=============================================================================
199 ; Reset an option to its default value 62 ; Reset an option to its default value
200 ; INPUT: FSR0 = option handle 63 ; INPUT: FSR0 = option handle
201 ; OUTPUT: none 64 ; OUTPUT: none
202 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 65 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2
203 ; 66 ;
204 global option_reset ; reset FSR0 option to factory default 67 global option_reset ; reset option value to default
205 option_reset: 68 option_reset:
206 ; Read type, default and register from table 69 ; read type, default and register from table
207 rcall option_read ; read option data 70 rcall option_read_definition ; read option definition
71
72 option_reset_loaded: ; entry point with option definition already read
73 bsf option_repaired ; flag that an option was repaired
74 bsf options_changed ; flag that EEPROM needs to be updated
208 movf opt_type,W ; get option type 75 movf opt_type,W ; get option type
209 xorlw 2 ; Type == STRING ? 76 xorlw .2 ; type = STRING ?
210 bz opt_reset_string ; YES - special copy 77 bz opt_reset_string ; YES - string copy
211 movff opt_default,INDF1 ; NO - just a 8 bit indirect copy 78 movff opt_default,INDF1 ; NO - 1 byte copy
212 return 79 return ; - done
80
213 opt_reset_string: 81 opt_reset_string:
214 movff FSR1L,FSR2L ; set string destination address 82 movff FSR1L,FSR2L ; set string destination address
215 movff FSR1H,FSR2H ; ... 83 movff FSR1H,FSR2H ; ...
216 movff opt_default+0,FSR1L ; get handle to multi-lingual text in FSR1 84 movff opt_default+0,FSR1L ; get handle to multi-lingual text in FSR1
217 movff opt_default+1,FSR1H ; ... 85 movff opt_default+1,FSR1H ; ...
218 movff TBLPTRL,opt_backup_tbl+0 ; TBLPTR trashed by text routine... 86 movff TBLPTRL,mpr+0 ; TBLPTR will be trashed by text routine, so make a back-up
219 movff TBLPTRH,opt_backup_tbl+1 ; ... 87 movff TBLPTRH,mpr+1 ; ...
220 movff TBLPTRU,opt_backup_tbl+2 ; ... 88 movff TBLPTRU,mpr+2 ; ...
221 call strcat_text ; copy translated text to FSR2 89 call strcat_text ; copy translated text to FSR2
222 movff opt_backup_tbl+0,TBLPTRL ; restore TBLPTR 90 movff mpr+0,TBLPTRL ; restore TBLPTR
223 movff opt_backup_tbl+1,TBLPTRH ; ... 91 movff mpr+1,TBLPTRH ; ...
224 movff opt_backup_tbl+2,TBLPTRU ; ... 92 movff mpr+2,TBLPTRU ; ...
225 93 return ; done
226 return 94
227 95
228 ;============================================================================= 96 ;=============================================================================
229 ; Save all options to EEPROM 97 ; Read option definition
230 ; 98 ; INPUT: FSR0 = option handle
231 global option_save_all ; save options to EEPROM 99 ; OUTPUT: FSR1 = address of variable.
232 option_save_all: 100 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
233 bcf PIR3,RC2IE 101 ;
234 ;---- Save option serial into EEPROM to detect reset and new version 102 option_read_definition:
235 movlw LOW(eeprom_serial_save) 103 movff FSR0L,TBLPTRL ; low byte : set memory address of option data set
236 movwf EEADR 104 movlw HIGH(option_table_begin) ; high byte : get table start address
237 movlw HIGH(eeprom_serial_save) 105 andlw 0xF0 ; keep only the upper nibble
238 movwf EEADRH 106 iorwf FSR0H,W ; add the memory address of the option data set
239 movlw LOW(eeprom_opt_serial) 107 movwf TBLPTRH ; set the resulting memory address
240 movwf EEDATA 108 movlw UPPER(option_table_begin) ; upper byte: get table start address
241 call write_eeprom 109 movwf TBLPTRU ; set memory address of option data set
242 incf EEADR,F 110
243 movlw HIGH(eeprom_opt_serial) 111 lfsr FSR1,opt_type ; load FSR1 with base address of option definition vars
244 movwf EEDATA 112 movlw opt_definiton_bytes ; get number of bytes to copy
245 call write_eeprom 113 movwf eeprom_loop ; initialize loop counter (using an EEPROM variable here)
246 114 option_read_definition_loop:
247 ;---- Save all options 115 tblrd*+ ; read one byte from program memory and increment address
248 movlw LOW(option_table_begin) 116 movff TABLAT,POSTINC1 ; transfer byte from program memory to memory
249 movwf FSR0L 117 decfsz eeprom_loop,F ; all bytes done?
250 movlw HIGH(option_table_begin) 118 bra option_read_definition_loop ; NO - loop
251 movwf FSR0H 119 tblrd* ; YES - read one byte ahead without incrementing address
252 120 movff TABLAT,POSTINC1 ; - store byte
253 option_save_all_1: 121 movff opt_memory+0,FSR1L ; - load FSR1 with the address of the option value variable
254 movlw LOW(option_table_end) 122 movff opt_memory+1,FSR1H ; - ...
255 cpfseq FSR0L 123 movff TBLPTRL,FSR0L ; - advance handle to the next option definition data set
256 bra option_save_all_2 ; not yet done... 124 movff TBLPTRH,FSR0H ; - ...
257 movlw HIGH(option_table_end) 125 return ; - done
258 cpfseq FSR0H 126
259 bra option_save_all_2 ; not yet done... 127
260 bsf PIR3,RC2IE 128 ;=============================================================================
261 return ; all done 129 ; Check one option and reset its value if it is out of min/max boundary
262 option_save_all_2: 130 ; INPUT: opt_* vars and FSR1
263 rcall option_save ; save one option... 131 ; OUTPUT: option value set to default if out of min/max
264 bra option_save_all_1 ; ...and loop 132 ; TRASH: WREG
265 133 ;
266 134 option_check_loaded:
267 global option_save 135 ; switch on type
268 option_save: 136 movf opt_type,W ; get type
269 rcall option_read 137 bz option_check_uint8 ; type 0: INT8
270 incf opt_eeprom,W ; should we save it ? 138 dcfsnz WREG ; decrement
271 btfsc STATUS,Z ; EEPROM address is FFh ? 139 bra option_check_enum8 ; type 1: ENUM
272 return ; YES - nothing to do 140 dcfsnz WREG ; decrement
273 movf opt_eeprom,W ; compute backup address in EEPROM 141 bra option_check_string ; type 2: STRING
274 addlw LOW(eeprom_opt_backup) ; add offset 142 ;bra option_check_uint8 ; type 3: INT8
275 movwf EEADR 143
276 movlw HIGH(eeprom_opt_backup) 144 option_check_uint8:
277 btfsc STATUS,C ; > 256 ? 145 tstfsz opt_min ; opt_min = 0 ?
278 addlw .1 ; YES - +1 146 bra option_check_min ; NO - check it
279 movwf EEADRH 147 bra option_check_enum8 ; YES - continue with check for maximum
148
149 option_check_min:
150 decf opt_min,W ; get (minimum permissible value - 1) into WREG
151 cpfsgt INDF1 ; option value > (minimum permissible value - 1) ?
152 bra option_reset_loaded ; NO - reset option value
153 ;bra option_check_enum8 ; YES - continue with check for maximum
154
155 option_check_enum8:
156 infsnz opt_max,W ; get (highest permissible value + 1) into WREG
157 return ; highest permissible value was 255, skip check, done
158 cpfslt INDF1 ; option value < (highest permissible value + 1) ?
159 bra option_reset_loaded ; NO - reset option value
160 return ; YES - within range, done
161
162 option_check_string:
163 return ; nothing to check with strings
164
165
166 ;=============================================================================
167 ; Check and store all option values in EEPROM
168 ;
169 global option_check_and_store_all
170 option_check_and_store_all:
171 bcf PIR3,RC2IE ; disable EUSART interrupts
172
173 ;---- save option version
174 MOVLI eeprom_opt_version,mpr ; get options version number
175 EEPROM_II_WRITE mpr,eeprom_options_version ; store options version number in EEPROM
176
177 ;---- check and resolve some interdependencies among options
178 bsf is_diluent_menu ; setup checking diluents
179 call gaslist_cleanup_list ; check and correct multiple or none First diluents
180
181 bcf is_diluent_menu ; setup checking gases
182 call gaslist_cleanup_list ; check and correct multiple or none First gases
183
184 IFNDEF _gauge_mode
185 call option_cleanup_gauge ; check and correct gauge mode
186 ENDIF
187
188 IFDEF _ccr_pscr
189 call option_cleanup_oCCRMode ; check and correct CCR / pSCR mode
190 ENDIF
191
192 call option_cleanup_GF ; check and correct GFlow <= GFhigh
193
194 ;---- check and save all option values
195 lfsr FSR0,option_table_begin ; point to start of option definition table
196 option_save_all_loop:
197 rcall option_check_and_store ; check and save option value
198 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ?
199 bra option_save_all_loop ; NO - do next option
200 return ; YES - done
201
202
203 ;=============================================================================
204 ; Check and store an option value in EEPROM
205 ;
206 global option_check_and_store
207 option_check_and_store:
208 rcall option_read_definition ; read the option definition
209 rcall option_check_loaded ; check if option value is within min/max, set to default if not
210
211 option_save_loaded_checked:
212 movf opt_eeprom_bank,W ; get bank
213 andlw b'11111110' ; keep only bits 7-1
214 tstfsz WREG ; bank < 0x02 ?
215 return ; NO - volatile option or illegal address, abort
216 tstfsz opt_eeprom_bank ; YES - bank = 0 ?
217 bra option_save_execute ; NO - address is valid
218 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1
219 cpfsgt opt_eeprom_index ; - index >= start address ?
220 return ; NO - illegal address, abort
221 ;bra option_save_execute ; YES - address is valid
222
223 option_save_execute:
224 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte)
225 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte)
226
280 movf opt_type,W ; get option type 227 movf opt_type,W ; get option type
281 xorlw 2 ; option type is string ? 228 xorlw .2 ; option type = string ?
282 bz option_save_string ; YES 229 bz option_save_string ; YES - special handling
283 movff INDF1,EEDATA ; NO - one byte to be saved to EEPROM 230 movff INDF1,EEDATA ; NO - copy option value to EEPROM write register
284 btfss EEADRH,1 ; - EEADR:EEADRH < 512 ? 231 call write_eeprom ; - execute write
285 call write_eeprom ; YES - write 232 return ; - done
286 return ; (NO) - done 233
287 option_save_string: 234 option_save_string:
288 movff POSTINC1,EEDATA ; write one byte 235 movff POSTINC1,EEDATA ; copy a character from the option value to the EEPROM write register
289 btfss EEADRH,1 ; EEADR:EEADRH < 512 ? 236 btfss EEADRH,1 ; current EEPROM address < 512 ?
290 call write_eeprom ; YES - write 237 call write_eeprom ; YES - execute write
291 infsnz EEADR,F ; (NO) - increment EEPROM address 238 infsnz EEADR,F ; increment EEPROM address, low byte
292 incf EEADRH,F ; - ... 239 incf EEADRH,F ; increment EEPROM address, high byte
293 decfsz opt_max ; - decrement string length, done? 240 decfsz opt_max ; decrement string length, done?
294 bra option_save_string ; NO - loop 241 bra option_save_string ; NO - loop
295 return ; YES 242 return ; YES - done
296 243
297 ;============================================================================= 244
298 245 ;=============================================================================
299 global option_restore_all ; restore options from EEPROM 246 ; Restore and check all option values from EEPROM
300 option_restore_all: 247 ;
301 ;---- Read option serial from EEPROM 248 global option_restore_and_check_all ; restore options from EEPROM
302 movlw LOW(eeprom_serial_save) 249 option_restore_and_check_all:
303 movwf EEADR 250 ;---- Read option version from EEPROM
304 movlw HIGH(eeprom_serial_save) 251 EEPROM_II_READ eeprom_options_version,mpr
305 movf EEADRH 252
306 call read_eeprom 253 movlw LOW(eeprom_opt_version) ; get options version from current firmware, low byte
307 movlw LOW(eeprom_opt_serial) 254 xorwf mpr+0,W ; compare with EEPROM version, do they match?
308 xorwf EEDATA,W 255 bnz option_restore_reset ; NO - reset to defaults of current firmware
309 bnz option_restore_bad ; auto reset if changed 256
310 incf EEADR,F 257 movlw HIGH(eeprom_opt_version) ; get options version from current firmware, high byte
311 call read_eeprom 258 xorwf mpr+1,W ; compare with EEPROM version, do they match?
312 movlw HIGH(eeprom_opt_serial) 259 bnz option_restore_reset ; NO - reset to defaults of current firmware
313 xorwf EEDATA,W 260
314 bz option_restore_ok ; auto reset if changed 261 ;---- restore all option values
315 262 lfsr FSR0,option_table_begin ; point to start of option definition table
316 option_restore_bad: 263 option_restore_all_loop:
317 call option_reset_all ; reset RAM contains 264 rcall option_restore_and_check ; restore and check the option
318 goto option_save_all ; then save to EEPROM 265 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ?
319 266 bra option_restore_all_loop ; NO - do next option
320 ;---- Proper restore 267 return ; YES - done
321 option_restore_ok: 268
322 movlw LOW(option_table_begin) 269 option_restore_reset:
323 movwf FSR0L 270 call option_reset_all ; reset all option values to their default
324 movlw HIGH(option_table_begin) 271 goto option_check_and_store_all ; write back all option values to EEPROM (and return)
325 movwf FSR0H 272
326 273
327 option_restore_all_1: 274 ;=============================================================================
328 movlw LOW(option_table_end) 275 ; Restore an option value from EEPROM and check it
329 cpfseq FSR0L 276 ;
330 bra option_restore_all_2 ; not yet done... 277 global option_restore_and_check
331 movlw HIGH(option_table_end) 278 option_restore_and_check:
332 cpfseq FSR0H 279 rcall option_read_definition ; read the option definition
333 bra option_restore_all_2 ; not yet done... 280
334 return ; all done 281 movf opt_eeprom_bank,W ; get bank
335 option_restore_all_2: 282 andlw b'11111110' ; keep only bits 7-1
336 rcall option_restore ; Restore one option 283 tstfsz WREG ; bank < 0x02 ?
337 bra option_restore_all_1 ; and loop 284 bra option_reset_loaded ; NO - volatile option or illegal address, restore to default
338 285 tstfsz opt_eeprom_bank ; YES - bank = 0 ?
339 option_restore: 286 bra option_restore_execute ; NO - address is valid
340 rcall option_read 287 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1
341 incf opt_eeprom,W ; shall we save it ? 288 cpfsgt opt_eeprom_index ; - index >= start address ?
342 btfsc STATUS,Z ; EEPROM address is FFh ? 289 bra option_reset_loaded ; NO - illegal address, restore to default
343 return ; YES - nothing to do. 290 ;bra option_restore_execute ; YES - address is valid
344 movf opt_eeprom,W ; compute backup address in EEPROM 291
345 addlw LOW(eeprom_opt_backup) ; add offset 292 option_restore_execute:
346 movwf EEADR 293 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte)
347 movlw HIGH(eeprom_opt_backup) 294 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte)
348 btfsc STATUS,C ; > 256 ? 295
349 addlw .1 ; YES - +1
350 movwf EEADRH
351 movf opt_type,W ; get option type 296 movf opt_type,W ; get option type
352 xorlw 2 ; Option type is string? 297 xorlw .2 ; option type = string ?
353 bz option_restore_string ; YES 298 bz option_restore_string ; YES - special handling
354 call read_eeprom ; read one byte from EEPROM 299 call read_eeprom ; NO - execute read
355 movff EEDATA, INDF1 ; restore option register 300 movff EEDATA,INDF1 ; - read option value from EEPROM read register
356 return 301 bcf option_repaired ; - clear option repaired flag
302 bra option_check_loaded ; - check if option value is within min/max, reset to default if not
303 btfsc option_repaired ; - was the option repaired?
304 bra option_save_loaded_checked ; YES - save repaired value to EEPROM
305 return ; NO - done
306
357 option_restore_string: 307 option_restore_string:
358 call read_eeprom ; read one byte, and... 308 call read_eeprom ; read one character from the EEPROM
359 movff EEDATA,POSTINC1 ; ... restore it 309 movff EEDATA,POSTINC1 ; copy it to the option value
360 infsnz EEADR,F 310 infsnz EEADR,F ; increment EEPROM address, low byte
361 incf EEADRH,F 311 incf EEADRH,F ; increment EEPROM address, high byte
362 decfsz opt_max ; decrement string length 312 decfsz opt_max ; decrement string length, done?
363 bra option_restore_string ; loop while not finished 313 bra option_restore_string ; NO - loop
364 return 314 return ; YES - done (nothing to check with strings)
365 315
366 ;============================================================================= 316
367 ; Increment an option, based on type, and boundary 317
318 ;=============================================================================
319 ; Read an option value via RS232
320 ; INPUT: lo = serial index
321 ; OUTPUT: hi = option value
322 ; WREG =0: option found and value valid, =1: option not found
323 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
324 ;
325 global option_read_serial
326 option_read_serial:
327 lfsr FSR0,option_table_begin ; point to start of option definition table
328 option_read_serial_loop:
329 rcall option_read_definition ; read option definition
330 movf opt_serial,W ; get serial index of the option into WREG
331 xorwf lo,W ; received index = index of this option ?
332 bz option_read_serial_execute ; YES - read value
333 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ?
334 bra option_read_serial_loop ; NO - try next option
335 retlw .1 ; YES - done, option not found
336
337 option_read_serial_execute:
338 movff INDF1,hi ; read option value into hi
339 retlw .0 ; done, option found
340
341
342 ;=============================================================================
343 ; Write an option value via RS232
344 ; INPUT: lo = serial index
345 ; hi = option value
346 ; OUTPUT: WREG =0: option found and value valid, =1: option not found, =2: value not valid
347 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, up
348 ;
349 global option_write_serial
350 option_write_serial:
351 lfsr FSR0,option_table_begin ; point to start of option definition table
352 option_write_serial_loop:
353 rcall option_read_definition ; read option definition
354 movf opt_serial,W ; get serial index of the option into WREG
355 xorwf lo,W ; received index = index of this option ?
356 bz option_write_serial_execute ; YES - check and update value
357 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ?
358 bra option_write_serial_loop ; NO - try next option
359 retlw .1 ; YES - done, option not found
360
361 option_write_serial_execute:
362 movff INDF1,up ; backup old value
363 movff hi,INDF1 ; write new value
364 bcf option_repaired ; clear option repaired flag
365 rcall option_check_loaded ; check the new value
366 btfsc option_repaired ; was the new value valid?
367 bra option_write_serial_execute_fail; NO - restore old value
368 bsf options_changed ; YES - flag that EEPROM needs to be updated
369 retlw .0 ; - done, success
370 option_write_serial_execute_fail:
371 movff up,INDF1 ; restore old value
372 retlw .2 ; done, value not valid
373
374
375 ;=============================================================================
376 ; Increment an option value based on type and min/max boundary
368 ; INPUT: FSR0 = option handle 377 ; INPUT: FSR0 = option handle
369 ; OUTPUT: none 378 ; OUTPUT: none
370 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 379 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
371 ; 380 ;
372 global option_inc ; increment FSR0 option 381 global option_inc ; increment FSR0 option
373 option_inc: 382 option_inc:
374 ; read type, default and register from table 383 ; read type, default and register from table
375 rcall option_read 384 rcall option_read_definition
385
386 bsf options_changed ; flag that EEPROM needs to be updated
376 387
377 ; switch on type 388 ; switch on type
378 movf opt_type,W 389 movf opt_type,W ; get option type
379 bz option_inc_uint8 390 bz option_inc_uint8 ; type 0: INT8
380 dcfsnz WREG 391 dcfsnz WREG ; decrement
381 bra option_inc_enum8 392 bra option_inc_enum8 ; type 1: ENUM
382 dcfsnz WREG 393 dcfsnz WREG ; decrement
383 bra option_inc_string 394 bra option_inc_string ; type 2: STRING
384 395 ;bra option_inc_uint8 ; type 3: INT8
385 option_inc_uint8: ; default type too... 396
386 movf INDF1,W 397 option_inc_uint8:
387 addwf opt_inc,W 398 movf INDF1,W ; get option value
388 cpfslt opt_max 399 addwf opt_inc,W ; add increment
389 bra option_inc_uint8_0 400 cpfslt opt_max ; max < option value ?
390 movf opt_min,W 401 bra option_inc_uint8_0 ; NO - new option value ok
402 movf opt_min,W ; YES - reset to min value
391 option_inc_uint8_0: 403 option_inc_uint8_0:
392 movwf INDF1 404 movwf INDF1 ; store new value
393 option_inc_uint8_1: 405 option_inc_uint8_1:
394 ; Now some rather crude hack into this routine to make CCR Calibration more convenient: 406 ; now some rather crude hack into this routine to make CCR calibration more convenient:
395 movlw .149 ; EEPROM address of option CalGasO2 407 movlw 0x37 ; serial ID of option CalGasO2
396 cpfseq opt_eeprom ; editing CalGasO2 right now? 408 cpfseq opt_serial ; editing CalGasO2 right now?
397 bra option_inc_uint8_2 ; NO - check next option 409 bra option_inc_uint8_2 ; NO - check next option
398 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR 410 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR
399 decfsz WREG,W ; - in CCR mode? 411 decfsz WREG,W ; - in CCR mode?
400 return ; NO - done 412 return ; NO - done
401 movlw .26 ; YES - 413 movlw .26 ; YES -
403 return ; NO - done 415 return ; NO - done
404 movlw .95 ; YES - advance it to 95 416 movlw .95 ; YES - advance it to 95
405 movwf INDF1 ; - store it 417 movwf INDF1 ; - store it
406 return 418 return
407 option_inc_uint8_2: 419 option_inc_uint8_2:
408 movlw .12 ; EEPROM address of option opt_GF_low 420 movlw 0x25 ; serial ID of option opt_GF_low
409 cpfseq opt_eeprom ; editing opt_GF_low right now? 421 cpfseq opt_serial ; editing opt_GF_low right now?
410 bra option_inc_uint8_3 ; NO - check next option 422 bra option_inc_uint8_3 ; NO - check next option
411 movff opt_GF_high,WREG ; get value of associated GF high into WREG 423 movff opt_GF_high,WREG ; get value of associated GF high into WREG
412 cpfsgt INDF1 ; GF low > GF high? 424 cpfsgt INDF1 ; GF low > GF high?
413 return ; NO - setting ok, done 425 return ; NO - setting ok, done
414 movff opt_min,INDF1 ; YES - wrap around to minimum value 426 movff opt_min,INDF1 ; YES - wrap around to minimum value
415 return ; - done 427 return ; - done
416 option_inc_uint8_3: 428 option_inc_uint8_3:
417 movlw .13 ; EEPROM address of option opt_GF_high 429 movlw 0x26 ; serial ID of option opt_GF_high
418 cpfseq opt_eeprom ; editing opt_GF_high right now? 430 cpfseq opt_serial ; editing opt_GF_high right now?
419 bra option_inc_uint8_4 ; NO - check next option 431 bra option_inc_uint8_4 ; NO - check next option
420 movff opt_GF_low,WREG ; get value of associated GF low into WREG 432 movff opt_GF_low,WREG ; get value of associated GF low into WREG
421 cpfslt INDF1 ; GF high < GF low? 433 cpfslt INDF1 ; GF high < GF low?
422 return ; NO - setting ok, done 434 return ; NO - setting ok, done
423 movwf INDF1 ; YES - rise GF high to GF low 435 movwf INDF1 ; YES - rise GF high to GF low
424 return ; - done 436 return ; - done
425 option_inc_uint8_4: 437 option_inc_uint8_4:
426 movlw .17 ; EEPROM address of option opt_aGF_low 438 movlw 0x27 ; serial ID of option opt_aGF_low
427 cpfseq opt_eeprom ; editing opt_aGF_low right now? 439 cpfseq opt_serial ; editing opt_aGF_low right now?
428 bra option_inc_uint8_5 ; NO - check next option 440 bra option_inc_uint8_5 ; NO - check next option
429 movff opt_aGF_high,WREG ; get value of associated GF high into WREG 441 movff opt_aGF_high,WREG ; get value of associated GF high into WREG
430 cpfsgt INDF1 ; GF low > GF high? 442 cpfsgt INDF1 ; GF low > GF high?
431 return ; NO - setting ok, done 443 return ; NO - setting ok, done
432 movff opt_min,INDF1 ; YES - wrap around to minimum value 444 movff opt_min,INDF1 ; YES - wrap around to minimum value
433 return ; - done 445 return ; - done
434 option_inc_uint8_5: 446 option_inc_uint8_5:
435 movlw .18 ; EEPROM address of option opt_aGF_high 447 movlw 0x28 ; serial ID of option opt_aGF_high
436 cpfseq opt_eeprom ; editing opt_aGF_high right now? 448 cpfseq opt_serial ; editing opt_aGF_high right now?
437 bra option_inc_uint8_6 ; NO - check next option 449 bra option_inc_uint8_6 ; NO - check next option
438 movff opt_aGF_low,WREG ; get value of associated GF low into WREG 450 movff opt_aGF_low,WREG ; get value of associated GF low into WREG
439 cpfslt INDF1 ; GF high < GF low? 451 cpfslt INDF1 ; GF high < GF low?
440 return ; NO - setting ok, done 452 return ; NO - setting ok, done
441 movwf INDF1 ; YES - rise GF high to GF low 453 movwf INDF1 ; YES - rise GF high to GF low
442 return ; - done 454 return ; - done
443 option_inc_uint8_6: 455 option_inc_uint8_6:
444 return ; all done 456 return ; all done
445 457
446 458
447 option_inc_enum8: ; always +1 459 option_inc_enum8:
448 incf INDF1,W 460 movf opt_max,W ; copy maximum permissible value to WREG
449 cpfsgt opt_max 461 cpfslt INDF1 ; option value < maximum permissible value ?
450 clrf WREG 462 bra option_inc_enum8_reset ; NO - reset option value
451 movwf INDF1 463 incf INDF1,F ; YES - increment option value
464 bra option_inc_enum8_1 ; - continue
465 option_inc_enum8_reset:
466 clrf INDF1 ; reset option value to zero
467
452 option_inc_enum8_1: 468 option_inc_enum8_1:
453 IFDEF _ccr_pscr 469 IFDEF _ccr_pscr
454 ; Now some rather crude hack into this routine to unify CCR & pSCR mode setting 470 ; now some rather crude hack into this routine to unify CCR & pSCR mode setting
455 movlw .25 ; EEPROM address of option oCCRMode 471 movlw 0x1F ; serial ID of option oCCRMode
456 cpfseq opt_eeprom ; editing oCCRMode right now? 472 cpfseq opt_serial ; editing oCCRMode right now?
457 bra option_inc_enum8_2 ; NO - check next option 473 bra option_inc_enum8_2 ; NO - check next option
458 IFDEF _external_sensor 474 IFDEF _external_sensor
459 btfsc analog_o2_input ; YES - does hosting OSTC have an analog interface? 475 btfsc analog_o2_input ; YES - does hosting OSTC have an analog interface?
460 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed 476 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed
461 btfsc optical_input ; does hosting OSTC have an optical interface? 477 btfsc optical_input ; does hosting OSTC have an optical interface?
471 bnz option_inc_enum8_1_exit ; NO - done 487 bnz option_inc_enum8_1_exit ; NO - done
472 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP) 488 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP)
473 option_inc_enum8_1_exit: 489 option_inc_enum8_1_exit:
474 return ; done 490 return ; done
475 ENDIF ; _ccr_pscr 491 ENDIF ; _ccr_pscr
492
476 option_inc_enum8_2: 493 option_inc_enum8_2:
477 ; (unused) 494 IFDEF _gas_contingency
495 ; now some rather crude hack to switch off contingency mode if gas needs calculation is switched off
496 movlw 0x5A ; serial ID of option opt_calc_gasvolume
497 cpfseq opt_serial ; editing opt_calc_gasvolume right now?
498 bra option_inc_enum8_3 ; NO - check next option
499 movf INDF1,W ; YES - get option value
500 ; xorlw .0 ; - option value = off ?
501 bnz option_inc_enum8_2_exit ; NO - done
502 clrf WREG ; YES - force contingency to be off, too
503 movff WREG,opt_gas_contingency_dive ; - ...
504 option_inc_enum8_2_exit:
505 return
506 ENDIF ; _gas_contingency
507
478 option_inc_enum8_3: 508 option_inc_enum8_3:
479 ; Now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode 509 ; now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode
480 movlw .8 ; EEPROM address of option opt_dive_mode 510 movlw 0x20 ; serial ID of option opt_dive_mode
481 cpfseq opt_eeprom ; editing opt_dive_mode right now? 511 cpfseq opt_serial ; editing opt_dive_mode right now?
482 bra option_inc_enum8_4 ; NO - check next option 512 bra option_inc_enum8_4 ; NO - check next option
483 movf INDF1,W ; YES - get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR 513 movf INDF1,W ; YES - get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR
484 xorlw .1 ; in CCR mode? 514 xorlw .1 ; in CCR mode?
485 bnz option_inc_enum8_3a ; NO - in some other mode 515 bnz option_inc_enum8_3a ; NO - in some other mode
486 IFNDEF _ccr_pscr 516 IFNDEF _ccr_pscr
523 option_inc_enum8_3_exit: 553 option_inc_enum8_3_exit:
524 return ; done 554 return ; done
525 555
526 option_inc_enum8_4: 556 option_inc_enum8_4:
527 IFDEF _rx_functions 557 IFDEF _rx_functions
528 ; Now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode 558 ; now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode
529 movlw .222 ; EEPROM address of option opt_TR_mode 559 movlw 0x7E ; serial ID of option opt_TR_mode
530 cpfseq opt_eeprom ; editing opt_TR_mode right now? 560 cpfseq opt_serial ; editing opt_TR_mode right now?
531 bra option_inc_enum8_5 ; NO - check next option 561 bra option_inc_enum8_5 ; NO - check next option
532 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR 562 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR
533 decfsz WREG,W ; dive mode = 1 CCR? 563 decfsz WREG,W ; dive mode = 1 CCR?
534 bra option_inc_enum8_4a ; NO - in any other mode 564 bra option_inc_enum8_4a ; NO - in any other mode
535 movf INDF1,W ; YES - get option value (TR mode) 565 movf INDF1,W ; YES - get option value (TR mode)
543 bnz option_inc_enum8_4_exit ; NO - done 573 bnz option_inc_enum8_4_exit ; NO - done
544 clrf INDF1 ; YES - advance option value to 0 "off" 574 clrf INDF1 ; YES - advance option value to 0 "off"
545 option_inc_enum8_4_exit: 575 option_inc_enum8_4_exit:
546 return ; done 576 return ; done
547 ENDIF ; _rx_functions 577 ENDIF ; _rx_functions
578
548 option_inc_enum8_5: 579 option_inc_enum8_5:
580 IFDEF _gas_contingency
581 ; now some rather crude hack to keep contingency mode switched off if gas needs calculation is switched off
582 movlw 0x91 ; serial ID of option opt_gas_contingency_dive
583 cpfseq opt_serial ; editing opt_gas_contingency_dive right now?
584 bra option_inc_enum8_6 ; NO - check next option
585 movff opt_calc_gasvolume,WREG ; YES - get current setting of gas needs calculation
586 tstfsz WREG ; - gas needs calculation switched off?
587 return ; NO - done, opt_gas_contingency_dive may be switched on
588 clrf INDF1 ; YES - force opt_gas_contingency_dive to off
589 return ; - done
590 ENDIF ; _gas_contingency
591
592 option_inc_enum8_6:
549 return 593 return
550 594
551 595
552 option_inc_string: ; no editing available 596 option_inc_string: ; no editing available
553 return 597 return
556 IFNDEF _gauge_mode 600 IFNDEF _gauge_mode
557 option_cleanup_gauge: 601 option_cleanup_gauge:
558 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) 602 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR)
559 xorlw .2 ; in Gauge mode? 603 xorlw .2 ; in Gauge mode?
560 bnz option_cleanup_gauge_1 ; NO - done 604 bnz option_cleanup_gauge_1 ; NO - done
561 banksel opt_dive_mode ; YES - setting not allowed, select options bank 605 movff WREG,opt_dive_mode ; YES - setting not allowed, WREG is zero -> reset to OC mode
562 clrf opt_dive_mode ; - reset to OC mode 606 bsf options_changed ; - flag that EEPROM needs to be updated
563 banksel common ; - back to bank common
564 option_cleanup_gauge_1: 607 option_cleanup_gauge_1:
565 return ; done 608 return ; done
566 ENDIF 609 ENDIF
567 610
568 611
576 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC 619 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC
577 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode 620 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode
578 banksel opt_ccr_mode ; YES - select options bank 621 banksel opt_ccr_mode ; YES - select options bank
579 bcf opt_ccr_mode,1 ; - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP, keeps sensor) 622 bcf opt_ccr_mode,1 ; - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP, keeps sensor)
580 banksel common ; - back to bank common 623 banksel common ; - back to bank common
581 bsf option_repaired ; - flag that an option was repaired 624 bsf options_changed ; - flag that EEPROM needs to be updated
582 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode 625 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode
583 IFDEF _external_sensor 626 IFDEF _external_sensor
584 btfsc analog_o2_input ; analog interface available? 627 btfsc analog_o2_input ; analog interface available?
585 return ; YES - setting 'sensor' allowed 628 return ; YES - setting 'sensor' allowed
586 btfsc optical_input ; does hosting OSTC have an optical interface? 629 btfsc optical_input ; does hosting OSTC have an optical interface?
591 tstfsz WREG ; - CCR mode = sensor? 634 tstfsz WREG ; - CCR mode = sensor?
592 return ; NO - setting allowed 635 return ; NO - setting allowed
593 banksel opt_ccr_mode ; YES - setting not allowed, select options bank 636 banksel opt_ccr_mode ; YES - setting not allowed, select options bank
594 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) 637 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP)
595 banksel common ; - back to bank common 638 banksel common ; - back to bank common
596 bsf option_repaired ; - flag that an option was repaired 639 bsf options_changed ; - flag that EEPROM needs to be updated
597 return ; - done 640 return ; - done
598 ENDIF ; _ccr_pscr 641 ENDIF ; _ccr_pscr
599 642
600 643
601 option_cleanup_GF: 644 option_cleanup_GF:
609 cpfsgt mpr ; - mpr > 100 ? 652 cpfsgt mpr ; - mpr > 100 ?
610 bra option_cleanup_GF_1 ; NO - correct GF low to GF high 653 bra option_cleanup_GF_1 ; NO - correct GF low to GF high
611 movwf mpr ; YES - correct GF low to 100% 654 movwf mpr ; YES - correct GF low to 100%
612 option_cleanup_GF_1: 655 option_cleanup_GF_1:
613 movff mpr,opt_GF_low ; store corrected GF low 656 movff mpr,opt_GF_low ; store corrected GF low
614 bsf option_repaired ; flag that an option was repaired 657 bsf options_changed ; flag that EEPROM needs to be updated
615 option_cleanup_GF_2: 658 option_cleanup_GF_2:
616 ; cleanup alternative GF 659 ; cleanup alternative GF
617 movff opt_aGF_high,WREG ; copy alternative GF high to WREG 660 movff opt_aGF_high,WREG ; copy alternative GF high to WREG
618 movff opt_aGF_low,mpr ; copy alternative GF low to mpr 661 movff opt_aGF_low,mpr ; copy alternative GF low to mpr
619 cpfsgt mpr ; GF low > GF high ? 662 cpfsgt mpr ; GF low > GF high ?
623 cpfsgt mpr ; - mpr > 100 ? 666 cpfsgt mpr ; - mpr > 100 ?
624 bra option_cleanup_GF_3 ; NO - correct GF low to GF high 667 bra option_cleanup_GF_3 ; NO - correct GF low to GF high
625 movwf mpr ; YES - correct GF low to 100% 668 movwf mpr ; YES - correct GF low to 100%
626 option_cleanup_GF_3: 669 option_cleanup_GF_3:
627 movff mpr,opt_aGF_low ; store corrected GF low 670 movff mpr,opt_aGF_low ; store corrected GF low
628 bsf option_repaired ; flag that an option was repaired 671 bsf options_changed ; flag that EEPROM needs to be updated
629 option_cleanup_GF_4: 672 option_cleanup_GF_4:
630 return ; done 673 return ; done
631 674
632 675
633 ;============================================================================= 676 ;=============================================================================
634 ; Strcat option into FSR2 buffer 677 ; Strcat option into FSR2 buffer
635 ; 678 ;
636 global option_draw ; STRCAT FRS0 option 679 global option_draw ; STRCAT FRS0 option
637 option_draw: 680 option_draw:
638 ; Read type, default and register from table 681 ; read type, default and register from table
639 rcall option_read 682 rcall option_read_definition
640 683
641 ; Switch on type 684 ; switch on type
642 movf opt_type,W 685 movf opt_type,W ; get option type
643 bz option_draw_uint8 ; type0 = INT8 686 bz option_draw_uint8 ; type0 = INT8
644 dcfsnz WREG 687 dcfsnz WREG
645 bra option_draw_enum8 ; type1 = ENUM 688 bra option_draw_enum8 ; type1 = ENUM
646 dcfsnz WREG 689 dcfsnz WREG
647 bra option_draw_string ; type2 = string 690 bra option_draw_string ; type2 = string
648 dcfsnz WREG 691 dcfsnz WREG
649 bra option_draw_uint8_depth ; type3 = INT8 with automatic display in meters or feet 692 bra option_draw_uint8_depth ; type3 = INT8 with automatic display in meters or feet
650 return ; unknown, return 693 return ; unknown, do nothing
651 694
652 option_draw_string: 695 option_draw_string:
653 movff POSTINC1,POSTINC2 696 movff POSTINC1,POSTINC2
654 decfsz opt_max 697 decfsz opt_max
655 bra option_draw_string 698 bra option_draw_string
690 goto strcat_text 733 goto strcat_text
691 734
692 735
693 ;---- Draw an enumerated value (set of translated strings) 736 ;---- Draw an enumerated value (set of translated strings)
694 option_draw_enum8: 737 option_draw_enum8:
695 movff INDF1,lo ; memorize current value 738 movf INDF1,W ; copy option value to WREG
696 movf INDF1,W ; copy current value to WREG 739 movwf lo ; memorize option value, too
697 cpfsgt opt_max ; max value (= highest usable value + 1) > current value? 740 cpfslt opt_max ; option value > maximum permissible value ?
698 clrf WREG ; NO - to avoid printing rubbish, reset to first value 741 bra option_draw_enum8_0 ; NO - option value allowed
742 clrf WREG ; YES - to avoid printing rubbish, use first ENUM item instead
743 option_draw_enum8_0:
699 addwf WREG ; current value *= 2 744 addwf WREG ; current value *= 2
700 addwf opt_inc,W ; base text + 2 * current value 745 addwf opt_inc,W ; base text + 2 * current value
701 movwf FSR1L ; load FSR0 746 movwf FSR1L ; load FSR1
702 movlw .0 ; propagate carry... 747 movlw .0 ; propagate carry...
703 addwfc opt_min,W ; ... 748 addwfc opt_min,W ; ...
704 movwf FSR1H ; ...into FSR1 749 movwf FSR1H ; ...into FSR1
705 call strcat_text ; print text 750 call strcat_text ; print text
706 movf opt_default,W ; get default value 751 movf opt_default,W ; get default value
709 return ; YES - default, done 754 return ; YES - default, done
710 option_draw_enum8_1: 755 option_draw_enum8_1:
711 PUTC "*" ; print "*" 756 PUTC "*" ; print "*"
712 return ; done 757 return ; done
713 758
714
715 ;----------------------------------------------------------------------------- 759 ;-----------------------------------------------------------------------------
716 760
717 END 761 END