diff src/simulator.asm @ 604:ca4556fb60b9

bump to 2.99beta, work on 3.00 stable
author heinrichsweikamp
date Thu, 22 Nov 2018 19:47:26 +0100
parents e1f0f5e3d4e4
children c40025d8e750
line wrap: on
line diff
--- a/src/simulator.asm	Thu Oct 11 21:06:29 2018 +0200
+++ b/src/simulator.asm	Thu Nov 22 19:47:26 2018 +0100
@@ -1,6 +1,6 @@
 ;=============================================================================
 ;
-;   File simulator.asm								REFACTORED VERSION V2.98
+;   File simulator.asm								REFACTORED VERSION V2.99e
 ;
 ;   Decoplan interface to C model code.
 ;
@@ -23,23 +23,18 @@
 #include "gaslist.inc"
 #include "isr.inc"
 
-gui		CODE
-
 	extern deco_clear_tissue
 	extern deco_push_tissues_to_vault
 	extern deco_calc_dive_interval
 	extern deco_calc_hauptroutine
 	extern deco_pull_tissues_from_vault
 	extern TFT_display_decotype_surface1
-	extern get_first_dil_to_WREG
-	extern get_first_gas_to_WREG
-	extern setup_dil_registers
-	extern setup_gas_registers
-	extern deco_setup_cc_diluents
-	extern deco_setup_oc_gases
 	extern log_screendump_and_onesecond
 	extern logbook_preloop_tasks
 	extern do_return_demo_planner
+	extern dive_boot_oc_bail
+	extern dive_boot_oc
+	extern dive_boot_cc
 
 
 ;---- Private local variables -------------------------------------------------
@@ -47,8 +42,8 @@
 	CBLOCK local1				; max size is 16 Byte !!!
 		decoplan_index			; within each page
 		decoplan_gindex			; global index
