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