changeset 224:49c90c5d9603

Gas usage + Show after last page of decoplan. + Units in 0.1 litters (or bars), hence 16bits. + Define CF#56 and CF#57, defaults to 20.0 l/min. + Go RED if volume > 6553.5 (saturated). + Calculate gas usage at bottom of ascent (safe bet). + Fix when first gas is not Gas1. + BUGFIX gas usage: first gas is not in the sorted gaslist (in general). KNOWN BUG: wrong result if the gaslist is not sorted, or first gas do have a depth > 0.
author JeanDo
date Thu, 03 Mar 2011 15:16:23 +0100
parents 2a0a446fa6c0
children 2dc4a7340510
files code_part1/OSTC_code_asm_part1/definitions.asm code_part1/OSTC_code_asm_part1/divemode.asm code_part1/OSTC_code_asm_part1/english_text.asm code_part1/OSTC_code_asm_part1/french_text.asm code_part1/OSTC_code_asm_part1/german_text.asm code_part1/OSTC_code_asm_part1/menu_reset.asm code_part1/OSTC_code_asm_part1/simulator.asm code_part1/OSTC_code_asm_part1/spanish_text.asm code_part1/OSTC_code_c_part2/p2_deco.c code_part1/OSTC_code_c_part2/p2_deco.o code_part1/OSTC_code_c_part2/shared_definitions.h
diffstat 11 files changed, 146 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/definitions.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/definitions.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -26,7 +26,7 @@
 
 #DEFINE softwareversion_beta 	1 			; (and 0 for release) 
 
-#DEFINE	max_custom_number		d'55'		; Number of last used custom function
+#DEFINE	max_custom_number		d'57'		; Number of last used custom function
 
 ; International extension. Selecting messages source:
 #DEFINE    ENGLISH                         ; Use english_text.asm
@@ -343,6 +343,7 @@
     extern deco_hash    
     extern deco_pull_tissues_from_vault
     extern deco_push_tissues_to_vault
+    extern deco_gas_volumes
 
 ;=============================================================================
 ;I/O Ports (I=Input, O=Output)
--- a/code_part1/OSTC_code_asm_part1/divemode.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/divemode.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -307,54 +307,54 @@
 divemode_check_decogases:					; CALLed from Simulator
 ; Copy active gases to char_I_deco_N2_ratio and char_I_deco_He_ratio
 	read_int_eeprom		d'97'			; Read He ratio
-	movff	EEDATA,char_I_deco_He_ratio5	; And copy into hold register
+	movff	EEDATA,char_I_deco_He_ratio+4	; And copy into hold register
 	read_int_eeprom		d'96'			; Read O2 ratio
-	movff	char_I_deco_He_ratio5, wait_temp			; copy into bank1 register
+	movff	char_I_deco_He_ratio+4, wait_temp			; copy into bank1 register
 	bsf		STATUS,C					; 
 	movlw	d'100'						; 100%
 	subfwb	wait_temp,W					; minus He
 	subfwb	EEDATA,F					; minus O2
-	movff	EEDATA, char_I_deco_N2_ratio5; = N2!
+	movff	EEDATA, char_I_deco_N2_ratio+4; = N2!
 
 	read_int_eeprom		d'101'			; Read He ratio
-	movff	EEDATA,char_I_deco_He_ratio4	; And copy into hold register
+	movff	EEDATA,char_I_deco_He_ratio+3	; And copy into hold register
 	read_int_eeprom		d'100'			; Read O2 ratio
-	movff	char_I_deco_He_ratio4, wait_temp			; copy into bank1 register
+	movff	char_I_deco_He_ratio+3, wait_temp			; copy into bank1 register
 	bsf		STATUS,C					; 
 	movlw	d'100'						; 100%
 	subfwb	wait_temp,W					; minus He
 	subfwb	EEDATA,F					; minus O2
