diff code_part1/OSTC_code_asm_part1/divemode.asm @ 33:6e5db85382a2

Speedy simulator! New Deco code test 1
author heinrichsweikamp
date Tue, 25 May 2010 17:37:26 +0200
parents 99512945c7a1
children d4f0c097a7fa
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/divemode.asm	Mon May 24 17:48:21 2010 +0200
+++ b/code_part1/OSTC_code_asm_part1/divemode.asm	Tue May 25 17:37:26 2010 +0200
@@ -319,129 +319,199 @@
 divemode_check_decogases:					; CALLed from Simulator
 	btfss	dekostop_active
 	bra		reset_decompression_gases	; While in NDL, do not set deompression gas
-; 1. Find active gas with deepest change depth < current depth
-; 2. Set Decogas
 
-	movff	rel_pressure+0,xA+0			
-	movff	rel_pressure+1,xA+1
-	movlw	d'100'
-	movwf	xB+0
-	clrf	xB+1
-	call	div16x16				; compute depth in full m -> result in xC+0
-	clrf	lo						; clear depth for comparison
-
-; check gas1 
-	read_int_eeprom		d'27'		; read flag register
-	btfss	EEDATA,0				; check active flag
-	bra		check_decogas2			; skip inactive gases!
-	read_int_eeprom		d'28'		; read gas_change_depth
-	movf	xC+0,W					; load depth in m into WREG
-	cpfslt	EEDATA					; gas_change_depth > current depth?
-	bra		check_decogas2			; W < EEDATA -> current depth lower then gas_change_depth
-	
-	movff	EEDATA,lo				; deepest gas_change_depth in lo
-	movlw	d'1'
-	movwf	hi						; Decogas # in hi (1-5)
+; Copy active gases to char_I_deco_N2_ratio and char_I_deco_He_ratio
 
-check_decogas2:
-	read_int_eeprom		d'27'		; read flag register
-	btfss	EEDATA,1				; check active flag
-	bra		check_decogas3			; skip inactive gases!
-	read_int_eeprom		d'29'		; read gas_change_depth
-	movf	xC+0,W					; load depth in m into WREG
-	cpfslt	EEDATA					; gas_change_depth > current depth?
-	bra		check_decogas3			; W < EEDATA -> current depth lower then gas_change_depth
+	clrf	hi						; # of gas (0-4)
+	; Gas0 is Start gas, do not copy
+	
+	lfsr	FSR1, char_I_deco_He_ratio5		; most shallow decogas
+	
+divemode_check_decogases2:
+	incf	hi,F						; increase
+	rcall	copy_decogas_info
+	movlw	d'4'
+	cpfseq	hi							; 4 Gases copied?
+	bra		divemode_check_decogases2	; No, Continue
 
-	read_int_eeprom		d'29'		; read gas_change_depth
-	movf	lo,W					; load current gas_change_depth into WREG
-	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
-	bra		check_decogas3			; W < lo -> last gas_change_depth > current gas_change_depth
-	movff	EEDATA,lo				; deepest gas_change_depth in lo
-	movlw	d'2'
-	movwf	hi						; Decogas # in hi (1-5)
+; Now, set change depth. Inactive gases get depth=0!
 
-check_decogas3:
 	read_int_eeprom		d'27'		; read flag register
-	btfss	EEDATA,2				; check active flag
-	bra		check_decogas4			; skip inactive gases!
-	read_int_eeprom		d'30'		; read gas_change_depth
-	movf	xC+0,W					; load depth in m into WREG
-	cpfslt	EEDATA					; gas_change_depth > current depth?
-	bra		check_decogas4			; W < EEDATA -> current depth lower then gas_change_depth
+	movff	EEDATA,hi				; temp
+	
+	read_int_eeprom		d'28'		; read gas_change_depth Gas1
+	movlw	d'0'
+	btfsc	hi,1					; Skip if clear -> Skip if inactive
+	movf	EEDATA,W
+	movff	WREG,char_I_deco_gas_change5
 
