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