diff src/logbook.asm @ 634:4050675965ea

3.10 stable release
author heinrichsweikamp
date Tue, 28 Apr 2020 17:34:31 +0200
parents 185ba2f91f59
children 8c1f1f334275
line wrap: on
line diff
--- a/src/logbook.asm	Thu Mar 05 15:06:14 2020 +0100
+++ b/src/logbook.asm	Tue Apr 28 17:34:31 2020 +0200
@@ -1,6 +1,6 @@
 ;=============================================================================
 ;
-;   File logbook.asm                          combined next generation V3.08.8
+;   File logbook.asm                        * combined next generation V3.09.5
 ;
 ;   Logbook
 ;
@@ -26,16 +26,17 @@
 #include "divemode.inc"
 #include "ghostwriter.inc"
 #include "rtc.inc"
+#include "gaslist.inc"
+#include "colorschemes.inc"
 
 #DEFINE inside_loogbook
 #include "logbook.inc"
 
 
-	extern	do_main_menu2
-	extern	gaslist_show_mix
+	extern	main_menu
 
 
-;---- Private local variables ------------------------------------------------
+;---- Private local Variables ------------------------------------------------
 
 	CBLOCK	local1						; max size is 16 byte !!!
 		count_temperature				; current sample count for temperature divisor
@@ -85,10 +86,7 @@
 	ENDC								; used: 16 byte, remaining: 0 byte => full
 
 
-	; Remarks: The variable gaslist_gas is "misused" here as a local variable,
-	;          because the storage space for local variables is fully used up.
-	;
-	;          This code includes decoding and displaying of log data for Trimix
+	; Remark:  This code includes decoding and displaying of log data for Trimix
 	;          and CCR/pSCR dives to make sure that if such dives are in the
 	;          logbook they will be displayed correctly.
 
@@ -192,16 +190,19 @@
 #DEFINE MBAR_column					log2_salinity_column
 
 
+;=============================================================================
 logbook		CODE
-
 ;=============================================================================
 
+;-----------------------------------------------------------------------------
+; Helper Function - show the Cursor
+;
 TFT_logbook_cursor:
 	WIN_BOX_BLACK .0, .239, logbook_list_left-.8, logbook_list_left-.1    ; top, bottom, left, right
 
 	WIN_LEFT logbook_list_left-.8					; set horizontal position
-	WIN_FONT FT_SMALL								; select small font
-	call	TFT_standard_color						; print in white color
+	FONT_SIZE  FT_SMALL								; set font size
+	FONT_COLOR_MEMO									; set font color
 	decf	menu_pos_cur,W							; get row number -1 into WREG
 	mullw	logbook_row_offset						; multiply with vertical offset between rows
 	movff	PRODL,win_top							; set vertical position
@@ -209,17 +210,19 @@
 	return											; done
 
 
-	global	logbook									; entry point coming from menu_tree.asm
+;-----------------------------------------------------------------------------
+; Entry Point coming from Surface Menu
+;
+	global	logbook
 logbook:
-	call	TFT_boot
-;	call	TFT_standard_color
+	call	TFT_boot								; initialize display
 
 	clrf	logbook_flags							; clear all flags
 	clrf	menu_pos_max							; clear number of used rows on current page
-	clrf	logbook_page_number						; here: # of current displayed page
-	clrf	logbook_divenumber						; # of dive in list during search
-	clrf	logbook_temp
-	clrf	logbook_temp_backup
+	clrf	logbook_page_number						; clear # of current displayed page
+	clrf	logbook_divenumber						; clear # of dive in list during search
+	clrf	logbook_temp							; clear temps
+	clrf	logbook_temp_backup						; ...
 
 	movlw	logbook_row_number						; get number of dive entry rows per list
 	movwf	menu_pos_cur							; initialize cursor position to last entry
@@ -229,14 +232,13 @@
 	movwf	logbook_max_dive_counter				; copy to logbook_max_dive_counter
 	movwf	total_num_dives							; copy to total_num_dives, too
 
+logbook2:
 
-;-----------------------------------------------------------------------------
-; display dive headers backwards from latest dive to first dive, stop when
-; - no dive is stored                (no valid header found)
-; - current dive has no valid header (past last dive, < 256 dives)
-; - when 255 dives are reached       (logbook display limit)
+	; display dive headers backwards from latest dive to first dive,
+	; stop when - no dive is stored                (no valid header found)
+	;           - current dive has no valid header (past last dive, < 256 dives)
+	;           - 255 dives are reached            (logbook display limit)
 
-logbook2:
 	incf	logbook_temp,F							; increase dive counter
 	incf	logbook_temp,W							; = 0x..FF ?
 	bz		logbook_reset							; YES - loop
@@ -244,12 +246,10 @@
 	; compute index for dive to show / goto previous dive
 	decf	logbook_max_dive_counter,F
 
-	; compute the start address of the header of the dive to show
-	movf	logbook_max_dive_counter,W				; hand over index in WREG
-	call	log_header_addr_by_index				; compute address of header start
-
 	; copy the first 22 byte of the header from FLASH to memory
-	FLASH_RR_READ mpr,header_buffer,.22
+	movf	logbook_max_dive_counter,W				; hand over header index in WREG
+	call	log_header_addr_by_index				; compute start address of the header
+	FLASH_RR_READ header_buffer,.22					; copy first 22 bytes of header from FLASH to memory
 
 	; check if there is a header
 	MOVCC	header_buffer+index_header_start,WREG	; read first byte of header
@@ -275,7 +275,7 @@
 logbook4:
 	btfsc	all_dives_shown							; all dives shown?
 	bra		logbook_display_loop2					; YES - page done
-	call	display_listdive						; NO  - display short header for list on current list position
+	call	display_listdive						; NO  - display dive summery on current list position
 	movlw	logbook_row_number						;     - load max number of lines
 	cpfseq	menu_pos_cur							;     - cursor on last line (exit)?
 	bra		logbook_display_loop1					;       NO - skip saving of address
@@ -337,7 +337,7 @@
 exit_logbook:
 	bcf		switch_right							; clear pending button events
 	bcf		switch_left								; ...
-	goto	do_main_menu2							; jump-back to main menu (in menu_tree.asm)
+	goto	main_menu								; jump-back to main menu (in menu_tree.asm)
 
 display_profile_or_next:
 	movlw	logbook_row_number+.1					; get menu line were the next page item is
@@ -345,8 +345,9 @@
 	bra		display_profile							; NO  - show profile of selected dive
 	goto	next_logbook2							; YES - show next page
 
+
 ;-----------------------------------------------------------------------------
-; show graphical dive profile
+; show graphical Dive Profile
 ;
 display_profile:
 	bcf		bailout_mode							; clear event flag
@@ -361,11 +362,9 @@
 	addwf	menu_pos_cur,W							; add number of selected dive on current page page
 	movwf	divenumber								; result is the number of the dive to show
 
-	; compute the header address by the dive number
-	call	log_header_addr_by_divenumber
-
-	; copy the complete header from FLASH to memory
-	FLASH_RR_READ mpr,header_buffer,.256
+	; copy header from FLASH into memory 
+	call	log_header_addr_by_divenumber			; compute header start address from the dive number
+	FLASH_RR_READ header_buffer,.256				; copy complete header from FLASH to memory
 
 	; read the sampling rate
 	MOVCC	header_buffer+index_samplingrate,sampling_rate
@@ -373,8 +372,8 @@
 	; --- start drawing the dive profile page ---
 
 display_profile2:
-	call	TFT_boot
-	call	TFT_standard_color
+	call	TFT_boot								; initialize display
+	FONT_COLOR_MEMO									; set font color
 
 	; show dive number
 	call	logbook_show_divenumber					; show the dive number in medium font
@@ -382,13 +381,13 @@
 	; show date
 	WIN_SMALL logbook_date_column, logbook_date_row
 	MOVTT	header_buffer+index_date,mpr			; read date
-	call	TFT_convert_date						; converts into "DD/MM/YY" or "MM/DD/YY" or "YY/MM/DD" in postinc2
-	STRCAT_PRINT ""
+	call	output_date								; print date
+	PRINT											; dump to screen
 
 	; show dive mode
 	WIN_SMALL log_divetime_mins_value_column,logbook_date_row	; align with surrounding data
 	MOVCC	header_buffer+index_divemode,lo			; read dive type (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR)
-	call	TFT_decotype_logbook					; "strcat_print"s dive mode (OC, CC, Gauge, Apnea or pSCR)
+	call	TFT_print_decotype						; print deco mode (OC, CC, Gauge, Apnea or pSCR)
 													; also sets aux_flag in case the dive was done in a deco mode
 
 	; show time
@@ -398,12 +397,14 @@
 	PUTC	':'										; print spacing ":"
 	movff	hi,lo									; print minute
 	output_99x										; ...
-	STRCAT_PRINT ""									; display 1st row of details
+	PRINT											; print buffer as 1st row of details to screen
 
 	; get log format version
 	MOVCC	header_buffer+index_profile_version,lo	; read profile format version
-	movlw	0x24
-	cpfslt	lo										; < 0x24 ?
+	movlw	b'00111111'								; load mask for external part of the profile version
+	andwf	lo,F									; keep only the external part
+	movlw	0x24									; recorded external version < 0x24
+	cpfslt	lo										; ... ?
 	bra		log_skip_extra_icon						; YES -  skip end of dive icon
 
 	; print end of dive icon
@@ -470,31 +471,29 @@
 
 display_profile_offset4_imperial:
 	call	convert_cm_to_feet						; convert value in mpr from [cm] to [feet]
