comparison src/options.asm @ 582:b455b31ce022

work on 2.97 stable
author heinrichsweikamp
date Mon, 26 Feb 2018 16:40:28 +0100
parents 8b7ea27ea1fa
children ca4556fb60b9
comparison
equal deleted inserted replaced
581:f5de1ff88814 582:b455b31ce022
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File options.asm REFACTORED VERSION V2.91 3 ; File options.asm REFACTORED VERSION V2.97
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 ;=============================================================================
11 ; 11 ;
12 ; RATIONALS: 12 ; RATIONALS:
13 ; 13 ;
14 ; Provides a centralized file with 14 ; Provides a centralized file with
15 15
16 #include "hwos.inc" ; Mandatory header 16 #include "hwos.inc" ; Mandatory header
17 #include "strings.inc" 17 #include "strings.inc"
18 #include "convert.inc" 18 #include "convert.inc"
19 #include "ghostwriter.inc" 19 #include "ghostwriter.inc"
20 #include "eeprom_rs232.inc" 20 #include "eeprom_rs232.inc"
21 #include "external_flash.inc" 21 #include "external_flash.inc"
22 #include "wait.inc" 22 #include "wait.inc"
23 23
24 extern write_eeprom 24 extern write_eeprom
25 extern read_eeprom 25 extern read_eeprom
26 extern eeprom_serial_save,eeprom_opt_backup 26 extern eeprom_serial_save,eeprom_opt_backup
27 extern option_table_begin,option_table_end 27 extern option_table_begin,option_table_end
28 28
29 global option_reset_all ; Reset all options to factory default. 29 global option_reset_all ; Reset all options to factory default.
30 global option_check_all ; Check all option and reset option if out of min/max boundary 30 global option_check_all ; Check all option and reset option if out of min/max boundary
31 global option_reset ; Reset FSR0 option to factory default. 31 global option_reset ; Reset FSR0 option to factory default.
32 global option_save_all ; Save options to EEPROM. 32 global option_save_all ; Save options to EEPROM.
33 global option_restore_all ; Restore options from EEPROM. 33 global option_restore_all ; Restore options from EEPROM.
34 global option_inc ; Increment FSR0 option. 34 global option_inc ; Increment FSR0 option.
35 global option_draw ; STRCAT FRS0 option. 35 global option_draw ; STRCAT FRS0 option.
36 36
37 37
38 ;============================================================================= 38 gui CODE ; Appends to other GUI segment
39 CBLOCK tmp+0x12 ; Reserve space for wordprocessor & convert 39
40 opt_type 40 ;=============================================================================
41 opt_default 41 ; Reset all options to factory defaults.
42 opt_inc ; Also default+1 (string), and enum low
43 opt_min ; also enum high
44 opt_max
45 opt_unit:2 ; Multi-lingual unit text.
46 opt_eeprom
47 opt_backup_tbl:3
48 ; Reserved to tmp+0x1C...
49 ENDC
50
51 gui CODE ; Appends to other GUI segment
52 ;=============================================================================
53 ; Reset all options to factory defauts.
54 ; 42 ;
55 ; INPUT: none 43 ; INPUT: none
56 ; OUTPUT: none 44 ; OUTPUT: none
57 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 45 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
58 46
59 option_reset_all: 47 option_reset_all:
60 clrf EEADRH 48 clrf EEADRH
61 read_int_eeprom .2 49 read_int_eeprom .2
62 tstfsz EEDATA ; Total dives=0? 50 tstfsz EEDATA ; Total dives=0?
63 bra option_reset_all2 ; No, skip resetting logbook 51 bra option_reset_all2 ; No, skip resetting logbook
64 read_int_eeprom .3 52 read_int_eeprom .3
65 tstfsz EEDATA ; Total dives=0? 53 tstfsz EEDATA ; Total dives=0?
66 bra option_reset_all2 ; No, skip resetting logbook 54 bra option_reset_all2 ; No, skip resetting logbook
67 55
68 clrf EEDATA 56 clrf EEDATA
69 write_int_eeprom .4 57 write_int_eeprom .4
70 write_int_eeprom .5 58 write_int_eeprom .5
71 write_int_eeprom .6 59 write_int_eeprom .6
72 write_int_eeprom .2 ; Also, delete total dive counter 60 write_int_eeprom .2 ; Also, delete total dive counter
73 write_int_eeprom .3 61 write_int_eeprom .3
74 call ext_flash_erase_logbook ; And complete logbook (!) 62 call ext_flash_erase_logbook ; And complete logbook (!)
75 63
76 option_reset_all2: 64 option_reset_all2:
77 clrf lo 65 clrf lo
78 clrf hi 66 clrf hi
79 call do_logoffset_common_write ; reset Logbook offset 67 call do_logoffset_common_write ; reset Logbook offset
80 68
81 ; Point to option table begin 69 ; Point to option table begin
82 movlw LOW(option_table_begin) 70 movlw LOW(option_table_begin)
83 movwf FSR0L 71 movwf FSR0L
84 movlw HIGH(option_table_begin) 72 movlw HIGH(option_table_begin)
85 movwf FSR0H 73 movwf FSR0H
86 option_reset_all_1: 74 option_reset_all_1:
87 movlw LOW(option_table_end) 75 movlw LOW(option_table_end)
88 cpfseq FSR0L 76 cpfseq FSR0L
89 bra option_reset_all_2 ; Not yet done... 77 bra option_reset_all_2 ; Not yet done...
90 movlw HIGH(option_table_end) 78 movlw HIGH(option_table_end)
91 cpfseq FSR0H 79 cpfseq FSR0H
92 bra option_reset_all_2 ; Not yet done... 80 bra option_reset_all_2 ; Not yet done...
93 return ; All done. 81 return ; All done.
94 option_reset_all_2: 82 option_reset_all_2:
95 rcall option_reset ; Reset one option. 83 rcall option_reset ; Reset one option.
96 bra option_reset_all_1 ; and loop. 84 bra option_reset_all_1 ; and loop.
97 85
98 ;============================================================================= 86 ;=============================================================================
99 ; Check all option and reset option if out of min/max boundary 87 ; Check all option and reset option if out of min/max boundary
100 ; 88 ;
101 ; INPUT: none 89 ; INPUT: none
102 ; OUTPUT: none 90 ; OUTPUT: none
103 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2 91 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
104 option_check_all: 92 option_check_all:
105 ; Point to option table begin 93 ; Point to option table begin
106 movlw LOW(option_table_begin) 94 movlw LOW(option_table_begin)
107 movwf FSR0L 95 movwf FSR0L
108 movlw HIGH(option_table_begin) 96 movlw HIGH(option_table_begin)
109 movwf FSR0H 97 movwf FSR0H
110 98
111 option_check_all_1: 99 option_check_all_1:
112 movlw LOW(option_table_end) 100 movlw LOW(option_table_end)
113 cpfseq FSR0L 101 cpfseq FSR0L
114 bra option_check_all_2 ; Not yet done... 102 bra option_check_all_2 ; Not yet done...
115 movlw HIGH(option_table_end) 103 movlw HIGH(option_table_end)
116 cpfseq FSR0H 104 cpfseq FSR0H
117 bra option_check_all_2 ; Not yet done... 105 bra option_check_all_2 ; Not yet done...
118 return ; All done. 106 return ; All done.
119 option_check_all_2: 107 option_check_all_2:
120 rcall option_check ; check one option. 108 rcall option_check ; check one option.
121 bra option_check_all_1 ; and loop 109 bra option_check_all_1 ; and loop
122 110
123 ;============================================================================= 111 ;=============================================================================
124 ; Read option handle 112 ; Read option handle
125 ; INPUT: FSR0 = option handle 113 ; INPUT: FSR0 = option handle
126 ; OUTPUT: FSR1 = address of variable. 114 ; OUTPUT: FSR1 = address of variable.
127 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 115 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
128 option_read: 116 option_read:
129 movff FSR0L,TBLPTRL 117 movff FSR0L,TBLPTRL
130 movlw HIGH(option_table_begin); Get 8 high bits. 118 movlw HIGH(option_table_begin) ; Get 8 high bits.
131 andlw 0xF0 ; Keep only the 4 highest ones. 119 andlw 0xF0 ; Keep only the 4 highest ones.
132 iorwf FSR0H,W ; Cat with the known 4 lower ones. 120 iorwf FSR0H,W ; Cat with the known 4 lower ones.
133 movwf TBLPTRH ; And we have the high byte. 121 movwf TBLPTRH ; And we have the high byte.
134 movlw UPPER(option_table_begin) 122 movlw UPPER(option_table_begin)
135 movwf TBLPTRU 123 movwf TBLPTRU
136 124
137 ; Read type, default and register from table 125 ; Read type, default and register from table
138 tblrd*+ 126 tblrd*+
139 movff TABLAT,opt_type 127 movff TABLAT,opt_type
140 tblrd*+ 128 tblrd*+
141 movff TABLAT,opt_default 129 movff TABLAT,opt_default
142 tblrd*+ 130 tblrd*+
143 movff TABLAT,opt_inc 131 movff TABLAT,opt_inc
144 tblrd*+ 132 tblrd*+
145 movff TABLAT,opt_min 133 movff TABLAT,opt_min
146 tblrd*+ 134 tblrd*+
147 movff TABLAT,opt_max 135 movff TABLAT,opt_max
148 tblrd*+ 136 tblrd*+
149 movff TABLAT,opt_eeprom 137 movff TABLAT,opt_eeprom
150 tblrd*+ 138 tblrd*+
151 movff TABLAT,opt_unit+0 139 movff TABLAT,opt_unit+0
152 tblrd*+ 140 tblrd*+
153 movff TABLAT,opt_unit+1 141 movff TABLAT,opt_unit+1
154 tblrd*+ 142 tblrd*+
155 movff TABLAT,FSR1L 143 movff TABLAT,FSR1L
156 tblrd*+ 144 tblrd*+
157 movff TABLAT,FSR1H 145 movff TABLAT,FSR1H
158 movff TBLPTRL,FSR0L ; Advance handle too, for reset_all 146 movff TBLPTRL,FSR0L ; Advance handle too, for reset_all
159 movff TBLPTRH,FSR0H 147 movff TBLPTRH,FSR0H
160 return 148 return
161 149
162 ;============================================================================= 150 ;=============================================================================
163 ; Check one option and reset if it's out of it's min/max boundaries 151 ; Check one option and reset if it's out of it's min/max boundaries
164 ; INPUT: FSR0 = option handle 152 ; INPUT: FSR0 = option handle
165 ; OUTPUT: none 153 ; OUTPUT: none
166 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2, lo 154 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2, lo
167 ; 155 ;
168 option_check: 156 option_check:
169 ; Read type, default and register from table 157 ; Read type, default and register from table
170 rcall option_read 158 rcall option_read
171 159
172 ; Switch on type 160 ; Switch on type
173 movf opt_type,W ; Type == STRING ? 161 movf opt_type,W ; Type == STRING ?
174 xorlw 2 162 xorlw 2
175 bz option_check_string ; String: Do not reset strings 163 bz option_check_string ; String: Do not reset strings
176 164
177 movf opt_type,W ; Type == ENUM8 ? 165 movf opt_type,W ; Type == ENUM8 ?
178 xorlw 1 166 xorlw 1
179 bz option_check_enum8 ; ENUM8: Check if lower then max. value only 167 bz option_check_enum8 ; ENUM8: Check if lower then max. value only
180 168
181 tstfsz opt_min ; opt_min=0? 169 tstfsz opt_min ; opt_min=0?
182 bra option_check_both ; no 170 bra option_check_both ; no
183 bra option_check_enum8 ; Check max only 171 bra option_check_enum8 ; Check max only
184 172
185 option_check_both: 173 option_check_both:
186 decf opt_min,W 174 decf opt_min,W
187 cpfsgt INDF1 ; bigger then opt_min-1? 175 cpfsgt INDF1 ; bigger then opt_min-1?
188 bra option_check_reset ; No, reset option 176 bra option_check_reset ; No, reset option
189 option_check_enum8: ; ENUM8: Check max only 177 option_check_enum8: ; ENUM8: Check max only
190 infsnz opt_max,W ; Max = 255? 178 infsnz opt_max,W ; Max = 255?
191 return ; Yes, igonore max. test 179 return ; Yes, ignore max. test
192 cpfslt INDF1 ; smaller then opt_max+1? 180 cpfslt INDF1 ; smaller then opt_max+1?
193 bra option_check_reset ; No, reset option 181 bra option_check_reset ; No, reset option
194 return ; in range, return 182 return ; in range, return
195 183
196 option_check_reset: 184 option_check_reset:
197 movff opt_default,INDF1 ; reset option to default 185 movff opt_default,INDF1 ; reset option to default
198 return ; Done. 186 return ; Done.
199 187
200 option_check_string: 188 option_check_string:
201 return 189 return
202 190
203 ;============================================================================= 191 ;=============================================================================
204 ; Reset an option to its default value. 192 ; Reset an option to its default value.
205 ; INPUT: FSR0 = option handle 193 ; INPUT: FSR0 = option handle
206 ; OUTPUT: none 194 ; OUTPUT: none
207 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2 195 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2
208 ; 196 ;
209 option_reset: 197 option_reset:
210 ; Read type, default and register from table 198 ; Read type, default and register from table
211 rcall option_read 199 rcall option_read
212 200
213 ; Switch on type 201 ; Switch on type
214 movf opt_type,W ; Type == STRING ? 202 movf opt_type,W ; Type == STRING ?
215 xorlw 2 203 xorlw 2
216 bz opt_reset_string ; YES: special copy 204 bz opt_reset_string ; YES: special copy
217 205
218 movff opt_default,INDF1 ; NO: just a 8bit indirect copy 206 movff opt_default,INDF1 ; NO: just a 8bit indirect copy
219 return 207 return
220 208
221 opt_reset_string: 209 opt_reset_string:
222 movff FSR1L,FSR2L ; set string destination address. 210 movff FSR1L,FSR2L ; set string destination address.
223 movff FSR1H,FSR2H 211 movff FSR1H,FSR2H
224 212
225 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
226 movff opt_default+1,FSR1H 214 movff opt_default+1,FSR1H
227 215
228 movff TBLPTRL,opt_backup_tbl+0; TBLPTR trashed by text routine... 216 movff TBLPTRL,opt_backup_tbl+0 ; TBLPTR trashed by text routine...
229 movff TBLPTRH,opt_backup_tbl+1 217 movff TBLPTRH,opt_backup_tbl+1
230 movff TBLPTRU,opt_backup_tbl+2 218 movff TBLPTRU,opt_backup_tbl+2
231 219
232 call strcat_text ; Copy translated text to FSR2 220 call strcat_text ; Copy translated text to FSR2
233 221
234 movff opt_backup_tbl+0,TBLPTRL 222 movff opt_backup_tbl+0,TBLPTRL
235 movff opt_backup_tbl+1,TBLPTRH 223 movff opt_backup_tbl+1,TBLPTRH
236 movff opt_backup_tbl+2,TBLPTRU 224 movff opt_backup_tbl+2,TBLPTRU
237 225
238 return 226 return
239 227
240 ;============================================================================= 228 ;=============================================================================
241 ; Save all options to EEPROM 229 ; Save all options to EEPROM
242 option_save_all: 230 option_save_all:
243 ;---- Save option serial into EEPROM to detect reset and new version 231 ;---- Save option serial into EEPROM to detect reset and new version
244 movlw LOW(eeprom_serial_save) 232 movlw LOW(eeprom_serial_save)
245 movwf EEADR 233 movwf EEADR
246 movlw HIGH(eeprom_serial_save) 234 movlw HIGH(eeprom_serial_save)
247 movwf EEADRH 235 movwf EEADRH
248 movlw LOW(eeprom_opt_serial) 236 movlw LOW(eeprom_opt_serial)
249 movwf EEDATA 237 movwf EEDATA
250 call write_eeprom 238 call write_eeprom
251 incf EEADR,F 239 incf EEADR,F
252 movlw HIGH(eeprom_opt_serial) 240 movlw HIGH(eeprom_opt_serial)
253 movwf EEDATA 241 movwf EEDATA
254 call write_eeprom 242 call write_eeprom
255 243
256 ;---- Save all options 244 ;---- Save all options
257 movlw LOW(option_table_begin) 245 movlw LOW(option_table_begin)
258 movwf FSR0L 246 movwf FSR0L
259 movlw HIGH(option_table_begin) 247 movlw HIGH(option_table_begin)
260 movwf FSR0H 248 movwf FSR0H
261 249
262 option_save_all_1: 250 option_save_all_1:
263 movlw LOW(option_table_end) 251 movlw LOW(option_table_end)
264 cpfseq FSR0L 252 cpfseq FSR0L
265 bra option_save_all_2 ; Not yet done... 253 bra option_save_all_2 ; Not yet done...
266 movlw HIGH(option_table_end) 254 movlw HIGH(option_table_end)
267 cpfseq FSR0H 255 cpfseq FSR0H
268 bra option_save_all_2 ; Not yet done... 256 bra option_save_all_2 ; Not yet done...
269 return ; All done. 257 return ; All done.
270 option_save_all_2: 258 option_save_all_2:
271 rcall option_save ; Save one option. 259 rcall option_save ; Save one option.
272 bra option_save_all_1 ; and loop. 260 bra option_save_all_1 ; and loop.
273 261
274 global option_save 262 global option_save
275 option_save: 263 option_save:
276 rcall option_read 264 rcall option_read
277 incf opt_eeprom,W ; Should we save it ? 265 incf opt_eeprom,W ; Should we save it ?
278 btfsc STATUS,Z ; eeprom address is FFh ? 266 btfsc STATUS,Z ; EEPROM address is FFh ?
279 return ; YES: nothing to do. 267 return ; YES: nothing to do.
280 268
281 movf opt_eeprom,W ; Compute backup address in EEPROM 269 movf opt_eeprom,W ; Compute backup address in EEPROM
282 addlw LOW(eeprom_opt_backup) ; Add offset 270 addlw LOW(eeprom_opt_backup) ; Add offset
283 movwf EEADR 271 movwf EEADR
284 movlw HIGH(eeprom_opt_backup) 272 movlw HIGH(eeprom_opt_backup)
285 btfsc STATUS,C ; >256 273 btfsc STATUS,C ; >256
286 addlw .1 ; Yes: +1 274 addlw .1 ; Yes: +1
287 movwf EEADRH 275 movwf EEADRH
288 276
289 movf opt_type,W ; Option type is string ? 277 movf opt_type,W ; Option type is string ?
290 xorlw 2 278 xorlw 2
291 bz option_save_string 279 bz option_save_string
292 280
293 ; One byte to save to eeprom 281 ; One byte to save to EEPROM
294 movff INDF1,EEDATA 282 movff INDF1,EEDATA
295 btfss EEADRH,1 ; EEADR:EEADRH < 512? 283 btfss EEADRH,1 ; EEADR:EEADRH < 512?
296 call write_eeprom ; Yes, write 284 call write_eeprom ; Yes, write
297 return 285 return
298 286
299 option_save_string: 287 option_save_string:
300 movff POSTINC1,EEDATA ; Write one byte 288 movff POSTINC1,EEDATA ; Write one byte
301 btfss EEADRH,1 ; EEADR:EEADRH < 512? 289 btfss EEADRH,1 ; EEADR:EEADRH < 512?
302 call write_eeprom ; Yes, write 290 call write_eeprom ; Yes, write
303 infsnz EEADR,F 291 infsnz EEADR,F
304 incf EEADRH,F 292 incf EEADRH,F
305 293
306 decfsz opt_max ; Decrement string length 294 decfsz opt_max ; Decrement string length
307 bra option_save_string ; And loop while not finished 295 bra option_save_string ; And loop while not finished
308 296
309 return 297 return
310 ;============================================================================= 298 ;=============================================================================
311 299
312 option_restore_all: 300 option_restore_all:
313 ;---- Read option serial from EEPROM 301 ;---- Read option serial from EEPROM
314 movlw LOW(eeprom_serial_save) 302 movlw LOW(eeprom_serial_save)
315 movwf EEADR 303 movwf EEADR
316 movlw HIGH(eeprom_serial_save) 304 movlw HIGH(eeprom_serial_save)
317 movf EEADRH 305 movf EEADRH
318 call read_eeprom 306 call read_eeprom
319 movlw LOW(eeprom_opt_serial) 307 movlw LOW(eeprom_opt_serial)
320 xorwf EEDATA,W 308 xorwf EEDATA,W
321 bnz option_restore_bad ; Auto reset if changed. 309 bnz option_restore_bad ; Auto reset if changed.
322 incf EEADR,F 310 incf EEADR,F
323 call read_eeprom 311 call read_eeprom
324 movlw HIGH(eeprom_opt_serial) 312 movlw HIGH(eeprom_opt_serial)
325 xorwf EEDATA,W 313 xorwf EEDATA,W
326 bz option_restore_ok ; Auto reset if changed. 314 bz option_restore_ok ; Auto reset if changed.
327 315
328 option_restore_bad: 316 option_restore_bad:
329 call option_reset_all ; Reset RAM contains 317 call option_reset_all ; Reset RAM contains
330 goto option_save_all ; Then save to EEPROM 318 goto option_save_all ; Then save to EEPROM
331 319
332 ;---- Proper restore 320 ;---- Proper restore
333 option_restore_ok: 321 option_restore_ok:
334 movlw LOW(option_table_begin) 322 movlw LOW(option_table_begin)
335 movwf FSR0L 323 movwf FSR0L
336 movlw HIGH(option_table_begin) 324 movlw HIGH(option_table_begin)
337 movwf FSR0H 325 movwf FSR0H
338 326
339 option_restore_all_1: 327 option_restore_all_1:
340 movlw LOW(option_table_end) 328 movlw LOW(option_table_end)
341 cpfseq FSR0L 329 cpfseq FSR0L
342 bra option_restore_all_2 ; Not yet done... 330 bra option_restore_all_2 ; Not yet done...
343 movlw HIGH(option_table_end) 331 movlw HIGH(option_table_end)
344 cpfseq FSR0H 332 cpfseq FSR0H
345 bra option_restore_all_2 ; Not yet done... 333 bra option_restore_all_2 ; Not yet done...
346 return ; All done. 334 return ; All done.
347 option_restore_all_2: 335 option_restore_all_2:
348 rcall option_restore ; Restore one option. 336 rcall option_restore ; Restore one option.
349 bra option_restore_all_1 ; and loop. 337 bra option_restore_all_1 ; and loop.
350 338
351 option_restore: 339 option_restore:
352 rcall option_read 340 rcall option_read
353 incf opt_eeprom,W ; Should we save it ? 341 incf opt_eeprom,W ; Should we save it ?
354 btfsc STATUS,Z ; eeprom address is FFh ? 342 btfsc STATUS,Z ; EEPROM address is FFh ?
355 return ; YES: nothing to do. 343 return ; YES: nothing to do.
356 344
357 movf opt_eeprom,W ; Compute backup address in EEPROM 345 movf opt_eeprom,W ; Compute backup address in EEPROM
358 addlw LOW(eeprom_opt_backup) ; Add offset 346 addlw LOW(eeprom_opt_backup) ; Add offset
359 movwf EEADR 347 movwf EEADR
360 movlw HIGH(eeprom_opt_backup) 348 movlw HIGH(eeprom_opt_backup)
361 btfsc STATUS,C ; >256 349 btfsc STATUS,C ; >256
362 addlw .1 ; Yes: +1 350 addlw .1 ; Yes: +1
363 movwf EEADRH 351 movwf EEADRH
364 352
365 movf opt_type,W ; Option type is string ? 353 movf opt_type,W ; Option type is string ?
366 xorlw 2 354 xorlw 2
367 bz option_restore_string 355 bz option_restore_string
368 356
369 ; Read one byte from eeprom 357 ; Read one byte from EEPROM
370 call read_eeprom 358 call read_eeprom
371 movff EEDATA, INDF1 ; And restore option register. 359 movff EEDATA, INDF1 ; And restore option register.
372 return 360 return
373 361
374 option_restore_string: 362 option_restore_string:
375 call read_eeprom ; Read one byte, and 363 call read_eeprom ; Read one byte, and
376 movff EEDATA,POSTINC1 ; restore it 364 movff EEDATA,POSTINC1 ; restore it
377 infsnz EEADR,F 365 infsnz EEADR,F
378 incf EEADRH,F 366 incf EEADRH,F
379 367
380 decfsz opt_max ; Decrement string length 368 decfsz opt_max ; Decrement string length
381 bra option_restore_string ; And loop while not finished 369 bra option_restore_string ; And loop while not finished
382 return 370 return
383 371
384 ;============================================================================= 372 ;=============================================================================
385 ; Increment an option, based on type, and boundary. 373 ; Increment an option, based on type, and boundary.
386 ; INPUT: FSR0 = option handle 374 ; INPUT: FSR0 = option handle
387 ; OUTPUT: none 375 ; OUTPUT: none
388 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1 376 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
389 option_inc: 377 option_inc:
390 ; Read type, default and register from table 378 ; Read type, default and register from table
391 rcall option_read 379 rcall option_read
392 380
393 ; Switch on type 381 ; Switch on type
394 movf opt_type,W 382 movf opt_type,W
395 bz option_inc_uint8 383 bz option_inc_uint8
396 dcfsnz WREG 384 dcfsnz WREG
397 bra option_inc_enum8 385 bra option_inc_enum8
398 dcfsnz WREG 386 dcfsnz WREG
399 bra option_inc_string 387 bra option_inc_string
400 388
401 389 option_inc_uint8: ; Defaults type too...
402 option_inc_uint8: ; Defaults type too... 390 movf INDF1,W
403 movf INDF1,W 391 addwf opt_inc,W
404 addwf opt_inc,W 392 cpfslt opt_max
405 cpfslt opt_max 393 bra option_inc_1
406 bra option_inc_1 394 movf opt_min,W
407 movf opt_min,W
408 option_inc_1: 395 option_inc_1:
409 movwf INDF1 396 movwf INDF1
410 397
411 ; NEW FROM HERE... ## voting logic (allow sensors for pSCR)
412 ; Now some rather crude hack into this routine to unify CCR & pSCR mode setting: 398 ; Now some rather crude hack into this routine to unify CCR & pSCR mode setting:
413 movlw .25 ; eeprom address of option oCCRMode 399 movlw .25 ; EEPROM address of option oCCRMode
414 cpfseq opt_eeprom ; skip next line if we deal with this option right now 400 cpfseq opt_eeprom ; skip next line if we deal with this option right now
415 bra option_inc_2 401 bra option_inc_2
416 btfsc FLAG_pscr_mode ; skip next line if we are not in PSCR mode 402 btfsc FLAG_pscr_mode ; skip next line if we are not in PSCR mode
417 bcf opt_ccr_mode,1 ; in pSCR mode, opt_ccr_mode may only be 0 or 1 403 bcf opt_ccr_mode,1 ; in pSCR mode, opt_ccr_mode may only be 0 or 1
418 404
419 option_inc_2: 405 option_inc_2:
420 ; ...UNTILL HERE
421 ; Now some rather crude hack into this routine to make CCR Calibration more convenient: 406 ; Now some rather crude hack into this routine to make CCR Calibration more convenient:
422 movlw .149 ; eeprom address of option CalGasO2 407 movlw .149 ; EEPROM address of option CalGasO2
423 cpfseq opt_eeprom ; skip next line if we deal with this option right now 408 cpfseq opt_eeprom ; skip next line if we deal with this option right now
424 return 409 return
425 410
426 btfsc FLAG_pscr_mode ; skip next line if we are not in PSCR mode 411 btfsc FLAG_pscr_mode ; skip next line if we are not in PSCR mode
427 return 412 return
428 movlw .26 413 movlw .26
429 cpfseq INDF1 ; skip next line if current option value is =26 414 cpfseq INDF1 ; skip next line if current option value is = 26
430 return 415 return
431 movlw .95 ; current option value =26, advance it to 95 416 movlw .95 ; current option value =26, advance it to 95
432 movwf INDF1 417 movwf INDF1
433 return 418 return
434 419
435 option_inc_enum8: ; Always +1 420
436 incf INDF1,W 421 option_inc_enum8: ; Always +1
437 cpfsgt opt_max 422 incf INDF1,W
438 clrf WREG 423 cpfsgt opt_max
439 movwf INDF1 424 clrf WREG
440 return 425 movwf INDF1
441 426 return
442 option_inc_string: ; No edition yet... 427
443 return 428
429 option_inc_string: ; No editing yet...
430 return
444 431
445 ;============================================================================= 432 ;=============================================================================
446 ; Strcat option into FSR2 buffer. 433 ; Strcat option into FSR2 buffer.
447 option_draw: 434 option_draw:
448 ; Read type, default and register from table 435 ; Read type, default and register from table
449 rcall option_read 436 rcall option_read
450 437
451 ; Switch on type 438 ; Switch on type
452 movf opt_type,W 439 movf opt_type,W
453 bz option_draw_uint8 440 bz option_draw_uint8
454 dcfsnz WREG 441 dcfsnz WREG
455 bra option_draw_enum8 442 bra option_draw_enum8
456 dcfsnz WREG 443 dcfsnz WREG
457 bra option_draw_string 444 bra option_draw_string
458 return ; Unknown: return... 445 return ; Unknown: return...
459 446
460 option_draw_uint8: 447 option_draw_uint8:
461 movff INDF1,lo ; Draw value. 448 movff INDF1,lo ; Draw value.
462 bsf leftbind 449 bsf leftbind
463 output_8 450 output_8
464 bcf leftbind 451 bcf leftbind
465 clrf INDF2 ; Make sure to close string... 452 clrf INDF2 ; Make sure to close string...
466 453
467 movf opt_unit+0,W ; Is there a unit to append ? 454 movf opt_unit+0,W ; Is there a unit to append ?
468 iorwf opt_unit+1,W 455 iorwf opt_unit+1,W
469 rcall option_draw_unit 456 rcall option_draw_unit
470 457
471 movf opt_default,W ; Default value 458 movf opt_default,W ; Default value
472 cpfseq lo ; Current value 459 cpfseq lo ; Current value
473 bra option_draw_uint8_2 ; Not default, add * 460 bra option_draw_uint8_2 ; Not default, add *
474 return ; Default, Done. 461 return ; Default, Done.
475 option_draw_uint8_2: 462 option_draw_uint8_2:
476 PUTC "*" 463 PUTC "*"
477 return ; Done. 464 return ; Done.
478 465
479 option_draw_unit: 466 option_draw_unit:
480 movff opt_unit+0,FSR1L 467 movff opt_unit+0,FSR1L
481 movff opt_unit+1,FSR1H 468 movff opt_unit+1,FSR1H
482 goto strcat_text 469 goto strcat_text
483
484 470
485 471
486 ;---- Draw an enumerated value (set of translated strings) 472 ;---- Draw an enumerated value (set of translated strings)
487 option_draw_enum8: 473 option_draw_enum8:
488 movf INDF1,W ; Get current value. 474 movf INDF1,W ; Get current value.
489 cpfsgt opt_max ; Bound value 475 cpfsgt opt_max ; Bound value
490 clrf WREG 476 clrf WREG
491 addwf WREG ; *= 2 477 addwf WREG ; *= 2
492 addwf opt_inc,W ; Base text + 2 * value 478 addwf opt_inc,W ; Base text + 2 * value
493 movwf FSR1L 479 movwf FSR1L
494 movlw 0 480 movlw .0
495 addwfc opt_min,W ; Propagate carry 481 addwfc opt_min,W ; Propagate carry
496 movwf FSR1H ; Into FSR1 482 movwf FSR1H ; Into FSR1
497 483 goto strcat_text
498 goto strcat_text
499 484
500 option_draw_string: 485 option_draw_string:
501 movff POSTINC1,POSTINC2 486 movff POSTINC1,POSTINC2
502 decfsz opt_max 487 decfsz opt_max
503 bra option_draw_string 488 bra option_draw_string
504 return 489 return
505 490
506 END 491 END