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