changeset 197:f15e804ff67f

Gas switch delay + New CF#55 for additional delay in decoplan for gas switch. + BUGFIX compute integration at full ascent, not half (or the formula is wrong). + BUGFIX minor typo in 2sec exposition factors.
author JeanDo
date Sun, 13 Feb 2011 17:27:43 +0100
parents e185b3b028af
children 1d98f30ed44e
files code_part1/OSTC_code_asm_part1/changelog.txt 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_asm_part1/start.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/p2_tables.romdata
diffstat 13 files changed, 416 insertions(+), 383 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/changelog.txt	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/changelog.txt	Sun Feb 13 17:27:43 2011 +0100
@@ -1,11 +1,13 @@
 New in 1.81 beta:
 BETA Version - Do NOT use for diving!
-CHANGE: ZH-L16 display all stops (up to 93m), as ZH-L16-GF mode
+CHANGE: ZH-L16 display all stops (up to 96m), as ZH-L16-GF mode
 BUGFIX: Don't wrap TTS sum (still limit each stop display (not compute) to ~4h)
 NEW: CF54: =1:Display shallowest stop first (decoplan and divemode)
 BUGFIX: Inactive gases greyed-out in Simulator results
 BUGFIX: "Better Gas" now works for Gas 4 and Gas 5, as well
 NEW: GF_lo and GF_hi stored in logbook
+BUGFIX: Gradient factor reworked
+NEW: CF55: Additional delay for gas switch (decoplan, includng divemode)
 
 New in 1.80 Stable:
 Stable release
--- a/code_part1/OSTC_code_asm_part1/definitions.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/definitions.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -28,7 +28,7 @@
 
 #DEFINE softwareversion_beta 	1 			; (and 0 for release) 
 
-#DEFINE	max_custom_number		d'53'		; Number of last used custom function
+#DEFINE	max_custom_number		d'55'		; Number of last used custom function
 
 ; International extension. Selecting messages source:
 #DEFINE     ENGLISH                         ; Use english_text.asm
--- a/code_part1/OSTC_code_asm_part1/divemode.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/divemode.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -452,24 +452,19 @@
 divemode_prepare_flags_for_deco:	
 	movff	amb_pressure+0,int_I_pres_respiration+0		; lo  and copy result to deco routine
 	movff	amb_pressure+1,int_I_pres_respiration+1		; hi
-	GETCUSTOM8	d'11'				; Saturation multiplier %
-	movwf	wait_temp
-	movff	wait_temp,char_I_saturation_multiplier
-	GETCUSTOM8	d'12'				; Desaturation multiplier %
-	movwf	wait_temp
-	movff	wait_temp,char_I_desaturation_multiplier
-	GETCUSTOM8	d'16'				; Deco distance to decostop in 1/10 meter for simulation
-	movwf	wait_temp
-	movff	wait_temp,char_I_deco_distance
-	GETCUSTOM8	d'29'				; Depth Last Deco in meter for simulation
-	movwf	wait_temp
-	movff	wait_temp,char_I_depth_last_deco
-	call	restart_set_modes_and_flags			; Sets decomode (char_I_deco_model) and flags (again)
-	return
+	GETCUSTOM8	d'11'                           ; Saturation multiplier %
+	movff	WREG,char_I_saturation_multiplier
+	GETCUSTOM8	d'12'                           ; Desaturation multiplier %
+	movff	WREG,char_I_desaturation_multiplier
+	GETCUSTOM8	d'16'                           ; Deco distance to decostop in 1/10 meter for simulation
+	movff	WREG,char_I_deco_distance
+	GETCUSTOM8	d'29'                           ; Depth Last Deco in meter for simulation
+	movff	WREG,char_I_depth_last_deco
+	goto	restart_set_modes_and_flags			; Sets decomode (char_I_deco_model) and flags (again)
 
 calc_deko_divemode3:
 	btfss	dekostop_active
-	call	PLED_display_deko_mask				; clear nostop time, display decodata
+	call	PLED_display_deko_mask              ; clear nostop time, display decodata
 	bsf		dekostop_active						; Set flag
 
 	movff	char_O_first_deco_depth,decodata+0	; ceiling
--- a/code_part1/OSTC_code_asm_part1/english_text.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/english_text.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -68,7 +68,7 @@
     TCODE    .20,  .95,      "Reset Menu"                ;009 Reset Menu
     TCODE    .20,  .125,     "Setup"                     ;010 Setup
     TCODE    .20,  .185,     "Exit"                      ;011 Exit
-    TCODE    .115, .2,       "Wait..."                   ;012 Wait...
+    TCODE    .111, .2,       "Wait..."                   ;012 Wait...
     TCODE    .0,   .24,      "MD2 Hash:"                 ;013 MD2 Hash:
     TCODE    .0,   .0,       "Desat"                     ;014 Desat         (Desaturation count-down)
     TCODE    .50,  .2,       "Interface"                 ;015 Interface		(Connected to USB)
@@ -241,8 +241,8 @@
     TCODE    .40,   .35,     "Show Stopwatch "           ;173 Show Stopwatch
     TCODE    .40,   .35,     "ShowTissueGraph"           ;174 ShowTissueGraph
     TCODE    .40,   .35,     "Show Lead.Tiss."           ;175 Show Lead.Tiss.
-    TCODE    .40,   .35,     "ShallowStop 1st"           ;176 Shallow stop 1st
-    TCODE    .40,   .35,     "not used       "           ;177 not used
+    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,     "not used       "           ;180 not used
--- a/code_part1/OSTC_code_asm_part1/french_text.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/french_text.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -230,7 +230,7 @@
     TCODE    .40,   .35,     "Ajuster SP fixe"           ;161 Adjust fixed SP
     TCODE    .40,   .35,     "Alarme Plafond "           ;162 Warn Ceiling
     TCODE    .40,   .35,     "Icone Type Mél."           ;163 Mix type icons
-    TCODE    .40,   .35,     "Aff.MeilleurGaz"           ;164 Blink BetterGas	(Remainder in divemode to switch to a beter decompression gas).
+    TCODE    .40,   .35,     "Aff.MeilleurGaz"           ;164 Blink BetterGas	(Remainder in divemode to switch to a better decompression gas).
     TCODE    .40,   .35,     "AlarmProf[mBar]"           ;165 DepthWarn[mBar]
     TCODE    .40,   .35,     "Alarme CNS  [%]"           ;166 CNS warning [%]
     TCODE    .40,   .35,     "Alarme GF   [%]"           ;167 GF warning  [%]
@@ -242,16 +242,16 @@
     TCODE    .40,   .35,     "Aff. Chrono.   "           ;173 Show Stopwatch
     TCODE    .40,   .35,     "Aff.GraphTissus"           ;174 ShowTissueGraph
     TCODE    .40,   .35,     "Aff.Tiss.Direct"           ;175 Show Lead.Tiss.
