Mercurial > public > hwos_code
comparison src/options.asm @ 634:4050675965ea
3.10 stable release
| author | heinrichsweikamp |
|---|---|
| date | Tue, 28 Apr 2020 17:34:31 +0200 |
| parents | 185ba2f91f59 |
| children | 070528a88715 |
comparison
equal
deleted
inserted
replaced
| 633:690c48db7b5b | 634:4050675965ea |
|---|---|
| 1 ;============================================================================= | 1 ;============================================================================= |
| 2 ; | 2 ; |
| 3 ; File options.asm next combined generation V3.08.8 | 3 ; File options.asm * next combined generation V3.09.4n |
| 4 ; | 4 ; |
| 5 ; Manage all options data. | 5 ; Manage all options data. |
| 6 ; | 6 ; |
| 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
| 8 ;============================================================================= | 8 ;============================================================================= |
| 23 extern write_eeprom | 23 extern write_eeprom |
| 24 extern read_eeprom | 24 extern read_eeprom |
| 25 extern option_table_begin,option_table_end | 25 extern option_table_begin,option_table_end |
| 26 extern convert_meter_to_feet | 26 extern convert_meter_to_feet |
| 27 | 27 |
| 28 options CODE | |
| 29 | 28 |
| 30 ;============================================================================= | 29 ;============================================================================= |
| 31 ; Reset all options to factory defaults (in memory only) | 30 options1 CODE |
| 32 ; | |
| 33 ; INPUT: none | |
| 34 ; OUTPUT: none | |
| 35 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 | |
| 36 ; | |
| 37 global option_reset_all ; reset all options to factory default | |
| 38 option_reset_all: | |
| 39 call eeprom_total_dives_read ; read total number of dives | |
| 40 tstfsz mpr+0 ; number of total dives, low byte = 0 ? | |
| 41 bra option_reset_all_1 ; NO - skip resetting logbook | |
| 42 tstfsz mpr+1 ; number of total dives, high byte = 0 ? | |
| 43 bra option_reset_all_1 ; NO - skip resetting logbook | |
| 44 | |
| 45 ; reset logbook | |
| 46 call erase_complete_logbook ; erase complete logbook | |
| 47 | |
| 48 ; reset logbook offset | |
| 49 CLRI mpr ; set logbook offset to zero | |
| 50 call eeprom_log_offset_write ; store logbook offset | |
| 51 | |
| 52 option_reset_all_1: | |
| 53 lfsr FSR0,option_table_begin ; point to start of option definition table | |
| 54 option_reset_all_loop: | |
| 55 rcall option_reset ; reset option | |
| 56 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
| 57 bra option_reset_all_loop ; NO - do next option | |
| 58 return ; YES - done | |
| 59 | |
| 60 | |
| 61 ;============================================================================= | 31 ;============================================================================= |
| 62 ; Reset an option to its default value | 32 |
| 63 ; INPUT: FSR0 = option handle | 33 |
| 64 ; OUTPUT: none | 34 ;----------------------------------------------------------------------------- |
| 65 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 | 35 ; Adjust Address in FSR0 to an Option within an Option Group |
| 66 ; | 36 ; |
| 67 global option_reset ; reset option value to default | 37 ; INPUT: FSR0 = base address of the option group |
| 68 option_reset: | 38 ; gaslist_gas = offset of the selected option within the group |
| 69 ; read type, default and register from table | 39 ; OUTPUT: FSR0 = pointing to selected option |
| 70 rcall option_read_definition ; read option definition | 40 ; |
| 71 | 41 global option_adjust_group_member |
| 72 option_reset_loaded: ; entry point with option definition already read | 42 option_adjust_group_member: |
| 73 bsf option_repaired ; flag that an option was repaired | 43 movf gaslist_gas,W ; get offset in number of options |
| 74 bsf options_changed ; flag that EEPROM needs to be updated | 44 mullw opt_definition_bytes ; calculate offset in number of bytes |
| 75 movf opt_type,W ; get option type | 45 movf PRODL,W ; get number of bytes, low byte |
| 76 xorlw .2 ; type = STRING ? | 46 addwf FSR0L,F ; add to FSR0, low byte |
| 77 bz opt_reset_string ; YES - string copy | 47 movf PRODH,W ; get number of bytes, high byte |
| 78 movff opt_default,INDF1 ; NO - 1 byte copy | 48 addwfc FSR0H,F ; add to FSR0, high byte |
| 79 return ; - done | 49 return ; done |
| 80 | 50 |
| 81 opt_reset_string: | 51 |
| 82 movff FSR1L,FSR2L ; set string destination address | 52 ;----------------------------------------------------------------------------- |
| 83 movff FSR1H,FSR2H ; ... | 53 ; Read the Option Definition |
| 84 movff opt_default+0,FSR1L ; get handle to multi-lingual text in FSR1 | 54 ; |
| 85 movff opt_default+1,FSR1H ; ... | |
| 86 movff TBLPTRL,mpr+0 ; TBLPTR will be trashed by text routine, so make a back-up | |
| 87 movff TBLPTRH,mpr+1 ; ... | |
| 88 movff TBLPTRU,mpr+2 ; ... | |
| 89 call strcat_text ; copy translated text to FSR2 | |
| 90 movff mpr+0,TBLPTRL ; restore TBLPTR | |
| 91 movff mpr+1,TBLPTRH ; ... | |
| 92 movff mpr+2,TBLPTRU ; ... | |
| 93 return ; done | |
| 94 | |
| 95 | |
| 96 ;============================================================================= | |
| 97 ; Read option definition | |
| 98 ; INPUT: FSR0 = option handle | 55 ; INPUT: FSR0 = option handle |
| 99 ; OUTPUT: FSR1 = address of variable. | 56 ; OUTPUT: FSR1 = address of variable. |
| 100 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | 57 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 |
| 101 ; | 58 ; |
| 102 option_read_definition: | 59 option_read_definition: |
| 103 movff FSR0L,TBLPTRL ; low byte : set memory address of option data set | 60 ; option_table_begin is at 0x0|80|00 |
| 104 movlw HIGH(option_table_begin) ; high byte : get table start address | 61 clrf TBLPTRU ; TBLPRT upper = 0x00 |
| 105 andlw 0xF0 ; keep only the upper nibble | 62 movlw HIGH(option_table_begin) ; TBLPRT high = 0x80 |
| 106 iorwf FSR0H,W ; add the memory address of the option data set | 63 iorwf FSR0H,W ; + 0x0H from FSR0H |
| 107 movwf TBLPTRH ; set the resulting memory address | 64 movwf TBLPTRH ; set 0x8H |
| 108 movlw UPPER(option_table_begin) ; upper byte: get table start address | 65 movff FSR0L,TBLPTRL ; TBLPRT low = 0xLL from FSR0L |
| 109 movwf TBLPTRU ; set memory address of option data set | 66 ; copy option definition from program to data memory |
| 110 | 67 lfsr FSR1,opt_type ; load FSR1 with base address of option definition buffer |
| 111 lfsr FSR1,opt_type ; load FSR1 with base address of option definition vars | 68 movlw opt_definition_bytes ; get number of bytes to copy |
| 112 movlw opt_definiton_bytes ; get number of bytes to copy | |
| 113 movwf eeprom_loop ; initialize loop counter (using an EEPROM variable here) | 69 movwf eeprom_loop ; initialize loop counter (using an EEPROM variable here) |
| 114 option_read_definition_loop: | 70 option_read_definition_loop: |
| 115 tblrd*+ ; read one byte from program memory and increment address | 71 tblrd*+ ; read one byte from program memory and increment address |
| 116 movff TABLAT,POSTINC1 ; transfer byte from program memory to memory | 72 movff TABLAT,POSTINC1 ; transfer byte from program memory to memory |
| 117 decfsz eeprom_loop,F ; all bytes done? | 73 decfsz eeprom_loop,F ; all bytes done? |
| 123 movff TBLPTRL,FSR0L ; - advance handle to the next option definition data set | 79 movff TBLPTRL,FSR0L ; - advance handle to the next option definition data set |
| 124 movff TBLPTRH,FSR0H ; - ... | 80 movff TBLPTRH,FSR0H ; - ... |
| 125 return ; - done | 81 return ; - done |
| 126 | 82 |
| 127 | 83 |
| 128 ;============================================================================= | 84 ;----------------------------------------------------------------------------- |
| 129 ; Check one option and reset its value if it is out of min/max boundary | 85 ; Reset all Options to Factory Defaults |
| 130 ; INPUT: opt_* vars and FSR1 | 86 ; |
| 131 ; OUTPUT: option value set to default if out of min/max | 87 ; INPUT: none |
| 88 ; OUTPUT: none | |
| 89 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 | |
| 90 ; | |
| 91 global option_reset_all ; reset all options to factory default | |
| 92 option_reset_all: | |
| 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 | |
| 98 | |
| 99 ; reset logbook | |
| 100 call erase_complete_logbook ; erase complete logbook | |
| 101 | |
| 102 ; reset logbook offset | |
| 103 CLRI mpr ; set logbook offset to zero | |
| 104 call eeprom_log_offset_write ; store logbook offset | |
| 105 | |
| 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 | |
| 113 | |
| 114 | |
| 115 ;----------------------------------------------------------------------------- | |
| 116 ; Reset an Option to its default Value | |
| 117 ; | |
| 118 ; INPUT: FSR0 = option handle | |
| 119 ; OUTPUT: option value set to default value | |
| 120 ; option_repaired flag set | |
| 121 ; option_changed flag set if not a volatile option | |
| 122 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 | |
| 123 ; | |
| 124 global option_reset ; reset option value to default | |
| 125 option_reset: | |
| 126 ; read type, default and register from table | |
| 127 rcall option_read_definition ; read option definition | |
| 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 | |
| 131 | |
| 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: | |
| 141 movf opt_type,W ; get option type | |
| 142 xorlw .2 ; type = STRING ? | |
| 143 bz opt_init_loaded_string ; YES - string copy | |
| 144 movff opt_default,INDF1 ; NO - 1 byte copy | |
| 145 return ; - done | |
| 146 | |
| 147 opt_init_loaded_string: | |
| 148 movff TBLPTRL,mpr+0 ; back-up TBLPTR | |
| 149 movff TBLPTRH,mpr+1 ; ... | |
| 150 movff TBLPTRU,mpr+2 ; ... | |
| 151 | |
| 152 movff FSR1L,FSR2L ; set string destination address | |
| 153 movff FSR1H,FSR2H ; ... | |
| 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 | |
| 158 movff mpr+0,TBLPTRL ; restore TBLPTR | |
| 159 movff mpr+1,TBLPTRH ; ... | |
| 160 movff mpr+2,TBLPTRU ; ... | |
| 161 | |
| 162 return ; done | |
| 163 | |
| 164 | |
| 165 ;----------------------------------------------------------------------------- | |
| 166 ; Check one Option and reset its Value if it is out of its min/max Limits | |
| 167 ; | |
| 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 | |
| 132 ; TRASH: WREG | 171 ; TRASH: WREG |
| 133 ; | 172 ; |
| 173 global option_check_loaded | |
| 134 option_check_loaded: | 174 option_check_loaded: |
| 135 ; switch on type | 175 ; switch on type |
| 176 bsf option_value_ok ; set result to ok by default | |
| 136 movf opt_type,W ; get type | 177 movf opt_type,W ; get type |
| 137 bz option_check_uint8 ; type 0: INT8 | 178 bz option_check_uint8 ; type 0: INT8 |
| 138 dcfsnz WREG ; decrement | 179 dcfsnz WREG ; decrement |
| 139 bra option_check_enum8 ; type 1: ENUM | 180 bra option_check_enum8 ; type 1: ENUM |
| 140 dcfsnz WREG ; decrement | 181 dcfsnz WREG ; decrement |
| 141 bra option_check_string ; type 2: STRING | 182 return ; type 2: STRING - nothing to check |
| 142 ;bra option_check_uint8 ; type 3: INT8 | 183 ;bra option_check_uint8 ; type 3: INT8 |
| 143 | 184 |
| 144 option_check_uint8: | 185 option_check_uint8: |
| 145 tstfsz opt_min ; opt_min = 0 ? | 186 tstfsz opt_min ; opt_min = 0 ? |
| 146 bra option_check_min ; NO - check it | 187 bra option_check_min ; NO - check it |
| 147 bra option_check_enum8 ; YES - continue with check for maximum | 188 bra option_check_enum8 ; YES - continue with check for maximum |
| 148 | 189 |
| 149 option_check_min: | 190 option_check_min: |
| 150 decf opt_min,W ; get (minimum permissible value - 1) into WREG | 191 decf opt_min,W ; get (minimum permissible value - 1) into WREG |
| 151 cpfsgt INDF1 ; option value > (minimum permissible value - 1) ? | 192 cpfsgt hi ; option value > (minimum permissible value - 1) ? |
| 152 bra option_reset_loaded ; NO - reset option value | 193 bra option_check_nok ; NO - value not ok |
| 153 ;bra option_check_enum8 ; YES - continue with check for maximum | 194 ;bra option_check_enum8 ; YES - continue with check for maximum |
| 154 | 195 |
| 155 option_check_enum8: | 196 option_check_enum8: |
| 156 infsnz opt_max,W ; get (highest permissible value + 1) into WREG | 197 infsnz opt_max,W ; get (highest permissible value + 1) into WREG |
| 157 return ; highest permissible value was 255, skip check, done | 198 return ; highest permissible value is 255, skip check, done |
| 158 cpfslt INDF1 ; option value < (highest permissible value + 1) ? | 199 cpfslt hi ; option value < (highest permissible value + 1) ? |
| 159 bra option_reset_loaded ; NO - reset option value | 200 bra option_check_nok ; NO - value not ok |
| 160 return ; YES - within range, done | 201 return ; YES - value ok, done |
| 161 | 202 |
| 162 option_check_string: | 203 option_check_nok: |
| 163 return ; nothing to check with strings | 204 bcf option_value_ok ; flag option value is invalid |
| 164 | 205 return ; done |
| 165 | 206 |
| 166 ;============================================================================= | 207 |
| 167 ; Check and store all option values in EEPROM | 208 ;----------------------------------------------------------------------------- |
| 209 ; Check and store all Option Values to EEPROM | |
| 168 ; | 210 ; |
| 169 global option_check_and_store_all | 211 global option_check_and_store_all |
| 170 option_check_and_store_all: | 212 option_check_and_store_all: |
| 171 bcf PIR3,RC2IE ; disable EUSART interrupts | 213 bcf PIR3,RC2IE ; disable EUSART interrupts TODO: why??? |
| 172 | 214 call option_crosschecks ; do some crosschecks between option values |
| 173 ;---- save option version | 215 ;bra option_store_all ; continue storing all option values to EEPROM |
| 216 | |
| 217 | |
| 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 | |
| 174 MOVLI eeprom_opt_version,mpr ; get options version number | 234 MOVLI eeprom_opt_version,mpr ; get options version number |
| 175 EEPROM_II_WRITE mpr,eeprom_options_version ; store options version number in EEPROM | 235 EEPROM_II_WRITE mpr,eeprom_options_version ; store options version number in EEPROM |
| 176 | 236 |
| 177 ;---- check and resolve some interdependencies among options | 237 bcf option_changed ; no pending EEPROM updates any more |
| 178 bsf is_diluent_menu ; setup checking diluents | 238 return ; done |
| 179 call gaslist_cleanup_list ; check and correct multiple or none First diluents | 239 |
| 180 | 240 |
| 181 bcf is_diluent_menu ; setup checking gases | 241 ;----------------------------------------------------------------------------- |
| 182 call gaslist_cleanup_list ; check and correct multiple or none First gases | 242 ; Check and store one Option Value to EEPROM |
| 183 | |
| 184 IFNDEF _gauge_mode | |
| 185 call option_cleanup_gauge ; check and correct gauge mode | |
| 186 ENDIF | |
| 187 | |
| 188 IFDEF _ccr_pscr | |
| 189 call option_cleanup_oCCRMode ; check and correct CCR / pSCR mode | |
| 190 ENDIF | |
| 191 | |
| 192 call option_cleanup_GF ; check and correct GFlow <= GFhigh | |
| 193 | |
| 194 ;---- check and save all option values | |
| 195 lfsr FSR0,option_table_begin ; point to start of option definition table | |
| 196 option_save_all_loop: | |
| 197 rcall option_check_and_store ; check and save option value | |
| 198 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
| 199 bra option_save_all_loop ; NO - do next option | |
| 200 return ; YES - done | |
| 201 | |
| 202 | |
| 203 ;============================================================================= | |
| 204 ; Check and store an option value in EEPROM | |
| 205 ; | 243 ; |
| 206 global option_check_and_store | 244 global option_check_and_store |
| 207 option_check_and_store: | 245 option_check_and_store: |
| 208 rcall option_read_definition ; read the option definition | 246 rcall option_read_definition ; read the option definition |
| 209 rcall option_check_loaded ; check if option value is within min/max, set to default if not | 247 movff INDF1,hi ; check current option value |
| 210 | 248 rcall option_check_loaded ; check value for validity |
| 211 option_save_loaded_checked: | 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 | |
| 252 | |
| 253 | |
| 254 ;----------------------------------------------------------------------------- | |
| 255 ; Store one Option Value to EEPROM | |
| 256 ; | |
| 257 global option_store_loaded | |
| 258 option_store_loaded: | |
| 212 movf opt_eeprom_bank,W ; get bank | 259 movf opt_eeprom_bank,W ; get bank |
| 213 andlw b'11111110' ; keep only bits 7-1 | 260 andlw b'11111110' ; keep only bits 7-1 |
| 214 tstfsz WREG ; bank < 0x02 ? | 261 tstfsz WREG ; bank < 0x02 ? |
| 215 return ; NO - volatile option or illegal address, abort | 262 return ; NO - volatile option or illegal address, done/abort |
| 216 tstfsz opt_eeprom_bank ; YES - bank = 0 ? | 263 tstfsz opt_eeprom_bank ; YES - bank = 0 ? |
| 217 bra option_save_execute ; NO - address is valid | 264 bra option_store_execute ; NO - address is valid in any case |
| 218 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 | 265 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 |
| 219 cpfsgt opt_eeprom_index ; - index >= start address ? | 266 cpfsgt opt_eeprom_index ; - index >= start address ? |
| 220 return ; NO - illegal address, abort | 267 return ; NO - illegal address, done |
| 221 ;bra option_save_execute ; YES - address is valid | 268 ;bra option_store_execute ; YES - address is valid |
| 222 | 269 |
| 223 option_save_execute: | 270 option_store_execute: |
| 224 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) | 271 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) |
| 225 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) | 272 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) |
| 226 | 273 |
| 227 movf opt_type,W ; get option type | 274 movf opt_type,W ; get option type |
| 228 xorlw .2 ; option type = string ? | 275 xorlw .2 ; option type = string ? |
| 229 bz option_save_string ; YES - special handling | 276 bz option_store_exec_string ; YES - store string of bytes |
| 230 movff INDF1,EEDATA ; NO - copy option value to EEPROM write register | 277 ;bnz option_store_exec_byte ; NO - store single byte |
| 231 call write_eeprom ; - execute write | 278 |
| 232 return ; - done | 279 option_store_exec_byte: |
| 233 | 280 call read_eeprom ; read stored value |
| 234 option_save_string: | 281 movf EEDATA,W ; copy stored value to WREG |
| 235 movff POSTINC1,EEDATA ; copy a character from the option value to the EEPROM write register | 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: | |
| 236 btfss EEADRH,1 ; current EEPROM address < 512 ? | 289 btfss EEADRH,1 ; current EEPROM address < 512 ? |
| 237 call write_eeprom ; YES - execute write | 290 rcall option_store_exec_byte ; YES - store one byte from the string |
| 291 movf POSTINC1,W ; increment FSR1 address by a dummy read | |
| 238 infsnz EEADR,F ; increment EEPROM address, low byte | 292 infsnz EEADR,F ; increment EEPROM address, low byte |
| 239 incf EEADRH,F ; increment EEPROM address, high byte | 293 incf EEADRH,F ; increment EEPROM address, high byte |
| 240 decfsz opt_max ; decrement string length, done? | 294 decfsz opt_max ; decrement string length, done? |
| 241 bra option_save_string ; NO - loop | 295 bra option_store_exec_string ; NO - loop |
| 242 return ; YES - done | 296 return ; YES - done |
| 243 | 297 |
| 244 | 298 |
| 245 ;============================================================================= | 299 ;----------------------------------------------------------------------------- |
| 246 ; Restore and check all option values from EEPROM | 300 ; Restore all Option Values from EEPROM and check them |
| 247 ; | 301 ; |
| 248 global option_restore_and_check_all ; restore options from EEPROM | 302 global option_restore_and_check_all |
| 249 option_restore_and_check_all: | 303 option_restore_and_check_all: |
| 250 ;---- Read option version from EEPROM | 304 ;---- Read option version from EEPROM |
| 251 EEPROM_II_READ eeprom_options_version,mpr | 305 EEPROM_II_READ eeprom_options_version,mpr |
| 252 | 306 |
| 253 movlw LOW(eeprom_opt_version) ; get options version from current firmware, low byte | 307 movlw LOW(eeprom_opt_version) ; get options version from current firmware, low byte |
| 262 lfsr FSR0,option_table_begin ; point to start of option definition table | 316 lfsr FSR0,option_table_begin ; point to start of option definition table |
| 263 option_restore_all_loop: | 317 option_restore_all_loop: |
| 264 rcall option_restore_and_check ; restore and check the option | 318 rcall option_restore_and_check ; restore and check the option |
| 265 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | 319 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? |
| 266 bra option_restore_all_loop ; NO - do next option | 320 bra option_restore_all_loop ; NO - do next option |
| 267 return ; YES - done | 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 | |
| 268 | 327 |
| 269 option_restore_reset: | 328 option_restore_reset: |
| 270 call option_reset_all ; reset all option values to their default | 329 call option_reset_all ; reset all option values to their default |
| 271 goto option_check_and_store_all ; write back all option values to EEPROM (and return) | 330 goto option_check_and_store_all ; write back all option values to EEPROM (and return) |
| 272 | 331 |
| 273 | 332 |
| 274 ;============================================================================= | 333 ;----------------------------------------------------------------------------- |
| 275 ; Restore an option value from EEPROM and check it | 334 ; Restore one Option Value from EEPROM and check it |
| 276 ; | 335 ; |
| 277 global option_restore_and_check | 336 global option_restore_and_check |
| 278 option_restore_and_check: | 337 option_restore_and_check: |
| 279 rcall option_read_definition ; read the option definition | 338 rcall option_read_definition ; read the option definition |
| 280 | 339 |
| 281 movf opt_eeprom_bank,W ; get bank | 340 movf opt_eeprom_bank,W ; get bank |
| 282 andlw b'11111110' ; keep only bits 7-1 | 341 andlw b'11111110' ; keep only bits 7-1 |
| 283 tstfsz WREG ; bank < 0x02 ? | 342 tstfsz WREG ; bank < 0x02 ? |
| 284 bra option_reset_loaded ; NO - volatile option or illegal address, restore to default | 343 bra option_init_loaded ; NO - volatile option or illegal address, initialize to default |
| 285 tstfsz opt_eeprom_bank ; YES - bank = 0 ? | 344 tstfsz opt_eeprom_bank ; YES - bank = 0 ? |
| 286 bra option_restore_execute ; NO - address is valid | 345 bra option_restore_execute ; NO - address is valid in any case |
| 287 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 | 346 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 |
| 288 cpfsgt opt_eeprom_index ; - index >= start address ? | 347 cpfsgt opt_eeprom_index ; - index >= start address ? |
| 289 bra option_reset_loaded ; NO - illegal address, restore to default | 348 bra option_init_loaded ; NO - illegal address, initialize to default |
| 290 ;bra option_restore_execute ; YES - address is valid | 349 ;bra option_restore_execute ; YES - address is valid |
| 291 | 350 |
| 292 option_restore_execute: | 351 option_restore_execute: |
| 293 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) | 352 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) |
| 294 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) | 353 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) |
| 295 | 354 |
| 296 movf opt_type,W ; get option type | 355 movf opt_type,W ; get option type |
| 297 xorlw .2 ; option type = string ? | 356 xorlw .2 ; option type = string ? |
| 298 bz option_restore_string ; YES - special handling | 357 bz option_restore_exec_string ; YES - special handling |
| 299 call read_eeprom ; NO - execute read | 358 call read_eeprom ; NO - execute EEPROM read |
| 300 movff EEDATA,INDF1 ; - read option value from EEPROM read register | 359 movff EEDATA,INDF1 ; - copy from EEPROM read register to option variable |
| 301 bcf option_repaired ; - clear option repaired flag | 360 movff EEDATA,hi ; - check loaded option value |
| 302 bra option_check_loaded ; - check if option value is within min/max, reset to default if not | 361 rcall option_check_loaded ; - check if option value is within min/max limits |
| 303 btfsc option_repaired ; - was the option repaired? | 362 btfsc option_value_ok ; - option value ok (strings will always be 'ok') ? |
| 304 bra option_save_loaded_checked ; YES - save repaired value to EEPROM | 363 return ; YES - done |
| 305 return ; NO - done | 364 movff opt_default,INDF1 ; NO - set option value to default |
| 306 | 365 movff INDF1,EEDATA ; - copy repaired value to EEPROM write register |
| 307 option_restore_string: | 366 goto write_eeprom ; - execute write and return |
| 367 | |
| 368 option_restore_exec_string: | |
| 308 call read_eeprom ; read one character from the EEPROM | 369 call read_eeprom ; read one character from the EEPROM |
| 309 movff EEDATA,POSTINC1 ; copy it to the option value | 370 movff EEDATA,POSTINC1 ; copy it to the option value |
| 310 infsnz EEADR,F ; increment EEPROM address, low byte | 371 infsnz EEADR,F ; increment EEPROM address, low byte |
| 311 incf EEADRH,F ; increment EEPROM address, high byte | 372 incf EEADRH,F ; increment EEPROM address, high byte |
| 312 decfsz opt_max ; decrement string length, done? | 373 decfsz opt_max ; decrement string length, done? |
| 313 bra option_restore_string ; NO - loop | 374 bra option_restore_exec_string ; NO - loop |
| 314 return ; YES - done (nothing to check with strings) | 375 return ; YES - done (nothing to check with strings) |
| 315 | 376 |
| 316 | 377 |
| 317 | 378 |
| 318 ;============================================================================= | 379 ;----------------------------------------------------------------------------- |
| 319 ; Read an option value via RS232 | 380 ; Read an Option Value via serial Index |
| 381 ; | |
| 320 ; INPUT: lo = serial index | 382 ; INPUT: lo = serial index |
| 321 ; OUTPUT: hi = option value | 383 ; OUTPUT: hi = option value |
| 322 ; WREG =0: option found and value valid, =1: option not found | 384 ; WREG =0: option found and value valid, =1: option not found |
| 323 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | 385 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 |
| 324 ; | 386 ; |
| 330 movf opt_serial,W ; get serial index of the option into WREG | 392 movf opt_serial,W ; get serial index of the option into WREG |
| 331 xorwf lo,W ; received index = index of this option ? | 393 xorwf lo,W ; received index = index of this option ? |
| 332 bz option_read_serial_execute ; YES - read value | 394 bz option_read_serial_execute ; YES - read value |
| 333 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? | 395 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? |
| 334 bra option_read_serial_loop ; NO - try next option | 396 bra option_read_serial_loop ; NO - try next option |
| 335 retlw .1 ; YES - done, option not found | 397 retlw .1 ; YES - option not found, abort |
| 336 | 398 |
| 337 option_read_serial_execute: | 399 option_read_serial_execute: |
| 338 movff INDF1,hi ; read option value into hi | 400 movff INDF1,hi ; read option value into hi |
| 339 retlw .0 ; done, option found | 401 retlw .0 ; done |
| 340 | 402 |
| 341 | 403 |
| 342 ;============================================================================= | 404 ;----------------------------------------------------------------------------- |
| 343 ; Write an option value via RS232 | 405 ; Write an Option Value via serial Index |
| 406 ; | |
| 344 ; INPUT: lo = serial index | 407 ; INPUT: lo = serial index |
| 345 ; hi = option value | 408 ; hi = option value |
| 346 ; OUTPUT: WREG =0: option found and value valid, =1: option not found, =2: value not valid | 409 ; OUTPUT: WREG =0: option found and value valid, =1: option not found, =2: value not valid |
| 347 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, up | 410 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, up |
| 348 ; | 411 ; |
| 354 movf opt_serial,W ; get serial index of the option into WREG | 417 movf opt_serial,W ; get serial index of the option into WREG |
| 355 xorwf lo,W ; received index = index of this option ? | 418 xorwf lo,W ; received index = index of this option ? |
| 356 bz option_write_serial_execute ; YES - check and update value | 419 bz option_write_serial_execute ; YES - check and update value |
| 357 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? | 420 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? |
| 358 bra option_write_serial_loop ; NO - try next option | 421 bra option_write_serial_loop ; NO - try next option |
| 359 retlw .1 ; YES - done, option not found | 422 retlw .1 ; YES - option not found, abort |
| 360 | 423 |
| 361 option_write_serial_execute: | 424 option_write_serial_execute: |
| 362 movff INDF1,up ; backup old value | 425 rcall option_check_loaded ; check if new value is valid |
| 363 movff hi,INDF1 ; write new value | 426 btfss option_value_ok ; value valid? |
| 364 bcf option_repaired ; clear option repaired flag | 427 retlw .2 ; NO - value not valid, abort |
| 365 rcall option_check_loaded ; check the new value | 428 movff hi,INDF1 ; YES - take new value |
| 366 btfsc option_repaired ; was the new value valid? | 429 btfss opt_eeprom_bank,7 ; - volatile option? |
| 367 bra option_write_serial_execute_fail; NO - restore old value | 430 bsf option_changed ; NO - flag that EEPROM needs to be updated |
| 368 bsf options_changed ; YES - flag that EEPROM needs to be updated | 431 retlw .0 ; - done |
| 369 retlw .0 ; - done, success | 432 |
| 370 option_write_serial_execute_fail: | 433 |
| 371 movff up,INDF1 ; restore old value | 434 ;----------------------------------------------------------------------------- |
| 372 retlw .2 ; done, value not valid | 435 ; Increment an Option Value based on Type and min/max Boundary |
| 373 | 436 ; |
| 374 | |
| 375 ;============================================================================= | |
| 376 ; Increment an option value based on type and min/max boundary | |
| 377 ; INPUT: FSR0 = option handle | 437 ; INPUT: FSR0 = option handle |
| 378 ; OUTPUT: none | 438 ; OUTPUT: incremented option value |
| 379 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | 439 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 |
| 380 ; | 440 ; |
| 381 global option_inc ; increment FSR0 option | 441 global option_inc |
| 382 option_inc: | 442 option_inc: |
| 383 ; read type, default and register from table | 443 ; read type, default and register from table |
| 384 rcall option_read_definition | 444 rcall option_read_definition |
| 385 | 445 |
| 386 bsf options_changed ; flag that EEPROM needs to be updated | 446 btfss opt_eeprom_bank,7 ; volatile option? |
| 447 bsf option_changed ; NO - flag that EEPROM needs to be updated | |
| 387 | 448 |
| 388 ; switch on type | 449 ; switch on type |
| 389 movf opt_type,W ; get option type | 450 movf opt_type,W ; get option type |
| 390 bz option_inc_uint8 ; type 0: INT8 | 451 bz option_inc_uint8 ; type 0: UINT8 |
| 391 dcfsnz WREG ; decrement | 452 dcfsnz WREG ; decrement |
| 392 bra option_inc_enum8 ; type 1: ENUM | 453 bra option_inc_enum8 ; type 1: ENUM |
| 393 dcfsnz WREG ; decrement | 454 dcfsnz WREG ; decrement |
| 394 bra option_inc_string ; type 2: STRING | 455 return ; type 2: STRING - no inc function defined |
| 395 ;bra option_inc_uint8 ; type 3: INT8 | 456 dcfsnz WREG ; decrement |
| 396 | 457 bra option_inc_uint8 ; type 3: UINT8 as meters or feet |
| 458 return ; unknown, do nothing | |
| 459 | |
| 460 | |
| 461 ;----------------------------------------------------------------------------- | |
| 462 ; Helper Function - increment UINT8, wrap-around or stop at option max | |
| 463 ; | |
| 397 option_inc_uint8: | 464 option_inc_uint8: |
| 398 movf INDF1,W ; get option value | 465 movf INDF1,W ; get option value |
| 399 addwf opt_inc,W ; add increment | 466 addwf opt_inc,W ; add increment |
| 400 cpfslt opt_max ; max < option value ? | 467 cpfslt opt_max ; option value > max ? |
| 401 bra option_inc_uint8_0 ; NO - new option value ok | 468 bra option_inc_uint8_0 ; NO - new option value ok |
| 402 movf opt_min,W ; YES - reset to min value | 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 | |
| 403 option_inc_uint8_0: | 472 option_inc_uint8_0: |
| 404 movwf INDF1 ; store new value | 473 movwf INDF1 ; store new value |
| 474 ; do cross-checks with other option values | |
| 405 option_inc_uint8_1: | 475 option_inc_uint8_1: |
| 406 ; now some rather crude hack into this routine to make CCR calibration more convenient: | 476 ; now some rather crude hack into this routine to make CCR calibration more convenient: |
| 407 movlw 0x37 ; serial ID of option CalGasO2 | 477 movlw 0x37 ; serial ID of option CalGasO2 |
| 408 cpfseq opt_serial ; editing CalGasO2 right now? | 478 cpfseq opt_serial ; editing CalGasO2 right now? |
| 409 bra option_inc_uint8_2 ; NO - check next option | 479 bra option_inc_uint8_2 ; NO - check next option |
| 414 cpfseq INDF1 ; - option value = 26 ? | 484 cpfseq INDF1 ; - option value = 26 ? |
| 415 return ; NO - done | 485 return ; NO - done |
| 416 movlw .95 ; YES - advance it to 95 | 486 movlw .95 ; YES - advance it to 95 |
| 417 movwf INDF1 ; - store it | 487 movwf INDF1 ; - store it |
| 418 return | 488 return |
| 489 | |
| 419 option_inc_uint8_2: | 490 option_inc_uint8_2: |
| 491 ; check GF low <= GF high | |
| 420 movlw 0x25 ; serial ID of option opt_GF_low | 492 movlw 0x25 ; serial ID of option opt_GF_low |
| 421 cpfseq opt_serial ; editing opt_GF_low right now? | 493 cpfseq opt_serial ; editing opt_GF_low right now? |
| 422 bra option_inc_uint8_3 ; NO - check next option | 494 bra option_inc_uint8_3 ; NO - check next option |
| 423 movff opt_GF_high,WREG ; get value of associated GF high into WREG | 495 movff opt_GF_high,WREG ; get value of associated GF high into WREG |
| 424 cpfsgt INDF1 ; GF low > GF high? | 496 cpfsgt INDF1 ; GF low > GF high? |
| 425 return ; NO - setting ok, done | 497 return ; NO - setting ok, done |
| 426 movff opt_min,INDF1 ; YES - wrap around to minimum value | 498 movff opt_min,INDF1 ; YES - wrap around to minimum value |
| 427 return ; - done | 499 return ; - done |
| 500 | |
| 428 option_inc_uint8_3: | 501 option_inc_uint8_3: |
| 502 ; check GF high >= GF low | |
| 429 movlw 0x26 ; serial ID of option opt_GF_high | 503 movlw 0x26 ; serial ID of option opt_GF_high |
| 430 cpfseq opt_serial ; editing opt_GF_high right now? | 504 cpfseq opt_serial ; editing opt_GF_high right now? |
| 431 bra option_inc_uint8_4 ; NO - check next option | 505 bra option_inc_uint8_4 ; NO - check next option |
| 432 movff opt_GF_low,WREG ; get value of associated GF low into WREG | 506 movff opt_GF_low,WREG ; get value of associated GF low into WREG |
| 433 cpfslt INDF1 ; GF high < GF low? | 507 cpfslt INDF1 ; GF high < GF low? |
| 434 return ; NO - setting ok, done | 508 return ; NO - setting ok, done |
| 435 movwf INDF1 ; YES - rise GF high to GF low | 509 movwf INDF1 ; YES - rise GF high to GF low |
| 436 return ; - done | 510 return ; - done |
| 511 | |
| 437 option_inc_uint8_4: | 512 option_inc_uint8_4: |
| 513 ; check aGF low <= aGF high | |
| 438 movlw 0x27 ; serial ID of option opt_aGF_low | 514 movlw 0x27 ; serial ID of option opt_aGF_low |
| 439 cpfseq opt_serial ; editing opt_aGF_low right now? | 515 cpfseq opt_serial ; editing opt_aGF_low right now? |
| 440 bra option_inc_uint8_5 ; NO - check next option | 516 bra option_inc_uint8_5 ; NO - check next option |
| 441 movff opt_aGF_high,WREG ; get value of associated GF high into WREG | 517 movff opt_aGF_high,WREG ; get value of associated GF high into WREG |
| 442 cpfsgt INDF1 ; GF low > GF high? | 518 cpfsgt INDF1 ; GF low > GF high? |
| 443 return ; NO - setting ok, done | 519 return ; NO - setting ok, done |
| 444 movff opt_min,INDF1 ; YES - wrap around to minimum value | 520 movff opt_min,INDF1 ; YES - wrap around to minimum value |
| 445 return ; - done | 521 return ; - done |
| 522 | |
| 446 option_inc_uint8_5: | 523 option_inc_uint8_5: |
| 524 ; check aGF high >= aGF low | |
| 447 movlw 0x28 ; serial ID of option opt_aGF_high | 525 movlw 0x28 ; serial ID of option opt_aGF_high |
| 448 cpfseq opt_serial ; editing opt_aGF_high right now? | 526 cpfseq opt_serial ; editing opt_aGF_high right now? |
| 449 bra option_inc_uint8_6 ; NO - check next option | 527 bra option_inc_uint8_6 ; NO - check next option |
| 450 movff opt_aGF_low,WREG ; get value of associated GF low into WREG | 528 movff opt_aGF_low,WREG ; get value of associated GF low into WREG |
| 451 cpfslt INDF1 ; GF high < GF low? | 529 cpfslt INDF1 ; GF high < GF low? |
| 452 return ; NO - setting ok, done | 530 return ; NO - setting ok, done |
| 453 movwf INDF1 ; YES - rise GF high to GF low | 531 movwf INDF1 ; YES - rise GF high to GF low |
| 454 return ; - done | 532 return ; - done |
| 533 | |
| 455 option_inc_uint8_6: | 534 option_inc_uint8_6: |
| 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 | |
| 456 return ; all done | 573 return ; all done |
| 457 | 574 |
| 458 | 575 |
| 576 ;----------------------------------------------------------------------------- | |
| 577 ; Helper Function - increment ENUM, will wrap-around on exceeding option max | |
| 578 ; | |
| 459 option_inc_enum8: | 579 option_inc_enum8: |
| 460 movf opt_max,W ; copy maximum permissible value to WREG | 580 incf INDF1,W ; get incremented option value |
| 461 cpfslt INDF1 ; option value < maximum permissible value ? | 581 cpfslt opt_max ; option value > max? |
| 462 bra option_inc_enum8_reset ; NO - reset option value | 582 bra option_inc_enum8_0 ; NO - new option value ok |
| 463 incf INDF1,F ; YES - increment option value | 583 clrf WREG ; YES - reset to 1st option value |
| 464 bra option_inc_enum8_1 ; - continue | 584 option_inc_enum8_0: |
| 465 option_inc_enum8_reset: | 585 movwf INDF1 ; store new value |
| 466 clrf INDF1 ; reset option value to zero | 586 ; do cross-checks with other option values |
| 467 | |
| 468 option_inc_enum8_1: | 587 option_inc_enum8_1: |
| 469 IFDEF _ccr_pscr | 588 IFDEF _ccr_pscr |
| 470 ; now some rather crude hack into this routine to unify CCR & pSCR mode setting | 589 ; now some rather crude hack into this routine to unify CCR & pSCR mode setting |
| 471 movlw 0x1F ; serial ID of option oCCRMode | 590 movlw 0x1F ; serial ID of option oCCRMode |
| 472 cpfseq opt_serial ; editing oCCRMode right now? | 591 cpfseq opt_serial ; editing oCCRMode right now? |
| 473 bra option_inc_enum8_2 ; NO - check next option | 592 bra option_inc_enum8_2 ; NO - check next option |
| 474 IFDEF _external_sensor | 593 IFDEF _external_sensor |
| 475 btfsc analog_o2_input ; YES - does hosting OSTC have an analog interface? | 594 btfsc ext_input_s8_ana ; YES - S8/analog input available? |
| 476 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed | 595 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed |
| 477 btfsc optical_input ; does hosting OSTC have an optical interface? | 596 btfsc ext_input_optical ; - optical interface available? |
| 478 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed | 597 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed |
| 479 ENDIF ; _external_sensor | 598 ENDIF ; _external_sensor |
| 480 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP) | 599 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP) |
| 481 xorlw .1 ; - in sensor mode? | 600 xorlw .1 ; - in sensor mode? |
| 482 bnz option_inc_enum8_1a ; NO - continue with next check | 601 bnz option_inc_enum8_1a ; NO - continue with next check |
| 495 ; now some rather crude hack to switch off contingency mode if gas needs calculation is switched off | 614 ; now some rather crude hack to switch off contingency mode if gas needs calculation is switched off |
| 496 movlw 0x5A ; serial ID of option opt_calc_gasvolume | 615 movlw 0x5A ; serial ID of option opt_calc_gasvolume |
| 497 cpfseq opt_serial ; editing opt_calc_gasvolume right now? | 616 cpfseq opt_serial ; editing opt_calc_gasvolume right now? |
| 498 bra option_inc_enum8_3 ; NO - check next option | 617 bra option_inc_enum8_3 ; NO - check next option |
| 499 movf INDF1,W ; YES - get option value | 618 movf INDF1,W ; YES - get option value |
| 500 ; xorlw .0 ; - option value = off ? | 619 ;xorlw .0 ; - option value = off ? |
| 501 bnz option_inc_enum8_2_exit ; NO - done | 620 bnz option_inc_enum8_2_exit ; NO - done |
| 502 clrf WREG ; YES - force contingency to be off, too | 621 clrf WREG ; YES - force contingency to be off, too |
| 503 movff WREG,opt_gas_contingency_dive ; - ... | 622 movff WREG,opt_gas_contingency_dive ; - ... |
| 504 option_inc_enum8_2_exit: | 623 option_inc_enum8_2_exit: |
| 505 return | 624 return |
| 588 clrf INDF1 ; YES - force opt_gas_contingency_dive to off | 707 clrf INDF1 ; YES - force opt_gas_contingency_dive to off |
| 589 return ; - done | 708 return ; - done |
| 590 ENDIF ; _gas_contingency | 709 ENDIF ; _gas_contingency |
| 591 | 710 |
| 592 option_inc_enum8_6: | 711 option_inc_enum8_6: |
| 712 ; add more cross-checks with other option values here | |
| 593 return | 713 return |
| 594 | 714 |
| 595 | 715 |
| 596 option_inc_string: ; no editing available | 716 ;----------------------------------------------------------------------------- |
| 597 return | 717 ; Decrement an Option Value based on Type and min/max Boundary |
| 598 | 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 | |
| 599 | 895 |
| 600 IFNDEF _gauge_mode | 896 IFNDEF _gauge_mode |
| 601 option_cleanup_gauge: | 897 rcall option_cleanup_gauge ; check and correct gauge mode |
| 602 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | 898 ENDIF ; _gauge_mode |
| 603 xorlw .2 ; in Gauge mode? | |
| 604 bnz option_cleanup_gauge_1 ; NO - done | |
| 605 movff WREG,opt_dive_mode ; YES - setting not allowed, WREG is zero -> reset to OC mode | |
| 606 bsf options_changed ; - flag that EEPROM needs to be updated | |
| 607 option_cleanup_gauge_1: | |
| 608 return ; done | |
| 609 ENDIF | |
| 610 | |
| 611 | 899 |
| 612 IFDEF _ccr_pscr | 900 IFDEF _ccr_pscr |
| 613 global option_cleanup_oCCRMode | 901 rcall option_cleanup_oCCRMode ; check and correct CCR / pSCR mode |
| 614 global option_cleanup_oCCRMode_pSCR | |
| 615 global option_cleanup_oCCRMode_CCR | |
| 616 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 | |
| 617 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
| 618 xorlw .4 ; in pSCR mode? | |
| 619 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC | |
| 620 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode | |
| 621 banksel opt_ccr_mode ; YES - select options bank | |
| 622 bcf opt_ccr_mode,1 ; - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP, keeps sensor) | |
| 623 banksel common ; - back to bank common | |
| 624 bsf options_changed ; - flag that EEPROM needs to be updated | |
| 625 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode | |
| 626 IFDEF _external_sensor | |
| 627 btfsc analog_o2_input ; analog interface available? | |
| 628 return ; YES - setting 'sensor' allowed | |
| 629 btfsc optical_input ; does hosting OSTC have an optical interface? | |
| 630 return ; YES - setting 'sensor' allowed | |
| 631 ENDIF | |
| 632 movff opt_ccr_mode,WREG ; NO to both - get CCR mode | |
| 633 xorlw .1 ; - coding for sensor | |
| 634 tstfsz WREG ; - CCR mode = sensor? | |
| 635 return ; NO - setting allowed | |
| 636 banksel opt_ccr_mode ; YES - setting not allowed, select options bank | |
| 637 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) | |
| 638 banksel common ; - back to bank common | |
| 639 bsf options_changed ; - flag that EEPROM needs to be updated | |
| 640 return ; - done | |
| 641 ENDIF ; _ccr_pscr | 902 ENDIF ; _ccr_pscr |
| 642 | 903 |
| 643 | 904 IFDEF _helium |
| 905 rcall option_cleanup_sum_O2_He ; check and correct O2% + He% <= 100 +++ | |
| 906 ENDIF ; _helium | |
| 907 | |
| 908 return ; done | |
| 909 | |
| 910 | |
| 911 ;----------------------------------------------------------------------------- | |
| 912 ; Check and correct GFs so that GF_high >= GF_low | |
| 913 ; | |
| 644 option_cleanup_GF: | 914 option_cleanup_GF: |
| 645 ; cleanup normal GF | 915 ; cleanup normal GF |
| 646 movff opt_GF_high,WREG ; copy normal GF high to WREG | 916 movff opt_GF_high,WREG ; copy normal GF high to WREG |
| 647 movff opt_GF_low,mpr ; copy normal GF low to mpr | 917 movff opt_GF_low,mpr ; copy normal GF low to mpr |
| 648 cpfsgt mpr ; GF low > GF high ? | 918 cpfsgt mpr ; GF low > GF high ? |
| 652 cpfsgt mpr ; - mpr > 100 ? | 922 cpfsgt mpr ; - mpr > 100 ? |
| 653 bra option_cleanup_GF_1 ; NO - correct GF low to GF high | 923 bra option_cleanup_GF_1 ; NO - correct GF low to GF high |
| 654 movwf mpr ; YES - correct GF low to 100% | 924 movwf mpr ; YES - correct GF low to 100% |
| 655 option_cleanup_GF_1: | 925 option_cleanup_GF_1: |
| 656 movff mpr,opt_GF_low ; store corrected GF low | 926 movff mpr,opt_GF_low ; store corrected GF low |
| 657 bsf options_changed ; flag that EEPROM needs to be updated | 927 bsf option_changed ; flag that EEPROM needs to be updated |
| 658 option_cleanup_GF_2: | 928 option_cleanup_GF_2: |
| 659 ; cleanup alternative GF | 929 ; cleanup alternative GF |
| 660 movff opt_aGF_high,WREG ; copy alternative GF high to WREG | 930 movff opt_aGF_high,WREG ; copy alternative GF high to WREG |
| 661 movff opt_aGF_low,mpr ; copy alternative GF low to mpr | 931 movff opt_aGF_low,mpr ; copy alternative GF low to mpr |
| 662 cpfsgt mpr ; GF low > GF high ? | 932 cpfsgt mpr ; GF low > GF high ? |
| 666 cpfsgt mpr ; - mpr > 100 ? | 936 cpfsgt mpr ; - mpr > 100 ? |
| 667 bra option_cleanup_GF_3 ; NO - correct GF low to GF high | 937 bra option_cleanup_GF_3 ; NO - correct GF low to GF high |
| 668 movwf mpr ; YES - correct GF low to 100% | 938 movwf mpr ; YES - correct GF low to 100% |
| 669 option_cleanup_GF_3: | 939 option_cleanup_GF_3: |
| 670 movff mpr,opt_aGF_low ; store corrected GF low | 940 movff mpr,opt_aGF_low ; store corrected GF low |
| 671 bsf options_changed ; flag that EEPROM needs to be updated | 941 bsf option_changed ; flag that EEPROM needs to be updated |
| 672 option_cleanup_GF_4: | 942 option_cleanup_GF_4: |
| 673 return ; done | 943 return ; done |
| 674 | 944 |
| 675 | 945 ;----------------------------------------------------------------------------- |
| 676 ;============================================================================= | 946 ; Check and correct Dive Mode if Gauge Mode is not allowed |
| 677 ; Strcat option into FSR2 buffer | 947 ; |
| 678 ; | 948 IFNDEF _gauge_mode |
| 679 global option_draw ; STRCAT FRS0 option | 949 option_cleanup_gauge: |
| 680 option_draw: | 950 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) |
| 681 ; read type, default and register from table | 951 xorlw .2 ; in Gauge mode? |
| 682 rcall option_read_definition | 952 bnz option_cleanup_gauge_1 ; NO - done |
| 683 | 953 movff WREG,opt_dive_mode ; YES - setting not allowed, WREG is zero -> reset to OC mode |
| 684 ; switch on type | 954 bsf option_changed ; - flag that EEPROM needs to be updated |
| 685 movf opt_type,W ; get option type | 955 option_cleanup_gauge_1: |
| 686 bz option_draw_uint8 ; type0 = INT8 | 956 return ; done |
| 687 dcfsnz WREG | 957 ENDIF ; _gauge_mode |
| 688 bra option_draw_enum8 ; type1 = ENUM | 958 |
| 689 dcfsnz WREG | 959 |
| 690 bra option_draw_string ; type2 = string | 960 ;----------------------------------------------------------------------------- |
| 691 dcfsnz WREG | 961 ; Check and correct AutoSP and external Sensor Settings dependent on Modes |
| 692 bra option_draw_uint8_depth ; type3 = INT8 with automatic display in meters or feet | 962 ; |
| 693 return ; unknown, do nothing | 963 IFDEF _ccr_pscr |
| 694 | 964 global option_cleanup_oCCRMode |
| 695 option_draw_string: | 965 global option_cleanup_oCCRMode_pSCR |
| 696 movff POSTINC1,POSTINC2 | 966 global option_cleanup_oCCRMode_CCR |
| 697 decfsz opt_max | 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 |
| 698 bra option_draw_string | 968 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) |
| 699 return | 969 xorlw .4 ; in pSCR mode? |
| 700 | 970 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC |
| 701 option_draw_uint8_depth: | 971 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode |
| 702 TSTOSS opt_units ; using metric units (0=m, 1=ft)? | 972 banksel opt_ccr_mode ; YES - select options bank |
| 703 bra option_draw_uint8 ; YES - handle with standard output | 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) |
| 704 movff INDF1,lo ; NO - imperial, get value to lo | 974 banksel common ; - back to bank common |
| 705 call convert_meter_to_feet ; - convert value in lo from meter to feet | 975 bsf option_changed ; - flag that EEPROM needs to be updated |
| 706 bsf leftbind ; - print with left alignment | 976 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode |
| 707 output_16_3 ; - display only last three digits from a 16 bit value (0-999) | 977 IFDEF _external_sensor |
| 708 bcf leftbind ; - back to normal alignment | 978 btfsc ext_input_s8_ana ; S8/analog interface available? |
| 709 STRCAT_TEXT tFeets ; - print unit | 979 return ; YES - setting 'sensor' allowed |
| 710 bra option_draw_uint8_common ; - continue with common part | 980 btfsc ext_input_optical ; does hosting OSTC have an optical interface? |
| 711 | 981 return ; YES - setting 'sensor' allowed |
| 712 option_draw_uint8: | 982 ENDIF ; _external_sensor |
| 713 movff INDF1,lo ; draw value | 983 movff opt_ccr_mode,WREG ; NO to both - get CCR mode |
| 714 bsf leftbind | 984 xorlw .1 ; - coding for sensor |
| 715 output_8 | 985 tstfsz WREG ; - CCR mode = sensor? |
| 716 bcf leftbind | 986 return ; NO - setting allowed |
| 717 clrf INDF2 ; make sure to close string | 987 banksel opt_ccr_mode ; YES - setting not allowed, select options bank |
| 718 movf opt_unit+0,W ; is there a unit to append? | 988 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) |
| 719 iorwf opt_unit+1,W | 989 banksel common ; - back to bank common |
| 720 rcall option_draw_unit ; YES | 990 bsf option_changed ; - flag that EEPROM needs to be updated |
| 721 option_draw_uint8_common: | 991 return ; - done |
| 722 movf opt_default,W ; get default value | 992 ENDIF ; _ccr_pscr |
| 723 cpfseq lo ; compare with current value, equal? | 993 |
| 724 bra option_draw_uint8_2 ; NO - not default, add * | 994 |
| 725 return ; YES - default, done | 995 ;----------------------------------------------------------------------------- |
| 726 option_draw_uint8_2: | 996 ; Check and correct that O2% + He% <= 100% |
| 727 PUTC "*" ; print "*" | 997 ; |
| 728 return ; done | 998 IFDEF _helium |
| 729 | 999 option_cleanup_sum_O2_He: |
| 730 option_draw_unit: | 1000 lfsr FSR0,opt_gas_He_ratio-1 ; load (base address of He% array - 1) because of PREINC |
| 731 movff opt_unit+0,FSR1L | 1001 movlw 2*NUM_GAS ; load loop counter |
| 732 movff opt_unit+1,FSR1H | 1002 movwf lo ; ... |
| 733 goto strcat_text | 1003 option_cleanup_sum_loop: |
| 734 | 1004 movff PREINC1,up ; get He ratio |
| 735 | 1005 movlw -2*NUM_GAS ; address O2 ratio |
| 736 ;---- Draw an enumerated value (set of translated strings) | 1006 movff PLUSW0,hi ; get O2 ratio |
| 737 option_draw_enum8: | 1007 movlw .100 ; load WREG with 100% |
| 738 movf INDF1,W ; copy option value to WREG | 1008 bsf STATUS,C ; set carry = clear borrow |
| 739 movwf lo ; memorize option value, too | 1009 subfwb hi,W ; subtract O2% from WREG |
| 740 cpfslt opt_max ; option value > maximum permissible value ? | 1010 subfwb up,W ; subtract He% from WREG |
| 741 bra option_draw_enum8_0 ; NO - option value allowed | 1011 btfsc STATUS,C ; result negative? |
| 742 clrf WREG ; YES - to avoid printing rubbish, use first ENUM item instead | 1012 bra option_cleanup_sum_loop_1 ; NO - sum valid |
| 743 option_draw_enum8_0: | 1013 clrf INDF1 ; YES - heal by setting He% to zero |
| 744 addwf WREG ; current value *= 2 | 1014 bsf option_changed ; flag that EEPROM needs to be updated |
| 745 addwf opt_inc,W ; base text + 2 * current value | 1015 option_cleanup_sum_loop_1: |
| 746 movwf FSR1L ; load FSR1 | 1016 decfsz lo ; decrement loop counter, all done? |
| 747 movlw .0 ; propagate carry... | 1017 bra option_cleanup_sum_loop ; NO - loop |
| 748 addwfc opt_min,W ; ... | 1018 return ; YES - done |
| 749 movwf FSR1H ; ...into FSR1 | 1019 ENDIF ; _helium |
| 750 call strcat_text ; print text | 1020 |
| 751 movf opt_default,W ; get default value | |
| 752 cpfseq lo ; compare with memorized current value, equal? | |
| 753 bra option_draw_enum8_1 ; NO - not default, add * | |
| 754 return ; YES - default, done | |
| 755 option_draw_enum8_1: | |
| 756 PUTC "*" ; print "*" | |
| 757 return ; done | |
| 758 | 1021 |
| 759 ;----------------------------------------------------------------------------- | 1022 ;----------------------------------------------------------------------------- |
| 760 | 1023 |
| 761 END | 1024 END |
