view src/gaslist.asm @ 595:1719de53e497

2.97 SP2 (999bar fix)
author heinrichsweikamp
date Mon, 25 Jun 2018 18:29:54 +0200
parents b455b31ce022
children ca4556fb60b9
line wrap: on
line source

;=============================================================================
;
;   File gaslist.asm												## V2.98
;
;   Managing OSTC gas list
;
;   Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
;=============================================================================
; HISTORY
;   2011-08-11 : [jDG] Creation.

#include "hwos.inc"						; Mandatory header
#include "convert.inc"
#include "math.inc"						; div16x16 for MOD calculations
#include "strings.inc"
#include "tft.inc"
#include "tft_outputs.inc"
#include "shared_definitions.h"

	extern	convert_mbar_to_feet
	extern	customview_show_mix
	extern	tGasDisabled
	extern	tDilDisabled
	extern	tbar

gui		CODE

;=============================================================================
; Append gas description to current string.
; Input:  PRODL : gas number (0..4)
;         FSR2  : Current string position.
; Output: Text appended into buffer pointed by FSR2.

	global	gaslist_strcat_gas
gaslist_strcat_gas:
	rcall	gaslist_setgas				; Sets gaslist_gas (0-4 for OC/Bailout, 5-9 for Diluents)
	; Retrieve gas definition:
gaslist_strcat_gas_0:
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_O2_ratio		; Read opt_gas_O2_ratio[WREG]
	movff	PLUSW1,lo					; O2 ratio
	;movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_He_ratio		; Read opt_gas_He_ratio[WREG]
	movff	PLUSW1,hi					; He ratio
	goto	customview_show_mix			; Put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and RETURN

;=============================================================================
; Append current mix to current string (For divemode)
; Input: FSR2 : Current string position.
; Output: Text appended into buffer pointed by FSR2.
	global	gaslist_strcat_gas6
gaslist_strcat_gas6:					; Show current O2/He mix
	STRCAT_TEXT tGas
	STRCAT	": "
	movff	gas6_O2_ratio,lo
	movff	gas6_He_ratio,hi
	goto	customview_show_mix			; Put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and RETURN


	global	gaslist_show_type
gaslist_show_type:
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_type			; Read opt_gas_type[WREG]
	movff	PLUSW1,lo					; lo holds gas type
	STRCAT_TEXT tType
	lfsr	FSR1,tGasDisabled			; Base text number
	btfsc	ccr_diluent_setup			; In CCR setup?
	lfsr	FSR1,tDilDisabled			; Base text number
	movff	lo,WREG						; 0-3
	rlncf	WREG						; x2
	addwf	FSR1L,F
	movlw	.0
	addwfc	FSR1H,F
	call	strcat_text
	return

	global	gaslist_toggle_type
gaslist_toggle_type:
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_type			; Read opt_gas_type[WREG]
	movff	PLUSW1,lo					; lo holds gas type
	incf	lo,F						; 0-3/0-2
	btfsc	ccr_diluent_setup			; In CCR setup?
	bra		gaslist_toggle_type2		; Yes
	btfsc	lo,2						; >3?
	clrf	lo							; Clear to zero
	movff	lo,PLUSW1					; Copy back result
	return
gaslist_toggle_type2:
	movlw	.3
	cpfslt	lo							; >2?
	clrf	lo							; Clear to zero
	movf	gaslist_gas,W
	movff	lo,PLUSW1					; Copy back result
	return

	global	gaslist_setSP
gaslist_setSP:
	movff	PRODL,gaslist_gas			; 0-4
	return


	global	gaslist_strcat_setpoint
	global	gaslist_strcat_setpoint_0
gaslist_strcat_setpoint:
	call	gaslist_setSP
gaslist_strcat_setpoint_0:
	bsf		leftbind
	btfsc	short_gas_decriptions		; =1: Use short versions of gaslist_strcat_gas_mod and gaslist_strcat_setpoint
	bra		gaslist_strcat_setpoint2	; Short version
	STRCAT_TEXT tSP
	incf	gaslist_gas,W
	movwf	lo
	output_8
	bcf		leftbind
	PUTC	":"
