annotate src/options.asm @ 219:4b2622e0fd50

init new 4kB Page in logbook memory when pointer is not valid.
author heinrichsweikamp
date Sun, 04 Jan 2015 21:24:01 +0100
parents f515712d8cd6
children effd7259f5a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File options.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Manage all options data.
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-07-12 : [jDG] Creation.
heinrichsweikamp
parents:
diff changeset
11 ;
heinrichsweikamp
parents:
diff changeset
12 ; RATIONALS:
heinrichsweikamp
parents:
diff changeset
13 ;
heinrichsweikamp
parents:
diff changeset
14 ; Provides a centralized file with
heinrichsweikamp
parents:
diff changeset
15
heinrichsweikamp
parents:
diff changeset
16 #include "ostc3.inc" ; Mandatory header
heinrichsweikamp
parents:
diff changeset
17 #include "strings.inc"
heinrichsweikamp
parents:
diff changeset
18 #include "convert.inc"
heinrichsweikamp
parents:
diff changeset
19 #include "ghostwriter.inc"
heinrichsweikamp
parents:
diff changeset
20 #include "eeprom_rs232.inc"
heinrichsweikamp
parents:
diff changeset
21 #include "external_flash.inc"
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
22 #include "wait.inc"
0
heinrichsweikamp
parents:
diff changeset
23
heinrichsweikamp
parents:
diff changeset
24 extern write_eeprom
heinrichsweikamp
parents:
diff changeset
25 extern read_eeprom
heinrichsweikamp
parents:
diff changeset
26 extern eeprom_serial_save,eeprom_opt_backup
143
be997abd1f73 seperate option table, place in address <0x10000
heinrichsweikamp
parents: 142
diff changeset
27 extern option_table_begin,option_table_end
0
heinrichsweikamp
parents:
diff changeset
28
heinrichsweikamp
parents:
diff changeset
29 global option_reset_all ; Reset all options to factory default.
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
30 global option_check_all ; Check all option and reset option if out of min/max boundary
0
heinrichsweikamp
parents:
diff changeset
31 global option_reset ; Reset FSR0 option to factory default.
heinrichsweikamp
parents:
diff changeset
32 global option_save_all ; Save options to EEPROM.
heinrichsweikamp
parents:
diff changeset
33 global option_restore_all ; Restore options from EEPROM.
heinrichsweikamp
parents:
diff changeset
34 global option_inc ; Increment FSR0 option.
heinrichsweikamp
parents:
diff changeset
35 global option_draw ; STRCAT FRS0 option.
heinrichsweikamp
parents:
diff changeset
36
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
37
0
heinrichsweikamp
parents:
diff changeset
38 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
39 CBLOCK tmp+0x10 ; Reserve space for wordprocessor & convert
heinrichsweikamp
parents:
diff changeset
40 opt_type
heinrichsweikamp
parents:
diff changeset
41 opt_default
heinrichsweikamp
parents:
diff changeset
42 opt_inc ; Also default+1 (string), and enum low
heinrichsweikamp
parents:
diff changeset
43 opt_min ; also enum high
heinrichsweikamp
parents:
diff changeset
44 opt_max
heinrichsweikamp
parents:
diff changeset
45 opt_unit:2 ; Multi-lingual unit text.
heinrichsweikamp
parents:
diff changeset
46 opt_eeprom
heinrichsweikamp
parents:
diff changeset
47 opt_backup_tbl:3
heinrichsweikamp
parents:
diff changeset
48 ; Reserved to tmp+0x1F...
heinrichsweikamp
parents:
diff changeset
49 ENDC
heinrichsweikamp
parents:
diff changeset
50
heinrichsweikamp
parents:
diff changeset
51 gui CODE ; Appends to other GUI segment
heinrichsweikamp
parents:
diff changeset
52 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
53 ; Reset all options to factory defauts.
heinrichsweikamp
parents:
diff changeset
54 ;
heinrichsweikamp
parents:
diff changeset
55 ; INPUT: none
heinrichsweikamp
parents:
diff changeset
56 ; OUTPUT: none
heinrichsweikamp
parents:
diff changeset
57 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
heinrichsweikamp
parents:
diff changeset
58
heinrichsweikamp
parents:
diff changeset
59 option_reset_all:
heinrichsweikamp
parents:
diff changeset
60 clrf EEADRH
heinrichsweikamp
parents:
diff changeset
61 read_int_eeprom .2
139
e0b758865e91 some cleanup
heinrichsweikamp
parents: 133
diff changeset
62 tstfsz EEDATA ; Total dives=0?
e0b758865e91 some cleanup
heinrichsweikamp
parents: 133
diff changeset
63 bra option_reset_all2 ; No, skip resetting logbook
0
heinrichsweikamp
parents:
diff changeset
64 read_int_eeprom .3
139
e0b758865e91 some cleanup
heinrichsweikamp
parents: 133
diff changeset
65 tstfsz EEDATA ; Total dives=0?
0
heinrichsweikamp
parents:
diff changeset
66 bra option_reset_all2 ; No, skip resetting logbook
heinrichsweikamp
parents:
diff changeset
67
heinrichsweikamp
parents:
diff changeset
68 clrf EEDATA
heinrichsweikamp
parents:
diff changeset
69 write_int_eeprom .4
heinrichsweikamp
parents:
diff changeset
70 write_int_eeprom .5
heinrichsweikamp
parents:
diff changeset
71 write_int_eeprom .6
heinrichsweikamp
parents:
diff changeset
72 write_int_eeprom .2 ; Also, delete total dive counter
heinrichsweikamp
parents:
diff changeset
73 write_int_eeprom .3
heinrichsweikamp
parents:
diff changeset
74 call ext_flash_erase_logbook ; And complete logbook (!)
heinrichsweikamp
parents:
diff changeset
75
heinrichsweikamp
parents:
diff changeset
76 option_reset_all2:
heinrichsweikamp
parents:
diff changeset
77 clrf lo
heinrichsweikamp
parents:
diff changeset
78 clrf hi
heinrichsweikamp
parents:
diff changeset
79 call do_logoffset_common_write ; reset Logbook offset
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
80
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
81 ; Point to option table begin
0
heinrichsweikamp
parents:
diff changeset
82 movlw LOW(option_table_begin)
heinrichsweikamp
parents:
diff changeset
83 movwf FSR0L
heinrichsweikamp
parents:
diff changeset
84 movlw HIGH(option_table_begin)
heinrichsweikamp
parents:
diff changeset
85 movwf FSR0H
heinrichsweikamp
parents:
diff changeset
86 option_reset_all_1:
heinrichsweikamp
parents:
diff changeset
87 movf FSR0L,W ; Reached end of table ?
heinrichsweikamp
parents:
diff changeset
88 xorlw LOW(option_table_end) ; (8bit test -> 10 bytes x 128 options max)
heinrichsweikamp
parents:
diff changeset
89 btfsc STATUS,Z ; YES: done.
heinrichsweikamp
parents:
diff changeset
90 return
heinrichsweikamp
parents:
diff changeset
91
heinrichsweikamp
parents:
diff changeset
92 rcall option_reset ; Reset one option.
heinrichsweikamp
parents:
diff changeset
93 bra option_reset_all_1 ; and loop.
heinrichsweikamp
parents:
diff changeset
94
heinrichsweikamp
parents:
diff changeset
95 ;=============================================================================
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
96 ; Check all option and reset option if out of min/max boundary
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
97 ;
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
98 ; INPUT: none
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
99 ; OUTPUT: none
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
100 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1, FSR2
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
101 option_check_all:
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
102 ; Point to option table begin
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
103 movlw LOW(option_table_begin)
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
104 movwf FSR0L
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
105 movlw HIGH(option_table_begin)
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
106 movwf FSR0H
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
107
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
108 option_check_all_1:
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
109 movf FSR0L,W ; Reached end of table ?
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
110 xorlw LOW(option_table_end) ; (8bit test -> 10 bytes x 128 options max)
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
111 btfsc STATUS,Z ; YES: done.
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
112 return
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
113
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
114 rcall option_check ; check one option.
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
115 bra option_check_all_1 ; and loop
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
116
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
117 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
118 ; Read option handle
heinrichsweikamp
parents:
diff changeset
119 ; INPUT: FSR0 = option handle
heinrichsweikamp
parents:
diff changeset
120 ; OUTPUT: FSR1 = address of variable.
heinrichsweikamp
parents:
diff changeset
121 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
heinrichsweikamp
parents:
diff changeset
122 option_read:
heinrichsweikamp
parents:
diff changeset
123 movff FSR0L,TBLPTRL
heinrichsweikamp
parents:
diff changeset
124 movlw HIGH(option_table_begin); Get 8 high bits.
heinrichsweikamp
parents:
diff changeset
125 andlw 0xF0 ; Keep only the 4 highest ones.
heinrichsweikamp
parents:
diff changeset
126 iorwf FSR0H,W ; Cat with the known 4 lower ones.
heinrichsweikamp
parents:
diff changeset
127 movwf TBLPTRH ; And we have the high byte.
heinrichsweikamp
parents:
diff changeset
128 movlw UPPER(option_table_begin)
heinrichsweikamp
parents:
diff changeset
129 movwf TBLPTRU
heinrichsweikamp
parents:
diff changeset
130
heinrichsweikamp
parents:
diff changeset
131 ; Read type, default and register from table
heinrichsweikamp
parents:
diff changeset
132 tblrd*+
heinrichsweikamp
parents:
diff changeset
133 movff TABLAT,opt_type
heinrichsweikamp
parents:
diff changeset
134 tblrd*+
heinrichsweikamp
parents:
diff changeset
135 movff TABLAT,opt_default
heinrichsweikamp
parents:
diff changeset
136 tblrd*+
heinrichsweikamp
parents:
diff changeset
137 movff TABLAT,opt_inc
heinrichsweikamp
parents:
diff changeset
138 tblrd*+
heinrichsweikamp
parents:
diff changeset
139 movff TABLAT,opt_min
heinrichsweikamp
parents:
diff changeset
140 tblrd*+
heinrichsweikamp
parents:
diff changeset
141 movff TABLAT,opt_max
heinrichsweikamp
parents:
diff changeset
142 tblrd*+
heinrichsweikamp
parents:
diff changeset
143 movff TABLAT,opt_eeprom
heinrichsweikamp
parents:
diff changeset
144 tblrd*+
heinrichsweikamp
parents:
diff changeset
145 movff TABLAT,opt_unit+0
heinrichsweikamp
parents:
diff changeset
146 tblrd*+
heinrichsweikamp
parents:
diff changeset
147 movff TABLAT,opt_unit+1
heinrichsweikamp
parents:
diff changeset
148 tblrd*+
heinrichsweikamp
parents:
diff changeset
149 movff TABLAT,FSR1L
heinrichsweikamp
parents:
diff changeset
150 tblrd*+
heinrichsweikamp
parents:
diff changeset
151 movff TABLAT,FSR1H
heinrichsweikamp
parents:
diff changeset
152 movff TBLPTRL,FSR0L ; Advance handle too, for reset_all
heinrichsweikamp
parents:
diff changeset
153 movff TBLPTRH,FSR0H
heinrichsweikamp
parents:
diff changeset
154 return
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
155
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
156 ;=============================================================================
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
157 ; Check one option and reset if it's out of it's min/max boundaries
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
158 ; INPUT: FSR0 = option handle
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
159 ; OUTPUT: none
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
160 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2, lo
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
161 ;
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
162 option_check:
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
163 ; Read type, default and register from table
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
164 rcall option_read
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
165
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
166 ; Switch on type
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
167 movf opt_type,W ; Type == STRING ?
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
168 xorlw 2
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
169 bz option_check_string ; String: Do not reset strings
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
170
110
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
171 movf opt_type,W ; Type == ENUM8 ?
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
172 xorlw 1
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
173 bz option_check_enum8 ; ENUM8: Check if lower then max. value only
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
174
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
175 movf opt_min,W
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
176 cpfsgt INDF1 ; bigger then opt_min?
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
177 bra option_check_reset ; No, reset option
185
f515712d8cd6 BUGFIX: Check min and max values after PC configuration properly
heinrichsweikamp
parents: 143
diff changeset
178 option_check_enum8: ; ENUM8: Check max only
f515712d8cd6 BUGFIX: Check min and max values after PC configuration properly
heinrichsweikamp
parents: 143
diff changeset
179 incf opt_max,W
f515712d8cd6 BUGFIX: Check min and max values after PC configuration properly
heinrichsweikamp
parents: 143
diff changeset
180 cpfslt INDF1 ; smaller then opt_max+1?
21
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
181 bra option_check_reset ; No, reset option
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
182 return ; in range, return
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
183
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
184 option_check_reset:
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
185 movff opt_default,INDF1 ; reset option to default
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
186 return ; Done.
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
187
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
188 option_check_string:
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
189 return
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
190
0
heinrichsweikamp
parents:
diff changeset
191 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
192 ; Reset an option to its default value.
heinrichsweikamp
parents:
diff changeset
193 ; INPUT: FSR0 = option handle
heinrichsweikamp
parents:
diff changeset
194 ; OUTPUT: none
heinrichsweikamp
parents:
diff changeset
195 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2
heinrichsweikamp
parents:
diff changeset
196 ;
heinrichsweikamp
parents:
diff changeset
197 option_reset:
heinrichsweikamp
parents:
diff changeset
198 ; Read type, default and register from table
heinrichsweikamp
parents:
diff changeset
199 rcall option_read
heinrichsweikamp
parents:
diff changeset
200
heinrichsweikamp
parents:
diff changeset
201 ; Switch on type
heinrichsweikamp
parents:
diff changeset
202 movf opt_type,W ; Type == STRING ?
heinrichsweikamp
parents:
diff changeset
203 xorlw 2
heinrichsweikamp
parents:
diff changeset
204 bz opt_reset_string ; YES: special copy
heinrichsweikamp
parents:
diff changeset
205
heinrichsweikamp
parents:
diff changeset
206 movff opt_default,INDF1 ; NO: just a 8bit indirect copy
heinrichsweikamp
parents:
diff changeset
207 return
heinrichsweikamp
parents:
diff changeset
208
heinrichsweikamp
parents:
diff changeset
209 opt_reset_string:
heinrichsweikamp
parents:
diff changeset
210 movff FSR1L,FSR2L ; set string destination address.
heinrichsweikamp
parents:
diff changeset
211 movff FSR1H,FSR2H
heinrichsweikamp
parents:
diff changeset
212
heinrichsweikamp
parents:
diff changeset
213 movff opt_default+0,FSR1L ; Get handle to multi-lingual text in FSR1
heinrichsweikamp
parents:
diff changeset
214 movff opt_default+1,FSR1H
heinrichsweikamp
parents:
diff changeset
215
heinrichsweikamp
parents:
diff changeset
216 movff TBLPTRL,opt_backup_tbl+0; TBLPTR trashed by text routine...
heinrichsweikamp
parents:
diff changeset
217 movff TBLPTRH,opt_backup_tbl+1
heinrichsweikamp
parents:
diff changeset
218 movff TBLPTRU,opt_backup_tbl+2
heinrichsweikamp
parents:
diff changeset
219
heinrichsweikamp
parents:
diff changeset
220 call strcat_text ; Copy translated text to FSR2
heinrichsweikamp
parents:
diff changeset
221
heinrichsweikamp
parents:
diff changeset
222 movff opt_backup_tbl+0,TBLPTRL
heinrichsweikamp
parents:
diff changeset
223 movff opt_backup_tbl+1,TBLPTRH
heinrichsweikamp
parents:
diff changeset
224 movff opt_backup_tbl+2,TBLPTRU
heinrichsweikamp
parents:
diff changeset
225
heinrichsweikamp
parents:
diff changeset
226 return
heinrichsweikamp
parents:
diff changeset
227
heinrichsweikamp
parents:
diff changeset
228 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
229 ; Save all options to EEPROM
heinrichsweikamp
parents:
diff changeset
230 option_save_all:
heinrichsweikamp
parents:
diff changeset
231 ;---- Save option serial into EEPROM to detect reset and new version
heinrichsweikamp
parents:
diff changeset
232 movlw LOW(eeprom_serial_save)
heinrichsweikamp
parents:
diff changeset
233 movwf EEADR
heinrichsweikamp
parents:
diff changeset
234 movlw HIGH(eeprom_serial_save)
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
235 movwf EEADRH
0
heinrichsweikamp
parents:
diff changeset
236 movlw LOW(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
237 movwf EEDATA
heinrichsweikamp
parents:
diff changeset
238 call write_eeprom
heinrichsweikamp
parents:
diff changeset
239 incf EEADR,F
heinrichsweikamp
parents:
diff changeset
240 movlw HIGH(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
241 movwf EEDATA
heinrichsweikamp
parents:
diff changeset
242 call write_eeprom
heinrichsweikamp
parents:
diff changeset
243
heinrichsweikamp
parents:
diff changeset
244 ;---- Save all options
heinrichsweikamp
parents:
diff changeset
245 movlw LOW(option_table_begin)
heinrichsweikamp
parents:
diff changeset
246 movwf FSR0L
heinrichsweikamp
parents:
diff changeset
247 movlw HIGH(option_table_begin)
heinrichsweikamp
parents:
diff changeset
248 movwf FSR0H
heinrichsweikamp
parents:
diff changeset
249
heinrichsweikamp
parents:
diff changeset
250 option_save_all_1:
heinrichsweikamp
parents:
diff changeset
251 movf FSR0L,W ; Reached end of table ?
heinrichsweikamp
parents:
diff changeset
252 xorlw LOW(option_table_end) ; (8bit test -> 10 bytes x 128 options max)
heinrichsweikamp
parents:
diff changeset
253 btfsc STATUS,Z ; YES: done.
heinrichsweikamp
parents:
diff changeset
254 return
heinrichsweikamp
parents:
diff changeset
255
heinrichsweikamp
parents:
diff changeset
256 rcall option_save ; Save one option.
heinrichsweikamp
parents:
diff changeset
257 bra option_save_all_1 ; and loop.
heinrichsweikamp
parents:
diff changeset
258
93
5e1ef9bf32ec clear pressure sensor compensation upon update
heinrichsweikamp
parents: 92
diff changeset
259 global option_save
0
heinrichsweikamp
parents:
diff changeset
260 option_save:
heinrichsweikamp
parents:
diff changeset
261 rcall option_read
heinrichsweikamp
parents:
diff changeset
262 incf opt_eeprom,W ; Should we save it ?
heinrichsweikamp
parents:
diff changeset
263 btfsc STATUS,Z ; eeprom address is FFh ?
heinrichsweikamp
parents:
diff changeset
264 return ; YES: nothing to do.
heinrichsweikamp
parents:
diff changeset
265
heinrichsweikamp
parents:
diff changeset
266 movf opt_eeprom,W ; Compute backup address in EEPROM
heinrichsweikamp
parents:
diff changeset
267 addlw LOW(eeprom_opt_backup) ; Add offset
heinrichsweikamp
parents:
diff changeset
268 movwf EEADR
heinrichsweikamp
parents:
diff changeset
269 movlw HIGH(eeprom_opt_backup)
142
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
270 btfsc STATUS,C ; >256
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
271 addlw .1 ; Yes: +1
0
heinrichsweikamp
parents:
diff changeset
272 movwf EEADRH
heinrichsweikamp
parents:
diff changeset
273
heinrichsweikamp
parents:
diff changeset
274 movf opt_type,W ; Option type is string ?
heinrichsweikamp
parents:
diff changeset
275 xorlw 2
heinrichsweikamp
parents:
diff changeset
276 bz option_save_string
heinrichsweikamp
parents:
diff changeset
277
heinrichsweikamp
parents:
diff changeset
278 ; One byte to save to eeprom
heinrichsweikamp
parents:
diff changeset
279 movff INDF1,EEDATA
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
280 btfss EEADRH,1 ; EEADR:EEADRH < 512?
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
281 call write_eeprom ; Yes, write
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
282 return
0
heinrichsweikamp
parents:
diff changeset
283
heinrichsweikamp
parents:
diff changeset
284 option_save_string:
heinrichsweikamp
parents:
diff changeset
285 movff POSTINC1,EEDATA ; Write one byte
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
286 btfss EEADRH,1 ; EEADR:EEADRH < 512?
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
287 call write_eeprom ; Yes, write
0
heinrichsweikamp
parents:
diff changeset
288 infsnz EEADR,F
heinrichsweikamp
parents:
diff changeset
289 incf EEADRH,F
heinrichsweikamp
parents:
diff changeset
290
heinrichsweikamp
parents:
diff changeset
291 decfsz opt_max ; Decrement string length
heinrichsweikamp
parents:
diff changeset
292 bra option_save_string ; And loop while not finished
heinrichsweikamp
parents:
diff changeset
293
heinrichsweikamp
parents:
diff changeset
294 return
heinrichsweikamp
parents:
diff changeset
295 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
296
heinrichsweikamp
parents:
diff changeset
297 option_restore_all:
heinrichsweikamp
parents:
diff changeset
298 ;---- Read option serial from EEPROM
heinrichsweikamp
parents:
diff changeset
299 movlw LOW(eeprom_serial_save)
heinrichsweikamp
parents:
diff changeset
300 movwf EEADR
heinrichsweikamp
parents:
diff changeset
301 movlw HIGH(eeprom_serial_save)
heinrichsweikamp
parents:
diff changeset
302 movf EEADRH
heinrichsweikamp
parents:
diff changeset
303 call read_eeprom
heinrichsweikamp
parents:
diff changeset
304 movlw LOW(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
305 xorwf EEDATA,W
heinrichsweikamp
parents:
diff changeset
306 bnz option_restore_bad ; Auto reset if changed.
heinrichsweikamp
parents:
diff changeset
307 incf EEADR,F
heinrichsweikamp
parents:
diff changeset
308 call read_eeprom
heinrichsweikamp
parents:
diff changeset
309 movlw HIGH(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
310 xorwf EEDATA,W
heinrichsweikamp
parents:
diff changeset
311 bz option_restore_ok ; Auto reset if changed.
heinrichsweikamp
parents:
diff changeset
312
heinrichsweikamp
parents:
diff changeset
313 option_restore_bad:
heinrichsweikamp
parents:
diff changeset
314 call option_reset_all ; Reset RAM contains
heinrichsweikamp
parents:
diff changeset
315 goto option_save_all ; Then save to EEPROM
heinrichsweikamp
parents:
diff changeset
316
heinrichsweikamp
parents:
diff changeset
317 ;---- Proper restore
heinrichsweikamp
parents:
diff changeset
318 option_restore_ok:
heinrichsweikamp
parents:
diff changeset
319 movlw LOW(option_table_begin)
heinrichsweikamp
parents:
diff changeset
320 movwf FSR0L
heinrichsweikamp
parents:
diff changeset
321 movlw HIGH(option_table_begin)
heinrichsweikamp
parents:
diff changeset
322 movwf FSR0H
heinrichsweikamp
parents:
diff changeset
323
heinrichsweikamp
parents:
diff changeset
324 option_restore_all_1:
heinrichsweikamp
parents:
diff changeset
325 movf FSR0L,W ; Reached end of table ?
heinrichsweikamp
parents:
diff changeset
326 xorlw LOW(option_table_end) ; (8bit test -> 10 bytes x 128 options max)
heinrichsweikamp
parents:
diff changeset
327 btfsc STATUS,Z ; YES: done.
heinrichsweikamp
parents:
diff changeset
328 return
heinrichsweikamp
parents:
diff changeset
329
heinrichsweikamp
parents:
diff changeset
330 rcall option_restore ; Restore one option.
heinrichsweikamp
parents:
diff changeset
331 bra option_restore_all_1 ; and loop.
heinrichsweikamp
parents:
diff changeset
332 return
heinrichsweikamp
parents:
diff changeset
333
heinrichsweikamp
parents:
diff changeset
334 option_restore:
heinrichsweikamp
parents:
diff changeset
335 rcall option_read
heinrichsweikamp
parents:
diff changeset
336 incf opt_eeprom,W ; Should we save it ?
heinrichsweikamp
parents:
diff changeset
337 btfsc STATUS,Z ; eeprom address is FFh ?
heinrichsweikamp
parents:
diff changeset
338 return ; YES: nothing to do.
heinrichsweikamp
parents:
diff changeset
339
heinrichsweikamp
parents:
diff changeset
340 movf opt_eeprom,W ; Compute backup address in EEPROM
heinrichsweikamp
parents:
diff changeset
341 addlw LOW(eeprom_opt_backup) ; Add offset
heinrichsweikamp
parents:
diff changeset
342 movwf EEADR
heinrichsweikamp
parents:
diff changeset
343 movlw HIGH(eeprom_opt_backup)
142
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
344 btfsc STATUS,C ; >256
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
345 addlw .1 ; Yes: +1
0
heinrichsweikamp
parents:
diff changeset
346 movwf EEADRH
heinrichsweikamp
parents:
diff changeset
347
heinrichsweikamp
parents:
diff changeset
348 movf opt_type,W ; Option type is string ?
heinrichsweikamp
parents:
diff changeset
349 xorlw 2
heinrichsweikamp
parents:
diff changeset
350 bz option_restore_string
heinrichsweikamp
parents:
diff changeset
351
heinrichsweikamp
parents:
diff changeset
352 ; Read one byte from eeprom
heinrichsweikamp
parents:
diff changeset
353 call read_eeprom
heinrichsweikamp
parents:
diff changeset
354 movff EEDATA, INDF1 ; And restore option register.
heinrichsweikamp
parents:
diff changeset
355 return
heinrichsweikamp
parents:
diff changeset
356
heinrichsweikamp
parents:
diff changeset
357 option_restore_string:
heinrichsweikamp
parents:
diff changeset
358 call read_eeprom ; Read one byte, and
heinrichsweikamp
parents:
diff changeset
359 movff EEDATA,POSTINC1 ; restore it
heinrichsweikamp
parents:
diff changeset
360 infsnz EEADR,F
heinrichsweikamp
parents:
diff changeset
361 incf EEADRH,F
heinrichsweikamp
parents:
diff changeset
362
heinrichsweikamp
parents:
diff changeset
363 decfsz opt_max ; Decrement string length
heinrichsweikamp
parents:
diff changeset
364 bra option_restore_string ; And loop while not finished
heinrichsweikamp
parents:
diff changeset
365 return
heinrichsweikamp
parents:
diff changeset
366
heinrichsweikamp
parents:
diff changeset
367 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
368 ; Increment an option, based on type, and boundary.
heinrichsweikamp
parents:
diff changeset
369 ; INPUT: FSR0 = option handle
heinrichsweikamp
parents:
diff changeset
370 ; OUTPUT: none
heinrichsweikamp
parents:
diff changeset
371 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
heinrichsweikamp
parents:
diff changeset
372 option_inc:
heinrichsweikamp
parents:
diff changeset
373 ; Read type, default and register from table
heinrichsweikamp
parents:
diff changeset
374 rcall option_read
heinrichsweikamp
parents:
diff changeset
375
heinrichsweikamp
parents:
diff changeset
376 ; Switch on type
heinrichsweikamp
parents:
diff changeset
377 movf opt_type,W
heinrichsweikamp
parents:
diff changeset
378 bz option_inc_uint8
heinrichsweikamp
parents:
diff changeset
379 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
380 bra option_inc_enum8
heinrichsweikamp
parents:
diff changeset
381 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
382 bra option_inc_string
heinrichsweikamp
parents:
diff changeset
383
heinrichsweikamp
parents:
diff changeset
384 option_inc_uint8: ; Defaults type too...
heinrichsweikamp
parents:
diff changeset
385 movf INDF1,W
heinrichsweikamp
parents:
diff changeset
386 addwf opt_inc,W
heinrichsweikamp
parents:
diff changeset
387 cpfslt opt_max
heinrichsweikamp
parents:
diff changeset
388 bra option_inc_1
heinrichsweikamp
parents:
diff changeset
389 movf opt_min,W
heinrichsweikamp
parents:
diff changeset
390 option_inc_1:
heinrichsweikamp
parents:
diff changeset
391 movwf INDF1
heinrichsweikamp
parents:
diff changeset
392 return
heinrichsweikamp
parents:
diff changeset
393
heinrichsweikamp
parents:
diff changeset
394 option_inc_enum8: ; Always +1
heinrichsweikamp
parents:
diff changeset
395 incf INDF1,W
heinrichsweikamp
parents:
diff changeset
396 cpfsgt opt_max
heinrichsweikamp
parents:
diff changeset
397 clrf WREG
heinrichsweikamp
parents:
diff changeset
398 movwf INDF1
heinrichsweikamp
parents:
diff changeset
399 return
heinrichsweikamp
parents:
diff changeset
400
heinrichsweikamp
parents:
diff changeset
401 option_inc_string: ; No edition yet...
heinrichsweikamp
parents:
diff changeset
402 return
heinrichsweikamp
parents:
diff changeset
403
heinrichsweikamp
parents:
diff changeset
404 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
405 ; Strcat option into FSR2 buffer.
heinrichsweikamp
parents:
diff changeset
406 option_draw:
heinrichsweikamp
parents:
diff changeset
407 ; Read type, default and register from table
heinrichsweikamp
parents:
diff changeset
408 rcall option_read
heinrichsweikamp
parents:
diff changeset
409
heinrichsweikamp
parents:
diff changeset
410 ; Switch on type
heinrichsweikamp
parents:
diff changeset
411 movf opt_type,W
heinrichsweikamp
parents:
diff changeset
412 bz option_draw_uint8
heinrichsweikamp
parents:
diff changeset
413 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
414 bra option_draw_enum8
heinrichsweikamp
parents:
diff changeset
415 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
416 bra option_draw_string
heinrichsweikamp
parents:
diff changeset
417 return ; Unknown: return...
heinrichsweikamp
parents:
diff changeset
418
heinrichsweikamp
parents:
diff changeset
419 option_draw_uint8:
heinrichsweikamp
parents:
diff changeset
420 movff INDF1,lo ; Draw value.
heinrichsweikamp
parents:
diff changeset
421 output_8
heinrichsweikamp
parents:
diff changeset
422 clrf INDF2 ; Make sure to close string...
heinrichsweikamp
parents:
diff changeset
423
heinrichsweikamp
parents:
diff changeset
424 movf opt_unit+0,W ; Is there a unit to append ?
heinrichsweikamp
parents:
diff changeset
425 iorwf opt_unit+1,W
heinrichsweikamp
parents:
diff changeset
426 rcall option_draw_unit
heinrichsweikamp
parents:
diff changeset
427
heinrichsweikamp
parents:
diff changeset
428 movf opt_default,W ; Default value
heinrichsweikamp
parents:
diff changeset
429 cpfseq lo ; Current value
heinrichsweikamp
parents:
diff changeset
430 bra option_draw_uint8_2 ; Not default, add *
heinrichsweikamp
parents:
diff changeset
431 return ; Default, Done.
heinrichsweikamp
parents:
diff changeset
432 option_draw_uint8_2:
heinrichsweikamp
parents:
diff changeset
433 PUTC "*"
heinrichsweikamp
parents:
diff changeset
434 return ; Done.
heinrichsweikamp
parents:
diff changeset
435
heinrichsweikamp
parents:
diff changeset
436 option_draw_unit:
heinrichsweikamp
parents:
diff changeset
437 movff opt_unit+0,FSR1L
heinrichsweikamp
parents:
diff changeset
438 movff opt_unit+1,FSR1H
heinrichsweikamp
parents:
diff changeset
439 goto strcat_text
heinrichsweikamp
parents:
diff changeset
440
heinrichsweikamp
parents:
diff changeset
441
heinrichsweikamp
parents:
diff changeset
442
heinrichsweikamp
parents:
diff changeset
443 ;---- Draw an enumerated value (set of translated strings)
heinrichsweikamp
parents:
diff changeset
444 option_draw_enum8:
heinrichsweikamp
parents:
diff changeset
445 movf INDF1,W ; Get current value.
heinrichsweikamp
parents:
diff changeset
446 cpfsgt opt_max ; Bound value
heinrichsweikamp
parents:
diff changeset
447 clrf WREG
heinrichsweikamp
parents:
diff changeset
448 addwf WREG ; *= 2
heinrichsweikamp
parents:
diff changeset
449 addwf opt_inc,W ; Base text + 2 * value
heinrichsweikamp
parents:
diff changeset
450 movwf FSR1L
heinrichsweikamp
parents:
diff changeset
451 movlw 0
heinrichsweikamp
parents:
diff changeset
452 addwfc opt_min,W ; Propagate carry
heinrichsweikamp
parents:
diff changeset
453 movwf FSR1H ; Into FSR1
heinrichsweikamp
parents:
diff changeset
454
heinrichsweikamp
parents:
diff changeset
455 goto strcat_text
heinrichsweikamp
parents:
diff changeset
456
heinrichsweikamp
parents:
diff changeset
457 option_draw_string:
heinrichsweikamp
parents:
diff changeset
458 movff POSTINC1,POSTINC2
heinrichsweikamp
parents:
diff changeset
459 decfsz opt_max
heinrichsweikamp
parents:
diff changeset
460 bra option_draw_string
heinrichsweikamp
parents:
diff changeset
461 return
heinrichsweikamp
parents:
diff changeset
462
heinrichsweikamp
parents:
diff changeset
463 END