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