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