Mercurial > public > hwos_code
annotate src/options.asm @ 642:a9a0188091e4
fix rare upgrade issue with OSTC sport 2019 hardware
author | heinrichsweikamp |
---|---|
date | Thu, 14 Jan 2021 16:24:07 +0100 |
parents | 4050675965ea |
children | 070528a88715 |
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: | |
634 | 425 rcall option_check_loaded ; check if new value is valid |
426 btfss option_value_ok ; value valid? | |
427 retlw .2 ; NO - value not valid, abort | |
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 | |
631 | 432 |
433 | |
634 | 434 ;----------------------------------------------------------------------------- |
435 ; Increment an Option Value based on Type and min/max Boundary | |
436 ; | |
0 | 437 ; INPUT: FSR0 = option handle |
634 | 438 ; OUTPUT: incremented option value |
0 | 439 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 |
604 | 440 ; |
634 | 441 global option_inc |
0 | 442 option_inc: |
604 | 443 ; read type, default and register from table |
631 | 444 rcall option_read_definition |
445 | |
634 | 446 btfss opt_eeprom_bank,7 ; volatile option? |
447 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
582 | 448 |
604 | 449 ; switch on type |
631 | 450 movf opt_type,W ; get option type |
634 | 451 bz option_inc_uint8 ; type 0: UINT8 |
631 | 452 dcfsnz WREG ; decrement |
453 bra option_inc_enum8 ; type 1: ENUM | |
454 dcfsnz WREG ; decrement | |
634 | 455 return ; type 2: STRING - no inc function defined |
456 dcfsnz WREG ; decrement | |
457 bra option_inc_uint8 ; type 3: UINT8 as meters or feet | |
458 return ; unknown, do nothing | |
0 | 459 |
634 | 460 |
461 ;----------------------------------------------------------------------------- | |
462 ; Helper Function - increment UINT8, wrap-around or stop at option max | |
463 ; | |
631 | 464 option_inc_uint8: |
465 movf INDF1,W ; get option value | |
466 addwf opt_inc,W ; add increment | |
634 | 467 cpfslt opt_max ; option value > max ? |
631 | 468 bra option_inc_uint8_0 ; NO - new option value ok |
634 | 469 movf opt_min,W ; YES - reset to min value by default |
470 btfsc option_stop_at_max ; - shall the option value stop at max? | |
471 movf opt_max,W ; YES - keep at max value | |
604 | 472 option_inc_uint8_0: |
631 | 473 movwf INDF1 ; store new value |
634 | 474 ; do cross-checks with other option values |
604 | 475 option_inc_uint8_1: |
631 | 476 ; now some rather crude hack into this routine to make CCR calibration more convenient: |
477 movlw 0x37 ; serial ID of option CalGasO2 | |
478 cpfseq opt_serial ; editing CalGasO2 right now? | |
608 | 479 bra option_inc_uint8_2 ; NO - check next option |
604 | 480 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR |
481 decfsz WREG,W ; - in CCR mode? | |
482 return ; NO - done | |
483 movlw .26 ; YES - | |
484 cpfseq INDF1 ; - option value = 26 ? | |
485 return ; NO - done | |
486 movlw .95 ; YES - advance it to 95 | |
487 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
|
488 return |
634 | 489 |
608 | 490 option_inc_uint8_2: |
634 | 491 ; check GF low <= GF high |
631 | 492 movlw 0x25 ; serial ID of option opt_GF_low |
493 cpfseq opt_serial ; editing opt_GF_low right now? | |
608 | 494 bra option_inc_uint8_3 ; NO - check next option |
495 movff opt_GF_high,WREG ; get value of associated GF high into WREG | |
496 cpfsgt INDF1 ; GF low > GF high? | |
497 return ; NO - setting ok, done | |
498 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
499 return ; - done | |
634 | 500 |
608 | 501 option_inc_uint8_3: |
634 | 502 ; check GF high >= GF low |
631 | 503 movlw 0x26 ; serial ID of option opt_GF_high |
504 cpfseq opt_serial ; editing opt_GF_high right now? | |
608 | 505 bra option_inc_uint8_4 ; NO - check next option |
506 movff opt_GF_low,WREG ; get value of associated GF low into WREG | |
507 cpfslt INDF1 ; GF high < GF low? | |
508 return ; NO - setting ok, done | |
509 movwf INDF1 ; YES - rise GF high to GF low | |
510 return ; - done | |
634 | 511 |
608 | 512 option_inc_uint8_4: |
634 | 513 ; check aGF low <= aGF high |
631 | 514 movlw 0x27 ; serial ID of option opt_aGF_low |
515 cpfseq opt_serial ; editing opt_aGF_low right now? | |
608 | 516 bra option_inc_uint8_5 ; NO - check next option |
517 movff opt_aGF_high,WREG ; get value of associated GF high into WREG | |
518 cpfsgt INDF1 ; GF low > GF high? | |
519 return ; NO - setting ok, done | |
520 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
521 return ; - done | |
634 | 522 |
608 | 523 option_inc_uint8_5: |
634 | 524 ; check aGF high >= aGF low |
631 | 525 movlw 0x28 ; serial ID of option opt_aGF_high |
526 cpfseq opt_serial ; editing opt_aGF_high right now? | |
608 | 527 bra option_inc_uint8_6 ; NO - check next option |
528 movff opt_aGF_low,WREG ; get value of associated GF low into WREG | |
529 cpfslt INDF1 ; GF high < GF low? | |
530 return ; NO - setting ok, done | |
531 movwf INDF1 ; YES - rise GF high to GF low | |
532 return ; - done | |
634 | 533 |
608 | 534 option_inc_uint8_6: |
634 | 535 ; progressive increment for char_I_SAC_work |
536 movlw 0x3C ; serial ID of option char_I_SAC_work | |
537 cpfseq opt_serial ; editing char_I_SAC_work right now? | |
538 bra option_inc_uint8_7 ; NO - check next option | |
539 movlw .40 ; YES - set threshold for incrementing in steps of 2 | |
540 cpfsgt INDF1 ; - option value > threshold ? | |
541 return ; NO - done | |
542 incf INDF1,F ; YES - increment one more time | |
543 return ; - done | |
544 | |
545 option_inc_uint8_7: | |
546 IFDEF _helium | |
547 ; check O2% + He% <= 100% | |
548 movlw 0xFA ; serial ID of O2% options | |
549 cpfseq opt_serial ; editing a O2% right now? | |
550 bra option_inc_uint8_7a ; NO - check for He% | |
551 movlw .2*NUM_GAS ; YES - load offset between O2% and He% for gas/dil 1-5 | |
552 btfsc opt_eeprom_bank,7 ; - volatile option? | |
553 movlw .1 ; YES - load offset between O2% and He% for gas 6 | |
554 bra option_inc_uint8_7b ; continue with common part | |
555 option_inc_uint8_7a: | |
556 movlw 0xFB ; serial ID of He% options | |
557 cpfseq opt_serial ; editing a He% right now? | |
558 bra option_inc_uint8_8 ; NO - check next option | |
559 movlw -.2*NUM_GAS ; YES - load offset between He% and O2% for gas/dil 1-5 | |
560 btfsc opt_eeprom_bank,7 ; - volatile option? | |
561 movlw -.1 ; YES - load offset between He% and O2% for gas 6 | |
562 option_inc_uint8_7b: | |
563 movff PLUSW1,hi ; - copy complementing gas % to hi | |
564 movf INDF1,W ; - copy primary gas % to WREG | |
565 addwf hi,F ; - hi = O2% + He% | |
566 movlw .101 ; - load max allowed sum + 1 | |
567 cpfslt hi ; - O2% + He% < 101 ? | |
568 decf INDF1,F ; NO - decrement primary gas% again | |
569 ENDIF ; _helium | |
570 | |
571 option_inc_uint8_8 | |
572 ; add more cross-checks with other option values here | |
608 | 573 return ; all done |
574 | |
0 | 575 |
634 | 576 ;----------------------------------------------------------------------------- |
577 ; Helper Function - increment ENUM, will wrap-around on exceeding option max | |
578 ; | |
631 | 579 option_inc_enum8: |
634 | 580 incf INDF1,W ; get incremented option value |
581 cpfslt opt_max ; option value > max? | |
582 bra option_inc_enum8_0 ; NO - new option value ok | |
583 clrf WREG ; YES - reset to 1st option value | |
584 option_inc_enum8_0: | |
585 movwf INDF1 ; store new value | |
586 ; do cross-checks with other option values | |
604 | 587 option_inc_enum8_1: |
623 | 588 IFDEF _ccr_pscr |
631 | 589 ; now some rather crude hack into this routine to unify CCR & pSCR mode setting |
590 movlw 0x1F ; serial ID of option oCCRMode | |
591 cpfseq opt_serial ; editing oCCRMode right now? | |
604 | 592 bra option_inc_enum8_2 ; NO - check next option |
623 | 593 IFDEF _external_sensor |
634 | 594 btfsc ext_input_s8_ana ; YES - S8/analog input available? |
604 | 595 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed |
634 | 596 btfsc ext_input_optical ; - optical interface available? |
604 | 597 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed |
623 | 598 ENDIF ; _external_sensor |
604 | 599 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP) |
600 xorlw .1 ; - in sensor mode? | |
601 bnz option_inc_enum8_1a ; NO - continue with next check | |
602 incf INDF1,F ; YES - advance option value to AutoSP | |
603 option_inc_enum8_1a: | |
604 movff opt_dive_mode,WREG ; get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
605 xorlw .4 ; in pSCR mode? | |
606 bnz option_inc_enum8_1_exit ; NO - done | |
607 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP) | |
608 option_inc_enum8_1_exit: | |
609 return ; done | |
623 | 610 ENDIF ; _ccr_pscr |
631 | 611 |
604 | 612 option_inc_enum8_2: |
631 | 613 IFDEF _gas_contingency |
614 ; now some rather crude hack to switch off contingency mode if gas needs calculation is switched off | |
615 movlw 0x5A ; serial ID of option opt_calc_gasvolume | |
616 cpfseq opt_serial ; editing opt_calc_gasvolume right now? | |
617 bra option_inc_enum8_3 ; NO - check next option | |
618 movf INDF1,W ; YES - get option value | |
634 | 619 ;xorlw .0 ; - option value = off ? |
631 | 620 bnz option_inc_enum8_2_exit ; NO - done |
621 clrf WREG ; YES - force contingency to be off, too | |
622 movff WREG,opt_gas_contingency_dive ; - ... | |
623 option_inc_enum8_2_exit: | |
624 return | |
625 ENDIF ; _gas_contingency | |
626 | |
604 | 627 option_inc_enum8_3: |
631 | 628 ; now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode |
629 movlw 0x20 ; serial ID of option opt_dive_mode | |
630 cpfseq opt_serial ; editing opt_dive_mode right now? | |
604 | 631 bra option_inc_enum8_4 ; NO - check next option |
623 | 632 movf INDF1,W ; YES - get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR |
633 xorlw .1 ; in CCR mode? | |
634 bnz option_inc_enum8_3a ; NO - in some other mode | |
635 IFNDEF _ccr_pscr | |
636 incf INDF1,f ; YES - no CCR mode compiled in, advance to gauge mode | |
628 | 637 bra option_inc_enum8_3a ; - check if gauge mode is available |
623 | 638 ENDIF ; _ccr_pscr |
639 IFDEF _rx_functions | |
640 global option_cleanup_oTrMode_CCR ; embedded clean-up entry-point | |
604 | 641 option_cleanup_oTrMode_CCR: ; entry point from cleanup during restart |
623 | 642 movff opt_TR_mode,WREG ; get TR mode |
643 xorlw .2 ; mode = 2 (ind.double)? | |
644 bnz option_inc_enum8_3_exit ; NO - done | |
645 bra option_inc_enum8_3_reset ; YES - revert mode to 1 (on) | |
646 ENDIF ; _rx_functions | |
604 | 647 option_inc_enum8_3a: ; any mode other than CCR |
628 | 648 IFNDEF _gauge_mode |
649 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
650 xorlw .2 ; in Gauge mode? | |
651 bnz option_inc_enum8_3b ; NO - in some other mode | |
652 incf INDF1,f ; YES - no Gauge mode compiled in, advance to Apnea mode | |
653 bra option_inc_enum8_3_exit ; - done (Apnea mode is always available) | |
654 ENDIF ; _gauge_mode | |
655 option_inc_enum8_3b: | |
623 | 656 IFNDEF _ccr_pscr |
657 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
658 xorlw .4 ; in pSCR mode? | |
628 | 659 bnz option_inc_enum8_3c ; NO - in some other mode |
623 | 660 clrf INDF1 ; YES - no pSCR mode compiled in, advance to 0 "OC" |
661 bra option_inc_enum8_3_exit ; - done | |
662 ENDIF ; _ccr_pscr | |
628 | 663 option_inc_enum8_3c: |
623 | 664 global option_cleanup_oTrMode_no_CCR ; embedded clean-up entry-point |
604 | 665 option_cleanup_oTrMode_no_CCR: ; entry point from cleanup during restart |
666 movff opt_TR_mode,WREG ; get TR mode | |
667 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
668 bnz option_inc_enum8_3_exit ; NO - done | |
669 option_inc_enum8_3_reset: ; YES - revert to mode 1 (on) | |
670 movlw .1 ; load coding of mode "on" | |
671 movff WREG,opt_TR_mode ; write to option | |
672 option_inc_enum8_3_exit: | |
673 return ; done | |
628 | 674 |
604 | 675 option_inc_enum8_4: |
623 | 676 IFDEF _rx_functions |
631 | 677 ; now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode |
678 movlw 0x7E ; serial ID of option opt_TR_mode | |
679 cpfseq opt_serial ; editing opt_TR_mode right now? | |
604 | 680 bra option_inc_enum8_5 ; NO - check next option |
681 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
682 decfsz WREG,W ; dive mode = 1 CCR? | |
683 bra option_inc_enum8_4a ; NO - in any other mode | |
684 movf INDF1,W ; YES - get option value (TR mode) | |
685 xorlw .2 ; - mode = 2 (ind.double)? | |
686 bnz option_inc_enum8_4_exit ; NO - done | |
687 incf INDF1,F ; YES - advance option value to 3 (CCR Dil+O2) | |
688 bra option_inc_enum8_4_exit ; - done | |
689 option_inc_enum8_4a: ; any mode other than CCR | |
690 movf INDF1,W ; get option value (TR mode) | |
691 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
692 bnz option_inc_enum8_4_exit ; NO - done | |
693 clrf INDF1 ; YES - advance option value to 0 "off" | |
694 option_inc_enum8_4_exit: | |
695 return ; done | |
623 | 696 ENDIF ; _rx_functions |
631 | 697 |
604 | 698 option_inc_enum8_5: |
631 | 699 IFDEF _gas_contingency |
700 ; now some rather crude hack to keep contingency mode switched off if gas needs calculation is switched off | |
701 movlw 0x91 ; serial ID of option opt_gas_contingency_dive | |
702 cpfseq opt_serial ; editing opt_gas_contingency_dive right now? | |
703 bra option_inc_enum8_6 ; NO - check next option | |
704 movff opt_calc_gasvolume,WREG ; YES - get current setting of gas needs calculation | |
705 tstfsz WREG ; - gas needs calculation switched off? | |
706 return ; NO - done, opt_gas_contingency_dive may be switched on | |
707 clrf INDF1 ; YES - force opt_gas_contingency_dive to off | |
708 return ; - done | |
709 ENDIF ; _gas_contingency | |
710 | |
711 option_inc_enum8_6: | |
634 | 712 ; add more cross-checks with other option values here |
582 | 713 return |
0 | 714 |
604 | 715 |
634 | 716 ;----------------------------------------------------------------------------- |
717 ; Decrement an Option Value based on Type and min/max Boundary | |
718 ; | |
719 ; INPUT: FSR0 = option handle | |
720 ; OUTPUT: decremented option value | |
721 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
722 ; | |
723 global option_dec | |
724 option_dec: | |
725 ; read type, default and register from table | |
726 rcall option_read_definition | |
727 | |
728 btfss opt_eeprom_bank,7 ; volatile option? | |
729 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
730 | |
731 ; switch on type | |
732 movf opt_type,W ; get option type | |
733 bz option_dec_uint8 ; type 0: UINT8 | |
734 dcfsnz WREG ; decrement | |
735 bra option_dec_enum8 ; type 1: ENUM | |
736 dcfsnz WREG ; decrement | |
737 return ; type 2: STRING - no dec function defined | |
738 dcfsnz WREG ; decrement | |
739 bra option_dec_uint8 ; type 3: UINT8 as meters or feet | |
740 return ; unknown, do nothing | |
741 | |
742 | |
743 ;----------------------------------------------------------------------------- | |
744 ; Helper Function - decrement UINT8, will stop on reaching option min | |
745 ; | |
746 option_dec_uint8: | |
747 movf INDF1,W ; get option value | |
748 bsf STATUS,C ; set carry (= clear borrow) | |
749 subfwb opt_inc,W ; subtract increment | |
750 bnc option_dec_uint8_reset ; under-run? -> reset | |
751 cpfsgt opt_min ; option value < min ? | |
752 bra option_dec_uint8_0 ; NO - new option value ok | |
753 option_dec_uint8_reset: | |
754 movf opt_min,W ; YES - reset to min value | |
755 option_dec_uint8_0: | |
756 movwf INDF1 ; store new value | |
757 ; add cross-checks with other option values here | |
758 return ; done | |
759 | |
760 | |
761 ;----------------------------------------------------------------------------- | |
762 ; Helper Function - decrement ENUM, will stop on reaching first option value | |
763 ; | |
764 option_dec_enum8: | |
765 tstfsz INDF1 ; option value = 0 ? | |
766 decf INDF1,F ; NO - decrement value | |
767 option_dec_enum8_0: | |
768 ; add cross-checks with other option values here | |
769 return ; done | |
770 | |
771 | |
772 ;----------------------------------------------------------------------------- | |
773 ; Draw an Option Value | |
774 ; | |
775 global option_draw | |
776 option_draw: | |
777 ; read type, default and register from table | |
778 rcall option_read_definition | |
779 | |
780 ; switch on type | |
781 movf opt_type,W ; get option type | |
782 bz option_draw_uint8 ; type0 = INT8 | |
783 dcfsnz WREG | |
784 bra option_draw_enum8 ; type1 = ENUM | |
785 dcfsnz WREG | |
786 bra option_draw_string ; type2 = string | |
787 dcfsnz WREG | |
788 bra option_draw_uint8_depth ; type3 = INT8 as meters or feet | |
789 return ; unknown, do nothing | |
790 | |
791 | |
792 ;----------------------------------------------------------------------------- | |
793 ; Helper Function - draw a String | |
794 ; | |
795 option_draw_string: | |
796 movff POSTINC1,POSTINC2 ; copy one character | |
797 decfsz opt_max ; decrement remaining string length, became zero? | |
798 bra option_draw_string ; NO - loop | |
799 return ; YES - done | |
800 | |
801 | |
802 ;----------------------------------------------------------------------------- | |
803 ; Helper Function - draw an INT with automatic display in meters or feet | |
804 ; | |
805 option_draw_uint8_depth: | |
806 TSTOSS opt_units ; using metric units (0=m, 1=ft)? | |
807 bra option_draw_uint8 ; YES - handle with standard output | |
808 movff INDF1,lo ; NO - imperial, get value to lo | |
809 call convert_meter_to_feet ; - convert value in lo from meter to feet | |
810 ; bsf leftbind ; - print with left alignment | |
811 output_999 ; - print depth (0-999) | |
812 STRCAT_TEXT tFeets ; - append unit and dump to screen | |
813 bra option_draw_uint8_common ; - continue with common part | |
814 | |
815 | |
816 ;----------------------------------------------------------------------------- | |
817 ; Helper Function - draw an INT | |
818 ; | |
819 option_draw_uint8: | |
820 movff INDF1,lo ; get option value | |
821 | |
822 movlw .99 ; load a 99 | |
823 cpfsgt opt_max ; max value > 99 ? | |
824 bsf hide_digit3 ; NO - do not show digit 3 | |
825 movlw .9 ; load a 9 | |
826 cpfsgt opt_max ; max value > 9 ? | |
827 bsf hide_digit2 ; NO - do not show digit 2 | |
828 | |
829 output_256 ; print option value | |
830 | |
831 movf opt_unit+0,W ; is there a unit to append? | |
832 iorwf opt_unit+1,W ; ... | |
833 bz option_draw_uint8_common ; NO - continue with common part | |
834 movff opt_unit+0,FSR1L ; YES - pointer to multi-lingual unit text | |
835 movff opt_unit+1,FSR1H ; - ... | |
836 call strcat_text_FSR ; - append unit text to buffer | |
837 ;bra option_draw_uint8_common ; - continue with common part | |
838 | |
839 | |
840 ;----------------------------------------------------------------------------- | |
841 ; Helper Function - common Part for INT | |
842 ; | |
843 option_draw_uint8_common: | |
844 movf opt_default,W ; get default value | |
845 cpfseq lo ; compare with current value, equal? | |
846 bra option_draw_uint8_common_1 ; NO - not default, add * | |
847 return ; YES - default, done | |
848 option_draw_uint8_common_1: | |
849 PUTC "*" ; print "*" | |
850 return ; done | |
851 | |
852 | |
853 ;----------------------------------------------------------------------------- | |
854 ; Helper Function - draw an ENUM (set of translated strings) | |
855 ; | |
856 option_draw_enum8: | |
857 movf INDF1,W ; copy option value to WREG | |
858 movwf lo ; memorize option value, too | |
859 cpfslt opt_max ; option value > maximum permissible value ? | |
860 bra option_draw_enum8_0 ; NO - option value allowed | |
861 clrf WREG ; YES - to avoid printing rubbish, use first ENUM item instead | |
862 option_draw_enum8_0: | |
863 addwf WREG ; current value *= 2 | |
864 addwf opt_inc,W ; base text + 2 * current value | |
865 movwf FSR1L ; load FSR1 | |
866 movlw .0 ; propagate carry... | |
867 addwfc opt_min,W ; ... | |
868 movwf FSR1H ; ...into FSR1 | |
869 call strcat_text_FSR ; print text | |
870 movf opt_default,W ; get default value | |
871 cpfseq lo ; compare with memorized current value, equal? | |
872 bra option_draw_enum8_1 ; NO - not default, add * | |
873 return ; YES - default, done | |
874 option_draw_enum8_1: | |
875 PUTC "*" ; print "*" | |
876 return ; done | |
877 | |
878 | |
879 ;============================================================================= | |
880 options2 CODE | |
881 ;============================================================================= | |
882 | |
883 | |
884 ;----------------------------------------------------------------------------- | |
885 ; Check and Resolve some Interdependencies among Option Values | |
886 ; | |
887 option_crosschecks: | |
888 bsf is_diluent_menu ; setup checking diluents | |
889 call gaslist_cleanup_list ; check and correct multiple or none First diluents | |
890 | |
891 bcf is_diluent_menu ; setup checking gases | |
892 call gaslist_cleanup_list ; check and correct multiple or none First gases | |
893 | |
894 rcall option_cleanup_GF ; check and correct GFlow <= GFhigh | |
895 | |
628 | 896 IFNDEF _gauge_mode |
634 | 897 rcall option_cleanup_gauge ; check and correct gauge mode |
898 ENDIF ; _gauge_mode | |
628 | 899 |
623 | 900 IFDEF _ccr_pscr |
634 | 901 rcall option_cleanup_oCCRMode ; check and correct CCR / pSCR mode |
623 | 902 ENDIF ; _ccr_pscr |
903 | |
634 | 904 IFDEF _helium |
905 rcall option_cleanup_sum_O2_He ; check and correct O2% + He% <= 100 +++ | |
906 ENDIF ; _helium | |
604 | 907 |
634 | 908 return ; done |
909 | |
910 | |
911 ;----------------------------------------------------------------------------- | |
912 ; Check and correct GFs so that GF_high >= GF_low | |
913 ; | |
608 | 914 option_cleanup_GF: |
915 ; cleanup normal GF | |
916 movff opt_GF_high,WREG ; copy normal GF high to WREG | |
623 | 917 movff opt_GF_low,mpr ; copy normal GF low to mpr |
918 cpfsgt mpr ; GF low > GF high ? | |
608 | 919 bra option_cleanup_GF_2 ; NO - option ok, check next option |
623 | 920 movwf mpr ; YES - copy GF high to mpr |
608 | 921 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 922 cpfsgt mpr ; - mpr > 100 ? |
608 | 923 bra option_cleanup_GF_1 ; NO - correct GF low to GF high |
623 | 924 movwf mpr ; YES - correct GF low to 100% |
608 | 925 option_cleanup_GF_1: |
623 | 926 movff mpr,opt_GF_low ; store corrected GF low |
634 | 927 bsf option_changed ; flag that EEPROM needs to be updated |
608 | 928 option_cleanup_GF_2: |
929 ; cleanup alternative GF | |
930 movff opt_aGF_high,WREG ; copy alternative GF high to WREG | |
623 | 931 movff opt_aGF_low,mpr ; copy alternative GF low to mpr |
932 cpfsgt mpr ; GF low > GF high ? | |
608 | 933 bra option_cleanup_GF_4 ; NO - option ok, check next option |
623 | 934 movwf mpr ; YES - copy GF high to mpr |
608 | 935 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 936 cpfsgt mpr ; - mpr > 100 ? |
608 | 937 bra option_cleanup_GF_3 ; NO - correct GF low to GF high |
623 | 938 movwf mpr ; YES - correct GF low to 100% |
608 | 939 option_cleanup_GF_3: |
623 | 940 movff mpr,opt_aGF_low ; store corrected GF low |
634 | 941 bsf option_changed ; flag that EEPROM needs to be updated |
608 | 942 option_cleanup_GF_4: |
943 return ; done | |
944 | |
634 | 945 ;----------------------------------------------------------------------------- |
946 ; Check and correct Dive Mode if Gauge Mode is not allowed | |
604 | 947 ; |
634 | 948 IFNDEF _gauge_mode |
949 option_cleanup_gauge: | |
950 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
951 xorlw .2 ; in Gauge mode? | |
952 bnz option_cleanup_gauge_1 ; NO - done | |
953 movff WREG,opt_dive_mode ; YES - setting not allowed, WREG is zero -> reset to OC mode | |
954 bsf option_changed ; - flag that EEPROM needs to be updated | |
955 option_cleanup_gauge_1: | |
604 | 956 return ; done |
634 | 957 ENDIF ; _gauge_mode |
0 | 958 |
959 | |
634 | 960 ;----------------------------------------------------------------------------- |
961 ; Check and correct AutoSP and external Sensor Settings dependent on Modes | |
962 ; | |
963 IFDEF _ccr_pscr | |
964 global option_cleanup_oCCRMode | |
965 global option_cleanup_oCCRMode_pSCR | |
966 global option_cleanup_oCCRMode_CCR | |
967 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 | |
968 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
969 xorlw .4 ; in pSCR mode? | |
970 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC | |
971 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode | |
972 banksel opt_ccr_mode ; YES - select options bank | |
973 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) | |
974 banksel common ; - back to bank common | |
975 bsf option_changed ; - flag that EEPROM needs to be updated | |
976 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode | |
977 IFDEF _external_sensor | |
978 btfsc ext_input_s8_ana ; S8/analog interface available? | |
979 return ; YES - setting 'sensor' allowed | |
980 btfsc ext_input_optical ; does hosting OSTC have an optical interface? | |
981 return ; YES - setting 'sensor' allowed | |
982 ENDIF ; _external_sensor | |
983 movff opt_ccr_mode,WREG ; NO to both - get CCR mode | |
984 xorlw .1 ; - coding for sensor | |
985 tstfsz WREG ; - CCR mode = sensor? | |
986 return ; NO - setting allowed | |
987 banksel opt_ccr_mode ; YES - setting not allowed, select options bank | |
988 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) | |
989 banksel common ; - back to bank common | |
990 bsf option_changed ; - flag that EEPROM needs to be updated | |
991 return ; - done | |
992 ENDIF ; _ccr_pscr | |
993 | |
994 | |
995 ;----------------------------------------------------------------------------- | |
996 ; Check and correct that O2% + He% <= 100% | |
997 ; | |
998 IFDEF _helium | |
999 option_cleanup_sum_O2_He: | |
1000 lfsr FSR0,opt_gas_He_ratio-1 ; load (base address of He% array - 1) because of PREINC | |
1001 movlw 2*NUM_GAS ; load loop counter | |
1002 movwf lo ; ... | |
1003 option_cleanup_sum_loop: | |
1004 movff PREINC1,up ; get He ratio | |
1005 movlw -2*NUM_GAS ; address O2 ratio | |
1006 movff PLUSW0,hi ; get O2 ratio | |
1007 movlw .100 ; load WREG with 100% | |
1008 bsf STATUS,C ; set carry = clear borrow | |
1009 subfwb hi,W ; subtract O2% from WREG | |
1010 subfwb up,W ; subtract He% from WREG | |
1011 btfsc STATUS,C ; result negative? | |
1012 bra option_cleanup_sum_loop_1 ; NO - sum valid | |
1013 clrf INDF1 ; YES - heal by setting He% to zero | |
1014 bsf option_changed ; flag that EEPROM needs to be updated | |
1015 option_cleanup_sum_loop_1: | |
1016 decfsz lo ; decrement loop counter, all done? | |
1017 bra option_cleanup_sum_loop ; NO - loop | |
1018 return ; YES - done | |
1019 ENDIF ; _helium | |
1020 | |
628 | 1021 |
623 | 1022 ;----------------------------------------------------------------------------- |
0 | 1023 |
623 | 1024 END |