gaslist_strcat_setpoint2:				; Short version
	btfsc	divemode
	bra		gaslist_strcat_setpoint4	; no "*" in divemode
	movf	gaslist_gas,W				; Number-1 into WREG
	bnz		gaslist_strcat_setpoint3	; Not SP1
	PUTC	"*"
	bra		gaslist_strcat_setpoint4
gaslist_strcat_setpoint3:
	PUTC	" "
gaslist_strcat_setpoint4:
	movf	gaslist_gas,W
	lfsr	FSR1,char_I_setpoint_cbar
	movf	PLUSW1,W
	movwf	lo
	clrf	hi
	bsf		leftbind
	output_16dp d'3'
	btfsc	divemode
	bra		gaslist_strcat_setpoint5	; Skip text in divemode
	STRCAT_TEXT tbar
gaslist_strcat_setpoint5:
	PUTC	" "
	; Read switch depth
	movf	gaslist_gas,W
	lfsr	FSR1,char_I_setpoint_change
	movff	PLUSW1,lo

	bsf		ccr_diluent_setup			; inhibit output of "----" for depth 
	call	gaslist_strcat_5
	bcf		ccr_diluent_setup
	return

;----------------------------------------------------------------------------
; Append gas description to current string.
; Input:  PRODL : gas number (0..4)
;         FSR2  : Current string position.
; Output: Text appended into buffer pointed by FSR2.
;
; NOTE: used in the menu-tree for the MENU_CALLBACK entry.

gaslist_strcat_gas_better:				; Yes, check if this is a "better gas"
	bcf		win_invert
	movff	better_gas_number,WREG		; get better gas number into WREG
	decf	WREG,W						; better_gas_number = better_gas_number -1
	btfsc	ccr_diluent_setup			; in CCR menus?
	addlw	.5							; Yes, offset to gases 5-9
	cpfseq	gaslist_gas					; 0-4 for OC/Bailout, 5-9 for Diluents
	return
	call	TFT_attention_color			; show in yellow
	bsf	win_invert						; And invert
	return

	global	gaslist_strcat_gas_mod
gaslist_strcat_gas_mod:
	rcall	gaslist_setgas				; Sets gaslist_gas (0-4 for OC/Bailout, 5-9 for Diluents)
	bsf		space_gas_decriptions		; add a space in front for gas numbers < 10 for alignment
	;bra	gaslist_gastitle

	global	gaslist_gastitle
gaslist_gastitle:
	btfsc	short_gas_decriptions		; =1: Use short versions of gaslist_strcat_gas_mod and gaslist_strcat_setpoint
	bra		gaslist_gastitle1			; Short version
	STRCAT_TEXT tGas
	incf	gaslist_gas,W
	movwf	lo
	btfss	space_gas_decriptions		; add a space in front for gas numbers < 10 for alignment?
	bra		gaslist_gastitle0			; NO
	bcf		space_gas_decriptions		; YES - clear flag again
	movlw	.10							;       load a 10
	cpfslt	lo							;       gas# < 10 ?
	bra		gaslist_gastitle0			;       NO
	PUTC	" "							;       YES - add a space
gaslist_gastitle0:
	bsf		leftbind
	output_8
	bcf		leftbind
	PUTC	":"
gaslist_gastitle1:
	lfsr	FSR1,opt_gas_type
	btfsc	divemode
	bra		gaslist_gastitle3			; no "*" in divemode
	movf	gaslist_gas,W
	decf	PLUSW1,W					; Type-1 into WREG
	bnz		gaslist_gastitle2			; Not "First"
	PUTC	"*"
	bra		gaslist_gastitle3
gaslist_gastitle2:
	PUTC	" "
gaslist_gastitle3:
	call	TFT_standard_color
	btfsc	divemode					; In divemode?
	rcall	gaslist_strcat_gas_better	; Yes, check if this is a "better gas"
	movf	gaslist_gas,W				; (0-4 for OC/Bailout, 5-9 for Diluents)
	movf	PLUSW1,W
	bnz		gaslist_strcat_3
	call	TFT_disabled_color
	bra		gaslist_strcat_4			; no MOD-check and red color for disabled gases
