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