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