diff src/gaslist.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents ca4556fb60b9
children cd58f7fc86db
line wrap: on
line diff
--- a/src/gaslist.asm	Wed Apr 10 10:51:07 2019 +0200
+++ b/src/gaslist.asm	Mon Jun 03 14:01:48 2019 +0200
@@ -1,6 +1,6 @@
 ;=============================================================================
 ;
-;   File gaslist.asm								REFACTORED VERSION V2.99e
+;   File gaslist.asm                          combined next generation V3.03.2
 ;
 ;   Managing OSTC gas list
 ;
@@ -11,19 +11,16 @@
 
 #include "hwos.inc"						; mandatory header
 #include "convert.inc"
-#include "math.inc"						; div16x16 for MOD calculations
+#include "math.inc"						; div16x16 for MOD calculation
 #include "strings.inc"
 #include "tft.inc"
 #include "tft_outputs.inc"
 #include "shared_definitions.h"
 #include "wait.inc"
+#include "rx_ops.inc"
 
- IFDEF _rx_functions
-#include "rx_ops.inc"
- ENDIF
 
 	extern	convert_mbar_to_feet
-	extern	customview_show_mix
 	extern	tSetup_GasDepth
 	extern	tGasDisabled
 	extern	tDilDisabled
@@ -31,7 +28,10 @@
 	extern	tbar10
 	extern	tbar
 
-gaslist		CODE
+
+gaslist	CODE
+
+;-----------------------------------------------------------------------------
 
 ;=============================================================================
 ; Helper Functions for divemenu_tree.asm
@@ -54,18 +54,24 @@
 	STRCAT_TEXT tDivemenu_ToggleGF
 	return
 
+;=============================================================================
 
  IFDEF _cave_mode
+
 	global	do_turn_dive_label
 do_turn_dive_label:
-	btfss	FLAG_cave_mode				; in cave mode?
+	btfss	cave_mode					; cave mode switched on?
 	call	TFT_disabled_color			; NO  - print in disabled color
-	btfsc	FLAG_dive_turned			; dive already turned?
+	btfsc	dive_turned					; dive already turned?
 	call	TFT_attention_color			; YES - print in attention color
 	STRCAT_TEXT tDivemenu_TurnDive		; output label
 	return
+
  ENDIF
 
+;=============================================================================
+
+ IFDEF _rx_functions
 
 	global	do_toggle_max_pres_diff_label
 do_toggle_max_pres_diff_label:
@@ -79,6 +85,12 @@
 	STRCAT_TEXT	tbar					; " bar"
 	return
 
+ ENDIF
+
+;=============================================================================
+
+ IFDEF _ccr_pscr
+
 	global	gaslist_copy_dil_to_oc
 gaslist_copy_dil_to_oc:
 ;
@@ -93,17 +105,17 @@
 ;  opt_gas_change				res 5
 ;  opt_dil_change				res 5
 ;
-;  char_I_tank_size				res 10
-;  char_I_tank_pres_fill		res 10
+;  char_I_gas_avail_size		res 10
+;  char_I_gas_avail_pres		res 10
 ;
-	bcf		aux_flag					; clear aux_flag by default
+	bcf		copying_dil					; default to copying a gas
 	movf	gaslist_gas,W				; copy current gas or diluent number to WREG
-	btfss	FLAG_diluent_setup			; in CCR menus?
+	btfss	is_diluent_menu				; setting up diluents?
 	bra		gaslist_copy_dil_to_oc_1	; NO  - gaslist_gas is already pointing to an OC gas
 	addlw	-.5							; YES - subtract offset between diluents and gases
 	movwf	gaslist_gas					;     - let gaslist_gas point to the corresponding OC gas
-	bsf		aux_flag					;     - remember we came from a CCR menu
-	bcf		FLAG_diluent_setup			;     - pretend we came from an OC gas menu
+	bsf		copying_dil					;     - we are copying a diluent
+	bcf		is_diluent_menu				;     - pretend we are setting up OC gases
 gaslist_copy_dil_to_oc_1:
 	lfsr	FSR0,opt_dil_O2_ratio		; load base address of diluents settings, ASM variables
 	lfsr	FSR1,opt_gas_O2_ratio		; load base address of gas      settings, ASM variables
@@ -115,21 +127,24 @@
 	addlw	.10							; add offset from type to change depth
 	movff	PLUSW0,PLUSW1				; copy change depth
 	addlw	-.30						; wind back to initial gas number
-	lfsr	FSR0,char_I_tank_size+5		; load base address of diluents settings, shared variables
-	lfsr	FSR1,char_I_tank_size+0		; load base address of gas      settings, shared variables
+	lfsr	FSR0,char_I_gas_avail_size+5; load base address of diluents settings, shared variables
+	lfsr	FSR1,char_I_gas_avail_size+0; load base address of gas      settings, shared variables
 	movff	PLUSW0,PLUSW1				; copy tank size
 	addlw	.10							; add offset from tank sizes to pressure budget
 	movff	PLUSW0,PLUSW1				; copy pressure budget
 	call	gaslist_cleanup_list		; make sure that there will be just one first gas
-	btfss	aux_flag					; did we came from a CCR menu?
+	btfss	copying_dil					; are we copying a diluent?
 	return								; NO  - done
