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