-	read_int_eeprom		d'30'		; read gas_change_depth
-	movf	lo,W					; load current gas_change_depth into WREG
-	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
-	bra		check_decogas4			; W < lo -> last gas_change_depth > current gas_change_depth
-	movff	EEDATA,lo				; deepest gas_change_depth in lo
-	movlw	d'3'
-	movwf	hi						; Decogas # in hi (1-5)
+	read_int_eeprom		d'29'		; read gas_change_depth Gas2
+	movlw	d'0'
+	btfsc	hi,2					; Skip if clear -> Skip if inactive
+	movf	EEDATA,W
+	movff	WREG,char_I_deco_gas_change4
 
-check_decogas4:
-	read_int_eeprom		d'27'		; read flag register
-	btfss	EEDATA,3				; check active flag
-	bra		check_decogas5			; skip inactive gases!
-	read_int_eeprom		d'31'		; read gas_change_depth
-	movf	xC+0,W					; load depth in m into WREG
-	cpfslt	EEDATA					; gas_change_depth > current depth?
-	bra		check_decogas5			; W < EEDATA -> current depth lower then gas_change_depth
-
-	read_int_eeprom		d'31'		; read gas_change_depth
-	movf	lo,W					; load current gas_change_depth into WREG
-	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
-	bra		check_decogas5			; W < lo -> last gas_change_depth > current gas_change_depth
-	movff	EEDATA,lo				; deepest gas_change_depth in lo
-	movlw	d'4'
-	movwf	hi						; Decogas # in hi (1-5)
+	read_int_eeprom		d'30'		; read gas_change_depth Gas3
+	movlw	d'0'
+	btfsc	hi,3					; Skip if clear -> Skip if inactive
+	movf	EEDATA,W
+	movff	WREG,char_I_deco_gas_change3
 
-check_decogas5:
-	read_int_eeprom		d'27'		; read flag register
-	btfss	EEDATA,4				; check active flag
-	bra		check_decogas_done		; skip inactive gases!
-	read_int_eeprom		d'32'		; read gas_change_depth
-	movf	xC+0,W					; load depth in m into WREG
-	cpfslt	EEDATA					; gas_change_depth > current depth?
-	bra		check_decogas_done		; W < EEDATA -> current depth lower then gas_change_depth
+	read_int_eeprom		d'31'		; read gas_change_depth Gas1
+	movlw	d'0'
+	btfsc	hi,4					; Skip if clear -> Skip if inactive
+	movf	EEDATA,W
+	movff	WREG,char_I_deco_gas_change2
+		
+	return
 
-	read_int_eeprom		d'32'		; read gas_change_depth
-	movf	lo,W					; load current gas_change_depth into WREG
-	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
-	bra		check_decogas_done		; W < lo -> last gas_change_depth > current gas_change_depth
-	movff	EEDATA,lo				; deepest gas_change_depth in lo
-	movlw	d'5'
-	movwf	hi						; Decogas # in hi (1-5)
-
-check_decogas_done:
-	ostc_debug	'E'		; Sends debug-information to screen if debugmode active
-
-	decf	hi,F						; Gas 0-4
-	movff	lo, char_I_deco_gas_change	; copy change_depth
-
-	movf	hi,W						; Gas 0-4
-	mullw	d'4'
-	movf	PRODL,W			
-	addlw	d'7'						; = address for He ratio
+copy_decogas_info:
+	movf	hi,W						; Gas 1-4
+	mullw	d'4'						; times 4...
+	movf	PRODL,W						;
+	addlw	d'7'						; +7 = address for He ratio
 	movwf	EEADR
 	call	read_eeprom					; Read He ratio
-	movff	EEDATA,char_I_deco_He_ratio	; And copy into hold register
-
+	movff	EEDATA,INDF1				; And copy into hold register
 
-	movf	hi,W						; Gas 0-4
-	mullw	d'4'
-	movf	PRODL,W			
-	addlw	d'6'						; = address for O2 ratio
+	movf	hi,W						; Gas 1-4
+	mullw	d'4'						; times 4...
+	movf	PRODL,W						;
+	addlw	d'6'						; +6 = address for O2 ratio
 	movwf	EEADR
 	call	read_eeprom					; Read O2 ratio