-	movff	EEDATA, char_I_deco_N2_ratio4; = N2!
+	movff	EEDATA, char_I_deco_N2_ratio+3; = N2!
 
 	read_int_eeprom		d'105'			; Read He ratio
-	movff	EEDATA,char_I_deco_He_ratio3	; And copy into hold register
+	movff	EEDATA,char_I_deco_He_ratio+2	; And copy into hold register
 	read_int_eeprom		d'104'			; Read O2 ratio
-	movff	char_I_deco_He_ratio3, wait_temp			; copy into bank1 register
+	movff	char_I_deco_He_ratio+2, wait_temp			; copy into bank1 register
 	bsf		STATUS,C					; 
 	movlw	d'100'						; 100%
 	subfwb	wait_temp,W					; minus He
 	subfwb	EEDATA,F					; minus O2
-	movff	EEDATA, char_I_deco_N2_ratio3; = N2!
+	movff	EEDATA, char_I_deco_N2_ratio+2; = N2!
 
 	read_int_eeprom		d'109'			; Read He ratio
-	movff	EEDATA,char_I_deco_He_ratio2	; And copy into hold register
+	movff	EEDATA,char_I_deco_He_ratio+1	; And copy into hold register
 	read_int_eeprom		d'108'			; Read O2 ratio
-	movff	char_I_deco_He_ratio2, wait_temp			; copy into bank1 register
+	movff	char_I_deco_He_ratio+1, wait_temp			; copy into bank1 register
 	bsf		STATUS,C					; 
 	movlw	d'100'						; 100%
 	subfwb	wait_temp,W					; minus He
 	subfwb	EEDATA,F					; minus O2
-	movff	EEDATA, char_I_deco_N2_ratio2; = N2!
+	movff	EEDATA, char_I_deco_N2_ratio+1; = N2!
 
 	read_int_eeprom		d'113'			; Read He ratio
-	movff	EEDATA,char_I_deco_He_ratio1; And copy into hold register
+	movff	EEDATA,char_I_deco_He_ratio+0; And copy into hold register
 	read_int_eeprom		d'112'			; Read O2 ratio
-	movff	char_I_deco_He_ratio1, wait_temp			; copy into bank1 register
+	movff	char_I_deco_He_ratio+0, wait_temp			; copy into bank1 register
 	bsf		STATUS,C					; 
 	movlw	d'100'						; 100%
 	subfwb	wait_temp,W					; minus He
 	subfwb	EEDATA,F					; minus O2
-	movff	EEDATA, char_I_deco_N2_ratio1; = N2!
+	movff	EEDATA, char_I_deco_N2_ratio+0; = N2!
 
 ; Now, set change depth. Inactive gases have depth=0!
 	read_int_eeprom		d'118'				; read gas_change_depth Gas1
@@ -384,21 +384,21 @@
 
 ; Debugger
 ;	call	enable_rs232	
-;	movff	char_I_deco_He_ratio5,TXREG
+;	movff	char_I_deco_He_ratio+4,TXREG
 ;	call	rs232_wait_tx				; wait for UART
-;	movff	char_I_deco_N2_ratio5,TXREG
+;	movff	char_I_deco_N2_ratio+4,TXREG
 ;	call	rs232_wait_tx				; wait for UART
-;	movff	char_I_deco_He_ratio4,TXREG
+;	movff	char_I_deco_He_ratio+3,TXREG
 ;	call	rs232_wait_tx				; wait for UART
-;	movff	char_I_deco_N2_ratio4,TXREG
+;	movff	char_I_deco_N2_ratio+3,TXREG
 ;	call	rs232_wait_tx				; wait for UART
-;	movff	char_I_deco_He_ratio3,TXREG
+;	movff	char_I_deco_He_ratio+2,TXREG
 ;	call	rs232_wait_tx				; wait for UART
-;	movff	char_I_deco_N2_ratio3,TXREG
+;	movff	char_I_deco_N2_ratio+2,TXREG
 ;	call	rs232_wait_tx				; wait for UART