-	bsf		FLAG_diluent_setup			; YES - restore proper origin again
+	bsf		is_diluent_menu				; YES - restore to be setting up diluents
 	movlw	.5							;     - offset between OC gases and diluents
 	addwf	gaslist_gas,F				;     - let gaslist_gas point to the diluent again
 	WIN_BOX_BLACK .30,.239,.0,.159		;     - create some visual effect to show activity
 	WAITMS	.200						;     - pause for 200 ms
 	return								;     - done
 
+ ENDIF
+
+;=============================================================================
 
 ;=============================================================================
 ; Append gas description to current string
@@ -140,10 +155,10 @@
 
 	global	gaslist_strcat_gas
 	global	gaslist_strcat_gas_WREG
-gaslist_strcat_gas:						; entry point with gas/dil in PRODL (0-4) and FLAG_diluent_setup
+gaslist_strcat_gas:						; entry point with gas/dil in PRODL (0-4) and flag 'is_diluent_menu' set accordingly
 	movff	PRODL,gaslist_gas			; get current menu item (0-4)
 	movlw	.5							; offset between gases and diluents
-	btfsc	FLAG_diluent_setup			; in CCR menus?
+	btfsc	is_diluent_menu				; setting up diluents?
 	addwf	gaslist_gas,F				; YES - add the offset
 	movf	gaslist_gas,W				; copy to WREG
 gaslist_strcat_gas_WREG:				; entry point with gas/dil in WREG (0-9)
@@ -151,23 +166,30 @@
 	movff	PLUSW1,lo					; read O2 ratio
 	lfsr	FSR1,opt_gas_He_ratio		; load base address of opt_gas_He_ratio
 	movff	PLUSW1,hi					; read He ratio
-	goto	customview_show_mix			; put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and RETURN
+	goto	gaslist_show_mix			; put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and RETURN
+
 
 ;=============================================================================
-; Append current mix to current string (for divemode)
+; Append current mix to current string (for dive mode)
 ;
 ; 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	": "
+	STRCAT_TEXT tGas					; print "Gas"
+	STRCAT	": "						; print ":"
 	movff	gas6_O2_ratio,hi			; TFT_color_code_gaslist needs O2 ratio in hi
 	call	TFT_color_code_gaslist		; color-code according to O2 ratio and depth
-	movff	gas6_O2_ratio,lo			; customview_show_mix needs O2 ratio in lo
-	movff	gas6_He_ratio,hi			;                   ... and He ratio in hi
-	goto	customview_show_mix			; put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and return
+	movff	gas6_O2_ratio,lo			; gaslist_show_mix needs O2 ratio in lo
+ IFDEF _helium
+	movff	gas6_He_ratio,hi			;                ... and He ratio in hi
+ ELSE
+	clrf	hi							;                ... and He ration will be zero
+ ENDIF
+	goto	gaslist_show_mix			; put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and return
+
+
 ;=============================================================================
 ; Helper functions for menu_tree
 
@@ -184,6 +206,7 @@
 	STRCAT_TEXT tSetup_GasDepth
 	return
 
+
 	global	gaslist_show_type
 gaslist_show_type:
 	movf	gaslist_gas,W
@@ -191,7 +214,7 @@
 	movff	PLUSW1,lo					; read gas type
 	STRCAT_TEXT tType
 	lfsr	FSR1,tGasDisabled			; load base address of gas type labels
-	btfsc	FLAG_diluent_setup			; in CCR setup?
+	btfsc	is_diluent_menu				; setting up diluents?
 	lfsr	FSR1,tDilDisabled			; YES - load base address of diluent type labels
 	movff	lo,WREG						; 0-3
 	rlncf	WREG						; x2
@@ -208,7 +231,7 @@
 	lfsr	FSR1,opt_gas_type			; load base address of opt_gas_type
 	movff	PLUSW1,lo					; read gas type
 	incf	lo,F						; increment type
-	btfsc	FLAG_diluent_setup			; in CCR setup?
+	btfsc	is_diluent_menu				; setting up diluents?
 	bra		gaslist_toggle_type2		; YES - diluents
 	btfsc	lo,2						; NO  - gases, type index > 3 ?
 	clrf	lo							;       YES - clear to zero
@@ -222,6 +245,9 @@
 	movff	lo,PLUSW1					; copy back result
 	return
 
+;=============================================================================
+
+ IFDEF _ccr_pscr
 
 	global	gaslist_strcat_setpoint
 	global	gaslist_strcat_setpoint_0
@@ -229,7 +255,7 @@
 	movff	PRODL,gaslist_gas			; get current menu item (0-4)
 gaslist_strcat_setpoint_0:				; entry point with setpoint index in gaslist_gas
 	bsf		leftbind
-	btfsc	short_gas_decriptions		; shall use short versions of gaslist_strcat_setpoint?
+	btfsc	short_gas_descriptions		; shall use short versions of gaslist_strcat_setpoint?
 	bra		gaslist_strcat_setpoint2	; YES - use short version
 	STRCAT_TEXT tSP						; "SP"
 	incf	gaslist_gas,W				; (0-4) -> (1-5) into WREG
@@ -239,7 +265,7 @@
 	PUTC	":"
 gaslist_strcat_setpoint2:				; short version
 	btfsc	divemode