-    TCODE    .40,   .35,     "Prof.DernPalier"           ;176 Shalow stop 1st
-    TCODE    .40,   .35,     "non utilisé    "           ;177 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;178 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;179 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;180 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;181 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;182 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;183 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;184 not used
-    TCODE    .40,   .35,     "non utilisé    "           ;185 not used
+    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,     "not used       "           ;180 not used
+    TCODE    .40,   .35,     "not used       "           ;181 not used
+    TCODE    .40,   .35,     "not used       "           ;182 not used
+    TCODE    .40,   .35,     "not used       "           ;183 not used
+    TCODE    .40,   .35,     "not used       "           ;184 not used
+    TCODE    .40,   .35,     "not used       "           ;185 not used
 ; End of function descriptor I
 ;
     TCODE    .13,   .2,      "Config Fonctions II"       ;186 Custom Functions II
--- a/code_part1/OSTC_code_asm_part1/german_text.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/german_text.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -68,7 +68,7 @@
     TCODE    .20,  .95,      "Reset Menu"                ;009 Reset Menu
     TCODE    .20,  .125,     "Setup"                     ;010 Setup
     TCODE    .20,  .185,     "Exit"                      ;011 Exit
-    TCODE    .115, .2,       "Wait..."                   ;012 Wait...
+    TCODE    .111, .2,       "Wait..."                   ;012 Wait...
     TCODE    .0,   .24,      "MD2 Hash:"                 ;013 MD2 Hash:
     TCODE    .0,   .0,       "Desat"                     ;014 Desat         (Desaturation count-down)
     TCODE    .50,  .2,       "Interface"                 ;015 Interface		(Connected to USB)
@@ -241,8 +241,8 @@
     TCODE    .40,   .35,     "Show Stopwatch "           ;173 Show Stopwatch
     TCODE    .40,   .35,     "ShowTissueGraph"           ;174 ShowTissueGraph
     TCODE    .40,   .35,     "Show Lead.Tiss."           ;175 Show Lead.Tiss.
-    TCODE    .40,   .35,     "ShallowStop 1st"           ;176 Shallow stop 1st
-    TCODE    .40,   .35,     "not used       "           ;177 not used
+    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,     "not used       "           ;180 not used
--- a/code_part1/OSTC_code_asm_part1/menu_reset.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/menu_reset.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -170,8 +170,8 @@
 	                
 	CF_DEFAULT    CF_BOOL,     	d'1',   0,      0 		; CF52 Show Tissue Graph in Divemode
 	CF_DEFAULT    CF_BOOL,	    d'0',   0,      0 		; CF53 Show Laeding Tissue in Divemode
-	CF_DEFAULT    CF_BOOL,      d'0',   0,      0 		; CF54 Display shalowest stop first
-	CF_DEFAULT    CF_INT15,     0,      0,      0 		; UNUSED
+	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
--- a/code_part1/OSTC_code_asm_part1/simulator.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/simulator.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -246,7 +246,7 @@
 
 	movff	logbook_temp1,logbook_temp3		; store bottom time
 
-	movff	logbook_temp2,xA+0
+	movff	logbook_temp2,xA+0              ; Bottom depth. 
 	clrf	xA+1
 	movlw	d'100'
 	movwf	xB+0
@@ -264,87 +264,78 @@
 	movff	sim_pressure+0,amb_pressure+0	; override readings with simulator values
 	movff	sim_pressure+1,amb_pressure+1
 
-	call	simulator_save_tissue_data		; Stores 32 floats "pre_tissue" into bank3
+	call	simulator_save_tissue_data  ; Stores 32 floats "pre_tissue" into bank3
 
 	call	PLED_topline_box
 	WIN_INVERT	.1
-	DISPLAYTEXT	.12							;" Wait.."
+	DISPLAYTEXT	.12                     ; "Wait..."
 	WIN_INVERT	.0
 
+	call	divemode_check_decogases    ; Checks for decogases and sets the gases
+	call	divemode_prepare_flags_for_deco
+	movlw	d'0'                        ; Begin of deco cycle (init sim tissues)
+	movff	WREG,char_O_deco_status     ; Reset Deco module.
+
 simulator_calc_deco_loop1:
-	call	divemode_check_decogases        ; Checks for decogases and sets the gases
-	call	divemode_prepare_flags_for_deco
-
-	call	deco_calc_hauptroutine		    ; calc_tissue
-	movlb	b'00000001'						; rambank 1 selected
+	call	deco_calc_hauptroutine      ; calc_tissue
+	movlb	b'00000001'                 ; rambank 1 selected
 
 	movff	char_O_deco_status,WREG
 	tstfsz	WREG                        ; deco_status=0 if decompression calculation done
-	bra		simulator_calc_deco_loop1			; Not finished
+	bra		simulator_calc_deco_loop1   ; Not finished
 
 	movlw	d'1'
-	movff	WREG,char_I_step_is_1min		; 1 minute mode
-
-	movlw	d'2'
-	movff	WREG,char_O_deco_status			; Reset Deco module
+	movff	WREG,char_I_step_is_1min    ; 1 minute mode
 
 simulator_calc_deco_loop2:
-	
 	call	PLED_simulator_data
+	btg     LED_red
 
-	btg		LED_red
-
-	call	divemode_check_decogases			; Checks for decogases and sets the gases
+	call	divemode_check_decogases    ; Checks for decogases and sets the gases
 	call	divemode_prepare_flags_for_deco
 
 	call	deco_calc_hauptroutine		; calc_tissue
-	movlb	b'00000001'						; rambank 1 selected
-	ostc_debug	'C'		; Sends debug-information to screen if debugmode active
-	
-	decfsz	logbook_temp1,F
-	bra		simulator_calc_deco_loop2
+	movlb	b'00000001'                 ; rambank 1 selected
+	ostc_debug	'C'	                    ; Sends debug-information to screen if debugmode active
+
+	decfsz	logbook_temp1,F             ; Decrement bottom time.
+	bra     simulator_calc_deco_loop2
 
 	movlw	d'0'
-	movff	WREG,char_I_step_is_1min		; 2 second deco mode
+	movff	WREG,char_I_step_is_1min    ; 2 second deco mode
+
+simulator_calc_deco2:
+	call	divemode_check_decogases    ; Checks for decogases and sets the gases
+	call	divemode_prepare_flags_for_deco
 
-	movlw	d'2'
-	movff	WREG,char_O_deco_status			; Reset Deco module
+	call	deco_calc_hauptroutine		; calc_tissue
+	movlb	b'00000001'                 ; rambank 1 selected
 
-	bra		simulator_calc_deco2				; Not finished
+	movff	char_O_deco_status,WREG
+	tstfsz	WREG                        ; deco_status=0 if decompression calculation done
+	bra		simulator_calc_deco2        ; Not finished
 
-simulator_calc_deco3:
+    ; Finished
 	bsf		LED_red
 	
 	call	simulator_restore_tissue_data	; Restore 32 floats "pre_tissue" from bank3
 