-;	movff	char_I_deco_He_ratio2,TXREG
+;	movff	char_I_deco_He_ratio+1,TXREG
 ;	call	rs232_wait_tx				; wait for UART
-;	movff	char_I_deco_N2_ratio2,TXREG
+;	movff	char_I_deco_N2_ratio+1,TXREG
 ;	call	rs232_wait_tx				; wait for UART
 ;	movff	char_I_deco_He_ratio,TXREG
 ;	call	rs232_wait_tx				; wait for UART
--- a/code_part1/OSTC_code_asm_part1/english_text.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/english_text.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -243,8 +243,8 @@
     TCODE    .40,   .35,     "Show Lead.Tiss."           ;175 Show Lead.Tiss.
     TCODE    .40,   .35,     "ShallowStop 1st"           ;176 Shallow stop 1st  (Reverse order of deco plans)
     TCODE    .40,   .35,     "Gas switch[min]"           ;177 Gas switch[min]   (Additional delay in decoplan for gas switches).
-    TCODE    .40,   .35,     "not used       "           ;178 not used
-    TCODE    .40,   .35,     "not used       "           ;179 not used
+    TCODE    .40,   .35,     "BottomGas[l/mn]"           ;178 BottomGas[l/mn]   (Bottom gas usage, for volume estimation).
+    TCODE    .40,   .35,     "AscentGas[l/mn]"           ;179 AscentGas[l/mn]   (Ascent+Deco gas usage)
     TCODE    .40,   .35,     "not used       "           ;180 not used
     TCODE    .40,   .35,     "not used       "           ;181 not used
     TCODE    .40,   .35,     "not used       "           ;182 not used
--- a/code_part1/OSTC_code_asm_part1/french_text.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/french_text.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -244,8 +244,8 @@
     TCODE    .40,   .35,     "Aff.Tiss.Direct"           ;175 Show Lead.Tiss.
     TCODE    .40,   .35,     "Ordre paliers  "           ;176 Shallow stop 1st   (Reverse order of deco plans)
     TCODE    .40,   .35,     "Chang. gaz[min]"           ;177 Gas switch[min]   (Additional delay in decoplan for gas switches).
-    TCODE    .40,   .35,     "not used       "           ;178 not used
-    TCODE    .40,   .35,     "not used       "           ;179 not used
+    TCODE    .40,   .35,     "ConsoFond[l/mn]"           ;178 BottomGas[l/mn]   (Bottom gas usage, for volume estimation).
+    TCODE    .40,   .35,     "ConsoDeco[l/mn]"           ;179 AscentGas[l/mn]   (Ascent+Deco gas usage)
     TCODE    .40,   .35,     "not used       "           ;180 not used
     TCODE    .40,   .35,     "not used       "           ;181 not used
     TCODE    .40,   .35,     "not used       "           ;182 not used
--- a/code_part1/OSTC_code_asm_part1/german_text.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/german_text.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -243,8 +243,8 @@
     TCODE    .40,   .35,     "Show Lead.Tiss."           ;175 Show Lead.Tiss.
     TCODE    .40,   .35,     "ShallowStop 1st"           ;176 Shallow stop 1st  (Reverse order of deco plans)
     TCODE    .40,   .35,     "Gas switch[min]"           ;177 Gas switch[min]   (Additional delay in decoplan for gas switches).
-    TCODE    .40,   .35,     "not used       "           ;178 not used
-    TCODE    .40,   .35,     "not used       "           ;179 not used
+    TCODE    .40,   .35,     "BottomGas[l/mn]"           ;178 BottomGas[l/mn]   (Bottom gas usage, for volume estimation).
+    TCODE    .40,   .35,     "AscentGas[l/mn]"           ;179 AscentGas[l/mn]   (Ascent+Deco gas usage)
     TCODE    .40,   .35,     "not used       "           ;180 not used
     TCODE    .40,   .35,     "not used       "           ;181 not used
     TCODE    .40,   .35,     "not used       "           ;182 not used