-	PUTC	' '
-	bcf		leftbind
-	output_16_3										; limit to 999 and display only (0-999)
-	STRCAT_TEXT_PRINT tFeets
-	bra		display_profile_offset4_common
+	PUTC	' '										; append a space
+	output_999										; print depth (0-999)
+	STRCAT_TEXT_PRINT tFeets						; append unit and dump to screen
+	bra		display_profile_offset4_common			; continue
 
 display_profile_offset4_metric:
-	bsf		ignore_digit5							; no cm...
-	movlw	d'1'									; no 1000 m
-	movwf	ignore_digits							; ...
-	output_16dp d'3'								; xxx.y
-	STRCAT_TEXT_PRINT tMeters
-	;bra	display_profile_offset4_common
+	bsf		omit_digit_1							; do not print 1st digit (no cm)
+	bsf		decimal_digit2							; place a decimal point in front of digit 2
+	output_65535									; print depth (0.0x-655.3x)
+	STRCAT_TEXT_PRINT tMeters						; append unit and dump to screen
+	;bra	display_profile_offset4_common			; continue
 
 display_profile_offset4_common:
 	WIN_SMALL log_divetime_mins_value_column,log_divetime_mins_value_row
-	bsf		leftbind
 
 	; show dive time minutes : seconds
 	MOVTT	header_buffer+index_divetime,mpr		; get   dive time
-	output_16										; print dive time minutes
+	bsf		leftbind								; print left-aligned
+	output_9999										; print dive time minutes (0-9999)
 	PUTC	'm'										; print "m" (minutes)
 	movff	up,lo									; print dive time seconds
 	output_99x										; dive time seconds
-	STRCAT_PRINT "s"								; print "s" (seconds)
+	PUTC_PRINT "s"									; append unit (seconds) and dump buffer to screen
 
 	; get minimum temperature (for later use)
 	MOVII	header_buffer+index_min_temp,logbook_min_tp
@@ -544,76 +543,80 @@
 	movwf	backup_color1							; keep copy of color for later restore
 	call	TFT_color_code_gas						; set color
 
+	; initialize flag for signaling when last sample set was read
+	bcf		end_of_profile
+
 	; set ext_flash_address to the begin of the profile data
 	MOVTT	header_buffer+index_profile_start_address,ext_flash_address
 
-	; skip the 0xFA 0xFA header of the profile data
-	ext_flash_inc_address_0x20 d'2'
+	; header start code sequence present?
+	FLASH_CW_READ_0x20								; get the 1st byte
+	xorlw	0xFA									; 1st byte = header start byte?
+	bnz		display_profile_no_profile_jump			; NO  - no profile data available, abort
 
-	; initialize flag for signaling when last sample set was read
-	bcf		end_of_profile
+	FLASH_CW_READ_0x20								; get the 2nd byte
+	xorlw	0xFA									; 2nd byte = header start byte?
+	bnz		display_profile_no_profile_jump			; NO  - no profile data available, abort
 
 	; check if the profile actually belongs to this dive (check done with low bytes only)
-	FLASH_CC_READ_0x20 lo								; read dive  number in profile
+	FLASH_CC_READ_0x20 lo							; read dive number in profile
 	incf	total_num_dives,W						; WREG = total number of dives + 1
 	bsf		STATUS,C								; set borrow
 	subfwb	divenumber,W							; WREG = total number of dives - number of dive to show - 1
 	cpfseq	lo										; number of dive in profile = number of dive to show?
+display_profile_no_profile_jump:
 	bra		display_profile_no_profile				; NO  - no profile data for this dive available
 	;bra	display_profile_show_profile			; YES - show profile
 
 display_profile_show_profile:
 
 	; skip high byte of dive number          1 byte
-	; skip second header code                2 byte
+	; skip second part of header start code  2 byte
 	; skip length of profile data            3 byte
-	; skip sampling rate in profile section  1 byte
+	; skip sampling rate in profile data     1 byte
 	; skip number of divisors                1 byte
 	;                                        ======
 	;        total number of bytes to skip = 8 byte
-	ext_flash_inc_address_0x20 d'8'
+
+	EXT_FLASH_INC_ADDRESS_0x20 d'8'					; skip next 8 bytes
 
 	; read divisor temp
-	ext_flash_inc_address_0x20 d'2'					; skip information type and length
-	FLASH_CW_READ_0x20								; read  temperature divisor
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip information type and length
+	FLASH_CW_READ_0x20								; read  temperature divisor into WREG
 	movwf	divisor_temperature						; store temperature divisor
 	movwf	count_temperature						; store to temperature counter, too
 
 	; read divisor deco
-	ext_flash_inc_address_0x20 d'2'					; skip information type and length
-	FLASH_CW_READ_0x20								; read  deco divisor
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip information type and length
+	FLASH_CW_READ_0x20								; read  deco divisor into WREG
 	movwf	divisor_deco							; store deco divisor
 	movwf	count_deco								; store to deco status counter, too
 
 	; read divisor GF
-	ext_flash_inc_address_0x20 d'2'					; skip information type and length
-	FLASH_CC_READ_0x20 divisor_gf						; store saturation divisor
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip information type and length
+	FLASH_CC_READ_0x20 divisor_gf					; store saturation divisor
 
 	; read divisor ppO2 sensors
-	ext_flash_inc_address_0x20 d'2'					; skip information type and length
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip information type and length
 	FLASH_CC_READ_0x20 divisor_ppo2_sensors			; store ppO2 divisor
 
 	; read divisor deco plan
-	ext_flash_inc_address_0x20 d'2'					; skip information type and length
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip information type and length
 	FLASH_CC_READ_0x20 divisor_decoplan				; store deco plan divisor
 
 	; read divisor CNS
-	ext_flash_inc_address_0x20 d'2'					; skip information type and length
-	FLASH_CC_READ_0x20 divisor_cns						; store CNS divisor
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip information type and length
+	FLASH_CC_READ_0x20 divisor_cns					; store CNS divisor
 
 	; read divisor tank data
-	ext_flash_inc_address_0x20 d'2'					; skip information type and length
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip information type and length
 	FLASH_CC_READ_0x20 divisor_tank					; store tank pressure divisor
 
-
-	; start drawing the profile
-
-	; set color
-	movlw	color_deepblue
-	call	TFT_set_color
+	;---- start drawing the profile ----------------
 
 	; draw a frame around profile area
-	WIN_FRAME_COLOR16 profile_top-1,profile_top+profile_height_pixels+1,profile_left-1,profile_left+profile_width_pixels+1
+	movlw	color_deepblue							; select color
+	WIN_FRAME_COLOR profile_top-1,profile_top+profile_height_pixels+1,profile_left-1,profile_left+profile_width_pixels+1
 
 	; draw depth grid
 	movlw	profile_top								; set top  position of plot area
@@ -627,7 +630,7 @@
 	clrf	win_width+1								; ...
 	bra		display_profile2_loline					; do not draw the 0 m line
 display_profile2_loop:
-	call	TFT_box									; draw the line
+	BOX												; draw the line
 display_profile2_loline:
 	movf	win_top,W								; get last row drawn
 	addwf	x_scale+0,W								; add line interval distance, low byte
@@ -641,9 +644,9 @@
 	bra		display_profile2_loop					; NO - draw the line
 
 	; do various initializations for drawing the curves
-	clrf	gaslist_gas								; here: used as counter for depth readings
-	movlw	profile_width_pixels+profile_left-.1
-	movwf	ignore_digits							; here: used as counter for x-pixels
+	clrf	ul										; clear counter for depth readings
+	movlw	profile_width_pixels+profile_left-.1	; load loop counter
+	movwf	ex										; ...
 
 	movlw	profile_left+.1
 	movwf	logbook_pixel_x_pos						; here: used as column x2 (start at column 5)
@@ -653,9 +656,9 @@
 	movwf	logbook_last_tp							; initialize for temperature curve, too
 
 	movlw	LOW(-.100)								; initialize max temperature to -10.0 °C
-	movwf	logbook_max_tp+0
-	movlw	HIGH 0xFFFF & (-.100)
-	movwf	logbook_max_tp+1
+	movwf	logbook_max_tp+0						; ...
+	movlw	HIGH 0xFFFF & (-.100)					; ...
+	movwf	logbook_max_tp+1						; ...
 
 	setf	logbook_cur_tp+0						; initialize temperature to 0xFFFF = 'no data'
 	setf	logbook_cur_tp+1						; ...
@@ -680,7 +683,8 @@
 
 ;	INIT_PIXEL_WRITE logbook_pixel_x_pos			; pixel x2 (also sets standard color!)
 
-	; start profile plotting loop
+	;---- start profile plotting loop --------------
+
 	CLRI	logbook_sample_counter					; clear counter for amount of samples read so far
 
 profile_display_loop:
@@ -701,8 +705,7 @@
 	btfsc	end_of_profile							; end of profile data reached?
 	bra		profile_display_loop_done				; YES - skip all remaining pixels
 
-
-	;---- draw ceiling curve, if any ---------------------------------------------
+	;---- draw ceiling curve, if any ---------------
 
 	movf	divisor_deco,W							; get divisor, deco data logged?
 	bz		profile_display_skip_deco				; NO - skip
@@ -729,7 +732,7 @@
 
 profile_display_skip_deco:
 
-	;---- draw temperature curve, if any ---------------------------------------------
+	;---- draw temperature curve, if any -----------
 
 	movf	divisor_temperature,W					; get divisor, deco data logged?
 	bz		profile_display_skip_temp				; NO - skip