-	bra		gaslist_strcat_setpoint4	; no "*" in divemode
+	bra		gaslist_strcat_setpoint4	; no "*" in dive mode
 	movf	gaslist_gas,W				; (0-4) into WREG
 	bnz		gaslist_strcat_setpoint3	; SP index = 0 ?
 	PUTC	"*"							; YES - print *
@@ -248,22 +274,23 @@
 	PUTC	" "							;     - print a space
 gaslist_strcat_setpoint4:
 	movf	gaslist_gas,W				; (0-4) into WREG
-	lfsr	FSR1,char_I_setpoint_cbar	; load base address of setpoint cbar values
+	lfsr	FSR1,opt_setpoint_cbar		; load base address of setpoint cbar values
 	movf	PLUSW1,W					; read cbar value
 	movwf	lo
 	clrf	hi
 	bsf		leftbind
 	output_16dp d'3'					; print as X.XX
-	btfsc	divemode					; in divemode?
-	bra		gaslist_strcat_setpoint5	; YES - skip text in divemode
+	btfsc	divemode					; in dive mode?
+	bra		gaslist_strcat_setpoint5	; YES - skip text in dive mode
 	STRCAT_TEXT tbar					; NO  - print "bar"
 gaslist_strcat_setpoint5:
 	PUTC	" "							; print a space
 	movf	gaslist_gas,W				; (0-4) into WREG
-	lfsr	FSR1,char_I_setpoint_change	; load base address of switch depths
+	lfsr	FSR1,opt_setpoint_change	; load base address of switch depths
 	movff	PLUSW1,lo					; read switch depth into lo
 	bra		gaslist_strcat_depth		; print depth in meters or ft
 
+ ENDIF	; _ccr_pscr
 
 ;----------------------------------------------------------------------------
 ; Append gas description to current string
@@ -279,14 +306,14 @@
 
 	global	gaslist_strcat_gas_cd
 	global	gaslist_gastitle
-gaslist_strcat_gas_cd:					; entry point with gas in PRODL (0-4) and usage of FLAG_diluent_setup
+gaslist_strcat_gas_cd:					; entry point with gas in PRODL (0-4) and flag 'is_diluent_menu' set accordingly
 	movff	PRODL,gaslist_gas			; get current menu item (0-4)
 	movlw	.5							; offset between gases and diluents
-	btfsc	FLAG_diluent_setup			; in diluent menus?
+	btfsc	is_diluent_menu				; setting up diluents?
 	addwf	gaslist_gas,F				; YES - add the offset
 gaslist_gastitle:						; entry point with gas/dil in gaslist_gas (0-4 for gases, 5-9 for diluents)
 	bcf		win_invert					; clear flag for inverted output by default
-	btfsc	short_gas_decriptions		; shall use short versions of gaslist_strcat_gas_cd?
+	btfsc	short_gas_descriptions		; shall use short versions of gaslist_strcat_gas_cd?
 	bra		gaslist_gastitle1			; YES - use short version
 	incf	gaslist_gas,W				; (0-9) -> (1-10) into WREG
 	movwf	lo
@@ -305,11 +332,11 @@
 	bcf		leftbind
 	PUTC	":"
 gaslist_gastitle1:						; short version of gaslist_strcat_gas_cd
-	btfsc	divemode					; in divemode?
+	btfsc	divemode					; in dive mode?
 	bra		gaslist_gastitle3			; YES - no "*" and "=" in front of gas composition, no highlighting for transmitters paired
 
  IFDEF _rx_functions
-	btfss	FLAG_tr_enabled				; NO  - TR functions enabled?
+	btfss	tr_functions_activated		; NO  - TR functions activated?
 	bra		gaslist_gastitle2			;       NO  - continue with gas type
 	lfsr	FSR1,opt_transmitter_id_1	;       YES - load base address of transmitter ID table
 	movf	gaslist_gas,W				;           - (0-4 for OC/Bailout, 5-9 for Diluents)
@@ -325,7 +352,7 @@
 	rcall	gaslist_strcat_gas_type		; print "*" for first gas/dil, "=" for a deco gas or " " else
 gaslist_gastitle3:
 	call	TFT_standard_color
-	btfsc	divemode					; in divemode?
+	btfsc	divemode					; in dive mode?
 	rcall	gaslist_strcat_gas_better	; YES - check if this is a "better gas"
 	lfsr	FSR1,opt_gas_type			; load base address of gas types
 	movf	gaslist_gas,W				; load index into WREG (0-4 for gases, 5-9 for diluents)
@@ -334,8 +361,8 @@
 	call	TFT_disabled_color			;                  YES - switch color to disabled
 	bra		gaslist_gastitle5			;                      - skip ppO2 check for disabled gases
 gaslist_gastitle4:
-	btfss	divemode					; in divemode?
-	bra		gaslist_gastitle5			; NO  - no ppO2 check if not in divemode
+	btfss	divemode					; in dive mode?
+	bra		gaslist_gastitle5			; NO  - no ppO2 check if not in dive mode
 	lfsr	FSR1,opt_gas_O2_ratio		; YES - load base address of opt_gas_O2_ratio
 	movf	gaslist_gas,W				;     - load index into WREG (0-4 for gases, 5-9 for diluents)
 	movff	PLUSW1,hi					;     - read O2 ratio into hi
