Mercurial > public > mk2
comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 116:14a074e1a375
Split C code, and use direct linking.
| author | JeanDo |
|---|---|
| date | Sun, 26 Dec 2010 14:30:13 +0100 |
| parents | |
| children | 3003a8040b78 |
comparison
equal
deleted
inserted
replaced
| 115:50a06adabc67 | 116:14a074e1a375 |
|---|---|
| 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 | |
| 61 // 10/14/08 v104: integration of temp_depth_last_deco for Gradient Model | |
| 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) | |
| 66 // | |
| 67 // | |
| 68 // literature: | |
| 69 // B"uhlmann, Albert: Tauchmedizin; 4. Auflage; | |
| 70 // 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 | |
| 71 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html | |
| 72 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf | |
| 73 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops" | |
| 74 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf | |
| 75 | |
| 76 | |
| 77 // ********************* | |
| 78 // ** I N C L U D E S ** | |
| 79 // ********************* | |
| 80 #include <math.h> | |
| 81 | |
| 82 #include "p2_definitions.h" | |
| 83 | |
| 84 // *********************************************** | |
| 85 // ** V A R I A B L E S D E F I N I T I O N S ** | |
| 86 // *********************************************** | |
| 87 | |
| 88 | |
| 89 #pragma udata bank2a=0x200 | |
| 90 // output: | |
| 91 unsigned int int_O_tissue_for_debug[32]; | |
| 92 unsigned int int_O_GF_spare____; // 0x240 | |
| 93 unsigned int int_O_GF_step; // 0x242 | |
| 94 unsigned int int_O_gtissue_limit; // 0x244 | |
| 95 unsigned int int_O_gtissue_press; // 0x246 | |
| 96 unsigned int int_O_limit_GF_low; // 0x248 | |
| 97 unsigned int int_O_gtissue_press_at_GF_low; // 0x24A | |
| 98 unsigned char char_I_step_is_1min; // 0x24C | |
| 99 | |
| 100 // ... | |
| 101 #pragma udata bank2b=0x24E | |
| 102 unsigned char char_O_GF_low_pointer; // 0x24E | |
| 103 unsigned char char_O_actual_pointer; // 0x24F | |
| 104 | |
| 105 #pragma udata bank2c=0x250 | |
| 106 unsigned char char_O_deco_table[32]; // 0x250 | |
| 107 | |
| 108 #pragma udata bank2d=0x270 | |
| 109 unsigned char char_I_table_deco_done[32]; | |
| 110 | |
| 111 #pragma udata bank2e=0x290 | |
| 112 unsigned int int_O_calc_tissue_call_counter; // 0x290 | |
| 113 | |
| 114 // internal: | |
| 115 static unsigned char lock_GF_depth_list; | |
| 116 static float temp_limit; | |
| 117 static float GF_low; | |
| 118 static float GF_high; | |
| 119 static float GF_delta; | |
| 120 static float GF_temp; | |
| 121 static float GF_step; | |
| 122 static float GF_step2; | |
| 123 static float temp_pres_gtissue; | |
| 124 static float temp_pres_gtissue_diff; | |
| 125 static float temp_pres_gtissue_limit_GF_low; | |
| 126 static float temp_pres_gtissue_limit_GF_low_below_surface; | |
| 127 static unsigned int temp_depth_limit; | |
| 128 static unsigned char temp_decotime; | |
| 129 static unsigned char temp_gtissue_no; | |
| 130 static unsigned int temp_depth_last_deco; // new in v.101 | |
| 131 | |
| 132 static unsigned char temp_depth_GF_low_meter; | |
| 133 static unsigned char temp_depth_GF_low_number; | |
| 134 static unsigned char internal_deco_pointer; | |
| 135 | |
| 136 #pragma udata bank2f=0x2C8 | |
| 137 static unsigned char internal_deco_table[32]; // 0x2C8 | |
| 138 static float temp_pres_deco_GF_low; | |
| 139 | |
| 140 #pragma udata bank3a=0x300 | |
| 141 static char output[32]; // used by the math routines | |
| 142 | |
| 143 #pragma udata bank3b=0x37C | |
| 144 static float cns_vault; | |
| 145 | |
| 146 #pragma udata bank3c=0x380 | |
| 147 static float pres_tissue_vault[32]; | |
| 148 | |
| 149 #pragma udata bank4a=0x400 | |
| 150 // internal: | |
| 151 static unsigned char ci ; // don't move - used in _asm routines - if moved then modify movlb commands | |
| 152 static unsigned char x; | |
| 153 static unsigned int main_i_dummy; | |
| 154 static unsigned int int_temp; | |
| 155 static unsigned int int_temp2; | |
| 156 static unsigned int int_temp_decostatus; | |
| 157 static float pres_respiration; | |
| 158 static float pres_surface; | |
| 159 static float temp1; | |
| 160 static float temp2; | |
| 161 static float temp3; | |
| 162 static float temp4; | |
| 163 static float temp_deco; | |
| 164 static float temp_atem; | |
| 165 static float temp2_atem; | |
| 166 static float temp_tissue; | |
| 167 static float temp_surface; | |
| 168 static float N2_ratio; | |
| 169 static float He_ratio; | |
| 170 static float temp_ratio; | |
| 171 static float var_a; | |
| 172 static float var2_a; | |
| 173 static float var_b; | |
| 174 static float var2_b; | |
| 175 static float var_t05nc; | |
| 176 static float var2_t05nc; | |
| 177 static float var_e2secs; | |
| 178 static float var2_e2secs; | |
| 179 static float var_e1min; | |
| 180 static float var2_e1min; | |
| 181 static float var_halftimes; | |
| 182 static float var2_halftimes; | |
| 183 static float pres_gtissue_limit; | |
| 184 static float temp_pres_gtissue_limit; | |
| 185 static float actual_ppO2; // new in v.102 | |
| 186 | |
| 187 #pragma udata bank4b=0x480 | |
| 188 static float pres_tissue[32]; | |
| 189 | |
| 190 #pragma udata bank5=0x500 | |
| 191 // don't move positions in this bank, the registers are addressed directly from assembler code | |
| 192 // input: | |
| 193 unsigned int int_I_pres_respiration; // 0x500 | |
| 194 unsigned int int_I_pres_surface; // 0x502 | |
| 195 unsigned int int_I_temp; // 0x504 new in v101 | |
| 196 unsigned char char_I_temp; // 0x506 new in v101 | |
| 197 unsigned char char_I_actual_ppO2; // 0x507 | |
| 198 unsigned char char_I_deco_N2_ratio2; // 0x508 new in v.109 | |
| 199 unsigned char char_I_deco_He_ratio2; // 0x509 new in v.109 | |
| 200 unsigned char char_I_deco_N2_ratio3; // 0x50A new in v.109 | |
| 201 unsigned char char_I_deco_He_ratio3; // 0x50B new in v.109 | |
| 202 unsigned char char_I_deco_N2_ratio4; // 0x50C new in v.109 | |
| 203 unsigned char char_I_deco_He_ratio4; // 0x50D new in v.109 | |
| 204 unsigned char char_I_deco_N2_ratio5; // 0x50E new in v.109 | |
| 205 unsigned char char_I_deco_He_ratio5; // 0x50F new in v.109 | |
| 206 unsigned char char_I_N2_ratio; // 0x510 | |
| 207 unsigned char char_I_He_ratio; // 0x511 | |
| 208 unsigned char char_I_saturation_multiplier; // for conservatism/safety values 1.0 (no conservatism) to 1.5 (50% faster saturation | |
| 209 unsigned char char_I_desaturation_multiplier; // for conservatism/safety values 0.66 (50% slower desaturation) to 1.0 (no conservatism)// consveratism used in calc_tissue(), calc_tissue_step_1_min() and sim_tissue_1min() | |
| 210 unsigned char char_I_GF_High_percentage; // 0x514 new in v.102 | |
| 211 unsigned char char_I_GF_Low_percentage; // 0x515 new in v.102 | |
| 212 unsigned char char_I_spare; // 0x516 | |
| 213 unsigned char char_I_deco_distance; // 0x517 | |
| 214 unsigned char char_I_const_ppO2; // 0x518 new in v.101 | |
| 215 unsigned char char_I_deco_ppO2_change; // 0x519 new in v.101 | |
| 216 unsigned char char_I_deco_ppO2; // 0x51A new in v.101 | |
| 217 unsigned char char_I_deco_gas_change; // 0x51B new in v.101 | |
| 218 unsigned char char_I_deco_N2_ratio; // 0x51C new in v.101 | |
| 219 unsigned char char_I_deco_He_ratio; // 0x51D new in v.101 | |
| 220 unsigned char char_I_depth_last_deco; // 0x51E new in v.101 unit: [m] | |
| 221 unsigned char char_I_deco_model; // 0x51F new in v.102 ( 1 = MultiGraF, sonst Std. mit (de-)saturation_multiplier) | |
| 222 | |
| 223 // output: | |
| 224 unsigned int int_O_desaturation_time; // 0x520 | |
| 225 unsigned char char_O_nullzeit; // 0x522 | |
| 226 unsigned char char_O_deco_status; // 0x523 | |
| 227 unsigned char char_O_array_decotime[7]; // 0x524 | |
| 228 unsigned char char_O_array_decodepth[6]; // 0x52B | |
| 229 unsigned char char_O_ascenttime; // 0x531 | |
| 230 unsigned char char_O_gradient_factor; // 0x532 | |
| 231 unsigned char char_O_tissue_saturation[32]; // 0x533 | |
| 232 unsigned char char_O_array_gradient_weighted[16]; // 0x553 | |
| 233 unsigned char char_O_gtissue_no; // 0x563 | |
| 234 unsigned char char_O_diluent; // 0x564 new in v.101 | |
| 235 unsigned char char_O_CNS_fraction; // 0x565 new in v.101 | |
| 236 unsigned char char_O_relative_gradient_GF; // 0x566 new in v.102 | |
| 237 unsigned char char_I_deco_gas_change2; // 0x567 new in v.109 | |
| 238 unsigned char char_I_deco_gas_change3; // 0x568 new in v.109 | |
| 239 unsigned char char_I_deco_gas_change4; // 0x569 new in v.109 | |
| 240 unsigned char char_I_deco_gas_change5; // 0x56A new in v.109 | |
| 241 | |
| 242 // internal: | |
| 243 static float pres_tissue_limit[16]; | |
| 244 static float sim_pres_tissue_limit[16]; | |
| 245 static float pres_diluent; // new in v.101 | |
| 246 static float deco_diluent; // new in v.101 | |
| 247 static float const_ppO2; // new in v.101 | |
| 248 static float deco_ppO2_change; // new in v.101 | |
| 249 static float deco_ppO2; // new in v.101 | |
| 250 | |
| 251 #pragma udata bank6=0x600 | |
| 252 // internal: | |
| 253 static float sim_pres_tissue[32]; | |
| 254 static float sim_pres_tissue_backup[32]; | |
| 255 | |
| 256 #pragma udata bank8=0x800 | |
| 257 static char md_pi_subst[256]; | |
| 258 | |
| 259 #pragma udata bank9a=0x900 | |
| 260 // output: | |
| 261 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! | |
| 262 | |
| 263 #pragma udata bank9b=0x930 | |
| 264 // output: | |
| 265 unsigned int int_O_DBS_bitfield; // 0x930 new in v.108 | |
| 266 unsigned int int_O_DBS2_bitfield; // 0x932 new in v.108 | |
| 267 unsigned int int_O_DBG_pre_bitfield; // 0x934 new in v.108 | |
| 268 unsigned int int_O_DBG_post_bitfield; // 0x936 new in v.108 | |
| 269 unsigned char char_O_NDL_at_20mtr; // 0x938 new in v.108 // 0xFF == undefined, max. 254 | |
| 270 | |
| 271 // internal: | |
| 272 static char md_t; | |
| 273 static char md_buffer[16]; | |
| 274 static char md_cksum[16]; | |
| 275 static char md_i; | |
| 276 static char md_j; | |
| 277 static char md_temp; | |
| 278 static unsigned int md_pointer; | |
| 279 static float deco_N2_ratio; // new in v.101 | |
| 280 static float deco_He_ratio; // new in v.101 | |
| 281 static float calc_N2_ratio; // new in v.101 | |
| 282 static float calc_He_ratio; // new in v.101 | |
| 283 static float deco_gas_change; // new in v.101 | |
| 284 static float CNS_fraction; // new in v.101 | |
| 285 static float float_saturation_multiplier; // new in v.101 | |
| 286 static float float_desaturation_multiplier; // new in v.101 | |
| 287 static float float_deco_distance; // new in v.101 | |
| 288 // internal, dbg: | |
| 289 static unsigned char DBG_char_I_deco_model; // new in v.108 | |
| 290 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 | |
| 291 static float DBG_pres_surface; // new in v.108 | |
| 292 static float DBG_GF_low; // new in v.108 | |
| 293 static float DBG_GF_high; // new in v.108 | |
| 294 static float DBG_const_ppO2; // new in v.108 | |
| 295 static float DBG_deco_ppO2_change; // new in v.108 | |
| 296 static float DBG_deco_ppO2; // new in v.108 | |
| 297 static float DBG_deco_N2_ratio; // new in v.108 | |
| 298 static float DBG_deco_He_ratio; // new in v.108 | |
| 299 static float DBG_deco_gas_change; // new in v.108 | |
| 300 static float DBG_float_saturation_multiplier; // new in v.108 | |
| 301 static float DBG_float_desaturation_multiplier; // new in v.108 | |
| 302 static float DBG_float_deco_distance; // new in v.108 | |
| 303 static float DBG_deco_N2_ratio; // new in v.108 | |
| 304 static float DBG_deco_He_ratio; // new in v.108 | |
| 305 static float DBG_N2_ratio; // new in v.108 | |
| 306 static float DBG_He_ratio; // new in v.108 | |
| 307 static char flag_in_divemode; // new in v.108 | |
| 308 static int int_dbg_i; // new in v.108 | |
| 309 static unsigned int temp_DBS; | |
| 310 | |
| 311 static float deco_gas_change2; // new in v.109 | |
| 312 static float deco_gas_change3; // new in v.109 | |
| 313 static float deco_gas_change4; // new in v.109 | |
| 314 static float deco_gas_change5; // new in v.109 | |
| 315 | |
| 316 static float deco_N2_ratio2; // new in v.109 | |
| 317 static float deco_N2_ratio3; // new in v.109 | |
| 318 static float deco_N2_ratio4; // new in v.109 | |
| 319 static float deco_N2_ratio5; // new in v.109 | |
| 320 static float deco_He_ratio2; // new in v.109 | |
| 321 static float deco_He_ratio3; // new in v.109 | |
| 322 static float deco_He_ratio4; // new in v.109 | |
| 323 static float deco_He_ratio5; // new in v.109 | |
| 324 | |
| 325 // *********************** | |
| 326 // *********************** | |
| 327 // ** THE LOOKUP TABLES ** | |
| 328 // *********************** | |
| 329 // *********************** | |
| 330 | |
| 331 #pragma romdata tables = 0x10200 | |
| 332 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_a modified) | |
| 333 | |
| 334 #pragma romdata tables2 = 0x10600 | |
| 335 rom const rom unsigned int md_pi[] = | |
| 336 { | |
| 337 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613 | |
| 338 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA | |
| 339 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512 | |
| 340 , 0xBE4E, 0xC4D6, 0xDA9E, 0xDE49, 0xA0FB, 0xF58E, 0xBB2F, 0xEE7A | |
| 341 , 0xA968, 0x7991, 0x15B2, 0x073F, 0x94C2, 0x1089, 0x0B22, 0x5F21 | |
| 342 , 0x807F, 0x5D9A, 0x5A90, 0x3227, 0x353E, 0xCCE7, 0xBFF7, 0x9703 | |
| 343 , 0xFF19, 0x30B3, 0x48A5, 0xB5D1, 0xD75E, 0x922A, 0xAC56, 0xAAC6 | |
| 344 , 0x4FB8, 0x38D2, 0x96A4, 0x7DB6, 0x76FC, 0x6BE2, 0x9C74, 0x04F1 | |
| 345 , 0x459D, 0x7059, 0x6471, 0x8720, 0x865B, 0xCF65, 0xE62D, 0xA802 | |
| 346 , 0x1B60, 0x25AD, 0xAEB0, 0xB9F6, 0x1C46, 0x6169, 0x3440, 0x7E0F | |
| 347 , 0x5547, 0xA323, 0xDD51, 0xAF3A, 0xC35C, 0xF9CE, 0xBAC5, 0xEA26 | |
| 348 , 0x2C53, 0x0D6E, 0x8528, 0x8409, 0xD3DF, 0xCDF4, 0x4181, 0x4D52 | |
| 349 , 0x6ADC, 0x37C8, 0x6CC1, 0xABFA, 0x24E1, 0x7B08, 0x0CBD, 0xB14A | |
| 350 , 0x7888, 0x958B, 0xE363, 0xE86D, 0xE9CB, 0xD5FE, 0x3B00, 0x1D39 | |
| 351 , 0xF2EF, 0xB70E, 0x6658, 0xD0E4, 0xA677, 0x72F8, 0xEB75, 0x4B0A | |
| 352 , 0x3144, 0x50B4, 0x8FED, 0x1F1A, 0xDB99, 0x8D33, 0x9F11, 0x8314 | |
| 353 }; | |
| 354 | |
| 355 // ********************* | |
| 356 // ********************* | |
| 357 // ** THE SUBROUTINES ** | |
| 358 // ********************* | |
| 359 // ********************* | |
| 360 // all new in v.102 | |
| 361 // moved from 0x0D000 to 0x0C000 in v.108 | |
| 362 | |
| 363 #pragma code p2_deco = 0x0C000 | |
| 364 | |
| 365 // ------------------------------- | |
| 366 // DBS - debug on start of dive // | |
| 367 // ------------------------------- | |
| 368 void create_dbs_set_dbg_and_ndl20mtr(void) | |
| 369 { | |
| 370 int_O_DBS_bitfield = 0; | |
| 371 int_O_DBS2_bitfield = 0; | |
| 372 if(int_O_DBG_pre_bitfield & DBG_RUN) | |
| 373 int_O_DBG_pre_bitfield = DBG_RESTART; | |
| 374 else | |
| 375 int_O_DBG_pre_bitfield = DBG_RUN; | |
| 376 int_O_DBG_post_bitfield = 0; | |
| 377 char_O_NDL_at_20mtr = 255; | |
| 378 | |
| 379 DBG_N2_ratio = N2_ratio; | |
| 380 DBG_He_ratio = He_ratio; | |
| 381 DBG_char_I_deco_model = char_I_deco_model; | |
| 382 DBG_char_I_depth_last_deco = char_I_depth_last_deco; | |
| 383 DBG_pres_surface = pres_surface; | |
| 384 DBG_GF_low = GF_low; | |
| 385 DBG_GF_high = GF_high; | |
| 386 DBG_const_ppO2 = const_ppO2; | |
| 387 DBG_deco_ppO2_change = deco_ppO2_change; | |
| 388 DBG_deco_ppO2 = deco_ppO2; | |
| 389 DBG_deco_N2_ratio = deco_N2_ratio; | |
| 390 DBG_deco_He_ratio = deco_He_ratio; | |
| 391 DBG_deco_gas_change = deco_gas_change; | |
| 392 DBG_float_saturation_multiplier = float_saturation_multiplier; | |
| 393 DBG_float_desaturation_multiplier = float_desaturation_multiplier; | |
| 394 DBG_float_deco_distance = float_deco_distance; | |
| 395 | |
| 396 if(char_I_deco_model) | |
| 397 int_O_DBS_bitfield |= DBS_mode; | |
| 398 if(const_ppO2) | |
| 399 int_O_DBS_bitfield |= DBS_ppO2; | |
| 400 for(int_dbg_i = 16; int_dbg_i < 32; int_dbg_i++) | |
| 401 if(pres_tissue[int_dbg_i]) | |
| 402 int_O_DBS_bitfield |= DBS_HE_sat; | |
| 403 if(deco_ppO2_change) | |
| 404 int_O_DBS_bitfield |= DBS_ppO2chg; | |
| 405 if(float_saturation_multiplier < 0.99) | |
| 406 int_O_DBS_bitfield |= DBS_SAT2l; | |
| 407 if(float_saturation_multiplier > 1.3) | |
| 408 int_O_DBS_bitfield |= DBS_SAT2h; | |
| 409 if(GF_low < 0.19) | |
| 410 int_O_DBS_bitfield |= DBS_GFLOW2l; | |
| 411 if(GF_low > 1.01) | |
| 412 int_O_DBS_bitfield |= DBS_GFLOW2h; | |
| 413 if(GF_high < 0.6) | |
| 414 int_O_DBS_bitfield |= DBS_GFHGH2l; | |
| 415 if(GF_high > 1.01) | |
| 416 int_O_DBS_bitfield |= DBS_GFHGH2h; | |
| 417 if((N2_ratio + He_ratio) > 0.95) | |
| 418 int_O_DBS_bitfield |= DBS_GASO22l; | |
| 419 if((N2_ratio + He_ratio) < 0.05) | |
| 420 int_O_DBS_bitfield |= DBS_GASO22h; | |
| 421 if(float_deco_distance > 0.25) | |
| 422 int_O_DBS_bitfield |= DBS_DIST2h; | |
| 423 if(char_I_depth_last_deco > 8) | |
| 424 int_O_DBS_bitfield |= DBS_LAST2h; | |
| 425 if(DBG_deco_gas_change && ((deco_N2_ratio + deco_He_ratio) > 0.95)) | |
| 426 int_O_DBS_bitfield |= DBS_DECOO2l; | |
| 427 if(DBG_deco_gas_change && ((deco_N2_ratio + deco_He_ratio) < 0.05)) | |
| 428 int_O_DBS_bitfield |= DBS_DECOO2h; | |
| 429 if(pres_respiration > 3.0) | |
| 430 int_O_DBS2_bitfield |= DBS2_PRES2h; | |
| 431 if(pres_surface - pres_respiration > 0.2) | |
| 432 int_O_DBS2_bitfield |= DBS2_PRES2l; | |
| 433 if(pres_surface < 0.75) | |
| 434 int_O_DBS2_bitfield |= DBS2_SURF2l; | |
| 435 if(pres_surface > 1.11) | |
| 436 int_O_DBS2_bitfield |= DBS2_SURF2h; | |
| 437 if(float_desaturation_multiplier < 0.70) | |
| 438 int_O_DBS2_bitfield |= DBS2_DESAT2l; | |
| 439 if(float_desaturation_multiplier > 1.01) | |
| 440 int_O_DBS2_bitfield |= DBS2_DESAT2h; | |
| 441 if(GF_low > GF_high) | |
| 442 int_O_DBS2_bitfield |= DBS2_GFDneg; | |
| 443 } | |
| 444 | |
| 445 // ------------------------------- | |
| 446 // DBG - set DBG to end_of_dive // | |
| 447 // ------------------------------- | |
| 448 void set_dbg_end_of_dive(void) | |
| 449 { | |
| 450 int_O_DBG_pre_bitfield &= (~DBG_RUN); | |
| 451 int_O_DBG_post_bitfield &= (~DBG_RUN); | |
| 452 } | |
| 453 | |
| 454 // ------------------------------- | |
| 455 // DBG - NDL at first 20 m. hit // | |
| 456 // ------------------------------- | |
| 457 void check_ndl(void) | |
| 458 { | |
| 459 if((char_O_NDL_at_20mtr == -1) && (int_I_pres_respiration > 3000)) | |
| 460 { | |
| 461 char_O_NDL_at_20mtr = char_O_nullzeit; | |
| 462 if(char_O_NDL_at_20mtr == 255) | |
| 463 char_O_NDL_at_20mtr == 254; | |
| 464 } | |
| 465 } | |
| 466 | |
| 467 // ------------------------------- | |
| 468 // DBG - multi main during dive // | |
| 469 // ------------------------------- | |
| 470 void check_dbg(char is_post_check) | |
| 471 { | |
| 472 temp_DBS = 0; | |
| 473 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) | |
| 474 temp_DBS |= DBG_c_gas; | |
| 475 if(DBG_const_ppO2 != const_ppO2) | |
| 476 temp_DBS |= DBG_c_ppO2; | |
| 477 if((DBG_float_saturation_multiplier != float_saturation_multiplier) || (DBG_float_desaturation_multiplier != float_desaturation_multiplier)) | |
| 478 temp_DBS |= DBG_CdeSAT; | |
| 479 if(DBG_char_I_deco_model != char_I_deco_model) | |
| 480 temp_DBS |= DBG_C_MODE; | |
| 481 if(DBG_pres_surface != pres_surface) | |
| 482 temp_DBS |= DBG_C_SURF; | |
| 483 if((!DBS_HE_sat) && (!He_ratio)) | |
| 484 for(int_dbg_i = 16; int_dbg_i < 32; int_dbg_i++) | |
| 485 if(pres_tissue[int_dbg_i]) | |
| 486 temp_DBS |= DBG_HEwoHE; | |
| 487 if(DBG_deco_ppO2 != deco_ppO2) | |
| 488 temp_DBS |= DBG_C_DPPO2; | |
| 489 if((DBG_deco_gas_change != deco_gas_change) || (DBG_deco_N2_ratio != deco_N2_ratio) || (DBG_deco_He_ratio != deco_He_ratio)) | |
| 490 temp_DBS |= DBG_C_DGAS; | |
| 491 if(DBG_float_deco_distance != float_deco_distance) | |
| 492 temp_DBS |= DBG_C_DIST; | |
| 493 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco) | |
| 494 temp_DBS |= DBG_C_LAST; | |
| 495 if((DBG_GF_low != GF_low) || (DBG_GF_high != GF_high)) | |
| 496 temp_DBS |= DBG_C_GF; | |
| 497 if(pres_respiration > 13.0) | |
| 498 temp_DBS |= DBG_PHIGH; | |
| 499 if(pres_surface - pres_respiration > 0.2) | |
| 500 temp_DBS |= DBG_PLOW; | |
| 501 if(is_post_check) | |
| 502 int_O_DBG_post_bitfield |= temp_DBS; | |
| 503 else | |
| 504 int_O_DBG_pre_bitfield |= temp_DBS; | |
| 505 } | |
| 506 | |
| 507 // ------------------------------- | |
| 508 // DBG - prior to calc. of dive // | |
| 509 // ------------------------------- | |
| 510 void check_pre_dbg(void) | |
| 511 { | |
| 512 check_dbg(0); | |
| 513 } | |
| 514 | |
| 515 // ------------------------------- | |
| 516 // DBG - after decocalc of dive // | |
| 517 // ------------------------------- | |
| 518 void check_post_dbg(void) | |
| 519 { | |
| 520 check_dbg(1); | |
| 521 } | |
| 522 | |
| 523 // ------------------------- | |
| 524 // calc_next_decodepth_GF // | |
| 525 // ------------------------- | |
| 526 // new in v.102 | |
| 527 void calc_nextdecodepth_GF(void) | |
| 528 { | |
| 529 // INPUT, changing during dive: | |
| 530 // temp_pres_gtissue_limit_GF_low | |
| 531 // temp_pres_gtissue_limit_GF_low_below_surface | |
| 532 // temp_pres_gtissue | |
| 533 // temp_pres_gtissue_diff | |
| 534 // lock_GF_depth_list | |
| 535 | |
| 536 // INPUT, fixed during dive: | |
| 537 // pres_surface | |
| 538 // GF_delta | |
| 539 // GF_high | |
| 540 // GF_low | |
| 541 // temp_depth_last_deco | |
| 542 // float_deco_distance | |
| 543 | |
| 544 // OUTPUT | |
| 545 // GF_step | |
| 546 // temp_deco | |
| 547 // temp_depth_limt | |
| 548 // lock_GF_depth_list | |
| 549 | |
| 550 // USES | |
| 551 // temp1 | |
| 552 // temp2 | |
| 553 // int_temp | |
| 554 | |
| 555 char_I_table_deco_done[0] = 0; // safety if changed somewhere else. Needed for exit | |
| 556 if (char_I_deco_model == 1) | |
| 557 { | |
| 558 if (lock_GF_depth_list == 0) | |
| 559 { | |
| 560 temp2 = temp_pres_gtissue_limit_GF_low_below_surface / 0.29985; // = ... / 99.95 / 0.003; | |
| 561 int_temp = (int) (temp2 + 0.99); | |
| 562 if (int_temp > 31) | |
| 563 int_temp = 31; // deepest deco at 93 meter (31 deco stops) | |
| 564 if (int_temp < 0) | |
| 565 int_temp = 0; | |
| 566 temp_depth_GF_low_number = int_temp; | |
| 567 temp_depth_GF_low_meter = 3 * temp_depth_GF_low_number; | |
| 568 temp2 = (float)temp_depth_GF_low_meter * 0.09995; | |
| 569 temp_pres_deco_GF_low = temp2 + float_deco_distance + pres_surface; | |
| 570 if (temp_depth_GF_low_number == 0) | |
| 571 GF_step = 0; | |
| 572 else | |
| 573 GF_step = GF_delta / (float)temp_depth_GF_low_number; | |
| 574 if (GF_step < 0) | |
| 575 GF_step = 0; | |
| 576 if (GF_step > GF_delta) | |
| 577 GF_step = GF_delta; | |
| 578 int_O_GF_step = (int)(GF_step * 10000); | |
| 579 int_O_limit_GF_low = (int)(temp_pres_deco_GF_low * 1000); | |
| 580 int_O_gtissue_press_at_GF_low = (int)(temp_pres_gtissue * 1000); | |
| 581 char_O_GF_low_pointer = temp_depth_GF_low_number; | |
| 582 lock_GF_depth_list = 1; | |
| 583 internal_deco_pointer = 0; | |
| 584 } | |
| 585 if (internal_deco_pointer == 0) // new run | |
| 586 { | |
| 587 internal_deco_pointer = temp_depth_GF_low_number; | |
| 588 GF_temp = GF_high - ((float)internal_deco_pointer * GF_step); | |
| 589 int_temp = char_I_table_deco_done[internal_deco_pointer]; | |
| 590 output[8] = int_temp; | |
| 591 output[9] = 33; | |
| 592 } | |
| 593 else | |
| 594 { | |
| 595 int_temp = 1; | |
| 596 } | |
| 597 while (int_temp == 1) | |
| 598 { | |
| 599 int_temp = internal_deco_pointer - 1; | |
| 600 if (int_temp == 1) // new in v104 | |
| 601 { | |
| 602 temp2 = (float)(temp_depth_last_deco * int_temp) * 0.09995; | |
| 603 GF_step2 = GF_step/3.0 * ((float)(6 - temp_depth_last_deco)); | |
| 604 } | |
| 605 else | |
| 606 if (int_temp == 0) | |
| 607 { | |
| 608 temp2 = 0.0; | |
| 609 GF_step2 = GF_high - GF_temp; | |
| 610 } | |
| 611 else | |
| 612 { | |
| 613 temp2 = (float)(3 *int_temp) * 0.09995; | |
| 614 GF_step2 = GF_step; | |
| 615 } | |
| 616 temp2 = temp2 + pres_surface; // next deco stop to be tested | |
| 617 temp1 = ((GF_temp + GF_step2)* temp_pres_gtissue_diff) + temp_pres_gtissue; // upper limit (lowest pressure allowed) // changes GF_step2 in v104 | |
| 618 if (temp1 > temp2) // check if ascent to next deco stop is ok | |
| 619 { | |
| 620 int_temp = 0; // no | |
| 621 } | |
| 622 else | |
| 623 { | |
| 624 internal_deco_pointer = int_temp; | |
| 625 GF_temp = GF_temp + GF_step2; // changed in v104 | |
| 626 int_temp = char_I_table_deco_done[internal_deco_pointer]; // yes and check for ascent to even next stop if deco_done is set | |
| 627 } | |
| 628 } // while | |
| 629 if (internal_deco_pointer > 0) | |
| 630 { | |
| 631 temp2 = (float)(0.29985 * internal_deco_pointer); | |
| 632 temp_deco = temp2 + float_deco_distance + pres_surface; | |
| 633 if (internal_deco_pointer == 1) // new in v104 | |
| 634 temp_depth_limit = temp_depth_last_deco; | |
| 635 else | |
| 636 temp_depth_limit = 3 * internal_deco_pointer; | |
| 637 if (output[9] == 33) | |
| 638 { | |
| 639 output[9] = internal_deco_pointer; | |
| 640 output[10] = char_I_table_deco_done[internal_deco_pointer]; | |
| 641 output[12] = output[12] + 1; | |
| 642 if (output[12] == 100) | |
| 643 output[12] = 0; | |
| 644 } | |
| 645 } | |
| 646 else // if (char_I_deco_model == 1) | |
| 647 { | |
| 648 temp_deco = pres_surface; | |
| 649 temp_depth_limit = 0; | |
| 650 } | |
| 651 } | |
| 652 else | |
| 653 { | |
| 654 // calc_nextdecodepth - original | |
| 655 // optimized in v.101 | |
| 656 // depth_last_deco included in v.101 | |
| 657 | |
| 658 temp1 = temp_pres_gtissue_limit - pres_surface; | |
| 659 if (temp1 >= 0) | |
| 660 { | |
| 661 temp1 = temp1 / 0.29985; // = temp1 / 99.95 / 0.003; | |
| 662 temp_depth_limit = (int) (temp1 + 0.99); | |
| 663 temp_depth_limit = 3 * temp_depth_limit; // depth for deco [m] | |
| 664 if (temp_depth_limit == 0) | |
| 665 temp_deco = pres_surface; | |
| 666 else | |
| 667 { | |
| 668 if (temp_depth_limit < temp_depth_last_deco) | |
| 669 temp_depth_limit = temp_depth_last_deco; | |
| 670 temp1 = (float)temp_depth_limit * 0.09995; | |
| 671 temp_deco = temp1 + float_deco_distance + pres_surface; // depth for deco [bar] | |
| 672 } // if (temp_depth_limit == 0) | |
| 673 } // if (temp1 >= 0) | |
| 674 else | |
| 675 { | |
| 676 temp_deco = pres_surface; | |
| 677 temp_depth_limit = 0; | |
| 678 } // if (temp1 >= 0) | |
| 679 } // calc_nextdecodepth original | |
| 680 } // calc_nextdecodepth_GF | |
| 681 | |
| 682 | |
| 683 // --------------------- | |
| 684 // copy_deco_table_GF // | |
| 685 // --------------------- | |
| 686 // new in v.102 | |
| 687 void copy_deco_table_GF(void) | |
| 688 { | |
| 689 if (char_I_deco_model == 1) | |
| 690 { | |
| 691 int_temp = 32; | |
| 692 for (ci=0;ci<int_temp;ci++) | |
| 693 char_O_deco_table[ci] = internal_deco_table[ci]; | |
| 694 } | |
| 695 } // copy_deco_table_GF | |
| 696 | |
| 697 | |
| 698 // ------------------------------ | |
| 699 // clear_internal_deco_table_GF// | |
| 700 // ------------------------------ | |
| 701 // new in v.102 | |
| 702 void clear_internal_deco_table_GF(void) | |
| 703 { | |
| 704 if (char_I_deco_model == 1) | |
| 705 { | |
| 706 for (ci=0;ci<32;ci++) // cycle through the 16 b"uhlmann tissues for Helium | |
| 707 { | |
| 708 internal_deco_table[ci] = 0; | |
| 709 } | |
| 710 } | |
| 711 } // clear_internal_deco_table_GF | |
| 712 | |
| 713 | |
| 714 // -------------------------------- | |
| 715 // update_internal_deco_table_GF // | |
| 716 // -------------------------------- | |
| 717 // new in v.102 | |
| 718 void update_internal_deco_table_GF(void) | |
| 719 { | |
| 720 if ((char_I_deco_model == 1) && (internal_deco_table[internal_deco_pointer] < 255)) | |
| 721 internal_deco_table[internal_deco_pointer] = internal_deco_table[internal_deco_pointer] + 1; | |
| 722 } // update_internal_deco_table_GF | |
| 723 | |
| 724 | |
| 725 // --------------------- | |
| 726 // temp_tissue_safety // | |
| 727 // --------------------- | |
| 728 // outsourced in v.102 | |
| 729 void temp_tissue_safety(void) | |
| 730 { | |
| 731 if (char_I_deco_model == 1) | |
| 732 { | |
| 733 } | |
| 734 else | |
| 735 { | |
| 736 if (temp_tissue < 0.0) | |
| 737 temp_tissue = temp_tissue * float_desaturation_multiplier; | |
| 738 else | |
| 739 temp_tissue = temp_tissue * float_saturation_multiplier; | |
| 740 } | |
| 741 } // temp_tissue_safety | |
| 742 | |
| 743 // ********************** | |
| 744 // ********************** | |
| 745 // ** THE JUMP-IN CODE ** | |
| 746 // ** for the asm code ** | |
| 747 // ********************** | |
| 748 // ********************** | |
| 749 void deco_calc_hauptroutine(void) | |
| 750 { | |
| 751 calc_hauptroutine(); | |
| 752 int_O_desaturation_time = 65535; | |
| 753 } | |
| 754 | |
| 755 void deco_calc_without_deco(void) | |
| 756 { | |
| 757 calc_without_deco(); | |
| 758 deco_calc_desaturation_time(); | |
| 759 } | |
| 760 | |
| 761 void deco_clear_tissue(void) | |
| 762 { | |
| 763 clear_tissue(); | |
| 764 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco | |
| 765 } | |
| 766 | |
| 767 void deco_calc_wo_deco_step_1_min(void) | |
| 768 { | |
| 769 calc_wo_deco_step_1_min(); | |
| 770 char_O_deco_status = 3; // surface new in v.102 overwrites value of calc_wo_deco_step_1_min | |
| 771 deco_calc_desaturation_time(); | |
| 772 } | |
| 773 | |
| 774 void deco_debug(void) | |
| 775 { | |
| 776 //debug(); | |
| 777 } | |
| 778 | |
| 779 // --------------- | |
| 780 // CLEAR tissue // | |
| 781 // --------------- | |
| 782 // optimized in v.101 (var_a) | |
| 783 | |
| 784 #pragma code p2_deco_suite = 0x10700 | |
| 785 | |
| 786 void clear_tissue(void) // preload tissues with standard pressure for the given ambient pressure | |
| 787 { | |
| 788 | |
| 789 flag_in_divemode = 0; | |
| 790 int_O_DBS_bitfield = 0; | |
| 791 int_O_DBS2_bitfield = 0; | |
| 792 int_O_DBG_pre_bitfield = 0; | |
| 793 int_O_DBG_post_bitfield = 0; | |
| 794 char_O_NDL_at_20mtr = 255; | |
| 795 | |
| 796 _asm | |
| 797 lfsr 1, 0x300 // C math routines shall use this variable bank | |
| 798 movlw 0x01 | |
| 799 movwf TBLPTRU,0 | |
| 800 _endasm | |
| 801 | |
| 802 // N2_ratio = (float)char_I_N2_ratio; // the 0.0002 of 0.7902 are missing with standard air | |
| 803 N2_ratio = 0.7902; // N2_ratio / 100.0; | |
| 804 pres_respiration = (float)int_I_pres_respiration / 1000.0; | |
| 805 for (ci=0;ci<16;ci++) // cycle through the 16 b"uhlmann tissues | |
| 806 { | |
| 807 pres_tissue[ci] = N2_ratio * (pres_respiration - 0.0627) ; | |
| 808 _asm | |
| 809 movlw 0x02 | |
| 810 movwf TBLPTRH,0 | |
| 811 movlb 4 // fuer ci | |
| 812 movf ci,0,1 | |
| 813 addwf ci,0,1 | |
| 814 addwf ci,0,1 | |
| 815 addwf ci,0,1 | |
| 816 addlw 0x80 | |
| 817 movwf TBLPTRL,0 | |
| 818 TBLRDPOSTINC | |
| 819 movff TABLAT,var_a+1 | |
| 820 TBLRDPOSTINC | |
| 821 movff TABLAT,var_a | |
| 822 TBLRDPOSTINC | |
| 823 movff TABLAT,var_a+3 | |
| 824 TBLRD | |
| 825 movff TABLAT,var_a+2 | |
| 826 addlw 0x80 | |
| 827 movwf TBLPTRL,0 | |
| 828 incf TBLPTRH,1,0 | |
| 829 TBLRDPOSTINC | |
| 830 movff TABLAT,var_b+1 | |
| 831 TBLRDPOSTINC | |
| 832 movff TABLAT,var_b | |
| 833 TBLRDPOSTINC | |
| 834 movff TABLAT,var_b+3 | |
| 835 TBLRD | |
| 836 movff TABLAT,var_b+2 | |
| 837 _endasm | |
| 838 | |
| 839 pres_tissue_limit[ci] = (pres_tissue[ci] - var_a) * var_b ; | |
| 840 // now update the guiding tissue | |
| 841 if (pres_tissue_limit[ci] < 0) | |
| 842 pres_tissue_limit[ci] = 0; | |
| 843 } // for 0 to 16 | |
| 844 | |
| 845 for (ci=16;ci<32;ci++) // cycle through the 16 b"uhlmann tissues for Helium | |
| 846 { | |
| 847 pres_tissue[ci] = 0.0; | |
| 848 } // for | |
| 849 | |
| 850 clear_decoarray(); | |
| 851 char_O_deco_status = 0; | |
| 852 char_O_nullzeit = 0; | |
| 853 char_O_ascenttime = 0; | |
| 854 char_O_gradient_factor = 0; | |
| 855 char_O_relative_gradient_GF = 0; | |
| 856 } // clear_tissue(void) | |
| 857 | |
| 858 | |
| 859 // -------------------- | |
| 860 // calc_without_deco // | |
| 861 // fixed N2_ratio ! // | |
| 862 // -------------------- | |
| 863 // optimized in v.101 (float_..saturation_multiplier) | |
| 864 | |
| 865 void calc_without_deco(void) | |
| 866 { | |
| 867 _asm | |
| 868 lfsr 1, 0x300 | |
| 869 _endasm | |
| 870 N2_ratio = 0.7902; // FIXED RATIO !! sum as stated in b"uhlmann | |
| 871 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | |
| 872 pres_surface = (float)int_I_pres_surface / 1000.0; | |
| 873 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body | |
| 874 temp2_atem = 0.0; | |
| 875 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does apply to the pressure without any inert ratio | |
| 876 float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0; | |
| 877 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; | |
| 878 | |
| 879 calc_tissue(); // update the pressure in the 16 tissues in accordance with the new ambient pressure | |
| 880 | |
| 881 clear_decoarray(); | |
| 882 char_O_deco_status = 0; | |
| 883 char_O_nullzeit = 0; | |
| 884 char_O_ascenttime = 0; | |
| 885 calc_gradient_factor(); | |
| 886 | |
| 887 } // calc_without_deco | |
| 888 | |
| 889 | |
| 890 // -------------------- | |
| 891 // calc_hauptroutine // | |
| 892 // -------------------- | |
| 893 // this is the major code in dive mode | |
| 894 // calculates: | |
| 895 // the tissues, | |
| 896 // the bottom time | |
| 897 // and simulates the ascend with all deco stops | |
| 898 | |
| 899 void calc_hauptroutine(void) | |
| 900 { | |
| 901 calc_hauptroutine_data_input(); | |
| 902 | |
| 903 if(!flag_in_divemode) | |
| 904 { | |
| 905 flag_in_divemode = 1; | |
| 906 create_dbs_set_dbg_and_ndl20mtr(); | |
| 907 } | |
| 908 else | |
| 909 check_pre_dbg(); | |
| 910 | |
| 911 calc_hauptroutine_update_tissues(); | |
| 912 calc_gradient_factor(); | |
| 913 | |
| 914 | |
| 915 switch (char_O_deco_status) // toggle between calculation for nullzeit (bottom time), deco stops and more deco stops (continue) | |
| 916 { | |
| 917 case 0: | |
| 918 update_startvalues(); | |
| 919 calc_nullzeit(); | |
| 920 check_ndl(); | |
| 921 char_O_deco_status = 255; // calc deco next time | |
| 922 break; | |
| 923 case 1: | |
| 924 if (char_O_deco_status == 3) | |
| 925 break; | |
| 926 char_O_deco_status = 0; | |
| 927 // char_O_lock_depth_list = 255; | |
| 928 calc_hauptroutine_calc_deco(); | |
| 929 // build_debug_output(); | |
| 930 break; | |
| 931 case 3: // new dive | |
| 932 clear_decoarray(); | |
| 933 clear_internal_deco_table_GF(); | |
| 934 copy_deco_table_GF(); | |
| 935 internal_deco_pointer = 0; | |
| 936 lock_GF_depth_list = 0; | |
| 937 update_startvalues(); | |
| 938 calc_nextdecodepth_GF(); | |
| 939 char_O_deco_status = 0; | |
| 940 break; | |
| 941 default: | |
| 942 update_startvalues(); | |
| 943 clear_decoarray(); | |
| 944 clear_internal_deco_table_GF(); | |
| 945 output[6] = 1; | |
| 946 calc_hauptroutine_calc_ascend_to_deco(); | |
| 947 if (char_O_deco_status > 15) // can't go up to first deco, too deep to calculate in the given time slot | |
| 948 { | |
| 949 char_O_deco_status = 2; | |
| 950 // char_O_lock_depth_list = 255; | |
| 951 } | |
| 952 else | |
| 953 { | |
| 954 // char_O_lock_depth_list = lock_GF_depth_list; | |
| 955 calc_hauptroutine_calc_deco(); | |
| 956 } | |
| 957 // build_debug_output(); | |
| 958 break; | |
| 959 } | |
| 960 calc_ascenttime(); | |
| 961 check_post_dbg(); | |
| 962 } | |
| 963 | |
| 964 void calc_hauptroutine_data_input(void) | |
| 965 { | |
| 966 pres_respiration = (float)int_I_pres_respiration / 1000.0; | |
| 967 pres_surface = (float)int_I_pres_surface / 1000.0; | |
| 968 | |
| 969 N2_ratio = (float)char_I_N2_ratio / 100.0;; // the 0.0002 of 0.7902 are missing with standard air | |
| 970 He_ratio = (float)char_I_He_ratio / 100.0;; | |
| 971 deco_N2_ratio = (float)char_I_deco_N2_ratio / 100.0; | |
| 972 deco_He_ratio = (float)char_I_deco_He_ratio / 100.0; | |
| 973 deco_N2_ratio2 = (float)char_I_deco_N2_ratio2 / 100.0; | |
| 974 deco_He_ratio2 = (float)char_I_deco_He_ratio2 / 100.0; | |
| 975 deco_N2_ratio3 = (float)char_I_deco_N2_ratio3 / 100.0; | |
| 976 deco_He_ratio3 = (float)char_I_deco_He_ratio3 / 100.0; | |
| 977 deco_N2_ratio4 = (float)char_I_deco_N2_ratio4 / 100.0; | |
| 978 deco_He_ratio4 = (float)char_I_deco_He_ratio4 / 100.0; | |
| 979 deco_N2_ratio5 = (float)char_I_deco_N2_ratio5 / 100.0; | |
| 980 deco_He_ratio5 = (float)char_I_deco_He_ratio5 / 100.0; | |
| 981 float_deco_distance = (float)char_I_deco_distance / 100.0; | |
| 982 | |
| 983 // ____________________________________________________ | |
| 984 // | |
| 985 // _____________ G A S _ C H A N G E S ________________ | |
| 986 // ____________________________________________________ | |
| 987 | |
| 988 int_temp = (int_I_pres_respiration - int_I_pres_surface) + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF; | |
| 989 | |
| 990 deco_gas_change = 0; | |
| 991 deco_gas_change2 = 0; | |
| 992 deco_gas_change3 = 0; | |
| 993 deco_gas_change4 = 0; | |
| 994 deco_gas_change5 = 0; | |
| 995 | |
| 996 if(char_I_deco_gas_change) | |
| 997 { | |
| 998 int_temp2 = ((int)char_I_deco_gas_change) * 100; | |
| 999 if(int_temp > int_temp2) | |
| 1000 { | |
| 1001 deco_gas_change = (float)char_I_deco_gas_change / 9.995 + pres_surface; | |
| 1002 deco_gas_change += float_deco_distance; | |
| 1003 } | |
| 1004 } | |
| 1005 if(char_I_deco_gas_change2) | |
| 1006 { | |
| 1007 int_temp2 = ((int)char_I_deco_gas_change2) * 100; | |
| 1008 if(int_temp > int_temp2) | |
| 1009 { | |
| 1010 deco_gas_change2 = (float)char_I_deco_gas_change2 / 9.995 + pres_surface; | |
| 1011 deco_gas_change2 += float_deco_distance; | |
| 1012 } | |
| 1013 } | |
| 1014 if(char_I_deco_gas_change3) | |
| 1015 { | |
| 1016 int_temp2 = ((int)char_I_deco_gas_change3) * 100; | |
| 1017 if(int_temp > int_temp2) | |
| 1018 { | |
| 1019 deco_gas_change3 = (float)char_I_deco_gas_change3 / 9.995 + pres_surface; | |
| 1020 deco_gas_change3 += float_deco_distance; | |
| 1021 } | |
| 1022 } | |
| 1023 if(char_I_deco_gas_change4) | |
| 1024 { | |
| 1025 int_temp2 = ((int)char_I_deco_gas_change4) * 100; | |
| 1026 if(int_temp > int_temp2) | |
| 1027 { | |
| 1028 deco_gas_change4 = (float)char_I_deco_gas_change4 / 9.995 + pres_surface; | |
| 1029 deco_gas_change4 += float_deco_distance; | |
| 1030 } | |
| 1031 } | |
| 1032 if(char_I_deco_gas_change5) | |
| 1033 { | |
| 1034 int_temp2 = ((int)char_I_deco_gas_change5) * 100; | |
| 1035 if(int_temp > int_temp2) | |
| 1036 { | |
| 1037 deco_gas_change5 = (float)char_I_deco_gas_change5 / 9.995 + pres_surface; | |
| 1038 deco_gas_change5 += float_deco_distance; | |
| 1039 } | |
| 1040 } | |
| 1041 | |
| 1042 const_ppO2 = (float)char_I_const_ppO2 / 100.0; | |
| 1043 deco_ppO2_change = (float)char_I_deco_ppO2_change / 99.95 + pres_surface; | |
| 1044 deco_ppO2_change = deco_ppO2_change + float_deco_distance; | |
| 1045 deco_ppO2 = (float)char_I_deco_ppO2 / 100.0; | |
| 1046 float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0; | |
| 1047 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; | |
| 1048 GF_low = (float)char_I_GF_Low_percentage / 100.0; | |
| 1049 GF_high = (float)char_I_GF_High_percentage / 100.0; | |
| 1050 GF_delta = GF_high - GF_low; | |
| 1051 | |
| 1052 temp2 = (pres_respiration - pres_surface) / 0.29985; | |
| 1053 int_temp = (int)(temp2); | |
| 1054 if (int_temp < 0) | |
| 1055 int_temp = 0; | |
| 1056 if (int_temp > 255) | |
| 1057 int_temp = 255; | |
| 1058 char_O_actual_pointer = int_temp; | |
| 1059 | |
| 1060 temp_depth_last_deco = (int)char_I_depth_last_deco; | |
| 1061 } | |
| 1062 | |
| 1063 void calc_hauptroutine_update_tissues(void) | |
| 1064 { | |
| 1065 int_O_calc_tissue_call_counter = int_O_calc_tissue_call_counter + 1; | |
| 1066 if (char_I_const_ppO2 == 0) // new in v.101 | |
| 1067 pres_diluent = pres_respiration; // new in v.101 | |
| 1068 else // new in v.101 | |
| 1069 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 | |
| 1070 if (pres_diluent > pres_respiration) // new in v.101 | |
| 1071 pres_diluent = pres_respiration; // new in v.101 | |
| 1072 if (pres_diluent > 0.0627) // new in v.101 | |
| 1073 { | |
| 1074 temp_atem = N2_ratio * (pres_diluent - 0.0627); // changed in v.101 | |
| 1075 temp2_atem = He_ratio * (pres_diluent - 0.0627); // changed in v.101 | |
| 1076 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0); | |
| 1077 } | |
| 1078 else // new in v.101 | |
| 1079 { | |
| 1080 temp_atem = 0.0; // new in v.101 | |
| 1081 temp2_atem = 0.0; // new in v.101 | |
| 1082 char_O_diluent = 0; | |
| 1083 } | |
| 1084 temp_surface = pres_surface; | |
| 1085 | |
| 1086 if(!char_I_step_is_1min) | |
| 1087 calc_tissue(); | |
| 1088 else | |
| 1089 calc_tissue_step_1_min(); | |
| 1090 | |
| 1091 int_O_gtissue_limit = (int)(pres_tissue_limit[char_O_gtissue_no] * 1000); | |
| 1092 int_O_gtissue_press = (int)((pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]) * 1000); | |
| 1093 if (char_I_deco_model == 1) | |
| 1094 { | |
| 1095 temp1 = temp1 * GF_high; | |
| 1096 } | |
| 1097 else | |
| 1098 { | |
| 1099 temp1 = temp_surface; | |
| 1100 } | |
| 1101 if (pres_gtissue_limit > temp1 && char_O_deco_status == 0) // if guiding tissue can not be exposed to surface pressure immediately | |
| 1102 { | |
| 1103 char_O_nullzeit = 0; // deco necessary | |
| 1104 char_O_deco_status = 255; // calculate deco skip nullzeit calculation | |
| 1105 } | |
| 1106 } // calc_hauptroutine_update_tissues | |
| 1107 | |
| 1108 void calc_hauptroutine_calc_deco(void) | |
| 1109 { | |
| 1110 do | |
| 1111 { | |
| 1112 int_temp_decostatus = 0; | |
| 1113 calc_nextdecodepth_GF(); | |
| 1114 if (temp_depth_limit > 0) | |
| 1115 { | |
| 1116 calc_N2_ratio = N2_ratio; | |
| 1117 calc_He_ratio = He_ratio; | |
| 1118 | |
| 1119 if (char_I_const_ppO2 == 0) // new in v.101 | |
| 1120 { | |
| 1121 deco_diluent = temp_deco; // new in v.101 | |
| 1122 | |
| 1123 if(deco_gas_change && (temp_deco < deco_gas_change)) | |
| 1124 { | |
| 1125 calc_N2_ratio = deco_N2_ratio; | |
| 1126 calc_He_ratio = deco_He_ratio; | |
| 1127 } | |
| 1128 if(deco_gas_change2 && (temp_deco < deco_gas_change2)) | |
| 1129 { | |
| 1130 calc_N2_ratio = deco_N2_ratio2; | |
| 1131 calc_He_ratio = deco_He_ratio2; | |
| 1132 } | |
| 1133 if(deco_gas_change3 && (temp_deco < deco_gas_change3)) | |
| 1134 { | |
| 1135 calc_N2_ratio = deco_N2_ratio3; | |
| 1136 calc_He_ratio = deco_He_ratio3; | |
| 1137 } | |
| 1138 if(deco_gas_change4 && (temp_deco < deco_gas_change4)) | |
| 1139 { | |
| 1140 calc_N2_ratio = deco_N2_ratio4; | |
| 1141 calc_He_ratio = deco_He_ratio4; | |
| 1142 } | |
| 1143 if(deco_gas_change5 && (temp_deco < deco_gas_change5)) | |
| 1144 { | |
| 1145 calc_N2_ratio = deco_N2_ratio5; | |
| 1146 calc_He_ratio = deco_He_ratio5; | |
| 1147 } | |
| 1148 } | |
| 1149 else // new in v.101 | |
| 1150 { | |
| 1151 if (temp_deco > deco_ppO2_change) | |
| 1152 { | |
| 1153 deco_diluent = ((temp_deco - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 | |
| 1154 } | |
| 1155 else | |
| 1156 { | |
| 1157 deco_diluent = ((temp_deco - deco_ppO2)/(N2_ratio + He_ratio)); // new in v.101 | |
| 1158 } | |
| 1159 } | |
| 1160 if (deco_diluent > temp_deco) // new in v.101 | |
| 1161 deco_diluent = temp_deco; // new in v.101 | |
| 1162 if (deco_diluent > 0.0627) // new in v.101 | |
| 1163 { | |
| 1164 temp_atem = calc_N2_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
| 1165 temp2_atem = calc_He_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
| 1166 } | |
| 1167 else // new in v.101 | |
| 1168 { | |
| 1169 temp_atem = 0.0; // new in v.101 | |
| 1170 temp2_atem = 0.0; // new in v.101 | |
| 1171 } | |
| 1172 sim_tissue_1min(); | |
| 1173 update_internal_deco_table_GF(); | |
| 1174 temp_decotime = 1; | |
| 1175 update_decoarray(); | |
| 1176 char_O_deco_status = char_O_deco_status + 1; | |
| 1177 if (char_O_deco_status < 16) | |
| 1178 int_temp_decostatus = 1; | |
| 1179 } | |
| 1180 else // if (temp_depth_limit > 0) | |
| 1181 { | |
| 1182 char_O_deco_status = 0; | |
| 1183 } | |
| 1184 } while (int_temp_decostatus == 1); | |
| 1185 if (char_O_deco_status > 15) | |
| 1186 { | |
| 1187 char_O_deco_status = 1; | |
| 1188 } | |
| 1189 else | |
| 1190 { | |
| 1191 copy_deco_table_GF(); | |
| 1192 char_O_deco_status = 0; | |
| 1193 } | |
| 1194 } | |
| 1195 | |
| 1196 void calc_hauptroutine_calc_ascend_to_deco(void) | |
| 1197 { | |
| 1198 update_startvalues(); | |
| 1199 char_O_deco_status = 0; | |
| 1200 temp_deco = pres_respiration; | |
| 1201 lock_GF_depth_list = 1; // new in v.102 | |
| 1202 do // go up to first deco | |
| 1203 { | |
| 1204 int_temp_decostatus = 0; | |
| 1205 temp_deco = temp_deco - 1.0; | |
| 1206 if ( char_I_deco_model == 1) // new in v.102 , 4 = deep stops | |
| 1207 temp_limit = temp_pres_gtissue_limit_GF_low; | |
| 1208 else | |
| 1209 temp_limit = temp_pres_gtissue_limit; | |
| 1210 if ((temp_deco > temp_limit) && (temp_deco > pres_surface)) // changes in v.102 | |
| 1211 { | |
| 1212 lock_GF_depth_list = 0; // new in v.102, distance to first stop > 10 mtr. | |
| 1213 output[6] = 0; | |
| 1214 temp_deco += 0.5; | |
| 1215 | |
| 1216 calc_N2_ratio = N2_ratio; | |
| 1217 calc_He_ratio = He_ratio; | |
| 1218 | |
| 1219 if (char_I_const_ppO2 == 0) // new in v.101 // calculate at half of the ascent | |
| 1220 { | |
| 1221 deco_diluent = temp_deco; // new in v.101 | |
| 1222 | |
| 1223 if(deco_gas_change && (temp_deco < deco_gas_change)) | |
| 1224 { | |
| 1225 calc_N2_ratio = deco_N2_ratio; | |
| 1226 calc_He_ratio = deco_He_ratio; | |
| 1227 } | |
| 1228 if(deco_gas_change2 && (temp_deco < deco_gas_change2)) | |
| 1229 { | |
| 1230 calc_N2_ratio = deco_N2_ratio2; | |
| 1231 calc_He_ratio = deco_He_ratio2; | |
| 1232 } | |
| 1233 if(deco_gas_change3 && (temp_deco < deco_gas_change3)) | |
| 1234 { | |
| 1235 calc_N2_ratio = deco_N2_ratio3; | |
| 1236 calc_He_ratio = deco_He_ratio3; | |
| 1237 } | |
| 1238 if(deco_gas_change4 && (temp_deco < deco_gas_change4)) | |
| 1239 { | |
| 1240 calc_N2_ratio = deco_N2_ratio4; | |
| 1241 calc_He_ratio = deco_He_ratio4; | |
| 1242 } | |
| 1243 if(deco_gas_change5 && (temp_deco < deco_gas_change5)) | |
| 1244 { | |
| 1245 calc_N2_ratio = deco_N2_ratio5; | |
| 1246 calc_He_ratio = deco_He_ratio5; | |
| 1247 } | |
| 1248 } | |
| 1249 else // new in v.101 | |
| 1250 { | |
| 1251 if (temp_deco > deco_ppO2_change) | |
| 1252 deco_diluent = ((temp_deco - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 // calculate at half of the ascent | |
| 1253 else | |
| 1254 deco_diluent = ((temp_deco - deco_ppO2)/(N2_ratio + He_ratio)); // new in v.101 // calculate at half of the ascent | |
| 1255 if (deco_diluent > (temp_deco)) // new in v.101 | |
| 1256 deco_diluent = temp_deco; // new in v.101 // calculate at half of the ascent | |
| 1257 } | |
| 1258 temp_deco -= 0.5; | |
| 1259 if (deco_diluent > 0.0627) // new in v.101 | |
| 1260 { | |
| 1261 temp_atem = calc_N2_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
| 1262 temp2_atem = calc_He_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
| 1263 } | |
| 1264 else // new in v.101 | |
| 1265 { | |
| 1266 temp_atem = 0.0; // new in v.101 | |
| 1267 temp2_atem = 0.0; // new in v.101 | |
| 1268 } | |
| 1269 sim_tissue_1min(); | |
| 1270 char_O_deco_status = char_O_deco_status + 1; | |
| 1271 if (char_O_deco_status < 16) // 16 is the limit of calculations for one time slot | |
| 1272 int_temp_decostatus = 1; | |
| 1273 } | |
| 1274 } while (int_temp_decostatus == 1); | |
| 1275 } // calc_hauptroutine_calc_ascend_to_deco | |
| 1276 | |
| 1277 // -------------- | |
| 1278 // calc_tissue // | |
| 1279 // -------------- | |
| 1280 // optimized in v.101 | |
| 1281 | |
| 1282 void calc_tissue(void) | |
| 1283 { | |
| 1284 _asm | |
| 1285 lfsr 1, 0x300 | |
| 1286 movlw 0x01 | |
| 1287 movwf TBLPTRU,0 | |
| 1288 _endasm | |
| 1289 | |
| 1290 char_O_gtissue_no = 255; | |
| 1291 pres_gtissue_limit = 0.0; | |
| 1292 | |
| 1293 for (ci=0;ci<16;ci++) | |
| 1294 { | |
| 1295 _asm | |
| 1296 movlw 0x02 | |
| 1297 movwf TBLPTRH,0 | |
| 1298 movlb 4 // fuer ci | |
| 1299 movf ci,0,1 | |
| 1300 addwf ci,0,1 | |
| 1301 addwf ci,0,1 | |
| 1302 addwf ci,0,1 | |
| 1303 movwf TBLPTRL,0 | |
| 1304 TBLRDPOSTINC | |
| 1305 movff TABLAT,var_e2secs+1 // the order is confussing | |
| 1306 TBLRDPOSTINC | |
| 1307 movff TABLAT,var_e2secs // low byte first, high afterwards | |
| 1308 TBLRDPOSTINC | |
| 1309 movff TABLAT,var_e2secs+3 | |
| 1310 TBLRD | |
| 1311 movff TABLAT,var_e2secs+2 | |
| 1312 addlw 0x40 | |
| 1313 movwf TBLPTRL,0 | |
| 1314 TBLRDPOSTINC | |
| 1315 movff TABLAT,var2_e2secs+1 | |
| 1316 TBLRDPOSTINC | |
| 1317 movff TABLAT,var2_e2secs | |
| 1318 TBLRDPOSTINC | |
| 1319 movff TABLAT,var2_e2secs+3 | |
| 1320 TBLRD | |
| 1321 movff TABLAT,var2_e2secs+2 | |
| 1322 addlw 0x40 | |
| 1323 movwf TBLPTRL,0 | |
| 1324 TBLRDPOSTINC | |
| 1325 movff TABLAT,var_a+1 | |
| 1326 TBLRDPOSTINC | |
| 1327 movff TABLAT,var_a | |
| 1328 TBLRDPOSTINC | |
| 1329 movff TABLAT,var_a+3 | |
| 1330 TBLRD | |
| 1331 movff TABLAT,var_a+2 | |
| 1332 addlw 0x40 | |
| 1333 movwf TBLPTRL,0 | |
| 1334 TBLRDPOSTINC | |
| 1335 movff TABLAT,var2_a+1 | |
| 1336 TBLRDPOSTINC | |
| 1337 movff TABLAT,var2_a | |
| 1338 TBLRDPOSTINC | |
| 1339 movff TABLAT,var2_a+3 | |
| 1340 TBLRD | |
| 1341 movff TABLAT,var2_a+2 | |
| 1342 addlw 0x40 | |
| 1343 movwf TBLPTRL,0 | |
| 1344 incf TBLPTRH,1,0 | |
| 1345 TBLRDPOSTINC | |
| 1346 movff TABLAT,var_b+1 | |
| 1347 TBLRDPOSTINC | |
| 1348 movff TABLAT,var_b | |
| 1349 TBLRDPOSTINC | |
| 1350 movff TABLAT,var_b+3 | |
| 1351 TBLRD | |
| 1352 movff TABLAT,var_b+2 | |
| 1353 addlw 0x40 | |
| 1354 movwf TBLPTRL,0 | |
| 1355 TBLRDPOSTINC | |
| 1356 movff TABLAT,var2_b+1 | |
| 1357 TBLRDPOSTINC | |
| 1358 movff TABLAT,var2_b | |
| 1359 TBLRDPOSTINC | |
| 1360 movff TABLAT,var2_b+3 | |
| 1361 TBLRD | |
| 1362 movff TABLAT,var2_b+2 | |
| 1363 _endasm | |
| 1364 // the start values are the previous end values // write new values in temp | |
| 1365 | |
| 1366 if( (var_e2secs < 0.0000363) | |
| 1367 || (var_e2secs > 0.00577) | |
| 1368 || (var2_e2secs < 0.0000961) | |
| 1369 || (var2_e2secs > 0.150) | |
| 1370 || (var_a < 0.231) | |
| 1371 || (var_a > 1.27) | |
| 1372 || (var_b < 0.504) | |
| 1373 || (var_b > 0.966) | |
| 1374 || (var2_a < 0.510) | |
| 1375 || (var2_a > 1.75) | |
| 1376 || (var2_b < 0.423) | |
| 1377 || (var2_b > 0.927) | |
| 1378 ) | |
| 1379 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
| 1380 | |
| 1381 // N2 | |
| 1382 temp_tissue = (temp_atem - pres_tissue[ci]) * var_e2secs; | |
| 1383 temp_tissue_safety(); | |
| 1384 pres_tissue[ci] = pres_tissue[ci] + temp_tissue; | |
| 1385 | |
| 1386 // He | |
| 1387 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var2_e2secs; | |
| 1388 temp_tissue_safety(); | |
| 1389 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue; | |
| 1390 | |
| 1391 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; | |
| 1392 | |
| 1393 var_a = (var_a * pres_tissue[ci] + var2_a * pres_tissue[ci+16]) / temp_tissue; | |
| 1394 var_b = (var_b * pres_tissue[ci] + var2_b * pres_tissue[ci+16]) / temp_tissue; | |
| 1395 pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
| 1396 if (pres_tissue_limit[ci] < 0) | |
| 1397 pres_tissue_limit[ci] = 0; | |
| 1398 if (pres_tissue_limit[ci] > pres_gtissue_limit) | |
| 1399 { | |
| 1400 pres_gtissue_limit = pres_tissue_limit[ci]; | |
| 1401 char_O_gtissue_no = ci; | |
| 1402 }//if | |
| 1403 } // for | |
| 1404 }//calc_tissue(void) | |
| 1405 | |
| 1406 // ---------------- | |
| 1407 // calc_nullzeit // | |
| 1408 // ---------------- | |
| 1409 // calculates the remaining bottom time | |
| 1410 | |
| 1411 // unchanged in v.101 | |
| 1412 | |
| 1413 void calc_nullzeit(void) | |
| 1414 { | |
| 1415 char_O_nullzeit = 0; | |
| 1416 int_temp = 1; | |
| 1417 do | |
| 1418 { | |
| 1419 backup_sim_pres_tissue(); | |
| 1420 sim_tissue_10min(); | |
| 1421 char_O_nullzeit = char_O_nullzeit + 10; | |
| 1422 int_temp = int_temp + 1; | |
| 1423 if (char_I_deco_model == 1) | |
| 1424 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue; | |
| 1425 else | |
| 1426 temp1 = temp_pres_gtissue_limit; | |
| 1427 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately | |
| 1428 int_temp = 255; | |
| 1429 } while (int_temp < 17); | |
| 1430 if (int_temp == 255) | |
| 1431 { | |
| 1432 restore_sim_pres_tissue(); | |
| 1433 char_O_nullzeit = char_O_nullzeit - 10; | |
| 1434 } //if int_temp == 255] | |
| 1435 int_temp = 1; | |
| 1436 if (char_O_nullzeit < 60) | |
| 1437 { | |
| 1438 do | |
| 1439 { | |
| 1440 sim_tissue_1min(); | |
| 1441 char_O_nullzeit = char_O_nullzeit + 1; | |
| 1442 int_temp = int_temp + 1; // new in v.102a | |
| 1443 if (char_I_deco_model == 1) | |
| 1444 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue; | |
| 1445 else | |
| 1446 temp1 = temp_pres_gtissue_limit; | |
| 1447 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately | |
| 1448 int_temp = 255; | |
| 1449 } while (int_temp < 10); | |
| 1450 if (int_temp == 255) | |
| 1451 char_O_nullzeit = char_O_nullzeit - 1; | |
| 1452 } // if char_O_nullzeit < 60 | |
| 1453 } //calc_nullzeit | |
| 1454 | |
| 1455 // ------------------------- | |
| 1456 // backup_sim_pres_tissue // | |
| 1457 // ------------------------- | |
| 1458 void backup_sim_pres_tissue(void) | |
| 1459 { | |
| 1460 for (x = 0;x<16;x++) | |
| 1461 { | |
| 1462 sim_pres_tissue_backup[x] = sim_pres_tissue[x]; | |
| 1463 sim_pres_tissue_backup[x+16] = sim_pres_tissue[x+16]; | |
| 1464 } | |
| 1465 } // backup_sim | |
| 1466 | |
| 1467 // -------------------------- | |
| 1468 // restore_sim_pres_tissue // | |
| 1469 // -------------------------- | |
| 1470 void restore_sim_pres_tissue(void) | |
| 1471 { | |
| 1472 for (x = 0;x<16;x++) | |
| 1473 { | |
| 1474 sim_pres_tissue[x] = sim_pres_tissue_backup[x]; | |
| 1475 sim_pres_tissue[x+16] = sim_pres_tissue_backup[x+16]; | |
| 1476 } | |
| 1477 } // restore_sim | |
| 1478 | |
| 1479 // ------------------ | |
| 1480 // calc_ascenttime // | |
| 1481 // ------------------ | |
| 1482 | |
| 1483 void calc_ascenttime(void) | |
| 1484 { | |
| 1485 if (pres_respiration > pres_surface) | |
| 1486 { | |
| 1487 switch (char_O_deco_status) | |
| 1488 { | |
| 1489 case 2: | |
| 1490 char_O_ascenttime = 255; | |
| 1491 break; | |
| 1492 case 1: | |
| 1493 break; | |
| 1494 default: | |
| 1495 temp1 = pres_respiration - pres_surface + 0.6; // + 0.6 hence 1 minute ascent time from a depth of 4 meter on | |
| 1496 if (temp1 < 0) | |
| 1497 temp1 = 0; | |
| 1498 if (temp1 > 255) | |
| 1499 temp1 = 255; | |
| 1500 char_O_ascenttime = (char)temp1; | |
| 1501 | |
| 1502 for(ci=0;ci<7;ci++) | |
| 1503 { | |
| 1504 x = char_O_ascenttime + char_O_array_decotime[ci]; | |
| 1505 if (x < char_O_ascenttime) | |
| 1506 char_O_ascenttime = 255; | |
| 1507 else | |
| 1508 char_O_ascenttime = x; | |
| 1509 } | |
| 1510 } | |
| 1511 } | |
| 1512 else | |
| 1513 char_O_ascenttime = 0; | |
| 1514 } // calc_ascenttime() | |
| 1515 | |
| 1516 | |
| 1517 // --------------------- | |
| 1518 // update_startvalues // | |
| 1519 // --------------------- | |
| 1520 // updated in v.102 | |
| 1521 | |
| 1522 void update_startvalues(void) | |
| 1523 { | |
| 1524 temp_pres_gtissue_limit = pres_gtissue_limit; | |
| 1525 temp_pres_gtissue = pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]; | |
| 1526 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; // negative number | |
| 1527 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; | |
| 1528 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; | |
| 1529 if (temp_pres_gtissue_limit_GF_low_below_surface < 0) | |
| 1530 temp_pres_gtissue_limit_GF_low_below_surface = 0; | |
| 1531 | |
| 1532 temp_gtissue_no = char_O_gtissue_no; | |
| 1533 for (x = 0;x<16;x++) | |
| 1534 { | |
| 1535 sim_pres_tissue[x] = pres_tissue[x]; | |
| 1536 sim_pres_tissue[x+16] = pres_tissue[x+16]; | |
| 1537 sim_pres_tissue_limit[x] = pres_tissue_limit[x]; | |
| 1538 } | |
| 1539 } // update_startvalues | |
| 1540 | |
| 1541 | |
| 1542 // ------------------ | |
| 1543 // sim_tissue_1min // | |
| 1544 // ------------------ | |
| 1545 // optimized in v.101 | |
| 1546 | |
| 1547 void sim_tissue_1min(void) | |
| 1548 { | |
| 1549 temp_pres_gtissue_limit = 0.0; | |
| 1550 temp_gtissue_no = 255; | |
| 1551 | |
| 1552 _asm | |
| 1553 lfsr 1, 0x300 | |
| 1554 movlw 0x01 | |
| 1555 movwf TBLPTRU,0 | |
| 1556 _endasm | |
| 1557 | |
| 1558 | |
| 1559 for (ci=0;ci<16;ci++) | |
| 1560 { | |
| 1561 _asm | |
| 1562 movlw 0x02 | |
| 1563 movwf TBLPTRH,0 | |
| 1564 movlb 4 // fuer ci | |
| 1565 movf ci,0,1 | |
| 1566 addwf ci,0,1 | |
| 1567 addwf ci,0,1 | |
| 1568 addwf ci,0,1 | |
| 1569 addlw 0x80 | |
| 1570 movwf TBLPTRL,0 | |
| 1571 TBLRDPOSTINC | |
| 1572 movff TABLAT,var_a+1 | |
| 1573 TBLRDPOSTINC | |
| 1574 movff TABLAT,var_a | |
| 1575 TBLRDPOSTINC | |
| 1576 movff TABLAT,var_a+3 | |
| 1577 TBLRD | |
| 1578 movff TABLAT,var_a+2 | |
| 1579 addlw 0x40 | |
| 1580 movwf TBLPTRL,0 | |
| 1581 TBLRDPOSTINC | |
| 1582 movff TABLAT,var2_a+1 | |
| 1583 TBLRDPOSTINC | |
| 1584 movff TABLAT,var2_a | |
| 1585 TBLRDPOSTINC | |
| 1586 movff TABLAT,var2_a+3 | |
| 1587 TBLRD | |
| 1588 movff TABLAT,var2_a+2 | |
| 1589 addlw 0x40 | |
| 1590 movwf TBLPTRL,0 | |
| 1591 incf TBLPTRH,1,0 | |
| 1592 TBLRDPOSTINC | |
| 1593 movff TABLAT,var_b+1 | |
| 1594 TBLRDPOSTINC | |
| 1595 movff TABLAT,var_b | |
| 1596 TBLRDPOSTINC | |
| 1597 movff TABLAT,var_b+3 | |
| 1598 TBLRD | |
| 1599 movff TABLAT,var_b+2 | |
| 1600 addlw 0x40 | |
| 1601 movwf TBLPTRL,0 | |
| 1602 TBLRDPOSTINC | |
| 1603 movff TABLAT,var2_b+1 | |
| 1604 TBLRDPOSTINC | |
| 1605 movff TABLAT,var2_b | |
| 1606 TBLRDPOSTINC | |
| 1607 movff TABLAT,var2_b+3 | |
| 1608 TBLRD | |
| 1609 movff TABLAT,var2_b+2 | |
| 1610 addlw 0xC0 | |
| 1611 movwf TBLPTRL,0 | |
| 1612 incf TBLPTRH,1,0 | |
| 1613 TBLRDPOSTINC | |
| 1614 movff TABLAT,var_e1min+1 | |
| 1615 TBLRDPOSTINC | |
| 1616 movff TABLAT,var_e1min | |
| 1617 TBLRDPOSTINC | |
| 1618 movff TABLAT,var_e1min+3 | |
| 1619 TBLRD | |
| 1620 movff TABLAT,var_e1min+2 | |
| 1621 addlw 0x40 | |
| 1622 movwf TBLPTRL,0 | |
| 1623 TBLRDPOSTINC | |
| 1624 movff TABLAT,var2_e1min+1 | |
| 1625 TBLRDPOSTINC | |
| 1626 movff TABLAT,var2_e1min | |
| 1627 TBLRDPOSTINC | |
| 1628 movff TABLAT,var2_e1min+3 | |
| 1629 TBLRD | |
| 1630 movff TABLAT,var2_e1min+2 | |
| 1631 _endasm | |
| 1632 // N2 | |
| 1633 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_e1min; | |
| 1634 temp_tissue_safety(); | |
| 1635 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; | |
| 1636 // He | |
| 1637 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var2_e1min; | |
| 1638 temp_tissue_safety(); | |
| 1639 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue; | |
| 1640 // pressure limit | |
| 1641 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16]; | |
| 1642 var_a = (var_a * sim_pres_tissue[ci] + var2_a * sim_pres_tissue[ci+16]) / temp_tissue; | |
| 1643 var_b = (var_b * sim_pres_tissue[ci] + var2_b * sim_pres_tissue[ci+16]) / temp_tissue; | |
| 1644 sim_pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
| 1645 | |
| 1646 if (sim_pres_tissue_limit[ci] < 0) | |
| 1647 sim_pres_tissue_limit[ci] = 0; | |
| 1648 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit) | |
| 1649 { | |
| 1650 temp_pres_gtissue = temp_tissue; | |
| 1651 temp_pres_gtissue_limit = sim_pres_tissue_limit[ci]; | |
| 1652 temp_gtissue_no = ci; | |
| 1653 } | |
| 1654 } // for | |
| 1655 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; | |
| 1656 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; | |
| 1657 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; | |
| 1658 if (temp_pres_gtissue_limit_GF_low_below_surface < 0) | |
| 1659 temp_pres_gtissue_limit_GF_low_below_surface = 0; | |
| 1660 } //sim_tissue_1min() | |
| 1661 | |
| 1662 //-------------------- | |
| 1663 // sim_tissue_10min // | |
| 1664 //-------------------- | |
| 1665 | |
| 1666 // Attention!! uses var_e1min und var2_e1min to load 10min data !!! | |
| 1667 // is identical to sim_tissue_1min routine except for the different load of those variables | |
| 1668 | |
| 1669 // optimized in v.101 | |
| 1670 | |
| 1671 void sim_tissue_10min(void) | |
| 1672 { | |
| 1673 temp_pres_gtissue_limit = 0.0; | |
| 1674 temp_gtissue_no = 255; | |
| 1675 | |
| 1676 _asm | |
| 1677 lfsr 1, 0x300 | |
| 1678 movlw 0x01 | |
| 1679 movwf TBLPTRU,0 | |
| 1680 _endasm | |
| 1681 | |
| 1682 for (ci=0;ci<16;ci++) | |
| 1683 { | |
| 1684 _asm | |
| 1685 movlw 0x02 | |
| 1686 movwf TBLPTRH,0 | |
| 1687 movlb 4 // fuer ci | |
| 1688 movf ci,0,1 | |
| 1689 addwf ci,0,1 | |
| 1690 addwf ci,0,1 | |
| 1691 addwf ci,0,1 | |
| 1692 addlw 0x80 | |
| 1693 movwf TBLPTRL,0 | |
| 1694 TBLRDPOSTINC | |
| 1695 movff TABLAT,var_a+1 | |
| 1696 TBLRDPOSTINC | |
| 1697 movff TABLAT,var_a | |
| 1698 TBLRDPOSTINC | |
| 1699 movff TABLAT,var_a+3 | |
| 1700 TBLRD | |
| 1701 movff TABLAT,var_a+2 | |
| 1702 addlw 0x40 | |
| 1703 movwf TBLPTRL,0 | |
| 1704 TBLRDPOSTINC | |
| 1705 movff TABLAT,var2_a+1 | |
| 1706 TBLRDPOSTINC | |
| 1707 movff TABLAT,var2_a | |
| 1708 TBLRDPOSTINC | |
| 1709 movff TABLAT,var2_a+3 | |
| 1710 TBLRD | |
| 1711 movff TABLAT,var2_a+2 | |
| 1712 addlw 0x40 | |
| 1713 movwf TBLPTRL,0 | |
| 1714 incf TBLPTRH,1,0 | |
| 1715 TBLRDPOSTINC | |
| 1716 movff TABLAT,var_b+1 | |
| 1717 TBLRDPOSTINC | |
| 1718 movff TABLAT,var_b | |
| 1719 TBLRDPOSTINC | |
| 1720 movff TABLAT,var_b+3 | |
| 1721 TBLRD | |
| 1722 movff TABLAT,var_b+2 | |
| 1723 addlw 0x40 | |
| 1724 movwf TBLPTRL,0 | |
| 1725 TBLRDPOSTINC | |
| 1726 movff TABLAT,var2_b+1 | |
| 1727 TBLRDPOSTINC | |
| 1728 movff TABLAT,var2_b | |
| 1729 TBLRDPOSTINC | |
| 1730 movff TABLAT,var2_b+3 | |
| 1731 TBLRD | |
| 1732 movff TABLAT,var2_b+2 | |
| 1733 addlw 0xC0 // different to 1 min | |
| 1734 movwf TBLPTRL,0 | |
| 1735 incf TBLPTRH,1,0 | |
| 1736 incf TBLPTRH,1,0 // different to 1 min | |
| 1737 TBLRDPOSTINC | |
| 1738 movff TABLAT,var_e1min+1 | |
| 1739 TBLRDPOSTINC | |
| 1740 movff TABLAT,var_e1min | |
| 1741 TBLRDPOSTINC | |
| 1742 movff TABLAT,var_e1min+3 | |
| 1743 TBLRD | |
| 1744 movff TABLAT,var_e1min+2 | |
| 1745 addlw 0x40 | |
| 1746 movwf TBLPTRL,0 | |
| 1747 //incf TBLPTRH,1,0 // different to 1 min | |
| 1748 TBLRDPOSTINC | |
| 1749 movff TABLAT,var2_e1min+1 | |
| 1750 TBLRDPOSTINC | |
| 1751 movff TABLAT,var2_e1min | |
| 1752 TBLRDPOSTINC | |
| 1753 movff TABLAT,var2_e1min+3 | |
| 1754 TBLRD | |
| 1755 movff TABLAT,var2_e1min+2 | |
| 1756 _endasm | |
| 1757 // N2 | |
| 1758 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_e1min; | |
| 1759 temp_tissue_safety(); | |
| 1760 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; | |
| 1761 // He | |
| 1762 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var2_e1min; | |
| 1763 temp_tissue_safety(); | |
| 1764 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue; | |
| 1765 // pressure limit | |
| 1766 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16]; | |
| 1767 var_a = (var_a * sim_pres_tissue[ci] + var2_a * sim_pres_tissue[ci+16]) / temp_tissue; | |
| 1768 var_b = (var_b * sim_pres_tissue[ci] + var2_b * sim_pres_tissue[ci+16]) / temp_tissue; | |
| 1769 | |
| 1770 sim_pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
| 1771 if (sim_pres_tissue_limit[ci] < 0) | |
| 1772 sim_pres_tissue_limit[ci] = 0; | |
| 1773 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit) | |
| 1774 { | |
| 1775 temp_pres_gtissue = temp_tissue; | |
| 1776 temp_pres_gtissue_limit = sim_pres_tissue_limit[ci]; | |
| 1777 temp_gtissue_no = ci; | |
| 1778 } | |
| 1779 } // for | |
| 1780 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; // negative number | |
| 1781 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; | |
| 1782 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; | |
| 1783 if (temp_pres_gtissue_limit_GF_low_below_surface < 0) | |
| 1784 temp_pres_gtissue_limit_GF_low_below_surface = 0; | |
| 1785 } //sim_tissue_10min() | |
| 1786 | |
| 1787 | |
| 1788 // ------------------ | |
| 1789 // clear_decoarray // | |
| 1790 // ------------------ | |
| 1791 // unchanged in v.101 | |
| 1792 | |
| 1793 void clear_decoarray(void) | |
| 1794 { | |
| 1795 char_O_array_decodepth[0] = 0; | |
| 1796 char_O_array_decodepth[1] = 0; | |
| 1797 char_O_array_decodepth[2] = 0; | |
| 1798 char_O_array_decodepth[3] = 0; | |
| 1799 char_O_array_decodepth[4] = 0; | |
| 1800 char_O_array_decodepth[5] = 0; | |
| 1801 char_O_array_decotime[0] = 0; | |
| 1802 char_O_array_decotime[1] = 0; | |
| 1803 char_O_array_decotime[2] = 0; | |
| 1804 char_O_array_decotime[3] = 0; | |
| 1805 char_O_array_decotime[4] = 0; | |
| 1806 char_O_array_decotime[5] = 0; | |
| 1807 char_O_array_decotime[6] = 0; | |
| 1808 } // clear_decoarray | |
| 1809 | |
| 1810 | |
| 1811 // ------------------- | |
| 1812 // update_decoarray // | |
| 1813 // ------------------- | |
| 1814 // unchanged in v.101 | |
| 1815 | |
| 1816 void update_decoarray() | |
| 1817 { | |
| 1818 x = 0; | |
| 1819 do | |
| 1820 { | |
| 1821 if (char_O_array_decodepth[x] == temp_depth_limit) | |
| 1822 { | |
| 1823 int_temp = char_O_array_decotime[x] + temp_decotime; | |
| 1824 if (int_temp < 0) | |
| 1825 int_temp = 0; | |
| 1826 if (int_temp > 240) | |
| 1827 int_temp = 240; | |
| 1828 char_O_array_decotime[x] = int_temp; | |
| 1829 x = 10; // exit | |
| 1830 } // if | |
| 1831 else | |
| 1832 { | |
| 1833 if (char_O_array_decodepth[x] == 0) | |
| 1834 { | |
| 1835 if (temp_depth_limit > 255) | |
| 1836 char_O_array_decodepth[x] = 255; | |
| 1837 else | |
| 1838 char_O_array_decodepth[x] = (char)temp_depth_limit; | |
| 1839 int_temp = char_O_array_decotime[x] + temp_decotime; | |
| 1840 if (int_temp > 240) | |
| 1841 char_O_array_decotime[x] = 240; | |
| 1842 else | |
| 1843 char_O_array_decotime[x] = (char)int_temp; | |
| 1844 x = 10; // exit | |
| 1845 } // if | |
| 1846 else | |
| 1847 x++; | |
| 1848 } // else | |
| 1849 } while (x<6); | |
| 1850 if (x == 6) | |
| 1851 { | |
| 1852 int_temp = char_O_array_decotime[6] + temp_decotime; | |
| 1853 if (int_temp > 220) | |
| 1854 char_O_array_decotime[6] = 220; | |
| 1855 else | |
| 1856 char_O_array_decotime[6] = (char)int_temp; | |
| 1857 } // if x == 6 | |
| 1858 } // update_decoarray | |
| 1859 | |
| 1860 | |
| 1861 // ----------------------- | |
| 1862 // calc_gradient_factor // | |
| 1863 // ----------------------- | |
| 1864 // optimized in v.101 (var_a) | |
| 1865 // new code in v.102 | |
| 1866 | |
| 1867 void calc_gradient_factor(void) | |
| 1868 { | |
| 1869 // tissue > respiration (entsaettigungsvorgang) | |
| 1870 // gradient ist wieviel prozent an limit mit basis tissue | |
| 1871 // dh. 0% = respiration == tissue | |
| 1872 // dh. 100% = respiration == limit | |
| 1873 temp_tissue = pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]; | |
| 1874 temp1 = temp_tissue - pres_respiration; | |
| 1875 temp2 = temp_tissue - pres_tissue_limit[char_O_gtissue_no]; // changed in v.102 | |
| 1876 temp2 = temp1/temp2; | |
| 1877 temp2 = temp2 * 100; // displayed in percent | |
| 1878 if (temp2 < 0) | |
| 1879 temp2 = 0; | |
| 1880 if (temp2 > 255) | |
| 1881 temp2 = 255; | |
| 1882 if (temp1 < 0) | |
| 1883 char_O_gradient_factor = 0; | |
| 1884 else | |
| 1885 char_O_gradient_factor = (char)temp2; | |
| 1886 | |
| 1887 temp3 = temp2; | |
| 1888 | |
| 1889 if (char_I_deco_model == 1) // calculate relative gradient factor | |
| 1890 { | |
| 1891 temp1 = (float)temp_depth_GF_low_meter * 0.09995; | |
| 1892 temp2 = pres_respiration - pres_surface; | |
| 1893 if (temp2 <= 0) | |
| 1894 temp1 = GF_high; | |
| 1895 else | |
| 1896 if (temp2 >= temp1) | |
| 1897 temp1 = GF_low; | |
| 1898 else | |
| 1899 temp1 = GF_low + (temp1 - temp2)/temp1*GF_delta; | |
| 1900 if (temp_depth_GF_low_meter == 0) | |
| 1901 temp1 = GF_high; | |
| 1902 temp2 = temp3 / temp1; // temp3 is already in percent | |
| 1903 if (temp2 < 0) | |
| 1904 temp2 = 0; | |
| 1905 if (temp2 > 255) | |
| 1906 temp2 = 255; | |
| 1907 char_O_relative_gradient_GF = (char)temp2; | |
| 1908 } // calc relative gradient factor | |
| 1909 else | |
| 1910 { | |
| 1911 char_O_relative_gradient_GF = char_O_gradient_factor; | |
| 1912 } | |
| 1913 } // calc_gradient | |
| 1914 | |
| 1915 // --------------------------- | |
| 1916 // deco_gradient_array // | |
| 1917 // --------------------------- | |
| 1918 // optimized in v.101 (var_a) | |
| 1919 // new code in v.102 | |
| 1920 | |
| 1921 void deco_gradient_array() | |
| 1922 { | |
| 1923 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | |
| 1924 for (ci=0;ci<16;ci++) | |
| 1925 { | |
| 1926 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; | |
| 1927 temp1 = temp_tissue - pres_respiration; | |
| 1928 temp2 = temp_tissue - pres_tissue_limit[ci]; | |
| 1929 temp2 = temp1/temp2; | |
| 1930 temp2 = temp2 * 200; // because of output in (Double-)percentage | |
| 1931 if (temp2 < 0) | |
| 1932 temp2 = 0; | |
| 1933 if (temp2 > 255) | |
| 1934 temp2 = 255; | |
| 1935 if (temp1 < 0) | |
| 1936 char_O_array_gradient_weighted[ci] = 0; | |
| 1937 else | |
| 1938 char_O_array_gradient_weighted[ci] = (char)temp2; | |
| 1939 } // for | |
| 1940 } // deco_gradient_array | |
| 1941 | |
| 1942 | |
| 1943 // ------------------------------ | |
| 1944 // deco_calc_desaturation_time // | |
| 1945 // ------------------------------ | |
| 1946 // FIXED N2_ratio | |
| 1947 // unchanged in v.101 | |
| 1948 | |
| 1949 void deco_calc_desaturation_time(void) | |
| 1950 { | |
| 1951 _asm | |
| 1952 lfsr 1, 0x300 | |
| 1953 movlw 0x01 | |
| 1954 movwf TBLPTRU,0 | |
| 1955 _endasm | |
| 1956 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann | |
| 1957 pres_surface = (float)int_I_pres_surface / 1000.0; | |
| 1958 temp_atem = N2_ratio * (pres_surface - 0.0627); | |
| 1959 int_O_desaturation_time = 0; | |
| 1960 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) | |
| 1961 | |
| 1962 for (ci=0;ci<16;ci++) | |
| 1963 { | |
| 1964 _asm | |
| 1965 movlw 0x04 | |
| 1966 movwf TBLPTRH,0 | |
| 1967 movlb 4 // fuer ci | |
| 1968 movf ci,0,1 | |
| 1969 addwf ci,0,1 | |
| 1970 addwf ci,0,1 | |
| 1971 addwf ci,0,1 | |
| 1972 addlw 0x80 | |
| 1973 movwf TBLPTRL,0 | |
| 1974 TBLRDPOSTINC | |
| 1975 movff TABLAT,var_halftimes+1 | |
| 1976 TBLRDPOSTINC | |
| 1977 movff TABLAT,var_halftimes | |
| 1978 TBLRDPOSTINC | |
| 1979 movff TABLAT,var_halftimes+3 | |
| 1980 TBLRD | |
| 1981 movff TABLAT,var_halftimes+2 | |
| 1982 addlw 0x40 | |
| 1983 movwf TBLPTRL,0 | |
| 1984 TBLRDPOSTINC | |
| 1985 movff TABLAT,var2_halftimes+1 | |
| 1986 TBLRDPOSTINC | |
| 1987 movff TABLAT,var2_halftimes | |
| 1988 TBLRDPOSTINC | |
| 1989 movff TABLAT,var2_halftimes+3 | |
| 1990 TBLRD | |
| 1991 movff TABLAT,var2_halftimes+2 | |
| 1992 _endasm | |
| 1993 | |
| 1994 // saturation_time (for flight) and N2_saturation in multiples of halftime | |
| 1995 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
| 1996 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
| 1997 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations | |
| 1998 // N2 | |
| 1999 temp1 = 1.05 * temp_atem; | |
| 2000 temp1 = temp1 - pres_tissue[ci]; | |
| 2001 temp2 = temp_atem - pres_tissue[ci]; | |
| 2002 if (temp2 >= 0.0) | |
| 2003 { | |
| 2004 temp1 = 0; | |
| 2005 temp2 = 0; | |
| 2006 } | |
| 2007 else | |
| 2008 temp1 = temp1 / temp2; | |
| 2009 if (temp1 > 0.0) | |
| 2010 { | |
| 2011 temp1 = log(1.0 - temp1); | |
| 2012 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary. | |
| 2013 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
| 2014 // minus because log is negative | |
| 2015 temp2 = var_halftimes * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 10 percent) , new in v.101: float_desaturation_multiplier | |
| 2016 } | |
| 2017 else | |
| 2018 { | |
| 2019 temp1 = 0; | |
| 2020 temp2 = 0; | |
| 2021 } | |
| 2022 | |
| 2023 // He | |
| 2024 temp3 = 0.1 - pres_tissue[ci+16]; | |
| 2025 if (temp3 >= 0.0) | |
| 2026 { | |
| 2027 temp3 = 0; | |
| 2028 temp4 = 0; | |
| 2029 } | |
| 2030 else | |
| 2031 temp3 = -1.0 * temp3 / pres_tissue[ci+16]; | |
| 2032 if (temp3 > 0.0) | |
| 2033 { | |
| 2034 temp3 = log(1.0 - temp3); | |
| 2035 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. | |
| 2036 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
| 2037 // minus because log is negative | |
| 2038 temp4 = var2_halftimes * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier | |
| 2039 } | |
| 2040 else | |
| 2041 { | |
| 2042 temp3 = 0; | |
| 2043 temp4 = 0; | |
| 2044 } | |
| 2045 | |
| 2046 // saturation_time (for flight) | |
| 2047 if (temp4 > temp2) | |
| 2048 int_temp = (int)temp4; | |
| 2049 else | |
| 2050 int_temp = (int)temp2; | |
| 2051 if(int_temp > int_O_desaturation_time) | |
| 2052 int_O_desaturation_time = int_temp; | |
| 2053 | |
| 2054 // N2 saturation in multiples of halftime for display purposes | |
| 2055 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
| 2056 temp2 = temp2 + 80.0; // set center | |
| 2057 if (temp2 < 0.0) | |
| 2058 temp2 = 0.0; | |
| 2059 if (temp2 > 255.0) | |
| 2060 temp2 = 255.0; | |
| 2061 char_O_tissue_saturation[ci] = (char)temp2; | |
| 2062 // He saturation in multiples of halftime for display purposes | |
| 2063 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
| 2064 temp4 = temp4 + 80.0; // set center | |
| 2065 if (temp4 < 0.0) | |
| 2066 temp4 = 0.0; | |
| 2067 if (temp4 > 255.0) | |
| 2068 temp4 = 255.0; | |
| 2069 char_O_tissue_saturation[ci+16] = (char)temp4; | |
| 2070 } // for | |
| 2071 } // deco_calc_desaturation_time | |
| 2072 | |
| 2073 | |
| 2074 // -------------------------- | |
| 2075 // calc_wo_deco_step_1_min // | |
| 2076 // -------------------------- | |
| 2077 // FIXED N2 Ratio | |
| 2078 // optimized in v.101 (...saturation_multiplier) | |
| 2079 // desaturation slowed down to 70,42% | |
| 2080 | |
| 2081 void calc_wo_deco_step_1_min(void) | |
| 2082 { | |
| 2083 if(flag_in_divemode) | |
| 2084 { | |
| 2085 flag_in_divemode = 0; | |
| 2086 set_dbg_end_of_dive(); | |
| 2087 } | |
| 2088 _asm | |
| 2089 lfsr 1, 0x300 | |
| 2090 _endasm | |
| 2091 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann | |
| 2092 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | |
| 2093 pres_surface = (float)int_I_pres_surface / 1000.0; | |
| 2094 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body | |
| 2095 temp2_atem = 0.0; | |
| 2096 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does not use the N2_ratio | |
| 2097 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) | |
| 2098 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; | |
| 2099 | |
| 2100 calc_tissue_step_1_min(); // update the pressure in the 16 tissues in accordance with the new ambient pressure | |
| 2101 clear_decoarray(); | |
| 2102 char_O_deco_status = 0; | |
| 2103 char_O_nullzeit = 0; | |
| 2104 char_O_ascenttime = 0; | |
| 2105 calc_gradient_factor(); | |
| 2106 | |
| 2107 } // calc_wo_deco_step_1_min(void) | |
| 2108 | |
| 2109 | |
| 2110 // ------------------------- | |
| 2111 // calc_tissue_step_1_min // | |
| 2112 // ------------------------- | |
| 2113 // optimized in v.101 | |
| 2114 | |
| 2115 void calc_tissue_step_1_min(void) | |
| 2116 { | |
| 2117 _asm | |
| 2118 lfsr 1, 0x300 | |
| 2119 movlw 0x01 | |
| 2120 movwf TBLPTRU,0 | |
| 2121 _endasm | |
| 2122 | |
| 2123 char_O_gtissue_no = 255; | |
| 2124 pres_gtissue_limit = 0.0; | |
| 2125 | |
| 2126 for (ci=0;ci<16;ci++) | |
| 2127 { | |
| 2128 _asm | |
| 2129 movlw 0x02 | |
| 2130 movwf TBLPTRH,0 | |
| 2131 movlb 4 // fuer ci | |
| 2132 movf ci,0,1 | |
| 2133 addwf ci,0,1 | |
| 2134 addwf ci,0,1 | |
| 2135 addwf ci,0,1 | |
| 2136 addlw 0x80 | |
| 2137 movwf TBLPTRL,0 | |
| 2138 TBLRDPOSTINC | |
| 2139 movff TABLAT,var_a+1 | |
| 2140 TBLRDPOSTINC | |
| 2141 movff TABLAT,var_a | |
| 2142 TBLRDPOSTINC | |
| 2143 movff TABLAT,var_a+3 | |
| 2144 TBLRD | |
| 2145 movff TABLAT,var_a+2 | |
| 2146 addlw 0x40 | |
| 2147 movwf TBLPTRL,0 | |
| 2148 TBLRDPOSTINC | |
| 2149 movff TABLAT,var2_a+1 | |
| 2150 TBLRDPOSTINC | |
| 2151 movff TABLAT,var2_a | |
| 2152 TBLRDPOSTINC | |
| 2153 movff TABLAT,var2_a+3 | |
| 2154 TBLRD | |
| 2155 movff TABLAT,var2_a+2 | |
| 2156 addlw 0x40 | |
| 2157 movwf TBLPTRL,0 | |
| 2158 incf TBLPTRH,1,0 | |
| 2159 TBLRDPOSTINC | |
| 2160 movff TABLAT,var_b+1 | |
| 2161 TBLRDPOSTINC | |
| 2162 movff TABLAT,var_b | |
| 2163 TBLRDPOSTINC | |
| 2164 movff TABLAT,var_b+3 | |
| 2165 TBLRD | |
| 2166 movff TABLAT,var_b+2 | |
| 2167 addlw 0x40 | |
| 2168 movwf TBLPTRL,0 | |
| 2169 TBLRDPOSTINC | |
| 2170 movff TABLAT,var2_b+1 | |
| 2171 TBLRDPOSTINC | |
| 2172 movff TABLAT,var2_b | |
| 2173 TBLRDPOSTINC | |
| 2174 movff TABLAT,var2_b+3 | |
| 2175 TBLRD | |
| 2176 movff TABLAT,var2_b+2 | |
| 2177 addlw 0xC0 | |
| 2178 movwf TBLPTRL,0 | |
| 2179 incf TBLPTRH,1,0 | |
| 2180 TBLRDPOSTINC | |
| 2181 movff TABLAT,var_e1min+1 | |
| 2182 TBLRDPOSTINC | |
| 2183 movff TABLAT,var_e1min | |
| 2184 TBLRDPOSTINC | |
| 2185 movff TABLAT,var_e1min+3 | |
| 2186 TBLRD | |
| 2187 movff TABLAT,var_e1min+2 | |
| 2188 addlw 0x40 | |
| 2189 movwf TBLPTRL,0 | |
| 2190 TBLRDPOSTINC | |
| 2191 movff TABLAT,var2_e1min+1 | |
| 2192 TBLRDPOSTINC | |
| 2193 movff TABLAT,var2_e1min | |
| 2194 TBLRDPOSTINC | |
| 2195 movff TABLAT,var2_e1min+3 | |
| 2196 TBLRD | |
| 2197 movff TABLAT,var2_e1min+2 | |
| 2198 _endasm | |
| 2199 | |
| 2200 // N2 1 min | |
| 2201 temp_tissue = (temp_atem - pres_tissue[ci]) * var_e1min; | |
| 2202 temp_tissue_safety(); | |
| 2203 pres_tissue[ci] = pres_tissue[ci] + temp_tissue; | |
| 2204 | |
| 2205 // He 1 min | |
| 2206 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var2_e1min; | |
| 2207 temp_tissue_safety(); | |
| 2208 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue; | |
| 2209 | |
| 2210 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; | |
| 2211 var_a = (var_a * pres_tissue[ci] + var2_a * pres_tissue[ci+16]) / temp_tissue; | |
| 2212 var_b = (var_b * pres_tissue[ci] + var2_b * pres_tissue[ci+16]) / temp_tissue; | |
| 2213 pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
| 2214 if (pres_tissue_limit[ci] < 0) | |
| 2215 pres_tissue_limit[ci] = 0; | |
| 2216 if (pres_tissue_limit[ci] > pres_gtissue_limit) | |
| 2217 { | |
| 2218 pres_gtissue_limit = pres_tissue_limit[ci]; | |
| 2219 char_O_gtissue_no = ci; | |
| 2220 }//if | |
| 2221 | |
| 2222 if(!char_I_step_is_1min) | |
| 2223 { | |
| 2224 // gradient factor array for graphical display | |
| 2225 // display range is 0 to 250! in steps of 5 for 1 pixel | |
| 2226 // the display is divided in 6 blocks | |
| 2227 // -> double the gradient 100% = 200 | |
| 2228 // tissue > respiration (entsaettigungsvorgang) | |
| 2229 // gradient ist wieviel prozent an limit von tissue aus | |
| 2230 // dh. 0% = respiration == tissue | |
| 2231 // dh. 100% = respiration == limit | |
| 2232 temp1 = temp_tissue - pres_respiration; | |
| 2233 temp2 = temp_tissue - pres_tissue_limit[ci]; // changed in v.102 | |
| 2234 temp2 = temp1/temp2; | |
| 2235 temp2 = temp2 * 200; // because of output in (Double-)percentage | |
| 2236 if (temp2 < 0) | |
| 2237 temp2 = 0; | |
| 2238 if (temp2 > 255) | |
| 2239 temp2 = 255; | |
| 2240 if (temp1 < 0) | |
| 2241 char_O_array_gradient_weighted[ci] = 0; | |
| 2242 else | |
| 2243 char_O_array_gradient_weighted[ci] = (char)temp2; | |
| 2244 } | |
| 2245 } // for | |
| 2246 } // calc wo deco 1min | |
| 2247 | |
| 2248 // ---------- | |
| 2249 // deco_hash // | |
| 2250 // ---------- | |
| 2251 void deco_hash(void) | |
| 2252 { | |
| 2253 // init | |
| 2254 for (md_i=0;md_i<16;md_i++) | |
| 2255 { | |
| 2256 md_state[md_i] = 0; | |
| 2257 md_cksum[md_i] = 0; | |
| 2258 } // for md_i 16 | |
| 2259 | |
| 2260 _asm | |
| 2261 movlw 0x01 | |
| 2262 movwf TBLPTRU,0 | |
| 2263 movlw 0x06 | |
| 2264 movwf TBLPTRH,0 | |
| 2265 movlw 0x00 | |
| 2266 movwf TBLPTRL,0 | |
| 2267 _endasm; | |
| 2268 for (md_i=0;md_i<127;md_i++) | |
| 2269 { | |
| 2270 _asm | |
| 2271 TBLRDPOSTINC | |
| 2272 movff TABLAT,md_temp | |
| 2273 _endasm | |
| 2274 md_pi_subst[md_i] = md_temp; | |
| 2275 } // for md_i 256 | |
| 2276 _asm | |
| 2277 TBLRDPOSTINC | |
| 2278 movff TABLAT,md_temp | |
| 2279 _endasm; | |
| 2280 md_pi_subst[127] = md_temp; | |
| 2281 for (md_i=0;md_i<127;md_i++) | |
| 2282 { | |
| 2283 _asm | |
| 2284 TBLRDPOSTINC | |
| 2285 movff TABLAT,md_temp | |
| 2286 _endasm | |
| 2287 md_pi_subst[md_i+128] = md_temp; | |
| 2288 } // for md_i 256 | |
| 2289 _asm | |
| 2290 TBLRD | |
| 2291 movff TABLAT,md_temp | |
| 2292 _endasm | |
| 2293 md_pi_subst[255] = md_temp; | |
| 2294 | |
| 2295 _asm | |
| 2296 movlw 0x00 | |
| 2297 movwf TBLPTRU,0 | |
| 2298 movlw 0x00 | |
| 2299 movwf TBLPTRH,0 | |
| 2300 movlw 0x00 | |
| 2301 movwf TBLPTRL,0 | |
| 2302 _endasm | |
| 2303 // cycle buffers | |
| 2304 for (md_pointer=0x0000;md_pointer<0x17f3;md_pointer++) | |
| 2305 { | |
| 2306 md_t = 0; | |
| 2307 for (md_i=0;md_i<16;md_i++) | |
| 2308 { | |
| 2309 if(md_pointer == 9) | |
| 2310 md_temp = md_cksum[md_i]; | |
| 2311 else | |
| 2312 { | |
| 2313 _asm | |
| 2314 TBLRDPOSTINC | |
| 2315 movff TABLAT,md_temp | |
| 2316 _endasm | |
| 2317 } // else | |
| 2318 md_buffer[md_i] = md_temp; | |
| 2319 md_state[md_i+16] = md_buffer[md_i]; | |
| 2320 md_state[md_i+32] = (unsigned char)(md_buffer[md_i] ^ md_state[md_i]); | |
| 2321 } // for md_i 16 | |
| 2322 | |
| 2323 for (md_i=0;md_i<18;md_i++) | |
| 2324 { | |
| 2325 for (md_j=0;md_j<48;md_j++) | |
| 2326 { | |
| 2327 md_state[md_j] = (unsigned char)(md_state[md_j] ^ md_pi_subst[md_t]); | |
| 2328 md_t = md_state[md_j]; | |
| 2329 } // for md_j 48 | |
| 2330 md_t = (unsigned char)(md_t+1); | |
| 2331 } // for md_i 18 | |
| 2332 md_t = md_cksum[15]; | |
| 2333 | |
| 2334 for (md_i=0;md_i<16;md_i++) | |
| 2335 { | |
| 2336 md_cksum[md_i] = (unsigned char)(md_cksum[md_i] ^ md_pi_subst[(md_buffer[md_i] ^ md_t)]); | |
| 2337 md_t = md_cksum[md_i]; | |
| 2338 } // for md_i 16 | |
| 2339 } // for md_pointer | |
| 2340 } // void deco_hash(void) | |
| 2341 | |
| 2342 // --------------------- | |
| 2343 // deco_clear_CNS_fraction // | |
| 2344 // --------------------- | |
| 2345 // new in v.101 | |
| 2346 | |
| 2347 void deco_clear_CNS_fraction(void) | |
| 2348 { | |
| 2349 CNS_fraction = 0.0; | |
| 2350 char_O_CNS_fraction = 0; | |
| 2351 } // void deco_clear_CNS_fraction(void) | |
| 2352 | |
| 2353 | |
| 2354 // ------------------------- | |
| 2355 // deco_calc_CNS_fraction // | |
| 2356 // ------------------------- | |
| 2357 // new in v.101 | |
| 2358 // optimized in v.102 : with new variables char_I_actual_ppO2 and actual_ppO2 | |
| 2359 | |
| 2360 // Input: char_I_actual_ppO2 | |
| 2361 // Output: char_O_CNS_fraction | |
| 2362 // Uses and Updates: CNS_fraction | |
| 2363 // Uses: acutal_ppO2 | |
| 2364 | |
| 2365 void deco_calc_CNS_fraction(void) | |
| 2366 { | |
| 2367 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; | |
| 2368 | |
| 2369 if (char_I_actual_ppO2 < 50) | |
| 2370 CNS_fraction = CNS_fraction;// no changes | |
| 2371 else if (char_I_actual_ppO2 < 60) | |
| 2372 CNS_fraction = 1/(-54000.0 * actual_ppO2 + 54000.0) + CNS_fraction; | |
| 2373 else if (char_I_actual_ppO2 < 70) | |
| 2374 CNS_fraction = 1/(-45000.0 * actual_ppO2 + 48600.0) + CNS_fraction; | |
| 2375 else if (char_I_actual_ppO2 < 80) | |
| 2376 CNS_fraction = 1/(-36000.0 * actual_ppO2 + 42300.0) + CNS_fraction; | |
| 2377 else if (char_I_actual_ppO2 < 90) | |
| 2378 CNS_fraction = 1/(-27000.0 * actual_ppO2 + 35100.0) + CNS_fraction; | |
| 2379 else if (char_I_actual_ppO2 < 110) | |
| 2380 CNS_fraction = 1/(-18000.0 * actual_ppO2 + 27000.0) + CNS_fraction; | |
| 2381 else if (char_I_actual_ppO2 < 150) | |
| 2382 CNS_fraction = 1/(-9000.0 * actual_ppO2 + 17100.0) + CNS_fraction; | |
| 2383 else if (char_I_actual_ppO2 < 160) | |
| 2384 CNS_fraction = 1/(-22500.0 * actual_ppO2 + 37350.0) + CNS_fraction; | |
| 2385 else if (char_I_actual_ppO2 < 165) | |
| 2386 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 | |
| 2387 else if (char_I_actual_ppO2 < 170) | |
| 2388 CNS_fraction = 0.00102 + CNS_fraction; // example calculation: Sqrt((1.7/1.55)^20)*0.000404 | |
| 2389 else if (char_I_actual_ppO2 < 175) | |
| 2390 CNS_fraction = 0.00136 + CNS_fraction; | |
| 2391 else if (char_I_actual_ppO2 < 180) | |
| 2392 CNS_fraction = 0.00180 + CNS_fraction; | |
| 2393 else if (char_I_actual_ppO2 < 185) | |
| 2394 CNS_fraction = 0.00237 + CNS_fraction; | |
| 2395 else if (char_I_actual_ppO2 < 190) | |
| 2396 CNS_fraction = 0.00310 + CNS_fraction; | |
| 2397 else if (char_I_actual_ppO2 < 195) | |
| 2398 CNS_fraction = 0.00401 + CNS_fraction; | |
| 2399 else if (char_I_actual_ppO2 < 200) | |
| 2400 CNS_fraction = 0.00517 + CNS_fraction; | |
| 2401 else if (char_I_actual_ppO2 < 230) | |
| 2402 CNS_fraction = 0.0209 + CNS_fraction; | |
| 2403 else | |
| 2404 CNS_fraction = 0.0482 + CNS_fraction; // value for 2.5 | |
| 2405 | |
| 2406 if (CNS_fraction > 2.5) | |
| 2407 CNS_fraction = 2.5; | |
| 2408 if (CNS_fraction < 0.0) | |
| 2409 CNS_fraction = 0.0; | |
| 2410 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); | |
| 2411 } // void deco_calc_CNS_fraction(void) | |
| 2412 | |
| 2413 // ------------------------------- | |
| 2414 // deco_calc_CNS_decrease_15min // | |
| 2415 // ------------------------------- | |
| 2416 // new in v.101 | |
| 2417 | |
| 2418 // calculates the half time of 90 minutes in 6 steps of 15 min | |
| 2419 | |
| 2420 // Output: char_O_CNS_fraction | |
| 2421 // Uses and Updates: CNS_fraction | |
| 2422 | |
| 2423 void deco_calc_CNS_decrease_15min(void) | |
| 2424 { | |
| 2425 CNS_fraction = 0.890899 * CNS_fraction; | |
| 2426 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); | |
| 2427 }// deco_calc_CNS_decrease_15min(void) | |
| 2428 | |
| 2429 | |
| 2430 // ----------------------- | |
| 2431 // deco_calc_percentage // | |
| 2432 // ----------------------- | |
| 2433 // new in v.101 | |
| 2434 | |
| 2435 // calculates int_I_temp * char_I_temp / 100 | |
| 2436 // output is int_I_temp | |
| 2437 | |
| 2438 void deco_calc_percentage(void) | |
| 2439 { | |
| 2440 temp1 = (float)int_I_temp; | |
| 2441 temp2 = (float)char_I_temp / 100.0; | |
| 2442 temp3 = temp1 * temp2; | |
| 2443 int_I_temp = (int)temp3; | |
| 2444 } | |
| 2445 | |
| 2446 void deco_push_tissues_to_vault(void) | |
| 2447 { | |
| 2448 cns_vault = CNS_fraction; | |
| 2449 for (ci=0;ci<32;ci++) | |
| 2450 pres_tissue_vault[ci] = pres_tissue[ci]; | |
| 2451 } | |
| 2452 void deco_pull_tissues_from_vault(void) | |
| 2453 { | |
| 2454 CNS_fraction = cns_vault; | |
| 2455 for (ci=0;ci<32;ci++) | |
| 2456 pres_tissue[ci] = pres_tissue_vault[ci]; | |
| 2457 } | |
| 2458 |