gaslist_strcat_3:
	rcall	gaslist_strcat_gas_0
	PUTC	" "
	; Read switch depth
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents-5
	movlw	.4
	cpfsgt	gaslist_gas					; >4? (-> Diluents)
	lfsr	FSR1,opt_OC_bail_gas_change	; Setup OC Gases

	movf	gaslist_gas,W				; (0-4 for OC/Bailout, 5-9 for Diluents)
	movff	PLUSW1,lo
	rcall	gaslist_calc_mod			; Compute MOD into WREG
	cpfsgt	lo							; within MOD range?
	bra		gaslist_strcat_5			; YES
	call	TFT_warnings_color			; NO  - turn red
	bra		gaslist_strcat_5			; skip gaslist_strcat_gas_0 here
gaslist_strcat_4:
	rcall	gaslist_strcat_gas_0
	PUTC	" "
	; Dummy code, needs some cleanup someday...
	; Read switch depth
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents-5
	movlw	.4
	cpfsgt	gaslist_gas					; >4? (-> Diluents)
	lfsr	FSR1,opt_OC_bail_gas_change	; Setup OC Gases
	movf	gaslist_gas,W				; (0-4 for OC/Bailout, 5-9 for Diluents)
	movff	PLUSW1,lo
	rcall	gaslist_calc_mod			; Compute MOD into WREG
gaslist_strcat_5:
	PUTC	" "
	TSTOSS	opt_units					; 0=Meter, 1=Feet
	bra		gaslist_strcat_3_metric
;gaslist_strcat_3_imperial:
	btfsc	ccr_diluent_setup			; =1: Setting up Diluents ("Gas6-10")
	bra		gaslist_imperial_non_travel
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_type			; Read opt_gas_type[WREG]
	movff	PLUSW1,up					; up holds gas type
	movlw	.2							; 2=Travel
	cpfseq	up							; compare gas type with type 2=Travel
	bra		gaslist_imperial_non_travel	; Non-Travel Gas
	bra		gaslist_strcat_depth_travel	; Show "---" instead of "0m"...
gaslist_imperial_non_travel:
	movf	lo,W
	mullw	.100						; convert meters to mbar
	movff	PRODL,lo
	movff	PRODH,hi
	call	convert_mbar_to_feet		; convert value in lo:hi from mbar to feet
	bsf		leftbind
	output_16_3							; limit to 999 and display only (0-999)
	STRCAT_TEXT tFeets					; "ft"
	return
gaslist_strcat_3_metric:
	btfsc	ccr_diluent_setup			; =1: Setting up Diluents ("Gas6-10")
	bra		gaslist_metric_non_travel
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_type			; Read opt_gas_type[WREG]
	movff	PLUSW1,up					; up holds gas type
	movlw	.2							; 2=Travel
	cpfseq	up							; compare gas type with type 2=Travel
	bra		gaslist_metric_non_travel	; Non-Travel Gas
gaslist_strcat_depth_travel:			; Show "---" instead of "0m"...
	STRCAT	"---"
	return
gaslist_metric_non_travel:
	output_99
	STRCAT_TEXT	tMeters					; "m"
	return

;----------------------------------------------------------------------------
; Store current menu item, and display gas description later.
; Input: PRODL : gas number (0..4)
; NOTE: used in the menu-tree for the MENU_CALLBACK entry.

	global	gaslist_setgas
gaslist_setgas:
	movff	PRODL,gaslist_gas
	movlw	.5
	btfsc	ccr_diluent_setup			; in CCR menus?
	addwf	gaslist_gas,F				; Yes, offset to gases 5-9
	return


	global	gaslist_cleanup_list		; Takes care that only one gas can be first and first has 0m change depth
gaslist_cleanup_list:
	bcf		ignore_last_edited_gas
	movlw	.0
	btfsc	ccr_diluent_setup			; In CCR-Menu?
	addlw	.5							; Yes, adjust offset
	subwf	gaslist_gas,F
gaslist_cleanup_list1:
	clrf	lo
	lfsr	FSR1,opt_gas_type			; Read opt_gas_type[WREG]
	movlw	.5							; Check 5 gases
	movwf	hi
