comparison src/p2_deco.c @ 111:c61b7a4e317c

Bugfix: CNS in planner
author heinrichsweikamp
date Tue, 17 Jun 2014 12:00:20 +0200
parents d7e6dfd5b498
children 109df032cc54
comparison
equal deleted inserted replaced
110:d39493c786a2 111:c61b7a4e317c
216 static float float_saturation_multiplier; // new in v.101 216 static float float_saturation_multiplier; // new in v.101
217 static float float_desaturation_multiplier; // new in v.101 217 static float float_desaturation_multiplier; // new in v.101
218 static float float_deco_distance; // new in v.101 218 static float float_deco_distance; // new in v.101
219 219
220 static unsigned char deco_gas_change[NUM_GAS]; // new in v.109 220 static unsigned char deco_gas_change[NUM_GAS]; // new in v.109
221 static unsigned char internal_deco_gas [NUM_STOPS];
221 222
222 //---- Bank 7 parameters ----------------------------------------------------- 223 //---- Bank 7 parameters -----------------------------------------------------
223 #ifndef UNIX 224 #ifndef UNIX
224 # pragma udata bank7=0x700 225 # pragma udata bank7=0x700
225 #endif 226 #endif
597 // 598 //
598 static void copy_deco_table(void) 599 static void copy_deco_table(void)
599 { 600 {
600 // Copy depth of the first (deepest) stop, because when reversing 601 // Copy depth of the first (deepest) stop, because when reversing
601 // order, it will be hard to find... 602 // order, it will be hard to find...
602 char_O_first_deco_depth = internal_deco_depth[0] & 0x7F; 603 char_O_first_deco_depth = internal_deco_depth[0];
603 char_O_first_deco_time = internal_deco_time [0]; 604 char_O_first_deco_time = internal_deco_time [0];
604 605
605 { 606 {
606 overlay unsigned char x, y; 607 overlay unsigned char x, y;
607 608
608 for(x=0; x<NUM_STOPS; x++) 609 for(x=0; x<NUM_STOPS; x++)
609 { 610 {
610 char_O_deco_depth[x] = internal_deco_depth[x]; 611 char_O_deco_depth[x] = internal_deco_depth[x];
611 char_O_deco_time [x] = internal_deco_time [x]; 612 char_O_deco_time [x] = internal_deco_time [x];
613 char_O_deco_gas [x] = internal_deco_gas [x];
612 } 614 }
613 615
614 //Now fill the char_O_deco_time_for_log array 616 //Now fill the char_O_deco_time_for_log array
615 //---- First: search the first non-null depth 617 //---- First: search the first non-null depth
616 for(x=(NUM_STOPS-1); x != 0; --x) 618 for(x=(NUM_STOPS-1); x != 0; --x)
627 629
628 //---- Third: fill table end with null 630 //---- Third: fill table end with null
629 for(y++; y<NUM_STOPS; y++) 631 for(y++; y<NUM_STOPS; y++)
630 { 632 {
631 char_O_deco_time_for_log [y] = 0; 633 char_O_deco_time_for_log [y] = 0;
634 char_O_deco_gas [y] = 0;
632 } 635 }
633 } 636 }
634 } 637 }
635 638
636 ////////////////////////////////////////////////////////////////////////////// 639 //////////////////////////////////////////////////////////////////////////////
1611 assert( temp_depth_limit > 0 ); // No stop at surface... 1614 assert( temp_depth_limit > 0 ); // No stop at surface...
1612 1615
1613 for(x=0; x<NUM_STOPS; ++x) 1616 for(x=0; x<NUM_STOPS; ++x)
1614 { 1617 {
1615 // Make sure deco-stops are recorded in order: 1618 // Make sure deco-stops are recorded in order:
1616 assert( !internal_deco_depth[x] || temp_depth_limit <= (internal_deco_depth[x]& 0x7F) ); 1619 assert( !internal_deco_depth[x] || temp_depth_limit <= internal_deco_depth[x] );
1617 1620
1618 if( (internal_deco_depth[x] & 0x7F) == temp_depth_limit ) 1621 if( internal_deco_depth[x]== temp_depth_limit )
1619 { 1622 {
1620 // Do not overflow (max 255') 1623 // Do not overflow (max 255')
1621 if( internal_deco_time[x] < 255 ) 1624 if( internal_deco_time[x] < 255 )
1622 { 1625 {
1623 internal_deco_time[x]++; 1626 internal_deco_time[x]++;
1629 if( internal_deco_depth[x] == 0 ) 1632 if( internal_deco_depth[x] == 0 )
1630 { 1633 {
1631 internal_deco_depth[x] = temp_depth_limit; 1634 internal_deco_depth[x] = temp_depth_limit;
1632 1635
1633 internal_deco_time[x] = 1; 1636 internal_deco_time[x] = 1;
1637 internal_deco_gas[x] = sim_gas_last_used;
1634 return 1; 1638 return 1;
1635 } 1639 }
1636 } 1640 }
1637 1641
1638 // Can't store stops at more than 96m. 1642 // Can't store stops at more than 96m.
2045 } 2049 }
2046 2050
2047 //---- Do all further stops ------------------------------------------ 2051 //---- Do all further stops ------------------------------------------
2048 for(i=0; i<NUM_STOPS; ++i) 2052 for(i=0; i<NUM_STOPS; ++i)
2049 { 2053 {
2050 overlay unsigned char switch_gas; 2054 overlay unsigned char stop_gas;
2051 2055
2052 //---- Get next stop, possibly in reverse order ------------------ 2056 //---- Get next stop, possibly in reverse order ------------------
2053 { 2057 {
2054 time = char_O_deco_time[(NUM_STOPS-1)-i]; 2058 time = char_O_deco_time[(NUM_STOPS-1)-i];
2055 temp_depth_limit = char_O_deco_depth[(NUM_STOPS-1)-i]; 2059 temp_depth_limit = char_O_deco_depth[(NUM_STOPS-1)-i];
2060 stop_gas = char_O_deco_gas[(NUM_STOPS-1)-i];
2056 } 2061 }
2057 if( time == 0 ) continue; 2062 if( time == 0 ) continue;
2058 2063
2059 //---- Gas Switch ? ---------------------------------------------- 2064 //---- Gas Switch ? ----------------------------------------------
2060 switch_gas = temp_depth_limit & 0x80; // Switch flag. 2065 if( stop_gas != sim_gas_last_used )
2061 temp_depth_limit &= 0x7F; // True stop depth.
2062
2063 if( switch_gas )
2064 { 2066 {
2065 gas_switch_deepest(); 2067 sim_gas_last_depth = deco_gas_change[stop_gas-1];
2068 sim_gas_last_used = stop_gas;
2066 gas_switch_set(); 2069 gas_switch_set();
2067 } 2070 }
2068 2071
2069 //---- Convert Depth and N2_ratio to ppO2 ------------------------ 2072 //---- Convert Depth and N2_ratio to ppO2 ------------------------
2070 actual_ppO2 = (pres_surface + temp_depth_limit * METER_TO_BAR) 2073 actual_ppO2 = (pres_surface + temp_depth_limit * METER_TO_BAR)
2184 if( deepest_first ) 2187 if( deepest_first )
2185 { 2188 {
2186 time = char_O_deco_time[i]; 2189 time = char_O_deco_time[i];
2187 if( time == 0 ) break; // End of table: done. 2190 if( time == 0 ) break; // End of table: done.
2188 2191
2189 newDepth = char_O_deco_depth[i] & 0x7F; 2192 newDepth = char_O_deco_depth[i];
2190 } 2193 }
2191 else 2194 else
2192 { 2195 {
2193 time = char_O_deco_time[31-i]; 2196 time = char_O_deco_time[31-i];
2194 if( time == 0 ) continue; // not yet: still search table. 2197 if( time == 0 ) continue; // not yet: still search table.
2195 2198
2196 newDepth = char_O_deco_depth[31-i] & 0x7F; 2199 newDepth = char_O_deco_depth[31-i];
2197 } 2200 }
2198 2201
2199 //---- Gas switch during this step ----------------------------------- 2202 //---- Gas switch during this step -----------------------------------
2200 { 2203 {
2201 overlay unsigned char newGas = 0; 2204 overlay unsigned char newGas = 0;