-	bcf		simulatormode_active			; normal simulator mode
-	bcf		standalone_simulator			; Standalone Simulator active
+	bcf		simulatormode_active        ; normal simulator mode
+	bcf		standalone_simulator        ; Standalone Simulator active
 
 	WAITMS	d'250'
 	WAITMS	d'250'
-	WAITMS	d'250'							; Wait for Pressure Sensor to get real pressure again...
+	WAITMS	d'250'                      ; Wait for Pressure Sensor to get real pressure again...
 
-	bcf		LED_red
+	bcf     LED_red
 	
 	movlw	d'1'
-	movwf	logbook_temp1					; Bottom time>0!
-
-	movlw	d'5'							; Pre-Set Cursor to "Show Decoplan"
-	movwf	menupos
-	movff	logbook_temp3,logbook_temp1		; restore bottom time
-	bra		menu_simulator1					; Done.
+	movwf	logbook_temp1                   ; Bottom time>0!
 
-simulator_calc_deco2:
-	call	divemode_check_decogases			; Checks for decogases and sets the gases
-	call	divemode_prepare_flags_for_deco
-
-	call	deco_calc_hauptroutine		; calc_tissue
-	movlb	b'00000001'						; rambank 1 selected
-
-	movff	char_O_deco_status,WREG
-	tstfsz	WREG                        ; deco_status=0 if decompression calculation done
-	bra		simulator_calc_deco2				; Not finished
-	bra		simulator_calc_deco3				; finished!
+	movlw	d'5'                            ; Pre-Set Cursor to "Show Decoplan"
+	movwf	menupos
+	movff	logbook_temp3,logbook_temp1     ; restore bottom time
+	bra     menu_simulator1                 ; Done.
 
 
 simulator_save_tissue_data:
--- a/code_part1/OSTC_code_asm_part1/spanish_text.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/spanish_text.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -241,16 +241,16 @@
     TCODE    .40,   .35,     "Mostrar Cronom."           ;173 Show Stopwatch
     TCODE    .40,   .35,     "Mostr. Gráf.Tej"           ;174 ShowTissueGraph
     TCODE    .40,   .35,     "Mostr. TejContr"           ;175 Show Lead.Tiss.
-    TCODE    .40,   .35,     "PriParadaSuperf"           ;176 Shallow stop 1st
-    TCODE    .40,   .35,     "sin uso        "           ;177 not used
-    TCODE    .40,   .35,     "sin uso        "           ;178 not used
-    TCODE    .40,   .35,     "sin uso        "           ;179 not used
-    TCODE    .40,   .35,     "sin uso        "           ;180 not used
-    TCODE    .40,   .35,     "sin uso        "           ;181 not used
-    TCODE    .40,   .35,     "sin uso        "           ;182 not used
-    TCODE    .40,   .35,     "sin uso        "           ;183 not used
-    TCODE    .40,   .35,     "sin uso        "           ;184 not used
-    TCODE    .40,   .35,     "sin uso        "           ;185 not used
+    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,     "not used       "           ;180 not used
+    TCODE    .40,   .35,     "not used       "           ;181 not used
+    TCODE    .40,   .35,     "not used       "           ;182 not used
+    TCODE    .40,   .35,     "not used       "           ;183 not used
+    TCODE    .40,   .35,     "not used       "           ;184 not used
+    TCODE    .40,   .35,     "not used       "           ;185 not used
 ; End of function descriptor I
 ;
     TCODE    .13,   .2,      "Func.Personaliz. II"       ;186 Custom Functions II
--- a/code_part1/OSTC_code_asm_part1/start.asm	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/start.asm	Sun Feb 13 17:27:43 2011 +0100
@@ -73,15 +73,14 @@
 
 ; reset deco data
 	incf	nofly_time+0,F					; =1
-	clrf	wait_temp						; Use as buffer
-	movff	wait_temp,char_I_He_ratio		; No He at the Surface
+	clrf	WREG                            ; Use as buffer
+	movff	WREG,char_I_He_ratio            ; No He at the Surface
 	movlw	d'79'							; 79% N2
-	movwf	wait_temp						; Use as buffer
-	movff	wait_temp,char_I_N2_ratio		; No He at the Surface
+	movff	WREG,char_I_N2_ratio            ; No He at the Surface
 	movff	amb_pressure+0,int_I_pres_respiration+0		; copy surface air pressure to deco routine
 	movff	amb_pressure+1,int_I_pres_respiration+1		
 
-	movlw	d'0'
+	clrf    WREG
 	movff	WREG,char_I_step_is_1min		; 2 second deco mode
 	call	deco_clear_tissue			    ;
 	call	deco_calc_desaturation_time     ; calculate desaturation time
@@ -210,70 +209,71 @@
 	call	PLED_new_cf_warning		; Display new CF warning screen
 	movlw	d'20'					; timeout for warning screen
 	bra		startup_screen3a		; Will RETURN after timeout or button press
-	
-restart_set_modes_and_flags:		; "Call"ed from divemode, as well!
+
+;=============================================================================
+; Setup all flags and parameters for divemode and simulator computations.
+;
+restart_set_modes_and_flags:		    ; "Call"ed from divemode, as well!
 	bcf		gauge_mode
 	bcf		FLAG_const_ppO2_mode
 	bcf		FLAG_apnoe_mode			
 
 ; Pre-load modes for OC, GF 90/90 and no Aponoe or Gauge.
-	bcf		no_deco_customviews		; Clear no-deco-mode-flag
+	bcf		no_deco_customviews		    ; Clear no-deco-mode-flag
 	movlw	d'0'
-	movwf	wait_temp
-	movff	wait_temp,char_I_deco_model	; Clear Flagbyte 
+	movff	WREG,char_I_deco_model	    ; Clear Flagbyte 
 ; Load GF values into RAM
 	movlw	d'90'
-	movwf	wait_temp
-	movff	wait_temp,char_I_GF_Low_percentage
-	movff	wait_temp,char_I_GF_High_percentage		; Set to 90/90...
+	movff	WREG,char_I_GF_Low_percentage
+	movff	WREG,char_I_GF_High_percentage		; Set to 90/90...
 	clrf	EEADRH
-	read_int_eeprom d'34'			; Read deco data	
-	movlw	d'1'					; Gauge mode
+	read_int_eeprom d'34'			    ; Read deco data	
+	movlw	d'1'					    ; Gauge mode
 	cpfseq	EEDATA
-	 bra	restart_3_test_ppO2_mode; check for ppO2 mode
-	bsf		gauge_mode				; Set flag for gauge mode
-	bsf		no_deco_customviews		; Set no-deco-mode-flag
-	return							; start in Surfacemode
+	bra     restart_3_test_ppO2_mode    ; check for ppO2 mode
+	bsf		gauge_mode				    ; Set flag for gauge mode
+	bsf		no_deco_customviews		    ; Set no-deco-mode-flag
+    return							    ; start in Surfacemode
 restart_3_test_ppO2_mode:
-	movlw	d'2'					; const ppO2 mode
+	movlw	d'2'					    ; const ppO2 mode
 	cpfseq	EEDATA
-	 bra	restart_3_test_apnoe_mode; check for apnoe mode
-	bsf		FLAG_const_ppO2_mode	; Set flag for ppO2 mode
-	return							; start in Surfacemode
+    bra	    restart_3_test_apnoe_mode; check for apnoe mode
+	bsf		FLAG_const_ppO2_mode	    ; Set flag for ppO2 mode
+	return							    ; start in Surfacemode
 restart_3_test_apnoe_mode:
-	movlw	d'3'					; Apnoe mode
+	movlw	d'3'                        ; Apnoe mode
 	cpfseq	EEDATA
-	 bra	restart_4_test_gf_mode	; check for GF OC mode
-	bsf		FLAG_apnoe_mode			; Set flag for Apnoe Mode
-	bsf		no_deco_customviews		; Set no-deco-mode-flag
-	return							; start in Surfacemode
+	bra     restart_4_test_gf_mode	    ; check for GF OC mode
+	bsf		FLAG_apnoe_mode			    ; Set flag for Apnoe Mode
+	bsf		no_deco_customviews		    ; Set no-deco-mode-flag
+    return							    ; start in Surfacemode
 restart_4_test_gf_mode:
-	movlw	d'4'					; GF OC mode
+	movlw	d'4'					    ; GF OC mode
 	cpfseq	EEDATA
-	bra		restart_5_test_gfO2_mode; check for GF CC mode
+	bra		restart_5_test_gfO2_mode    ; check for GF CC mode
 	movlw	d'1'
-	movwf	wait_temp
-	movff	wait_temp,char_I_deco_model	; Set Flagbyte for GF method
+	movff	WREG,char_I_deco_model      ; Set Flagbyte for GF method
 ; Load GF values into RAM
-	GETCUSTOM8	d'32'			; GF low
-	movff		EEDATA,char_I_GF_Low_percentage
-	GETCUSTOM8	d'33'			; GF high
-	movff		EEDATA,char_I_GF_High_percentage
-	return							; start in Surfacemode
+	GETCUSTOM8	d'32'			        ; GF low
+	movff   EEDATA,char_I_GF_Low_percentage
+	GETCUSTOM8	d'33'			        ; GF high
+	movff   EEDATA,char_I_GF_High_percentage
+	return							    ; start in Surfacemode
 restart_5_test_gfO2_mode:
-	movlw	d'5'					; GF CC mode
+	movlw	d'5'					    ; GF CC mode
 	cpfseq	EEDATA
-	return							; Start in Surfacemode
-	bsf		FLAG_const_ppO2_mode	; Set flag for ppO2 mode
+	return							    ; Start in Surfacemode
+	bsf		FLAG_const_ppO2_mode	    ; Set flag for ppO2 mode
 	movlw	d'1'
-	movwf	wait_temp
-	movff	wait_temp,char_I_deco_model	; Set Flagbyte for GF method
+	movff	WREG,char_I_deco_model	    ; Set Flagbyte for GF method
 	; Load GF values into RAM
-	GETCUSTOM8	d'32'			; GF low
+	GETCUSTOM8	d'32'                   ; GF low
 	movff		EEDATA,char_I_GF_Low_percentage
-	GETCUSTOM8	d'33'			; GF high
+	GETCUSTOM8	d'33'                   ; GF high
 	movff		EEDATA,char_I_GF_High_percentage
-	return							; start in Surfacemode
+	return							    ; start in Surfacemode
+
+;=============================================================================
 
 startup_screen1:
 	call	PLED_ClearScreen		
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Sun Feb 13 17:27:43 2011 +0100
@@ -69,9 +69,9 @@
 // 2011/01/25: [jDG] Fusion deco array for both models.
 // 2011/01/25: [jDG] Use CF(54) to reverse deco order.
 // 2011/02/11: [jDG] Reworked gradient-factor implementation.
+// 2011/02/13: [jDG] CF55 for additional gas switch delay in decoplan.
 //
 // TODO:
-//  + Allow (CF) delay for gas switch while predicting ascent.
 //  + Allow to abort MD2 calculation (have to restart next time).
 //
 // Literature:
@@ -160,9 +160,6 @@
 static float 			pres_respiration;
 static float			pres_surface;
 static float			temp1;
-static float			temp2;
-static float			temp3;
-static float			temp4;
 static float			temp_deco;
 static float			temp_atem;
 static float			temp2_atem;
@@ -184,7 +181,8 @@
 static float            deco_ppO2_change;           // new in v.101
 static float            deco_ppO2;                  // new in v.101
 
-static unsigned char    calc_gas_switch;            // Detected a gas switch. 
+static unsigned char    sim_gas_last_used;         // Last used gas, to detected a gas switch. 
+static unsigned char    sim_gas_delay;             // Delay added for gas switch (count down) [min].
 static float			calc_N2_ratio;			// new in v.101
 static float			calc_He_ratio;			// new in v.101
 static float			CNS_fraction;			// new in v.101
@@ -201,27 +199,19 @@
 
 static float			deco_N2_ratio1;			// new in v.101
 static float			deco_He_ratio1;			// new in v.101
-static float			deco_N2_ratio2;			// new in v.109
-static float			deco_N2_ratio3;			// new in v.109
-static float			deco_N2_ratio4;			// new in v.109
-static float			deco_N2_ratio5;			// new in v.109
-static float			deco_He_ratio2;			// new in v.109
-static float			deco_He_ratio3;			// new in v.109
-static float			deco_He_ratio4;			// new in v.109
-static float			deco_He_ratio5;			// new in v.109
 
 
 //---- Bank 6 parameters -----------------------------------------------------
 #pragma udata bank6=0x600
 
-static float  pres_tissue[32];
-static float  pres_tissue_limit[16];
-static float  sim_pres_tissue_limit[16];
+float  pres_tissue[32];
+float  pres_tissue_limit[16];
+float  sim_pres_tissue_limit[16];
 
 //---- Bank 7 parameters -----------------------------------------------------
 #pragma udata bank7=0x700
 
-static float  sim_pres_tissue[32];              // 32 floats = 128 bytes.
+float  sim_pres_tissue[32];                 // 32 floats = 128 bytes.
 static float  sim_pres_tissue_backup[32];
 
 //---- Bank 8 parameters -----------------------------------------------------
@@ -518,6 +508,7 @@
         movwf TBLPTRU,0
     _endasm
 #endif
+    assert( 0 <= ci && ci < 16 );
 
     var_N2_a = buhlmann_a[ci];
     var_N2_b = buhlmann_b[ci];
@@ -584,6 +575,9 @@
             int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
 
         break;
+
+    default:
+            assert(0);  // Never go there...
     }
 }
 
