Mercurial > public > hwos_code
annotate src/options.asm @ 632:0347acdf6d8e
changelog updates
author | heinrichsweikamp |
---|---|
date | Sat, 29 Feb 2020 16:57:45 +0100 |
parents | 185ba2f91f59 |
children | 4050675965ea |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
631 | 3 ; File options.asm next combined generation V3.08.8 |
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 option_table_begin,option_table_end | |
623 | 26 extern convert_meter_to_feet |
0 | 27 |
604 | 28 options CODE |
582 | 29 |
0 | 30 ;============================================================================= |
631 | 31 ; Reset all options to factory defaults (in memory only) |
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: |
631 | 39 call eeprom_total_dives_read ; read total number of dives |
40 tstfsz mpr+0 ; number of total dives, low byte = 0 ? | |
41 bra option_reset_all_1 ; NO - skip resetting logbook | |
42 tstfsz mpr+1 ; number of total dives, high byte = 0 ? | |
43 bra option_reset_all_1 ; NO - skip resetting logbook | |
0 | 44 |
631 | 45 ; reset logbook |
46 call erase_complete_logbook ; erase complete logbook | |
623 | 47 |
631 | 48 ; reset logbook offset |
49 CLRI mpr ; set logbook offset to zero | |
50 call eeprom_log_offset_write ; store logbook offset | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
51 |
631 | 52 option_reset_all_1: |
53 lfsr FSR0,option_table_begin ; point to start of option definition table | |
54 option_reset_all_loop: | |
55 rcall option_reset ; reset option | |
56 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
57 bra option_reset_all_loop ; NO - do next option | |
58 return ; YES - done | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
59 |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
18
diff
changeset
|
60 |
0 | 61 ;============================================================================= |
604 | 62 ; Reset an option to its default value |
0 | 63 ; INPUT: FSR0 = option handle |
64 ; OUTPUT: none | |
65 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 | |
66 ; | |
631 | 67 global option_reset ; reset option value to default |
0 | 68 option_reset: |
631 | 69 ; read type, default and register from table |
70 rcall option_read_definition ; read option definition | |
71 | |
72 option_reset_loaded: ; entry point with option definition already read | |
73 bsf option_repaired ; flag that an option was repaired | |
74 bsf options_changed ; flag that EEPROM needs to be updated | |
604 | 75 movf opt_type,W ; get option type |
631 | 76 xorlw .2 ; type = STRING ? |
77 bz opt_reset_string ; YES - string copy | |
78 movff opt_default,INDF1 ; NO - 1 byte copy | |
79 return ; - done | |
80 | |
0 | 81 opt_reset_string: |
604 | 82 movff FSR1L,FSR2L ; set string destination address |
83 movff FSR1H,FSR2H ; ... | |
84 movff opt_default+0,FSR1L ; get handle to multi-lingual text in FSR1 | |
85 movff opt_default+1,FSR1H ; ... | |
631 | 86 movff TBLPTRL,mpr+0 ; TBLPTR will be trashed by text routine, so make a back-up |
87 movff TBLPTRH,mpr+1 ; ... | |
88 movff TBLPTRU,mpr+2 ; ... | |
604 | 89 call strcat_text ; copy translated text to FSR2 |
631 | 90 movff mpr+0,TBLPTRL ; restore TBLPTR |
91 movff mpr+1,TBLPTRH ; ... | |
92 movff mpr+2,TBLPTRU ; ... | |
93 return ; done | |
94 | |
0 | 95 |
631 | 96 ;============================================================================= |
97 ; Read option definition | |
98 ; INPUT: FSR0 = option handle | |
99 ; OUTPUT: FSR1 = address of variable. | |
100 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
101 ; | |
102 option_read_definition: | |
103 movff FSR0L,TBLPTRL ; low byte : set memory address of option data set | |
104 movlw HIGH(option_table_begin) ; high byte : get table start address | |
105 andlw 0xF0 ; keep only the upper nibble | |
106 iorwf FSR0H,W ; add the memory address of the option data set | |
107 movwf TBLPTRH ; set the resulting memory address | |
108 movlw UPPER(option_table_begin) ; upper byte: get table start address | |
109 movwf TBLPTRU ; set memory address of option data set | |
110 | |
111 lfsr FSR1,opt_type ; load FSR1 with base address of option definition vars | |
112 movlw opt_definiton_bytes ; get number of bytes to copy | |
113 movwf eeprom_loop ; initialize loop counter (using an EEPROM variable here) | |
114 option_read_definition_loop: | |
115 tblrd*+ ; read one byte from program memory and increment address | |
116 movff TABLAT,POSTINC1 ; transfer byte from program memory to memory | |
117 decfsz eeprom_loop,F ; all bytes done? | |
118 bra option_read_definition_loop ; NO - loop | |
119 tblrd* ; YES - read one byte ahead without incrementing address | |
120 movff TABLAT,POSTINC1 ; - store byte | |
121 movff opt_memory+0,FSR1L ; - load FSR1 with the address of the option value variable | |
122 movff opt_memory+1,FSR1H ; - ... | |
123 movff TBLPTRL,FSR0L ; - advance handle to the next option definition data set | |
124 movff TBLPTRH,FSR0H ; - ... | |
125 return ; - done | |
126 | |
0 | 127 |
128 ;============================================================================= | |
631 | 129 ; Check one option and reset its value if it is out of min/max boundary |
130 ; INPUT: opt_* vars and FSR1 | |
131 ; OUTPUT: option value set to default if out of min/max | |
132 ; TRASH: WREG | |
604 | 133 ; |
631 | 134 option_check_loaded: |
135 ; switch on type | |
136 movf opt_type,W ; get type | |
137 bz option_check_uint8 ; type 0: INT8 | |
138 dcfsnz WREG ; decrement | |
139 bra option_check_enum8 ; type 1: ENUM | |
140 dcfsnz WREG ; decrement | |
141 bra option_check_string ; type 2: STRING | |
142 ;bra option_check_uint8 ; type 3: INT8 | |
143 | |
144 option_check_uint8: | |
145 tstfsz opt_min ; opt_min = 0 ? | |
146 bra option_check_min ; NO - check it | |
147 bra option_check_enum8 ; YES - continue with check for maximum | |
148 | |
149 option_check_min: | |
150 decf opt_min,W ; get (minimum permissible value - 1) into WREG | |
151 cpfsgt INDF1 ; option value > (minimum permissible value - 1) ? | |
152 bra option_reset_loaded ; NO - reset option value | |
153 ;bra option_check_enum8 ; YES - continue with check for maximum | |
154 | |
155 option_check_enum8: | |
156 infsnz opt_max,W ; get (highest permissible value + 1) into WREG | |
157 return ; highest permissible value was 255, skip check, done | |
158 cpfslt INDF1 ; option value < (highest permissible value + 1) ? | |
159 bra option_reset_loaded ; NO - reset option value | |
160 return ; YES - within range, done | |
161 | |
162 option_check_string: | |
163 return ; nothing to check with strings | |
582 | 164 |
631 | 165 |
166 ;============================================================================= | |
167 ; Check and store all option values in EEPROM | |
168 ; | |
169 global option_check_and_store_all | |
170 option_check_and_store_all: | |
171 bcf PIR3,RC2IE ; disable EUSART interrupts | |
172 | |
173 ;---- save option version | |
174 MOVLI eeprom_opt_version,mpr ; get options version number | |
175 EEPROM_II_WRITE mpr,eeprom_options_version ; store options version number in EEPROM | |
176 | |
177 ;---- check and resolve some interdependencies among options | |
178 bsf is_diluent_menu ; setup checking diluents | |
179 call gaslist_cleanup_list ; check and correct multiple or none First diluents | |
0 | 180 |
631 | 181 bcf is_diluent_menu ; setup checking gases |
182 call gaslist_cleanup_list ; check and correct multiple or none First gases | |
183 | |
184 IFNDEF _gauge_mode | |
185 call option_cleanup_gauge ; check and correct gauge mode | |
186 ENDIF | |
187 | |
188 IFDEF _ccr_pscr | |
189 call option_cleanup_oCCRMode ; check and correct CCR / pSCR mode | |
190 ENDIF | |
191 | |
192 call option_cleanup_GF ; check and correct GFlow <= GFhigh | |
193 | |
194 ;---- check and save all option values | |
195 lfsr FSR0,option_table_begin ; point to start of option definition table | |
196 option_save_all_loop: | |
197 rcall option_check_and_store ; check and save option value | |
198 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
199 bra option_save_all_loop ; NO - do next option | |
200 return ; YES - done | |
604 | 201 |
0 | 202 |
631 | 203 ;============================================================================= |
204 ; Check and store an option value in EEPROM | |
205 ; | |
206 global option_check_and_store | |
207 option_check_and_store: | |
208 rcall option_read_definition ; read the option definition | |
209 rcall option_check_loaded ; check if option value is within min/max, set to default if not | |
210 | |
211 option_save_loaded_checked: | |
212 movf opt_eeprom_bank,W ; get bank | |
213 andlw b'11111110' ; keep only bits 7-1 | |
214 tstfsz WREG ; bank < 0x02 ? | |
215 return ; NO - volatile option or illegal address, abort | |
216 tstfsz opt_eeprom_bank ; YES - bank = 0 ? | |
217 bra option_save_execute ; NO - address is valid | |
218 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 | |
219 cpfsgt opt_eeprom_index ; - index >= start address ? | |
220 return ; NO - illegal address, abort | |
221 ;bra option_save_execute ; YES - address is valid | |
222 | |
223 option_save_execute: | |
224 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) | |
225 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) | |
226 | |
604 | 227 movf opt_type,W ; get option type |
631 | 228 xorlw .2 ; option type = string ? |
229 bz option_save_string ; YES - special handling | |
230 movff INDF1,EEDATA ; NO - copy option value to EEPROM write register | |
231 call write_eeprom ; - execute write | |
232 return ; - done | |
233 | |
604 | 234 option_save_string: |
631 | 235 movff POSTINC1,EEDATA ; copy a character from the option value to the EEPROM write register |
236 btfss EEADRH,1 ; current EEPROM address < 512 ? | |
237 call write_eeprom ; YES - execute write | |
238 infsnz EEADR,F ; increment EEPROM address, low byte | |
239 incf EEADRH,F ; increment EEPROM address, high byte | |
240 decfsz opt_max ; decrement string length, done? | |
241 bra option_save_string ; NO - loop | |
242 return ; YES - done | |
243 | |
244 | |
245 ;============================================================================= | |
246 ; Restore and check all option values from EEPROM | |
247 ; | |
248 global option_restore_and_check_all ; restore options from EEPROM | |
249 option_restore_and_check_all: | |
250 ;---- Read option version from EEPROM | |
251 EEPROM_II_READ eeprom_options_version,mpr | |
252 | |
253 movlw LOW(eeprom_opt_version) ; get options version from current firmware, low byte | |
254 xorwf mpr+0,W ; compare with EEPROM version, do they match? | |
255 bnz option_restore_reset ; NO - reset to defaults of current firmware | |
256 | |
257 movlw HIGH(eeprom_opt_version) ; get options version from current firmware, high byte | |
258 xorwf mpr+1,W ; compare with EEPROM version, do they match? | |
259 bnz option_restore_reset ; NO - reset to defaults of current firmware | |
260 | |
261 ;---- restore all option values | |
262 lfsr FSR0,option_table_begin ; point to start of option definition table | |
263 option_restore_all_loop: | |
264 rcall option_restore_and_check ; restore and check the option | |
265 incfsz opt_end_token,F ; was this the last option (was opt_end_token = 255) ? | |
266 bra option_restore_all_loop ; NO - do next option | |
267 return ; YES - done | |
268 | |
269 option_restore_reset: | |
270 call option_reset_all ; reset all option values to their default | |
271 goto option_check_and_store_all ; write back all option values to EEPROM (and return) | |
272 | |
582 | 273 |
0 | 274 ;============================================================================= |
631 | 275 ; Restore an option value from EEPROM and check it |
276 ; | |
277 global option_restore_and_check | |
278 option_restore_and_check: | |
279 rcall option_read_definition ; read the option definition | |
0 | 280 |
631 | 281 movf opt_eeprom_bank,W ; get bank |
282 andlw b'11111110' ; keep only bits 7-1 | |
283 tstfsz WREG ; bank < 0x02 ? | |
284 bra option_reset_loaded ; NO - volatile option or illegal address, restore to default | |
285 tstfsz opt_eeprom_bank ; YES - bank = 0 ? | |
286 bra option_restore_execute ; NO - address is valid | |
287 movlw low(eeprom_options_storage-1) ; YES - get start address of options storage minus 1 | |
288 cpfsgt opt_eeprom_index ; - index >= start address ? | |
289 bra option_reset_loaded ; NO - illegal address, restore to default | |
290 ;bra option_restore_execute ; YES - address is valid | |
0 | 291 |
631 | 292 option_restore_execute: |
293 movff opt_eeprom_index,EEADR ; set EEPROM index (address low byte) | |
294 movff opt_eeprom_bank, EEADRH ; set EEPROM page (address high byte) | |
0 | 295 |
631 | 296 movf opt_type,W ; get option type |
297 xorlw .2 ; option type = string ? | |
298 bz option_restore_string ; YES - special handling | |
299 call read_eeprom ; NO - execute read | |
300 movff EEDATA,INDF1 ; - read option value from EEPROM read register | |
301 bcf option_repaired ; - clear option repaired flag | |
302 bra option_check_loaded ; - check if option value is within min/max, reset to default if not | |
303 btfsc option_repaired ; - was the option repaired? | |
304 bra option_save_loaded_checked ; YES - save repaired value to EEPROM | |
305 return ; NO - done | |
0 | 306 |
307 option_restore_string: | |
631 | 308 call read_eeprom ; read one character from the EEPROM |
309 movff EEDATA,POSTINC1 ; copy it to the option value | |
310 infsnz EEADR,F ; increment EEPROM address, low byte | |
311 incf EEADRH,F ; increment EEPROM address, high byte | |
312 decfsz opt_max ; decrement string length, done? | |
313 bra option_restore_string ; NO - loop | |
314 return ; YES - done (nothing to check with strings) | |
315 | |
316 | |
0 | 317 |
318 ;============================================================================= | |
631 | 319 ; Read an option value via RS232 |
320 ; INPUT: lo = serial index | |
321 ; OUTPUT: hi = option value | |
322 ; WREG =0: option found and value valid, =1: option not found | |
323 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
324 ; | |
325 global option_read_serial | |
326 option_read_serial: | |
327 lfsr FSR0,option_table_begin ; point to start of option definition table | |
328 option_read_serial_loop: | |
329 rcall option_read_definition ; read option definition | |
330 movf opt_serial,W ; get serial index of the option into WREG | |
331 xorwf lo,W ; received index = index of this option ? | |
332 bz option_read_serial_execute ; YES - read value | |
333 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? | |
334 bra option_read_serial_loop ; NO - try next option | |
335 retlw .1 ; YES - done, option not found | |
336 | |
337 option_read_serial_execute: | |
338 movff INDF1,hi ; read option value into hi | |
339 retlw .0 ; done, option found | |
340 | |
341 | |
342 ;============================================================================= | |
343 ; Write an option value via RS232 | |
344 ; INPUT: lo = serial index | |
345 ; hi = option value | |
346 ; OUTPUT: WREG =0: option found and value valid, =1: option not found, =2: value not valid | |
347 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, up | |
348 ; | |
349 global option_write_serial | |
350 option_write_serial: | |
351 lfsr FSR0,option_table_begin ; point to start of option definition table | |
352 option_write_serial_loop: | |
353 rcall option_read_definition ; read option definition | |
354 movf opt_serial,W ; get serial index of the option into WREG | |
355 xorwf lo,W ; received index = index of this option ? | |
356 bz option_write_serial_execute ; YES - check and update value | |
357 incfsz opt_end_token,F ; NO - was this the last option (was opt_end_token = 255) ? | |
358 bra option_write_serial_loop ; NO - try next option | |
359 retlw .1 ; YES - done, option not found | |
360 | |
361 option_write_serial_execute: | |
362 movff INDF1,up ; backup old value | |
363 movff hi,INDF1 ; write new value | |
364 bcf option_repaired ; clear option repaired flag | |
365 rcall option_check_loaded ; check the new value | |
366 btfsc option_repaired ; was the new value valid? | |
367 bra option_write_serial_execute_fail; NO - restore old value | |
368 bsf options_changed ; YES - flag that EEPROM needs to be updated | |
369 retlw .0 ; - done, success | |
370 option_write_serial_execute_fail: | |
371 movff up,INDF1 ; restore old value | |
372 retlw .2 ; done, value not valid | |
373 | |
374 | |
375 ;============================================================================= | |
376 ; Increment an option value based on type and min/max boundary | |
0 | 377 ; INPUT: FSR0 = option handle |
378 ; OUTPUT: none | |
379 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 | |
604 | 380 ; |
381 global option_inc ; increment FSR0 option | |
0 | 382 option_inc: |
604 | 383 ; read type, default and register from table |
631 | 384 rcall option_read_definition |
385 | |
386 bsf options_changed ; flag that EEPROM needs to be updated | |
582 | 387 |
604 | 388 ; switch on type |
631 | 389 movf opt_type,W ; get option type |
390 bz option_inc_uint8 ; type 0: INT8 | |
391 dcfsnz WREG ; decrement | |
392 bra option_inc_enum8 ; type 1: ENUM | |
393 dcfsnz WREG ; decrement | |
394 bra option_inc_string ; type 2: STRING | |
395 ;bra option_inc_uint8 ; type 3: INT8 | |
0 | 396 |
631 | 397 option_inc_uint8: |
398 movf INDF1,W ; get option value | |
399 addwf opt_inc,W ; add increment | |
400 cpfslt opt_max ; max < option value ? | |
401 bra option_inc_uint8_0 ; NO - new option value ok | |
402 movf opt_min,W ; YES - reset to min value | |
604 | 403 option_inc_uint8_0: |
631 | 404 movwf INDF1 ; store new value |
604 | 405 option_inc_uint8_1: |
631 | 406 ; now some rather crude hack into this routine to make CCR calibration more convenient: |
407 movlw 0x37 ; serial ID of option CalGasO2 | |
408 cpfseq opt_serial ; editing CalGasO2 right now? | |
608 | 409 bra option_inc_uint8_2 ; NO - check next option |
604 | 410 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR |
411 decfsz WREG,W ; - in CCR mode? | |
412 return ; NO - done | |
413 movlw .26 ; YES - | |
414 cpfseq INDF1 ; - option value = 26 ? | |
415 return ; NO - done | |
416 movlw .95 ; YES - advance it to 95 | |
417 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
|
418 return |
608 | 419 option_inc_uint8_2: |
631 | 420 movlw 0x25 ; serial ID of option opt_GF_low |
421 cpfseq opt_serial ; editing opt_GF_low right now? | |
608 | 422 bra option_inc_uint8_3 ; NO - check next option |
423 movff opt_GF_high,WREG ; get value of associated GF high into WREG | |
424 cpfsgt INDF1 ; GF low > GF high? | |
425 return ; NO - setting ok, done | |
426 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
427 return ; - done | |
428 option_inc_uint8_3: | |
631 | 429 movlw 0x26 ; serial ID of option opt_GF_high |
430 cpfseq opt_serial ; editing opt_GF_high right now? | |
608 | 431 bra option_inc_uint8_4 ; NO - check next option |
432 movff opt_GF_low,WREG ; get value of associated GF low into WREG | |
433 cpfslt INDF1 ; GF high < GF low? | |
434 return ; NO - setting ok, done | |
435 movwf INDF1 ; YES - rise GF high to GF low | |
436 return ; - done | |
437 option_inc_uint8_4: | |
631 | 438 movlw 0x27 ; serial ID of option opt_aGF_low |
439 cpfseq opt_serial ; editing opt_aGF_low right now? | |
608 | 440 bra option_inc_uint8_5 ; NO - check next option |
441 movff opt_aGF_high,WREG ; get value of associated GF high into WREG | |
442 cpfsgt INDF1 ; GF low > GF high? | |
443 return ; NO - setting ok, done | |
444 movff opt_min,INDF1 ; YES - wrap around to minimum value | |
445 return ; - done | |
446 option_inc_uint8_5: | |
631 | 447 movlw 0x28 ; serial ID of option opt_aGF_high |
448 cpfseq opt_serial ; editing opt_aGF_high right now? | |
608 | 449 bra option_inc_uint8_6 ; NO - check next option |
450 movff opt_aGF_low,WREG ; get value of associated GF low into WREG | |
451 cpfslt INDF1 ; GF high < GF low? | |
452 return ; NO - setting ok, done | |
453 movwf INDF1 ; YES - rise GF high to GF low | |
454 return ; - done | |
455 option_inc_uint8_6: | |
456 return ; all done | |
457 | |
0 | 458 |
631 | 459 option_inc_enum8: |
460 movf opt_max,W ; copy maximum permissible value to WREG | |
461 cpfslt INDF1 ; option value < maximum permissible value ? | |
462 bra option_inc_enum8_reset ; NO - reset option value | |
463 incf INDF1,F ; YES - increment option value | |
464 bra option_inc_enum8_1 ; - continue | |
465 option_inc_enum8_reset: | |
466 clrf INDF1 ; reset option value to zero | |
467 | |
604 | 468 option_inc_enum8_1: |
623 | 469 IFDEF _ccr_pscr |
631 | 470 ; now some rather crude hack into this routine to unify CCR & pSCR mode setting |
471 movlw 0x1F ; serial ID of option oCCRMode | |
472 cpfseq opt_serial ; editing oCCRMode right now? | |
604 | 473 bra option_inc_enum8_2 ; NO - check next option |
623 | 474 IFDEF _external_sensor |
604 | 475 btfsc analog_o2_input ; YES - does hosting OSTC have an analog interface? |
476 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed | |
477 btfsc optical_input ; does hosting OSTC have an optical interface? | |
478 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed | |
623 | 479 ENDIF ; _external_sensor |
604 | 480 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP) |
481 xorlw .1 ; - in sensor mode? | |
482 bnz option_inc_enum8_1a ; NO - continue with next check | |
483 incf INDF1,F ; YES - advance option value to AutoSP | |
484 option_inc_enum8_1a: | |
485 movff opt_dive_mode,WREG ; get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
486 xorlw .4 ; in pSCR mode? | |
487 bnz option_inc_enum8_1_exit ; NO - done | |
488 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP) | |
489 option_inc_enum8_1_exit: | |
490 return ; done | |
623 | 491 ENDIF ; _ccr_pscr |
631 | 492 |
604 | 493 option_inc_enum8_2: |
631 | 494 IFDEF _gas_contingency |
495 ; now some rather crude hack to switch off contingency mode if gas needs calculation is switched off | |
496 movlw 0x5A ; serial ID of option opt_calc_gasvolume | |
497 cpfseq opt_serial ; editing opt_calc_gasvolume right now? | |
498 bra option_inc_enum8_3 ; NO - check next option | |
499 movf INDF1,W ; YES - get option value | |
500 ; xorlw .0 ; - option value = off ? | |
501 bnz option_inc_enum8_2_exit ; NO - done | |
502 clrf WREG ; YES - force contingency to be off, too | |
503 movff WREG,opt_gas_contingency_dive ; - ... | |
504 option_inc_enum8_2_exit: | |
505 return | |
506 ENDIF ; _gas_contingency | |
507 | |
604 | 508 option_inc_enum8_3: |
631 | 509 ; now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode |
510 movlw 0x20 ; serial ID of option opt_dive_mode | |
511 cpfseq opt_serial ; editing opt_dive_mode right now? | |
604 | 512 bra option_inc_enum8_4 ; NO - check next option |
623 | 513 movf INDF1,W ; YES - get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR |
514 xorlw .1 ; in CCR mode? | |
515 bnz option_inc_enum8_3a ; NO - in some other mode | |
516 IFNDEF _ccr_pscr | |
517 incf INDF1,f ; YES - no CCR mode compiled in, advance to gauge mode | |
628 | 518 bra option_inc_enum8_3a ; - check if gauge mode is available |
623 | 519 ENDIF ; _ccr_pscr |
520 IFDEF _rx_functions | |
521 global option_cleanup_oTrMode_CCR ; embedded clean-up entry-point | |
604 | 522 option_cleanup_oTrMode_CCR: ; entry point from cleanup during restart |
623 | 523 movff opt_TR_mode,WREG ; get TR mode |
524 xorlw .2 ; mode = 2 (ind.double)? | |
525 bnz option_inc_enum8_3_exit ; NO - done | |
526 bra option_inc_enum8_3_reset ; YES - revert mode to 1 (on) | |
527 ENDIF ; _rx_functions | |
604 | 528 option_inc_enum8_3a: ; any mode other than CCR |
628 | 529 IFNDEF _gauge_mode |
530 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
531 xorlw .2 ; in Gauge mode? | |
532 bnz option_inc_enum8_3b ; NO - in some other mode | |
533 incf INDF1,f ; YES - no Gauge mode compiled in, advance to Apnea mode | |
534 bra option_inc_enum8_3_exit ; - done (Apnea mode is always available) | |
535 ENDIF ; _gauge_mode | |
536 option_inc_enum8_3b: | |
623 | 537 IFNDEF _ccr_pscr |
538 movf INDF1,W ; get option value: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
539 xorlw .4 ; in pSCR mode? | |
628 | 540 bnz option_inc_enum8_3c ; NO - in some other mode |
623 | 541 clrf INDF1 ; YES - no pSCR mode compiled in, advance to 0 "OC" |
542 bra option_inc_enum8_3_exit ; - done | |
543 ENDIF ; _ccr_pscr | |
628 | 544 option_inc_enum8_3c: |
623 | 545 global option_cleanup_oTrMode_no_CCR ; embedded clean-up entry-point |
604 | 546 option_cleanup_oTrMode_no_CCR: ; entry point from cleanup during restart |
547 movff opt_TR_mode,WREG ; get TR mode | |
548 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
549 bnz option_inc_enum8_3_exit ; NO - done | |
550 option_inc_enum8_3_reset: ; YES - revert to mode 1 (on) | |
551 movlw .1 ; load coding of mode "on" | |
552 movff WREG,opt_TR_mode ; write to option | |
553 option_inc_enum8_3_exit: | |
554 return ; done | |
628 | 555 |
604 | 556 option_inc_enum8_4: |
623 | 557 IFDEF _rx_functions |
631 | 558 ; now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode |
559 movlw 0x7E ; serial ID of option opt_TR_mode | |
560 cpfseq opt_serial ; editing opt_TR_mode right now? | |
604 | 561 bra option_inc_enum8_5 ; NO - check next option |
562 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR | |
563 decfsz WREG,W ; dive mode = 1 CCR? | |
564 bra option_inc_enum8_4a ; NO - in any other mode | |
565 movf INDF1,W ; YES - get option value (TR mode) | |
566 xorlw .2 ; - mode = 2 (ind.double)? | |
567 bnz option_inc_enum8_4_exit ; NO - done | |
568 incf INDF1,F ; YES - advance option value to 3 (CCR Dil+O2) | |
569 bra option_inc_enum8_4_exit ; - done | |
570 option_inc_enum8_4a: ; any mode other than CCR | |
571 movf INDF1,W ; get option value (TR mode) | |
572 xorlw .3 ; mode = 3 (CCR Dil+O2)? | |
573 bnz option_inc_enum8_4_exit ; NO - done | |
574 clrf INDF1 ; YES - advance option value to 0 "off" | |
575 option_inc_enum8_4_exit: | |
576 return ; done | |
623 | 577 ENDIF ; _rx_functions |
631 | 578 |
604 | 579 option_inc_enum8_5: |
631 | 580 IFDEF _gas_contingency |
581 ; now some rather crude hack to keep contingency mode switched off if gas needs calculation is switched off | |
582 movlw 0x91 ; serial ID of option opt_gas_contingency_dive | |
583 cpfseq opt_serial ; editing opt_gas_contingency_dive right now? | |
584 bra option_inc_enum8_6 ; NO - check next option | |
585 movff opt_calc_gasvolume,WREG ; YES - get current setting of gas needs calculation | |
586 tstfsz WREG ; - gas needs calculation switched off? | |
587 return ; NO - done, opt_gas_contingency_dive may be switched on | |
588 clrf INDF1 ; YES - force opt_gas_contingency_dive to off | |
589 return ; - done | |
590 ENDIF ; _gas_contingency | |
591 | |
592 option_inc_enum8_6: | |
582 | 593 return |
594 | |
595 | |
604 | 596 option_inc_string: ; no editing available |
582 | 597 return |
0 | 598 |
604 | 599 |
628 | 600 IFNDEF _gauge_mode |
601 option_cleanup_gauge: | |
602 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) | |
603 xorlw .2 ; in Gauge mode? | |
604 bnz option_cleanup_gauge_1 ; NO - done | |
631 | 605 movff WREG,opt_dive_mode ; YES - setting not allowed, WREG is zero -> reset to OC mode |
606 bsf options_changed ; - flag that EEPROM needs to be updated | |
628 | 607 option_cleanup_gauge_1: |
608 return ; done | |
609 ENDIF | |
610 | |
611 | |
623 | 612 IFDEF _ccr_pscr |
604 | 613 global option_cleanup_oCCRMode |
614 global option_cleanup_oCCRMode_pSCR | |
615 global option_cleanup_oCCRMode_CCR | |
616 option_cleanup_oCCRMode: ; in pSCR mode, revert AutoSP (2) to calculated SP (0), in pSCR and CCR revert Sensor to fixed SP if no sensor interface available | |
623 | 617 movff opt_dive_mode,WREG ; get dive mode into WREG (0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR) |
604 | 618 xorlw .4 ; in pSCR mode? |
619 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC | |
620 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode | |
623 | 621 banksel opt_ccr_mode ; YES - select options bank |
622 bcf opt_ccr_mode,1 ; - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP, keeps sensor) | |
623 banksel common ; - back to bank common | |
631 | 624 bsf options_changed ; - flag that EEPROM needs to be updated |
604 | 625 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode |
623 | 626 IFDEF _external_sensor |
627 btfsc analog_o2_input ; analog interface available? | |
628 return ; YES - setting 'sensor' allowed | |
604 | 629 btfsc optical_input ; does hosting OSTC have an optical interface? |
623 | 630 return ; YES - setting 'sensor' allowed |
631 ENDIF | |
632 movff opt_ccr_mode,WREG ; NO to both - get CCR mode | |
633 xorlw .1 ; - coding for sensor | |
634 tstfsz WREG ; - CCR mode = sensor? | |
635 return ; NO - setting allowed | |
636 banksel opt_ccr_mode ; YES - setting not allowed, select options bank | |
637 clrf opt_ccr_mode ; - revert setting to 0 (fixed or calculated SP) | |
638 banksel common ; - back to bank common | |
631 | 639 bsf options_changed ; - flag that EEPROM needs to be updated |
623 | 640 return ; - done |
641 ENDIF ; _ccr_pscr | |
642 | |
604 | 643 |
608 | 644 option_cleanup_GF: |
645 ; cleanup normal GF | |
646 movff opt_GF_high,WREG ; copy normal GF high to WREG | |
623 | 647 movff opt_GF_low,mpr ; copy normal GF low to mpr |
648 cpfsgt mpr ; GF low > GF high ? | |
608 | 649 bra option_cleanup_GF_2 ; NO - option ok, check next option |
623 | 650 movwf mpr ; YES - copy GF high to mpr |
608 | 651 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 652 cpfsgt mpr ; - mpr > 100 ? |
608 | 653 bra option_cleanup_GF_1 ; NO - correct GF low to GF high |
623 | 654 movwf mpr ; YES - correct GF low to 100% |
608 | 655 option_cleanup_GF_1: |
623 | 656 movff mpr,opt_GF_low ; store corrected GF low |
631 | 657 bsf options_changed ; flag that EEPROM needs to be updated |
608 | 658 option_cleanup_GF_2: |
659 ; cleanup alternative GF | |
660 movff opt_aGF_high,WREG ; copy alternative GF high to WREG | |
623 | 661 movff opt_aGF_low,mpr ; copy alternative GF low to mpr |
662 cpfsgt mpr ; GF low > GF high ? | |
608 | 663 bra option_cleanup_GF_4 ; NO - option ok, check next option |
623 | 664 movwf mpr ; YES - copy GF high to mpr |
608 | 665 movlw .100 ; - load GF low limit of 100% into WREG |
623 | 666 cpfsgt mpr ; - mpr > 100 ? |
608 | 667 bra option_cleanup_GF_3 ; NO - correct GF low to GF high |
623 | 668 movwf mpr ; YES - correct GF low to 100% |
608 | 669 option_cleanup_GF_3: |
623 | 670 movff mpr,opt_aGF_low ; store corrected GF low |
631 | 671 bsf options_changed ; flag that EEPROM needs to be updated |
608 | 672 option_cleanup_GF_4: |
673 return ; done | |
674 | |
604 | 675 |
0 | 676 ;============================================================================= |
604 | 677 ; Strcat option into FSR2 buffer |
678 ; | |
679 global option_draw ; STRCAT FRS0 option | |
0 | 680 option_draw: |
631 | 681 ; read type, default and register from table |
682 rcall option_read_definition | |
582 | 683 |
631 | 684 ; switch on type |
685 movf opt_type,W ; get option type | |
623 | 686 bz option_draw_uint8 ; type0 = INT8 |
687 dcfsnz WREG | |
688 bra option_draw_enum8 ; type1 = ENUM | |
582 | 689 dcfsnz WREG |
623 | 690 bra option_draw_string ; type2 = string |
582 | 691 dcfsnz WREG |
623 | 692 bra option_draw_uint8_depth ; type3 = INT8 with automatic display in meters or feet |
631 | 693 return ; unknown, do nothing |
623 | 694 |
604 | 695 option_draw_string: |
696 movff POSTINC1,POSTINC2 | |
697 decfsz opt_max | |
698 bra option_draw_string | |
699 return | |
700 | |
623 | 701 option_draw_uint8_depth: |
702 TSTOSS opt_units ; using metric units (0=m, 1=ft)? | |
703 bra option_draw_uint8 ; YES - handle with standard output | |
704 movff INDF1,lo ; NO - imperial, get value to lo | |
705 call convert_meter_to_feet ; - convert value in lo from meter to feet | |
706 bsf leftbind ; - print with left alignment | |
707 output_16_3 ; - display only last three digits from a 16 bit value (0-999) | |
708 bcf leftbind ; - back to normal alignment | |
709 STRCAT_TEXT tFeets ; - print unit | |
710 bra option_draw_uint8_common ; - continue with common part | |
0 | 711 |
712 option_draw_uint8: | |
604 | 713 movff INDF1,lo ; draw value |
582 | 714 bsf leftbind |
715 output_8 | |
716 bcf leftbind | |
604 | 717 clrf INDF2 ; make sure to close string |
718 movf opt_unit+0,W ; is there a unit to append? | |
582 | 719 iorwf opt_unit+1,W |
604 | 720 rcall option_draw_unit ; YES |
623 | 721 option_draw_uint8_common: |
604 | 722 movf opt_default,W ; get default value |
723 cpfseq lo ; compare with current value, equal? | |
724 bra option_draw_uint8_2 ; NO - not default, add * | |
725 return ; YES - default, done | |
0 | 726 option_draw_uint8_2: |
604 | 727 PUTC "*" ; print "*" |
728 return ; done | |
623 | 729 |
0 | 730 option_draw_unit: |
582 | 731 movff opt_unit+0,FSR1L |
732 movff opt_unit+1,FSR1H | |
733 goto strcat_text | |
0 | 734 |
735 | |
736 ;---- Draw an enumerated value (set of translated strings) | |
737 option_draw_enum8: | |
631 | 738 movf INDF1,W ; copy option value to WREG |
739 movwf lo ; memorize option value, too | |
740 cpfslt opt_max ; option value > maximum permissible value ? | |
741 bra option_draw_enum8_0 ; NO - option value allowed | |
742 clrf WREG ; YES - to avoid printing rubbish, use first ENUM item instead | |
743 option_draw_enum8_0: | |
628 | 744 addwf WREG ; current value *= 2 |
745 addwf opt_inc,W ; base text + 2 * current value | |
631 | 746 movwf FSR1L ; load FSR1 |
628 | 747 movlw .0 ; propagate carry... |
748 addwfc opt_min,W ; ... | |
604 | 749 movwf FSR1H ; ...into FSR1 |
628 | 750 call strcat_text ; print text |
751 movf opt_default,W ; get default value | |
752 cpfseq lo ; compare with memorized current value, equal? | |
753 bra option_draw_enum8_1 ; NO - not default, add * | |
754 return ; YES - default, done | |
755 option_draw_enum8_1: | |
756 PUTC "*" ; print "*" | |
757 return ; done | |
758 | |
623 | 759 ;----------------------------------------------------------------------------- |
0 | 760 |
623 | 761 END |