@@ -766,7 +769,7 @@
 	movff	xC+1,xC+0
 
 	movlw	color_orange							; select color for temperature curve
-	call	TFT_set_color							; set color
+	call	TFT_set_color							; set    color
 
 	movf	logbook_last_tp,W						; do we have a valid previous value?
 	bz		profile_display_temp_1					; NO  - skip the vertical line
@@ -785,7 +788,7 @@
 
 profile_display_skip_temp:
 
-	;---- draw depth curve ---------------------------------------------------
+	;---- draw depth curve -------------------------
 
 	MOVII	y_scale,          xB					; divide pressure in mbar/pixel for row offset
 	MOVII	logbook_cur_depth,xA					; get current depth
@@ -796,7 +799,8 @@
 	movff	fill_between_rows,xC+0					; YES - ignore
 
 	movf	backup_color1,W							; copy gas number to WREG for color-coding
-	call	TFT_color_code_gas						; set color
+	call	TFT_color_code_gas						; get color for gas
+	call	TFT_set_color							; set drawing color
 
 	movff	fill_between_rows,xC+1					; set position
 	call	profile_display_fill					; in this column between this row (xC+0) and the last row (xC+1)
@@ -805,7 +809,7 @@
 	PIXEL_WRITE logbook_pixel_x_pos,xC+0			; draw a pixel
 	incf	logbook_pixel_x_pos,F					; advance to next column
 
-	;---- draw marker square, if any -----------------------------------------
+	;---- draw marker square, if any ---------------
 
 	btfss	log_marker_found						; any marker to draw?
 	bra		profile_display_skip_marker				; NO  - skip
@@ -828,11 +832,10 @@
 	movwf	win_leftx2
 
 	; print marker
-	movlw	color_orange
-	call	TFT_set_color
-	WIN_FONT FT_TINY
-	lfsr	FSR2,buffer
-	STRCPY_PRINT "m"
+	FONT_COLOR color_orange							; set font color
+	FONT_SIZE FT_TINY								; set font size
+	INIT_BUFFER										; initialize output buffer
+	STRCPY_PRINT "m"								; print a "m" (marker)
 
 	movlw	profile_left
 	movwf	win_leftx2
@@ -848,7 +851,7 @@
 
 profile_display_skip_marker:
 
-	;---- draw CNS curve, if any ---------------------------------------------
+	;---- draw CNS curve, if any -------------------
 
 	movf	divisor_cns,W							; get divisor, CNS logged?
 	bz		profile_display_skip_cns				; NO - skip
@@ -858,7 +861,7 @@
 
 profile_display_skip_cns:
 
-	;---- draw saturation curve, if any --------------------------------------
+	;---- draw saturation curve, if any ------------
 
 	movf	divisor_gf,W							; get divisor, saturation logged?
 	bz		profile_display_skip_gf					; NO - skip
@@ -868,9 +871,7 @@
 
 profile_display_skip_gf:
 
-	; all curves done
-	bra		profile_display_skip_loop1
-
+	;---- all curves done --------------------------
 
 profile_display_skip_loop1:
 	dcfsnz	profile_temp2+0,F						; decrement low byte of x-scaler, became zero?
@@ -883,26 +884,24 @@
 profile_display_loop3:
 	decfsz	profile_temp2+1,F						; decrement high byte of x-scaler, became zero?
 	bra		profile_display_skip_loop1				; NO  - continue
-	decfsz	ignore_digits,F							; YES - count drown x-pixels to zero, became zero?
+	decfsz	ex,F									; YES - count drown x-pixels to zero, became zero?
 	bra		profile_display_loop					;       NO  - draw next sample
 	bra		profile_display_loop_done				;       YES - done
 
 profile_display_loop_done:
 	btfss	bailout_mode							; bailout during the dive?
 	bra		profile_display_gas6					; NO  - skip next
-	movlw	color_pink								; YES - show "Bailout" in pink color
-	call	TFT_set_color							;     - ...
-	WIN_TINY logbook_bailout_column,logbook_bailout_row;  - ...
-	STRCPY_TEXT_PRINT tDiveBailout					;     - print text
+	FONT_COLOR color_pink							; YES - select pink color
+	WIN_TINY logbook_bailout_column,logbook_bailout_row;  - select font and position
+	STRCPY_TEXT_PRINT tDiveBailout					;     - print "Bailout" and dump to screen
 
 profile_display_gas6:
 	btfss	event_gas_change_gas6					; did a change to gas 6 occurred?
 	bra		profile_display_temperatures			; NO  - skip next
-	movlw	color_pink								; YES - select color
-	call	TFT_set_color							;     - set color
+	FONT_COLOR color_pink							; YES - select color
 	WIN_TINY logbook_bailout_column,logbook_bailout_row-.15
 	STRCPY_TEXT tGas								;     - print "Gas"
-	STRCAT_PRINT " 6!"								;     - print " 6!"
+	STRCAT_PRINT " 6!"								;     - append " 6!" and dump to screen
 
 profile_display_temperatures:
 	movff	logbook_min_temp_pos,win_top			; get Y position at lowest temperature
@@ -910,12 +909,10 @@
 	movlw	.130									; left border limit
 	cpfslt	win_leftx2								; too far to the left?
 	movwf	win_leftx2								; YES - set to limit
-	WIN_FONT FT_TINY								; select font
-	movlw	color_yellow							; select color
-	call	TFT_set_color							; set    color
+	FONT_SIZE FT_TINY								; set font size
+	FONT_COLOR color_yellow							; set font color
 
 	MOVII	logbook_min_tp,mpr						; get min temperature
-	lfsr	FSR2,buffer								; initialize string buffer
 
 	TSTOSS	opt_units								; 0=°C, 1=°F
 	bra		logbook_show_temp_metric				; 0 - do Celsius
@@ -923,66 +920,59 @@
 
 logbook_show_temp_imperial:
 	; min temperature
-	call	TFT_convert_signed_16bit				; convert lo:hi into signed-short and add '-' to POSTINC2 if required
-	call	convert_celsius_to_fahrenheit			; convert value in lo:hi from Celsius to Fahrenheit
-	lfsr	FSR2,buffer								; overwrite "-"
-	bsf		ignore_digit5							; full degrees only
-	output_16
-	STRCAT_TEXT_PRINT tLogTunitF
+	rcall	logbook_show_temp_imperial_out			; print temperature
 	; max temperature
-	movlw	.15
-	subwf	logbook_max_temp_pos,W
+	movlw	.15										; set position
+	subwf	logbook_max_temp_pos,W					; ...
 	movwf	win_top									; Y position at max temperature
-	MOVII	logbook_max_tp,mpr
-	lfsr	FSR2,buffer
-	call	TFT_convert_signed_16bit				; converts lo:hi into signed-short and adds '-' to POSTINC2 if required
-	call	convert_celsius_to_fahrenheit			; convert value in lo:hi from Celsius to Fahrenheit
-	output_16
-	bcf		ignore_digit5
-	STRCAT_TEXT_PRINT tLogTunitF
-	bra		logbook_show_gases
+	MOVII	logbook_max_tp,mpr						; get max temperature
+	rcall	logbook_show_temp_imperial_out			; print temperature
+	bra		logbook_show_gases						; continue
 
 logbook_show_temp_metric:
 	; min temperature
-	call	TFT_convert_signed_16bit				; convert lo:hi into signed-short and add '-' to POSTINC2 if required
-	movlw	d'3'
-	movwf	ignore_digits
-	bsf		leftbind
-	output_16dp d'2'								; temperature
-	STRCAT_TEXT_PRINT tLogTunitC
+	rcall	logbook_show_temp_metric_out			; print temperature
 	; max temperature
-	movlw	.15
-	subwf	logbook_max_temp_pos,W
+	movlw	.15										; set position
+	subwf	logbook_max_temp_pos,W					; ...
 	movwf	win_top									; Y position at max temperature
-	MOVII	logbook_max_tp,mpr
-	lfsr	FSR2,buffer
-	call	TFT_convert_signed_16bit				; converts lo:hi into signed-short and adds '-' to POSTINC2 if required
-	movlw	d'3'
-	movwf	ignore_digits
-	bsf		leftbind
-	output_16dp d'2'								; temperature
-	STRCAT_TEXT_PRINT tLogTunitC
-	bra		logbook_show_gases
+	MOVII	logbook_max_tp,mpr						; get max  temperature
+	rcall	logbook_show_temp_metric_out			; print temperature
+	bra		logbook_show_gases						; continue
+
+logbook_show_temp_imperial_out:
+	INIT_BUFFER										; initialize output buffer
+	call	convert_celsius_to_fahrenheit			; convert value in lo:hi from Celsius to Fahrenheit
+	bsf		leftbind								; print left-aligned
+	bsf		omit_digit_1							; full degrees only
+	output_9999										; print temperature (0x-999x)
+	STRCAT_TEXT_PRINT tLogTunitF					; add unit and dump to screen
+	return											; done
+
+logbook_show_temp_metric_out:
+	INIT_BUFFER										; initialize output buffer
+	call	convert_signed_16bit					; convert lo:hi into unsigned-short and add '-' to POSTINC2 if required
+	bsf		leftbind								; print left-aligned
+	bsf		decimal_digit1							; place a decimal point in front of the 1st digit
+	output_999										; print temperature (0.0-99.9)
+	STRCAT_TEXT_PRINT tLogTunitC					; add unit and dump to screen
+	return											; done
 
 
 display_profile_no_profile:
-	; print message "No Data anymore..."
+	; print "no profile anymore..." message
 	WIN_SMALL .4,.110								; set text size and position
-	call	TFT_disabled_color						; use the color for disabled things
+	FONT_COLOR_DISABLED								; use the color for disabled things
 	STRCPY_TEXT_PRINT tNoProfileData				; print message
 
-
 logbook_show_gases:
-	bcf		leftbind
-	call	TFT_standard_color
-
+	FONT_COLOR_MEMO									; back to standard color
 	btfss	aux_flag								; dive done in a deco mode?
 	bra		logbook_show_gases_done					; NO - don't show gases
 
 	; show gases
-	lfsr	FSR0,header_buffer+index_gas1			; load base address of gases
+	lfsr	FSR0,header_buffer+index_gas1			; load base address of the gases
 	bsf		log_show_gas_short						; do the short version of log_show_gas
-	bsf		leftbind
 
 	WIN_TINY log_gas_column1, log_gas_row
 	movlw	.1										; color for gas 1
@@ -1004,10 +994,7 @@
 	movlw	.5										; color for gas 5
 	call	log_show_gas
 
-	bcf		leftbind
-
 logbook_show_gases_done:
-
 	rcall	logbook_preloop_tasks					; clear timeout, some flags and set to Speed_eco
 display_profile_loop:
 	btfsc	switch_right							; right button pressed?
@@ -1018,8 +1005,8 @@
 	bra		display_profile_loop					;           - loop waiting for something to do
 
 
-;=============================================================================
-; Draw a vertical line between xC+1 and xC+0, at current X position
+;-----------------------------------------------------------------------------
+; Helper Function - draw a vertical line between xC+1 and xC+0 at current X position
 ;
 ; Note: should keep xC+0
 ; Note: ascending or descending !
@@ -1064,9 +1051,10 @@
 	bra		profile_display_fill_up
 	return											; fill_between_rows and xC+0 are untouched
 
-;=============================================================================
 
-
+;-----------------------------------------------------------------------------
+; read next Profile Data Set and plot Depth and Temperature
+;
 profile_view_get_depth:
 	INCI	logbook_sample_counter					; count read pixels
 
@@ -1076,14 +1064,14 @@
 	movf	logbook_sample_counter+1,W
 	cpfseq	vertical_interval+1
 	bra		profile_view_get_depth_no_line			; no need to draw a 10min line, continue
-	; draw a new 10min line here...
-	CLRI	logbook_sample_counter					; clear counting registers for next line
+
+	;---- 10 min vertical line ---------------------
 
-	; Vertical lines...
-	movlw	color_deepblue
-	call	TFT_set_color
-	movlw	profile_top+.1
-	movwf	win_top
+	CLRI	logbook_sample_counter					; clear counting registers for next line
+	movlw	color_deepblue							; select color
+	call	TFT_set_color							; set    color
+	movlw	profile_top+.1							; set top position
+	movwf	win_top									; ...
 	incf	logbook_pixel_x_pos,W					; draw one line to right to make sure it's the background of the profile
 	movwf	win_leftx2								; left border (0-159)
 	movlw	profile_height_pixels
@@ -1093,17 +1081,17 @@
 	call	half_horizontal_line					; inputs: win_top, win_leftx2, win_width, win_color1, win_color2
 
 profile_view_get_depth_no_line:
-	FLASH_II_READ_0x20 logbook_cur_depth				; read depth (2 bytes)
-	FLASH_CC_READ_0x20 gaslist_gas						; read Profile Flag Byte
+	FLASH_II_READ_0x20 logbook_cur_depth			; read depth (2 bytes)
+	FLASH_CC_READ_0x20 ul							; read Profile Flag Byte
 
 	bcf		event_occured							; clear flag by default
-	btfsc	gaslist_gas,7							; event recorded?
+	btfsc	ul,7									; event recorded?
 	bsf		event_occured							; YES - we also have an event byte
-	bcf		gaslist_gas,7							; clear event byte flag (if any)
+	bcf		ul,7									; clear event byte flag (if any)
 
-	; gaslist_gas now holds the number of additional bytes to ignore (0-127)
+	; ul now holds the number of additional bytes to ignore (0-127)
 
-	; check for end of profile
+	;---- check for end of profile -----------------
 	movlw	0xFD									; load token for end of profile data
 	cpfseq	logbook_cur_depth+0						; end of profile token in 1st depth byte?
 	bra		profile_view_get_depth_new1				; NO  - profile continues
@@ -1116,14 +1104,15 @@
 	btfsc	event_occured							; was there an event attached to this sample?
 	rcall	profile_view_get_depth_events			; YES - get information about this event(s)
 
-	; read temperature if available AND divisor reached AND bytes available
+	;---- temperature ------------------------------
+
 	movf	divisor_temperature,W					; is temperature divisor null ?
 	bz		profile_view_get_depth_no_tp			; YES - no temperature curve
 	decf	count_temperature,F						; NO  - decrement temperature counter, counter zero now?
 	bnz		profile_view_get_depth_no_tp			;       NO  - no temperature this time
-	FLASH_II_READ_0x20 logbook_cur_tp					;       YES - read temperature (2 bytes)
-	decf	gaslist_gas,F							;           - reduce counter twice
-	decf	gaslist_gas,F							;           - ...
+	FLASH_II_READ_0x20 logbook_cur_tp				;       YES - read temperature (2 bytes)
+	decf	ul,F									;           - reduce counter twice
+	decf	ul,F									;           - ...
 	movff	divisor_temperature,count_temperature	;           - restart counter
 
 	; compute max temperature on the fly...
@@ -1143,37 +1132,41 @@
 profile_view_compute_max_temp:
 	MOVII	logbook_cur_tp,logbook_max_tp			; store new max temperature
 
-	;---- read deco, if any AND divisor=0 AND bytes available ----------------
 profile_view_get_depth_no_tp:
+
+	;---- deco ceiling -----------------------------
+
 	movf	divisor_deco,W
 	bz		profile_view_get_depth_no_deco
 	decf	count_deco,F
 	bnz		profile_view_get_depth_no_deco
 
-	FLASH_CC_READ_0x20 logbook_ceiling					; read the ceiling
-	decf	gaslist_gas,F							; reduce the counter
+	FLASH_CC_READ_0x20 logbook_ceiling				; read the ceiling
+	decf	ul,F									; reduce the counter
 	movff	divisor_deco,count_deco					; restart counter
-	ext_flash_inc_address_0x40 d'1'					; skip the stop duration
-	decf	gaslist_gas,F							; reduce the counter
-
-	;---- read GF, if any AND divisor=0 AND bytes available ------------------
+	EXT_FLASH_INC_ADDRESS_0x20 d'1'					; skip the stop duration
+	decf	ul,F									; reduce the counter
 
 profile_view_get_depth_no_deco:
 	; then skip remaining bytes...
-	movf	gaslist_gas,W							; get number of additional bytes to ignore (0-127)
+	movf	ul,W									; get number of additional bytes to ignore (0-127)
 	tstfsz	WREG									; anything to skip?
-	call	incf_ext_flash_address0_0x20			; YES - skip #WREG bytes
-	return
+	call	ext_flash_inc_address_0x20_exec			; YES - skip #WREG bytes
+	return											; done
+
 
+;-----------------------------------------------------------------------------
+; get Information about Event(s)
+;
 profile_view_get_depth_events:
 	clrf	event_byte2								; clear event byte 2
-	FLASH_CC_READ_0x20 event_byte1						; read  event byte 1
-	decf	gaslist_gas,F							; reduce counter
+	FLASH_CC_READ_0x20 event_byte1					; read  event byte 1
+	decf	ul,F									; reduce counter
 
 	btfss	event_byte1,7							; another event byte?
 	bra		profile_no_second_eventbyte				; NO  - skip next
-	FLASH_CC_READ_0x20 event_byte2						; YES - read event byte 2
-	decf	gaslist_gas,F							;     - reduce counter
+	FLASH_CC_READ_0x20 event_byte2					; YES - read event byte 2
+	decf	ul,F									;     - reduce counter
 	bcf		event_byte1,7							;     - clear flag
 
 profile_no_second_eventbyte:
@@ -1188,8 +1181,8 @@
 	rcall	logbook_event2							; YES
 	; any alarm?
 	bcf		event_byte1,4							; clear bits already tested
-	bcf		event_byte1,5
-	bcf		event_byte1,6
+	bcf		event_byte1,5							; ...
+	bcf		event_byte1,6							; ...
 	movlw	.6										; coding for manual marker
 	cpfseq	event_byte1								; manual marker set?
 	return											; NO  - done
@@ -1197,20 +1190,20 @@
 	return											;     - done
 
 logbook_event4:										; stored gas changed
-	FLASH_CC_READ_0x20 backup_color1					; read gas number, to be used as color index
-	decf	gaslist_gas,F							; reduce counter
+	FLASH_CC_READ_0x20 backup_color1				; read gas number, to be used as color index
+	decf	ul,F									; reduce counter
 	call	TFT_color_code_gas						; change profile color according to gas number (still in WREG)
-	return
+	return											; done
 
 logbook_event1:										; gas 6 used
 	bsf		event_gas_change_gas6					; set event flag
 	movlw	.6										; use gas 6 color
 	movwf	backup_color1							; select color for gas 6
 	call	TFT_color_code_gas						; set profile color