@@ -343,7 +370,7 @@
 gaslist_gastitle5:
 	movf	gaslist_gas,W				; copy gas/dil index to WREG (0-9)
 	rcall	gaslist_strcat_gas_WREG		; print gas composition
-	btfss	divemode					; in divemode?
+	btfss	divemode					; in dive mode?
 	bra		gaslist_gastitle6			; NO  - continue printing a space
 	rcall	gaslist_strcat_gas_type		; YES - print "*" for first gas/dil, "=" for a deco gas, or a space else
 	bra		gaslist_gastitle7			;     - continue with change depth
@@ -362,28 +389,33 @@
 	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					; append "ft"	REMARK: still one char to long for space available in divemode menu!
+	STRCAT_TEXT tFeets					; append "ft"	REMARK: still one char to long for space available in dive mode menu!
 	return
 gaslist_strcat_depth_metric:
-	PUTC	" "							; print a space
-	output_99
+;	PUTC	" "							; print a space
+;	output_99
+	output_8
 	STRCAT_TEXT tMeters					; "m"
 	return
 
+
+; check for better gas
+;
 gaslist_strcat_gas_better:				; color-code output if this is the best gas/diluent
 	btfss	better_gas_hint				; shall better gas hints be given?
 	return								; NO - return
 	movf	best_gas_number,W			; get best gas number into WREG
-	btfsc	FLAG_diluent_setup			; in CCR (pSCR) menus?
+ IFDEF _ccr_pscr
+	btfsc	is_diluent_menu				; setting up diluents?
 	movf	best_dil_number,W			; YES - overwrite with best diluent number
+ ENDIF
 	tstfsz	WREG						; is a best gas/dil available?
 	bra		gaslist_strcat_gas_better1	; YES - proceed
 	return								; NO  - return
 gaslist_strcat_gas_better1:
 	decf	WREG,W						; (1-5) -> (0-4)
-	btfsc	FLAG_diluent_setup			; in diluent menus?
+	btfsc	is_diluent_menu				; setting up diluents?
 	addlw	.5							; YES - add offset between gases and diluents (0-4) -> (5-9)
 	cpfseq	gaslist_gas					; compare with given gas/dil (0-4 for OC bailout gases, 5-9 for diluents)
 	return								; not equal - return
@@ -391,6 +423,7 @@
 	movlw	color_green					;           - select green color (gas is something "good")
 	goto	TFT_set_color				;           - activate color and return
 
+
 gaslist_strcat_gas_type:
 	lfsr	FSR1,opt_gas_type			; load base address of gas types
 	movf	gaslist_gas,W				; load index to WREG (0-4 for gases, 5-9 for diluents)
@@ -409,6 +442,7 @@
 	PUTC	" "							; neither first nor deco, print a space
 	return
 
+
 ;----------------------------------------------------------------------------
 ; Housekeeping for the gas/dil settings, e.g. making sure there is one FIRST only
 ;
@@ -417,9 +451,11 @@
 	global	gaslist_cleanup_list
 gaslist_cleanup_list:
 	lfsr	FSR1,opt_gas_type			; load base address of opt_gas_type
+ IFDEF _ccr_pscr
 	movlw	.5							; offset between gases and diluents
-	btfsc	FLAG_diluent_setup			; in CCR-Menu?
+	btfsc	is_diluent_menu				; setting up diluents?
 	subwf	gaslist_gas,F				; YES - subtract offset from gaslist_gas: (5-9) -> (0-4)
+ ENDIF
 gaslist_cleanup_list0:
 	bcf		ignore_last_edited_gas
 gaslist_cleanup_list1:
@@ -428,8 +464,10 @@
 	movwf	hi
 gaslist_cleanup_list2:					; loop body
 	decf	hi,W						; WREG = current gas/dil (0-4)
-	btfsc	FLAG_diluent_setup			; in CCR-Menu?
+ IFDEF _ccr_pscr
+	btfsc	is_diluent_menu				; setting up diluents?
 	addlw	.5							; YES - add offset from gases to diluents -> (5-9)
+ ENDIF
 	movff	PLUSW1,WREG					; read type into WREG
 	decfsz	WREG						; is type = first (ex type code 1)?
 	bra		gaslist_cleanup_list3		; NO  - done with this gas/dil
@@ -441,17 +479,20 @@
 gaslist_cleanup_list2b:
 	movff	hi,up						;             (NO) - remember the last "first gas" found
 gaslist_cleanup_list3:
-	decfsz	hi,F						; decrement loop counter
-	bra		gaslist_cleanup_list2		; loop counter became 0 ? NO  - loop
-	tstfsz	lo							;                         YES - any first gas/dil at all?
-	bra		gaslist_cleanup_list4		;                               YES - at least one first gas/dil existing
-	btfsc	FLAG_diluent_setup			;                               NO  - in CCR-Menu?
-	lfsr	FSR1,opt_dil_type			;                                     YES - load base address of opt_gas_type
-	movlw	.1							;                                   - load coding for first gas
-	movwf	INDF1						;                                   - make gas/dil 1 the first gas
-	return								;                                   - done
+	decfsz	hi,F						; decrement loop counter, did loop counter became 0?
+	bra		gaslist_cleanup_list2		; NO  - loop
+	tstfsz	lo							; YES - any first gas/dil at all?
+	bra		gaslist_cleanup_list4		;       YES - at least one first gas/dil existing
+ IFDEF _ccr_pscr
+	btfsc	is_diluent_menu				;       NO  - setting up diluents?
+	lfsr	FSR1,opt_dil_type			;             YES - load base address of opt_gas_type
+ ENDIF
+	movlw	.1							;           - load coding for first gas
+	movwf	INDF1						;           - make gas/dil 1 the first gas
+	bsf		option_repaired				;           - flag that an option was repaired
+	return								;           - done
 gaslist_cleanup_list4:
