comparison 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
comparison
equal deleted inserted replaced
630:4cd81bdbf15c 631:185ba2f91f59
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File simulator.asm combined next generation V3.04.3 3 ; File simulator.asm combined next generation V3.08.8
4 ; 4 ;
5 ; Deco Calculator 5 ; Deco Calculator
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
29 extern deco_calc_dive_interval 29 extern deco_calc_dive_interval
30 extern deco_calc_hauptroutine 30 extern deco_calc_hauptroutine
31 extern deco_pull_tissues_from_vault 31 extern deco_pull_tissues_from_vault
32 extern TFT_decotype_logbook 32 extern TFT_decotype_logbook
33 extern do_return_demo_planner 33 extern do_return_demo_planner
34 extern dive_boot_oc_bail 34 extern convert_meter_to_feet
35 extern dive_boot_oc 35 extern dive_boot_oc
36 extern get_first_gas_to_WREG
36 37
37 IFDEF _ccr_pscr 38 IFDEF _ccr_pscr
38 extern dive_boot_cc 39 extern dive_boot_cc
40 extern get_first_dil_to_WREG
39 ENDIF 41 ENDIF
40 42
41 43
42 ;---- Private local Variables ------------------------------------------------- 44 ;---- Private local Variables -------------------------------------------------
43 45
129 131
130 ; initialization of the deco engine 132 ; initialization of the deco engine
131 btfsc update_surface_pressure ; is there a pending surface pressure update? 133 btfsc update_surface_pressure ; is there a pending surface pressure update?
132 bra $-2 ; YES - loop waiting for the ISR to kick in 134 bra $-2 ; YES - loop waiting for the ISR to kick in
133 135
134 ; set absolute pressure at selected depth 136 ; calculate absolute pressure at selected depth
135 movff char_I_bottom_depth,WREG ; get selected depth in meters 137 movff char_I_bottom_depth,WREG ; get selected depth in meters
136 movwf depth_meter ; set depth for check_gas_best code 138 movwf depth_meter ; store depth for check_gas_best code
137 mullw .100 ; multiply depth with 100 to get relative pressure in mbar 139
138 movff int_I_pres_surface+0,WREG ; low byte - get surface pressure to WREG 140 movwf xA+0 ; copy depth in [m] to xA, low byte
139 addwf PRODL,W ; - add relative pressure 141 clrf xA+1 ; clear xA, high byte
140 movff WREG,int_I_pres_respiration+0 ; - store as absolute pressure at depth 142
141 movff int_I_pres_surface+1,WREG ; high byte - get surface pressure to WREG 143 movff opt_salinity,WREG ; get salinity setting (0 - 4 %)
142 addwfc PRODH,W ; - add relative pressure 144 addlw d'100' ; add density of fresh water (1.00 kg/l)
143 movff WREG,int_I_pres_respiration+1 ; - store as absolute pressure at depth 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
144 158
145 ; compute absolute pressure / 10, will be used by check_gas_best 159 ; compute absolute pressure / 10, will be used by check_gas_best
146 MOVII int_I_pres_respiration,xA ; get absolute pressure at depth 160 MOVII int_I_pres_respiration,xA ; get absolute pressure at depth
147 MOVLI .10,xB ; divide by 10 161 MOVLI .10,xB ; divide by 10
148 call div16x16 ; xC = xA / xB = absolute pressure / 10 162 call div16x16 ; xC = xA / xB = absolute pressure / 10
149 MOVII xC,pressure_abs_10 ; store result for later use 163 MOVII xC,pressure_abs_10 ; store result for later use
150 164
151 ; set up gas / diluent to be used on bottom segment 165 ; set up gas / diluent to be used on bottom segment
152 clrf WREG ; reset the deco info vector / deco flag so that ... 166 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 167 movff WREG,char_O_deco_info ; ... check_gas_best will not pick any deco gases
168
169 call get_first_gas_to_WREG ; find first gas
170 movwf active_gas ; set first gas
154 IFDEF _ccr_pscr 171 IFDEF _ccr_pscr
155 clrf active_dil ; invalidate active diluent 172 call get_first_dil_to_WREG ; find first diluent
156 ENDIF 173 movwf active_dil ; set first diluent
157 clrf active_gas ; invalidate active gas 174 ENDIF
158 call check_gas_best ; determine best diluent and/or gas 175 call check_gas_best ; check if first gas & dil are usable, if not replace by usable gas / dil
159 176
160 IFDEF _ccr_pscr 177 IFDEF _ccr_pscr
161 btfsc FLAG_oc_mode ; in OC mode? 178 btfsc FLAG_oc_mode ; in OC mode?
162 bra deco_calculate_0_oc ; YES - set up OC mode 179 bra deco_calculate_0_oc ; YES - set up OC mode
163 ;bra deco_calculate_0_loop ; NO - set up CCR/pSCR mode 180 ;bra deco_calculate_0_loop ; NO - set up CCR/pSCR mode
189 bcf switch_left ; clear potential button event 206 bcf switch_left ; clear potential button event
190 return ; return to deco calculator main function 207 return ; return to deco calculator main function
191 208
192 deco_calculate_0_com: 209 deco_calculate_0_com:
193 ; set deco stop settings 210 ; set deco stop settings
194 movff opt_last_stop,char_I_depth_last_deco ; write last stop depth to deco engine 211 movff opt_last_stop,char_I_last_stop_depth ; write last stop depth to deco engine
195 212
196 ; set GF factors 213 ; set GF factors
197 movff opt_GF_low, char_I_GF_Low_percentage ; load normal GF factors by default 214 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 ; ... 215 movff opt_GF_high,char_I_GF_High_percentage ; ...
199 TSTOSS opt_sim_use_aGF ; shall use alternative GF factors in simulation? 216 TSTOSS opt_sim_use_aGF ; shall use alternative GF factors in simulation?
210 movff WREG,char_I_const_ppO2 ; YES - configure pSCR computations to calculated ppO2 227 movff WREG,char_I_const_ppO2 ; YES - configure pSCR computations to calculated ppO2
211 btfss FLAG_ccr_mode ; in CCR mode? 228 btfss FLAG_ccr_mode ; in CCR mode?
212 bra deco_calculate_2 ; NO - skip next 229 bra deco_calculate_2 ; NO - skip next
213 movff opt_sim_setpoint_number,WREG ; YES - get selected setpoint 230 movff opt_sim_setpoint_number,WREG ; YES - get selected setpoint
214 decf WREG,W ; - 1-5 -> 0-4 231 decf WREG,W ; - 1-5 -> 0-4
215 lfsr FSR1,opt_setpoint_cbar ; - load base address of setpoint list 232 lfsr FSR1,opt_setpoint_cbar ; - set base address of setpoint list
216 movff PLUSW1,char_I_const_ppO2 ; - configure setpoint value 233 movff PLUSW1,char_I_const_ppO2 ; - configure setpoint value
217 ENDIF 234 ENDIF
218 235
219 deco_calculate_2: 236 deco_calculate_2:
220 237
221 ; configure the deco engine - char_O_main_status 238 ; 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 239 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 240 bsf hi,DECO_VOLUME_FLAG ; enable gas volume calculation
224 bsf hi,DECO_BOTTOM_FLAG ; include bottom segment into gas needs 241 bsf hi,DECO_BOTTOM_FLAG ; include bottom segment into gas needs
242
243 IFDEF _cave_mode
225 bcf hi,DECO_CAVE_MODE ; cave mode not supported in deco calculator 244 bcf hi,DECO_CAVE_MODE ; cave mode not supported in deco calculator
226 bcf hi,DECO_Z_FACTOR_FLAG ; disable Z factors by default 245 ENDIF
227 TSTOSC opt_ZfactorUse ; shall use Z factors? 246
228 bsf hi,DECO_Z_FACTOR_FLAG ; YES - enable Z factors 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
229 bcf hi,DECO_EXTENDED_STOPS ; disable extended stops by default 253 bcf hi,DECO_EXTENDED_STOPS ; disable extended stops by default
230 TSTOSC opt_extended_stops ; shall make extended stops? 254 TSTOSC opt_ext_stops ; shall make extended stops?
231 bsf hi,DECO_EXTENDED_STOPS ; YES - activate extended stops 255 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 256 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 257 movff hi,char_O_main_status ; bank-safe copy to deco engine control
234 258
235 ; configure the deco engine - char_O_deco_status 259 ; configure the deco engine - char_O_deco_status
237 bcf lo,DECO_START_NORM ; clear flag for normal plan mode 261 bcf lo,DECO_START_NORM ; clear flag for normal plan mode
238 bcf lo,DECO_START_ALT ; clear flag for alternative plan mode 262 bcf lo,DECO_START_ALT ; clear flag for alternative plan mode
239 bsf lo,DECO_INITIALIZE ; set flag for once-per-dive initialization 263 bsf lo,DECO_INITIALIZE ; set flag for once-per-dive initialization
240 bsf lo,DECO_CALCULATOR_MODE ; signal that the deco engine is run from the deco calculator 264 bsf lo,DECO_CALCULATOR_MODE ; signal that the deco engine is run from the deco calculator
241 bcf lo,DECO_BAILOUT_FLAG ; no gas switches before first deco stop 265 bcf lo,DECO_BAILOUT_FLAG ; no gas switches before first deco stop
242 bcf lo,DECO_ASCENT_FLAG ; no delayed ascent 266 bcf lo,DECO_DELAY_FLAG ; no delayed ascent
243 movff lo,char_O_deco_status ; bank-safe copy to deco engine control 267 movff lo,char_O_deco_status ; bank-safe copy to deco engine control
244 268
245 deco_calculate_redo: 269 deco_calculate_redo:
246 270
247 call request_speed_fastest ; request CPU speed change to fastest speed (again, if in redo) 271 call request_speed_fastest ; request CPU speed change to fastest speed (again, if in redo)
283 movff char_O_main_status,hi ; - bank-safe copy from deco engine control (main status) 307 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 308 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 309 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) 310 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 311 bsf lo,DECO_BAILOUT_FLAG ; - allow gas switches before first deco stop
288 bsf lo,DECO_ASCENT_FLAG ; - allow delayed ascent 312 bsf lo,DECO_DELAY_FLAG ; - allow delayed ascent
289 movff lo,char_O_deco_status ; - bank-safe copy back to deco engine control 313 movff lo,char_O_deco_status ; - bank-safe copy back to deco engine control
290 314
291 TEXT_SMALL .20,.125, tCalcBailout ; - print what we are doing 315 TEXT_SMALL .20,.125, tCalcBailout ; - print what we are doing
292 ENDIF 316 ENDIF
293 317
302 bra deco_calculate_abort ; YES - set abort flag, do some clean-up and return 326 bra deco_calculate_abort ; YES - set abort flag, do some clean-up and return
303 call deco_calc_hauptroutine ; NO - invoke the deco engine so that it can do the deco calculation (C-code) 327 call deco_calc_hauptroutine ; NO - invoke the deco engine so that it can do the deco calculation (C-code)
304 banksel common ; - back to bank common 328 banksel common ; - back to bank common
305 movff char_O_depth_sim,lo ; - get the depth reached (in meters) 329 movff char_O_depth_sim,lo ; - get the depth reached (in meters)
306 WIN_SMALL .75,.150 ; - set output position 330 WIN_SMALL .75,.150 ; - set output position
307 output_8 ; - print depth reached (in meters) 331
308 STRCAT " m" ; - print unit (meters) 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:
309 btg decoplan_toggleflag ; - toggle the toggle flag 348 btg decoplan_toggleflag ; - toggle the toggle flag
310 btfsc decoplan_toggleflag ; - toggle flag set? 349 btfsc decoplan_toggleflag ; - toggle flag set?
311 bra deco_calculate_loop_1 ; YES - print ". " 350 bra deco_calculate_loop_1 ; YES - print ". "
312 STRCAT_PRINT " ." ; NO - print " ." 351 STRCAT_PRINT " ." ; NO - print " ."
313 bra deco_calculate_loop_2 ; 352 bra deco_calculate_loop_2 ;
403 ENDIF 442 ENDIF
404 deco_results_page_1: 443 deco_results_page_1:
405 TEXT_SMALL .80,.1, tDivePlan 444 TEXT_SMALL .80,.1, tDivePlan
406 deco_results_page_2: 445 deco_results_page_2:
407 movff char_O_deco_info,WREG ; get the deco info vector 446 movff char_O_deco_info,WREG ; get the deco info vector
408 btfsc WREG,deco_stops ; are there deco stops? 447 btfsc WREG,deco_stops_norm ; are there deco stops?
409 bra deco_plan_show_1 ; YES 448 bra deco_plan_show_1 ; YES
410 449
411 ;---- no deco -------------------------------------------------------- 450 ;---- no deco --------------------------------------------------------
412 call TFT_standard_color 451 call TFT_standard_color
413 TEXT_SMALL .80, .25, tNoDeco 452 TEXT_SMALL .80, .25, tNoDeco
414 453
415 ; output of remaining NDL time 454 ; output of remaining NDL time
416 WIN_SMALL .80, .50 ; same line as bottom time 455 WIN_SMALL .80, .50 ; same line as bottom time
417 PUTC "+" 456 PUTC "+"
418 movff char_O_NDL_norm,lo ; get NDL time in normal plan 457 movff int_O_NDL_norm+0,lo ; get NDL time in normal plan
419 bsf leftbind 458 bsf leftbind
420 output_8 459 output_8
421 bcf leftbind 460 bcf leftbind
422 PUTC "'" 461 PUTC "'"
423 PUTC " " 462 PUTC " "
427 return 466 return
428 467
429 ;---- deco stops --------------------------------------------------------- 468 ;---- deco stops ---------------------------------------------------------
430 deco_plan_show_1: 469 deco_plan_show_1:
431 lfsr FSR0,char_O_deco_depth ; initialize indexed addressing 470 lfsr FSR0,char_O_deco_depth ; initialize indexed addressing
432 lfsr FSR1,char_O_deco_time 471 lfsr FSR1,char_O_deco_time ; ...
433 472
434 clrf decoplan_index ; start with index = 0 473 clrf decoplan_index ; start with index = 0
435 movlw .24 474 movlw .24
436 movwf win_top ; and row = 0 at position 24 475 movwf win_top ; and row = 0 at position 24
437 476
508 ; print bottom depth 547 ; print bottom depth
509 WIN_SMALL .0,.75 548 WIN_SMALL .0,.75
510 STRCPY_TEXT tDepth 549 STRCPY_TEXT tDepth
511 PUTC ":" 550 PUTC ":"
512 movff char_I_bottom_depth,lo 551 movff char_I_bottom_depth,lo
513 output_8 552
514 STRCAT_PRINT "m" 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
515 570
516 ; print warnings or sat/dsat factors 571 ; print warnings or sat/dsat factors
517 WIN_SMALL .0,.105 572 WIN_SMALL .0,.105
518 573
519 ; check for stop table overflow 574 ; check for stop table overflow
553 deco_results_m1: 608 deco_results_m1:
554 609
555 call TFT_standard_color ; clean-up from warnings 610 call TFT_standard_color ; clean-up from warnings
556 611
557 ; get model 612 ; get model
558 movff char_I_deco_model,WREG ; 0: straight Buhlmann, 1: with GF 613 movff char_I_model,WREG ; 0: straight Buhlmann, 1: with GF
559 iorwf WREG ; GF factors in use? 614 iorwf WREG ; GF factors in use?
560 bz deco_results_m2 ; NO 615 bz deco_results_m2 ; NO
561 616
562 ; display GF low/high factors 617 ; display GF low/high factors
563 WIN_SMALL .0,.130 618 WIN_SMALL .0,.130
592 647
593 deco_results_2c: 648 deco_results_2c:
594 649
595 btfss FLAG_oc_mode ; current dive mode = OC ? 650 btfss FLAG_oc_mode ; current dive mode = OC ?
596 bra deco_results_2d ; NO - skip 651 bra deco_results_2d ; NO - skip
597 TSTOSS opt_extended_stops ; YES - extended stops activated? 652 TSTOSS opt_ext_stops ; YES - extended stops activated?
598 bra deco_results_2d ; NO - skip 653 bra deco_results_2d ; NO - skip
599 WIN_SMALL .18,.155 ; YES - set position 654 WIN_SMALL .18,.155 ; YES - set position
600 STRCAT_PRINT "ext.Stop" ; - print notice 655 STRCAT_PRINT "ext.Stop" ; - print notice
601 656
602 deco_results_2d: 657 deco_results_2d:
688 incf gas_index,F ; increment gas index 743 incf gas_index,F ; increment gas index
689 744
690 movf gas_index,W ; copy gas index to WREG for color-coding 745 movf gas_index,W ; copy gas index to WREG for color-coding
691 call TFT_color_code_gas ; set output color according to gas (1-5) 746 call TFT_color_code_gas ; set output color according to gas (1-5)
692 747
693 lfsr FSR2,buffer ; load base address of output buffer 748 lfsr FSR2,buffer ; set base address of output buffer
694 bsf short_gas_descriptions ; configure gaslist_strcat_gas output format 749 bsf short_gas_descriptions ; configure gaslist_strcat_gas output format
695 bsf divemode ; configure gaslist_strcat_gas output format 750 bsf divemode ; configure gaslist_strcat_gas output format
696 call gaslist_strcat_gas ; write "Nxlo", "Txlo/hi", "Air" or "O2" into output buffer 751 call gaslist_strcat_gas ; write "Nxlo", "Txlo/hi", "Air" or "O2" into output buffer
697 bcf divemode ; cleanup above 752 bcf divemode ; cleanup above
698 753
774 829
775 deco_results_gas_volumes_7: 830 deco_results_gas_volumes_7:
776 btfsc decoplan_pressures_shown ; results shown in bar? 831 btfsc decoplan_pressures_shown ; results shown in bar?
777 bra deco_results_1 ; YES - show deco stops again 832 bra deco_results_1 ; YES - show deco stops again
778 bsf decoplan_pressures_shown ; NO - but now 833 bsf decoplan_pressures_shown ; NO - but now
779 lfsr FSR0,int_O_gas_need_pres ; - load base address of gas needs in bar 834 lfsr FSR0,int_O_gas_need_pres ; - set base address of gas needs in bar
780 bra deco_results_gas_common ; - re-run gas needs output in pressure mode 835 bra deco_results_gas_common ; - re-run gas needs output in pressure mode
781 836
782 837
783 END 838 END