Mercurial > public > mk2
annotate code_part1/OSTC_code_c_part2/p2_deco.c @ 218:f4b79292e31f
BUGFIX NoFly time
Bug in char-to-float promotion ???
author | JeanDo |
---|---|
date | Sat, 26 Feb 2011 17:53:43 +0100 |
parents | ce6f16711567 |
children | 638f8e17bd51 |
rev | line source |
---|---|
116 | 1 // ************************************************************** |
2 // p2_deco.c | |
3 // | |
4 // Created on: 12.05.2009 | |
5 // Author: chsw | |
6 // | |
7 // ************************************************************** | |
8 | |
9 ////////////////////////////////////////////////////////////////////////////// | |
10 // OSTC - diving computer code | |
11 // Copyright (C) 2008 HeinrichsWeikamp GbR | |
12 // | |
13 // This program is free software: you can redistribute it and/or modify | |
14 // it under the terms of the GNU General Public License as published by | |
15 // the Free Software Foundation, either version 3 of the License, or | |
16 // (at your option) any later version. | |
17 // | |
18 // This program is distributed in the hope that it will be useful, | |
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 // GNU General Public License for more details. | |
22 // | |
23 // You should have received a copy of the GNU General Public License | |
24 // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 // | |
26 ////////////////////////////////////////////////////////////////////////////// | |
27 | |
28 // ***************************** | |
29 // ** I N T R O D U C T I O N ** | |
30 // ***************************** | |
31 // | |
32 // OSTC | |
33 // | |
34 // code: | |
35 // p2_deco_main_c_v101.c | |
36 // part2 of the OSTC code | |
37 // code with constant O2 partial pressure routines | |
38 // under construction !! | |
39 // | |
40 // summary: | |
41 // decompression routines | |
42 // for the OSTC experimental project | |
43 // written by Christian Weikamp | |
44 // last revision __________ | |
45 // comments added _________ | |
46 // | |
47 // additional files: | |
48 // p2_tables_v100.romdata (other files) | |
49 // 18f4685_ostc_v100.lkr (linker script) | |
50 // | |
51 // history: | |
52 // 01/03/08 v100: first release candidate | |
53 // 03/13/08 v101: start of programming ppO2 code | |
54 // 03/13/25 v101a: backup of interrim version with ppO2 calculation | |
55 // 03/13/25 v101: open circuit gas change during deco | |
56 // 03/13/25 v101: CNS_fraction calculation | |
57 // 03/13/26 v101: optimization of tissue calc routines | |
58 // 07/xx/08 v102a: debug of bottom time routine | |
59 // 09/xx/08 v102d: Gradient Factor Model implemenation | |
60 // 10/10/08 v104: renamed to build v103 for v118 stable | |
171 | 61 // 10/14/08 v104: integration of char_I_depth_last_deco for Gradient Model |
116 | 62 // 03/31/09 v107: integration of FONT Incon24 |
63 // 05/23/10 v109: 5 gas changes & 1 min timer | |
64 // 07/13/10 v110: cns vault added | |
65 // 12/25/10 v110: split in three files (deco.c, main.c, definitions.h) | |
163 | 66 // 2011/01/20: [jDG] Create a common file included in ASM and C code. |
167 | 67 // 2011/01/23: [jDG] Added read_custom_function(). |
203 | 68 // 2011/01/24: [jDG] Make ascenttime an short. No more overflow! |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
69 // 2011/01/25: [jDG] Fusion deco array for both models. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
70 // 2011/01/25: [jDG] Use CF(54) to reverse deco order. |
193 | 71 // 2011/02/11: [jDG] Reworked gradient-factor implementation. |
197 | 72 // 2011/02/13: [jDG] CF55 for additional gas switch delay in decoplan. |
217 | 73 // 2011/02/24: [jDG] Fixed inconsistencies introduced by gas switch delays. |
116 | 74 // |
167 | 75 // TODO: |
76 // + Allow to abort MD2 calculation (have to restart next time). | |
77 // | |
78 // Literature: | |
200 | 79 // Bühlmann, Albert: Tauchmedizin; 4. Auflage [2002]; |
116 | 80 // Schr"oder, Kai & Reith, Steffen; 2000; S"attigungsvorg"ange beim Tauchen, das Modell ZH-L16, Funktionsweise von Tauchcomputern; http://www.achim-und-kai.de/kai/tausim/saett_faq |
81 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html | |
82 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf | |
83 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops" | |
84 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf | |
167 | 85 // |
86 // | |
116 | 87 |
88 // ********************* | |
89 // ** I N C L U D E S ** | |
90 // ********************* | |
91 #include <math.h> | |
167 | 92 |
192 | 93 // *********************************************** |
94 // ** V A R I A B L E S D E F I N I T I O N S ** | |
95 // *********************************************** | |
96 | |
97 #include "p2_definitions.h" | |
98 #include "shared_definitions.h" | |
99 | |
200 | 100 // Water vapour partial pressure in the lumb. |
101 static const float ppWVapour = 0.0627; | |
102 | |
167 | 103 // ************************* |
104 // ** P R O T O T Y P E S ** | |
105 // ************************* | |
106 | |
107 static void calc_hauptroutine(void); | |
108 static void calc_nullzeit(void); | |
109 | |
192 | 110 static void calc_tissue(PARAMETER unsigned char period); |
111 static void calc_limit(PARAMETER float GF_current); | |
112 | |
167 | 113 static void clear_tissue(void); |
114 static void calc_ascenttime(void); | |
115 static void update_startvalues(void); | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
116 static void clear_deco_table(void); |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
117 static void update_deco_table(void); |
192 | 118 |
119 static void backup_sim_pres_tissue(void); | |
120 static void restore_sim_pres_tissue(void); | |
121 static void sim_tissue(PARAMETER unsigned char period); | |
122 static void sim_limit(PARAMETER float GF_current); | |
167 | 123 static void calc_gradient_factor(void); |
124 static void calc_wo_deco_step_1_min(void); | |
125 | |
126 static void calc_hauptroutine_data_input(void); | |
127 static void calc_hauptroutine_update_tissues(void); | |
128 static void calc_hauptroutine_calc_deco(void); | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
129 static void sim_ascent_to_first_stop(void); |
167 | 130 |
217 | 131 static void deepest_gas_switch(void); |
132 static void best_gas_switch(void); | |
133 static void set_gas(void); | |
134 | |
171 | 135 static void calc_nextdecodepth(void); |
116 | 136 |
200 | 137 //---- Bank 4 parameters ----------------------------------------------------- |
163 | 138 #pragma udata bank4=0x400 |
116 | 139 |
140 static float temp_limit; | |
141 static float GF_low; | |
142 static float GF_high; | |
143 static float GF_delta; | |
192 | 144 static unsigned char low_depth; // Depth of deepest stop |
145 static float locked_GF_step; // GF_delta / low_depth | |
146 | |
147 static unsigned char temp_depth_limit; | |
171 | 148 |
192 | 149 // Simulation context: used to predict ascent. |
150 static unsigned char sim_lead_tissue_no; // Leading compatiment number. | |
151 static float sim_lead_tissue_limit; // Buhlmann tolerated pressure. | |
116 | 152 |
192 | 153 // Real context: what we are doing now. |
154 static float calc_lead_tissue_limit; // | |
116 | 155 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
156 static unsigned char internal_deco_time[32]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
157 static unsigned char internal_deco_depth[32]; |
116 | 158 |
159 static float cns_vault; | |
160 static float pres_tissue_vault[32]; | |
161 | |
163 | 162 //---- Bank 5 parameters ----------------------------------------------------- |
163 #pragma udata bank5=0x500 | |
164 | |
167 | 165 static unsigned char ci; |
116 | 166 static float pres_respiration; |
167 static float pres_surface; | |
168 static float temp_deco; | |
200 | 169 static float ppO2; |
170 static float ppHe; | |
116 | 171 static float temp_tissue; |
200 | 172 static float N2_ratio; // Breathed gas nitrogen ratio. |
173 static float He_ratio; // Breathed gas helium ratio. | |
174 static float var_N2_a; // Bühlmann a, for current N2 tissue. | |
175 static float var_N2_b; // Bühlmann b, for current N2 tissue. | |
176 static float var_He_a; // Bühlmann a, for current He tissue. | |
177 static float var_He_b; // Bühlmann b, for current He tissue. | |
178 static float var_N2_e; // Exposition, for current N2 tissue. | |
179 static float var_He_e; // Exposition, for current He tissue. | |
116 | 180 |
164 | 181 static float pres_diluent; // new in v.101 |
182 static float const_ppO2; // new in v.101 | |
183 static float deco_ppO2_change; // new in v.101 | |
184 static float deco_ppO2; // new in v.101 | |
116 | 185 |
200 | 186 static unsigned char sim_gas_last_used; // Last used gas, to detected a gas switch. |
203 | 187 static unsigned short sim_gas_delay; // Time of gas-switch-stop ends [min on dive]. |
188 static unsigned short sim_dive_mins; // Simulated dive time. | |
200 | 189 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio. |
190 static float calc_He_ratio; // Simulated (switched) helium ratio. | |
191 static float CNS_fraction; // new in v.101 | |
192 static float float_saturation_multiplier; // new in v.101 | |
193 static float float_desaturation_multiplier; // new in v.101 | |
167 | 194 static float float_deco_distance; // new in v.101 |
195 static char flag_in_divemode; // new in v.108 | |
196 | |
212 | 197 static unsigned char deco_gas_change1; // new in v.101 |
198 static unsigned char deco_gas_change2; // new in v.109 | |
199 static unsigned char deco_gas_change3; // new in v.109 | |
200 static unsigned char deco_gas_change4; // new in v.109 | |
201 static unsigned char deco_gas_change5; // new in v.109 | |
167 | 202 |
203 static float deco_N2_ratio1; // new in v.101 | |
204 static float deco_He_ratio1; // new in v.101 | |
205 | |
206 | |
163 | 207 //---- Bank 6 parameters ----------------------------------------------------- |
208 #pragma udata bank6=0x600 | |
116 | 209 |
197 | 210 float pres_tissue[32]; |
211 float pres_tissue_limit[16]; | |
212 float sim_pres_tissue_limit[16]; | |
116 | 213 |
163 | 214 //---- Bank 7 parameters ----------------------------------------------------- |
215 #pragma udata bank7=0x700 | |
216 | |
197 | 217 float sim_pres_tissue[32]; // 32 floats = 128 bytes. |
116 | 218 static float sim_pres_tissue_backup[32]; |
219 | |
163 | 220 //---- Bank 8 parameters ----------------------------------------------------- |
116 | 221 #pragma udata bank8=0x800 |
163 | 222 |
116 | 223 static char md_pi_subst[256]; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
224 #define C_STACK md_pi_subst // Overlay C-code data stack here, too. |
116 | 225 |
163 | 226 //---- Bank 9 parameters ----------------------------------------------------- |
167 | 227 #pragma udata bank9=0x900 |
116 | 228 |
163 | 229 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! |
116 | 230 |
164 | 231 // internal, dbg: |
167 | 232 static unsigned char DBG_char_I_deco_model; // new in v.108. |
164 | 233 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 |
212 | 234 static unsigned char DBG_deco_gas_change; // new in v.108 |
164 | 235 static float DBG_pres_surface; // new in v.108 |
236 static float DBG_GF_low; // new in v.108 | |
237 static float DBG_GF_high; // new in v.108 | |
238 static float DBG_const_ppO2; // new in v.108 | |
239 static float DBG_deco_ppO2_change; // new in v.108 | |
240 static float DBG_deco_ppO2; // new in v.108 | |
241 static float DBG_deco_N2_ratio; // new in v.108 | |
242 static float DBG_deco_He_ratio; // new in v.108 | |
243 static float DBG_float_saturation_multiplier; // new in v.108 | |
244 static float DBG_float_desaturation_multiplier; // new in v.108 | |
245 static float DBG_float_deco_distance; // new in v.108 | |
246 static float DBG_deco_N2_ratio; // new in v.108 | |
247 static float DBG_deco_He_ratio; // new in v.108 | |
248 static float DBG_N2_ratio; // new in v.108 | |
249 static float DBG_He_ratio; // new in v.108 | |
250 | |
167 | 251 ////////////////////////////////////////////////////////////////////////////// |
252 ////////////////////////////////////////////////////////////////////////////// | |
253 ///////////////////////////// THE LOOKUP TABLES ////////////////////////////// | |
254 ////////////////////////////////////////////////////////////////////////////// | |
255 ////////////////////////////////////////////////////////////////////////////// | |
256 // | |
257 // End of PROM code is 17F00, So push tables on PROM top... | |
258 // | |
259 #pragma romdata buhlmann_tables = 0x017B00 // Needs to be in UPPER bank. | |
260 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_N2_a modified) | |
116 | 261 |
167 | 262 // Magic table to compute the MD2 HASH |
263 // | |
264 #pragma romdata hash_tables = 0x017E00 // Address fixed by ASM access... | |
203 | 265 rom const rom unsigned short md_pi[] = |
116 | 266 { |
267 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613 | |
268 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA | |
269 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512 | |
270 , 0xBE4E, 0xC4D6, 0xDA9E, 0xDE49, 0xA0FB, 0xF58E, 0xBB2F, 0xEE7A | |
271 , 0xA968, 0x7991, 0x15B2, 0x073F, 0x94C2, 0x1089, 0x0B22, 0x5F21 | |
272 , 0x807F, 0x5D9A, 0x5A90, 0x3227, 0x353E, 0xCCE7, 0xBFF7, 0x9703 | |
273 , 0xFF19, 0x30B3, 0x48A5, 0xB5D1, 0xD75E, 0x922A, 0xAC56, 0xAAC6 | |
274 , 0x4FB8, 0x38D2, 0x96A4, 0x7DB6, 0x76FC, 0x6BE2, 0x9C74, 0x04F1 | |
275 , 0x459D, 0x7059, 0x6471, 0x8720, 0x865B, 0xCF65, 0xE62D, 0xA802 | |
276 , 0x1B60, 0x25AD, 0xAEB0, 0xB9F6, 0x1C46, 0x6169, 0x3440, 0x7E0F | |
277 , 0x5547, 0xA323, 0xDD51, 0xAF3A, 0xC35C, 0xF9CE, 0xBAC5, 0xEA26 | |
278 , 0x2C53, 0x0D6E, 0x8528, 0x8409, 0xD3DF, 0xCDF4, 0x4181, 0x4D52 | |
279 , 0x6ADC, 0x37C8, 0x6CC1, 0xABFA, 0x24E1, 0x7B08, 0x0CBD, 0xB14A | |
280 , 0x7888, 0x958B, 0xE363, 0xE86D, 0xE9CB, 0xD5FE, 0x3B00, 0x1D39 | |
281 , 0xF2EF, 0xB70E, 0x6658, 0xD0E4, 0xA677, 0x72F8, 0xEB75, 0x4B0A | |
282 , 0x3144, 0x50B4, 0x8FED, 0x1F1A, 0xDB99, 0x8D33, 0x9F11, 0x8314 | |
283 }; | |
284 | |
167 | 285 ////////////////////////////////////////////////////////////////////////////// |
286 ////////////////////////////////////////////////////////////////////////////// | |
287 ////////////////////////////// THE SUBROUTINES /////////////////////////////// | |
288 ////////////////////////////////////////////////////////////////////////////// | |
289 ////////////////////////////////////////////////////////////////////////////// | |
290 // | |
116 | 291 // all new in v.102 |
292 // moved from 0x0D000 to 0x0C000 in v.108 | |
293 | |
294 #pragma code p2_deco = 0x0C000 | |
295 | |
167 | 296 ////////////////////////////////////////////////////////////////////////////// |
297 // DBS - debug on start of dive | |
298 // | |
299 static void create_dbs_set_dbg_and_ndl20mtr(void) | |
116 | 300 { |
167 | 301 overlay char i; // Local loop index. |
302 | |
303 //---- Reset DEBUG bit fields -------------------------------------------- | |
116 | 304 int_O_DBS_bitfield = 0; |
305 int_O_DBS2_bitfield = 0; | |
306 if(int_O_DBG_pre_bitfield & DBG_RUN) | |
307 int_O_DBG_pre_bitfield = DBG_RESTART; | |
308 else | |
309 int_O_DBG_pre_bitfield = DBG_RUN; | |
310 int_O_DBG_post_bitfield = 0; | |
167 | 311 |
312 //---- Set 20meters ND limit --------------------------------------------- | |
116 | 313 char_O_NDL_at_20mtr = 255; |
314 | |
167 | 315 //---- Copy all dive parameters ------------------------------------------ |
116 | 316 DBG_N2_ratio = N2_ratio; |
317 DBG_He_ratio = He_ratio; | |
318 DBG_char_I_deco_model = char_I_deco_model; | |
319 DBG_char_I_depth_last_deco = char_I_depth_last_deco; | |
320 DBG_pres_surface = pres_surface; | |
321 DBG_GF_low = GF_low; | |
322 DBG_GF_high = GF_high; | |
323 DBG_const_ppO2 = const_ppO2; | |
324 DBG_deco_ppO2_change = deco_ppO2_change; | |
325 DBG_deco_ppO2 = deco_ppO2; | |
167 | 326 DBG_deco_N2_ratio = deco_N2_ratio1; |
327 DBG_deco_He_ratio = deco_He_ratio1; | |
328 DBG_deco_gas_change = deco_gas_change1; | |
116 | 329 DBG_float_saturation_multiplier = float_saturation_multiplier; |
330 DBG_float_desaturation_multiplier = float_desaturation_multiplier; | |
331 DBG_float_deco_distance = float_deco_distance; | |
332 | |
167 | 333 //---- Setup some error (?) conditions ----------------------------------- |
116 | 334 if(char_I_deco_model) |
335 int_O_DBS_bitfield |= DBS_mode; | |
336 if(const_ppO2) | |
337 int_O_DBS_bitfield |= DBS_ppO2; | |
167 | 338 for(i = 16; i < 32; i++) |
339 if(pres_tissue[i]) | |
116 | 340 int_O_DBS_bitfield |= DBS_HE_sat; |
341 if(deco_ppO2_change) | |
342 int_O_DBS_bitfield |= DBS_ppO2chg; | |
343 if(float_saturation_multiplier < 0.99) | |
344 int_O_DBS_bitfield |= DBS_SAT2l; | |
345 if(float_saturation_multiplier > 1.3) | |
346 int_O_DBS_bitfield |= DBS_SAT2h; | |
347 if(GF_low < 0.19) | |
348 int_O_DBS_bitfield |= DBS_GFLOW2l; | |
349 if(GF_low > 1.01) | |
350 int_O_DBS_bitfield |= DBS_GFLOW2h; | |
351 if(GF_high < 0.6) | |
352 int_O_DBS_bitfield |= DBS_GFHGH2l; | |
353 if(GF_high > 1.01) | |
354 int_O_DBS_bitfield |= DBS_GFHGH2h; | |
355 if((N2_ratio + He_ratio) > 0.95) | |
356 int_O_DBS_bitfield |= DBS_GASO22l; | |
357 if((N2_ratio + He_ratio) < 0.05) | |
358 int_O_DBS_bitfield |= DBS_GASO22h; | |
359 if(float_deco_distance > 0.25) | |
360 int_O_DBS_bitfield |= DBS_DIST2h; | |
361 if(char_I_depth_last_deco > 8) | |
362 int_O_DBS_bitfield |= DBS_LAST2h; | |
167 | 363 if(DBG_deco_gas_change && ((deco_N2_ratio1 + deco_He_ratio1) > 0.95)) |
116 | 364 int_O_DBS_bitfield |= DBS_DECOO2l; |
167 | 365 if(DBG_deco_gas_change && ((deco_N2_ratio1 + deco_He_ratio1) < 0.05)) |
116 | 366 int_O_DBS_bitfield |= DBS_DECOO2h; |
367 if(pres_respiration > 3.0) | |
368 int_O_DBS2_bitfield |= DBS2_PRES2h; | |
369 if(pres_surface - pres_respiration > 0.2) | |
370 int_O_DBS2_bitfield |= DBS2_PRES2l; | |
371 if(pres_surface < 0.75) | |
372 int_O_DBS2_bitfield |= DBS2_SURF2l; | |
373 if(pres_surface > 1.11) | |
374 int_O_DBS2_bitfield |= DBS2_SURF2h; | |
375 if(float_desaturation_multiplier < 0.70) | |
376 int_O_DBS2_bitfield |= DBS2_DESAT2l; | |
377 if(float_desaturation_multiplier > 1.01) | |
378 int_O_DBS2_bitfield |= DBS2_DESAT2h; | |
379 if(GF_low > GF_high) | |
380 int_O_DBS2_bitfield |= DBS2_GFDneg; | |
381 } | |
382 | |
167 | 383 ////////////////////////////////////////////////////////////////////////////// |
384 // DBG - set DBG to end_of_dive | |
385 // | |
386 static void set_dbg_end_of_dive(void) | |
116 | 387 { |
388 int_O_DBG_pre_bitfield &= (~DBG_RUN); | |
389 int_O_DBG_post_bitfield &= (~DBG_RUN); | |
390 } | |
391 | |
167 | 392 ////////////////////////////////////////////////////////////////////////////// |
393 // DBG - NDL at first 20 m. hit | |
394 // | |
395 static void check_ndl(void) | |
116 | 396 { |
167 | 397 if( char_O_NDL_at_20mtr == 255 // Still in NDL mode ? |
398 && int_I_pres_respiration > 3000 // And we hit the 20m limit ? | |
399 ) | |
116 | 400 { |
167 | 401 char_O_NDL_at_20mtr = char_O_nullzeit; // change to max bottom time. |
402 if( char_O_NDL_at_20mtr == 255) // and avoid confusion. | |
184 | 403 char_O_NDL_at_20mtr = 254; |
116 | 404 } |
405 } | |
406 | |
167 | 407 ////////////////////////////////////////////////////////////////////////////// |
408 // DBG - multi main during dive | |
409 // | |
184 | 410 static void check_dbg(PARAMETER char is_post_check) |
116 | 411 { |
203 | 412 overlay unsigned short temp_DBS = 0; |
200 | 413 overlay unsigned char i; // Local loop index. |
167 | 414 |
116 | 415 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) |
416 temp_DBS |= DBG_c_gas; | |
417 if(DBG_const_ppO2 != const_ppO2) | |
418 temp_DBS |= DBG_c_ppO2; | |
167 | 419 if( DBG_float_saturation_multiplier != float_saturation_multiplier |
420 || DBG_float_desaturation_multiplier != float_desaturation_multiplier | |
421 ) | |
116 | 422 temp_DBS |= DBG_CdeSAT; |
423 if(DBG_char_I_deco_model != char_I_deco_model) | |
424 temp_DBS |= DBG_C_MODE; | |
425 if(DBG_pres_surface != pres_surface) | |
426 temp_DBS |= DBG_C_SURF; | |
167 | 427 |
428 if( !DBS_HE_sat && !He_ratio) | |
429 for(i = 16; i < 32; i++) | |
430 if(pres_tissue[i]) | |
116 | 431 temp_DBS |= DBG_HEwoHE; |
167 | 432 |
116 | 433 if(DBG_deco_ppO2 != deco_ppO2) |
434 temp_DBS |= DBG_C_DPPO2; | |
167 | 435 |
436 if( DBG_deco_gas_change != deco_gas_change1 | |
437 || DBG_deco_N2_ratio != deco_N2_ratio1 | |
438 || DBG_deco_He_ratio != deco_He_ratio1 ) | |
116 | 439 temp_DBS |= DBG_C_DGAS; |
167 | 440 |
116 | 441 if(DBG_float_deco_distance != float_deco_distance) |
442 temp_DBS |= DBG_C_DIST; | |
443 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco) | |
444 temp_DBS |= DBG_C_LAST; | |
167 | 445 if( DBG_GF_low != GF_low |
446 || DBG_GF_high != GF_high ) | |
116 | 447 temp_DBS |= DBG_C_GF; |
448 if(pres_respiration > 13.0) | |
449 temp_DBS |= DBG_PHIGH; | |
450 if(pres_surface - pres_respiration > 0.2) | |
451 temp_DBS |= DBG_PLOW; | |
452 if(is_post_check) | |
453 int_O_DBG_post_bitfield |= temp_DBS; | |
454 else | |
455 int_O_DBG_pre_bitfield |= temp_DBS; | |
456 } | |
457 | |
167 | 458 ////////////////////////////////////////////////////////////////////////////// |
459 // DBG - prior to calc. of dive | |
460 // | |
461 static void check_pre_dbg(void) | |
116 | 462 { |
463 check_dbg(0); | |
464 } | |
465 | |
167 | 466 ////////////////////////////////////////////////////////////////////////////// |
467 // DBG - after decocalc of dive | |
468 // | |
469 static void check_post_dbg(void) | |
116 | 470 { |
471 check_dbg(1); | |
472 } | |
473 | |
165 | 474 ////////////////////////////////////////////////////////////////////////////// |
167 | 475 ////////////////////////////////////////////////////////////////////////////// |
476 /////////////////////// U T I L I T I E S ///////////////////////////////// | |
477 ////////////////////////////////////////////////////////////////////////////// | |
478 ////////////////////////////////////////////////////////////////////////////// | |
479 | |
203 | 480 static short read_custom_function(PARAMETER unsigned char cf) |
167 | 481 { |
184 | 482 #ifdef CROSS_COMPILE |
483 extern unsigned short custom_functions[]; | |
484 return custom_functions[cf]; | |
485 #else | |
167 | 486 extern unsigned char hi, lo; |
487 extern void getcustom15(); | |
488 _asm | |
489 movff cf,WREG | |
490 call getcustom15,0 | |
491 movff lo,PRODL | |
492 movff hi,PRODH | |
493 _endasm | |
184 | 494 #endif |
167 | 495 } |
496 | |
497 ////////////////////////////////////////////////////////////////////////////// | |
165 | 498 // read buhlmann tables for compatriment ci |
167 | 499 // If period == 0 : 2sec interval |
500 // 1 : 1 min interval | |
501 // 2 : 10 min interval. | |
184 | 502 static void read_buhlmann_coefficients(PARAMETER char period) |
165 | 503 { |
184 | 504 #ifndef CROSS_COMPILE |
167 | 505 // Note: we don't use far rom pointer, because the |
506 // 24 bits is to complex, hence we have to set | |
507 // the UPPER page ourself... | |
508 // --> Set zero if tables are moved to lower pages ! | |
509 _asm | |
510 movlw 1 | |
511 movwf TBLPTRU,0 | |
512 _endasm | |
184 | 513 #endif |
197 | 514 assert( 0 <= ci && ci < 16 ); |
167 | 515 |
165 | 516 var_N2_a = buhlmann_a[ci]; |
517 var_N2_b = buhlmann_b[ci]; | |
167 | 518 var_He_a = (buhlmann_a+16)[ci]; |
519 var_He_b = (buhlmann_b+16)[ci]; | |
520 | |
165 | 521 // Check reading consistency: |
522 if( (var_N2_a < 0.231) | |
523 || (var_N2_a > 1.27) | |
524 || (var_N2_b < 0.504) | |
525 || (var_N2_b > 0.966) | |
526 || (var_He_a < 0.510) | |
527 || (var_He_a > 1.75) | |
528 || (var_He_b < 0.423) | |
529 || (var_He_b > 0.927) | |
530 ) | |
531 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
167 | 532 |
165 | 533 // Integration intervals. |
167 | 534 switch(period) |
165 | 535 { |
167 | 536 case -1://---- no interval ----------------------------------------------- |
537 var_N2_e = var_He_e = 0.0; | |
538 break; | |
539 | |
165 | 540 case 0: //---- 2 sec ----------------------------------------------------- |
541 var_N2_e = e2secs[ci]; | |
167 | 542 var_He_e = (e2secs+16)[ci]; |
165 | 543 |
544 // Check reading consistency: | |
545 if( (var_N2_e < 0.0000363) | |
546 || (var_N2_e > 0.00577) | |
547 || (var_He_e < 0.0000961) | |
548 || (var_He_e > 0.150) | |
549 ) | |
550 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
551 | |
552 break; | |
553 | |
554 case 1: //---- 1 min ----------------------------------------------------- | |
555 var_N2_e = e1min[ci]; | |
167 | 556 var_He_e = (e1min+16)[ci]; |
165 | 557 |
558 // Check reading consistency: | |
559 if( (var_N2_e < 1.09E-3) | |
560 || (var_N2_e > 0.1592) | |
561 || (var_He_e < 0.00288) | |
562 || (var_He_e > 0.3682) | |
563 ) | |
564 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
565 | |
566 break; | |
567 | |
568 case 2: //---- 10 min ---------------------------------------------------- | |
569 var_N2_e = e10min[ci]; | |
167 | 570 var_He_e = (e10min+16)[ci]; |
165 | 571 |
572 // Check reading consistency: | |
573 if( (var_N2_e < 0.01085) | |
574 || (var_N2_e > 0.82323) | |
575 || (var_He_e < 0.02846) | |
576 || (var_He_e > 0.98986) | |
577 ) | |
578 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
579 | |
580 break; | |
197 | 581 |
582 default: | |
583 assert(0); // Never go there... | |
165 | 584 } |
585 } | |
586 | |
587 ////////////////////////////////////////////////////////////////////////////// | |
167 | 588 // calc_next_decodepth_GF |
165 | 589 // |
116 | 590 // new in v.102 |
165 | 591 // |
116 | 592 // INPUT, changing during dive: |
192 | 593 // low_depth |
167 | 594 // |
116 | 595 // INPUT, fixed during dive: |
167 | 596 // pres_surface |
597 // GF_delta | |
598 // GF_high | |
599 // GF_low | |
171 | 600 // char_I_depth_last_deco |
167 | 601 // float_deco_distance |
602 // | |
116 | 603 // OUTPUT |
171 | 604 // locked_GF_step |
167 | 605 // temp_depth_limt |
192 | 606 // low_depth |
167 | 607 // |
171 | 608 static void calc_nextdecodepth(void) |
167 | 609 { |
212 | 610 //---- ZH-L16 + GRADIENT FACTOR model ------------------------------------ |
116 | 611 if (char_I_deco_model == 1) |
612 { | |
192 | 613 // Recompute leading gas limit, at current depth: |
614 overlay float depth = (temp_deco - pres_surface) / 0.09995; | |
615 assert( depth >= 0.0 ); | |
203 | 616 assert( low_depth < 255 ); |
167 | 617 |
192 | 618 if( depth > low_depth ) |
619 sim_limit( GF_low ); | |
620 else | |
621 sim_limit( GF_high - depth * locked_GF_step ); | |
622 | |
623 // Stops are needed ? | |
624 if( sim_lead_tissue_limit > pres_surface ) | |
625 { | |
626 // Deepest stop, in meter. | |
203 | 627 overlay unsigned char first_stop = 3 * (short)(0.99 + (sim_lead_tissue_limit - pres_surface) / 0.29985); |
192 | 628 assert( first_stop < 128 ); |
171 | 629 |
212 | 630 // Apply correction for the shallowest stop. |
192 | 631 if( first_stop == 3 ) // new in v104 |
632 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead. | |
171 | 633 |
192 | 634 // Check all stops until one is higher than tolerated presure |
635 while(first_stop > 0) | |
636 { | |
637 overlay unsigned char next_stop; // Next index (0..30) | |
638 overlay float pres_stop; // Next depth (0m..90m) | |
171 | 639 |
192 | 640 if( first_stop <= char_I_depth_last_deco ) // new in v104 |
641 next_stop = 0; | |
216 | 642 else if( first_stop == 6 ) |
643 next_stop = char_I_depth_last_deco; | |
192 | 644 else |
645 next_stop = first_stop - 3; // Index of next (upper) stop. | |
167 | 646 |
192 | 647 pres_stop = next_stop * 0.09995 // Meters to bar |
648 + pres_surface; | |
649 | |
212 | 650 // Keep GF_low until a first stop depth is found: |
651 if( next_stop >= low_depth ) | |
652 sim_limit( GF_low ); | |
653 else | |
654 // current GF is GF_high - alpha (GF_high - GF_low) | |
655 // With alpha = currentDepth / maxDepth, hence in [0..1] | |
656 sim_limit( GF_high - next_stop * locked_GF_step ); | |
171 | 657 |
192 | 658 // upper limit (lowest pressure tolerated): |
659 if( sim_lead_tissue_limit >= pres_stop ) // check if ascent to next deco stop is ok | |
660 break; | |
661 | |
662 // Else, validate that stop and loop... | |
663 first_stop = next_stop; | |
664 } | |
171 | 665 |
212 | 666 // Is it a new deepest first stop ? If yes this is the reference for |
667 // the varying gradient factor. So reset that: | |
668 if( first_stop > low_depth ) | |
669 { | |
670 // Store the deepest stop depth, as reference for GF_low. | |
671 low_depth = first_stop; | |
672 locked_GF_step = GF_delta / low_depth; | |
673 } | |
674 | |
675 // next stop is the last validated depth found, aka first_stop | |
192 | 676 temp_depth_limit = first_stop; // Stop depth, in meter. |
677 } | |
171 | 678 else |
192 | 679 temp_depth_limit = 0; // stop depth, in meter. |
116 | 680 } |
167 | 681 else //---- ZH-L16 model ------------------------------------------------- |
116 | 682 { |
192 | 683 overlay float pres_gradient; |
684 | |
685 // Original model | |
116 | 686 // optimized in v.101 |
171 | 687 // char_I_depth_last_deco included in v.101 |
116 | 688 |
192 | 689 // Compute sim_lead_tissue_limit too, but just once. |
690 sim_limit(1.0); | |
691 | |
692 pres_gradient = sim_lead_tissue_limit - pres_surface; | |
167 | 693 if (pres_gradient >= 0) |
116 | 694 { |
192 | 695 pres_gradient /= 0.29985; // Bar --> stop number; |
203 | 696 temp_depth_limit = 3 * (short) (pres_gradient + 0.99); // --> meter : depth for deco |
212 | 697 if (temp_depth_limit != 0) // At surface ? |
116 | 698 { |
171 | 699 if (temp_depth_limit < char_I_depth_last_deco) // Implement last stop at 4m/5m/6m... |
700 temp_depth_limit = char_I_depth_last_deco; | |
701 } | |
702 } | |
116 | 703 else |
192 | 704 temp_depth_limit = 0; // stop depth, in meter. |
171 | 705 } |
212 | 706 |
217 | 707 //---- Check gas change -------------------------------------------------- |
708 best_gas_switch(); // Update temp_depth_limit if there is a change, | |
212 | 709 // Calculate N2_ratio and He_ratio too. |
167 | 710 } |
116 | 711 |
167 | 712 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
713 // copy_deco_table |
167 | 714 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
715 // Buffer the stops, once computed, so we can continue to display them |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
716 // while computing the next set. |
167 | 717 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
718 static void copy_deco_table(void) |
116 | 719 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
720 // Copy depth of the first (deepest) stop, because when reversing |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
721 // order, it will be hard to find... |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
722 char_O_first_deco_depth = internal_deco_depth[0]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
723 char_O_first_deco_time = internal_deco_time [0]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
724 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
725 if( read_custom_function(54) & 1 ) //---- Should we reverse table ? ------ |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
726 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
727 overlay unsigned char x, y; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
728 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
729 //---- First: search the first non-null depth |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
730 for(x=31; x != 0; --x) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
731 if( internal_deco_depth[x] != 0 ) break; |
116 | 732 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
733 //---- Second: copy to output table (in reverse order) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
734 for(y=0; y<32; y++, --x) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
735 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
736 char_O_deco_depth[y] = internal_deco_depth[x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
737 char_O_deco_time [y] = internal_deco_time [x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
738 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
739 // Stop only once the last transfer is done. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
740 if( x == 0 ) break; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
741 } |
116 | 742 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
743 //---- Third: fill table end with null |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
744 for(y++; y<32; y++) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
745 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
746 char_O_deco_time [y] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
747 char_O_deco_depth[y] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
748 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
749 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
750 else //---- Straight copy ------------------------------------------------ |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
751 { |
167 | 752 overlay unsigned char x; |
753 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
754 for(x=0; x<32; x++) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
755 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
756 char_O_deco_depth[x] = internal_deco_depth[x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
757 char_O_deco_time [x] = internal_deco_time [x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
758 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
759 } |
167 | 760 } |
116 | 761 |
167 | 762 ////////////////////////////////////////////////////////////////////////////// |
116 | 763 // temp_tissue_safety // |
167 | 764 // |
116 | 765 // outsourced in v.102 |
167 | 766 // |
767 // Apply safety factors for brand ZH-L16 model. | |
768 // | |
769 static void temp_tissue_safety(void) | |
116 | 770 { |
197 | 771 assert( 0.0 < float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 ); |
772 assert( 1.0 <= float_saturation_multiplier && float_saturation_multiplier <= 2.0 ); | |
773 | |
167 | 774 if( char_I_deco_model == 0 ) |
116 | 775 { |
776 if (temp_tissue < 0.0) | |
126 | 777 temp_tissue *= float_desaturation_multiplier; |
116 | 778 else |
126 | 779 temp_tissue *= float_saturation_multiplier; |
116 | 780 } |
167 | 781 } |
116 | 782 |
167 | 783 ////////////////////////////////////////////////////////////////////////////// |
784 ////////////////////////////////////////////////////////////////////////////// | |
116 | 785 // ** THE JUMP-IN CODE ** |
786 // ** for the asm code ** | |
167 | 787 ////////////////////////////////////////////////////////////////////////////// |
788 ////////////////////////////////////////////////////////////////////////////// | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
789 |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
790 void fillDataStack(void) |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
791 { |
184 | 792 #ifndef CROSS_COMPILE |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
793 _asm |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
794 LFSR 1,C_STACK |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
795 MOVLW 0xCC |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
796 loop: MOVWF POSTINC1,0 |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
797 TSTFSZ FSR1L,0 |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
798 BRA loop |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
799 |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
800 LFSR 1,C_STACK |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
801 LFSR 2,C_STACK |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
802 _endasm |
184 | 803 #endif |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
804 } |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
805 |
167 | 806 ////////////////////////////////////////////////////////////////////////////// |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
807 // When calling C code from ASM context, the data stack pointer and |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
808 // frames should be reset. Bank3 is dedicated to the stack (see the |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
809 // .lkr script). |
184 | 810 #ifdef CROSS_COMPILE |
811 # define RESET_C_STACK | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
812 #else |
184 | 813 # ifdef __DEBUG |
814 # define RESET_C_STACK fillDataStack(); | |
815 # else | |
816 # define RESET_C_STACK \ | |
817 _asm \ | |
818 LFSR 1, C_STACK \ | |
819 LFSR 2, C_STACK \ | |
820 _endasm | |
821 # endif | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
822 #endif |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
823 |
167 | 824 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
825 // Called every 2 seconds during diving. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
826 // update tissues every time. |
184 | 827 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
828 // Every 6 seconds (or slower when TTS > 16): |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
829 // - update deco table (char_O_deco_time/depth) with new values. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
830 // - update ascent time, |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
831 // - set status to zero (so we can check there is new results). |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
832 // |
116 | 833 void deco_calc_hauptroutine(void) |
834 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
835 RESET_C_STACK |
116 | 836 calc_hauptroutine(); |
837 int_O_desaturation_time = 65535; | |
838 } | |
839 | |
167 | 840 ////////////////////////////////////////////////////////////////////////////// |
184 | 841 // Reset decompression model: |
842 // + Set all tissues to equilibrium with Air at ambient pressure. | |
843 // + Reset last stop to 0m | |
844 // + Reset all model output. | |
116 | 845 void deco_clear_tissue(void) |
846 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
847 RESET_C_STACK |
116 | 848 clear_tissue(); |
849 } | |
850 | |
167 | 851 ////////////////////////////////////////////////////////////////////////////// |
852 | |
116 | 853 void deco_calc_wo_deco_step_1_min(void) |
854 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
855 RESET_C_STACK |
116 | 856 calc_wo_deco_step_1_min(); |
857 deco_calc_desaturation_time(); | |
858 } | |
859 | |
167 | 860 ////////////////////////////////////////////////////////////////////////////// |
861 | |
116 | 862 void deco_debug(void) |
863 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
864 RESET_C_STACK |
116 | 865 } |
866 | |
167 | 867 ////////////////////////////////////////////////////////////////////////////// |
217 | 868 // Find deepest available gas. |
201 | 869 // |
217 | 870 // Input: deco_gas_change* |
212 | 871 // sim_gas_delay, sim_gas_last_used, sim_dive_mins. |
872 // | |
217 | 873 // Output: temp_depth_limit, sim_gas_delay, sim_gas_last_used IFF the is a switch. |
212 | 874 // |
217 | 875 static void deepest_gas_switch(void) |
201 | 876 { |
203 | 877 overlay unsigned char temp_gas_switch = 0; |
212 | 878 overlay unsigned char switch_deco = 0; |
201 | 879 |
880 if (char_I_const_ppO2 == 0) | |
881 { | |
882 // Keep selecting the best gas during the ascent simulation. | |
212 | 883 // Add a one meter margin in depth comparaison. |
884 if( deco_gas_change1 && ((temp_depth_limit-1) <= deco_gas_change1)) | |
201 | 885 { |
886 temp_gas_switch = 1; | |
887 switch_deco = deco_gas_change1; | |
217 | 888 } |
889 else if(deco_gas_change2 && ((temp_depth_limit-1) <= deco_gas_change2)) | |
201 | 890 { |
891 temp_gas_switch = 2; | |
892 switch_deco = deco_gas_change2; | |
217 | 893 } |
894 else if(deco_gas_change3 && ((temp_depth_limit-1) <= deco_gas_change3)) | |
201 | 895 { |
896 temp_gas_switch = 3; | |
897 switch_deco = deco_gas_change3; | |
898 } | |
217 | 899 else if(deco_gas_change4 && ((temp_depth_limit-1) <= deco_gas_change4)) |
201 | 900 { |
901 temp_gas_switch = 4; | |
902 switch_deco = deco_gas_change4; | |
903 } | |
217 | 904 else if(deco_gas_change5 && ((temp_depth_limit-1) <= deco_gas_change5)) |
201 | 905 { |
906 temp_gas_switch = 5; | |
907 switch_deco = deco_gas_change5; | |
908 } | |
909 } | |
910 | |
203 | 911 // If there is a better gas available |
912 if( temp_gas_switch ) | |
201 | 913 { |
212 | 914 // Should restart gas-switch delay only when gas do changes... |
203 | 915 // sim_gas_last_used: used to detect just once in each ascent simu. |
916 // N2_ratio : used to detect when already breathing that gas. | |
217 | 917 if( temp_depth_limit != switch_deco |
918 && sim_gas_last_used < temp_gas_switch | |
919 && sim_gas_delay <= sim_dive_mins ) | |
203 | 920 { |
921 sim_gas_last_used = temp_gas_switch; | |
922 sim_gas_delay = read_custom_function(55); | |
201 | 923 |
203 | 924 // Apply depth correction ONLY if CF#55 is not null: |
925 if( sim_gas_delay > 0 ) | |
926 { | |
927 sim_gas_delay += sim_dive_mins; | |
212 | 928 temp_depth_limit = switch_deco; |
203 | 929 } |
201 | 930 } |
931 } | |
203 | 932 else |
933 sim_gas_delay = 0; | |
217 | 934 } |
935 | |
936 ////////////////////////////////////////////////////////////////////////////// | |
937 // Find best (shallowest) available gas. | |
938 // | |
939 // Input: deco_gas_change* | |
940 // sim_gas_delay, sim_gas_last_used, sim_dive_mins. | |
941 // | |
942 // Output: temp_depth_limit, sim_gas_delay, sim_gas_last_used IFF the is a switch. | |
943 // | |
944 static void best_gas_switch(void) | |
945 { | |
946 overlay unsigned char temp_gas_switch = 0; | |
947 overlay unsigned char switch_deco = 0; | |
948 | |
949 if (char_I_const_ppO2 == 0) | |
950 { | |
951 // Keep selecting the best gas during the ascent simulation. | |
952 // Add a one meter margin in depth comparaison. | |
953 if( deco_gas_change5 && ((temp_depth_limit-1) <= deco_gas_change5)) | |
954 { | |
955 temp_gas_switch = 5; | |
956 switch_deco = deco_gas_change5; | |
957 } | |
958 else if(deco_gas_change4 && ((temp_depth_limit-1) <= deco_gas_change4)) | |
959 { | |
960 temp_gas_switch = 4; | |
961 switch_deco = deco_gas_change4; | |
962 } | |
963 else if(deco_gas_change3 && ((temp_depth_limit-1) <= deco_gas_change3)) | |
964 { | |
965 temp_gas_switch = 3; | |
966 switch_deco = deco_gas_change3; | |
967 } | |
968 else if(deco_gas_change2 && ((temp_depth_limit-1) <= deco_gas_change2)) | |
969 { | |
970 temp_gas_switch = 2; | |
971 switch_deco = deco_gas_change2; | |
972 } | |
973 else if(deco_gas_change1 && ((temp_depth_limit-1) <= deco_gas_change1)) | |
974 { | |
975 temp_gas_switch = 1; | |
976 switch_deco = deco_gas_change1; | |
977 } | |
978 } | |
979 | |
980 // If there is a better gas available | |
981 if( temp_gas_switch ) | |
982 { | |
983 // Should restart gas-switch delay only when gas do changes... | |
984 // sim_gas_last_used: used to detect just once in each ascent simu. | |
985 // N2_ratio : used to detect when already breathing that gas. | |
986 if( sim_gas_last_used < temp_gas_switch | |
987 && sim_gas_delay <= sim_dive_mins ) | |
988 { | |
989 sim_gas_last_used = temp_gas_switch; | |
990 sim_gas_delay = read_custom_function(55); | |
991 | |
992 // Apply depth correction ONLY if CF#55 is not null: | |
993 if( sim_gas_delay > 0 ) | |
994 { | |
995 sim_gas_delay += sim_dive_mins; | |
996 temp_depth_limit = switch_deco; | |
997 } | |
998 } | |
999 } | |
1000 else | |
1001 sim_gas_delay = 0; | |
1002 } | |
1003 | |
1004 ////////////////////////////////////////////////////////////////////////////// | |
1005 // Calculate gas switches | |
1006 // | |
1007 // | |
1008 // Input: N2_ratio, He_ratio. | |
1009 // sim_gas_last_used | |
1010 // | |
1011 // Output: calc_N2_ratio, calc_He_ratio | |
1012 // | |
1013 static void set_gas(void) | |
1014 { | |
1015 switch(sim_gas_last_used) | |
1016 { | |
1017 default: | |
1018 calc_N2_ratio = N2_ratio; | |
1019 calc_He_ratio = He_ratio; | |
1020 break; | |
1021 case 1: | |
1022 calc_N2_ratio = deco_N2_ratio1; | |
1023 calc_He_ratio = deco_He_ratio1; | |
1024 break; | |
1025 | |
1026 case 2: | |
1027 calc_N2_ratio = char_I_deco_N2_ratio2 * 0.01; | |
1028 calc_He_ratio = char_I_deco_He_ratio2 * 0.01; | |
1029 break; | |
1030 case 3: | |
1031 calc_N2_ratio = char_I_deco_N2_ratio3 * 0.01; | |
1032 calc_He_ratio = char_I_deco_He_ratio3 * 0.01; | |
1033 break; | |
1034 case 4: | |
1035 calc_N2_ratio = char_I_deco_N2_ratio4 * 0.01; | |
1036 calc_He_ratio = char_I_deco_He_ratio4 * 0.01; | |
1037 break; | |
1038 case 5: | |
1039 calc_N2_ratio = char_I_deco_N2_ratio5 * 0.01; | |
1040 calc_He_ratio = char_I_deco_He_ratio5 * 0.01; | |
1041 break; | |
1042 } | |
201 | 1043 |
1044 assert( 0.0 <= calc_N2_ratio && calc_N2_ratio <= 0.95 ); | |
1045 assert( 0.0 <= calc_He_ratio && calc_He_ratio <= 0.95 ); | |
1046 assert( (calc_N2_ratio + calc_He_ratio) <= 1.00 ); | |
1047 } | |
1048 | |
1049 ////////////////////////////////////////////////////////////////////////////// | |
1050 // | |
212 | 1051 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix. |
1052 // temp_deco : simulated respiration pressure + security offset (deco_distance) | |
1053 // Water-vapor pressure inside lumbs (ppWVapour). | |
1054 // | |
1055 // Output: ppO2, ppHe. | |
1056 // | |
1057 static void sim_alveolar_presures(void) | |
201 | 1058 { |
212 | 1059 overlay float deco_diluent = temp_deco; // new in v.101 |
1060 | |
1061 //---- CCR mode : deco gas switch ? -------------------------------------- | |
201 | 1062 if (char_I_const_ppO2 != 0) |
1063 { | |
212 | 1064 // In CCR mode, calc_XX_ratio == XX_ratio. |
1065 if( temp_deco > deco_ppO2_change ) | |
1066 deco_diluent = ((temp_deco - const_ppO2)/(calc_N2_ratio + calc_He_ratio)); | |
201 | 1067 else |
212 | 1068 deco_diluent = ((temp_deco - deco_ppO2)/(calc_N2_ratio + calc_He_ratio)); |
1069 | |
1070 if (deco_diluent > temp_deco) | |
1071 deco_diluent = temp_deco; | |
201 | 1072 } |
1073 | |
212 | 1074 // Take deco offset into account, but not at surface. |
1075 if( deco_diluent > pres_surface ) | |
1076 deco_diluent += float_deco_distance; | |
1077 | |
1078 if( deco_diluent > ppWVapour ) | |
201 | 1079 { |
1080 ppO2 = calc_N2_ratio * (deco_diluent - ppWVapour); | |
1081 ppHe = calc_He_ratio * (deco_diluent - ppWVapour); | |
1082 } | |
1083 else | |
1084 { | |
1085 ppO2 = 0.0; | |
1086 ppHe = 0.0; | |
1087 } | |
1088 assert( 0.0 <= ppO2 && ppO2 < 14.0 ); | |
1089 assert( 0.0 <= ppHe && ppHe < 14.0 ); | |
1090 } | |
1091 | |
1092 ////////////////////////////////////////////////////////////////////////////// | |
167 | 1093 // clear_tissue |
1094 // | |
165 | 1095 // optimized in v.101 (var_N2_a) |
167 | 1096 // |
1097 // preload tissues with standard pressure for the given ambient pressure. | |
1098 // Note: fixed N2_ratio for standard air. | |
201 | 1099 // |
167 | 1100 static void clear_tissue(void) |
116 | 1101 { |
1102 flag_in_divemode = 0; | |
1103 int_O_DBS_bitfield = 0; | |
1104 int_O_DBS2_bitfield = 0; | |
1105 int_O_DBG_pre_bitfield = 0; | |
1106 int_O_DBG_post_bitfield = 0; | |
1107 char_O_NDL_at_20mtr = 255; | |
1108 | |
167 | 1109 // Kludge: the 0.0002 of 0.7902 are missing with standard air. |
1110 N2_ratio = 0.7902; | |
212 | 1111 pres_respiration = int_I_pres_respiration * 0.001; |
164 | 1112 |
167 | 1113 for(ci=0; ci<16; ci++) |
126 | 1114 { |
197 | 1115 // cycle through the 16 Bühlmann tissues |
200 | 1116 overlay float p = N2_ratio * (pres_respiration - ppWVapour); |
164 | 1117 pres_tissue[ci] = p; |
197 | 1118 |
184 | 1119 read_buhlmann_coefficients(-1); |
165 | 1120 |
1121 p = (p - var_N2_a) * var_N2_b ; | |
164 | 1122 if( p < 0.0 ) |
1123 p = 0.0; | |
1124 pres_tissue_limit[ci] = p; | |
1125 | |
197 | 1126 // cycle through the 16 Bühlmann tissues for Helium |
167 | 1127 (pres_tissue+16)[ci] = 0.0; |
126 | 1128 } // for 0 to 16 |
116 | 1129 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1130 clear_deco_table(); |
126 | 1131 char_O_deco_status = 0; |
1132 char_O_nullzeit = 0; | |
168 | 1133 int_O_ascenttime = 0; |
126 | 1134 char_O_gradient_factor = 0; |
1135 char_O_relative_gradient_GF = 0; | |
197 | 1136 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco |
167 | 1137 } |
116 | 1138 |
167 | 1139 ////////////////////////////////////////////////////////////////////////////// |
1140 // calc_hauptroutine | |
1141 // | |
1142 // this is the major code in dive mode calculates: | |
116 | 1143 // the tissues, |
167 | 1144 // the bottom time, |
1145 // and simulates the ascend with all deco stops. | |
171 | 1146 // |
1147 // The deco_state sequence is : | |
1148 // 3 (at surface) | |
1149 // +---> 0 : calc nullzeit | |
1150 // | 2 : simulate ascent to first stop (at 10m/min, less that 16x 1min simu) | |
1151 // | +-> 1 : simulate up to 16min of stops. | |
1152 // | +------< not finished | |
1153 // +--------< finish | |
1154 // | |
167 | 1155 static void calc_hauptroutine(void) |
116 | 1156 { |
217 | 1157 static unsigned char backup_gas_used = 0; |
1158 static unsigned char backup_gas_delay = 0; | |
186 | 1159 |
116 | 1160 calc_hauptroutine_data_input(); |
1161 | |
1162 if(!flag_in_divemode) | |
1163 { | |
1164 flag_in_divemode = 1; | |
1165 create_dbs_set_dbg_and_ndl20mtr(); | |
1166 } | |
1167 else | |
1168 check_pre_dbg(); | |
1169 | |
1170 calc_hauptroutine_update_tissues(); | |
1171 calc_gradient_factor(); | |
1172 | |
167 | 1173 // toggle between calculation for nullzeit (bottom time), |
1174 // deco stops | |
1175 // and more deco stops (continue) | |
1176 switch( char_O_deco_status ) | |
116 | 1177 { |
186 | 1178 case 3: //---- At surface: start a new dive ------------------------------ |
1179 clear_deco_table(); | |
1180 copy_deco_table(); | |
200 | 1181 int_O_ascenttime = 0; // Reset DTR. |
1182 char_O_nullzeit = 0; // Reset bottom time. | |
1183 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration. | |
201 | 1184 |
217 | 1185 // Values that should be reset just once for the full real dive. |
1186 // This is used to record the lowest stop for the whole dive, | |
1187 // Including ACCROSS all simulated ascent. | |
1188 low_depth = 0; | |
1189 | |
1190 // Reset gas switch history. | |
1191 backup_gas_used = sim_gas_last_used = 0; | |
1192 backup_gas_delay = sim_gas_delay = 0; | |
203 | 1193 sim_dive_mins = 0; |
1194 break; | |
186 | 1195 |
167 | 1196 case 0: //---- bottom time ----------------------------------------------- |
1197 calc_nullzeit(); | |
1198 check_ndl(); | |
186 | 1199 char_O_deco_status = 2; // calc ascent next time. |
1200 break; | |
1201 | |
1202 case 2: //---- Simulate ascent to first stop ----------------------------- | |
203 | 1203 // Check proposed gas at begin of ascent simulation |
1204 sim_dive_mins = int_I_divemins; // and time. | |
212 | 1205 temp_depth_limit = (int)(0.95 + (pres_respiration - pres_surface) / 0.09985) ; // Starts from current real depth. |
217 | 1206 best_gas_switch(); |
1207 set_gas(); | |
203 | 1208 |
1209 backup_gas_used = sim_gas_last_used;// And save for later simu steps. | |
1210 backup_gas_delay = sim_gas_delay; | |
186 | 1211 |
1212 sim_ascent_to_first_stop(); | |
201 | 1213 |
1214 char_O_deco_status = 1; // Calc stops next time (deco or gas switch). | |
167 | 1215 break; |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1216 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1217 case 1: //---- Simulate stops -------------------------------------------- |
167 | 1218 calc_hauptroutine_calc_deco(); |
186 | 1219 |
1220 // If simulation is finished, restore the GF low reference, so that | |
1221 // next ascent simulation is done from the current depth: | |
217 | 1222 if( char_O_deco_status == 0 ) |
186 | 1223 { |
201 | 1224 sim_gas_last_used = backup_gas_used; |
203 | 1225 sim_gas_delay = backup_gas_delay; |
186 | 1226 } |
167 | 1227 break; |
116 | 1228 } |
167 | 1229 |
116 | 1230 check_post_dbg(); |
1231 } | |
1232 | |
167 | 1233 ////////////////////////////////////////////////////////////////////////////// |
1234 // calc_hauptroutine_data_input | |
1235 // | |
1236 // Reset all C-code dive parameters from their ASM-code values. | |
1237 // Detect gas change condition. | |
1238 // | |
116 | 1239 void calc_hauptroutine_data_input(void) |
1240 { | |
203 | 1241 overlay short int_temp; |
126 | 1242 |
197 | 1243 pres_respiration = int_I_pres_respiration * 0.001; |
1244 pres_surface = int_I_pres_surface * 0.001; | |
1245 N2_ratio = char_I_N2_ratio * 0.01; | |
1246 He_ratio = char_I_He_ratio * 0.01; | |
1247 deco_N2_ratio1 = char_I_deco_N2_ratio1 * 0.01; | |
1248 deco_He_ratio1 = char_I_deco_He_ratio1 * 0.01; | |
1249 float_deco_distance = char_I_deco_distance * 0.01; // Get offset is in mbar. | |
116 | 1250 |
126 | 1251 // ____________________________________________________ |
1252 // | |
1253 // _____________ G A S _ C H A N G E S ________________ | |
1254 // ____________________________________________________ | |
1255 | |
212 | 1256 // Keep a margin of 150mbar = 1.50m |
1257 int_temp = (int_I_pres_respiration - int_I_pres_surface) | |
1258 + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF; | |
126 | 1259 |
212 | 1260 deco_gas_change1 = 0; |
1261 deco_gas_change2 = 0; | |
1262 deco_gas_change3 = 0; | |
1263 deco_gas_change4 = 0; | |
1264 deco_gas_change5 = 0; | |
116 | 1265 |
203 | 1266 // Gas are selectable if we did not pass the change depth by more than 1.50m: |
167 | 1267 if(char_I_deco_gas_change1) |
126 | 1268 { |
203 | 1269 if( int_temp > 100 *(short)char_I_deco_gas_change1 ) |
212 | 1270 deco_gas_change1 = char_I_deco_gas_change1; |
126 | 1271 } |
1272 if(char_I_deco_gas_change2) | |
1273 { | |
203 | 1274 if( int_temp > 100 *(short)char_I_deco_gas_change2 ) |
212 | 1275 deco_gas_change2 = char_I_deco_gas_change2; |
126 | 1276 } |
1277 if(char_I_deco_gas_change3) | |
1278 { | |
203 | 1279 if( int_temp > 100 *(short)char_I_deco_gas_change3 ) |
212 | 1280 deco_gas_change3 = char_I_deco_gas_change3; |
126 | 1281 } |
1282 if(char_I_deco_gas_change4) | |
1283 { | |
203 | 1284 if( int_temp > 100 *(short)char_I_deco_gas_change4 ) |
212 | 1285 deco_gas_change4 = char_I_deco_gas_change4; |
126 | 1286 } |
1287 if(char_I_deco_gas_change5) | |
1288 { | |
203 | 1289 if( int_temp > 100 *(short)char_I_deco_gas_change5 ) |
212 | 1290 deco_gas_change5 = char_I_deco_gas_change5; |
126 | 1291 } |
116 | 1292 |
197 | 1293 const_ppO2 = char_I_const_ppO2 * 0.01; |
1294 deco_ppO2_change = char_I_deco_ppO2_change / 99.95 | |
1295 + pres_surface | |
1296 + float_deco_distance; | |
1297 deco_ppO2 = char_I_deco_ppO2 * 0.01; | |
1298 float_desaturation_multiplier = char_I_desaturation_multiplier * 0.01; | |
1299 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; | |
1300 GF_low = char_I_GF_Low_percentage * 0.01; | |
1301 GF_high = char_I_GF_High_percentage * 0.01; | |
126 | 1302 GF_delta = GF_high - GF_low; |
116 | 1303 } |
1304 | |
167 | 1305 ////////////////////////////////////////////////////////////////////////////// |
171 | 1306 // |
1307 // | |
116 | 1308 void calc_hauptroutine_update_tissues(void) |
1309 { | |
197 | 1310 assert( 0.00 <= N2_ratio && N2_ratio <= 1.00 ); |
1311 assert( 0.00 <= He_ratio && He_ratio <= 1.00 ); | |
1312 assert( (N2_ratio + He_ratio) <= 0.95 ); | |
1313 | |
1314 if (char_I_const_ppO2 == 0) // new in v.101 | |
167 | 1315 pres_diluent = pres_respiration; // new in v.101 |
186 | 1316 else |
1317 { | |
167 | 1318 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 |
186 | 1319 if (pres_diluent > pres_respiration) // new in v.101 |
1320 pres_diluent = pres_respiration; // new in v.101 | |
1321 } | |
200 | 1322 if (pres_diluent > ppWVapour) // new in v.101 |
116 | 1323 { |
200 | 1324 ppO2 = N2_ratio * (pres_diluent - ppWVapour); // changed in v.101 |
1325 ppHe = He_ratio * (pres_diluent - ppWVapour); // changed in v.101 | |
116 | 1326 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0); |
1327 } | |
167 | 1328 else // new in v.101 |
116 | 1329 { |
200 | 1330 ppO2 = 0.0; // new in v.101 |
1331 ppHe = 0.0; // new in v.101 | |
116 | 1332 char_O_diluent = 0; |
1333 } | |
1334 | |
1335 if(!char_I_step_is_1min) | |
192 | 1336 calc_tissue(0); |
116 | 1337 else |
192 | 1338 calc_tissue(1); |
186 | 1339 |
192 | 1340 // Calc limit for surface, ie. GF_high. |
1341 calc_limit(GF_high); | |
186 | 1342 |
203 | 1343 int_O_gtissue_limit = (short)(calc_lead_tissue_limit * 1000); |
1344 int_O_gtissue_press = (short)((pres_tissue[char_O_gtissue_no] + (pres_tissue+16)[char_O_gtissue_no]) * 1000); | |
192 | 1345 |
1346 // if guiding tissue can not be exposed to surface pressure immediately | |
1347 if( calc_lead_tissue_limit > pres_surface && char_O_deco_status == 0) | |
116 | 1348 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1349 char_O_nullzeit = 0; // deco necessary |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1350 char_O_deco_status = 2; // calculate ascent on next iteration. |
116 | 1351 } |
171 | 1352 } |
1353 | |
116 | 1354 |
167 | 1355 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1356 // Compute stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1357 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1358 // Note: because this can be very long, break on 16 iterations, and set state |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1359 // to 0 when finished, or to 1 when needing to continue. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1360 // |
116 | 1361 void calc_hauptroutine_calc_deco(void) |
1362 { | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1363 overlay unsigned char loop; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1364 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1365 for(loop = 0; loop < 16; ++loop) |
116 | 1366 { |
212 | 1367 overlay float new_presure; |
1368 overlay unsigned char backup_gas_last_used; | |
1369 | |
197 | 1370 // Do not ascent while doing a gas switch. |
203 | 1371 if( sim_gas_delay <= sim_dive_mins ) |
1372 { | |
212 | 1373 backup_gas_last_used = sim_gas_last_used; |
197 | 1374 calc_nextdecodepth(); |
116 | 1375 |
203 | 1376 //---- Finish computations once surface is reached --------------- |
1377 if( temp_depth_limit == 0 ) | |
1378 { | |
1379 copy_deco_table(); | |
1380 calc_ascenttime(); | |
1381 char_O_deco_status = 0; // calc nullzeit next time. | |
1382 return; | |
1383 } | |
212 | 1384 } |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1385 |
212 | 1386 //---- Can we ascent to that stop at once, or is it just ascenting ? |
1387 new_presure = temp_depth_limit * 0.09985 // Convert to relative bar, | |
1388 + pres_surface; // To absolute, | |
1389 | |
1390 if( (temp_deco - new_presure) > 1.0 ) // More than 10m/mn ? | |
1391 { | |
1392 temp_deco -= 1.0; // Just keep ascending. | |
1393 sim_gas_delay = 0; // Reset gas delay, | |
1394 sim_gas_last_used = backup_gas_last_used; // and usage history. | |
1395 } | |
1396 else | |
1397 { | |
1398 temp_deco = new_presure; | |
1399 update_deco_table(); // This is a one minute stops. | |
203 | 1400 } |
197 | 1401 |
203 | 1402 //---- Then update tissue and decoplan ------------------------------- |
1403 sim_dive_mins++; // Advance simulated time by 1 minute. | |
217 | 1404 set_gas(); // Apply any simulated gas change, once validated. |
212 | 1405 sim_alveolar_presures(); // Updates ppN2 and ppHe. |
192 | 1406 sim_tissue(1); // Simulate compartiments for 1 minute. |
116 | 1407 } |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1408 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1409 // Surface not reached, need more stops... |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1410 char_O_deco_status = 1; // calc more stops next time. |
116 | 1411 } |
1412 | |
167 | 1413 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1414 // Simulation ascention to first deco stop. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1415 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1416 // Note: because we ascent with a constant speed (10m/mn, ie. 1bar/mn), |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1417 // there is no need to break on more that 16 iterations |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1418 // (or we are already in deep shit). |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1419 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1420 void sim_ascent_to_first_stop(void) |
116 | 1421 { |
171 | 1422 update_startvalues(); |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1423 clear_deco_table(); |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1424 |
200 | 1425 temp_deco = pres_respiration; // Starts from current real depth. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1426 |
212 | 1427 // Do we have a gas switch going on ? |
1428 if( sim_gas_delay > sim_dive_mins ) | |
1429 return; | |
1430 | |
203 | 1431 // Loop until first stop, gas switch, or surface is reached. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1432 for(;;) |
116 | 1433 { |
203 | 1434 // No: try ascending 1 full minute. |
1435 temp_deco -= 1.0; // Ascent 1 min, at 10m/min. == 1bar/min. | |
1436 | |
212 | 1437 // Compute sim_lead_tissue_limit at GF_low (deepest stop). |
1438 sim_limit(GF_low); | |
1439 | |
1440 // Did we reach deepest remaining stop ? | |
1441 if( temp_deco <= sim_lead_tissue_limit ) | |
1442 { | |
1443 temp_deco += 1.0; // Restore last correct depth. | |
1444 break; // Return stop found ! | |
1445 } | |
1446 | |
203 | 1447 // Did we reach surface ? |
1448 if( temp_deco <= pres_surface ) | |
1449 { | |
1450 temp_deco = pres_surface; // Yes: finished ! | |
1451 break; | |
1452 } | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1453 |
212 | 1454 // Check gas change 5 meter below new depth. |
1455 temp_depth_limit = (temp_deco + 0.5 - pres_surface) / 0.09985; | |
217 | 1456 deepest_gas_switch(); |
212 | 1457 if( sim_gas_delay > sim_dive_mins ) |
1458 break; | |
171 | 1459 |
203 | 1460 sim_dive_mins++; // Advance simulated time by 1 minute. |
212 | 1461 sim_alveolar_presures(); // Still uses temp_deco. |
203 | 1462 sim_tissue(1); // and update tissues for 1 min. |
1463 } | |
167 | 1464 } |
116 | 1465 |
167 | 1466 ////////////////////////////////////////////////////////////////////////////// |
1467 // calc_tissue | |
1468 // | |
116 | 1469 // optimized in v.101 |
167 | 1470 // |
184 | 1471 static void calc_tissue(PARAMETER unsigned char period) |
116 | 1472 { |
126 | 1473 for (ci=0;ci<16;ci++) |
1474 { | |
184 | 1475 read_buhlmann_coefficients(period); // 2 sec or 1 min period. |
116 | 1476 |
126 | 1477 // N2 |
200 | 1478 temp_tissue = (ppO2 - pres_tissue[ci]) * var_N2_e; |
126 | 1479 temp_tissue_safety(); |
167 | 1480 pres_tissue[ci] += temp_tissue; |
165 | 1481 |
126 | 1482 // He |
200 | 1483 temp_tissue = (ppHe - (pres_tissue+16)[ci]) * var_He_e; |
126 | 1484 temp_tissue_safety(); |
167 | 1485 (pres_tissue+16)[ci] += temp_tissue; |
192 | 1486 } |
167 | 1487 } |
116 | 1488 |
167 | 1489 ////////////////////////////////////////////////////////////////////////////// |
192 | 1490 // calc_limit |
167 | 1491 // |
192 | 1492 // New in v.111 : separated from calc_tissue(), and depends on GF value. |
167 | 1493 // |
192 | 1494 static void calc_limit(PARAMETER float GF_current) |
167 | 1495 { |
192 | 1496 char_O_gtissue_no = 255; |
1497 calc_lead_tissue_limit = 0.0; | |
1498 | |
1499 for (ci=0;ci<16;ci++) | |
1500 { | |
1501 overlay float p = pres_tissue[ci] + (pres_tissue+16)[ci]; | |
1502 | |
1503 read_buhlmann_coefficients(-1); // 2 sec or 1 min period. | |
1504 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * (pres_tissue+16)[ci]) / p; | |
1505 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * (pres_tissue+16)[ci]) / p; | |
116 | 1506 |
192 | 1507 // Apply the Eric Baker's varying gradient factor correction. |
1508 // Note: the correction factor depends both on GF and b, | |
1509 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%), | |
1510 // so that can change who is the leading gas... | |
1511 // Note: Also depends of the GF. So the calcul is different for | |
1512 // GF_low, current GF, or GF_high... | |
1513 // *BUT* calc_tissue() is used to compute bottom time, | |
1514 // hence what would happend at surface, | |
1515 // hence at GF_high. | |
1516 if( char_I_deco_model == 1 ) | |
1517 p = ( p - var_N2_a * GF_current) * var_N2_b | |
1518 / (GF_current + var_N2_b * (1.0 - GF_current)); | |
1519 else | |
1520 p = (p - var_N2_a) * var_N2_b; | |
1521 if( p < 0 ) p = 0; | |
1522 | |
1523 pres_tissue_limit[ci] = p; | |
1524 if( p > calc_lead_tissue_limit ) | |
1525 { | |
1526 char_O_gtissue_no = ci; | |
1527 calc_lead_tissue_limit = p; | |
1528 } | |
1529 } | |
197 | 1530 |
1531 assert( char_O_gtissue_no < 16 ); | |
1532 assert( 0.0 <= calc_lead_tissue_limit && calc_lead_tissue_limit <= 14.0); | |
167 | 1533 } |
1534 | |
1535 ////////////////////////////////////////////////////////////////////////////// | |
1536 // calc_nullzeit | |
1537 // | |
1538 // calculates the remaining bottom time | |
1539 // | |
1540 // unchanged in v.101 | |
1541 // | |
1542 static void calc_nullzeit(void) | |
1543 { | |
203 | 1544 overlay unsigned char loop; |
200 | 1545 update_startvalues(); |
167 | 1546 |
116 | 1547 char_O_nullzeit = 0; |
167 | 1548 for(loop = 1; loop <= 17; loop++) |
116 | 1549 { |
1550 backup_sim_pres_tissue(); | |
197 | 1551 sim_tissue(2); // 10 min. |
192 | 1552 sim_limit(GF_high); |
167 | 1553 |
192 | 1554 if( sim_lead_tissue_limit > pres_surface ) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately |
185 | 1555 { |
1556 restore_sim_pres_tissue(); | |
1557 break; | |
1558 } | |
1559 // Validate once we know its good. | |
1560 char_O_nullzeit += 10; | |
167 | 1561 } |
1562 | |
116 | 1563 if (char_O_nullzeit < 60) |
1564 { | |
167 | 1565 for(loop=1; loop <= 10; loop++) |
116 | 1566 { |
197 | 1567 sim_tissue(1); // 1 min |
192 | 1568 sim_limit(GF_high); |
1569 | |
1570 if( sim_lead_tissue_limit > pres_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately | |
185 | 1571 break; |
1572 char_O_nullzeit++; | |
167 | 1573 } |
185 | 1574 } |
1575 } | |
116 | 1576 |
167 | 1577 ////////////////////////////////////////////////////////////////////////////// |
1578 // backup_sim_pres_tissue | |
1579 // | |
116 | 1580 void backup_sim_pres_tissue(void) |
1581 { | |
167 | 1582 overlay unsigned char x; |
1583 | |
1584 for(x = 0; x<32; x++) | |
126 | 1585 sim_pres_tissue_backup[x] = sim_pres_tissue[x]; |
167 | 1586 } |
116 | 1587 |
167 | 1588 ////////////////////////////////////////////////////////////////////////////// |
1589 // restore_sim_pres_tissue | |
1590 // | |
116 | 1591 void restore_sim_pres_tissue(void) |
1592 { | |
167 | 1593 overlay unsigned char x; |
1594 | |
1595 for(x = 0; x<32; x++) | |
126 | 1596 sim_pres_tissue[x] = sim_pres_tissue_backup[x]; |
167 | 1597 } |
116 | 1598 |
167 | 1599 ////////////////////////////////////////////////////////////////////////////// |
1600 // calc_ascenttime | |
1601 // | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1602 static void calc_ascenttime(void) |
116 | 1603 { |
126 | 1604 if (pres_respiration > pres_surface) |
1605 { | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1606 overlay unsigned char x; |
168 | 1607 |
192 | 1608 // + 0.7 to count 1 minute ascent time from 3 meter to surface |
1609 overlay float ascent = pres_respiration - pres_surface + 0.7; | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1610 if (ascent < 0.0) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1611 ascent = 0.0; |
203 | 1612 int_O_ascenttime = (unsigned short)(ascent + 0.99); |
168 | 1613 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1614 for(x=0; x<32 && internal_deco_depth[x]; x++) |
203 | 1615 int_O_ascenttime += (unsigned short)internal_deco_time[x]; |
126 | 1616 } |
1617 else | |
168 | 1618 int_O_ascenttime = 0; |
167 | 1619 } |
116 | 1620 |
167 | 1621 ////////////////////////////////////////////////////////////////////////////// |
1622 // update_startvalues | |
1623 // | |
116 | 1624 // updated in v.102 |
167 | 1625 // |
116 | 1626 void update_startvalues(void) |
1627 { | |
167 | 1628 overlay unsigned char x; |
116 | 1629 |
201 | 1630 // Start ascent simulation with current tissue partial pressures. |
116 | 1631 for (x = 0;x<16;x++) |
1632 { | |
1633 sim_pres_tissue[x] = pres_tissue[x]; | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1634 (sim_pres_tissue+16)[x] = (pres_tissue+16)[x]; |
116 | 1635 sim_pres_tissue_limit[x] = pres_tissue_limit[x]; |
1636 } | |
197 | 1637 |
201 | 1638 // No leading tissue (yet) for this ascent simulation. |
197 | 1639 sim_lead_tissue_limit = 0.0; |
1640 sim_lead_tissue_no = 255; | |
167 | 1641 } |
116 | 1642 |
167 | 1643 ////////////////////////////////////////////////////////////////////////////// |
192 | 1644 // sim_tissue |
167 | 1645 // |
116 | 1646 // optimized in v.101 |
167 | 1647 // |
1648 // Function very simular to calc_tissue, but: | |
1649 // + Use a 1min or 10min period. | |
1650 // + Do it on sim_pres_tissue, instead of pres_tissue. | |
184 | 1651 static void sim_tissue(PARAMETER unsigned char period) |
116 | 1652 { |
192 | 1653 for(ci=0; ci<16; ci++) |
126 | 1654 { |
184 | 1655 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval |
165 | 1656 |
126 | 1657 // N2 |
200 | 1658 temp_tissue = (ppO2 - sim_pres_tissue[ci]) * var_N2_e; |
126 | 1659 temp_tissue_safety(); |
167 | 1660 sim_pres_tissue[ci] += temp_tissue; |
126 | 1661 |
1662 // He | |
200 | 1663 temp_tissue = (ppHe - (sim_pres_tissue+16)[ci]) * var_He_e; |
126 | 1664 temp_tissue_safety(); |
167 | 1665 (sim_pres_tissue+16)[ci] += temp_tissue; |
192 | 1666 } |
167 | 1667 } |
116 | 1668 |
167 | 1669 ////////////////////////////////////////////////////////////////////////////// |
192 | 1670 // sim_limit() |
1671 // | |
1672 // New in v.111 | |
1673 // | |
1674 // Function separated from sim_tissue() to allow recomputing limit on | |
1675 // different depth, because it depends on current gradient factor. | |
167 | 1676 // |
192 | 1677 static void sim_limit(PARAMETER float GF_current) |
116 | 1678 { |
212 | 1679 assert( 0.0 < GF_current && GF_current <= 1.0f); |
1680 | |
192 | 1681 sim_lead_tissue_limit = 0.0; |
212 | 1682 sim_lead_tissue_no = 0; // If no one is critic, keep first tissue. |
192 | 1683 |
1684 for(ci=0; ci<16; ci++) | |
1685 { | |
1686 overlay float p = sim_pres_tissue[ci] + (sim_pres_tissue+16)[ci]; | |
1687 | |
1688 read_buhlmann_coefficients(-1); | |
1689 var_N2_a = (var_N2_a * sim_pres_tissue[ci] + var_He_a * (sim_pres_tissue+16)[ci]) / p; | |
1690 var_N2_b = (var_N2_b * sim_pres_tissue[ci] + var_He_b * (sim_pres_tissue+16)[ci]) / p; | |
1691 | |
1692 // Apply the Eric Baker's varying gradient factor correction. | |
1693 // Note: the correction factor depends both on GF and b, | |
1694 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%), | |
1695 // so that can change who is the leading gas... | |
1696 // Note: Also depends of the GF_current... | |
1697 // *BUT* calc_tissue() is used to compute bottom time, | |
1698 // hence what would happend at surface, | |
1699 // hence at GF_high. | |
1700 if( char_I_deco_model == 1 ) | |
1701 p = ( p - var_N2_a * GF_current) * var_N2_b | |
1702 / (GF_current + var_N2_b * (1.0 - GF_current)); | |
1703 else | |
1704 p = (p - var_N2_a) * var_N2_b; | |
1705 if( p < 0 ) p = 0; | |
1706 | |
1707 sim_pres_tissue_limit[ci] = p; | |
1708 if( p > sim_lead_tissue_limit ) | |
1709 { | |
1710 sim_lead_tissue_no = ci; | |
1711 sim_lead_tissue_limit = p; | |
1712 } | |
1713 } // for ci | |
197 | 1714 |
1715 assert( sim_lead_tissue_no < 16 ); | |
1716 assert( 0.0 <= sim_lead_tissue_limit && sim_lead_tissue_limit <= 14.0); | |
167 | 1717 } |
116 | 1718 |
167 | 1719 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1720 // clear_deco_table |
167 | 1721 // |
1722 // unchanged in v.101 | |
1723 // | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1724 static void clear_deco_table(void) |
116 | 1725 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1726 overlay unsigned char x; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1727 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1728 for(x=0; x<32; ++x) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1729 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1730 internal_deco_time [x] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1731 internal_deco_depth[x] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1732 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1733 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1734 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1735 ////////////////////////////////////////////////////////////////////////////// |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1736 // update_deco_table |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1737 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1738 // Add 1 min to current stop. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1739 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1740 // Inputs: |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1741 // temp_depth_limit = stop's depth, in meters. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1742 // In/Out: |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1743 // internal_deco_depth[] : depth (in meters) of each stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1744 // internal_deco_time [] : time (in minutes) of each stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1745 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1746 static void update_deco_table() |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1747 { |
192 | 1748 overlay unsigned char x; |
200 | 1749 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown). |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1750 |
192 | 1751 for(x=0; x<32; ++x) |
1752 { | |
212 | 1753 // Make sure deco-stops are recorded in order: |
1754 assert( !internal_deco_depth[x] || temp_depth_limit <= internal_deco_depth[x] ); | |
1755 | |
200 | 1756 if( internal_deco_depth[x] == temp_depth_limit ) |
192 | 1757 { |
1758 // Do not overflow (max 255') | |
1759 if( internal_deco_time[x] < 255 ) | |
1760 { | |
1761 internal_deco_time[x]++; | |
1762 return; | |
1763 } | |
1764 // But store extra in the next stop... | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1765 } |
192 | 1766 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1767 if( internal_deco_depth[x] == 0 ) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1768 { |
192 | 1769 internal_deco_depth[x] = temp_depth_limit; |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1770 internal_deco_time[x] = 1; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1771 return; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1772 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1773 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1774 |
192 | 1775 // Can't store stops at more than 96m. |
1776 // Or stops at less that 3m too. | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1777 // Just do nothing with that... |
167 | 1778 } |
116 | 1779 |
167 | 1780 ////////////////////////////////////////////////////////////////////////////// |
1781 // calc_gradient_factor | |
1782 // | |
165 | 1783 // optimized in v.101 (var_N2_a) |
116 | 1784 // new code in v.102 |
167 | 1785 // |
1786 static void calc_gradient_factor(void) | |
116 | 1787 { |
197 | 1788 overlay float gf; |
1789 assert( char_O_gtissue_no < 16 ); | |
1790 | |
116 | 1791 // tissue > respiration (entsaettigungsvorgang) |
1792 // gradient ist wieviel prozent an limit mit basis tissue | |
1793 // dh. 0% = respiration == tissue | |
1794 // dh. 100% = respiration == limit | |
197 | 1795 temp_tissue = pres_tissue[char_O_gtissue_no] + (pres_tissue+16)[char_O_gtissue_no]; |
1796 if( temp_tissue < pres_respiration ) | |
1797 gf = 0.0; | |
1798 else | |
1799 { | |
1800 gf = (temp_tissue - pres_respiration) | |
1801 / (temp_tissue - pres_tissue_limit[char_O_gtissue_no]) | |
1802 * 100.0; | |
1803 if( gf > 255.0 ) gf = 255.0; | |
1804 if( gf < 0.0 ) gf = 0.0; | |
1805 } | |
1806 char_O_gradient_factor = (unsigned char)gf; | |
116 | 1807 |
1808 if (char_I_deco_model == 1) // calculate relative gradient factor | |
1809 { | |
197 | 1810 overlay float rgf; |
1811 | |
1812 if( low_depth == 0 ) | |
1813 rgf = GF_high; | |
1814 else | |
1815 { | |
1816 overlay float temp1 = low_depth * 0.09995; | |
1817 overlay float temp2 = pres_respiration - pres_surface; | |
186 | 1818 |
197 | 1819 if (temp2 <= 0) |
1820 rgf = GF_high; | |
1821 else if (temp2 >= temp1) | |
1822 rgf = GF_low; | |
1823 else | |
1824 rgf = GF_low + (temp1 - temp2)/temp1*GF_delta; | |
1825 } | |
186 | 1826 |
197 | 1827 rgf = gf / rgf; // gf is already in percent |
1828 if( rgf < 0.0 ) rgf = 0.0; | |
1829 if( rgf > 255.0 ) rgf = 255.0; | |
1830 char_O_relative_gradient_GF = (unsigned char)rgf; | |
116 | 1831 } // calc relative gradient factor |
1832 else | |
1833 { | |
186 | 1834 char_O_relative_gradient_GF = char_O_gradient_factor; |
116 | 1835 } |
167 | 1836 } |
116 | 1837 |
167 | 1838 ////////////////////////////////////////////////////////////////////////////// |
1839 // deco_calc_desaturation_time | |
1840 // | |
116 | 1841 // FIXED N2_ratio |
1842 // unchanged in v.101 | |
167 | 1843 // |
116 | 1844 void deco_calc_desaturation_time(void) |
1845 { | |
203 | 1846 overlay unsigned short desat_time; // For a particular compartiment, in min. |
200 | 1847 overlay float temp1; |
197 | 1848 overlay float temp2; |
1849 overlay float temp3; | |
1850 overlay float temp4; | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
1851 RESET_C_STACK |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
1852 |
126 | 1853 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann |
1854 pres_surface = (float)int_I_pres_surface / 1000.0; | |
200 | 1855 ppO2 = N2_ratio * (pres_surface - ppWVapour); |
126 | 1856 int_O_desaturation_time = 0; |
1857 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) | |
1858 | |
1859 for (ci=0;ci<16;ci++) | |
1860 { | |
200 | 1861 overlay float var_N2_halftime = buhlmann_ht[ci]; |
1862 overlay float var_He_halftime = (buhlmann_ht+16)[ci]; | |
116 | 1863 |
126 | 1864 // saturation_time (for flight) and N2_saturation in multiples of halftime |
1865 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
1866 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
1867 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations | |
1868 // N2 | |
200 | 1869 temp1 = 1.05 * ppO2; |
126 | 1870 temp1 = temp1 - pres_tissue[ci]; |
200 | 1871 temp2 = ppO2 - pres_tissue[ci]; |
126 | 1872 if (temp2 >= 0.0) |
1873 { | |
1874 temp1 = 0; | |
1875 temp2 = 0; | |
1876 } | |
1877 else | |
1878 temp1 = temp1 / temp2; | |
1879 if (temp1 > 0.0) | |
1880 { | |
1881 temp1 = log(1.0 - temp1); | |
1882 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary. | |
1883 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
1884 // minus because log is negative | |
165 | 1885 temp2 = var_N2_halftime * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 10 percent) , new in v.101: float_desaturation_multiplier |
126 | 1886 } |
1887 else | |
1888 { | |
1889 temp1 = 0; | |
1890 temp2 = 0; | |
1891 } | |
116 | 1892 |
126 | 1893 // He |
167 | 1894 temp3 = 0.1 - (pres_tissue+16)[ci]; |
126 | 1895 if (temp3 >= 0.0) |
1896 { | |
1897 temp3 = 0; | |
1898 temp4 = 0; | |
1899 } | |
1900 else | |
167 | 1901 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci]; |
126 | 1902 if (temp3 > 0.0) |
1903 { | |
1904 temp3 = log(1.0 - temp3); | |
1905 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. | |
1906 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
1907 // minus because log is negative | |
165 | 1908 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier |
126 | 1909 } |
1910 else | |
1911 { | |
1912 temp3 = 0; | |
1913 temp4 = 0; | |
1914 } | |
116 | 1915 |
126 | 1916 // saturation_time (for flight) |
1917 if (temp4 > temp2) | |
203 | 1918 desat_time = (unsigned short)temp4; |
126 | 1919 else |
203 | 1920 desat_time = (unsigned short)temp2; |
167 | 1921 if(desat_time > int_O_desaturation_time) |
1922 int_O_desaturation_time = desat_time; | |
116 | 1923 |
126 | 1924 // N2 saturation in multiples of halftime for display purposes |
1925 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
1926 temp2 = temp2 + 80.0; // set center | |
1927 if (temp2 < 0.0) | |
1928 temp2 = 0.0; | |
1929 if (temp2 > 255.0) | |
1930 temp2 = 255.0; | |
1931 char_O_tissue_saturation[ci] = (char)temp2; | |
1932 // He saturation in multiples of halftime for display purposes | |
1933 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
1934 temp4 = temp4 + 80.0; // set center | |
1935 if (temp4 < 0.0) | |
1936 temp4 = 0.0; | |
1937 if (temp4 > 255.0) | |
1938 temp4 = 255.0; | |
167 | 1939 (char_O_tissue_saturation+16)[ci] = (char)temp4; |
126 | 1940 } // for |
167 | 1941 } |
116 | 1942 |
167 | 1943 ////////////////////////////////////////////////////////////////////////////// |
1944 // calc_wo_deco_step_1_min | |
1945 // | |
116 | 1946 // FIXED N2 Ratio |
1947 // optimized in v.101 (...saturation_multiplier) | |
1948 // desaturation slowed down to 70,42% | |
167 | 1949 // |
1950 static void calc_wo_deco_step_1_min(void) | |
116 | 1951 { |
1952 if(flag_in_divemode) | |
1953 { | |
1954 flag_in_divemode = 0; | |
1955 set_dbg_end_of_dive(); | |
1956 } | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
1957 |
126 | 1958 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann |
212 | 1959 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system |
1960 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio | |
200 | 1961 ppO2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body |
1962 ppHe = 0.0; | |
126 | 1963 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) |
197 | 1964 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; |
126 | 1965 |
192 | 1966 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure |
167 | 1967 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1968 clear_deco_table(); |
200 | 1969 char_O_deco_status = 3; // surface new in v.102 : stays in surface state. |
126 | 1970 char_O_nullzeit = 0; |
168 | 1971 int_O_ascenttime = 0; |
126 | 1972 calc_gradient_factor(); |
167 | 1973 } |
126 | 1974 |
167 | 1975 ////////////////////////////////////////////////////////////////////////////// |
1976 ////////////////////////////////////////////////////////////////////////////// | |
1977 ////////////////////////////////// deco_hash ///////////////////////////////// | |
1978 ////////////////////////////////////////////////////////////////////////////// | |
1979 ////////////////////////////////////////////////////////////////////////////// | |
126 | 1980 |
184 | 1981 #ifndef CROSS_COMPILE |
116 | 1982 void deco_hash(void) |
1983 { | |
167 | 1984 overlay unsigned char md_i, md_j; // Loop index. |
1985 overlay unsigned char md_t; | |
1986 overlay unsigned char md_buffer[16]; | |
1987 overlay unsigned char md_temp; | |
203 | 1988 overlay unsigned short md_pointer; |
167 | 1989 |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
1990 RESET_C_STACK |
126 | 1991 |
1992 // init | |
164 | 1993 for(md_i=0;md_i<16;md_i++) |
126 | 1994 { |
1995 md_state[md_i] = 0; | |
164 | 1996 char_O_hash[md_i] = 0; |
126 | 1997 } // for md_i 16 |
116 | 1998 |
126 | 1999 _asm |
167 | 2000 movlw 0x01 // md_pi address. |
2001 movwf TBLPTRU,0 | |
2002 movlw 0x7E | |
2003 movwf TBLPTRH,0 | |
2004 movlw 0x00 | |
2005 movwf TBLPTRL,0 | |
126 | 2006 _endasm; |
165 | 2007 md_i = 0; |
2008 do { | |
126 | 2009 _asm |
2010 TBLRDPOSTINC | |
2011 movff TABLAT,md_temp | |
2012 _endasm | |
165 | 2013 md_pi_subst[md_i++] = md_temp; |
2014 } while( md_i != 0 ); | |
2015 | |
126 | 2016 _asm |
167 | 2017 movlw 0x00 |
2018 movwf TBLPTRU,0 | |
2019 movlw 0x00 | |
2020 movwf TBLPTRH,0 | |
2021 movlw 0x00 | |
2022 movwf TBLPTRL,0 | |
126 | 2023 _endasm |
167 | 2024 |
126 | 2025 // cycle buffers |
2026 for (md_pointer=0x0000;md_pointer<0x17f3;md_pointer++) | |
2027 { | |
2028 md_t = 0; | |
2029 for (md_i=0;md_i<16;md_i++) | |
2030 { | |
2031 if(md_pointer == 9) | |
164 | 2032 md_temp = char_O_hash[md_i]; |
126 | 2033 else |
2034 { | |
2035 _asm | |
167 | 2036 TBLRDPOSTINC |
2037 movff TABLAT,md_temp | |
126 | 2038 _endasm |
2039 } // else | |
167 | 2040 |
2041 md_buffer[md_i] = md_temp; | |
186 | 2042 md_state[md_i+16] = md_temp; |
2043 md_state[md_i+32] = (unsigned char)(md_temp ^ md_state[md_i]); | |
126 | 2044 } // for md_i 16 |
2045 | |
2046 for (md_i=0;md_i<18;md_i++) | |
2047 { | |
2048 for (md_j=0;md_j<48;md_j++) | |
2049 { | |
167 | 2050 md_state[md_j] ^= md_pi_subst[md_t]; |
126 | 2051 md_t = md_state[md_j]; |
2052 } // for md_j 48 | |
2053 md_t = (unsigned char)(md_t+1); | |
2054 } // for md_i 18 | |
164 | 2055 md_t = char_O_hash[15]; |
126 | 2056 |
2057 for (md_i=0;md_i<16;md_i++) | |
2058 { | |
167 | 2059 char_O_hash[md_i] ^= md_pi_subst[(md_buffer[md_i] ^ md_t)]; |
164 | 2060 md_t = char_O_hash[md_i]; |
126 | 2061 } // for md_i 16 |
2062 } // for md_pointer | |
116 | 2063 } // void deco_hash(void) |
184 | 2064 #endif |
116 | 2065 |
167 | 2066 ////////////////////////////////////////////////////////////////////////////// |
2067 // deco_clear_CNS_fraction | |
2068 // | |
116 | 2069 // new in v.101 |
167 | 2070 // |
116 | 2071 void deco_clear_CNS_fraction(void) |
2072 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2073 RESET_C_STACK |
126 | 2074 CNS_fraction = 0.0; |
2075 char_O_CNS_fraction = 0; | |
167 | 2076 } |
116 | 2077 |
167 | 2078 ////////////////////////////////////////////////////////////////////////////// |
2079 // deco_calc_CNS_fraction | |
2080 // | |
116 | 2081 // new in v.101 |
2082 // optimized in v.102 : with new variables char_I_actual_ppO2 and actual_ppO2 | |
167 | 2083 // |
116 | 2084 // Input: char_I_actual_ppO2 |
2085 // Output: char_O_CNS_fraction | |
2086 // Uses and Updates: CNS_fraction | |
2087 // Uses: acutal_ppO2 | |
167 | 2088 // |
116 | 2089 void deco_calc_CNS_fraction(void) |
2090 { | |
167 | 2091 overlay float actual_ppO2; |
126 | 2092 RESET_C_STACK |
167 | 2093 |
126 | 2094 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; |
116 | 2095 |
126 | 2096 if (char_I_actual_ppO2 < 50) |
2097 CNS_fraction = CNS_fraction;// no changes | |
2098 else if (char_I_actual_ppO2 < 60) | |
2099 CNS_fraction = 1/(-54000.0 * actual_ppO2 + 54000.0) + CNS_fraction; | |
2100 else if (char_I_actual_ppO2 < 70) | |
2101 CNS_fraction = 1/(-45000.0 * actual_ppO2 + 48600.0) + CNS_fraction; | |
2102 else if (char_I_actual_ppO2 < 80) | |
2103 CNS_fraction = 1/(-36000.0 * actual_ppO2 + 42300.0) + CNS_fraction; | |
2104 else if (char_I_actual_ppO2 < 90) | |
2105 CNS_fraction = 1/(-27000.0 * actual_ppO2 + 35100.0) + CNS_fraction; | |
2106 else if (char_I_actual_ppO2 < 110) | |
2107 CNS_fraction = 1/(-18000.0 * actual_ppO2 + 27000.0) + CNS_fraction; | |
2108 else if (char_I_actual_ppO2 < 150) | |
2109 CNS_fraction = 1/(-9000.0 * actual_ppO2 + 17100.0) + CNS_fraction; | |
2110 else if (char_I_actual_ppO2 < 160) | |
2111 CNS_fraction = 1/(-22500.0 * actual_ppO2 + 37350.0) + CNS_fraction; | |
2112 else if (char_I_actual_ppO2 < 165) | |
2113 CNS_fraction = 0.000755 + CNS_fraction; // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity... Formula (A1) based on value for 1.55 and c=20 | |
2114 else if (char_I_actual_ppO2 < 170) | |
2115 CNS_fraction = 0.00102 + CNS_fraction; // example calculation: Sqrt((1.7/1.55)^20)*0.000404 | |
2116 else if (char_I_actual_ppO2 < 175) | |
2117 CNS_fraction = 0.00136 + CNS_fraction; | |
2118 else if (char_I_actual_ppO2 < 180) | |
2119 CNS_fraction = 0.00180 + CNS_fraction; | |
2120 else if (char_I_actual_ppO2 < 185) | |
2121 CNS_fraction = 0.00237 + CNS_fraction; | |
2122 else if (char_I_actual_ppO2 < 190) | |
2123 CNS_fraction = 0.00310 + CNS_fraction; | |
2124 else if (char_I_actual_ppO2 < 195) | |
2125 CNS_fraction = 0.00401 + CNS_fraction; | |
2126 else if (char_I_actual_ppO2 < 200) | |
2127 CNS_fraction = 0.00517 + CNS_fraction; | |
2128 else if (char_I_actual_ppO2 < 230) | |
2129 CNS_fraction = 0.0209 + CNS_fraction; | |
2130 else | |
2131 CNS_fraction = 0.0482 + CNS_fraction; // value for 2.5 | |
116 | 2132 |
126 | 2133 if (CNS_fraction > 2.5) |
2134 CNS_fraction = 2.5; | |
2135 if (CNS_fraction < 0.0) | |
2136 CNS_fraction = 0.0; | |
2137 | |
2138 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); | |
167 | 2139 } |
116 | 2140 |
167 | 2141 ////////////////////////////////////////////////////////////////////////////// |
2142 // deco_calc_CNS_decrease_15min | |
2143 // | |
116 | 2144 // new in v.101 |
167 | 2145 // |
116 | 2146 // calculates the half time of 90 minutes in 6 steps of 15 min |
200 | 2147 // (Used in sleepmode, for low battery mode). |
167 | 2148 // |
116 | 2149 // Output: char_O_CNS_fraction |
2150 // Uses and Updates: CNS_fraction | |
167 | 2151 // |
116 | 2152 void deco_calc_CNS_decrease_15min(void) |
2153 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2154 RESET_C_STACK |
126 | 2155 CNS_fraction = 0.890899 * CNS_fraction; |
167 | 2156 char_O_CNS_fraction = (char)(CNS_fraction * 100.0 + 0.5); |
2157 } | |
116 | 2158 |
167 | 2159 ////////////////////////////////////////////////////////////////////////////// |
2160 // deco_calc_percentage | |
2161 // | |
116 | 2162 // new in v.101 |
167 | 2163 // |
116 | 2164 // calculates int_I_temp * char_I_temp / 100 |
2165 // output is int_I_temp | |
200 | 2166 // |
2167 // Used to compute NoFly remaining time. | |
116 | 2168 |
2169 void deco_calc_percentage(void) | |
2170 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2171 RESET_C_STACK |
218 | 2172 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) / 100.0); |
116 | 2173 } |
2174 | |
167 | 2175 ////////////////////////////////////////////////////////////////////////////// |
2176 | |
116 | 2177 void deco_push_tissues_to_vault(void) |
2178 { | |
167 | 2179 overlay unsigned char x; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2180 RESET_C_STACK |
167 | 2181 |
116 | 2182 cns_vault = CNS_fraction; |
167 | 2183 for (x=0;x<32;x++) |
2184 pres_tissue_vault[x] = pres_tissue[x]; | |
116 | 2185 } |
167 | 2186 |
116 | 2187 void deco_pull_tissues_from_vault(void) |
2188 { | |
167 | 2189 overlay unsigned char x; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2190 RESET_C_STACK |
167 | 2191 |
116 | 2192 CNS_fraction = cns_vault; |
167 | 2193 for (x=0;x<32;x++) |
2194 pres_tissue[x] = pres_tissue_vault[x]; | |
116 | 2195 } |
2196 | |
167 | 2197 ////////////////////////////////////////////////////////////////////////////// |
2198 // | |
184 | 2199 #ifndef CROSS_COMPILE |
2200 void main() {} | |
2201 #endif |