-	movlw	.1
+	movlw	.1							; total number of Firsts that should exist is 1
 	cpfsgt	lo							; more then one "first gas" found?
 	return								; NO  - done
 	decf	up,W						; YES - WREG = last found "first gas" - 1 (0-4)
@@ -460,25 +501,29 @@
 	bsf		ignore_last_edited_gas		;       YES - do not disable last edited gas, search again but ignore the last edited gas
 	bra		gaslist_cleanup_list1		;           - loop until only one "first" is left over
 gaslist_cleanup_list4b:
-	btfsc	FLAG_diluent_setup			; in CCR-Menu?
+ IFDEF _ccr_pscr
+	btfsc	is_diluent_menu				; setting up diluents?
 	addlw	.5							; YES - adjust offset
+ ENDIF
 	clrf	PLUSW1						; disable gas
+	bsf		option_repaired				; flag that an option was repaired
 	bra		gaslist_cleanup_list0		; redo from start until only one "first" is left over
 	return
 
+
 ;----------------------------------------------------------------------------
 ; Tank Settings
 ;
-; Inputs: char_I_tank_size       size of the tank,                     using unit text tLiter ("l")
-;         char_I_tank_pres_fill  fill pressure in multiples of 10 bar, using unit text tbar10 ("0 bar")
+; Input: char_I_gas_avail_size   size of the tank in liters
+;        char_I_gas_avail_pres   available pressure in multiples of 10 bar
 
 	global	gaslist_tank_size_pres
 gaslist_tank_size_pres:					; dynamic title: xx l, xx0 bar
-	lfsr	FSR1,char_I_tank_size		; load base address of char_I_tank_size
+	lfsr	FSR1,char_I_gas_avail_size	; load base address of char_I_gas_avail_size
 	movf	gaslist_gas,W				; load index (0-9)
-	movff	PLUSW1,lo					; read char_I_tank_size[WREG] into lo
-	lfsr	FSR1,char_I_tank_pres_fill	; load base address of char_I_tank_pres_fill
-	movff	PLUSW1,hi					; read char_I_tank_pres_fill[WREG] into hi
+	movff	PLUSW1,lo					; read char_I_gas_avail_size[WREG] into lo
+	lfsr	FSR1,char_I_gas_avail_pres	; load base address of char_I_gas_avail_pres
+	movff	PLUSW1,hi					; read char_I_gas_avail_pres[WREG] into hi
 	STRCAT	"     "						; print 5 leading spaces for alignment
 	output_8							; print tank size
 	STRCAT_TEXT tLiter					; print unit (" l")
@@ -487,11 +532,12 @@
 	STRCAT_TEXT tbar10					; print unit ("0 bar")
 	return
 
+
 	global	gaslist_tank_size
-gaslist_tank_size:						; adjust char_I_tank_size between min_tank_size and max_tank_size
-	lfsr	FSR1,char_I_tank_size		; load base address of char_I_tank_size
+gaslist_tank_size:						; adjust char_I_gas_avail_size between min_tank_size and max_tank_size
+	lfsr	FSR1,char_I_gas_avail_size	; load base address of char_I_gas_avail_size
 	movf	gaslist_gas,W				; load index (0-9)
-	movff	PLUSW1,lo					; read char_I_tank_size[WREG] into lo
+	movff	PLUSW1,lo					; read char_I_gas_avail_size[WREG] into lo
 	incf	lo,F						; increment tank size by 1 liter
 	movlw	max_tank_size				; load max. allowed value into WREG
 	cpfsgt	lo							; tank size <= max value?
@@ -500,14 +546,15 @@
 	movwf	lo							;     - and write to lo
 gaslist_tank_size_1:
 	movf	gaslist_gas,W				; re-load index
-	movff	lo,PLUSW1					; write back tank size to char_I_tank_size[WREG]
+	movff	lo,PLUSW1					; write back tank size to char_I_gas_avail_size[WREG]
 	return
 
+
 	global	gaslist_tank_pres
-gaslist_tank_pres:						; adjust char_I_tank_pres_fill between 5(0) and 29(0) bar
-	lfsr	FSR1,char_I_tank_pres_fill	; load base address of char_I_tank_pres_fill
+gaslist_tank_pres:						; adjust char_I_gas_avail_pres between 5(0) and 29(0) bar
+	lfsr	FSR1,char_I_gas_avail_pres	; load base address of char_I_gas_avail_pres
 	movf	gaslist_gas,W				; load index (0-9)
