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