comparison src/options.asm @ 604:ca4556fb60b9

bump to 2.99beta, work on 3.00 stable
author heinrichsweikamp
date Thu, 22 Nov 2018 19:47:26 +0100
parents b455b31ce022
children d866684249bd
comparison
equal deleted inserted replaced
603:00b24fb4324d 604:ca4556fb60b9
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File options.asm REFACTORED VERSION V2.97 3 ; File options.asm REFACTORED VERSION V2.99e
4 ; 4 ;
5 ; Manage all options data. 5 ; Manage all options data.
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 ; HISTORY 9 ; HISTORY
10 ; 2011-07-12 : [jDG] Creation. 10 ; 2011-07-12 : [jDG] Creation.
11 ; 11 ;
12 ; RATIONALS: 12
13 ; 13 #include "hwos.inc" ; mandatory header
14 ; Provides a centralized file with
15
16 #include "hwos.inc" ; Mandatory header
17 #include "strings.inc" 14 #include "strings.inc"
18 #include "convert.inc" 15 #include "convert.inc"
19 #include "ghostwriter.inc" 16 #include "ghostwriter.inc"
20 #include "eeprom_rs232.inc" 17 #include "eeprom_rs232.inc"
21 #include "external_flash.inc" 18 #include "external_flash.inc"
22 #include "wait.inc" 19 #include "wait.inc"
20 #include "shared_definitions.h"
23 21
24 extern write_eeprom 22 extern write_eeprom
25 extern read_eeprom 23 extern read_eeprom
26 extern eeprom_serial_save,eeprom_opt_backup 24 extern eeprom_serial_save,eeprom_opt_backup
27 extern option_table_begin,option_table_end 25 extern option_table_begin,option_table_end
28 26
29 global option_reset_all ; Reset all options to factory default. 27 options CODE
30 global option_check_all ; Check all option and reset option if out of min/max boundary 28
31 global option_reset ; Reset FSR0 option to factory default. 29 ;=============================================================================
32 global option_save_all ; Save options to EEPROM. 30 ; Reset all options to factory defaults
33 global option_restore_all ; Restore options from EEPROM.
34 global option_inc ; Increment FSR0 option.
35 global option_draw ; STRCAT FRS0 option.
36
37
38 gui CODE ; Appends to other GUI segment
39
40 ;=============================================================================
41 ; Reset all options to factory defaults.
42 ; 31 ;
43 ; INPUT: none 32 ; INPUT: none
44 ; OUTPUT: none 33 ; OUTPUT: none
45 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 34 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
46 35 ;
36 global option_reset_all ; reset all options to factory default
47 option_reset_all: 37 option_reset_all:
48 clrf EEADRH 38 clrf EEADRH
49 read_int_eeprom .2 39 read_int_eeprom .2
50 tstfsz EEDATA ; Total dives=0? 40 tstfsz EEDATA ; number of total dives = 0 ?
51 bra option_reset_all2 ; No, skip resetting logbook 41 bra option_reset_all2 ; NO - skip resetting logbook
52 read_int_eeprom .3 42 read_int_eeprom .3
53 tstfsz EEDATA ; Total dives=0? 43 tstfsz EEDATA ; number of total dives = 0 ?
54 bra option_reset_all2 ; No, skip resetting logbook 44 bra option_reset_all2 ; NO - skip resetting logbook
55 45
56 clrf EEDATA 46 clrf EEDATA
57 write_int_eeprom .4 47 write_int_eeprom .4
58 write_int_eeprom .5 48 write_int_eeprom .5
59 write_int_eeprom .6 49 write_int_eeprom .6
60 write_int_eeprom .2 ; Also, delete total dive counter 50 write_int_eeprom .2 ; delete total dive counter, too
61 write_int_eeprom .3 51 write_int_eeprom .3
62 call ext_flash_erase_logbook ; And complete logbook (!) 52 call ext_flash_erase_logbook ; complete logbook
63 53
64 option_reset_all2: 54 option_reset_all2:
65 clrf lo 55 clrf lo
66 clrf hi 56 clrf hi
67 call do_logoffset_common_write ; reset Logbook offset 57 call do_logoffset_common_write ; reset logbook offset
68 58 movlw LOW(option_table_begin) ; point to option table begin
69 ; Point to option table begin
70 movlw LOW(option_table_begin)
71 movwf FSR0L 59 movwf FSR0L
72 movlw HIGH(option_table_begin) 60 movlw HIGH(option_table_begin)
73 movwf FSR0H 61 movwf FSR0H
74 option_reset_all_1: 62 option_reset_all_1:
75 movlw LOW(option_table_end) 63 movlw LOW(option_table_end) ; get low byte of end of table address
76 cpfseq FSR0L 64 cpfseq FSR0L ; does it equal the current pointer position?
77 bra option_reset_all_2 ; Not yet done... 65 bra option_reset_all_2 ; NO - more options to process
78 movlw HIGH(option_table_end) 66 movlw HIGH(option_table_end) ; get high byte of end of table address
79 cpfseq FSR0H 67 cpfseq FSR0H ; does it equal the current pointer position?
80 bra option_reset_all_2 ; Not yet done... 68 bra option_reset_all_2 ; NO - more options to process
81 return ; All done. 69 return ; YES to both - end of option table reached, done
82 option_reset_all_2: 70 option_reset_all_2:
83 rcall option_reset ; Reset one option. 71 rcall option_reset ; reset one option...
84 bra option_reset_all_1 ; and loop. 72 bra option_reset_all_1 ; ... and loop
85 73
86 ;============================================================================= 74 ;=============================================================================
87 ; Check all option and reset option if out of min/max boundary 75 ; Check all option and reset option if out of min/max boundary
88 ; 76 ;
89 ; INPUT: none 77 ; INPUT: none
90 ; OUTPUT: none 78 ; OUTPUT: none
91 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 79 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
80 ;
81 global option_check_all ; check all option and reset option if out of min/max boundary
92 option_check_all: 82 option_check_all:
93 ; Point to option table begin 83 movlw LOW(option_table_begin) ; point to option table begin
94 movlw LOW(option_table_begin)
95 movwf FSR0L 84 movwf FSR0L
96 movlw HIGH(option_table_begin) 85 movlw HIGH(option_table_begin)
97 movwf FSR0H 86 movwf FSR0H
98 87
99 option_check_all_1: 88 option_check_all_1:
100 movlw LOW(option_table_end) 89 movlw LOW(option_table_end) ; get low byte of end of table address
101 cpfseq FSR0L 90 cpfseq FSR0L ; does it equal the current pointer position?
102 bra option_check_all_2 ; Not yet done... 91 bra option_check_all_2 ; NO - more options to process
103 movlw HIGH(option_table_end) 92 movlw HIGH(option_table_end) ; get high byte of end of table address
104 cpfseq FSR0H 93 cpfseq FSR0H ; does it equal the current pointer position?
105 bra option_check_all_2 ; Not yet done... 94 bra option_check_all_2 ; NO - more options to process
106 return ; All done. 95 return ; YES to both - end of option table reached, done
107 option_check_all_2: 96 option_check_all_2:
108 rcall option_check ; check one option. 97 rcall option_check ; check one option...
109 bra option_check_all_1 ; and loop 98 bra option_check_all_1 ; ... and loop
110 99
111 ;============================================================================= 100 ;=============================================================================
112 ; Read option handle 101 ; Read option handle
113 ; INPUT: FSR0 = option handle 102 ; INPUT: FSR0 = option handle
114 ; OUTPUT: FSR1 = address of variable. 103 ; OUTPUT: FSR1 = address of variable.
115 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 104 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
105 ;
116 option_read: 106 option_read:
117 movff FSR0L,TBLPTRL 107 movff FSR0L,TBLPTRL
118 movlw HIGH(option_table_begin) ; Get 8 high bits. 108 movlw HIGH(option_table_begin) ; get 8 high bits.
119 andlw 0xF0 ; Keep only the 4 highest ones. 109 andlw 0xF0 ; keep only the 4 highest ones
120 iorwf FSR0H,W ; Cat with the known 4 lower ones. 110 iorwf FSR0H,W ; cat with the known 4 lower ones
121 movwf TBLPTRH ; And we have the high byte. 111 movwf TBLPTRH ; we have the high byte
122 movlw UPPER(option_table_begin) 112 movlw UPPER(option_table_begin)
123 movwf TBLPTRU 113 movwf TBLPTRU
124 114
125 ; Read type, default and register from table 115 ; Read type, default and register from table
126 tblrd*+ 116 tblrd*+
141 movff TABLAT,opt_unit+1 131 movff TABLAT,opt_unit+1
142 tblrd*+ 132 tblrd*+
143 movff TABLAT,FSR1L 133 movff TABLAT,FSR1L
144 tblrd*+ 134 tblrd*+
145 movff TABLAT,FSR1H 135 movff TABLAT,FSR1H
146 movff TBLPTRL,FSR0L ; Advance handle too, for reset_all 136 movff TBLPTRL,FSR0L ; advance handle, too, for reset_all
147 movff TBLPTRH,FSR0H 137 movff TBLPTRH,FSR0H
148 return 138 return
149 139
150 ;============================================================================= 140 ;=============================================================================
151 ; Check one option and reset if it's out of it's min/max boundaries 141 ; Check one option and reset if it's out of it's min/max boundaries
156 option_check: 146 option_check:
157 ; Read type, default and register from table 147 ; Read type, default and register from table
158 rcall option_read 148 rcall option_read
159 149
160 ; Switch on type 150 ; Switch on type
161 movf opt_type,W ; Type == STRING ? 151 movf opt_type,W ; get option type
162 xorlw 2 152 xorlw 2 ; type == STRING ?
163 bz option_check_string ; String: Do not reset strings 153 bz option_check_string ; YES
164 154 movf opt_type,W ; get option type (again)
165 movf opt_type,W ; Type == ENUM8 ? 155 xorlw 1 ; type == ENUM8 ?
166 xorlw 1 156 bz option_check_enum8 ; YES - check if lower then max. value only
167 bz option_check_enum8 ; ENUM8: Check if lower then max. value only 157 ; NO to all - must be integer then
168 158 tstfsz opt_min ; opt_min = 0 ?
169 tstfsz opt_min ; opt_min=0? 159 bra option_check_both ; NO - check it
170 bra option_check_both ; no 160 bra option_check_enum8 ; check max only
171 bra option_check_enum8 ; Check max only
172 161
173 option_check_both: 162 option_check_both:
174 decf opt_min,W 163 decf opt_min,W ; check against minimum value
175 cpfsgt INDF1 ; bigger then opt_min-1? 164 cpfsgt INDF1 ; bigger then opt_min - 1 ?
176 bra option_check_reset ; No, reset option 165 bra option_check_reset ; NO - reset option
177 option_check_enum8: ; ENUM8: Check max only 166 option_check_enum8: ; check against maximum value
178 infsnz opt_max,W ; Max = 255? 167 infsnz opt_max,W ; max = 255?
179 return ; Yes, ignore max. test 168 return ; YES - ignore the max. test
180 cpfslt INDF1 ; smaller then opt_max+1? 169 cpfslt INDF1 ; NO - smaller then opt_max + 1 ?
181 bra option_check_reset ; No, reset option 170 bra option_check_reset ; NO - reset option
182 return ; in range, return 171 return ; YES - in range, return
183 172
184 option_check_reset: 173 option_check_reset:
185 movff opt_default,INDF1 ; reset option to default 174 movff opt_default,INDF1 ; reset option to default
186 return ; Done. 175 return ; done
187 176
188 option_check_string: 177 option_check_string:
189 return 178 return
190 179
191 ;============================================================================= 180 ;=============================================================================
192 ; Reset an option to its default value. 181 ; Reset an option to its default value
193 ; INPUT: FSR0 = option handle 182 ; INPUT: FSR0 = option handle
194 ; OUTPUT: none 183 ; OUTPUT: none
195 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 184 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2
196 ; 185 ;
186 global option_reset ; reset FSR0 option to factory default
197 option_reset: 187 option_reset:
198 ; Read type, default and register from table 188 ; Read type, default and register from table
199 rcall option_read 189 rcall option_read ; read option data
200 190 movf opt_type,W ; get option type
201 ; Switch on type 191 xorlw 2 ; Type == STRING ?
202 movf opt_type,W ; Type == STRING ? 192 bz opt_reset_string ; YES - special copy
203 xorlw 2 193 movff opt_default,INDF1 ; NO - just a 8 bit indirect copy
204 bz opt_reset_string ; YES: special copy 194 return
205
206 movff opt_default,INDF1 ; NO: just a 8bit indirect copy
207 return
208
209 opt_reset_string: 195 opt_reset_string:
210 movff FSR1L,FSR2L ; set string destination address. 196 movff FSR1L,FSR2L ; set string destination address
211 movff FSR1H,FSR2H 197 movff FSR1H,FSR2H ; ...
212 198 movff opt_default+0,FSR1L ; get handle to multi-lingual text in FSR1
213 movff opt_default+0,FSR1L ; Get handle to multi-lingual text in FSR1 199 movff opt_default+1,FSR1H ; ...
214 movff opt_default+1,FSR1H
215
216 movff TBLPTRL,opt_backup_tbl+0 ; TBLPTR trashed by text routine... 200 movff TBLPTRL,opt_backup_tbl+0 ; TBLPTR trashed by text routine...
217 movff TBLPTRH,opt_backup_tbl+1 201 movff TBLPTRH,opt_backup_tbl+1 ; ...
218 movff TBLPTRU,opt_backup_tbl+2 202 movff TBLPTRU,opt_backup_tbl+2 ; ...
219 203 call strcat_text ; copy translated text to FSR2
220 call strcat_text ; Copy translated text to FSR2 204 movff opt_backup_tbl+0,TBLPTRL ; restore TBLPTR
221 205 movff opt_backup_tbl+1,TBLPTRH ; ...
222 movff opt_backup_tbl+0,TBLPTRL 206 movff opt_backup_tbl+2,TBLPTRU ; ...
223 movff opt_backup_tbl+1,TBLPTRH
224 movff opt_backup_tbl+2,TBLPTRU
225 207
226 return 208 return
227 209
228 ;============================================================================= 210 ;=============================================================================
229 ; Save all options to EEPROM 211 ; Save all options to EEPROM
212 ;
213 global option_save_all ; save options to EEPROM
230 option_save_all: 214 option_save_all:
231 ;---- Save option serial into EEPROM to detect reset and new version 215 ;---- Save option serial into EEPROM to detect reset and new version
232 movlw LOW(eeprom_serial_save) 216 movlw LOW(eeprom_serial_save)
233 movwf EEADR 217 movwf EEADR
234 movlw HIGH(eeprom_serial_save) 218 movlw HIGH(eeprom_serial_save)
248 movwf FSR0H 232 movwf FSR0H
249 233
250 option_save_all_1: 234 option_save_all_1:
251 movlw LOW(option_table_end) 235 movlw LOW(option_table_end)
252 cpfseq FSR0L 236 cpfseq FSR0L
253 bra option_save_all_2 ; Not yet done... 237 bra option_save_all_2 ; not yet done...
254 movlw HIGH(option_table_end) 238 movlw HIGH(option_table_end)
255 cpfseq FSR0H 239 cpfseq FSR0H
256 bra option_save_all_2 ; Not yet done... 240 bra option_save_all_2 ; not yet done...
257 return ; All done. 241 return ; all done
258 option_save_all_2: 242 option_save_all_2:
259 rcall option_save ; Save one option. 243 rcall option_save ; save one option...
260 bra option_save_all_1 ; and loop. 244 bra option_save_all_1 ; ...and loop
245
261 246
262 global option_save 247 global option_save
263 option_save: 248 option_save:
264 rcall option_read 249 rcall option_read
265 incf opt_eeprom,W ; Should we save it ? 250 incf opt_eeprom,W ; should we save it ?
266 btfsc STATUS,Z ; EEPROM address is FFh ? 251 btfsc STATUS,Z ; EEPROM address is FFh ?
267 return ; YES: nothing to do. 252 return ; YES - nothing to do
268 253 movf opt_eeprom,W ; compute backup address in EEPROM
269 movf opt_eeprom,W ; Compute backup address in EEPROM 254 addlw LOW(eeprom_opt_backup) ; add offset
270 addlw LOW(eeprom_opt_backup) ; Add offset
271 movwf EEADR 255 movwf EEADR
272 movlw HIGH(eeprom_opt_backup) 256 movlw HIGH(eeprom_opt_backup)
273 btfsc STATUS,C ; >256 257 btfsc STATUS,C ; > 256 ?
274 addlw .1 ; Yes: +1 258 addlw .1 ; YES - +1
275 movwf EEADRH 259 movwf EEADRH
276 260 movf opt_type,W ; get option type
277 movf opt_type,W ; Option type is string ? 261 xorlw 2 ; option type is string ?
278 xorlw 2 262 bz option_save_string ; YES
279 bz option_save_string 263 movff INDF1,EEDATA ; one byte to be saved to EEPROM
280 264 btfss EEADRH,1 ; EEADR:EEADRH < 512 ?
281 ; One byte to save to EEPROM 265 call write_eeprom ; YES - write
282 movff INDF1,EEDATA 266 return
283 btfss EEADRH,1 ; EEADR:EEADRH < 512?
284 call write_eeprom ; Yes, write
285 return
286
287 option_save_string: 267 option_save_string:
288 movff POSTINC1,EEDATA ; Write one byte 268 movff POSTINC1,EEDATA ; write one byte
289 btfss EEADRH,1 ; EEADR:EEADRH < 512? 269 btfss EEADRH,1 ; EEADR:EEADRH < 512 ?
290 call write_eeprom ; Yes, write 270 call write_eeprom ; Yes - write
291 infsnz EEADR,F 271 infsnz EEADR,F
292 incf EEADRH,F 272 incf EEADRH,F
293 273 decfsz opt_max ; decrement string length
294 decfsz opt_max ; Decrement string length 274 bra option_save_string ; loop while not finished
295 bra option_save_string ; And loop while not finished 275 return
296 276
297 return 277 ;=============================================================================
298 ;============================================================================= 278
299 279 global option_restore_all ; restore options from EEPROM
300 option_restore_all: 280 option_restore_all:
301 ;---- Read option serial from EEPROM 281 ;---- Read option serial from EEPROM
302 movlw LOW(eeprom_serial_save) 282 movlw LOW(eeprom_serial_save)
303 movwf EEADR 283 movwf EEADR
304 movlw HIGH(eeprom_serial_save) 284 movlw HIGH(eeprom_serial_save)
305 movf EEADRH 285 movf EEADRH
306 call read_eeprom 286 call read_eeprom
307 movlw LOW(eeprom_opt_serial) 287 movlw LOW(eeprom_opt_serial)
308 xorwf EEDATA,W 288 xorwf EEDATA,W
309 bnz option_restore_bad ; Auto reset if changed. 289 bnz option_restore_bad ; auto reset if changed
310 incf EEADR,F 290 incf EEADR,F
311 call read_eeprom 291 call read_eeprom
312 movlw HIGH(eeprom_opt_serial) 292 movlw HIGH(eeprom_opt_serial)
313 xorwf EEDATA,W 293 xorwf EEDATA,W
314 bz option_restore_ok ; Auto reset if changed. 294 bz option_restore_ok ; auto reset if changed
315 295
316 option_restore_bad: 296 option_restore_bad:
317 call option_reset_all ; Reset RAM contains 297 call option_reset_all ; reset RAM contains
318 goto option_save_all ; Then save to EEPROM 298 goto option_save_all ; then save to EEPROM
319 299
320 ;---- Proper restore 300 ;---- Proper restore
321 option_restore_ok: 301 option_restore_ok:
322 movlw LOW(option_table_begin) 302 movlw LOW(option_table_begin)
323 movwf FSR0L 303 movwf FSR0L
325 movwf FSR0H 305 movwf FSR0H
326 306
327 option_restore_all_1: 307 option_restore_all_1:
328 movlw LOW(option_table_end) 308 movlw LOW(option_table_end)
329 cpfseq FSR0L 309 cpfseq FSR0L
330 bra option_restore_all_2 ; Not yet done... 310 bra option_restore_all_2 ; not yet done...
331 movlw HIGH(option_table_end) 311 movlw HIGH(option_table_end)
332 cpfseq FSR0H 312 cpfseq FSR0H
333 bra option_restore_all_2 ; Not yet done... 313 bra option_restore_all_2 ; not yet done...
334 return ; All done. 314 return ; all done
335 option_restore_all_2: 315 option_restore_all_2:
336 rcall option_restore ; Restore one option. 316 rcall option_restore ; Restore one option
337 bra option_restore_all_1 ; and loop. 317 bra option_restore_all_1 ; and loop
338 318
339 option_restore: 319 option_restore:
340 rcall option_read 320 rcall option_read
341 incf opt_eeprom,W ; Should we save it ? 321 incf opt_eeprom,W ; shall we save it ?
342 btfsc STATUS,Z ; EEPROM address is FFh ? 322 btfsc STATUS,Z ; EEPROM address is FFh ?
343 return ; YES: nothing to do. 323 return ; YES - nothing to do.
344 324 movf opt_eeprom,W ; compute backup address in EEPROM
345 movf opt_eeprom,W ; Compute backup address in EEPROM 325 addlw LOW(eeprom_opt_backup) ; add offset
346 addlw LOW(eeprom_opt_backup) ; Add offset
347 movwf EEADR 326 movwf EEADR
348 movlw HIGH(eeprom_opt_backup) 327 movlw HIGH(eeprom_opt_backup)
349 btfsc STATUS,C ; >256 328 btfsc STATUS,C ; > 256 ?
350 addlw .1 ; Yes: +1 329 addlw .1 ; YES - +1
351 movwf EEADRH 330 movwf EEADRH
352 331 movf opt_type,W ; get option type
353 movf opt_type,W ; Option type is string ? 332 xorlw 2 ; Option type is string?
354 xorlw 2 333 bz option_restore_string ; YES
355 bz option_restore_string 334 call read_eeprom ; read one byte from EEPROM
356 335 movff EEDATA, INDF1 ; restore option register
357 ; Read one byte from EEPROM 336 return
358 call read_eeprom
359 movff EEDATA, INDF1 ; And restore option register.
360 return
361
362 option_restore_string: 337 option_restore_string:
363 call read_eeprom ; Read one byte, and 338 call read_eeprom ; read one byte, and...
364 movff EEDATA,POSTINC1 ; restore it 339 movff EEDATA,POSTINC1 ; ... restore it
365 infsnz EEADR,F 340 infsnz EEADR,F
366 incf EEADRH,F 341 incf EEADRH,F
367 342 decfsz opt_max ; decrement string length
368 decfsz opt_max ; Decrement string length 343 bra option_restore_string ; loop while not finished
369 bra option_restore_string ; And loop while not finished 344 return
370 return 345
371 346 ;=============================================================================
372 ;============================================================================= 347 ; Increment an option, based on type, and boundary
373 ; Increment an option, based on type, and boundary.
374 ; INPUT: FSR0 = option handle 348 ; INPUT: FSR0 = option handle
375 ; OUTPUT: none 349 ; OUTPUT: none
376 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 350 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
351 ;
352 global option_inc ; increment FSR0 option
377 option_inc: 353 option_inc:
378 ; Read type, default and register from table 354 ; read type, default and register from table
379 rcall option_read 355 rcall option_read
380 356
381 ; Switch on type 357 ; switch on type
382 movf opt_type,W 358 movf opt_type,W
383 bz option_inc_uint8 359 bz option_inc_uint8
384 dcfsnz WREG 360 dcfsnz WREG
385 bra option_inc_enum8 361 bra option_inc_enum8
386 dcfsnz WREG 362 dcfsnz WREG
387 bra option_inc_string 363 bra option_inc_string
388 364
389 option_inc_uint8: ; Defaults type too... 365 option_inc_uint8: ; default type too...
390 movf INDF1,W 366 movf INDF1,W
391 addwf opt_inc,W 367 addwf opt_inc,W
392 cpfslt opt_max 368 cpfslt opt_max
393 bra option_inc_1 369 bra option_inc_uint8_0
394 movf opt_min,W 370 movf opt_min,W
395 option_inc_1: 371 option_inc_uint8_0:
396 movwf INDF1 372 movwf INDF1
397 373 option_inc_uint8_1:
398 ; Now some rather crude hack into this routine to unify CCR & pSCR mode setting:
399 movlw .25 ; EEPROM address of option oCCRMode
400 cpfseq opt_eeprom ; skip next line if we deal with this option right now
401 bra option_inc_2
402 btfsc FLAG_pscr_mode ; skip next line if we are not in PSCR mode
403 bcf opt_ccr_mode,1 ; in pSCR mode, opt_ccr_mode may only be 0 or 1
404
405 option_inc_2:
406 ; Now some rather crude hack into this routine to make CCR Calibration more convenient: 374 ; Now some rather crude hack into this routine to make CCR Calibration more convenient:
407 movlw .149 ; EEPROM address of option CalGasO2 375 movlw .149 ; EEPROM address of option CalGasO2
408 cpfseq opt_eeprom ; skip next line if we deal with this option right now 376 cpfseq opt_eeprom ; editing CalGasO2 right now?
409 return 377 return ; NO - done (or bra option_inc_uint8_2)
410 378 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR
411 btfsc FLAG_pscr_mode ; skip next line if we are not in PSCR mode 379 decfsz WREG,W ; - in CCR mode?
412 return 380 return ; NO - done
413 movlw .26 381 movlw .26 ; YES -
414 cpfseq INDF1 ; skip next line if current option value is = 26 382 cpfseq INDF1 ; - option value = 26 ?
415 return 383 return ; NO - done
416 movlw .95 ; current option value =26, advance it to 95 384 movlw .95 ; YES - advance it to 95
417 movwf INDF1 385 movwf INDF1 ; - store it
418 return 386 return
419 387
420 388 option_inc_enum8: ; always +1
421 option_inc_enum8: ; Always +1
422 incf INDF1,W 389 incf INDF1,W
423 cpfsgt opt_max 390 cpfsgt opt_max
424 clrf WREG 391 clrf WREG
425 movwf INDF1 392 movwf INDF1
426 return 393 option_inc_enum8_1:
427 394 ; Now some rather crude hack into this routine to unify CCR & pSCR mode setting
428 395 movlw .25 ; EEPROM address of option oCCRMode
429 option_inc_string: ; No editing yet... 396 cpfseq opt_eeprom ; editing oCCRMode right now?
430 return 397 bra option_inc_enum8_2 ; NO - check next option
431 398 btfsc analog_o2_input ; YES - does hosting OSTC have an analog interface?
432 ;============================================================================= 399 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed
433 ; Strcat option into FSR2 buffer. 400 btfsc optical_input ; does hosting OSTC have an optical interface?
401 bra option_inc_enum8_1a ; YES - setting 'sensor' allowed
402 movf INDF1,W ; NO to both - get mode (=0: fixed SP, =1: Sensor, =2: AutoSP)
403 xorlw .1 ; - in sensor mode?
404 bnz option_inc_enum8_1a ; NO - continue with next check
405 incf INDF1,F ; YES - advance option value to AutoSP
406 option_inc_enum8_1a:
407 movff opt_dive_mode,WREG ; get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR
408 xorlw .4 ; in pSCR mode?
409 bnz option_inc_enum8_1_exit ; NO - done
410 bcf INDF1,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP)
411 option_inc_enum8_1_exit:
412 return ; done
413 option_inc_enum8_2:
414 ; (unused)
415 option_inc_enum8_3:
416
417 IFDEF _rx_functions
418 global option_cleanup_oTrMode_CCR ; embedded clean-up entry-point
419 global option_cleanup_oTrMode_no_CCR ; embedded clean-up entry-point
420 ; Now some rather crude hack to correct opt_TR_mode in dependency of opt_dive_mode
421 movlw .8 ; EEPROM address of option opt_dive_mode
422 cpfseq opt_eeprom ; editing opt_dive_mode right now?
423 bra option_inc_enum8_4 ; NO - check next option
424 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR
425 decfsz WREG,W ; dive mode = 1 CCR?
426 bra option_inc_enum8_3a ; NO - in any other mode
427 option_cleanup_oTrMode_CCR: ; entry point from cleanup during restart
428 movff opt_TR_mode,WREG ; YES - get TR mode
429 xorlw .2 ; - mode = 2 (ind.double)?
430 bnz option_inc_enum8_3_exit ; NO - done
431 bra option_inc_enum8_3_reset ; YES - revert mode to 1 (on)
432 option_inc_enum8_3a: ; any mode other than CCR
433 option_cleanup_oTrMode_no_CCR: ; entry point from cleanup during restart
434 movff opt_TR_mode,WREG ; get TR mode
435 xorlw .3 ; mode = 3 (CCR Dil+O2)?
436 bnz option_inc_enum8_3_exit ; NO - done
437 option_inc_enum8_3_reset: ; YES - revert to mode 1 (on)
438 movlw .1 ; load coding of mode "on"
439 movff WREG,opt_TR_mode ; write to option
440 option_inc_enum8_3_exit:
441 return ; done
442 option_inc_enum8_4:
443 ; Now some rather crude hack to advance opt_TR_mode in dependency of opt_dive_mode
444 movlw .222 ; EEPROM address of option opt_TR_mode
445 cpfseq opt_eeprom ; editing opt_TR_mode right now?
446 bra option_inc_enum8_5 ; NO - check next option
447 movff opt_dive_mode,WREG ; YES - get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR
448 decfsz WREG,W ; dive mode = 1 CCR?
449 bra option_inc_enum8_4a ; NO - in any other mode
450 movf INDF1,W ; YES - get option value (TR mode)
451 xorlw .2 ; - mode = 2 (ind.double)?
452 bnz option_inc_enum8_4_exit ; NO - done
453 incf INDF1,F ; YES - advance option value to 3 (CCR Dil+O2)
454 bra option_inc_enum8_4_exit ; - done
455 option_inc_enum8_4a: ; any mode other than CCR
456 movf INDF1,W ; get option value (TR mode)
457 xorlw .3 ; mode = 3 (CCR Dil+O2)?
458 bnz option_inc_enum8_4_exit ; NO - done
459 clrf INDF1 ; YES - advance option value to 0 "off"
460 option_inc_enum8_4_exit:
461 return ; done
462 ENDIF
463
464 option_inc_enum8_5:
465 return
466
467
468 option_inc_string: ; no editing available
469 return
470
471
472 global option_cleanup_oCCRMode
473 global option_cleanup_oCCRMode_pSCR
474 global option_cleanup_oCCRMode_CCR
475 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
476 banksel opt_dive_mode ; select options bank
477 movf opt_dive_mode,W ; get dive mode: 0=OC, 1=CCR, 2=Gauge, 3=Apnea, 4=pSCR
478 xorlw .4 ; in pSCR mode?
479 bnz option_cleanup_oCCRMode_CCR ; NO - check if sensor is available on hosting OSTC
480 option_cleanup_oCCRMode_pSCR: ; jump-in from start.asm if known to be in pSCR mode
481 banksel opt_ccr_mode ; select options bank
482 bcf opt_ccr_mode,1 ; YES - clear bit 1 because opt_ccr_mode may only be 0 or 1 (reverts AutoSP to calculated SP)
483 option_cleanup_oCCRMode_CCR: ; continue from above & jump-in from start.asm if known to be in CCR mode
484 banksel common ; flags are located in bank common
485 btfsc analog_o2_input ; does hosting OSTC have an analog interface?
486 bra option_cleanup_oCCRMode_exit ; YES - setting 'sensor' allowed
487 btfsc optical_input ; does hosting OSTC have an optical interface?
488 bra option_cleanup_oCCRMode_exit ; YES - setting 'sensor' allowed
489 banksel opt_ccr_mode ; NO to both - select options bank
490 movf opt_ccr_mode,W ; - get CCR mode
491 xorlw .1 ; - CCR mode = sensor?
492 bnz option_cleanup_oCCRMode_exit ; NO - ok
493 clrf opt_ccr_mode ; - YES - set CCR mode to fixed SP (0)
494 option_cleanup_oCCRMode_exit:
495 banksel common ; back to bank common
496 return ; done
497
498
499 ;=============================================================================
500 ; Strcat option into FSR2 buffer
501 ;
502 global option_draw ; STRCAT FRS0 option
434 option_draw: 503 option_draw:
435 ; Read type, default and register from table 504 ; Read type, default and register from table
436 rcall option_read 505 rcall option_read
437 506
438 ; Switch on type 507 ; Switch on type
440 bz option_draw_uint8 509 bz option_draw_uint8
441 dcfsnz WREG 510 dcfsnz WREG
442 bra option_draw_enum8 511 bra option_draw_enum8
443 dcfsnz WREG 512 dcfsnz WREG
444 bra option_draw_string 513 bra option_draw_string
445 return ; Unknown: return... 514 return ; unknown, return
515 option_draw_string:
516 movff POSTINC1,POSTINC2
517 decfsz opt_max
518 bra option_draw_string
519 return
520
446 521
447 option_draw_uint8: 522 option_draw_uint8:
448 movff INDF1,lo ; Draw value. 523 movff INDF1,lo ; draw value
449 bsf leftbind 524 bsf leftbind
450 output_8 525 output_8
451 bcf leftbind 526 bcf leftbind
452 clrf INDF2 ; Make sure to close string... 527 clrf INDF2 ; make sure to close string
453 528 movf opt_unit+0,W ; is there a unit to append?
454 movf opt_unit+0,W ; Is there a unit to append ?
455 iorwf opt_unit+1,W 529 iorwf opt_unit+1,W
456 rcall option_draw_unit 530 rcall option_draw_unit ; YES
457 531 movf opt_default,W ; get default value
458 movf opt_default,W ; Default value 532 cpfseq lo ; compare with current value, equal?
459 cpfseq lo ; Current value 533 bra option_draw_uint8_2 ; NO - not default, add *
460 bra option_draw_uint8_2 ; Not default, add * 534 return ; YES - default, done
461 return ; Default, Done.
462 option_draw_uint8_2: 535 option_draw_uint8_2:
463 PUTC "*" 536 PUTC "*" ; print "*"
464 return ; Done. 537 return ; done
465
466 option_draw_unit: 538 option_draw_unit:
467 movff opt_unit+0,FSR1L 539 movff opt_unit+0,FSR1L
468 movff opt_unit+1,FSR1H 540 movff opt_unit+1,FSR1H
469 goto strcat_text 541 goto strcat_text
470 542
471 543
472 ;---- Draw an enumerated value (set of translated strings) 544 ;---- Draw an enumerated value (set of translated strings)
473 option_draw_enum8: 545 option_draw_enum8:
474 movf INDF1,W ; Get current value. 546 movf INDF1,W ; get current value
475 cpfsgt opt_max ; Bound value 547 cpfsgt opt_max ; bound value
476 clrf WREG 548 clrf WREG
477 addwf WREG ; *= 2 549 addwf WREG ; *= 2
478 addwf opt_inc,W ; Base text + 2 * value 550 addwf opt_inc,W ; base text + 2 * value
479 movwf FSR1L 551 movwf FSR1L
480 movlw .0 552 movlw .0
481 addwfc opt_min,W ; Propagate carry 553 addwfc opt_min,W ; propagate carry...
482 movwf FSR1H ; Into FSR1 554 movwf FSR1H ; ...into FSR1
483 goto strcat_text 555 goto strcat_text
484 556
485 option_draw_string:
486 movff POSTINC1,POSTINC2
487 decfsz opt_max
488 bra option_draw_string
489 return
490 557
491 END 558 END