comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 167:cb055a7d75f3

+ Use overlay local vars. + Make all private functions static. + Merge calc_tissue 2sec and 1min + Merge sim_tissue 1min and 10min + Expose basic display utilities for c-code. + Prepare stand-alone utilities for p2_main.c testing platform. + New c utility: int read_custom_function(cf#)
author JeanDo
date Mon, 24 Jan 2011 23:31:57 +0100
parents 8b5b848db4cd
children 494587193f5d
comparison
equal deleted inserted replaced
166:80de93d72a17 167:cb055a7d75f3
62 // 03/31/09 v107: integration of FONT Incon24 62 // 03/31/09 v107: integration of FONT Incon24
63 // 05/23/10 v109: 5 gas changes & 1 min timer 63 // 05/23/10 v109: 5 gas changes & 1 min timer
64 // 07/13/10 v110: cns vault added 64 // 07/13/10 v110: cns vault added
65 // 12/25/10 v110: split in three files (deco.c, main.c, definitions.h) 65 // 12/25/10 v110: split in three files (deco.c, main.c, definitions.h)
66 // 2011/01/20: [jDG] Create a common file included in ASM and C code. 66 // 2011/01/20: [jDG] Create a common file included in ASM and C code.
67 // 67 // 2011/01/23: [jDG] Added read_custom_function().
68 // 68 //
69 // literature: 69 // TODO:
70 // + Make char_O_ascenttime an int.
71 // + Fusion deco array for both models.
72 // + Allow (CF) revesring stop order (while copying).
73 // + Allow (CF) delay for gas switch while predicting ascent.
74 // + Allow to abort MD2 calculation (have to restart next time).
75 //
76 // Literature:
70 // B"uhlmann, Albert: Tauchmedizin; 4. Auflage; 77 // B"uhlmann, Albert: Tauchmedizin; 4. Auflage;
71 // 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 78 // 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
72 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html 79 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html
73 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf 80 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf
74 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops" 81 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops"
75 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf 82 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf
76 83 //
84 //
77 85
78 // ********************* 86 // *********************
79 // ** I N C L U D E S ** 87 // ** I N C L U D E S **
80 // ********************* 88 // *********************
81 #include <math.h> 89 #include <math.h>
82 90
83 #include "p2_definitions.h" 91 // *************************
92 // ** P R O T O T Y P E S **
93 // *************************
94
95 static void calc_hauptroutine(void);
96 static void calc_tissue_2_secs(void);
97 static void calc_tissue_1_min(void);
98 static void calc_nullzeit(void);
99 static void backup_sim_pres_tissue(void);
100 static void restore_sim_pres_tissue(void);
101
102 static void calc_without_deco(void);
103 static void clear_tissue(void);
104 static void calc_ascenttime(void);
105 static void update_startvalues(void);
106 static void clear_decoarray(void);
107 static void update_decoarray(void);
108 static void sim_tissue_1min(void);
109 static void sim_tissue_10min(void);
110 static void calc_gradient_factor(void);
111 static void calc_wo_deco_step_1_min(void);
112
113 static void calc_hauptroutine_data_input(void);
114 static void calc_hauptroutine_update_tissues(void);
115 static void calc_hauptroutine_calc_deco(void);
116 static void calc_hauptroutine_calc_ascend_to_deco(void);
117
118 static void calc_nextdecodepth_GF(void);
119 static void copy_deco_table_GF(void);
120 static void clear_internal_deco_table_GF(void);
121 static void update_internal_deco_table_GF(void);
84 122
85 // *********************************************** 123 // ***********************************************
86 // ** V A R I A B L E S D E F I N I T I O N S ** 124 // ** V A R I A B L E S D E F I N I T I O N S **
87 // *********************************************** 125 // ***********************************************
88 126
127 #include "p2_definitions.h"
89 #include "../OSTC_code_c_part2/shared_definitions.h" 128 #include "../OSTC_code_c_part2/shared_definitions.h"
90 129
91 //---- Bank 3 parameters ----------------------------------------------------- 130 //---- Bank 3 parameters -----------------------------------------------------
92 #pragma udata bank4=0x400 131 #pragma udata bank4=0x400
93 132
107 static unsigned char temp_decotime; 146 static unsigned char temp_decotime;
108 static unsigned char temp_gtissue_no; 147 static unsigned char temp_gtissue_no;
109 static unsigned int temp_depth_last_deco; // new in v.101 148 static unsigned int temp_depth_last_deco; // new in v.101
110 149
111 static unsigned char temp_depth_GF_low_meter; 150 static unsigned char temp_depth_GF_low_meter;
112 static unsigned char temp_depth_GF_low_number;
113 static unsigned char internal_deco_pointer; 151 static unsigned char internal_deco_pointer;
114 152
115 static unsigned char internal_deco_table[32]; // 0x2C8 153 static unsigned char internal_deco_table[32];
116 static float temp_pres_deco_GF_low;
117 154
118 static char output[32]; // used by the math routines 155 static char output[32]; // used by the math routines
119 156
120 static float cns_vault; 157 static float cns_vault;
121 158
122 static float pres_tissue_vault[32]; 159 static float pres_tissue_vault[32];
123 160
124 //---- Bank 5 parameters ----------------------------------------------------- 161 //---- Bank 5 parameters -----------------------------------------------------
125 #pragma udata bank5=0x500 162 #pragma udata bank5=0x500
126 163
127 static unsigned char ci ; // don't move - used in _asm routines - if moved then modify movlb commands 164 static unsigned char ci;
128 static unsigned char x;
129 static unsigned int main_i_dummy;
130 static unsigned int int_temp;
131 static unsigned int int_temp2;
132 static unsigned int int_temp_decostatus; 165 static unsigned int int_temp_decostatus;
133 static float pres_respiration; 166 static float pres_respiration;
134 static float pres_surface; 167 static float pres_surface;
135 static float temp1; 168 static float temp1;
136 static float temp2; 169 static float temp2;
141 static float temp2_atem; 174 static float temp2_atem;
142 static float temp_tissue; 175 static float temp_tissue;
143 static float temp_surface; 176 static float temp_surface;
144 static float N2_ratio; 177 static float N2_ratio;
145 static float He_ratio; 178 static float He_ratio;
146 static float temp_ratio;
147 static float var_N2_a; 179 static float var_N2_a;
148 static float var_N2_b; 180 static float var_N2_b;
149 static float var_He_a; 181 static float var_He_a;
150 static float var_He_b; 182 static float var_He_b;
151 static float var_N2_e; 183 static float var_N2_e;
152 static float var_He_e; 184 static float var_He_e;
153 static float var_N2_halftime; 185 static float var_N2_halftime;
154 static float var_He_halftime; 186 static float var_He_halftime;
155 static float pres_gtissue_limit; 187 static float pres_gtissue_limit;
156 static float temp_pres_gtissue_limit; 188 static float temp_pres_gtissue_limit;
157 static float actual_ppO2; // new in v.102
158 189
159 static float pres_diluent; // new in v.101 190 static float pres_diluent; // new in v.101
160 static float deco_diluent; // new in v.101 191 static float deco_diluent; // new in v.101
161 static float const_ppO2; // new in v.101 192 static float const_ppO2; // new in v.101
162 static float deco_ppO2_change; // new in v.101 193 static float deco_ppO2_change; // new in v.101
163 static float deco_ppO2; // new in v.101 194 static float deco_ppO2; // new in v.101
164 195
165 //---- Bank 6 parameters -----------------------------------------------------
166 #pragma udata bank6=0x600
167
168 static float pres_tissue[32];
169 static float pres_tissue_limit[16];
170 static float sim_pres_tissue_limit[16];
171
172 //---- Bank 7 parameters -----------------------------------------------------
173 #pragma udata bank7=0x700
174
175 static float sim_pres_tissue[32]; // 32 floats = 128 bytes.
176 static float sim_pres_tissue_backup[32];
177
178 //---- Bank 8 parameters -----------------------------------------------------
179 #pragma udata bank8=0x800
180
181 static char md_pi_subst[256];
182 #define C_STACK md_pi_subst // Overlay C-code data stack here, too.
183
184 //---- Bank 9 parameters -----------------------------------------------------
185 #pragma udata bank9a=0x900
186
187 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!!
188
189 static char md_t;
190 static char md_buffer[16];
191 static unsigned char md_i;
192 static char md_j;
193 static char md_temp;
194 static unsigned int md_pointer;
195 static float deco_N2_ratio; // new in v.101
196 static float deco_He_ratio; // new in v.101
197 static float calc_N2_ratio; // new in v.101 196 static float calc_N2_ratio; // new in v.101
198 static float calc_He_ratio; // new in v.101 197 static float calc_He_ratio; // new in v.101
199 static float deco_gas_change; // new in v.101
200 static float CNS_fraction; // new in v.101 198 static float CNS_fraction; // new in v.101
201 static float float_saturation_multiplier; // new in v.101 199 static float float_saturation_multiplier; // new in v.101
202 static float float_desaturation_multiplier; // new in v.101 200 static float float_desaturation_multiplier; // new in v.101
203 static float float_deco_distance; // new in v.101 201 static float float_deco_distance; // new in v.101
202 static char flag_in_divemode; // new in v.108
203
204 static float deco_gas_change1; // new in v.101
205 static float deco_gas_change2; // new in v.109
206 static float deco_gas_change3; // new in v.109
207 static float deco_gas_change4; // new in v.109
208 static float deco_gas_change5; // new in v.109
209
210 static float deco_N2_ratio1; // new in v.101
211 static float deco_He_ratio1; // new in v.101
212 static float deco_N2_ratio2; // new in v.109
213 static float deco_N2_ratio3; // new in v.109
214 static float deco_N2_ratio4; // new in v.109
215 static float deco_N2_ratio5; // new in v.109
216 static float deco_He_ratio2; // new in v.109
217 static float deco_He_ratio3; // new in v.109
218 static float deco_He_ratio4; // new in v.109
219 static float deco_He_ratio5; // new in v.109
220
221
222 //---- Bank 6 parameters -----------------------------------------------------
223 #pragma udata bank6=0x600
224
225 static float pres_tissue[32];
226 static float pres_tissue_limit[16];
227 static float sim_pres_tissue_limit[16];
228
229 //---- Bank 7 parameters -----------------------------------------------------
230 #pragma udata bank7=0x700
231
232 static float sim_pres_tissue[32]; // 32 floats = 128 bytes.
233 static float sim_pres_tissue_backup[32];
234
235 //---- Bank 8 parameters -----------------------------------------------------
236 #pragma udata bank8=0x800
237
238 static char md_pi_subst[256];
239 #define C_STACK md_pi_subst // Overlay C-code data stack here, too.
240
241 //---- Bank 9 parameters -----------------------------------------------------
242 #pragma udata bank9=0x900
243
244 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!!
204 245
205 // internal, dbg: 246 // internal, dbg:
206 static unsigned char DBG_char_I_deco_model; // new in v.108 247 static unsigned char DBG_char_I_deco_model; // new in v.108.
207 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 248 static unsigned char DBG_char_I_depth_last_deco; // new in v.108
208 static float DBG_pres_surface; // new in v.108 249 static float DBG_pres_surface; // new in v.108
209 static float DBG_GF_low; // new in v.108 250 static float DBG_GF_low; // new in v.108
210 static float DBG_GF_high; // new in v.108 251 static float DBG_GF_high; // new in v.108
211 static float DBG_const_ppO2; // new in v.108 252 static float DBG_const_ppO2; // new in v.108
219 static float DBG_float_deco_distance; // new in v.108 260 static float DBG_float_deco_distance; // new in v.108
220 static float DBG_deco_N2_ratio; // new in v.108 261 static float DBG_deco_N2_ratio; // new in v.108
221 static float DBG_deco_He_ratio; // new in v.108 262 static float DBG_deco_He_ratio; // new in v.108
222 static float DBG_N2_ratio; // new in v.108 263 static float DBG_N2_ratio; // new in v.108
223 static float DBG_He_ratio; // new in v.108 264 static float DBG_He_ratio; // new in v.108
224 static char flag_in_divemode; // new in v.108 265
225 static int int_dbg_i; // new in v.108 266 //////////////////////////////////////////////////////////////////////////////
226 static unsigned int temp_DBS; 267 //////////////////////////////////////////////////////////////////////////////
227 268 ///////////////////////////// THE LOOKUP TABLES //////////////////////////////
228 static float deco_gas_change2; // new in v.109 269 //////////////////////////////////////////////////////////////////////////////
229 static float deco_gas_change3; // new in v.109 270 //////////////////////////////////////////////////////////////////////////////
230 static float deco_gas_change4; // new in v.109 271 //
231 static float deco_gas_change5; // new in v.109 272 // End of PROM code is 17F00, So push tables on PROM top...
232 273 //
233 static float deco_N2_ratio2; // new in v.109 274 #pragma romdata buhlmann_tables = 0x017B00 // Needs to be in UPPER bank.
234 static float deco_N2_ratio3; // new in v.109 275 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_N2_a modified)
235 static float deco_N2_ratio4; // new in v.109 276
236 static float deco_N2_ratio5; // new in v.109 277 // Magic table to compute the MD2 HASH
237 static float deco_He_ratio2; // new in v.109 278 //
238 static float deco_He_ratio3; // new in v.109 279 #pragma romdata hash_tables = 0x017E00 // Address fixed by ASM access...
239 static float deco_He_ratio4; // new in v.109
240 static float deco_He_ratio5; // new in v.109
241
242 // ***********************
243 // ***********************
244 // ** THE LOOKUP TABLES **
245 // ***********************
246 // ***********************
247
248 #pragma romdata buhlmann_tables = 0x010200 // Needs to be in UPPER bank.
249 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_N2_a modified)
250
251 #pragma romdata hash_tables = 0x010600 // Address fixed by ASM access...
252 rom const rom unsigned int md_pi[] = 280 rom const rom unsigned int md_pi[] =
253 { 281 {
254 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613 282 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613
255 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA 283 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA
256 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512 284 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512
267 , 0x7888, 0x958B, 0xE363, 0xE86D, 0xE9CB, 0xD5FE, 0x3B00, 0x1D39 295 , 0x7888, 0x958B, 0xE363, 0xE86D, 0xE9CB, 0xD5FE, 0x3B00, 0x1D39
268 , 0xF2EF, 0xB70E, 0x6658, 0xD0E4, 0xA677, 0x72F8, 0xEB75, 0x4B0A 296 , 0xF2EF, 0xB70E, 0x6658, 0xD0E4, 0xA677, 0x72F8, 0xEB75, 0x4B0A
269 , 0x3144, 0x50B4, 0x8FED, 0x1F1A, 0xDB99, 0x8D33, 0x9F11, 0x8314 297 , 0x3144, 0x50B4, 0x8FED, 0x1F1A, 0xDB99, 0x8D33, 0x9F11, 0x8314
270 }; 298 };
271 299
272 // ********************* 300 //////////////////////////////////////////////////////////////////////////////
273 // ********************* 301 //////////////////////////////////////////////////////////////////////////////
274 // ** THE SUBROUTINES ** 302 ////////////////////////////// THE SUBROUTINES ///////////////////////////////
275 // ********************* 303 //////////////////////////////////////////////////////////////////////////////
276 // ********************* 304 //////////////////////////////////////////////////////////////////////////////
305 //
277 // all new in v.102 306 // all new in v.102
278 // moved from 0x0D000 to 0x0C000 in v.108 307 // moved from 0x0D000 to 0x0C000 in v.108
279 308
280 #pragma code p2_deco = 0x0C000 309 #pragma code p2_deco = 0x0C000
281 310
282 // ------------------------------- 311 //////////////////////////////////////////////////////////////////////////////
283 // DBS - debug on start of dive // 312 // DBS - debug on start of dive
284 // ------------------------------- 313 //
285 void create_dbs_set_dbg_and_ndl20mtr(void) 314 static void create_dbs_set_dbg_and_ndl20mtr(void)
286 { 315 {
316 overlay char i; // Local loop index.
317
318 //---- Reset DEBUG bit fields --------------------------------------------
287 int_O_DBS_bitfield = 0; 319 int_O_DBS_bitfield = 0;
288 int_O_DBS2_bitfield = 0; 320 int_O_DBS2_bitfield = 0;
289 if(int_O_DBG_pre_bitfield & DBG_RUN) 321 if(int_O_DBG_pre_bitfield & DBG_RUN)
290 int_O_DBG_pre_bitfield = DBG_RESTART; 322 int_O_DBG_pre_bitfield = DBG_RESTART;
291 else 323 else
292 int_O_DBG_pre_bitfield = DBG_RUN; 324 int_O_DBG_pre_bitfield = DBG_RUN;
293 int_O_DBG_post_bitfield = 0; 325 int_O_DBG_post_bitfield = 0;
326
327 //---- Set 20meters ND limit ---------------------------------------------
294 char_O_NDL_at_20mtr = 255; 328 char_O_NDL_at_20mtr = 255;
295 329
330 //---- Copy all dive parameters ------------------------------------------
296 DBG_N2_ratio = N2_ratio; 331 DBG_N2_ratio = N2_ratio;
297 DBG_He_ratio = He_ratio; 332 DBG_He_ratio = He_ratio;
298 DBG_char_I_deco_model = char_I_deco_model; 333 DBG_char_I_deco_model = char_I_deco_model;
299 DBG_char_I_depth_last_deco = char_I_depth_last_deco; 334 DBG_char_I_depth_last_deco = char_I_depth_last_deco;
300 DBG_pres_surface = pres_surface; 335 DBG_pres_surface = pres_surface;
301 DBG_GF_low = GF_low; 336 DBG_GF_low = GF_low;
302 DBG_GF_high = GF_high; 337 DBG_GF_high = GF_high;
303 DBG_const_ppO2 = const_ppO2; 338 DBG_const_ppO2 = const_ppO2;
304 DBG_deco_ppO2_change = deco_ppO2_change; 339 DBG_deco_ppO2_change = deco_ppO2_change;
305 DBG_deco_ppO2 = deco_ppO2; 340 DBG_deco_ppO2 = deco_ppO2;
306 DBG_deco_N2_ratio = deco_N2_ratio; 341 DBG_deco_N2_ratio = deco_N2_ratio1;
307 DBG_deco_He_ratio = deco_He_ratio; 342 DBG_deco_He_ratio = deco_He_ratio1;
308 DBG_deco_gas_change = deco_gas_change; 343 DBG_deco_gas_change = deco_gas_change1;
309 DBG_float_saturation_multiplier = float_saturation_multiplier; 344 DBG_float_saturation_multiplier = float_saturation_multiplier;
310 DBG_float_desaturation_multiplier = float_desaturation_multiplier; 345 DBG_float_desaturation_multiplier = float_desaturation_multiplier;
311 DBG_float_deco_distance = float_deco_distance; 346 DBG_float_deco_distance = float_deco_distance;
312 347
348 //---- Setup some error (?) conditions -----------------------------------
313 if(char_I_deco_model) 349 if(char_I_deco_model)
314 int_O_DBS_bitfield |= DBS_mode; 350 int_O_DBS_bitfield |= DBS_mode;
315 if(const_ppO2) 351 if(const_ppO2)
316 int_O_DBS_bitfield |= DBS_ppO2; 352 int_O_DBS_bitfield |= DBS_ppO2;
317 for(int_dbg_i = 16; int_dbg_i < 32; int_dbg_i++) 353 for(i = 16; i < 32; i++)
318 if(pres_tissue[int_dbg_i]) 354 if(pres_tissue[i])
319 int_O_DBS_bitfield |= DBS_HE_sat; 355 int_O_DBS_bitfield |= DBS_HE_sat;
320 if(deco_ppO2_change) 356 if(deco_ppO2_change)
321 int_O_DBS_bitfield |= DBS_ppO2chg; 357 int_O_DBS_bitfield |= DBS_ppO2chg;
322 if(float_saturation_multiplier < 0.99) 358 if(float_saturation_multiplier < 0.99)
323 int_O_DBS_bitfield |= DBS_SAT2l; 359 int_O_DBS_bitfield |= DBS_SAT2l;
337 int_O_DBS_bitfield |= DBS_GASO22h; 373 int_O_DBS_bitfield |= DBS_GASO22h;
338 if(float_deco_distance > 0.25) 374 if(float_deco_distance > 0.25)
339 int_O_DBS_bitfield |= DBS_DIST2h; 375 int_O_DBS_bitfield |= DBS_DIST2h;
340 if(char_I_depth_last_deco > 8) 376 if(char_I_depth_last_deco > 8)
341 int_O_DBS_bitfield |= DBS_LAST2h; 377 int_O_DBS_bitfield |= DBS_LAST2h;
342 if(DBG_deco_gas_change && ((deco_N2_ratio + deco_He_ratio) > 0.95)) 378 if(DBG_deco_gas_change && ((deco_N2_ratio1 + deco_He_ratio1) > 0.95))
343 int_O_DBS_bitfield |= DBS_DECOO2l; 379 int_O_DBS_bitfield |= DBS_DECOO2l;
344 if(DBG_deco_gas_change && ((deco_N2_ratio + deco_He_ratio) < 0.05)) 380 if(DBG_deco_gas_change && ((deco_N2_ratio1 + deco_He_ratio1) < 0.05))
345 int_O_DBS_bitfield |= DBS_DECOO2h; 381 int_O_DBS_bitfield |= DBS_DECOO2h;
346 if(pres_respiration > 3.0) 382 if(pres_respiration > 3.0)
347 int_O_DBS2_bitfield |= DBS2_PRES2h; 383 int_O_DBS2_bitfield |= DBS2_PRES2h;
348 if(pres_surface - pres_respiration > 0.2) 384 if(pres_surface - pres_respiration > 0.2)
349 int_O_DBS2_bitfield |= DBS2_PRES2l; 385 int_O_DBS2_bitfield |= DBS2_PRES2l;
357 int_O_DBS2_bitfield |= DBS2_DESAT2h; 393 int_O_DBS2_bitfield |= DBS2_DESAT2h;
358 if(GF_low > GF_high) 394 if(GF_low > GF_high)
359 int_O_DBS2_bitfield |= DBS2_GFDneg; 395 int_O_DBS2_bitfield |= DBS2_GFDneg;
360 } 396 }
361 397
362 // ------------------------------- 398 //////////////////////////////////////////////////////////////////////////////
363 // DBG - set DBG to end_of_dive // 399 // DBG - set DBG to end_of_dive
364 // ------------------------------- 400 //
365 void set_dbg_end_of_dive(void) 401 static void set_dbg_end_of_dive(void)
366 { 402 {
367 int_O_DBG_pre_bitfield &= (~DBG_RUN); 403 int_O_DBG_pre_bitfield &= (~DBG_RUN);
368 int_O_DBG_post_bitfield &= (~DBG_RUN); 404 int_O_DBG_post_bitfield &= (~DBG_RUN);
369 } 405 }
370 406
371 // ------------------------------- 407 //////////////////////////////////////////////////////////////////////////////
372 // DBG - NDL at first 20 m. hit // 408 // DBG - NDL at first 20 m. hit
373 // ------------------------------- 409 //
374 void check_ndl(void) 410 static void check_ndl(void)
375 { 411 {
376 if((char_O_NDL_at_20mtr == -1) && (int_I_pres_respiration > 3000)) 412 if( char_O_NDL_at_20mtr == 255 // Still in NDL mode ?
413 && int_I_pres_respiration > 3000 // And we hit the 20m limit ?
414 )
377 { 415 {
378 char_O_NDL_at_20mtr = char_O_nullzeit; 416 char_O_NDL_at_20mtr = char_O_nullzeit; // change to max bottom time.
379 if(char_O_NDL_at_20mtr == 255) 417 if( char_O_NDL_at_20mtr == 255) // and avoid confusion.
380 char_O_NDL_at_20mtr == 254; 418 char_O_NDL_at_20mtr == 254;
381 } 419 }
382 } 420 }
383 421
384 // ------------------------------- 422 //////////////////////////////////////////////////////////////////////////////
385 // DBG - multi main during dive // 423 // DBG - multi main during dive
386 // ------------------------------- 424 //
387 void check_dbg(static char is_post_check) 425 static void check_dbg(static char is_post_check)
388 { 426 {
389 temp_DBS = 0; 427 overlay unsigned int temp_DBS = 0;
428 overlay char i; // Local loop index.
429
390 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) 430 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) )
391 temp_DBS |= DBG_c_gas; 431 temp_DBS |= DBG_c_gas;
392 if(DBG_const_ppO2 != const_ppO2) 432 if(DBG_const_ppO2 != const_ppO2)
393 temp_DBS |= DBG_c_ppO2; 433 temp_DBS |= DBG_c_ppO2;
394 if((DBG_float_saturation_multiplier != float_saturation_multiplier) || (DBG_float_desaturation_multiplier != float_desaturation_multiplier)) 434 if( DBG_float_saturation_multiplier != float_saturation_multiplier
435 || DBG_float_desaturation_multiplier != float_desaturation_multiplier
436 )
395 temp_DBS |= DBG_CdeSAT; 437 temp_DBS |= DBG_CdeSAT;
396 if(DBG_char_I_deco_model != char_I_deco_model) 438 if(DBG_char_I_deco_model != char_I_deco_model)
397 temp_DBS |= DBG_C_MODE; 439 temp_DBS |= DBG_C_MODE;
398 if(DBG_pres_surface != pres_surface) 440 if(DBG_pres_surface != pres_surface)
399 temp_DBS |= DBG_C_SURF; 441 temp_DBS |= DBG_C_SURF;
400 if((!DBS_HE_sat) && (!He_ratio)) 442
401 for(int_dbg_i = 16; int_dbg_i < 32; int_dbg_i++) 443 if( !DBS_HE_sat && !He_ratio)
402 if(pres_tissue[int_dbg_i]) 444 for(i = 16; i < 32; i++)
445 if(pres_tissue[i])
403 temp_DBS |= DBG_HEwoHE; 446 temp_DBS |= DBG_HEwoHE;
447
404 if(DBG_deco_ppO2 != deco_ppO2) 448 if(DBG_deco_ppO2 != deco_ppO2)
405 temp_DBS |= DBG_C_DPPO2; 449 temp_DBS |= DBG_C_DPPO2;
406 if((DBG_deco_gas_change != deco_gas_change) || (DBG_deco_N2_ratio != deco_N2_ratio) || (DBG_deco_He_ratio != deco_He_ratio)) 450
451 if( DBG_deco_gas_change != deco_gas_change1
452 || DBG_deco_N2_ratio != deco_N2_ratio1
453 || DBG_deco_He_ratio != deco_He_ratio1 )
407 temp_DBS |= DBG_C_DGAS; 454 temp_DBS |= DBG_C_DGAS;
455
408 if(DBG_float_deco_distance != float_deco_distance) 456 if(DBG_float_deco_distance != float_deco_distance)
409 temp_DBS |= DBG_C_DIST; 457 temp_DBS |= DBG_C_DIST;
410 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco) 458 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco)
411 temp_DBS |= DBG_C_LAST; 459 temp_DBS |= DBG_C_LAST;
412 if((DBG_GF_low != GF_low) || (DBG_GF_high != GF_high)) 460 if( DBG_GF_low != GF_low
461 || DBG_GF_high != GF_high )
413 temp_DBS |= DBG_C_GF; 462 temp_DBS |= DBG_C_GF;
414 if(pres_respiration > 13.0) 463 if(pres_respiration > 13.0)
415 temp_DBS |= DBG_PHIGH; 464 temp_DBS |= DBG_PHIGH;
416 if(pres_surface - pres_respiration > 0.2) 465 if(pres_surface - pres_respiration > 0.2)
417 temp_DBS |= DBG_PLOW; 466 temp_DBS |= DBG_PLOW;
419 int_O_DBG_post_bitfield |= temp_DBS; 468 int_O_DBG_post_bitfield |= temp_DBS;
420 else 469 else
421 int_O_DBG_pre_bitfield |= temp_DBS; 470 int_O_DBG_pre_bitfield |= temp_DBS;
422 } 471 }
423 472
424 // ------------------------------- 473 //////////////////////////////////////////////////////////////////////////////
425 // DBG - prior to calc. of dive // 474 // DBG - prior to calc. of dive
426 // ------------------------------- 475 //
427 void check_pre_dbg(void) 476 static void check_pre_dbg(void)
428 { 477 {
429 check_dbg(0); 478 check_dbg(0);
430 } 479 }
431 480
432 // ------------------------------- 481 //////////////////////////////////////////////////////////////////////////////
433 // DBG - after decocalc of dive // 482 // DBG - after decocalc of dive
434 // ------------------------------- 483 //
435 void check_post_dbg(void) 484 static void check_post_dbg(void)
436 { 485 {
437 check_dbg(1); 486 check_dbg(1);
438 } 487 }
439 488
440 ////////////////////////////////////////////////////////////////////////////// 489 //////////////////////////////////////////////////////////////////////////////
490 //////////////////////////////////////////////////////////////////////////////
491 /////////////////////// U T I L I T I E S /////////////////////////////////
492 //////////////////////////////////////////////////////////////////////////////
493 //////////////////////////////////////////////////////////////////////////////
494
495 static int read_custom_function(static unsigned char cf)
496 {
497 extern unsigned char hi, lo;
498 extern void getcustom15();
499 _asm
500 movff cf,WREG
501 call getcustom15,0
502 movff lo,PRODL
503 movff hi,PRODH
504 _endasm
505 }
506
507 //////////////////////////////////////////////////////////////////////////////
441 // read buhlmann tables for compatriment ci 508 // read buhlmann tables for compatriment ci
442 // If mode == 0 : 2sec interval 509 // If period == 0 : 2sec interval
443 // 1 : 1 min interval 510 // 1 : 1 min interval
444 // 2 : 10 min interval. 511 // 2 : 10 min interval.
445 // TODO: an assembleur version of the table reads... 512 static void read_buhlmann_coeffifients(static char period)
446 static void read_buhlmann_compartment(static char mode) 513 {
447 { 514 // Note: we don't use far rom pointer, because the
515 // 24 bits is to complex, hence we have to set
516 // the UPPER page ourself...
517 // --> Set zero if tables are moved to lower pages !
518 _asm
519 movlw 1
520 movwf TBLPTRU,0
521 _endasm
522
448 var_N2_a = buhlmann_a[ci]; 523 var_N2_a = buhlmann_a[ci];
449 var_N2_b = buhlmann_b[ci]; 524 var_N2_b = buhlmann_b[ci];
450 var_He_a = buhlmann_a[ci + 16]; 525 var_He_a = (buhlmann_a+16)[ci];
451 var_He_b = buhlmann_b[ci + 16]; 526 var_He_b = (buhlmann_b+16)[ci];
527
452 // Check reading consistency: 528 // Check reading consistency:
453 if( (var_N2_a < 0.231) 529 if( (var_N2_a < 0.231)
454 || (var_N2_a > 1.27) 530 || (var_N2_a > 1.27)
455 || (var_N2_b < 0.504) 531 || (var_N2_b < 0.504)
456 || (var_N2_b > 0.966) 532 || (var_N2_b > 0.966)
458 || (var_He_a > 1.75) 534 || (var_He_a > 1.75)
459 || (var_He_b < 0.423) 535 || (var_He_b < 0.423)
460 || (var_He_b > 0.927) 536 || (var_He_b > 0.927)
461 ) 537 )
462 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; 538 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
463 539
464 // Integration intervals. 540 // Integration intervals.
465 switch(mode) 541 switch(period)
466 { 542 {
543 case -1://---- no interval -----------------------------------------------
544 var_N2_e = var_He_e = 0.0;
545 break;
546
467 case 0: //---- 2 sec ----------------------------------------------------- 547 case 0: //---- 2 sec -----------------------------------------------------
468 var_N2_e = e2secs[ci]; 548 var_N2_e = e2secs[ci];
469 var_He_e = e2secs[ci + 16]; 549 var_He_e = (e2secs+16)[ci];
470 550
471 // Check reading consistency: 551 // Check reading consistency:
472 if( (var_N2_e < 0.0000363) 552 if( (var_N2_e < 0.0000363)
473 || (var_N2_e > 0.00577) 553 || (var_N2_e > 0.00577)
474 || (var_He_e < 0.0000961) 554 || (var_He_e < 0.0000961)
478 558
479 break; 559 break;
480 560
481 case 1: //---- 1 min ----------------------------------------------------- 561 case 1: //---- 1 min -----------------------------------------------------
482 var_N2_e = e1min[ci]; 562 var_N2_e = e1min[ci];
483 var_He_e = e1min[ci + 16]; 563 var_He_e = (e1min+16)[ci];
484 564
485 // Check reading consistency: 565 // Check reading consistency:
486 if( (var_N2_e < 1.09E-3) 566 if( (var_N2_e < 1.09E-3)
487 || (var_N2_e > 0.1592) 567 || (var_N2_e > 0.1592)
488 || (var_He_e < 0.00288) 568 || (var_He_e < 0.00288)
492 572
493 break; 573 break;
494 574
495 case 2: //---- 10 min ---------------------------------------------------- 575 case 2: //---- 10 min ----------------------------------------------------
496 var_N2_e = e10min[ci]; 576 var_N2_e = e10min[ci];
497 var_He_e = e10min[ci + 16]; 577 var_He_e = (e10min+16)[ci];
498 578
499 // Check reading consistency: 579 // Check reading consistency:
500 if( (var_N2_e < 0.01085) 580 if( (var_N2_e < 0.01085)
501 || (var_N2_e > 0.82323) 581 || (var_N2_e > 0.82323)
502 || (var_He_e < 0.02846) 582 || (var_He_e < 0.02846)
507 break; 587 break;
508 } 588 }
509 } 589 }
510 590
511 ////////////////////////////////////////////////////////////////////////////// 591 //////////////////////////////////////////////////////////////////////////////
512 // calc_next_decodepth_GF // 592 // calc_next_decodepth_GF
513 // 593 //
514 // new in v.102 594 // new in v.102
515 // 595 //
516 void calc_nextdecodepth_GF(void)
517 {
518 // INPUT, changing during dive: 596 // INPUT, changing during dive:
519 // temp_pres_gtissue_limit_GF_low 597 // temp_pres_gtissue_limit_GF_low
520 // temp_pres_gtissue_limit_GF_low_below_surface 598 // temp_pres_gtissue_limit_GF_low_below_surface
521 // temp_pres_gtissue 599 // temp_pres_gtissue
522 // temp_pres_gtissue_diff 600 // temp_pres_gtissue_diff
523 // lock_GF_depth_list 601 // lock_GF_depth_list
524 602 //
525 // INPUT, fixed during dive: 603 // INPUT, fixed during dive:
526 // pres_surface 604 // pres_surface
527 // GF_delta 605 // GF_delta
528 // GF_high 606 // GF_high
529 // GF_low 607 // GF_low
530 // temp_depth_last_deco 608 // temp_depth_last_deco
531 // float_deco_distance 609 // float_deco_distance
532 610 //
533 // OUTPUT 611 // OUTPUT
534 // GF_step 612 // GF_step
535 // temp_deco 613 // temp_deco
536 // temp_depth_limt 614 // temp_depth_limt
537 // lock_GF_depth_list 615 // lock_GF_depth_list
538 616 //
539 // USES 617 static void calc_nextdecodepth_GF(void)
540 // temp1 618 {
541 // temp2
542 // int_temp
543 619
544 char_I_table_deco_done[0] = 0; // safety if changed somewhere else. Needed for exit 620 char_I_table_deco_done[0] = 0; // safety if changed somewhere else. Needed for exit
621
622 //---- ZH-L16 + Gradient factor model ------------------------------------
545 if (char_I_deco_model == 1) 623 if (char_I_deco_model == 1)
546 { 624 {
625 overlay float next_stop; // Next stop to test, in Bar.
626 overlay float press_tol; // Upper limit (lower pressure) tolerated.
627 overlay int int_temp;
628 overlay unsigned char temp_depth_GF_low_number;
629 overlay float temp_pres_deco_GF_low;
630
547 if (lock_GF_depth_list == 0) 631 if (lock_GF_depth_list == 0)
548 { 632 {
549 temp2 = temp_pres_gtissue_limit_GF_low_below_surface / 0.29985; // = ... / 99.95 / 0.003; 633 next_stop = temp_pres_gtissue_limit_GF_low_below_surface / 0.29985; // = ... / 99.95 / 0.003;
550 int_temp = (int) (temp2 + 0.99); 634 int_temp = (int) (next_stop + 0.99);
551 if (int_temp > 31) 635 if (int_temp > 31)
552 int_temp = 31; // deepest deco at 93 meter (31 deco stops) 636 int_temp = 31; // deepest deco at 93 meter (31 deco stops)
553 if (int_temp < 0) 637 if (int_temp < 0)
554 int_temp = 0; 638 int_temp = 0;
555 temp_depth_GF_low_number = int_temp; 639 temp_depth_GF_low_number = int_temp;
556 temp_depth_GF_low_meter = 3 * temp_depth_GF_low_number; 640 temp_depth_GF_low_meter = 3 * temp_depth_GF_low_number;
557 temp2 = (float)temp_depth_GF_low_meter * 0.09995; 641 next_stop = (float)temp_depth_GF_low_meter * 0.09995;
558 temp_pres_deco_GF_low = temp2 + float_deco_distance + pres_surface; 642 temp_pres_deco_GF_low = next_stop + float_deco_distance + pres_surface;
559 if (temp_depth_GF_low_number == 0) 643 if (temp_depth_GF_low_number == 0)
560 GF_step = 0; 644 GF_step = 0;
561 else 645 else
562 GF_step = GF_delta / (float)temp_depth_GF_low_number; 646 GF_step = GF_delta / (float)temp_depth_GF_low_number;
563 if (GF_step < 0) 647 if (GF_step < 0)
586 while (int_temp == 1) 670 while (int_temp == 1)
587 { 671 {
588 int_temp = internal_deco_pointer - 1; 672 int_temp = internal_deco_pointer - 1;
589 if (int_temp == 1) // new in v104 673 if (int_temp == 1) // new in v104
590 { 674 {
591 temp2 = (float)(temp_depth_last_deco * int_temp) * 0.09995; 675 next_stop = (float)(temp_depth_last_deco * int_temp) * 0.09995;
592 GF_step2 = GF_step/3.0 * ((float)(6 - temp_depth_last_deco)); 676 GF_step2 = GF_step/3.0 * ((float)(6 - temp_depth_last_deco));
593 } 677 }
594 else 678 else
595 if (int_temp == 0) 679 if (int_temp == 0)
596 { 680 {
597 temp2 = 0.0; 681 next_stop = 0.0;
598 GF_step2 = GF_high - GF_temp; 682 GF_step2 = GF_high - GF_temp;
599 } 683 }
600 else 684 else
601 { 685 {
602 temp2 = (float)(3 *int_temp) * 0.09995; 686 next_stop = (float)(3 *int_temp) * 0.09995;
603 GF_step2 = GF_step; 687 GF_step2 = GF_step;
604 } 688 }
605 temp2 = temp2 + pres_surface; // next deco stop to be tested 689 next_stop = next_stop + pres_surface; // next deco stop to be tested
606 temp1 = ((GF_temp + GF_step2)* temp_pres_gtissue_diff) + temp_pres_gtissue; // upper limit (lowest pressure allowed) // changes GF_step2 in v104 690 press_tol = ((GF_temp + GF_step2)* temp_pres_gtissue_diff) + temp_pres_gtissue; // upper limit (lowest pressure allowed) // changes GF_step2 in v104
607 if (temp1 > temp2) // check if ascent to next deco stop is ok 691 if (press_tol > next_stop) // check if ascent to next deco stop is ok
608 { 692 {
609 int_temp = 0; // no 693 int_temp = 0; // no
610 } 694 }
611 else 695 else
612 { 696 {
613 internal_deco_pointer = int_temp; 697 internal_deco_pointer = int_temp;
614 GF_temp = GF_temp + GF_step2; // changed in v104 698 GF_temp = GF_temp + GF_step2; // changed in v104
615 int_temp = char_I_table_deco_done[internal_deco_pointer]; // yes and check for ascent to even next stop if deco_done is set 699 int_temp = char_I_table_deco_done[internal_deco_pointer]; // yes and check for ascent to even next stop if deco_done is set
616 } 700 }
617 } // while 701 } // while
702
618 if (internal_deco_pointer > 0) 703 if (internal_deco_pointer > 0)
619 { 704 {
620 temp2 = (float)(0.29985 * internal_deco_pointer); 705 next_stop = 0.29985 * internal_deco_pointer;
621 temp_deco = temp2 + float_deco_distance + pres_surface; 706 temp_deco = next_stop + float_deco_distance + pres_surface;
622 if (internal_deco_pointer == 1) // new in v104 707 if (internal_deco_pointer == 1) // new in v104
623 temp_depth_limit = temp_depth_last_deco; 708 temp_depth_limit = temp_depth_last_deco;
624 else 709 else
625 temp_depth_limit = 3 * internal_deco_pointer; 710 temp_depth_limit = 3 * internal_deco_pointer;
626 if (output[9] == 33) 711 if (output[9] == 33)
636 { 721 {
637 temp_deco = pres_surface; 722 temp_deco = pres_surface;
638 temp_depth_limit = 0; 723 temp_depth_limit = 0;
639 } 724 }
640 } 725 }
641 else 726 else //---- ZH-L16 model -------------------------------------------------
642 { 727 {
643 // calc_nextdecodepth - original 728 // calc_nextdecodepth - original
644 // optimized in v.101 729 // optimized in v.101
645 // depth_last_deco included in v.101 730 // depth_last_deco included in v.101
646 731
647 temp1 = temp_pres_gtissue_limit - pres_surface; 732 overlay float pres_gradient = temp_pres_gtissue_limit - pres_surface;
648 if (temp1 >= 0) 733 if (pres_gradient >= 0)
649 { 734 {
650 temp1 = temp1 / 0.29985; // = temp1 / 99.95 / 0.003; 735 pres_gradient = pres_gradient / 0.29985; // = pres_gradient / 99.95 / 0.003;
651 temp_depth_limit = (int) (temp1 + 0.99); 736 temp_depth_limit = (int) (pres_gradient + 0.99);
652 temp_depth_limit = 3 * temp_depth_limit; // depth for deco [m] 737 temp_depth_limit = 3 * temp_depth_limit; // depth for deco [m]
653 if (temp_depth_limit == 0) 738 if (temp_depth_limit == 0)
654 temp_deco = pres_surface; 739 temp_deco = pres_surface;
655 else 740 else
656 { 741 {
657 if (temp_depth_limit < temp_depth_last_deco) 742 if (temp_depth_limit < temp_depth_last_deco)
658 temp_depth_limit = temp_depth_last_deco; 743 temp_depth_limit = temp_depth_last_deco;
659 temp1 = (float)temp_depth_limit * 0.09995; 744 pres_gradient = (float)temp_depth_limit * 0.09995;
660 temp_deco = temp1 + float_deco_distance + pres_surface; // depth for deco [bar] 745 temp_deco = pres_gradient + float_deco_distance + pres_surface; // depth for deco [bar]
661 } // if (temp_depth_limit == 0) 746 } // if (temp_depth_limit == 0)
662 } // if (temp1 >= 0) 747 } // if (pres_gradient >= 0)
663 else 748 else
664 { 749 {
665 temp_deco = pres_surface; 750 temp_deco = pres_surface;
666 temp_depth_limit = 0; 751 temp_depth_limit = 0;
667 } // if (temp1 >= 0) 752 } // if (pres_gradient >= 0)
668 } // calc_nextdecodepth original 753 } // calc_nextdecodepth original
669 } // calc_nextdecodepth_GF 754 }
670 755
671 756 //////////////////////////////////////////////////////////////////////////////
672 // --------------------- 757 // copy_deco_table_GF
673 // copy_deco_table_GF // 758 //
674 // ---------------------
675 // new in v.102 759 // new in v.102
676 void copy_deco_table_GF(void) 760 //
761 static void copy_deco_table_GF(void)
762 {
763 overlay unsigned char x;
764
765 if( char_I_deco_model == 1 )
766 {
767 for(x=0; x<32; x++)
768 char_O_deco_table[x] = internal_deco_table[x];
769 }
770 }
771
772 //////////////////////////////////////////////////////////////////////////////
773 // clear_internal_deco_table_GF
774 //
775 // new in v.102
776 //
777 static void clear_internal_deco_table_GF(void)
677 { 778 {
678 if (char_I_deco_model == 1) 779 if (char_I_deco_model == 1)
679 { 780 {
680 for (ci=0;ci<32;ci++) 781 overlay unsigned char x;
681 char_O_deco_table[ci] = internal_deco_table[ci]; 782
783 for(x=0;x<32;x++) // cycle through the 16 tissues for N2 and He
784 internal_deco_table[x] = 0;
682 } 785 }
683 } // copy_deco_table_GF 786 }
684 787
685 788 //////////////////////////////////////////////////////////////////////////////
686 // ------------------------------ 789 // update_internal_deco_table_GF
687 // clear_internal_deco_table_GF// 790 //
688 // ------------------------------
689 // new in v.102 791 // new in v.102
690 void clear_internal_deco_table_GF(void) 792 //
691 { 793 // Add one minute to the current stop (if lower than 255).
692 if (char_I_deco_model == 1) 794 //
693 { 795 static void update_internal_deco_table_GF(void)
694 for (ci=0;ci<32;ci++) // cycle through the 16 b"uhlmann tissues for Helium
695 {
696 internal_deco_table[ci] = 0;
697 }
698 }
699 } // clear_internal_deco_table_GF
700
701
702 // --------------------------------
703 // update_internal_deco_table_GF //
704 // --------------------------------
705 // new in v.102
706 void update_internal_deco_table_GF(void)
707 { 796 {
708 if ((char_I_deco_model == 1) && (internal_deco_table[internal_deco_pointer] < 255)) 797 if ((char_I_deco_model == 1) && (internal_deco_table[internal_deco_pointer] < 255))
709 internal_deco_table[internal_deco_pointer] = internal_deco_table[internal_deco_pointer] + 1; 798 internal_deco_table[internal_deco_pointer]++;
710 } // update_internal_deco_table_GF 799 }
711 800
712 801 //////////////////////////////////////////////////////////////////////////////
713 // ---------------------
714 // temp_tissue_safety // 802 // temp_tissue_safety //
715 // --------------------- 803 //
716 // outsourced in v.102 804 // outsourced in v.102
717 void temp_tissue_safety(void) 805 //
718 { 806 // Apply safety factors for brand ZH-L16 model.
719 if (char_I_deco_model != 1) 807 //
808 static void temp_tissue_safety(void)
809 {
810 if( char_I_deco_model == 0 )
720 { 811 {
721 if (temp_tissue < 0.0) 812 if (temp_tissue < 0.0)
722 temp_tissue *= float_desaturation_multiplier; 813 temp_tissue *= float_desaturation_multiplier;
723 else 814 else
724 temp_tissue *= float_saturation_multiplier; 815 temp_tissue *= float_saturation_multiplier;
725 } 816 }
726 } // temp_tissue_safety 817 }
727 818
728 // ********************** 819 //////////////////////////////////////////////////////////////////////////////
729 // ********************** 820 //////////////////////////////////////////////////////////////////////////////
730 // ** THE JUMP-IN CODE ** 821 // ** THE JUMP-IN CODE **
731 // ** for the asm code ** 822 // ** for the asm code **
732 // ********************** 823 //////////////////////////////////////////////////////////////////////////////
733 // ********************** 824 //////////////////////////////////////////////////////////////////////////////
734 825
735 void fillDataStack(void) 826 void fillDataStack(void)
736 { 827 {
737 _asm 828 _asm
738 LFSR 1,C_STACK 829 LFSR 1,C_STACK
741 TSTFSZ FSR1L,0 832 TSTFSZ FSR1L,0
742 BRA loop 833 BRA loop
743 834
744 LFSR 1,C_STACK 835 LFSR 1,C_STACK
745 LFSR 2,C_STACK 836 LFSR 2,C_STACK
746 MOVLW 1
747 MOVWF TBLPTRU,0
748 _endasm 837 _endasm
749 } 838 }
750 839
840 //////////////////////////////////////////////////////////////////////////////
751 // When calling C code from ASM context, the data stack pointer and 841 // When calling C code from ASM context, the data stack pointer and
752 // frames should be reset. Bank3 is dedicated to the stack (see the 842 // frames should be reset. Bank3 is dedicated to the stack (see the
753 // .lkr script). 843 // .lkr script).
754 #ifdef __DEBUG 844 #ifdef __DEBUG
755 # define RESET_C_STACK fillDataStack(); 845 # define RESET_C_STACK fillDataStack();
756 #else 846 #else
757 # define RESET_C_STACK \ 847 # define RESET_C_STACK \
758 _asm \ 848 _asm \
759 LFSR 1, C_STACK \ 849 LFSR 1, C_STACK \
760 LFSR 2, C_STACK \ 850 LFSR 2, C_STACK \
761 MOVLW 1 \
762 MOVWF TBLPTRU,0 \
763 _endasm 851 _endasm
764 #endif 852 #endif
853
854 //////////////////////////////////////////////////////////////////////////////
765 855
766 void deco_calc_hauptroutine(void) 856 void deco_calc_hauptroutine(void)
767 { 857 {
768 RESET_C_STACK 858 RESET_C_STACK
769 calc_hauptroutine(); 859 calc_hauptroutine();
770 int_O_desaturation_time = 65535; 860 int_O_desaturation_time = 65535;
771 } 861 }
772 862
863 //////////////////////////////////////////////////////////////////////////////
864
773 void deco_calc_without_deco(void) 865 void deco_calc_without_deco(void)
774 { 866 {
775 RESET_C_STACK 867 RESET_C_STACK
776 calc_without_deco(); 868 calc_without_deco();
777 deco_calc_desaturation_time(); 869 deco_calc_desaturation_time();
778 } 870 }
779 871
872 //////////////////////////////////////////////////////////////////////////////
873
780 void deco_clear_tissue(void) 874 void deco_clear_tissue(void)
781 { 875 {
782 RESET_C_STACK 876 RESET_C_STACK
783 clear_tissue(); 877 clear_tissue();
784 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco 878 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco
785 } 879 }
880
881 //////////////////////////////////////////////////////////////////////////////
786 882
787 void deco_calc_wo_deco_step_1_min(void) 883 void deco_calc_wo_deco_step_1_min(void)
788 { 884 {
789 RESET_C_STACK 885 RESET_C_STACK
790 calc_wo_deco_step_1_min(); 886 calc_wo_deco_step_1_min();
791 char_O_deco_status = 3; // surface new in v.102 overwrites value of calc_wo_deco_step_1_min 887 char_O_deco_status = 3; // surface new in v.102 overwrites value of calc_wo_deco_step_1_min
792 deco_calc_desaturation_time(); 888 deco_calc_desaturation_time();
793 } 889 }
794 890
891 //////////////////////////////////////////////////////////////////////////////
892
795 void deco_debug(void) 893 void deco_debug(void)
796 { 894 {
797 RESET_C_STACK 895 RESET_C_STACK
798 // debug(); 896 }
799 } 897
800 898 //////////////////////////////////////////////////////////////////////////////
801 // --------------- 899 // clear_tissue
802 // CLEAR tissue // 900 //
803 // ---------------
804 // optimized in v.101 (var_N2_a) 901 // optimized in v.101 (var_N2_a)
805 902 //
806 #pragma code p2_deco_suite = 0x10700 903 // preload tissues with standard pressure for the given ambient pressure.
807 904 // Note: fixed N2_ratio for standard air.
808 void clear_tissue(void) // preload tissues with standard pressure for the given ambient pressure 905
906 static void clear_tissue(void)
809 { 907 {
810 flag_in_divemode = 0; 908 flag_in_divemode = 0;
811 int_O_DBS_bitfield = 0; 909 int_O_DBS_bitfield = 0;
812 int_O_DBS2_bitfield = 0; 910 int_O_DBS2_bitfield = 0;
813 int_O_DBG_pre_bitfield = 0; 911 int_O_DBG_pre_bitfield = 0;
814 int_O_DBG_post_bitfield = 0; 912 int_O_DBG_post_bitfield = 0;
815 char_O_NDL_at_20mtr = 255; 913 char_O_NDL_at_20mtr = 255;
816 914
817 // N2_ratio = (float)char_I_N2_ratio; // the 0.0002 of 0.7902 are missing with standard air 915 // Kludge: the 0.0002 of 0.7902 are missing with standard air.
818 N2_ratio = 0.7902; // N2_ratio / 100.0; 916 N2_ratio = 0.7902;
819 pres_respiration = (float)int_I_pres_respiration / 1000.0; 917 pres_respiration = (float)int_I_pres_respiration / 1000.0;
820 918
821 _asm 919 for(ci=0; ci<16; ci++)
822 movlw 1
823 movwf TBLPTRU,0
824 _endasm
825 for(ci=0;ci<16;ci++)
826 { 920 {
827 // cycle through the 16 b"uhlmann tissues 921 // cycle through the 16 b"uhlmann tissues
828 overlay float p = N2_ratio * (pres_respiration - 0.0627); 922 overlay float p = N2_ratio * (pres_respiration - 0.0627);
829 pres_tissue[ci] = p; 923 pres_tissue[ci] = p;
830 924
831 read_buhlmann_compartment(0); 925 read_buhlmann_coeffifients(-1);
832 926
833 p = (p - var_N2_a) * var_N2_b ; 927 p = (p - var_N2_a) * var_N2_b ;
834 if( p < 0.0 ) 928 if( p < 0.0 )
835 p = 0.0; 929 p = 0.0;
836 pres_tissue_limit[ci] = p; 930 pres_tissue_limit[ci] = p;
837 931
838 // cycle through the 16 b"uhlmann tissues for Helium 932 // cycle through the 16 b"uhlmann tissues for Helium
839 pres_tissue[ci+16] = 0.0; 933 (pres_tissue+16)[ci] = 0.0;
840 } // for 0 to 16 934 } // for 0 to 16
841 935
842 clear_decoarray(); 936 clear_decoarray();
843 char_O_deco_status = 0; 937 char_O_deco_status = 0;
844 char_O_nullzeit = 0; 938 char_O_nullzeit = 0;
845 char_O_ascenttime = 0; 939 char_O_ascenttime = 0;
846 char_O_gradient_factor = 0; 940 char_O_gradient_factor = 0;
847 char_O_relative_gradient_GF = 0; 941 char_O_relative_gradient_GF = 0;
848 } // clear_tissue(void) 942 }
849 943
850 944 //////////////////////////////////////////////////////////////////////////////
851 // -------------------- 945 // calc_without_deco
852 // calc_without_deco // 946 //
853 // fixed N2_ratio ! //
854 // --------------------
855 // optimized in v.101 (float_..saturation_multiplier) 947 // optimized in v.101 (float_..saturation_multiplier)
856 948 //
857 void calc_without_deco(void) 949 // Note: fixed N2_ratio for standard air.
858 { 950
859 N2_ratio = 0.7902; // FIXED RATIO !! sum as stated in b"uhlmann 951 static void calc_without_deco(void)
952 {
953 N2_ratio = 0.7902; // Sum as stated in b"uhlmann
860 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system 954 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system
861 pres_surface = (float)int_I_pres_surface / 1000.0; 955 pres_surface = (float)int_I_pres_surface / 1000.0;
862 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body 956 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body
863 temp2_atem = 0.0; 957 temp2_atem = 0.0;
864 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does apply to the pressure without any inert ratio 958 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does apply to the pressure without any inert ratio
865 float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0; 959 float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0;
866 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; 960 float_saturation_multiplier = char_I_saturation_multiplier / 100.0;
867 961
868 calc_tissue(); // update the pressure in the 16 tissues in accordance with the new ambient pressure 962 calc_tissue_2_secs(); // update the pressure in the 32 tissues in accordance with the new ambient pressure
869 963
870 clear_decoarray(); 964 clear_decoarray();
871 char_O_deco_status = 0; 965 char_O_deco_status = 0;
872 char_O_nullzeit = 0; 966 char_O_nullzeit = 0;
873 char_O_ascenttime = 0; 967 char_O_ascenttime = 0;
874 calc_gradient_factor(); 968 calc_gradient_factor();
875 } // calc_without_deco 969 }
876 970
877 971 //////////////////////////////////////////////////////////////////////////////
878 // -------------------- 972 // calc_hauptroutine
879 // calc_hauptroutine // 973 //
880 // -------------------- 974 // this is the major code in dive mode calculates:
881 // this is the major code in dive mode
882 // calculates:
883 // the tissues, 975 // the tissues,
884 // the bottom time 976 // the bottom time,
885 // and simulates the ascend with all deco stops 977 // and simulates the ascend with all deco stops.
886 978
887 void calc_hauptroutine(void) 979 static void calc_hauptroutine(void)
888 { 980 {
889 calc_hauptroutine_data_input(); 981 calc_hauptroutine_data_input();
890 982
891 if(!flag_in_divemode) 983 if(!flag_in_divemode)
892 { 984 {
897 check_pre_dbg(); 989 check_pre_dbg();
898 990
899 calc_hauptroutine_update_tissues(); 991 calc_hauptroutine_update_tissues();
900 calc_gradient_factor(); 992 calc_gradient_factor();
901 993
902 994 // toggle between calculation for nullzeit (bottom time),
903 switch (char_O_deco_status) // toggle between calculation for nullzeit (bottom time), deco stops and more deco stops (continue) 995 // deco stops
996 // and more deco stops (continue)
997 switch( char_O_deco_status )
904 { 998 {
905 case 0: 999 case 0: //---- bottom time -----------------------------------------------
906 update_startvalues(); 1000 update_startvalues();
907 calc_nullzeit(); 1001 calc_nullzeit();
908 check_ndl(); 1002 check_ndl();
909 char_O_deco_status = 255; // calc deco next time 1003 char_O_deco_status = 255; // calc deco next time
910 break; 1004 break;
911 case 1: 1005
912 if (char_O_deco_status == 3) 1006 case 1: //---- ???? ------------------------------------------------------
913 break; 1007 char_O_deco_status = 0;
914 char_O_deco_status = 0; 1008 calc_hauptroutine_calc_deco();
915 calc_hauptroutine_calc_deco(); 1009 break;
916 break; 1010
917 case 3: // new dive 1011 case 3: //---- new dive --------------------------------------------------
918 clear_decoarray(); 1012 clear_decoarray();
919 clear_internal_deco_table_GF(); 1013 clear_internal_deco_table_GF();
920 copy_deco_table_GF(); 1014 copy_deco_table_GF();
921 internal_deco_pointer = 0; 1015 internal_deco_pointer = 0;
922 lock_GF_depth_list = 0; 1016 lock_GF_depth_list = 0;
923 update_startvalues(); 1017 update_startvalues();
924 calc_nextdecodepth_GF(); 1018 calc_nextdecodepth_GF();
925 char_O_deco_status = 0; 1019 char_O_deco_status = 0;
926 break; 1020 break;
927 default: 1021
928 update_startvalues(); 1022 default: //---- Continue stops calculation -------------------------------
929 clear_decoarray(); 1023 update_startvalues();
930 clear_internal_deco_table_GF(); 1024 clear_decoarray();
931 output[6] = 1; 1025 clear_internal_deco_table_GF();
932 calc_hauptroutine_calc_ascend_to_deco(); 1026 output[6] = 1;
933 if (char_O_deco_status > 15) // can't go up to first deco, too deep to calculate in the given time slot 1027 calc_hauptroutine_calc_ascend_to_deco();
934 { 1028
935 char_O_deco_status = 2; 1029 // can't go up to first deco, too deep to calculate in the given time slot
936 } 1030 if (char_O_deco_status > 15)
937 else 1031 char_O_deco_status = 2;
938 { 1032 else
939 calc_hauptroutine_calc_deco(); 1033 calc_hauptroutine_calc_deco();
940 } 1034 break;
941 break;
942 } 1035 }
1036
943 calc_ascenttime(); 1037 calc_ascenttime();
944 check_post_dbg(); 1038 check_post_dbg();
945 } 1039 }
946 1040
1041 //////////////////////////////////////////////////////////////////////////////
1042 // calc_hauptroutine_data_input
1043 //
1044 // Reset all C-code dive parameters from their ASM-code values.
1045 // Detect gas change condition.
1046 //
947 void calc_hauptroutine_data_input(void) 1047 void calc_hauptroutine_data_input(void)
948 { 1048 {
949 pres_respiration = (float)int_I_pres_respiration / 1000.0; 1049 overlay int int_temp;
950 pres_surface = (float)int_I_pres_surface / 1000.0;
951 1050
952 N2_ratio = (float)char_I_N2_ratio / 100.0;; // the 0.0002 of 0.7902 are missing with standard air 1051 pres_respiration = int_I_pres_respiration / 1000.0;
953 He_ratio = (float)char_I_He_ratio / 100.0;; 1052 pres_surface = int_I_pres_surface / 1000.0;
954 deco_N2_ratio = (float)char_I_deco_N2_ratio / 100.0; 1053 N2_ratio = char_I_N2_ratio / 100.0;
955 deco_He_ratio = (float)char_I_deco_He_ratio / 100.0; 1054 He_ratio = char_I_He_ratio / 100.0;
956 deco_N2_ratio2 = (float)char_I_deco_N2_ratio2 / 100.0; 1055 deco_N2_ratio1 = char_I_deco_N2_ratio1 / 100.0;
957 deco_He_ratio2 = (float)char_I_deco_He_ratio2 / 100.0; 1056 deco_He_ratio1 = char_I_deco_He_ratio1 / 100.0;
958 deco_N2_ratio3 = (float)char_I_deco_N2_ratio3 / 100.0; 1057 deco_N2_ratio2 = char_I_deco_N2_ratio2 / 100.0;
959 deco_He_ratio3 = (float)char_I_deco_He_ratio3 / 100.0; 1058 deco_He_ratio2 = char_I_deco_He_ratio2 / 100.0;
960 deco_N2_ratio4 = (float)char_I_deco_N2_ratio4 / 100.0; 1059 deco_N2_ratio3 = char_I_deco_N2_ratio3 / 100.0;
961 deco_He_ratio4 = (float)char_I_deco_He_ratio4 / 100.0; 1060 deco_He_ratio3 = char_I_deco_He_ratio3 / 100.0;
962 deco_N2_ratio5 = (float)char_I_deco_N2_ratio5 / 100.0; 1061 deco_N2_ratio4 = char_I_deco_N2_ratio4 / 100.0;
963 deco_He_ratio5 = (float)char_I_deco_He_ratio5 / 100.0; 1062 deco_He_ratio4 = char_I_deco_He_ratio4 / 100.0;
964 float_deco_distance = (float)char_I_deco_distance / 100.0; 1063 deco_N2_ratio5 = char_I_deco_N2_ratio5 / 100.0;
1064 deco_He_ratio5 = char_I_deco_He_ratio5 / 100.0;
1065 float_deco_distance = char_I_deco_distance / 100.0;
965 1066
966 // ____________________________________________________ 1067 // ____________________________________________________
967 // 1068 //
968 // _____________ G A S _ C H A N G E S ________________ 1069 // _____________ G A S _ C H A N G E S ________________
969 // ____________________________________________________ 1070 // ____________________________________________________
970 1071
971 int_temp = (int_I_pres_respiration - int_I_pres_surface) + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF; 1072 int_temp = (int_I_pres_respiration - int_I_pres_surface) + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF;
972 1073
973 deco_gas_change = 0; 1074 deco_gas_change1 = 0;
974 deco_gas_change2 = 0; 1075 deco_gas_change2 = 0;
975 deco_gas_change3 = 0; 1076 deco_gas_change3 = 0;
976 deco_gas_change4 = 0; 1077 deco_gas_change4 = 0;
977 deco_gas_change5 = 0; 1078 deco_gas_change5 = 0;
978 1079
979 if(char_I_deco_gas_change) 1080 if(char_I_deco_gas_change1)
980 { 1081 {
981 int_temp2 = ((int)char_I_deco_gas_change) * 100; 1082 overlay int int_temp2 = ((int)char_I_deco_gas_change1) * 100;
982 if(int_temp > int_temp2) 1083 if(int_temp > int_temp2)
983 { 1084 {
984 deco_gas_change = (float)char_I_deco_gas_change / 9.995 + pres_surface; 1085 deco_gas_change1 = (float)char_I_deco_gas_change1 / 9.995 + pres_surface;
985 deco_gas_change += float_deco_distance; 1086 deco_gas_change1 += float_deco_distance;
986 } 1087 }
987 } 1088 }
988 if(char_I_deco_gas_change2) 1089 if(char_I_deco_gas_change2)
989 { 1090 {
990 int_temp2 = ((int)char_I_deco_gas_change2) * 100; 1091 overlay int int_temp2 = ((int)char_I_deco_gas_change2) * 100;
991 if(int_temp > int_temp2) 1092 if(int_temp > int_temp2)
992 { 1093 {
993 deco_gas_change2 = (float)char_I_deco_gas_change2 / 9.995 + pres_surface; 1094 deco_gas_change2 = (float)char_I_deco_gas_change2 / 9.995 + pres_surface;
994 deco_gas_change2 += float_deco_distance; 1095 deco_gas_change2 += float_deco_distance;
995 } 1096 }
996 } 1097 }
997 if(char_I_deco_gas_change3) 1098 if(char_I_deco_gas_change3)
998 { 1099 {
999 int_temp2 = ((int)char_I_deco_gas_change3) * 100; 1100 overlay int int_temp2 = ((int)char_I_deco_gas_change3) * 100;
1000 if(int_temp > int_temp2) 1101 if(int_temp > int_temp2)
1001 { 1102 {
1002 deco_gas_change3 = (float)char_I_deco_gas_change3 / 9.995 + pres_surface; 1103 deco_gas_change3 = (float)char_I_deco_gas_change3 / 9.995 + pres_surface;
1003 deco_gas_change3 += float_deco_distance; 1104 deco_gas_change3 += float_deco_distance;
1004 } 1105 }
1005 } 1106 }
1006 if(char_I_deco_gas_change4) 1107 if(char_I_deco_gas_change4)
1007 { 1108 {
1008 int_temp2 = ((int)char_I_deco_gas_change4) * 100; 1109 overlay int int_temp2 = ((int)char_I_deco_gas_change4) * 100;
1009 if(int_temp > int_temp2) 1110 if(int_temp > int_temp2)
1010 { 1111 {
1011 deco_gas_change4 = (float)char_I_deco_gas_change4 / 9.995 + pres_surface; 1112 deco_gas_change4 = (float)char_I_deco_gas_change4 / 9.995 + pres_surface;
1012 deco_gas_change4 += float_deco_distance; 1113 deco_gas_change4 += float_deco_distance;
1013 } 1114 }
1014 } 1115 }
1015 if(char_I_deco_gas_change5) 1116 if(char_I_deco_gas_change5)
1016 { 1117 {
1017 int_temp2 = ((int)char_I_deco_gas_change5) * 100; 1118 overlay int int_temp2 = ((int)char_I_deco_gas_change5) * 100;
1018 if(int_temp > int_temp2) 1119 if(int_temp > int_temp2)
1019 { 1120 {
1020 deco_gas_change5 = (float)char_I_deco_gas_change5 / 9.995 + pres_surface; 1121 deco_gas_change5 = (float)char_I_deco_gas_change5 / 9.995 + pres_surface;
1021 deco_gas_change5 += float_deco_distance; 1122 deco_gas_change5 += float_deco_distance;
1022 } 1123 }
1041 char_O_actual_pointer = int_temp; 1142 char_O_actual_pointer = int_temp;
1042 1143
1043 temp_depth_last_deco = (int)char_I_depth_last_deco; 1144 temp_depth_last_deco = (int)char_I_depth_last_deco;
1044 } 1145 }
1045 1146
1147 //////////////////////////////////////////////////////////////////////////////
1148
1046 void calc_hauptroutine_update_tissues(void) 1149 void calc_hauptroutine_update_tissues(void)
1047 { 1150 {
1048 int_O_calc_tissue_call_counter = int_O_calc_tissue_call_counter + 1; 1151 int_O_calc_tissue_call_counter = int_O_calc_tissue_call_counter + 1;
1049 if (char_I_const_ppO2 == 0) // new in v.101 1152 if (char_I_const_ppO2 == 0) // new in v.101
1050 pres_diluent = pres_respiration; // new in v.101 1153 pres_diluent = pres_respiration; // new in v.101
1051 else // new in v.101 1154 else // new in v.101
1052 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 1155 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101
1053 if (pres_diluent > pres_respiration) // new in v.101 1156 if (pres_diluent > pres_respiration) // new in v.101
1054 pres_diluent = pres_respiration; // new in v.101 1157 pres_diluent = pres_respiration; // new in v.101
1055 if (pres_diluent > 0.0627) // new in v.101 1158 if (pres_diluent > 0.0627) // new in v.101
1056 { 1159 {
1057 temp_atem = N2_ratio * (pres_diluent - 0.0627); // changed in v.101 1160 temp_atem = N2_ratio * (pres_diluent - 0.0627); // changed in v.101
1058 temp2_atem = He_ratio * (pres_diluent - 0.0627); // changed in v.101 1161 temp2_atem = He_ratio * (pres_diluent - 0.0627); // changed in v.101
1059 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0); 1162 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0);
1060 } 1163 }
1061 else // new in v.101 1164 else // new in v.101
1062 { 1165 {
1063 temp_atem = 0.0; // new in v.101 1166 temp_atem = 0.0; // new in v.101
1064 temp2_atem = 0.0; // new in v.101 1167 temp2_atem = 0.0; // new in v.101
1065 char_O_diluent = 0; 1168 char_O_diluent = 0;
1066 } 1169 }
1067 temp_surface = pres_surface; 1170 temp_surface = pres_surface;
1068 1171
1069 if(!char_I_step_is_1min) 1172 if(!char_I_step_is_1min)
1070 calc_tissue(); 1173 calc_tissue_2_secs();
1071 else 1174 else
1072 calc_tissue_step_1_min(); 1175 calc_tissue_1_min();
1073 1176
1074 int_O_gtissue_limit = (int)(pres_tissue_limit[char_O_gtissue_no] * 1000); 1177 int_O_gtissue_limit = (int)(pres_tissue_limit[char_O_gtissue_no] * 1000);
1075 int_O_gtissue_press = (int)((pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]) * 1000); 1178 int_O_gtissue_press = (int)((pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]) * 1000);
1076 if (char_I_deco_model == 1) 1179 if (char_I_deco_model == 1)
1077 { 1180 {
1086 char_O_nullzeit = 0; // deco necessary 1189 char_O_nullzeit = 0; // deco necessary
1087 char_O_deco_status = 255; // calculate deco skip nullzeit calculation 1190 char_O_deco_status = 255; // calculate deco skip nullzeit calculation
1088 } 1191 }
1089 } // calc_hauptroutine_update_tissues 1192 } // calc_hauptroutine_update_tissues
1090 1193
1194 //////////////////////////////////////////////////////////////////////////////
1195
1091 void calc_hauptroutine_calc_deco(void) 1196 void calc_hauptroutine_calc_deco(void)
1092 { 1197 {
1093 do 1198 do
1094 { 1199 {
1095 int_temp_decostatus = 0; 1200 int_temp_decostatus = 0;
1101 1206
1102 if (char_I_const_ppO2 == 0) // new in v.101 1207 if (char_I_const_ppO2 == 0) // new in v.101
1103 { 1208 {
1104 deco_diluent = temp_deco; // new in v.101 1209 deco_diluent = temp_deco; // new in v.101
1105 1210
1106 if(deco_gas_change && (temp_deco < deco_gas_change)) 1211 if(deco_gas_change1 && (temp_deco < deco_gas_change1))
1107 { 1212 {
1108 calc_N2_ratio = deco_N2_ratio; 1213 calc_N2_ratio = deco_N2_ratio1;
1109 calc_He_ratio = deco_He_ratio; 1214 calc_He_ratio = deco_He_ratio1;
1110 } 1215 }
1111 if(deco_gas_change2 && (temp_deco < deco_gas_change2)) 1216 if(deco_gas_change2 && (temp_deco < deco_gas_change2))
1112 { 1217 {
1113 calc_N2_ratio = deco_N2_ratio2; 1218 calc_N2_ratio = deco_N2_ratio2;
1114 calc_He_ratio = deco_He_ratio2; 1219 calc_He_ratio = deco_He_ratio2;
1163 else // if (temp_depth_limit > 0) 1268 else // if (temp_depth_limit > 0)
1164 { 1269 {
1165 char_O_deco_status = 0; 1270 char_O_deco_status = 0;
1166 } 1271 }
1167 } while (int_temp_decostatus == 1); 1272 } while (int_temp_decostatus == 1);
1273
1168 if (char_O_deco_status > 15) 1274 if (char_O_deco_status > 15)
1169 { 1275 {
1170 char_O_deco_status = 1; 1276 char_O_deco_status = 1;
1171 } 1277 }
1172 else 1278 else
1173 { 1279 {
1174 copy_deco_table_GF(); 1280 copy_deco_table_GF();
1175 char_O_deco_status = 0; 1281 char_O_deco_status = 0;
1176 } 1282 }
1177 } 1283 }
1284
1285 //////////////////////////////////////////////////////////////////////////////
1178 1286
1179 void calc_hauptroutine_calc_ascend_to_deco(void) 1287 void calc_hauptroutine_calc_ascend_to_deco(void)
1180 { 1288 {
1181 update_startvalues(); 1289 update_startvalues();
1182 char_O_deco_status = 0; 1290 char_O_deco_status = 0;
1201 1309
1202 if (char_I_const_ppO2 == 0) // new in v.101 // calculate at half of the ascent 1310 if (char_I_const_ppO2 == 0) // new in v.101 // calculate at half of the ascent
1203 { 1311 {
1204 deco_diluent = temp_deco; // new in v.101 1312 deco_diluent = temp_deco; // new in v.101
1205 1313
1206 if(deco_gas_change && (temp_deco < deco_gas_change)) 1314 if(deco_gas_change1 && (temp_deco < deco_gas_change1))
1207 { 1315 {
1208 calc_N2_ratio = deco_N2_ratio; 1316 calc_N2_ratio = deco_N2_ratio1;
1209 calc_He_ratio = deco_He_ratio; 1317 calc_He_ratio = deco_He_ratio1;
1210 } 1318 }
1211 if(deco_gas_change2 && (temp_deco < deco_gas_change2)) 1319 if(deco_gas_change2 && (temp_deco < deco_gas_change2))
1212 { 1320 {
1213 calc_N2_ratio = deco_N2_ratio2; 1321 calc_N2_ratio = deco_N2_ratio2;
1214 calc_He_ratio = deco_He_ratio2; 1322 calc_He_ratio = deco_He_ratio2;
1253 char_O_deco_status = char_O_deco_status + 1; 1361 char_O_deco_status = char_O_deco_status + 1;
1254 if (char_O_deco_status < 16) // 16 is the limit of calculations for one time slot 1362 if (char_O_deco_status < 16) // 16 is the limit of calculations for one time slot
1255 int_temp_decostatus = 1; 1363 int_temp_decostatus = 1;
1256 } 1364 }
1257 } while (int_temp_decostatus == 1); 1365 } while (int_temp_decostatus == 1);
1258 } // calc_hauptroutine_calc_ascend_to_deco 1366 }
1259 1367
1260 // -------------- 1368 //////////////////////////////////////////////////////////////////////////////
1261 // calc_tissue // 1369 // calc_tissue
1262 // -------------- 1370 //
1263 // optimized in v.101 1371 // optimized in v.101
1264 1372 //
1265 void calc_tissue(void) 1373 static void calc_tissue(static unsigned char period)
1266 { 1374 {
1267 char_O_gtissue_no = 255; 1375 char_O_gtissue_no = 255;
1268 pres_gtissue_limit = 0.0; 1376 pres_gtissue_limit = 0.0;
1269 1377
1270 for (ci=0;ci<16;ci++) 1378 for (ci=0;ci<16;ci++)
1271 { 1379 {
1272 read_buhlmann_compartment(0); // 2 sec mode. 1380 read_buhlmann_coeffifients(period); // 2 sec or 1 min period.
1273 1381
1274 // N2 1382 // N2
1275 temp_tissue = (temp_atem - pres_tissue[ci]) * var_N2_e; 1383 temp_tissue = (temp_atem - pres_tissue[ci]) * var_N2_e;
1276 temp_tissue_safety(); 1384 temp_tissue_safety();
1277 pres_tissue[ci] = pres_tissue[ci] + temp_tissue; 1385 pres_tissue[ci] += temp_tissue;
1278 1386
1279 // He 1387 // He
1280 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var_He_e; 1388 temp_tissue = (temp2_atem - (pres_tissue+16)[ci]) * var_He_e;
1281 temp_tissue_safety(); 1389 temp_tissue_safety();
1282 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue; 1390 (pres_tissue+16)[ci] += temp_tissue;
1283 1391
1284 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; 1392 temp_tissue = pres_tissue[ci] + (pres_tissue+16)[ci];
1285 1393
1286 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * pres_tissue[ci+16]) / temp_tissue; 1394 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * (pres_tissue+16)[ci]) / temp_tissue;
1287 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * pres_tissue[ci+16]) / temp_tissue; 1395 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * (pres_tissue+16)[ci]) / temp_tissue;
1288 pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b; 1396 pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
1289 if (pres_tissue_limit[ci] < 0) 1397 if (pres_tissue_limit[ci] < 0)
1290 pres_tissue_limit[ci] = 0; 1398 pres_tissue_limit[ci] = 0;
1291 if (pres_tissue_limit[ci] > pres_gtissue_limit) 1399 if (pres_tissue_limit[ci] > pres_gtissue_limit)
1292 { 1400 {
1293 pres_gtissue_limit = pres_tissue_limit[ci]; 1401 pres_gtissue_limit = pres_tissue_limit[ci];
1294 char_O_gtissue_no = ci; 1402 char_O_gtissue_no = ci;
1295 }//if 1403 }//if
1296 } // for 1404 } // for
1297 }//calc_tissue(void) 1405 }
1298 1406
1299 // ---------------- 1407 //////////////////////////////////////////////////////////////////////////////
1300 // calc_nullzeit // 1408 // calc_tissue_2_secs
1301 // ---------------- 1409 //
1410 // optimized in v.101
1411 //
1412 static void calc_tissue_2_secs(void)
1413 {
1414 calc_tissue(0);
1415 }
1416
1417 //////////////////////////////////////////////////////////////////////////////
1418 // calc_tissue_1_min
1419 //
1420 // optimized in v.101
1421 //
1422 static void calc_tissue_1_min(void)
1423 {
1424 calc_tissue(1);
1425 }
1426
1427 //////////////////////////////////////////////////////////////////////////////
1428 // calc_nullzeit
1429 //
1302 // calculates the remaining bottom time 1430 // calculates the remaining bottom time
1303 1431 //
1304 // unchanged in v.101 1432 // unchanged in v.101
1305 1433 //
1306 void calc_nullzeit(void) 1434 static void calc_nullzeit(void)
1307 { 1435 {
1436 overlay int loop;
1437
1308 char_O_nullzeit = 0; 1438 char_O_nullzeit = 0;
1309 int_temp = 1; 1439 for(loop = 1; loop <= 17; loop++)
1310 do
1311 { 1440 {
1312 backup_sim_pres_tissue(); 1441 backup_sim_pres_tissue();
1313 sim_tissue_10min(); 1442 sim_tissue_10min();
1314 char_O_nullzeit = char_O_nullzeit + 10; 1443 char_O_nullzeit = char_O_nullzeit + 10;
1315 int_temp = int_temp + 1; 1444
1316 if (char_I_deco_model == 1) 1445 if (char_I_deco_model == 1)
1317 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue; 1446 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue;
1318 else 1447 else
1319 temp1 = temp_pres_gtissue_limit; 1448 temp1 = temp_pres_gtissue_limit;
1320 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately 1449 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately
1321 int_temp = 255; 1450 loop = 255;
1322 } while (int_temp < 17); 1451 }
1323 if (int_temp == 255) 1452
1453 if (loop == 255)
1324 { 1454 {
1325 restore_sim_pres_tissue(); 1455 restore_sim_pres_tissue();
1326 char_O_nullzeit = char_O_nullzeit - 10; 1456 char_O_nullzeit = char_O_nullzeit - 10;
1327 } //if int_temp == 255] 1457 } //if loop == 255]
1328 int_temp = 1; 1458
1329 if (char_O_nullzeit < 60) 1459 if (char_O_nullzeit < 60)
1330 { 1460 {
1331 do 1461 for(loop=1; loop <= 10; loop++)
1332 { 1462 {
1333 sim_tissue_1min(); 1463 sim_tissue_1min();
1334 char_O_nullzeit = char_O_nullzeit + 1; 1464 char_O_nullzeit = char_O_nullzeit + 1;
1335 int_temp = int_temp + 1; // new in v.102a 1465 if (char_I_deco_model == 1)
1336 if (char_I_deco_model == 1) 1466 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue;
1337 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue; 1467 else
1338 else 1468 temp1 = temp_pres_gtissue_limit;
1339 temp1 = temp_pres_gtissue_limit; 1469 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately
1340 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately 1470 loop = 255;
1341 int_temp = 255; 1471 }
1342 } while (int_temp < 10); 1472 if (loop == 255)
1343 if (int_temp == 255)
1344 char_O_nullzeit = char_O_nullzeit - 1; 1473 char_O_nullzeit = char_O_nullzeit - 1;
1345 } // if char_O_nullzeit < 60 1474 } // if char_O_nullzeit < 60
1346 } //calc_nullzeit 1475 } //calc_nullzeit
1347 1476
1348 // ------------------------- 1477 //////////////////////////////////////////////////////////////////////////////
1349 // backup_sim_pres_tissue // 1478 // backup_sim_pres_tissue
1350 // ------------------------- 1479 //
1351 void backup_sim_pres_tissue(void) 1480 void backup_sim_pres_tissue(void)
1352 { 1481 {
1353 for (x = 0;x<16;x++) 1482 overlay unsigned char x;
1354 { 1483
1484 for(x = 0; x<32; x++)
1355 sim_pres_tissue_backup[x] = sim_pres_tissue[x]; 1485 sim_pres_tissue_backup[x] = sim_pres_tissue[x];
1356 sim_pres_tissue_backup[x+16] = sim_pres_tissue[x+16]; 1486 }
1357 } 1487
1358 } // backup_sim 1488 //////////////////////////////////////////////////////////////////////////////
1359 1489 // restore_sim_pres_tissue
1360 // -------------------------- 1490 //
1361 // restore_sim_pres_tissue //
1362 // --------------------------
1363 void restore_sim_pres_tissue(void) 1491 void restore_sim_pres_tissue(void)
1364 { 1492 {
1365 for (x = 0;x<16;x++) 1493 overlay unsigned char x;
1366 { 1494
1495 for(x = 0; x<32; x++)
1367 sim_pres_tissue[x] = sim_pres_tissue_backup[x]; 1496 sim_pres_tissue[x] = sim_pres_tissue_backup[x];
1368 sim_pres_tissue[x+16] = sim_pres_tissue_backup[x+16]; 1497 }
1369 } 1498
1370 } // restore_sim 1499 //////////////////////////////////////////////////////////////////////////////
1371 1500 // calc_ascenttime
1372 // ------------------ 1501 //
1373 // calc_ascenttime //
1374 // ------------------
1375
1376 void calc_ascenttime(void) 1502 void calc_ascenttime(void)
1377 { 1503 {
1378 if (pres_respiration > pres_surface) 1504 if (pres_respiration > pres_surface)
1379 { 1505 {
1380 switch (char_O_deco_status) 1506 switch (char_O_deco_status)
1383 char_O_ascenttime = 255; 1509 char_O_ascenttime = 255;
1384 break; 1510 break;
1385 case 1: 1511 case 1:
1386 break; 1512 break;
1387 default: 1513 default:
1388 temp1 = pres_respiration - pres_surface + 0.6; // + 0.6 hence 1 minute ascent time from a depth of 4 meter on
1389 if (temp1 < 0)
1390 temp1 = 0;
1391 if (temp1 > 255)
1392 temp1 = 255;
1393 char_O_ascenttime = (char)temp1;
1394
1395 for(ci=0;ci<7;ci++)
1396 { 1514 {
1397 x = char_O_ascenttime + char_O_array_decotime[ci]; 1515 overlay unsigned char x;
1398 if (x < char_O_ascenttime) 1516 overlay float ascent = pres_respiration - pres_surface + 0.6; // + 0.6 hence 1 minute ascent time from a depth of 4 meter on
1399 char_O_ascenttime = 255; 1517
1400 else 1518 if (ascent < 0.0)
1401 char_O_ascenttime = x; 1519 ascent = 0.0;
1520 if (ascent > 255.0)
1521 ascent = 255.0;
1522 char_O_ascenttime = (char)ascent;
1523
1524 for(x=0; x<7; x++)
1525 {
1526 overlay int int_ascent = (int)char_O_ascenttime + (int)char_O_array_decotime[x];
1527 if(int_ascent >= 255)
1528 char_O_ascenttime = 255;
1529 else
1530 char_O_ascenttime = int_ascent;
1531 }
1532 break;
1402 } 1533 }
1403 break;
1404 } 1534 }
1405 } 1535 }
1406 else 1536 else
1407 char_O_ascenttime = 0; 1537 char_O_ascenttime = 0;
1408 } // calc_ascenttime() 1538 }
1409 1539
1410 1540 //////////////////////////////////////////////////////////////////////////////
1411 // --------------------- 1541 // update_startvalues
1412 // update_startvalues // 1542 //
1413 // ---------------------
1414 // updated in v.102 1543 // updated in v.102
1415 1544 //
1416 void update_startvalues(void) 1545 void update_startvalues(void)
1417 { 1546 {
1547 overlay unsigned char x;
1548
1418 temp_pres_gtissue_limit = pres_gtissue_limit; 1549 temp_pres_gtissue_limit = pres_gtissue_limit;
1419 temp_pres_gtissue = pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]; 1550 temp_pres_gtissue = pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16];
1420 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; // negative number 1551 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; // negative number
1421 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; 1552 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue;
1422 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; 1553 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface;
1428 { 1559 {
1429 sim_pres_tissue[x] = pres_tissue[x]; 1560 sim_pres_tissue[x] = pres_tissue[x];
1430 sim_pres_tissue[x+16] = pres_tissue[x+16]; 1561 sim_pres_tissue[x+16] = pres_tissue[x+16];
1431 sim_pres_tissue_limit[x] = pres_tissue_limit[x]; 1562 sim_pres_tissue_limit[x] = pres_tissue_limit[x];
1432 } 1563 }
1433 } // update_startvalues 1564 }
1434 1565
1435 1566 //////////////////////////////////////////////////////////////////////////////
1436 // ------------------ 1567 // sim_tissue_1min
1437 // sim_tissue_1min // 1568 //
1438 // ------------------
1439 // optimized in v.101 1569 // optimized in v.101
1440 1570 //
1441 void sim_tissue_1min(void) 1571 // Function very simular to calc_tissue, but:
1572 // + Use a 1min or 10min period.
1573 // + Do it on sim_pres_tissue, instead of pres_tissue.
1574 // + Update GF_low state for GF decompression model.
1575 //
1576 static void sim_tissue(static unsigned char period)
1442 { 1577 {
1443 temp_pres_gtissue_limit = 0.0; 1578 temp_pres_gtissue_limit = 0.0;
1444 temp_gtissue_no = 255; 1579 temp_gtissue_no = 255;
1445 1580
1446 for (ci=0;ci<16;ci++) 1581 for (ci=0;ci<16;ci++)
1447 { 1582 {
1448 read_buhlmann_compartment(1); // 1 minute interval 1583 read_buhlmann_coeffifients(period); // 1 or 10 minute(s) interval
1449 1584
1450 // N2 1585 // N2
1451 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_N2_e; 1586 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_N2_e;
1452 temp_tissue_safety(); 1587 temp_tissue_safety();
1453 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; 1588 sim_pres_tissue[ci] += temp_tissue;
1454 1589
1455 // He 1590 // He
1456 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var_He_e; 1591 temp_tissue = (temp2_atem - (sim_pres_tissue+16)[ci]) * var_He_e;
1457 temp_tissue_safety(); 1592 temp_tissue_safety();
1458 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue; 1593 (sim_pres_tissue+16)[ci] += temp_tissue;
1459 1594
1460 // pressure limit 1595 // pressure limit
1461 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16]; 1596 temp_tissue = sim_pres_tissue[ci] + (sim_pres_tissue+16)[ci];
1462 var_N2_a = (var_N2_a * sim_pres_tissue[ci] + var_He_a * sim_pres_tissue[ci+16]) / temp_tissue; 1597 var_N2_a = (var_N2_a * sim_pres_tissue[ci] + var_He_a * (sim_pres_tissue+16)[ci]) / temp_tissue;
1463 var_N2_b = (var_N2_b * sim_pres_tissue[ci] + var_He_b * sim_pres_tissue[ci+16]) / temp_tissue; 1598 var_N2_b = (var_N2_b * sim_pres_tissue[ci] + var_He_b * (sim_pres_tissue+16)[ci]) / temp_tissue;
1464 sim_pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b; 1599 sim_pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
1465 1600
1466 if (sim_pres_tissue_limit[ci] < 0) 1601 if (sim_pres_tissue_limit[ci] < 0)
1467 sim_pres_tissue_limit[ci] = 0; 1602 sim_pres_tissue_limit[ci] = 0;
1468 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit) 1603 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit)
1476 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; 1611 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue;
1477 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; 1612 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue;
1478 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; 1613 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface;
1479 if (temp_pres_gtissue_limit_GF_low_below_surface < 0) 1614 if (temp_pres_gtissue_limit_GF_low_below_surface < 0)
1480 temp_pres_gtissue_limit_GF_low_below_surface = 0; 1615 temp_pres_gtissue_limit_GF_low_below_surface = 0;
1481 } //sim_tissue_1min() 1616 }
1482 1617
1483 //-------------------- 1618 //////////////////////////////////////////////////////////////////////////////
1484 // sim_tissue_10min // 1619 // sim_tissue_1min
1485 //-------------------- 1620 //
1486 1621 static void sim_tissue_1min(void)
1487 // Attention!! uses var_N2_e und var_He_e to load 10min data !!! 1622 {
1488 // is identical to sim_tissue_1min routine except for the different load of those variables 1623 sim_tissue(1); // 1 minute period
1489 1624 }
1490 // optimized in v.101 1625
1491 1626 //////////////////////////////////////////////////////////////////////////////
1492 void sim_tissue_10min(void) 1627 // sim_tissue_10min
1493 { 1628 //
1494 temp_pres_gtissue_limit = 0.0; 1629 static void sim_tissue_10min(void)
1495 temp_gtissue_no = 255; 1630 {
1496 1631 sim_tissue(2); // 10 minutes period
1497 for (ci=0;ci<16;ci++) 1632 }
1633
1634 //////////////////////////////////////////////////////////////////////////////
1635 // clear_decoarray
1636 //
1637 // unchanged in v.101
1638 //
1639 static void clear_decoarray(void)
1640 {
1641 overlay unsigned char x;
1642
1643 for(x=0; x<6; ++x)
1498 { 1644 {
1499 read_buhlmann_compartment(2); // 10 minute interval 1645 char_O_array_decodepth[x] = 0;
1500 1646 char_O_array_decotime [x] = 0;
1501 // N2 1647 }
1502 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_N2_e; 1648 char_O_array_decotime[6] = 0;
1503 temp_tissue_safety(); 1649 }
1504 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; 1650
1505 // He 1651 //////////////////////////////////////////////////////////////////////////////
1506 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var_He_e; 1652 // update_decoarray
1507 temp_tissue_safety(); 1653 //
1508 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue;
1509
1510 // pressure limit
1511 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16];
1512 var_N2_a = (var_N2_a * sim_pres_tissue[ci] + var_He_a * sim_pres_tissue[ci+16]) / temp_tissue;
1513 var_N2_b = (var_N2_b * sim_pres_tissue[ci] + var_He_b * sim_pres_tissue[ci+16]) / temp_tissue;
1514
1515 sim_pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
1516 if (sim_pres_tissue_limit[ci] < 0)
1517 sim_pres_tissue_limit[ci] = 0;
1518 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit)
1519 {
1520 temp_pres_gtissue = temp_tissue;
1521 temp_pres_gtissue_limit = sim_pres_tissue_limit[ci];
1522 temp_gtissue_no = ci;
1523 }
1524 } // for
1525
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 } //sim_tissue_10min()
1532
1533
1534 // ------------------
1535 // clear_decoarray //
1536 // ------------------
1537 // unchanged in v.101 1654 // unchanged in v.101
1538 1655 //
1539 void clear_decoarray(void) 1656 static void update_decoarray()
1540 { 1657 {
1541 char_O_array_decodepth[0] = 0; 1658 overlay int stop_time;
1542 char_O_array_decodepth[1] = 0; 1659 overlay unsigned char x = 0;
1543 char_O_array_decodepth[2] = 0;
1544 char_O_array_decodepth[3] = 0;
1545 char_O_array_decodepth[4] = 0;
1546 char_O_array_decodepth[5] = 0;
1547 char_O_array_decotime[0] = 0;
1548 char_O_array_decotime[1] = 0;
1549 char_O_array_decotime[2] = 0;
1550 char_O_array_decotime[3] = 0;
1551 char_O_array_decotime[4] = 0;
1552 char_O_array_decotime[5] = 0;
1553 char_O_array_decotime[6] = 0;
1554 } // clear_decoarray
1555
1556
1557 // -------------------
1558 // update_decoarray //
1559 // -------------------
1560 // unchanged in v.101
1561
1562 void update_decoarray()
1563 {
1564 x = 0;
1565 do 1660 do
1566 { 1661 {
1567 if (char_O_array_decodepth[x] == temp_depth_limit) 1662 if (char_O_array_decodepth[x] == temp_depth_limit)
1568 { 1663 {
1569 int_temp = char_O_array_decotime[x] + temp_decotime; 1664 stop_time = char_O_array_decotime[x] + temp_decotime;
1570 if (int_temp < 0) 1665 if (stop_time < 0)
1571 int_temp = 0; 1666 stop_time = 0;
1572 if (int_temp > 240) 1667 if (stop_time > 240)
1573 int_temp = 240; 1668 stop_time = 240;
1574 char_O_array_decotime[x] = int_temp; 1669 char_O_array_decotime[x] = stop_time;
1575 x = 10; // exit 1670 x = 10; // exit
1576 } // if 1671 } // if
1577 else 1672 else
1578 { 1673 {
1579 if (char_O_array_decodepth[x] == 0) 1674 if (char_O_array_decodepth[x] == 0)
1580 { 1675 {
1581 if (temp_depth_limit > 255) 1676 if (temp_depth_limit > 255)
1582 char_O_array_decodepth[x] = 255; 1677 char_O_array_decodepth[x] = 255;
1583 else 1678 else
1584 char_O_array_decodepth[x] = (char)temp_depth_limit; 1679 char_O_array_decodepth[x] = (char)temp_depth_limit;
1585 int_temp = char_O_array_decotime[x] + temp_decotime; 1680 stop_time = char_O_array_decotime[x] + temp_decotime;
1586 if (int_temp > 240) 1681 if (stop_time > 240)
1587 char_O_array_decotime[x] = 240; 1682 char_O_array_decotime[x] = 240;
1588 else 1683 else
1589 char_O_array_decotime[x] = (char)int_temp; 1684 char_O_array_decotime[x] = (char)stop_time;
1590 x = 10; // exit 1685 x = 10; // exit
1591 } // if 1686 } // if
1592 else 1687 else
1593 x++; 1688 x++;
1594 } // else 1689 } // else
1595 } while (x<6); 1690 } while (x<6);
1596 if (x == 6) 1691 if (x == 6)
1597 { 1692 {
1598 int_temp = char_O_array_decotime[6] + temp_decotime; 1693 stop_time = char_O_array_decotime[6] + temp_decotime;
1599 if (int_temp > 220) 1694 if (stop_time > 220)
1600 char_O_array_decotime[6] = 220; 1695 char_O_array_decotime[6] = 220;
1601 else 1696 else
1602 char_O_array_decotime[6] = (char)int_temp; 1697 char_O_array_decotime[6] = (char)stop_time;
1603 } // if x == 6 1698 } // if x == 6
1604 } // update_decoarray 1699 }
1605 1700
1606 1701 //////////////////////////////////////////////////////////////////////////////
1607 // ----------------------- 1702 // calc_gradient_factor
1608 // calc_gradient_factor // 1703 //
1609 // -----------------------
1610 // optimized in v.101 (var_N2_a) 1704 // optimized in v.101 (var_N2_a)
1611 // new code in v.102 1705 // new code in v.102
1612 1706 //
1613 void calc_gradient_factor(void) 1707 static void calc_gradient_factor(void)
1614 { 1708 {
1615 // tissue > respiration (entsaettigungsvorgang) 1709 // tissue > respiration (entsaettigungsvorgang)
1616 // gradient ist wieviel prozent an limit mit basis tissue 1710 // gradient ist wieviel prozent an limit mit basis tissue
1617 // dh. 0% = respiration == tissue 1711 // dh. 0% = respiration == tissue
1618 // dh. 100% = respiration == limit 1712 // dh. 100% = respiration == limit
1654 } // calc relative gradient factor 1748 } // calc relative gradient factor
1655 else 1749 else
1656 { 1750 {
1657 char_O_relative_gradient_GF = char_O_gradient_factor; 1751 char_O_relative_gradient_GF = char_O_gradient_factor;
1658 } 1752 }
1659 } // calc_gradient 1753 }
1660 1754
1661 // ------------------------------ 1755 //////////////////////////////////////////////////////////////////////////////
1662 // deco_calc_desaturation_time // 1756 // deco_calc_desaturation_time
1663 // ------------------------------ 1757 //
1664 // FIXED N2_ratio 1758 // FIXED N2_ratio
1665 // unchanged in v.101 1759 // unchanged in v.101
1666 1760 //
1667 void deco_calc_desaturation_time(void) 1761 void deco_calc_desaturation_time(void)
1668 { 1762 {
1763 overlay int desat_time; // For a particular compartiment, in min.
1764
1669 RESET_C_STACK 1765 RESET_C_STACK
1670 1766
1671 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann 1767 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann
1672 pres_surface = (float)int_I_pres_surface / 1000.0; 1768 pres_surface = (float)int_I_pres_surface / 1000.0;
1673 temp_atem = N2_ratio * (pres_surface - 0.0627); 1769 temp_atem = N2_ratio * (pres_surface - 0.0627);
1675 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1771 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1676 1772
1677 for (ci=0;ci<16;ci++) 1773 for (ci=0;ci<16;ci++)
1678 { 1774 {
1679 var_N2_halftime = buhlmann_ht[ci]; 1775 var_N2_halftime = buhlmann_ht[ci];
1680 var_He_halftime = buhlmann_ht[ci + 16]; 1776 var_He_halftime = (buhlmann_ht+16)[ci];
1681 1777
1682 // saturation_time (for flight) and N2_saturation in multiples of halftime 1778 // saturation_time (for flight) and N2_saturation in multiples of halftime
1683 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1779 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time )
1684 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1780 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time )
1685 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations 1781 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations
1707 temp1 = 0; 1803 temp1 = 0;
1708 temp2 = 0; 1804 temp2 = 0;
1709 } 1805 }
1710 1806
1711 // He 1807 // He
1712 temp3 = 0.1 - pres_tissue[ci+16]; 1808 temp3 = 0.1 - (pres_tissue+16)[ci];
1713 if (temp3 >= 0.0) 1809 if (temp3 >= 0.0)
1714 { 1810 {
1715 temp3 = 0; 1811 temp3 = 0;
1716 temp4 = 0; 1812 temp4 = 0;
1717 } 1813 }
1718 else 1814 else
1719 temp3 = -1.0 * temp3 / pres_tissue[ci+16]; 1815 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci];
1720 if (temp3 > 0.0) 1816 if (temp3 > 0.0)
1721 { 1817 {
1722 temp3 = log(1.0 - temp3); 1818 temp3 = log(1.0 - temp3);
1723 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. 1819 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary.
1724 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1820 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1731 temp4 = 0; 1827 temp4 = 0;
1732 } 1828 }
1733 1829
1734 // saturation_time (for flight) 1830 // saturation_time (for flight)
1735 if (temp4 > temp2) 1831 if (temp4 > temp2)
1736 int_temp = (int)temp4; 1832 desat_time = (int)temp4;
1737 else 1833 else
1738 int_temp = (int)temp2; 1834 desat_time = (int)temp2;
1739 if(int_temp > int_O_desaturation_time) 1835 if(desat_time > int_O_desaturation_time)
1740 int_O_desaturation_time = int_temp; 1836 int_O_desaturation_time = desat_time;
1741 1837
1742 // N2 saturation in multiples of halftime for display purposes 1838 // N2 saturation in multiples of halftime for display purposes
1743 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 1839 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8
1744 temp2 = temp2 + 80.0; // set center 1840 temp2 = temp2 + 80.0; // set center
1745 if (temp2 < 0.0) 1841 if (temp2 < 0.0)
1752 temp4 = temp4 + 80.0; // set center 1848 temp4 = temp4 + 80.0; // set center
1753 if (temp4 < 0.0) 1849 if (temp4 < 0.0)
1754 temp4 = 0.0; 1850 temp4 = 0.0;
1755 if (temp4 > 255.0) 1851 if (temp4 > 255.0)
1756 temp4 = 255.0; 1852 temp4 = 255.0;
1757 char_O_tissue_saturation[ci+16] = (char)temp4; 1853 (char_O_tissue_saturation+16)[ci] = (char)temp4;
1758 } // for 1854 } // for
1759 } // deco_calc_desaturation_time 1855 }
1760 1856
1761 1857 //////////////////////////////////////////////////////////////////////////////
1762 // -------------------------- 1858 // calc_wo_deco_step_1_min
1763 // calc_wo_deco_step_1_min // 1859 //
1764 // --------------------------
1765 // FIXED N2 Ratio 1860 // FIXED N2 Ratio
1766 // optimized in v.101 (...saturation_multiplier) 1861 // optimized in v.101 (...saturation_multiplier)
1767 // desaturation slowed down to 70,42% 1862 // desaturation slowed down to 70,42%
1768 1863 //
1769 void calc_wo_deco_step_1_min(void) 1864 static void calc_wo_deco_step_1_min(void)
1770 { 1865 {
1771 if(flag_in_divemode) 1866 if(flag_in_divemode)
1772 { 1867 {
1773 flag_in_divemode = 0; 1868 flag_in_divemode = 0;
1774 set_dbg_end_of_dive(); 1869 set_dbg_end_of_dive();
1781 temp2_atem = 0.0; 1876 temp2_atem = 0.0;
1782 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does not use the N2_ratio 1877 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does not use the N2_ratio
1783 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1878 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1784 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; 1879 float_saturation_multiplier = char_I_saturation_multiplier / 100.0;
1785 1880
1786 calc_tissue_step_1_min(); // update the pressure in the 16 tissues in accordance with the new ambient pressure 1881 calc_tissue_1_min(); // update the pressure in the 32 tissues in accordance with the new ambient pressure
1882
1787 clear_decoarray(); 1883 clear_decoarray();
1788 char_O_deco_status = 0; 1884 char_O_deco_status = 0;
1789 char_O_nullzeit = 0; 1885 char_O_nullzeit = 0;
1790 char_O_ascenttime = 0; 1886 char_O_ascenttime = 0;
1791 calc_gradient_factor(); 1887 calc_gradient_factor();
1792 1888 }
1793 } // calc_wo_deco_step_1_min(void) 1889
1794 1890 //////////////////////////////////////////////////////////////////////////////
1795 1891 //////////////////////////////////////////////////////////////////////////////
1796 // ------------------------- 1892 ////////////////////////////////// deco_hash /////////////////////////////////
1797 // calc_tissue_step_1_min // 1893 //////////////////////////////////////////////////////////////////////////////
1798 // ------------------------- 1894 //////////////////////////////////////////////////////////////////////////////
1799 // optimized in v.101 1895
1800
1801 void calc_tissue_step_1_min(void)
1802 {
1803 char_O_gtissue_no = 255;
1804 pres_gtissue_limit = 0.0;
1805
1806 for (ci=0;ci<16;ci++)
1807 {
1808 read_buhlmann_compartment(1); // 1 minute interval
1809
1810 // N2 1 min
1811 temp_tissue = (temp_atem - pres_tissue[ci]) * var_N2_e;
1812 temp_tissue_safety();
1813 pres_tissue[ci] = pres_tissue[ci] + temp_tissue;
1814
1815 // He 1 min
1816 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var_He_e;
1817 temp_tissue_safety();
1818 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue;
1819
1820 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16];
1821 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * pres_tissue[ci+16]) / temp_tissue;
1822 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * pres_tissue[ci+16]) / temp_tissue;
1823 pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
1824 if (pres_tissue_limit[ci] < 0)
1825 pres_tissue_limit[ci] = 0;
1826 if (pres_tissue_limit[ci] > pres_gtissue_limit)
1827 {
1828 pres_gtissue_limit = pres_tissue_limit[ci];
1829 char_O_gtissue_no = ci;
1830 }//if
1831 } // for
1832 } // calc wo deco 1min
1833
1834 // ----------
1835 // deco_hash //
1836 // ----------
1837 void deco_hash(void) 1896 void deco_hash(void)
1838 { 1897 {
1898 overlay unsigned char md_i, md_j; // Loop index.
1899 overlay unsigned char md_t;
1900 overlay unsigned char md_buffer[16];
1901 overlay unsigned char md_temp;
1902 overlay unsigned int md_pointer;
1903
1839 RESET_C_STACK 1904 RESET_C_STACK
1840 1905
1841 // init 1906 // init
1842 for(md_i=0;md_i<16;md_i++) 1907 for(md_i=0;md_i<16;md_i++)
1843 { 1908 {
1844 md_state[md_i] = 0; 1909 md_state[md_i] = 0;
1845 char_O_hash[md_i] = 0; 1910 char_O_hash[md_i] = 0;
1846 } // for md_i 16 1911 } // for md_i 16
1847 1912
1848 _asm 1913 _asm
1849 movlw 0x01 // md_pi address. 1914 movlw 0x01 // md_pi address.
1850 movwf TBLPTRU,0 1915 movwf TBLPTRU,0
1851 movlw 0x06 1916 movlw 0x7E
1852 movwf TBLPTRH,0 1917 movwf TBLPTRH,0
1853 movlw 0x00 1918 movlw 0x00
1854 movwf TBLPTRL,0 1919 movwf TBLPTRL,0
1855 _endasm; 1920 _endasm;
1856 md_i = 0; 1921 md_i = 0;
1857 do { 1922 do {
1858 _asm 1923 _asm
1859 TBLRDPOSTINC 1924 TBLRDPOSTINC
1861 _endasm 1926 _endasm
1862 md_pi_subst[md_i++] = md_temp; 1927 md_pi_subst[md_i++] = md_temp;
1863 } while( md_i != 0 ); 1928 } while( md_i != 0 );
1864 1929
1865 _asm 1930 _asm
1866 movlw 0x00 1931 movlw 0x00
1867 movwf TBLPTRU,0 1932 movwf TBLPTRU,0
1868 movlw 0x00 1933 movlw 0x00
1869 movwf TBLPTRH,0 1934 movwf TBLPTRH,0
1870 movlw 0x00 1935 movlw 0x00
1871 movwf TBLPTRL,0 1936 movwf TBLPTRL,0
1872 _endasm 1937 _endasm
1938
1873 // cycle buffers 1939 // cycle buffers
1874 for (md_pointer=0x0000;md_pointer<0x17f3;md_pointer++) 1940 for (md_pointer=0x0000;md_pointer<0x17f3;md_pointer++)
1875 { 1941 {
1876 md_t = 0; 1942 md_t = 0;
1877 for (md_i=0;md_i<16;md_i++) 1943 for (md_i=0;md_i<16;md_i++)
1879 if(md_pointer == 9) 1945 if(md_pointer == 9)
1880 md_temp = char_O_hash[md_i]; 1946 md_temp = char_O_hash[md_i];
1881 else 1947 else
1882 { 1948 {
1883 _asm 1949 _asm
1884 TBLRDPOSTINC 1950 TBLRDPOSTINC
1885 movff TABLAT,md_temp 1951 movff TABLAT,md_temp
1886 _endasm 1952 _endasm
1887 } // else 1953 } // else
1888 md_buffer[md_i] = md_temp; 1954
1955 md_buffer[md_i] = md_temp;
1889 md_state[md_i+16] = md_buffer[md_i]; 1956 md_state[md_i+16] = md_buffer[md_i];
1890 md_state[md_i+32] = (unsigned char)(md_buffer[md_i] ^ md_state[md_i]); 1957 md_state[md_i+32] = (unsigned char)(md_buffer[md_i] ^ md_state[md_i]);
1891 } // for md_i 16 1958 } // for md_i 16
1892 1959
1893 for (md_i=0;md_i<18;md_i++) 1960 for (md_i=0;md_i<18;md_i++)
1894 { 1961 {
1895 for (md_j=0;md_j<48;md_j++) 1962 for (md_j=0;md_j<48;md_j++)
1896 { 1963 {
1897 md_state[md_j] = (unsigned char)(md_state[md_j] ^ md_pi_subst[md_t]); 1964 md_state[md_j] ^= md_pi_subst[md_t];
1898 md_t = md_state[md_j]; 1965 md_t = md_state[md_j];
1899 } // for md_j 48 1966 } // for md_j 48
1900 md_t = (unsigned char)(md_t+1); 1967 md_t = (unsigned char)(md_t+1);
1901 } // for md_i 18 1968 } // for md_i 18
1902 md_t = char_O_hash[15]; 1969 md_t = char_O_hash[15];
1903 1970
1904 for (md_i=0;md_i<16;md_i++) 1971 for (md_i=0;md_i<16;md_i++)
1905 { 1972 {
1906 char_O_hash[md_i] = (unsigned char)(char_O_hash[md_i] ^ md_pi_subst[(md_buffer[md_i] ^ md_t)]); 1973 char_O_hash[md_i] ^= md_pi_subst[(md_buffer[md_i] ^ md_t)];
1907 md_t = char_O_hash[md_i]; 1974 md_t = char_O_hash[md_i];
1908 } // for md_i 16 1975 } // for md_i 16
1909 } // for md_pointer 1976 } // for md_pointer
1910 } // void deco_hash(void) 1977 } // void deco_hash(void)
1911 1978
1912 // --------------------- 1979 //////////////////////////////////////////////////////////////////////////////
1913 // deco_clear_CNS_fraction // 1980 // deco_clear_CNS_fraction
1914 // --------------------- 1981 //
1915 // new in v.101 1982 // new in v.101
1916 1983 //
1917 void deco_clear_CNS_fraction(void) 1984 void deco_clear_CNS_fraction(void)
1918 { 1985 {
1919 RESET_C_STACK 1986 RESET_C_STACK
1920 CNS_fraction = 0.0; 1987 CNS_fraction = 0.0;
1921 char_O_CNS_fraction = 0; 1988 char_O_CNS_fraction = 0;
1922 } // void deco_clear_CNS_fraction(void) 1989 }
1923 1990
1924 1991 //////////////////////////////////////////////////////////////////////////////
1925 // ------------------------- 1992 // deco_calc_CNS_fraction
1926 // deco_calc_CNS_fraction // 1993 //
1927 // -------------------------
1928 // new in v.101 1994 // new in v.101
1929 // optimized in v.102 : with new variables char_I_actual_ppO2 and actual_ppO2 1995 // optimized in v.102 : with new variables char_I_actual_ppO2 and actual_ppO2
1930 1996 //
1931 // Input: char_I_actual_ppO2 1997 // Input: char_I_actual_ppO2
1932 // Output: char_O_CNS_fraction 1998 // Output: char_O_CNS_fraction
1933 // Uses and Updates: CNS_fraction 1999 // Uses and Updates: CNS_fraction
1934 // Uses: acutal_ppO2 2000 // Uses: acutal_ppO2
1935 2001 //
1936 void deco_calc_CNS_fraction(void) 2002 void deco_calc_CNS_fraction(void)
1937 { 2003 {
2004 overlay float actual_ppO2;
1938 RESET_C_STACK 2005 RESET_C_STACK
2006
1939 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; 2007 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0;
1940 2008
1941 if (char_I_actual_ppO2 < 50) 2009 if (char_I_actual_ppO2 < 50)
1942 CNS_fraction = CNS_fraction;// no changes 2010 CNS_fraction = CNS_fraction;// no changes
1943 else if (char_I_actual_ppO2 < 60) 2011 else if (char_I_actual_ppO2 < 60)
1979 CNS_fraction = 2.5; 2047 CNS_fraction = 2.5;
1980 if (CNS_fraction < 0.0) 2048 if (CNS_fraction < 0.0)
1981 CNS_fraction = 0.0; 2049 CNS_fraction = 0.0;
1982 2050
1983 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); 2051 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0);
1984 } // void deco_calc_CNS_fraction(void) 2052 }
1985 2053
1986 // ------------------------------- 2054 //////////////////////////////////////////////////////////////////////////////
1987 // deco_calc_CNS_decrease_15min // 2055 // deco_calc_CNS_decrease_15min
1988 // ------------------------------- 2056 //
1989 // new in v.101 2057 // new in v.101
1990 2058 //
1991 // calculates the half time of 90 minutes in 6 steps of 15 min 2059 // calculates the half time of 90 minutes in 6 steps of 15 min
1992 2060 //
1993 // Output: char_O_CNS_fraction 2061 // Output: char_O_CNS_fraction
1994 // Uses and Updates: CNS_fraction 2062 // Uses and Updates: CNS_fraction
1995 2063 //
1996 void deco_calc_CNS_decrease_15min(void) 2064 void deco_calc_CNS_decrease_15min(void)
1997 { 2065 {
1998 RESET_C_STACK 2066 RESET_C_STACK
1999 CNS_fraction = 0.890899 * CNS_fraction; 2067 CNS_fraction = 0.890899 * CNS_fraction;
2000 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); 2068 char_O_CNS_fraction = (char)(CNS_fraction * 100.0 + 0.5);
2001 }// deco_calc_CNS_decrease_15min(void) 2069 }
2002 2070
2003 2071 //////////////////////////////////////////////////////////////////////////////
2004 // ----------------------- 2072 // deco_calc_percentage
2005 // deco_calc_percentage // 2073 //
2006 // -----------------------
2007 // new in v.101 2074 // new in v.101
2008 2075 //
2009 // calculates int_I_temp * char_I_temp / 100 2076 // calculates int_I_temp * char_I_temp / 100
2010 // output is int_I_temp 2077 // output is int_I_temp
2011 2078
2012 void deco_calc_percentage(void) 2079 void deco_calc_percentage(void)
2013 { 2080 {
2016 temp2 = (float)char_I_temp / 100.0; 2083 temp2 = (float)char_I_temp / 100.0;
2017 temp3 = temp1 * temp2; 2084 temp3 = temp1 * temp2;
2018 int_I_temp = (int)temp3; 2085 int_I_temp = (int)temp3;
2019 } 2086 }
2020 2087
2088 //////////////////////////////////////////////////////////////////////////////
2089
2021 void deco_push_tissues_to_vault(void) 2090 void deco_push_tissues_to_vault(void)
2022 { 2091 {
2092 overlay unsigned char x;
2023 RESET_C_STACK 2093 RESET_C_STACK
2094
2024 cns_vault = CNS_fraction; 2095 cns_vault = CNS_fraction;
2025 for (ci=0;ci<32;ci++) 2096 for (x=0;x<32;x++)
2026 pres_tissue_vault[ci] = pres_tissue[ci]; 2097 pres_tissue_vault[x] = pres_tissue[x];
2027 } 2098 }
2099
2028 void deco_pull_tissues_from_vault(void) 2100 void deco_pull_tissues_from_vault(void)
2029 { 2101 {
2102 overlay unsigned char x;
2030 RESET_C_STACK 2103 RESET_C_STACK
2104
2031 CNS_fraction = cns_vault; 2105 CNS_fraction = cns_vault;
2032 for (ci=0;ci<32;ci++) 2106 for (x=0;x<32;x++)
2033 pres_tissue[ci] = pres_tissue_vault[ci]; 2107 pres_tissue[x] = pres_tissue_vault[x];
2034 } 2108 }
2035 2109
2110 //////////////////////////////////////////////////////////////////////////////
2111 //
2036 void main() {} 2112 void main() {}