diff code_part1/OSTC_code_c_part2/p2_deco.c @ 563:7bec4cf28cc7 bug_deco_clearing_missed_stops

BUGFIX bad CNS in decoplan when CF54 set.
author JeanDo
date Sat, 25 Feb 2012 19:41:43 +0100
parents 56753ea6a791
children 4e9e95d108d2
line wrap: on
line diff
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Sat Feb 25 15:13:26 2012 +0100
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Sat Feb 25 19:41:43 2012 +0100
@@ -2201,6 +2201,7 @@
         overlay unsigned char i = 0;    // Decostop loop counter
         overlay float actual_ppO2;
         overlay unsigned char time, t;
+        overlay unsigned char deepest_first = (read_custom_function(54) == 0);
 
         //---- Ascent to surface delay
         // NOTE: count as if time is spent with bottom pressure,
@@ -2220,20 +2221,35 @@
             sim_dive_mins++;
         }
 
-        //---- Do all further stops
+        //---- Do all further stops ------------------------------------------
         for(i=0; i<NUM_STOPS; ++i)
         {
-            //---- Get next stop
-            time             = char_O_deco_time[i];
-            temp_depth_limit = char_O_deco_depth[i] & 0x7F;
-            if( time == 0 ) break;      // End of table: done.
+            overlay unsigned char switch_gas;
+
+            //---- Get next stop, possibly in reverse order ------------------
+            if( deepest_first )
+            {
+                time             = char_O_deco_time[i];
+                temp_depth_limit = char_O_deco_depth[i];
+            }
+            else
+            {
+                time             = char_O_deco_time[(NUM_STOPS-1)-i];
+                temp_depth_limit = char_O_deco_depth[(NUM_STOPS-1)-i];
+            }
+            if( time == 0 ) continue;
     
-            //---- Gas Switch ?
-            if( char_O_deco_depth[i] & 0x80 )
-                if( gas_switch_deepest() )
-                    gas_switch_set();
-        
-            //---- Convert Depth and N2_ratio to ppO2
+            //---- Gas Switch ? ----------------------------------------------
+            switch_gas = temp_depth_limit & 0x80;   // Switch flag.
+            temp_depth_limit &= 0x7F;               // True stop depth.
+
+            if( switch_gas )
+            {
+                gas_switch_deepest();
+                gas_switch_set();
+            }
+
+            //---- Convert Depth and N2_ratio to ppO2 ------------------------
             actual_ppO2 = (pres_surface + temp_depth_limit * METER_TO_BAR)
                         * (1.0 - calc_N2_ratio - calc_He_ratio);
             if( actual_ppO2 < 0.0  ) actual_ppO2 = 0.0;
@@ -2249,7 +2265,7 @@
         }
     }
 
-    // Back to normal mode...
+    //---- Back to normal mode... --------------------------------------------
     char_I_step_is_1min = 0;
     sim_gas_last_depth  = backup_gas_last_depth;
     sim_gas_last_used   = backup_gas_last_used;