gaslist_cleanup_list2:
	decf	hi,w						; 0-4
	btfsc	ccr_diluent_setup			; In CCR-Menu?
	addlw	.5							; Yes, adjust offset
	movff	PLUSW1,WREG					; read gas type
	decfsz	WREG						; is gas = first (ex 1)?
	bra		gaslist_cleanup_list3		; NO
	incf	lo,F						; YES - count "first gases"
	btfss	ignore_last_edited_gas		; If we are not in the second-pass mode
	bra		gaslist_cleanup_list2b
	decf	hi,w						; 0-4
	cpfseq	gaslist_gas					; Do not disable last edited gas
gaslist_cleanup_list2b:
	movff	hi,up						; Keep the last "first gas" found
gaslist_cleanup_list3:
	decfsz	hi,F
	bra		gaslist_cleanup_list2		; Loop
	tstfsz	lo							; No gas active?
	bra		gaslist_cleanup_list4		; No, at least one is active
	btfsc	ccr_diluent_setup			; In CCR-Menu?
	bra		gaslist_cleanup_list3a		; Yes.
	; make gas1 first and zero
	movlw	.1							; First
	movwf	up
	movwf	INDF1
	bra	gaslist_cleanup_list5			; Set change depth to zero
gaslist_cleanup_list3a:
	movlw	.5
	addwf	FSR1L,F
	movlw	.0
	addwfc	FSR1H,F						; Setup to Diluents
	; make dil1 first and zero
	movlw	.1							; First
	movwf	up
	movwf	INDF1
	bra		gaslist_cleanup_list5		; Set change depth to zero
gaslist_cleanup_list4:
	movlw	.1
	cpfsgt	lo							; More then one "first gas"?
	bra		gaslist_cleanup_list5		; No, done.
	; More then one Gas is "first gas"
	; Disable last found "first gas" but keep it's change depth
	decf	up,W						; 0-4
	cpfseq	gaslist_gas					; Do not disable last edited gas
	bra		gaslist_cleanup_list4b
	; Do not disable last edited gas
	; search again but ignore last edited gas
	bsf		ignore_last_edited_gas
	bra		gaslist_cleanup_list1		; Loop until only one "first gas" is left
gaslist_cleanup_list4b:
	btfsc	ccr_diluent_setup			; In CCR-Menu?
	addlw	.5							; Yes, adjust offset
	clrf	PLUSW1						; Disable gas
	bra		gaslist_cleanup_list		; Loop until only one "first gas" is left
gaslist_cleanup_list5:
	; Read switch depth
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents-5
	btfss	ccr_diluent_setup			; In CCR-Menu?
	lfsr	FSR1,opt_OC_bail_gas_change	; No, setup OC Gases
	decf	up,W
	btfsc	ccr_diluent_setup			; In CCR-Menu?
	addlw	.5							; Yes, adjust offset
	clrf	PLUSW1						; Set First gas to zero m
	return

;----------------------------------------------------------------------------
; Increment/Decrement O2 ratio

	global	gaslist_pO2
gaslist_pO2:
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_He_ratio		; Read opt_gas_He_ratio[WREG]
	movff	PLUSW1,hi					; hi holds He ratio
	lfsr	FSR1,opt_gas_O2_ratio		; Read opt_gas_O2_ratio[WREG]
	movff	PLUSW1,lo					; lo holds O2 ratio

	incf	lo,F						; O2++
	movf	hi,W						; get He ratio into WREG
	addwf	lo,W						; add O2 ratio to WREG
	movwf	up							; move sum He + O2 to up
	movlw	.101						;
	cpfslt	up							; O2 + He < 101?
	decf	lo,F						; O2-- (revoke ++)
	movf	gaslist_gas,W
	movff	lo,PLUSW1					; write back O2 ratio to opt_gas_O2_ratio[WREG]
	return

	global	gaslist_mO2
gaslist_mO2:
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_O2_ratio		; Read opt_gas_O2_ratio[WREG]
	movff	PLUSW1,lo					; lo holds O2 ratio

	decf	lo,F						; O2--
	movlw	gaslist_min_o2				; get minimum allowed O2 ratio
	cpfslt	lo							; current O2 ratio below allowed minimum?
	bra		gaslist_mO2_1				; NO
	movlw	gaslist_min_o2				; YES - load minimum
	movwf	lo							;       write minimum to current O2 ratio
gaslist_mO2_1:
	movf	gaslist_gas,W
	movff	lo,PLUSW1					; write back O2 ratio to opt_gas_O2_ratio[WREG]
	return