@@ -778,6 +772,9 @@
 //
 static void temp_tissue_safety(void)
 {
+    assert( 0.0 <  float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 );
+    assert( 1.0 <= float_saturation_multiplier   && float_saturation_multiplier   <= 2.0 );
+
 	if( char_I_deco_model == 0 )
 	{
 		if (temp_tissue < 0.0)
@@ -904,10 +901,10 @@
     
     for(ci=0; ci<16; ci++)
     {
-        // cycle through the 16 b"uhlmann tissues
+        // cycle through the 16 Bühlmann tissues
         overlay float p = N2_ratio * (pres_respiration -  0.0627);
         pres_tissue[ci] = p;
-        
+
         read_buhlmann_coefficients(-1);
 
         p = (p - var_N2_a) * var_N2_b ;
@@ -915,7 +912,7 @@
             p = 0.0;
         pres_tissue_limit[ci] = p;
 
-        // cycle through the 16 b"uhlmann tissues for Helium
+        // cycle through the 16 Bühlmann tissues for Helium
         (pres_tissue+16)[ci] = 0.0;
     } // for 0 to 16
 
@@ -925,7 +922,7 @@
     int_O_ascenttime = 0;
     char_O_gradient_factor = 0;
     char_O_relative_gradient_GF = 0;
-    char_I_depth_last_deco	= 0;		// for compatibility with v.101pre_no_last_deco
+    char_I_depth_last_deco = 0;		// for compatibility with v.101pre_no_last_deco
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -942,8 +939,8 @@
     pres_surface = (float)int_I_pres_surface / 1000.0;  // the b"uhlmann formula using pres_surface does apply to the pressure without any inert ratio
     temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body
     temp2_atem = 0.0;
-    float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0;
-    float_saturation_multiplier = char_I_saturation_multiplier / 100.0;
+    float_desaturation_multiplier = char_I_desaturation_multiplier * 0.01;
+    float_saturation_multiplier   = char_I_saturation_multiplier   * 0.01;
     
     calc_tissue(0);     // update the pressure in the 32 tissues in accordance with the new ambient pressure for 2 seconds.
     
@@ -1047,21 +1044,13 @@
 {
     overlay int int_temp;
     
-    pres_respiration    = int_I_pres_respiration / 1000.0;
-    pres_surface        = int_I_pres_surface / 1000.0;
-    N2_ratio            = char_I_N2_ratio / 100.0;
-    He_ratio            = char_I_He_ratio / 100.0;
-    deco_N2_ratio1      = char_I_deco_N2_ratio1 / 100.0;
-    deco_He_ratio1      = char_I_deco_He_ratio1 / 100.0;
-    deco_N2_ratio2      = char_I_deco_N2_ratio2 / 100.0;
-    deco_He_ratio2      = char_I_deco_He_ratio2 / 100.0;
-    deco_N2_ratio3      = char_I_deco_N2_ratio3 / 100.0;
-    deco_He_ratio3      = char_I_deco_He_ratio3 / 100.0;
-    deco_N2_ratio4      = char_I_deco_N2_ratio4 / 100.0;
-    deco_He_ratio4      = char_I_deco_He_ratio4 / 100.0;
-    deco_N2_ratio5      = char_I_deco_N2_ratio5 / 100.0;
-    deco_He_ratio5      = char_I_deco_He_ratio5 / 100.0;
-    float_deco_distance = char_I_deco_distance  / 100.0;     // Get offset is in mbar.
+    pres_respiration    = int_I_pres_respiration * 0.001;
+    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.
 
     // ____________________________________________________
     //
@@ -1122,14 +1111,15 @@
     	}
     }
 
-    const_ppO2 = (float)char_I_const_ppO2 / 100.0;
-    deco_ppO2_change = (float)char_I_deco_ppO2_change / 99.95 + pres_surface;
-    deco_ppO2_change += float_deco_distance;
-    deco_ppO2 = (float)char_I_deco_ppO2 / 100.0;
-    float_desaturation_multiplier = char_I_desaturation_multiplier / 100.0;
-    float_saturation_multiplier = char_I_saturation_multiplier / 100.0;
-    GF_low = (float)char_I_GF_Low_percentage / 100.0;
-    GF_high = (float)char_I_GF_High_percentage / 100.0;
+    const_ppO2 = char_I_const_ppO2 * 0.01;
+    deco_ppO2_change = char_I_deco_ppO2_change / 99.95 
+                     + pres_surface
+                     + float_deco_distance;
+    deco_ppO2 = char_I_deco_ppO2 * 0.01;
+    float_desaturation_multiplier = char_I_desaturation_multiplier * 0.01;
+    float_saturation_multiplier   = char_I_saturation_multiplier   * 0.01;
+    GF_low   = char_I_GF_Low_percentage  * 0.01;
+    GF_high  = char_I_GF_High_percentage * 0.01;
     GF_delta = GF_high - GF_low;
 }
 
