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