-	movff	PLUSW1,lo					; read char_I_tank_pres_fill[WREG] into lo
+	movff	PLUSW1,lo					; read char_I_gas_avail_pres[WREG] into lo
 	incf	lo,F						; increment fill press by by 1(0) bar
 	movlw	max_fill_press				; load max. allowed value into WREG
 	cpfsgt	lo							; press <= max value?
@@ -516,14 +563,16 @@
 	movwf	lo							;     - and write to lo
 gaslist_tank_pres_1:
 	movf	gaslist_gas,W				; re-load index
-	movff	lo,PLUSW1					; write back tank size to char_I_tank_pres_fill[WREG]
+	movff	lo,PLUSW1					; write back tank size to char_I_gas_avail_pres[WREG]
 	return
 
-;----------------------------------------------------------------------------
-; Transmitter functions
+
+;=============================================================================
 
  IFDEF _rx_functions
 
+; Transmitter functions - ID
+;
 	global	gaslist_tank_id_pres
 gaslist_tank_id_pres:					; dynamic title: shows ID and pressure from transmitter with ID opt_transmitter_id[gaslist_gas]
 										;                When changing layout, adapt output position TFT_menu_tank_pres!
@@ -540,20 +589,20 @@
 	bra		gaslist_tank_id_pres_1		; YES - a transmitter is paired to the tank
 	tstfsz	lo							; low  byte of ID <> 0 ?
 	bra		gaslist_tank_id_pres_1		; YES - a transmitter is paired to the tank
-	; no transmitter paired
-	STRCAT	"----"						;
-	bcf		menu_update_tank_pres		; stop imprinting of tank pressure updates
-	return
-gaslist_tank_id_pres_1:
-	; show ID
-	movf	hi,W						; copy high byte of ID to WREG
-	output_hex							; print it
-	movf	lo,W						; copy low  byte of ID to WREG
-	output_hex							; print it
-	bsf		menu_update_tank_pres		; start imprinting of tank pressure updates
-	return
+	STRCAT	"----"						; NO  - no transmitter paired
+	bcf		imprint_xmitter_pres		;     - stop imprinting of transmitter pressure data
+	return								;     - done
+gaslist_tank_id_pres_1:					; YES - show ID
+	movf	hi,W						;     - copy high byte of ID to WREG
+	output_hex							;     - print it
+	movf	lo,W						;     - copy low  byte of ID to WREG
+	output_hex							;     - print it
+	bsf		imprint_xmitter_pres		;     - start imprinting of transmitter pressure data
+	return								;     - done
 
 
+; Transmitter functions - Pairing
+;
 	global	gaslist_tank_pairing
 gaslist_tank_pairing:
 	incf	pairing_slot,F				; goto next RX data slot
@@ -582,9 +631,14 @@
 
  ENDIF
 
+;=============================================================================
+
 ;----------------------------------------------------------------------------
-; Increment/Decrement O2 ratio
+; Helper Functions for Menu Operations
+
 
+; Increment O2 ratio
+;
 	global	gaslist_pO2
 gaslist_pO2:
 	movf	gaslist_gas,W				; load index (0-9)
@@ -595,7 +649,7 @@
 
 	incf	lo,F						; O2++
 	movf	hi,W						; get He ratio into WREG
-	addwf	lo,W						; add O2 ratio to WREG
+	addwf	lo,W						; add O2 ratio to   WREG
 	movwf	up							; move sum He + O2 to up
 	movlw	.101						;
 	cpfslt	up							; O2 + He < 101?
@@ -604,6 +658,9 @@
 	movff	lo,PLUSW1					; write back O2 ratio to opt_gas_O2_ratio[WREG]
 	return
 
+
+; Decrement O2 ratio
+;
 	global	gaslist_mO2
 gaslist_mO2:
 	movf	gaslist_gas,W				; load index (0-9)
@@ -620,9 +677,12 @@
 	movff	lo,PLUSW1					; write back O2 ratio to opt_gas_O2_ratio[WREG]
 	return
 
-;----------------------------------------------------------------------------
-; Increment/Decrement He ratio
+;=============================================================================
 
+ IFDEF _helium
+
+; Increment He ratio
+;
 	global	gaslist_pHe
 gaslist_pHe:
 	movf	gaslist_gas,W				; load index (0-9)
@@ -642,6 +702,8 @@
 	movff	hi,PLUSW1					; write back He ratio to opt_gas_He_ratio[WREG]
 	return
 
+; Decrement He ratio
+;
 	global	gaslist_mHe
 gaslist_mHe:
 	movf	gaslist_gas,W				; load index (0-9)
@@ -656,9 +718,12 @@
 	movff	hi,PLUSW1					; write back He ratio to opt_gas_He_ratio[WREG]
 	return
 
-;----------------------------------------------------------------------------
-; Increment/Decrement switch depth
+ ENDIF	; _helium
 
+;=============================================================================
+
+; Increment switch depth
+;
 	global	gaslist_pDepth
 gaslist_pDepth:
 	lfsr	FSR1,opt_gas_change			; load base address of opt_gas_change
@@ -674,6 +739,9 @@
 	movff	lo,PLUSW1					; write back switch depth
 	return
 
+
+; Decrement switch depth
+;
 	global	gaslist_mDepth
 gaslist_mDepth:
 	lfsr	FSR1,opt_gas_change			; load base address of opt_gas_change
