Mercurial > public > hwos_code
annotate src/options.asm @ 650:bc214815deb2
3.19/10.75 release
author | heinrichsweikamp |
---|---|
date | Sun, 28 Aug 2022 13:13:38 +0200 |
parents | 070528a88715 |
children | 75e90cd0c2c3 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File options.asm * next combined generation V3.09.4n |
0 | 4 ; |
5 ; Manage all options data. | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-07-12 : [jDG] Creation. | |
11 ; | |
12 | |
604 | 13 #include "hwos.inc" ; mandatory header |
582 | 14 #include "strings.inc" |
15 #include "convert.inc" | |
16 #include "ghostwriter.inc" | |
17 #include "eeprom_rs232.inc" | |
18 #include "external_flash.inc" | |
19 #include "wait.inc" | |
604 | 20 #include "shared_definitions.h" |
608 | 21 #include "gaslist.inc" |
0 | 22 |
582 | 23 extern write_eeprom |
24 extern read_eeprom | |
25 extern option_table_begin,option_table_end | |
623 | 26 extern convert_meter_to_feet |
0 | 27 |
582 | 28 |
0 | 29 ;============================================================================= |
634 | 30 options1 CODE |
31 ;============================================================================= | |
32 | |
33 | |
34 ;----------------------------------------------------------------------------- | |
35 ; Adjust Address in FSR0 to an Option within an Option Group | |
36 ; | |
37 ; INPUT: FSR0 = base address of the option group | |
38 ; gaslist_gas = offset of the selected option within the group | |
39 ; OUTPUT: FSR0 = pointing to selected option | |
40 ; | |
41 global option_adjust_group_member | |
42 option_adjust_group_member: | |
43 movf gaslist_gas,W ; get offset in number of options | |
44 mullw opt_definition_bytes ; calculate offset in number of bytes | |
45 movf PRODL,W ; get number of bytes, low byte | |
46 addwf FSR0L,F ; add to FSR0, low byte | |
47 movf PRODH,W ; get number of bytes, high byte | |
48 addwfc FSR0H,F ; add to FSR0, high byte | |
49 return ; done | |
50 | |
51 | |
52 ;----------------------------------------------------------------------------- | |
53 ; Read the Option Definition | |
54 ; | |
55 ; INPUT: FSR0 = option handle | |
56 ; OUTPUT: FSR1 = address of variable. | |
57 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
58 ; | |
59 option_read_definition: | |
60 ; option_table_begin is at 0x0|80|00 | |
61 clrf TBLPTRU ; TBLPRT upper = 0x00 | |
62 movlw HIGH(option_table_begin) ; TBLPRT high = 0x80 | |
63 iorwf FSR0H,W ; + 0x0H from FSR0H | |
64 movwf TBLPTRH ; set 0x8H | |
65 movff FSR0L,TBLPTRL ; TBLPRT low = 0xLL from FSR0L | |
66 ; copy option definition from program to data memory | |
67 lfsr FSR1,opt_type ; load FSR1 with base address of option definition buffer | |
68 movlw opt_definition_bytes ; get number of bytes to copy | |
69 movwf eeprom_loop ; initialize loop counter (using an EEPROM variable here) | |
70 option_read_definition_loop: | |
71 tblrd*+ ; read one byte from program memory and increment address | |
72 movff TABLAT,POSTINC1 ; transfer byte from program memory to memory | |
73 decfsz eeprom_loop,F ; all bytes done? | |
74 bra option_read_definition_loop ; NO - loop | |
75 tblrd* ; YES - read one byte ahead without incrementing address | |
76 movff TABLAT,POSTINC1 ; - store byte | |
77 movff opt_memory+0,FSR1L ; - load FSR1 with the address of the option value variable | |
78 movff opt_memory+1,FSR1H ; - ... | |
79 movff TBLPTRL,FSR0L ; - advance handle to the next option definition data set | |
80 movff TBLPTRH,FSR0H ; - ... | |
81 return ; - done | |
82 | |
83 | |
84 ;----------------------------------------------------------------------------- | |
85 ; Reset all Options to Factory Defaults | |
0 | 86 ; |
87 ; INPUT: none | |
88 ; OUTPUT: none | |
89 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 | |
604 | 90 ; |
91 global option_reset_all ; reset all options to factory default | |
0 | 92 option_reset_all: |
631 | 93 call eeprom_total_dives_read ; read total number of dives |
94 tstfsz mpr+0 ; number of total dives, low byte = 0 ? | |
95 bra option_reset_all_1 ; NO - skip resetting logbook | |
96 tstfsz mpr+1 ; number of total dives, high byte = 0 ? | |
97 bra option_reset_all_1 ; NO - skip resetting logbook | |
0 | 98 |
631 | 99 ; reset logbook |
100 call erase_complete_logbook ; erase complete logbook | |
623 | 101 |
631 | 102 ; reset logbook offset |
103 CLRI mpr ; set logbook offset to zero | |
104 call eeprom_log_offset_write ; store logbook offset | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
105 |
631 | 106 option_reset_all_1: |
107 lfsr FSR0,option_table_begin ; point to start of option definition table | |
108 option_reset_all_loop: | |
109 rcall option_reset ; reset option | |
110 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
111 bra option_reset_all_loop ; NO - do next option | |
112 return ; YES - done | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
113 |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
114 |
634 | 115 ;----------------------------------------------------------------------------- |
116 ; Reset an Option to its default Value | |
117 ; | |
0 | 118 ; INPUT: FSR0 = option handle |
634 | 119 ; OUTPUT: option value set to default value |
120 ; option_repaired flag set | |
121 ; option_changed flag set if not a volatile option | |
0 | 122 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 |
123 ; | |
631 | 124 global option_reset ; reset option value to default |
0 | 125 option_reset: |
631 | 126 ; read type, default and register from table |
127 rcall option_read_definition ; read option definition | |
634 | 128 btfss opt_eeprom_bank,7 ; volatile option? |
129 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
130 ;bra option_init_loaded ; continue initializing the option value | |
631 | 131 |
634 | 132 |
133 ;----------------------------------------------------------------------------- | |
134 ; Reset an Option to its default Value | |
135 ; | |
136 ; INPUT: opt_* option definition vars initialized | |
137 ; OUTPUT: option value set to default value | |
138 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 | |
139 ; | |
140 option_init_loaded: | |
604 | 141 movf opt_type,W ; get option type |
631 | 142 xorlw .2 ; type = STRING ? |
634 | 143 bz opt_init_loaded_string ; YES - string copy |
631 | 144 movff opt_default,INDF1 ; NO - 1 byte copy |
145 return ; - done | |
146 | |
634 | 147 opt_init_loaded_string: |
148 movff TBLPTRL,mpr+0 ; back-up TBLPTR | |
149 movff TBLPTRH,mpr+1 ; ... | |
150 movff TBLPTRU,mpr+2 ; ... | |
151 | |
604 | 152 movff FSR1L,FSR2L ; set string destination address |
153 movff FSR1H,FSR2H ; ... | |
634 | 154 movff opt_inc,FSR1L ; get pointer to multi-lingual default text (stored in opt_inc:opt_min) |
155 movff opt_min,FSR1H ; ... | |
156 call strcat_text_FSR ; copy translated text to FSR2, hence string option | |
157 | |
631 | 158 movff mpr+0,TBLPTRL ; restore TBLPTR |
159 movff mpr+1,TBLPTRH ; ... | |
160 movff mpr+2,TBLPTRU ; ... | |
634 | 161 |
631 | 162 return ; done |
163 | |
0 | 164 |
634 | 165 ;----------------------------------------------------------------------------- |
166 ; Check one Option and reset its Value if it is out of its min/max Limits | |
631 | 167 ; |
634 | 168 ; INPUT: opt_* vars loaded, FSR1 pointing to option value |
169 ; hi value to be checked for validity | |
170 ; OUTPUT: option_value_ok set/not set | |
631 | 171 ; TRASH: WREG |
604 | 172 ; |
634 | 173 global option_check_loaded |
631 | 174 option_check_loaded: |
175 ; switch on type | |
634 | 176 bsf option_value_ok ; set result to ok by default |
631 | 177 movf opt_type,W ; get type |
178 bz option_check_uint8 ; type 0: INT8 | |
179 dcfsnz WREG ; decrement | |
180 bra option_check_enum8 ; type 1: ENUM | |
181 dcfsnz WREG ; decrement | |
634 | 182 return ; type 2: STRING - nothing to check |
631 | 183 ;bra option_check_uint8 ; type 3: INT8 |
184 | |
185 option_check_uint8: | |
186 tstfsz opt_min ; opt_min = 0 ? | |
187 bra option_check_min ; NO - check it | |
188 bra option_check_enum8 ; YES - continue with check for maximum | |
189 | |
190 option_check_min: | |
191 decf opt_min,W ; get (minimum permissible value - 1) into WREG | |
634 | 192 cpfsgt hi ; option value > (minimum permissible value - 1) ? |
193 bra option_check_nok ; NO - value not ok | |
631 | 194 ;bra option_check_enum8 ; YES - continue with check for maximum |
195 | |
196 option_check_enum8: | |
197 infsnz opt_max,W ; get (highest permissible value + 1) into WREG | |
634 | 198 return ; highest permissible value is 255, skip check, done |
199 cpfslt hi ; option value < (highest permissible value + 1) ? | |
200 bra option_check_nok ; NO - value not ok | |
201 return ; YES - value ok, done | |
631 | 202 |
634 | 203 option_check_nok: |
204 bcf option_value_ok ; flag option value is invalid | |
205 return ; done | |
582 | 206 |
631 | 207 |
634 | 208 ;----------------------------------------------------------------------------- |
209 ; Check and store all Option Values to EEPROM | |
631 | 210 ; |
211 global option_check_and_store_all | |
212 option_check_and_store_all: | |
634 | 213 bcf PIR3,RC2IE ; disable EUSART interrupts TODO: why??? |
214 call option_crosschecks ; do some crosschecks between option values | |
215 ;bra option_store_all ; continue storing all option values to EEPROM | |
216 | |
631 | 217 |
634 | 218 ;----------------------------------------------------------------------------- |
219 ; Store all Option Values to EEPROM | |
220 ; | |
221 option_store_all: | |
222 ;---- invalidate option version while updating | |
223 CLRI mpr ; set options version number to zero | |
224 EEPROM_II_WRITE mpr,eeprom_options_version ; store options version number in EEPROM | |
225 | |
226 ;---- check and store all option values | |
227 lfsr FSR0,option_table_begin ; point to start of option definition table | |
228 option_save_all_loop: | |
229 rcall option_check_and_store ; check and store option value | |
230 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
231 bra option_save_all_loop ; NO - do next option | |
232 | |
233 ;---- store option version | |
631 | 234 MOVLI eeprom_opt_version,mpr ; get options version number |
235 EEPROM_II_WRITE mpr,eeprom_options_version ; store options version number in EEPROM | |
236 | |
634 | 237 bcf option_changed ; no pending EEPROM updates any more |
238 return ; done | |
604 | 239 |
0 | 240 |
634 | 241 ;----------------------------------------------------------------------------- |
242 ; Check and store one Option Value to EEPROM | |
631 | 243 ; |
244 global option_check_and_store | |
245 option_check_and_store: | |
246 rcall option_read_definition ; read the option definition | |
634 | 247 movff INDF1,hi ; check current option value |
248 rcall option_check_loaded ; check value for validity | |
249 btfss option_value_ok ; value ok (strings are always 'valid') ? | |
250 movff opt_default,INDF1 ; NO - set value to default | |
251 ;bra option_store_loaded ; continue storing value | |
631 | 252 |
634 | 253 |
254 ;----------------------------------------------------------------------------- | |
255 ; Store one Option Value to EEPROM | |
256 ; | |
257 global option_store_loaded | |
258 option_store_loaded: | |
631 | 259 movf opt_eeprom_bank,W ; get bank |
260 andlw b'11111110' ; keep only bits 7-1 | |
261 tstfsz WREG ; bank < 0x02 ? | |
634 | 262 return ; NO - volatile option or illegal address, done/abort |
631 | 263 tstfsz opt_eeprom_bank ; YES - bank = 0 ? |
634 | 264 bra option_store_execute ; NO - address is valid in any case |
631 | 265 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 |
266 cpfsgt opt_eeprom_index ; - index >= start address ? | |
634 | 267 return ; NO - illegal address, done |
268 ;bra option_store_execute ; YES - address is valid | |
631 | 269 |
634 | 270 option_store_execute: |
631 | 271 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) |
272 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) | |
273 | |
604 | 274 movf opt_type,W ; get option type |
631 | 275 xorlw .2 ; option type = string ? |
634 | 276 bz option_store_exec_string ; YES - store string of bytes |
277 ;bnz option_store_exec_byte ; NO - store single byte | |
631 | 278 |
634 | 279 option_store_exec_byte: |
280 call read_eeprom ; read stored value | |
281 movf EEDATA,W ; copy stored value to WREG | |
282 xorwf INDF1,W ; xor with current value | |
283 btfsc STATUS,Z ; equal? | |
284 return ; YES - no need to write to EEPROM, done | |
285 movff INDF1,EEDATA ; NO - copy current option value to EEPROM write register | |
286 goto write_eeprom ; - execute write and return | |
287 | |
288 option_store_exec_string: | |
631 | 289 btfss EEADRH,1 ; current EEPROM address < 512 ? |
634 | 290 rcall option_store_exec_byte ; YES - store one byte from the string |
291 movf POSTINC1,W ; increment FSR1 address by a dummy read | |
631 | 292 infsnz EEADR,F ; increment EEPROM address, low byte |
293 incf EEADRH,F ; increment EEPROM address, high byte | |
294 decfsz opt_max ; decrement string length, done? | |
634 | 295 bra option_store_exec_string ; NO - loop |
631 | 296 return ; YES - done |
297 | |
298 | |
634 | 299 ;----------------------------------------------------------------------------- |
300 ; Restore all Option Values from EEPROM and check them | |
631 | 301 ; |
634 | 302 global option_restore_and_check_all |
631 | 303 option_restore_and_check_all: |
304 ;---- Read option version from EEPROM | |
305 EEPROM_II_READ eeprom_options_version,mpr | |
306 | |
307 movlw LOW(eeprom_opt_version) ; get options version from current firmware, low byte | |
308 xorwf mpr+0,W ; compare with EEPROM version, do they match? | |
309 bnz option_restore_reset ; NO - reset to defaults of current firmware | |
310 | |
311 movlw HIGH(eeprom_opt_version) ; get options version from current firmware, high byte | |
312 xorwf mpr+1,W ; compare with EEPROM version, do they match? | |
313 bnz option_restore_reset ; NO - reset to defaults of current firmware | |
314 | |
315 ;---- restore all option values | |
316 lfsr FSR0,option_table_begin ; point to start of option definition table | |
317 option_restore_all_loop: | |
318 rcall option_restore_and_check ; restore and check the option | |
319 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
320 bra option_restore_all_loop ; NO - do next option | |
634 | 321 |
322 bcf option_changed ; clear flag | |
323 call option_crosschecks ; do some crosschecks between option values | |
324 btfsc option_changed ; found and corrected errors? | |
325 bra option_store_all ; YES - write back corrected data to EEPROM | |
326 return ; NO - done | |
631 | 327 |
328 option_restore_reset: | |
329 call option_reset_all ; reset all option values to their default | |
330 goto option_check_and_store_all ; write back all option values to EEPROM (and return) | |
331 | |
582 | 332 |
634 | 333 ;----------------------------------------------------------------------------- |
334 ; Restore one Option Value from EEPROM and check it | |
631 | 335 ; |
336 global option_restore_and_check | |
337 option_restore_and_check: | |
338 rcall option_read_definition ; read the option definition | |
0 | 339 |
631 | 340 movf opt_eeprom_bank,W ; get bank |
341 andlw b'11111110' ; keep only bits 7-1 | |
342 tstfsz WREG ; bank < 0x02 ? | |
634 | 343 bra option_init_loaded ; NO - volatile option or illegal address, initialize to default |
631 | 344 tstfsz opt_eeprom_bank ; YES - bank = 0 ? |
634 | 345 bra option_restore_execute ; NO - address is valid in any case |
631 | 346 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 |
347 cpfsgt opt_eeprom_index ; - index >= start address ? | |
634 | 348 bra option_init_loaded ; NO - illegal address, initialize to default |
631 | 349 ;bra option_restore_execute ; YES - address is valid |
0 | 350 |
631 | 351 option_restore_execute: |
352 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) | |
353 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) | |
0 | 354 |
631 | 355 movf opt_type,W ; get option type |
356 xorlw .2 ; option type = string ? | |
634 | 357 bz option_restore_exec_string ; YES - special handling |
358 call read_eeprom ; NO - execute EEPROM read | |
359 movff EEDATA,INDF1 ; - copy from EEPROM read register to option variable | |
360 movff EEDATA,hi ; - check loaded option value | |
361 rcall option_check_loaded ; - check if option value is within min/max limits | |
362 btfsc option_value_ok ; - option value ok (strings will always be 'ok') ? | |
363 return ; YES - done | |
364 movff opt_default,INDF1 ; NO - set option value to default | |
365 movff INDF1,EEDATA ; - copy repaired value to EEPROM write register | |
366 goto write_eeprom ; - execute write and return | |
0 | 367 |
634 | 368 option_restore_exec_string: |
631 | 369 call read_eeprom ; read one character from the EEPROM |
370 movff EEDATA,POSTINC1 ; copy it to the option value | |
371 infsnz EEADR,F ; increment EEPROM address, low byte | |
372 incf EEADRH,F ; increment EEPROM address, high byte | |
373 decfsz opt_max ; decrement string length, done? | |
634 | 374 bra option_restore_exec_string ; NO - loop |
631 | 375 return ; YES - done (nothing to check with strings) |
376 | |
377 | |
0 | 378 |
634 | 379 ;----------------------------------------------------------------------------- |
380 ; Read an Option Value via serial Index | |
381 ; | |
631 | 382 ; INPUT: lo = serial index |
383 ; OUTPUT: hi = option value | |
384 ; WREG =0: option found and value valid, =1: option not found | |
385 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
386 ; | |
387 global option_read_serial | |
388 option_read_serial: | |
389 lfsr FSR0,option_table_begin ; point to start of option definition table | |
390 option_read_serial_loop: | |
391 rcall option_read_definition ; read option definition | |
392 movf opt_serial,W ; get serial index of the option into WREG | |
393 xorwf lo,W ; received index = index of this option ? | |
394 bz option_read_serial_execute ; YES - read value | |
395 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? | |
396 bra option_read_serial_loop ; NO - try next option | |
634 | 397 retlw .1 ; YES - option not found, abort |
631 | 398 |
399 option_read_serial_execute: | |
400 movff INDF1,hi ; read option value into hi | |
634 | 401 retlw .0 ; done |
631 | 402 |
403 | |
634 | 404 ;----------------------------------------------------------------------------- |
405 ; Write an Option Value via serial Index | |
406 ; | |
631 | 407 ; INPUT: lo = serial index |
408 ; hi = option value | |
409 ; OUTPUT: WREG =0: option found and value valid, =1: option not found, =2: value not valid | |
410 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, up | |
411 ; | |
412 global option_write_serial | |
413 option_write_serial: | |
414 lfsr FSR0,option_table_begin ; point to start of option definition table | |
415 option_write_serial_loop: | |
416 rcall option_read_definition ; read option definition | |
417 movf opt_serial,W ; get serial index of the option into WREG | |
418 xorwf lo,W ; received index = index of this option ? | |
419 bz option_write_serial_execute ; YES - check and update value | |
420 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? | |
421 bra option_write_serial_loop ; NO - try next option | |
634 | 422 retlw .1 ; YES - option not found, abort |
631 | 423 |
424 option_write_serial_execute: | |
645 | 425 rcall option_check_loaded ; check if new value is valid |
426 btfss option_value_ok ; value valid? | |
427 bra option_write_serial_invalid ; NO | |
428 movff hi,INDF1 ; YES - take new value | |
429 btfss opt_eeprom_bank,7 ; - volatile option? | |
430 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
431 retlw .0 ; - done | |
432 | |
433 option_write_serial_invalid: | |
434 movlw 0x32 ; load serial id of the language option (oLanguage) | |
435 cpfseq lo ; option to write = language option ? | |
436 retlw .2 ; NO - value not valid, abort | |
437 retlw .0 ; YES - value not valid, but silently ignore | |
631 | 438 |
439 | |
634 | 440 ;----------------------------------------------------------------------------- |
441 ; Increment an Option Value based on Type and min/max Boundary | |
442 ; | |
0 | 443 ; INPUT: FSR0 = option handle |
634 | 444 ; OUTPUT: incremented option value |
0 | 445 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 |
604 | 446 ; |
634 | 447 global option_inc |
0 | 448 option_inc: |
604 | 449 ; read type, default and register from table |
631 | 450 rcall option_read_definition |
451 | |
634 | 452 btfss opt_eeprom_bank,7 ; volatile option? |
453 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
582 | 454 |
604 | 455 ; switch on type |
631 | 456 movf opt_type,W ; get option type |
634 | 457 bz option_inc_uint8 ; type 0: UINT8 |
631 | 458 dcfsnz WREG ; decrement |
459 bra option_inc_enum8 ; type 1: ENUM | |
460 dcfsnz WREG ; decrement | |
634 | 461 return ; type 2: STRING - no inc function defined |
462 dcfsnz WREG ; decrement | |
463 bra option_inc_uint8 ; type 3: UINT8 as meters or feet | |
464 return ; unknown, do nothing | |
0 | 465 |
634 | 466 |
467 ;----------------------------------------------------------------------------- | |
468 ; Helper Function - increment UINT8, wrap-around or stop at option max | |
469 ; | |
631 | 470 option_inc_uint8: |
471 movf INDF1,W ; get option value | |
472 addwf opt_inc,W ; add increment | |
634 | 473 cpfslt opt_max ; option value > max ? |
631 | 474 bra option_inc_uint8_0 ; NO - new option value ok |
634 | 475 movf opt_min,W ; YES - reset to min value by default |
476 btfsc option_stop_at_max ; - shall the option value stop at max? | |
477 movf opt_max,W ; YES - keep at max value | |
604 | 478 option_inc_uint8_0: |
631 | 479 movwf INDF1 ; store new value |
634 | 480 ; do cross-checks with other option values |
604 | 481 option_inc_uint8_1: |
631 | 482 ; now some rather crude hack into this routine to make CCR calibration more convenient: |
483 movlw 0x37 ; serial ID of option CalGasO2 | |
484 cpfseq opt_serial ; editing CalGasO2 right now? | |
608 | 485 bra option_inc_uint8_2 ; NO - check next option |
604 | 486 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR |
487 decfsz WREG,W ; - in CCR mode? | |
488 return ; NO - done | |
489 movlw .26 ; YES - | |
490 cpfseq INDF1 ; - option value = 26 ? | |
491 return ; NO - done | |
492 movlw .95 ; YES - advance it to 95 | |
493 movwf INDF1 ; - store it | |
533
dfac393b2199
CHANGE: CCR Calibration gas range limited to O2% 21-25 and 95-100 to save button presses
heinrichsweikamp
parents:
418
diff
changeset
|
494 return |
634 | 495 |
608 | 496 option_inc_uint8_2: |
634 | 497 ; check GF low <= GF high |
631 | 498 movlw 0x25 ; serial ID of option opt_GF_low |
499 cpfseq opt_serial ; editing opt_GF_low right now? | |
608 | 500 bra option_inc_uint8_3 ; NO - check next option |
501 movff opt_GF_high,WREG ; get value of associated GF high into WREG | |
502 cpfsgt INDF1 ; GF low > GF high? | |
503 return ; NO - setting ok, done | |
504 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
505 return ; - done | |
634 | 506 |
608 | 507 option_inc_uint8_3: |
634 | 508 ; check GF high >= GF low |
631 | 509 movlw 0x26 ; serial ID of option opt_GF_high |
510 cpfseq opt_serial ; editing opt_GF_high right now? | |
608 | 511 bra option_inc_uint8_4 ; NO - check next option |
512 movff opt_GF_low,WREG ; get value of associated GF low into WREG | |
513 cpfslt INDF1 ; GF high < GF low? | |
514 return ; NO - setting ok, done | |
515 movwf INDF1 ; YES - rise GF high to GF low | |
516 return ; - done | |
634 | 517 |
608 | 518 option_inc_uint8_4: |
634 | 519 ; check aGF low <= aGF high |
631 | 520 movlw 0x27 ; serial ID of option opt_aGF_low |
521 cpfseq opt_serial ; editing opt_aGF_low right now? | |
608 | 522 bra option_inc_uint8_5 ; NO - check next option |
523 movff opt_aGF_high,WREG ; get value of associated GF high into WREG | |
524 cpfsgt INDF1 ; GF low > GF high? | |
525 return ; NO - setting ok, done | |
526 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
527 return ; - done | |
634 | 528 |
608 | 529 option_inc_uint8_5: |
634 | 530 ; check aGF high >= aGF low |
631 | 531 movlw 0x28 ; serial ID of option opt_aGF_high |
532 cpfseq opt_serial ; editing opt_aGF_high right now? | |
608 | 533 bra option_inc_uint8_6 ; NO - check next option |
534 movff opt_aGF_low,WREG ; get value of associated GF low into WREG | |
535 cpfslt INDF1 ; GF high < GF low? | |
536 return ; NO - setting ok, done | |
537 movwf INDF1 ; YES - rise GF high to GF low | |
538 return ; - done | |
634 | 539 |
608 | 540 option_inc_uint8_6: |
634 | 541 ; progressive increment for char_I_SAC_work |
542 movlw 0x3C ; serial ID of option char_I_SAC_work | |
543 cpfseq opt_serial ; editing char_I_SAC_work right now? | |
544 bra option_inc_uint8_7 ; NO - check next option | |
545 movlw .40 ; YES - set threshold for incrementing in steps of 2 | |
546 cpfsgt INDF1 ; - option value > threshold ? | |
547 return ; NO - done | |
548 incf INDF1,F ; YES - increment one more time | |
549 return ; - done | |
550 | |
551 option_inc_uint8_7: | |
552 IFDEF _helium | |
553 ; check O2% + He% <= 100% | |
554 movlw 0xFA ; serial ID of O2% options | |
555 cpfseq opt_serial ; editing a O2% right now? | |
556 bra option_inc_uint8_7a ; NO - check for He% | |
557 movlw .2*NUM_GAS ; YES - load offset between O2% and He% for gas/dil 1-5 | |
558 btfsc opt_eeprom_bank,7 ; - volatile option? | |
559 movlw .1 ; YES - load offset between O2% and He% for gas 6 | |
560 bra option_inc_uint8_7b ; continue with common part | |
561 option_inc_uint8_7a: | |
562 movlw 0xFB ; serial ID of He% options | |
563 cpfseq opt_serial ; editing a He% right now? | |
564 bra option_inc_uint8_8 ; NO - check next option | |
565 movlw -.2*NUM_GAS ; YES - load offset between He% and O2% for gas/dil 1-5 | |
566 btfsc opt_eeprom_bank,7 ; - volatile option? | |
567 movlw -.1 ; YES - load offset between He% and O2% for gas 6 | |
568 option_inc_uint8_7b: | |
569 movff PLUSW1,hi ; - copy complementing gas % to hi | |
570 movf INDF1,W ; - copy primary gas % to WREG | |
571 addwf hi,F ; - hi = O2% + He% | |
572 movlw .101 ; - load max allowed sum + 1 | |
573 cpfslt hi ; - O2% + He% < 101 ? | |
574 decf INDF1,F ; NO - decrement primary gas% again | |
575 ENDIF ; _helium | |
576 | |
577 option_inc_uint8_8 | |
578 ; add more cross-checks with other option values here | |
608 | 579 return ; all done |
580 | |
0 | 581 |
634 | 582 ;----------------------------------------------------------------------------- |
583 ; Helper Function - increment ENUM, will wrap-around on exceeding option max | |
584 ; | |
631 | 585 option_inc_enum8: |
634 | 586 incf INDF1,W ; get incremented option value |
587 cpfslt opt_max ; option value > max? | |
588 bra option_inc_enum8_0 ; NO - new option value ok | |
589 clrf WREG ; YES - reset to 1st option value | |
590 option_inc_enum8_0: | |
591 movwf INDF1 ; store new value | |
592 ; do cross-checks with other option values | |
604 | 593 option_inc_enum8_1: |
623 | 594 IFDEF _ccr_pscr |
631 | 595 ; now some rather crude hack into this routine to unify CCR & pSCR mode setting |
596 movlw 0x1F ; serial ID of option oCCRMode | |
597 cpfseq opt_serial ; editing oCCRMode right now? | |
604 | 598 bra option_inc_enum8_2 ; NO - check next option |
623 | 599 IFDEF _external_sensor |
634 | 600 btfsc ext_input_s8_ana ; YES - S8/analog input available? |
604 | 601 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed |
634 | 602 btfsc ext_input_optical ; - optical interface available? |
604 | 603 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed |
623 | 604 ENDIF ; _external_sensor |
604 | 605 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP) |
606 xorlw .1 ; - in sensor mode? | |
607 bnz option_inc_enum8_1a ; NO - continue with next check | |
608 incf INDF1,F ; YES - advance option value to AutoSP | |
609 option_inc_enum8_1a: | |
610 movff opt_dive_mode,WREG ; get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
611 xorlw .4 ; in pSCR mode? | |
612 bnz option_inc_enum8_1_exit ; NO - done | |
613 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP) | |
614 option_inc_enum8_1_exit: | |
615 return ; done | |
623 | 616 ENDIF ; _ccr_pscr |
631 | 617 |
604 | 618 option_inc_enum8_2: |
631 | 619 IFDEF _gas_contingency |
620 ; now some rather crude hack to switch off contingency mode if gas needs calculation is switched off | |
621 movlw 0x5A ; serial ID of option opt_calc_gasvolume | |
622 cpfseq opt_serial ; editing opt_calc_gasvolume right now? | |
623 bra option_inc_enum8_3 ; NO - check next option | |
624 movf INDF1,W ; YES - get option value | |
634 | 625 ;xorlw .0 ; - option value = off ? |
631 | 626 bnz option_inc_enum8_2_exit ; NO - done |
627 clrf WREG ; YES - force contingency to be off, too | |
628 movff WREG,opt_gas_contingency_dive ; - ... | |
629 option_inc_enum8_2_exit: | |
630 return | |
631 ENDIF ; _gas_contingency | |
632 | |
604 | 633 option_inc_enum8_3: |
631 | 634 ; now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode |
635 movlw 0x20 ; serial ID of option opt_dive_mode | |
636 cpfseq opt_serial ; editing opt_dive_mode right now? | |
604 | 637 bra option_inc_enum8_4 ; NO - check next option |
623 | 638 movf INDF1,W ; YES - get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR |
639 xorlw .1 ; in CCR mode? | |
640 bnz option_inc_enum8_3a ; NO - in some other mode | |
641 IFNDEF _ccr_pscr | |
642 incf INDF1,f ; YES - no CCR mode compiled in, advance to gauge mode | |
628 | 643 bra option_inc_enum8_3a ; - check if gauge mode is available |
623 | 644 ENDIF ; _ccr_pscr |
645 IFDEF _rx_functions | |
646 global option_cleanup_oTrMode_CCR ; embedded clean-up entry-point | |
604 | 647 option_cleanup_oTrMode_CCR: ; entry point from cleanup during restart |
623 | 648 movff opt_TR_mode,WREG ; get TR mode |
649 xorlw .2 ; mode = 2 (ind.double)? | |
650 bnz option_inc_enum8_3_exit ; NO - done | |
651 bra option_inc_enum8_3_reset ; YES - revert mode to 1 (on) | |
652 ENDIF ; _rx_functions | |
604 | 653 option_inc_enum8_3a: ; any mode other than CCR |
628 | 654 IFNDEF _gauge_mode |
655 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
656 xorlw .2 ; in Gauge mode? | |
657 bnz option_inc_enum8_3b ; NO - in some other mode | |
658 incf INDF1,f ; YES - no Gauge mode compiled in, advance to Apnea mode | |
659 bra option_inc_enum8_3_exit ; - done (Apnea mode is always available) | |
660 ENDIF ; _gauge_mode | |
661 option_inc_enum8_3b: | |
623 | 662 IFNDEF _ccr_pscr |
663 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
664 xorlw .4 ; in pSCR mode? | |
628 | 665 bnz option_inc_enum8_3c ; NO - in some other mode |
623 | 666 clrf INDF1 ; YES - no pSCR mode compiled in, advance to 0 "OC" |
667 bra option_inc_enum8_3_exit ; - done | |
668 ENDIF ; _ccr_pscr | |
628 | 669 option_inc_enum8_3c: |
623 | 670 global option_cleanup_oTrMode_no_CCR ; embedded clean-up entry-point |
604 | 671 option_cleanup_oTrMode_no_CCR: ; entry point from cleanup during restart |
672 movff opt_TR_mode,WREG ; get TR mode | |
673 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
674 bnz option_inc_enum8_3_exit ; NO - done | |
675 option_inc_enum8_3_reset: ; YES - revert to mode 1 (on) | |
676 movlw .1 ; load coding of mode "on" | |
677 movff WREG,opt_TR_mode ; write to option | |
678 option_inc_enum8_3_exit: | |
679 return ; done | |
628 | 680 |
604 | 681 option_inc_enum8_4: |
623 | 682 IFDEF _rx_functions |
631 | 683 ; now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode |
684 movlw 0x7E ; serial ID of option opt_TR_mode | |
685 cpfseq opt_serial ; editing opt_TR_mode right now? | |
604 | 686 bra option_inc_enum8_5 ; NO - check next option |
687 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
688 decfsz WREG,W ; dive mode = 1 CCR? | |
689 bra option_inc_enum8_4a ; NO - in any other mode | |
690 movf INDF1,W ; YES - get option value (TR mode) | |
691 xorlw .2 ; - mode = 2 (ind.double)? | |
692 bnz option_inc_enum8_4_exit ; NO - done | |
693 incf INDF1,F ; YES - advance option value to 3 (CCR Dil+O2) | |
694 bra option_inc_enum8_4_exit ; - done | |
695 option_inc_enum8_4a: ; any mode other than CCR | |
696 movf INDF1,W ; get option value (TR mode) | |
697 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
698 bnz option_inc_enum8_4_exit ; NO - done | |
699 clrf INDF1 ; YES - advance option value to 0 "off" | |
700 option_inc_enum8_4_exit: | |
701 return ; done | |
623 | 702 ENDIF ; _rx_functions |
631 | 703 |
604 | 704 option_inc_enum8_5: |
631 | 705 IFDEF _gas_contingency |
706 ; now some rather crude hack to keep contingency mode switched off if gas needs calculation is switched off | |
707 movlw 0x91 ; serial ID of option opt_gas_contingency_dive | |
708 cpfseq opt_serial ; editing opt_gas_contingency_dive right now? | |
709 bra option_inc_enum8_6 ; NO - check next option | |
710 movff opt_calc_gasvolume,WREG ; YES - get current setting of gas needs calculation | |
711 tstfsz WREG ; - gas needs calculation switched off? | |
712 return ; NO - done, opt_gas_contingency_dive may be switched on | |
713 clrf INDF1 ; YES - force opt_gas_contingency_dive to off | |
714 return ; - done | |
715 ENDIF ; _gas_contingency | |
716 | |
717 option_inc_enum8_6: | |
634 | 718 ; add more cross-checks with other option values here |
582 | 719 return |
0 | 720 |
604 | 721 |
634 | 722 ;----------------------------------------------------------------------------- |
723 ; Decrement an Option Value based on Type and min/max Boundary | |
724 ; | |
725 ; INPUT: FSR0 = option handle | |
726 ; OUTPUT: decremented option value | |
727 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
728 ; | |
729 global option_dec | |
730 option_dec: | |
731 ; read type, default and register from table | |
732 rcall option_read_definition | |
733 | |
734 btfss opt_eeprom_bank,7 ; volatile option? | |
735 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
736 | |
737 ; switch on type | |
738 movf opt_type,W ; get option type | |
739 bz option_dec_uint8 ; type 0: UINT8 | |
740 dcfsnz WREG ; decrement | |
741 bra option_dec_enum8 ; type 1: ENUM | |
742 dcfsnz WREG ; decrement | |
743 return ; type 2: STRING - no dec function defined | |
744 dcfsnz WREG ; decrement | |
745 bra option_dec_uint8 ; type 3: UINT8 as meters or feet | |
746 return ; unknown, do nothing | |
747 | |
748 | |
749 ;----------------------------------------------------------------------------- | |
750 ; Helper Function - decrement UINT8, will stop on reaching option min | |
751 ; | |
752 option_dec_uint8: | |
753 movf INDF1,W ; get option value | |
754 bsf STATUS,C ; set carry (= clear borrow) | |
755 subfwb opt_inc,W ; subtract increment | |
756 bnc option_dec_uint8_reset ; under-run? -> reset | |
757 cpfsgt opt_min ; option value < min ? | |
758 bra option_dec_uint8_0 ; NO - new option value ok | |
759 option_dec_uint8_reset: | |
760 movf opt_min,W ; YES - reset to min value | |
761 option_dec_uint8_0: | |
762 movwf INDF1 ; store new value | |
763 ; add cross-checks with other option values here | |
764 return ; done | |
765 | |
766 | |
767 ;----------------------------------------------------------------------------- | |
768 ; Helper Function - decrement ENUM, will stop on reaching first option value | |
769 ; | |
770 option_dec_enum8: | |
771 tstfsz INDF1 ; option value = 0 ? | |
772 decf INDF1,F ; NO - decrement value | |
773 option_dec_enum8_0: | |
774 ; add cross-checks with other option values here | |
775 return ; done | |
776 | |
777 | |
778 ;----------------------------------------------------------------------------- | |
779 ; Draw an Option Value | |
780 ; | |
781 global option_draw | |
782 option_draw: | |
783 ; read type, default and register from table | |
784 rcall option_read_definition | |
785 | |
786 ; switch on type | |
787 movf opt_type,W ; get option type | |
788 bz option_draw_uint8 ; type0 = INT8 | |
789 dcfsnz WREG | |
790 bra option_draw_enum8 ; type1 = ENUM | |
791 dcfsnz WREG | |
792 bra option_draw_string ; type2 = string | |
793 dcfsnz WREG | |
794 bra option_draw_uint8_depth ; type3 = INT8 as meters or feet | |
795 return ; unknown, do nothing | |
796 | |
797 | |
798 ;----------------------------------------------------------------------------- | |
799 ; Helper Function - draw a String | |
800 ; | |
801 option_draw_string: | |
802 movff POSTINC1,POSTINC2 ; copy one character | |
803 decfsz opt_max ; decrement remaining string length, became zero? | |
804 bra option_draw_string ; NO - loop | |
805 return ; YES - done | |
806 | |
807 | |
808 ;----------------------------------------------------------------------------- | |
809 ; Helper Function - draw an INT with automatic display in meters or feet | |
810 ; | |
811 option_draw_uint8_depth: | |
812 TSTOSS opt_units ; using metric units (0=m, 1=ft)? | |
813 bra option_draw_uint8 ; YES - handle with standard output | |
814 movff INDF1,lo ; NO - imperial, get value to lo | |
815 call convert_meter_to_feet ; - convert value in lo from meter to feet | |
816 ; bsf leftbind ; - print with left alignment | |
817 output_999 ; - print depth (0-999) | |
818 STRCAT_TEXT tFeets ; - append unit and dump to screen | |
819 bra option_draw_uint8_common ; - continue with common part | |
820 | |
821 | |
822 ;----------------------------------------------------------------------------- | |
823 ; Helper Function - draw an INT | |
824 ; | |
825 option_draw_uint8: | |
826 movff INDF1,lo ; get option value | |
827 | |
828 movlw .99 ; load a 99 | |
829 cpfsgt opt_max ; max value > 99 ? | |
830 bsf hide_digit3 ; NO - do not show digit 3 | |
831 movlw .9 ; load a 9 | |
832 cpfsgt opt_max ; max value > 9 ? | |
833 bsf hide_digit2 ; NO - do not show digit 2 | |
834 | |
835 output_256 ; print option value | |
836 | |
837 movf opt_unit+0,W ; is there a unit to append? | |
838 iorwf opt_unit+1,W ; ... | |
839 bz option_draw_uint8_common ; NO - continue with common part | |
840 movff opt_unit+0,FSR1L ; YES - pointer to multi-lingual unit text | |
841 movff opt_unit+1,FSR1H ; - ... | |
842 call strcat_text_FSR ; - append unit text to buffer | |
843 ;bra option_draw_uint8_common ; - continue with common part | |
844 | |
845 | |
846 ;----------------------------------------------------------------------------- | |
847 ; Helper Function - common Part for INT | |
848 ; | |
849 option_draw_uint8_common: | |
850 movf opt_default,W ; get default value | |
851 cpfseq lo ; compare with current value, equal? | |
852 bra option_draw_uint8_common_1 ; NO - not default, add * | |
853 return ; YES - default, done | |
854 option_draw_uint8_common_1: | |
855 PUTC "*" ; print "*" | |
856 return ; done | |
857 | |
858 | |
859 ;----------------------------------------------------------------------------- | |
860 ; Helper Function - draw an ENUM (set of translated strings) | |
861 ; | |
862 option_draw_enum8: | |
863 movf INDF1,W ; copy option value to WREG | |
864 movwf lo ; memorize option value, too | |
865 cpfslt opt_max ; option value > maximum permissible value ? | |
866 bra option_draw_enum8_0 ; NO - option value allowed | |
867 clrf WREG ; YES - to avoid printing rubbish, use first ENUM item instead | |
868 option_draw_enum8_0: | |
869 addwf WREG ; current value *= 2 | |
870 addwf opt_inc,W ; base text + 2 * current value | |
871 movwf FSR1L ; load FSR1 | |
872 movlw .0 ; propagate carry... | |
873 addwfc opt_min,W ; ... | |
874 movwf FSR1H ; ...into FSR1 | |
875 call strcat_text_FSR ; print text | |
876 movf opt_default,W ; get default value | |
877 cpfseq lo ; compare with memorized current value, equal? | |
878 bra option_draw_enum8_1 ; NO - not default, add * | |
879 return ; YES - default, done | |
880 option_draw_enum8_1: | |
881 PUTC "*" ; print "*" | |
882 return ; done | |
883 | |
884 | |
885 ;============================================================================= | |
886 options2 CODE | |
887 ;============================================================================= | |
888 | |
889 | |
890 ;----------------------------------------------------------------------------- | |
891 ; Check and Resolve some Interdependencies among Option Values | |
892 ; | |
893 option_crosschecks: | |
894 bsf is_diluent_menu ; setup checking diluents | |
895 call gaslist_cleanup_list ; check and correct multiple or none First diluents | |
896 | |
897 bcf is_diluent_menu ; setup checking gases | |
898 call gaslist_cleanup_list ; check and correct multiple or none First gases | |
899 | |
900 rcall option_cleanup_GF ; check and correct GFlow <= GFhigh | |
901 | |
628 | 902 IFNDEF _gauge_mode |
634 | 903 rcall option_cleanup_gauge ; check and correct gauge mode |
904 ENDIF ; _gauge_mode | |
628 | 905 |
623 | 906 IFDEF _ccr_pscr |
634 | 907 rcall option_cleanup_oCCRMode ; check and correct CCR / pSCR mode |
623 | 908 ENDIF ; _ccr_pscr |
909 | |
634 | 910 IFDEF _helium |
911 rcall option_cleanup_sum_O2_He ; check and correct O2% + He% <= 100 +++ | |
912 ENDIF ; _helium | |
604 | 913 |
634 | 914 return ; done |
915 | |
916 | |
917 ;----------------------------------------------------------------------------- | |
918 ; Check and correct GFs so that GF_high >= GF_low | |
919 ; | |
608 | 920 option_cleanup_GF: |
921 ; cleanup normal GF | |
922 movff opt_GF_high,WREG ; copy normal GF high to WREG | |
623 | 923 movff opt_GF_low,mpr ; copy normal GF low to mpr |
924 cpfsgt mpr ; GF low > GF high ? | |
608 | 925 bra option_cleanup_GF_2 ; NO - option ok, check next option |
623 | 926 movwf mpr ; YES - copy GF high to mpr |
608 | 927 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 928 cpfsgt mpr ; - mpr > 100 ? |
608 | 929 bra option_cleanup_GF_1 ; NO - correct GF low to GF high |
623 | 930 movwf mpr ; YES - correct GF low to 100% |
608 | 931 option_cleanup_GF_1: |
623 | 932 movff mpr,opt_GF_low ; store corrected GF low |
634 | 933 bsf option_changed ; flag that EEPROM needs to be updated |
608 | 934 option_cleanup_GF_2: |
935 ; cleanup alternative GF | |
936 movff opt_aGF_high,WREG ; copy alternative GF high to WREG | |
623 | 937 movff opt_aGF_low,mpr ; copy alternative GF low to mpr |
938 cpfsgt mpr ; GF low > GF high ? | |
608 | 939 bra option_cleanup_GF_4 ; NO - option ok, check next option |
623 | 940 movwf mpr ; YES - copy GF high to mpr |
608 | 941 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 942 cpfsgt mpr ; - mpr > 100 ? |
608 | 943 bra option_cleanup_GF_3 ; NO - correct GF low to GF high |
623 | 944 movwf mpr ; YES - correct GF low to 100% |
608 | 945 option_cleanup_GF_3: |
623 | 946 movff mpr,opt_aGF_low ; store corrected GF low |
634 | 947 bsf option_changed ; flag that EEPROM needs to be updated |
608 | 948 option_cleanup_GF_4: |
949 return ; done | |
950 | |
634 | 951 ;----------------------------------------------------------------------------- |
952 ; Check and correct Dive Mode if Gauge Mode is not allowed | |
604 | 953 ; |
634 | 954 IFNDEF _gauge_mode |
955 option_cleanup_gauge: | |
956 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
957 xorlw .2 ; in Gauge mode? | |
958 bnz option_cleanup_gauge_1 ; NO - done | |
959 movff WREG,opt_dive_mode ; YES - setting not allowed, WREG is zero -> reset to OC mode | |
960 bsf option_changed ; - flag that EEPROM needs to be updated | |
961 option_cleanup_gauge_1: | |
604 | 962 return ; done |
634 | 963 ENDIF ; _gauge_mode |
0 | 964 |
965 | |
634 | 966 ;----------------------------------------------------------------------------- |
967 ; Check and correct AutoSP and external Sensor Settings dependent on Modes | |
968 ; | |
969 IFDEF _ccr_pscr | |
970 global option_cleanup_oCCRMode | |
971 global option_cleanup_oCCRMode_pSCR | |
972 global option_cleanup_oCCRMode_CCR | |
973 option_cleanup_oCCRMode: ; in pSCR mode, revert AutoSP (2) to calculated SP (0), in pSCR and CCR revert Sensor to fixed SP if no sensor interface available | |
974 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
975 xorlw .4 ; in pSCR mode? | |
976 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC | |
977 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode | |
978 banksel opt_ccr_mode ; YES - select options bank | |
979 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) | |
980 banksel common ; - back to bank common | |
981 bsf option_changed ; - flag that EEPROM needs to be updated | |
982 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode | |
983 IFDEF _external_sensor | |
984 btfsc ext_input_s8_ana ; S8/analog interface available? | |
985 return ; YES - setting 'sensor' allowed | |
986 btfsc ext_input_optical ; does hosting OSTC have an optical interface? | |
987 return ; YES - setting 'sensor' allowed | |
988 ENDIF ; _external_sensor | |
989 movff opt_ccr_mode,WREG ; NO to both - get CCR mode | |
990 xorlw .1 ; - coding for sensor | |
991 tstfsz WREG ; - CCR mode = sensor? | |
992 return ; NO - setting allowed | |
993 banksel opt_ccr_mode ; YES - setting not allowed, select options bank | |
994 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) | |
995 banksel common ; - back to bank common | |
996 bsf option_changed ; - flag that EEPROM needs to be updated | |
997 return ; - done | |
998 ENDIF ; _ccr_pscr | |
999 | |
1000 | |
1001 ;----------------------------------------------------------------------------- | |
1002 ; Check and correct that O2% + He% <= 100% | |
1003 ; | |
1004 IFDEF _helium | |
1005 option_cleanup_sum_O2_He: | |
1006 lfsr FSR0,opt_gas_He_ratio-1 ; load (base address of He% array - 1) because of PREINC | |
1007 movlw 2*NUM_GAS ; load loop counter | |
1008 movwf lo ; ... | |
1009 option_cleanup_sum_loop: | |
1010 movff PREINC1,up ; get He ratio | |
1011 movlw -2*NUM_GAS ; address O2 ratio | |
1012 movff PLUSW0,hi ; get O2 ratio | |
1013 movlw .100 ; load WREG with 100% | |
1014 bsf STATUS,C ; set carry = clear borrow | |
1015 subfwb hi,W ; subtract O2% from WREG | |
1016 subfwb up,W ; subtract He% from WREG | |
1017 btfsc STATUS,C ; result negative? | |
1018 bra option_cleanup_sum_loop_1 ; NO - sum valid | |
1019 clrf INDF1 ; YES - heal by setting He% to zero | |
1020 bsf option_changed ; flag that EEPROM needs to be updated | |
1021 option_cleanup_sum_loop_1: | |
1022 decfsz lo ; decrement loop counter, all done? | |
1023 bra option_cleanup_sum_loop ; NO - loop | |
1024 return ; YES - done | |
1025 ENDIF ; _helium | |
1026 | |
628 | 1027 |
623 | 1028 ;----------------------------------------------------------------------------- |
0 | 1029 |
623 | 1030 END |