comparison src/ghostwriter.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents ca4556fb60b9
children cd58f7fc86db
comparison
equal deleted inserted replaced
622:02d1386429a6 623:c40025d8e750
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File ghostwriter.asm REFACTORED VERSION V2.99a 3 ; File ghostwriter.asm combined next generation V3.03.1
4 ; 4 ;
5 ; Ghostwriter (Log profile recorder) 5 ; Ghostwriter (Log profile recorder)
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
14 #include "external_flash.inc" 14 #include "external_flash.inc"
15 #include "surfmode.inc" 15 #include "surfmode.inc"
16 #include "eeprom_rs232.inc" 16 #include "eeprom_rs232.inc"
17 #include "strings.inc" 17 #include "strings.inc"
18 #include "isr.inc"
19 #include "tft_outputs.inc" 18 #include "tft_outputs.inc"
20 #include "divemode.inc" 19 #include "divemode.inc"
21 #include "rtc.inc" 20 #include "rtc.inc"
22 21
22
23 extern deco_pull_tissues_from_vault 23 extern deco_pull_tissues_from_vault
24 24
25 25
26 ;---- Private local variables ------------------------------------------------- 26 ; private local Variables
27 27
28 CBLOCK local3 ; max size is 16 Byte !!! 28 CBLOCK local3 ; max size is 16 Byte !!!
29 divisor_temperature ; divisor used to time the sampling of dive data 29 divisor_temperature ; divisor used to time the sampling of dive data
30 divisor_deco ; divisor used to time the sampling of dive data 30 divisor_deco ; divisor used to time the sampling of dive data
31 divisor_gf ; divisor used to time the sampling of dive data 31 divisor_supersat ; divisor used to time the sampling of dive data
32 divisor_ppo2_sensors ; divisor used to time the sampling of dive data 32 divisor_ppo2_sensors ; divisor used to time the sampling of dive data
33 divisor_decoplan ; divisor used to time the sampling of dive data 33 divisor_decoplan ; divisor used to time the sampling of dive data
34 divisor_cns ; divisor used to time the sampling of dive data 34 divisor_cns ; divisor used to time the sampling of dive data
35 divisor_tank ; divisor used to time the sampling of dive data 35 divisor_tank ; divisor used to time the sampling of dive data
36 ProfileFlagByte ; used to store events 36 ProfileFlagByte ; used to store events
37 ENDC ; used: 8 byte, remaining: 8 byte 37 ENDC ; used: 8 byte, remaining: 8 byte
38 38
39 39
40 ghostwriter CODE 40 ghostwriter CODE
41 41
42 ;============================================================================= 42 ;=============================================================================
43 43
44 44
45 global init_recording_params ; initialize profile recording parameters 45 global init_recording_params ; initialize profile recording parameters
46 init_recording_params: 46 init_recording_params:
47 movff samplingrate,samplesecs_value; to avoid EEPROM access in the ISR 47 movlw div_temperature ; get divisor for temperature storage
48 movlw div_temperature 48 movwf divisor_temperature ; initialize divisor
49 movwf divisor_temperature ; load divisors for profile storage 49
50 movlw div_deco 50 movlw div_deco ; ...
51 movwf divisor_deco 51 movwf divisor_deco ; ...
52
52 movlw div_gf 53 movlw div_gf
53 movwf divisor_gf 54 movwf divisor_supersat
55
56 movlw div_decoplan
57 movwf divisor_decoplan
58
59 movlw div_cns
60 movwf divisor_cns
61
62 movlw div_tank
63 movwf divisor_tank
64
65 IFDEF _external_sensor
54 movlw div_ppo2_sensors 66 movlw div_ppo2_sensors
55 movwf divisor_ppo2_sensors 67 movwf divisor_ppo2_sensors
56 movlw div_decoplan 68
57 movwf divisor_decoplan
58 movlw div_cns
59 movwf divisor_cns
60 movlw div_tank
61 movwf divisor_tank
62 btfss FLAG_apnoe_mode ; in Apnoe mode?
63 bra init_recording_params_1 ; NO
64 movlw samplingrate_apnoe ; YES - overwrite some parameters in Apnoe mode
65 movwf samplesecs_value ; to avoid EEPROM access in the ISR
66 init_recording_params_1:
67 btfsc FLAG_ccr_mode ; in CCR mode? 69 btfsc FLAG_ccr_mode ; in CCR mode?
68 bra init_recording_params_2 ; YES 70 bra init_recording_params_2 ; YES
69 btfsc FLAG_pscr_mode ; in pSCR mode? 71 btfsc FLAG_pscr_mode ; in pSCR mode?
70 bra init_recording_params_2 ; YES 72 bra init_recording_params_2 ; YES
71 ; in all modes but CCR and pSCR, disable ppO2 logging 73 ; in all modes but CCR and pSCR, disable ppO2 logging
72 movlw .0 74 movlw .0
73 movwf divisor_ppo2_sensors 75 movwf divisor_ppo2_sensors
76 ENDIF
77
74 init_recording_params_2: 78 init_recording_params_2:
75 return 79 return
76 80
77 81
78 global store_dive_data 82 global store_dive_data
79 store_dive_data: 83 store_dive_data:
80 bcf store_sample ; clear flag 84 bcf trigger_sample_divedata ; clear flag
81 85
82 ifndef __DEBUG 86 ifndef _DEBUG
83 btfsc simulatormode_active ; are we in simulator mode? 87 btfsc sensor_override_active ; in simulator mode?
84 return ; YES - discard everything 88 return ; YES - no dive data stored in simulator mode
85 endif 89 endif
86 90
87 btfsc FLAG_apnoe_mode ; in Apnoe mode? 91 btfss FLAG_apnoe_mode ; in apnoe mode?
88 return ; YES - discard everything 92 bra store_dive_data_1 ; NO - proceed
89 93 TSTOSS opt_store_apnoe_dive ; YES - logging in apnoe mode enabled?
90 SAFE_2BYTE_COPY rel_pressure, lo 94 return ; NO - done
91 movf lo,W ; store depth with every sample 95
92 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 96 store_dive_data_1:
93 movf hi,W 97 ; Store depth with every sample
94 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 98 movf pressure_rel_cur_cached+0,W ; get depth (relative pressure), low byte
99 rcall ghostwrite_byte_profile ; store to profile in ext. flash
100 movf pressure_rel_cur_cached+1,W ; get depth (relative pressure), high byte
101 rcall ghostwrite_byte_profile ; store to profile in ext. flash
95 102
96 ; First, find out how many bytes will be appended to this sample set 103 ; First, find out how many bytes will be appended to this sample set
97 clrf ProfileFlagByte ; clear number of bytes to append 104 clrf ProfileFlagByte ; clear number of bytes to append
98 105
99 ; Check Extended informations 106 ; Check Extended Information
100 decfsz divisor_temperature,W ; check divisor 107 decfsz divisor_temperature,W ; check divisor if it will become 0, dump decremented value to WREG
101 bra check_extended1 108 bra check_extended1 ; NO - skip
102 movlw infolength_temperature 109 movlw infolength_temperature ; YES - get length of extra data
103 addwf ProfileFlagByte,F ; add to ProfileFlagByte 110 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
104 check_extended1: 111 check_extended1:
105 decfsz divisor_deco,W ; check divisor 112 decfsz divisor_deco,W ; check divisor if it will become 0, dump decremented value to WREG
106 bra check_extended2 113 bra check_extended2 ; NO - skip
107 movlw infolength_deco 114 movlw infolength_deco ; YES - get length of extra data
108 addwf ProfileFlagByte,F ; add to ProfileFlagByte 115 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
109 check_extended2: 116 check_extended2:
110 decfsz divisor_gf,W ; check divisor 117 decfsz divisor_supersat,W ; check divisor if it will become 0, dump decremented value to WREG
111 bra check_extended3 118 bra check_extended3 ; NO - skip
112 movlw infolength_gf 119 movlw infolength_gf ; YES - get length of extra data
113 addwf ProfileFlagByte,F ; add to ProfileFlagByte 120 addwf ProfileFlagByte,F ; add to ProfileFlagByte
114 check_extended3: 121 check_extended3:
115 decfsz divisor_ppo2_sensors,W ; check divisor 122 IFDEF _external_sensor
116 bra check_extended4 123 decfsz divisor_ppo2_sensors,W ; check divisor if it will become 0, dump decremented value to WREG
117 movlw infolength_ppo2_sensors 124 bra check_extended4 ; NO - skip
118 addwf ProfileFlagByte,F ; add to ProfileFlagByte 125 movlw infolength_ppo2_sensors ; YES - get length of extra data
126 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
127 ENDIF
119 check_extended4: 128 check_extended4:
120 decfsz divisor_decoplan,W ; check divisor 129 decfsz divisor_decoplan,W ; check divisor if it will become 0, dump decremented value to WREG
121 bra check_extended5 130 bra check_extended5 ; NO - skip
122 movlw infolength_decoplan 131 movlw infolength_decoplan ; YES - get length of extra data
123 addwf ProfileFlagByte,F ; add to ProfileFlagByte 132 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
124 check_extended5: 133 check_extended5:
125 decfsz divisor_cns,W ; check divisor 134 decfsz divisor_cns,W ; check divisor if it will become 0, dump decremented value to WREG
126 bra check_extended6 135 bra check_extended6 ; NO - skip
127 movlw infolength_cns 136 movlw infolength_cns ; YES - get length of extra data
128 addwf ProfileFlagByte,F ; add to ProfileFlagByte 137 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
129 check_extended6: 138 check_extended6:
130 decfsz divisor_tank,W ; check divisor 139 decfsz divisor_tank,W ; check divisor if it will become 0, dump decremented value to WREG
131 bra check_extended7 140 bra check_extended7 ; NO - skip
132 movlw infolength_tank 141 movlw infolength_tank ; YES - get length of extra data
133 addwf ProfileFlagByte,F ; add to ProfileFlagByte 142 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
134 check_extended7: 143 check_extended7:
135 144
136 ; Second, check global event flag 145 ; Second, check global event flag
137 btfss event_occured ; check global event flag 146 btfss event_occured ; check global event flag
138 bra store_dive_data3 ; no event 147 bra store_dive_data3 ; no event
139 148
140 incf ProfileFlagByte,F ; add one byte (the EventByte1) 149 incf ProfileFlagByte,F ; add one byte (the event byte 1)
141 150
142 clrf EventByte1 ; reset EventByte1 151 clrf event_byte1 ; reset event byte 1
143 clrf EventByte2 ; reset EventByte2 152 clrf event_byte2 ; reset event byte 2
144 153
145 movf AlarmType,W ; type of Alarm Bit 0-3 154 movf alarm_type,W ; type of alarm Bit 0-3
146 addwf EventByte1,F ; copy to EventByte1 Bit 0-3 155 addwf event_byte1,F ; copy to event byte 1, bit 0-3
147 clrf AlarmType ; reset AlarmType 156 clrf alarm_type ; reset alarm type
148 157
149 ; Third, check events and add additional bytes 158 ; Third, check events and add additional bytes
150 btfss gas6_changed ; check flag 159 btfss event_gas_change_gas6 ; did a change to gas 6 occur?
151 bra check_event2 160 bra check_event2 ; NO
152 movlw d'2' ; information length 161 movlw d'2' ; YES - set information length
153 addwf ProfileFlagByte,F ; add to ProfileFlagByte 162 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
154 bsf EventByte1,4 ; also set Flag in EventByte1! 163 bsf event_byte1,4 ; - set flag in event byte 1
155 check_event2: 164 check_event2:
156 btfss stored_gas_changed ; check flag 165 btfss event_gas_change ; did a gas change occur?
157 bra check_event3 166 bra check_event3 ; NO
158 movlw d'1' ; information length 167 movlw d'1' ; YES - set information length
159 addwf ProfileFlagByte,F ; add to ProfileFlagByte 168 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
160 bsf EventByte1,5 ; also set Flag in EventByte1! 169 bsf event_byte1,5 ; - set flag in event byte 1
161 check_event3: 170 check_event3:
162 btfss setpoint_changed ; check flag 171 IFDEF _ccr_pscr
163 bra check_event4 172 btfss event_SP_change ; did a setpoint change occur?
164 movlw d'1' ; information length 173 bra check_event4 ; NO
165 addwf ProfileFlagByte,F ; add to ProfileFlagByte 174 movlw d'1' ; YES - set information length
166 bsf EventByte1,6 ; also set Flag in EventByte1! 175 addwf ProfileFlagByte,F ; - add to ProfileFlagByte
176 bsf event_byte1,6 ; - set flag in event byte 1
177 ENDIF
167 check_event4: 178 check_event4:
168 btfss bailoutgas_event ; =1: bailout was selected or a gas change during bailout 179 IFDEF _ccr_pscr
180 btfss event_bailout ; did a gas change due to bailout occur?
169 bra check_event5 181 bra check_event5
170 movlw d'2' ; information length 182 movlw d'2' ; information length
171 addwf ProfileFlagByte,F ; add to ProfileFlagByte 183 addwf ProfileFlagByte,F ; add to ProfileFlagByte
172 bsf EventByte2,0 ; set flag in EventByte2! 184 bsf event_byte2,0 ; set flag in event byte 2
173 bsf EventByte1,7 ; =1: another EventByte1 is available 185 bsf event_byte1,7 ; =1: another event byte is available
186 ENDIF
174 187
175 check_event5: 188 check_event5:
176 ; more events? 189 ; more events?
177 190
178 store_dive_data3: 191 store_dive_data3:
179 btfsc EventByte1,7 ; =1: Another EventByte1 is available 192 btfsc event_byte1,7 ; =1: another event byte is available
180 incf ProfileFlagByte,F ; add one byte (The EventByte2) 193 incf ProfileFlagByte,F ; add one byte (the event byte 2)
181 194
182 btfsc event_occured ; check global event flag 195 btfsc event_occured ; check global event flag
183 bsf ProfileFlagByte,7 ; set EventByte1 flag in ProfileFlagByte 196 bsf ProfileFlagByte,7 ; set event byte 1 flag in ProfileFlagByte
184 197
185 movf ProfileFlagByte,W ; finally, write ProfileFlagByte 198 movf ProfileFlagByte,W ; finally, write ProfileFlagByte
186 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 199 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
187 200
188 btfss event_occured ; check global event flag (again) 201 btfss event_occured ; check global event flag (again)
189 bra store_dive_data4 ; no event 202 bra store_dive_data4 ; no event
190 203
191 ; Store the EventByte(s) + additional bytes now 204 ; Store the EventByte(s) + additional bytes now
192 movf EventByte1,W 205 movf event_byte1,W
193 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 206 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
194 207 movf event_byte2,W ; write second event byte...
195 movf EventByte2,W ; write second event byte... 208 btfsc event_byte1,7 ; =1: another event byte is available
196 btfsc EventByte1,7 ; =1: another EventByte1 is available 209 rcall ghostwrite_byte_profile ; store that information
197 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 210
198 211 btfss event_gas_change_gas6 ; did a change to gas 6 occur?
199 btfss gas6_changed ; check flag 212 bra store_dive_data3b ; NO
200 bra store_dive_data3b 213 movff char_I_O2_ratio,WREG ; YES - get gas 6 O2 ratio
201 movff char_I_O2_ratio,WREG ; store gas 6 o2 ratio 214 rcall ghostwrite_byte_profile ; - store it
202 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 215 IFDEF _helium
203 movff char_I_He_ratio,WREG ; store gas 6 He ratio 216 movff char_I_He_ratio,WREG ; - get gas 6 He ratio
204 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 217 ELSE
205 bcf gas6_changed ; clear this event 218 clrf WREG ; - He ratio is zero
219 ENDIF
220 rcall ghostwrite_byte_profile ; - store it
221 bcf event_gas_change_gas6 ; - clear event flag
206 store_dive_data3b: 222 store_dive_data3b:
207 btfss stored_gas_changed ; check flag 223 btfss event_gas_change ; did a gas change occur?
208 bra store_dive_data3c 224 bra store_dive_data3c ; NO
209 movf active_dil,W ; store active diluent (default, may be overwritten soon) 225 IFDEF _ccr_pscr
210 btfsc FLAG_oc_mode ; in OC mode? 226 movf active_dil,W ; YES - store active diluent (default, may be overwritten soon)
211 movf active_gas,W ; YES - store active gas 227 btfsc FLAG_oc_mode ; - in OC mode?
212 btfsc FLAG_bailout_mode ; in bailout? 228 movf active_gas,W ; YES - get active gas
213 movf active_gas,W ; YES - store active OC = bailout gas 229 btfsc bailout_mode ; - in bailout?
214 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 230 ENDIF
215 bcf stored_gas_changed ; clear this event 231 movf active_gas,W ; YES - get active OC = bailout gas
232 rcall ghostwrite_byte_profile ; - store it
233 bcf event_gas_change ; - clear event flag
216 store_dive_data3c: 234 store_dive_data3c:
217 btfss setpoint_changed ; check flag 235 IFDEF _ccr_pscr
218 bra store_dive_data3d 236 btfss event_SP_change ; did a setpoint change occur?
219 movff char_I_const_ppO2,WREG ; store setpoint 237 bra store_dive_data3d ; NO
220 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 238 movff char_I_const_ppO2,WREG ; YES - get setpoint
221 bcf setpoint_changed ; clear this event 239 rcall ghostwrite_byte_profile ; - store it
240 bcf event_SP_change ; - clear event flag
241 ENDIF
222 store_dive_data3d: 242 store_dive_data3d:
223 btfss bailoutgas_event ; check flag 243 IFDEF _ccr_pscr
224 bra store_dive_data4 244 btfss event_bailout ; did a gas change due to bailout occur?
225 movff char_I_O2_ratio,WREG ; store O2 ratio of bailout gas 245 bra store_dive_data4 ; NO
226 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 246 movff char_I_O2_ratio,WREG ; YES - get O2 ratio of bailout gas
227 movff char_I_He_ratio,WREG ; store He ratio of bailout gas 247 rcall ghostwrite_byte_profile ; - store it
228 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 248 IFDEF _helium
229 bcf bailoutgas_event ; clear this event 249 movff char_I_He_ratio,WREG ; - get He ratio of bailout gas
230 250 ELSE
251 clrf WREG ; - He ratio is zero
252 ENDIF
253 rcall ghostwrite_byte_profile ; - store it
254 bcf event_bailout ; - clear event flag
255 ENDIF ; _ccr_pscr
231 store_dive_data4: 256 store_dive_data4:
232 ; Store extended information 257 ; Store extended information
233 decfsz divisor_temperature,F ; check divisor 258 decfsz divisor_temperature,F ; time to store a temperature sample ?
234 bra store_extended1 259 bra store_extended1 ; NO - skip
235 rcall store_dive_temperature 260 rcall store_dive_temperature ; YES - store data
236 store_extended1: 261 store_extended1:
237 decfsz divisor_deco,F ; check divisor 262 decfsz divisor_deco,F ; time to store the current deco data?
238 bra store_extended2 263 bra store_extended2 ; NO - skip
239 rcall store_dive_decodata 264 rcall store_dive_decodata ; YES - store data
240 store_extended2: 265 store_extended2:
241 decfsz divisor_gf,F ; check divisor 266 decfsz divisor_supersat,F ; time to store the current supersaturation ?
242 bra store_extended3 267 bra store_extended3 ; NO - skip
243 rcall store_dive_gf 268 rcall store_dive_supersat ; YES - store data
244 store_extended3: 269 store_extended3:
245 decfsz divisor_ppo2_sensors,F ; check divisor 270 IFDEF _external_sensor
246 bra store_extended4 271 decfsz divisor_ppo2_sensors,F ; decrement divisor, did it became 0 ?
247 rcall store_dive_ppO2_sensors 272 bra store_extended4 ; NO - skip
273 rcall store_dive_ppO2_sensors ; YES - store data
274 ENDIF
248 store_extended4: 275 store_extended4:
249 decfsz divisor_decoplan,F ; check divisor 276 decfsz divisor_decoplan,F ; decrement divisor, did it became 0 ?
250 bra store_extended5 277 bra store_extended5 ; NO - skip
251 rcall store_dive_decoplan 278 rcall store_dive_decoplan ; YES - store data
252 store_extended5: 279 store_extended5:
253 decfsz divisor_cns,F ; check divisor 280 decfsz divisor_cns,F ; decrement divisor, did it became 0 ?
254 bra store_extended6 281 bra store_extended6 ; NO - skip
255 rcall store_dive_cns 282 rcall store_dive_cns ; YES - store data
256 store_extended6: 283 store_extended6:
257 decfsz divisor_tank,F ; check divisor 284 decfsz divisor_tank,F ; decrement divisor, did it became 0 ?
258 bra store_extended7 285 bra store_extended7 ; NO - skip
259 rcall store_dive_tank 286 rcall store_dive_tank ; YES - store data
260 store_extended7: 287 store_extended7:
261 288
262 ; The next block is required to take care of "store never" 289 ; The next block is required to take care of "store never"
263 btfsc divisor_temperature,7 ; test highest bit (register must have been zero before the "decfsz" command!) 290 btfsc divisor_temperature,7 ; test highest bit (register must have been zero before the "decfsz" command!)
264 clrf divisor_temperature ; and clear register again, so it will never reach zero... 291 clrf divisor_temperature ; and clear register again, so it will never reach zero...
292
265 btfsc divisor_deco,7 293 btfsc divisor_deco,7
266 clrf divisor_deco 294 clrf divisor_deco
267 btfsc divisor_gf,7 295
268 clrf divisor_gf 296 btfsc divisor_supersat,7
297 clrf divisor_supersat
298
299 IFDEF _external_sensor
269 btfsc divisor_ppo2_sensors,7 300 btfsc divisor_ppo2_sensors,7
270 clrf divisor_ppo2_sensors 301 clrf divisor_ppo2_sensors
302 ENDIF
303
271 btfsc divisor_decoplan,7 304 btfsc divisor_decoplan,7
272 clrf divisor_decoplan 305 clrf divisor_decoplan
306
273 btfsc divisor_cns,7 307 btfsc divisor_cns,7
274 clrf divisor_cns 308 clrf divisor_cns
309
275 btfsc divisor_tank,7 310 btfsc divisor_tank,7
276 clrf divisor_tank 311 clrf divisor_tank
277 312
278 store_dive_data5: 313 store_dive_data5:
279 bcf event_occured ; clear the global event flag 314 bcf event_occured ; clear the global event flag
280 clrf EventByte1 ; reset EventByte1 315 clrf event_byte1 ; reset event byte 1
281 clrf EventByte2 ; reset EventByte2 316 clrf event_byte2 ; reset event byte 2
282 return ; done (sample with all informations written to external flash) 317 return ; done (sample with all informations written to external flash)
283 318
284 store_dive_cns: 319 store_dive_cns:
285 movff int_O_CNS_fraction+0,WREG 320 movff int_O_CNS_current+0,WREG ; get current CNS, low byte
286 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 321 rcall ghostwrite_byte_profile ; store it
287 movff int_O_CNS_fraction+1,WREG 322 movff int_O_CNS_current+1,WREG ; get current CNS, high byte
288 bcf WREG,int_warning_flag ; clear warning flag 323 bcf WREG,int_warning_flag ; clear warning flag
289 bcf WREG,int_attention_flag ; clear attention flag 324 bcf WREG,int_attention_flag ; clear attention flag
290 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 325 rcall ghostwrite_byte_profile ; store it
291 movlw div_cns 326 movlw div_cns
292 movwf divisor_cns ; reload divisor from CF 327 movwf divisor_cns ; reload divisor from CF
293 return 328 return
294 329
295 store_dive_tank: 330 store_dive_tank:
298 movwf divisor_tank ; reload divisor from CF 333 movwf divisor_tank ; reload divisor from CF
299 return 334 return
300 335
301 store_dive_decoplan: 336 store_dive_decoplan:
302 ; Store the deco plan 337 ; Store the deco plan
303 lfsr FSR1,char_O_deco_time_for_log+.0 338 lfsr FSR1,char_O_deco_time_for_log ; load base address of deco stop times table
304 movlw .15 339 movlw NUM_STOPS_LOG ; load size of deco stop times table
305 movwf lo 340 movwf lo ; copy size to loop counter
306 store_dive_decoplan_loop: 341 store_dive_decoplan_loop:
307 movf POSTINC1,W 342 movf POSTINC1,W ; get a stop time
308 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 343 rcall ghostwrite_byte_profile ; store it
309 decfsz lo,F 344 decfsz lo,F ; decrement loop counter, became zero?
310 bra store_dive_decoplan_loop 345 bra store_dive_decoplan_loop ; NO - loop
311 movlw div_decoplan 346 movlw div_decoplan ; YES - get divisor for deco plan recording
312 movwf divisor_decoplan ; reload divisor from CF 347 movwf divisor_decoplan ; - reload timer
348 return ; - done
349
350 ;=============================================================================
351
352 IFDEF _external_sensor
353
354 store_dive_ppO2_sensors:
355 movff sensor1_ppO2,WREG ; get sensor 1 ppO2 (in 0.01 bar steps)
356 rcall ghostwrite_byte_profile ; store it
357 SMOVII sensor1_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor to hi:lo
358 movf lo,W ; in 0.1 mV steps, low byte
359 rcall ghostwrite_byte_profile ; store it
360 movf hi,W ; in 0.1 mV steps, high byte
361 rcall ghostwrite_byte_profile ; store it
362
363 movff sensor2_ppO2,WREG ; get sensor 2 ppO2 (in 0.01 bar steps)
364 rcall ghostwrite_byte_profile ; store it
365 SMOVII sensor2_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor to hi:lo
366 movf lo,W ; in 0.1 mV steps, low byte
367 rcall ghostwrite_byte_profile ; store it
368 movf hi,W ; in 0.1 mV steps, high byte
369 rcall ghostwrite_byte_profile ; store it
370
371 movff sensor3_ppO2,WREG ; get sensor 3 ppO2 (in 0.01 bar steps)
372 rcall ghostwrite_byte_profile ; store it
373 SMOVII sensor3_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor to hi:lo
374 movf lo,W ; in 0.1 mV steps, low byte
375 rcall ghostwrite_byte_profile ; store it
376 movf hi,W ; in 0.1 mV steps, high byte
377 rcall ghostwrite_byte_profile ; store it
378
379 movlw div_ppo2_sensors
380 movwf divisor_ppo2_sensors ; reload timer
313 return 381 return
314 382
315 store_dive_ppO2_sensors: 383 ENDIF
316 movf o2_ppo2_sensor1,W ; Sensor1 ppO2 (in 0.01 bar steps) 384
317 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 385 ;=============================================================================
318 SAFE_2BYTE_COPY o2_mv_sensor1,lo ; o2_mv_sensor may be modified via ISR during the two writes here... 386
319 movf lo,W ; in 0.1 mV steps 387 store_dive_supersat:
320 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 388 movff int_O_lead_supersat+0,WREG ; get leading tissue's supersaturation (value is limited to 255, only lower byte is used for the value)
321 movf hi,W ; in 0.1 mV steps 389 rcall ghostwrite_byte_profile ; store it
322 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
323
324 movf o2_ppo2_sensor2,W ; Sensor2 ppO2 (in 0.01 bar steps)
325 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
326 SAFE_2BYTE_COPY o2_mv_sensor2,lo ; o2_mv_sensor may be modified via ISR during the two writes here...
327 movf lo,W ; in 0.1 mV steps
328 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
329 movf hi,W ; in 0.1 mV steps
330 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
331
332 movf o2_ppo2_sensor3,W ; Sensor3 ppO2 (in 0.01 bar steps)
333 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
334 SAFE_2BYTE_COPY o2_mv_sensor3,lo ; o2_mv_sensor may be modified via ISR during the two writes here...
335 movf lo,W ; in 0.1 mV steps
336 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
337 movf hi,W ; in 0.1 mV steps
338 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
339
340 movlw div_ppo2_sensors
341 movwf divisor_ppo2_sensors ; reload divisor
342 return
343
344 store_dive_gf:
345 movff int_O_gradient_factor+0,WREG ; gradient factor absolute (range is limited to 255, only lower byte used for value)
346 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
347 movlw div_gf 390 movlw div_gf
348 movwf divisor_gf ; reload divisor 391 movwf divisor_supersat ; reload timer
349 return 392 return
350 393
351 store_dive_decodata: 394 store_dive_decodata:
352 ; Check if deco stops are necessary 395 ; Check if deco stops are necessary
353 movff char_O_first_deco_depth,WREG ; get ceiling 396 movff char_O_deco_depth,WREG ; get depth of the first stop
354 tstfsz WREG ; ceiling < 0 m (aka in deco) ? 397 tstfsz WREG ; depth of first stop > 0 m (aka in deco) ?
355 bra store_dive_decodata_deco ; YES 398 bra store_dive_decodata_deco ; YES
356 ; NO - within NDL 399 ; NO - within NDL
357 clrf WREG ; =0: no stop dive 400 clrf WREG ; =0: no stop dive
358 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 401 rcall ghostwrite_byte_profile ; store it
359 movff char_O_nullzeit,WREG ; remaining NDL time 402 movff char_O_NDL_norm,WREG ; get NDL time in normal plan
360 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 403 rcall ghostwrite_byte_profile ; store it
361 bra store_dive_decodata_common 404 bra store_dive_decodata_common
362 store_dive_decodata_deco: 405 store_dive_decodata_deco:
363 ; YES - in deco 406 ; YES - in deco
364 movff char_O_first_deco_depth,WREG ; ceiling in m 407 movff char_O_deco_depth,WREG ; get depth of the first stop in meters
365 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 408 rcall ghostwrite_byte_profile ; store it
366 movff char_O_first_deco_time,WREG ; length of first stop in minutes 409 movff char_O_deco_time,WREG ; get time of the first stop in minutes
367 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 410 rcall ghostwrite_byte_profile ; store it
368 store_dive_decodata_common: 411 store_dive_decodata_common:
369 movlw div_deco 412 movlw div_deco
370 movwf divisor_deco ; Reload divisor 413 movwf divisor_deco ; reload timer
371 return 414 return
372 415
373 store_dive_temperature: 416 store_dive_temperature:
374 SAFE_2BYTE_COPY temperature,lo 417 SMOVII temperature_cur,mpr ; ISR-safe 2 byte copy of current temperature to hi:lo
375 movf lo,W ; append temperature to current sample! 418 movf lo,W ; get low byte
376 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 419 rcall ghostwrite_byte_profile ; store it
377 movf hi,W 420 movf hi,W ; get high byte
378 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 421 rcall ghostwrite_byte_profile ; store it
379 movlw div_temperature 422 movlw div_temperature
380 movwf divisor_temperature ; reload divisor 423 movwf divisor_temperature ; reload timer
381 return 424 return
382 425
383 ghostwrite_byte_header: 426 ghostwrite_byte_header:
384 goto write_byte_ext_flash_plus_header ; (this call will also delete the 4kB TOC entry first) 427 goto write_byte_ext_flash_plus_header ; (this call will also delete the 4kB TOC entry first)
385 ; returns... 428 ; returns...
386 429
387 ghostwrite_byte_profile: 430 ghostwrite_byte_profile:
388 goto write_byte_ext_flash_plus ; writes byte and increases address with banking at 0x200000 431 goto write_byte_ext_flash_plus ; writes byte and increases address with banking at 0x200000
389 ; returns... 432 ; returns...
390 433
434
391 global ghostwriter_end_dive 435 global ghostwriter_end_dive
392 ghostwriter_end_dive: 436 ghostwriter_end_dive:
437 ; save end-of-profile pointer to store in header
393 movff ext_flash_address+0,ext_flash_log_pointer+0 438 movff ext_flash_address+0,ext_flash_log_pointer+0
394 movff ext_flash_address+1,ext_flash_log_pointer+1 439 movff ext_flash_address+1,ext_flash_log_pointer+1
395 movff ext_flash_address+2,ext_flash_log_pointer+2 ; save end-of-profile pointer to store in header 440 movff ext_flash_address+2,ext_flash_log_pointer+2
396 441
397 movff menupos3,customview_divemode ; store last custom view 442 ; remember last custom view shown in dive mode
398 443 movff active_customview,customview_divemode
399 btfss realdive ; dive longer then one minute 444
445 btfss divetime_longer_1min ; dive longer then one minute
400 goto ghostwriter_end_dive_common ; NO - discard everything 446 goto ghostwriter_end_dive_common ; NO - discard everything
401 447
402 ; In DEBUG compile, keep all simulated dives in logbook, Desat time, nofly, etc... 448 ; In DEBUG compile, write simulated dives to logbook
403 ifndef __DEBUG 449 ifndef _DEBUG
404 btfsc simulatormode_active ; are we in simulator mode? 450 btfsc sensor_override_active ; are we in simulator mode?
405 goto ghostwriter_end_dive_common_sim ; YES - discard everything
406 endif
407
408 btfsc FLAG_apnoe_mode ; in Apnoe mode?
409 goto ghostwriter_end_dive_common ; YES - discard everything 451 goto ghostwriter_end_dive_common ; YES - discard everything
410 452 endif
453
454 btfss FLAG_apnoe_mode ; are we in apnoe mode?
455 bra ghostwriter_end_dive_1 ; NO - proceed
456 TSTOSS opt_store_apnoe_dive ; YES - logging in apnoe mode enabled?
457 goto ghostwriter_end_dive_common ; NO - discard everything
458
459 ghostwriter_end_dive_1:
411 ; Dive finished (and longer than one minute) 460 ; Dive finished (and longer than one minute)
412 461
413 btfsc FLAG_apnoe_mode ; calc max. depth (again) for very short apnoe dives 462 btfsc FLAG_apnoe_mode ; are we in apnoe mode?
414 call apnoe_calc_maxdepth 463 call apnoe_calc_maxdepth ; YES - calculate max. depth (again) for very short apnoe dives
415 464
416 ; calculate desaturation time 465 movlw 0xFD ; coding for End-of-Profile, byte 1
417 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; pass surface to desat routine ! 466 rcall ghostwrite_byte_profile ; store it
418 movff last_surfpressure_30min+1,int_I_pres_surface+1 467 movlw 0xFD ; coding for End-of-Profile, byte 2
419 468 rcall ghostwrite_byte_profile ; store it
420 call deco_calc_dive_interval_1min ; calculate deco in surface mode 469
421 call deco_calc_desaturation_time ; calculate desaturation time 470 ; Save end-of-profile pointer to store in header
422 banksel common ; select ram bank 1
423
424 movlw 0xFD ; .... End-of-Profile bytes
425 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
426 movlw 0xFD
427 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
428 movff ext_flash_address+0,ext_flash_log_pointer+0 471 movff ext_flash_address+0,ext_flash_log_pointer+0
429 movff ext_flash_address+1,ext_flash_log_pointer+1 472 movff ext_flash_address+1,ext_flash_log_pointer+1
430 movff ext_flash_address+2,ext_flash_log_pointer+2 ; save end-of-profile pointer to store in header 473 movff ext_flash_address+2,ext_flash_log_pointer+2
431 474
432 ; Set to first address again to store dive length ext_flash_dive_counter:3 475 ; Set to first address again to store dive length ext_flash_dive_counter:3
433 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 476 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6
434 477
435 incf_ext_flash_address_0x20 d'6' ; skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header 478 incf_ext_flash_address_0x20 d'6' ; skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header
446 ; Load total number of dives 489 ; Load total number of dives
447 read_int_eeprom .2 490 read_int_eeprom .2
448 movff EEDATA,lo 491 movff EEDATA,lo
449 read_int_eeprom .3 492 read_int_eeprom .3
450 movff EEDATA,hi 493 movff EEDATA,hi
451 ; +1 ; increase total dive counter 494
452 infsnz lo,F 495 INCI mpr ; increase total dive counter
453 incf hi,F 496
454 ; Store new number in EEPROM 497 ; Store new number in EEPROM
455 movff lo,EEDATA 498 movff lo,EEDATA
456 write_int_eeprom .2 499 write_int_eeprom .2
457 movff hi,EEDATA 500 movff hi,EEDATA
458 write_int_eeprom .3 501 write_int_eeprom .3
474 movf PRODL,W 517 movf PRODL,W
475 addwf ext_flash_address+1,F 518 addwf ext_flash_address+1,F
476 movf PRODH,W 519 movf PRODH,W
477 addwfc ext_flash_address+2,F 520 addwfc ext_flash_address+2,F
478 521
479 ; Now, write header 522 ; write header start code
480
481 movlw 0xFA ; header start 523 movlw 0xFA ; header start
482 rcall ghostwrite_byte_header ; (this call will also delete the 4kB TOC entry first) 524 rcall ghostwrite_byte_header ; (this call will also delete the 4kB TOC entry first)
483 movlw 0xFA 525 movlw 0xFA
484 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 526 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
485 527
500 movf ext_flash_log_pointer+1,W 542 movf ext_flash_log_pointer+1,W
501 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 543 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
502 movf ext_flash_log_pointer+2,W 544 movf ext_flash_log_pointer+2,W
503 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 545 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
504 546
505 ; write rest of header 547 ; write the remainder of the header
506 movlw logbook_profile_version ; defined in hwos.inc 548 movlw logbook_profile_version ; defined in hwos.inc
507 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 549 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
508 550
509 ; Store dive length 551 ; store dive length
510 movf ext_flash_dive_counter+0,W 552 movf ext_flash_dive_counter+0,W
511 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 553 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
512 movf ext_flash_dive_counter+1,W 554 movf ext_flash_dive_counter+1,W
513 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 555 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
514 movf ext_flash_dive_counter+2,W 556 movf ext_flash_dive_counter+2,W
515 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 557 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
516 558
559 ; store start of time time & date
517 lfsr FSR0,start_year ; load base address of start-of-dive data 560 lfsr FSR0,start_year ; load base address of start-of-dive data
518 movf POSTINC0,W ; year 561 movf POSTINC0,W ; year
519 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 562 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
520 movf POSTINC0,W ; month 563 movf POSTINC0,W ; month
521 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 564 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
527 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 570 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
528 571
529 btfss FLAG_apnoe_mode ; store apnoe max or normal max (which is only max from the last descent) 572 btfss FLAG_apnoe_mode ; store apnoe max or normal max (which is only max from the last descent)
530 bra end_dive1 ; store normal depth 573 bra end_dive1 ; store normal depth
531 574
532 movff apnoe_max_pressure+0,lo 575 ; apnoe max depth
533 movff apnoe_max_pressure+1,hi 576 MOVII apnoe_max_pressure,mpr
534 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] 577 call adjust_depth_with_salinity ; compute salinity setting into hi:lo [mbar]
535 movff lo,apnoe_max_pressure+0 578 MOVII mpr,apnoe_max_pressure
536 movff hi,apnoe_max_pressure+1 579 bra end_dive2 ; store max depth
537 580
538 movf lo,W ; max. depth, low byte 581 end_dive1:
582 ; normal max depth
583 MOVII pressure_rel_max_cached,mpr
584 call adjust_depth_with_salinity ; compute salinity setting into hi:lo [mbar]
585 MOVII mpr,pressure_rel_max_cached
586
587 end_dive2:
588 ; store max depth (common part)
589 movf lo,W ; max. depth, low byte
539 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 590 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
540 movf hi,W ; max. depth, high byte 591 movf hi,W ; max. depth, high byte
541 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 592 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
542 bra end_dive2 ; skip normal max. depth 593
543 594 ; store dive time
544 end_dive1: 595 SMOVTT counted_divetime_mins,mpr ; ISR-safe 3 byte copy of minutes:2 and seconds
545 movff max_pressure+0,lo 596 movf mpr+0,W ; dive time minutes, low byte
546 movff max_pressure+1,hi 597 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
547 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] 598 movf mpr+1,W ; dive time minutes, high byte
548 movff lo,max_pressure+0 599 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
549 movff hi,max_pressure+1 600 movf mpr+2,W ; dive time seconds
550 601 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
551 movf lo,W ; max. depth, low byte 602
552 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 603 ; store minimum temperature
553 movf hi,W ; max. depth, high byte 604 movff temperature_min+0,WREG ; minimum temperature, low byte
554 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 605 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
555 606 movff temperature_min+1,WREG ; minimum temperature, high byte
556 end_dive2: 607 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
557 movf divemins+0,W ; dive time minutes 608
558 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 609 ; store surface pressure (as used by deco engine)
559 movf divemins+1,W 610 movff int_I_pres_surface+0,WREG ; surface pressure, low byte
560 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 611 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
561 movf divesecs,W ; dive time seconds 612 movff int_I_pres_surface+1,WREG ; surface pressure, high byte
562 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 613 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
563 movff minimum_temperature+0,WREG ; minimum temperature 614
564 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 615 ; store desaturation time
565 movff minimum_temperature+1,WREG 616 movff int_O_desaturation_time+0,WREG ; desaturation time in minutes, low byte
566 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 617 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
567 movff last_surfpressure_30min+0,WREG ; air pressure before dive 618 movff int_O_desaturation_time+1,WREG ; desaturation time in minutes, high byte
568 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 619 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
569 movff last_surfpressure_30min+1,WREG 620
570 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 621 IFDEF _ccr_pscr
571 movff int_O_desaturation_time+0,WREG ; desaturation time in minutes
572 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
573 movff int_O_desaturation_time+1,WREG
574 rcall ghostwrite_byte_header ; WREG -> header in ext. flash
575
576 btfsc FLAG_ccr_mode ; in CCR mode? 622 btfsc FLAG_ccr_mode ; in CCR mode?
577 bra end_dive_dil_gaslist ; YES - write diluent gas list 623 bra end_dive_dil_gaslist ; YES - write diluent gas list
578 btfsc FLAG_pscr_mode ; in pSCR mode? 624 btfsc FLAG_pscr_mode ; in pSCR mode?
579 bra end_dive_dil_gaslist ; YES - write diluent gas list 625 bra end_dive_dil_gaslist ; YES - write diluent gas list
626 ENDIF
580 627
581 end_dive_oc_gaslist: ; write OC gases 628 end_dive_oc_gaslist: ; write OC gases
582 lfsr FSR0,opt_gas_O2_ratio-.1 ; set base address to (opt_gas_O2_ratio - 1) because of pre-increment statement 629 lfsr FSR0,opt_gas_O2_ratio-.1 ; set base address to (opt_gas_O2_ratio - 1) because of pre-increment statement
583 bra end_dive_gaslist ; write all 5 OC gases 630 bra end_dive_gaslist ; write all 5 OC gases
584 631
632 IFDEF _ccr_pscr
585 end_dive_dil_gaslist: ; write diluents 633 end_dive_dil_gaslist: ; write diluents
586 lfsr FSR0,opt_dil_O2_ratio-.1 ; set base address to (opt_dil_O2_ratio - 1) because of pre-increment statement 634 lfsr FSR0,opt_dil_O2_ratio-.1 ; set base address to (opt_dil_O2_ratio - 1) because of pre-increment statement
587 ;bra end_dive_gaslist ; write all 5 diluents 635 ;bra end_dive_gaslist ; write all 5 diluents
636 ENDIF
588 637
589 end_dive_gaslist: ; helper function for writing gas list entries 638 end_dive_gaslist: ; helper function for writing gas list entries
590 ; 639 ;
591 ; Memory Map: 640 ; Memory Map:
592 ; ------------------------- 641 ; -------------------------
616 decfsz lo ; decrement counter, did it became 0 ? 665 decfsz lo ; decrement counter, did it became 0 ?
617 bra end_dive_gaslist_loop ; NO - loop 666 bra end_dive_gaslist_loop ; NO - loop
618 ;bra end_dive_oc_cc_common ; YES - done 667 ;bra end_dive_oc_cc_common ; YES - done
619 668
620 end_dive_oc_cc_common: 669 end_dive_oc_cc_common:
621 movlw softwareversion_x ; firmware version 670 movlw softwareversion_x ; get firmware version X (major)
622 rcall ghostwrite_byte_header 671 rcall ghostwrite_byte_header ; store data
623 movlw softwareversion_y 672 movlw softwareversion_y ; get firmware version Y (minor)
624 rcall ghostwrite_byte_header 673 rcall ghostwrite_byte_header ; store data
625 movf batt_voltage+0,W ; battery voltage 674
626 rcall ghostwrite_byte_header 675 ; store battery voltage
627 movf batt_voltage+1,W 676 movf batt_voltage+0,W ; get battery voltage, low byte
628 rcall ghostwrite_byte_header 677 rcall ghostwrite_byte_header ; store data
629 678 movf batt_voltage+1,W ; get battery voltage, high byte
630 movf samplingrate,W ; Sampling rate 679 rcall ghostwrite_byte_header ; store data
631 btfsc FLAG_apnoe_mode ; Apnoe mode? 680
632 movlw samplingrate_apnoe ; Apnoe sampling rate 681 ; store sampling rate
633 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 682 movf sampling_rate,W ; get sampling rate
634 683 rcall ghostwrite_byte_header ; store data
635 ; CNS at beginning of dive 684
636 movff CNS_start+0,WREG 685 ; store CNS at beginning of dive
637 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 686 movf CNS_start+0,W ; get CNS at start of dive, low byte
638 movff CNS_start+1,WREG 687 rcall ghostwrite_byte_header ; store data
639 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 688 movf CNS_start+1,W ; get CNS at start of dive, high byte
640 ; Gradient factor 689 rcall ghostwrite_byte_header ; store data
641 movff GF_start,WREG 690
642 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 691 ; store gradient factors
643 movff int_O_gradient_factor+0,WREG ; value limited to 255, only lower byte in use 692 movff supersat_start,WREG ; get supersaturation at start of dive
644 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 693 rcall ghostwrite_byte_header ; store data
645 694 movff int_O_lead_supersat+0,WREG ; get supersaturation at end of dive
646 ; Logbook offset 695 rcall ghostwrite_byte_header ; store data
647 call do_logoffset_common_read ; Read into lo:hi 696
648 movf lo,W 697 ; store logbook offset
649 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 698 call do_logoffset_common_read ; read into mpr:2
650 movf hi,W 699 movf mpr+0,W
651 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 700 rcall ghostwrite_byte_header ; store data
652 701 movf mpr+1,W
653 ; Battery info at Byte 59 702 rcall ghostwrite_byte_header ; store data
654 movf batt_percent,W ; 0-100 703
655 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 704 ; store battery info at Byte 59
656 705 movf batt_percent,W ; 0-100%
657 ; Store the setpoints 706 rcall ghostwrite_byte_header ; store data
658 lfsr FSR0,char_I_setpoint_cbar ; base address of ppO2 values 707
659 lfsr FSR1,char_I_setpoint_change ; base address of change depths 708 ; store setpoints
660 movlw .5 ; 5 setpoints to store 709 IFDEF _ccr_pscr
710 lfsr FSR0,opt_setpoint_cbar ; base address of ppO2 values
711 lfsr FSR1,opt_setpoint_change ; base address of change depths
712 ENDIF
713 movlw .5 ; 5 setpoints to be stored
661 movwf lo ; use lo as counter 714 movwf lo ; use lo as counter
662 end_dive_sp_loop: 715 end_dive_sp_loop:
663 movf POSTINC0,W ; get ppO2 value 716 IFDEF _ccr_pscr
664 rcall ghostwrite_byte_header ; store ppO2 value 717 movf POSTINC0,W ; get ppO2 value
665 movf POSTINC1,W ; get change depth 718 ELSE
666 rcall ghostwrite_byte_header ; store change depth 719 clrf WREG
720 ENDIF
721 rcall ghostwrite_byte_header ; store data
722 IFDEF _ccr_pscr
723 movf POSTINC1,W ; get change depth
724 ELSE
725 clrf WREG
726 ENDIF
727 rcall ghostwrite_byte_header ; store data
667 decfsz lo ; decrement counter, did it became 0 ? 728 decfsz lo ; decrement counter, did it became 0 ?
668 bra end_dive_sp_loop ; NO - loop 729 bra end_dive_sp_loop ; NO - loop
669 730
670 ; Store further data 731 ; store salinity
671 movff opt_salinity,WREG ; salinity (0-4%) 732 movff opt_salinity,WREG ; get salinity (0-4%)
672 rcall ghostwrite_byte_header ; store salinity 733 rcall ghostwrite_byte_header ; store data
673 734
674 movff int_O_CNS_fraction+0,WREG ; CNS value, low byte 735 ; store CNS at end of dive
675 rcall ghostwrite_byte_header ; store CNS% 736 movff int_O_CNS_current+0,WREG ; get current CNS, low byte
676 movff int_O_CNS_fraction+1,WREG ; CNS value, high byte 737 rcall ghostwrite_byte_header ; store data
738 movff int_O_CNS_current+1,WREG ; get current CNS, high byte
677 bcf WREG,int_warning_flag ; clear warning flag 739 bcf WREG,int_warning_flag ; clear warning flag
678 bcf WREG,int_attention_flag ; clear attention flag 740 bcf WREG,int_attention_flag ; clear attention flag
679 rcall ghostwrite_byte_header ; store CNS% 741 rcall ghostwrite_byte_header ; store data
680 742
681 movff avg_rel_pressure_total+0,WREG ; average depth 743 ; store average depth
682 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 744 movff pressure_rel_avg_total+0,WREG ; get total dive average depth, low byte
683 movff avg_rel_pressure_total+1,WREG ; average depth 745 rcall ghostwrite_byte_header ; store data
684 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 746 movff pressure_rel_avg_total+1,WREG ; get total dive average depth, high byte
685 747 rcall ghostwrite_byte_header ; store data
686 movff total_divetime_seconds+0,WREG ; total dive time (regardless of start_dive_threshold) 748
687 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 749 ; store total dive time
688 movff total_divetime_seconds+1,WREG ; total dive time (regardless of start_dive_threshold) 750 SMOVII total_divetime_secs,mpr ; ISR-safe 2 byte copy of the total dive time
689 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 751 movff mpr+0,WREG ; total dive time, low byte
690 752 rcall ghostwrite_byte_header ; store data
691 movff char_I_GF_Low_percentage,WREG ; GF_lo 753 movff mpr+1,WREG ; total dive time, high byte
754 rcall ghostwrite_byte_header ; store data
755
756 ; store GF low or saturation multiplier
757 movff char_I_GF_Low_percentage,WREG ; get GF_lo
758 movff char_I_deco_model,lo
759 decfsz lo,F ; skip next line if char_I_deco_model == 1
760 movff char_I_saturation_multiplier,WREG ; get saturation multiplier
761 rcall ghostwrite_byte_header ; store data
762
763 ; store GF high or desaturation multiplier
764 movff char_I_GF_High_percentage,WREG ; get GF_hi
692 movff char_I_deco_model,lo 765 movff char_I_deco_model,lo
693 decfsz lo,F ; jump over next line if char_I_deco_model == 1 766 decfsz lo,F ; jump over next line if char_I_deco_model == 1
694 movff char_I_saturation_multiplier,WREG ; saturation multiplier 767 movff char_I_desaturation_multiplier,WREG ; get desaturation multiplier
695 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 768 rcall ghostwrite_byte_header ; store data
696 769
697 movff char_I_GF_High_percentage,WREG ; GF_hi 770 ; store deco model
698 movff char_I_deco_model,lo 771 movff char_I_deco_model,WREG ; get deco model (0 = ZH-L16, 1 = ZH-L16-GF)
699 decfsz lo,F ; jump over next line if char_I_deco_model == 1 772 rcall ghostwrite_byte_header ; store data
700 movff char_I_desaturation_multiplier,WREG ; desaturation multiplier 773
701 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 774 ; store total dive number
702 775 read_int_eeprom .2 ; get total dive counter, low
703 movff char_I_deco_model,WREG ; 0 = ZH-L16, 1 = ZH-L16-GF 776 movf EEDATA,W ; ...
704 rcall ghostwrite_byte_header ; writes byte and increases address (no banking) 777 rcall ghostwrite_byte_header ; store data
705 778 read_int_eeprom .3 ; get total dive counter, high
706 read_int_eeprom .2 779 movf EEDATA,W ; ...
707 movf EEDATA,W 780 rcall ghostwrite_byte_header ; store data
708 rcall ghostwrite_byte_header ; total dive counter, low 781
709 read_int_eeprom .3 782 ; store deco mode
710 movf EEDATA,W 783 movff opt_dive_mode,WREG ; get deco mode (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR)
711 rcall ghostwrite_byte_header ; total dive counter, high 784 rcall ghostwrite_byte_header ; store data
712 785
713 movff opt_dive_mode,WREG 786 ; store tissue data - N2 chars
714 rcall ghostwrite_byte_header ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR
715
716 ; Store all tissue data available
717 movlw .16 787 movlw .16
718 movwf lo 788 movwf lo
719 lfsr FSR1,char_O_tissue_N2_saturation+0 789 lfsr FSR1,char_O_tissue_pres_N2
720 end_dive_store_tissues_N2: 790 end_dive_store_tissues_N2:
721 movf POSTINC1,W 791 movf POSTINC1,W
722 bcf WREG,7 ; clear flag bit for ongassing/offgassing 792 bcf WREG,7 ; clear flag bit for on-gassing/off-gassing
723 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 793 rcall ghostwrite_byte_header ; store data
724 decfsz lo,F 794 decfsz lo,F
725 bra end_dive_store_tissues_N2 ; NO 795 bra end_dive_store_tissues_N2 ; NO
726 796
797 ; store tissue data - N2 floats
727 movlw .64 798 movlw .64
728 movwf lo 799 movwf lo
729 lfsr FSR1,0x700 ; pres_tissue_N2+0 ; 16*4 Byte Float = 64 Bytes 800 lfsr FSR1,0x700 ; pres_tissue_N2+0 ; 16*4 Byte Float = 64 Bytes
730 end_dive_store_tissues_N2_2: 801 end_dive_store_tissues_N2_2:
731 movf POSTINC1,W 802 movf POSTINC1,W
732 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 803 rcall ghostwrite_byte_header ; store data
733 decfsz lo,F 804 decfsz lo,F
734 bra end_dive_store_tissues_N2_2 ; NO 805 bra end_dive_store_tissues_N2_2 ; NO
735 806
807 ; store tissue data - He chars
736 movlw .16 808 movlw .16
737 movwf lo 809 movwf lo
738 lfsr FSR1,char_O_tissue_He_saturation+0 810 lfsr FSR1,char_O_tissue_pres_He
739 end_dive_store_tissues_He: 811 end_dive_store_tissues_He:
740 movf POSTINC1,W 812 movf POSTINC1,W
741 bcf WREG,7 ; clear flag bit for ongassing/offgassing 813 bcf WREG,7 ; clear flag bit for on-gassing/off-gassing
742 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 814 rcall ghostwrite_byte_header ; store data
743 decfsz lo,F 815 decfsz lo,F
744 bra end_dive_store_tissues_He ; NO 816 bra end_dive_store_tissues_He ; NO
745 817
818 ; store tissue data - He floats
746 movlw .64 819 movlw .64
747 movwf lo 820 movwf lo
748 lfsr FSR1,0x740 ; pres_tissue_He+0 ; 16*4 Byte Float = 64 Bytes 821 lfsr FSR1,0x740 ; pres_tissue_He+0 ; 16*4 Byte Float = 64 Bytes
749 end_dive_store_tissues_He_2: 822 end_dive_store_tissues_He_2:
750 movf POSTINC1,W 823 movf POSTINC1,W
751 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 824 rcall ghostwrite_byte_header ; store data
752 decfsz lo,F 825 decfsz lo,F
753 bra end_dive_store_tissues_He_2 ; NO 826 bra end_dive_store_tissues_He_2 ; NO
754 827
755 ; Some deco stuff 828 ; store last stop depth
756 movff char_I_depth_last_deco,WREG ; last stop [m] 829 movff char_I_depth_last_deco,WREG ; get last stop depth [m]
757 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 830 rcall ghostwrite_byte_header ; store data
758 movff char_I_deco_distance,WREG ; assumed distance to shown stop 831
759 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 832 ; store deco distance
760 833 movff char_I_deco_distance,WREG ; get assumed distance to shown stop
761 ; Last HUD data 834 rcall ghostwrite_byte_header ; store data
762 movff hud_battery_mv+0,WREG ; last HUD battery value 835
763 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 836 IFDEF _external_sensor
764 movff hud_battery_mv+1,WREG ; last HUD battery value 837 ; store last HUD data
765 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 838 SMOVTT hud_status_byte,mpr ; ISR-safe 3 byte copy of last HUD status (1 byte) and battery voltage (2 byte)
766 movff hud_status_byte,WREG ; last HUD status 839 movff mpr+1,WREG ; HUD battery value, low byte
767 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 840 rcall ghostwrite_byte_header ; store data
768 841 movff mpr+2,WREG ; HUD battery value, high byte
769 ; Battery gauge registers [nAs] 842 rcall ghostwrite_byte_header ; store data
770 lfsr FSR0,battery_gauge ; load base address of battery gauge register 843 movff mpr+0,WREG ; HUD status
771 movf POSTINC0,W ; get byte 0 844 rcall ghostwrite_byte_header ; store data
772 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 845 ELSE
773 movf POSTINC0,W ; get byte 1 846 ; store dummy data to keep format
774 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 847 clrf WREG
775 movf POSTINC0,W ; get byte 2 848 rcall ghostwrite_byte_header ; store null byte
776 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 849 clrf WREG
777 movf POSTINC0,W ; get byte 3 850 rcall ghostwrite_byte_header ; store null byte
778 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 851 clrf WREG
779 movf POSTINC0,W ; get byte 4 852 rcall ghostwrite_byte_header ; store null byte
780 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 853 ENDIF
781 movf POSTINC0,W ; get byte 5 854
782 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 855 ; store battery gauge registers [nAs]
783 856 SMOVSS battery_gauge,mpr ; ISR-safe 6 byte copy of battery gauge value
784 ; Header stop 857 movf mpr+0,W ; get byte 0
858 rcall ghostwrite_byte_header ; store data
859 movf mpr+1,W ; get byte 1
860 rcall ghostwrite_byte_header ; store data
861 movf mpr+2,W ; get byte 2
862 rcall ghostwrite_byte_header ; store data
863 movf mpr+3,W ; get byte 3
864 rcall ghostwrite_byte_header ; store data
865 movf mpr+4,W ; get byte 4
866 rcall ghostwrite_byte_header ; store data
867 movf mpr+5,W ; get byte 5
868 rcall ghostwrite_byte_header ; store data
869
870 ; write header stop code
785 movlw 0xFB 871 movlw 0xFB
786 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 872 rcall ghostwrite_byte_header ; store data
787 movlw 0xFB 873 movlw 0xFB
788 rcall ghostwrite_byte_header ; WREG -> header in ext. flash 874 rcall ghostwrite_byte_header ; store data
789 875
790 call divemode_store_statistics ; store/update statistics for this unit 876 call divemode_store_statistics ; store/update statistics for this unit
791 877 bsf reset_surface_interval ; request ISR to reset the surface interval timer
792 clrf surface_interval+0
793 clrf surface_interval+1 ; clear surface interval timer
794 878
795 ghostwriter_end_dive_common: 879 ghostwriter_end_dive_common:
796 ; Update ext_flash_log_pointer into EEPROM 880 ; Update ext_flash_log_pointer into EEPROM
797 clrf EEADRH 881 clrf EEADRH
798 movff ext_flash_log_pointer+0,EEDATA 882 movff ext_flash_log_pointer+0,EEDATA
800 movff ext_flash_log_pointer+1,EEDATA 884 movff ext_flash_log_pointer+1,EEDATA
801 write_int_eeprom .5 885 write_int_eeprom .5
802 movff ext_flash_log_pointer+2,EEDATA 886 movff ext_flash_log_pointer+2,EEDATA
803 write_int_eeprom .6 887 write_int_eeprom .6
804 888
805 bcf simulatormode_active ; if we were in simulator mode 889 ; In DEBUG compile, write simulated dives to logbook and keep tissue pressures from simulation
806 890 btfss simulatormode ; in simulator mode, i.e. need to restore tissue pressures?
807 ; In DEBUG compile, keep all simulated dives in logbook, Desat time, nofly, etc... 891 bra ghostwriter_end_dive_common_1 ; NO
808 ifndef __DEBUG 892 bcf simulatormode ; YES - clear mode flag
809 btfsc restore_deco_data ; restore decodata? 893 ifndef _DEBUG
810 call deco_pull_tissues_from_vault 894 call deco_pull_tissues_from_vault ; - restore tissue pressures (C-code)
811 banksel common ; bank 1 895 banksel common ; - back to bank common
812 endif 896 endif
897
898 ghostwriter_end_dive_common_1:
899 bsf reset_timebase ; request ISR to reset the timebase
900 ; btfsc reset_timebase ; has the ISR confirmed reset of timebase?
901 ; bra $-2 ; NO - not yet, loop waiting for the ISR
902 bcf sensor_override_request ; request ISR to terminate the simulator mode
903 btfsc sensor_override_active ; has the ISR confirmed termination of simulator mode?
904 bra $-2 ; NO - not yet, loop waiting for the ISR
813 call update_battery_registers ; update battery registers into EEPROM 905 call update_battery_registers ; update battery registers into EEPROM
814 goto surfloop ; and return to surface loop 906 movff simulator_time,char_I_dive_interval ; get the simulator runtime, reads 0 if exiting from a real dive
815 907 call deco_calc_dive_interval ; catch up with tissue desaturation when exiting from simulator,
816 908 ; else calculates for 2 seconds only when exiting from a real dive,
817 ghostwriter_end_dive_common_sim: 909 ; needed to update CNS, GF and tissue graphics for surface display (C-code)
818 tstfsz surface_interval+0 ; was interval zero? 910 call deco_calc_desaturation_time ; calculate desaturation and no-fly/no-altitude time after catch-up (C-code)
819 bra ghostwriter_end_dive_common_sim2 ; NO 911 banksel common ; back to bank common
820 tstfsz surface_interval+1 ; was interval zero? 912
821 bra ghostwriter_end_dive_common_sim2 ; NO 913 ; the last surface pressure sample may have been taken while being submerged a bit already,
822 bra ghostwriter_end_dive_common ; YES - done 914 ; therefore it will be replaced by the sample taken one more before, which is the one that
823 ghostwriter_end_dive_common_sim2: 915 ; became the surface pressure reference used while this dive.
824 movf divemins+0,W 916 MOVII pressure_abs_ref,pressure_abs_sampled
825 addwf surface_interval+0,F 917
826 movf divemins+1,W 918 goto surfloop ; done with post-dive operations, return to surface loop
827 addwfc surface_interval+1 ; add simulated dive time to surface interval
828 bra ghostwriter_end_dive_common
829 919
830 920
831 ghostwriter_load_pointer: ; load ext_flash_address:3 from EEPROM .4-.6 921 ghostwriter_load_pointer: ; load ext_flash_address:3 from EEPROM .4-.6
832 clrf EEADRH ; make sure to select EEPROM bank 0 922 clrf EEADRH ; make sure to select EEPROM bank 0
833 read_int_eeprom .4 923 read_int_eeprom .4
856 movff ext_flash_address+1,EEDATA 946 movff ext_flash_address+1,EEDATA
857 write_int_eeprom .5 ; write new pointer 947 write_int_eeprom .5 ; write new pointer
858 movff ext_flash_address+2,EEDATA 948 movff ext_flash_address+2,EEDATA
859 write_int_eeprom .6 ; write new pointer 949 write_int_eeprom .6 ; write new pointer
860 bra ghostwriter_short_header2 ; Done 950 bra ghostwriter_short_header2 ; Done
951
861 952
862 global ghostwriter_short_header 953 global ghostwriter_short_header
863 ghostwriter_short_header: ; write short header with dive number into profile memory 954 ghostwriter_short_header: ; write short header with dive number into profile memory
864 ; load pointer for profile storing into RAM (Updated in EEPROM after the dive) 955 ; load pointer for profile storing into RAM (Updated in EEPROM after the dive)
865 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 956 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6
910 movlw 0xFF 1001 movlw 0xFF
911 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) 1002 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase)
912 movlw 0xFF 1003 movlw 0xFF
913 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) 1004 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase)
914 1005
915 movf samplingrate,W ; sampling rate 1006 movf sampling_rate,W ; get sampling rate
916 btfsc FLAG_apnoe_mode ; apnoe mode?
917 movlw samplingrate_apnoe ; apnoe sampling rate
918 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 1007 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
919 1008
920 movlw .7 ; number of divisors 1009 movlw .7 ; number of divisors
921 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash 1010 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash
922 1011
973 1062
974 return 1063 return
975 1064
976 divemode_store_statistics: ; store/update statistics for this unit 1065 divemode_store_statistics: ; store/update statistics for this unit
977 call vault_decodata_into_eeprom ; update deco data 1066 call vault_decodata_into_eeprom ; update deco data
978 call do_logoffset_common_read ; existing logbook offset into lo:hi 1067 call do_logoffset_common_read ; read current logbook offset into mpr
979 1068
980 tstfsz lo ; lo=0? 1069 tstfsz lo ; offset, low byte = 0 ?
981 bra change_logbook_offset1 ; NO - adjust offset 1070 bra change_logbook_offset1 ; NO - adjust offset
982 tstfsz hi ; hi=0? 1071 tstfsz hi ; offset, high byte = 0 ?
983 bra change_logbook_offset1 ; NO - adjust offset 1072 bra change_logbook_offset1 ; NO - adjust offset
984 bra change_logbook_offset2 ; lo=0 and hi=0 -> skip offset routine 1073 bra change_logbook_offset2 ; YES to both - skip offset routine
985 1074
986 change_logbook_offset1: 1075 change_logbook_offset1:
987 movlw d'1' 1076 INCI mpr ; increment offset
988 addwf lo 1077 call do_logoffset_common_write ; write incremented offset as the new offset
989 movlw d'0'
990 addwfc hi
991 call do_logoffset_common_write ; lo:hi -> EEPROM
992 1078
993 change_logbook_offset2: 1079 change_logbook_offset2:
994 ; Clear lastdive:4 1080 clrf mpr+0 ; prepare a 4 byte null value to clear the last dive time
995 banksel lastdive_time+0 1081 clrf mpr+1 ; ...
996 clrf lastdive_time+0 1082 clrf mpr+2 ; ...
997 clrf lastdive_time+1 1083 clrf mpr+3 ; ...
998 clrf lastdive_time+2 1084 SMOVFF mpr,lastdive_time ; ISR-safe 4 byte copy of null value to last dive time counter
999 clrf lastdive_time+3 1085
1000 movff divemins+0,lastdive_duration+0 1086
1001 movff divemins+1,lastdive_duration+1 1087 ; ISR-safe 3 byte copy of minutes:2 and seconds to last dive duration
1002 movff divesecs, lastdive_duration+2 1088 SMOVTT counted_divetime_mins,lastdive_duration
1003 movff max_pressure+0,lastdive_maxdepth+0 1089
1004 movff max_pressure+1,lastdive_maxdepth+1 1090 ; 2 byte copies of max and avg relative pressures to last dive data
1005 banksel common 1091 MOVII pressure_rel_max_cached,lastdive_maxdepth
1006 1092 MOVII pressure_rel_avg_total, lastdive_avgdepth
1007 ; Add more here... 1093
1008 return 1094 return
1009 1095
1010 END 1096 END