-	ext_flash_inc_address_0x20 d'2'					; skip two bytes
-	decf	gaslist_gas,F							; reduce counter
-	decf	gaslist_gas,F							; reduce counter
-	return
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip two bytes
+	decf	ul,F									; reduce counter
+	decf	ul,F									; reduce counter
+	return											; done
 
 logbook_event2:										; bailout
 	bsf		bailout_mode							; set flag
@@ -1218,14 +1211,14 @@
 	movlw	.6										; use Gas6 color
 	movwf	backup_color1
 	call	TFT_color_code_gas						; use gas 6 color
-	ext_flash_inc_address_0x20 d'2'					; skip two bytes
-	decf	gaslist_gas,F							; reduce counter
-	decf	gaslist_gas,F							; reduce counter
-	return
+	EXT_FLASH_INC_ADDRESS_0x20 d'2'					; skip two bytes
+	decf	ul,F									; reduce counter
+	decf	ul,F									; reduce counter
+	return											; done
 
 logbook_event3:										; setpoint change
-	ext_flash_inc_address_0x20 d'1'					; skip one byte
-	decf	gaslist_gas,F							; reduce counter
+	EXT_FLASH_INC_ADDRESS_0x20 d'1'					; skip one byte
+	decf	ul,F									; reduce counter
 	btfss	bailout_mode							; in bailout?
 	return											; NO  - done
 	movff	backup_color2,backup_color1				; YES - restore color
@@ -1233,10 +1226,12 @@
 	call	TFT_color_code_gas						;     - back to normal profile color
 	return											;     - done
 
-; ------------------------------------------------------------------------
 
+;-----------------------------------------------------------------------------
+; Helper Function - return to Dive List
+;
 exit_profileview:
-	clrf	gaslist_gas								; restore all registers to build same page again
+	clrf	ul										; restore all registers to build same page again
 	movff	logbook_divenumber_temp,logbook_divenumber
 	movff	logbook_max_dive_counter_temp,logbook_max_dive_counter
 	movff	logbook_temp_backup,logbook_temp
@@ -1247,8 +1242,12 @@
 	movlw	logbook_row_number
 	movwf	menu_pos_cur							; here: active row on current page
 	call	TFT_boot
-	goto	logbook2								; start search
+	goto	logbook2								; display dive headers
+
 
+;-----------------------------------------------------------------------------
+; Helper Function - show next Page
+;
 next_logbook2:
 	btfsc	all_dives_shown							; all shown?
 	goto	logbook									; YES
@@ -1258,13 +1257,17 @@
 	incf	logbook_page_number,F					; start new screen
 	bsf		keep_cursor_new_page					; keep cursor on "next page"
 	call	TFT_boot
-	goto	logbook2								; start search
+	goto	logbook2								; display dive headers
+
 
+;-----------------------------------------------------------------------------
+; Helper Function - move Cursor
+;
 next_logbook3:
 	incf	menu_pos_cur,F							; set cursor to next line
 	movlw	logbook_row_number+.2					; get maximum number of lines
 	cpfsgt	menu_pos_cur							; cursor position beyond last line?
-	bra		next_logbook3a							; NO - ok, done
+	bra		next_logbook3a							; NO  - ok, done
 	movlw	.1										; YES - reset to first line
 	movwf	menu_pos_cur							;     - ...
 	bra		next_logbook3b							;     - done
@@ -1281,38 +1284,41 @@
 	bsf		all_dives_shown							; NO - set flag to load first page again (full reset)
 
 next_logbook3b:
-	call	TFT_logbook_cursor
-	goto	logbook_loop_pre
+	call	TFT_logbook_cursor						; show the cursor
+	goto	logbook_loop_pre						; serve HMI
 
-; ------------------------------------------------------------------
-; list one dive
+
+;-----------------------------------------------------------------------------
+; Helper Function - display Dive Summery
 ;
 display_listdive:
 	bsf		logbook_page_not_empty					; flag page will not be empty
 	incf	menu_pos_max,F							; increment number of lines shown
 
-	lfsr	FSR2,buffer								; initialize output buffer
-	WIN_FONT FT_SMALL								; select font
+	FONT_SIZE FT_SMALL								; set font size
+	FONT_COLOR_MEMO									; set font color
 	WIN_LEFT logbook_list_left						; set horizontal output position
 	decf	menu_pos_max,W							; get current line -1 into WREG
 	mullw	logbook_row_offset						; multiply with row spacing
 	movff	PRODL,win_top							; set vertical output position
+	INIT_BUFFER										; initialize output buffer
 
 	; print dive number
 	movf	logbook_divenumber,W					; get running number of the dive
 	call	log_compute_divenumber					; compute dive number to show (incorporate dive number offset)
-	bsf		leftbind								; start left-aligned
-	movlw	.3										; start with 3rd digit (i.e. suppress the thousands)
-	movwf	ignore_digits							; ...
-	output_16dp .0									; print dive number
-	bcf		leftbind								; end left-alignment
+	bcf		leftbind								; make sure dive number is printed in 5 digit format
+	output_65535									; print dive number (0-65535)
+	movff	buffer+2,buffer+0						; drop first 2 digits
+	movff	buffer+3,buffer+1						; ...
+	movff	buffer+4,buffer+2						; ...
+	movlw	.3										; relocate buffer pointer
+	movwf	FSR2L									; ...
 
 	PUTC	' '										; print a space char
 
 	; print dive date
 	MOVTT	header_buffer+index_date,mpr			; get date
-	call	TFT_convert_date_short					; convert and print date
-
+	call	output_date_short						; print date (day and month)
 	PUTC	' '										; print a space char
 
 	; print dive depth
@@ -1325,48 +1331,47 @@
 display_listdive2_imperial:
 	call	convert_cm_to_feet						; convert value in mpr from [cm] to [feet]
 	PUTC	' '										; print one space char
-	output_16_3										; print depth, limited to 999
+	output_999										; print depth (0-999)
 	STRCAT_TEXT tFeets1								; print unit label
 	bra		display_listdive3						; continue with common part
 
 display_listdive2_metric:
-	bsf		ignore_digit5							; do not print the cm
-	movlw	d'1'									; do not print the first digit (no 1000 m)
-	movwf	ignore_digits							; ...
-	output_16dp .3									; print depth in format xxx.y
+	bsf		omit_digit_1							; do not print 1st digit (no cm)
+	bsf		decimal_digit2							; place a decimal point in front of digit 2
+	output_65535									; print depth (0.0x-655.3x)
 	STRCAT_TEXT tMeters								; print unit label
-	PUTC	' '										; print one space char
+	PUTC	' '										; append one space char
 	;bra	display_listdive3						; continue with common part
 
 	; print dive time
 display_listdive3:
 	MOVII	header_buffer+index_divetime,mpr		; get dive time (minutes only)
-	output_16_3										; print minutes (0-999 min)
+	output_999										; print minutes (0-999)
 	STRCAT_TEXT tMinutes							; print minutes mark ("'")
-	clrf	WREG									; create string terminator
-	movff	WREG,buffer+.21							; hard limit the output to 21 chars
-	STRCAT_PRINT ""									; finalize output
-
+	movlw	.21										; max string length is 21 chars
+	call	TFT_buffer_trim_length					; fill or cut buffer to correct length
+	PRINT											; dump to screen
 	return											; done
 
-; ------------------------------------------------------------------
 
+;-----------------------------------------------------------------------------
+; Helper Function - show Dive Number
+;
 logbook_show_divenumber:
 	WIN_MEDIUM	logbook_divenumer_column, logbook_divenumer_row
 	movf	divenumber,W							; log_compute_divenumber needs the list number
 	call	log_compute_divenumber					; compute dive number
-	bsf		leftbind
-	output_16										; show dive number
-	bcf		leftbind
-	STRCAT_PRINT ""									; finalize output
+	bsf		leftbind								; print left-aligned
+	output_65535									; show dive number
+	PRINT											; print buffer to screen
 	return											; done
 
 
 ;-----------------------------------------------------------------------------
 ;  1st Details Page after Profile: Dive Statistics
-
+;
 logbook_page1:										; show more info
-	rcall	log_details_header						; shows number, time/date and basic dive info
+	rcall	log_details_header						; show number, time/date and basic dive data
 
 	btfss	aux_flag								; dive done in a deco mode?
 	bra		logbook_page1_1							; NO
@@ -1380,28 +1385,26 @@
 
 logbook_decomodel_2:
 	; deco model GF version
-	STRCAT_PRINT "ZHL-16+GF"
-	WIN_SMALL .5,.90
-	STRCPY_TEXT tGF2
+	STRCAT_PRINT "ZH-L16+GF"						; print model label
+	WIN_SMALL .5,.90								; set position
+	STRCPY_TEXT tSD2								; print label
 	MOVII	header_buffer+index_gf_lo_hi,mpr		; get  GF factors
-	output_8										; print GF lo
-	STRCAT	"%/"
-	movff	hi,lo									; print GF hi
-	output_8										; ...
-	STRCAT_PRINT "%"
-	bra		logbook_cns
+	bra		logbook_decomodel_com					; continue with common part
 
 logbook_decomodel_1:
 	; deco model none-GF version
-	STRCAT_PRINT "ZH-L16"
-	WIN_SMALL .5,.90
+	STRCAT_PRINT "ZH-L16"							; print model label
+	WIN_SMALL .5,.90								; set position
+	STRCPY_TEXT tGF2								; print label
 	MOVII	header_buffer+index_factor_sat_desat,mpr; get both factors
