Mercurial > public > hwos_code
annotate src/simulator.asm @ 631:185ba2f91f59
3.09 beta 1 release
author | heinrichsweikamp |
---|---|
date | Fri, 28 Feb 2020 15:45:07 +0100 |
parents | cd58f7fc86db |
children | 4050675965ea |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
631 | 3 ; File simulator.asm combined next generation V3.08.8 |
0 | 4 ; |
623 | 5 ; Deco Calculator |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
582 | 10 ; 2011-07-09 : [jDG] Creation... |
0 | 11 |
582 | 12 #include "hwos.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,... | |
0 | 17 #include "start.inc" |
18 #include "divemode.inc" | |
623 | 19 #include "sleepmode.inc" |
0 | 20 #include "math.inc" |
21 #include "eeprom_rs232.inc" | |
50 | 22 #include "tft_outputs.inc" |
298
2fe34fc0e2ae
new submenu for gas consumption, show actual mix instead of GAS1-GAS5 in deco planner
heinrichsweikamp
parents:
296
diff
changeset
|
23 #include "gaslist.inc" |
623 | 24 #include "surfmode.inc" |
25 #include "wait.inc" | |
0 | 26 |
623 | 27 |
582 | 28 extern deco_push_tissues_to_vault |
29 extern deco_calc_dive_interval | |
30 extern deco_calc_hauptroutine | |
31 extern deco_pull_tissues_from_vault | |
623 | 32 extern TFT_decotype_logbook |
582 | 33 extern do_return_demo_planner |
631 | 34 extern convert_meter_to_feet |
604 | 35 extern dive_boot_oc |
631 | 36 extern get_first_gas_to_WREG |
623 | 37 |
38 IFDEF _ccr_pscr | |
604 | 39 extern dive_boot_cc |
631 | 40 extern get_first_dil_to_WREG |
623 | 41 ENDIF |
560 | 42 |
0 | 43 |
623 | 44 ;---- Private local Variables ------------------------------------------------- |
0 | 45 |
628 | 46 CBLOCK local3 ; max size is 16 Byte !!! |
582 | 47 decoplan_index ; within each page |
48 decoplan_gindex ; global index | |
623 | 49 decoplan_last ; depth of last stop |
50 decoplan_flags ; private flags | |
582 | 51 decoplan_page ; page number |
52 decoplan_warnings ; deco engine warnings | |
623 | 53 gas_index ; counter for looping through the gases |
54 output_row ; used for positioning of the results output | |
628 | 55 real_CNS ; real CNS value from before simulated dive |
582 | 56 ENDC ; used: 8 byte, remaining: 8 byte |
57 | |
623 | 58 |
59 ;---- Private local Flags ---------------------------------------------------- | |
560 | 60 |
623 | 61 #define decoplan_abort decoplan_flags,0 ; =1: deco calculations were aborted |
62 #define decoplan_last_stop_shown decoplan_flags,1 ; =1: last deco stop is shown | |
63 #define decoplan_pressures_shown decoplan_flags,2 ; =1: show gas volumes in bar as per tank sizes | |
64 #define decoplan_overflow decoplan_flags,3 ; =1: result > 999 | |
65 #define decoplan_toggleflag decoplan_flags,4 ; used to show calculation progress | |
66 ; decoplan_flags,5 ; --- unused | |
67 ; decoplan_flags,6 ; --- unused | |
68 ; decoplan_flags,7 ; --- unused | |
560 | 69 |
604 | 70 |
623 | 71 simulator CODE |
604 | 72 |
623 | 73 ;----------------------------------------------------------------------------- |
604 | 74 |
623 | 75 ;============================================================================= |
76 ; Deco Calculator Main Function | |
77 ; | |
582 | 78 global do_demo_planner |
0 | 79 do_demo_planner: |
604 | 80 btfsc FLAG_gauge_mode ; in gauge mode? |
81 bra do_demo_planner_exit ; YES - abort | |
623 | 82 btfsc FLAG_apnoe_mode ; in apnea mode? |
604 | 83 bra do_demo_planner_exit ; YES - abort |
623 | 84 |
85 clrf decoplan_flags ; clear all local flags | |
86 bsf simulatormode ; activate simulator mode | |
87 bsf reset_timebase ; request ISR to reset the timebase | |
88 ; btfsc reset_timebase ; has the ISR confirmed reset of the timebase? | |
89 ; bra $-2 ; NO - not yet, loop waiting for the ISR | |
90 call deco_push_tissues_to_vault ; back-up the state of the real tissues (C-code) | |
91 banksel common ; back to bank common | |
92 | |
628 | 93 MOVII int_O_CNS_current,real_CNS ; memorize real CNS value from before simulated dive |
94 | |
623 | 95 rcall deco_calculate ; calculate deco plan |
628 | 96 |
623 | 97 btfss decoplan_abort ; was the deco plan calculation aborted? |
98 rcall deco_results ; NO - show results | |
99 | |
100 movff simulator_time,char_I_dive_interval ; get the deco calculator runtime | |
101 call deco_pull_tissues_from_vault ; restore the status of the real tissues (C-code) | |
102 call deco_calc_dive_interval ; catch up with tissue desaturation (C-code) | |
103 call deco_calc_desaturation_time ; calculate desaturation and no-fly/no-altitude time after catch-up (C-code) | |
104 banksel common ; back to bank common | |
105 | |
106 bcf switch_left ; clear left button event (may be left over from abort/exit) | |
107 bcf simulatormode ; terminate simulator mode | |
108 bsf reset_timebase ; request ISR to reset the timebase | |
109 ; btfsc reset_timebase ; has the ISR confirmed reset of timebase? | |
110 ; bra $-2 ; NO - not yet, loop waiting for the ISR | |
111 | |
112 btfsc divemode ; shall go into dive mode? | |
113 goto restart ; YES - goto restart which will dispatch further on to dive mode | |
114 | |
115 btfss trigger_timeout ; timeout on any button press? | |
116 bra do_demo_planner_exit ; NO - take normal exit into surface menu | |
117 bcf trigger_timeout ; YES - clear timeout flag | |
118 bcf restart_fast ; - set next restart to be done slow, i.e. with logos | |
119 goto sleeploop ; - goto sleep mode | |
120 | |
604 | 121 do_demo_planner_exit: |
623 | 122 goto do_return_demo_planner ; return to simulator menu |
0 | 123 |
124 | |
623 | 125 ;============================================================================= |
126 ; Calculate the Deco Plan | |
127 ; | |
128 deco_calculate: | |
129 call request_speed_fastest ; request CPU speed change to fastest speed | |
130 call TFT_ClearScreen ; clear screen to show that calculator is starting up | |
131 | |
132 ; initialization of the deco engine | |
133 btfsc update_surface_pressure ; is there a pending surface pressure update? | |
134 bra $-2 ; YES - loop waiting for the ISR to kick in | |
135 | |
631 | 136 ; calculate absolute pressure at selected depth |
623 | 137 movff char_I_bottom_depth,WREG ; get selected depth in meters |
631 | 138 movwf depth_meter ; store depth for check_gas_best code |
139 | |
140 movwf xA+0 ; copy depth in [m] to xA, low byte | |
141 clrf xA+1 ; clear xA, high byte | |
142 | |
143 movff opt_salinity,WREG ; get salinity setting (0 - 4 %) | |
144 addlw d'100' ; add density of fresh water (1.00 kg/l) | |
145 mullw .100 ; multiply by 100 to counteract the x 100 with the freshwater conversion factor | |
146 MOVII PRODL,xB ; copy result to xB | |
147 call mult16x16 ; xC:4 = xA:2 * xB:2 | |
148 | |
149 MOVLI .102,xB ; load conversion factor x 100 for fresh water (1.02 cm per each 1 mbar) | |
150 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder = relative pressure [mbar] at depth | |
151 | |
152 movff int_I_pres_surface+0,WREG ; get surface pressure, low byte | |
153 addwf xC+0,W ; add relative pressure, low byte | |
154 movff WREG,int_I_pres_respiration+0 ; store as absolute pressure, low byte | |
155 movff int_I_pres_surface+1,WREG ; get surface pressure, high byte | |
156 addwfc xC+1,W ; add relative pressure, high byte | |
157 movff WREG,int_I_pres_respiration+1 ; store as absolute pressure, high byte | |
582 | 158 |
628 | 159 ; compute absolute pressure / 10, will be used by check_gas_best |
160 MOVII int_I_pres_respiration,xA ; get absolute pressure at depth | |
161 MOVLI .10,xB ; divide by 10 | |
162 call div16x16 ; xC = xA / xB = absolute pressure / 10 | |
163 MOVII xC,pressure_abs_10 ; store result for later use | |
164 | |
165 ; set up gas / diluent to be used on bottom segment | |
166 clrf WREG ; reset the deco info vector / deco flag so that ... | |
167 movff WREG,char_O_deco_info ; ... check_gas_best will not pick any deco gases | |
631 | 168 |
169 call get_first_gas_to_WREG ; find first gas | |
170 movwf active_gas ; set first gas | |
628 | 171 IFDEF _ccr_pscr |
631 | 172 call get_first_dil_to_WREG ; find first diluent |
173 movwf active_dil ; set first diluent | |
628 | 174 ENDIF |
631 | 175 call check_gas_best ; check if first gas & dil are usable, if not replace by usable gas / dil |
628 | 176 |
177 IFDEF _ccr_pscr | |
178 btfsc FLAG_oc_mode ; in OC mode? | |
179 bra deco_calculate_0_oc ; YES - set up OC mode | |
180 ;bra deco_calculate_0_loop ; NO - set up CCR/pSCR mode | |
181 | |
182 deco_calculate_0_loop: | |
183 movf best_dil_number,W ; get best diluent into WREG | |
184 bz deco_calculate_0_error ; any usable diluent found? if NO do error handling | |
185 call setup_dil_registers ; set-up of diluent parameters for currently breathed diluent | |
186 call deco_setup_cc_diluents ; set-up of diluent list for deco calculations | |
187 bra deco_calculate_0_com ; continue with common part | |
188 ENDIF | |
189 | |
190 deco_calculate_0_oc: | |
191 movf best_gas_number,W ; get best gas into WREG | |
192 bz deco_calculate_0_error ; any usable gas found? if NO do error handling | |
193 call setup_gas_registers ; set-up of gas parameters of currently breathed gas | |
194 call deco_setup_oc_gases ; set-up of gas list for deco calculations | |
195 bra deco_calculate_0_com ; continue with common part | |
196 | |
197 deco_calculate_0_error: | |
198 call request_speed_normal ; request switch back to normal speed | |
199 WIN_COLOR color_red ; select color for error message | |
200 TEXT_SMALL .0, .80, tNoBottomGas1 ; print error message, line 1 | |
201 TEXT_SMALL .0, .105, tNoBottomGas2 ; print error message, line 2 | |
202 bsf decoplan_abort ; set abort flag | |
203 call wait_1s ; wait up to a full second | |
204 call wait_1s ; wait a full second | |
205 call wait_1s ; wait another full second | |
206 bcf switch_left ; clear potential button event | |
207 return ; return to deco calculator main function | |
208 | |
209 deco_calculate_0_com: | |
623 | 210 ; set deco stop settings |
631 | 211 movff opt_last_stop,char_I_last_stop_depth ; write last stop depth to deco engine |
0 | 212 |
623 | 213 ; set GF factors |
214 movff opt_GF_low, char_I_GF_Low_percentage ; load normal GF factors by default | |
215 movff opt_GF_high,char_I_GF_High_percentage ; ... | |
216 TSTOSS opt_sim_use_aGF ; shall use alternative GF factors in simulation? | |
217 bra deco_calculate_1 ; NO - keep normal GF factors | |
218 movff opt_aGF_low ,char_I_GF_Low_percentage ; YES - overwrite with alternative GF factors | |
219 movff opt_aGF_high,char_I_GF_High_percentage ; - ... | |
220 | |
221 deco_calculate_1: | |
582 | 222 |
623 | 223 IFDEF _ccr_pscr |
224 ; set char_I_const_ppO2 for pSCR/CCR mode | |
225 clrf WREG ; load coding for pSCR calculated ppO2 | |
226 btfsc FLAG_pscr_mode ; in pSCR mode? | |
227 movff WREG,char_I_const_ppO2 ; YES - configure pSCR computations to calculated ppO2 | |
228 btfss FLAG_ccr_mode ; in CCR mode? | |
229 bra deco_calculate_2 ; NO - skip next | |
230 movff opt_sim_setpoint_number,WREG ; YES - get selected setpoint | |
231 decf WREG,W ; - 1-5 -> 0-4 | |
631 | 232 lfsr FSR1,opt_setpoint_cbar ; - set base address of setpoint list |
623 | 233 movff PLUSW1,char_I_const_ppO2 ; - configure setpoint value |
234 ENDIF | |
0 | 235 |
623 | 236 deco_calculate_2: |
560 | 237 |
623 | 238 ; configure the deco engine - char_O_main_status |
239 movff char_O_main_status,hi ; get the configuration set by dive_boot_oc / dive_boot_cc | |
240 bsf hi,DECO_VOLUME_FLAG ; enable gas volume calculation | |
241 bsf hi,DECO_BOTTOM_FLAG ; include bottom segment into gas needs | |
631 | 242 |
243 IFDEF _cave_mode | |
623 | 244 bcf hi,DECO_CAVE_MODE ; cave mode not supported in deco calculator |
631 | 245 ENDIF |
246 | |
247 IFDEF _gas_contingency | |
248 bcf hi,DECO_GAS_CONTINGENCY ; disable gas contingency mode by default | |
249 TSTOSC opt_gas_contingency_sim ; gas contingency switched on? | |
250 bsf hi,DECO_GAS_CONTINGENCY ; YES - activate gas contingency mode | |
251 ENDIF | |
252 | |
623 | 253 bcf hi,DECO_EXTENDED_STOPS ; disable extended stops by default |
631 | 254 TSTOSC opt_ext_stops ; shall make extended stops? |
623 | 255 bsf hi,DECO_EXTENDED_STOPS ; YES - activate extended stops |
256 bcf hi,DECO_TR_FUNCTIONS ; execution of TR functions is not needed in deco calculator mode | |
257 movff hi,char_O_main_status ; bank-safe copy to deco engine control | |
560 | 258 |
623 | 259 ; configure the deco engine - char_O_deco_status |
260 movff char_O_deco_status,lo ; get the configuration set by dive_boot_oc / dive_boot_cc | |
261 bcf lo,DECO_START_NORM ; clear flag for normal plan mode | |
262 bcf lo,DECO_START_ALT ; clear flag for alternative plan mode | |
263 bsf lo,DECO_INITIALIZE ; set flag for once-per-dive initialization | |
628 | 264 bsf lo,DECO_CALCULATOR_MODE ; signal that the deco engine is run from the deco calculator |
623 | 265 bcf lo,DECO_BAILOUT_FLAG ; no gas switches before first deco stop |
631 | 266 bcf lo,DECO_DELAY_FLAG ; no delayed ascent |
623 | 267 movff lo,char_O_deco_status ; bank-safe copy to deco engine control |
268 | |
269 deco_calculate_redo: | |
270 | |
271 call request_speed_fastest ; request CPU speed change to fastest speed (again, if in redo) | |
560 | 272 |
623 | 273 ; show that the deco calculation is in progress |
274 call TFT_ClearScreen ; clear screen from last results | |
275 WIN_COLOR color_lightblue ; select color for abort label | |
276 TEXT_SMALL .1,.215, tAbort ; print abort label | |
277 WIN_COLOR color_white ; select color for title and progress outputs | |
278 TEXT_SMALL .0, .40, tCalculating ; print "Calculating..." | |
0 | 279 |
628 | 280 ; calculate the surface interval |
623 | 281 TSTOSS opt_surface_interval ; surface interval > 0 ? |
282 bra deco_calculate_bottom ; NO - continue with bottom segment | |
283 TEXT_SMALL .20,.75, tCalcSurfInter ; YES - print what we are doing | |
284 movff opt_surface_interval,char_I_dive_interval ; - copy surface interval to deco engine | |
285 call deco_calc_dive_interval ; - calculate surface interval (C-code) | |
286 banksel common ; - back to bank common | |
0 | 287 |
623 | 288 ; calculate the bottom segment |
289 deco_calculate_bottom: | |
290 ; advance tissues by selected bottom time, | |
291 ; char_I_sim_advance_time is cleared by deco engine after execution | |
292 movff char_I_bottom_time,char_I_sim_advance_time | |
293 | |
628 | 294 TEXT_SMALL .20,.100,tCalcBotSeg ; print what we are doing |
623 | 295 |
296 ; invoke the deco engine once to condition the real tissues | |
297 ; to their pressure state at the end of the bottom segment | |
298 call deco_calc_hauptroutine ; (C-code) | |
604 | 299 banksel common |
0 | 300 |
623 | 301 IFDEF _ccr_pscr |
302 ; conditional switch to bailout mode | |
303 btfss bailout_mode ; shall calculate a bailout plan? | |
304 bra deco_calculate_ascent ; NO - skip next | |
111 | 305 |
628 | 306 call dive_boot_oc ; YES - switch to OC mode, configure OC gases and switch to gas set as 'First' |
623 | 307 movff char_O_main_status,hi ; - bank-safe copy from deco engine control (main status) |
308 bcf hi,DECO_BOTTOM_FLAG ; - exclude bottom segment from gas needs, i.e. calculate ascent needs only | |
309 movff hi,char_O_main_status ; - bank-safe copy back to deco engine control | |
310 movff char_O_deco_status,lo ; - bank-safe copy from deco engine control (deco status) | |
311 bsf lo,DECO_BAILOUT_FLAG ; - allow gas switches before first deco stop | |
631 | 312 bsf lo,DECO_DELAY_FLAG ; - allow delayed ascent |
623 | 313 movff lo,char_O_deco_status ; - bank-safe copy back to deco engine control |
604 | 314 |
623 | 315 TEXT_SMALL .20,.125, tCalcBailout ; - print what we are doing |
316 ENDIF | |
0 | 317 |
623 | 318 ; calculate ascent |
319 deco_calculate_ascent: | |
320 movff char_O_deco_status,lo ; bank-safe copy from deco engine control | |
321 bsf lo,DECO_START_NORM ; start calculation of a normal plan | |
322 movff lo,char_O_deco_status ; bank-safe copy back to deco engine control | |
323 TEXT_SMALL .20,.150, tCalcAscent ; print what we are doing | |
324 deco_calculate_loop: | |
325 btfsc switch_left ; was the left button pressed? | |
326 bra deco_calculate_abort ; YES - set abort flag, do some clean-up and return | |
628 | 327 call deco_calc_hauptroutine ; NO - invoke the deco engine so that it can do the deco calculation (C-code) |
623 | 328 banksel common ; - back to bank common |
329 movff char_O_depth_sim,lo ; - get the depth reached (in meters) | |
628 | 330 WIN_SMALL .75,.150 ; - set output position |
631 | 331 |
332 TSTOSS opt_units ; check depth units | |
333 bra deco_calculate_loop_metric ; 0 - use Meters | |
334 ;bra deco_calculate_loop_imperial ; 1 - use Feet | |
335 | |
336 deco_calculate_loop_imperial: | |
337 call convert_meter_to_feet ; convert value in lo from [m] to [feet] | |
338 output_16_3 ; print depth reached | |
339 STRCAT_TEXT tFeets ; print unit (feet) | |
340 bra deco_calculate_loop_0 | |
341 | |
342 deco_calculate_loop_metric: | |
343 output_8 ; print depth reached (in meters) | |
344 STRCAT_TEXT tMeters ; print unit (meters) | |
345 ;bra deco_calculate_loop_0 ; continue | |
346 | |
347 deco_calculate_loop_0: | |
623 | 348 btg decoplan_toggleflag ; - toggle the toggle flag |
349 btfsc decoplan_toggleflag ; - toggle flag set? | |
350 bra deco_calculate_loop_1 ; YES - print ". " | |
351 STRCAT_PRINT " ." ; NO - print " ." | |
352 bra deco_calculate_loop_2 ; | |
353 deco_calculate_loop_1: ; | |
354 STRCAT_PRINT ". " ; | |
355 deco_calculate_loop_2: ; | |
356 movff char_O_deco_status,lo ; - get deco calculation status | |
357 btfss lo,DECO_COMPLETED_NORM ; - deco calculation completed? | |
358 bra deco_calculate_loop ; NO - loop | |
359 movff char_O_deco_warnings,decoplan_warnings; YES - copy warnings for later display | |
360 bra deco_calculate_finish ; - do some clean-up and return | |
361 deco_calculate_abort: | |
362 bcf switch_left ; clear button event | |
363 bsf decoplan_abort ; set abort flag | |
364 deco_calculate_finish: | |
365 goto request_speed_normal ; request switch back to normal speed and return to deco calculator main function | |
0 | 366 |
367 | |
368 ;----------------------------------------------------------------------------- | |
623 | 369 ; Draw a stop of the deco plan (simulator or dive) |
582 | 370 ; Inputs: lo = depth |
371 ; hi = minutes | |
372 ; win_top = line to draw on screen. | |
373 ; | |
374 ; Trashed: hi, lo, | |
375 ; win_height, win_leftx2, win_width, win_color*, | |
0 | 376 ; WREG, PROD, TBLPTR TABLAT. |
377 ; | |
378 deco_plan_show_stop: | |
623 | 379 ; print depth |
380 lfsr FSR2,char_O_deco_gas ; needed to be initialized here every time because... | |
381 movf decoplan_gindex,W ; ...FSR2 is also used for string operations | |
382 movff PLUSW2,WREG ; get current gas and copy it to WREG for color-coding | |
383 call TFT_color_code_gas ; set output color dependent on gas (1-5) | |
0 | 384 |
623 | 385 lfsr FSR2,buffer ; set up output buffer |
0 | 386 |
623 | 387 TSTOSS opt_units ; 0=Meter, 1=Feet |
388 bra deco_plan_show_nstd_stop_metric ; 0 - do metric | |
389 ; 1 - do imperial | |
390 movff hi,ul ; back-up hi (minutes) | |
604 | 391 WIN_LEFT .80 |
623 | 392 call convert_meter_to_feet ; convert value in lo from meters to feet |
393 output_16_3 ; limit output to 0...999 | |
604 | 394 STRCAT_PRINT "ft" |
623 | 395 movff ul,hi ; restore hi (minutes) |
582 | 396 bra deco_plan_show_nstd_stop_common |
0 | 397 |
398 deco_plan_show_nstd_stop_metric: | |
604 | 399 WIN_LEFT .85 |
623 | 400 output_8 ; outputs into postinc2 |
604 | 401 STRCAT_PRINT "m" |
582 | 402 |
0 | 403 deco_plan_show_nstd_stop_common: |
623 | 404 |
405 ; print duration | |
582 | 406 WIN_LEFT .135 |
407 lfsr FSR2,buffer | |
408 movff hi,lo | |
628 | 409 output_99dd ; stop entries are 99 minutes at max., prints double dots if duration is zero |
604 | 410 STRCAT_PRINT "'" |
0 | 411 |
623 | 412 ; draw the bar graph used for deco stops (lo = minutes) |
582 | 413 incf win_top,F |
414 movlw .19 | |
415 movwf win_height | |
416 movlw .118 | |
623 | 417 movwf win_leftx2 ; column left (0-159) |
418 MOVLI .16,win_width ; column max width | |
419 incf lo,W ; add 1 for a minimum visible active bargraph area | |
420 movwf win_bargraph ; set width of the active bargraph area | |
421 call TFT_box ; draw bargraph | |
0 | 422 |
623 | 423 ; restore win_top |
582 | 424 call TFT_standard_color |
623 | 425 decf win_top,F ; restore win_top |
582 | 426 return |
0 | 427 |
428 | |
429 ;----------------------------------------------------------------------------- | |
623 | 430 ; Display the deco plan (simulator) |
0 | 431 ; Inputs: char_O_deco_table (array of stop times, in minutes) |
432 ; decoplan_page = page number. | |
433 ; | |
623 | 434 deco_results_page: |
435 bcf win_invert ; reset invert flag | |
436 WIN_COLOR color_greenish | |
437 IFDEF _ccr_pscr | |
438 btfss bailout_mode ; bailout results? | |
439 bra deco_results_page_1 ; NO | |
440 TEXT_SMALL .80,.1, tDiveBailout ; YES | |
441 bra deco_results_page_2 | |
442 ENDIF | |
443 deco_results_page_1: | |
444 TEXT_SMALL .80,.1, tDivePlan | |
445 deco_results_page_2: | |
628 | 446 movff char_O_deco_info,WREG ; get the deco info vector |
631 | 447 btfsc WREG,deco_stops_norm ; are there deco stops? |
628 | 448 bra deco_plan_show_1 ; YES |
0 | 449 |
623 | 450 ;---- no deco -------------------------------------------------------- |
582 | 451 call TFT_standard_color |
623 | 452 TEXT_SMALL .80, .25, tNoDeco |
604 | 453 |
454 ; output of remaining NDL time | |
623 | 455 WIN_SMALL .80, .50 ; same line as bottom time |
628 | 456 PUTC "+" |
631 | 457 movff int_O_NDL_norm+0,lo ; get NDL time in normal plan |
628 | 458 bsf leftbind |
604 | 459 output_8 |
628 | 460 bcf leftbind |
604 | 461 PUTC "'" |
462 PUTC " " | |
628 | 463 STRCAT_TEXT_PRINT tNDLleft ; "NDL" |
604 | 464 |
623 | 465 bsf decoplan_last_stop_shown |
582 | 466 return |
0 | 467 |
623 | 468 ;---- deco stops --------------------------------------------------------- |
0 | 469 deco_plan_show_1: |
623 | 470 lfsr FSR0,char_O_deco_depth ; initialize indexed addressing |
631 | 471 lfsr FSR1,char_O_deco_time ; ... |
0 | 472 |
623 | 473 clrf decoplan_index ; start with index = 0 |
604 | 474 movlw .24 |
623 | 475 movwf win_top ; and row = 0 at position 24 |
0 | 476 |
623 | 477 ; read stop parameters, indexed by decoplan_index and decoplan_page |
478 movf decoplan_page,W ; decoplan_gindex = 6*decoplan_page + decoplan_index | |
479 mullw .8 ; 8 lines/page in deco plan | |
582 | 480 movf decoplan_index,W |
481 addwf PRODL,W | |
623 | 482 movwf decoplan_gindex ; --> decoplan_gindex |
0 | 483 |
623 | 484 bcf decoplan_last_stop_shown ; not done yet... |
0 | 485 |
486 deco_plan_show_2: | |
623 | 487 btfsc decoplan_gindex,5 ; reached table length (32) ? |
488 bra deco_plan_show_99 ; YES - done | |
0 | 489 |
623 | 490 ; read stop parameters, indexed by decoplan_index |
491 movf decoplan_gindex,W ; index | |
492 movff PLUSW0,lo ; char_O_deco_depth[decoplan_gindex] | |
493 movff PLUSW1,hi ; char_O_deco_time [decoplan_gindex] | |
582 | 494 movf lo,W |
623 | 495 bz deco_plan_show_99 ; depth == 0 -> done |
0 | 496 |
623 | 497 ; display the stop line |
582 | 498 rcall deco_plan_show_stop |
0 | 499 |
623 | 500 ; next |
582 | 501 movlw .24 |
623 | 502 addwf win_top,F ; row: += 24 |
503 incf decoplan_index,F ; local index += 1 | |
504 incf decoplan_gindex,F ; global index += 1 | |
0 | 505 |
623 | 506 ; max number of lines/page reached? |
507 movlw .8 ; 8 lines/page in deco plan | |
582 | 508 cpfseq decoplan_index |
623 | 509 bra deco_plan_show_2 ; NO - loop |
0 | 510 |
623 | 511 ; check if next stop is end-of-list? |
582 | 512 movf decoplan_gindex,W |
623 | 513 movf PLUSW0,W ; char_O_deco_depth[decoplan_gindex] |
514 bz deco_plan_show_99 ; end of list | |
0 | 515 |
582 | 516 call TFT_standard_color |
628 | 517 WIN_SMALL .135,.212 |
518 STRCAT_PRINT ">>>" | |
582 | 519 return |
0 | 520 |
521 deco_plan_show_99: | |
623 | 522 bsf decoplan_last_stop_shown ; nothing more in table to display |
523 call TFT_standard_color | |
582 | 524 return |
0 | 525 |
623 | 526 ;============================================================================= |
527 ; Show Deco Calculation Results | |
528 ; | |
529 deco_results: | |
582 | 530 call TFT_ClearScreen |
531 call TFT_standard_color | |
623 | 532 |
628 | 533 ; print interval |
582 | 534 WIN_SMALL .0,.25 |
623 | 535 STRCPY "Int. :" |
628 | 536 movff opt_surface_interval,lo |
582 | 537 output_8 |
538 STRCAT_PRINT "'" | |
628 | 539 |
540 ; print bottom time | |
582 | 541 WIN_SMALL .0,.50 |
542 STRCPY_TEXT tBtTm_short | |
543 movff char_I_bottom_time,lo | |
544 output_8 | |
545 STRCAT_PRINT "'" | |
628 | 546 |
547 ; print bottom depth | |
582 | 548 WIN_SMALL .0,.75 |
549 STRCPY_TEXT tDepth | |
550 PUTC ":" | |
551 movff char_I_bottom_depth,lo | |
631 | 552 |
553 TSTOSS opt_units ; check depth units | |
554 bra deco_results_metric ; 0 - use Meters | |
555 ;bra deco_results_imperial ; 1 - use Feet | |
556 | |
557 deco_results_imperial: | |
558 call convert_meter_to_feet ; convert value in lo from [m] to [feet] | |
559 output_16_3 ; print depth reached | |
560 STRCAT_TEXT tFeets ; print unit (feet) | |
561 bra deco_results_0 ; continue | |
562 | |
563 deco_results_metric: | |
564 output_8 ; print depth reached (in meters) | |
565 STRCAT_TEXT tMeters ; print unit (meters) | |
566 ;bra deco_results_0 ; continue | |
567 | |
568 deco_results_0: | |
569 STRCAT_PRINT "" ; finalize bottom depth output | |
628 | 570 |
571 ; print warnings or sat/dsat factors | |
572 WIN_SMALL .0,.105 | |
208
53771bd3d567
NEW: Show plan parameters in decoplan result page
heinrichsweikamp
parents:
197
diff
changeset
|
573 |
623 | 574 ; check for stop table overflow |
628 | 575 btfss decoplan_warnings,deco_plan_incomplete ; check if deco plan is incomplete |
623 | 576 bra deco_results_0a ; NO - skip |
577 | |
578 ; display overflow warning | |
579 call TFT_warning_color ; YES - show overflow warning | |
582 | 580 STRCAT_PRINT "incomplete" ; max 10 characters |
623 | 581 bra deco_results_m1 ; skip displaying sat/dsat factors |
582 | |
583 deco_results_0a: | |
582 | 584 |
623 | 585 IFDEF _helium |
586 ; check for IBCD warning | |
582 | 587 btfss decoplan_warnings,IBCD_warning_lock ; check if we have a locked IBCD warning |
623 | 588 bra deco_results_2b ; NO - skip |
589 | |
590 ; display IBCD warning | |
582 | 591 call TFT_attention_color ; YES - show IBCD warning |
592 STRCAT_PRINT "IBCD!" ; max 10 characters | |
623 | 593 bra deco_results_m1 ; skip displaying sat/dsat factors |
594 ENDIF | |
582 | 595 |
623 | 596 deco_results_2b: |
597 | |
598 ; display Sat/Desat factors --> omitted if there were warnings | |
582 | 599 STRCAT_PRINT "SD:" |
600 WIN_SMALL .25,.105 | |
601 movff char_I_saturation_multiplier,lo | |
602 output_8 | |
604 | 603 STRCAT "/" |
582 | 604 movff char_I_desaturation_multiplier,lo |
605 output_8 | |
606 STRCAT_PRINT "" | |
560 | 607 |
623 | 608 deco_results_m1: |
609 | |
582 | 610 call TFT_standard_color ; clean-up from warnings |
0 | 611 |
623 | 612 ; get model |
631 | 613 movff char_I_model,WREG ; 0: straight Buhlmann, 1: with GF |
623 | 614 iorwf WREG ; GF factors in use? |
615 bz deco_results_m2 ; NO | |
560 | 616 |
623 | 617 ; display GF low/high factors |
582 | 618 WIN_SMALL .0,.130 |
619 STRCAT_PRINT "GF:" | |
620 WIN_SMALL .25,.130 | |
621 movff char_I_GF_Low_percentage,lo | |
604 | 622 output_8 |
582 | 623 STRCAT "/" |
624 movff char_I_GF_High_percentage,lo | |
604 | 625 output_8 |
582 | 626 STRCAT_PRINT "" |
560 | 627 |
623 | 628 deco_results_m2: |
629 | |
630 ; display deco mode | |
582 | 631 WIN_SMALL .0,.155 |
632 lfsr FSR2,buffer | |
623 | 633 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR |
634 call TFT_decotype_logbook | |
635 | |
636 IFDEF _ccr_pscr | |
582 | 637 btfss FLAG_ccr_mode ; current dive mode = CCR ? |
623 | 638 bra deco_results_2c ; NO - skip |
582 | 639 WIN_SMALL .25,.155 |
640 STRCPY "SP:" ; output setpoint used for calculation | |
641 movff opt_sim_setpoint_number,lo | |
642 bsf leftbind | |
643 output_8 | |
644 bcf leftbind | |
645 STRCAT_PRINT "" | |
623 | 646 ENDIF |
0 | 647 |
623 | 648 deco_results_2c: |
649 | |
650 btfss FLAG_oc_mode ; current dive mode = OC ? | |
651 bra deco_results_2d ; NO - skip | |
631 | 652 TSTOSS opt_ext_stops ; YES - extended stops activated? |
623 | 653 bra deco_results_2d ; NO - skip |
654 WIN_SMALL .18,.155 ; YES - set position | |
655 STRCAT_PRINT "ext.Stop" ; - print notice | |
656 | |
657 deco_results_2d: | |
658 | |
659 ; display TTS result | |
582 | 660 WIN_SMALL .0,.180 |
661 STRCPY_TEXT tTTS | |
662 STRCAT ": " | |
623 | 663 MOVII int_O_TTS_norm,mpr |
582 | 664 bsf leftbind |
665 output_16 | |
666 bcf leftbind | |
667 STRCAT_PRINT "'" | |
0 | 668 |
623 | 669 ; display CNS result |
582 | 670 WIN_TOP .205 |
671 STRCPY_TEXT tCNS2 ; "CNS:" | |
628 | 672 MOVII real_CNS,mpr ; recall real CNS from before simulated dive |
604 | 673 call TFT_color_code_cns ; color-code CNS output |
582 | 674 bsf leftbind |
675 output_16_3 ; limit to 999 and display only (0-999) | |
676 bcf leftbind | |
677 STRCAT "%\x92" ; "->" | |
628 | 678 MOVII int_O_CNS_norm,mpr ; get CNS at end of simulated dive in normal plan |
604 | 679 call TFT_color_code_cns ; color-code CNS output |
582 | 680 bsf leftbind |
681 output_16_3 ; limit to 999 and display only (0-999) | |
682 bcf leftbind | |
683 STRCAT_PRINT "%" | |
684 call TFT_standard_color | |
685 | |
623 | 686 ; loop through deco plan pages |
687 deco_results_1: | |
688 clrf decoplan_page ; start from first page | |
689 bcf decoplan_pressures_shown ; when showing the gas needs, start with volumes (liter) | |
690 deco_results_1a: | |
628 | 691 WIN_BOX_BLACK .0, .239, .80, .159 ; clear the complete right part of the result column (top, bottom, left, right) |
623 | 692 rcall deco_results_page ; show a results page |
693 incf decoplan_page,F ; increment results page number | |
694 call reset_timeout_surfmode ; reset timeout | |
695 bcf switch_right ; clear left-over right button event | |
696 bcf switch_left ; clear left-over left button event | |
697 deco_results_2: | |
698 btfsc switch_right ; right button pressed? | |
699 bra deco_results_3 ; YES - show further results | |
700 btfsc switch_left ; left button pressed? | |
701 return ; YES - return to deco calculator main function | |
702 call housekeeping ; NO to both - handle screen dump request, timeout and need to enter dive mode | |
703 btfsc divemode ; shall go into dive mode? | |
704 bsf decoplan_abort ; YES - set abort flag | |
705 btfsc trigger_timeout ; timeout on any button press? | |
706 bsf decoplan_abort ; YES - set abort flag | |
707 btfss decoplan_abort ; shall abort? | |
708 bra deco_results_2 ; NO - loop | |
582 | 709 return ; YES |
560 | 710 |
623 | 711 deco_results_3: |
712 btfss decoplan_last_stop_shown ; was the last stop shown already? | |
713 bra deco_results_1a ; NO - loop | |
284
d1117b99fd99
preperations to compute gas consumtion in simulator
heinrichsweikamp
parents:
275
diff
changeset
|
714 |
623 | 715 IFDEF _ccr_pscr |
716 movff char_O_deco_status,WREG ; YES - get deco calculation status | |
717 btfss WREG,DECO_MODE_LOOP_FLAG ; - check if calculation was made for loop mode (CCR/pSCR) | |
718 bra deco_results_gas_volumes ; NO - normal OC mode or bailout mode, show gas needs | |
719 bsf bailout_mode ; YES - do a 2nd deco-plan in bailout mode | |
628 | 720 call deco_pull_tissues_from_vault ; - restore the status of the real tissues (C-code) |
721 banksel common ; - back to bank common | |
722 rcall deco_calculate_redo ; - redo complete deco calculation | |
623 | 723 btfss decoplan_abort ; - was the calculation aborted? |
724 bra deco_results ; NO - redo display of deco stops | |
725 return ; YES - return to deco calculator main function | |
726 ENDIF | |
284
d1117b99fd99
preperations to compute gas consumtion in simulator
heinrichsweikamp
parents:
275
diff
changeset
|
727 |
623 | 728 ;---- show the gas needs (OC and bailout only) --------------------------- |
729 deco_results_gas_volumes: | |
730 lfsr FSR0,int_O_gas_need_vol ; load base address of gas needs in volume | |
731 | |
732 deco_results_gas_common: | |
628 | 733 WIN_BOX_BLACK .0, .239, .80, .159 ; clear the complete right part of the result column (top, bottom, left, right) |
623 | 734 movlw .25 ; output row is 25 (fixed offset set here) + n*25 (line increment, see below) |
735 movwf output_row ; set fixed vertical offset for output row | |
604 | 736 WIN_LEFT .80 ; set column |
582 | 737 call TFT_standard_color |
623 | 738 clrf gas_index ; initialize gas counter |
739 bcf is_diluent_menu ; working on OC gases | |
604 | 740 |
623 | 741 deco_results_gas_loop: |
742 movff gas_index,PRODL ; copy gas index to PRODL (interface to gaslist_strcat_gas) | |
743 incf gas_index,F ; increment gas index | |
582 | 744 |
623 | 745 movf gas_index,W ; copy gas index to WREG for color-coding |
582 | 746 call TFT_color_code_gas ; set output color according to gas (1-5) |
560 | 747 |
631 | 748 lfsr FSR2,buffer ; set base address of output buffer |
623 | 749 bsf short_gas_descriptions ; configure gaslist_strcat_gas output format |
750 bsf divemode ; configure gaslist_strcat_gas output format | |
751 call gaslist_strcat_gas ; write "Nxlo", "Txlo/hi", "Air" or "O2" into output buffer | |
752 bcf divemode ; cleanup above | |
560 | 753 |
623 | 754 movlw .25 ; spacing between outputs |
755 addwf output_row,F ; increase row position | |
756 movff output_row,win_top ; set row position | |
582 | 757 |
623 | 758 movff POSTINC0,lo ; read gas volume low byte |
759 movff POSTINC0,hi ; high byte | |
760 | |
761 bcf decoplan_overflow ; no overflow in gas needs by default | |
762 | |
763 btfsc decoplan_pressures_shown ; results in bar? | |
764 bra deco_results_gas_volumes_1 ; YES | |
284
d1117b99fd99
preperations to compute gas consumtion in simulator
heinrichsweikamp
parents:
275
diff
changeset
|
765 |
623 | 766 ; output of gas needs in liter |
767 movf lo,W ; check if hi:lo = 65535: copy low byte to WREG | |
768 andwf hi,W ; and do a bitwise AND with the high byte | |
769 incfsz WREG ; add 1, result zero now? | |
770 bra deco_results_gas_volumes_2 ; NO - print volume | |
771 STRCAT_PRINT ">65500" ; YES - print ">65500" | |
772 bra deco_results_gas_volumes_3 ; - continue checking if all gases are shown | |
284
d1117b99fd99
preperations to compute gas consumtion in simulator
heinrichsweikamp
parents:
275
diff
changeset
|
773 |
623 | 774 ; output of gas needs in bar |
775 deco_results_gas_volumes_1: | |
776 btfsc hi,int_high_flag ; overflow in result? | |
777 bsf decoplan_overflow ; YES - remember it | |
778 bcf hi,int_high_flag ; clear flag for overflow in result | |
779 btfsc hi,int_warning_flag ; gas needs above available amount? | |
780 bsf win_invert ; YES - print in inverse | |
781 bcf hi,int_warning_flag ; clear flag for gas needs above available amount | |
782 bcf hi,int_attention_flag ; clear flag for gas needs close to available amount | |
783 bcf hi,int_invalid_flag ; clear flag for invalid data | |
784 bcf hi,int_is_zero ; clear flag for zero | |
582 | 785 |
623 | 786 deco_results_gas_volumes_2: |
787 PUTC ":" ; print ":" | |
788 output_16 ; print 16 bit number | |
789 movlw '>' ; load coding of ">" sign into WREG | |
790 btfsc decoplan_overflow ; overflow in result? | |
791 movff WREG,buffer+.7 ; YES - place ">" before number | |
792 STRCAT_PRINT "" ; finalize output | |
793 bcf win_invert ; back to none-inverse printing | |
582 | 794 |
623 | 795 deco_results_gas_volumes_3: |
796 movlw NUM_GAS ; 5 gases to show | |
797 cpfseq gas_index ; all gases shown? | |
798 bra deco_results_gas_loop ; NO - loop | |
799 | |
800 WIN_COLOR color_greenish ; set color | |
801 TEXT_SMALL .80,.01,tGasUsage ; "Gas Usage" | |
582 | 802 |
623 | 803 btfsc decoplan_pressures_shown ; results shown in bar? |
804 bra deco_results_gas_volumes_4 ; YES | |
805 TEXT_SMALL .120,.25,tLiterLong ; NO - in Liter then | |
806 bra deco_results_gas_volumes_5 ; - continue with initialization of housekeeping | |
604 | 807 |
623 | 808 deco_results_gas_volumes_4: |
809 TEXT_SMALL .120,.25,tbar ; " bar" (with leading space) | |
284
d1117b99fd99
preperations to compute gas consumtion in simulator
heinrichsweikamp
parents:
275
diff
changeset
|
810 |
623 | 811 deco_results_gas_volumes_5: |
812 call TFT_standard_color ; revert to standard color | |
813 call reset_timeout_surfmode ; reset timeout | |
814 bcf switch_right ; clear left-over right button event | |
815 bcf switch_left ; clear left-over left button event | |
816 deco_results_gas_volumes_6: | |
817 btfsc switch_right ; right button pressed? | |
818 bra deco_results_gas_volumes_7 ; YES - show results in bar or restart with deco stops again | |
819 btfsc switch_left ; left button pressed? | |
820 return ; YES - return to deco calculator main function | |
821 call housekeeping ; NO to both - handle screen dump request, timeout and need to enter dive mode | |
822 btfsc divemode ; shall go into dive mode? | |
823 bsf decoplan_abort ; YES - set abort flag | |
824 btfsc trigger_timeout ; timeout on any button press? | |
825 bsf decoplan_abort ; YES - set abort flag | |
826 btfss decoplan_abort ; shall abort? | |
827 bra deco_results_gas_volumes_6 ; NO - loop | |
828 return ; YES | |
560 | 829 |
623 | 830 deco_results_gas_volumes_7: |
831 btfsc decoplan_pressures_shown ; results shown in bar? | |
832 bra deco_results_1 ; YES - show deco stops again | |
833 bsf decoplan_pressures_shown ; NO - but now | |
631 | 834 lfsr FSR0,int_O_gas_need_pres ; - set base address of gas needs in bar |
623 | 835 bra deco_results_gas_common ; - re-run gas needs output in pressure mode |
836 | |
0 | 837 |
582 | 838 END |