Mercurial > public > hwos_code
annotate src/options.asm @ 628:cd58f7fc86db
3.05 stable work
author | heinrichsweikamp |
---|---|
date | Thu, 19 Sep 2019 12:01:29 +0200 |
parents | c40025d8e750 |
children | 185ba2f91f59 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
628 | 3 ; File options.asm next combined generation V3.04.3 |
0 | 4 ; |
5 ; Manage all options data. | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-07-12 : [jDG] Creation. | |
11 ; | |
12 | |
604 | 13 #include "hwos.inc" ; mandatory header |
582 | 14 #include "strings.inc" |
15 #include "convert.inc" | |
16 #include "ghostwriter.inc" | |
17 #include "eeprom_rs232.inc" | |
18 #include "external_flash.inc" | |
19 #include "wait.inc" | |
604 | 20 #include "shared_definitions.h" |
608 | 21 #include "gaslist.inc" |
0 | 22 |
582 | 23 extern write_eeprom |
24 extern read_eeprom | |
25 extern eeprom_serial_save,eeprom_opt_backup | |
26 extern option_table_begin,option_table_end | |
623 | 27 extern convert_meter_to_feet |
0 | 28 |
604 | 29 options CODE |
582 | 30 |
0 | 31 ;============================================================================= |
604 | 32 ; Reset all options to factory defaults |
0 | 33 ; |
34 ; INPUT: none | |
35 ; OUTPUT: none | |
36 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 | |
604 | 37 ; |
38 global option_reset_all ; reset all options to factory default | |
0 | 39 option_reset_all: |
582 | 40 clrf EEADRH |
41 read_int_eeprom .2 | |
604 | 42 tstfsz EEDATA ; number of total dives = 0 ? |
43 bra option_reset_all2 ; NO - skip resetting logbook | |
582 | 44 read_int_eeprom .3 |
604 | 45 tstfsz EEDATA ; number of total dives = 0 ? |
46 bra option_reset_all2 ; NO - skip resetting logbook | |
0 | 47 |
582 | 48 clrf EEDATA |
49 write_int_eeprom .4 | |
50 write_int_eeprom .5 | |
51 write_int_eeprom .6 | |
604 | 52 write_int_eeprom .2 ; delete total dive counter, too |
582 | 53 write_int_eeprom .3 |
604 | 54 call ext_flash_erase_logbook ; complete logbook |
0 | 55 |
56 option_reset_all2: | |
582 | 57 clrf lo |
58 clrf hi | |
604 | 59 call do_logoffset_common_write ; reset logbook offset |
60 movlw LOW(option_table_begin) ; point to option table begin | |
582 | 61 movwf FSR0L |
62 movlw HIGH(option_table_begin) | |
63 movwf FSR0H | |
0 | 64 option_reset_all_1: |
604 | 65 movlw LOW(option_table_end) ; get low byte of end of table address |
66 cpfseq FSR0L ; does it equal the current pointer position? | |
67 bra option_reset_all_2 ; NO - more options to process | |
68 movlw HIGH(option_table_end) ; get high byte of end of table address | |
69 cpfseq FSR0H ; does it equal the current pointer position? | |
70 bra option_reset_all_2 ; NO - more options to process | |
71 return ; YES to both - end of option table reached, done | |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
72 option_reset_all_2: |
604 | 73 rcall option_reset ; reset one option... |
74 bra option_reset_all_1 ; ... and loop | |
0 | 75 |
76 ;============================================================================= | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
77 ; Check all option and reset option if out of min/max boundary |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
78 ; |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
79 ; INPUT: none |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
80 ; OUTPUT: none |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
81 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 |
604 | 82 ; |
623 | 83 global option_check_all ; check all option and reset option if out of min/max boundary |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
84 option_check_all: |
623 | 85 bcf option_repaired ; no option needed repair up to now |
604 | 86 movlw LOW(option_table_begin) ; point to option table begin |
582 | 87 movwf FSR0L |
88 movlw HIGH(option_table_begin) | |
89 movwf FSR0H | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
90 option_check_all_1: |
604 | 91 movlw LOW(option_table_end) ; get low byte of end of table address |
92 cpfseq FSR0L ; does it equal the current pointer position? | |
93 bra option_check_all_2 ; NO - more options to process | |
94 movlw HIGH(option_table_end) ; get high byte of end of table address | |
95 cpfseq FSR0H ; does it equal the current pointer position? | |
96 bra option_check_all_2 ; NO - more options to process | |
608 | 97 bra option_check_all_3 ; YES to both - end of option table reached |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
98 option_check_all_2: |
604 | 99 rcall option_check ; check one option... |
100 bra option_check_all_1 ; ... and loop | |
608 | 101 option_check_all_3: |
623 | 102 bsf is_diluent_menu ; setup checking diluents |
608 | 103 call gaslist_cleanup_list ; check and correct multiple or none First diluent |
623 | 104 bcf is_diluent_menu ; setup checking gases |
608 | 105 call gaslist_cleanup_list ; check and correct multiple or none First gas |
628 | 106 IFNDEF _gauge_mode |
107 call option_cleanup_gauge ; check and correct Gauge mode | |
108 ENDIF | |
623 | 109 IFDEF _ccr_pscr |
110 call option_cleanup_oCCRMode ; check and correct CCR / pSCR mode | |
111 ENDIF | |
608 | 112 call option_cleanup_GF ; check and correct GFlow <= GFhigh |
113 return ; all done | |
114 | |
623 | 115 |
116 | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
117 ;============================================================================= |
0 | 118 ; Read option handle |
119 ; INPUT: FSR0 = option handle | |
120 ; OUTPUT: FSR1 = address of variable. | |
121 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
604 | 122 ; |
0 | 123 option_read: |
623 | 124 movff FSR0L,TBLPTRL ; set memory address of option data set, low byte |
125 movlw HIGH(option_table_begin) ; get table begin address, high byte | |
126 andlw 0xF0 ; keep only the upper nibble | |
127 iorwf FSR0H,W ; add the memory address of the option data set, high byte | |
128 movwf TBLPTRH ; set the resulting memory address, high byte | |
129 movlw UPPER(option_table_begin) ; get table begin address, upper byte | |
130 movwf TBLPTRU ; set memory address of option data set, upper byte | |
0 | 131 |
582 | 132 ; Read type, default and register from table |
133 tblrd*+ | |
134 movff TABLAT,opt_type | |
135 tblrd*+ | |
136 movff TABLAT,opt_default | |
137 tblrd*+ | |
138 movff TABLAT,opt_inc | |
139 tblrd*+ | |
140 movff TABLAT,opt_min | |
141 tblrd*+ | |
142 movff TABLAT,opt_max | |
143 tblrd*+ | |
144 movff TABLAT,opt_eeprom | |
145 tblrd*+ | |
146 movff TABLAT,opt_unit+0 | |
147 tblrd*+ | |
148 movff TABLAT,opt_unit+1 | |
149 tblrd*+ | |
150 movff TABLAT,FSR1L | |
151 tblrd*+ | |
152 movff TABLAT,FSR1H | |
623 | 153 movff TBLPTRL,FSR0L ; advance handle to next option data set (used for reset_all) |
582 | 154 movff TBLPTRH,FSR0H |
155 return | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
156 |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
157 ;============================================================================= |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
158 ; Check one option and reset if it's out of it's min/max boundaries |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
159 ; INPUT: FSR0 = option handle |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
160 ; OUTPUT: none |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
161 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2, lo |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
162 ; |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
163 option_check: |
582 | 164 ; Read type, default and register from table |
165 rcall option_read | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
166 |
582 | 167 ; Switch on type |
604 | 168 movf opt_type,W ; get option type |
623 | 169 xorlw .2 ; type == STRING ? |
604 | 170 bz option_check_string ; YES |
171 movf opt_type,W ; get option type (again) | |
623 | 172 xorlw .1 ; type == ENUM8 ? |
604 | 173 bz option_check_enum8 ; YES - check if lower then max. value only |
174 ; NO to all - must be integer then | |
175 tstfsz opt_min ; opt_min = 0 ? | |
176 bra option_check_both ; NO - check it | |
177 bra option_check_enum8 ; check max only | |
220
effd7259f5a5
make button sensitivity configurable (cR hardware)
heinrichsweikamp
parents:
185
diff
changeset
|
178 |
effd7259f5a5
make button sensitivity configurable (cR hardware)
heinrichsweikamp
parents:
185
diff
changeset
|
179 option_check_both: |
604 | 180 decf opt_min,W ; check against minimum value |
623 | 181 cpfsgt INDF1 ; bigger than opt_min - 1 ? |
604 | 182 bra option_check_reset ; NO - reset option |
183 option_check_enum8: ; check against maximum value | |
184 infsnz opt_max,W ; max = 255? | |
185 return ; YES - ignore the max. test | |
186 cpfslt INDF1 ; NO - smaller then opt_max + 1 ? | |
187 bra option_check_reset ; NO - reset option | |
623 | 188 return ; YES - within range, return |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
189 |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
190 option_check_reset: |
582 | 191 movff opt_default,INDF1 ; reset option to default |
623 | 192 bsf option_repaired ; flag that an option was repaired |
604 | 193 return ; done |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
194 |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
195 option_check_string: |
582 | 196 return |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
197 |
0 | 198 ;============================================================================= |
604 | 199 ; Reset an option to its default value |
0 | 200 ; INPUT: FSR0 = option handle |
201 ; OUTPUT: none | |
202 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 | |
203 ; | |
604 | 204 global option_reset ; reset FSR0 option to factory default |
0 | 205 option_reset: |
582 | 206 ; Read type, default and register from table |
604 | 207 rcall option_read ; read option data |
208 movf opt_type,W ; get option type | |
209 xorlw 2 ; Type == STRING ? | |
210 bz opt_reset_string ; YES - special copy | |
211 movff opt_default,INDF1 ; NO - just a 8 bit indirect copy | |
582 | 212 return |
0 | 213 opt_reset_string: |
604 | 214 movff FSR1L,FSR2L ; set string destination address |
215 movff FSR1H,FSR2H ; ... | |
216 movff opt_default+0,FSR1L ; get handle to multi-lingual text in FSR1 | |
217 movff opt_default+1,FSR1H ; ... | |
582 | 218 movff TBLPTRL,opt_backup_tbl+0 ; TBLPTR trashed by text routine... |
604 | 219 movff TBLPTRH,opt_backup_tbl+1 ; ... |
220 movff TBLPTRU,opt_backup_tbl+2 ; ... | |
221 call strcat_text ; copy translated text to FSR2 | |
222 movff opt_backup_tbl+0,TBLPTRL ; restore TBLPTR | |
223 movff opt_backup_tbl+1,TBLPTRH ; ... | |
224 movff opt_backup_tbl+2,TBLPTRU ; ... | |
0 | 225 |
582 | 226 return |
0 | 227 |
228 ;============================================================================= | |
229 ; Save all options to EEPROM | |
604 | 230 ; |
231 global option_save_all ; save options to EEPROM | |
0 | 232 option_save_all: |
628 | 233 bcf PIR3,RC2IE |
582 | 234 ;---- Save option serial into EEPROM to detect reset and new version |
235 movlw LOW(eeprom_serial_save) | |
236 movwf EEADR | |
237 movlw HIGH(eeprom_serial_save) | |
238 movwf EEADRH | |
239 movlw LOW(eeprom_opt_serial) | |
240 movwf EEDATA | |
241 call write_eeprom | |
242 incf EEADR,F | |
243 movlw HIGH(eeprom_opt_serial) | |
244 movwf EEDATA | |
245 call write_eeprom | |
246 | |
247 ;---- Save all options | |
248 movlw LOW(option_table_begin) | |
249 movwf FSR0L | |
250 movlw HIGH(option_table_begin) | |
251 movwf FSR0H | |
0 | 252 |
253 option_save_all_1: | |
582 | 254 movlw LOW(option_table_end) |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
255 cpfseq FSR0L |
604 | 256 bra option_save_all_2 ; not yet done... |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
257 movlw HIGH(option_table_end) |
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
258 cpfseq FSR0H |
604 | 259 bra option_save_all_2 ; not yet done... |
628 | 260 bsf PIR3,RC2IE |
604 | 261 return ; all done |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
262 option_save_all_2: |
604 | 263 rcall option_save ; save one option... |
264 bra option_save_all_1 ; ...and loop | |
265 | |
0 | 266 |
582 | 267 global option_save |
0 | 268 option_save: |
582 | 269 rcall option_read |
604 | 270 incf opt_eeprom,W ; should we save it ? |
582 | 271 btfsc STATUS,Z ; EEPROM address is FFh ? |
604 | 272 return ; YES - nothing to do |
273 movf opt_eeprom,W ; compute backup address in EEPROM | |
274 addlw LOW(eeprom_opt_backup) ; add offset | |
582 | 275 movwf EEADR |
276 movlw HIGH(eeprom_opt_backup) | |
604 | 277 btfsc STATUS,C ; > 256 ? |
278 addlw .1 ; YES - +1 | |
582 | 279 movwf EEADRH |
604 | 280 movf opt_type,W ; get option type |
281 xorlw 2 ; option type is string ? | |
282 bz option_save_string ; YES | |
623 | 283 movff INDF1,EEDATA ; NO - one byte to be saved to EEPROM |
284 btfss EEADRH,1 ; - EEADR:EEADRH < 512 ? | |
285 call write_eeprom ; YES - write | |
286 return ; (NO) - done | |
604 | 287 option_save_string: |
288 movff POSTINC1,EEDATA ; write one byte | |
289 btfss EEADRH,1 ; EEADR:EEADRH < 512 ? | |
623 | 290 call write_eeprom ; YES - write |
291 infsnz EEADR,F ; (NO) - increment EEPROM address | |
292 incf EEADRH,F ; - ... | |
293 decfsz opt_max ; - decrement string length, done? | |
294 bra option_save_string ; NO - loop | |
295 return ; YES | |
582 | 296 |
0 | 297 ;============================================================================= |
298 | |
604 | 299 global option_restore_all ; restore options from EEPROM |
0 | 300 option_restore_all: |
582 | 301 ;---- Read option serial from EEPROM |
302 movlw LOW(eeprom_serial_save) | |
303 movwf EEADR | |
304 movlw HIGH(eeprom_serial_save) | |
305 movf EEADRH | |
306 call read_eeprom | |
307 movlw LOW(eeprom_opt_serial) | |
308 xorwf EEDATA,W | |
604 | 309 bnz option_restore_bad ; auto reset if changed |
582 | 310 incf EEADR,F |
311 call read_eeprom | |
312 movlw HIGH(eeprom_opt_serial) | |
313 xorwf EEDATA,W | |
604 | 314 bz option_restore_ok ; auto reset if changed |
0 | 315 |
316 option_restore_bad: | |
604 | 317 call option_reset_all ; reset RAM contains |
318 goto option_save_all ; then save to EEPROM | |
0 | 319 |
582 | 320 ;---- Proper restore |
0 | 321 option_restore_ok: |
582 | 322 movlw LOW(option_table_begin) |
323 movwf FSR0L | |
324 movlw HIGH(option_table_begin) | |
325 movwf FSR0H | |
0 | 326 |
327 option_restore_all_1: | |
582 | 328 movlw LOW(option_table_end) |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
329 cpfseq FSR0L |
604 | 330 bra option_restore_all_2 ; not yet done... |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
331 movlw HIGH(option_table_end) |
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
332 cpfseq FSR0H |
604 | 333 bra option_restore_all_2 ; not yet done... |
334 return ; all done | |
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
560
diff
changeset
|
335 option_restore_all_2: |
604 | 336 rcall option_restore ; Restore one option |
337 bra option_restore_all_1 ; and loop | |
0 | 338 |
339 option_restore: | |
582 | 340 rcall option_read |
604 | 341 incf opt_eeprom,W ; shall we save it ? |
582 | 342 btfsc STATUS,Z ; EEPROM address is FFh ? |
604 | 343 return ; YES - nothing to do. |
344 movf opt_eeprom,W ; compute backup address in EEPROM | |
345 addlw LOW(eeprom_opt_backup) ; add offset | |
582 | 346 movwf EEADR |
347 movlw HIGH(eeprom_opt_backup) | |
604 | 348 btfsc STATUS,C ; > 256 ? |
349 addlw .1 ; YES - +1 | |
582 | 350 movwf EEADRH |
604 | 351 movf opt_type,W ; get option type |
352 xorlw 2 ; Option type is string? | |
353 bz option_restore_string ; YES | |
354 call read_eeprom ; read one byte from EEPROM | |
355 movff EEDATA, INDF1 ; restore option register | |
582 | 356 return |
0 | 357 option_restore_string: |
604 | 358 call read_eeprom ; read one byte, and... |
359 movff EEDATA,POSTINC1 ; ... restore it | |
582 | 360 infsnz EEADR,F |
361 incf EEADRH,F | |
604 | 362 decfsz opt_max ; decrement string length |
363 bra option_restore_string ; loop while not finished | |
582 | 364 return |
0 | 365 |
366 ;============================================================================= | |
604 | 367 ; Increment an option, based on type, and boundary |
0 | 368 ; INPUT: FSR0 = option handle |
369 ; OUTPUT: none | |
370 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
604 | 371 ; |
372 global option_inc ; increment FSR0 option | |
0 | 373 option_inc: |
604 | 374 ; read type, default and register from table |
582 | 375 rcall option_read |
376 | |
604 | 377 ; switch on type |
582 | 378 movf opt_type,W |
379 bz option_inc_uint8 | |
380 dcfsnz WREG | |
381 bra option_inc_enum8 | |
382 dcfsnz WREG | |
383 bra option_inc_string | |
0 | 384 |
604 | 385 option_inc_uint8: ; default type too... |
582 | 386 movf INDF1,W |
387 addwf opt_inc,W | |
388 cpfslt opt_max | |
604 | 389 bra option_inc_uint8_0 |
582 | 390 movf opt_min,W |
604 | 391 option_inc_uint8_0: |
582 | 392 movwf INDF1 |
604 | 393 option_inc_uint8_1: |
533
dfac393b2199
CHANGE: CCR Calibration gas range limited to O2% 21-25 and 95-100 to save button presses
heinrichsweikamp
parents:
418
diff
changeset
|
394 ; Now some rather crude hack into this routine to make CCR Calibration more convenient: |
608 | 395 movlw .149 ; EEPROM address of option CalGasO2 |
604 | 396 cpfseq opt_eeprom ; editing CalGasO2 right now? |
608 | 397 bra option_inc_uint8_2 ; NO - check next option |
604 | 398 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR |
399 decfsz WREG,W ; - in CCR mode? | |
400 return ; NO - done | |
401 movlw .26 ; YES - | |
402 cpfseq INDF1 ; - option value = 26 ? | |
403 return ; NO - done | |
404 movlw .95 ; YES - advance it to 95 | |
405 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
|
406 return |
608 | 407 option_inc_uint8_2: |
408 movlw .12 ; EEPROM address of option opt_GF_low | |
409 cpfseq opt_eeprom ; editing opt_GF_low right now? | |
410 bra option_inc_uint8_3 ; NO - check next option | |
411 movff opt_GF_high,WREG ; get value of associated GF high into WREG | |
412 cpfsgt INDF1 ; GF low > GF high? | |
413 return ; NO - setting ok, done | |
414 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
415 return ; - done | |
416 option_inc_uint8_3: | |
417 movlw .13 ; EEPROM address of option opt_GF_high | |
418 cpfseq opt_eeprom ; editing opt_GF_high right now? | |
419 bra option_inc_uint8_4 ; NO - check next option | |
420 movff opt_GF_low,WREG ; get value of associated GF low into WREG | |
421 cpfslt INDF1 ; GF high < GF low? | |
422 return ; NO - setting ok, done | |
423 movwf INDF1 ; YES - rise GF high to GF low | |
424 return ; - done | |
425 option_inc_uint8_4: | |
426 movlw .17 ; EEPROM address of option opt_aGF_low | |
427 cpfseq opt_eeprom ; editing opt_aGF_low right now? | |
428 bra option_inc_uint8_5 ; NO - check next option | |
429 movff opt_aGF_high,WREG ; get value of associated GF high into WREG | |
430 cpfsgt INDF1 ; GF low > GF high? | |
431 return ; NO - setting ok, done | |
432 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
433 return ; - done | |
434 option_inc_uint8_5: | |
435 movlw .18 ; EEPROM address of option opt_aGF_high | |
436 cpfseq opt_eeprom ; editing opt_aGF_high right now? | |
437 bra option_inc_uint8_6 ; NO - check next option | |
438 movff opt_aGF_low,WREG ; get value of associated GF low into WREG | |
439 cpfslt INDF1 ; GF high < GF low? | |
440 return ; NO - setting ok, done | |
441 movwf INDF1 ; YES - rise GF high to GF low | |
442 return ; - done | |
443 option_inc_uint8_6: | |
444 return ; all done | |
445 | |
0 | 446 |
604 | 447 option_inc_enum8: ; always +1 |
582 | 448 incf INDF1,W |
449 cpfsgt opt_max | |
450 clrf WREG | |
451 movwf INDF1 | |
604 | 452 option_inc_enum8_1: |
623 | 453 IFDEF _ccr_pscr |
604 | 454 ; Now some rather crude hack into this routine to unify CCR & pSCR mode setting |
455 movlw .25 ; EEPROM address of option oCCRMode | |
456 cpfseq opt_eeprom ; editing oCCRMode right now? | |
457 bra option_inc_enum8_2 ; NO - check next option | |
623 | 458 IFDEF _external_sensor |
604 | 459 btfsc analog_o2_input ; YES - does hosting OSTC have an analog interface? |
460 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed | |
461 btfsc optical_input ; does hosting OSTC have an optical interface? | |
462 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed | |
623 | 463 ENDIF ; _external_sensor |
604 | 464 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP) |
465 xorlw .1 ; - in sensor mode? | |
466 bnz option_inc_enum8_1a ; NO - continue with next check | |
467 incf INDF1,F ; YES - advance option value to AutoSP | |
468 option_inc_enum8_1a: | |
469 movff opt_dive_mode,WREG ; get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
470 xorlw .4 ; in pSCR mode? | |
471 bnz option_inc_enum8_1_exit ; NO - done | |
472 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP) | |
473 option_inc_enum8_1_exit: | |
474 return ; done | |
623 | 475 ENDIF ; _ccr_pscr |
604 | 476 option_inc_enum8_2: |
477 ; (unused) | |
478 option_inc_enum8_3: | |
479 ; Now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode | |
480 movlw .8 ; EEPROM address of option opt_dive_mode | |
481 cpfseq opt_eeprom ; editing opt_dive_mode right now? | |
482 bra option_inc_enum8_4 ; NO - check next option | |
623 | 483 movf INDF1,W ; YES - get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR |
484 xorlw .1 ; in CCR mode? | |
485 bnz option_inc_enum8_3a ; NO - in some other mode | |
486 IFNDEF _ccr_pscr | |
487 incf INDF1,f ; YES - no CCR mode compiled in, advance to gauge mode | |
628 | 488 bra option_inc_enum8_3a ; - check if gauge mode is available |
623 | 489 ENDIF ; _ccr_pscr |
490 IFDEF _rx_functions | |
491 global option_cleanup_oTrMode_CCR ; embedded clean-up entry-point | |
604 | 492 option_cleanup_oTrMode_CCR: ; entry point from cleanup during restart |
623 | 493 movff opt_TR_mode,WREG ; get TR mode |
494 xorlw .2 ; mode = 2 (ind.double)? | |
495 bnz option_inc_enum8_3_exit ; NO - done | |
496 bra option_inc_enum8_3_reset ; YES - revert mode to 1 (on) | |
497 ENDIF ; _rx_functions | |
604 | 498 option_inc_enum8_3a: ; any mode other than CCR |
628 | 499 IFNDEF _gauge_mode |
500 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
501 xorlw .2 ; in Gauge mode? | |
502 bnz option_inc_enum8_3b ; NO - in some other mode | |
503 incf INDF1,f ; YES - no Gauge mode compiled in, advance to Apnea mode | |
504 bra option_inc_enum8_3_exit ; - done (Apnea mode is always available) | |
505 ENDIF ; _gauge_mode | |
506 option_inc_enum8_3b: | |
623 | 507 IFNDEF _ccr_pscr |
508 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
509 xorlw .4 ; in pSCR mode? | |
628 | 510 bnz option_inc_enum8_3c ; NO - in some other mode |
623 | 511 clrf INDF1 ; YES - no pSCR mode compiled in, advance to 0 "OC" |
512 bra option_inc_enum8_3_exit ; - done | |
513 ENDIF ; _ccr_pscr | |
628 | 514 option_inc_enum8_3c: |
623 | 515 global option_cleanup_oTrMode_no_CCR ; embedded clean-up entry-point |
604 | 516 option_cleanup_oTrMode_no_CCR: ; entry point from cleanup during restart |
517 movff opt_TR_mode,WREG ; get TR mode | |
518 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
519 bnz option_inc_enum8_3_exit ; NO - done | |
520 option_inc_enum8_3_reset: ; YES - revert to mode 1 (on) | |
521 movlw .1 ; load coding of mode "on" | |
522 movff WREG,opt_TR_mode ; write to option | |
523 option_inc_enum8_3_exit: | |
524 return ; done | |
628 | 525 |
604 | 526 option_inc_enum8_4: |
623 | 527 IFDEF _rx_functions |
604 | 528 ; Now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode |
529 movlw .222 ; EEPROM address of option opt_TR_mode | |
530 cpfseq opt_eeprom ; editing opt_TR_mode right now? | |
531 bra option_inc_enum8_5 ; NO - check next option | |
532 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
533 decfsz WREG,W ; dive mode = 1 CCR? | |
534 bra option_inc_enum8_4a ; NO - in any other mode | |
535 movf INDF1,W ; YES - get option value (TR mode) | |
536 xorlw .2 ; - mode = 2 (ind.double)? | |
537 bnz option_inc_enum8_4_exit ; NO - done | |
538 incf INDF1,F ; YES - advance option value to 3 (CCR Dil+O2) | |
539 bra option_inc_enum8_4_exit ; - done | |
540 option_inc_enum8_4a: ; any mode other than CCR | |
541 movf INDF1,W ; get option value (TR mode) | |
542 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
543 bnz option_inc_enum8_4_exit ; NO - done | |
544 clrf INDF1 ; YES - advance option value to 0 "off" | |
545 option_inc_enum8_4_exit: | |
546 return ; done | |
623 | 547 ENDIF ; _rx_functions |
604 | 548 option_inc_enum8_5: |
582 | 549 return |
550 | |
551 | |
604 | 552 option_inc_string: ; no editing available |
582 | 553 return |
0 | 554 |
604 | 555 |
628 | 556 IFNDEF _gauge_mode |
557 option_cleanup_gauge: | |
558 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
559 xorlw .2 ; in Gauge mode? | |
560 bnz option_cleanup_gauge_1 ; NO - done | |
561 banksel opt_dive_mode ; YES - setting not allowed, select options bank | |
562 clrf opt_dive_mode ; - reset to OC mode | |
563 banksel common ; - back to bank common | |
564 option_cleanup_gauge_1: | |
565 return ; done | |
566 ENDIF | |
567 | |
568 | |
623 | 569 IFDEF _ccr_pscr |
604 | 570 global option_cleanup_oCCRMode |
571 global option_cleanup_oCCRMode_pSCR | |
572 global option_cleanup_oCCRMode_CCR | |
573 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 | |
623 | 574 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) |
604 | 575 xorlw .4 ; in pSCR mode? |
576 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC | |
577 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode | |
623 | 578 banksel opt_ccr_mode ; YES - select options bank |
579 bcf opt_ccr_mode,1 ; - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP, keeps sensor) | |
580 banksel common ; - back to bank common | |
581 bsf option_repaired ; - flag that an option was repaired | |
604 | 582 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode |
623 | 583 IFDEF _external_sensor |
584 btfsc analog_o2_input ; analog interface available? | |
585 return ; YES - setting 'sensor' allowed | |
604 | 586 btfsc optical_input ; does hosting OSTC have an optical interface? |
623 | 587 return ; YES - setting 'sensor' allowed |
588 ENDIF | |
589 movff opt_ccr_mode,WREG ; NO to both - get CCR mode | |
590 xorlw .1 ; - coding for sensor | |
591 tstfsz WREG ; - CCR mode = sensor? | |
592 return ; NO - setting allowed | |
593 banksel opt_ccr_mode ; YES - setting not allowed, select options bank | |
594 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) | |
595 banksel common ; - back to bank common | |
596 bsf option_repaired ; - flag that an option was repaired | |
597 return ; - done | |
598 ENDIF ; _ccr_pscr | |
599 | |
604 | 600 |
608 | 601 option_cleanup_GF: |
602 ; cleanup normal GF | |
603 movff opt_GF_high,WREG ; copy normal GF high to WREG | |
623 | 604 movff opt_GF_low,mpr ; copy normal GF low to mpr |
605 cpfsgt mpr ; GF low > GF high ? | |
608 | 606 bra option_cleanup_GF_2 ; NO - option ok, check next option |
623 | 607 movwf mpr ; YES - copy GF high to mpr |
608 | 608 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 609 cpfsgt mpr ; - mpr > 100 ? |
608 | 610 bra option_cleanup_GF_1 ; NO - correct GF low to GF high |
623 | 611 movwf mpr ; YES - correct GF low to 100% |
608 | 612 option_cleanup_GF_1: |
623 | 613 movff mpr,opt_GF_low ; store corrected GF low |
614 bsf option_repaired ; flag that an option was repaired | |
608 | 615 option_cleanup_GF_2: |
616 ; cleanup alternative GF | |
617 movff opt_aGF_high,WREG ; copy alternative GF high to WREG | |
623 | 618 movff opt_aGF_low,mpr ; copy alternative GF low to mpr |
619 cpfsgt mpr ; GF low > GF high ? | |
608 | 620 bra option_cleanup_GF_4 ; NO - option ok, check next option |
623 | 621 movwf mpr ; YES - copy GF high to mpr |
608 | 622 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 623 cpfsgt mpr ; - mpr > 100 ? |
608 | 624 bra option_cleanup_GF_3 ; NO - correct GF low to GF high |
623 | 625 movwf mpr ; YES - correct GF low to 100% |
608 | 626 option_cleanup_GF_3: |
623 | 627 movff mpr,opt_aGF_low ; store corrected GF low |
628 bsf option_repaired ; flag that an option was repaired | |
608 | 629 option_cleanup_GF_4: |
630 return ; done | |
631 | |
604 | 632 |
0 | 633 ;============================================================================= |
604 | 634 ; Strcat option into FSR2 buffer |
635 ; | |
636 global option_draw ; STRCAT FRS0 option | |
0 | 637 option_draw: |
582 | 638 ; Read type, default and register from table |
639 rcall option_read | |
640 | |
641 ; Switch on type | |
642 movf opt_type,W | |
623 | 643 bz option_draw_uint8 ; type0 = INT8 |
644 dcfsnz WREG | |
645 bra option_draw_enum8 ; type1 = ENUM | |
582 | 646 dcfsnz WREG |
623 | 647 bra option_draw_string ; type2 = string |
582 | 648 dcfsnz WREG |
623 | 649 bra option_draw_uint8_depth ; type3 = INT8 with automatic display in meters or feet |
604 | 650 return ; unknown, return |
623 | 651 |
604 | 652 option_draw_string: |
653 movff POSTINC1,POSTINC2 | |
654 decfsz opt_max | |
655 bra option_draw_string | |
656 return | |
657 | |
623 | 658 option_draw_uint8_depth: |
659 TSTOSS opt_units ; using metric units (0=m, 1=ft)? | |
660 bra option_draw_uint8 ; YES - handle with standard output | |
661 movff INDF1,lo ; NO - imperial, get value to lo | |
662 call convert_meter_to_feet ; - convert value in lo from meter to feet | |
663 bsf leftbind ; - print with left alignment | |
664 output_16_3 ; - display only last three digits from a 16 bit value (0-999) | |
665 bcf leftbind ; - back to normal alignment | |
666 STRCAT_TEXT tFeets ; - print unit | |
667 bra option_draw_uint8_common ; - continue with common part | |
0 | 668 |
669 option_draw_uint8: | |
604 | 670 movff INDF1,lo ; draw value |
582 | 671 bsf leftbind |
672 output_8 | |
673 bcf leftbind | |
604 | 674 clrf INDF2 ; make sure to close string |
675 movf opt_unit+0,W ; is there a unit to append? | |
582 | 676 iorwf opt_unit+1,W |
604 | 677 rcall option_draw_unit ; YES |
623 | 678 option_draw_uint8_common: |
604 | 679 movf opt_default,W ; get default value |
680 cpfseq lo ; compare with current value, equal? | |
681 bra option_draw_uint8_2 ; NO - not default, add * | |
682 return ; YES - default, done | |
0 | 683 option_draw_uint8_2: |
604 | 684 PUTC "*" ; print "*" |
685 return ; done | |
623 | 686 |
0 | 687 option_draw_unit: |
582 | 688 movff opt_unit+0,FSR1L |
689 movff opt_unit+1,FSR1H | |
690 goto strcat_text | |
0 | 691 |
692 | |
693 ;---- Draw an enumerated value (set of translated strings) | |
694 option_draw_enum8: | |
628 | 695 movff INDF1,lo ; memorize current value |
696 movf INDF1,W ; copy current value to WREG | |
697 cpfsgt opt_max ; max value (= highest usable value + 1) > current value? | |
698 clrf WREG ; NO - to avoid printing rubbish, reset to first value | |
699 addwf WREG ; current value *= 2 | |
700 addwf opt_inc,W ; base text + 2 * current value | |
701 movwf FSR1L ; load FSR0 | |
702 movlw .0 ; propagate carry... | |
703 addwfc opt_min,W ; ... | |
604 | 704 movwf FSR1H ; ...into FSR1 |
628 | 705 call strcat_text ; print text |
706 movf opt_default,W ; get default value | |
707 cpfseq lo ; compare with memorized current value, equal? | |
708 bra option_draw_enum8_1 ; NO - not default, add * | |
709 return ; YES - default, done | |
710 option_draw_enum8_1: | |
711 PUTC "*" ; print "*" | |
712 return ; done | |
713 | |
0 | 714 |
623 | 715 ;----------------------------------------------------------------------------- |
0 | 716 |
623 | 717 END |