--- a/code_part1/OSTC_code_asm_part1/menu_reset.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/menu_reset.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -172,9 +172,9 @@
 	CF_DEFAULT    CF_BOOL,	    d'0',   0,      0 		; CF53 Show Laeding Tissue in Divemode
 	CF_DEFAULT    CF_BOOL,      d'0',   0,      0 		; CF54 Display shallowest stop first
 	CF_DEFAULT    CF_INT8,      d'0',   d'0',   d'10'   ; GF55 Gas switch additional delay
-	CF_DEFAULT    CF_INT15,     0,      0,      0 		; UNUSED
-	                
-	CF_DEFAULT    CF_INT15,     0,      0,      0 		; UNUSED
+	CF_DEFAULT    CF_DECI,      d'200', d'5',   0       ; CF56 Bottom gas usage (l/min or bar/min)
+
+	CF_DEFAULT    CF_DECI,      d'200', d'5',   0       ; CF57 Ascent/deco gas usage (l/min or bar/min)
 	CF_DEFAULT    CF_INT15,     0,      0,      0 		; UNUSED
 	CF_DEFAULT    CF_INT15,     0,      0,      0 		; UNUSED
 	CF_DEFAULT    CF_INT15,     0,      0,      0 		; UNUSED
--- a/code_part1/OSTC_code_asm_part1/simulator.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/simulator.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -180,15 +180,19 @@
         STRCAT_PRINT    "'"		
 
 simulator_decoplan_notts:
+        ; Print ambient pressure in DEBUG compile, because if might
+        ; be usefull to calibrate decompression algorithm.
+#ifdef  __DEBUG
         movff   int_I_pres_surface+0,lo
         movff   int_I_pres_surface+1,hi
 
-        WIN_TOP .190                    ; Print Pamb used for compute
+        WIN_TOP .190
         lfsr    FSR2, letter
         bsf		leftbind
         output_16
         bcf		leftbind
         STRCAT_PRINT    " mbar"
+#endif
 
         WIN_INVERT	.1	                ; Init new Wordprocessor	
         DISPLAYTEXT	.188		        ; Sim. Results:
@@ -213,7 +217,7 @@
 	bra		simulator_show_decoplan4	; Quit display
 
 	btfsc	switch_left
-	bra		simulator_show_decoplan5	; Quit display or new Decoplan-Page (GF Mode only)
+	bra		simulator_show_decoplan5	; Next decoplan-page.
 
 	btfsc	sleepmode
 	goto	more_menu
@@ -232,8 +236,64 @@
 	bra		simulator_show_decoplan1	
 
 simulator_show_decoplan5_0:
+    btfss   display_see_deco
+    bra     simulator_show_decoplan4
 	bcf		display_see_deco			; clear flag