-		decoplan_last			; Depth of last stop (CF#29)
-		decoplan_flags			; Various private flags.
+		decoplan_last			; depth of last stop (CF#29)
+		decoplan_flags			; various private flags
 		decoplan_page			; page number
 		decoplan_warnings		; deco engine warnings
 		gas_counter				; counter for looping through the gases
@@ -60,39 +55,35 @@
 #define decoplan_last_ceiling_shown	decoplan_flags,0
 #define decoplan_abort				decoplan_flags,1
 
+
+simulator		CODE
+
+
 ;---- Demo deco planner ------------------------------------------------------
 
 	global	do_demo_planner
 do_demo_planner:
-	btfsc	FLAG_gauge_mode				; =1: In Gauge mode
-	goto	do_return_demo_planner
-	btfsc	FLAG_apnoe_mode				; =1: In Apnea mode
-	goto	do_return_demo_planner
-	bcf		decoplan_abort				; initialize (clear) abort flag
-	bcf		is_bailout					; clear bailout condition (may have remained set from last invocation)
+	btfsc	FLAG_gauge_mode					; in gauge mode?
+	bra		do_demo_planner_exit			; YES - abort
+	btfsc	FLAG_apnoe_mode					; in Apnea mode?
+	bra		do_demo_planner_exit			; YES - abort
+	bcf		decoplan_abort					; initialize (clear) abort flag
+	bcf		FLAG_bailout_mode				; clear bailout condition (may have remained set from last invocation)
 	rcall	deco_planer
-	btfss	decoplan_abort				; skip recall deco_show_plan if calculations were aborted
+	btfss	decoplan_abort					; skip recall deco_show_plan if calculations were aborted
 	rcall	deco_show_plan
+do_demo_planner_exit:
 	goto	do_return_demo_planner
 
 
-	global	deco_setup
 deco_setup:
-	btfsc	FLAG_ccr_mode
-	bra		deco_setup_cc
-	btfsc	FLAG_pscr_mode
-	bra		deco_setup_cc
-deco_setup_oc:
-	call	get_first_gas_to_WREG			; gets first gas (1-5) into WREG
-	call	setup_gas_registers				; with WREG=Gas 1-5
-	call	deco_setup_oc_gases				; setup OC/Bailout Gases and configure for OC deco calculation
-	bra		deco_setup_cont
-deco_setup_cc:
-	call	get_first_dil_to_WREG			; gets first gas (1-5) into WREG
-	call	setup_dil_registers				; with WREG=Gas 1-5
-	call	deco_setup_cc_diluents			; setup CCR/pSCR diluents and configure for CCR/pSCR deco calculation
-deco_setup_cont:
-	; use ambient conditions for simulation
+	call	dive_boot_oc_bail				; basic setup for all modes
+	btfsc	FLAG_oc_mode					; in OC mode?
+	call	dive_boot_oc					; YES - set up OC mode
+	btfss	FLAG_oc_mode					; in OC mode?
+	call	dive_boot_cc					; NO - set up CCR/pSCR mode
+
+	; use ambient conditions for deco calculation
 	SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface	; copy surface pressure to deco routine
 
 	movlw	deco_distance
@@ -103,17 +94,15 @@
 	movff	opt_GF_high,char_I_GF_High_percentage
 
 	; overwrite GF if aGF is wanted
-	bsf		use_agf
-	TSTOSS	opt_sim_use_aGF
-	bcf		use_agf
+	bsf		use_agf							; set flag to use alternative GF factors by default
+	TSTOSS	opt_sim_use_aGF					; shall use alternative GF factors?
+	bcf		use_agf							; NO - clear flag again
 
-	btfsc	use_agf							; =1: Use aGF
+	btfsc	use_agf							; =1: use aGF
 	movff	opt_aGF_low,char_I_GF_Low_percentage
-	btfsc	use_agf							; =1: Use aGF
+	btfsc	use_agf							; =1: use aGF
 	movff	opt_aGF_high,char_I_GF_High_percentage
 
-	bcf		is_bailout
-
 	; setup char_I_const_ppO2 for CC modes
 	clrf	WREG
 	btfsc	FLAG_pscr_mode
@@ -131,25 +120,29 @@
 ;
 		global	deco_planer
 deco_planer:
-	call	speed_fastest					; Quick !
+	call	speed_fastest					; quick!
+	call	TFT_ClearScreen					; clear screen to show that calculator is starting up
 	call	deco_push_tissues_to_vault		; C-code: back-up state of the real tissues
 	banksel	common
-	rcall	deco_setup						; Setup all model parameters.
+	rcall	deco_setup						; setup all model parameters
 
 ;---- Specific settings ------------------------------------------------------
 
 	; configure the deco engine for normal plan, CNS & gas volume calculation and no delayed ascent
-	movff	char_O_deco_status,WREG			; bank-safe copy
-	bcf		WREG,DECO_PLAN_FLAG				; normal plan mode,
-	bsf		WREG,DECO_CNS_FLAG				; enable CNS calculation (CNS at end of dive),
-	bsf		WREG,DECO_VOLUME_FLAG			; enable gas volume calculation, and
-	bcf		WREG,DECO_ASCENT_FLAG			; disable delayed ascent calculation
-	movff	WREG,char_O_deco_status			; bank-safe copy back
+	movff	char_O_deco_status,lo			; bank-safe copy
+	bcf		lo,DECO_PLAN_FLAG				; normal plan mode,
+	bsf		lo,DECO_VOLUME_FLAG				; enable gas volume calculation, and
+	bcf		lo,DECO_ASCENT_FLAG				; disable delayed ascent calculation
+	movff	lo,char_O_deco_status			; bank-safe copy back
 
 	; configure the deco engine for total-dive gas volume calculation
-	movff	char_O_main_status,WREG			; bank-safe copy
-	bsf		WREG,DECO_BOTTOM_FLAG			; set bottom flag
-	movff	WREG,char_O_main_status			; bank-safe copy back
+	movff	char_O_main_status,hi			; bank-safe copy
+	bcf		hi,DECO_TR_FUNCTIONS			; execution of TR functions is not needed in deco calculator mode
+	bsf		hi,DECO_BOTTOM_FLAG				; set bottom flag
+	bsf		hi,DECO_Z_FACTOR_FLAG			; enable use of Z factor by default
+	TSTOSS	opt_ZfactorUse					; shall use Z factor?
+	bcf		hi,DECO_Z_FACTOR_FLAG			; NO - disable again
+	movff	hi,char_O_main_status			; bank-safe copy back
 
 deco_planer_redo:
 	; show deco calculation is in progress
@@ -160,66 +153,65 @@
 	WIN_SMALL	.1,.215
 	STRCPY_TEXT_PRINT tAbort
 
-	; configure the deco engine for restart:
-	movff	char_O_deco_status,WREG			; bank-safe copy
-	bsf		WREG,DECO_STATUS_0_FLAG			; configure init ...
-	bsf		WREG,DECO_STATUS_1_FLAG			; ... state,
-	movff	WREG,char_O_deco_status			; bank-safe copy back
+	; configure the deco engine for initialization
+	movff	char_O_deco_status,lo			; bank-safe copy
+	bsf		lo,DECO_STATUS_0_FLAG			; configure init ...
+	bsf		lo,DECO_STATUS_1_FLAG			; ... state,
+	movff	lo,char_O_deco_status			; bank-safe copy back
 
-;---- Add delay at surface, if needed ----------------------------------------
+;---- add delay at surface, if requested -------------------------------------
 	banksel	char_I_dive_interval
 	tstfsz	char_I_dive_interval
 	call	deco_calc_dive_interval
 
 ;---- Dive loop --------------------------------------------------------------
-	; Compute dive ambient conditions
+	; compute dive ambient conditions
 	banksel	char_I_bottom_depth
 	movf	char_I_bottom_depth,W
 	mullw	.100
-	movlw	LOW(.1000)
+	movlw	LOW (.1000)
 	addwf	PRODL,W
 	movwf	int_I_pres_respiration+0
 	movlw	HIGH(.1000)
 	addwfc	PRODH,W
 	movwf	int_I_pres_respiration+1
-	banksel common
+	banksel	common
 
 	movff	char_I_bottom_time,char_I_sim_advance_time
 
-	clrf	TMR5L
-	clrf	TMR5H							; 30,51757813µs/bit in TMR5L:TMR5H
+	clrf	TMR5L							; restart timer used to preempt stops calculation
+	clrf	TMR5H							;
 
-	call	deco_calc_hauptroutine			; C-code: initialization + complete bottom time part
+	call	deco_calc_hauptroutine			; initialization, complete bottom time part and initial ascent
 	banksel	common
 
-;---- BAILOUT: Switch to OC gases for ascent cycles --------------------------
-	btfss	is_bailout						; Doing a bailout deco plan ?
-	bra	 deco_planer_finishing				; NO  - keep gases
-											; YES - switch to OC gas 
+	btfss	FLAG_bailout_mode				; doing a bailout deco plan?
+	bra		deco_planer_loop				; NO  - keep gases and go on
+											; YES - switch to OC gas and restart deco plan
 
-	; reconfigure the deco engine for delayed ascent mode
+;---- BAILOUT: Switch to OC gases for ascent -----------------------------------
+
+	; reconfigure the deco engine for delayed ascent & bailout mode and start a new calculation cycle
 	movff	char_O_deco_status,lo			; bank-safe copy
 	bsf		lo,DECO_ASCENT_FLAG				; set flag for delayed ascent calculation
+	bsf		lo,DECO_BAILOUT_FLAG			; set bailout mode flag to allow gas changes on initial ascent
+	bcf		lo,DECO_STATUS_0_FLAG			; configure start of a new...
+	bcf		lo,DECO_STATUS_1_FLAG			; ... deco calculation cycle
 	movff	lo,char_O_deco_status			; bank-safe copy back
 
-	; configure the deco engine for delayed ascent part gas volume calculation
-	movff	char_O_main_status,WREG			; bank-safe copy
-	bcf		WREG,DECO_BOTTOM_FLAG			; set bottom flag
-	movff	WREG,char_O_main_status			; bank-safe copy back
+	; reconfigure the deco engine for bailout ascent needs
+	movff	char_O_main_status,hi			; bank-safe copy
+	bcf		hi,DECO_BOTTOM_FLAG				; clear bottom flag
+	movff	hi,char_O_main_status			; bank-safe copy back
 
 	; reconfigure gas settings to OC gases
-	call	get_first_gas_to_WREG			; get first gas (1-5) into WREG
-	call	setup_gas_registers				; With WREG=Gas 1-5 (or 6, not applicable here)
-	call	deco_setup_oc_gases				; With WREG=Gas 1-5 (or 6, not applicable here)
-
-	; set the gas change override flag to allow gas changes before deco stops as done in alternative plan
-	movff	char_O_main_status,lo			; bank-safe copy
-	bsf		lo,DECO_GASCHANGE_OVRD			; set flag for gas change override
-	movff	lo,char_O_main_status			; bank-safe copy back
+	call	dive_boot_oc					; configure deco engine for OC mode
 
 ;---- Wait until status reaches zero -------------------------------------------
-deco_planer_finishing:
-	call	deco_calc_hauptroutine			; C-code: Simulate more dive time to trigger the deco calculations
+deco_planer_loop:
+	clrf	TMR5L							; restart timer used to preempt stops calculation
+	clrf	TMR5H							;
+	call	deco_calc_hauptroutine			; simulate more dive time to trigger the deco calculations
 	banksel	common
 
 	btfss	switch_left						; check if left button was pressed
@@ -227,11 +219,9 @@
 	bsf		decoplan_abort					; YES - set abort flag so that deco_show_plan will not be called
 	bra		deco_planer_finishing_2			;       do some clean-up and return
 deco_planer_finishing_1:
-	movff	char_O_deco_status,lo			; working copy of char_O_deco_status in bank common
-	movlw	DECO_STATUS_MASK				; bit mask for deco status bit set
-	andwf	lo,W							; mask out bits showing state of computation
-	tstfsz	WREG							; check if a compute cycle is finished (bits 1 and 0 == 0)
-	bra		deco_planer_finishing			; NO - needs more computation cycles
+	movff	char_O_main_status,hi			; working copy of char_O_main_status in bank common
+	btfss	hi,DECO_COMPLETED_NORM			; calculations completed?
+	bra		deco_planer_loop				; NO - needs more computation cycles
 
 ;---- Done: add CNS from decoplan, and restore tissues
 deco_planer_finishing_2:
@@ -263,13 +253,13 @@
 
 	lfsr	FSR2,buffer
 
-	TSTOSS	opt_units					; 0=Meters, 1=Feets
+	TSTOSS	opt_units					; 0=Meter, 1=Feet
 	bra		deco_plan_show_nstd_stop_metric
 
-	movff	hi,up						; backup hi (minutes)
-	WIN_LEFT .85
+	movff	hi,ul						; back-up hi (minutes)
+	WIN_LEFT .80
 	movf	lo,W						; lo = m
-	mullw	.100						; PRODL:PRODH = mbar
+	mullw	.100						; PRODL:PRODH = hPa
 	movff	PRODL,lo
 	movff	PRODH,hi
 	; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops...
@@ -292,76 +282,62 @@
 	call	div32x16					; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
 	movff	xC+0,lo
 	movff	xC+1,hi						; restore lo and hi with updated value
-	bsf		leftbind
-	bsf		ignore_digit4				; Only full feet
+	bsf		ignore_digit4				; only full feet
 	output_16
-	bcf		leftbind
-	STRCAT_PRINT "ft "
-	movff	up,hi						; restore hi (minutes)
+	STRCAT_PRINT "ft"
+	movff	ul,hi						; restore hi (minutes)
 	bra		deco_plan_show_nstd_stop_common
 
 deco_plan_show_nstd_stop_metric:
-	WIN_LEFT .90
-	bsf	leftbind
-	output_8							; outputs into Postinc2!
-	bcf	leftbind
-	STRCAT_PRINT "m "
+	WIN_LEFT .85
+	output_8							; outputs into postinc2
+	STRCAT_PRINT "m"
 
 deco_plan_show_nstd_stop_common:
 	;---- Print duration -------------------------------------------------
 	WIN_LEFT .135
 	lfsr	FSR2,buffer
-
-	movf	lo,W						; Swap hi & lo
 	movff	hi,lo
-	movwf	hi
-
-	output_8							; Allow up to 240'
-	clrf	WREG
-	movff	WREG,buffer+.3				; limit to 2 chars
-	STRCAT_PRINT ""
-
-	movf	lo,W						; Swap back hi & lo
-	movff	hi,lo
-	movwf	hi
+	output_99							; stop entries are 99 min max.
+	STRCAT_PRINT "'"
 
 	;---------------------------------------------------------------------
-	; Draw the bar graph used for deco stops (deco plan in simulator or dive).
+	; Draw the bar graph used for deco stops (deco plan in simulator or dive)
 	incf	win_top,F
 	movlw	.19
 	movwf	win_height
 	movlw	.118
 	movwf	win_leftx2					; column left (0-159)
 	movlw	.16
-	movwf	win_width+0					; column max width.
+	movwf	win_width+0					; column max width
 	clrf	win_width+1
 
-	; Draw used area (hi = minutes):
-	movlw	.16							; Limit length (16min)
-	cpfslt	hi
-	movwf	hi
-	movff	hi,win_bargraph				; Active width, the rest is cleared.
+	; Draw used area (lo = minutes):
+	movlw	.16							; limit length to max. column width
+	cpfslt	lo
+	movwf	lo
+	movff	lo,win_bargraph				; active width, the rest is cleared
 	call	TFT_box
 
 	; Restore win_top
 	call	TFT_standard_color
-	decf	win_top,F					; Restore win_top
+	decf	win_top,F					; restore win_top
 	return
 
 ;-----------------------------------------------------------------------------
 ; Clear unused area below last stop
 ; Inputs: win_top : last used area...
 deco_plan_show_clear_bottom:
-	movf	win_top,W					; Get back from bank0
-	sublw	.239						; No: bottom row in planning
+	movf	win_top,W					; get back from bank0
+	sublw	.239						; bottom row in planning
 	movwf	win_height
 
-	WIN_LEFT .85						; Full dive menu width
+	WIN_LEFT .85						; full dive menu width
 	movlw	.159-.85+.1
 	movwf	win_width+0
 	clrf	win_width+1
 
-	clrf	win_color1					; Fill with black
+	clrf	win_color1					; fill with black
 	clrf	win_color2
 
 	goto	TFT_box						; and return
@@ -372,9 +348,9 @@
 ;         decoplan_page = page number.
 ;
 deco_show_plan_page:
-	bcf	 win_invert						; Reset invert flag
+	bcf		win_invert					; reset invert flag
 
-	;---- Is there deco stops ? ------------------------------------------
+	;---- Are there deco stops ? ------------------------------------------
 	movff	char_O_first_deco_depth,WREG
 	iorwf	WREG
 	bnz		deco_plan_show_1
@@ -382,15 +358,25 @@
 	;---- No Deco --------------------------------------------------------
 	call	TFT_standard_color
 	TEXT_SMALL .80, .0, tNoDeco
+
+	; output of remaining NDL time
+	WIN_SMALL	.80, .50				; same line as bottom time
+	movff	char_O_nullzeit,lo			; remaining NDL at end of bottom time
+	output_8
+	PUTC	"'"
+	PUTC	" "
+	STRCAT_TEXT_PRINT tNDLleft			; "left"
+
 	bsf		decoplan_last_ceiling_shown
 	return
 
 deco_plan_show_1:
-	lfsr	FSR0,char_O_deco_depth		; Initialize indexed addressing.
+	lfsr	FSR0,char_O_deco_depth		; initialize indexed addressing
 	lfsr	FSR1,char_O_deco_time
 
-	clrf	decoplan_index				; Start with index = 0
-	clrf	win_top						; and row = 0
+	clrf	decoplan_index				; start with index = 0
+	movlw	.24
+	movwf	win_top						; and row = 0 at position 24
 
 	; Read stop parameters, indexed by decoplan_index and decoplan_page
 	movf	decoplan_page,W				; decoplan_gindex = 6*decoplan_page + decoplan_index
@@ -399,18 +385,18 @@
 	addwf	PRODL,W
 	movwf	decoplan_gindex				; --> decoplan_gindex
 
-	bcf		decoplan_last_ceiling_shown	; Not finished yet...
+	bcf		decoplan_last_ceiling_shown	; not done yet...
 
 deco_plan_show_2:
-	btfsc	decoplan_gindex,5			; Reached table length (32) ?
-	bra		deco_plan_show_99			; YES: finished...
+	btfsc	decoplan_gindex,5			; reached table length (32) ?
+	bra		deco_plan_show_99			; YES - done
 
 	; Read stop parameters, indexed by decoplan_index
 	movf	decoplan_gindex,W			; index
 	movff	PLUSW0,lo					; char_O_deco_depth[gindex]
 	movff	PLUSW1,hi					; char_O_deco_time [gindex]
 	movf	lo,W
-	bz		deco_plan_show_99			; depth == 0 : finished.
+	bz		deco_plan_show_99			; depth == 0 : done
 
 	; Display the stop line
 	rcall	deco_plan_show_stop
@@ -424,23 +410,23 @@
 	; Max number of lines/page reached ?
 	movlw	.8							; 8 lines/page in deco plan
 	cpfseq	decoplan_index
-	bra		deco_plan_show_2			; NO: loop
+	bra		deco_plan_show_2			; NO - loop
 
 	; Check if next stop is end-of-list ?
 	movf	decoplan_gindex,W
 	movf	PLUSW0,W					; char_O_deco_depth[gindex]
-	bz		deco_plan_show_99			; End of list...
+	bz		deco_plan_show_99			; end of list
 
 	; Display the message "more..."
-	rcall	deco_plan_show_clear_bottom	; Clear from next line
+	rcall	deco_plan_show_clear_bottom	; clear from next line
 
 	call	TFT_standard_color
 	TEXT_SMALL .88, .220, tMore
 	return
 
 deco_plan_show_99:
-	bsf		decoplan_last_ceiling_shown ; Nothing more in table to display.
-	rcall	deco_plan_show_clear_bottom ; Clear from next line
+	bsf		decoplan_last_ceiling_shown ; nothing more in table to display
+	rcall	deco_plan_show_clear_bottom ; clear from next line
 	return
 
 ;-----------------------------------------------------------------------------
@@ -451,17 +437,17 @@
 	clrf	decoplan_page
 	call	TFT_ClearScreen
 	WIN_COLOR color_greenish
-	btfsc	is_bailout
+	btfsc	FLAG_bailout_mode
 	bra		deco_show_plan_bail_title
 	TEXT_SMALL .1,.1, tDivePlan
 	bra		deco_show_plan2
-deco_show_plan_bail_title:	
-		TEXT_SMALL .1,.1, tDiveBailout
+deco_show_plan_bail_title:
+	TEXT_SMALL .1,.1, tDiveBailout
 deco_show_plan2:
 	call	TFT_standard_color
 	;---- Display Plan Parameters
 	WIN_SMALL .0,.25
-	STRCPY	"Int:"
+	STRCPY	"Int.:"
 	movff	char_I_dive_interval,lo
 	bsf		leftbind
 	output_8
@@ -470,17 +456,17 @@
 	WIN_SMALL .0,.50
 	STRCPY_TEXT tBtTm_short
 	movff	char_I_bottom_time,lo
-	bsf	leftbind
+	bsf		leftbind
 	output_8
-	bcf	leftbind
+	bcf		leftbind
 	STRCAT_PRINT "'"
 	WIN_SMALL .0,.75
 	STRCPY_TEXT tDepth
 	PUTC	":"
 	movff	char_I_bottom_depth,lo
-	bsf	leftbind
+	bsf		leftbind
 	output_8
-	bcf	leftbind
+	bcf		leftbind
 	STRCAT_PRINT "m"
 	WIN_SMALL .0,.105								; set position for warnings or sat/dsat factors
 
@@ -507,7 +493,7 @@
 	WIN_SMALL .25,.105
 	movff	char_I_saturation_multiplier,lo
 	output_8
-	STRCAT "/"
+	STRCAT	"/"
 	movff	char_I_desaturation_multiplier,lo
 	output_8
 	STRCAT_PRINT ""
@@ -515,20 +501,20 @@
 deco_show_plan_m1:
 	call	TFT_standard_color				; clean-up from warnings
 
-	;---- Get Model
+	;---- get Model
 	movff	char_I_deco_model,WREG
 	iorwf	WREG
-	bz	 deco_show_plan_m2
+	bz		deco_show_plan_m2
 
 	;---- Display GF low/high values
 	WIN_SMALL .0,.130
 	STRCAT_PRINT "GF:"
 	WIN_SMALL .25,.130
 	movff	char_I_GF_Low_percentage,lo
-	output_99x
+	output_8
 	STRCAT	"/"
 	movff	char_I_GF_High_percentage,lo
-	output_99x
+	output_8
 	STRCAT_PRINT ""
 
 deco_show_plan_m2:
@@ -564,14 +550,14 @@
 	STRCPY_TEXT tCNS2						; "CNS:"
 	movff	int_O_CNS_fraction+0,lo
 	movff	int_O_CNS_fraction+1,hi
-	call	TFT_color_code_cns				; Color-code CNS output
+	call	TFT_color_code_cns				; color-code CNS output
 	bsf		leftbind
 	output_16_3								; limit to 999 and display only (0-999)
 	bcf		leftbind
 	STRCAT	"%\x92"							; "->"
 	movff	int_O_normal_CNS_fraction+0,lo
 	movff	int_O_normal_CNS_fraction+1,hi
-	call	TFT_color_code_cns				; Color-code CNS output
+	call	TFT_color_code_cns				; color-code CNS output
 	bsf		leftbind
 	output_16_3								; limit to 999 and display only (0-999)
 	bcf		leftbind
@@ -590,22 +576,22 @@
 	btfsc	switch_right
 	bra		deco_show_plan_3
 	btfsc	switch_left
-	return									; Return to simulator menu
-	call	log_screendump_and_onesecond	; Check if we need to make a screen shot and check for new second
-	btfsc	sleepmode						; Timeout?
+	return									; return to simulator menu
+	call	log_screendump_and_onesecond	; check if we need to make a screen shot and check for new second
+	btfsc	sleepmode						; timeout?
 	goto	restart
 	bra		deco_show_plan_2
 
 deco_show_plan_3:
 	btfss	decoplan_last_ceiling_shown
 	bra		deco_show_plan_1
-	; All stops shown
+	; all stops shown
 
-;---- In CCR and pSCR mode, compute a BAILOUT deco plan -----------------------
+;----in CCR and pSCR mode, compute a BAILOUT deco plan -----------------------
 	movff	char_O_deco_status,WREG			; get deco calculation status
 	btfss	WREG,DECO_MODE_LOOP_FLAG		; check if in CCR or pSCR mode
 	bra		simulator_show_decoplan5_0		; NO  - normal OC mode: just display
-	bsf		is_bailout						; YES - redo 2nd deco-plan in bailout mode
+	bsf		FLAG_bailout_mode				; YES - redo 2nd deco-plan in bailout mode
 	rcall	deco_planer_redo				;       redo plan computation
 
 	btfss	decoplan_abort					; shall we abort?
@@ -613,42 +599,44 @@
 	return									; YES
 
 
-;---- In OC+BAIL modes, show the gas usage special page -----------------------
+;---- in OC+BAIL modes, show the gas usage special page -----------------------
 simulator_show_decoplan5_0:
 	; Clear the complete stop result column:
 	WIN_BOX_BLACK .0, .239, .80, .159		; top, bottom, left, right
 
 	movlw	.25
-	movwf	row_pos							; Row for gas list is .25+.25
-	clrf	gas_counter						; Gas counter
-	lfsr	FSR0,int_O_gas_volumes			; Initialize indexed addressing.
+	movwf	row_pos							; row for gas list is .25+.25
+	clrf	gas_counter						; gas counter
+	lfsr	FSR0,int_O_ascent_volumes		; initialize indexed addressing
 
-	WIN_LEFT .80							; Set column
+	WIN_LEFT .80							; set column
 	call	TFT_standard_color
 
+	bcf		FLAG_diluent_setup				; steer gaslist_strcat_gas to use OC gases
+
 simulator_show_decoplan5_loop:
-	movff	gas_counter,PRODL				; Copy to PRODL first
-	incf	gas_counter,F					; Increment gas #
+	movff	gas_counter,PRODL				; copy to PRODL first
+	incf	gas_counter,F					; increment gas #
 
 	movff	gas_counter,WREG				; copy current gas to WREG for color-coding
 	call	TFT_color_code_gas				; set output color according to gas (1-5)
 
 	lfsr	FSR2,buffer
 	bsf		short_gas_decriptions
-	bsf		divemode						; Tweak "customview_show_mix:"
-	call	gaslist_strcat_gas				; Input: PRODL : gas number (0..4), Output: "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2
-	bcf		divemode						; Tweak "customview_show_mix:"
+	bsf		divemode						; tweak "customview_show_mix:"
+	call	gaslist_strcat_gas				; input: PRODL : gas number (0..4), Output: "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2
+	bcf		divemode						; tweak "customview_show_mix:"
 
 	movlw	.25
-	addwf	row_pos,F						; Increase row position
-	movff	row_pos,win_top					; Set Row
+	addwf	row_pos,F						; increase row position
+	movff	row_pos,win_top					; set row
 
-	movff	POSTINC0,lo						; Read (16bit) result, low first,
-	movff	POSTINC0,hi						; then high.
+	movff	POSTINC0,lo						; read (16bit) result, low first,
+	movff	POSTINC0,hi						; then high
 
 	movf	lo,W
 	andwf	hi,W
-	incf	WREG							; > 65535? 
+	incf	WREG							; > 65535 ?
 	bnz		simulator_show_decoplan5_1		; NO
 	STRCAT_PRINT ">65500"					; YES
 	bra		simulator_show_decoplan5_2
@@ -656,27 +644,25 @@
 simulator_show_decoplan5_1:
 	PUTC	":"
 	bsf		leftbind
-	output_16								; No decimal anymore.
+	output_16								; no decimal anymore
 	bcf		leftbind
 	STRCAT_PRINT ""
 
 	; Loop for all 5 gas
 simulator_show_decoplan5_2:
 	movlw	d'5'							; list all five gases
-	cpfseq	gas_counter						; All gases shown?
-	bra		simulator_show_decoplan5_loop	; No
+	cpfseq	gas_counter						; all gases shown?
+	bra		simulator_show_decoplan5_loop	; NO - loop
 
 	WIN_COLOR color_greenish
 
-	movlw	.30
-	addwf	row_pos,F						; Increase row position
-	movff	row_pos,win_top					; Set Row
-	STRCPY_TEXT_PRINT tBarLiter				; "Bar Liter"
-
 	WIN_SMALL .80,.25
 	STRCPY_TEXT tGasUsage					; "Gas Usage"
 	STRCAT_PRINT ":"
 
+	WIN_SMALL .120,.175
+	STRCPY_TEXT_PRINT tLiterLong			; "Liter"
+
 	call	TFT_standard_color
 	call	logbook_preloop_tasks
 
@@ -689,13 +675,12 @@
 simulator_show_decoplan5_3a:
 	btfss	switch_left
 	bra		simulator_show_decoplan5_4
-	bcf		is_bailout						; Back to normal
-	bcf		ccr_diluent_setup				; init for OC/Bailout
-	return									; Return to simulator menu
+	bcf		FLAG_bailout_mode				; back to normal
+	return									; return to simulator menu
 
 simulator_show_decoplan5_4:
-	call	log_screendump_and_onesecond	; Check if we need to make a screen shot and check for new second
-	btfsc	sleepmode						; Timeout?
+	call	log_screendump_and_onesecond	; check if we need to make a screen shot and check for new second
+	btfsc	sleepmode						; timeout?
 	goto	restart
 	bra		simulator_show_decoplan5_3