-	output_8										; print saturation factor
+	;bra	logbook_decomodel_com					; continue with common part
+
+logbook_decomodel_com:
+	output_256										; print saturation factor
 	STRCAT	"%/"
 	movff	hi,lo									; print desaturation factor
-	output_8										; ...
-	STRCAT_PRINT "%"
-	;bra	logbook_cns
+	output_256										; ...
+	PUTC_PRINT "%"									; append unit and dump buffer to screen
 
 logbook_cns:
 	WIN_SMALL .5,.115
@@ -1409,13 +1412,13 @@
 	MOVII	header_buffer+index_cns_start,mpr		; get CNS at start of dive
 	bcf		mpr+1,int_warning_flag					; clear warning   flag (fix for cases were the flags already got stored to EEPROM)
 	bcf		mpr+1,int_attention_flag				; clear attention flag (fix for cases were the flags already got stored to EEPROM)
-	output_16
-	STRCAT	"->"
+	output_999										; print CNS % (0-999)
+	STRCAT	"->"									; print an arrow
 	MOVII	header_buffer+index_cns_end,mpr			; get CNS at end of dive
 	bcf		hi,int_warning_flag						; clear warning   flag (fix for cases were the flags already got stored to EEPROM)
 	bcf		hi,int_attention_flag					; clear attention flag (fix for cases were the flags already got stored to EEPROM)
-	output_16
-	STRCAT_PRINT "%"
+	output_999										; print CNS % (0-999)
+	PUTC_PRINT "%"									; append unit and dump buffer to screen
 
 logbook_page1_1:
 	WIN_SMALL .5,.140
@@ -1428,96 +1431,102 @@
 
 logbook_page1_1_imperial:
 	call	convert_cm_to_feet						; convert value in lo:hi from [cm] to [feet]
-	PUTC	' '
-	output_16_3										; limit to 999 and display only (0-999)
-	STRCAT_PRINT "ft"
-	bra		logbook_page1_1_common
+	PUTC	' '										; addend a space
+	output_999										; print depth (0-999)
+	STRCAT_PRINT "ft"								; append unit and dump to screen
+	bra		logbook_page1_1_common					; continue
 
 logbook_page1_1_metric:
-	bsf		ignore_digit5							; no cm (flag will be cleared by output_16)
-	movlw	.1										; no 1000 meters
-	movwf	ignore_digits							; ...
-	output_16dp .3									; xxx.y
-	STRCAT_PRINT "m"
-	;bra	logbook_page1_1_common
+	bsf		decimal_digit2							; place a decimal point in front of digit 2
+	bsf		omit_digit_1							; do not print 1st digit
+	output_65535									; print depth (0.0x - 999.9x)
+	PUTC_PRINT "m"									; append unit and dump buffer to screen
+	;bra	logbook_page1_1_common					; continue
 
 logbook_page1_1_common:
 	btfss	aux_flag								; dive done in a deco mode?
 	bra		logbook_page1_2							; NO
 
 	; Salinity
-	WIN_SMALL .5,.165								; ex WIN_SMALL .5,.140
-	STRCPY_TEXT tDvSalinity2
-	bsf		leftbind
+	WIN_SMALL .5,.165								; set position
+	STRCPY_TEXT tDvSalinity2						; print label
 	MOVCC	header_buffer+index_salinity,lo			; read salinity
-	output_8
-	STRCAT_PRINT "%"
+	output_99										; print salinity (0-99, effectively 0-4 with leading space)
+	PUTC_PRINT "%"									; append unit and dump to screen
 
 	; Last deco
-	WIN_SMALL .5,.190
-	STRCPY_TEXT tLastDeco
+	WIN_SMALL .5,.190								; set position
+	STRCPY_TEXT tLastDeco							; print label
 	MOVCC	header_buffer+index_last_stop,lo		; read last stop depth
-	output_8
-	STRCAT_PRINT "m"
+	output_99										; print depth (0-99, effectively 0-6 with leading space)
+	PUTC_PRINT "m"									; append unit and dump to screen
 
 logbook_page1_2:
-	movlw	color_lightblue
-	call	TFT_set_color
-	WIN_FRAME_COLOR16 .63,.220,.2,.105				; top, bottom, left, right
+	movlw	color_lightblue							; select color
+	WIN_FRAME_COLOR .63,.220,.2,.105				; top, bottom, left, right
 
 	; Firmware
-	call	TFT_standard_color
-	WIN_SMALL .110,.65
-	STRCAT	"V:"
+	FONT_COLOR_MEMO									; set font color
+	WIN_SMALL .110,.65								; set output position
+	STRCAT	"V:"									; print "V:"
 	MOVII	header_buffer+index_firmware,mpr		; get firmware version
 	movff	lo,up									; keep a backup of major in up
 	bsf		leftbind								; print left-aligned
-	output_8										; print major version (in 1 digit due to leftbind)
+	output_99										; print major version
 	PUTC	"."										; print "."
 	movff	hi,lo									; print minor version...
 	output_99x										; ... in 2 digit format
-	STRCAT_PRINT ""									; finalize output
+	PRINT											; print buffer to screen
 
+logbook_battery_hwos_tech:
+	; all hwos tech >= 2.15 also stored battery %
 	movf	up,W									; get major into WREG
 	xorlw	.3										; major == 3 ?
 	bz		logbook_battery_percent					; YES - show battery %
 	movf	up,W									; NO  - get major into WREG (again)
 	xorlw	.2										;       major == 2 ?
-	bnz		logbook_battery_voltage					;       NO  - skip battery %
+	bnz		logbook_battery_hwos_sport				;       NO  - check for hwos sport
 	movlw	.14										;       YES - check minor version
 	cpfsgt	lo										;           - minor > 14 ?
-	bra		logbook_battery_voltage					;             NO  - skip battery %
-	;bra	logbook_battery_percent					;             YES - show battery %
+	bra		logbook_battery_hwos_sport				;             NO  - check for hwos sport
+	bra		logbook_battery_percent					;             YES - show battery %
+
+logbook_battery_hwos_sport:
+	; all hwos_sport >= 10.34 also stored battery %
+	; check major again for .10 (for maintainability)
+	movf	up,W									; get major into WREG
+	xorlw	.10										; major == 10 ?
+	bnz		logbook_battery_voltage					; NO  - skip battery %
+	movlw	.33										; YES - check minor version
+	cpfsgt	lo										;     - minor > 33 ?
+	bra		logbook_battery_voltage					;       NO  - skip battery %
+	;bra	logbook_battery_percent					;       YES - show battery %
 
 	; Battery %
 logbook_battery_percent:
 	WIN_SMALL .110,.140
 	MOVCC	header_buffer+index_batt_percent,lo		; get   battery percent
-	output_8										; print battery percent
-	STRCAT_PRINT "%"								; print "%" and finalize output
+	output_256										; print battery percent
+	PUTC_PRINT "%"									; append "%" and dump buffer to screen
 
 	; Battery Voltage
 logbook_battery_voltage:
-	WIN_SMALL .110,.90
-	STRCAT_PRINT "Batt:"
-	WIN_SMALL .110,.115
-	MOVII	header_buffer+index_battery_voltage,mpr	; get   battery voltage
-	output_16dp .2									; print battery voltage
-	STRCAT_PRINT "V"								; print unit (Volt)
+	WIN_SMALL .110,.90								; set position
+	STRCAT_PRINT "Batt:"							; print label
+	WIN_SMALL .110,.115								; set position
+	MOVII	header_buffer+index_battery_voltage,mpr	; get battery voltage
+	bsf		decimal_digit3							; place a decimal point in front of digit 3
+	output_9999										; print battery voltage (0.000-9.999)
+	PUTC_PRINT "V"									; append unit and dump buffer to screen
 
 	; Surface Pressure
 	MOVII	header_buffer+index_surface_press,mpr	; get surface pressure
 	WIN_SMALL .110,.165								; set output position
-	bsf		leftbind								; print without leading spaces
-	output_16										; print surface pressure before dive
-	STRCAT_TEXT tMBAR								; print unit
-	clrf	WREG									; string terminator
-	movff	WREG,buffer+7							; limit to 7 chars
-	STRCAT_PRINT ""									; dump buffer to screen
+	output_9999										; print surface pressure before dive (0-9999)
+	STRCAT_TEXT_PRINT tMBAR							; append unit and dump to screen
 
 	movlw	color_greenish							; select color
-	call	TFT_set_color							; ...
-	WIN_FRAME_COLOR16 .63,.220,.107,.159			; draw a frame with coordinates top, bottom, left, right
+	WIN_FRAME_COLOR .63,.220,.107,.159				; draw a frame with coordinates top, bottom, left, right
 
 	; handle HMI
 	rcall	logbook_preloop_tasks					; clear timeout and remaining button events
@@ -1537,30 +1546,19 @@
 
 ;-----------------------------------------------------------------------------
 ;  2nd Details Page after Profile: Tissue and Decompression Status
-
+;
 logbook_page2:
 
-; ################# to be removed later ##################################
-;	movlw	fw_version_beta				; get beta status
-;	tstfsz	WREG						; beta?
-;	bra		display_page2_betajump		; YES - omit firmware version check
-; ########################################################################
-
-	; skip this page for dives recorded with firmwares < 3.09
-	MOVII	header_buffer+index_firmware,mpr		; get firmware version major and minor
+	; skip this page for dives recorded with internal profile < 0x01
 