-	bra		simulator_show_decoplan4	; Quit
+   
+    call    deco_gas_volumes
+    movlb   1
+
+    call    PLED_clear_divemode_menu    ; Clear right part.
+
+	movlw	d'10'
+	movwf	waitms_temp                 ; Row for gas list is .10+.25
+	clrf	wait_temp                   ; Gas counter
+    lfsr	FSR0,int_O_gas_volumes      ; Initialize indexed addressing.
+
+	WIN_LEFT	.90                     ; Set column
+
+simulator_show_decoplan5_loop:
+    incf    wait_temp,F                 ; Increment gas #
+    
+	movlw	.25
+	addwf	waitms_temp,F		        ; Increase row position
+	movff	waitms_temp,win_top         ; Set Row
+
+    movff   POSTINC0,lo                 ; Read (16bit) result, low first,
+    movff   POSTINC0,hi                 ; then high.
+    movf    lo,W                        ; Null ?
+    iorwf   hi,W
+    bz      simulator_show_decoplan5_1  ; Skip printing.
+
+    movf    lo,W                        ; == 65535 (saturated ?)
+    iorwf   hi,W
+    incf    WREG
+    bnz     simulator_show_decoplan5_2
+    call    PLED_warnings_color
+    STRCPY  "> "
+    bra     simulator_show_decoplan5_3
+    
+simulator_show_decoplan5_2: 
+    call    PLED_standard_color   
+    STRCPY  "= "
+
+simulator_show_decoplan5_3:    
+    output_16dp .4                      ; 1 decimal.
+    call    word_processor              ; No unit: can be bars or litters.
+    
+    ; Loop for all 5 gas
+simulator_show_decoplan5_1:
+	movlw	d'5'                        ; list all five gases
+	cpfseq	wait_temp                   ; All gases shown?
+	bra		simulator_show_decoplan5_loop	; No
+	
+	WIN_TOP  .2
+	WIN_LEFT .0
+	WIN_INVERT 1
+	STRCPY_PRINT "Gas usage:  "
+	WIN_INVERT 0
+
+	bra		simulator_show_decoplan1		
 
 simulator_show_decoplan4:
 	movlw	d'5'
@@ -247,7 +307,10 @@
 	bsf		simulatormode_active			; normal simulator mode
 	bsf		standalone_simulator			; Standalone Simulator active
 
-	movff	logbook_temp1,logbook_temp3		; store bottom time.
+    ; Save dive parameters for gas volume estimation:
+    movff   logbook_temp2,char_I_bottom_depth
+    movff   logbook_temp1,char_I_bottom_time
+
 
 	movff	logbook_temp2,xA+0              ; Bottom depth. 
 	clrf	xA+1
@@ -336,10 +399,9 @@
 	
 	movlw	d'5'                            ; Pre-Set Cursor to "Show Decoplan"
 	movwf	menupos
-	movff	logbook_temp3,logbook_temp1     ; restore bottom time.
+	movff	char_I_bottom_time,logbook_temp1; restore bottom time.
 	bra     menu_simulator1                 ; Done.
 
-
 simulator_save_tissue_data:
 	bsf		restore_deco_data		; Set restore flag
 	ostc_debug	'S'							; Sends debug-information to screen if debugmode active
--- a/code_part1/OSTC_code_asm_part1/spanish_text.asm	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/spanish_text.asm	Thu Mar 03 15:16:23 2011 +0100
@@ -243,8 +243,8 @@
     TCODE    .40,   .35,     "Mostr. TejContr"           ;175 Show Lead.Tiss.
     TCODE    .40,   .35,     "PriParadaSuperf"           ;176 Shallow stop 1st  (Reverse order of deco plans)
     TCODE    .40,   .35,     "Gas switch[min]"           ;177 Gas switch[min]   (Additional delay in decoplan for gas switches).
-    TCODE    .40,   .35,     "not used       "           ;178 not used
-    TCODE    .40,   .35,     "not used       "           ;179 not used
+    TCODE    .40,   .35,     "BottomGas[l/mn]"           ;178 BottomGas[l/mn]   (Bottom gas usage, for volume estimation).
+    TCODE    .40,   .35,     "AscentGas[l/mn]"           ;179 AscentGas[l/mn]   (Ascent+Deco gas usage)
     TCODE    .40,   .35,     "not used       "           ;180 not used
     TCODE    .40,   .35,     "not used       "           ;181 not used
     TCODE    .40,   .35,     "not used       "           ;182 not used
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Thu Mar 03 15:16:23 2011 +0100
@@ -200,10 +200,6 @@
 static unsigned char    deco_gas_change4;		// new in v.109
 static unsigned char    deco_gas_change5;		// new in v.109
 
-static float			deco_N2_ratio1;			// new in v.101
-static float			deco_He_ratio1;			// new in v.101
-
-
 //---- Bank 6 parameters -----------------------------------------------------
 #pragma udata bank6=0x600
 
