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