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