@@ -685,10 +753,16 @@
 	movff	lo,PLUSW1					; write back switch depth
 	return
 
+;=============================================================================
+
+ IFDEF _ccr_pscr
+
+; Increment setpoint
+;
 	global	gaslist_spplus
 gaslist_spplus:
 	movf	gaslist_gas,W
-	lfsr	FSR1,char_I_setpoint_cbar
+	lfsr	FSR1,opt_setpoint_cbar
 	movff	PLUSW1,lo					; read setpoint
 	movlw	gaslist_sp_stepsize
 	addwf	lo,F
@@ -702,11 +776,14 @@
 	movff	lo,PLUSW1					; write back setpoint
 	return
 
+
+; Increment setpoint switch depth
+;
 	global	gaslist_spdepthplus
 gaslist_spdepthplus:
 	movf	gaslist_gas,W				; get setpoint number (0-4)
 	bz		gaslist_spdepthplus2		; setpoint number = 0? YES - force depth to always be 0m
-	lfsr	FSR1,char_I_setpoint_change	; load base address of char_I_setpoint_change
+	lfsr	FSR1,opt_setpoint_change	; load base address of opt_setpoint_change
 	movff	PLUSW1,lo					; read setpoint depth into lo
 	incf	lo,F						; increment depth
 	movlw	gaslist_max_change_depth	; get max. depth
@@ -718,11 +795,14 @@
 	movff	lo,PLUSW1					; write back setpoint depth
 	return
 
+
+; Decrement set point switch depth
+;
 	global	gaslist_spdepthminus
 gaslist_spdepthminus:
 	movf	gaslist_gas,W				; get setpoint number (0-4)
 	bz		gaslist_spdepthminus2		; setpoint number = 0? YES - force depth to always be 0m
-	lfsr	FSR1,char_I_setpoint_change	; load base address of char_I_setpoint_change
+	lfsr	FSR1,opt_setpoint_change	; load base address of opt_setpoint_change
 	movff	PLUSW1,lo					; read setpoint depth into lo
 	decf	lo,F						; decrement switch depth
 	btfsc	STATUS,N					; did depth became negative?
@@ -730,15 +810,22 @@
 	movff	lo,PLUSW1					; write back setpoint depth
 	return
 
+
+; helper for increment/decrement setpoint switch depth
+;
 gaslist_spdepthplus2:
 gaslist_spdepthminus2:
 	movlw	.0
-	movff	WREG,char_I_setpoint_change+0	; hard reset to 0m
+	movff	WREG,opt_setpoint_change+0; hard reset to 0m
 	return
 
+ ENDIF	; _ccr_pscr
+
+;=============================================================================
+
 
 ;----------------------------------------------------------------------------
-; Compute MOD from char_I_ppO2_max/char_I_ppO2_max_deco and current O2 ratio
+; Compute MOD from char_I_ppO2_max_work/char_I_ppO2_max_deco and current O2 ratio
 ;
 ; Input:  gaslist_gas                   = current gas index.
 ;         opt_gas_O2_ratio[gaslist_gas] = current O2 ratio
@@ -749,23 +836,24 @@
 	lfsr	FSR1,opt_gas_O2_ratio		; load base address of opt_gas_O2_ratio
 	movff	PLUSW1,xB+0					; read O2 ratio into xB+0
 	lfsr	FSR1,opt_gas_type			; load base address of opt_gas_type
-	movff	PLUSW1,xA+0					; read gas/dil type into xA+0 (used as temp here)
+	movff	PLUSW1,xA+0					; read gas/dil type into xA+0     (used as temp here)
 	movff	char_I_ppO2_max_deco,xB+1	; get max ppO2 for deco into xB+1 (used as temp here)
 	movlw	.3							; type code for deco gases
 	cpfseq	xA+0						; is it a deco gas?
-	movff	char_I_ppO2_max,xB+1		; NO - overwrite ppO2 max with none-deco max
+	movff	char_I_ppO2_max_work,xB+1	; NO - overwrite ppO2 max with working phase max
 	movf	xB+1,W						; copy resulting ppO2 max into WREG
 	clrf	xB+1						; clear xB+1 for div16x16 operation
 	mullw	.10							; multiply ppO2 max value with 10
-	movff	PRODL,xA+0					; copy result to xA
-	movff	PRODH,xA+1
+	MOVII	PROD,xA						; copy result to xA
 	call	div16x16					; xC = xA / xB with xA as remainder
-	movf	xC+0,W						; copy result to WREG
+	movf	xC+0,W						; copy   low  byte of the result to WREG
 	addlw	-.10						; subtract 10 cbar
-	return								; return with final result in WREG
+	return								; return with final result [in meters] in WREG
 
 ;----------------------------------------------------------------------------
 
+; print ppO2 as x.xx for gas/diluent in gaslist_gas (0-9)
+;
 	global	gaslist_ppo2
 gaslist_ppo2:
 	STRCAT_TEXT tppO2					; ppO2:
@@ -773,19 +861,14 @@
 	movf	gaslist_gas,W				; load index (0-9)
 	movf	PLUSW1,W					; read change depth into WREG
 	mullw	.10							; PROD = depth in mbar/10 (100 = 1.00 bar)