;----------------------------------------------------------------------------
; Increment/Decrement He ratio

	global	gaslist_pHe
gaslist_pHe:
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_O2_ratio		; Read opt_gas_O2_ratio[WREG]
	movff	PLUSW1,lo					; lo holds O2 ratio
	lfsr	FSR1,opt_gas_He_ratio		; Read opt_gas_He_ratio[WREG]
	movff	PLUSW1,hi					; hi holds He ratio

	incf	hi,F						; He++
	movf	hi,W						; get He ratio into WREG
	addwf	lo,W						; add O2 ratio to WREG
	movwf	up							; move sum He + O2 to up
	movlw	.101						;
	cpfslt	up							; O2 + He < 101?
	decf	hi,F						; He-- (revoke ++)
	movf	gaslist_gas,W
	movff	hi,PLUSW1					; write back He ratio to opt_gas_He_ratio[WREG]
	return

	global	gaslist_mHe
gaslist_mHe:
	movf	gaslist_gas,W
	lfsr	FSR1,opt_gas_He_ratio		; Read opt_gas_He_ratio[WREG]
	movff	PLUSW1,hi					; hi holds He ratio

	decf	hi,F						; He--
	bnn		gaslist_mHe_1				; He ratio negative?
	clrf	hi							; YES - set He to 0
gaslist_mHe_1:
	movf	gaslist_gas,W
	movff	hi,PLUSW1					; write back He ratio to opt_gas_He_ratio[WREG]
	return

;----------------------------------------------------------------------------
; Increment/Decrement switch depth

	global	gaslist_pDepth
gaslist_pDepth:
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents-5
	movlw	.4
	cpfsgt	gaslist_gas					; >4? (-> Diluents)
	lfsr	FSR1,opt_OC_bail_gas_change	; Setup OC Gases
	movf	gaslist_gas,W
	movff	PLUSW1,lo					; Read char_I_deco_gas_change[WREG]
	incf	lo,F
	movlw	gaslist_max_change_depth
	cpfsgt	lo
	bra		gaslist_pDepth_1
	movlw	gaslist_max_change_depth
	movwf	lo
gaslist_pDepth_1:
	movf	gaslist_gas,W
	movff	lo,PLUSW1					; Write back to char_I_deco_gas_change[WREG]
	return

	global	gaslist_mDepth
gaslist_mDepth:
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents-5
	movlw	.4
	cpfsgt	gaslist_gas					; >4? (-> Diluents)
	lfsr	FSR1,opt_OC_bail_gas_change	; Setup OC Gases

	movf	gaslist_gas,W
	movff	PLUSW1,lo					; Read char_I_deco_gas_change[WREG]

	decf	lo,F
	btfsc	STATUS,N
	clrf	lo

	movf	gaslist_gas,W
	movff	lo,PLUSW1					; And write back to char_I_deco_gas_change[WREG]
	return

	global	gaslist_spplus
gaslist_spplus:
	movf	gaslist_gas,W
	lfsr	FSR1,char_I_setpoint_cbar
	movff	PLUSW1,lo					; Read char_I_setpoint_cbar[WREG]
	movlw	gaslist_sp_stepsize
	addwf	lo,F
	movlw	gaslist_sp_max
	cpfsgt	lo
	bra		gaslist_spplus2
	movlw	gaslist_sp_min
	movwf	lo
gaslist_spplus2:
	movf	gaslist_gas,W
	movff	lo,PLUSW1					; Write back to char_I_setpoint_cbar
	return

	global	gaslist_spdepthplus
gaslist_spdepthplus:
	movf	gaslist_gas,W
	bz		gaslist_spdepthplus3		; Setpoint 1 is always 0m
	lfsr	FSR1,char_I_setpoint_change
	movff	PLUSW1,lo					; Read char_I_deco_gas_change[WREG]
	incf	lo,F
	movlw	gaslist_max_change_depth
	cpfsgt	lo
	bra		gaslist_spdepthplus_1
	movlw	gaslist_max_change_depth
	movwf	lo
gaslist_spdepthplus_1:
	movf	gaslist_gas,W
	movff	lo,PLUSW1					; Write back to char_I_deco_gas_change[WREG]
	return

