Mercurial > public > hwos_code
annotate src/options.asm @ 656:8af5aefbcdaf default tip
Update to 3.31 beta
| author | heinrichsweikamp |
|---|---|
| date | Thu, 27 Nov 2025 18:32:58 +0100 |
| parents | 75e90cd0c2c3 |
| children |
| 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 ; | |
| 654 | 7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved. |
| 0 | 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 |
| 656 | 599 IFDEF _external_sensor_eccr |
| 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 |
| 656 | 604 btfsc ext_s8_full_digital ; are we in external S8 full digital mode? |
| 605 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed | |
| 606 ENDIF ; _external_sensor_eccr | |
| 604 | 607 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP) |
| 608 xorlw .1 ; - in sensor mode? | |
| 609 bnz option_inc_enum8_1a ; NO - continue with next check | |
| 610 incf INDF1,F ; YES - advance option value to AutoSP | |
| 611 option_inc_enum8_1a: | |
| 612 movff opt_dive_mode,WREG ; get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
| 613 xorlw .4 ; in pSCR mode? | |
| 614 bnz option_inc_enum8_1_exit ; NO - done | |
| 615 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP) | |
| 616 option_inc_enum8_1_exit: | |
| 617 return ; done | |
| 623 | 618 ENDIF ; _ccr_pscr |
| 631 | 619 |
| 604 | 620 option_inc_enum8_2: |
| 631 | 621 IFDEF _gas_contingency |
| 622 ; now some rather crude hack to switch off contingency mode if gas needs calculation is switched off | |
| 623 movlw 0x5A ; serial ID of option opt_calc_gasvolume | |
| 624 cpfseq opt_serial ; editing opt_calc_gasvolume right now? | |
| 625 bra option_inc_enum8_3 ; NO - check next option | |
| 626 movf INDF1,W ; YES - get option value | |
| 634 | 627 ;xorlw .0 ; - option value = off ? |
| 631 | 628 bnz option_inc_enum8_2_exit ; NO - done |
| 629 clrf WREG ; YES - force contingency to be off, too | |
| 630 movff WREG,opt_gas_contingency_dive ; - ... | |
| 631 option_inc_enum8_2_exit: | |
| 632 return | |
| 633 ENDIF ; _gas_contingency | |
| 634 | |
| 604 | 635 option_inc_enum8_3: |
| 631 | 636 ; now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode |
| 637 movlw 0x20 ; serial ID of option opt_dive_mode | |
| 638 cpfseq opt_serial ; editing opt_dive_mode right now? | |
| 604 | 639 bra option_inc_enum8_4 ; NO - check next option |
| 623 | 640 movf INDF1,W ; YES - get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR |
| 641 xorlw .1 ; in CCR mode? | |
| 642 bnz option_inc_enum8_3a ; NO - in some other mode | |
| 643 IFNDEF _ccr_pscr | |
| 644 incf INDF1,f ; YES - no CCR mode compiled in, advance to gauge mode | |
| 628 | 645 bra option_inc_enum8_3a ; - check if gauge mode is available |
| 623 | 646 ENDIF ; _ccr_pscr |
| 647 IFDEF _rx_functions | |
| 648 global option_cleanup_oTrMode_CCR ; embedded clean-up entry-point | |
| 604 | 649 option_cleanup_oTrMode_CCR: ; entry point from cleanup during restart |
| 623 | 650 movff opt_TR_mode,WREG ; get TR mode |
| 651 xorlw .2 ; mode = 2 (ind.double)? | |
| 652 bnz option_inc_enum8_3_exit ; NO - done | |
| 653 bra option_inc_enum8_3_reset ; YES - revert mode to 1 (on) | |
| 654 ENDIF ; _rx_functions | |
| 604 | 655 option_inc_enum8_3a: ; any mode other than CCR |
| 628 | 656 IFNDEF _gauge_mode |
| 657 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
| 658 xorlw .2 ; in Gauge mode? | |
| 659 bnz option_inc_enum8_3b ; NO - in some other mode | |
| 660 incf INDF1,f ; YES - no Gauge mode compiled in, advance to Apnea mode | |
| 661 bra option_inc_enum8_3_exit ; - done (Apnea mode is always available) | |
| 662 ENDIF ; _gauge_mode | |
| 663 option_inc_enum8_3b: | |
| 623 | 664 IFNDEF _ccr_pscr |
| 665 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
| 666 xorlw .4 ; in pSCR mode? | |
| 628 | 667 bnz option_inc_enum8_3c ; NO - in some other mode |
| 623 | 668 clrf INDF1 ; YES - no pSCR mode compiled in, advance to 0 "OC" |
| 669 bra option_inc_enum8_3_exit ; - done | |
| 670 ENDIF ; _ccr_pscr | |
| 628 | 671 option_inc_enum8_3c: |
| 623 | 672 global option_cleanup_oTrMode_no_CCR ; embedded clean-up entry-point |
| 604 | 673 option_cleanup_oTrMode_no_CCR: ; entry point from cleanup during restart |
| 674 movff opt_TR_mode,WREG ; get TR mode | |
| 675 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
| 676 bnz option_inc_enum8_3_exit ; NO - done | |
| 677 option_inc_enum8_3_reset: ; YES - revert to mode 1 (on) | |
| 678 movlw .1 ; load coding of mode "on" | |
| 679 movff WREG,opt_TR_mode ; write to option | |
| 680 option_inc_enum8_3_exit: | |
| 681 return ; done | |
| 628 | 682 |
| 604 | 683 option_inc_enum8_4: |
| 623 | 684 IFDEF _rx_functions |
| 631 | 685 ; now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode |
| 686 movlw 0x7E ; serial ID of option opt_TR_mode | |
| 687 cpfseq opt_serial ; editing opt_TR_mode right now? | |
| 604 | 688 bra option_inc_enum8_5 ; NO - check next option |
| 689 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
| 690 decfsz WREG,W ; dive mode = 1 CCR? | |
| 691 bra option_inc_enum8_4a ; NO - in any other mode | |
| 692 movf INDF1,W ; YES - get option value (TR mode) | |
| 693 xorlw .2 ; - mode = 2 (ind.double)? | |
| 694 bnz option_inc_enum8_4_exit ; NO - done | |
| 695 incf INDF1,F ; YES - advance option value to 3 (CCR Dil+O2) | |
| 696 bra option_inc_enum8_4_exit ; - done | |
| 697 option_inc_enum8_4a: ; any mode other than CCR | |
| 698 movf INDF1,W ; get option value (TR mode) | |
| 699 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
| 700 bnz option_inc_enum8_4_exit ; NO - done | |
| 701 clrf INDF1 ; YES - advance option value to 0 "off" | |
| 702 option_inc_enum8_4_exit: | |
| 703 return ; done | |
| 623 | 704 ENDIF ; _rx_functions |
| 631 | 705 |
| 604 | 706 option_inc_enum8_5: |
| 631 | 707 IFDEF _gas_contingency |
| 708 ; now some rather crude hack to keep contingency mode switched off if gas needs calculation is switched off | |
| 709 movlw 0x91 ; serial ID of option opt_gas_contingency_dive | |
| 710 cpfseq opt_serial ; editing opt_gas_contingency_dive right now? | |
| 711 bra option_inc_enum8_6 ; NO - check next option | |
| 712 movff opt_calc_gasvolume,WREG ; YES - get current setting of gas needs calculation | |
| 713 tstfsz WREG ; - gas needs calculation switched off? | |
| 714 return ; NO - done, opt_gas_contingency_dive may be switched on | |
| 715 clrf INDF1 ; YES - force opt_gas_contingency_dive to off | |
| 716 return ; - done | |
| 717 ENDIF ; _gas_contingency | |
| 718 | |
| 719 option_inc_enum8_6: | |
| 634 | 720 ; add more cross-checks with other option values here |
| 582 | 721 return |
| 0 | 722 |
| 604 | 723 |
| 634 | 724 ;----------------------------------------------------------------------------- |
| 725 ; Decrement an Option Value based on Type and min/max Boundary | |
| 726 ; | |
| 727 ; INPUT: FSR0 = option handle | |
| 728 ; OUTPUT: decremented option value | |
| 729 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
| 730 ; | |
| 731 global option_dec | |
| 732 option_dec: | |
| 733 ; read type, default and register from table | |
| 734 rcall option_read_definition | |
| 735 | |
| 736 btfss opt_eeprom_bank,7 ; volatile option? | |
| 737 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
| 738 | |
| 739 ; switch on type | |
| 740 movf opt_type,W ; get option type | |
| 741 bz option_dec_uint8 ; type 0: UINT8 | |
| 742 dcfsnz WREG ; decrement | |
| 743 bra option_dec_enum8 ; type 1: ENUM | |
| 744 dcfsnz WREG ; decrement | |
| 745 return ; type 2: STRING - no dec function defined | |
| 746 dcfsnz WREG ; decrement | |
| 747 bra option_dec_uint8 ; type 3: UINT8 as meters or feet | |
| 748 return ; unknown, do nothing | |
| 749 | |
| 750 | |
| 751 ;----------------------------------------------------------------------------- | |
| 752 ; Helper Function - decrement UINT8, will stop on reaching option min | |
| 753 ; | |
| 754 option_dec_uint8: | |
| 755 movf INDF1,W ; get option value | |
| 756 bsf STATUS,C ; set carry (= clear borrow) | |
| 757 subfwb opt_inc,W ; subtract increment | |
| 758 bnc option_dec_uint8_reset ; under-run? -> reset | |
| 759 cpfsgt opt_min ; option value < min ? | |
| 760 bra option_dec_uint8_0 ; NO - new option value ok | |
| 761 option_dec_uint8_reset: | |
| 762 movf opt_min,W ; YES - reset to min value | |
| 763 option_dec_uint8_0: | |
| 764 movwf INDF1 ; store new value | |
| 765 ; add cross-checks with other option values here | |
| 766 return ; done | |
| 767 | |
| 768 | |
| 769 ;----------------------------------------------------------------------------- | |
| 770 ; Helper Function - decrement ENUM, will stop on reaching first option value | |
| 771 ; | |
| 772 option_dec_enum8: | |
| 773 tstfsz INDF1 ; option value = 0 ? | |
| 774 decf INDF1,F ; NO - decrement value | |
| 775 option_dec_enum8_0: | |
| 776 ; add cross-checks with other option values here | |
| 777 return ; done | |
| 778 | |
| 779 | |
| 780 ;----------------------------------------------------------------------------- | |
| 781 ; Draw an Option Value | |
| 782 ; | |
| 783 global option_draw | |
| 784 option_draw: | |
| 785 ; read type, default and register from table | |
| 786 rcall option_read_definition | |
| 787 | |
| 788 ; switch on type | |
| 789 movf opt_type,W ; get option type | |
| 790 bz option_draw_uint8 ; type0 = INT8 | |
| 791 dcfsnz WREG | |
| 792 bra option_draw_enum8 ; type1 = ENUM | |
| 793 dcfsnz WREG | |
| 794 bra option_draw_string ; type2 = string | |
| 795 dcfsnz WREG | |
| 796 bra option_draw_uint8_depth ; type3 = INT8 as meters or feet | |
| 797 return ; unknown, do nothing | |
| 798 | |
| 799 | |
| 800 ;----------------------------------------------------------------------------- | |
| 801 ; Helper Function - draw a String | |
| 802 ; | |
| 803 option_draw_string: | |
| 804 movff POSTINC1,POSTINC2 ; copy one character | |
| 805 decfsz opt_max ; decrement remaining string length, became zero? | |
| 806 bra option_draw_string ; NO - loop | |
| 807 return ; YES - done | |
| 808 | |
| 809 | |
| 810 ;----------------------------------------------------------------------------- | |
| 811 ; Helper Function - draw an INT with automatic display in meters or feet | |
| 812 ; | |
| 813 option_draw_uint8_depth: | |
| 814 TSTOSS opt_units ; using metric units (0=m, 1=ft)? | |
| 815 bra option_draw_uint8 ; YES - handle with standard output | |
| 816 movff INDF1,lo ; NO - imperial, get value to lo | |
| 817 call convert_meter_to_feet ; - convert value in lo from meter to feet | |
| 818 ; bsf leftbind ; - print with left alignment | |
| 819 output_999 ; - print depth (0-999) | |
| 820 STRCAT_TEXT tFeets ; - append unit and dump to screen | |
| 821 bra option_draw_uint8_common ; - continue with common part | |
| 822 | |
| 823 | |
| 824 ;----------------------------------------------------------------------------- | |
| 825 ; Helper Function - draw an INT | |
| 826 ; | |
| 827 option_draw_uint8: | |
| 828 movff INDF1,lo ; get option value | |
| 829 | |
| 830 movlw .99 ; load a 99 | |
| 831 cpfsgt opt_max ; max value > 99 ? | |
| 832 bsf hide_digit3 ; NO - do not show digit 3 | |
| 833 movlw .9 ; load a 9 | |
| 834 cpfsgt opt_max ; max value > 9 ? | |
| 835 bsf hide_digit2 ; NO - do not show digit 2 | |
| 836 | |
| 837 output_256 ; print option value | |
| 838 | |
| 839 movf opt_unit+0,W ; is there a unit to append? | |
| 840 iorwf opt_unit+1,W ; ... | |
| 841 bz option_draw_uint8_common ; NO - continue with common part | |
| 842 movff opt_unit+0,FSR1L ; YES - pointer to multi-lingual unit text | |
| 843 movff opt_unit+1,FSR1H ; - ... | |
| 844 call strcat_text_FSR ; - append unit text to buffer | |
| 845 ;bra option_draw_uint8_common ; - continue with common part | |
| 846 | |
| 847 | |
| 848 ;----------------------------------------------------------------------------- | |
| 849 ; Helper Function - common Part for INT | |
| 850 ; | |
| 851 option_draw_uint8_common: | |
| 852 movf opt_default,W ; get default value | |
| 853 cpfseq lo ; compare with current value, equal? | |
| 854 bra option_draw_uint8_common_1 ; NO - not default, add * | |
| 855 return ; YES - default, done | |
| 856 option_draw_uint8_common_1: | |
| 857 PUTC "*" ; print "*" | |
| 858 return ; done | |
| 859 | |
| 860 | |
| 861 ;----------------------------------------------------------------------------- | |
| 862 ; Helper Function - draw an ENUM (set of translated strings) | |
| 863 ; | |
| 864 option_draw_enum8: | |
| 865 movf INDF1,W ; copy option value to WREG | |
| 866 movwf lo ; memorize option value, too | |
| 867 cpfslt opt_max ; option value > maximum permissible value ? | |
| 868 bra option_draw_enum8_0 ; NO - option value allowed | |
| 869 clrf WREG ; YES - to avoid printing rubbish, use first ENUM item instead | |
| 870 option_draw_enum8_0: | |
| 871 addwf WREG ; current value *= 2 | |
| 872 addwf opt_inc,W ; base text + 2 * current value | |
| 873 movwf FSR1L ; load FSR1 | |
| 874 movlw .0 ; propagate carry... | |
| 875 addwfc opt_min,W ; ... | |
| 876 movwf FSR1H ; ...into FSR1 | |
| 877 call strcat_text_FSR ; print text | |
| 878 movf opt_default,W ; get default value | |
| 879 cpfseq lo ; compare with memorized current value, equal? | |
| 880 bra option_draw_enum8_1 ; NO - not default, add * | |
| 881 return ; YES - default, done | |
| 882 option_draw_enum8_1: | |
| 883 PUTC "*" ; print "*" | |
| 884 return ; done | |
| 885 | |
| 886 | |
| 887 ;============================================================================= | |
| 888 options2 CODE | |
| 889 ;============================================================================= | |
| 890 | |
| 891 | |
| 892 ;----------------------------------------------------------------------------- | |
| 893 ; Check and Resolve some Interdependencies among Option Values | |
| 894 ; | |
| 895 option_crosschecks: | |
| 896 bsf is_diluent_menu ; setup checking diluents | |
| 897 call gaslist_cleanup_list ; check and correct multiple or none First diluents | |
| 898 | |
| 899 bcf is_diluent_menu ; setup checking gases | |
| 900 call gaslist_cleanup_list ; check and correct multiple or none First gases | |
| 901 | |
| 902 rcall option_cleanup_GF ; check and correct GFlow <= GFhigh | |
| 903 | |
| 628 | 904 IFNDEF _gauge_mode |
| 634 | 905 rcall option_cleanup_gauge ; check and correct gauge mode |
| 906 ENDIF ; _gauge_mode | |
| 628 | 907 |
| 623 | 908 IFDEF _ccr_pscr |
| 634 | 909 rcall option_cleanup_oCCRMode ; check and correct CCR / pSCR mode |
| 623 | 910 ENDIF ; _ccr_pscr |
| 911 | |
| 634 | 912 IFDEF _helium |
| 913 rcall option_cleanup_sum_O2_He ; check and correct O2% + He% <= 100 +++ | |
| 914 ENDIF ; _helium | |
| 604 | 915 |
| 634 | 916 return ; done |
| 917 | |
| 918 | |
| 919 ;----------------------------------------------------------------------------- | |
| 920 ; Check and correct GFs so that GF_high >= GF_low | |
| 921 ; | |
| 608 | 922 option_cleanup_GF: |
| 923 ; cleanup normal GF | |
| 924 movff opt_GF_high,WREG ; copy normal GF high to WREG | |
| 623 | 925 movff opt_GF_low,mpr ; copy normal GF low to mpr |
| 926 cpfsgt mpr ; GF low > GF high ? | |
| 608 | 927 bra option_cleanup_GF_2 ; NO - option ok, check next option |
| 623 | 928 movwf mpr ; YES - copy GF high to mpr |
| 608 | 929 movlw .100 ; - load GF low limit of 100% into WREG |
| 623 | 930 cpfsgt mpr ; - mpr > 100 ? |
| 608 | 931 bra option_cleanup_GF_1 ; NO - correct GF low to GF high |
| 623 | 932 movwf mpr ; YES - correct GF low to 100% |
| 608 | 933 option_cleanup_GF_1: |
| 623 | 934 movff mpr,opt_GF_low ; store corrected GF low |
| 634 | 935 bsf option_changed ; flag that EEPROM needs to be updated |
| 608 | 936 option_cleanup_GF_2: |
| 937 ; cleanup alternative GF | |
| 938 movff opt_aGF_high,WREG ; copy alternative GF high to WREG | |
| 623 | 939 movff opt_aGF_low,mpr ; copy alternative GF low to mpr |
| 940 cpfsgt mpr ; GF low > GF high ? | |
| 608 | 941 bra option_cleanup_GF_4 ; NO - option ok, check next option |
| 623 | 942 movwf mpr ; YES - copy GF high to mpr |
| 608 | 943 movlw .100 ; - load GF low limit of 100% into WREG |
| 623 | 944 cpfsgt mpr ; - mpr > 100 ? |
| 608 | 945 bra option_cleanup_GF_3 ; NO - correct GF low to GF high |
| 623 | 946 movwf mpr ; YES - correct GF low to 100% |
| 608 | 947 option_cleanup_GF_3: |
| 623 | 948 movff mpr,opt_aGF_low ; store corrected GF low |
| 634 | 949 bsf option_changed ; flag that EEPROM needs to be updated |
| 608 | 950 option_cleanup_GF_4: |
| 951 return ; done | |
| 952 | |
| 634 | 953 ;----------------------------------------------------------------------------- |
| 954 ; Check and correct Dive Mode if Gauge Mode is not allowed | |
| 604 | 955 ; |
| 634 | 956 IFNDEF _gauge_mode |
| 957 option_cleanup_gauge: | |
| 958 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
| 959 xorlw .2 ; in Gauge mode? | |
| 960 bnz option_cleanup_gauge_1 ; NO - done | |
| 961 movff WREG,opt_dive_mode ; YES - setting not allowed, WREG is zero -> reset to OC mode | |
| 962 bsf option_changed ; - flag that EEPROM needs to be updated | |
| 963 option_cleanup_gauge_1: | |
| 604 | 964 return ; done |
| 634 | 965 ENDIF ; _gauge_mode |
| 0 | 966 |
| 967 | |
| 634 | 968 ;----------------------------------------------------------------------------- |
| 969 ; Check and correct AutoSP and external Sensor Settings dependent on Modes | |
| 970 ; | |
| 971 IFDEF _ccr_pscr | |
| 972 global option_cleanup_oCCRMode | |
| 973 global option_cleanup_oCCRMode_pSCR | |
| 974 global option_cleanup_oCCRMode_CCR | |
| 975 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 | |
| 976 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
| 977 xorlw .4 ; in pSCR mode? | |
| 978 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC | |
| 979 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode | |
| 980 banksel opt_ccr_mode ; YES - select options bank | |
| 981 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) | |
| 982 banksel common ; - back to bank common | |
| 983 bsf option_changed ; - flag that EEPROM needs to be updated | |
| 984 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode | |
| 656 | 985 IFDEF _external_sensor_eccr |
| 634 | 986 btfsc ext_input_s8_ana ; S8/analog interface available? |
| 987 return ; YES - setting 'sensor' allowed | |
| 988 btfsc ext_input_optical ; does hosting OSTC have an optical interface? | |
| 989 return ; YES - setting 'sensor' allowed | |
| 656 | 990 btfsc ext_s8_full_digital ; are we in external S8 full digital mode? |
| 991 return ; YES - setting 'sensor' allowed | |
| 992 ENDIF ; _external_sensor_eccr | |
| 634 | 993 movff opt_ccr_mode,WREG ; NO to both - get CCR mode |
| 994 xorlw .1 ; - coding for sensor | |
| 995 tstfsz WREG ; - CCR mode = sensor? | |
| 996 return ; NO - setting allowed | |
| 997 banksel opt_ccr_mode ; YES - setting not allowed, select options bank | |
| 998 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) | |
| 999 banksel common ; - back to bank common | |
| 1000 bsf option_changed ; - flag that EEPROM needs to be updated | |
| 1001 return ; - done | |
| 1002 ENDIF ; _ccr_pscr | |
| 1003 | |
| 1004 | |
| 1005 ;----------------------------------------------------------------------------- | |
| 1006 ; Check and correct that O2% + He% <= 100% | |
| 1007 ; | |
| 1008 IFDEF _helium | |
| 1009 option_cleanup_sum_O2_He: | |
| 1010 lfsr FSR0,opt_gas_He_ratio-1 ; load (base address of He% array - 1) because of PREINC | |
| 1011 movlw 2*NUM_GAS ; load loop counter | |
| 1012 movwf lo ; ... | |
| 1013 option_cleanup_sum_loop: | |
| 1014 movff PREINC1,up ; get He ratio | |
| 1015 movlw -2*NUM_GAS ; address O2 ratio | |
| 1016 movff PLUSW0,hi ; get O2 ratio | |
| 1017 movlw .100 ; load WREG with 100% | |
| 1018 bsf STATUS,C ; set carry = clear borrow | |
| 1019 subfwb hi,W ; subtract O2% from WREG | |
| 1020 subfwb up,W ; subtract He% from WREG | |
| 1021 btfsc STATUS,C ; result negative? | |
| 1022 bra option_cleanup_sum_loop_1 ; NO - sum valid | |
| 1023 clrf INDF1 ; YES - heal by setting He% to zero | |
| 1024 bsf option_changed ; flag that EEPROM needs to be updated | |
| 1025 option_cleanup_sum_loop_1: | |
| 1026 decfsz lo ; decrement loop counter, all done? | |
| 1027 bra option_cleanup_sum_loop ; NO - loop | |
| 1028 return ; YES - done | |
| 1029 ENDIF ; _helium | |
| 1030 | |
| 628 | 1031 |
| 623 | 1032 ;----------------------------------------------------------------------------- |
| 0 | 1033 |
| 623 | 1034 END |
