Mercurial > public > mk2
comparison code_part1/OSTC_code_c_part2/p2_deco_main.c @ 0:96a35aeda5f2
Initial setup
author | heinrichsweikamp |
---|---|
date | Tue, 12 Jan 2010 15:05:59 +0100 |
parents | |
children | 3691ea95a34d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:96a35aeda5f2 |
---|---|
1 /* | |
2 * p2_deco_main.c | |
3 * | |
4 * Created on: 31.08.2009 | |
5 * Author: christian.w @ heinrichsweikamp.com | |
6 * | |
7 */ | |
8 | |
9 //#include <p2_deco_header_c_v102d.h> | |
10 | |
11 // OSTC - diving computer code | |
12 // Copyright (C) 2009 HeinrichsWeikamp GbR | |
13 | |
14 // This program is free software: you can redistribute it and/or modify | |
15 // it under the terms of the GNU General Public License as published by | |
16 // the Free Software Foundation, either version 3 of the License, or | |
17 // (at your option) any later version. | |
18 | |
19 // This program is distributed in the hope that it will be useful, | |
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 // GNU General Public License for more details. | |
23 | |
24 // You should have received a copy of the GNU General Public License | |
25 // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
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/090 v107: integration of FONT Incon24 | |
63 | |
64 // | |
65 // literature: | |
66 // B"uhlmann, Albert: Tauchmedizin; 4. Auflage; | |
67 // 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 | |
68 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html | |
69 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf | |
70 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops" | |
71 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf | |
72 | |
73 | |
74 // ********************* | |
75 // ** I N C L U D E S ** | |
76 // ********************* | |
77 #include <p18f4685.h> | |
78 #include <math.h> | |
79 | |
80 // ******************************** | |
81 // ** C O N F I G U R A T I O N ** | |
82 // ** for simulation without asm ** | |
83 // ******************************** | |
84 #pragma config OSC = IRCIO67 | |
85 #pragma config FCMEN = OFF | |
86 #pragma config IESO = OFF | |
87 #pragma config PWRT = ON | |
88 #pragma config BOREN = OFF | |
89 #pragma config WDT = OFF | |
90 #pragma config WDTPS = 128 | |
91 #pragma config MCLRE = ON | |
92 #pragma config LPT1OSC = OFF | |
93 #pragma config PBADEN = OFF | |
94 #pragma config DEBUG = OFF | |
95 #pragma config XINST = OFF | |
96 #pragma config LVP = OFF | |
97 #pragma config STVREN = OFF | |
98 | |
99 // **************************** | |
100 // ** D E F I N E S ** | |
101 // ** missing in p18f4685.h ** | |
102 // **************************** | |
103 /* | |
104 #define INT0IF 1 | |
105 #define INT1IF 0 | |
106 #define TMR1IF 0 | |
107 */ | |
108 | |
109 # define DBG_c_gas 0b0000000000000001 | |
110 # define DBG_c_ppO2 0b0000000000000010 | |
111 # define DBG_RUN 0b0000000000000100 | |
112 # define DBG_RESTART 0b0000000000001000 | |
113 | |
114 # define DBG_CdeSAT 0b0000000000010000 | |
115 # define DBG_C_MODE 0b0000000000100000 | |
116 # define DBG_C_SURF 0b0000000001000000 | |
117 # define DBG_HEwoHE 0b0000000010000000 | |
118 | |
119 # define DBG_C_DPPO2 0b0000000100000000 | |
120 # define DBG_C_DGAS 0b0000001000000000 | |
121 # define DBG_C_DIST 0b0000010000000000 | |
122 # define DBG_C_LAST 0b0000100000000000 | |
123 | |
124 # define DBG_C_GF 0b0001000000000000 | |
125 # define DBG_ZH16ERR 0b0010000000000000 | |
126 # define DBG_PHIGH 0b0100000000000000 | |
127 # define DBG_PLOW 0b1000000000000000 | |
128 | |
129 | |
130 # define DBS_mode 0b0000000000000001 | |
131 # define DBS_ppO2 0b0000000000000010 | |
132 # define DBS_HE_sat 0b0000000000000100 | |
133 # define DBS_ppO2chg 0b0000000000001000 | |
134 | |
135 # define DBS_SAT2l 0b0000000000010000 | |
136 # define DBS_SAT2h 0b0000000000100000 | |
137 # define DBS_GFLOW2l 0b0000000001000000 | |
138 # define DBS_GFLOW2h 0b0000000010000000 | |
139 | |
140 # define DBS_GFHGH2l 0b0000000100000000 | |
141 # define DBS_GFHGH2h 0b0000001000000000 | |
142 # define DBS_GASO22l 0b0000010000000000 | |
143 # define DBS_GASO22h 0b0000100000000000 | |
144 | |
145 # define DBS_DIST2h 0b0001000000000000 | |
146 # define DBS_LAST2h 0b0010000000000000 | |
147 # define DBS_DECOO2l 0b0100000000000000 | |
148 # define DBS_DECOO2h 0b1000000000000000 | |
149 | |
150 | |
151 # define DBS2_PRES2h 0b0000000000000001 | |
152 # define DBS2_PRES2l 0b0000000000000010 | |
153 # define DBS2_SURF2l 0b0000000000000100 | |
154 # define DBS2_SURF2h 0b0000000000001000 | |
155 | |
156 # define DBS2_DESAT2l 0b0000000000010000 | |
157 # define DBS2_DESAT2h 0b0000000000100000 | |
158 # define DBS2_GFDneg 0b0000000001000000 | |
159 # define DBS2_ 0b000000000000000 | |
160 | |
161 # define DBS2_ 0b000000000000000 | |
162 # define DBS2_ 0b000000000000000 | |
163 # define DBS2_ 0b000000000000000 | |
164 # define DBS2_ 0b000000000000000 | |
165 | |
166 // NDL_at_20mtr | |
167 | |
168 | |
169 | |
170 // *********************** | |
171 // ** V A R I A B L E S ** | |
172 // *********************** | |
173 // prefixes etc: | |
174 // _O_ = output for use in the assembler code | |
175 // _I_ = input from the assembler code for the c code | |
176 // char_ and int_ = used to identify output and input size | |
177 // var = variable (from b"uhlmann) | |
178 // pres = pressure | |
179 // gtissue = guiding tissue, the one limiting the ascent | |
180 // e2secs = exp of the b"uhlmann formula precalculated for a 2 second step | |
181 // e1min = same for 1 minute step | |
182 // sim = used in simulating the ascent to the surface | |
183 // nullzeit = remaining ground/bottom time for "no deco" | |
184 // hauptroutine = main | |
185 | |
186 #define WP_FONT_SMALL_HEIGHT 24 | |
187 #define WP_FONT_MEDIUM_HEIGHT 32 | |
188 #define WP_FONT_LARGE_HEIGHT 58 | |
189 | |
190 #define oled_rw PORTA,2,0 | |
191 #define oled_rs PORTE,0,0 | |
192 | |
193 #define U8 unsigned char | |
194 #define U16 unsigned int | |
195 | |
196 // IO assembler | |
197 #pragma udata bank0a=0x060 | |
198 volatile unsigned char wp_stringstore[26]; | |
199 volatile U8 wp_color1; | |
200 volatile U8 wp_color2; | |
201 volatile U8 wp_top; | |
202 volatile U8 wp_leftx2; | |
203 volatile U8 wp_font; | |
204 volatile U8 wp_invert; | |
205 volatile U8 wp_temp_U8; | |
206 // internal C | |
207 #pragma udata bank0b=0x081 | |
208 volatile U8 wp_txtptr; | |
209 volatile unsigned char wp_char; | |
210 volatile U8 wp_command; | |
211 volatile U16 wp_data_16bit; | |
212 volatile U8 wp_data_8bit_one; | |
213 volatile U8 wp_data_8bit_two; | |
214 volatile U16 wp_start; | |
215 volatile U16 wp_end; | |
216 volatile U16 wp_i; | |
217 volatile U8 wp_black; | |
218 // some spare | |
219 volatile U8 wp_debug_U8; | |
220 | |
221 // asm only | |
222 #pragma udata bank0c=0x0D0 | |
223 #define LENGTH_kf_bank0 48 | |
224 volatile unsigned char keep_free_bank0[LENGTH_kf_bank0]; | |
225 | |
226 | |
227 #pragma udata bank1=0x100 | |
228 #define LENGTH_kf_bank1 256 | |
229 volatile unsigned char keep_free_bank1[LENGTH_kf_bank1]; // used by the assembler code | |
230 | |
231 #pragma udata bank2a=0x200 | |
232 // output: | |
233 static unsigned int int_O_tissue_for_debug[32]; | |
234 static unsigned int int_O_GF_spare____; // 0x240 | |
235 static unsigned int int_O_GF_step; // 0x242 | |
236 static unsigned int int_O_gtissue_limit; // 0x244 | |
237 static unsigned int int_O_gtissue_press; // 0x246 | |
238 static unsigned int int_O_limit_GF_low; // 0x248 | |
239 static unsigned int int_O_gtissue_press_at_GF_low; // 0x24A | |
240 // 0x24C + 0x24D noch unbenutzt | |
241 | |
242 #pragma udata bank2b=0x24E | |
243 static unsigned char char_O_GF_low_pointer; // 0x24E | |
244 static unsigned char char_O_actual_pointer; // 0x24F | |
245 #pragma udata bank2c=0x250 | |
246 static unsigned char char_O_deco_table[32]; // 0x250 | |
247 #pragma udata bank2d=0x270 | |
248 static unsigned char char_I_table_deco_done[32]; | |
249 #pragma udata bank2e=0x290 | |
250 static unsigned int int_O_calc_tissue_call_counter; // 0x290 | |
251 // internal: | |
252 unsigned char lock_GF_depth_list; | |
253 static float temp_limit; | |
254 static float GF_low; | |
255 static float GF_high; | |
256 static float GF_delta; | |
257 static float GF_temp; | |
258 static float GF_step; | |
259 static float GF_step2; | |
260 static float temp_pres_gtissue; | |
261 static float temp_pres_gtissue_diff; | |
262 static float temp_pres_gtissue_limit_GF_low; | |
263 static float temp_pres_gtissue_limit_GF_low_below_surface; | |
264 static unsigned int temp_depth_limit; | |
265 static unsigned char temp_decotime; | |
266 static unsigned char temp_gtissue_no; | |
267 static unsigned int temp_depth_last_deco; // new in v.101 | |
268 | |
269 static unsigned char temp_depth_GF_low_meter; | |
270 static unsigned char temp_depth_GF_low_number; | |
271 static unsigned char internal_deco_pointer; | |
272 static unsigned char internal_deco_table[32]; | |
273 static float temp_pres_deco_GF_low; | |
274 | |
275 static unsigned int debug_temp; | |
276 | |
277 | |
278 #pragma udata bank3a=0x300 | |
279 static char output[32]; | |
280 // used by the math routines | |
281 #pragma udata bank3b=0x380 | |
282 volatile float pres_tissue_vault[32]; | |
283 #pragma udata bank4a=0x400 | |
284 // internal: | |
285 unsigned char ci ; // don't move - used in _asm routines - if moved then modify movlb commands | |
286 unsigned char x; | |
287 unsigned int main_i; | |
288 unsigned int int_temp; | |
289 unsigned int int_temp_decostatus; | |
290 static float pres_respiration; | |
291 static float pres_surface; | |
292 static float temp1; | |
293 static float temp2; | |
294 static float temp3; | |
295 static float temp4; | |
296 static float temp_deco; | |
297 static float temp_atem; | |
298 static float temp2_atem; | |
299 static float temp_tissue; | |
300 static float temp_surface; | |
301 static float N2_ratio; | |
302 static float He_ratio; | |
303 static float temp_ratio; | |
304 static float var_a; | |
305 static float var2_a; | |
306 static float var_b; | |
307 static float var2_b; | |
308 static float var_t05nc; | |
309 static float var2_t05nc; | |
310 static float var_e2secs; | |
311 static float var2_e2secs; | |
312 static float var_e1min; | |
313 static float var2_e1min; | |
314 static float var_halftimes; | |
315 static float var2_halftimes; | |
316 static float pres_gtissue_limit; | |
317 static float temp_pres_gtissue_limit; | |
318 static float actual_ppO2; // new in v.102 | |
319 #pragma udata bank4b=0x480 | |
320 static float pres_tissue[32]; | |
321 | |
322 #pragma udata bank5=0x500 | |
323 // don't move positions in this bank, the registers are addressed directly from assembler code | |
324 // input: | |
325 static unsigned int int_I_pres_respiration; // 0x500 | |
326 static unsigned int int_I_pres_surface; // 0x502 | |
327 static unsigned int int_I_temp; // 0x504 new in v101 | |
328 static unsigned char char_I_temp; // 0x506 new in v101 | |
329 static unsigned char char_I_actual_ppO2; // 0x507 | |
330 static unsigned int int_I_spare_3; | |
331 static unsigned int int_I_spare_4; | |
332 static unsigned int int_I_spare_5; | |
333 static unsigned int int_I_spare_6; | |
334 static unsigned char char_I_N2_ratio; // 0x510 | |
335 static unsigned char char_I_He_ratio; // 0x511 | |
336 static unsigned char char_I_saturation_multiplier; // for conservatism/safety values 1.0 (no conservatism) to 1.5 (50% faster saturation | |
337 static 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() | |
338 static unsigned char char_I_GF_High_percentage; // 0x514 new in v.102 | |
339 static unsigned char char_I_GF_Low_percentage; // 0x515 new in v.102 | |
340 static unsigned char char_I_spare; // 0x516 | |
341 static unsigned char char_I_deco_distance; // 0x517 | |
342 static unsigned char char_I_const_ppO2; // 0x518 new in v.101 | |
343 static unsigned char char_I_deco_ppO2_change; // 0x519 new in v.101 | |
344 static unsigned char char_I_deco_ppO2; // 0x51A new in v.101 | |
345 static unsigned char char_I_deco_gas_change; // 0x51B new in v.101 | |
346 static unsigned char char_I_deco_N2_ratio; // 0x51C new in v.101 | |
347 static unsigned char char_I_deco_He_ratio; // 0x51D new in v.101 | |
348 static unsigned char char_I_depth_last_deco; // 0x51E new in v.101 unit: [m] | |
349 static unsigned char char_I_deco_model; // 0x51F new in v.102 ( 1 = MultiGraF, sonst Std. mit (de-)saturation_multiplier) | |
350 // output: | |
351 static unsigned int int_O_desaturation_time; // 0x520 | |
352 static unsigned char char_O_nullzeit; // 0x522 | |
353 static unsigned char char_O_deco_status; // 0x523 | |
354 static unsigned char char_O_array_decotime[7]; // 0x524 | |
355 static unsigned char char_O_array_decodepth[6]; // 0x52B | |
356 static unsigned char char_O_ascenttime; // 0x531 | |
357 static unsigned char char_O_gradient_factor; // 0x532 | |
358 static unsigned char char_O_tissue_saturation[32]; // 0x533 | |
359 static unsigned char char_O_array_gradient_weighted[16]; // 0x553 | |
360 static unsigned char char_O_gtissue_no; // 0x563 | |
361 static unsigned char char_O_diluent; // 0x564 new in v.101 | |
362 static unsigned char char_O_CNS_fraction; // 0x565 new in v.101 | |
363 static unsigned char char_O_relative_gradient_GF; // 0x566 new in v.102 | |
364 | |
365 // internal: | |
366 static float pres_tissue_limit[16]; | |
367 static float sim_pres_tissue_limit[16]; | |
368 static float pres_diluent; // new in v.101 | |
369 static float deco_diluent; // new in v.101 | |
370 static float const_ppO2; // new in v.101 | |
371 static float deco_ppO2_change; // new in v.101 | |
372 static float deco_ppO2; // new in v.101 | |
373 | |
374 | |
375 | |
376 #pragma udata bank6=0x600 | |
377 // internal: | |
378 static float sim_pres_tissue[32]; | |
379 static float sim_pres_tissue_backup[32]; | |
380 | |
381 //#pragma udata bank7=0x700 | |
382 //const unsigned char keep_free_bank7[256]; // used by the assembler code (DD font2display) | |
383 | |
384 #pragma udata bank8=0x800 | |
385 static char md_pi_subst[256]; | |
386 | |
387 #pragma udata bank9a=0x900 | |
388 // output: | |
389 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! | |
390 #pragma udata bank9b=0x930 | |
391 // output: | |
392 static unsigned int int_O_DBS_bitfield; // 0x930 new in v.108 | |
393 static unsigned int int_O_DBS2_bitfield; // 0x932 new in v.108 | |
394 static unsigned int int_O_DBG_pre_bitfield; // 0x934 new in v.108 | |
395 static unsigned int int_O_DBG_post_bitfield; // 0x936 new in v.108 | |
396 static char char_O_NDL_at_20mtr; // 0x938 new in v.108 // 0xFF == undefined, max. 254 | |
397 // internal: | |
398 static char md_t; | |
399 static char md_buffer[16]; | |
400 static char md_cksum[16]; | |
401 static char md_i; | |
402 static char md_j; | |
403 static char md_temp; | |
404 static unsigned int md_pointer; | |
405 static float deco_N2_ratio; // new in v.101 | |
406 static float deco_He_ratio; // new in v.101 | |
407 static float calc_N2_ratio; // new in v.101 | |
408 static float calc_He_ratio; // new in v.101 | |
409 static float deco_gas_change; // new in v.101 | |
410 static float CNS_fraction; // new in v.101 | |
411 static float float_saturation_multiplier; // new in v.101 | |
412 static float float_desaturation_multiplier; // new in v.101 | |
413 static float float_deco_distance; // new in v.101 | |
414 // internal, dbg: | |
415 static unsigned char DBG_char_I_deco_model; // new in v.108 | |
416 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 | |
417 static float DBG_pres_surface; // new in v.108 | |
418 static float DBG_GF_low; // new in v.108 | |
419 static float DBG_GF_high; // new in v.108 | |
420 static float DBG_const_ppO2; // new in v.108 | |
421 static float DBG_deco_ppO2_change; // new in v.108 | |
422 static float DBG_deco_ppO2; // new in v.108 | |
423 static float DBG_deco_N2_ratio; // new in v.108 | |
424 static float DBG_deco_He_ratio; // new in v.108 | |
425 static float DBG_deco_gas_change; // new in v.108 | |
426 static float DBG_float_saturation_multiplier; // new in v.108 | |
427 static float DBG_float_desaturation_multiplier; // new in v.108 | |
428 static float DBG_float_deco_distance; // new in v.108 | |
429 static float DBG_deco_N2_ratio; // new in v.108 | |
430 static float DBG_deco_He_ratio; // new in v.108 | |
431 static float DBG_N2_ratio; // new in v.108 | |
432 static float DBG_He_ratio; // new in v.108 | |
433 static char flag_in_divemode; // new in v.108 | |
434 static int int_dbg_i; // new in v.108 | |
435 unsigned int temp_DBS; | |
436 | |
437 // ************************* | |
438 // ** P R O T O T Y P E S ** | |
439 // ************************* | |
440 void main_calc_hauptroutine(void); | |
441 void main_calc_without_deco(void); | |
442 void main_clear_tissue(void); | |
443 void main_calc_percentage(void); | |
444 void main_calc_wo_deco_step_1_min(void); | |
445 void main_debug(void); | |
446 void main_gradient_array(void); | |
447 void main_hash(void); | |
448 | |
449 void calc_hauptroutine(void); | |
450 void calc_tissue(void); | |
451 void calc_nullzeit(void); | |
452 void backup_sim_pres_tissue(void); | |
453 void restore_sim_pres_tissue(void); | |
454 | |
455 void calc_without_deco(void); | |
456 void clear_tissue(void); | |
457 void calc_ascenttime(void); | |
458 void update_startvalues(void); | |
459 void clear_decoarray(void); | |
460 void update_decoarray(void); | |
461 void sim_tissue_1min(void); | |
462 void sim_tissue_10min(void); | |
463 void calc_gradient_factor(void); | |
464 void calc_gradient_array_only(void); | |
465 void calc_desaturation_time(void); | |
466 void calc_wo_deco_step_1_min(void); | |
467 void calc_tissue_step_1_min(void); | |
468 void hash(void); | |
469 void clear_CNS_fraction(void); | |
470 void calc_CNS_fraction(void); | |
471 void calc_CNS_decrease_15min(void); | |
472 void calc_percentage(void); | |
473 void main(void); | |
474 void calc_hauptroutine_data_input(void); | |
475 void calc_hauptroutine_update_tissues(void); | |
476 void calc_hauptroutine_calc_deco(void); | |
477 void calc_hauptroutine_calc_ascend_to_deco(void); | |
478 void calc_nextdecodepth_GF(void); | |
479 void copy_deco_table_GF(void); | |
480 void clear_internal_deco_table_GF(void); | |
481 void update_internal_deco_table_GF(void); | |
482 void DD2_write(void); | |
483 void DD2_write_incon42(void); | |
484 void DD2_get_pointer_to_char(void); | |
485 void DD2_set_column(void); | |
486 void DD2_load_background(void); | |
487 void DD2_build_one_line_of_char(void); | |
488 void DD2_print_column(void); | |
489 void DD2_CmdWrite(void); | |
490 void DD2_DataWrite(void); | |
491 void push_tissues_to_vault(void); | |
492 void pull_tissues_from_vault(void); | |
493 void main_push_tissues_to_vault(void); | |
494 void main_pull_tissues_from_vault(void); | |
495 void wordprocessor(void); | |
496 | |
497 // ******************************* | |
498 // ** start ** | |
499 // ** necessary for compilation ** | |
500 // ******************************* | |
501 #pragma romdata der_code = 0x0000 | |
502 #pragma code der_start = 0x0000 | |
503 void der_start(void) | |
504 { | |
505 _asm | |
506 goto main | |
507 _endasm | |
508 } | |
509 | |
510 // *********************************** | |
511 // ** main code for simulation / ** | |
512 // ** tests without assembler code ** | |
513 // ** is NOT a part of the OSTC ** | |
514 // *********************************** | |
515 #pragma code main = 0x9000 | |
516 void main(void) | |
517 { | |
518 for(wp_temp_U8=0;wp_temp_U8<LENGTH_kf_bank0 - 1;wp_temp_U8++) | |
519 keep_free_bank0[wp_temp_U8] = 7; | |
520 keep_free_bank0[LENGTH_kf_bank0 - 1] = 7; | |
521 | |
522 for(wp_temp_U8=0;wp_temp_U8<LENGTH_kf_bank1 - 1;wp_temp_U8++) | |
523 keep_free_bank1[wp_temp_U8] = 7; | |
524 keep_free_bank1[LENGTH_kf_bank1 - 1] = 7; | |
525 | |
526 #if 1 | |
527 // new main to test DR-5 | |
528 | |
529 wp_top = 10; | |
530 wp_leftx2 = 10; | |
531 wp_color1 = 255; | |
532 wp_color2 = 255; | |
533 wp_font = 0; | |
534 wp_invert = 0; | |
535 wp_stringstore[0] = ' '; | |
536 wp_stringstore[1] = ' '; | |
537 wp_stringstore[2] = '1'; | |
538 wp_stringstore[3] = ':'; | |
539 wp_stringstore[4] = 0; | |
540 wordprocessor(); | |
541 | |
542 GF_low = 1.0; | |
543 GF_high = 1.0; | |
544 | |
545 GF_temp = GF_low * GF_high; | |
546 | |
547 clear_CNS_fraction(); | |
548 //char_I_const_ppO2 = 100; | |
549 //for (main_i=0;main_i<255;main_i++) | |
550 //{ | |
551 //calc_CNS_fraction(); | |
552 //} //for | |
553 | |
554 | |
555 | |
556 | |
557 int_I_pres_respiration = 1000;//980; | |
558 int_I_pres_surface = 1000;//980; | |
559 char_I_N2_ratio = 39; //38; | |
560 char_I_He_ratio = 40; //50; | |
561 char_I_deco_distance = 0; // 10 = 1 meter | |
562 char_I_depth_last_deco = 3; // values below 3 (meter) are ignored | |
563 | |
564 char_I_const_ppO2 = 0; | |
565 char_I_deco_ppO2_change = 0; // [dm] 10 = 1 meter | |
566 char_I_deco_ppO2 = 0; | |
567 | |
568 char_I_deco_gas_change = 0; // [m] 1 = 1 meter | |
569 char_I_deco_N2_ratio = 0; | |
570 char_I_deco_He_ratio = 0; | |
571 | |
572 //char_I_actual_ppO2; // 0x507 | |
573 char_I_GF_High_percentage = 100; // 0x514 new in v.102 | |
574 char_I_GF_Low_percentage = 100; // 0x515 new in v.102 | |
575 | |
576 char_I_saturation_multiplier = 110; | |
577 char_I_desaturation_multiplier = 90; | |
578 | |
579 char_I_deco_model = 0; | |
580 | |
581 main_clear_tissue(); | |
582 | |
583 int_I_pres_respiration = 1000 + int_I_pres_surface; | |
584 main_calc_wo_deco_step_1_min(); | |
585 int_I_pres_respiration = 3000 + int_I_pres_surface; | |
586 main_calc_wo_deco_step_1_min(); | |
587 int_I_pres_respiration = 5000 + int_I_pres_surface; | |
588 main_calc_wo_deco_step_1_min(); | |
589 | |
590 /* | |
591 int_I_pres_respiration = 6000 + int_I_pres_surface; | |
592 for (main_i=0;main_i<27;main_i++) | |
593 main_calc_wo_deco_step_1_min(); | |
594 */ | |
595 | |
596 char_O_deco_status = 255; | |
597 while (char_O_deco_status) | |
598 main_calc_hauptroutine(); | |
599 _asm | |
600 nop | |
601 _endasm | |
602 | |
603 for (main_i=0;main_i<50;main_i++) | |
604 { | |
605 main_calc_hauptroutine(); | |
606 } | |
607 int_I_pres_respiration = 10000; | |
608 for (main_i=0;main_i<1500;main_i++) | |
609 { | |
610 main_calc_hauptroutine(); | |
611 } | |
612 | |
613 _asm | |
614 nop | |
615 _endasm | |
616 | |
617 | |
618 int_I_pres_respiration = 3000; | |
619 for (main_i=0;main_i<150;main_i++) | |
620 { | |
621 calc_hauptroutine_data_input(); | |
622 calc_hauptroutine_update_tissues(); | |
623 } //for | |
624 | |
625 update_startvalues(); | |
626 clear_decoarray(); | |
627 clear_internal_deco_table_GF(); | |
628 calc_hauptroutine_calc_ascend_to_deco(); | |
629 if (char_O_deco_status > 15) // can't go up to first deco, too deep to calculate in the given time slot | |
630 { | |
631 char_O_deco_status = 2; | |
632 // char_O_lock_depth_list = 255; | |
633 } | |
634 else | |
635 { | |
636 // char_O_lock_depth_list = lock_GF_depth_list; | |
637 calc_hauptroutine_calc_deco(); | |
638 } | |
639 // build_debug_output(); | |
640 | |
641 _asm | |
642 nop | |
643 _endasm | |
644 while (char_O_deco_status == 1) | |
645 { | |
646 char_O_deco_status = 0; | |
647 // char_O_lock_depth_list = 255; | |
648 calc_hauptroutine_calc_deco(); | |
649 // build_debug_output(); | |
650 _asm | |
651 nop | |
652 _endasm | |
653 }; | |
654 debug_temp = 60; // [mtr Aufstieg in 10 mtr/min (30steps'2sec/min] | |
655 int_I_pres_respiration = 9980; | |
656 for (main_i=0;main_i<debug_temp;main_i++) | |
657 { | |
658 int_I_pres_respiration = int_I_pres_respiration - 33; | |
659 calc_hauptroutine_data_input(); | |
660 calc_hauptroutine_update_tissues(); | |
661 int_I_pres_respiration = int_I_pres_respiration - 33; | |
662 calc_hauptroutine_data_input(); | |
663 calc_hauptroutine_update_tissues(); | |
664 int_I_pres_respiration = int_I_pres_respiration - 34; | |
665 calc_hauptroutine_data_input(); | |
666 calc_hauptroutine_update_tissues(); | |
667 } //for | |
668 _asm | |
669 nop | |
670 _endasm | |
671 | |
672 update_startvalues(); | |
673 clear_decoarray(); | |
674 clear_internal_deco_table_GF(); | |
675 calc_hauptroutine_calc_ascend_to_deco(); | |
676 if (char_O_deco_status > 15) // can't go up to first deco, too deep to calculate in the given time slot | |
677 { | |
678 char_O_deco_status = 2; | |
679 // char_O_lock_depth_list = 255; | |
680 } | |
681 else | |
682 { | |
683 // char_O_lock_depth_list = lock_GF_depth_list; | |
684 calc_hauptroutine_calc_deco(); | |
685 } | |
686 // build_debug_output(); | |
687 | |
688 _asm | |
689 nop | |
690 _endasm | |
691 while (char_O_deco_status == 1) | |
692 { | |
693 char_O_deco_status = 0; | |
694 // char_O_lock_depth_list = 255; | |
695 calc_hauptroutine_calc_deco(); | |
696 // build_debug_output(); | |
697 _asm | |
698 nop | |
699 _endasm | |
700 }; | |
701 _asm | |
702 nop | |
703 _endasm | |
704 debug_temp = 60; // [mtr Aufstieg in 10 mtr/min (30steps'2sec/min] | |
705 int_I_pres_respiration = 9980; | |
706 debug_temp = debug_temp * 3; | |
707 for (main_i=0;main_i<debug_temp;main_i++) | |
708 { | |
709 calc_hauptroutine_data_input(); | |
710 calc_hauptroutine_update_tissues(); | |
711 } //for | |
712 _asm | |
713 nop | |
714 _endasm | |
715 #endif | |
716 // ----------------------- | |
717 | |
718 } // main | |
719 | |
720 // ****************************************************** | |
721 // ****************************************************** | |
722 // ** THE FOLLOWING CODE HAS TO BE COPPIED TO THE OSTC ** | |
723 // ****************************************************** | |
724 // ****************************************************** | |
725 | |
726 // *************** | |
727 // *************** | |
728 // ** THE FONTS ** | |
729 // *************** | |
730 // *************** | |
731 // all new for bigscreen | |
732 | |
733 #pragma romdata font_data_large = 0x09A00 | |
734 rom const rom U16 wp_large_data[] = | |
735 { | |
736 #include "ostc90.drx.txt" // length 0x59A | |
737 }; | |
738 | |
739 #pragma romdata font_table_large = 0x09FA0 | |
740 rom const rom U16 wp_large_table[] = | |
741 { | |
742 #include "ostc90.tbl.txt" // length 0x18 | |
743 }; | |
744 | |
745 #pragma romdata font_table_medium = 0x0A000 | |
746 rom const rom U16 wp_medium_table[] = | |
747 { | |
748 #include "ostc48.tbl.txt" // length 0x22 | |
749 }; | |
750 | |
751 #pragma romdata font_data_medium = 0x0A024 | |
752 rom const rom U16 wp_medium_data[] = | |
753 { | |
754 #include "ostc48.drx.txt" // length 0x374 // geht bis einschl. 0xA398 | |
755 }; | |
756 | |
757 #pragma romdata font_table_small = 0x0A39A | |
758 rom const rom U16 wp_small_table[] = | |
759 { | |
760 #include "ostc28.tbl.txt" // length 0xE8 | |
761 }; | |
762 | |
763 #pragma romdata font_data_small = 0x0A484 | |
764 rom const rom U16 wp_small_data[] = | |
765 { | |
766 #include "ostc28.drx.txt" | |
767 }; | |
768 | |
769 | |
770 // *********************** | |
771 // *********************** | |
772 // ** THE SUBROUTINES 2 ** | |
773 // *********************** | |
774 // *********************** | |
775 // all new in v.102 | |
776 // moved from 0x0D000 to 0x0C000 in v.108 | |
777 | |
778 #pragma code subroutines2 = 0x0C000 // can be adapted to fit the romdata tables ahead | |
779 | |
780 // ------------------------------- | |
781 // DBS - debug on start of dive // | |
782 // ------------------------------- | |
783 void create_dbs_set_dbg_and_ndl20mtr(void) | |
784 { | |
785 int_O_DBS_bitfield = 0; | |
786 int_O_DBS2_bitfield = 0; | |
787 if(int_O_DBG_pre_bitfield & DBG_RUN) | |
788 int_O_DBG_pre_bitfield = DBG_RESTART; | |
789 else | |
790 int_O_DBG_pre_bitfield = DBG_RUN; | |
791 int_O_DBG_post_bitfield = 0; | |
792 char_O_NDL_at_20mtr = 255; | |
793 | |
794 DBG_N2_ratio = N2_ratio; | |
795 DBG_He_ratio = He_ratio; | |
796 DBG_char_I_deco_model = char_I_deco_model; | |
797 DBG_char_I_depth_last_deco = char_I_depth_last_deco; | |
798 DBG_pres_surface = pres_surface; | |
799 DBG_GF_low = GF_low; | |
800 DBG_GF_high = GF_high; | |
801 DBG_const_ppO2 = const_ppO2; | |
802 DBG_deco_ppO2_change = deco_ppO2_change; | |
803 DBG_deco_ppO2 = deco_ppO2; | |
804 DBG_deco_N2_ratio = deco_N2_ratio; | |
805 DBG_deco_He_ratio = deco_He_ratio; | |
806 DBG_deco_gas_change = deco_gas_change; | |
807 DBG_float_saturation_multiplier = float_saturation_multiplier; | |
808 DBG_float_desaturation_multiplier = float_desaturation_multiplier; | |
809 DBG_float_deco_distance = float_deco_distance; | |
810 | |
811 if(char_I_deco_model) | |
812 int_O_DBS_bitfield |= DBS_mode; | |
813 if(const_ppO2) | |
814 int_O_DBS_bitfield |= DBS_ppO2; | |
815 for(int_dbg_i = 16; int_dbg_i < 32; int_dbg_i++) | |
816 if(pres_tissue[int_dbg_i]) | |
817 int_O_DBS_bitfield |= DBS_HE_sat; | |
818 if(deco_ppO2_change) | |
819 int_O_DBS_bitfield |= DBS_ppO2chg; | |
820 if(float_saturation_multiplier < 0.99) | |
821 int_O_DBS_bitfield |= DBS_SAT2l; | |
822 if(float_saturation_multiplier > 1.3) | |
823 int_O_DBS_bitfield |= DBS_SAT2h; | |
824 if(GF_low < 0.19) | |
825 int_O_DBS_bitfield |= DBS_GFLOW2l; | |
826 if(GF_low > 1.01) | |
827 int_O_DBS_bitfield |= DBS_GFLOW2h; | |
828 if(GF_high < 0.6) | |
829 int_O_DBS_bitfield |= DBS_GFHGH2l; | |
830 if(GF_high > 1.01) | |
831 int_O_DBS_bitfield |= DBS_GFHGH2h; | |
832 if((N2_ratio + He_ratio) > 0.95) | |
833 int_O_DBS_bitfield |= DBS_GASO22l; | |
834 if((N2_ratio + He_ratio) < 0.05) | |
835 int_O_DBS_bitfield |= DBS_GASO22h; | |
836 if(float_deco_distance > 0.25) | |
837 int_O_DBS_bitfield |= DBS_DIST2h; | |
838 if(char_I_depth_last_deco > 8) | |
839 int_O_DBS_bitfield |= DBS_LAST2h; | |
840 if(DBG_deco_gas_change && ((deco_N2_ratio + deco_He_ratio) > 0.95)) | |
841 int_O_DBS_bitfield |= DBS_DECOO2l; | |
842 if(DBG_deco_gas_change && ((deco_N2_ratio + deco_He_ratio) < 0.05)) | |
843 int_O_DBS_bitfield |= DBS_DECOO2h; | |
844 if(pres_respiration > 3.0) | |
845 int_O_DBS2_bitfield |= DBS2_PRES2h; | |
846 if(pres_surface - pres_respiration > 0.2) | |
847 int_O_DBS2_bitfield |= DBS2_PRES2l; | |
848 if(pres_surface < 0.75) | |
849 int_O_DBS2_bitfield |= DBS2_SURF2l; | |
850 if(pres_surface > 1.11) | |
851 int_O_DBS2_bitfield |= DBS2_SURF2h; | |
852 if(float_desaturation_multiplier < 0.70) | |
853 int_O_DBS2_bitfield |= DBS2_DESAT2l; | |
854 if(float_desaturation_multiplier > 1.01) | |
855 int_O_DBS2_bitfield |= DBS2_DESAT2h; | |
856 if(GF_low > GF_high) | |
857 int_O_DBS2_bitfield |= DBS2_GFDneg; | |
858 } | |
859 | |
860 // ------------------------------- | |
861 // DBG - set DBG to end_of_dive // | |
862 // ------------------------------- | |
863 void set_dbg_end_of_dive(void) | |
864 { | |
865 int_O_DBG_pre_bitfield &= (~DBG_RUN); | |
866 int_O_DBG_post_bitfield &= (~DBG_RUN); | |
867 } | |
868 | |
869 // ------------------------------- | |
870 // DBG - NDL at first 20 m. hit // | |
871 // ------------------------------- | |
872 void check_ndl(void) | |
873 { | |
874 if((char_O_NDL_at_20mtr == -1) && (int_I_pres_respiration > 3000)) | |
875 { | |
876 char_O_NDL_at_20mtr = char_O_nullzeit; | |
877 if(char_O_NDL_at_20mtr == 255) | |
878 char_O_NDL_at_20mtr == 254; | |
879 } | |
880 } | |
881 | |
882 // ------------------------------- | |
883 // DBG - multi main during dive // | |
884 // ------------------------------- | |
885 void check_dbg(char is_post_check) | |
886 { | |
887 temp_DBS = 0; | |
888 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) | |
889 temp_DBS |= DBG_c_gas; | |
890 if(DBG_const_ppO2 != const_ppO2) | |
891 temp_DBS |= DBG_c_ppO2; | |
892 if((DBG_float_saturation_multiplier != float_saturation_multiplier) || (DBG_float_desaturation_multiplier != float_desaturation_multiplier)) | |
893 temp_DBS |= DBG_CdeSAT; | |
894 if(DBG_char_I_deco_model != char_I_deco_model) | |
895 temp_DBS |= DBG_C_MODE; | |
896 if(DBG_pres_surface != pres_surface) | |
897 temp_DBS |= DBG_C_SURF; | |
898 if((!DBS_HE_sat) && (!He_ratio)) | |
899 for(int_dbg_i = 16; int_dbg_i < 32; int_dbg_i++) | |
900 if(pres_tissue[int_dbg_i]) | |
901 temp_DBS |= DBG_HEwoHE; | |
902 if(DBG_deco_ppO2 != deco_ppO2) | |
903 temp_DBS |= DBG_C_DPPO2; | |
904 if((DBG_deco_gas_change != deco_gas_change) || (DBG_deco_N2_ratio != deco_N2_ratio) || (DBG_deco_He_ratio != deco_He_ratio)) | |
905 temp_DBS |= DBG_C_DGAS; | |
906 if(DBG_float_deco_distance != float_deco_distance) | |
907 temp_DBS |= DBG_C_DIST; | |
908 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco) | |
909 temp_DBS |= DBG_C_LAST; | |
910 if((DBG_GF_low != GF_low) || (DBG_GF_high != GF_high)) | |
911 temp_DBS |= DBG_C_GF; | |
912 if(pres_respiration > 13.0) | |
913 temp_DBS |= DBG_PHIGH; | |
914 if(pres_surface - pres_respiration > 0.2) | |
915 temp_DBS |= DBG_PLOW; | |
916 /* | |
917 if() | |
918 temp_DBS |= ; | |
919 if() | |
920 temp_DBS |= ; | |
921 */ | |
922 if(is_post_check) | |
923 int_O_DBG_post_bitfield |= temp_DBS; | |
924 else | |
925 int_O_DBG_pre_bitfield |= temp_DBS; | |
926 } | |
927 | |
928 // ------------------------------- | |
929 // DBG - prior to calc. of dive // | |
930 // ------------------------------- | |
931 void check_pre_dbg(void) | |
932 { | |
933 check_dbg(0); | |
934 } | |
935 | |
936 // ------------------------------- | |
937 // DBG - after decocalc of dive // | |
938 // ------------------------------- | |
939 void check_post_dbg(void) | |
940 { | |
941 check_dbg(1); | |
942 } | |
943 | |
944 | |
945 | |
946 // ------------------------- | |
947 // calc_next_decodepth_GF // | |
948 // ------------------------- | |
949 // new in v.102 | |
950 void calc_nextdecodepth_GF(void) | |
951 { | |
952 // INPUT, changing during dive: | |
953 // temp_pres_gtissue_limit_GF_low | |
954 // temp_pres_gtissue_limit_GF_low_below_surface | |
955 // temp_pres_gtissue | |
956 // temp_pres_gtissue_diff | |
957 // lock_GF_depth_list | |
958 | |
959 // INPUT, fixed during dive: | |
960 // pres_surface | |
961 // GF_delta | |
962 // GF_high | |
963 // GF_low | |
964 // temp_depth_last_deco | |
965 // float_deco_distance | |
966 | |
967 // OUTPUT | |
968 // GF_step | |
969 // temp_deco | |
970 // temp_depth_limt | |
971 // lock_GF_depth_list | |
972 | |
973 // USES | |
974 // temp1 | |
975 // temp2 | |
976 // int_temp | |
977 | |
978 char_I_table_deco_done[0] = 0; // safety if changed somewhere else. Needed for exit | |
979 if (char_I_deco_model == 1) | |
980 { | |
981 if (lock_GF_depth_list == 0) | |
982 { | |
983 temp2 = temp_pres_gtissue_limit_GF_low_below_surface / 0.29985; // = ... / 99.95 / 0.003; | |
984 int_temp = (int) (temp2 + 0.99); | |
985 if (int_temp > 31) | |
986 int_temp = 31; // deepest deco at 93 meter (31 deco stops) | |
987 if (int_temp < 0) | |
988 int_temp = 0; | |
989 temp_depth_GF_low_number = int_temp; | |
990 temp_depth_GF_low_meter = 3 * temp_depth_GF_low_number; | |
991 temp2 = (float)temp_depth_GF_low_meter * 0.09995; | |
992 temp_pres_deco_GF_low = temp2 + float_deco_distance + pres_surface; | |
993 if (temp_depth_GF_low_number == 0) | |
994 GF_step = 0; | |
995 else | |
996 GF_step = GF_delta / (float)temp_depth_GF_low_number; | |
997 if (GF_step < 0) | |
998 GF_step = 0; | |
999 if (GF_step > GF_delta) | |
1000 GF_step = GF_delta; | |
1001 int_O_GF_step = (int)(GF_step * 10000); | |
1002 int_O_limit_GF_low = (int)(temp_pres_deco_GF_low * 1000); | |
1003 int_O_gtissue_press_at_GF_low = (int)(temp_pres_gtissue * 1000); | |
1004 char_O_GF_low_pointer = temp_depth_GF_low_number; | |
1005 lock_GF_depth_list = 1; | |
1006 internal_deco_pointer = 0; | |
1007 } | |
1008 if (internal_deco_pointer == 0) // new run | |
1009 { | |
1010 internal_deco_pointer = temp_depth_GF_low_number; | |
1011 GF_temp = GF_high - ((float)internal_deco_pointer * GF_step); | |
1012 int_temp = char_I_table_deco_done[internal_deco_pointer]; | |
1013 output[8] = int_temp; | |
1014 output[9] = 33; | |
1015 } | |
1016 else | |
1017 { | |
1018 int_temp = 1; | |
1019 } | |
1020 while (int_temp == 1) | |
1021 { | |
1022 int_temp = internal_deco_pointer - 1; | |
1023 if (int_temp == 1) // new in v104 | |
1024 { | |
1025 temp2 = (float)(temp_depth_last_deco * int_temp) * 0.09995; | |
1026 GF_step2 = GF_step/3.0 * ((float)(6 - temp_depth_last_deco)); | |
1027 } | |
1028 else | |
1029 if (int_temp == 0) | |
1030 { | |
1031 temp2 = 0.0; | |
1032 GF_step2 = GF_high - GF_temp; | |
1033 } | |
1034 else | |
1035 { | |
1036 temp2 = (float)(3 *int_temp) * 0.09995; | |
1037 GF_step2 = GF_step; | |
1038 } | |
1039 temp2 = temp2 + pres_surface; // next deco stop to be tested | |
1040 temp1 = ((GF_temp + GF_step2)* temp_pres_gtissue_diff) + temp_pres_gtissue; // upper limit (lowest pressure allowed) // changes GF_step2 in v104 | |
1041 if (temp1 > temp2) // check if ascent to next deco stop is ok | |
1042 { | |
1043 int_temp = 0; // no | |
1044 } | |
1045 else | |
1046 { | |
1047 internal_deco_pointer = int_temp; | |
1048 GF_temp = GF_temp + GF_step2; // changed in v104 | |
1049 int_temp = char_I_table_deco_done[internal_deco_pointer]; // yes and check for ascent to even next stop if deco_done is set | |
1050 } | |
1051 } // while | |
1052 if (internal_deco_pointer > 0) | |
1053 { | |
1054 temp2 = (float)(0.29985 * internal_deco_pointer); | |
1055 temp_deco = temp2 + float_deco_distance + pres_surface; | |
1056 if (internal_deco_pointer == 1) // new in v104 | |
1057 temp_depth_limit = temp_depth_last_deco; | |
1058 else | |
1059 temp_depth_limit = 3 * internal_deco_pointer; | |
1060 if (output[9] == 33) | |
1061 { | |
1062 output[9] = internal_deco_pointer; | |
1063 output[10] = char_I_table_deco_done[internal_deco_pointer]; | |
1064 output[12] = output[12] + 1; | |
1065 if (output[12] == 100) | |
1066 output[12] = 0; | |
1067 } | |
1068 } | |
1069 else // if (char_I_deco_model == 1) | |
1070 { | |
1071 temp_deco = pres_surface; | |
1072 temp_depth_limit = 0; | |
1073 } | |
1074 } | |
1075 else | |
1076 { | |
1077 // calc_nextdecodepth - original | |
1078 // optimized in v.101 | |
1079 // depth_last_deco included in v.101 | |
1080 | |
1081 temp1 = temp_pres_gtissue_limit - pres_surface; | |
1082 if (temp1 >= 0) | |
1083 { | |
1084 temp1 = temp1 / 0.29985; // = temp1 / 99.95 / 0.003; | |
1085 temp_depth_limit = (int) (temp1 + 0.99); | |
1086 temp_depth_limit = 3 * temp_depth_limit; // depth for deco [m] | |
1087 if (temp_depth_limit == 0) | |
1088 temp_deco = pres_surface; | |
1089 else | |
1090 { | |
1091 if (temp_depth_limit < temp_depth_last_deco) | |
1092 temp_depth_limit = temp_depth_last_deco; | |
1093 temp1 = (float)temp_depth_limit * 0.09995; | |
1094 temp_deco = temp1 + float_deco_distance + pres_surface; // depth for deco [bar] | |
1095 } // if (temp_depth_limit == 0) | |
1096 } // if (temp1 >= 0) | |
1097 else | |
1098 { | |
1099 temp_deco = pres_surface; | |
1100 temp_depth_limit = 0; | |
1101 } // if (temp1 >= 0) | |
1102 } // calc_nextdecodepth original | |
1103 } // calc_nextdecodepth_GF | |
1104 | |
1105 | |
1106 #if 0 | |
1107 void build_debug_output(void) | |
1108 { | |
1109 output[0] = 0; // not used in asm PLED output | |
1110 output[1] = (int) (GF_low * 100); | |
1111 output[2] = (int) (GF_high * 100); | |
1112 output[3] = (int) (GF_step * 100); | |
1113 output[4] = (int) temp_depth_GF_low_number; | |
1114 output[5] = (int) temp_depth_GF_low_meter; | |
1115 //output[6] | |
1116 output[7] = (int) internal_deco_pointer; | |
1117 //output[8] = char_I_table_deco_done[temp_depth_GF_low_number] | |
1118 //output[9] = internal_deco_pointer @ new run | |
1119 //output[10] = char_I_table_deco_done[internal_deco_pointer] @ new run | |
1120 output [11] = (int) (temp_pres_deco_GF_low * 10); | |
1121 } // build_debug_output | |
1122 #endif | |
1123 | |
1124 // --------------------- | |
1125 // copy_deco_table_GF // | |
1126 // --------------------- | |
1127 // new in v.102 | |
1128 void copy_deco_table_GF(void) | |
1129 { | |
1130 if (char_I_deco_model == 1) | |
1131 { | |
1132 int_temp = 32; | |
1133 for (ci=0;ci<int_temp;ci++) | |
1134 char_O_deco_table[ci] = internal_deco_table[ci]; | |
1135 } | |
1136 } // copy_deco_table_GF | |
1137 | |
1138 | |
1139 // ------------------------------ | |
1140 // clear_internal_deco_table_GF// | |
1141 // ------------------------------ | |
1142 // new in v.102 | |
1143 void clear_internal_deco_table_GF(void) | |
1144 { | |
1145 if (char_I_deco_model == 1) | |
1146 { | |
1147 for (ci=0;ci<32;ci++) // cycle through the 16 b"uhlmann tissues for Helium | |
1148 { | |
1149 internal_deco_table[ci] = 0; | |
1150 } | |
1151 } | |
1152 } // clear_internal_deco_table_GF | |
1153 | |
1154 | |
1155 // -------------------------------- | |
1156 // update_internal_deco_table_GF // | |
1157 // -------------------------------- | |
1158 // new in v.102 | |
1159 void update_internal_deco_table_GF(void) | |
1160 { | |
1161 if ((char_I_deco_model == 1) && (internal_deco_table[internal_deco_pointer] < 255)) | |
1162 internal_deco_table[internal_deco_pointer] = internal_deco_table[internal_deco_pointer] + 1; | |
1163 } // update_internal_deco_table_GF | |
1164 | |
1165 | |
1166 // --------------------- | |
1167 // temp_tissue_safety // | |
1168 // --------------------- | |
1169 // outsourced in v.102 | |
1170 void temp_tissue_safety(void) | |
1171 { | |
1172 if (char_I_deco_model == 1) | |
1173 { | |
1174 } | |
1175 else | |
1176 { | |
1177 if (temp_tissue < 0.0) | |
1178 temp_tissue = temp_tissue * float_desaturation_multiplier; | |
1179 else | |
1180 temp_tissue = temp_tissue * float_saturation_multiplier; | |
1181 } | |
1182 } // temp_tissue_safety | |
1183 | |
1184 // ----------- | |
1185 // dd2 OLD // | |
1186 // ----------- | |
1187 void DD2_write(void) | |
1188 { | |
1189 _asm | |
1190 nop | |
1191 _endasm | |
1192 } | |
1193 void DD2_write_incon42(void) | |
1194 { | |
1195 DD2_write(); | |
1196 } | |
1197 | |
1198 void DD2_write_incon24(void) | |
1199 { | |
1200 DD2_write(); | |
1201 } | |
1202 void DD2_get_pointer_to_char(void) | |
1203 { | |
1204 DD2_write(); | |
1205 } | |
1206 void DD2_set_column(void) | |
1207 { | |
1208 DD2_write(); | |
1209 } | |
1210 void DD2_load_background(void) | |
1211 { | |
1212 DD2_write(); | |
1213 } | |
1214 void DD2_build_one_line_of_char(void) | |
1215 { | |
1216 DD2_write(); | |
1217 } | |
1218 void DD2_print_column(void) | |
1219 { | |
1220 DD2_write(); | |
1221 } | |
1222 void DD2_CmdWrite(void) | |
1223 { | |
1224 DD2_write(); | |
1225 } | |
1226 void DD2_DataWrite(void) | |
1227 { | |
1228 DD2_write(); | |
1229 } | |
1230 | |
1231 // ********************** | |
1232 // ********************** | |
1233 // ** THE JUMP-IN CODE ** | |
1234 // ** for the asm code ** | |
1235 // ********************** | |
1236 // ********************** | |
1237 #pragma code main_calc_hauptroutine = 0x10000 | |
1238 void main_calc_hauptroutine(void) // length 0x0A | |
1239 { | |
1240 calc_hauptroutine(); | |
1241 int_O_desaturation_time = 65535; | |
1242 } // divemode | |
1243 | |
1244 #pragma code main_without_deco = 0x1000C // length 0x06 | |
1245 void main_calc_without_deco(void) | |
1246 { | |
1247 calc_without_deco(); | |
1248 calc_desaturation_time(); | |
1249 } | |
1250 | |
1251 | |
1252 #pragma code main_clear_CNS_fraction = 0x10016 | |
1253 void main_clear_CNS_fraction(void) | |
1254 { | |
1255 clear_CNS_fraction(); | |
1256 } | |
1257 | |
1258 #pragma code main_calc_CNS_decrease_15min = 0x1001C | |
1259 void main_calc_CNS_decrease_15min(void) // length 0x06 | |
1260 { | |
1261 calc_CNS_decrease_15min(); | |
1262 } | |
1263 | |
1264 #pragma code main_calc_percentage = 0x10022 | |
1265 void main_calc_percentage(void) | |
1266 { | |
1267 calc_percentage(); | |
1268 } | |
1269 | |
1270 #pragma code main_clear_tissue = 0x10028 | |
1271 void main_clear_tissue(void) | |
1272 { | |
1273 clear_tissue(); | |
1274 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco | |
1275 } | |
1276 | |
1277 #pragma code main_calc_CNS_fraction = 0x10032 | |
1278 void main_calc_CNS_fraction(void) | |
1279 { | |
1280 calc_CNS_fraction(); | |
1281 } | |
1282 | |
1283 #pragma code main_calc_desaturation_time = 0x10038 | |
1284 void main_calc_desaturation_time(void) | |
1285 { | |
1286 calc_desaturation_time(); | |
1287 } | |
1288 | |
1289 #pragma code main_calc_wo_deco_step_1_min = 0x1003E | |
1290 void main_calc_wo_deco_step_1_min(void) | |
1291 { | |
1292 calc_wo_deco_step_1_min(); | |
1293 char_O_deco_status = 3; // surface new in v.102 overwrites value of calc_wo_deco_step_1_min | |
1294 calc_desaturation_time(); | |
1295 } // surface mode | |
1296 | |
1297 #pragma code main_wordprocessor = 0x1004E | |
1298 void main_wordprocessor(void) | |
1299 { | |
1300 wordprocessor(); | |
1301 } | |
1302 | |
1303 #pragma code main_gradient_array = 0x10054 | |
1304 void main_gradient_array(void) | |
1305 { | |
1306 calc_gradient_array_only(); | |
1307 } | |
1308 | |
1309 #pragma code main_push_tissues = 0x1005A | |
1310 void main_push_tissues_to_vault(void) | |
1311 { | |
1312 push_tissues_to_vault(); | |
1313 } | |
1314 | |
1315 #pragma code main_pull_tissues = 0x10060 | |
1316 void main_pull_tissues_from_vault(void) | |
1317 { | |
1318 pull_tissues_from_vault(); | |
1319 } | |
1320 | |
1321 #pragma code main_hash = 0x10066 | |
1322 void main_hash(void) | |
1323 { | |
1324 hash(); | |
1325 } | |
1326 /* | |
1327 #pragma code main_debug = 0x1004E | |
1328 void main_debug(void) | |
1329 { | |
1330 // debug(); | |
1331 } | |
1332 */ | |
1333 | |
1334 // *********************** | |
1335 // *********************** | |
1336 // ** THE LOOKUP TABLES ** | |
1337 // *********************** | |
1338 // *********************** | |
1339 | |
1340 #pragma romdata tables = 0x10200 | |
1341 #include <p2_tables.romdata> // new table for deco_main_v.101 (var_a modified) | |
1342 | |
1343 #pragma romdata tables2 = 0x10600 | |
1344 rom const rom unsigned int md_pi[] = | |
1345 { | |
1346 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613 | |
1347 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA | |
1348 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512 | |
1349 , 0xBE4E, 0xC4D6, 0xDA9E, 0xDE49, 0xA0FB, 0xF58E, 0xBB2F, 0xEE7A | |
1350 , 0xA968, 0x7991, 0x15B2, 0x073F, 0x94C2, 0x1089, 0x0B22, 0x5F21 | |
1351 , 0x807F, 0x5D9A, 0x5A90, 0x3227, 0x353E, 0xCCE7, 0xBFF7, 0x9703 | |
1352 , 0xFF19, 0x30B3, 0x48A5, 0xB5D1, 0xD75E, 0x922A, 0xAC56, 0xAAC6 | |
1353 , 0x4FB8, 0x38D2, 0x96A4, 0x7DB6, 0x76FC, 0x6BE2, 0x9C74, 0x04F1 | |
1354 , 0x459D, 0x7059, 0x6471, 0x8720, 0x865B, 0xCF65, 0xE62D, 0xA802 | |
1355 , 0x1B60, 0x25AD, 0xAEB0, 0xB9F6, 0x1C46, 0x6169, 0x3440, 0x7E0F | |
1356 , 0x5547, 0xA323, 0xDD51, 0xAF3A, 0xC35C, 0xF9CE, 0xBAC5, 0xEA26 | |
1357 , 0x2C53, 0x0D6E, 0x8528, 0x8409, 0xD3DF, 0xCDF4, 0x4181, 0x4D52 | |
1358 , 0x6ADC, 0x37C8, 0x6CC1, 0xABFA, 0x24E1, 0x7B08, 0x0CBD, 0xB14A | |
1359 , 0x7888, 0x958B, 0xE363, 0xE86D, 0xE9CB, 0xD5FE, 0x3B00, 0x1D39 | |
1360 , 0xF2EF, 0xB70E, 0x6658, 0xD0E4, 0xA677, 0x72F8, 0xEB75, 0x4B0A | |
1361 , 0x3144, 0x50B4, 0x8FED, 0x1F1A, 0xDB99, 0x8D33, 0x9F11, 0x8314 | |
1362 }; | |
1363 | |
1364 // ********************* | |
1365 // ********************* | |
1366 // ** THE SUBROUTINES ** | |
1367 // ********************* | |
1368 // ********************* | |
1369 | |
1370 #pragma code subroutines = 0x10700 // can be adapted to fit the romdata tables ahead | |
1371 | |
1372 | |
1373 // --------------- | |
1374 // CLEAR tissue // | |
1375 // --------------- | |
1376 // optimized in v.101 (var_a) | |
1377 | |
1378 void clear_tissue(void) // preload tissues with standard pressure for the given ambient pressure | |
1379 { | |
1380 | |
1381 flag_in_divemode = 0; | |
1382 int_O_DBS_bitfield = 0; | |
1383 int_O_DBS2_bitfield = 0; | |
1384 int_O_DBG_pre_bitfield = 0; | |
1385 int_O_DBG_post_bitfield = 0; | |
1386 char_O_NDL_at_20mtr = 255; | |
1387 | |
1388 _asm | |
1389 lfsr 1, 0x300 // C math routines shall use this variable bank | |
1390 movlw 0x01 | |
1391 movwf TBLPTRU,0 | |
1392 _endasm | |
1393 | |
1394 // N2_ratio = (float)char_I_N2_ratio; // the 0.0002 of 0.7902 are missing with standard air | |
1395 N2_ratio = 0.7902; // N2_ratio / 100.0; | |
1396 pres_respiration = (float)int_I_pres_respiration / 1000.0; | |
1397 for (ci=0;ci<16;ci++) // cycle through the 16 b"uhlmann tissues | |
1398 { | |
1399 pres_tissue[ci] = N2_ratio * (pres_respiration - 0.0627) ; | |
1400 _asm | |
1401 movlw 0x02 | |
1402 movwf TBLPTRH,0 | |
1403 movlb 4 // fuer ci | |
1404 movf ci,0,1 | |
1405 addwf ci,0,1 | |
1406 addwf ci,0,1 | |
1407 addwf ci,0,1 | |
1408 addlw 0x80 | |
1409 movwf TBLPTRL,0 | |
1410 TBLRDPOSTINC | |
1411 movff TABLAT,var_a+1 | |
1412 TBLRDPOSTINC | |
1413 movff TABLAT,var_a | |
1414 TBLRDPOSTINC | |
1415 movff TABLAT,var_a+3 | |
1416 TBLRD | |
1417 movff TABLAT,var_a+2 | |
1418 addlw 0x80 | |
1419 movwf TBLPTRL,0 | |
1420 incf TBLPTRH,1,0 | |
1421 TBLRDPOSTINC | |
1422 movff TABLAT,var_b+1 | |
1423 TBLRDPOSTINC | |
1424 movff TABLAT,var_b | |
1425 TBLRDPOSTINC | |
1426 movff TABLAT,var_b+3 | |
1427 TBLRD | |
1428 movff TABLAT,var_b+2 | |
1429 _endasm | |
1430 | |
1431 pres_tissue_limit[ci] = (pres_tissue[ci] - var_a) * var_b ; | |
1432 // now update the guiding tissue | |
1433 if (pres_tissue_limit[ci] < 0) | |
1434 pres_tissue_limit[ci] = 0; | |
1435 } // for 0 to 16 | |
1436 | |
1437 for (ci=16;ci<32;ci++) // cycle through the 16 b"uhlmann tissues for Helium | |
1438 { | |
1439 pres_tissue[ci] = 0.0; | |
1440 } // for | |
1441 | |
1442 clear_decoarray(); | |
1443 char_O_deco_status = 0; | |
1444 char_O_nullzeit = 0; | |
1445 char_O_ascenttime = 0; | |
1446 char_O_gradient_factor = 0; | |
1447 char_O_relative_gradient_GF = 0; | |
1448 } // clear_tissue(void) | |
1449 | |
1450 | |
1451 // -------------------- | |
1452 // calc_without_deco // | |
1453 // fixed N2_ratio ! // | |
1454 // -------------------- | |
1455 // optimized in v.101 (float_..saturation_multiplier) | |
1456 | |
1457 void calc_without_deco(void) | |
1458 { | |
1459 _asm | |
1460 lfsr 1, 0x300 | |
1461 _endasm | |
1462 N2_ratio = 0.7902; // FIXED RATIO !! sum as stated in b"uhlmann | |
1463 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | |
1464 pres_surface = (float)int_I_pres_surface / 1000.0; | |
1465 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body | |
1466 temp2_atem = 0.0; | |
1467 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does apply to the pressure without any inert ratio | |
1468 float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0; | |
1469 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; | |
1470 | |
1471 calc_tissue(); // update the pressure in the 16 tissues in accordance with the new ambient pressure | |
1472 | |
1473 clear_decoarray(); | |
1474 char_O_deco_status = 0; | |
1475 char_O_nullzeit = 0; | |
1476 char_O_ascenttime = 0; | |
1477 calc_gradient_factor(); | |
1478 | |
1479 } // calc_without_deco | |
1480 | |
1481 | |
1482 // -------------------- | |
1483 // calc_hauptroutine // | |
1484 // -------------------- | |
1485 // this is the major code in dive mode | |
1486 // calculates: | |
1487 // the tissues, | |
1488 // the bottom time | |
1489 // and simulates the ascend with all deco stops | |
1490 | |
1491 void calc_hauptroutine(void) | |
1492 { | |
1493 calc_hauptroutine_data_input(); | |
1494 | |
1495 if(!flag_in_divemode) | |
1496 { | |
1497 flag_in_divemode = 1; | |
1498 create_dbs_set_dbg_and_ndl20mtr(); | |
1499 } | |
1500 else | |
1501 check_pre_dbg(); | |
1502 | |
1503 calc_hauptroutine_update_tissues(); | |
1504 calc_gradient_factor(); | |
1505 | |
1506 | |
1507 switch (char_O_deco_status) // toggle between calculation for nullzeit (bottom time), deco stops and more deco stops (continue) | |
1508 { | |
1509 case 0: | |
1510 update_startvalues(); | |
1511 calc_nullzeit(); | |
1512 check_ndl(); | |
1513 char_O_deco_status = 255; // calc deco next time | |
1514 break; | |
1515 case 1: | |
1516 if (char_O_deco_status == 3) | |
1517 break; | |
1518 char_O_deco_status = 0; | |
1519 // char_O_lock_depth_list = 255; | |
1520 calc_hauptroutine_calc_deco(); | |
1521 // build_debug_output(); | |
1522 break; | |
1523 case 3: // new dive | |
1524 clear_decoarray(); | |
1525 clear_internal_deco_table_GF(); | |
1526 copy_deco_table_GF(); | |
1527 internal_deco_pointer = 0; | |
1528 lock_GF_depth_list = 0; | |
1529 update_startvalues(); | |
1530 calc_nextdecodepth_GF(); | |
1531 char_O_deco_status = 0; | |
1532 break; | |
1533 default: | |
1534 update_startvalues(); | |
1535 clear_decoarray(); | |
1536 clear_internal_deco_table_GF(); | |
1537 output[6] = 1; | |
1538 calc_hauptroutine_calc_ascend_to_deco(); | |
1539 if (char_O_deco_status > 15) // can't go up to first deco, too deep to calculate in the given time slot | |
1540 { | |
1541 char_O_deco_status = 2; | |
1542 // char_O_lock_depth_list = 255; | |
1543 } | |
1544 else | |
1545 { | |
1546 // char_O_lock_depth_list = lock_GF_depth_list; | |
1547 calc_hauptroutine_calc_deco(); | |
1548 } | |
1549 // build_debug_output(); | |
1550 break; | |
1551 } | |
1552 calc_ascenttime(); | |
1553 check_post_dbg(); | |
1554 } | |
1555 | |
1556 void calc_hauptroutine_data_input(void) | |
1557 { | |
1558 pres_respiration = (float)int_I_pres_respiration / 1000.0; | |
1559 pres_surface = (float)int_I_pres_surface / 1000.0; | |
1560 | |
1561 N2_ratio = (float)char_I_N2_ratio / 100.0;; // the 0.0002 of 0.7902 are missing with standard air | |
1562 He_ratio = (float)char_I_He_ratio / 100.0;; | |
1563 deco_N2_ratio = (float)char_I_deco_N2_ratio / 100.0; | |
1564 deco_He_ratio = (float)char_I_deco_He_ratio / 100.0; | |
1565 float_deco_distance = (float)char_I_deco_distance / 100.0; | |
1566 if(char_I_deco_gas_change) | |
1567 { | |
1568 deco_gas_change = (float)char_I_deco_gas_change / 9.995 + pres_surface; | |
1569 deco_gas_change = deco_gas_change + float_deco_distance; | |
1570 } | |
1571 else | |
1572 deco_gas_change = 0; | |
1573 const_ppO2 = (float)char_I_const_ppO2 / 100.0; | |
1574 deco_ppO2_change = (float)char_I_deco_ppO2_change / 99.95 + pres_surface; | |
1575 deco_ppO2_change = deco_ppO2_change + float_deco_distance; | |
1576 deco_ppO2 = (float)char_I_deco_ppO2 / 100.0; | |
1577 float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0; | |
1578 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; | |
1579 GF_low = (float)char_I_GF_Low_percentage / 100.0; | |
1580 GF_high = (float)char_I_GF_High_percentage / 100.0; | |
1581 GF_delta = GF_high - GF_low; | |
1582 | |
1583 temp2 = (pres_respiration - pres_surface) / 0.29985; | |
1584 int_temp = (int)(temp2); | |
1585 if (int_temp < 0) | |
1586 int_temp = 0; | |
1587 if (int_temp > 255) | |
1588 int_temp = 255; | |
1589 char_O_actual_pointer = int_temp; | |
1590 | |
1591 temp_depth_last_deco = (int)char_I_depth_last_deco; | |
1592 } | |
1593 | |
1594 void calc_hauptroutine_update_tissues(void) | |
1595 { | |
1596 int_O_calc_tissue_call_counter = int_O_calc_tissue_call_counter + 1; | |
1597 if (char_I_const_ppO2 == 0) // new in v.101 | |
1598 pres_diluent = pres_respiration; // new in v.101 | |
1599 else // new in v.101 | |
1600 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 | |
1601 if (pres_diluent > pres_respiration) // new in v.101 | |
1602 pres_diluent = pres_respiration; // new in v.101 | |
1603 if (pres_diluent > 0.0627) // new in v.101 | |
1604 { | |
1605 temp_atem = N2_ratio * (pres_diluent - 0.0627); // changed in v.101 | |
1606 temp2_atem = He_ratio * (pres_diluent - 0.0627); // changed in v.101 | |
1607 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0); | |
1608 } | |
1609 else // new in v.101 | |
1610 { | |
1611 temp_atem = 0.0; // new in v.101 | |
1612 temp2_atem = 0.0; // new in v.101 | |
1613 char_O_diluent = 0; | |
1614 } | |
1615 temp_surface = pres_surface; | |
1616 calc_tissue(); | |
1617 int_O_gtissue_limit = (int)(pres_tissue_limit[char_O_gtissue_no] * 1000); | |
1618 int_O_gtissue_press = (int)((pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]) * 1000); | |
1619 if (char_I_deco_model == 1) | |
1620 { | |
1621 temp1 = temp1 * GF_high; | |
1622 } | |
1623 else | |
1624 { | |
1625 temp1 = temp_surface; | |
1626 } | |
1627 if (pres_gtissue_limit > temp1 && char_O_deco_status == 0) // if guiding tissue can not be exposed to surface pressure immediately | |
1628 { | |
1629 char_O_nullzeit = 0; // deco necessary | |
1630 char_O_deco_status = 255; // calculate deco skip nullzeit calculation | |
1631 } | |
1632 } // calc_hauptroutine_update_tissues | |
1633 void calc_hauptroutine_calc_deco(void) | |
1634 { | |
1635 do | |
1636 { | |
1637 int_temp_decostatus = 0; | |
1638 calc_nextdecodepth_GF(); | |
1639 if (temp_depth_limit > 0) | |
1640 { | |
1641 if (char_I_const_ppO2 == 0) // new in v.101 | |
1642 { | |
1643 deco_diluent = temp_deco; // new in v.101 | |
1644 if (temp_deco > deco_gas_change) | |
1645 { | |
1646 calc_N2_ratio = N2_ratio; | |
1647 calc_He_ratio = He_ratio; | |
1648 } | |
1649 else | |
1650 { | |
1651 calc_N2_ratio = deco_N2_ratio; | |
1652 calc_He_ratio = deco_He_ratio; | |
1653 } | |
1654 } | |
1655 else // new in v.101 | |
1656 { | |
1657 calc_N2_ratio = N2_ratio; | |
1658 calc_He_ratio = He_ratio; | |
1659 if (temp_deco > deco_ppO2_change) | |
1660 { | |
1661 deco_diluent = ((temp_deco - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 | |
1662 } | |
1663 else | |
1664 { | |
1665 deco_diluent = ((temp_deco - deco_ppO2)/(N2_ratio + He_ratio)); // new in v.101 | |
1666 } | |
1667 } | |
1668 if (deco_diluent > temp_deco) // new in v.101 | |
1669 deco_diluent = temp_deco; // new in v.101 | |
1670 if (deco_diluent > 0.0627) // new in v.101 | |
1671 { | |
1672 temp_atem = calc_N2_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
1673 temp2_atem = calc_He_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
1674 } | |
1675 else // new in v.101 | |
1676 { | |
1677 temp_atem = 0.0; // new in v.101 | |
1678 temp2_atem = 0.0; // new in v.101 | |
1679 } | |
1680 sim_tissue_1min(); | |
1681 update_internal_deco_table_GF(); | |
1682 temp_decotime = 1; | |
1683 update_decoarray(); | |
1684 char_O_deco_status = char_O_deco_status + 1; | |
1685 if (char_O_deco_status < 16) | |
1686 int_temp_decostatus = 1; | |
1687 } | |
1688 else // if (temp_depth_limit > 0) | |
1689 { | |
1690 char_O_deco_status = 0; | |
1691 } | |
1692 } while (int_temp_decostatus == 1); | |
1693 if (char_O_deco_status > 15) | |
1694 { | |
1695 char_O_deco_status = 1; | |
1696 } | |
1697 else | |
1698 { | |
1699 copy_deco_table_GF(); | |
1700 char_O_deco_status = 0; | |
1701 } | |
1702 } | |
1703 | |
1704 void calc_hauptroutine_calc_ascend_to_deco(void) | |
1705 { | |
1706 update_startvalues(); | |
1707 char_O_deco_status = 0; | |
1708 temp_deco = pres_respiration; | |
1709 lock_GF_depth_list = 1; // new in v.102 | |
1710 do // go up to first deco | |
1711 { | |
1712 int_temp_decostatus = 0; | |
1713 temp_deco = temp_deco - 1.0; | |
1714 if ( char_I_deco_model == 1) // new in v.102 , 4 = deep stops | |
1715 temp_limit = temp_pres_gtissue_limit_GF_low; | |
1716 else | |
1717 temp_limit = temp_pres_gtissue_limit; | |
1718 if ((temp_deco > temp_limit) && (temp_deco > pres_surface)) // changes in v.102 | |
1719 { | |
1720 lock_GF_depth_list = 0; // new in v.102, distance to first stop > 10 mtr. | |
1721 output[6] = 0; | |
1722 if (char_I_const_ppO2 == 0) // new in v.101 // calculate at half of the ascent | |
1723 { | |
1724 deco_diluent = temp_deco + 0.5; // new in v.101 | |
1725 if (temp_deco + 0.5 > deco_gas_change) | |
1726 { | |
1727 calc_N2_ratio = N2_ratio; | |
1728 calc_He_ratio = He_ratio; | |
1729 } | |
1730 else | |
1731 { | |
1732 calc_N2_ratio = deco_N2_ratio; | |
1733 calc_He_ratio = deco_He_ratio; | |
1734 } | |
1735 } | |
1736 else // new in v.101 | |
1737 { | |
1738 calc_N2_ratio = N2_ratio; | |
1739 calc_He_ratio = He_ratio; | |
1740 if (temp_deco + 0.5 > deco_ppO2_change) | |
1741 deco_diluent = ((temp_deco + 0.5 - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 // calculate at half of the ascent | |
1742 else | |
1743 deco_diluent = ((temp_deco + 0.5 - deco_ppO2)/(N2_ratio + He_ratio)); // new in v.101 // calculate at half of the ascent | |
1744 if (deco_diluent > (temp_deco +0.5)) // new in v.101 | |
1745 deco_diluent = temp_deco + 0.5; // new in v.101 // calculate at half of the ascent | |
1746 } | |
1747 if (deco_diluent > 0.0627) // new in v.101 | |
1748 { | |
1749 temp_atem = calc_N2_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
1750 temp2_atem = calc_He_ratio * (deco_diluent - 0.0627); // changed in v.101 | |
1751 } | |
1752 else // new in v.101 | |
1753 { | |
1754 temp_atem = 0.0; // new in v.101 | |
1755 temp2_atem = 0.0; // new in v.101 | |
1756 } | |
1757 sim_tissue_1min(); | |
1758 char_O_deco_status = char_O_deco_status + 1; | |
1759 if (char_O_deco_status < 16) // 16 is the limit of calculations for one time slot | |
1760 int_temp_decostatus = 1; | |
1761 } | |
1762 } while (int_temp_decostatus == 1); | |
1763 } // calc_hauptroutine_calc_ascend_to_deco | |
1764 | |
1765 // -------------- | |
1766 // calc_tissue // | |
1767 // -------------- | |
1768 // optimized in v.101 | |
1769 | |
1770 void calc_tissue(void) | |
1771 { | |
1772 _asm | |
1773 lfsr 1, 0x300 | |
1774 movlw 0x01 | |
1775 movwf TBLPTRU,0 | |
1776 _endasm | |
1777 | |
1778 char_O_gtissue_no = 255; | |
1779 pres_gtissue_limit = 0.0; | |
1780 | |
1781 for (ci=0;ci<16;ci++) | |
1782 { | |
1783 _asm | |
1784 movlw 0x02 | |
1785 movwf TBLPTRH,0 | |
1786 movlb 4 // fuer ci | |
1787 movf ci,0,1 | |
1788 addwf ci,0,1 | |
1789 addwf ci,0,1 | |
1790 addwf ci,0,1 | |
1791 movwf TBLPTRL,0 | |
1792 TBLRDPOSTINC | |
1793 movff TABLAT,var_e2secs+1 // the order is confussing | |
1794 TBLRDPOSTINC | |
1795 movff TABLAT,var_e2secs // low byte first, high afterwards | |
1796 TBLRDPOSTINC | |
1797 movff TABLAT,var_e2secs+3 | |
1798 TBLRD | |
1799 movff TABLAT,var_e2secs+2 | |
1800 addlw 0x40 | |
1801 movwf TBLPTRL,0 | |
1802 TBLRDPOSTINC | |
1803 movff TABLAT,var2_e2secs+1 | |
1804 TBLRDPOSTINC | |
1805 movff TABLAT,var2_e2secs | |
1806 TBLRDPOSTINC | |
1807 movff TABLAT,var2_e2secs+3 | |
1808 TBLRD | |
1809 movff TABLAT,var2_e2secs+2 | |
1810 addlw 0x40 | |
1811 movwf TBLPTRL,0 | |
1812 TBLRDPOSTINC | |
1813 movff TABLAT,var_a+1 | |
1814 TBLRDPOSTINC | |
1815 movff TABLAT,var_a | |
1816 TBLRDPOSTINC | |
1817 movff TABLAT,var_a+3 | |
1818 TBLRD | |
1819 movff TABLAT,var_a+2 | |
1820 addlw 0x40 | |
1821 movwf TBLPTRL,0 | |
1822 TBLRDPOSTINC | |
1823 movff TABLAT,var2_a+1 | |
1824 TBLRDPOSTINC | |
1825 movff TABLAT,var2_a | |
1826 TBLRDPOSTINC | |
1827 movff TABLAT,var2_a+3 | |
1828 TBLRD | |
1829 movff TABLAT,var2_a+2 | |
1830 addlw 0x40 | |
1831 movwf TBLPTRL,0 | |
1832 incf TBLPTRH,1,0 | |
1833 TBLRDPOSTINC | |
1834 movff TABLAT,var_b+1 | |
1835 TBLRDPOSTINC | |
1836 movff TABLAT,var_b | |
1837 TBLRDPOSTINC | |
1838 movff TABLAT,var_b+3 | |
1839 TBLRD | |
1840 movff TABLAT,var_b+2 | |
1841 addlw 0x40 | |
1842 movwf TBLPTRL,0 | |
1843 TBLRDPOSTINC | |
1844 movff TABLAT,var2_b+1 | |
1845 TBLRDPOSTINC | |
1846 movff TABLAT,var2_b | |
1847 TBLRDPOSTINC | |
1848 movff TABLAT,var2_b+3 | |
1849 TBLRD | |
1850 movff TABLAT,var2_b+2 | |
1851 _endasm | |
1852 // the start values are the previous end values // write new values in temp | |
1853 | |
1854 if( (var_e2secs < 0.0000363) | |
1855 || (var_e2secs > 0.00577) | |
1856 || (var2_e2secs < 0.0000961) | |
1857 || (var2_e2secs > 0.150) | |
1858 || (var_a < 0.231) | |
1859 || (var_a > 1.27) | |
1860 || (var_b < 0.504) | |
1861 || (var_b > 0.966) | |
1862 || (var2_a < 0.510) | |
1863 || (var2_a > 1.75) | |
1864 || (var2_b < 0.423) | |
1865 || (var2_b > 0.927) | |
1866 ) | |
1867 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
1868 | |
1869 // N2 | |
1870 temp_tissue = (temp_atem - pres_tissue[ci]) * var_e2secs; | |
1871 temp_tissue_safety(); | |
1872 pres_tissue[ci] = pres_tissue[ci] + temp_tissue; | |
1873 | |
1874 // He | |
1875 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var2_e2secs; | |
1876 temp_tissue_safety(); | |
1877 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue; | |
1878 | |
1879 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; | |
1880 | |
1881 var_a = (var_a * pres_tissue[ci] + var2_a * pres_tissue[ci+16]) / temp_tissue; | |
1882 var_b = (var_b * pres_tissue[ci] + var2_b * pres_tissue[ci+16]) / temp_tissue; | |
1883 pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
1884 if (pres_tissue_limit[ci] < 0) | |
1885 pres_tissue_limit[ci] = 0; | |
1886 if (pres_tissue_limit[ci] > pres_gtissue_limit) | |
1887 { | |
1888 pres_gtissue_limit = pres_tissue_limit[ci]; | |
1889 char_O_gtissue_no = ci; | |
1890 }//if | |
1891 } // for | |
1892 }//calc_tissue(void) | |
1893 | |
1894 // ---------------- | |
1895 // calc_nullzeit // | |
1896 // ---------------- | |
1897 // calculates the remaining bottom time | |
1898 | |
1899 // unchanged in v.101 | |
1900 | |
1901 void calc_nullzeit(void) | |
1902 { | |
1903 char_O_nullzeit = 0; | |
1904 int_temp = 1; | |
1905 do | |
1906 { | |
1907 backup_sim_pres_tissue(); | |
1908 sim_tissue_10min(); | |
1909 char_O_nullzeit = char_O_nullzeit + 10; | |
1910 int_temp = int_temp + 1; | |
1911 if (char_I_deco_model == 1) | |
1912 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue; | |
1913 else | |
1914 temp1 = temp_pres_gtissue_limit; | |
1915 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately | |
1916 int_temp = 255; | |
1917 } while (int_temp < 17); | |
1918 if (int_temp == 255) | |
1919 { | |
1920 restore_sim_pres_tissue(); | |
1921 char_O_nullzeit = char_O_nullzeit - 10; | |
1922 } //if int_temp == 255] | |
1923 int_temp = 1; | |
1924 if (char_O_nullzeit < 60) | |
1925 { | |
1926 do | |
1927 { | |
1928 sim_tissue_1min(); | |
1929 char_O_nullzeit = char_O_nullzeit + 1; | |
1930 int_temp = int_temp + 1; // new in v.102a | |
1931 if (char_I_deco_model == 1) | |
1932 temp1 = GF_high * temp_pres_gtissue_diff + temp_pres_gtissue; | |
1933 else | |
1934 temp1 = temp_pres_gtissue_limit; | |
1935 if (temp1 > temp_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately | |
1936 int_temp = 255; | |
1937 } while (int_temp < 10); | |
1938 if (int_temp == 255) | |
1939 char_O_nullzeit = char_O_nullzeit - 1; | |
1940 } // if char_O_nullzeit < 60 | |
1941 } //calc_nullzeit | |
1942 | |
1943 // ------------------------- | |
1944 // backup_sim_pres_tissue // | |
1945 // ------------------------- | |
1946 void backup_sim_pres_tissue(void) | |
1947 { | |
1948 for (x = 0;x<16;x++) | |
1949 { | |
1950 sim_pres_tissue_backup[x] = sim_pres_tissue[x]; | |
1951 sim_pres_tissue_backup[x+16] = sim_pres_tissue[x+16]; | |
1952 } | |
1953 } // backup_sim | |
1954 | |
1955 // -------------------------- | |
1956 // restore_sim_pres_tissue // | |
1957 // -------------------------- | |
1958 void restore_sim_pres_tissue(void) | |
1959 { | |
1960 for (x = 0;x<16;x++) | |
1961 { | |
1962 sim_pres_tissue[x] = sim_pres_tissue_backup[x]; | |
1963 sim_pres_tissue[x+16] = sim_pres_tissue_backup[x+16]; | |
1964 } | |
1965 } // restore_sim | |
1966 | |
1967 // ------------------ | |
1968 // calc_ascenttime // | |
1969 // ------------------ | |
1970 | |
1971 void calc_ascenttime(void) | |
1972 { | |
1973 if (pres_respiration > pres_surface) | |
1974 { | |
1975 switch (char_O_deco_status) | |
1976 { | |
1977 case 2: | |
1978 char_O_ascenttime = 255; | |
1979 break; | |
1980 case 1: | |
1981 break; | |
1982 default: | |
1983 temp1 = pres_respiration - pres_surface + 0.6; // + 0.6 hence 1 minute ascent time from a depth of 4 meter on | |
1984 if (temp1 < 0) | |
1985 temp1 = 0; | |
1986 if (temp1 > 255) | |
1987 temp1 = 255; | |
1988 char_O_ascenttime = (char)temp1; | |
1989 | |
1990 for(ci=0;ci<7;ci++) | |
1991 { | |
1992 x = char_O_ascenttime + char_O_array_decotime[ci]; | |
1993 if (x < char_O_ascenttime) | |
1994 char_O_ascenttime = 255; | |
1995 else | |
1996 char_O_ascenttime = x; | |
1997 } | |
1998 } | |
1999 } | |
2000 else | |
2001 char_O_ascenttime = 0; | |
2002 } // calc_ascenttime() | |
2003 | |
2004 | |
2005 // --------------------- | |
2006 // update_startvalues // | |
2007 // --------------------- | |
2008 // updated in v.102 | |
2009 | |
2010 void update_startvalues(void) | |
2011 { | |
2012 temp_pres_gtissue_limit = pres_gtissue_limit; | |
2013 temp_pres_gtissue = pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]; | |
2014 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; // negative number | |
2015 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; | |
2016 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; | |
2017 if (temp_pres_gtissue_limit_GF_low_below_surface < 0) | |
2018 temp_pres_gtissue_limit_GF_low_below_surface = 0; | |
2019 | |
2020 temp_gtissue_no = char_O_gtissue_no; | |
2021 for (x = 0;x<16;x++) | |
2022 { | |
2023 sim_pres_tissue[x] = pres_tissue[x]; | |
2024 sim_pres_tissue[x+16] = pres_tissue[x+16]; | |
2025 sim_pres_tissue_limit[x] = pres_tissue_limit[x]; | |
2026 } | |
2027 } // update_startvalues | |
2028 | |
2029 | |
2030 // ------------------ | |
2031 // sim_tissue_1min // | |
2032 // ------------------ | |
2033 // optimized in v.101 | |
2034 | |
2035 void sim_tissue_1min(void) | |
2036 { | |
2037 temp_pres_gtissue_limit = 0.0; | |
2038 temp_gtissue_no = 255; | |
2039 | |
2040 _asm | |
2041 lfsr 1, 0x300 | |
2042 movlw 0x01 | |
2043 movwf TBLPTRU,0 | |
2044 _endasm | |
2045 | |
2046 | |
2047 for (ci=0;ci<16;ci++) | |
2048 { | |
2049 _asm | |
2050 movlw 0x02 | |
2051 movwf TBLPTRH,0 | |
2052 movlb 4 // fuer ci | |
2053 movf ci,0,1 | |
2054 addwf ci,0,1 | |
2055 addwf ci,0,1 | |
2056 addwf ci,0,1 | |
2057 addlw 0x80 | |
2058 movwf TBLPTRL,0 | |
2059 TBLRDPOSTINC | |
2060 movff TABLAT,var_a+1 | |
2061 TBLRDPOSTINC | |
2062 movff TABLAT,var_a | |
2063 TBLRDPOSTINC | |
2064 movff TABLAT,var_a+3 | |
2065 TBLRD | |
2066 movff TABLAT,var_a+2 | |
2067 addlw 0x40 | |
2068 movwf TBLPTRL,0 | |
2069 TBLRDPOSTINC | |
2070 movff TABLAT,var2_a+1 | |
2071 TBLRDPOSTINC | |
2072 movff TABLAT,var2_a | |
2073 TBLRDPOSTINC | |
2074 movff TABLAT,var2_a+3 | |
2075 TBLRD | |
2076 movff TABLAT,var2_a+2 | |
2077 addlw 0x40 | |
2078 movwf TBLPTRL,0 | |
2079 incf TBLPTRH,1,0 | |
2080 TBLRDPOSTINC | |
2081 movff TABLAT,var_b+1 | |
2082 TBLRDPOSTINC | |
2083 movff TABLAT,var_b | |
2084 TBLRDPOSTINC | |
2085 movff TABLAT,var_b+3 | |
2086 TBLRD | |
2087 movff TABLAT,var_b+2 | |
2088 addlw 0x40 | |
2089 movwf TBLPTRL,0 | |
2090 TBLRDPOSTINC | |
2091 movff TABLAT,var2_b+1 | |
2092 TBLRDPOSTINC | |
2093 movff TABLAT,var2_b | |
2094 TBLRDPOSTINC | |
2095 movff TABLAT,var2_b+3 | |
2096 TBLRD | |
2097 movff TABLAT,var2_b+2 | |
2098 addlw 0xC0 | |
2099 movwf TBLPTRL,0 | |
2100 incf TBLPTRH,1,0 | |
2101 TBLRDPOSTINC | |
2102 movff TABLAT,var_e1min+1 | |
2103 TBLRDPOSTINC | |
2104 movff TABLAT,var_e1min | |
2105 TBLRDPOSTINC | |
2106 movff TABLAT,var_e1min+3 | |
2107 TBLRD | |
2108 movff TABLAT,var_e1min+2 | |
2109 addlw 0x40 | |
2110 movwf TBLPTRL,0 | |
2111 TBLRDPOSTINC | |
2112 movff TABLAT,var2_e1min+1 | |
2113 TBLRDPOSTINC | |
2114 movff TABLAT,var2_e1min | |
2115 TBLRDPOSTINC | |
2116 movff TABLAT,var2_e1min+3 | |
2117 TBLRD | |
2118 movff TABLAT,var2_e1min+2 | |
2119 _endasm | |
2120 // N2 | |
2121 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_e1min; | |
2122 temp_tissue_safety(); | |
2123 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; | |
2124 // He | |
2125 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var2_e1min; | |
2126 temp_tissue_safety(); | |
2127 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue; | |
2128 // pressure limit | |
2129 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16]; | |
2130 var_a = (var_a * sim_pres_tissue[ci] + var2_a * sim_pres_tissue[ci+16]) / temp_tissue; | |
2131 var_b = (var_b * sim_pres_tissue[ci] + var2_b * sim_pres_tissue[ci+16]) / temp_tissue; | |
2132 sim_pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
2133 | |
2134 if (sim_pres_tissue_limit[ci] < 0) | |
2135 sim_pres_tissue_limit[ci] = 0; | |
2136 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit) | |
2137 { | |
2138 temp_pres_gtissue = temp_tissue; | |
2139 temp_pres_gtissue_limit = sim_pres_tissue_limit[ci]; | |
2140 temp_gtissue_no = ci; | |
2141 } | |
2142 } // for | |
2143 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; | |
2144 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; | |
2145 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; | |
2146 if (temp_pres_gtissue_limit_GF_low_below_surface < 0) | |
2147 temp_pres_gtissue_limit_GF_low_below_surface = 0; | |
2148 } //sim_tissue_1min() | |
2149 | |
2150 //-------------------- | |
2151 // sim_tissue_10min // | |
2152 //-------------------- | |
2153 | |
2154 // Attention!! uses var_e1min und var2_e1min to load 10min data !!! | |
2155 // is identical to sim_tissue_1min routine except for the different load of those variables | |
2156 | |
2157 // optimized in v.101 | |
2158 | |
2159 void sim_tissue_10min(void) | |
2160 { | |
2161 temp_pres_gtissue_limit = 0.0; | |
2162 temp_gtissue_no = 255; | |
2163 | |
2164 _asm | |
2165 lfsr 1, 0x300 | |
2166 movlw 0x01 | |
2167 movwf TBLPTRU,0 | |
2168 _endasm | |
2169 | |
2170 for (ci=0;ci<16;ci++) | |
2171 { | |
2172 _asm | |
2173 movlw 0x02 | |
2174 movwf TBLPTRH,0 | |
2175 movlb 4 // fuer ci | |
2176 movf ci,0,1 | |
2177 addwf ci,0,1 | |
2178 addwf ci,0,1 | |
2179 addwf ci,0,1 | |
2180 addlw 0x80 | |
2181 movwf TBLPTRL,0 | |
2182 TBLRDPOSTINC | |
2183 movff TABLAT,var_a+1 | |
2184 TBLRDPOSTINC | |
2185 movff TABLAT,var_a | |
2186 TBLRDPOSTINC | |
2187 movff TABLAT,var_a+3 | |
2188 TBLRD | |
2189 movff TABLAT,var_a+2 | |
2190 addlw 0x40 | |
2191 movwf TBLPTRL,0 | |
2192 TBLRDPOSTINC | |
2193 movff TABLAT,var2_a+1 | |
2194 TBLRDPOSTINC | |
2195 movff TABLAT,var2_a | |
2196 TBLRDPOSTINC | |
2197 movff TABLAT,var2_a+3 | |
2198 TBLRD | |
2199 movff TABLAT,var2_a+2 | |
2200 addlw 0x40 | |
2201 movwf TBLPTRL,0 | |
2202 incf TBLPTRH,1,0 | |
2203 TBLRDPOSTINC | |
2204 movff TABLAT,var_b+1 | |
2205 TBLRDPOSTINC | |
2206 movff TABLAT,var_b | |
2207 TBLRDPOSTINC | |
2208 movff TABLAT,var_b+3 | |
2209 TBLRD | |
2210 movff TABLAT,var_b+2 | |
2211 addlw 0x40 | |
2212 movwf TBLPTRL,0 | |
2213 TBLRDPOSTINC | |
2214 movff TABLAT,var2_b+1 | |
2215 TBLRDPOSTINC | |
2216 movff TABLAT,var2_b | |
2217 TBLRDPOSTINC | |
2218 movff TABLAT,var2_b+3 | |
2219 TBLRD | |
2220 movff TABLAT,var2_b+2 | |
2221 addlw 0xC0 // different to 1 min | |
2222 movwf TBLPTRL,0 | |
2223 incf TBLPTRH,1,0 | |
2224 incf TBLPTRH,1,0 // different to 1 min | |
2225 TBLRDPOSTINC | |
2226 movff TABLAT,var_e1min+1 | |
2227 TBLRDPOSTINC | |
2228 movff TABLAT,var_e1min | |
2229 TBLRDPOSTINC | |
2230 movff TABLAT,var_e1min+3 | |
2231 TBLRD | |
2232 movff TABLAT,var_e1min+2 | |
2233 addlw 0x40 | |
2234 movwf TBLPTRL,0 | |
2235 //incf TBLPTRH,1,0 // different to 1 min | |
2236 TBLRDPOSTINC | |
2237 movff TABLAT,var2_e1min+1 | |
2238 TBLRDPOSTINC | |
2239 movff TABLAT,var2_e1min | |
2240 TBLRDPOSTINC | |
2241 movff TABLAT,var2_e1min+3 | |
2242 TBLRD | |
2243 movff TABLAT,var2_e1min+2 | |
2244 _endasm | |
2245 // N2 | |
2246 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_e1min; | |
2247 temp_tissue_safety(); | |
2248 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; | |
2249 // He | |
2250 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var2_e1min; | |
2251 temp_tissue_safety(); | |
2252 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue; | |
2253 // pressure limit | |
2254 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16]; | |
2255 var_a = (var_a * sim_pres_tissue[ci] + var2_a * sim_pres_tissue[ci+16]) / temp_tissue; | |
2256 var_b = (var_b * sim_pres_tissue[ci] + var2_b * sim_pres_tissue[ci+16]) / temp_tissue; | |
2257 | |
2258 sim_pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
2259 if (sim_pres_tissue_limit[ci] < 0) | |
2260 sim_pres_tissue_limit[ci] = 0; | |
2261 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit) | |
2262 { | |
2263 temp_pres_gtissue = temp_tissue; | |
2264 temp_pres_gtissue_limit = sim_pres_tissue_limit[ci]; | |
2265 temp_gtissue_no = ci; | |
2266 } | |
2267 } // for | |
2268 temp_pres_gtissue_diff = temp_pres_gtissue_limit - temp_pres_gtissue; // negative number | |
2269 temp_pres_gtissue_limit_GF_low = GF_low * temp_pres_gtissue_diff + temp_pres_gtissue; | |
2270 temp_pres_gtissue_limit_GF_low_below_surface = temp_pres_gtissue_limit_GF_low - pres_surface; | |
2271 if (temp_pres_gtissue_limit_GF_low_below_surface < 0) | |
2272 temp_pres_gtissue_limit_GF_low_below_surface = 0; | |
2273 } //sim_tissue_10min() | |
2274 | |
2275 | |
2276 // ------------------ | |
2277 // clear_decoarray // | |
2278 // ------------------ | |
2279 // unchanged in v.101 | |
2280 | |
2281 void clear_decoarray(void) | |
2282 { | |
2283 char_O_array_decodepth[0] = 0; | |
2284 char_O_array_decodepth[1] = 0; | |
2285 char_O_array_decodepth[2] = 0; | |
2286 char_O_array_decodepth[3] = 0; | |
2287 char_O_array_decodepth[4] = 0; | |
2288 char_O_array_decodepth[5] = 0; | |
2289 char_O_array_decotime[0] = 0; | |
2290 char_O_array_decotime[1] = 0; | |
2291 char_O_array_decotime[2] = 0; | |
2292 char_O_array_decotime[3] = 0; | |
2293 char_O_array_decotime[4] = 0; | |
2294 char_O_array_decotime[5] = 0; | |
2295 char_O_array_decotime[6] = 0; | |
2296 } // clear_decoarray | |
2297 | |
2298 | |
2299 // ------------------- | |
2300 // update_decoarray // | |
2301 // ------------------- | |
2302 // unchanged in v.101 | |
2303 | |
2304 void update_decoarray() | |
2305 { | |
2306 x = 0; | |
2307 do | |
2308 { | |
2309 if (char_O_array_decodepth[x] == temp_depth_limit) | |
2310 { | |
2311 int_temp = char_O_array_decotime[x] + temp_decotime; | |
2312 if (int_temp < 0) | |
2313 int_temp = 0; | |
2314 if (int_temp > 240) | |
2315 int_temp = 240; | |
2316 char_O_array_decotime[x] = int_temp; | |
2317 x = 10; // exit | |
2318 } // if | |
2319 else | |
2320 { | |
2321 if (char_O_array_decodepth[x] == 0) | |
2322 { | |
2323 if (temp_depth_limit > 255) | |
2324 char_O_array_decodepth[x] = 255; | |
2325 else | |
2326 char_O_array_decodepth[x] = (char)temp_depth_limit; | |
2327 int_temp = char_O_array_decotime[x] + temp_decotime; | |
2328 if (int_temp > 240) | |
2329 char_O_array_decotime[x] = 240; | |
2330 else | |
2331 char_O_array_decotime[x] = (char)int_temp; | |
2332 x = 10; // exit | |
2333 } // if | |
2334 else | |
2335 x++; | |
2336 } // else | |
2337 } while (x<6); | |
2338 if (x == 6) | |
2339 { | |
2340 int_temp = char_O_array_decotime[6] + temp_decotime; | |
2341 if (int_temp > 220) | |
2342 char_O_array_decotime[6] = 220; | |
2343 else | |
2344 char_O_array_decotime[6] = (char)int_temp; | |
2345 } // if x == 6 | |
2346 } // update_decoarray | |
2347 | |
2348 | |
2349 // ----------------------- | |
2350 // calc_gradient_factor // | |
2351 // ----------------------- | |
2352 // optimized in v.101 (var_a) | |
2353 // new code in v.102 | |
2354 | |
2355 void calc_gradient_factor(void) | |
2356 { | |
2357 // tissue > respiration (entsaettigungsvorgang) | |
2358 // gradient ist wieviel prozent an limit mit basis tissue | |
2359 // dh. 0% = respiration == tissue | |
2360 // dh. 100% = respiration == limit | |
2361 temp_tissue = pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16]; | |
2362 temp1 = temp_tissue - pres_respiration; | |
2363 temp2 = temp_tissue - pres_tissue_limit[char_O_gtissue_no]; // changed in v.102 | |
2364 temp2 = temp1/temp2; | |
2365 temp2 = temp2 * 100; // displayed in percent | |
2366 if (temp2 < 0) | |
2367 temp2 = 0; | |
2368 if (temp2 > 255) | |
2369 temp2 = 255; | |
2370 if (temp1 < 0) | |
2371 char_O_gradient_factor = 0; | |
2372 else | |
2373 char_O_gradient_factor = (char)temp2; | |
2374 | |
2375 temp3 = temp2; | |
2376 | |
2377 if (char_I_deco_model == 1) // calculate relative gradient factor | |
2378 { | |
2379 temp1 = (float)temp_depth_GF_low_meter * 0.09995; | |
2380 temp2 = pres_respiration - pres_surface; | |
2381 if (temp2 <= 0) | |
2382 temp1 = GF_high; | |
2383 else | |
2384 if (temp2 >= temp1) | |
2385 temp1 = GF_low; | |
2386 else | |
2387 temp1 = GF_low + (temp1 - temp2)/temp1*GF_delta; | |
2388 if (temp_depth_GF_low_meter == 0) | |
2389 temp1 = GF_high; | |
2390 temp2 = temp3 / temp1; // temp3 is already in percent | |
2391 if (temp2 < 0) | |
2392 temp2 = 0; | |
2393 if (temp2 > 255) | |
2394 temp2 = 255; | |
2395 char_O_relative_gradient_GF = (char)temp2; | |
2396 } // calc relative gradient factor | |
2397 else | |
2398 { | |
2399 char_O_relative_gradient_GF = char_O_gradient_factor; | |
2400 } | |
2401 } // calc_gradient | |
2402 | |
2403 // --------------------------- | |
2404 // calc_gradient_array_only // | |
2405 // --------------------------- | |
2406 // optimized in v.101 (var_a) | |
2407 // new code in v.102 | |
2408 | |
2409 void calc_gradient_array_only() | |
2410 { | |
2411 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | |
2412 for (ci=0;ci<16;ci++) | |
2413 { | |
2414 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; | |
2415 temp1 = temp_tissue - pres_respiration; | |
2416 temp2 = temp_tissue - pres_tissue_limit[ci]; | |
2417 temp2 = temp1/temp2; | |
2418 temp2 = temp2 * 200; // because of output in (Double-)percentage | |
2419 if (temp2 < 0) | |
2420 temp2 = 0; | |
2421 if (temp2 > 255) | |
2422 temp2 = 255; | |
2423 if (temp1 < 0) | |
2424 char_O_array_gradient_weighted[ci] = 0; | |
2425 else | |
2426 char_O_array_gradient_weighted[ci] = (char)temp2; | |
2427 } // for | |
2428 } // calc_gradient_array_only | |
2429 | |
2430 | |
2431 // ------------------------- | |
2432 // calc_desaturation_time // | |
2433 // ------------------------- | |
2434 // FIXED N2_ratio | |
2435 // unchanged in v.101 | |
2436 | |
2437 void calc_desaturation_time(void) | |
2438 { | |
2439 _asm | |
2440 lfsr 1, 0x300 | |
2441 movlw 0x01 | |
2442 movwf TBLPTRU,0 | |
2443 _endasm | |
2444 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann | |
2445 pres_surface = (float)int_I_pres_surface / 1000.0; | |
2446 temp_atem = N2_ratio * (pres_surface - 0.0627); | |
2447 int_O_desaturation_time = 0; | |
2448 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) | |
2449 | |
2450 for (ci=0;ci<16;ci++) | |
2451 { | |
2452 _asm | |
2453 movlw 0x04 | |
2454 movwf TBLPTRH,0 | |
2455 movlb 4 // fuer ci | |
2456 movf ci,0,1 | |
2457 addwf ci,0,1 | |
2458 addwf ci,0,1 | |
2459 addwf ci,0,1 | |
2460 addlw 0x80 | |
2461 movwf TBLPTRL,0 | |
2462 TBLRDPOSTINC | |
2463 movff TABLAT,var_halftimes+1 | |
2464 TBLRDPOSTINC | |
2465 movff TABLAT,var_halftimes | |
2466 TBLRDPOSTINC | |
2467 movff TABLAT,var_halftimes+3 | |
2468 TBLRD | |
2469 movff TABLAT,var_halftimes+2 | |
2470 addlw 0x40 | |
2471 movwf TBLPTRL,0 | |
2472 TBLRDPOSTINC | |
2473 movff TABLAT,var2_halftimes+1 | |
2474 TBLRDPOSTINC | |
2475 movff TABLAT,var2_halftimes | |
2476 TBLRDPOSTINC | |
2477 movff TABLAT,var2_halftimes+3 | |
2478 TBLRD | |
2479 movff TABLAT,var2_halftimes+2 | |
2480 _endasm | |
2481 | |
2482 // saturation_time (for flight) and N2_saturation in multiples of halftime | |
2483 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
2484 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
2485 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations | |
2486 // N2 | |
2487 temp1 = 1.05 * temp_atem; | |
2488 temp1 = temp1 - pres_tissue[ci]; | |
2489 temp2 = temp_atem - pres_tissue[ci]; | |
2490 if (temp2 >= 0.0) | |
2491 { | |
2492 temp1 = 0; | |
2493 temp2 = 0; | |
2494 } | |
2495 else | |
2496 temp1 = temp1 / temp2; | |
2497 if (temp1 > 0.0) | |
2498 { | |
2499 temp1 = log(1.0 - temp1); | |
2500 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary. | |
2501 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
2502 // minus because log is negative | |
2503 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 | |
2504 } | |
2505 else | |
2506 { | |
2507 temp1 = 0; | |
2508 temp2 = 0; | |
2509 } | |
2510 | |
2511 // He | |
2512 temp3 = 0.1 - pres_tissue[ci+16]; | |
2513 if (temp3 >= 0.0) | |
2514 { | |
2515 temp3 = 0; | |
2516 temp4 = 0; | |
2517 } | |
2518 else | |
2519 temp3 = -1.0 * temp3 / pres_tissue[ci+16]; | |
2520 if (temp3 > 0.0) | |
2521 { | |
2522 temp3 = log(1.0 - temp3); | |
2523 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. | |
2524 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
2525 // minus because log is negative | |
2526 temp4 = var2_halftimes * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier | |
2527 } | |
2528 else | |
2529 { | |
2530 temp3 = 0; | |
2531 temp4 = 0; | |
2532 } | |
2533 | |
2534 // saturation_time (for flight) | |
2535 if (temp4 > temp2) | |
2536 int_temp = (int)temp4; | |
2537 else | |
2538 int_temp = (int)temp2; | |
2539 if(int_temp > int_O_desaturation_time) | |
2540 int_O_desaturation_time = int_temp; | |
2541 | |
2542 // N2 saturation in multiples of halftime for display purposes | |
2543 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
2544 temp2 = temp2 + 80.0; // set center | |
2545 if (temp2 < 0.0) | |
2546 temp2 = 0.0; | |
2547 if (temp2 > 255.0) | |
2548 temp2 = 255.0; | |
2549 char_O_tissue_saturation[ci] = (char)temp2; | |
2550 // He saturation in multiples of halftime for display purposes | |
2551 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
2552 temp4 = temp4 + 80.0; // set center | |
2553 if (temp4 < 0.0) | |
2554 temp4 = 0.0; | |
2555 if (temp4 > 255.0) | |
2556 temp4 = 255.0; | |
2557 char_O_tissue_saturation[ci+16] = (char)temp4; | |
2558 } // for | |
2559 } // calc_desaturation_time | |
2560 | |
2561 | |
2562 // -------------------------- | |
2563 // calc_wo_deco_step_1_min // | |
2564 // -------------------------- | |
2565 // FIXED N2 Ratio | |
2566 // optimized in v.101 (...saturation_multiplier) | |
2567 // desaturation slowed down to 70,42% | |
2568 | |
2569 void calc_wo_deco_step_1_min(void) | |
2570 { | |
2571 if(flag_in_divemode) | |
2572 { | |
2573 flag_in_divemode = 0; | |
2574 set_dbg_end_of_dive(); | |
2575 } | |
2576 _asm | |
2577 lfsr 1, 0x300 | |
2578 _endasm | |
2579 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann | |
2580 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | |
2581 pres_surface = (float)int_I_pres_surface / 1000.0; | |
2582 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body | |
2583 temp2_atem = 0.0; | |
2584 temp_surface = pres_surface; // the b"uhlmann formula using temp_surface does not use the N2_ratio | |
2585 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) | |
2586 float_saturation_multiplier = char_I_saturation_multiplier / 100.0; | |
2587 | |
2588 calc_tissue_step_1_min(); // update the pressure in the 16 tissues in accordance with the new ambient pressure | |
2589 clear_decoarray(); | |
2590 char_O_deco_status = 0; | |
2591 char_O_nullzeit = 0; | |
2592 char_O_ascenttime = 0; | |
2593 calc_gradient_factor(); | |
2594 | |
2595 } // calc_wo_deco_step_1_min(void) | |
2596 | |
2597 | |
2598 // ------------------------- | |
2599 // calc_tissue_step_1_min // | |
2600 // ------------------------- | |
2601 // optimized in v.101 | |
2602 | |
2603 void calc_tissue_step_1_min(void) | |
2604 { | |
2605 _asm | |
2606 lfsr 1, 0x300 | |
2607 movlw 0x01 | |
2608 movwf TBLPTRU,0 | |
2609 _endasm | |
2610 | |
2611 char_O_gtissue_no = 255; | |
2612 pres_gtissue_limit = 0.0; | |
2613 | |
2614 for (ci=0;ci<16;ci++) | |
2615 { | |
2616 _asm | |
2617 movlw 0x02 | |
2618 movwf TBLPTRH,0 | |
2619 movlb 4 // fuer ci | |
2620 movf ci,0,1 | |
2621 addwf ci,0,1 | |
2622 addwf ci,0,1 | |
2623 addwf ci,0,1 | |
2624 addlw 0x80 | |
2625 movwf TBLPTRL,0 | |
2626 TBLRDPOSTINC | |
2627 movff TABLAT,var_a+1 | |
2628 TBLRDPOSTINC | |
2629 movff TABLAT,var_a | |
2630 TBLRDPOSTINC | |
2631 movff TABLAT,var_a+3 | |
2632 TBLRD | |
2633 movff TABLAT,var_a+2 | |
2634 addlw 0x40 | |
2635 movwf TBLPTRL,0 | |
2636 TBLRDPOSTINC | |
2637 movff TABLAT,var2_a+1 | |
2638 TBLRDPOSTINC | |
2639 movff TABLAT,var2_a | |
2640 TBLRDPOSTINC | |
2641 movff TABLAT,var2_a+3 | |
2642 TBLRD | |
2643 movff TABLAT,var2_a+2 | |
2644 addlw 0x40 | |
2645 movwf TBLPTRL,0 | |
2646 incf TBLPTRH,1,0 | |
2647 TBLRDPOSTINC | |
2648 movff TABLAT,var_b+1 | |
2649 TBLRDPOSTINC | |
2650 movff TABLAT,var_b | |
2651 TBLRDPOSTINC | |
2652 movff TABLAT,var_b+3 | |
2653 TBLRD | |
2654 movff TABLAT,var_b+2 | |
2655 addlw 0x40 | |
2656 movwf TBLPTRL,0 | |
2657 TBLRDPOSTINC | |
2658 movff TABLAT,var2_b+1 | |
2659 TBLRDPOSTINC | |
2660 movff TABLAT,var2_b | |
2661 TBLRDPOSTINC | |
2662 movff TABLAT,var2_b+3 | |
2663 TBLRD | |
2664 movff TABLAT,var2_b+2 | |
2665 addlw 0xC0 | |
2666 movwf TBLPTRL,0 | |
2667 incf TBLPTRH,1,0 | |
2668 TBLRDPOSTINC | |
2669 movff TABLAT,var_e1min+1 | |
2670 TBLRDPOSTINC | |
2671 movff TABLAT,var_e1min | |
2672 TBLRDPOSTINC | |
2673 movff TABLAT,var_e1min+3 | |
2674 TBLRD | |
2675 movff TABLAT,var_e1min+2 | |
2676 addlw 0x40 | |
2677 movwf TBLPTRL,0 | |
2678 TBLRDPOSTINC | |
2679 movff TABLAT,var2_e1min+1 | |
2680 TBLRDPOSTINC | |
2681 movff TABLAT,var2_e1min | |
2682 TBLRDPOSTINC | |
2683 movff TABLAT,var2_e1min+3 | |
2684 TBLRD | |
2685 movff TABLAT,var2_e1min+2 | |
2686 _endasm | |
2687 | |
2688 // N2 1 min | |
2689 temp_tissue = (temp_atem - pres_tissue[ci]) * var_e1min; | |
2690 temp_tissue_safety(); | |
2691 pres_tissue[ci] = pres_tissue[ci] + temp_tissue; | |
2692 | |
2693 // He 1 min | |
2694 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var2_e1min; | |
2695 temp_tissue_safety(); | |
2696 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue; | |
2697 | |
2698 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; | |
2699 var_a = (var_a * pres_tissue[ci] + var2_a * pres_tissue[ci+16]) / temp_tissue; | |
2700 var_b = (var_b * pres_tissue[ci] + var2_b * pres_tissue[ci+16]) / temp_tissue; | |
2701 pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; | |
2702 if (pres_tissue_limit[ci] < 0) | |
2703 pres_tissue_limit[ci] = 0; | |
2704 if (pres_tissue_limit[ci] > pres_gtissue_limit) | |
2705 { | |
2706 pres_gtissue_limit = pres_tissue_limit[ci]; | |
2707 char_O_gtissue_no = ci; | |
2708 }//if | |
2709 | |
2710 // gradient factor array for graphical display | |
2711 // display range is 0 to 250! in steps of 5 for 1 pixel | |
2712 // the display is divided in 6 blocks | |
2713 // -> double the gradient 100% = 200 | |
2714 // tissue > respiration (entsaettigungsvorgang) | |
2715 // gradient ist wieviel prozent an limit von tissue aus | |
2716 // dh. 0% = respiration == tissue | |
2717 // dh. 100% = respiration == limit | |
2718 temp1 = temp_tissue - pres_respiration; | |
2719 temp2 = temp_tissue - pres_tissue_limit[ci]; // changed in v.102 | |
2720 temp2 = temp1/temp2; | |
2721 temp2 = temp2 * 200; // because of output in (Double-)percentage | |
2722 if (temp2 < 0) | |
2723 temp2 = 0; | |
2724 if (temp2 > 255) | |
2725 temp2 = 255; | |
2726 if (temp1 < 0) | |
2727 char_O_array_gradient_weighted[ci] = 0; | |
2728 else | |
2729 char_O_array_gradient_weighted[ci] = (char)temp2; | |
2730 | |
2731 } // for | |
2732 } // calc wo deco 1min | |
2733 | |
2734 #if 0 | |
2735 // -------- | |
2736 // debug // | |
2737 // -------- | |
2738 void debug(void) | |
2739 { | |
2740 for (ci=0;ci<32;ci++) | |
2741 { | |
2742 int_O_tissue_for_debug[ci] = (unsigned int)(pres_tissue[ci] *1000); | |
2743 } | |
2744 } // void debug(void) | |
2745 #endif | |
2746 | |
2747 // ---------- | |
2748 // md hash // | |
2749 // ---------- | |
2750 void hash(void) | |
2751 { | |
2752 // init | |
2753 for (md_i=0;md_i<16;md_i++) | |
2754 { | |
2755 md_state[md_i] = 0; | |
2756 md_cksum[md_i] = 0; | |
2757 } // for md_i 16 | |
2758 | |
2759 _asm | |
2760 movlw 0x01 | |
2761 movwf TBLPTRU,0 | |
2762 movlw 0x06 | |
2763 movwf TBLPTRH,0 | |
2764 movlw 0x00 | |
2765 movwf TBLPTRL,0 | |
2766 _endasm | |
2767 for (md_i=0;md_i<127;md_i++) | |
2768 { | |
2769 _asm | |
2770 TBLRDPOSTINC | |
2771 movff TABLAT,md_temp | |
2772 _endasm | |
2773 md_pi_subst[md_i] = md_temp; | |
2774 } // for md_i 256 | |
2775 _asm | |
2776 TBLRDPOSTINC | |
2777 movff TABLAT,md_temp | |
2778 _endasm | |
2779 md_pi_subst[127] = md_temp; | |
2780 for (md_i=0;md_i<127;md_i++) | |
2781 { | |
2782 _asm | |
2783 TBLRDPOSTINC | |
2784 movff TABLAT,md_temp | |
2785 _endasm | |
2786 md_pi_subst[md_i+128] = md_temp; | |
2787 } // for md_i 256 | |
2788 _asm | |
2789 TBLRD | |
2790 movff TABLAT,md_temp | |
2791 _endasm | |
2792 md_pi_subst[255] = md_temp; | |
2793 | |
2794 _asm | |
2795 movlw 0x00 | |
2796 movwf TBLPTRU,0 | |
2797 movlw 0x00 | |
2798 movwf TBLPTRH,0 | |
2799 movlw 0x00 | |
2800 movwf TBLPTRL,0 | |
2801 _endasm | |
2802 // cycle buffers | |
2803 for (md_pointer=0x0000;md_pointer<0x17f3;md_pointer++) | |
2804 { | |
2805 md_t = 0; | |
2806 for (md_i=0;md_i<16;md_i++) | |
2807 { | |
2808 if(md_pointer == 9) | |
2809 md_temp = md_cksum[md_i]; | |
2810 else | |
2811 { | |
2812 _asm | |
2813 TBLRDPOSTINC | |
2814 movff TABLAT,md_temp | |
2815 _endasm | |
2816 } // else | |
2817 md_buffer[md_i] = md_temp; | |
2818 md_state[md_i+16] = md_buffer[md_i]; | |
2819 md_state[md_i+32] = (unsigned char)(md_buffer[md_i] ^ md_state[md_i]); | |
2820 } // for md_i 16 | |
2821 | |
2822 for (md_i=0;md_i<18;md_i++) | |
2823 { | |
2824 for (md_j=0;md_j<48;md_j++) | |
2825 { | |
2826 md_state[md_j] = (unsigned char)(md_state[md_j] ^ md_pi_subst[md_t]); | |
2827 md_t = md_state[md_j]; | |
2828 } // for md_j 48 | |
2829 md_t = (unsigned char)(md_t+1); | |
2830 } // for md_i 18 | |
2831 md_t = md_cksum[15]; | |
2832 | |
2833 for (md_i=0;md_i<16;md_i++) | |
2834 { | |
2835 md_cksum[md_i] = (unsigned char)(md_cksum[md_i] ^ md_pi_subst[(md_buffer[md_i] ^ md_t)]); | |
2836 md_t = md_cksum[md_i]; | |
2837 } // for md_i 16 | |
2838 } // for md_pointer | |
2839 } // void hash(void) | |
2840 | |
2841 // --------------------- | |
2842 // clear_CNS_fraction // | |
2843 // --------------------- | |
2844 // new in v.101 | |
2845 | |
2846 void clear_CNS_fraction(void) | |
2847 { | |
2848 CNS_fraction = 0.0; | |
2849 char_O_CNS_fraction = 0; | |
2850 } // void clear_CNS_fraction(void) | |
2851 | |
2852 | |
2853 // -------------------- | |
2854 // calc_CNS_fraction // | |
2855 // -------------------- | |
2856 // new in v.101 | |
2857 // optimized in v.102 : with new variables char_I_actual_ppO2 and actual_ppO2 | |
2858 | |
2859 // Input: char_I_actual_ppO2 | |
2860 // Output: char_O_CNS_fraction | |
2861 // Uses and Updates: CNS_fraction | |
2862 // Uses: acutal_ppO2 | |
2863 | |
2864 void calc_CNS_fraction(void) | |
2865 { | |
2866 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; | |
2867 | |
2868 if (char_I_actual_ppO2 < 50) | |
2869 CNS_fraction = CNS_fraction;// no changes | |
2870 else if (char_I_actual_ppO2 < 60) | |
2871 CNS_fraction = 1/(-54000.0 * actual_ppO2 + 54000.0) + CNS_fraction; | |
2872 else if (char_I_actual_ppO2 < 70) | |
2873 CNS_fraction = 1/(-45000.0 * actual_ppO2 + 48600.0) + CNS_fraction; | |
2874 else if (char_I_actual_ppO2 < 80) | |
2875 CNS_fraction = 1/(-36000.0 * actual_ppO2 + 42300.0) + CNS_fraction; | |
2876 else if (char_I_actual_ppO2 < 90) | |
2877 CNS_fraction = 1/(-27000.0 * actual_ppO2 + 35100.0) + CNS_fraction; | |
2878 else if (char_I_actual_ppO2 < 110) | |
2879 CNS_fraction = 1/(-18000.0 * actual_ppO2 + 27000.0) + CNS_fraction; | |
2880 else if (char_I_actual_ppO2 < 150) | |
2881 CNS_fraction = 1/(-9000.0 * actual_ppO2 + 17100.0) + CNS_fraction; | |
2882 else if (char_I_actual_ppO2 < 160) | |
2883 CNS_fraction = 1/(-22500.0 * actual_ppO2 + 37350.0) + CNS_fraction; | |
2884 else if (char_I_actual_ppO2 < 165) | |
2885 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 | |
2886 else if (char_I_actual_ppO2 < 170) | |
2887 CNS_fraction = 0.00102 + CNS_fraction; // example calculation: Sqrt((1.7/1.55)^20)*0.000404 | |
2888 else if (char_I_actual_ppO2 < 175) | |
2889 CNS_fraction = 0.00136 + CNS_fraction; | |
2890 else if (char_I_actual_ppO2 < 180) | |
2891 CNS_fraction = 0.00180 + CNS_fraction; | |
2892 else if (char_I_actual_ppO2 < 185) | |
2893 CNS_fraction = 0.00237 + CNS_fraction; | |
2894 else if (char_I_actual_ppO2 < 190) | |
2895 CNS_fraction = 0.00310 + CNS_fraction; | |
2896 else if (char_I_actual_ppO2 < 195) | |
2897 CNS_fraction = 0.00401 + CNS_fraction; | |
2898 else if (char_I_actual_ppO2 < 200) | |
2899 CNS_fraction = 0.00517 + CNS_fraction; | |
2900 else if (char_I_actual_ppO2 < 230) | |
2901 CNS_fraction = 0.0209 + CNS_fraction; | |
2902 else | |
2903 CNS_fraction = 0.0482 + CNS_fraction; // value for 2.5 | |
2904 | |
2905 if (CNS_fraction > 2.5) | |
2906 CNS_fraction = 2.5; | |
2907 if (CNS_fraction < 0.0) | |
2908 CNS_fraction = 0.0; | |
2909 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); | |
2910 } // void calc_CNS_fraction(void) | |
2911 | |
2912 // -------------------------- | |
2913 // calc_CNS_decrease_15min // | |
2914 // -------------------------- | |
2915 // new in v.101 | |
2916 | |
2917 // calculates the half time of 90 minutes in 6 steps of 15 min | |
2918 | |
2919 // Output: char_O_CNS_fraction | |
2920 // Uses and Updates: CNS_fraction | |
2921 | |
2922 void calc_CNS_decrease_15min(void) | |
2923 { | |
2924 CNS_fraction = 0.890899 * CNS_fraction; | |
2925 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); | |
2926 }// calc_CNS_decrease_15min(void) | |
2927 | |
2928 | |
2929 // ------------------ | |
2930 // calc_percentage // | |
2931 // ------------------ | |
2932 // new in v.101 | |
2933 | |
2934 // calculates int_I_temp * char_I_temp / 100 | |
2935 // output is int_I_temp | |
2936 | |
2937 void calc_percentage(void) | |
2938 { | |
2939 temp1 = (float)int_I_temp; | |
2940 temp2 = (float)char_I_temp / 100.0; | |
2941 temp3 = temp1 * temp2; | |
2942 int_I_temp = (int)temp3; | |
2943 } | |
2944 void push_tissues_to_vault(void) | |
2945 { | |
2946 for (ci=0;ci<32;ci++) | |
2947 pres_tissue_vault[ci] = pres_tissue[ci]; | |
2948 } | |
2949 void pull_tissues_from_vault(void) | |
2950 { | |
2951 for (ci=0;ci<32;ci++) | |
2952 pres_tissue[ci] = pres_tissue_vault[ci]; | |
2953 } | |
2954 | |
2955 void wp_write_command(void) | |
2956 { | |
2957 _asm | |
2958 bcf oled_rs | |
2959 nop | |
2960 movff wp_command,PORTD | |
2961 bcf oled_rw | |
2962 nop | |
2963 bsf oled_rw | |
2964 _endasm | |
2965 } | |
2966 | |
2967 void wp_write_data(void) | |
2968 { | |
2969 wp_data_8bit_one = wp_data_16bit >> 8; | |
2970 wp_data_8bit_two = wp_data_16bit; | |
2971 _asm | |
2972 bsf oled_rs | |
2973 nop | |
2974 movff wp_data_8bit_one,PORTD | |
2975 bcf oled_rw | |
2976 nop | |
2977 bsf oled_rw | |
2978 nop | |
2979 movff wp_data_8bit_two,PORTD | |
2980 nop | |
2981 bcf oled_rw | |
2982 nop | |
2983 bsf oled_rw | |
2984 _endasm | |
2985 } | |
2986 | |
2987 void wp_write_black(void) | |
2988 { | |
2989 _asm | |
2990 movff wp_black,PORTD | |
2991 bcf oled_rw | |
2992 nop | |
2993 bsf oled_rw | |
2994 nop | |
2995 bcf oled_rw | |
2996 nop | |
2997 bsf oled_rw | |
2998 _endasm | |
2999 } | |
3000 | |
3001 void wp_write_color(void) | |
3002 { | |
3003 _asm | |
3004 movff wp_color1,PORTD | |
3005 bcf oled_rw | |
3006 nop | |
3007 bsf oled_rw | |
3008 nop | |
3009 movff wp_color2,PORTD | |
3010 bcf oled_rw | |
3011 nop | |
3012 bsf oled_rw | |
3013 _endasm | |
3014 } | |
3015 | |
3016 void wp_set_window(void) | |
3017 { | |
3018 // x axis start ( 0 - 319) | |
3019 wp_command = 0x35; | |
3020 wp_write_command(); | |
3021 wp_data_16bit = ((U16)wp_leftx2) << 1; | |
3022 wp_write_data(); | |
3023 // x axis end ( 0 - 319) | |
3024 wp_command = 0x36; | |
3025 wp_write_command(); | |
3026 wp_data_16bit = 319; | |
3027 wp_write_data(); | |
3028 // y axis start + end ( 0 - 239 ) | |
3029 wp_command = 0x37; | |
3030 wp_write_command(); | |
3031 // the bottom part | |
3032 wp_data_16bit = wp_top; | |
3033 if(wp_font == 2) | |
3034 wp_data_16bit += WP_FONT_LARGE_HEIGHT; | |
3035 else if(wp_font == 1) | |
3036 wp_data_16bit += WP_FONT_MEDIUM_HEIGHT; | |
3037 else | |
3038 wp_data_16bit += WP_FONT_SMALL_HEIGHT; | |
3039 wp_data_16bit--; | |
3040 if(wp_data_16bit > 239) | |
3041 wp_data_16bit = 239; | |
3042 // the top part | |
3043 wp_data_16bit |= ((U16)wp_top) << 8; | |
3044 // all together in one 16bit transfer | |
3045 wp_write_data(); | |
3046 | |
3047 // start | |
3048 wp_command = 0x20; | |
3049 wp_write_command(); | |
3050 wp_data_16bit = wp_top; | |
3051 wp_write_data(); | |
3052 | |
3053 wp_command = 0x21; | |
3054 wp_write_command(); | |
3055 wp_data_16bit = ((U16)wp_leftx2) << 1; | |
3056 wp_write_data(); | |
3057 } | |
3058 | |
3059 void wp_set_char_font_small(void) | |
3060 { | |
3061 if(wp_char == ' ') | |
3062 wp_char = '¶'; | |
3063 | |
3064 if (wp_char > 0x7E) // skip space between ~ and ¡ | |
3065 wp_char -= 34; | |
3066 | |
3067 if((wp_char < '!') || (wp_char > 0xA1)) // font has 34 chars after ~ // ¾ + 4 chars limit to end of battery at the moment | |
3068 wp_char = 0x82; // ¤ | |
3069 | |
3070 wp_start = wp_small_table[wp_char - '!']; | |
3071 wp_end = wp_small_table[1 + wp_char - '!']; | |
3072 } | |
3073 | |
3074 void wp_set_char_font_medium(void) | |
3075 { | |
3076 // space is 3E | |
3077 if (wp_char == 0x27) // 0x27 == ' | |
3078 wp_char = 0x3B; | |
3079 if (wp_char == '"') | |
3080 wp_char = 0x3C; | |
3081 if (wp_char == 'm') | |
3082 wp_char = 0x3D; | |
3083 if (wp_char == ' ') | |
3084 wp_char = 0x3E; | |
3085 | |
3086 if((wp_char < '.') || (wp_char > 0x3E)) | |
3087 wp_char = 0x3E; | |
3088 wp_start = wp_medium_table[wp_char - '.']; | |
3089 wp_end = wp_medium_table[1 + wp_char - '.']; | |
3090 } | |
3091 | |
3092 void wp_set_char_font_large(void) | |
3093 { | |
3094 // space is / = 0x2F | |
3095 if (wp_char == ' ') | |
3096 wp_char = 0x2F; | |
3097 | |
3098 if((wp_char < '.') || (wp_char > '9')) | |
3099 wp_char = 0x2F; | |
3100 wp_start = wp_large_table[wp_char - '.']; | |
3101 wp_end = wp_large_table[1 + wp_char - '.']; | |
3102 } | |
3103 | |
3104 void wordprocessor(void) | |
3105 { | |
3106 wp_set_window(); | |
3107 | |
3108 // access to GRAM | |
3109 wp_command = 0x22; | |
3110 wp_write_command(); | |
3111 _asm | |
3112 bsf oled_rs | |
3113 nop | |
3114 _endasm | |
3115 | |
3116 wp_txtptr = 0; | |
3117 wp_char = wp_stringstore[wp_txtptr]; | |
3118 | |
3119 while(wp_char) | |
3120 { | |
3121 if(wp_font == 2) | |
3122 wp_set_char_font_large(); | |
3123 else if(wp_font == 1) | |
3124 wp_set_char_font_medium(); | |
3125 else | |
3126 wp_set_char_font_small(); | |
3127 | |
3128 wp_black = 0; | |
3129 | |
3130 for(wp_i = wp_start; wp_i<wp_end;wp_i++) | |
3131 { | |
3132 if(wp_font == 2) | |
3133 wp_data_16bit = wp_large_data[wp_i / 2]; | |
3134 else if(wp_font == 1) | |
3135 wp_data_16bit = wp_medium_data[wp_i / 2]; | |
3136 else | |
3137 wp_data_16bit = wp_small_data[wp_i / 2]; | |
3138 if(wp_i & 1) | |
3139 wp_temp_U8 = wp_data_16bit & 0xFF; | |
3140 else | |
3141 wp_temp_U8 = wp_data_16bit >> 8; | |
3142 if((wp_temp_U8 & 128)) | |
3143 { | |
3144 wp_temp_U8 -= 127; | |
3145 if(wp_invert) | |
3146 { | |
3147 while(wp_temp_U8 > 0) | |
3148 { | |
3149 wp_temp_U8--; | |
3150 wp_write_color(); | |
3151 } | |
3152 } | |
3153 else | |
3154 { | |
3155 _asm | |
3156 movff wp_black,PORTD | |
3157 _endasm | |
3158 while(wp_temp_U8 > 0) | |
3159 { | |
3160 wp_temp_U8--; | |
3161 _asm | |
3162 bcf oled_rw | |
3163 nop | |
3164 bsf oled_rw | |
3165 nop | |
3166 bcf oled_rw | |
3167 nop | |
3168 bsf oled_rw | |
3169 _endasm | |
3170 } | |
3171 } | |
3172 } | |
3173 else | |
3174 { | |
3175 wp_temp_U8++; | |
3176 if(wp_invert) | |
3177 { | |
3178 _asm | |
3179 movff wp_black,PORTD | |
3180 _endasm | |
3181 while(wp_temp_U8 > 0) | |
3182 { | |
3183 wp_temp_U8--; | |
3184 _asm | |
3185 bcf oled_rw | |
3186 nop | |
3187 bsf oled_rw | |
3188 nop | |
3189 bcf oled_rw | |
3190 nop | |
3191 bsf oled_rw | |
3192 _endasm | |
3193 } | |
3194 } | |
3195 else | |
3196 { | |
3197 while(wp_temp_U8 > 0) | |
3198 { | |
3199 wp_temp_U8--; | |
3200 wp_write_color(); | |
3201 } | |
3202 } | |
3203 } | |
3204 } | |
3205 wp_txtptr++; | |
3206 wp_char = wp_stringstore[wp_txtptr]; | |
3207 } | |
3208 wp_command = 0x00; | |
3209 wp_write_command(); | |
3210 } | |
3211 |