-	movlw	.100						; add 1 bar
-	addwf	PRODL,F
-	movlw	.0
-	addwfc	PRODH,F
-	movff	PRODL,xA+0					; copy result to xA
-	movff	PRODH,xA+1
+	ADDLI	.100,PROD					; add 1 bar
+	MOVII	PROD,xA						; copy result to xA
 	lfsr	FSR1,opt_gas_O2_ratio		; load base address of opt_gas_O2_ratio
 	movf	gaslist_gas,W				; load index (0-9)
 	movff	PLUSW1,xB+0					; read O2 ratio into xB+0
 	clrf	xB+1						; clear xB+1
 	call	mult16x16					; calculate char_I_O2_ratio * (p_amb/10)
-	movff	xC+0,xA+0					; copy result to xA
-	movff	xC+1,xA+1
+	MOVII	xC,xA						; copy result to xA
 	movlw	d'100'						; load 100 to xB
 	movwf	xB+0
 	clrf	xB+1
@@ -793,8 +876,7 @@
 	; check for very high ppO2
 	tstfsz	xC+2						; xC+2 remains from mult16x16, xC+2 > 0 (-> ppO2 is > 6.55 bar) ?
 	bra		gaslist_ppo2_1				; YES - display a fixed max value
-	movff	xC+0,lo						; copy result to lo, hi
-	movff	xC+1,hi
+	MOVII	xC,mpr						; copy result to hi:lo
 	bcf		ignore_digit4
 	bsf		leftbind
 	output_16dp d'3'					; print ppO2 as x.xx
@@ -804,6 +886,9 @@
 	STRCAT	">6.6"
 	return
 
+
+; print MOD and END for gas in gaslist_gas (0-9)
+;
 	global	gaslist_MOD_END
 gaslist_MOD_END:
 	STRCAT_TEXT tMOD					; print "MOD:"
@@ -824,8 +909,7 @@
 	subwf	xA+0,F						; xA+0 = 100 - He ratio in %
 	clrf	xA+1
 	call	mult16x16					; xA*xB=xC
-	movff	xC+0,xA+0
-	movff	xC+1,xA+1
+	MOVII	xC,xA
 	movlw	d'100'
 	movwf	xB+0
 	clrf	xB+1
@@ -837,6 +921,8 @@
 	bra		gaslist_strcat_depth		; print depth in meters or feet as configured and return
 
 
+; print change depth of gas in gaslist_gas (0-9), use warning color if > MOD
+;
 	global	gaslist_reset_mod_title
 gaslist_reset_mod_title:
 	STRCAT_TEXT tDepthReset
@@ -847,10 +933,12 @@
 	movf	PLUSW1,W					; read change depth into WREG
 	cpfslt	lo							; change depth > MOD ?
 	bra		gaslist_strcat_depth		; NO  - return
-	call	TFT_warnings_color			; YES - use red color
+	call	TFT_warning_color			; YES - use red color
 	bra		gaslist_strcat_depth		;     - return
 
 
+; set change depth of gas in gaslist_gas (0-9) to its MOD
+;
 	global	gaslist_reset_mod
 gaslist_reset_mod:
 	rcall	gaslist_calc_mod			; compute MOD into WREG
@@ -861,4 +949,54 @@
 	return
 
 ;----------------------------------------------------------------------------
+; put "Nxlo", "Txlo/hi", "Air" or "O2" into postinc2
+;
+; Includes capability to show trimix gases to be able to properly decode data
+; from logbook in case trimix dives are stored on an OSTC running the sport FW.
+
+	global	gaslist_show_mix
+gaslist_show_mix:
+	tstfsz	hi							; He=0?
+	bra		gaslist_show_mix5			; NO - show a TX
+	movlw	.21
+	cpfseq	lo							; Air?
+	bra		gaslist_show_mix2			; NO
+	STRCAT_TEXT tSelectAir				; YES - show "Air"
+	bra		gaslist_show_mix4b
+gaslist_show_mix2:
+	movlw	.100
+	cpfseq	lo							; O2?
+	bra		gaslist_show_mix3			; NO
+	STRCAT_TEXT tSelectO2				; YES - show "O2"
+	bra		gaslist_show_mix4b
+gaslist_show_mix3:
+	movlw	.21
+	cpfslt	lo							; < Nx21?
+	bra		gaslist_show_mix4			; NO
+	STRCAT_TEXT tGasErr					; YES - show "Err"
+	output_99							; O2 ratio is still in "lo"
+	bra		gaslist_show_mix4c
+gaslist_show_mix4:
+	STRCAT_TEXT tSelectNx				; show "Nx"
+	output_99							; O2 ratio is still in "lo"
+gaslist_show_mix4b:
+	STRCAT	" "
+gaslist_show_mix4c:
+	btfsc	divemode					; in dive mode?
+	return								; YES
+	STRCAT	"  "
+	return
+gaslist_show_mix5:
+	btfsc	divemode
+	bra		gaslist_show_mix6
+	STRCAT_TEXT tSelectTx				; show "Tx"
+gaslist_show_mix6:
+	output_99							; O2 ratio is still in "lo"
+	PUTC	"/"
+	movff	hi,lo
+	output_99							; He ratio
+	return
+
+;-----------------------------------------------------------------------------
+
 	END