annotate src/options.asm @ 155:5f71e31bd5b3

CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
author heinrichsweikamp
date Thu, 28 Aug 2014 12:13:52 +0200
parents be997abd1f73
children f515712d8cd6
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
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
178 movf INDF1,W
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
179 cpfsgt opt_max ; bigger then INDF1?
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
180 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
181 return ; in range, return
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
182
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
183 option_check_reset:
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
184 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
185 return ; Done.
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
186
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
187 option_check_string:
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
188 return
79b2084fd75a Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents: 18
diff changeset
189
110
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
190 option_check_enum8:
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
191 movf INDF1,W
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
192 cpfsgt opt_max ; bigger then INDF1?
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
193 bra option_check_reset ; No, reset option
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
194 return ; in range, return
d39493c786a2 BUGFIX: OSTC settings via USB issues
heinrichsweikamp
parents: 104
diff changeset
195
0
heinrichsweikamp
parents:
diff changeset
196 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
197 ; Reset an option to its default value.
heinrichsweikamp
parents:
diff changeset
198 ; INPUT: FSR0 = option handle
heinrichsweikamp
parents:
diff changeset
199 ; OUTPUT: none
heinrichsweikamp
parents:
diff changeset
200 ; TRASH: TBLPTR, TABLAT, WREG, FSR1, FSR2
heinrichsweikamp
parents:
diff changeset
201 ;
heinrichsweikamp
parents:
diff changeset
202 option_reset:
heinrichsweikamp
parents:
diff changeset
203 ; Read type, default and register from table
heinrichsweikamp
parents:
diff changeset
204 rcall option_read
heinrichsweikamp
parents:
diff changeset
205
heinrichsweikamp
parents:
diff changeset
206 ; Switch on type
heinrichsweikamp
parents:
diff changeset
207 movf opt_type,W ; Type == STRING ?
heinrichsweikamp
parents:
diff changeset
208 xorlw 2
heinrichsweikamp
parents:
diff changeset
209 bz opt_reset_string ; YES: special copy
heinrichsweikamp
parents:
diff changeset
210
heinrichsweikamp
parents:
diff changeset
211 movff opt_default,INDF1 ; NO: just a 8bit indirect copy
heinrichsweikamp
parents:
diff changeset
212 return
heinrichsweikamp
parents:
diff changeset
213
heinrichsweikamp
parents:
diff changeset
214 opt_reset_string:
heinrichsweikamp
parents:
diff changeset
215 movff FSR1L,FSR2L ; set string destination address.
heinrichsweikamp
parents:
diff changeset
216 movff FSR1H,FSR2H
heinrichsweikamp
parents:
diff changeset
217
heinrichsweikamp
parents:
diff changeset
218 movff opt_default+0,FSR1L ; Get handle to multi-lingual text in FSR1
heinrichsweikamp
parents:
diff changeset
219 movff opt_default+1,FSR1H
heinrichsweikamp
parents:
diff changeset
220
heinrichsweikamp
parents:
diff changeset
221 movff TBLPTRL,opt_backup_tbl+0; TBLPTR trashed by text routine...
heinrichsweikamp
parents:
diff changeset
222 movff TBLPTRH,opt_backup_tbl+1
heinrichsweikamp
parents:
diff changeset
223 movff TBLPTRU,opt_backup_tbl+2
heinrichsweikamp
parents:
diff changeset
224
heinrichsweikamp
parents:
diff changeset
225 call strcat_text ; Copy translated text to FSR2
heinrichsweikamp
parents:
diff changeset
226
heinrichsweikamp
parents:
diff changeset
227 movff opt_backup_tbl+0,TBLPTRL
heinrichsweikamp
parents:
diff changeset
228 movff opt_backup_tbl+1,TBLPTRH
heinrichsweikamp
parents:
diff changeset
229 movff opt_backup_tbl+2,TBLPTRU
heinrichsweikamp
parents:
diff changeset
230
heinrichsweikamp
parents:
diff changeset
231 return
heinrichsweikamp
parents:
diff changeset
232
heinrichsweikamp
parents:
diff changeset
233 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
234 ; Save all options to EEPROM
heinrichsweikamp
parents:
diff changeset
235 option_save_all:
heinrichsweikamp
parents:
diff changeset
236 ;---- Save option serial into EEPROM to detect reset and new version
heinrichsweikamp
parents:
diff changeset
237 movlw LOW(eeprom_serial_save)
heinrichsweikamp
parents:
diff changeset
238 movwf EEADR
heinrichsweikamp
parents:
diff changeset
239 movlw HIGH(eeprom_serial_save)
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
240 movwf EEADRH
0
heinrichsweikamp
parents:
diff changeset
241 movlw LOW(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
242 movwf EEDATA
heinrichsweikamp
parents:
diff changeset
243 call write_eeprom
heinrichsweikamp
parents:
diff changeset
244 incf EEADR,F
heinrichsweikamp
parents:
diff changeset
245 movlw HIGH(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
246 movwf EEDATA
heinrichsweikamp
parents:
diff changeset
247 call write_eeprom
heinrichsweikamp
parents:
diff changeset
248
heinrichsweikamp
parents:
diff changeset
249 ;---- Save all options
heinrichsweikamp
parents:
diff changeset
250 movlw LOW(option_table_begin)
heinrichsweikamp
parents:
diff changeset
251 movwf FSR0L
heinrichsweikamp
parents:
diff changeset
252 movlw HIGH(option_table_begin)
heinrichsweikamp
parents:
diff changeset
253 movwf FSR0H
heinrichsweikamp
parents:
diff changeset
254
heinrichsweikamp
parents:
diff changeset
255 option_save_all_1:
heinrichsweikamp
parents:
diff changeset
256 movf FSR0L,W ; Reached end of table ?
heinrichsweikamp
parents:
diff changeset
257 xorlw LOW(option_table_end) ; (8bit test -> 10 bytes x 128 options max)
heinrichsweikamp
parents:
diff changeset
258 btfsc STATUS,Z ; YES: done.
heinrichsweikamp
parents:
diff changeset
259 return
heinrichsweikamp
parents:
diff changeset
260
heinrichsweikamp
parents:
diff changeset
261 rcall option_save ; Save one option.
heinrichsweikamp
parents:
diff changeset
262 bra option_save_all_1 ; and loop.
heinrichsweikamp
parents:
diff changeset
263
93
5e1ef9bf32ec clear pressure sensor compensation upon update
heinrichsweikamp
parents: 92
diff changeset
264 global option_save
0
heinrichsweikamp
parents:
diff changeset
265 option_save:
heinrichsweikamp
parents:
diff changeset
266 rcall option_read
heinrichsweikamp
parents:
diff changeset
267 incf opt_eeprom,W ; Should we save it ?
heinrichsweikamp
parents:
diff changeset
268 btfsc STATUS,Z ; eeprom address is FFh ?
heinrichsweikamp
parents:
diff changeset
269 return ; YES: nothing to do.
heinrichsweikamp
parents:
diff changeset
270
heinrichsweikamp
parents:
diff changeset
271 movf opt_eeprom,W ; Compute backup address in EEPROM
heinrichsweikamp
parents:
diff changeset
272 addlw LOW(eeprom_opt_backup) ; Add offset
heinrichsweikamp
parents:
diff changeset
273 movwf EEADR
heinrichsweikamp
parents:
diff changeset
274 movlw HIGH(eeprom_opt_backup)
142
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
275 btfsc STATUS,C ; >256
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
276 addlw .1 ; Yes: +1
0
heinrichsweikamp
parents:
diff changeset
277 movwf EEADRH
heinrichsweikamp
parents:
diff changeset
278
heinrichsweikamp
parents:
diff changeset
279 movf opt_type,W ; Option type is string ?
heinrichsweikamp
parents:
diff changeset
280 xorlw 2
heinrichsweikamp
parents:
diff changeset
281 bz option_save_string
heinrichsweikamp
parents:
diff changeset
282
heinrichsweikamp
parents:
diff changeset
283 ; One byte to save to eeprom
heinrichsweikamp
parents:
diff changeset
284 movff INDF1,EEDATA
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
285 btfss EEADRH,1 ; EEADR:EEADRH < 512?
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
286 call write_eeprom ; Yes, write
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
287 return
0
heinrichsweikamp
parents:
diff changeset
288
heinrichsweikamp
parents:
diff changeset
289 option_save_string:
heinrichsweikamp
parents:
diff changeset
290 movff POSTINC1,EEDATA ; Write one byte
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
291 btfss EEADRH,1 ; EEADR:EEADRH < 512?
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
292 call write_eeprom ; Yes, write
0
heinrichsweikamp
parents:
diff changeset
293 infsnz EEADR,F
heinrichsweikamp
parents:
diff changeset
294 incf EEADRH,F
heinrichsweikamp
parents:
diff changeset
295
heinrichsweikamp
parents:
diff changeset
296 decfsz opt_max ; Decrement string length
heinrichsweikamp
parents:
diff changeset
297 bra option_save_string ; And loop while not finished
heinrichsweikamp
parents:
diff changeset
298
heinrichsweikamp
parents:
diff changeset
299 return
heinrichsweikamp
parents:
diff changeset
300 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
301
heinrichsweikamp
parents:
diff changeset
302 option_restore_all:
heinrichsweikamp
parents:
diff changeset
303 ;---- Read option serial from EEPROM
heinrichsweikamp
parents:
diff changeset
304 movlw LOW(eeprom_serial_save)
heinrichsweikamp
parents:
diff changeset
305 movwf EEADR
heinrichsweikamp
parents:
diff changeset
306 movlw HIGH(eeprom_serial_save)
heinrichsweikamp
parents:
diff changeset
307 movf EEADRH
heinrichsweikamp
parents:
diff changeset
308 call read_eeprom
heinrichsweikamp
parents:
diff changeset
309 movlw LOW(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
310 xorwf EEDATA,W
heinrichsweikamp
parents:
diff changeset
311 bnz option_restore_bad ; Auto reset if changed.
heinrichsweikamp
parents:
diff changeset
312 incf EEADR,F
heinrichsweikamp
parents:
diff changeset
313 call read_eeprom
heinrichsweikamp
parents:
diff changeset
314 movlw HIGH(eeprom_opt_serial)
heinrichsweikamp
parents:
diff changeset
315 xorwf EEDATA,W
heinrichsweikamp
parents:
diff changeset
316 bz option_restore_ok ; Auto reset if changed.
heinrichsweikamp
parents:
diff changeset
317
heinrichsweikamp
parents:
diff changeset
318 option_restore_bad:
heinrichsweikamp
parents:
diff changeset
319 call option_reset_all ; Reset RAM contains
heinrichsweikamp
parents:
diff changeset
320 goto option_save_all ; Then save to EEPROM
heinrichsweikamp
parents:
diff changeset
321
heinrichsweikamp
parents:
diff changeset
322 ;---- Proper restore
heinrichsweikamp
parents:
diff changeset
323 option_restore_ok:
heinrichsweikamp
parents:
diff changeset
324 movlw LOW(option_table_begin)
heinrichsweikamp
parents:
diff changeset
325 movwf FSR0L
heinrichsweikamp
parents:
diff changeset
326 movlw HIGH(option_table_begin)
heinrichsweikamp
parents:
diff changeset
327 movwf FSR0H
heinrichsweikamp
parents:
diff changeset
328
heinrichsweikamp
parents:
diff changeset
329 option_restore_all_1:
heinrichsweikamp
parents:
diff changeset
330 movf FSR0L,W ; Reached end of table ?
heinrichsweikamp
parents:
diff changeset
331 xorlw LOW(option_table_end) ; (8bit test -> 10 bytes x 128 options max)
heinrichsweikamp
parents:
diff changeset
332 btfsc STATUS,Z ; YES: done.
heinrichsweikamp
parents:
diff changeset
333 return
heinrichsweikamp
parents:
diff changeset
334
heinrichsweikamp
parents:
diff changeset
335 rcall option_restore ; Restore one option.
heinrichsweikamp
parents:
diff changeset
336 bra option_restore_all_1 ; and loop.
heinrichsweikamp
parents:
diff changeset
337 return
heinrichsweikamp
parents:
diff changeset
338
heinrichsweikamp
parents:
diff changeset
339 option_restore:
heinrichsweikamp
parents:
diff changeset
340 rcall option_read
heinrichsweikamp
parents:
diff changeset
341 incf opt_eeprom,W ; Should we save it ?
heinrichsweikamp
parents:
diff changeset
342 btfsc STATUS,Z ; eeprom address is FFh ?
heinrichsweikamp
parents:
diff changeset
343 return ; YES: nothing to do.
heinrichsweikamp
parents:
diff changeset
344
heinrichsweikamp
parents:
diff changeset
345 movf opt_eeprom,W ; Compute backup address in EEPROM
heinrichsweikamp
parents:
diff changeset
346 addlw LOW(eeprom_opt_backup) ; Add offset
heinrichsweikamp
parents:
diff changeset
347 movwf EEADR
heinrichsweikamp
parents:
diff changeset
348 movlw HIGH(eeprom_opt_backup)
142
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
349 btfsc STATUS,C ; >256
8531f39eb70a option_read and option_write eeprom banking
mh@mh-THINK
parents: 139
diff changeset
350 addlw .1 ; Yes: +1
0
heinrichsweikamp
parents:
diff changeset
351 movwf EEADRH
heinrichsweikamp
parents:
diff changeset
352
heinrichsweikamp
parents:
diff changeset
353 movf opt_type,W ; Option type is string ?
heinrichsweikamp
parents:
diff changeset
354 xorlw 2
heinrichsweikamp
parents:
diff changeset
355 bz option_restore_string
heinrichsweikamp
parents:
diff changeset
356
heinrichsweikamp
parents:
diff changeset
357 ; Read one byte from eeprom
heinrichsweikamp
parents:
diff changeset
358 call read_eeprom
heinrichsweikamp
parents:
diff changeset
359 movff EEDATA, INDF1 ; And restore option register.
heinrichsweikamp
parents:
diff changeset
360 return
heinrichsweikamp
parents:
diff changeset
361
heinrichsweikamp
parents:
diff changeset
362 option_restore_string:
heinrichsweikamp
parents:
diff changeset
363 call read_eeprom ; Read one byte, and
heinrichsweikamp
parents:
diff changeset
364 movff EEDATA,POSTINC1 ; restore it
heinrichsweikamp
parents:
diff changeset
365 infsnz EEADR,F
heinrichsweikamp
parents:
diff changeset
366 incf EEADRH,F
heinrichsweikamp
parents:
diff changeset
367
heinrichsweikamp
parents:
diff changeset
368 decfsz opt_max ; Decrement string length
heinrichsweikamp
parents:
diff changeset
369 bra option_restore_string ; And loop while not finished
heinrichsweikamp
parents:
diff changeset
370 return
heinrichsweikamp
parents:
diff changeset
371
heinrichsweikamp
parents:
diff changeset
372 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
373 ; Increment an option, based on type, and boundary.
heinrichsweikamp
parents:
diff changeset
374 ; INPUT: FSR0 = option handle
heinrichsweikamp
parents:
diff changeset
375 ; OUTPUT: none
heinrichsweikamp
parents:
diff changeset
376 ; TRASH: TBLPTR, TABLAT, WREG, FSR0, FSR1
heinrichsweikamp
parents:
diff changeset
377 option_inc:
heinrichsweikamp
parents:
diff changeset
378 ; Read type, default and register from table
heinrichsweikamp
parents:
diff changeset
379 rcall option_read
heinrichsweikamp
parents:
diff changeset
380
heinrichsweikamp
parents:
diff changeset
381 ; Switch on type
heinrichsweikamp
parents:
diff changeset
382 movf opt_type,W
heinrichsweikamp
parents:
diff changeset
383 bz option_inc_uint8
heinrichsweikamp
parents:
diff changeset
384 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
385 bra option_inc_enum8
heinrichsweikamp
parents:
diff changeset
386 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
387 bra option_inc_string
heinrichsweikamp
parents:
diff changeset
388
heinrichsweikamp
parents:
diff changeset
389 option_inc_uint8: ; Defaults type too...
heinrichsweikamp
parents:
diff changeset
390 movf INDF1,W
heinrichsweikamp
parents:
diff changeset
391 addwf opt_inc,W
heinrichsweikamp
parents:
diff changeset
392 cpfslt opt_max
heinrichsweikamp
parents:
diff changeset
393 bra option_inc_1
heinrichsweikamp
parents:
diff changeset
394 movf opt_min,W
heinrichsweikamp
parents:
diff changeset
395 option_inc_1:
heinrichsweikamp
parents:
diff changeset
396 movwf INDF1
heinrichsweikamp
parents:
diff changeset
397 return
heinrichsweikamp
parents:
diff changeset
398
heinrichsweikamp
parents:
diff changeset
399 option_inc_enum8: ; Always +1
heinrichsweikamp
parents:
diff changeset
400 incf INDF1,W
heinrichsweikamp
parents:
diff changeset
401 cpfsgt opt_max
heinrichsweikamp
parents:
diff changeset
402 clrf WREG
heinrichsweikamp
parents:
diff changeset
403 movwf INDF1
heinrichsweikamp
parents:
diff changeset
404 return
heinrichsweikamp
parents:
diff changeset
405
heinrichsweikamp
parents:
diff changeset
406 option_inc_string: ; No edition yet...
heinrichsweikamp
parents:
diff changeset
407 return
heinrichsweikamp
parents:
diff changeset
408
heinrichsweikamp
parents:
diff changeset
409 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
410 ; Strcat option into FSR2 buffer.
heinrichsweikamp
parents:
diff changeset
411 option_draw:
heinrichsweikamp
parents:
diff changeset
412 ; Read type, default and register from table
heinrichsweikamp
parents:
diff changeset
413 rcall option_read
heinrichsweikamp
parents:
diff changeset
414
heinrichsweikamp
parents:
diff changeset
415 ; Switch on type
heinrichsweikamp
parents:
diff changeset
416 movf opt_type,W
heinrichsweikamp
parents:
diff changeset
417 bz option_draw_uint8
heinrichsweikamp
parents:
diff changeset
418 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
419 bra option_draw_enum8
heinrichsweikamp
parents:
diff changeset
420 dcfsnz WREG
heinrichsweikamp
parents:
diff changeset
421 bra option_draw_string
heinrichsweikamp
parents:
diff changeset
422 return ; Unknown: return...
heinrichsweikamp
parents:
diff changeset
423
heinrichsweikamp
parents:
diff changeset
424 option_draw_uint8:
heinrichsweikamp
parents:
diff changeset
425 movff INDF1,lo ; Draw value.
heinrichsweikamp
parents:
diff changeset
426 output_8
heinrichsweikamp
parents:
diff changeset
427 clrf INDF2 ; Make sure to close string...
heinrichsweikamp
parents:
diff changeset
428
heinrichsweikamp
parents:
diff changeset
429 movf opt_unit+0,W ; Is there a unit to append ?
heinrichsweikamp
parents:
diff changeset
430 iorwf opt_unit+1,W
heinrichsweikamp
parents:
diff changeset
431 rcall option_draw_unit
heinrichsweikamp
parents:
diff changeset
432
heinrichsweikamp
parents:
diff changeset
433 movf opt_default,W ; Default value
heinrichsweikamp
parents:
diff changeset
434 cpfseq lo ; Current value
heinrichsweikamp
parents:
diff changeset
435 bra option_draw_uint8_2 ; Not default, add *
heinrichsweikamp
parents:
diff changeset
436 return ; Default, Done.
heinrichsweikamp
parents:
diff changeset
437 option_draw_uint8_2:
heinrichsweikamp
parents:
diff changeset
438 PUTC "*"
heinrichsweikamp
parents:
diff changeset
439 return ; Done.
heinrichsweikamp
parents:
diff changeset
440
heinrichsweikamp
parents:
diff changeset
441 option_draw_unit:
heinrichsweikamp
parents:
diff changeset
442 movff opt_unit+0,FSR1L
heinrichsweikamp
parents:
diff changeset
443 movff opt_unit+1,FSR1H
heinrichsweikamp
parents:
diff changeset
444 goto strcat_text
heinrichsweikamp
parents:
diff changeset
445
heinrichsweikamp
parents:
diff changeset
446
heinrichsweikamp
parents:
diff changeset
447
heinrichsweikamp
parents:
diff changeset
448 ;---- Draw an enumerated value (set of translated strings)
heinrichsweikamp
parents:
diff changeset
449 option_draw_enum8:
heinrichsweikamp
parents:
diff changeset
450 movf INDF1,W ; Get current value.
heinrichsweikamp
parents:
diff changeset
451 cpfsgt opt_max ; Bound value
heinrichsweikamp
parents:
diff changeset
452 clrf WREG
heinrichsweikamp
parents:
diff changeset
453 addwf WREG ; *= 2
heinrichsweikamp
parents:
diff changeset
454 addwf opt_inc,W ; Base text + 2 * value
heinrichsweikamp
parents:
diff changeset
455 movwf FSR1L
heinrichsweikamp
parents:
diff changeset
456 movlw 0
heinrichsweikamp
parents:
diff changeset
457 addwfc opt_min,W ; Propagate carry
heinrichsweikamp
parents:
diff changeset
458 movwf FSR1H ; Into FSR1
heinrichsweikamp
parents:
diff changeset
459
heinrichsweikamp
parents:
diff changeset
460 goto strcat_text
heinrichsweikamp
parents:
diff changeset
461
heinrichsweikamp
parents:
diff changeset
462 option_draw_string:
heinrichsweikamp
parents:
diff changeset
463 movff POSTINC1,POSTINC2
heinrichsweikamp
parents:
diff changeset
464 decfsz opt_max
heinrichsweikamp
parents:
diff changeset
465 bra option_draw_string
heinrichsweikamp
parents:
diff changeset
466 return
heinrichsweikamp
parents:
diff changeset
467
heinrichsweikamp
parents:
diff changeset
468 END