comparison src/simulator.asm @ 604:ca4556fb60b9

bump to 2.99beta, work on 3.00 stable
author heinrichsweikamp
date Thu, 22 Nov 2018 19:47:26 +0100
parents e1f0f5e3d4e4
children c40025d8e750
comparison
equal deleted inserted replaced
603:00b24fb4324d 604:ca4556fb60b9
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File simulator.asm REFACTORED VERSION V2.98 3 ; File simulator.asm REFACTORED VERSION V2.99e
4 ; 4 ;
5 ; Decoplan interface to C model code. 5 ; Decoplan interface to C model code.
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
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 "isr.inc"
25 25
26 gui CODE
27
28 extern deco_clear_tissue 26 extern deco_clear_tissue
29 extern deco_push_tissues_to_vault 27 extern deco_push_tissues_to_vault
30 extern deco_calc_dive_interval 28 extern deco_calc_dive_interval
31 extern deco_calc_hauptroutine 29 extern deco_calc_hauptroutine
32 extern deco_pull_tissues_from_vault 30 extern deco_pull_tissues_from_vault
33 extern TFT_display_decotype_surface1 31 extern TFT_display_decotype_surface1
34 extern get_first_dil_to_WREG
35 extern get_first_gas_to_WREG
36 extern setup_dil_registers
37 extern setup_gas_registers
38 extern deco_setup_cc_diluents
39 extern deco_setup_oc_gases
40 extern log_screendump_and_onesecond 32 extern log_screendump_and_onesecond
41 extern logbook_preloop_tasks 33 extern logbook_preloop_tasks
42 extern do_return_demo_planner 34 extern do_return_demo_planner
35 extern dive_boot_oc_bail
36 extern dive_boot_oc
37 extern dive_boot_cc
43 38
44 39
45 ;---- Private local variables ------------------------------------------------- 40 ;---- Private local variables -------------------------------------------------
46 41
47 CBLOCK local1 ; max size is 16 Byte !!! 42 CBLOCK local1 ; max size is 16 Byte !!!
48 decoplan_index ; within each page 43 decoplan_index ; within each page
49 decoplan_gindex ; global index 44 decoplan_gindex ; global index
50 decoplan_last ; Depth of last stop (CF#29) 45 decoplan_last ; depth of last stop (CF#29)
51 decoplan_flags ; Various private flags. 46 decoplan_flags ; various private flags
52 decoplan_page ; page number 47 decoplan_page ; page number
53 decoplan_warnings ; deco engine warnings 48 decoplan_warnings ; deco engine warnings
54 gas_counter ; counter for looping through the gases 49 gas_counter ; counter for looping through the gases
55 row_pos ; used for positioning of graphic elements 50 row_pos ; used for positioning of graphic elements
56 ENDC ; used: 8 byte, remaining: 8 byte 51 ENDC ; used: 8 byte, remaining: 8 byte
58 ;---- Defines ---------------------------------------------------------------- 53 ;---- Defines ----------------------------------------------------------------
59 54
60 #define decoplan_last_ceiling_shown decoplan_flags,0 55 #define decoplan_last_ceiling_shown decoplan_flags,0
61 #define decoplan_abort decoplan_flags,1 56 #define decoplan_abort decoplan_flags,1
62 57
58
59 simulator CODE
60
61
63 ;---- Demo deco planner ------------------------------------------------------ 62 ;---- Demo deco planner ------------------------------------------------------
64 63
65 global do_demo_planner 64 global do_demo_planner
66 do_demo_planner: 65 do_demo_planner:
67 btfsc FLAG_gauge_mode ; =1: In Gauge mode 66 btfsc FLAG_gauge_mode ; in gauge mode?
67 bra do_demo_planner_exit ; YES - abort
68 btfsc FLAG_apnoe_mode ; in Apnea mode?
69 bra do_demo_planner_exit ; YES - abort
70 bcf decoplan_abort ; initialize (clear) abort flag
71 bcf FLAG_bailout_mode ; clear bailout condition (may have remained set from last invocation)
72 rcall deco_planer
73 btfss decoplan_abort ; skip recall deco_show_plan if calculations were aborted
74 rcall deco_show_plan
75 do_demo_planner_exit:
68 goto do_return_demo_planner 76 goto do_return_demo_planner
69 btfsc FLAG_apnoe_mode ; =1: In Apnea mode 77
70 goto do_return_demo_planner 78
71 bcf decoplan_abort ; initialize (clear) abort flag
72 bcf is_bailout ; clear bailout condition (may have remained set from last invocation)
73 rcall deco_planer
74 btfss decoplan_abort ; skip recall deco_show_plan if calculations were aborted
75 rcall deco_show_plan
76 goto do_return_demo_planner
77
78
79 global deco_setup
80 deco_setup: 79 deco_setup:
81 btfsc FLAG_ccr_mode 80 call dive_boot_oc_bail ; basic setup for all modes
82 bra deco_setup_cc 81 btfsc FLAG_oc_mode ; in OC mode?
83 btfsc FLAG_pscr_mode 82 call dive_boot_oc ; YES - set up OC mode
84 bra deco_setup_cc 83 btfss FLAG_oc_mode ; in OC mode?
85 deco_setup_oc: 84 call dive_boot_cc ; NO - set up CCR/pSCR mode
86 call get_first_gas_to_WREG ; gets first gas (1-5) into WREG 85
87 call setup_gas_registers ; with WREG=Gas 1-5 86 ; use ambient conditions for deco calculation
88 call deco_setup_oc_gases ; setup OC/Bailout Gases and configure for OC deco calculation
89 bra deco_setup_cont
90 deco_setup_cc:
91 call get_first_dil_to_WREG ; gets first gas (1-5) into WREG
92 call setup_dil_registers ; with WREG=Gas 1-5
93 call deco_setup_cc_diluents ; setup CCR/pSCR diluents and configure for CCR/pSCR deco calculation
94 deco_setup_cont:
95 ; use ambient conditions for simulation
96 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ; copy surface pressure to deco routine 87 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ; copy surface pressure to deco routine
97 88
98 movlw deco_distance 89 movlw deco_distance
99 movff WREG,char_I_deco_distance 90 movff WREG,char_I_deco_distance
100 91
101 movff opt_last_stop,char_I_depth_last_deco 92 movff opt_last_stop,char_I_depth_last_deco
102 movff opt_GF_low,char_I_GF_Low_percentage 93 movff opt_GF_low,char_I_GF_Low_percentage
103 movff opt_GF_high,char_I_GF_High_percentage 94 movff opt_GF_high,char_I_GF_High_percentage
104 95
105 ; overwrite GF if aGF is wanted 96 ; overwrite GF if aGF is wanted
106 bsf use_agf 97 bsf use_agf ; set flag to use alternative GF factors by default
107 TSTOSS opt_sim_use_aGF 98 TSTOSS opt_sim_use_aGF ; shall use alternative GF factors?
108 bcf use_agf 99 bcf use_agf ; NO - clear flag again
109 100
110 btfsc use_agf ; =1: Use aGF 101 btfsc use_agf ; =1: use aGF
111 movff opt_aGF_low,char_I_GF_Low_percentage 102 movff opt_aGF_low,char_I_GF_Low_percentage
112 btfsc use_agf ; =1: Use aGF 103 btfsc use_agf ; =1: use aGF
113 movff opt_aGF_high,char_I_GF_High_percentage 104 movff opt_aGF_high,char_I_GF_High_percentage
114
115 bcf is_bailout
116 105
117 ; setup char_I_const_ppO2 for CC modes 106 ; setup char_I_const_ppO2 for CC modes
118 clrf WREG 107 clrf WREG
119 btfsc FLAG_pscr_mode 108 btfsc FLAG_pscr_mode
120 movff WREG,char_I_const_ppO2 ; configure pSCR computations to calculated ppO2 109 movff WREG,char_I_const_ppO2 ; configure pSCR computations to calculated ppO2
129 ;============================================================================= 118 ;=============================================================================
130 ; Launch deco planning 119 ; Launch deco planning
131 ; 120 ;
132 global deco_planer 121 global deco_planer
133 deco_planer: 122 deco_planer:
134 call speed_fastest ; Quick ! 123 call speed_fastest ; quick!
124 call TFT_ClearScreen ; clear screen to show that calculator is starting up
135 call deco_push_tissues_to_vault ; C-code: back-up state of the real tissues 125 call deco_push_tissues_to_vault ; C-code: back-up state of the real tissues
136 banksel common 126 banksel common
137 rcall deco_setup ; Setup all model parameters. 127 rcall deco_setup ; setup all model parameters
138 128
139 ;---- Specific settings ------------------------------------------------------ 129 ;---- Specific settings ------------------------------------------------------
140 130
141 ; configure the deco engine for normal plan, CNS & gas volume calculation and no delayed ascent 131 ; configure the deco engine for normal plan, CNS & gas volume calculation and no delayed ascent
142 movff char_O_deco_status,WREG ; bank-safe copy 132 movff char_O_deco_status,lo ; bank-safe copy
143 bcf WREG,DECO_PLAN_FLAG ; normal plan mode, 133 bcf lo,DECO_PLAN_FLAG ; normal plan mode,
144 bsf WREG,DECO_CNS_FLAG ; enable CNS calculation (CNS at end of dive), 134 bsf lo,DECO_VOLUME_FLAG ; enable gas volume calculation, and
145 bsf WREG,DECO_VOLUME_FLAG ; enable gas volume calculation, and 135 bcf lo,DECO_ASCENT_FLAG ; disable delayed ascent calculation
146 bcf WREG,DECO_ASCENT_FLAG ; disable delayed ascent calculation 136 movff lo,char_O_deco_status ; bank-safe copy back
147 movff WREG,char_O_deco_status ; bank-safe copy back
148 137
149 ; configure the deco engine for total-dive gas volume calculation 138 ; configure the deco engine for total-dive gas volume calculation
150 movff char_O_main_status,WREG ; bank-safe copy 139 movff char_O_main_status,hi ; bank-safe copy
151 bsf WREG,DECO_BOTTOM_FLAG ; set bottom flag 140 bcf hi,DECO_TR_FUNCTIONS ; execution of TR functions is not needed in deco calculator mode
152 movff WREG,char_O_main_status ; bank-safe copy back 141 bsf hi,DECO_BOTTOM_FLAG ; set bottom flag
142 bsf hi,DECO_Z_FACTOR_FLAG ; enable use of Z factor by default
143 TSTOSS opt_ZfactorUse ; shall use Z factor?
144 bcf hi,DECO_Z_FACTOR_FLAG ; NO - disable again
145 movff hi,char_O_main_status ; bank-safe copy back
153 146
154 deco_planer_redo: 147 deco_planer_redo:
155 ; show deco calculation is in progress 148 ; show deco calculation is in progress
156 call TFT_ClearScreen 149 call TFT_ClearScreen
157 WIN_COLOR color_greenish 150 WIN_COLOR color_greenish
158 TEXT_SMALL .20,.40, tCalculating 151 TEXT_SMALL .20,.40, tCalculating
159 WIN_COLOR color_lightblue 152 WIN_COLOR color_lightblue
160 WIN_SMALL .1,.215 153 WIN_SMALL .1,.215
161 STRCPY_TEXT_PRINT tAbort 154 STRCPY_TEXT_PRINT tAbort
162 155
163 ; configure the deco engine for restart: 156 ; configure the deco engine for initialization
164 movff char_O_deco_status,WREG ; bank-safe copy 157 movff char_O_deco_status,lo ; bank-safe copy
165 bsf WREG,DECO_STATUS_0_FLAG ; configure init ... 158 bsf lo,DECO_STATUS_0_FLAG ; configure init ...
166 bsf WREG,DECO_STATUS_1_FLAG ; ... state, 159 bsf lo,DECO_STATUS_1_FLAG ; ... state,
167 movff WREG,char_O_deco_status ; bank-safe copy back 160 movff lo,char_O_deco_status ; bank-safe copy back
168 161
169 ;---- Add delay at surface, if needed ---------------------------------------- 162 ;---- add delay at surface, if requested -------------------------------------
170 banksel char_I_dive_interval 163 banksel char_I_dive_interval
171 tstfsz char_I_dive_interval 164 tstfsz char_I_dive_interval
172 call deco_calc_dive_interval 165 call deco_calc_dive_interval
173 166
174 ;---- Dive loop -------------------------------------------------------------- 167 ;---- Dive loop --------------------------------------------------------------
175 ; Compute dive ambient conditions 168 ; compute dive ambient conditions
176 banksel char_I_bottom_depth 169 banksel char_I_bottom_depth
177 movf char_I_bottom_depth,W 170 movf char_I_bottom_depth,W
178 mullw .100 171 mullw .100
179 movlw LOW(.1000) 172 movlw LOW (.1000)
180 addwf PRODL,W 173 addwf PRODL,W
181 movwf int_I_pres_respiration+0 174 movwf int_I_pres_respiration+0
182 movlw HIGH(.1000) 175 movlw HIGH(.1000)
183 addwfc PRODH,W 176 addwfc PRODH,W
184 movwf int_I_pres_respiration+1 177 movwf int_I_pres_respiration+1
185 banksel common 178 banksel common
186 179
187 movff char_I_bottom_time,char_I_sim_advance_time 180 movff char_I_bottom_time,char_I_sim_advance_time
188 181
189 clrf TMR5L 182 clrf TMR5L ; restart timer used to preempt stops calculation
190 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H 183 clrf TMR5H ;
191 184
192 call deco_calc_hauptroutine ; C-code: initialization + complete bottom time part 185 call deco_calc_hauptroutine ; initialization, complete bottom time part and initial ascent
193 banksel common 186 banksel common
194 187
195 ;---- BAILOUT: Switch to OC gases for ascent cycles -------------------------- 188 btfss FLAG_bailout_mode ; doing a bailout deco plan?
196 btfss is_bailout ; Doing a bailout deco plan ? 189 bra deco_planer_loop ; NO - keep gases and go on
197 bra deco_planer_finishing ; NO - keep gases 190 ; YES - switch to OC gas and restart deco plan
198 ; YES - switch to OC gas 191
199 192 ;---- BAILOUT: Switch to OC gases for ascent -----------------------------------
200 ; reconfigure the deco engine for delayed ascent mode 193
194 ; reconfigure the deco engine for delayed ascent & bailout mode and start a new calculation cycle
201 movff char_O_deco_status,lo ; bank-safe copy 195 movff char_O_deco_status,lo ; bank-safe copy
202 bsf lo,DECO_ASCENT_FLAG ; set flag for delayed ascent calculation 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
203 movff lo,char_O_deco_status ; bank-safe copy back 200 movff lo,char_O_deco_status ; bank-safe copy back
204 201
205 ; configure the deco engine for delayed ascent part gas volume calculation 202 ; reconfigure the deco engine for bailout ascent needs
206 movff char_O_main_status,WREG ; bank-safe copy 203 movff char_O_main_status,hi ; bank-safe copy
207 bcf WREG,DECO_BOTTOM_FLAG ; set bottom flag 204 bcf hi,DECO_BOTTOM_FLAG ; clear bottom flag
208 movff WREG,char_O_main_status ; bank-safe copy back 205 movff hi,char_O_main_status ; bank-safe copy back
209 206
210 ; reconfigure gas settings to OC gases 207 ; reconfigure gas settings to OC gases
211 call get_first_gas_to_WREG ; get first gas (1-5) into WREG 208 call dive_boot_oc ; configure deco engine for OC mode
212 call setup_gas_registers ; With WREG=Gas 1-5 (or 6, not applicable here)
213 call deco_setup_oc_gases ; With WREG=Gas 1-5 (or 6, not applicable here)
214
215 ; set the gas change override flag to allow gas changes before deco stops as done in alternative plan
216 movff char_O_main_status,lo ; bank-safe copy
217 bsf lo,DECO_GASCHANGE_OVRD ; set flag for gas change override
218 movff lo,char_O_main_status ; bank-safe copy back
219 209
220 ;---- Wait until status reaches zero ------------------------------------------- 210 ;---- Wait until status reaches zero -------------------------------------------
221 deco_planer_finishing: 211 deco_planer_loop:
222 call deco_calc_hauptroutine ; C-code: Simulate more dive time to trigger the deco calculations 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
223 banksel common 215 banksel common
224 216
225 btfss switch_left ; check if left button was pressed 217 btfss switch_left ; check if left button was pressed
226 bra deco_planer_finishing_1 ; NO - continue calculations 218 bra deco_planer_finishing_1 ; NO - continue calculations
227 bsf decoplan_abort ; YES - set abort flag so that deco_show_plan will not be called 219 bsf decoplan_abort ; YES - set abort flag so that deco_show_plan will not be called
228 bra deco_planer_finishing_2 ; do some clean-up and return 220 bra deco_planer_finishing_2 ; do some clean-up and return
229 deco_planer_finishing_1: 221 deco_planer_finishing_1:
230 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common 222 movff char_O_main_status,hi ; working copy of char_O_main_status in bank common
231 movlw DECO_STATUS_MASK ; bit mask for deco status bit set 223 btfss hi,DECO_COMPLETED_NORM ; calculations completed?
232 andwf lo,W ; mask out bits showing state of computation 224 bra deco_planer_loop ; NO - needs more computation cycles
233 tstfsz WREG ; check if a compute cycle is finished (bits 1 and 0 == 0)
234 bra deco_planer_finishing ; NO - needs more computation cycles
235 225
236 ;---- Done: add CNS from decoplan, and restore tissues 226 ;---- Done: add CNS from decoplan, and restore tissues
237 deco_planer_finishing_2: 227 deco_planer_finishing_2:
238 movff char_O_deco_warnings,decoplan_warnings ; copy warnings 228 movff char_O_deco_warnings,decoplan_warnings ; copy warnings
239 229
261 movff PLUSW2,WREG ; get current gas and copy it to WREG for color-coding 251 movff PLUSW2,WREG ; get current gas and copy it to WREG for color-coding
262 call TFT_color_code_gas ; set output color dependent on gas (1-5) 252 call TFT_color_code_gas ; set output color dependent on gas (1-5)
263 253
264 lfsr FSR2,buffer 254 lfsr FSR2,buffer
265 255
266 TSTOSS opt_units ; 0=Meters, 1=Feets 256 TSTOSS opt_units ; 0=Meter, 1=Feet
267 bra deco_plan_show_nstd_stop_metric 257 bra deco_plan_show_nstd_stop_metric
268 258
269 movff hi,up ; backup hi (minutes) 259 movff hi,ul ; back-up hi (minutes)
270 WIN_LEFT .85 260 WIN_LEFT .80
271 movf lo,W ; lo = m 261 movf lo,W ; lo = m
272 mullw .100 ; PRODL:PRODH = mbar 262 mullw .100 ; PRODL:PRODH = hPa
273 movff PRODL,lo 263 movff PRODL,lo
274 movff PRODH,hi 264 movff PRODH,hi
275 ; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops... 265 ; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops...
276 movff lo,xA+0 266 movff lo,xA+0
277 movff hi,xA+1 267 movff hi,xA+1
290 movwf xB+0 280 movwf xB+0
291 clrf xB+1 281 clrf xB+1
292 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder 282 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
293 movff xC+0,lo 283 movff xC+0,lo
294 movff xC+1,hi ; restore lo and hi with updated value 284 movff xC+1,hi ; restore lo and hi with updated value
295 bsf leftbind 285 bsf ignore_digit4 ; only full feet
296 bsf ignore_digit4 ; Only full feet
297 output_16 286 output_16
298 bcf leftbind 287 STRCAT_PRINT "ft"
299 STRCAT_PRINT "ft " 288 movff ul,hi ; restore hi (minutes)
300 movff up,hi ; restore hi (minutes)
301 bra deco_plan_show_nstd_stop_common 289 bra deco_plan_show_nstd_stop_common
302 290
303 deco_plan_show_nstd_stop_metric: 291 deco_plan_show_nstd_stop_metric:
304 WIN_LEFT .90 292 WIN_LEFT .85
305 bsf leftbind 293 output_8 ; outputs into postinc2
306 output_8 ; outputs into Postinc2! 294 STRCAT_PRINT "m"
307 bcf leftbind
308 STRCAT_PRINT "m "
309 295
310 deco_plan_show_nstd_stop_common: 296 deco_plan_show_nstd_stop_common:
311 ;---- Print duration ------------------------------------------------- 297 ;---- Print duration -------------------------------------------------
312 WIN_LEFT .135 298 WIN_LEFT .135
313 lfsr FSR2,buffer 299 lfsr FSR2,buffer
314
315 movf lo,W ; Swap hi & lo
316 movff hi,lo 300 movff hi,lo
317 movwf hi 301 output_99 ; stop entries are 99 min max.
318 302 STRCAT_PRINT "'"
319 output_8 ; Allow up to 240'
320 clrf WREG
321 movff WREG,buffer+.3 ; limit to 2 chars
322 STRCAT_PRINT ""
323
324 movf lo,W ; Swap back hi & lo
325 movff hi,lo
326 movwf hi
327 303
328 ;--------------------------------------------------------------------- 304 ;---------------------------------------------------------------------
329 ; Draw the bar graph used for deco stops (deco plan in simulator or dive). 305 ; Draw the bar graph used for deco stops (deco plan in simulator or dive)
330 incf win_top,F 306 incf win_top,F
331 movlw .19 307 movlw .19
332 movwf win_height 308 movwf win_height
333 movlw .118 309 movlw .118
334 movwf win_leftx2 ; column left (0-159) 310 movwf win_leftx2 ; column left (0-159)
335 movlw .16 311 movlw .16
336 movwf win_width+0 ; column max width. 312 movwf win_width+0 ; column max width
337 clrf win_width+1 313 clrf win_width+1
338 314
339 ; Draw used area (hi = minutes): 315 ; Draw used area (lo = minutes):
340 movlw .16 ; Limit length (16min) 316 movlw .16 ; limit length to max. column width
341 cpfslt hi 317 cpfslt lo
342 movwf hi 318 movwf lo
343 movff hi,win_bargraph ; Active width, the rest is cleared. 319 movff lo,win_bargraph ; active width, the rest is cleared
344 call TFT_box 320 call TFT_box
345 321
346 ; Restore win_top 322 ; Restore win_top
347 call TFT_standard_color 323 call TFT_standard_color
348 decf win_top,F ; Restore win_top 324 decf win_top,F ; restore win_top
349 return 325 return
350 326
351 ;----------------------------------------------------------------------------- 327 ;-----------------------------------------------------------------------------
352 ; Clear unused area below last stop 328 ; Clear unused area below last stop
353 ; Inputs: win_top : last used area... 329 ; Inputs: win_top : last used area...
354 deco_plan_show_clear_bottom: 330 deco_plan_show_clear_bottom:
355 movf win_top,W ; Get back from bank0 331 movf win_top,W ; get back from bank0
356 sublw .239 ; No: bottom row in planning 332 sublw .239 ; bottom row in planning
357 movwf win_height 333 movwf win_height
358 334
359 WIN_LEFT .85 ; Full dive menu width 335 WIN_LEFT .85 ; full dive menu width
360 movlw .159-.85+.1 336 movlw .159-.85+.1
361 movwf win_width+0 337 movwf win_width+0
362 clrf win_width+1 338 clrf win_width+1
363 339
364 clrf win_color1 ; Fill with black 340 clrf win_color1 ; fill with black
365 clrf win_color2 341 clrf win_color2
366 342
367 goto TFT_box ; and return 343 goto TFT_box ; and return
368 344
369 ;----------------------------------------------------------------------------- 345 ;-----------------------------------------------------------------------------
370 ; Display the deco plan (simulator). 346 ; Display the deco plan (simulator).
371 ; Inputs: char_O_deco_table (array of stop times, in minutes) 347 ; Inputs: char_O_deco_table (array of stop times, in minutes)
372 ; decoplan_page = page number. 348 ; decoplan_page = page number.
373 ; 349 ;
374 deco_show_plan_page: 350 deco_show_plan_page:
375 bcf win_invert ; Reset invert flag 351 bcf win_invert ; reset invert flag
376 352
377 ;---- Is there deco stops ? ------------------------------------------ 353 ;---- Are there deco stops ? ------------------------------------------
378 movff char_O_first_deco_depth,WREG 354 movff char_O_first_deco_depth,WREG
379 iorwf WREG 355 iorwf WREG
380 bnz deco_plan_show_1 356 bnz deco_plan_show_1
381 357
382 ;---- No Deco -------------------------------------------------------- 358 ;---- No Deco --------------------------------------------------------
383 call TFT_standard_color 359 call TFT_standard_color
384 TEXT_SMALL .80, .0, tNoDeco 360 TEXT_SMALL .80, .0, tNoDeco
361
362 ; output of remaining NDL time
363 WIN_SMALL .80, .50 ; same line as bottom time
364 movff char_O_nullzeit,lo ; remaining NDL at end of bottom time
365 output_8
366 PUTC "'"
367 PUTC " "
368 STRCAT_TEXT_PRINT tNDLleft ; "left"
369
385 bsf decoplan_last_ceiling_shown 370 bsf decoplan_last_ceiling_shown
386 return 371 return
387 372
388 deco_plan_show_1: 373 deco_plan_show_1:
389 lfsr FSR0,char_O_deco_depth ; Initialize indexed addressing. 374 lfsr FSR0,char_O_deco_depth ; initialize indexed addressing
390 lfsr FSR1,char_O_deco_time 375 lfsr FSR1,char_O_deco_time
391 376
392 clrf decoplan_index ; Start with index = 0 377 clrf decoplan_index ; start with index = 0
393 clrf win_top ; and row = 0 378 movlw .24
379 movwf win_top ; and row = 0 at position 24
394 380
395 ; Read stop parameters, indexed by decoplan_index and decoplan_page 381 ; Read stop parameters, indexed by decoplan_index and decoplan_page
396 movf decoplan_page,W ; decoplan_gindex = 6*decoplan_page + decoplan_index 382 movf decoplan_page,W ; decoplan_gindex = 6*decoplan_page + decoplan_index
397 mullw .8 ; 8 lines/page in deco plan 383 mullw .8 ; 8 lines/page in deco plan
398 movf decoplan_index,W 384 movf decoplan_index,W
399 addwf PRODL,W 385 addwf PRODL,W
400 movwf decoplan_gindex ; --> decoplan_gindex 386 movwf decoplan_gindex ; --> decoplan_gindex
401 387
402 bcf decoplan_last_ceiling_shown ; Not finished yet... 388 bcf decoplan_last_ceiling_shown ; not done yet...
403 389
404 deco_plan_show_2: 390 deco_plan_show_2:
405 btfsc decoplan_gindex,5 ; Reached table length (32) ? 391 btfsc decoplan_gindex,5 ; reached table length (32) ?
406 bra deco_plan_show_99 ; YES: finished... 392 bra deco_plan_show_99 ; YES - done
407 393
408 ; Read stop parameters, indexed by decoplan_index 394 ; Read stop parameters, indexed by decoplan_index
409 movf decoplan_gindex,W ; index 395 movf decoplan_gindex,W ; index
410 movff PLUSW0,lo ; char_O_deco_depth[gindex] 396 movff PLUSW0,lo ; char_O_deco_depth[gindex]
411 movff PLUSW1,hi ; char_O_deco_time [gindex] 397 movff PLUSW1,hi ; char_O_deco_time [gindex]
412 movf lo,W 398 movf lo,W
413 bz deco_plan_show_99 ; depth == 0 : finished. 399 bz deco_plan_show_99 ; depth == 0 : done
414 400
415 ; Display the stop line 401 ; Display the stop line
416 rcall deco_plan_show_stop 402 rcall deco_plan_show_stop
417 403
418 ; Next 404 ; Next
422 incf decoplan_gindex,F ; global index += 1 408 incf decoplan_gindex,F ; global index += 1
423 409
424 ; Max number of lines/page reached ? 410 ; Max number of lines/page reached ?
425 movlw .8 ; 8 lines/page in deco plan 411 movlw .8 ; 8 lines/page in deco plan
426 cpfseq decoplan_index 412 cpfseq decoplan_index
427 bra deco_plan_show_2 ; NO: loop 413 bra deco_plan_show_2 ; NO - loop
428 414
429 ; Check if next stop is end-of-list ? 415 ; Check if next stop is end-of-list ?
430 movf decoplan_gindex,W 416 movf decoplan_gindex,W
431 movf PLUSW0,W ; char_O_deco_depth[gindex] 417 movf PLUSW0,W ; char_O_deco_depth[gindex]
432 bz deco_plan_show_99 ; End of list... 418 bz deco_plan_show_99 ; end of list
433 419
434 ; Display the message "more..." 420 ; Display the message "more..."
435 rcall deco_plan_show_clear_bottom ; Clear from next line 421 rcall deco_plan_show_clear_bottom ; clear from next line
436 422
437 call TFT_standard_color 423 call TFT_standard_color
438 TEXT_SMALL .88, .220, tMore 424 TEXT_SMALL .88, .220, tMore
439 return 425 return
440 426
441 deco_plan_show_99: 427 deco_plan_show_99:
442 bsf decoplan_last_ceiling_shown ; Nothing more in table to display. 428 bsf decoplan_last_ceiling_shown ; nothing more in table to display
443 rcall deco_plan_show_clear_bottom ; Clear from next line 429 rcall deco_plan_show_clear_bottom ; clear from next line
444 return 430 return
445 431
446 ;----------------------------------------------------------------------------- 432 ;-----------------------------------------------------------------------------
447 ; Loop to show all pages of the deco plan (surface mode) 433 ; Loop to show all pages of the deco plan (surface mode)
448 434
449 global deco_show_plan 435 global deco_show_plan
450 deco_show_plan: 436 deco_show_plan:
451 clrf decoplan_page 437 clrf decoplan_page
452 call TFT_ClearScreen 438 call TFT_ClearScreen
453 WIN_COLOR color_greenish 439 WIN_COLOR color_greenish
454 btfsc is_bailout 440 btfsc FLAG_bailout_mode
455 bra deco_show_plan_bail_title 441 bra deco_show_plan_bail_title
456 TEXT_SMALL .1,.1, tDivePlan 442 TEXT_SMALL .1,.1, tDivePlan
457 bra deco_show_plan2 443 bra deco_show_plan2
458 deco_show_plan_bail_title: 444 deco_show_plan_bail_title:
459 TEXT_SMALL .1,.1, tDiveBailout 445 TEXT_SMALL .1,.1, tDiveBailout
460 deco_show_plan2: 446 deco_show_plan2:
461 call TFT_standard_color 447 call TFT_standard_color
462 ;---- Display Plan Parameters 448 ;---- Display Plan Parameters
463 WIN_SMALL .0,.25 449 WIN_SMALL .0,.25
464 STRCPY "Int:" 450 STRCPY "Int.:"
465 movff char_I_dive_interval,lo 451 movff char_I_dive_interval,lo
466 bsf leftbind 452 bsf leftbind
467 output_8 453 output_8
468 bcf leftbind 454 bcf leftbind
469 STRCAT_PRINT "'" 455 STRCAT_PRINT "'"
470 WIN_SMALL .0,.50 456 WIN_SMALL .0,.50
471 STRCPY_TEXT tBtTm_short 457 STRCPY_TEXT tBtTm_short
472 movff char_I_bottom_time,lo 458 movff char_I_bottom_time,lo
473 bsf leftbind 459 bsf leftbind
474 output_8 460 output_8
475 bcf leftbind 461 bcf leftbind
476 STRCAT_PRINT "'" 462 STRCAT_PRINT "'"
477 WIN_SMALL .0,.75 463 WIN_SMALL .0,.75
478 STRCPY_TEXT tDepth 464 STRCPY_TEXT tDepth
479 PUTC ":" 465 PUTC ":"
480 movff char_I_bottom_depth,lo 466 movff char_I_bottom_depth,lo
481 bsf leftbind 467 bsf leftbind
482 output_8 468 output_8
483 bcf leftbind 469 bcf leftbind
484 STRCAT_PRINT "m" 470 STRCAT_PRINT "m"
485 WIN_SMALL .0,.105 ; set position for warnings or sat/dsat factors 471 WIN_SMALL .0,.105 ; set position for warnings or sat/dsat factors
486 472
487 ;---- Check for Stop Table Overflow 473 ;---- Check for Stop Table Overflow
488 btfss decoplan_warnings,stoptable_overflow ; check if we have a overflow warning 474 btfss decoplan_warnings,stoptable_overflow ; check if we have a overflow warning
505 ;---- Display Sat/Desat Factors --> omitted if there were warnings 491 ;---- Display Sat/Desat Factors --> omitted if there were warnings
506 STRCAT_PRINT "SD:" 492 STRCAT_PRINT "SD:"
507 WIN_SMALL .25,.105 493 WIN_SMALL .25,.105
508 movff char_I_saturation_multiplier,lo 494 movff char_I_saturation_multiplier,lo
509 output_8 495 output_8
510 STRCAT "/" 496 STRCAT "/"
511 movff char_I_desaturation_multiplier,lo 497 movff char_I_desaturation_multiplier,lo
512 output_8 498 output_8
513 STRCAT_PRINT "" 499 STRCAT_PRINT ""
514 500
515 deco_show_plan_m1: 501 deco_show_plan_m1:
516 call TFT_standard_color ; clean-up from warnings 502 call TFT_standard_color ; clean-up from warnings
517 503
518 ;---- Get Model 504 ;---- get Model
519 movff char_I_deco_model,WREG 505 movff char_I_deco_model,WREG
520 iorwf WREG 506 iorwf WREG
521 bz deco_show_plan_m2 507 bz deco_show_plan_m2
522 508
523 ;---- Display GF low/high values 509 ;---- Display GF low/high values
524 WIN_SMALL .0,.130 510 WIN_SMALL .0,.130
525 STRCAT_PRINT "GF:" 511 STRCAT_PRINT "GF:"
526 WIN_SMALL .25,.130 512 WIN_SMALL .25,.130
527 movff char_I_GF_Low_percentage,lo 513 movff char_I_GF_Low_percentage,lo
528 output_99x 514 output_8
529 STRCAT "/" 515 STRCAT "/"
530 movff char_I_GF_High_percentage,lo 516 movff char_I_GF_High_percentage,lo
531 output_99x 517 output_8
532 STRCAT_PRINT "" 518 STRCAT_PRINT ""
533 519
534 deco_show_plan_m2: 520 deco_show_plan_m2:
535 ;---- Display Deco Mode 521 ;---- Display Deco Mode
536 WIN_SMALL .0,.155 522 WIN_SMALL .0,.155
562 ;---- Display CNS result 548 ;---- Display CNS result
563 WIN_TOP .205 549 WIN_TOP .205
564 STRCPY_TEXT tCNS2 ; "CNS:" 550 STRCPY_TEXT tCNS2 ; "CNS:"
565 movff int_O_CNS_fraction+0,lo 551 movff int_O_CNS_fraction+0,lo
566 movff int_O_CNS_fraction+1,hi 552 movff int_O_CNS_fraction+1,hi
567 call TFT_color_code_cns ; Color-code CNS output 553 call TFT_color_code_cns ; color-code CNS output
568 bsf leftbind 554 bsf leftbind
569 output_16_3 ; limit to 999 and display only (0-999) 555 output_16_3 ; limit to 999 and display only (0-999)
570 bcf leftbind 556 bcf leftbind
571 STRCAT "%\x92" ; "->" 557 STRCAT "%\x92" ; "->"
572 movff int_O_normal_CNS_fraction+0,lo 558 movff int_O_normal_CNS_fraction+0,lo
573 movff int_O_normal_CNS_fraction+1,hi 559 movff int_O_normal_CNS_fraction+1,hi
574 call TFT_color_code_cns ; Color-code CNS output 560 call TFT_color_code_cns ; color-code CNS output
575 bsf leftbind 561 bsf leftbind
576 output_16_3 ; limit to 999 and display only (0-999) 562 output_16_3 ; limit to 999 and display only (0-999)
577 bcf leftbind 563 bcf leftbind
578 STRCAT_PRINT "%" 564 STRCAT_PRINT "%"
579 call TFT_standard_color 565 call TFT_standard_color
588 call logbook_preloop_tasks 574 call logbook_preloop_tasks
589 deco_show_plan_2: 575 deco_show_plan_2:
590 btfsc switch_right 576 btfsc switch_right
591 bra deco_show_plan_3 577 bra deco_show_plan_3
592 btfsc switch_left 578 btfsc switch_left
593 return ; Return to simulator menu 579 return ; return to simulator menu
594 call log_screendump_and_onesecond ; Check if we need to make a screen shot and check for new second 580 call log_screendump_and_onesecond ; check if we need to make a screen shot and check for new second
595 btfsc sleepmode ; Timeout? 581 btfsc sleepmode ; timeout?
596 goto restart 582 goto restart
597 bra deco_show_plan_2 583 bra deco_show_plan_2
598 584
599 deco_show_plan_3: 585 deco_show_plan_3:
600 btfss decoplan_last_ceiling_shown 586 btfss decoplan_last_ceiling_shown
601 bra deco_show_plan_1 587 bra deco_show_plan_1
602 ; All stops shown 588 ; all stops shown
603 589
604 ;---- In CCR and pSCR mode, compute a BAILOUT deco plan ----------------------- 590 ;----in CCR and pSCR mode, compute a BAILOUT deco plan -----------------------
605 movff char_O_deco_status,WREG ; get deco calculation status 591 movff char_O_deco_status,WREG ; get deco calculation status
606 btfss WREG,DECO_MODE_LOOP_FLAG ; check if in CCR or pSCR mode 592 btfss WREG,DECO_MODE_LOOP_FLAG ; check if in CCR or pSCR mode
607 bra simulator_show_decoplan5_0 ; NO - normal OC mode: just display 593 bra simulator_show_decoplan5_0 ; NO - normal OC mode: just display
608 bsf is_bailout ; YES - redo 2nd deco-plan in bailout mode 594 bsf FLAG_bailout_mode ; YES - redo 2nd deco-plan in bailout mode
609 rcall deco_planer_redo ; redo plan computation 595 rcall deco_planer_redo ; redo plan computation
610 596
611 btfss decoplan_abort ; shall we abort? 597 btfss decoplan_abort ; shall we abort?
612 bra deco_show_plan ; NO - display bailout stops 598 bra deco_show_plan ; NO - display bailout stops
613 return ; YES 599 return ; YES
614 600
615 601
616 ;---- In OC+BAIL modes, show the gas usage special page ----------------------- 602 ;---- in OC+BAIL modes, show the gas usage special page -----------------------
617 simulator_show_decoplan5_0: 603 simulator_show_decoplan5_0:
618 ; Clear the complete stop result column: 604 ; Clear the complete stop result column:
619 WIN_BOX_BLACK .0, .239, .80, .159 ; top, bottom, left, right 605 WIN_BOX_BLACK .0, .239, .80, .159 ; top, bottom, left, right
620 606
621 movlw .25 607 movlw .25
622 movwf row_pos ; Row for gas list is .25+.25 608 movwf row_pos ; row for gas list is .25+.25
623 clrf gas_counter ; Gas counter 609 clrf gas_counter ; gas counter
624 lfsr FSR0,int_O_gas_volumes ; Initialize indexed addressing. 610 lfsr FSR0,int_O_ascent_volumes ; initialize indexed addressing
625 611
626 WIN_LEFT .80 ; Set column 612 WIN_LEFT .80 ; set column
627 call TFT_standard_color 613 call TFT_standard_color
628 614
615 bcf FLAG_diluent_setup ; steer gaslist_strcat_gas to use OC gases
616
629 simulator_show_decoplan5_loop: 617 simulator_show_decoplan5_loop:
630 movff gas_counter,PRODL ; Copy to PRODL first 618 movff gas_counter,PRODL ; copy to PRODL first
631 incf gas_counter,F ; Increment gas # 619 incf gas_counter,F ; increment gas #
632 620
633 movff gas_counter,WREG ; copy current gas to WREG for color-coding 621 movff gas_counter,WREG ; copy current gas to WREG for color-coding
634 call TFT_color_code_gas ; set output color according to gas (1-5) 622 call TFT_color_code_gas ; set output color according to gas (1-5)
635 623
636 lfsr FSR2,buffer 624 lfsr FSR2,buffer
637 bsf short_gas_decriptions 625 bsf short_gas_decriptions
638 bsf divemode ; Tweak "customview_show_mix:" 626 bsf divemode ; tweak "customview_show_mix:"
639 call gaslist_strcat_gas ; Input: PRODL : gas number (0..4), Output: "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2 627 call gaslist_strcat_gas ; input: PRODL : gas number (0..4), Output: "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2
640 bcf divemode ; Tweak "customview_show_mix:" 628 bcf divemode ; tweak "customview_show_mix:"
641 629
642 movlw .25 630 movlw .25
643 addwf row_pos,F ; Increase row position 631 addwf row_pos,F ; increase row position
644 movff row_pos,win_top ; Set Row 632 movff row_pos,win_top ; set row
645 633
646 movff POSTINC0,lo ; Read (16bit) result, low first, 634 movff POSTINC0,lo ; read (16bit) result, low first,
647 movff POSTINC0,hi ; then high. 635 movff POSTINC0,hi ; then high
648 636
649 movf lo,W 637 movf lo,W
650 andwf hi,W 638 andwf hi,W
651 incf WREG ; > 65535? 639 incf WREG ; > 65535 ?
652 bnz simulator_show_decoplan5_1 ; NO 640 bnz simulator_show_decoplan5_1 ; NO
653 STRCAT_PRINT ">65500" ; YES 641 STRCAT_PRINT ">65500" ; YES
654 bra simulator_show_decoplan5_2 642 bra simulator_show_decoplan5_2
655 643
656 simulator_show_decoplan5_1: 644 simulator_show_decoplan5_1:
657 PUTC ":" 645 PUTC ":"
658 bsf leftbind 646 bsf leftbind
659 output_16 ; No decimal anymore. 647 output_16 ; no decimal anymore
660 bcf leftbind 648 bcf leftbind
661 STRCAT_PRINT "" 649 STRCAT_PRINT ""
662 650
663 ; Loop for all 5 gas 651 ; Loop for all 5 gas
664 simulator_show_decoplan5_2: 652 simulator_show_decoplan5_2:
665 movlw d'5' ; list all five gases 653 movlw d'5' ; list all five gases
666 cpfseq gas_counter ; All gases shown? 654 cpfseq gas_counter ; all gases shown?
667 bra simulator_show_decoplan5_loop ; No 655 bra simulator_show_decoplan5_loop ; NO - loop
668 656
669 WIN_COLOR color_greenish 657 WIN_COLOR color_greenish
670
671 movlw .30
672 addwf row_pos,F ; Increase row position
673 movff row_pos,win_top ; Set Row
674 STRCPY_TEXT_PRINT tBarLiter ; "Bar Liter"
675 658
676 WIN_SMALL .80,.25 659 WIN_SMALL .80,.25
677 STRCPY_TEXT tGasUsage ; "Gas Usage" 660 STRCPY_TEXT tGasUsage ; "Gas Usage"
678 STRCAT_PRINT ":" 661 STRCAT_PRINT ":"
662
663 WIN_SMALL .120,.175
664 STRCPY_TEXT_PRINT tLiterLong ; "Liter"
679 665
680 call TFT_standard_color 666 call TFT_standard_color
681 call logbook_preloop_tasks 667 call logbook_preloop_tasks
682 668
683 simulator_show_decoplan5_3: 669 simulator_show_decoplan5_3:
687 clrf decoplan_page 673 clrf decoplan_page
688 bra deco_show_plan_1 ; toggle between stops plan and gas usage 674 bra deco_show_plan_1 ; toggle between stops plan and gas usage
689 simulator_show_decoplan5_3a: 675 simulator_show_decoplan5_3a:
690 btfss switch_left 676 btfss switch_left
691 bra simulator_show_decoplan5_4 677 bra simulator_show_decoplan5_4
692 bcf is_bailout ; Back to normal 678 bcf FLAG_bailout_mode ; back to normal
693 bcf ccr_diluent_setup ; init for OC/Bailout 679 return ; return to simulator menu
694 return ; Return to simulator menu
695 680
696 simulator_show_decoplan5_4: 681 simulator_show_decoplan5_4:
697 call log_screendump_and_onesecond ; Check if we need to make a screen shot and check for new second 682 call log_screendump_and_onesecond ; check if we need to make a screen shot and check for new second
698 btfsc sleepmode ; Timeout? 683 btfsc sleepmode ; timeout?
699 goto restart 684 goto restart
700 bra simulator_show_decoplan5_3 685 bra simulator_show_decoplan5_3
701 686
702 END 687 END