Mercurial > public > hwos_code
comparison src/simulator.asm @ 560:b7eb98dbd800
bump to 2.96beta (REFACTORED VERSION)
author | heinrichsweikamp |
---|---|
date | Wed, 31 Jan 2018 19:39:37 +0100 |
parents | 7c408bfaf2e8 |
children | b455b31ce022 |
comparison
equal
deleted
inserted
replaced
559:9cb967d844f0 | 560:b7eb98dbd800 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File simulator.asm | 3 ; File simulator.asm REFACTORED VERSION V2.95a1 |
4 ; | 4 ; |
5 ; Decoplan interface to C model code. | 5 ; Decoplan interface to C model code. |
6 ; | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
9 ; HISTORY | 9 ; HISTORY |
10 ; 2011-07-09 : [jDG] Creation... | 10 ; 2011-07-09 : [jDG] Creation... |
11 | 11 |
12 #include "hwos.inc" ; Mandatory include. | 12 #include "hwos.inc" ; Mandatory include |
13 #include "convert.inc" ; output_* | 13 #include "convert.inc" ; output_* |
14 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | 14 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c |
15 #include "strings.inc" ; STRCPY,... | 15 #include "strings.inc" ; STRCPY,... |
16 #include "tft.inc" ; WIN_LEFT,... | 16 #include "tft.inc" ; WIN_LEFT,... |
17 #include "wait.inc" ; speed_* | 17 #include "wait.inc" ; speed_* |
26 | 26 |
27 extern deco_clear_tissue | 27 extern deco_clear_tissue |
28 extern deco_push_tissues_to_vault | 28 extern deco_push_tissues_to_vault |
29 extern deco_calc_dive_interval | 29 extern deco_calc_dive_interval |
30 extern deco_calc_hauptroutine | 30 extern deco_calc_hauptroutine |
31 extern deco_calc_tissue | |
32 extern deco_calc_CNS_fraction | |
33 extern deco_calc_CNS_planning | |
34 extern deco_pull_tissues_from_vault | 31 extern deco_pull_tissues_from_vault |
35 extern TFT_display_decotype_surface1 | 32 extern TFT_display_decotype_surface1 |
33 extern get_first_dil_to_WREG | |
34 extern get_first_gas_to_WREG | |
35 extern setup_dil_registers | |
36 extern setup_gas_registers | |
37 extern deco_setup_cc_diluents | |
38 extern deco_setup_oc_gases | |
39 | |
36 | 40 |
37 extern log_screendump_and_onesecond, logbook_preloop_tasks | 41 extern log_screendump_and_onesecond, logbook_preloop_tasks |
38 extern do_planner_menu | 42 extern do_planner_menu |
39 | 43 |
40 ;---- Private temp variables ------------------------------------------------- | 44 ;---- Private temp variables ------------------------------------------------- |
41 CBLOCK tmp+0x12 ; Reserved space for wordprocessor and convert | 45 |
42 decoplan_index ; within each page | 46 CBLOCK tmp+0x12 ; Reserved space for word processor and convert |
43 decoplan_gindex ; global index | 47 decoplan_index ; within each page |
44 decoplan_last ; Depth of last stop (CF#29) | 48 decoplan_gindex ; global index |
45 decoplan_flags ; Various private flags. | 49 decoplan_last ; Depth of last stop (CF#29) |
46 decoplan_CNS:2 ; Backup CNS before vault restore | 50 decoplan_flags ; Various private flags. |
47 decoplan_page ; page number | 51 decoplan_page ; page number |
48 ; Reserved to tmp+0x18... | 52 decoplan_warnings ; deco engine warnings (ex reserved to tmp+0x18...) |
49 ENDC | 53 ENDC |
50 #define decoplan_last_ceiling_shown decoplan_flags,0 | 54 |
51 | 55 ;---- Defines ---------------------------------------------------------------- |
52 ;---- Demo decoplanner ------------------------------------------------------- | 56 |
53 global do_demo_planner | 57 #define decoplan_last_ceiling_shown decoplan_flags,0 |
58 #define decoplan_abort decoplan_flags,1 | |
59 | |
60 ;---- Demo deco planner ------------------------------------------------------ | |
61 global do_demo_planner | |
54 | 62 |
55 do_demo_planner: | 63 do_demo_planner: |
56 btfsc FLAG_gauge_mode ; =1: In Gauge mode | 64 btfsc FLAG_gauge_mode ; =1: In Gauge mode |
57 goto do_planner_menu | 65 goto do_planner_menu |
58 btfsc FLAG_apnoe_mode ; =1: In Apnea mode | 66 btfsc FLAG_apnoe_mode ; =1: In Apnea mode |
59 goto do_planner_menu | 67 goto do_planner_menu |
60 ; call deco_reset ; TODO: remove reset all Decodata | 68 bcf decoplan_abort ; initialize (clear) abort flag |
61 rcall deco_planer | 69 bcf is_bailout ; clear bailout condition (may have remained set from last invocation) |
62 rcall deco_show_plan | 70 rcall deco_planer |
63 goto do_planner_menu | 71 btfss decoplan_abort ; skip recall deco_show_plan if calculations were aborted |
64 | 72 rcall deco_show_plan |
73 goto do_planner_menu | |
74 | |
75 | |
76 global deco_setup | |
77 deco_setup: | |
78 banksel common | |
79 btfsc FLAG_ccr_mode | |
80 bra deco_setup_cc | |
81 btfsc FLAG_pscr_mode | |
82 bra deco_setup_cc | |
83 deco_setup_oc: | |
84 call get_first_gas_to_WREG ; gets first gas (1-5) into WREG | |
85 call setup_gas_registers ; with WREG=Gas 1-5 | |
86 call deco_setup_oc_gases ; setup OC/Bailout Gases and configure for OC deco calculation | |
87 bra deco_setup_cont | |
88 deco_setup_cc: | |
89 call get_first_dil_to_WREG ; gets first gas (1-5) into WREG | |
90 call setup_dil_registers ; with WREG=Gas 1-5 | |
91 call deco_setup_cc_diluents ; setup CCR/pSCR diluents and configure for CCR/pSCR deco calculation | |
92 deco_setup_cont: | |
93 ; use ambient conditions for simulation ## V2.94 | |
94 #include "isr.inc" | |
95 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ; copy surface pressure to deco routine | |
96 | |
97 movlw deco_distance | |
98 movff WREG,char_I_deco_distance | |
99 | |
100 movff opt_last_stop,char_I_depth_last_deco | |
101 movff opt_GF_low,char_I_GF_Low_percentage | |
102 movff opt_GF_high,char_I_GF_High_percentage | |
103 | |
104 ; overwrite GF if aGF is wanted | |
105 bsf use_agf | |
106 TSTOSS opt_sim_use_aGF | |
107 bcf use_agf | |
108 | |
109 btfsc use_agf ; =1: Use aGF | |
110 movff opt_aGF_low,char_I_GF_Low_percentage | |
111 btfsc use_agf ; =1: Use aGF | |
112 movff opt_aGF_high,char_I_GF_High_percentage | |
113 | |
114 bcf is_bailout | |
115 | |
116 ; setup char_I_const_ppO2 for CC modes | |
117 clrf WREG | |
118 btfsc FLAG_pscr_mode | |
119 movff WREG,char_I_const_ppO2 ; configure pSCR computations to calculated ppO2 | |
120 btfss FLAG_ccr_mode | |
121 return ; done if not in CCR mode | |
122 movff opt_sim_setpoint_number,WREG ; configure CCR computations to selected setpoint | |
123 decf WREG,W ; 1-5 -> 0-4 | |
124 lfsr FSR1,char_I_setpoint_cbar ; load base address of setpoint list | |
125 movff PLUSW1,char_I_const_ppO2 ; setup setpoint | |
126 return | |
127 | |
65 ;============================================================================= | 128 ;============================================================================= |
66 ; Pass all parameters to the C code | 129 ; Launch deco planning |
67 ; | |
68 | |
69 global get_first_dil_to_WREG | |
70 get_first_dil_to_WREG: ; Gets first dil (0-4) into WREG | |
71 lfsr FSR1,opt_dil_type ; Point to dil types | |
72 clrf lo ; start with Gas0 | |
73 get_first_dil_to_WREG2: | |
74 movf lo,W ; | |
75 movf PLUSW1,W ; Get Type of Dil #lo | |
76 sublw .1 ; it is = 1 (First Dil) | |
77 bz get_first_dil_to_WREG3 ; Found the first dil! | |
78 incf lo,F ; ++ | |
79 movlw NUM_GAS+1 | |
80 cpfseq lo ; All done? | |
81 bra get_first_dil_to_WREG2 ; Not yet | |
82 ; No first dil found, use #1 | |
83 movlw .0 | |
84 movff WREG,opt_dil_type+0 ; Set Dil1 to First | |
85 return | |
86 get_first_dil_to_WREG3: | |
87 movf lo,W ; Put into Wreg | |
88 return ; Done | |
89 | |
90 global get_first_gas_to_WREG | |
91 get_first_gas_to_WREG: ; Gets first gas (0-4) into WREG | |
92 lfsr FSR1,opt_gas_type ; Point to gas types | |
93 clrf lo ; start with Gas0 | |
94 get_first_gas_to_WREG2: | |
95 movf lo,W ; | |
96 movf PLUSW1,W ; Get Type of Gas #lo | |
97 sublw .1 ; it is = 1 (First Gas) | |
98 bz get_first_gas_to_WREG3 ; Found the first gas! | |
99 incf lo,F ; ++ | |
100 movlw NUM_GAS+1 | |
101 cpfseq lo ; All done? | |
102 bra get_first_gas_to_WREG2 ; Not yet | |
103 ; No first gas found, use #1 | |
104 movlw .0 | |
105 movff WREG,opt_gas_type+0 ; Set Gas1 to First | |
106 return | |
107 get_first_gas_to_WREG3: | |
108 movf lo,W ; Put into Wreg | |
109 return ; Done | |
110 | |
111 deco_setup: | |
112 banksel char_I_step_is_1min ; Select the right bank... | |
113 clrf char_I_step_is_1min ; Default to 2sec steps. | |
114 | |
115 ; Fixed ambient surface pressure to 1bar. | |
116 movlw LOW(.1000) | |
117 movwf int_I_pres_surface+0 | |
118 movwf int_I_pres_respiration+0 | |
119 movlw HIGH(.1000) | |
120 movwf int_I_pres_surface+1 | |
121 movwf int_I_pres_respiration+1 | |
122 | |
123 clrf int_I_divemins+0 ; Dive start | |
124 clrf int_I_divemins+1 | |
125 | |
126 banksel common ; Bank1 | |
127 bcf use_agf ; =1: Use aGF | |
128 | |
129 rcall deco_setup_dive | |
130 | |
131 movlw .0 ; Bank safe "clrf" | |
132 movff WREG,char_I_const_ppO2 ; deactivate CCR-mode in deco calculations unless in CCR mode (char_I_const_ppO2 is filled below again) | |
133 | |
134 ; Setup char_I_const_ppO2 for CC modes | |
135 btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
136 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; Setup fixed Setpoint (Always start with SP1) | |
137 rcall get_first_gas_to_WREG ; Gets first gas (0-4) into WREG | |
138 | |
139 ; Overwrite WREG in CCR and PSCR Mode | |
140 btfsc FLAG_ccr_mode | |
141 rcall get_first_dil_to_WREG | |
142 btfsc FLAG_pscr_mode | |
143 rcall get_first_dil_to_WREG | |
144 | |
145 incf WREG ; 1-5 | |
146 movff WREG,char_I_first_gas ; Copy for compatibility | |
147 decf WREG ; 0-4 | |
148 extern setup_gas_registers | |
149 call setup_gas_registers ; With WREG=Gas 0-4, set current N2/He/O2 ratios. | |
150 extern set_actual_ppo2 | |
151 goto set_actual_ppo2 ; Then configure char_I_actual_ppO2 (For CNS) (And return!) | |
152 | |
153 global deco_setup_dive | |
154 deco_setup_dive: ; Called from divemode | |
155 banksel common ; Bank1 | |
156 | |
157 btfsc is_bailout | |
158 bra deco_setup_dive_oc | |
159 btfsc FLAG_ccr_mode | |
160 bra deco_setup_dive_cc | |
161 btfsc FLAG_pscr_mode | |
162 bra deco_setup_dive_cc | |
163 | |
164 deco_setup_dive_oc: | |
165 rcall deco_setup_oc_gases ; Setup OC/Bailout Gases | |
166 bra deco_setup_dive_cont | |
167 deco_setup_dive_cc: | |
168 rcall deco_setup_cc_diluents ; Setup CC Diluents | |
169 deco_setup_dive_cont: | |
170 | |
171 movff divemins+0,int_I_divemins+0 ; Current dive time. | |
172 movff divemins+1,int_I_divemins+1 | |
173 | |
174 movlw deco_distance | |
175 movff WREG,char_I_deco_distance | |
176 movff opt_last_stop,char_I_depth_last_deco | |
177 movff opt_GF_low,char_I_GF_Low_percentage | |
178 movff opt_GF_high,char_I_GF_High_percentage | |
179 ;Overwrite GF if aGF is wanted | |
180 btfsc use_agf ; =1: Use aGF | |
181 movff opt_aGF_low,char_I_GF_Low_percentage | |
182 btfsc use_agf ; =1: Use aGF | |
183 movff opt_aGF_high,char_I_GF_High_percentage | |
184 return | |
185 | |
186 deco_setup_cc_diluents: | |
187 movff opt_dil_He_ratio+0,char_I_deco_He_ratio+0 | |
188 movff char_I_deco_He_ratio+0,lo | |
189 movff opt_dil_O2_ratio+0,WREG | |
190 addwf lo,W ; O2 + He -> WREG | |
191 sublw .100 ; 100 - (O2 + He) -> WREG | |
192 movff WREG,char_I_deco_N2_ratio+0 | |
193 movff opt_dil_type+0,WREG ; 0=Disabled, 1=First, 2=Normal | |
194 tstfsz WREG ; Disabled? | |
195 bra $+4 ; No | |
196 movff WREG,char_I_dil_change+0 ; Yes, clear char_I_deco_gas_change (Bank safe) | |
197 | |
198 movff opt_dil_He_ratio+1,char_I_deco_He_ratio+1 | |
199 movff char_I_deco_He_ratio+1,lo | |
200 movff opt_dil_O2_ratio+1,WREG | |
201 addwf lo,W ; O2 + He -> WREG | |
202 sublw .100 ; 100 - (O2 + He) -> WREG | |
203 movff WREG,char_I_deco_N2_ratio+1 | |
204 movff opt_dil_type+1,WREG ; 0=Disabled, 1=First, 2=Normal | |
205 tstfsz WREG ; Disabled? | |
206 bra $+4 ; No | |
207 movff WREG,char_I_dil_change+1 ; Yes, clear char_I_dil_change | |
208 | |
209 movff opt_dil_He_ratio+2,char_I_deco_He_ratio+2 | |
210 movff char_I_deco_He_ratio+2,lo | |
211 movff opt_dil_O2_ratio+2,WREG | |
212 addwf lo,W ; O2 + He -> WREG | |
213 sublw .100 ; 100 - (O2 + He) -> WREG | |
214 movff WREG,char_I_deco_N2_ratio+2 | |
215 movff opt_dil_type+2,WREG ; 0=Disabled, 1=First, 2=Normal | |
216 tstfsz WREG ; Disabled? | |
217 bra $+4 ; No | |
218 movff WREG,char_I_dil_change+2 ; Yes, clear char_I_dil_change | |
219 | |
220 movff opt_dil_He_ratio+3,char_I_deco_He_ratio+3 | |
221 movff char_I_deco_He_ratio+3,lo | |
222 movff opt_dil_O2_ratio+3,WREG | |
223 addwf lo,W ; O2 + He -> WREG | |
224 sublw .100 ; 100 - (O2 + He) -> WREG | |
225 movff WREG,char_I_deco_N2_ratio+3 | |
226 movff opt_dil_type+3,WREG ; 0=Disabled, 1=First, 2=Normal | |
227 tstfsz WREG ; Disabled? | |
228 bra $+4 ; No | |
229 movff WREG,char_I_dil_change+3 ; Yes, clear char_I_dil_change | |
230 | |
231 movff opt_dil_He_ratio+4,char_I_deco_He_ratio+4 | |
232 movff char_I_deco_He_ratio+4,lo | |
233 movff opt_dil_O2_ratio+4,WREG | |
234 addwf lo,W ; O2 + He -> WREG | |
235 sublw .100 ; 100 - (O2 + He) -> WREG | |
236 movff WREG,char_I_deco_N2_ratio+4 | |
237 movff opt_dil_type+4,WREG ; 0=Disabled, 1=First, 2=Normal | |
238 tstfsz WREG ; Disabled? | |
239 bra $+4 ; No | |
240 movff WREG,char_I_dil_change+4 ; Yes, clear char_I_dil_change | |
241 | |
242 ; Setup char_I_deco_gas_change array | |
243 movff char_I_dil_change+0, char_I_deco_gas_change+0 | |
244 movff char_I_dil_change+1, char_I_deco_gas_change+1 | |
245 movff char_I_dil_change+2, char_I_deco_gas_change+2 | |
246 movff char_I_dil_change+3, char_I_deco_gas_change+3 | |
247 movff char_I_dil_change+4, char_I_deco_gas_change+4 | |
248 return | |
249 | |
250 deco_setup_oc_gases: | |
251 movff opt_gas_He_ratio+0,char_I_deco_He_ratio+0 | |
252 movff char_I_deco_He_ratio+0,lo | |
253 movff opt_gas_O2_ratio+0,WREG | |
254 addwf lo,W ; O2 + He -> WREG | |
255 sublw .100 ; 100 - (O2 + He) -> WREG | |
256 movff WREG,char_I_deco_N2_ratio+0 | |
257 banksel opt_gas_type+0 | |
258 movlw .3 ; 3=Deco | |
259 cpfseq opt_gas_type+0 ; Gas is deco type? | |
260 clrf opt_OC_bail_gas_change+0 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
261 banksel common | |
262 | |
263 movff opt_gas_He_ratio+1,char_I_deco_He_ratio+1 | |
264 movff char_I_deco_He_ratio+1,lo | |
265 movff opt_gas_O2_ratio+1,WREG | |
266 addwf lo,W ; O2 + He -> WREG | |
267 sublw .100 ; 100 - (O2 + He) -> WREG | |
268 movff WREG,char_I_deco_N2_ratio+1 | |
269 banksel opt_gas_type+1 | |
270 movlw .3 ; 3=Deco | |
271 cpfseq opt_gas_type+1 ; Gas is deco type? | |
272 clrf opt_OC_bail_gas_change+1 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
273 banksel common | |
274 | |
275 movff opt_gas_He_ratio+2,char_I_deco_He_ratio+2 | |
276 movff char_I_deco_He_ratio+2,lo | |
277 movff opt_gas_O2_ratio+2,WREG | |
278 addwf lo,W ; O2 + He -> WREG | |
279 sublw .100 ; 100 - (O2 + He) -> WREG | |
280 movff WREG,char_I_deco_N2_ratio+2 | |
281 banksel opt_gas_type+2 | |
282 movlw .3 ; 3=Deco | |
283 cpfseq opt_gas_type+2 ; Gas is deco type? | |
284 clrf opt_OC_bail_gas_change+2 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
285 banksel common | |
286 | |
287 movff opt_gas_He_ratio+3,char_I_deco_He_ratio+3 | |
288 movff char_I_deco_He_ratio+3,lo | |
289 movff opt_gas_O2_ratio+3,WREG | |
290 addwf lo,W ; O2 + He -> WREG | |
291 sublw .100 ; 100 - (O2 + He) -> WREG | |
292 movff WREG,char_I_deco_N2_ratio+3 | |
293 banksel opt_gas_type+3 | |
294 movlw .3 ; 3=Deco | |
295 cpfseq opt_gas_type+3 ; Gas is deco type? | |
296 clrf opt_OC_bail_gas_change+3 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
297 banksel common | |
298 | |
299 movff opt_gas_He_ratio+4,char_I_deco_He_ratio+4 | |
300 movff char_I_deco_He_ratio+4,lo | |
301 movff opt_gas_O2_ratio+4,WREG | |
302 addwf lo,W ; O2 + He -> WREG | |
303 sublw .100 ; 100 - (O2 + He) -> WREG | |
304 movff WREG,char_I_deco_N2_ratio+4 | |
305 banksel opt_gas_type+4 | |
306 movlw .3 ; 3=Deco | |
307 cpfseq opt_gas_type+4 ; Gas is deco type? | |
308 clrf opt_OC_bail_gas_change+4 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
309 banksel common | |
310 | |
311 movlw .0 | |
312 movff WREG,char_I_const_ppO2 ; Clear constant ppO2 for OC/bailout | |
313 | |
314 ; Setup char_I_deco_gas_change array | |
315 movff opt_OC_bail_gas_change+0, char_I_deco_gas_change+0 | |
316 movff opt_OC_bail_gas_change+1, char_I_deco_gas_change+1 | |
317 movff opt_OC_bail_gas_change+2, char_I_deco_gas_change+2 | |
318 movff opt_OC_bail_gas_change+3, char_I_deco_gas_change+3 | |
319 movff opt_OC_bail_gas_change+4, char_I_deco_gas_change+4 | |
320 return | |
321 | |
322 ;============================================================================= | |
323 ; Reset decompression tissues | |
324 ; | 130 ; |
325 global deco_reset | 131 global deco_planer |
326 deco_reset: | |
327 rcall deco_setup ; Setup all model parameters. | |
328 call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio | |
329 call deco_clear_CNS_fraction ; Reset CNS value. | |
330 banksel common ; Bank1 | |
331 return | |
332 | |
333 ;============================================================================= | |
334 ; Launch decoplanning | |
335 ; | |
336 global deco_planer | |
337 deco_planer: | 132 deco_planer: |
338 call speed_fastest ; Quick ! | 133 call speed_fastest ; Quick ! |
339 rcall deco_setup ; Setup all model parameters. | 134 call deco_push_tissues_to_vault |
340 call deco_push_tissues_to_vault | 135 rcall deco_setup ; Setup all model parameters. |
341 banksel common ; Bank1 | |
342 | 136 |
343 ;---- Specific settings ------------------------------------------------------ | 137 ;---- Specific settings ------------------------------------------------------ |
138 | |
139 ; configure the deco engine for normal plan, CNS & gas volume calculation and no delayed ascent | |
140 movff char_O_deco_status,WREG ; bank-safe copy | |
141 bcf WREG,DECO_PLAN_FLAG ; normal plan mode, | |
142 bsf WREG,DECO_CNS_FLAG ; enable CNS calculation (CNS at end of dive), | |
143 bsf WREG,DECO_VOLUME_FLAG ; enable gas volume calculation, and | |
144 bcf WREG,DECO_ASCENT_FLAG ; disable delayed ascent calculation | |
145 movff WREG,char_O_deco_status ; bank-safe copy back | |
146 | |
147 ; configure the deco engine for total-dive gas volume calculation | |
148 movff char_O_main_status,WREG ; bank-safe copy | |
149 bsf WREG,DECO_BOTTOM_FLAG ; set bottom flag | |
150 movff WREG,char_O_main_status ; bank-safe copy back | |
151 | |
344 deco_planer_redo: | 152 deco_planer_redo: |
345 banksel char_O_deco_status ; Bank 2 | 153 |
346 movlw .3 ; Start in surface state. | 154 ; show deco calculation is in progress |
347 movwf char_O_deco_status | 155 call TFT_ClearScreen |
348 | 156 WIN_COLOR color_greenish |
349 banksel char_I_step_is_1min ; Bank 3 | 157 TEXT_SMALL .20,.40, tCalculating |
350 movlw 1 | 158 WIN_COLOR color_lightblue |
351 movwf char_I_step_is_1min ; Set 1min steps | 159 WIN_SMALL .1,.215 |
160 STRCPY_TEXT_PRINT tAbort | |
161 | |
162 ; configure the deco engine for restart: | |
163 movff char_O_deco_status,WREG ; bank-safe copy | |
164 bsf WREG,DECO_STATUS_0_FLAG ; configure init ... | |
165 bsf WREG,DECO_STATUS_1_FLAG ; ... state, | |
166 movff WREG,char_O_deco_status ; bank-safe copy back | |
352 | 167 |
353 ;---- Add delay at surface, if needed ---------------------------------------- | 168 ;---- Add delay at surface, if needed ---------------------------------------- |
169 | |
170 banksel char_I_dive_interval | |
354 tstfsz char_I_dive_interval | 171 tstfsz char_I_dive_interval |
355 call deco_calc_dive_interval | 172 call deco_calc_dive_interval |
356 | 173 |
357 ;---- Dive loop -------------------------------------------------------------- | 174 ;---- Dive loop -------------------------------------------------------------- |
358 | 175 |
359 ; Compute dive ambiant conditions | 176 ; Compute dive ambient conditions |
360 banksel char_I_bottom_depth | 177 banksel char_I_bottom_depth |
361 movf char_I_bottom_depth,W | 178 movf char_I_bottom_depth,W |
362 mullw .100 | 179 mullw .100 |
363 movlw LOW(.1000) | 180 movlw LOW(.1000) |
364 addwf PRODL,W | 181 addwf PRODL,W |
365 movwf int_I_pres_respiration+0 | 182 movwf int_I_pres_respiration+0 |
366 movlw HIGH(.1000) | 183 movlw HIGH(.1000) |
367 addwfc PRODH,W | 184 addwfc PRODH,W |
368 movwf int_I_pres_respiration+1 | 185 movwf int_I_pres_respiration+1 |
369 | 186 |
370 banksel int_I_divemins ; Bank 4 | 187 banksel common |
371 clrf int_I_divemins+0 ; Clear dive time | 188 |
372 clrf int_I_divemins+1 | 189 movff char_I_bottom_time,char_I_sim_advance_time |
373 | 190 |
374 clrf TMR5L | 191 clrf TMR5L |
375 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H | 192 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H |
376 call deco_calc_hauptroutine ; Reset + simulate first min. | 193 |
377 | 194 call deco_calc_hauptroutine ; initialization + complete bottom time part |
378 deco_planer_loop: | 195 banksel common |
379 banksel int_I_divemins ; Bank 3 | 196 |
380 incf int_I_divemins,F ; Done 1 min. | |
381 btg LEDg | |
382 | |
383 movf char_I_bottom_time,W ; Finished ? | |
384 xorwf int_I_divemins,W | |
385 bz deco_planer_endloop ; YES | |
386 | |
387 call deco_calc_tissue ; JUST calc tissue (faster). | |
388 call deco_calc_CNS_fraction ; Also calculate CNS (in 1min loop) | |
389 bra deco_planer_loop | |
390 | |
391 deco_planer_endloop: | |
392 banksel char_I_step_is_1min | |
393 clrf char_I_step_is_1min ; Back to 2sec loops | |
394 | |
395 ;---- BAILOUT: Switch to OC gases for ascent cycles -------------------------- | 197 ;---- BAILOUT: Switch to OC gases for ascent cycles -------------------------- |
396 banksel common | 198 |
397 btfss is_bailout ; Doing a bailout decoplan ? | 199 btfss is_bailout ; Doing a bailout deco plan ? |
398 bra deco_planer_finishing ; NO: keep gases | 200 bra deco_planer_finishing ; NO - keep gases |
399 | 201 ; YES - switch to OC gas |
400 rcall deco_setup_oc_gases ; Switch to OC gas and no const_ppO2 | 202 |
401 | 203 ; reconfigure the deco engine for delayed ascent mode |
402 movlw .0 | 204 movff char_O_deco_status,lo ; bank-safe copy |
403 movff WREG,char_I_const_ppO2 ; deactivate CCR-mode deco calculations | 205 bsf lo,DECO_ASCENT_FLAG ; set flag for delayed ascent calculation |
404 | 206 movff lo,char_O_deco_status ; bank-safe copy back |
405 ;---- Wait until status reach zero ------------------------------------------- | 207 |
208 ; configure the deco engine for delayed ascent part gas volume calculation | |
209 movff char_O_main_status,WREG ; bank-safe copy | |
210 bcf WREG,DECO_BOTTOM_FLAG ; set bottom flag | |
211 movff WREG,char_O_main_status ; bank-safe copy back | |
212 | |
213 ; reconfigure gas settings to OC gases | |
214 call get_first_gas_to_WREG ; get first gas (1-5) into WREG | |
215 call setup_gas_registers ; With WREG=Gas 1-5 (or 6, not applicable here) | |
216 call deco_setup_oc_gases ; With WREG=Gas 1-5 (or 6, not applicable here) | |
217 | |
218 ; set the gas change override flag to allow gas changes before deco stops as done in alternative plan | |
219 movff char_O_main_status,lo ; bank-safe copy | |
220 bsf lo,DECO_GASCHANGE_OVRD ; set flag for gas change override | |
221 movff lo,char_O_main_status ; bank-safe copy back | |
222 | |
223 ;---- Wait until status reaches zero ------------------------------------------- | |
224 | |
406 deco_planer_finishing: | 225 deco_planer_finishing: |
407 btg LEDg | 226 call deco_calc_hauptroutine ; Simulate more dive time to trigger the deco calculations |
408 ; clrf TMR5L | 227 banksel common |
409 ; clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H | 228 |
410 call deco_calc_hauptroutine ; Simulate 2sec more | 229 btfss switch_left ; check if left button was pressed |
411 | 230 bra deco_planer_finishing_1 ; NO - continue calculations |
412 banksel char_O_deco_status ; Bank 2 | 231 bsf decoplan_abort ; YES - set abort flag so that deco_show_plan will not be called |
413 movf char_O_deco_status,W | 232 bra deco_planer_finishing_2 ; do some clean-up and return |
414 bnz deco_planer_finishing | 233 deco_planer_finishing_1: |
234 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common | |
235 movlw DECO_STATUS_MASK ; bit mask for deco status bit set | |
236 andwf lo,W ; mask out bits showing state of computation | |
237 tstfsz WREG ; check if a compute cycle is finished (bits 1 and 0 == 0) | |
238 bra deco_planer_finishing ; NO - needs more computation cycles | |
415 | 239 |
416 ;---- Done: add CNS from decoplan, and restore tissues | 240 ;---- Done: add CNS from decoplan, and restore tissues |
417 call deco_calc_CNS_planning | 241 |
418 movff int_O_CNS_fraction+0,decoplan_CNS+0 | 242 deco_planer_finishing_2: |
419 movff int_O_CNS_fraction+1,decoplan_CNS+1 | 243 |
420 call deco_pull_tissues_from_vault | 244 movff char_O_deco_warnings,decoplan_warnings ; copy warnings |
421 bcf LEDg | 245 |
422 banksel common ; Bank1 | 246 call deco_pull_tissues_from_vault ; restore "real" deco data |
423 movlw b'00111000' ; 1:8 Prescaler -> 65,536ms@16MHz | 247 banksel common ; back to bank 1 |
424 movwf T3CON | 248 |
425 call speed_normal | 249 movlw b'00111000' ; 1:8 Prescaler -> 65,536ms@16MHz |
426 return | 250 movwf T3CON |
251 goto speed_normal ;(and return) | |
427 | 252 |
428 ;----------------------------------------------------------------------------- | 253 ;----------------------------------------------------------------------------- |
429 ; Draw a stop of the deco plan (simulator or dive). | 254 ; Draw a stop of the deco plan (simulator or dive). |
430 ; Inputs: lo = depth. Range 3m...93m | 255 ; Inputs: lo = depth. Range 3m...93m |
431 ; + 80 if this is a switch-gas stop. | 256 ; + 0x80 if this is a switch-gas stop. |
432 ; up = minutes. range 1'..240'. | 257 ; up = minutes. range 1'..240'. |
433 ; win_top = line to draw on screen. | 258 ; win_top = line to draw on screen. |
434 ; Trashed: up, lo, win_height, win_leftx2, win_width, win_color*, | 259 ; Trashed: up, lo, win_height, win_leftx2, win_width, win_color*, |
435 ; WREG, PROD, TBLPTR TABLAT. | 260 ; WREG, PROD, TBLPTR TABLAT. |
436 ; | 261 ; |
437 deco_plan_show_stop: | 262 deco_plan_show_stop: |
438 ;---- Print depth ---------------------------------------------------- | 263 |
439 btfss lo,7 ; Bit set ? | 264 ;---- Print depth ---------------------------------------------------- |
440 bra deco_plan_show_std_stop ; No : Just an usual stop. | 265 bcf lo,7 ; clear gas-switch flag (not used any more anyhow) |
441 | 266 lfsr FSR2,char_O_deco_gas |
442 call TFT_attention_color | 267 movf decoplan_gindex,W ; index |
443 bcf lo,7 ; and cleanup depth. | 268 movff PLUSW2,WREG ; get current gas |
444 bra deco_plan_show_nstd_stop | 269 rcall simulator_color_gas ; set output color dependent on gas (1-5) |
445 | 270 |
446 deco_plan_show_std_stop: | |
447 call TFT_standard_color | |
448 | |
449 deco_plan_show_nstd_stop: | |
450 lfsr FSR2,buffer | 271 lfsr FSR2,buffer |
451 | 272 |
452 TSTOSS opt_units ; 0=Meters, 1=Feets | 273 TSTOSS opt_units ; 0=Meters, 1=Feets |
453 bra deco_plan_show_nstd_stop_metric | 274 bra deco_plan_show_nstd_stop_metric |
454 | 275 |
455 WIN_LEFT .85 | 276 WIN_LEFT .85 |
456 movf lo,W ; lo = m | 277 movf lo,W ; lo = m |
457 mullw .100 ; PRODL:PRODH = mbar | 278 mullw .100 ; PRODL:PRODH = mbar |
458 movff PRODL,lo | 279 movff PRODL,lo |
459 movff PRODH,hi | 280 movff PRODH,hi |
460 ; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops... | 281 ; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops... |
461 movff lo,xA+0 | 282 movff lo,xA+0 |
462 movff hi,xA+1 | 283 movff hi,xA+1 |
463 movlw LOW d'334' ; 334feet/100m | 284 movlw LOW d'334' ; 334feet/100m |
464 movwf xB+0 | 285 movwf xB+0 |
465 movlw HIGH d'334' | 286 movlw HIGH d'334' |
478 movff xC+0,lo | 299 movff xC+0,lo |
479 movff xC+1,hi ; restore lo and hi with updated value | 300 movff xC+1,hi ; restore lo and hi with updated value |
480 bsf leftbind | 301 bsf leftbind |
481 bsf ignore_digit4 ; Only full feet | 302 bsf ignore_digit4 ; Only full feet |
482 output_16 | 303 output_16 |
304 bcf leftbind | |
483 STRCAT_PRINT "ft " | 305 STRCAT_PRINT "ft " |
484 bra deco_plan_show_nstd_stop_common | 306 bra deco_plan_show_nstd_stop_common |
485 | 307 |
486 deco_plan_show_nstd_stop_metric: | 308 deco_plan_show_nstd_stop_metric: |
487 WIN_LEFT .90 | 309 WIN_LEFT .90 |
488 bsf leftbind | 310 bsf leftbind |
489 output_8 ; outputs into Postinc2! | 311 output_8 ; outputs into Postinc2! |
312 bcf leftbind | |
490 STRCAT_PRINT "m " | 313 STRCAT_PRINT "m " |
491 deco_plan_show_nstd_stop_common: | 314 deco_plan_show_nstd_stop_common: |
492 ;---- Print duration ------------------------------------------------- | 315 ;---- Print duration ------------------------------------------------- |
493 WIN_LEFT .135 | 316 WIN_LEFT .135 |
494 lfsr FSR2,buffer | 317 lfsr FSR2,buffer |
506 movf lo,W ; Swap back up & lo | 329 movf lo,W ; Swap back up & lo |
507 movff up,lo | 330 movff up,lo |
508 movwf up | 331 movwf up |
509 | 332 |
510 ;--------------------------------------------------------------------- | 333 ;--------------------------------------------------------------------- |
511 ; Draw the bar graph used for deco stops (decoplan in simulator or dive). | 334 ; Draw the bar graph used for deco stops (deco plan in simulator or dive). |
512 incf win_top,F | 335 incf win_top,F |
513 movlw .19 | 336 movlw .19 |
514 movwf win_height | 337 movwf win_height |
515 movlw .118 | 338 movlw .118 |
516 movwf win_leftx2 ; column left (0-159) | 339 movwf win_leftx2 ; column left (0-159) |
517 movlw .16 | 340 movlw .16 |
518 movwf win_width+0 ; column max width. | 341 movwf win_width+0 ; column max width. |
519 clrf win_width+1 | 342 clrf win_width+1 |
520 | 343 |
521 ; Draw used area (up = minutes): | 344 ; Draw used area (up = minutes): |
522 movlw .16 ; Limit length (16min) | 345 movlw .16 ; Limit length (16min) |
523 cpfslt up | 346 cpfslt up |
524 movwf up | 347 movwf up |
529 call TFT_standard_color | 352 call TFT_standard_color |
530 decf win_top,F ; Restore win_top | 353 decf win_top,F ; Restore win_top |
531 return | 354 return |
532 | 355 |
533 ;----------------------------------------------------------------------------- | 356 ;----------------------------------------------------------------------------- |
534 ; Clear unused area belw last stop | 357 ; Clear unused area below last stop |
535 ; Inputs: win_top : last used area... | 358 ; Inputs: win_top : last used area... |
536 deco_plan_show_clear_bottom: | 359 deco_plan_show_clear_bottom: |
537 movf win_top,W ; Get back from bank0 | 360 movf win_top,W ; Get back from bank0 |
538 sublw .239 ; No: bottom row in planning | 361 sublw .239 ; No: bottom row in planning |
539 movwf win_height | 362 movwf win_height |
540 | 363 |
541 WIN_LEFT .85 ; Full divemenu width | 364 WIN_LEFT .85 ; Full dive menu width |
542 movlw .159-.85+1 | 365 movlw .159-.85+1 |
543 movwf win_width+0 | 366 movwf win_width+0 |
544 clrf win_width+1 | 367 clrf win_width+1 |
545 | 368 |
546 clrf win_color1 ; Fill with black | 369 clrf win_color1 ; Fill with black |
547 clrf win_color2 | 370 clrf win_color2 |
548 | 371 |
549 goto TFT_box ; and return | 372 goto TFT_box ; and return |
550 | 373 |
551 ;----------------------------------------------------------------------------- | 374 ;----------------------------------------------------------------------------- |
552 ; Display the decoplan (simulator). | 375 ; Display the deco plan (simulator). |
553 ; Inputs: char_O_deco_table (array of stop times, in minutes) | 376 ; Inputs: char_O_deco_table (array of stop times, in minutes) |
554 ; decoplan_page = page number. | 377 ; decoplan_page = page number. |
555 ; | 378 ; |
556 deco_show_plan_page: | 379 deco_show_plan_page: |
557 bcf win_invert ; Reset invert flag | 380 bcf win_invert ; Reset invert flag |
574 clrf decoplan_index ; Start with index = 0 | 397 clrf decoplan_index ; Start with index = 0 |
575 clrf win_top ; and row = 0 | 398 clrf win_top ; and row = 0 |
576 | 399 |
577 ; Read stop parameters, indexed by decoplan_index and decoplan_page | 400 ; Read stop parameters, indexed by decoplan_index and decoplan_page |
578 movf decoplan_page,W ; decoplan_gindex = 6*decoplan_page + decoplan_index | 401 movf decoplan_page,W ; decoplan_gindex = 6*decoplan_page + decoplan_index |
579 mullw .8 ; 8 lines/page in decoplan | 402 mullw .8 ; 8 lines/page in deco plan |
580 movf decoplan_index,W | 403 movf decoplan_index,W |
581 addwf PRODL,W | 404 addwf PRODL,W |
582 movwf decoplan_gindex ; --> decoplan_gindex | 405 movwf decoplan_gindex ; --> decoplan_gindex |
583 | 406 |
584 bcf decoplan_last_ceiling_shown ; Not finished yet... | 407 bcf decoplan_last_ceiling_shown ; Not finished yet... |
597 ; Display the stop line | 420 ; Display the stop line |
598 rcall deco_plan_show_stop | 421 rcall deco_plan_show_stop |
599 | 422 |
600 ; Next | 423 ; Next |
601 movlw .24 | 424 movlw .24 |
602 addwf win_top,F ; row: += 24 | 425 addwf win_top,F ; row: += 24 |
603 incf decoplan_index,F ; local index += 1 | 426 incf decoplan_index,F ; local index += 1 |
604 incf decoplan_gindex,F ; global index += 1 | 427 incf decoplan_gindex,F ; global index += 1 |
605 | 428 |
606 ; Max number of lines/page reached ? | 429 ; Max number of lines/page reached ? |
607 movlw .8 ; 8 lines/page in decoplan | 430 movlw .8 ; 8 lines/page in deco plan |
608 cpfseq decoplan_index | 431 cpfseq decoplan_index |
609 bra deco_plan_show_2 ; NO: loop | 432 bra deco_plan_show_2 ; NO: loop |
610 | 433 |
611 ; Check if next stop if end-of-list ? | 434 ; Check if next stop is end-of-list ? |
612 movf decoplan_gindex,W | 435 movf decoplan_gindex,W |
613 movf PLUSW0,W ; char_O_deco_depth[gindex] | 436 movf PLUSW0,W ; char_O_deco_depth[gindex] |
614 bz deco_plan_show_99 ; End of list... | 437 bz deco_plan_show_99 ; End of list... |
615 | 438 |
616 ; Display the message "more..." | 439 ; Display the message "more..." |
617 rcall deco_plan_show_clear_bottom ; Clear from next line | 440 rcall deco_plan_show_clear_bottom ; Clear from next line |
618 | 441 |
619 call TFT_standard_color | 442 call TFT_standard_color |
624 bsf decoplan_last_ceiling_shown ; Nothing more in table to display. | 447 bsf decoplan_last_ceiling_shown ; Nothing more in table to display. |
625 rcall deco_plan_show_clear_bottom ; Clear from next line | 448 rcall deco_plan_show_clear_bottom ; Clear from next line |
626 return | 449 return |
627 | 450 |
628 ;----------------------------------------------------------------------------- | 451 ;----------------------------------------------------------------------------- |
629 ; Loop to show all pages of the decoplan (surfacemode) | 452 ; Loop to show all pages of the deco plan (surface mode) |
630 | 453 |
631 global deco_show_plan | 454 global deco_show_plan |
632 deco_show_plan: | 455 deco_show_plan: |
633 clrf decoplan_page | 456 clrf decoplan_page |
634 call TFT_ClearScreen | 457 call TFT_ClearScreen |
635 WIN_COLOR color_greenish | 458 WIN_COLOR color_greenish |
636 btfsc is_bailout | 459 btfsc is_bailout |
637 bra deco_show_plan_bail_title | 460 bra deco_show_plan_bail_title |
638 TEXT_SMALL .1,.1, tDivePlan | 461 TEXT_SMALL .1,.1, tDivePlan |
639 bra deco_show_plan2 | 462 bra deco_show_plan2 |
640 deco_show_plan_bail_title: | 463 deco_show_plan_bail_title: |
641 TEXT_SMALL .1,.1, tDiveBailout | 464 TEXT_SMALL .1,.1, tDiveBailout |
642 deco_show_plan2: | 465 deco_show_plan2: |
643 call TFT_standard_color | 466 call TFT_standard_color |
644 ; Show plan parameters | 467 ;---- Display Plan Parameters |
645 WIN_SMALL .0,.25 | 468 WIN_SMALL .0,.25 |
646 STRCPY "Int:" | 469 STRCPY "Int:" |
647 movff char_I_dive_interval,lo | 470 movff char_I_dive_interval,lo |
648 bsf leftbind | 471 bsf leftbind |
649 output_8 | 472 output_8 |
473 bcf leftbind | |
650 STRCAT_PRINT "'" | 474 STRCAT_PRINT "'" |
651 WIN_SMALL .0,.50 | 475 WIN_SMALL .0,.50 |
652 STRCPY_TEXT tBtTm_short | 476 STRCPY_TEXT tBtTm_short |
653 movff char_I_bottom_time,lo | 477 movff char_I_bottom_time,lo |
654 bsf leftbind | 478 bsf leftbind |
655 output_8 | 479 output_8 |
480 bcf leftbind | |
656 STRCAT_PRINT "'" | 481 STRCAT_PRINT "'" |
657 WIN_SMALL .0,.75 | 482 WIN_SMALL .0,.75 |
658 STRCPY_TEXT tDepth | 483 STRCPY_TEXT tDepth |
659 PUTC ":" | 484 PUTC ":" |
660 movff char_I_bottom_depth,lo | 485 movff char_I_bottom_depth,lo |
661 bsf leftbind | 486 bsf leftbind |
662 output_8 | 487 output_8 |
488 bcf leftbind | |
663 STRCAT_PRINT "m" | 489 STRCAT_PRINT "m" |
664 | 490 |
665 ; Show deco mode | 491 WIN_SMALL .0,.105 ; set position for warnings or sat/dsat factors |
666 WIN_TOP .155 | 492 |
667 lfsr FSR2,buffer | 493 ;---- Check for Stop Table Overflow |
668 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR | 494 btfss decoplan_warnings,stoptable_overflow ; check if we have a overflow warning |
669 call TFT_display_decotype_surface1 | 495 bra deco_show_plan2a ; NO - skip |
670 | 496 ;---- Display Overflow warning |
671 ;---- Display model | 497 call TFT_warnings_color ; YES - show overflow warning |
498 STRCAT_PRINT "incomplete" ; max 10 characters | |
499 bra deco_show_plan_m1 ; skip displaying sat/dsat factors | |
500 | |
501 deco_show_plan2a: | |
502 ;---- Check for IBCD Warning | |
503 btfss decoplan_warnings,IBCD_warning_lock ; check if we have a locked IBCD warning | |
504 bra deco_show_plan2b ; NO - skip | |
505 ;---- Display IBCD warning | |
506 call TFT_attention_color ; YES - show IBCD warning | |
507 STRCAT_PRINT "IBCD!" ; max 10 characters | |
508 bra deco_show_plan_m1 ; skip displaying sat/dsat factors | |
509 | |
510 deco_show_plan2b: | |
511 ;---- Display Sat/Desat Factors --> is skipped if there were warnings | |
512 STRCAT_PRINT "SD:" | |
513 WIN_SMALL .25,.105 | |
514 movff char_I_saturation_multiplier,lo | |
515 output_8 | |
516 STRCAT "/" | |
517 movff char_I_desaturation_multiplier,lo | |
518 output_8 | |
519 STRCAT_PRINT "" | |
520 | |
521 deco_show_plan_m1: | |
522 call TFT_standard_color ; clean-up from warnings | |
523 | |
524 ;---- Get Model | |
672 movff char_I_deco_model,WREG | 525 movff char_I_deco_model,WREG |
673 iorwf WREG | 526 iorwf WREG |
674 bnz deco_show_plan_m1 | 527 bz deco_show_plan_m2 |
675 | 528 |
676 ; Display ZH-L16 sat/desat model. | 529 ;---- Display GF low/high values |
677 TEXT_SMALL .0,.130, tZHL16 | 530 WIN_SMALL .0,.130 |
678 WIN_SMALL .14,.155 | 531 STRCAT_PRINT "GF:" |
679 PUTC "," | 532 WIN_SMALL .25,.130 |
680 movff char_I_desaturation_multiplier,lo | |
681 output_8 | |
682 STRCAT "%/" | |
683 movff char_I_saturation_multiplier,lo | |
684 output_8 | |
685 bra deco_show_plan_m2 | |
686 | |
687 ; Display ZH-L16-GF low/high model. | |
688 deco_show_plan_m1: | |
689 TEXT_SMALL .0,.130, tZHL16GF | |
690 WIN_SMALL .14,.155 | |
691 PUTC "," | |
692 movff char_I_GF_Low_percentage,lo | 533 movff char_I_GF_Low_percentage,lo |
693 output_99x | 534 output_99x |
694 STRCAT "%/" | 535 STRCAT "/" |
695 movff char_I_GF_High_percentage,lo | 536 movff char_I_GF_High_percentage,lo |
696 output_99x | 537 output_99x |
538 STRCAT_PRINT "" | |
539 | |
697 deco_show_plan_m2: | 540 deco_show_plan_m2: |
698 STRCAT_PRINT "%" | 541 ;---- Display Deco Mode |
699 | 542 WIN_SMALL .0,.155 |
543 lfsr FSR2,buffer | |
544 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR | |
545 call TFT_display_decotype_surface1 | |
546 btfss FLAG_ccr_mode ; current dive mode = CCR ? | |
547 bra deco_show_plan2c ; NO - branch | |
548 WIN_SMALL .25,.155 | |
549 STRCPY "SP:" ; output setpoint used for calculation | |
550 movff opt_sim_setpoint_number,lo | |
551 bsf leftbind | |
552 output_8 | |
553 bcf leftbind | |
554 STRCAT_PRINT "" | |
555 | |
556 deco_show_plan2c: | |
700 ;---- Display TTS result | 557 ;---- Display TTS result |
701 WIN_SMALL .0,.180 | 558 WIN_SMALL .0,.180 |
702 STRCPY_TEXT tTTS | 559 STRCPY_TEXT tTTS |
703 STRCAT ": " | 560 STRCAT ": " |
704 | |
705 movff int_O_ascenttime+0,lo | 561 movff int_O_ascenttime+0,lo |
706 movff int_O_ascenttime+1,hi | 562 movff int_O_ascenttime+1,hi |
707 bsf leftbind | 563 bsf leftbind |
708 output_16 | 564 output_16 |
565 bcf leftbind | |
709 STRCAT_PRINT "'" | 566 STRCAT_PRINT "'" |
710 | 567 |
711 ;---- Display CNS result | 568 ;---- Display CNS result |
712 WIN_TOP .205 | 569 WIN_TOP .205 |
713 STRCPY_TEXT tCNS2 ; "CNS:" | 570 STRCPY_TEXT tCNS2 ; "CNS:" |
714 movff int_O_CNS_fraction+0,lo | 571 movff int_O_CNS_fraction+0,lo |
715 movff int_O_CNS_fraction+1,hi | 572 movff int_O_CNS_fraction+1,hi |
716 output_16_3 ; limit to 999 and display only (0-999) | 573 TFT_color_code warn_cns ; Color-code CNS output |
717 STRCAT "%\x92" ; "->" | 574 bsf leftbind |
718 movff decoplan_CNS+0,lo | 575 output_16_3 ; limit to 999 and display only (0-999) |
719 movff decoplan_CNS+1,hi | 576 bcf leftbind |
720 output_16_3 ; limit to 999 and display only (0-999) | 577 STRCAT "%\x92" ; "->" |
578 movff int_O_normal_CNS_fraction+0,lo | |
579 movff int_O_normal_CNS_fraction+1,hi | |
580 TFT_color_code warn_cns ; Color-code CNS output | |
581 bsf leftbind | |
582 output_16_3 ; limit to 999 and display only (0-999) | |
583 bcf leftbind | |
721 STRCAT_PRINT "%" | 584 STRCAT_PRINT "%" |
585 call TFT_standard_color | |
722 | 586 |
723 ;---- Loop through pages | 587 ;---- Loop through pages |
724 deco_show_plan_1: | 588 deco_show_plan_1: |
589 ; Clear the complete stop result column: | |
590 WIN_BOX_BLACK .0, .239, .80, .159 ; top, bottom, left, right | |
591 | |
725 rcall deco_show_plan_page | 592 rcall deco_show_plan_page |
726 incf decoplan_page,F | 593 incf decoplan_page,F |
727 | |
728 call logbook_preloop_tasks | 594 call logbook_preloop_tasks |
729 deco_show_plan_2: | 595 deco_show_plan_2: |
730 btfsc switch_right | 596 btfsc switch_right |
731 bra deco_show_plan_3 | 597 bra deco_show_plan_3 |
732 btfsc switch_left | 598 btfsc switch_left |
733 return ; Return to simulator menu | 599 return ; Return to simulator menu |
734 call log_screendump_and_onesecond ; Check if we need to make a screenshot and check for new second | 600 call log_screendump_and_onesecond ; Check if we need to make a screen shot and check for new second |
735 btfsc sleepmode ; Timeout? | 601 btfsc sleepmode ; Timeout? |
736 goto restart | 602 goto restart |
737 bra deco_show_plan_2 | 603 bra deco_show_plan_2 |
738 | 604 |
739 deco_show_plan_3: | 605 deco_show_plan_3: |
740 btfss decoplan_last_ceiling_shown | 606 btfss decoplan_last_ceiling_shown |
741 bra deco_show_plan_1 | 607 bra deco_show_plan_1 |
742 ; All stops shown | 608 ; All stops shown |
743 | 609 |
744 ;---- In CCR mode, compute a BAILOUT decoplan --------------------------------- | 610 ;---- In CCR and pSCR mode, compute a BAILOUT deco plan ----------------------- |
611 | |
745 banksel common | 612 banksel common |
746 btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | 613 movff char_O_deco_status,WREG ; get deco calculation status |
747 bra simulator_show_decoplan5_0 ; NO: normal OC mode: just display | 614 btfss WREG,DECO_MODE_LOOP_FLAG ; check if in CCR or pSCR mode |
748 | 615 bra simulator_show_decoplan5_0 ; NO - normal OC mode: just display |
749 btfsc is_bailout ; ALREADY in bailout mode ? | 616 bsf is_bailout ; YES - redo 2nd deco-plan in bailout mode |
750 bra simulator_show_decoplan5_0 ; YES: alreay BAIL plan: display gas | 617 rcall deco_planer_redo ; redo plan computation |
751 | 618 |
752 ; Redo 2nd deco-plann, in bailout mode: | 619 btfss decoplan_abort ; shall we abort? |
753 bsf is_bailout ; Set special bailout mode. | 620 bra deco_show_plan ; NO - display bailout stops |
754 rcall deco_planer_redo ; Redo plan computation | 621 return ; YES |
755 | 622 |
756 movff char_I_setpoint_cbar+0,char_I_const_ppO2 | |
757 bra deco_show_plan ; and display bailout stops | |
758 | 623 |
759 ;---- In OC+BAIL modes, show the gas Usage special page ----------------------- | 624 ;---- In OC+BAIL modes, show the gas Usage special page ----------------------- |
760 simulator_show_decoplan5_0: | 625 simulator_show_decoplan5_0: |
761 bcf is_bailout ; Back to normal | 626 |
762 bcf ccr_diluent_setup ; init for OC/Bailout | |
763 | |
764 ; Make sure to pass first gas | |
765 call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG | |
766 incf WREG,f ; gas 1..5 | |
767 movff WREG,char_I_first_gas ; Copy for compatibility | |
768 | |
769 ; Compute gas consumption for each tank. | |
770 extern deco_gas_volumes | |
771 call deco_gas_volumes | |
772 movlb .1 | 627 movlb .1 |
773 | 628 |
774 ; Clear the complete stop result column: | 629 ; Clear the complete stop result column: |
775 WIN_BOX_BLACK .0, .239, .80, .159 ; top, bottom, left, right | 630 WIN_BOX_BLACK .0, .239, .80, .159 ; top, bottom, left, right |
776 | 631 |
783 call TFT_standard_color | 638 call TFT_standard_color |
784 | 639 |
785 simulator_show_decoplan5_loop: | 640 simulator_show_decoplan5_loop: |
786 movff wait_temp,PRODL ; Copy to PRODL first | 641 movff wait_temp,PRODL ; Copy to PRODL first |
787 incf wait_temp,F ; Increment gas # | 642 incf wait_temp,F ; Increment gas # |
643 | |
644 movff wait_temp,WREG | |
645 rcall simulator_color_gas ; set output color according to gas (number 1-5 in WREG) | |
646 | |
788 lfsr FSR2,buffer | 647 lfsr FSR2,buffer |
789 bsf short_gas_decriptions | 648 bsf short_gas_decriptions |
790 bsf divemode ; Tweak "customview_show_mix:" | 649 bsf divemode ; Tweak "customview_show_mix:" |
791 call gaslist_strcat_gas ; Input: PRODL : gas number (0..4), Output: "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2 | 650 call gaslist_strcat_gas ; Input: PRODL : gas number (0..4), Output: "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2 |
792 bcf divemode ; Tweak "customview_show_mix:" | 651 bcf divemode ; Tweak "customview_show_mix:" |
795 addwf waitms_temp,F ; Increase row position | 654 addwf waitms_temp,F ; Increase row position |
796 movff waitms_temp,win_top ; Set Row | 655 movff waitms_temp,win_top ; Set Row |
797 | 656 |
798 movff POSTINC0,lo ; Read (16bit) result, low first, | 657 movff POSTINC0,lo ; Read (16bit) result, low first, |
799 movff POSTINC0,hi ; then high. | 658 movff POSTINC0,hi ; then high. |
800 movf lo,W ; Null ? | 659 |
801 iorwf hi,W | 660 movf lo,W |
802 | |
803 movf lo,W ; == 65535 (saturated ?) | |
804 andwf hi,W | 661 andwf hi,W |
805 incf WREG | 662 incf WREG ; > 65535? |
806 bnz simulator_show_decoplan5_2 | 663 bnz simulator_show_decoplan5_2 ; NO |
807 call TFT_attention_color | 664 STRCAT_PRINT ">65500" ; YES |
808 STRCAT_PRINT ":xxxx.x" | |
809 call TFT_standard_color | |
810 bra simulator_show_decoplan5_1 | 665 bra simulator_show_decoplan5_1 |
811 | 666 |
812 simulator_show_decoplan5_2: | 667 simulator_show_decoplan5_2: |
813 PUTC ":" | 668 PUTC ":" |
814 bsf leftbind | 669 bsf leftbind |
815 output_16 ; No decimal anymore. | 670 output_16 ; No decimal anymore. |
816 bcf leftbind | 671 bcf leftbind |
817 STRCAT_PRINT "" ; No unit: can be bars or litters. | 672 STRCAT_PRINT "" ; No unit: can be bars or litters. |
818 | 673 |
819 ; Loop for all 5 gas | 674 ; Loop for all 5 gas |
820 simulator_show_decoplan5_1: | 675 simulator_show_decoplan5_1: |
821 movlw d'5' ; list all five gases | 676 movlw d'5' ; list all five gases |
822 cpfseq wait_temp ; All gases shown? | 677 cpfseq wait_temp ; All gases shown? |
823 bra simulator_show_decoplan5_loop ; No | 678 bra simulator_show_decoplan5_loop ; No |
824 | 679 |
825 WIN_COLOR color_greenish | 680 WIN_COLOR color_greenish |
826 WIN_SMALL .80,.25 | 681 WIN_SMALL .80,.25 |
827 | 682 STRCPY_TEXT tGasUsage ; OC: "Gas Usage" |
828 ; btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
829 ; bra simulator_show_decoplan5_4 ; YES: This is bailout mode | |
830 | |
831 STRCPY_TEXT tGasUsage ; OC: "Gas Usage" | |
832 ; bra simulator_show_decoplan5_5 | |
833 | |
834 ;simulator_show_decoplan5_4: | |
835 ; STRCPY_TEXT tDiveBailout ; CCR: "Bailout" | |
836 | |
837 ;simulator_show_decoplan5_5: | |
838 STRCAT_PRINT ":" | 683 STRCAT_PRINT ":" |
839 call TFT_standard_color | 684 call TFT_standard_color |
840 | |
841 call logbook_preloop_tasks | 685 call logbook_preloop_tasks |
686 | |
842 simulator_show_decoplan5_3: | 687 simulator_show_decoplan5_3: |
843 btfsc switch_right | 688 btfss switch_right |
689 bra simulator_show_decoplan5_3a | |
690 bcf switch_right | |
691 clrf decoplan_page | |
692 bra deco_show_plan_1 ; toggle between stops plan and gas usage | |
693 simulator_show_decoplan5_3a: | |
694 btfss switch_left | |
695 bra simulator_show_decoplan5_4 | |
696 bcf is_bailout ; Back to normal | |
697 bcf ccr_diluent_setup ; init for OC/Bailout | |
844 return ; Return to simulator menu | 698 return ; Return to simulator menu |
845 btfsc switch_left | 699 |
846 return ; Return to simulator menu | 700 simulator_show_decoplan5_4: |
847 call log_screendump_and_onesecond ; Check if we need to make a screenshot and check for new second | 701 call log_screendump_and_onesecond ; Check if we need to make a screen shot and check for new second |
848 btfsc sleepmode ; Timeout? | 702 btfsc sleepmode ; Timeout? |
849 goto restart | 703 goto restart |
850 bra simulator_show_decoplan5_3 | 704 bra simulator_show_decoplan5_3 |
851 | 705 |
706 | |
707 simulator_color_gas: ; set output color dependent on gas (1-5, in WREG) | |
708 movwf tft_temp1 ; used in TFT_set_color anyway | |
709 dcfsnz tft_temp1,F | |
710 movlw color_white ; color for Gas 1 | |
711 dcfsnz tft_temp1,F | |
712 movlw color_green ; color for Gas 2 | |
713 dcfsnz tft_temp1,F | |
714 movlw color_red ; Color for Gas 3 | |
715 dcfsnz tft_temp1,F | |
716 movlw color_yellow ; color for Gas 4 | |
717 dcfsnz tft_temp1,F | |
718 movlw color_cyan ; color for Gas 5 | |
719 goto TFT_set_color ; set color and return... | |
720 | |
852 ;============================================================================= | 721 ;============================================================================= |
853 ; | 722 ; |
854 global do_demo_divemode | 723 global do_demo_divemode |
855 do_demo_divemode: | 724 do_demo_divemode: |
856 extern option_save_all | 725 extern option_save_all |
857 call option_save_all ; Save all settings into EEPROM before starting simulation | 726 call option_save_all ; Save all settings into EEPROM before starting simulation |
858 call deco_push_tissues_to_vault | 727 call deco_push_tissues_to_vault |
859 banksel common ; Bank1 | 728 banksel common ; Bank1 |
860 | 729 |
861 bsf restore_deco_data ; Restore tissue and CNS after sim | 730 ; +++ COMMENTED OUT FOR TESTING PURPOSE ONLY !!! +++ |
862 | 731 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++ |
863 bcf pressure_refresh | 732 bsf restore_deco_data ; Restore tissue and CNS after simulator use |
864 btfss pressure_refresh ; Wait for sensor | 733 |
865 bra $-2 | 734 bcf pressure_refresh |
866 | 735 btfss pressure_refresh ; Wait for sensor |
867 bsf simulatormode_active ; Set Flag | 736 bra $-2 |
737 | |
738 bsf simulatormode_active ; Set Flag | |
868 ; Compute dive ambient conditions | 739 ; Compute dive ambient conditions |
869 banksel char_I_bottom_depth | 740 banksel char_I_bottom_depth |
870 movf char_I_bottom_depth,W | 741 movf char_I_bottom_depth,W |
871 mullw .100 | 742 mullw .100 |
872 movff PRODL,rel_pressure+0 | 743 movff PRODL,rel_pressure+0 |
876 movff WREG,sim_pressure+0 | 747 movff WREG,sim_pressure+0 |
877 movlw HIGH(.1000) | 748 movlw HIGH(.1000) |
878 addwfc PRODH,W | 749 addwfc PRODH,W |
879 movff WREG,sim_pressure+1 | 750 movff WREG,sim_pressure+1 |
880 | 751 |
881 banksel common ; Bank1 | 752 banksel common ; Bank1 |
882 bsf divemode | 753 bsf divemode |
883 goto diveloop ; Switch into Divemode! | 754 goto diveloop ; Switch into Divemode! |
884 | 755 |
885 | 756 |
886 END | 757 END |