gaslist_spdepthplus3:
	movlw	.0
	movff	WREG,char_I_setpoint_change+0	; Reset to 0m
	return

	global	gaslist_spdepthminus
gaslist_spdepthminus:
	movf	gaslist_gas,W
	bz		gaslist_spdepthplus3		; Setpoint 1 is always 0m
	lfsr	FSR1,char_I_setpoint_change
	movff	PLUSW1,lo					; Read char_I_deco_gas_change[WREG]
	decf	lo,F
	btfsc	STATUS,N
	clrf	lo
	movf	gaslist_gas,W
	movff	lo,PLUSW1					; Write back to char_I_deco_gas_change[WREG]
	return

;----------------------------------------------------------------------------
; Compute MOD from char_I_ppO2_max/char_I_ppO2_max_deco and current O2 Ratio.
;
; Input:  gaslist_gas                   = current gas index.
;         opt_gas_O2_ratio[gaslist_gas] = current O2 ratio
; Output: WREG                          = MOD [m]
;
gaslist_calc_mod:
	movf	gaslist_gas,W				; get gas number (0...5)
	lfsr	FSR1,opt_gas_O2_ratio		; read opt_gas_O2_ratio[WREG]
	movf	PLUSW1,W

	btfsc	divemode					; in divemode?
	bra		gaslist_calc_mod_divemode	; YES

	; Pamb max = ppO2 Max / O2 ratio
	movwf	xB+0

	movf	gaslist_gas,W				; get gas number (0...5)
	lfsr	FSR1,opt_gas_type			; 0=Disabled, 1=First, 2=Travel, 3=Deco for OC gases and 0=Disabled, 1=First, 2=Normal for diluents
	movff	PLUSW1,xA+0					; xA+0 used as temp here -> holds type

	movff	char_I_ppO2_max_deco,xB+1	; xB+1 used as temp here
	movlw	.3
	cpfseq	xA+0						; Deco?
	movff	char_I_ppO2_max,xB+1		; No, overwrite with travel/bottom max
	movf	xB+1,W						; Result in WREG

	clrf	xB+1						; Clear for div16x16
	mullw	.10
	movff	PRODL,xA+0
	movff	PRODH,xA+1
	call	div16x16

	; Prof = Pamb - 1 bar
	movf	xC+0,W
	addlw	-.10
	return

gaslist_calc_mod_divemode:
	movwf	hi							; Copy O2%
	call	TFT_color_code_gaslist		; Color-code current row in Gaslist (%O2 in hi), char_I_ppO2_max/char_I_ppO2_max_deco as threshold
	return

;----------------------------------------------------------------------------

	global	gaslist_ppo2
gaslist_ppo2:
	STRCAT_TEXT tppO2					; ppO2:
	movf	gaslist_gas,W
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents
	btfss	ccr_diluent_setup			; In CCR-Menu?
	lfsr	FSR1,opt_OC_bail_gas_change	; No, setup OC/Bailout Gases
	movf	PLUSW1,W
	mullw	.10							; PROD=Depth in mbar/10 (100 = 1.00 bar)
	movlw	.100
	addwf	PRODL,F
	movlw	.0
	addwfc	PRODH,F						; add 1bar
	movff	PRODL,xA+0
	movff	PRODH,xA+1
	movf	gaslist_gas,W				; Read current gas O2 ratio
	lfsr	FSR1,opt_dil_O2_ratio-.5	; Read dil_gas_O2_ratio[WREG]
	btfss	ccr_diluent_setup			; In CCR-Menu?
	lfsr	FSR1,opt_gas_O2_ratio		; No, read opt_gas_O2_ratio[WREG]
	movff	PLUSW1,xB+0
	clrf	xB+1
	call	mult16x16					; char_I_O2_ratio * (p_amb/10)
	movff	xC+0,xA+0
	movff	xC+1,xA+1
	movlw	d'100'
	movwf	xB+0
	clrf	xB+1
	call	div16x16					; xC=(char_I_O2_ratio * p_amb/10)/100
	; Check very high ppO2 manually
	tstfsz	xC+2						; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar?
	bra		gaslist_ppo2_2				; Yes, display fixed Value!
	movff	xC+0,lo
	movff	xC+1,hi
	bcf		ignore_digit4
	bsf		leftbind
	output_16dp d'3'					; x.xx
	STRCAT_TEXT tbar					; bar
	return
