0
|
1 ;=============================================================================
|
|
2 ;
|
|
3 ; File simulator.asm
|
|
4 ;
|
|
5 ; Decoplan interface to C model code.
|
|
6 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
|
10 ; 2011-07-09 : [jDG] Creation...
|
|
11
|
|
12 #include "ostc3.inc" ; Mandatory include.
|
|
13 #include "convert.inc" ; output_*
|
|
14 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
|
|
15 #include "strings.inc" ; STRCPY,...
|
|
16 #include "tft.inc" ; WIN_LEFT,...
|
|
17 #include "wait.inc" ; speed_*
|
|
18 #include "start.inc"
|
|
19 #include "divemode.inc"
|
|
20 #include "math.inc"
|
|
21 #include "eeprom_rs232.inc"
|
50
|
22 #include "tft_outputs.inc"
|
0
|
23
|
|
24 gui CODE
|
|
25
|
|
26 extern deco_clear_tissue
|
|
27 extern deco_push_tissues_to_vault
|
|
28 extern deco_calc_dive_interval
|
|
29 extern deco_calc_hauptroutine
|
|
30 extern deco_calc_tissue
|
|
31 extern deco_calc_CNS_fraction
|
|
32 extern deco_calc_CNS_planning
|
|
33 extern deco_pull_tissues_from_vault
|
|
34
|
|
35 extern log_screendump_and_onesecond, logbook_preloop_tasks
|
|
36
|
|
37 ;---- Private temp variables -------------------------------------------------
|
|
38 CBLOCK tmp+0x10 ; Reserved space for wordprocessor and convert
|
|
39 decoplan_index ; within each page
|
|
40 decoplan_gindex ; global index
|
|
41 decoplan_last ; Depth of last stop (CF#29)
|
|
42 decoplan_flags ; Various private flags.
|
|
43 decoplan_CNS:2 ; Backup CNS before vault restore
|
|
44 ; Reserved to tmp+0x1F...
|
|
45 ENDC
|
|
46 #define decoplan_last_ceiling_shown decoplan_flags,0
|
|
47
|
|
48 ;---- Demo decoplanner -------------------------------------------------------
|
|
49 global do_demo_planner
|
|
50 extern do_planner_menu
|
|
51
|
|
52 do_demo_planner:
|
|
53 call speed_fastest
|
|
54 ; call deco_reset ; TODO: remove reset all Decodata
|
|
55 call deco_planer
|
|
56 call deco_show_plan
|
|
57 bcf switch_right
|
|
58 bcf switch_left
|
|
59 goto do_planner_menu
|
|
60
|
|
61 ;=============================================================================
|
|
62 ; Pass all parameters to the C code
|
|
63 ;
|
|
64
|
|
65 global get_first_dil_to_WREG
|
|
66 get_first_dil_to_WREG: ; Gets first dil (0-4) into WREG
|
|
67 lfsr FSR1,opt_dil_type ; Point to dil types
|
|
68 clrf lo ; start with Gas0
|
81
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
69 get_first_dil_to_WREG2:
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
70 movf lo,W ;
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
71 movf PLUSW1,W ; Get Type of Dil #lo
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
72 sublw .1 ; it is = 1 (First Dil)
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
73 bz get_first_dil_to_WREG3 ; Found the first dil!
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
74 incf lo,F ; ++
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
75 movlw NUM_GAS+1
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
76 cpfseq lo ; All done?
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
77 bra get_first_dil_to_WREG2 ; Not yet
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
78 ; No first dil found, use #1
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
79 movlw .1
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
80 movff WREG,opt_dil_type+0 ; Set Dil1 to First
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
81 return
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
82 get_first_dil_to_WREG3:
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
83 movf lo,W ; Put into Wreg
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
84 return ; Done
|
0
|
85
|
|
86 global get_first_gas_to_WREG
|
|
87 get_first_gas_to_WREG: ; Gets first gas (0-4) into WREG
|
|
88 lfsr FSR1,opt_gas_type ; Point to gas types
|
|
89 clrf lo ; start with Gas0
|
|
90 get_first_gas_to_WREG2:
|
|
91 movf lo,W ;
|
|
92 movf PLUSW1,W ; Get Type of Gas #lo
|
|
93 sublw .1 ; it is = 1 (First Gas)
|
|
94 bz get_first_gas_to_WREG3 ; Found the first gas!
|
|
95 incf lo,F ; ++
|
|
96 movlw NUM_GAS+1
|
|
97 cpfseq lo ; All done?
|
|
98 bra get_first_gas_to_WREG2 ; Not yet
|
81
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
99 ; No first gas found, use #1
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
100 movlw .1
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
101 movff WREG,opt_gas_type+0 ; Set Gas1 to First
|
8e13866b5496
add some extra safety checks when settings were altered from the PC software
mh@mh-THINK.localdomain
diff
changeset
|
102 return
|
0
|
103 get_first_gas_to_WREG3:
|
|
104 movf lo,W ; Put into Wreg
|
|
105 return ; Done
|
|
106
|
|
107 deco_setup:
|
|
108 banksel char_I_step_is_1min ; Select the right bank...
|
|
109 clrf char_I_step_is_1min ; Default to 2sec steps.
|
46
|
110 clrf char_I_const_ppO2 ; Clear for OC, will be set for CC later
|
0
|
111
|
|
112 ; Fixed ambient surface pressure to 1bar.
|
|
113 movlw LOW(.1000)
|
|
114 movwf int_I_pres_surface+0
|
|
115 movwf int_I_pres_respiration+0
|
|
116 movlw HIGH(.1000)
|
|
117 movwf int_I_pres_surface+1
|
|
118 movwf int_I_pres_respiration+1
|
|
119
|
46
|
120 clrf int_I_divemins+0 ; Dive start
|
0
|
121 clrf int_I_divemins+1
|
46
|
122 banksel common ; Bank1
|
|
123 bcf use_agf ; =1: Use aGF
|
|
124
|
40
|
125 rcall deco_setup_dive
|
0
|
126
|
46
|
127 ; Setup char_I_const_ppO2 for CC modes
|
|
128 btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
|
40
|
129 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; Setup fixed Setpoint (Always start with SP1)
|
|
130
|
|
131 rcall get_first_gas_to_WREG ; Gets first gas (0-4) into WREG
|
0
|
132 movff WREG,char_I_first_gas ; Copy for compatibility
|
197
|
133 banksel char_I_first_gas
|
|
134 incf char_I_first_gas,F ; 0-4 -> 1-5
|
|
135 banksel common
|
0
|
136 extern setup_gas_registers
|
|
137 call setup_gas_registers ; With WREG=Gas 0-4, set current N2/He/O2 ratios.
|
|
138 extern set_actual_ppo2
|
|
139 call set_actual_ppo2 ; Then configure char_I_actual_ppO2 (For CNS)
|
40
|
140 return
|
0
|
141
|
|
142 global deco_setup_dive
|
|
143 deco_setup_dive: ; Called from divemode
|
|
144 banksel common ; Bank1
|
|
145
|
97
|
146 btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
|
|
147 rcall deco_setup_cc_diluents ; Setup CC Diluents
|
0
|
148 btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
|
|
149 rcall deco_setup_oc_gases ; Setup OC Gases
|
|
150 btfsc is_bailout ; =1: Bailout
|
|
151 rcall deco_setup_oc_gases ; Setup OC/Bailout Gases
|
|
152
|
178
|
153 movff divemins+0,int_I_divemins+0 ; Current dive time.
|
|
154 movff divemins+1,int_I_divemins+1
|
|
155
|
0
|
156 movlw deco_distance
|
|
157 movff WREG,char_I_deco_distance
|
|
158 movff opt_last_stop,char_I_depth_last_deco
|
|
159 movff opt_GF_low,char_I_GF_Low_percentage
|
|
160 movff opt_GF_high,char_I_GF_High_percentage
|
|
161 ;Overwrite GF if aGF is wanted
|
|
162 btfsc use_agf ; =1: Use aGF
|
|
163 movff opt_aGF_low,char_I_GF_Low_percentage
|
|
164 btfsc use_agf ; =1: Use aGF
|
|
165 movff opt_aGF_high,char_I_GF_High_percentage
|
|
166 return
|
|
167
|
|
168 deco_setup_cc_diluents:
|
|
169 movff opt_dil_He_ratio+0,char_I_deco_He_ratio+0
|
|
170 movff char_I_deco_He_ratio+0,lo
|
|
171 movff opt_dil_O2_ratio+0,WREG
|
|
172 addwf lo,W ; O2 + He -> WREG
|
|
173 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
174 movff WREG,char_I_deco_N2_ratio+0
|
|
175 movff opt_dil_type+0,WREG ; 0=Disabled, 1=First, 2=Normal
|
|
176 tstfsz WREG ; Disabled?
|
|
177 bra $+4 ; No
|
97
|
178 movff WREG,char_I_dil_change+0 ; Yes, clear char_I_deco_gas_change
|
0
|
179
|
|
180 movff opt_dil_He_ratio+1,char_I_deco_He_ratio+1
|
|
181 movff char_I_deco_He_ratio+1,lo
|
|
182 movff opt_dil_O2_ratio+1,WREG
|
|
183 addwf lo,W ; O2 + He -> WREG
|
|
184 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
185 movff WREG,char_I_deco_N2_ratio+1
|
|
186 movff opt_dil_type+1,WREG ; 0=Disabled, 1=First, 2=Normal
|
|
187 tstfsz WREG ; Disabled?
|
|
188 bra $+4 ; No
|
97
|
189 movff WREG,char_I_dil_change+1 ; Yes, clear char_I_dil_change
|
0
|
190
|
|
191 movff opt_dil_He_ratio+2,char_I_deco_He_ratio+2
|
|
192 movff char_I_deco_He_ratio+2,lo
|
|
193 movff opt_dil_O2_ratio+2,WREG
|
|
194 addwf lo,W ; O2 + He -> WREG
|
|
195 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
196 movff WREG,char_I_deco_N2_ratio+2
|
|
197 movff opt_dil_type+2,WREG ; 0=Disabled, 1=First, 2=Normal
|
|
198 tstfsz WREG ; Disabled?
|
|
199 bra $+4 ; No
|
97
|
200 movff WREG,char_I_dil_change+2 ; Yes, clear char_I_dil_change
|
0
|
201
|
|
202 movff opt_dil_He_ratio+3,char_I_deco_He_ratio+3
|
|
203 movff char_I_deco_He_ratio+3,lo
|
|
204 movff opt_dil_O2_ratio+3,WREG
|
|
205 addwf lo,W ; O2 + He -> WREG
|
|
206 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
207 movff WREG,char_I_deco_N2_ratio+3
|
|
208 movff opt_dil_type+3,WREG ; 0=Disabled, 1=First, 2=Normal
|
|
209 tstfsz WREG ; Disabled?
|
|
210 bra $+4 ; No
|
97
|
211 movff WREG,char_I_dil_change+3 ; Yes, clear char_I_dil_change
|
0
|
212
|
|
213 movff opt_dil_He_ratio+4,char_I_deco_He_ratio+4
|
|
214 movff char_I_deco_He_ratio+4,lo
|
|
215 movff opt_dil_O2_ratio+4,WREG
|
|
216 addwf lo,W ; O2 + He -> WREG
|
|
217 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
218 movff WREG,char_I_deco_N2_ratio+4
|
|
219 movff opt_dil_type+4,WREG ; 0=Disabled, 1=First, 2=Normal
|
|
220 tstfsz WREG ; Disabled?
|
|
221 bra $+4 ; No
|
97
|
222 movff WREG,char_I_dil_change+4 ; Yes, clear char_I_dil_change
|
|
223
|
|
224 ; Setup char_I_deco_gas_change array
|
|
225 movff char_I_dil_change+0, char_I_deco_gas_change+0
|
|
226 movff char_I_dil_change+1, char_I_deco_gas_change+1
|
|
227 movff char_I_dil_change+2, char_I_deco_gas_change+2
|
|
228 movff char_I_dil_change+3, char_I_deco_gas_change+3
|
|
229 movff char_I_dil_change+4, char_I_deco_gas_change+4
|
0
|
230 return
|
|
231
|
|
232 deco_setup_oc_gases:
|
|
233 movff opt_gas_He_ratio+0,char_I_deco_He_ratio+0
|
|
234 movff char_I_deco_He_ratio+0,lo
|
|
235 movff opt_gas_O2_ratio+0,WREG
|
|
236 addwf lo,W ; O2 + He -> WREG
|
|
237 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
238 movff WREG,char_I_deco_N2_ratio+0
|
174
|
239 banksel opt_gas_type+0
|
|
240 movlw .3 ; 3=Deco
|
|
241 cpfseq opt_gas_type+0 ; Gas is deco type?
|
|
242 clrf opt_OC_bail_gas_change+0 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
|
|
243 banksel common
|
0
|
244
|
|
245 movff opt_gas_He_ratio+1,char_I_deco_He_ratio+1
|
|
246 movff char_I_deco_He_ratio+1,lo
|
|
247 movff opt_gas_O2_ratio+1,WREG
|
|
248 addwf lo,W ; O2 + He -> WREG
|
|
249 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
250 movff WREG,char_I_deco_N2_ratio+1
|
174
|
251 banksel opt_gas_type+1
|
|
252 movlw .3 ; 3=Deco
|
|
253 cpfseq opt_gas_type+1 ; Gas is deco type?
|
|
254 clrf opt_OC_bail_gas_change+1 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
|
|
255 banksel common
|
0
|
256
|
|
257 movff opt_gas_He_ratio+2,char_I_deco_He_ratio+2
|
|
258 movff char_I_deco_He_ratio+2,lo
|
|
259 movff opt_gas_O2_ratio+2,WREG
|
|
260 addwf lo,W ; O2 + He -> WREG
|
|
261 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
262 movff WREG,char_I_deco_N2_ratio+2
|
174
|
263 banksel opt_gas_type+2
|
|
264 movlw .3 ; 3=Deco
|
|
265 cpfseq opt_gas_type+2 ; Gas is deco type?
|
|
266 clrf opt_OC_bail_gas_change+2 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
|
|
267 banksel common
|
0
|
268
|
|
269 movff opt_gas_He_ratio+3,char_I_deco_He_ratio+3
|
|
270 movff char_I_deco_He_ratio+3,lo
|
|
271 movff opt_gas_O2_ratio+3,WREG
|
|
272 addwf lo,W ; O2 + He -> WREG
|
|
273 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
274 movff WREG,char_I_deco_N2_ratio+3
|
174
|
275 banksel opt_gas_type+3
|
|
276 movlw .3 ; 3=Deco
|
|
277 cpfseq opt_gas_type+3 ; Gas is deco type?
|
|
278 clrf opt_OC_bail_gas_change+3 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
|
|
279 banksel common
|
0
|
280
|
|
281 movff opt_gas_He_ratio+4,char_I_deco_He_ratio+4
|
|
282 movff char_I_deco_He_ratio+4,lo
|
|
283 movff opt_gas_O2_ratio+4,WREG
|
|
284 addwf lo,W ; O2 + He -> WREG
|
|
285 sublw .100 ; 100 - (O2 + He) -> WREG
|
|
286 movff WREG,char_I_deco_N2_ratio+4
|
174
|
287 banksel opt_gas_type+4
|
|
288 movlw .3 ; 3=Deco
|
|
289 cpfseq opt_gas_type+4 ; Gas is deco type?
|
|
290 clrf opt_OC_bail_gas_change+4 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
|
|
291 banksel common
|
94
|
292
|
|
293 movlw .0
|
|
294 movff WREG,char_I_const_ppO2 ; Clear constant ppO2 for OC/bailout
|
97
|
295
|
|
296 ; Setup char_I_deco_gas_change array
|
|
297 movff opt_OC_bail_gas_change+0, char_I_deco_gas_change+0
|
|
298 movff opt_OC_bail_gas_change+1, char_I_deco_gas_change+1
|
|
299 movff opt_OC_bail_gas_change+2, char_I_deco_gas_change+2
|
|
300 movff opt_OC_bail_gas_change+3, char_I_deco_gas_change+3
|
|
301 movff opt_OC_bail_gas_change+4, char_I_deco_gas_change+4
|
0
|
302 return
|
|
303
|
|
304 ;=============================================================================
|
|
305 ; Reset decompression tissues
|
|
306 ;
|
|
307 global deco_reset
|
|
308 deco_reset:
|
|
309 rcall deco_setup ; Setup all model parameters.
|
|
310 call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio
|
|
311 call deco_clear_CNS_fraction ; Reset CNS value.
|
|
312 banksel common ; Bank1
|
|
313 return
|
|
314
|
|
315 ;=============================================================================
|
|
316 ; Launch decoplanning
|
|
317 ;
|
|
318 global deco_planer
|
|
319 deco_planer:
|
|
320 call speed_fastest ; Quick !
|
|
321 rcall deco_setup ; Setup all model parameters.
|
|
322 call deco_push_tissues_to_vault
|
|
323 banksel common ; Bank1
|
|
324
|
|
325 ;---- Specific settings ------------------------------------------------------
|
|
326
|
|
327 banksel char_O_deco_status ; Bank 2
|
|
328 movlw .3 ; Start in surface state.
|
|
329 movwf char_O_deco_status
|
|
330
|
|
331 banksel char_I_step_is_1min ; Bank 3
|
|
332 movlw 1
|
|
333 movwf char_I_step_is_1min ; Set 1min steps
|
|
334
|
|
335 ;---- Add delay at surface, if needed ----------------------------------------
|
|
336 tstfsz char_I_dive_interval
|
|
337 call deco_calc_dive_interval
|
|
338
|
|
339 ;---- Dive loop --------------------------------------------------------------
|
|
340
|
|
341 ; Compute dive ambiant conditions
|
|
342 banksel char_I_bottom_depth
|
|
343 movf char_I_bottom_depth,W
|
|
344 mullw .100
|
|
345 movlw LOW(.1000)
|
|
346 addwf PRODL,W
|
|
347 movwf int_I_pres_respiration+0
|
|
348 movlw HIGH(.1000)
|
|
349 addwfc PRODH,W
|
|
350 movwf int_I_pres_respiration+1
|
|
351
|
|
352 banksel int_I_divemins ; Bank 4
|
|
353 clrf int_I_divemins+0 ; Clear dive time
|
|
354 clrf int_I_divemins+1
|
|
355
|
|
356 clrf TMR5L
|
|
357 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H
|
|
358 call deco_calc_hauptroutine ; Reset + simulate first min.
|
|
359
|
|
360 deco_planer_loop:
|
|
361 banksel int_I_divemins ; Bank 3
|
|
362 incf int_I_divemins,F ; Done 1 min.
|
|
363 btg LEDg
|
|
364
|
|
365 movf char_I_bottom_time,W ; Finished ?
|
|
366 xorwf int_I_divemins,W
|
|
367 bz deco_planer_endloop ; YES
|
111
|
368
|
0
|
369 call deco_calc_tissue ; JUST calc tissue (faster).
|
|
370 call deco_calc_CNS_fraction ; Also calculate CNS (in 1min loop)
|
|
371 bra deco_planer_loop
|
|
372
|
|
373 deco_planer_endloop:
|
|
374 banksel char_I_step_is_1min
|
|
375 clrf char_I_step_is_1min ; Back to 2sec loops
|
|
376
|
|
377 ;---- Wait until status reach zero -------------------------------------------
|
|
378 deco_planer_finishing:
|
|
379 btg LEDg
|
|
380 clrf TMR5L
|
|
381 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H
|
|
382 call deco_calc_hauptroutine ; Simulate 2sec more
|
|
383
|
|
384 banksel char_O_deco_status ; Bank 2
|
|
385 movf char_O_deco_status,W
|
|
386 bz deco_planer_finished
|
|
387
|
|
388 bra deco_planer_finishing
|
|
389
|
|
390 deco_planer_finished:
|
|
391 call deco_calc_CNS_planning
|
|
392 movff int_O_CNS_fraction+0,decoplan_CNS+0
|
|
393 movff int_O_CNS_fraction+1,decoplan_CNS+1
|
|
394 call deco_pull_tissues_from_vault
|
|
395 bcf LEDg
|
|
396 banksel common ; Bank1
|
|
397 movlw b'00111000' ; 1:8 Prescaler -> 65,536ms@16MHz
|
|
398 movwf T3CON
|
|
399 call speed_normal
|
|
400 return
|
|
401
|
|
402 ;-----------------------------------------------------------------------------
|
|
403 ; Draw a stop of the deco plan (simulator or dive).
|
|
404 ; Inputs: lo = depth. Range 3m...93m
|
|
405 ; + 80 if this is a switch-gas stop.
|
|
406 ; up = minutes. range 1'..240'.
|
|
407 ; win_top = line to draw on screen.
|
|
408 ; Trashed: up, lo, win_height, win_leftx2, win_width, win_color*,
|
|
409 ; WREG, PROD, TBLPTR TABLAT.
|
|
410 ;
|
|
411 deco_plan_show_stop:
|
|
412 ;---- Print depth ----------------------------------------------------
|
|
413 btfss lo,7 ; Bit set ?
|
|
414 bra deco_plan_show_std_stop ; No : Just an usual stop.
|
|
415
|
50
|
416 call TFT_attention_color
|
0
|
417 bcf lo,7 ; and cleanup depth.
|
|
418 bra deco_plan_show_nstd_stop
|
|
419
|
|
420 deco_plan_show_std_stop:
|
50
|
421 call TFT_standard_color
|
0
|
422
|
|
423 deco_plan_show_nstd_stop:
|
|
424 lfsr FSR2,buffer
|
|
425
|
|
426 TSTOSS opt_units ; 0=Meters, 1=Feets
|
|
427 bra deco_plan_show_nstd_stop_metric
|
|
428
|
|
429 WIN_LEFT .85
|
|
430 movf lo,W ; lo = m
|
|
431 mullw .100 ; PRODL:PRODH = mbar
|
|
432 movff PRODL,lo
|
|
433 movff PRODH,hi
|
|
434 ; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops...
|
|
435 movff lo,xA+0
|
|
436 movff hi,xA+1
|
|
437 movlw LOW d'334' ; 334feet/100m
|
|
438 movwf xB+0
|
|
439 movlw HIGH d'334'
|
|
440 movwf xB+1
|
|
441 call mult16x16 ; xA*xB=xC (lo:hi * 328)
|
|
442 movlw d'50' ; round up
|
|
443 addwf xC+0,F
|
|
444 movlw 0
|
|
445 addwfc xC+1,F
|
|
446 addwfc xC+2,F
|
|
447 addwfc xC+3,F
|
|
448 movlw d'100'
|
|
449 movwf xB+0
|
|
450 clrf xB+1
|
|
451 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
|
|
452 movff xC+0,lo
|
|
453 movff xC+1,hi ; restore lo and hi with updated value
|
|
454 bsf leftbind
|
|
455 bsf ignore_digit4 ; Only full feet
|
|
456 output_16
|
|
457 STRCAT_PRINT "ft "
|
|
458 bra deco_plan_show_nstd_stop_common
|
|
459
|
|
460 deco_plan_show_nstd_stop_metric:
|
|
461 WIN_LEFT .90
|
|
462 bsf leftbind
|
|
463 output_8 ; outputs into Postinc2!
|
|
464 STRCAT_PRINT "m "
|
|
465 deco_plan_show_nstd_stop_common:
|
|
466 ;---- Print duration -------------------------------------------------
|
|
467 WIN_LEFT .135
|
|
468 lfsr FSR2,buffer
|
|
469
|
|
470 movf lo,W ; Swap up & lo
|
|
471 movff up,lo
|
|
472 movwf up
|
|
473
|
|
474 output_8 ; Allow up to 240'
|
|
475 STRCAT_PRINT "' " ; 1 to 3 chars for depth.
|
|
476
|
|
477 movf lo,W ; Swap back up & lo
|
|
478 movff up,lo
|
|
479 movwf up
|
|
480
|
|
481 ;---------------------------------------------------------------------
|
|
482 ; Draw the bar graph used for deco stops (decoplan in simulator or dive).
|
|
483 incf win_top,F
|
|
484 movlw .19
|
|
485 movwf win_height
|
|
486 movlw .118
|
|
487 movwf win_leftx2 ; column left (0-159)
|
|
488 movlw .16
|
|
489 movwf win_width ; column max width.
|
|
490
|
|
491 ; Draw used area (up = minutes):
|
|
492 movlw .16 ; Limit length (16min)
|
|
493 cpfslt up
|
|
494 movwf up
|
|
495 movff up,win_bargraph ; Active width, the rest is cleared.
|
|
496 call TFT_box
|
|
497
|
|
498 ; Restore win_top
|
50
|
499 call TFT_standard_color
|
0
|
500 decf win_top,F ; Restore win_top
|
|
501 return
|
|
502
|
|
503 ;-----------------------------------------------------------------------------
|
|
504 ; Clear unused area belw last stop
|
|
505 ; Inputs: win_top : last used area...
|
|
506 deco_plan_show_clear_bottom:
|
|
507 movf win_top,W ; Get back from bank0
|
|
508 btfsc divemode ; In dive mode ?
|
|
509 sublw .168 ; Yes: bottom row in divemode
|
|
510 btfss divemode ; In dive mode ?
|
|
511 sublw .240 ; No: bottom row in planning
|
|
512 movwf win_height
|
|
513
|
|
514 WIN_LEFT .85 ; Full divemenu width
|
|
515 movlw .160-.85+1
|
|
516 movwf win_width
|
|
517
|
|
518 clrf win_color1 ; Fill with black
|
|
519 clrf win_color2
|
|
520
|
|
521 goto TFT_box
|
|
522
|
|
523 ;-----------------------------------------------------------------------------
|
|
524 ; Display the decoplan (simulator or divemode).
|
|
525 ; Inputs: char_O_deco_table (array of stop times, in minutes)
|
|
526 ; decoplan_page = page number.
|
|
527 ;
|
|
528 deco_show_plan_page:
|
189
|
529 bcf win_invert ; Reset invert flag
|
0
|
530
|
|
531 ;---- Is there deco stops ? ------------------------------------------
|
|
532 movff char_O_first_deco_depth,WREG
|
|
533 iorwf WREG
|
|
534 bnz deco_plan_show_1
|
|
535
|
|
536 ;---- No Deco --------------------------------------------------------
|
50
|
537 call TFT_standard_color
|
0
|
538 TEXT_SMALL .80, .0, tNoDeco
|
|
539 bsf decoplan_last_ceiling_shown
|
|
540 return
|
|
541
|
|
542 deco_plan_show_1:
|
|
543 lfsr FSR0,char_O_deco_depth ; Initialize indexed addressing.
|
|
544 lfsr FSR1,char_O_deco_time
|
|
545
|
|
546 clrf decoplan_index ; Start with index = 0
|
|
547 clrf win_top ; and row = 0
|
|
548
|
|
549 ; Read stop parameters, indexed by decoplan_index and decoplan_page
|
|
550 movf decoplan_page,W ; decoplan_gindex = 6*decoplan_page + decoplan_index
|
148
|
551 mullw .8 ; 8 lines/page in decoplan
|
0
|
552 movf decoplan_index,W
|
|
553 addwf PRODL,W
|
|
554 movwf decoplan_gindex ; --> decoplan_gindex
|
|
555
|
|
556 bcf decoplan_last_ceiling_shown ; Not finished yet...
|
|
557
|
|
558 deco_plan_show_2:
|
|
559 btfsc decoplan_gindex,5 ; Reached table length (32) ?
|
|
560 bra deco_plan_show_99 ; YES: finished...
|
|
561
|
|
562 ; Read stop parameters, indexed by decoplan_index
|
|
563 movf decoplan_gindex,W ; index
|
|
564 movff PLUSW1,up ; char_O_deco_time [gindex] --> up
|
|
565 movff PLUSW0,lo ; char_O_deco_depth[gindex]
|
|
566 movf lo,W
|
|
567 bz deco_plan_show_99 ; depth == 0 : finished.
|
|
568
|
|
569 ; Display the stop line
|
|
570 rcall deco_plan_show_stop
|
|
571
|
|
572 ; Next
|
|
573 movlw .24
|
|
574 addwf win_top,F ; row: += 24
|
|
575 incf decoplan_index,F ; local index += 1
|
|
576 incf decoplan_gindex,F ; global index += 1
|
|
577
|
|
578 ; Max number of lines/page reached ?
|
148
|
579 movlw .8 ; 8 lines/page in decoplan
|
0
|
580 cpfseq decoplan_index
|
|
581 bra deco_plan_show_2 ; NO: loop
|
|
582
|
|
583 ; Check if next stop if end-of-list ?
|
|
584 movf decoplan_gindex,W
|
|
585 movf PLUSW0,W ; char_O_deco_depth[gindex]
|
|
586 bz deco_plan_show_99 ; End of list...
|
|
587
|
|
588 ; Display the message "more..."
|
|
589 rcall deco_plan_show_clear_bottom ; Clear from next line
|
|
590
|
50
|
591 call TFT_standard_color
|
0
|
592 TEXT_SMALL .85, .240-.25, tMore
|
|
593 return
|
|
594
|
|
595 deco_plan_show_99:
|
|
596 bsf decoplan_last_ceiling_shown ; Nothing more in table to display.
|
|
597 rcall deco_plan_show_clear_bottom ; Clear from next line
|
|
598 return
|
|
599
|
|
600 ;-----------------------------------------------------------------------------
|
|
601 ; Loop to show all pages of the decoplan (surfacemode)
|
|
602
|
|
603 global deco_show_plan
|
|
604 deco_show_plan:
|
|
605 clrf decoplan_page
|
|
606 call TFT_ClearScreen
|
|
607 WIN_COLOR color_greenish
|
|
608 TEXT_SMALL .1,.1, tDivePlan
|
50
|
609 call TFT_standard_color
|
0
|
610 WIN_LEFT .0
|
|
611
|
|
612 ;---- Display model
|
|
613 movff char_I_deco_model,WREG
|
|
614 iorwf WREG
|
|
615 bnz deco_show_plan_m1
|
|
616
|
|
617 ; Display ZH-L16 sat/desat model.
|
|
618 TEXT_SMALL .0,.40, tZHL16
|
|
619 WIN_TOP .65
|
|
620 lfsr FSR2,buffer
|
|
621 movff char_I_desaturation_multiplier,lo
|
|
622 bsf leftbind
|
|
623 output_8
|
|
624 STRCAT "%/"
|
|
625 movff char_I_saturation_multiplier,lo
|
|
626 output_8
|
|
627 STRCAT_PRINT "%"
|
|
628 bra deco_show_plan_m2
|
|
629
|
|
630 ; Display ZH-L16-GF low/high model.
|
|
631 deco_show_plan_m1:
|
|
632 TEXT_SMALL .0,.40, tZHL16GF
|
|
633 WIN_TOP .65
|
|
634 lfsr FSR2,buffer
|
|
635 movff char_I_GF_Low_percentage,lo
|
|
636 output_99x
|
|
637 STRCAT "%/"
|
|
638 movff char_I_GF_High_percentage,lo
|
|
639 output_99x
|
|
640 STRCAT_PRINT "%"
|
|
641 ;bra deco_show_plan_m2
|
|
642
|
40
|
643 deco_show_plan_m2:
|
|
644 ; Show deco mode
|
|
645 extern TFT_display_decotype_surface1
|
|
646 WIN_TOP .90
|
|
647 lfsr FSR2,buffer
|
|
648 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea
|
|
649 call TFT_display_decotype_surface1
|
0
|
650
|
|
651 ;---- Display TTS result
|
|
652 WIN_TOP .165
|
|
653 STRCPY_TEXT tTTS
|
|
654 STRCAT ": "
|
|
655
|
|
656 movff int_O_ascenttime+0,lo
|
|
657 movff int_O_ascenttime+1,hi
|
|
658 bsf leftbind
|
|
659 output_16
|
|
660 STRCAT_PRINT "'"
|
|
661
|
|
662 ;---- Display CNS result
|
|
663 WIN_TOP .190
|
|
664 STRCPY_TEXT tCNS
|
|
665 STRCAT ": "
|
|
666 movff int_O_CNS_fraction+0,lo
|
|
667 movff int_O_CNS_fraction+1,hi
|
|
668 output_16_3
|
|
669 STRCAT "%\x92" ; "->"
|
|
670 movff decoplan_CNS+0,lo
|
|
671 movff decoplan_CNS+1,hi
|
|
672 output_16_3
|
|
673 STRCAT_PRINT "%"
|
|
674
|
|
675 ;---- Loop through pages
|
|
676 deco_show_plan_1:
|
|
677 call speed_normal
|
|
678 rcall deco_show_plan_page
|
|
679 incf decoplan_page,F
|
|
680
|
|
681 call logbook_preloop_tasks
|
|
682 deco_show_plan_2:
|
|
683 btfsc switch_right
|
|
684 bra deco_show_plan_3
|
|
685 btfsc switch_left
|
|
686 bra deco_show_plan_4
|
|
687 call log_screendump_and_onesecond ; Check if we need to make a screenshot and check for new second
|
|
688 btfsc sleepmode ; Timeout?
|
9
|
689 goto restart
|
0
|
690 bra deco_show_plan_2
|
|
691
|
|
692 deco_show_plan_3:
|
|
693 btfss decoplan_last_ceiling_shown
|
|
694 bra deco_show_plan_1
|
|
695
|
|
696 deco_show_plan_4:
|
|
697 call speed_normal ; Display in fast mode.
|
|
698 return
|
|
699
|
|
700 ;=============================================================================
|
|
701 ;
|
|
702 global do_demo_divemode
|
|
703 do_demo_divemode:
|
|
704 extern option_save_all
|
|
705 call option_save_all ; Save all settings into EEPROM before starting simulation
|
|
706 call deco_push_tissues_to_vault
|
|
707 banksel common ; Bank1
|
|
708
|
|
709 bsf restore_deco_data ; Restore tissue and CNS after sim
|
|
710
|
|
711 bcf pressure_refresh
|
|
712 btfss pressure_refresh ; Wait for sensor
|
|
713 bra $-2
|
|
714
|
|
715 bsf simulatormode_active ; Set Flag
|
132
|
716 ; Compute dive ambient conditions
|
|
717 banksel char_I_bottom_depth
|
|
718 movf char_I_bottom_depth,W
|
|
719 mullw .100
|
|
720 movff PRODL,rel_pressure+0
|
|
721 movff PRODH,rel_pressure+1
|
|
722 movlw LOW(.1000)
|
|
723 addwf PRODL,W
|
|
724 movff WREG,sim_pressure+0
|
|
725 movlw HIGH(.1000)
|
|
726 addwfc PRODH,W
|
|
727 movff WREG,sim_pressure+1
|
0
|
728
|
136
|
729 banksel common ; Bank1
|
0
|
730 bsf divemode
|
|
731 goto diveloop ; Switch into Divemode!
|
|
732
|
|
733
|
|
734 END |