@@ -1138,7 +1128,11 @@
 //
 void calc_hauptroutine_update_tissues(void)
 {
- 	if (char_I_const_ppO2 == 0)													// new in v.101
+    assert( 0.00 <= N2_ratio && N2_ratio <= 1.00 );
+    assert( 0.00 <= He_ratio && He_ratio <= 1.00 );
+    assert( (N2_ratio + He_ratio) <= 0.95 );
+
+    if (char_I_const_ppO2 == 0)													// new in v.101
   		pres_diluent = pres_respiration;										// new in v.101
  	else
     {
@@ -1184,46 +1178,64 @@
 //
 void check_gas_switch(void)
 {
+    overlay unsigned char temp_gas_switch = sim_gas_last_used;
+
     calc_N2_ratio = N2_ratio;   
     calc_He_ratio = He_ratio;
     
     if (char_I_const_ppO2 == 0)
     {
     	deco_diluent = temp_deco;
-        calc_gas_switch = 0;
 
-		if(deco_gas_change1 && (temp_deco < deco_gas_change1))
+		if( deco_gas_change1 && (temp_deco < deco_gas_change1) )
 		{
     		calc_N2_ratio = deco_N2_ratio1;
     		calc_He_ratio = deco_He_ratio1;
-    		calc_gas_switch = 1;
+            temp_gas_switch = 1;
     	}
-		if(deco_gas_change2 && (temp_deco < deco_gas_change2))
+		if(deco_gas_change2 && (temp_deco < deco_gas_change2) )
 		{
-    		calc_N2_ratio = deco_N2_ratio2;
-    		calc_He_ratio = deco_He_ratio2;
-    		calc_gas_switch = 2;
+    		calc_N2_ratio = char_I_deco_N2_ratio2 * 0.01;
+    		calc_He_ratio = char_I_deco_He_ratio2 * 0.01;
+            temp_gas_switch = 2;
     	}
 		if(deco_gas_change3 && (temp_deco < deco_gas_change3))
 		{
-    		calc_N2_ratio = deco_N2_ratio3;
-    		calc_He_ratio = deco_He_ratio3;
-    		calc_gas_switch = 3;
+    		calc_N2_ratio = char_I_deco_N2_ratio3 * 0.01;
+    		calc_He_ratio = char_I_deco_He_ratio3 * 0.01;
+            temp_gas_switch = 3;
     	}
 		if(deco_gas_change4 && (temp_deco < deco_gas_change4))
 		{
-    		calc_N2_ratio = deco_N2_ratio4;
-    		calc_He_ratio = deco_He_ratio4;
-    		calc_gas_switch = 4;
+    		calc_N2_ratio = char_I_deco_N2_ratio4 * 0.01;
+    		calc_He_ratio = char_I_deco_He_ratio4 * 0.01;
+            temp_gas_switch = 4;
     	}
 		if(deco_gas_change5 && (temp_deco < deco_gas_change5))
 		{
-    		calc_N2_ratio = deco_N2_ratio5;
-    		calc_He_ratio = deco_He_ratio5;
-    		calc_gas_switch = 4;
+    		calc_N2_ratio = char_I_deco_N2_ratio5 * 0.01;
+    		calc_He_ratio = char_I_deco_He_ratio5 * 0.01;
+            temp_gas_switch = 5;
     	}
     }
-    else
+
+    // Should detect gas switch just once.
+    if( temp_gas_switch != sim_gas_last_used )
+    {
+        sim_gas_last_used = temp_gas_switch;
+        sim_gas_delay = read_custom_function(55);
+    }
+
+    assert( 0.0 <= calc_N2_ratio && calc_N2_ratio <= 0.95 );
+    assert( 0.0 <= calc_He_ratio && calc_He_ratio <= 0.95 );
+    assert( (calc_N2_ratio + calc_He_ratio) <= 1.00 );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+static void alveolar_presures(void)
+{
+    if (char_I_const_ppO2 != 0)
    	{
    		if (temp_deco > deco_ppO2_change)
     	{
@@ -1237,7 +1249,6 @@
 
     if (deco_diluent > temp_deco)
     	deco_diluent = temp_deco;
-
     if (deco_diluent > 0.0627)
     {
         temp_atem = calc_N2_ratio * (deco_diluent - 0.0627);
@@ -1248,6 +1259,8 @@
         temp_atem = 0.0;
         temp2_atem = 0.0;
     }
+    assert( 0.0 <= temp_atem  && temp_atem  < 14.0 );
+    assert( 0.0 <= temp2_atem && temp2_atem < 14.0 );
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -1262,7 +1275,9 @@
 
  	for(loop = 0; loop < 16; ++loop)
   	{
-        calc_nextdecodepth();
+        // Do not ascent while doing a gas switch.
+        if( sim_gas_delay == 0 )
+            calc_nextdecodepth();
 
         //---- Finish computations once surface is reached -------------------
         if( temp_depth_limit <= 0 )
@@ -1274,7 +1289,12 @@
       	}
 
         //---- Else, continue simulating the stops ---------------------------
-        check_gas_switch();         // Also updates ppN2 and ppHe.
+        if( sim_gas_delay == 0 )
+            check_gas_switch();     // Calculate N2_ratio and He_ratio.
+        else
+            sim_gas_delay--;
+
+        alveolar_presures();        // Updates ppN2 and ppHe.
  
         sim_tissue(1);              // Simulate compartiments for 1 minute.
         update_deco_table();        // Add one minute stops.
@@ -1301,25 +1321,37 @@
     // Loop until first top or surface is reached.
  	for(;;)
   	{
-  		temp_deco -= 1.0;               // Ascent 1 min, at 10m/min. == 1bar/min.
+        // Do not ascent while doing a gas switch.
+        if( sim_gas_delay == 0 )
+  		    temp_deco -= 1.0;           // Ascent 1 min, at 10m/min. == 1bar/min.
 
         // Compute sim_lead_tissue_limit at GF_low (deepest stop).
         sim_limit(GF_low);
 
         // Did we reach first stop ?
         if( temp_deco <= sim_lead_tissue_limit )
-            break;                      //Yes: finished !
+            break;                      // Yes: finished !
         
         // Next stop is surface ?
         if( temp_deco <= pres_surface )
             break;                      // Yes: finished too.
 
-        //---- Simulat gas switches, and compute ppN2/ppHe at half the ascent:
- 		temp_deco += 0.5;               // Check gas change 5 meter below new depth.
+        //---- Simulat gas switches
+        if( sim_gas_delay > 0 )
+        {
+            sim_gas_delay--;            // Decrement switch delay
+            temp_depth_limit = (temp_deco - pres_surface) / 0.09985;
+            update_deco_table();        // And mark stop in table
+        }
+        else
+        {
+ 		    temp_deco += 0.5;           // Check gas change 5 meter below new depth.
             check_gas_switch();
- 		temp_deco -= 0.5;               // Back to new depth.
+ 		    temp_deco -= 0.5;           // Back to new depth.
+        }
 
         // Then simulate with the new gas pressures... (1min)
+        alveolar_presures();            // Calculated at true depth !
 		sim_tissue(1);
 	}
     temp_deco += 1.0;                   // Restore last correct depth.
@@ -1389,6 +1421,9 @@
             calc_lead_tissue_limit = p;
         }
     }
+
+    assert( char_O_gtissue_no < 16 );
+    assert( 0.0 <= calc_lead_tissue_limit && calc_lead_tissue_limit <= 14.0);
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -1406,7 +1441,7 @@
 	for(loop = 1; loop <= 17; loop++)
 	{
   		backup_sim_pres_tissue();
-  		sim_tissue(2);
+  		sim_tissue(2);      // 10 min.
         sim_limit(GF_high);
 
 		if( sim_lead_tissue_limit > pres_surface )  // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately
@@ -1422,7 +1457,7 @@
  	{
      	for(loop=1; loop <= 10; loop++)
 		{
-   			sim_tissue(1);
+   			sim_tissue(1);  // 1 min
             sim_limit(GF_high);
 
     		if( sim_lead_tissue_limit > pres_surface)  // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately
@@ -1491,6 +1526,10 @@
    		(sim_pres_tissue+16)[x] = (pres_tissue+16)[x];
    		sim_pres_tissue_limit[x] = pres_tissue_limit[x];
   	}
+
+    sim_gas_last_used = -1;     // No switch yet.
+    sim_lead_tissue_limit = 0.0;
+    sim_lead_tissue_no = 255;
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -1562,6 +1601,9 @@
             sim_lead_tissue_limit = p;
         }
     } // for ci
+
+    assert( sim_lead_tissue_no < 16 );
+    assert( 0.0 <= sim_lead_tissue_limit && sim_lead_tissue_limit <= 14.0);
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -1629,46 +1671,49 @@
 //
 static void calc_gradient_factor(void)
 {
+    overlay float gf;
+    assert( char_O_gtissue_no < 16 );
+
 	// tissue > respiration (entsaettigungsvorgang)
 	// gradient ist wieviel prozent an limit mit basis tissue
 	// dh. 0% = respiration == tissue
 	// dh. 100% = respiration == limit
-	temp_tissue = pres_tissue[char_O_gtissue_no] + pres_tissue[char_O_gtissue_no+16];
-	temp1 = temp_tissue - pres_respiration;
-	temp2 = temp_tissue - pres_tissue_limit[char_O_gtissue_no];	// changed in v.102
-	temp2 = temp1/temp2;
-	temp2 = temp2 * 100; // displayed in percent
-	if (temp2 < 0)
-		temp2 = 0;
-	if (temp2 > 255)
-		temp2 = 255;
-	if (temp1 < 0)
- 		char_O_gradient_factor = 0;
-	else
- 		char_O_gradient_factor = (char)temp2;
-
-	temp3 = temp2;
+	temp_tissue = pres_tissue[char_O_gtissue_no] + (pres_tissue+16)[char_O_gtissue_no];
+    if( temp_tissue < pres_respiration )
+ 		gf = 0.0;
+    else
+    {
+       gf = (temp_tissue - pres_respiration) 
+          / (temp_tissue - pres_tissue_limit[char_O_gtissue_no])
+          * 100.0;
+        if( gf > 255.0 ) gf = 255.0;
+        if( gf < 0.0   ) gf = 0.0;
+    }
+	char_O_gradient_factor = (unsigned char)gf;
 
 	if (char_I_deco_model == 1)		// calculate relative gradient factor
 	{
-		temp1 = (float)low_depth * 0.09995;
-		temp2 = pres_respiration - pres_surface;
-		if (temp2 <= 0)
-			temp1 = GF_high;
-		else if (temp2 >= temp1)
-			temp1 = GF_low;
-		else
-			temp1 = GF_low + (temp1 - temp2)/temp1*GF_delta;
+        overlay float rgf;
+
+		if( low_depth == 0 )
+			rgf = GF_high;
+        else
+        {
+            overlay float temp1 = low_depth * 0.09995;
+            overlay float temp2 = pres_respiration - pres_surface;
 
-		if (low_depth == 0)
-			temp1 = GF_high;
+            if (temp2 <= 0)
+			    rgf = GF_high;
+		    else if (temp2 >= temp1)
+			    rgf = GF_low;
+		    else
+			    rgf = GF_low + (temp1 - temp2)/temp1*GF_delta;
+        }
 
-		temp2 = temp3 / temp1; // temp3 is already in percent
-		if (temp2 < 0)
-			temp2 = 0;
-		if (temp2 > 255)
-			temp2 = 255;
-		char_O_relative_gradient_GF  = (char)temp2;
+		rgf = gf / rgf; // gf is already in percent
+		if( rgf <   0.0 ) rgf =   0.0;
+		if( rgf > 255.0 ) rgf = 255.0;
+		char_O_relative_gradient_GF  = (unsigned char)rgf;
 	}	// calc relative gradient factor
 	else
 	{
@@ -1685,7 +1730,9 @@
 void deco_calc_desaturation_time(void)
 {
     overlay unsigned int desat_time;    // For a particular compartiment, in min.
-
+    overlay float temp2;
+    overlay float temp3;
+    overlay float temp4;
     RESET_C_STACK
 
     N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann
@@ -1799,7 +1846,7 @@
     temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body
     temp2_atem = 0.0;
     float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101	(70,42%/100.=142)
-    float_saturation_multiplier = char_I_saturation_multiplier / 100.0;
+    float_saturation_multiplier   = char_I_saturation_multiplier   * 0.01;
     
     calc_tissue(1);  // update the pressure in the 32 tissues in accordance with the new ambient pressure
     
@@ -2004,10 +2051,7 @@
 void deco_calc_percentage(void)
 {
     RESET_C_STACK
-    temp1 = (float)int_I_temp;
-    temp2 = (float)char_I_temp / 100.0;
-    temp3 = temp1 * temp2;
-    int_I_temp = (int)temp3;
+    int_I_temp = (int)(int_I_temp * (char_I_temp / 100.0));
 }
 
 //////////////////////////////////////////////////////////////////////////////
Binary file code_part1/OSTC_code_c_part2/p2_deco.o has changed
--- a/code_part1/OSTC_code_c_part2/p2_tables.romdata	Sun Feb 13 10:16:59 2011 +0100
+++ b/code_part1/OSTC_code_c_part2/p2_tables.romdata	Sun Feb 13 17:27:43 2011 +0100
@@ -16,53 +16,54 @@
 //    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 // HISTORY
-// 2011-01-20; jDG Cleanup addressing.
+// 2011-01-20: jDG Cleanup addressing.
+// 2011-02-13: jDG Correct some typos.
 //
 // **************************************************************
 
 rom const float buhlmann_a[32] =
-{	// ??? Data ZH-L16A, from Tauchmedizin 1995 ???
+{	// Data ZH-L16C, from Bühlmann Tauchmedizin 2002, option 1a (4mn)
 //---a for N2 ----------------------------------------------------------------
-	1.2599,		/// WARNING ZH-L16c-1990 gives different values: 1.3318
-	1.0000,		/// ... 1.0048
-	0.8618,		/// ... 0.8653
-	0.7562,		/// ... 0.7520
-	0.6200,		/// ... 0.6194
-	0.5043,		/// ... 0.5043
-	0.4410,		/// ... 0.4396
-	0.4000,		/// ... 0.3977
-	0.3750,		/// ... 0.3701
-	0.3500,		/// ... 0.3456
-	0.3295,		/// ... 0.3269
-	0.3065,		/// ... 0.3065
-	0.2835,		/// ... 0.2848
-	0.2610,		/// ... 0.2622
-	0.2480,		/// ... 0.2486
-	0.2327,		/// ... 0.2341
+	1.2599,
+	1.0000,
+	0.8618,
+	0.7562,
+	0.6200,
+	0.5043,
+	0.4410,
+	0.4000,
+	0.3750,
+	0.3500,
+	0.3295,
+	0.3065,
+	0.2835,
+	0.2610,
+	0.2480,
+	0.2327,
 //---- a of He ---------------------------------------------------------------
-	1.7424,		/// ... 1,7443
-	1.3830,		/// ... 1,3800
-	1.1919,		/// ... 1,1879
-	1.0458,		/// ... 1,0455
-	.9220,		/// ... 0,9211
-	.8205,		/// ... 0,8232
-	.7305,		/// ... 0,7321
-	.6502,		/// ... 0,6508
-	.5950,		/// ... 0,5981
-	.5545,		/// ... 0,5568
-	.5333,		/// ... 0,5285
-	.5189,		/// ... 0,5178
-	.5181,		/// ... 0,5137
-	.5176,		/// ... 0,5196
-	.5172,		/// ... 0,5150
-	.5119		/// ... 0,5109
+	1.7424,
+	1.3830,
+	1.1919,
+	1.0458,
+	.9220,
+	.8205,
+	.7305,
+	.6502,
+	.5950,
+	.5545,
+	.5333,
+	.5189,
+	.5181,
+	.5176,
+	.5172,
+	.5119
 };
 
 rom const float buhlmann_b[] =
 {
 //---- b for N2 --------------------------------------------------------------
-	0.5050, 	/// WARNING ZH-L16c gives a different value: 0.5241
-	0.6514,		/// All the other values matches ZH-L16c-1990
+	0.5050,
+	0.6514,
 	0.7222,
 	0.7825,
 	0.8126,
@@ -99,7 +100,7 @@
 rom const float buhlmann_ht[] =
 {
 //---- N2 --------------------------------------------------------------------
-	4,			// Compartiment length, in minute, for nitrogen.
+	4,			// Compartiment half-life, in minute, for nitrogen.
 	8,
 	12,
 	18,
@@ -137,77 +138,77 @@
 rom const float e2secs[] =
 { 
 //---- N2 --------------------------------------------------------------------
-	5.7596E-03,  // und zwar  1 - 2^(-2sec/HT)
-	2.8839E-03,
-	1.8467e-03,
-	1.2481e-03,
-	8.5537E-04,
-	6.0308E-04,
-	4.2541E-04, 
-	3.0002E-04,
-	2.1195E-04,
-	1.5824E-04,
-	1.2355E-04,
-	9.6669E-05,
-	7.5751E-05,
-	5.92E-05,
-	4.64E-05,
-	3.64E-05,
+	5.75958E-03,  // und zwar  1 - 2^(-1/(30sec*HT))
+	2.88395E-03,
+    1.92356E-03,
+    1.28278E-03,
+    8.55371E-04,
+    5.92258E-04,
+    4.20001E-04,
+    3.00019E-04,
+    2.11949E-04,
+    1.58240E-04,
+    1.23548E-04,
+    9.66686E-05,
+    7.57509E-05,
+    5.92416E-05,
+    4.63943E-05,
+    3.63850E-05,
 //---- He --------------------------------------------------------------------
-	0.01518479275,
-	0.007621439546,
-	0.004883145696,
-	0.003299965996,
-	0.002260409686,
-	0.00159437032,
-	0.001124788578,
-	0.0007933953673,
-	0.0005606414716,
-	0.0004185553604,
-	0.0003267948866,
-	0.0002557222899,
-	0.0002003867723,
-	0.0001567161546,
-	0.0001227342122,
-	9.625377675E-5
+	1.51848E-02,
+    7.62144E-03,
+    4.88315E-03,
+    3.29997E-03,
+    2.26041E-03,
+    1.59437E-03,
+    1.12479E-03,
+    7.93395E-04,
+    5.60641E-04,
+    4.18555E-04,
+    3.26795E-04,
+    2.55722E-04,
+    2.00387E-04,
+    1.56716E-04,
+    1.22734E-04,
+    9.62538E-05
 };
 
 rom const float e1min[] =
 {
 //---- N2 --------------------------------------------------------------------
-	0.1591036,			// Integration constant for 1 minute,
-	0.08299596,			// ie. 1 - 2^(-1/ht)
-	0.053942353,
-	0.036774196,
-	0.02534539,
-	0.017935055,
-	0.012684012,
-	8.961515534E-3,
-	6.338971845E-3,
-	4.73633146E-3,	
-	3.699808187E-3,
-	2.89599589E-3,
-	2.270033275E-3,
-	1.775722E-3,
-	1.390893611E-3,
-	1.090974815E-3,
+	1.59104E-01,     	// Integration constant for 1 minute,
+    8.29960E-02,        // Ie. 1- 2^(-1/HT)
+    5.61257E-02,
+    3.77762E-02,
+    2.53454E-02,
+    1.76160E-02,
+    1.25236E-02,
+    8.96152E-03,
+    6.33897E-03,
+    4.73633E-03,
+    3.69981E-03,
+    2.89600E-03,
+    2.27003E-03,
+    1.77572E-03,
+    1.39089E-03,
+    1.09097E-03,
 //---- e 1min He -------------------------------------------------------------
-	0.368108684,
-	0.2050840824,
-	0.1365792957,
-	0.09440463235,
-	0.06563586265,
-	0.04674161154,
-	0.03319905126,
-	0.02353005571,
-	0.0166832282,
-	0.01248075064,
-	0.009757532198,
-	0.007643290133,
-	0.005994168431,
-	0.004690816669,
-	0.003675481163,
-	0.002883586737
+	3.68109E-01,
+	2.05084E-01,
+    1.36579E-01,
+    9.44046E-02,
+    6.56359E-02,
+    4.67416E-02,
+    3.31991E-02,
+    2.35301E-02,
+    1.66832E-02,
+    1.24808E-02,
+    9.75753E-03,
+    7.64329E-03,
+    5.99417E-03,
+    4.69082E-03,
+    3.67548E-03,
+    2.88359E-03
 };
 
 rom const float e10min[] =
@@ -215,38 +216,38 @@
 //---- N2 --------------------------------------------------------------------
 // Die 10 min Werte in float Notation:
 //  und zwar 1 - 2^(-10/ht)
-	0.823223,			// 1 - 2^(-10/4.0)
-	0.579552,
-	0.425651,
-	0.312487,
-	0.226416,
-	0.165547,
-	0.11984,
-	0.0860863,
-	0.0616117,
-	0.0463665,
-	0.0363881,
-	0.0285855,
-	0.0224698,
-	0.017616,
-	0.0138222,
-	0.0108563,
+	8.23223E-01,			// 1 - 2^(-10/4.0)
+	5.79552E-01,
+    4.38769E-01,
+    3.19605E-01,
+    2.26416E-01,
+    1.62832E-01,
+    1.18409E-01,
+    8.60863E-02,
+    6.16117E-02,
+    4.63665E-02,
+    3.63881E-02,
+    2.85855E-02,
+    2.24698E-02,
+    1.76160E-02,
+    1.38222E-02,
+    1.08563E-02,
 //---- He --------------------------------------------------------------------
-	0.989851,
-	0.899258,
-	0.769737,
-	0.629027,
-	0.492821,
-	0.380407,
-	0.286538,
-	0.211886,
-	0.154849,
-	0.118026,
-	0.0934005,
-	0.0738569,
-	0.0583504,
-	0.0459303,
-	0.0361528,
-	0.0284646,
+	9.89851E-01,
+	8.99258E-01,
+    7.69737E-01,
+    6.29027E-01,
+    4.92821E-01,
+    3.80407E-01,
+    2.86538E-01,
+    2.11886E-01,
+    1.54849E-01,
+    1.18026E-01,
+    9.34005E-02,
+    7.38569E-02,
+    5.83504E-02,
+    4.59303E-02,
+    3.61528E-02,
+    2.84646E-02
 };