gaslist_ppo2_2:
	STRCAT	">6.6"
	return

	global	gaslist_MOD_END
gaslist_MOD_END:
	rcall	gaslist_calc_mod			; Compute MOD into WREG
	movwf	lo							; Copy to lo
	STRCAT_TEXT tMOD					; MOD:
	TSTOSS	opt_units					; 0=Meters, 1=Feets
	bra		gaslist_MOD_metric
	;gaslist_MOD_imperial:
	movf	lo,W
	mullw	.100						; convert meters to mbar
	movff	PRODL,lo
	movff	PRODH,hi
	call	convert_mbar_to_feet		; convert value in lo:hi from mbar to feet
	bsf		leftbind
	output_16_3							; limit to 999 and display only (0-999)
	STRCAT_TEXT tFeets					; "ft"
	bra		gaslist_MOD_common
gaslist_MOD_metric:
	output_8
	STRCAT_TEXT tMeters					; m
gaslist_MOD_common:
	PUTC	"/"
	STRCAT_TEXT tEND					; END:
	rcall	gaslist_calc_mod			; Output: WREG = MOD [m]
	addlw	.10							; MOD=MOD+10m
	movwf	xB+0
	clrf	xB+1
	movlw	d'100'
	movwf	xA+0
	movf	gaslist_gas,W				; get gas number (0...5)
	lfsr	FSR1,opt_gas_He_ratio		; read opt_gas_O2_ratio[WREG]
	movf	PLUSW1,W					; He value in %
	subwf	xA+0,F						; xA+0 = 100 - He Value in %
	clrf	xA+1
	call	mult16x16					; xA*xB=xC
	movff	xC+0,xA+0
	movff	xC+1,xA+1
	movlw	d'100'
	movwf	xB+0
	clrf	xB+1
	call	div16x16					; xA/xB=xC with xA as remainder
	;									; xC:2 = ((MOD+10) * 100 - HE Value in %) / 100
	movlw	d'10'
	subwf	xC+0,F						; Subtract 10m...
	movff	xC+0,lo
	;; END 8Bit only
	;movlw	d'0'
	;subwfb	xC+1,F
	;movff	xC+1,hi
	TSTOSS	opt_units					; 0=Meter, 1=Feet
	bra		gaslist_END_metric
	;gaslist_END_imperial:
	movf	lo,W
	mullw	.100						; convert meters to mbar
	movff	PRODL,lo
	movff	PRODH,hi
	call	convert_mbar_to_feet		; convert value in lo:hi from mbar to feet
	bsf		leftbind
	output_16_3							; limit to 999 and display only (0-999)
	STRCAT_TEXT tFeets					; "ft"
	return
gaslist_END_metric:
	output_8
	STRCAT_TEXT tMeters					; m
	return

;----------------------------------------------------------------------------
	global	gaslist_reset_mod_title
gaslist_reset_mod_title:
	STRCAT_TEXT tDepthReset

gaslist_reset_mod_title2:
	rcall	gaslist_calc_mod			; Compute MOD into WREG
	movwf	lo							; Copy to lo

	movf	gaslist_gas,W				; Compare to switch depth
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents
	btfss	ccr_diluent_setup			; In CCR-Menu?
	lfsr	FSR1,opt_OC_bail_gas_change	; No, setup OC Gases
	movf	PLUSW1,W
	cpfslt	lo
	bra		gaslist_strcat_5			; and return...
	call	TFT_warnings_color			; turn red if bigger !
	bra		gaslist_strcat_5			; and return...

;----------------------------------------------------------------------------
	global	gaslist_reset_mod
gaslist_reset_mod:
	rcall	gaslist_calc_mod			; Compute MOD, it is returned in WREG
	movwf	lo							; buffer MOD to lo
	movf	gaslist_gas,W				; Read current gas O2 ratio
	lfsr	FSR1,char_I_dil_change-.5	; Setup Diluents
	btfss	ccr_diluent_setup			; In CCR-Menu?
	lfsr	FSR1,opt_OC_bail_gas_change	; NO - setup OC Gases
	movff	lo,PLUSW1					; write back new change depth
	return
;----------------------------------------------------------------------------
	END