@@ -232,19 +228,17 @@
 static unsigned char	DBG_char_I_deco_model;	// new in v.108.
 static unsigned char	DBG_char_I_depth_last_deco;			// new in v.108
 static unsigned char	DBG_deco_gas_change;	// new in v.108
+static unsigned char    DBG_deco_N2_ratio;		// new in v.108
+static unsigned char	DBG_deco_He_ratio;		// new in v.108
 static float			DBG_pres_surface;		// new in v.108
 static float			DBG_GF_low;				// new in v.108
 static float			DBG_GF_high;			// new in v.108
 static float			DBG_const_ppO2;			// new in v.108
 static float			DBG_deco_ppO2_change;	// new in v.108
 static float			DBG_deco_ppO2;			// new in v.108
-static float			DBG_deco_N2_ratio;		// new in v.108
-static float			DBG_deco_He_ratio;		// new in v.108
 static float			DBG_float_saturation_multiplier;	// new in v.108
 static float			DBG_float_desaturation_multiplier;	// new in v.108
 static float			DBG_float_deco_distance;			// new in v.108
-static float			DBG_deco_N2_ratio;		// new in v.108
-static float			DBG_deco_He_ratio;		// new in v.108
 static float			DBG_N2_ratio;			// new in v.108
 static float			DBG_He_ratio;			// new in v.108
 
@@ -323,8 +317,8 @@
 	DBG_const_ppO2 = const_ppO2;
 	DBG_deco_ppO2_change = deco_ppO2_change;
 	DBG_deco_ppO2 = deco_ppO2;
-	DBG_deco_N2_ratio = deco_N2_ratio1;
-	DBG_deco_He_ratio = deco_He_ratio1;
+	DBG_deco_N2_ratio = char_I_deco_N2_ratio[0];
+	DBG_deco_He_ratio = char_I_deco_He_ratio[0];
 	DBG_deco_gas_change = deco_gas_change1;
 	DBG_float_saturation_multiplier = float_saturation_multiplier;
 	DBG_float_desaturation_multiplier = float_desaturation_multiplier;
@@ -360,9 +354,9 @@
 		int_O_DBS_bitfield |= DBS_DIST2h;
 	if(char_I_depth_last_deco > 8)
 		int_O_DBS_bitfield |= DBS_LAST2h;
-	if(DBG_deco_gas_change && ((deco_N2_ratio1 + deco_He_ratio1) > 0.95))
+	if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) > 95))
 		int_O_DBS_bitfield |= DBS_DECOO2l;
-	if(DBG_deco_gas_change && ((deco_N2_ratio1 + deco_He_ratio1) < 0.05))
+	if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) <  5))
 		int_O_DBS_bitfield |= DBS_DECOO2h;
 	if(pres_respiration > 3.0)
 		int_O_DBS2_bitfield |= DBS2_PRES2h;
@@ -434,8 +428,8 @@
 		temp_DBS |= DBG_C_DPPO2;
 
 	if( DBG_deco_gas_change != deco_gas_change1
-	 || DBG_deco_N2_ratio != deco_N2_ratio1
-	 || DBG_deco_He_ratio != deco_He_ratio1 )
+	 || DBG_deco_N2_ratio != char_I_deco_N2_ratio[0]
+	 || DBG_deco_He_ratio != char_I_deco_He_ratio[0] )
 		temp_DBS |= DBG_C_DGAS;
 
 	if(DBG_float_deco_distance != float_deco_distance)
