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