-	
-	movff	char_I_deco_He_ratio, wait_temp	; copy into bank1 register
-	bsf		STATUS,C					; Borrow bit
+;	movff	EEDATA, char_I_O2_ratio		; O2 ratio
+	movff	POSTDEC1, wait_temp			; copy into bank1 register
+	bsf		STATUS,C					; 
 	movlw	d'100'						; 100%
 	subfwb	wait_temp,W					; minus He
-	bsf		STATUS,C					; Borrow bit
 	subfwb	EEDATA,F					; minus O2
-	movff	EEDATA, char_I_deco_N2_ratio	; = N2!
-	bra		skip_decompression_gases
+	movff	EEDATA, POSTDEC1			; = N2!
+	return
 
+;; 1. Find active gas with deepest change depth < current depth
+;; 2. Set Decogas
+;
+;	movff	rel_pressure+0,xA+0			
+;	movff	rel_pressure+1,xA+1
+;	movlw	d'100'
+;	movwf	xB+0
+;	clrf	xB+1
+;	call	div16x16				; compute depth in full m -> result in xC+0
+;	clrf	lo						; clear depth for comparison
+;
+;; check gas1 
+;	read_int_eeprom		d'27'		; read flag register
+;	btfss	EEDATA,0				; check active flag
+;	bra		check_decogas2			; skip inactive gases!
+;	read_int_eeprom		d'28'		; read gas_change_depth
+;	movf	xC+0,W					; load depth in m into WREG
+;	cpfslt	EEDATA					; gas_change_depth > current depth?
+;	bra		check_decogas2			; W < EEDATA -> current depth lower then gas_change_depth
+;	
+;	movff	EEDATA,lo				; deepest gas_change_depth in lo
+;	movlw	d'1'
+;	movwf	hi						; Decogas # in hi (1-5)
+;
+;check_decogas2:
+;	read_int_eeprom		d'27'		; read flag register
+;	btfss	EEDATA,1				; check active flag
+;	bra		check_decogas3			; skip inactive gases!
+;	read_int_eeprom		d'29'		; read gas_change_depth
+;	movf	xC+0,W					; load depth in m into WREG
+;	cpfslt	EEDATA					; gas_change_depth > current depth?
+;	bra		check_decogas3			; W < EEDATA -> current depth lower then gas_change_depth
+;
+;	read_int_eeprom		d'29'		; read gas_change_depth
+;	movf	lo,W					; load current gas_change_depth into WREG
+;	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
+;	bra		check_decogas3			; W < lo -> last gas_change_depth > current gas_change_depth
+;	movff	EEDATA,lo				; deepest gas_change_depth in lo
+;	movlw	d'2'
+;	movwf	hi						; Decogas # in hi (1-5)
+;
+;check_decogas3:
+;	read_int_eeprom		d'27'		; read flag register
+;	btfss	EEDATA,2				; check active flag
+;	bra		check_decogas4			; skip inactive gases!
+;	read_int_eeprom		d'30'		; read gas_change_depth
+;	movf	xC+0,W					; load depth in m into WREG
+;	cpfslt	EEDATA					; gas_change_depth > current depth?
+;	bra		check_decogas4			; W < EEDATA -> current depth lower then gas_change_depth
+;
+;	read_int_eeprom		d'30'		; read gas_change_depth
+;	movf	lo,W					; load current gas_change_depth into WREG
+;	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
+;	bra		check_decogas4			; W < lo -> last gas_change_depth > current gas_change_depth
+;	movff	EEDATA,lo				; deepest gas_change_depth in lo
+;	movlw	d'3'
+;	movwf	hi						; Decogas # in hi (1-5)
+;
+;check_decogas4:
+;	read_int_eeprom		d'27'		; read flag register
+;	btfss	EEDATA,3				; check active flag
+;	bra		check_decogas5			; skip inactive gases!
+;	read_int_eeprom		d'31'		; read gas_change_depth
+;	movf	xC+0,W					; load depth in m into WREG
+;	cpfslt	EEDATA					; gas_change_depth > current depth?
+;	bra		check_decogas5			; W < EEDATA -> current depth lower then gas_change_depth
+;
+;	read_int_eeprom		d'31'		; read gas_change_depth
+;	movf	lo,W					; load current gas_change_depth into WREG
+;	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
+;	bra		check_decogas5			; W < lo -> last gas_change_depth > current gas_change_depth
+;	movff	EEDATA,lo				; deepest gas_change_depth in lo
+;	movlw	d'4'
+;	movwf	hi						; Decogas # in hi (1-5)
+;
+;check_decogas5:
+;	read_int_eeprom		d'27'		; read flag register
+;	btfss	EEDATA,4				; check active flag
+;	bra		check_decogas_done		; skip inactive gases!
+;	read_int_eeprom		d'32'		; read gas_change_depth
+;	movf	xC+0,W					; load depth in m into WREG
+;	cpfslt	EEDATA					; gas_change_depth > current depth?
+;	bra		check_decogas_done		; W < EEDATA -> current depth lower then gas_change_depth
+;
+;	read_int_eeprom		d'32'		; read gas_change_depth
+;	movf	lo,W					; load current gas_change_depth into WREG
+;	cpfsgt	EEDATA					; last gas_change_depth > current gas_change_depth ?
+;	bra		check_decogas_done		; W < lo -> last gas_change_depth > current gas_change_depth
+;	movff	EEDATA,lo				; deepest gas_change_depth in lo
+;	movlw	d'5'
+;	movwf	hi						; Decogas # in hi (1-5)
+;
+;check_decogas_done:
+;	ostc_debug	'E'		; Sends debug-information to screen if debugmode active
+;
+;	decf	hi,F						; Gas 0-4
+;	movff	lo, char_I_deco_gas_change	; copy change_depth
+;
+;	movf	hi,W						; Gas 0-4
+;	mullw	d'4'
+;	movf	PRODL,W			
+;	addlw	d'7'						; = address for He ratio
+;	movwf	EEADR
+;	call	read_eeprom					; Read He ratio
+;	movff	EEDATA,char_I_deco_He_ratio	; And copy into hold register
+;
+;
+;	movf	hi,W						; Gas 0-4
+;	mullw	d'4'
+;	movf	PRODL,W			
+;	addlw	d'6'						; = address for O2 ratio
+;	movwf	EEADR
+;	call	read_eeprom					; Read O2 ratio
+;	
+;	movff	char_I_deco_He_ratio, wait_temp	; copy into bank1 register
+;	bsf		STATUS,C					; Borrow bit
+;	movlw	d'100'						; 100%
+;	subfwb	wait_temp,W					; minus He
+;	bsf		STATUS,C					; Borrow bit
+;	subfwb	EEDATA,F					; minus O2
+;	movff	EEDATA, char_I_deco_N2_ratio	; = N2!
+;	bra		skip_decompression_gases
+;
 reset_decompression_gases:				; reset the deco gas while in NDL
 	ostc_debug	'F'		; Sends debug-information to screen if debugmode active
   	clrf	lo
@@ -519,6 +589,9 @@
 
 	bcf		LED_red						; LEDr off (Marker)
 
+	btfsc	simulatormode_active		; Are we in simulator mode?
+	return								; Yes, discard everything
+
 	btfsc	header_stored				; Header already stored?
 	bra	store_dive_data2				; Yes, store only profile data
 	bsf		header_stored				; Store header
@@ -1047,6 +1120,9 @@
 	btfss	realdive					; dive longer then one minute
 	goto	end_dive_common				; No, discard everything
 
+	btfsc	simulatormode_active		; Are we in simulator mode?
+	goto	end_dive_common				; Yes, discard everything
+
 	; Dive finished (and longer then one minute or Apnoe timeout occured)
 
 	btfsc	FLAG_apnoe_mode			; Calc max. depth (again) for very short apnoe dives
@@ -1298,9 +1374,10 @@
 
 change_logbook_offset2:
 	bcf		LED_blue
+
+end_dive_common:
 	bcf		simulatormode_active		; if we were in simulator mode
 
-end_dive_common:
 	btfsc	restore_deco_data			; Restore decodata?
 	call	simulator_restore_tissue_data		; Yes!