@@ -1012,33 +1006,17 @@
 //
 static void set_gas(void)
 {
-    switch(sim_gas_last_used)
-    {
-    default:
-        calc_N2_ratio = N2_ratio;   
-        calc_He_ratio = He_ratio;
-        break;
-    case 1:
-	    calc_N2_ratio = deco_N2_ratio1;
-	    calc_He_ratio = deco_He_ratio1;
-        break;
+    assert( 0 <= sim_gas_last_used && sim_gas_last_used <= 5 );
 
-    case 2:
-		calc_N2_ratio = char_I_deco_N2_ratio2 * 0.01;
-		calc_He_ratio = char_I_deco_He_ratio2 * 0.01;
-        break;
-    case 3:
-		calc_N2_ratio = char_I_deco_N2_ratio3 * 0.01;
-		calc_He_ratio = char_I_deco_He_ratio3 * 0.01;
-        break;
-    case 4:
-		calc_N2_ratio = char_I_deco_N2_ratio4 * 0.01;
-		calc_He_ratio = char_I_deco_He_ratio4 * 0.01;
-        break;
-    case 5:
-		calc_N2_ratio = char_I_deco_N2_ratio5 * 0.01;
-		calc_He_ratio = char_I_deco_He_ratio5 * 0.01;
-        break;
+    if( sim_gas_last_used == 0 )
+    {
+        calc_N2_ratio = N2_ratio;
+	    calc_He_ratio = He_ratio;
+    }
+    else
+    {
+        calc_N2_ratio = char_I_deco_N2_ratio[sim_gas_last_used-1] * 0.01;
+	    calc_He_ratio = char_I_deco_He_ratio[sim_gas_last_used-1] * 0.01;
     }
 
     assert( 0.0 <= calc_N2_ratio && calc_N2_ratio <= 0.95 );
@@ -1244,8 +1222,6 @@
     pres_surface        = int_I_pres_surface     * 0.001;
     N2_ratio            = char_I_N2_ratio        * 0.01;
     He_ratio            = char_I_He_ratio        * 0.01;
-    deco_N2_ratio1      = char_I_deco_N2_ratio1  * 0.01;
-    deco_He_ratio1      = char_I_deco_He_ratio1  * 0.01;
     float_deco_distance = char_I_deco_distance   * 0.01;     // Get offset is in mbar.
 
     // ____________________________________________________
@@ -2186,13 +2162,13 @@
 //          decoplan (char_O_deco_depth, char_O_deco_time).
 //          CF#56 == bottom deci-liters/minutes (0.5 .. 50.0)
 //          CF#57 == deco deci-liters/minutes (0.5 .. 50.0).
-// Output:  char_O_gas_volumes[0..4] in litters x 100.
+// Output:  int_O_gas_volumes[0..4] in litters * 0.1
 //
 void deco_gas_volumes(void)
 {
     overlay float volumes[5];
     overlay float ascent_usage;
-    overlay unsigned char i, j;
+    overlay unsigned char i;
     RESET_C_STACK
 
     //---- initialize with bottom consumption --------------------------------
@@ -2206,42 +2182,45 @@
 
     //---- Ascent usage ------------------------------------------------------
 
-    ascent_usage = read_custom_function(57) * 0.1;  // In liter/minutes.
+    ascent_usage = read_custom_function(57) * 0.1;  // In litter/minutes.
 
-    // Usage to the first stop:
-    //  - computed at mean depth (triangular integration),
+    // Usage up to the first stop:
+    //  - computed at MAX depth (easier, safer),
     //  - with an ascent speed of 10m/min.
-    //  - with ascent liter / minutes.
+    //  - with ascent litter / minutes.
     //  - still using bottom gas:
-    volumes[0] += (0.05 * (char_I_bottom_depth + char_O_first_deco_depth) + 1.0)
+    volumes[0] += (char_I_bottom_depth* 0.1 + 1.0)
                * (char_I_bottom_depth - char_O_first_deco_depth) * 0.1
                * ascent_usage;
 
     for(i=0; i<32 && char_O_deco_depth[i] > 0; ++i)
     {
+        overlay unsigned char j, gas;
         // Gas switch depth ?
-        for(j=4; j>0; --j)
+        for(gas=j=0; j<4; ++j)
         {
             if( char_O_deco_depth[i] <= char_I_deco_gas_change[j] )
-                break;
+                if( (gas == 0) || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) )
+                    gas = j;
         }
 
         // usage during stop:
-        volumes[j] += (char_O_deco_depth[i]*0.1 + 1.0)// Use Psurface = 1.0 bar.
-                    * char_O_deco_time[i]               // in minutes.
-                    * ascent_usage
+        // Note: because first gas is not in there, increment gas+1
+        volumes[gas+1] += (char_O_deco_depth[i]*0.1 + 1.0)// Use Psurface = 1.0 bar.
+                        * char_O_deco_time[i]               // in minutes.
+                        * ascent_usage
         // Plus usage during ascent to the next stop, at 10m/min.
-                    + (0.05*(char_O_deco_depth[i] + char_O_deco_depth[i+1]) + 1.0)
-                    * (char_O_deco_depth[i] - char_O_deco_depth[i+1]) * 0.1
-                    * ascent_usage;
+                        + (char_O_deco_depth[i]*0.1  + 1.0)
+                        * (char_O_deco_depth[i] - char_O_deco_depth[i+1]) * 0.1
+                        * ascent_usage;
     }
 
     //---- convert results for the ASM interface -----------------------------
     for(i=0; i<5; ++i)
-        if( volumes[i] > 25499.0 )
-            char_O_gas_volumes[i] = 255;
+        if( volumes[i] > 6553.4 )
+            int_O_gas_volumes[i] = 65535;
         else
-            char_O_gas_volumes[i] = (unsigned char)((volumes[i] + 99.0)*0.01);
+            int_O_gas_volumes[i] = (unsigned short)(volumes[i]*10.0 + 0.5);
 }
 
 //////////////////////////////////////////////////////////////////////////////
Binary file code_part1/OSTC_code_c_part2/p2_deco.o has changed
--- a/code_part1/OSTC_code_c_part2/shared_definitions.h	Thu Mar 03 02:23:56 2011 +0100
+++ b/code_part1/OSTC_code_c_part2/shared_definitions.h	Thu Mar 03 15:16:23 2011 +0100
@@ -100,7 +100,7 @@
 VAR_UINT  (int_O_DBG_post_bitfield);
 VAR_UCHAR (char_O_NDL_at_20mtr);
 
-TAB_UCHAR (char_O_gas_volumes, 5);           // Volumes evaluation for each gas tank, in 100's of liters.
+TAB_UINT (int_O_gas_volumes, 5);            // Volumes evaluation for each gas tank, in 0.1 liters.
 
 TAB_UCHAR (char_O_hash, 16);
 
@@ -137,17 +137,8 @@
 VAR_UCHAR (char_I_bottom_time);            // Bottom time for planning (used in gas volume evaluation).
 
 TAB_UCHAR (char_I_deco_gas_change, 5);     // new in v.101
-
-VAR_UCHAR (char_I_deco_N2_ratio1);         // new in v.101
-VAR_UCHAR (char_I_deco_He_ratio1);         // new in v.101
-VAR_UCHAR (char_I_deco_N2_ratio2);         // new in v.109
-VAR_UCHAR (char_I_deco_He_ratio2);         // new in v.109
-VAR_UCHAR (char_I_deco_N2_ratio3);         // new in v.109
-VAR_UCHAR (char_I_deco_He_ratio3);         // new in v.109
-VAR_UCHAR (char_I_deco_N2_ratio4);         // new in v.109
-VAR_UCHAR (char_I_deco_He_ratio4);         // new in v.109
-VAR_UCHAR (char_I_deco_N2_ratio5);         // new in v.109
-VAR_UCHAR (char_I_deco_He_ratio5);         // new in v.109
+TAB_UCHAR (char_I_deco_N2_ratio, 5);       // new in v.101
+TAB_UCHAR (char_I_deco_He_ratio, 5);       // new in v.101
 
 #ifdef __18CXX
 //----------------------------------------------------------------------------