-	movlw	.2										; minimum required major is 3, -1 for cpfsgt
-	cpfsgt	lo										; major >= requirement?
-	bra		logbook_page3							; NO  - skip this page
-	movlw	.8										; YES - minimum required minor is 9, -1 for cpfsgt
-	cpfsgt	hi										;     - minor >= requirement?
-	bra		logbook_page3							;       NO  - skip this page
+	MOVCC	header_buffer+index_profile_version,WREG; read profile format version
+	andlw	b'11000000'								; keep only the internal part of the profile version
+	bnz		logbook_page2a							; show page 2 if internal version  > 0
+	bra		logbook_page3							; skip page 2 if internal version is 0
 
-; ################# to be removed later ##################################
-display_page2_betajump:
-; ########################################################################
+logbook_page2a:
 
-	rcall	log_details_header						; shows number, time/date and basic dive info
+	rcall	log_details_header						; show number, time/date and basic dive data
 
 	; basic configuration of tissue graphics
 	bsf		tissue_graphic_mode						; select logbook mode
@@ -1574,7 +1572,7 @@
 	bsf		tissue_graphic_gf						; YES - show GF lines
 
 	; draw the graphics
-	call	TFT_surface_tissues
+	call	TFT_surf_cv_tissues
 
 	; calculate time/date of the end of the dive
 	MOVTT	header_buffer+index_date,      rtc_latched_year		; get start    of the dive - year, month, day
@@ -1586,14 +1584,14 @@
 	; print time/date of the end of the dive
 	WIN_SMALL .8,.193									; select font and output position
 	MOVTT	rtc_latched_year,mpr						; get computed end-of-dive date
-	call	TFT_convert_date_short						; convert and print date
+	call	output_date_short							; print date (day and month)
 	STRCAT	".-"										; print spacing ".-"
 	MOVII	rtc_latched_hour,mpr						; get computed end-of-dive time
 	output_99x											; print hour
 	PUTC	':'											; print spacing ":"
 	movff	hi,lo										; print minute
 	output_99x											; ...
-	STRCAT_PRINT ""										; finalize output
+	PRINT												; print buffer to screen
 
 
 	; draw a white frame around the time/date
@@ -1614,9 +1612,8 @@
 	; 2nd line: 
 	WIN_SMALL .100+.28,.93							; +16 for centered, +28 for right-aligned
 	MOVCC	header_buffer+index_supersat_start,lo	; get supersaturation at start of dive
-	bcf		leftbind
-	output_8										; print percent value
-	STRCAT_PRINT "%"								; print "%" and finalize output
+	output_256										; print percent value
+	PUTC_PRINT "%"									; append "%" and dump buffer to screen
 
 	; 3rd line: 
 	WIN_SMALL .100,.118
@@ -1625,9 +1622,8 @@
 	; 4th line: 
 	WIN_SMALL .100+.28,.143							; +16 for centered, +28 for right-aligned
 	MOVCC	header_buffer+index_supersat_end,lo		; get supersaturation at end of dive
-	bcf		leftbind
-	output_8										; print percent value
-	STRCAT_PRINT "%"								; print "%" and finalize output
+	output_256										; print percent value
+	PUTC_PRINT "%"									; append "%" and dump buffer to screen
 
 	; 5th line: desaturation time label
 	WIN_SMALL .100,.168
@@ -1644,15 +1640,14 @@
 	PUTC	'h'										; print hours mark
 	movff	hi,lo									; print minutes...
 	output_99x										; ... in two digits, leading zero
-	STRCAT_PRINT "m"								; print minutes mark and finalize output
+	PUTC_PRINT "m"									; append minutes mark and dump buffer to screen
 
 	; draw a colored frame around the right side
 	movlw	color_orange							; select color
-	call	TFT_set_color							; ...
-	WIN_FRAME_COLOR16 .65,.220,.97,.159				; draw a frame with coordinates top, bottom, left, right
+	WIN_FRAME_COLOR .65,.220,.97,.159				; draw a frame with coordinates top, bottom, left, right
 
 	; handle HMI
-	rcall	logbook_preloop_tasks					; clear timeout and remaining button events
+	rcall	logbook_preloop_tasks					; clear timeout and left-over button events
 display_details1b_loop:
 	btfsc	switch_right							; right button pressed?
 	bra		logbook_page3							; YES - show more info
@@ -1663,11 +1658,12 @@
 
 
 ;-----------------------------------------------------------------------------
-; helper function
+; Helper Function - clear Timeout and left-over Button Events
+;
 logbook_preloop_tasks:
 	movlw	CCP1CON_VALUE							; see hwos.inc
 	movwf	CCP1CON									; power-on backlight
-	call	TFT_standard_color						; revert to standard color
+	FONT_COLOR_MEMO									; revert font color to standard
 	call	reset_timeout_surfmode					; reset timeout
 	bcf		switch_left								; clear left-over left  button event
 	bcf		switch_right							; clear left-over right button event
@@ -1675,12 +1671,12 @@
 
 ;-----------------------------------------------------------------------------
 ; 3rd Details Page after Profile: Gases / Diluents
-
+;
 logbook_page3:
-	rcall	log_details_header						; shows number, time/date and basic dive info
+	rcall	log_details_header						; show number, time/date and basic dive data
+
 	lfsr	FSR0,header_buffer+index_gas1			; load base address of the gases
 	bcf		log_show_gas_short						; do the long version of log_show_gas
-	bcf		leftbind
 
 	WIN_SMALL .5,.90
 	movlw	.1										; color for gas 1
@@ -1703,8 +1699,8 @@
 	rcall	log_show_gas
 
 	; OC/CC gas list
-	WIN_SMALL .5,.65
-	WIN_COLOR color_greenish
+	WIN_SMALL .5,.65								; set title position
+	FONT_COLOR color_greenish						; set title color
 
 	MOVCC	header_buffer+index_divemode,WREG		; read dive mode (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4= pSCR)
 	decfsz	WREG,W									; dive mode = CC ?
@@ -1714,9 +1710,8 @@
 logbook_page3a:
 	STRCPY_TEXT_PRINT tGaslist						; print OC title
 logbook_page3b:
-	movlw	color_lightblue							; select color
-	call	TFT_set_color							; set    color
-	WIN_FRAME_COLOR16 .63,.220,.2,.114				; draw a frame with coordinates top, bottom, left, right
+	movlw	color_lightblue							; select frame color
+	WIN_FRAME_COLOR .63,.220,.2,.114				; draw frame (top, bottom, left, right)
 
 	; handle HMI
 	rcall	logbook_preloop_tasks					; clear timeout, some flags and set to speed_eco
@@ -1731,34 +1726,33 @@
 
 ;-----------------------------------------------------------------------------
 ; 4th Details Page after Profile: Setpoints
-
+;
 logbook_page4:
 	MOVCC	header_buffer+index_divemode,WREG		; get dive mode (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4= pSCR)
 	decfsz	WREG,W									; =1 (CC)?
 	goto	display_profile2						; NO - skip setpoints
 
-	rcall	log_details_header						; shows number, time/date and basic dive info
+	rcall	log_details_header						; show number, time/date and basic dive data
 
 	; print setpoint list
 	lfsr	FSR0,header_buffer+index_sp1			; load base address of the setpoints
-	WIN_SMALL .5,.65
-	WIN_COLOR color_greenish
-	STRCPY_TEXT_PRINT tFixedSetpoints
-	call	TFT_standard_color
-	WIN_SMALL .5,.90
-	rcall	  log_show_sp
-	WIN_SMALL .5,.115
-	rcall	  log_show_sp
-	WIN_SMALL .5,.140
-	rcall	  log_show_sp
-	WIN_SMALL .5,.165
-	rcall	  log_show_sp
-	WIN_SMALL .5,.190
-	rcall	  log_show_sp
+	WIN_SMALL .5,.65								; set title position
+	FONT_COLOR color_greenish						; set title color
+	STRCPY_TEXT_PRINT tFixedSetpoints				; print title
+	FONT_COLOR_MEMO									; set font color
+	WIN_SMALL .5,.90								; set position
+	rcall	  log_show_sp							; print setpoint data set
+	WIN_SMALL .5,.115								; set position
+	rcall	  log_show_sp							; print setpoint data set
+	WIN_SMALL .5,.140								; set position
+	rcall	  log_show_sp							; print setpoint data set
+	WIN_SMALL .5,.165								; set position
+	rcall	  log_show_sp							; print setpoint data set
+	WIN_SMALL .5,.190								; set position
+	rcall	  log_show_sp							; print setpoint data set
 
-	movlw	color_greenish
-	call	TFT_set_color
-	WIN_FRAME_COLOR16 .63,.220,.2,.112				; top, bottom, left, right
+	movlw	color_greenish							; select color for the frame
+	WIN_FRAME_COLOR .63,.220,.2,.112				; draw frame (top, bottom, left, right)
 
 	; handle HMI
 	rcall	logbook_preloop_tasks					; clear timeout, some flags and set to Speed_eco
@@ -1772,27 +1766,25 @@
 
 
 ;-----------------------------------------------------------------------------
-; Helper Functions
-
+; Helper Function - show Dive Number, Time/Date and basic Dive Data
+;
 log_details_header:
-	call	TFT_boot
-	call	TFT_standard_color
+	call	TFT_boot								; initialize display
+	FONT_COLOR_MEMO									; set font color
 
 	rcall	logbook_show_divenumber					; show the dive number in medium font
 
 	; show date and time in first row
 	WIN_SMALL .59,.10
 	MOVTT	header_buffer+index_date,mpr			; get date
