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