Mercurial > public > hwos_code
diff src/simulator.asm @ 560:b7eb98dbd800
bump to 2.96beta (REFACTORED VERSION)
author | heinrichsweikamp |
---|---|
date | Wed, 31 Jan 2018 19:39:37 +0100 |
parents | 7c408bfaf2e8 |
children | b455b31ce022 |
line wrap: on
line diff
--- a/src/simulator.asm Wed Dec 27 14:34:11 2017 +0100 +++ b/src/simulator.asm Wed Jan 31 19:39:37 2018 +0100 @@ -1,6 +1,6 @@ ;============================================================================= ; -; File simulator.asm +; File simulator.asm REFACTORED VERSION V2.95a1 ; ; Decoplan interface to C model code. ; @@ -9,7 +9,7 @@ ; HISTORY ; 2011-07-09 : [jDG] Creation... -#include "hwos.inc" ; Mandatory include. +#include "hwos.inc" ; Mandatory include #include "convert.inc" ; output_* #include "shared_definitions.h" ; Mailbox from/to p2_deco.c #include "strings.inc" ; STRCPY,... @@ -28,335 +28,152 @@ extern deco_push_tissues_to_vault extern deco_calc_dive_interval extern deco_calc_hauptroutine - extern deco_calc_tissue - extern deco_calc_CNS_fraction - extern deco_calc_CNS_planning extern deco_pull_tissues_from_vault extern TFT_display_decotype_surface1 + extern get_first_dil_to_WREG + extern get_first_gas_to_WREG + extern setup_dil_registers + extern setup_gas_registers + extern deco_setup_cc_diluents + extern deco_setup_oc_gases + extern log_screendump_and_onesecond, logbook_preloop_tasks extern do_planner_menu ;---- Private temp variables ------------------------------------------------- - CBLOCK tmp+0x12 ; Reserved space for wordprocessor and convert - decoplan_index ; within each page - decoplan_gindex ; global index - decoplan_last ; Depth of last stop (CF#29) - decoplan_flags ; Various private flags. - decoplan_CNS:2 ; Backup CNS before vault restore - decoplan_page ; page number - ; Reserved to tmp+0x18... - ENDC -#define decoplan_last_ceiling_shown decoplan_flags,0 -;---- Demo decoplanner ------------------------------------------------------- - global do_demo_planner + CBLOCK tmp+0x12 ; Reserved space for word processor and convert + decoplan_index ; within each page + decoplan_gindex ; global index + decoplan_last ; Depth of last stop (CF#29) + decoplan_flags ; Various private flags. + decoplan_page ; page number + decoplan_warnings ; deco engine warnings (ex reserved to tmp+0x18...) + ENDC + +;---- Defines ---------------------------------------------------------------- + +#define decoplan_last_ceiling_shown decoplan_flags,0 +#define decoplan_abort decoplan_flags,1 + +;---- Demo deco planner ------------------------------------------------------ + global do_demo_planner do_demo_planner: - btfsc FLAG_gauge_mode ; =1: In Gauge mode - goto do_planner_menu - btfsc FLAG_apnoe_mode ; =1: In Apnea mode - goto do_planner_menu -; call deco_reset ; TODO: remove reset all Decodata - rcall deco_planer - rcall deco_show_plan - goto do_planner_menu - -;============================================================================= -; Pass all parameters to the C code -; + btfsc FLAG_gauge_mode ; =1: In Gauge mode + goto do_planner_menu + btfsc FLAG_apnoe_mode ; =1: In Apnea mode + goto do_planner_menu + bcf decoplan_abort ; initialize (clear) abort flag + bcf is_bailout ; clear bailout condition (may have remained set from last invocation) + rcall deco_planer + btfss decoplan_abort ; skip recall deco_show_plan if calculations were aborted + rcall deco_show_plan + goto do_planner_menu - global get_first_dil_to_WREG -get_first_dil_to_WREG: ; Gets first dil (0-4) into WREG - lfsr FSR1,opt_dil_type ; Point to dil types - clrf lo ; start with Gas0 -get_first_dil_to_WREG2: - movf lo,W ; - movf PLUSW1,W ; Get Type of Dil #lo - sublw .1 ; it is = 1 (First Dil) - bz get_first_dil_to_WREG3 ; Found the first dil! - incf lo,F ; ++ - movlw NUM_GAS+1 - cpfseq lo ; All done? - bra get_first_dil_to_WREG2 ; Not yet - ; No first dil found, use #1 - movlw .0 - movff WREG,opt_dil_type+0 ; Set Dil1 to First - return -get_first_dil_to_WREG3: - movf lo,W ; Put into Wreg - return ; Done - global get_first_gas_to_WREG -get_first_gas_to_WREG: ; Gets first gas (0-4) into WREG - lfsr FSR1,opt_gas_type ; Point to gas types - clrf lo ; start with Gas0 -get_first_gas_to_WREG2: - movf lo,W ; - movf PLUSW1,W ; Get Type of Gas #lo - sublw .1 ; it is = 1 (First Gas) - bz get_first_gas_to_WREG3 ; Found the first gas! - incf lo,F ; ++ - movlw NUM_GAS+1 - cpfseq lo ; All done? - bra get_first_gas_to_WREG2 ; Not yet - ; No first gas found, use #1 - movlw .0 - movff WREG,opt_gas_type+0 ; Set Gas1 to First - return -get_first_gas_to_WREG3: - movf lo,W ; Put into Wreg - return ; Done - + global deco_setup deco_setup: - banksel char_I_step_is_1min ; Select the right bank... - clrf char_I_step_is_1min ; Default to 2sec steps. - - ; Fixed ambient surface pressure to 1bar. - movlw LOW(.1000) - movwf int_I_pres_surface+0 - movwf int_I_pres_respiration+0 - movlw HIGH(.1000) - movwf int_I_pres_surface+1 - movwf int_I_pres_respiration+1 - - clrf int_I_divemins+0 ; Dive start - clrf int_I_divemins+1 + banksel common + btfsc FLAG_ccr_mode + bra deco_setup_cc + btfsc FLAG_pscr_mode + bra deco_setup_cc +deco_setup_oc: + call get_first_gas_to_WREG ; gets first gas (1-5) into WREG + call setup_gas_registers ; with WREG=Gas 1-5 + call deco_setup_oc_gases ; setup OC/Bailout Gases and configure for OC deco calculation + bra deco_setup_cont +deco_setup_cc: + call get_first_dil_to_WREG ; gets first gas (1-5) into WREG + call setup_dil_registers ; with WREG=Gas 1-5 + call deco_setup_cc_diluents ; setup CCR/pSCR diluents and configure for CCR/pSCR deco calculation +deco_setup_cont: + ; use ambient conditions for simulation ## V2.94 + #include "isr.inc" + SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ; copy surface pressure to deco routine - banksel common ; Bank1 - bcf use_agf ; =1: Use aGF - - rcall deco_setup_dive - - movlw .0 ; Bank safe "clrf" - movff WREG,char_I_const_ppO2 ; deactivate CCR-mode in deco calculations unless in CCR mode (char_I_const_ppO2 is filled below again) - - ; Setup char_I_const_ppO2 for CC modes - btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active - movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; Setup fixed Setpoint (Always start with SP1) - rcall get_first_gas_to_WREG ; Gets first gas (0-4) into WREG - - ; Overwrite WREG in CCR and PSCR Mode - btfsc FLAG_ccr_mode - rcall get_first_dil_to_WREG - btfsc FLAG_pscr_mode - rcall get_first_dil_to_WREG - - incf WREG ; 1-5 - movff WREG,char_I_first_gas ; Copy for compatibility - decf WREG ; 0-4 - extern setup_gas_registers - call setup_gas_registers ; With WREG=Gas 0-4, set current N2/He/O2 ratios. - extern set_actual_ppo2 - goto set_actual_ppo2 ; Then configure char_I_actual_ppO2 (For CNS) (And return!) - - global deco_setup_dive -deco_setup_dive: ; Called from divemode - banksel common ; Bank1 - - btfsc is_bailout - bra deco_setup_dive_oc - btfsc FLAG_ccr_mode - bra deco_setup_dive_cc - btfsc FLAG_pscr_mode - bra deco_setup_dive_cc - -deco_setup_dive_oc: - rcall deco_setup_oc_gases ; Setup OC/Bailout Gases - bra deco_setup_dive_cont -deco_setup_dive_cc: - rcall deco_setup_cc_diluents ; Setup CC Diluents -deco_setup_dive_cont: - - movff divemins+0,int_I_divemins+0 ; Current dive time. - movff divemins+1,int_I_divemins+1 - - movlw deco_distance - movff WREG,char_I_deco_distance - movff opt_last_stop,char_I_depth_last_deco - movff opt_GF_low,char_I_GF_Low_percentage - movff opt_GF_high,char_I_GF_High_percentage - ;Overwrite GF if aGF is wanted - btfsc use_agf ; =1: Use aGF - movff opt_aGF_low,char_I_GF_Low_percentage - btfsc use_agf ; =1: Use aGF - movff opt_aGF_high,char_I_GF_High_percentage - return - -deco_setup_cc_diluents: - movff opt_dil_He_ratio+0,char_I_deco_He_ratio+0 - movff char_I_deco_He_ratio+0,lo - movff opt_dil_O2_ratio+0,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+0 - movff opt_dil_type+0,WREG ; 0=Disabled, 1=First, 2=Normal - tstfsz WREG ; Disabled? - bra $+4 ; No - movff WREG,char_I_dil_change+0 ; Yes, clear char_I_deco_gas_change (Bank safe) + movlw deco_distance + movff WREG,char_I_deco_distance - movff opt_dil_He_ratio+1,char_I_deco_He_ratio+1 - movff char_I_deco_He_ratio+1,lo - movff opt_dil_O2_ratio+1,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+1 - movff opt_dil_type+1,WREG ; 0=Disabled, 1=First, 2=Normal - tstfsz WREG ; Disabled? - bra $+4 ; No - movff WREG,char_I_dil_change+1 ; Yes, clear char_I_dil_change - - movff opt_dil_He_ratio+2,char_I_deco_He_ratio+2 - movff char_I_deco_He_ratio+2,lo - movff opt_dil_O2_ratio+2,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+2 - movff opt_dil_type+2,WREG ; 0=Disabled, 1=First, 2=Normal - tstfsz WREG ; Disabled? - bra $+4 ; No - movff WREG,char_I_dil_change+2 ; Yes, clear char_I_dil_change + movff opt_last_stop,char_I_depth_last_deco + movff opt_GF_low,char_I_GF_Low_percentage + movff opt_GF_high,char_I_GF_High_percentage + + ; overwrite GF if aGF is wanted + bsf use_agf + TSTOSS opt_sim_use_aGF + bcf use_agf - movff opt_dil_He_ratio+3,char_I_deco_He_ratio+3 - movff char_I_deco_He_ratio+3,lo - movff opt_dil_O2_ratio+3,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+3 - movff opt_dil_type+3,WREG ; 0=Disabled, 1=First, 2=Normal - tstfsz WREG ; Disabled? - bra $+4 ; No - movff WREG,char_I_dil_change+3 ; Yes, clear char_I_dil_change - - movff opt_dil_He_ratio+4,char_I_deco_He_ratio+4 - movff char_I_deco_He_ratio+4,lo - movff opt_dil_O2_ratio+4,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+4 - movff opt_dil_type+4,WREG ; 0=Disabled, 1=First, 2=Normal - tstfsz WREG ; Disabled? - bra $+4 ; No - movff WREG,char_I_dil_change+4 ; Yes, clear char_I_dil_change - - ; Setup char_I_deco_gas_change array - movff char_I_dil_change+0, char_I_deco_gas_change+0 - movff char_I_dil_change+1, char_I_deco_gas_change+1 - movff char_I_dil_change+2, char_I_deco_gas_change+2 - movff char_I_dil_change+3, char_I_deco_gas_change+3 - movff char_I_dil_change+4, char_I_deco_gas_change+4 - return - -deco_setup_oc_gases: - movff opt_gas_He_ratio+0,char_I_deco_He_ratio+0 - movff char_I_deco_He_ratio+0,lo - movff opt_gas_O2_ratio+0,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+0 - banksel opt_gas_type+0 - movlw .3 ; 3=Deco - cpfseq opt_gas_type+0 ; Gas is deco type? - clrf opt_OC_bail_gas_change+0 ; No, clear depth for 0=Disabled, 1=First and 2=Travel - banksel common + btfsc use_agf ; =1: Use aGF + movff opt_aGF_low,char_I_GF_Low_percentage + btfsc use_agf ; =1: Use aGF + movff opt_aGF_high,char_I_GF_High_percentage - movff opt_gas_He_ratio+1,char_I_deco_He_ratio+1 - movff char_I_deco_He_ratio+1,lo - movff opt_gas_O2_ratio+1,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+1 - banksel opt_gas_type+1 - movlw .3 ; 3=Deco - cpfseq opt_gas_type+1 ; Gas is deco type? - clrf opt_OC_bail_gas_change+1 ; No, clear depth for 0=Disabled, 1=First and 2=Travel - banksel common - - movff opt_gas_He_ratio+2,char_I_deco_He_ratio+2 - movff char_I_deco_He_ratio+2,lo - movff opt_gas_O2_ratio+2,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+2 - banksel opt_gas_type+2 - movlw .3 ; 3=Deco - cpfseq opt_gas_type+2 ; Gas is deco type? - clrf opt_OC_bail_gas_change+2 ; No, clear depth for 0=Disabled, 1=First and 2=Travel - banksel common - - movff opt_gas_He_ratio+3,char_I_deco_He_ratio+3 - movff char_I_deco_He_ratio+3,lo - movff opt_gas_O2_ratio+3,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+3 - banksel opt_gas_type+3 - movlw .3 ; 3=Deco - cpfseq opt_gas_type+3 ; Gas is deco type? - clrf opt_OC_bail_gas_change+3 ; No, clear depth for 0=Disabled, 1=First and 2=Travel - banksel common - - movff opt_gas_He_ratio+4,char_I_deco_He_ratio+4 - movff char_I_deco_He_ratio+4,lo - movff opt_gas_O2_ratio+4,WREG - addwf lo,W ; O2 + He -> WREG - sublw .100 ; 100 - (O2 + He) -> WREG - movff WREG,char_I_deco_N2_ratio+4 - banksel opt_gas_type+4 - movlw .3 ; 3=Deco - cpfseq opt_gas_type+4 ; Gas is deco type? - clrf opt_OC_bail_gas_change+4 ; No, clear depth for 0=Disabled, 1=First and 2=Travel - banksel common - - movlw .0 - movff WREG,char_I_const_ppO2 ; Clear constant ppO2 for OC/bailout - - ; Setup char_I_deco_gas_change array - movff opt_OC_bail_gas_change+0, char_I_deco_gas_change+0 - movff opt_OC_bail_gas_change+1, char_I_deco_gas_change+1 - movff opt_OC_bail_gas_change+2, char_I_deco_gas_change+2 - movff opt_OC_bail_gas_change+3, char_I_deco_gas_change+3 - movff opt_OC_bail_gas_change+4, char_I_deco_gas_change+4 - return - + bcf is_bailout + + ; setup char_I_const_ppO2 for CC modes + clrf WREG + btfsc FLAG_pscr_mode + movff WREG,char_I_const_ppO2 ; configure pSCR computations to calculated ppO2 + btfss FLAG_ccr_mode + return ; done if not in CCR mode + movff opt_sim_setpoint_number,WREG ; configure CCR computations to selected setpoint + decf WREG,W ; 1-5 -> 0-4 + lfsr FSR1,char_I_setpoint_cbar ; load base address of setpoint list + movff PLUSW1,char_I_const_ppO2 ; setup setpoint + return + ;============================================================================= -; Reset decompression tissues +; Launch deco planning ; - global deco_reset -deco_reset: - rcall deco_setup ; Setup all model parameters. - call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio - call deco_clear_CNS_fraction ; Reset CNS value. - banksel common ; Bank1 - return - -;============================================================================= -; Launch decoplanning -; - global deco_planer + global deco_planer deco_planer: - call speed_fastest ; Quick ! - rcall deco_setup ; Setup all model parameters. - call deco_push_tissues_to_vault - banksel common ; Bank1 + call speed_fastest ; Quick ! + call deco_push_tissues_to_vault + rcall deco_setup ; Setup all model parameters. ;---- Specific settings ------------------------------------------------------ + + ; configure the deco engine for normal plan, CNS & gas volume calculation and no delayed ascent + movff char_O_deco_status,WREG ; bank-safe copy + bcf WREG,DECO_PLAN_FLAG ; normal plan mode, + bsf WREG,DECO_CNS_FLAG ; enable CNS calculation (CNS at end of dive), + bsf WREG,DECO_VOLUME_FLAG ; enable gas volume calculation, and + bcf WREG,DECO_ASCENT_FLAG ; disable delayed ascent calculation + movff WREG,char_O_deco_status ; bank-safe copy back + + ; configure the deco engine for total-dive gas volume calculation + movff char_O_main_status,WREG ; bank-safe copy + bsf WREG,DECO_BOTTOM_FLAG ; set bottom flag + movff WREG,char_O_main_status ; bank-safe copy back + deco_planer_redo: - banksel char_O_deco_status ; Bank 2 - movlw .3 ; Start in surface state. - movwf char_O_deco_status - - banksel char_I_step_is_1min ; Bank 3 - movlw 1 - movwf char_I_step_is_1min ; Set 1min steps + + ; show deco calculation is in progress + call TFT_ClearScreen + WIN_COLOR color_greenish + TEXT_SMALL .20,.40, tCalculating + WIN_COLOR color_lightblue + WIN_SMALL .1,.215 + STRCPY_TEXT_PRINT tAbort + + ; configure the deco engine for restart: + movff char_O_deco_status,WREG ; bank-safe copy + bsf WREG,DECO_STATUS_0_FLAG ; configure init ... + bsf WREG,DECO_STATUS_1_FLAG ; ... state, + movff WREG,char_O_deco_status ; bank-safe copy back ;---- Add delay at surface, if needed ---------------------------------------- + + banksel char_I_dive_interval tstfsz char_I_dive_interval call deco_calc_dive_interval ;---- Dive loop -------------------------------------------------------------- - ; Compute dive ambiant conditions + ; Compute dive ambient conditions banksel char_I_bottom_depth movf char_I_bottom_depth,W mullw .100 @@ -366,90 +183,94 @@ movlw HIGH(.1000) addwfc PRODH,W movwf int_I_pres_respiration+1 + + banksel common - banksel int_I_divemins ; Bank 4 - clrf int_I_divemins+0 ; Clear dive time - clrf int_I_divemins+1 + movff char_I_bottom_time,char_I_sim_advance_time + + clrf TMR5L + clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H - clrf TMR5L - clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H - call deco_calc_hauptroutine ; Reset + simulate first min. + call deco_calc_hauptroutine ; initialization + complete bottom time part + banksel common + +;---- BAILOUT: Switch to OC gases for ascent cycles -------------------------- -deco_planer_loop: - banksel int_I_divemins ; Bank 3 - incf int_I_divemins,F ; Done 1 min. - btg LEDg - - movf char_I_bottom_time,W ; Finished ? - xorwf int_I_divemins,W - bz deco_planer_endloop ; YES + btfss is_bailout ; Doing a bailout deco plan ? + bra deco_planer_finishing ; NO - keep gases + ; YES - switch to OC gas - call deco_calc_tissue ; JUST calc tissue (faster). - call deco_calc_CNS_fraction ; Also calculate CNS (in 1min loop) - bra deco_planer_loop + ; reconfigure the deco engine for delayed ascent mode + movff char_O_deco_status,lo ; bank-safe copy + bsf lo,DECO_ASCENT_FLAG ; set flag for delayed ascent calculation + movff lo,char_O_deco_status ; bank-safe copy back + + ; configure the deco engine for delayed ascent part gas volume calculation + movff char_O_main_status,WREG ; bank-safe copy + bcf WREG,DECO_BOTTOM_FLAG ; set bottom flag + movff WREG,char_O_main_status ; bank-safe copy back -deco_planer_endloop: - banksel char_I_step_is_1min - clrf char_I_step_is_1min ; Back to 2sec loops + ; reconfigure gas settings to OC gases + call get_first_gas_to_WREG ; get first gas (1-5) into WREG + call setup_gas_registers ; With WREG=Gas 1-5 (or 6, not applicable here) + call deco_setup_oc_gases ; With WREG=Gas 1-5 (or 6, not applicable here) + + ; set the gas change override flag to allow gas changes before deco stops as done in alternative plan + movff char_O_main_status,lo ; bank-safe copy + bsf lo,DECO_GASCHANGE_OVRD ; set flag for gas change override + movff lo,char_O_main_status ; bank-safe copy back + +;---- Wait until status reaches zero ------------------------------------------- -;---- BAILOUT: Switch to OC gases for ascent cycles -------------------------- - banksel common - btfss is_bailout ; Doing a bailout decoplan ? - bra deco_planer_finishing ; NO: keep gases - - rcall deco_setup_oc_gases ; Switch to OC gas and no const_ppO2 - - movlw .0 - movff WREG,char_I_const_ppO2 ; deactivate CCR-mode deco calculations - -;---- Wait until status reach zero ------------------------------------------- deco_planer_finishing: - btg LEDg -; clrf TMR5L -; clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H - call deco_calc_hauptroutine ; Simulate 2sec more - - banksel char_O_deco_status ; Bank 2 - movf char_O_deco_status,W - bnz deco_planer_finishing + call deco_calc_hauptroutine ; Simulate more dive time to trigger the deco calculations + banksel common + + btfss switch_left ; check if left button was pressed + bra deco_planer_finishing_1 ; NO - continue calculations + bsf decoplan_abort ; YES - set abort flag so that deco_show_plan will not be called + bra deco_planer_finishing_2 ; do some clean-up and return +deco_planer_finishing_1: + movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common + movlw DECO_STATUS_MASK ; bit mask for deco status bit set + andwf lo,W ; mask out bits showing state of computation + tstfsz WREG ; check if a compute cycle is finished (bits 1 and 0 == 0) + bra deco_planer_finishing ; NO - needs more computation cycles ;---- Done: add CNS from decoplan, and restore tissues - call deco_calc_CNS_planning - movff int_O_CNS_fraction+0,decoplan_CNS+0 - movff int_O_CNS_fraction+1,decoplan_CNS+1 - call deco_pull_tissues_from_vault - bcf LEDg - banksel common ; Bank1 - movlw b'00111000' ; 1:8 Prescaler -> 65,536ms@16MHz - movwf T3CON - call speed_normal - return + +deco_planer_finishing_2: + + movff char_O_deco_warnings,decoplan_warnings ; copy warnings + + call deco_pull_tissues_from_vault ; restore "real" deco data + banksel common ; back to bank 1 + + movlw b'00111000' ; 1:8 Prescaler -> 65,536ms@16MHz + movwf T3CON + goto speed_normal ;(and return) ;----------------------------------------------------------------------------- ; Draw a stop of the deco plan (simulator or dive). ; Inputs: lo = depth. Range 3m...93m -; + 80 if this is a switch-gas stop. +; + 0x80 if this is a switch-gas stop. ; up = minutes. range 1'..240'. ; win_top = line to draw on screen. ; Trashed: up, lo, win_height, win_leftx2, win_width, win_color*, ; WREG, PROD, TBLPTR TABLAT. ; deco_plan_show_stop: - ;---- Print depth ---------------------------------------------------- - btfss lo,7 ; Bit set ? - bra deco_plan_show_std_stop ; No : Just an usual stop. - call TFT_attention_color - bcf lo,7 ; and cleanup depth. - bra deco_plan_show_nstd_stop + ;---- Print depth ---------------------------------------------------- + bcf lo,7 ; clear gas-switch flag (not used any more anyhow) + lfsr FSR2,char_O_deco_gas + movf decoplan_gindex,W ; index + movff PLUSW2,WREG ; get current gas + rcall simulator_color_gas ; set output color dependent on gas (1-5) -deco_plan_show_std_stop: - call TFT_standard_color - -deco_plan_show_nstd_stop: lfsr FSR2,buffer - TSTOSS opt_units ; 0=Meters, 1=Feets + TSTOSS opt_units ; 0=Meters, 1=Feets bra deco_plan_show_nstd_stop_metric WIN_LEFT .85 @@ -457,7 +278,7 @@ mullw .100 ; PRODL:PRODH = mbar movff PRODL,lo movff PRODH,hi -; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops... + ; Convert with 334feet/100m to have 10ft, 20ft, 30ft stops... movff lo,xA+0 movff hi,xA+1 movlw LOW d'334' ; 334feet/100m @@ -480,6 +301,7 @@ bsf leftbind bsf ignore_digit4 ; Only full feet output_16 + bcf leftbind STRCAT_PRINT "ft " bra deco_plan_show_nstd_stop_common @@ -487,6 +309,7 @@ WIN_LEFT .90 bsf leftbind output_8 ; outputs into Postinc2! + bcf leftbind STRCAT_PRINT "m " deco_plan_show_nstd_stop_common: ;---- Print duration ------------------------------------------------- @@ -508,7 +331,7 @@ movwf up ;--------------------------------------------------------------------- - ; Draw the bar graph used for deco stops (decoplan in simulator or dive). + ; Draw the bar graph used for deco stops (deco plan in simulator or dive). incf win_top,F movlw .19 movwf win_height @@ -516,7 +339,7 @@ movwf win_leftx2 ; column left (0-159) movlw .16 movwf win_width+0 ; column max width. - clrf win_width+1 + clrf win_width+1 ; Draw used area (up = minutes): movlw .16 ; Limit length (16min) @@ -531,25 +354,25 @@ return ;----------------------------------------------------------------------------- -; Clear unused area belw last stop +; Clear unused area below last stop ; Inputs: win_top : last used area... deco_plan_show_clear_bottom: movf win_top,W ; Get back from bank0 sublw .239 ; No: bottom row in planning movwf win_height - WIN_LEFT .85 ; Full divemenu width + WIN_LEFT .85 ; Full dive menu width movlw .159-.85+1 movwf win_width+0 - clrf win_width+1 + clrf win_width+1 clrf win_color1 ; Fill with black clrf win_color2 - goto TFT_box ; and return + goto TFT_box ; and return ;----------------------------------------------------------------------------- -; Display the decoplan (simulator). +; Display the deco plan (simulator). ; Inputs: char_O_deco_table (array of stop times, in minutes) ; decoplan_page = page number. ; @@ -576,7 +399,7 @@ ; Read stop parameters, indexed by decoplan_index and decoplan_page movf decoplan_page,W ; decoplan_gindex = 6*decoplan_page + decoplan_index - mullw .8 ; 8 lines/page in decoplan + mullw .8 ; 8 lines/page in deco plan movf decoplan_index,W addwf PRODL,W movwf decoplan_gindex ; --> decoplan_gindex @@ -599,19 +422,19 @@ ; Next movlw .24 - addwf win_top,F ; row: += 24 - incf decoplan_index,F ; local index += 1 - incf decoplan_gindex,F ; global index += 1 + addwf win_top,F ; row: += 24 + incf decoplan_index,F ; local index += 1 + incf decoplan_gindex,F ; global index += 1 ; Max number of lines/page reached ? - movlw .8 ; 8 lines/page in decoplan + movlw .8 ; 8 lines/page in deco plan cpfseq decoplan_index - bra deco_plan_show_2 ; NO: loop + bra deco_plan_show_2 ; NO: loop - ; Check if next stop if end-of-list ? + ; Check if next stop is end-of-list ? movf decoplan_gindex,W - movf PLUSW0,W ; char_O_deco_depth[gindex] - bz deco_plan_show_99 ; End of list... + movf PLUSW0,W ; char_O_deco_depth[gindex] + bz deco_plan_show_99 ; End of list... ; Display the message "more..." rcall deco_plan_show_clear_bottom ; Clear from next line @@ -626,33 +449,35 @@ return ;----------------------------------------------------------------------------- -; Loop to show all pages of the decoplan (surfacemode) +; Loop to show all pages of the deco plan (surface mode) global deco_show_plan deco_show_plan: clrf decoplan_page call TFT_ClearScreen WIN_COLOR color_greenish - btfsc is_bailout - bra deco_show_plan_bail_title + btfsc is_bailout + bra deco_show_plan_bail_title TEXT_SMALL .1,.1, tDivePlan - bra deco_show_plan2 + bra deco_show_plan2 deco_show_plan_bail_title: - TEXT_SMALL .1,.1, tDiveBailout + TEXT_SMALL .1,.1, tDiveBailout deco_show_plan2: - call TFT_standard_color - ; Show plan parameters + call TFT_standard_color + ;---- Display Plan Parameters WIN_SMALL .0,.25 STRCPY "Int:" movff char_I_dive_interval,lo bsf leftbind output_8 + bcf leftbind STRCAT_PRINT "'" WIN_SMALL .0,.50 STRCPY_TEXT tBtTm_short movff char_I_bottom_time,lo bsf leftbind output_8 + bcf leftbind STRCAT_PRINT "'" WIN_SMALL .0,.75 STRCPY_TEXT tDepth @@ -660,52 +485,84 @@ movff char_I_bottom_depth,lo bsf leftbind output_8 + bcf leftbind STRCAT_PRINT "m" + + WIN_SMALL .0,.105 ; set position for warnings or sat/dsat factors + + ;---- Check for Stop Table Overflow + btfss decoplan_warnings,stoptable_overflow ; check if we have a overflow warning + bra deco_show_plan2a ; NO - skip + ;---- Display Overflow warning + call TFT_warnings_color ; YES - show overflow warning + STRCAT_PRINT "incomplete" ; max 10 characters + bra deco_show_plan_m1 ; skip displaying sat/dsat factors - ; Show deco mode - WIN_TOP .155 - lfsr FSR2,buffer - movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR - call TFT_display_decotype_surface1 - - ;---- Display model - movff char_I_deco_model,WREG - iorwf WREG - bnz deco_show_plan_m1 - - ; Display ZH-L16 sat/desat model. - TEXT_SMALL .0,.130, tZHL16 - WIN_SMALL .14,.155 - PUTC "," +deco_show_plan2a: + ;---- Check for IBCD Warning + btfss decoplan_warnings,IBCD_warning_lock ; check if we have a locked IBCD warning + bra deco_show_plan2b ; NO - skip + ;---- Display IBCD warning + call TFT_attention_color ; YES - show IBCD warning + STRCAT_PRINT "IBCD!" ; max 10 characters + bra deco_show_plan_m1 ; skip displaying sat/dsat factors + +deco_show_plan2b: + ;---- Display Sat/Desat Factors --> is skipped if there were warnings + STRCAT_PRINT "SD:" + WIN_SMALL .25,.105 + movff char_I_saturation_multiplier,lo + output_8 + STRCAT "/" movff char_I_desaturation_multiplier,lo output_8 - STRCAT "%/" - movff char_I_saturation_multiplier,lo - output_8 - bra deco_show_plan_m2 + STRCAT_PRINT "" + +deco_show_plan_m1: + call TFT_standard_color ; clean-up from warnings - ; Display ZH-L16-GF low/high model. -deco_show_plan_m1: - TEXT_SMALL .0,.130, tZHL16GF - WIN_SMALL .14,.155 - PUTC "," + ;---- Get Model + movff char_I_deco_model,WREG + iorwf WREG + bz deco_show_plan_m2 + + ;---- Display GF low/high values + WIN_SMALL .0,.130 + STRCAT_PRINT "GF:" + WIN_SMALL .25,.130 movff char_I_GF_Low_percentage,lo output_99x - STRCAT "%/" + STRCAT "/" movff char_I_GF_High_percentage,lo output_99x + STRCAT_PRINT "" + deco_show_plan_m2: - STRCAT_PRINT "%" + ;---- Display Deco Mode + WIN_SMALL .0,.155 + lfsr FSR2,buffer + movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR + call TFT_display_decotype_surface1 + btfss FLAG_ccr_mode ; current dive mode = CCR ? + bra deco_show_plan2c ; NO - branch + WIN_SMALL .25,.155 + STRCPY "SP:" ; output setpoint used for calculation + movff opt_sim_setpoint_number,lo + bsf leftbind + output_8 + bcf leftbind + STRCAT_PRINT "" +deco_show_plan2c: ;---- Display TTS result WIN_SMALL .0,.180 STRCPY_TEXT tTTS STRCAT ": " - movff int_O_ascenttime+0,lo movff int_O_ascenttime+1,hi bsf leftbind output_16 + bcf leftbind STRCAT_PRINT "'" ;---- Display CNS result @@ -713,25 +570,34 @@ STRCPY_TEXT tCNS2 ; "CNS:" movff int_O_CNS_fraction+0,lo movff int_O_CNS_fraction+1,hi - output_16_3 ; limit to 999 and display only (0-999) - STRCAT "%\x92" ; "->" - movff decoplan_CNS+0,lo - movff decoplan_CNS+1,hi - output_16_3 ; limit to 999 and display only (0-999) + TFT_color_code warn_cns ; Color-code CNS output + bsf leftbind + output_16_3 ; limit to 999 and display only (0-999) + bcf leftbind + STRCAT "%\x92" ; "->" + movff int_O_normal_CNS_fraction+0,lo + movff int_O_normal_CNS_fraction+1,hi + TFT_color_code warn_cns ; Color-code CNS output + bsf leftbind + output_16_3 ; limit to 999 and display only (0-999) + bcf leftbind STRCAT_PRINT "%" + call TFT_standard_color ;---- Loop through pages deco_show_plan_1: + ; Clear the complete stop result column: + WIN_BOX_BLACK .0, .239, .80, .159 ; top, bottom, left, right + rcall deco_show_plan_page incf decoplan_page,F - call logbook_preloop_tasks deco_show_plan_2: btfsc switch_right bra deco_show_plan_3 btfsc switch_left return ; Return to simulator menu - call log_screendump_and_onesecond ; Check if we need to make a screenshot and check for new second + call log_screendump_and_onesecond ; Check if we need to make a screen shot and check for new second btfsc sleepmode ; Timeout? goto restart bra deco_show_plan_2 @@ -740,35 +606,24 @@ btfss decoplan_last_ceiling_shown bra deco_show_plan_1 ; All stops shown - -;---- In CCR mode, compute a BAILOUT decoplan --------------------------------- - banksel common - btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active - bra simulator_show_decoplan5_0 ; NO: normal OC mode: just display + +;---- In CCR and pSCR mode, compute a BAILOUT deco plan ----------------------- - btfsc is_bailout ; ALREADY in bailout mode ? - bra simulator_show_decoplan5_0 ; YES: alreay BAIL plan: display gas - -; Redo 2nd deco-plann, in bailout mode: - bsf is_bailout ; Set special bailout mode. - rcall deco_planer_redo ; Redo plan computation + banksel common + movff char_O_deco_status,WREG ; get deco calculation status + btfss WREG,DECO_MODE_LOOP_FLAG ; check if in CCR or pSCR mode + bra simulator_show_decoplan5_0 ; NO - normal OC mode: just display + bsf is_bailout ; YES - redo 2nd deco-plan in bailout mode + rcall deco_planer_redo ; redo plan computation - movff char_I_setpoint_cbar+0,char_I_const_ppO2 - bra deco_show_plan ; and display bailout stops + btfss decoplan_abort ; shall we abort? + bra deco_show_plan ; NO - display bailout stops + return ; YES + ;---- In OC+BAIL modes, show the gas Usage special page ----------------------- simulator_show_decoplan5_0: - bcf is_bailout ; Back to normal - bcf ccr_diluent_setup ; init for OC/Bailout - - ; Make sure to pass first gas - call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG - incf WREG,f ; gas 1..5 - movff WREG,char_I_first_gas ; Copy for compatibility - - ; Compute gas consumption for each tank. - extern deco_gas_volumes - call deco_gas_volumes + movlb .1 ; Clear the complete stop result column: @@ -785,6 +640,10 @@ simulator_show_decoplan5_loop: movff wait_temp,PRODL ; Copy to PRODL first incf wait_temp,F ; Increment gas # + + movff wait_temp,WREG + rcall simulator_color_gas ; set output color according to gas (number 1-5 in WREG) + lfsr FSR2,buffer bsf short_gas_decriptions bsf divemode ; Tweak "customview_show_mix:" @@ -797,74 +656,86 @@ movff POSTINC0,lo ; Read (16bit) result, low first, movff POSTINC0,hi ; then high. - movf lo,W ; Null ? - iorwf hi,W - movf lo,W ; == 65535 (saturated ?) + movf lo,W andwf hi,W - incf WREG - bnz simulator_show_decoplan5_2 - call TFT_attention_color - STRCAT_PRINT ":xxxx.x" - call TFT_standard_color + incf WREG ; > 65535? + bnz simulator_show_decoplan5_2 ; NO + STRCAT_PRINT ">65500" ; YES bra simulator_show_decoplan5_1 simulator_show_decoplan5_2: PUTC ":" bsf leftbind - output_16 ; No decimal anymore. + output_16 ; No decimal anymore. bcf leftbind - STRCAT_PRINT "" ; No unit: can be bars or litters. + STRCAT_PRINT "" ; No unit: can be bars or litters. ; Loop for all 5 gas simulator_show_decoplan5_1: - movlw d'5' ; list all five gases - cpfseq wait_temp ; All gases shown? + movlw d'5' ; list all five gases + cpfseq wait_temp ; All gases shown? bra simulator_show_decoplan5_loop ; No WIN_COLOR color_greenish WIN_SMALL .80,.25 - -; btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active -; bra simulator_show_decoplan5_4 ; YES: This is bailout mode - - STRCPY_TEXT tGasUsage ; OC: "Gas Usage" -; bra simulator_show_decoplan5_5 - -;simulator_show_decoplan5_4: -; STRCPY_TEXT tDiveBailout ; CCR: "Bailout" - -;simulator_show_decoplan5_5: + STRCPY_TEXT tGasUsage ; OC: "Gas Usage" STRCAT_PRINT ":" call TFT_standard_color + call logbook_preloop_tasks - call logbook_preloop_tasks simulator_show_decoplan5_3: - btfsc switch_right + btfss switch_right + bra simulator_show_decoplan5_3a + bcf switch_right + clrf decoplan_page + bra deco_show_plan_1 ; toggle between stops plan and gas usage +simulator_show_decoplan5_3a: + btfss switch_left + bra simulator_show_decoplan5_4 + bcf is_bailout ; Back to normal + bcf ccr_diluent_setup ; init for OC/Bailout return ; Return to simulator menu - btfsc switch_left - return ; Return to simulator menu - call log_screendump_and_onesecond ; Check if we need to make a screenshot and check for new second + +simulator_show_decoplan5_4: + call log_screendump_and_onesecond ; Check if we need to make a screen shot and check for new second btfsc sleepmode ; Timeout? goto restart bra simulator_show_decoplan5_3 + +simulator_color_gas: ; set output color dependent on gas (1-5, in WREG) + movwf tft_temp1 ; used in TFT_set_color anyway + dcfsnz tft_temp1,F + movlw color_white ; color for Gas 1 + dcfsnz tft_temp1,F + movlw color_green ; color for Gas 2 + dcfsnz tft_temp1,F + movlw color_red ; Color for Gas 3 + dcfsnz tft_temp1,F + movlw color_yellow ; color for Gas 4 + dcfsnz tft_temp1,F + movlw color_cyan ; color for Gas 5 + goto TFT_set_color ; set color and return... + ;============================================================================= ; global do_demo_divemode do_demo_divemode: extern option_save_all - call option_save_all ; Save all settings into EEPROM before starting simulation + call option_save_all ; Save all settings into EEPROM before starting simulation call deco_push_tissues_to_vault - banksel common ; Bank1 - - bsf restore_deco_data ; Restore tissue and CNS after sim + banksel common ; Bank1 - bcf pressure_refresh - btfss pressure_refresh ; Wait for sensor - bra $-2 + ; +++ COMMENTED OUT FOR TESTING PURPOSE ONLY !!! +++ + ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++ + bsf restore_deco_data ; Restore tissue and CNS after simulator use - bsf simulatormode_active ; Set Flag + bcf pressure_refresh + btfss pressure_refresh ; Wait for sensor + bra $-2 + + bsf simulatormode_active ; Set Flag ; Compute dive ambient conditions banksel char_I_bottom_depth movf char_I_bottom_depth,W @@ -878,9 +749,9 @@ addwfc PRODH,W movff WREG,sim_pressure+1 - banksel common ; Bank1 + banksel common ; Bank1 bsf divemode - goto diveloop ; Switch into Divemode! + goto diveloop ; Switch into Divemode! END \ No newline at end of file