-	call	TFT_convert_date						; convert into "DD/MM/YY" or "MM/DD/YY" or "YY/MM/DD" in buffer
-
-	PUTC	"-"
-
+	call	output_date								; print date
+	PUTC	"-"										; print "-"
 	MOVII	header_buffer+index_time,mpr			; get time
 	output_99x										; print hour
 	PUTC	':'										; print spacing ":"
 	movff	hi,lo									; print minute
 	output_99x										; ...
-	STRCAT_PRINT ""									; display 1st row of details
+	PRINT											; dump to screen
 
 	; show max depth and dive time
 	WIN_SMALL .5,.35
@@ -1805,32 +1797,33 @@
 
 logbook_page2_depth_imperial:
 	call	convert_cm_to_feet						; convert value in lo:hi from [cm] to [feet]
-	PUTC	' '
-	bcf		leftbind
-	output_16_3
-	STRCAT_TEXT tFeets
-	bra		logbook_page2_depth_common
+	PUTC	' '										; append a space
+	output_999										; print depth
+	STRCAT_TEXT tFeets								; append unit
+	bra		logbook_page2_depth_common				; continue
 
 logbook_page2_depth_metric:
-	bsf		ignore_digit5							; no cm...
-	movlw	d'1'									; no 1000 m
-	movwf	ignore_digits							; ...
-	output_16dp d'3'								; xxy.y
-	STRCAT_TEXT tMeters
-	;bra	logbook_page2_depth_common
+	bsf		omit_digit_1							; do not print 1st digit
+	bsf		decimal_digit2							; place a decimal point in front of digit 2
+	output_65535									; print depth (0.0x-655.3x)
+	STRCAT_TEXT tMeters								; append unit
+	;bra	logbook_page2_depth_common				; continue
 
 logbook_page2_depth_common:
 	STRCAT	" - "
 	MOVTT	header_buffer+index_divetime,mpr		; get dive time
-	bsf		leftbind
-	output_16										; print minutes
-	PUTC	"m"
+	bsf		leftbind								; print left-aligned
+	output_9999										; print minutes (0-9999)
+	PUTC	"m"										; append unit
 	movff	up,lo									; print seconds
 	output_99x										; ...
-	STRCAT_PRINT "s"
-	return
+	PUTC_PRINT "s"									; append unit and dump buffer to screen
+	return											; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - show Setpoint Data
+;
 log_show_sp:
 	; log point is set by caller
 	MOVCC	POSTINC0,lo								; copy set point    into lo
@@ -1838,11 +1831,11 @@
 
 	movff	mpr+1,mpr+2								; save change depth
 	clrf	mpr+1									; set high byte to zero for printing setpoint
-	bsf		leftbind
-	output_16dp d'3'								; print setpoint x.xx
-	bcf		leftbind
-	STRCAT_TEXT tbar
-	PUTC	" "
+	bsf		leftbind								; print left-aligned
+	bsf		decimal_digit2							; place a decimal point in front of digit 2
+	output_999										; print setpoint (0.00-9.99)
+	STRCAT_TEXT tbar								; append unit
+	PUTC	" "										; append a space
 	movff	mpr+2,mpr+0								; restore change depth to lo
 
 	TSTOSS	opt_units								; 0=Meter, 1=Feet
@@ -1851,33 +1844,34 @@
 
 log_show_sp_imperial:
 	call	convert_meter_to_feet					; convert value in lo from [m] to [feet]
-	output_16_3
-	PUTC	" "
-	STRCAT_TEXT tFeets								; "ft"
-	bra		log_show_sp_common
+	output_999										; print depth (0-999)
+	PUTC	" "										; append space
+	STRCAT_TEXT_PRINT tFeets						; append unit and dump to screen
+	return											; done
 
 log_show_sp_metric:
-	output_8
-	PUTC	" "
-	STRCAT_TEXT tMeters								; "m"
-	;bra	log_show_sp_common
-
-log_show_sp_common:
-	STRCAT_PRINT ""
-	return
+	output_256										; print depth (0-256)
+	PUTC	" "										; append space
+	STRCAT_TEXT_PRINT tMeters						; append unit and dump to screen
+	return											; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - show Gas Data
+;
 log_show_gas:										; show gas data
 	call	TFT_color_code_gas						; color the output (gas number is in WREG)
-	MOVCC	POSTINC0,lo								; copy O2 fraction into lo
-	MOVCC	POSTINC0,hi								; copy He fraction into hi
-	call	gaslist_show_mix						; put "Nxlo", "Txlo/hi", "Air" or "O2" into buffer
+	MOVCC	POSTINC0,lo								; read O2 fraction into lo
+	MOVCC	POSTINC0,hi								; read He fraction into hi
+	call	gaslist_strcat_mix						; put "Nxlo", "Txlo/hi", "Air" or "O2" into buffer
 
-	MOVCC	POSTINC0,lo								; copy change depth into lo
-	MOVCC	POSTINC0,hi								; copy gas    type  into hi
-	btfsc	log_show_gas_short						; shall we do the short version?
-	bra		log_show_gas_common						; YES - do short version
-	;bra	log_show_gas_long						; NO  - add gas types
+	MOVCC	POSTINC0,lo								; read change depth into lo
+	MOVCC	POSTINC0,hi								; read gas    type  into hi
+
+	btfss	log_show_gas_short						; shall do the short version?
+	bra		log_show_gas_long						; NO  - add gas types
+	PRINT											; YES - dump to screen
+	return											; done
 
 log_show_gas_long:
 	PUTC	" "										; put one space between gas composition and gas type marking
@@ -1901,26 +1895,26 @@
 log_show_gas_4:
 	PUTC	" "										; put one space between gas type marking and change depth
 
+	bsf		leftbind								; print left-aligned
 	TSTOSS	opt_units								; 0=Meter, 1=Feet
 	bra		log_show_gas_metric						; 0 - do metric
 	;bra	log_show_gas_imperial					; 1 - do imperial
 
 log_show_gas_imperial:
 	call	convert_meter_to_feet					; convert value in lo from [m] to [feet]
-	output_16_3										; limit to 999 and display only 0-999
-	STRCAT_TEXT tFeets								; "ft"
-	bra		log_show_gas_common
+	output_999										; print depth (0-999)
+	STRCAT_TEXT_PRINT tFeets						; append unit and dump to screen
+	return											; done
 
 log_show_gas_metric:
-	output_8
-	STRCAT_TEXT tMeters								; "m"
-	;bra	log_show_gas_common
-
-log_show_gas_common:
-	STRCAT_PRINT ""
-	return
+	output_256										; print depth (0-255)
+	STRCAT_TEXT_PRINT tMeters						; append unit and dump to screen
+	return											; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - compute Dive Number
+;
 log_compute_divenumber:
 	movwf	mpr+2									; store current dive number in mpr+2
 	call	eeprom_log_offset_read					; read log offset into mpr+0 & +1
@@ -1951,10 +1945,11 @@
 	MOVII	sub_c,mpr								;     - copy result back to mpr
 	return											;     - done
 
-;----------------------------------------------------------------------------
-; Compute flash address for header data of a particular dive
+
+;-----------------------------------------------------------------------------
+; Helper Function - compute Flash Address of Header by Dive Number
 ;
-; Memory map in flash:
+; Memory Map in Flash:
 ;
 ; low(total number of dives) -> index -> start address    end address
 ; --------------------------------------------------------------------
@@ -1963,9 +1958,9 @@
 ;          3                      2       0x2|02|000   -   0x2|02|FFF
 ;        ...
 ;  256 ->  0                    255       0x2|FF|000   -   0x2|FF|FFF
-
+;
 log_header_addr_by_divenumber:
-	; compute index of the dive with number 'divenumber'
+	; compute dive index from of the dive number
 	decf	divenumber,W							; compute number of dive to show -1...
 	movwf	mpr+3									; ... and store in mpr+3
 	movf	total_num_dives,W						; get number of total dives (low byte)
@@ -1973,23 +1968,24 @@
 	subfwb	mpr+3,W									; index = number of total dives - number of dive to show + 1
 	;bra	log_header_addr_by_index				; get address by index
 
+
+;-----------------------------------------------------------------------------
+; Helper Function - compute Flash Address of Header by Dive Index
+;
 	global	log_header_addr_by_index
 log_header_addr_by_index:
 	; compute the start address of the header belonging to the dive whose index is in WREG
-	movwf	mpr+3									; copy index to mpr+3
-	clrf	mpr+0									; set up base address 0x200000
-	clrf	mpr+1									; ...
-	movlw	0x20									; ...
-	movwf	mpr+2									; ...
-	movlw	.16										; prepare a shift left by 4 bit
-	mulwf	mpr+3									; shift left index to create offset
-	movf	PRODL,W									; get    low   byte of offset
-	addwf	mpr+1,F									; add to high  byte of address
-	movf	PRODH,W									; get    high  byte of offset
-	addwfc	mpr+2,F									; add to upper byte of address
-
-	return
+	movwf	lo										; copy index to lo
+	movlw	.16										; prepare a shift left by 4 bit -> multiply with 16
+	mulwf	lo										; shift left the index to create the offset
+	clrf	ext_flash_address+0						; clear    low   byte of the address
+	movf	PRODL,W									; get      low   byte of the offset
+	movwf	ext_flash_address+1						; store as high  byte of the address
+	movf	PRODH,W									; get      high  byte of the offset
+	addlw	0x20									; add 0x20
+	movwf	ext_flash_address+2						; store as upper byte of the address
+	return											; done
 
 ; ----------------------------------------------------------------
 
-	END
\ No newline at end of file
+	END