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