Mercurial > public > hwos_code
diff src/ghostwriter.asm @ 604:ca4556fb60b9
bump to 2.99beta, work on 3.00 stable
author | heinrichsweikamp |
---|---|
date | Thu, 22 Nov 2018 19:47:26 +0100 |
parents | 08a0162d3ca1 |
children | c40025d8e750 |
line wrap: on
line diff
--- a/src/ghostwriter.asm Thu Oct 11 21:06:29 2018 +0200 +++ b/src/ghostwriter.asm Thu Nov 22 19:47:26 2018 +0100 @@ -1,6 +1,6 @@ ;============================================================================= ; -; File ghostwriter.asm REFACTORED VERSION 2.98 +; File ghostwriter.asm REFACTORED VERSION V2.99a ; ; Ghostwriter (Log profile recorder) ; @@ -20,10 +20,12 @@ #include "divemode.inc" #include "rtc.inc" + extern deco_pull_tissues_from_vault + ;---- Private local variables ------------------------------------------------- - CBLOCK local2 ; max size is 16 Byte !!! + CBLOCK local3 ; max size is 16 Byte !!! divisor_temperature ; divisor used to time the sampling of dive data divisor_deco ; divisor used to time the sampling of dive data divisor_gf ; divisor used to time the sampling of dive data @@ -40,7 +42,7 @@ ;============================================================================= - global init_recording_params ; Initialize profile recording parameters + global init_recording_params ; initialize profile recording parameters init_recording_params: movff samplingrate,samplesecs_value; to avoid EEPROM access in the ISR movlw div_temperature @@ -57,7 +59,7 @@ movwf divisor_cns movlw div_tank movwf divisor_tank - btfss FLAG_apnoe_mode ; In Apnoe mode? + btfss FLAG_apnoe_mode ; in Apnoe mode? bra init_recording_params_1 ; NO movlw samplingrate_apnoe ; YES - overwrite some parameters in Apnoe mode movwf samplesecs_value ; to avoid EEPROM access in the ISR @@ -66,7 +68,7 @@ bra init_recording_params_2 ; YES btfsc FLAG_pscr_mode ; in pSCR mode? bra init_recording_params_2 ; YES - ; in OC Mode, disable ppO2 logging + ; in all modes but CCR and pSCR, disable ppO2 logging movlw .0 movwf divisor_ppo2_sensors init_recording_params_2: @@ -78,97 +80,97 @@ bcf store_sample ; clear flag ifndef __DEBUG - btfsc simulatormode_active ; Are we in simulator mode? - return ; Yes, discard everything + btfsc simulatormode_active ; are we in simulator mode? + return ; YES - discard everything endif - btfsc FLAG_apnoe_mode ; In Apnoe mode? - return ; Yes, discard everything + btfsc FLAG_apnoe_mode ; in Apnoe mode? + return ; YES - discard everything SAFE_2BYTE_COPY rel_pressure, lo movf lo,W ; store depth with every sample - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movf hi,W - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash -; First, find out how many bytes will append to this sample.... +; First, find out how many bytes will be appended to this sample set clrf ProfileFlagByte ; clear number of bytes to append ; Check Extended informations - decfsz divisor_temperature,W ; Check divisor + decfsz divisor_temperature,W ; check divisor bra check_extended1 movlw infolength_temperature addwf ProfileFlagByte,F ; add to ProfileFlagByte check_extended1: - decfsz divisor_deco,W ; Check divisor + decfsz divisor_deco,W ; check divisor bra check_extended2 movlw infolength_deco addwf ProfileFlagByte,F ; add to ProfileFlagByte check_extended2: - decfsz divisor_gf,W ; Check divisor + decfsz divisor_gf,W ; check divisor bra check_extended3 movlw infolength_gf addwf ProfileFlagByte,F ; add to ProfileFlagByte check_extended3: - decfsz divisor_ppo2_sensors,W ; Check divisor + decfsz divisor_ppo2_sensors,W ; check divisor bra check_extended4 movlw infolength_ppo2_sensors addwf ProfileFlagByte,F ; add to ProfileFlagByte check_extended4: - decfsz divisor_decoplan,W ; Check divisor + decfsz divisor_decoplan,W ; check divisor bra check_extended5 movlw infolength_decoplan addwf ProfileFlagByte,F ; add to ProfileFlagByte check_extended5: - decfsz divisor_cns,W ; Check divisor + decfsz divisor_cns,W ; check divisor bra check_extended6 movlw infolength_cns addwf ProfileFlagByte,F ; add to ProfileFlagByte check_extended6: - decfsz divisor_tank,W ; Check divisor + decfsz divisor_tank,W ; check divisor bra check_extended7 movlw infolength_tank addwf ProfileFlagByte,F ; add to ProfileFlagByte check_extended7: ; Second, check global event flag - btfss event_occured ; Check global event flag - bra store_dive_data3 ; No Event + btfss event_occured ; check global event flag + bra store_dive_data3 ; no event - incf ProfileFlagByte,F ; add one byte (The EventByte1) + incf ProfileFlagByte,F ; add one byte (the EventByte1) clrf EventByte1 ; reset EventByte1 clrf EventByte2 ; reset EventByte2 - movf AlarmType,W ; Type of Alarm Bit 0-3 - addwf EventByte1,F ; Copy to EventByte1 Bit 0-3 - clrf AlarmType ; Reset AlarmType + movf AlarmType,W ; type of Alarm Bit 0-3 + addwf EventByte1,F ; copy to EventByte1 Bit 0-3 + clrf AlarmType ; reset AlarmType ; Third, check events and add additional bytes - btfss gas6_changed ; Check flag + btfss gas6_changed ; check flag bra check_event2 - movlw d'2' ; Information length + movlw d'2' ; information length addwf ProfileFlagByte,F ; add to ProfileFlagByte - bsf EventByte1,4 ; Also set Flag in EventByte1! + bsf EventByte1,4 ; also set Flag in EventByte1! check_event2: - btfss stored_gas_changed ; Check flag + btfss stored_gas_changed ; check flag bra check_event3 - movlw d'1' ; Information length + movlw d'1' ; information length addwf ProfileFlagByte,F ; add to ProfileFlagByte - bsf EventByte1,5 ; Also set Flag in EventByte1! + bsf EventByte1,5 ; also set Flag in EventByte1! check_event3: - btfss setpoint_changed ; Check flag + btfss setpoint_changed ; check flag bra check_event4 - movlw d'1' ; Information length + movlw d'1' ; information length addwf ProfileFlagByte,F ; add to ProfileFlagByte - bsf EventByte1,6 ; Also set Flag in EventByte1! + bsf EventByte1,6 ; also set Flag in EventByte1! check_event4: btfss bailoutgas_event ; =1: bailout was selected or a gas change during bailout bra check_event5 - movlw d'2' ; Information length + movlw d'2' ; information length addwf ProfileFlagByte,F ; add to ProfileFlagByte bsf EventByte2,0 ; set flag in EventByte2! - bsf EventByte1,7 ; =1: Another EventByte1 is available + bsf EventByte1,7 ; =1: another EventByte1 is available check_event5: ; more events? @@ -177,85 +179,89 @@ btfsc EventByte1,7 ; =1: Another EventByte1 is available incf ProfileFlagByte,F ; add one byte (The EventByte2) - btfsc event_occured ; Check global event flag - bsf ProfileFlagByte,7 ; Set EventByte1 Flag in ProfileFlagByte + btfsc event_occured ; check global event flag + bsf ProfileFlagByte,7 ; set EventByte1 flag in ProfileFlagByte - movf ProfileFlagByte,W ; finally, write ProfileFlagByte! - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movf ProfileFlagByte,W ; finally, write ProfileFlagByte + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - btfss event_occured ; Check global event flag (again) - bra store_dive_data4 ; No Event + btfss event_occured ; check global event flag (again) + bra store_dive_data4 ; no event ; Store the EventByte(s) + additional bytes now movf EventByte1,W - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movf EventByte2,W ; Write second event byte... - btfsc EventByte1,7 ; =1: Another EventByte1 is available - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movf EventByte2,W ; write second event byte... + btfsc EventByte1,7 ; =1: another EventByte1 is available + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - btfss gas6_changed ; Check flag + btfss gas6_changed ; check flag bra store_dive_data3b movff char_I_O2_ratio,WREG ; store gas 6 o2 ratio - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movff char_I_He_ratio,WREG ; store gas 6 He ratio - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - bcf gas6_changed ; Clear this event + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + bcf gas6_changed ; clear this event store_dive_data3b: - btfss stored_gas_changed ; Check flag + btfss stored_gas_changed ; check flag bra store_dive_data3c - movf active_gas,W ; Store active gas - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - bcf stored_gas_changed ; Clear this event + movf active_dil,W ; store active diluent (default, may be overwritten soon) + btfsc FLAG_oc_mode ; in OC mode? + movf active_gas,W ; YES - store active gas + btfsc FLAG_bailout_mode ; in bailout? + movf active_gas,W ; YES - store active OC = bailout gas + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + bcf stored_gas_changed ; clear this event store_dive_data3c: - btfss setpoint_changed ; Check flag + btfss setpoint_changed ; check flag bra store_dive_data3d movff char_I_const_ppO2,WREG ; store setpoint - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - bcf setpoint_changed ; Clear this event + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + bcf setpoint_changed ; clear this event store_dive_data3d: - btfss bailoutgas_event ; Check flag + btfss bailoutgas_event ; check flag bra store_dive_data4 movff char_I_O2_ratio,WREG ; store O2 ratio of bailout gas - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movff char_I_He_ratio,WREG ; store He ratio of bailout gas - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - bcf bailoutgas_event ; Clear this event + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + bcf bailoutgas_event ; clear this event store_dive_data4: -; Store extended informations - decfsz divisor_temperature,F ; Check divisor +; Store extended information + decfsz divisor_temperature,F ; check divisor bra store_extended1 rcall store_dive_temperature store_extended1: - decfsz divisor_deco,F ; Check divisor + decfsz divisor_deco,F ; check divisor bra store_extended2 rcall store_dive_decodata store_extended2: - decfsz divisor_gf,F ; Check divisor + decfsz divisor_gf,F ; check divisor bra store_extended3 rcall store_dive_gf store_extended3: - decfsz divisor_ppo2_sensors,F ; Check divisor + decfsz divisor_ppo2_sensors,F ; check divisor bra store_extended4 rcall store_dive_ppO2_sensors store_extended4: - decfsz divisor_decoplan,F ; Check divisor + decfsz divisor_decoplan,F ; check divisor bra store_extended5 rcall store_dive_decoplan store_extended5: - decfsz divisor_cns,F ; Check divisor + decfsz divisor_cns,F ; check divisor bra store_extended6 rcall store_dive_cns store_extended6: - decfsz divisor_tank,F ; Check divisor + decfsz divisor_tank,F ; check divisor bra store_extended7 rcall store_dive_tank store_extended7: ; The next block is required to take care of "store never" - btfsc divisor_temperature,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) - clrf divisor_temperature ; And clear register again, so it will never reach zero... + btfsc divisor_temperature,7 ; test highest bit (register must have been zero before the "decfsz" command!) + clrf divisor_temperature ; and clear register again, so it will never reach zero... btfsc divisor_deco,7 clrf divisor_deco btfsc divisor_gf,7 @@ -270,25 +276,26 @@ clrf divisor_tank store_dive_data5: - bcf event_occured ; Clear the global event flag + bcf event_occured ; clear the global event flag clrf EventByte1 ; reset EventByte1 clrf EventByte2 ; reset EventByte2 - return ; Done. (Sample with all informations written to external flash) + return ; done (sample with all informations written to external flash) store_dive_cns: movff int_O_CNS_fraction+0,WREG - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movff int_O_CNS_fraction+1,WREG - bcf WREG,int_warning_flag ; clear warning flag - bcf WREG,int_attention_flag ; clear attention flag - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + bcf WREG,int_warning_flag ; clear warning flag + bcf WREG,int_attention_flag ; clear attention flag + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw div_cns - movwf divisor_cns ; Reload divisor from CF + movwf divisor_cns ; reload divisor from CF return store_dive_tank: + ; OSTC TR tank pressure logging movlw div_tank - movwf divisor_tank ; Reload divisor from CF + movwf divisor_tank ; reload divisor from CF return store_dive_decoplan: @@ -298,143 +305,143 @@ movwf lo store_dive_decoplan_loop: movf POSTINC1,W - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash decfsz lo,F bra store_dive_decoplan_loop movlw div_decoplan - movwf divisor_decoplan ; Reload divisor from CF + movwf divisor_decoplan ; reload divisor from CF return store_dive_ppO2_sensors: - movf o2_ppo2_sensor1,W ; Sensor1 ppO2 (in 0.01bar steps) - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - SAFE_2BYTE_COPY o2_mv_sensor1,lo ; o2_mv_sensor may be modified via ISR during the two writes here... - movf lo,W ; in 0.1mV steps - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - movf hi,W ; in 0.1mV steps - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movf o2_ppo2_sensor1,W ; Sensor1 ppO2 (in 0.01 bar steps) + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + SAFE_2BYTE_COPY o2_mv_sensor1,lo ; o2_mv_sensor may be modified via ISR during the two writes here... + movf lo,W ; in 0.1 mV steps + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movf hi,W ; in 0.1 mV steps + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movf o2_ppo2_sensor2,W ; Sensor2 ppO2 (in 0.01bar steps) - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - SAFE_2BYTE_COPY o2_mv_sensor2,lo ; o2_mv_sensor may be modified via ISR during the two writes here... - movf lo,W ; in 0.1mV steps - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - movf hi,W ; in 0.1mV steps - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movf o2_ppo2_sensor2,W ; Sensor2 ppO2 (in 0.01 bar steps) + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + SAFE_2BYTE_COPY o2_mv_sensor2,lo ; o2_mv_sensor may be modified via ISR during the two writes here... + movf lo,W ; in 0.1 mV steps + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movf hi,W ; in 0.1 mV steps + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movf o2_ppo2_sensor3,W ; Sensor3 ppO2 (in 0.01bar steps) - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - SAFE_2BYTE_COPY o2_mv_sensor3,lo ; o2_mv_sensor may be modified via ISR during the two writes here... - movf lo,W ; in 0.1mV steps - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - movf hi,W ; in 0.1mV steps - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movf o2_ppo2_sensor3,W ; Sensor3 ppO2 (in 0.01 bar steps) + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + SAFE_2BYTE_COPY o2_mv_sensor3,lo ; o2_mv_sensor may be modified via ISR during the two writes here... + movf lo,W ; in 0.1 mV steps + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movf hi,W ; in 0.1 mV steps + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw div_ppo2_sensors - movwf divisor_ppo2_sensors ; Reload divisor + movwf divisor_ppo2_sensors ; reload divisor return store_dive_gf: - movff int_O_gradient_factor+0,WREG; gradient factor absolute (range is limited to 255, only lower byte used for value) - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movff int_O_gradient_factor+0,WREG ; gradient factor absolute (range is limited to 255, only lower byte used for value) + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw div_gf - movwf divisor_gf ; Reload divisor + movwf divisor_gf ; reload divisor return store_dive_decodata: ; Check if deco stops are necessary - movff char_O_first_deco_depth,WREG; get ceiling - tstfsz WREG ; ceiling < 0m (aka in deco) ? - bra store_dive_decodata_deco ; YES + movff char_O_first_deco_depth,WREG ; get ceiling + tstfsz WREG ; ceiling < 0 m (aka in deco) ? + bra store_dive_decodata_deco ; YES ; NO - within NDL - clrf WREG ; =0: no stop dive - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - movff char_O_nullzeit,WREG ; remaining NDL time - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + clrf WREG ; =0: no stop dive + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movff char_O_nullzeit,WREG ; remaining NDL time + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash bra store_dive_decodata_common store_dive_decodata_deco: ; YES - in deco - movff char_O_first_deco_depth,WREG; ceiling in m - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash - movff char_O_first_deco_time,WREG ; length of first stop in minutes - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movff char_O_first_deco_depth,WREG ; ceiling in m + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movff char_O_first_deco_time,WREG ; length of first stop in minutes + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash store_dive_decodata_common: movlw div_deco - movwf divisor_deco ; Reload divisor + movwf divisor_deco ; Reload divisor return store_dive_temperature: SAFE_2BYTE_COPY temperature,lo - movf lo,W ; append temperature to current sample! - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movf lo,W ; append temperature to current sample! + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movf hi,W - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw div_temperature - movwf divisor_temperature ; Reload divisor + movwf divisor_temperature ; reload divisor return ghostwrite_byte_header: - goto write_byte_ext_flash_plus_header ; (This call will also delete the 4kB TOC entry first) + goto write_byte_ext_flash_plus_header ; (this call will also delete the 4kB TOC entry first) ; returns... ghostwrite_byte_profile: - goto write_byte_ext_flash_plus ; writes byte and increases address with banking at 0x200000 + goto write_byte_ext_flash_plus ; writes byte and increases address with banking at 0x200000 ; returns... global ghostwriter_end_dive ghostwriter_end_dive: movff ext_flash_address+0,ext_flash_log_pointer+0 movff ext_flash_address+1,ext_flash_log_pointer+1 - movff ext_flash_address+2,ext_flash_log_pointer+2 ; Save end-of-profile pointer to store in header + movff ext_flash_address+2,ext_flash_log_pointer+2 ; save end-of-profile pointer to store in header - movff menupos3,customview_divemode ; store last custom view + movff menupos3,customview_divemode ; store last custom view - btfss realdive ; dive longer then one minute - goto ghostwriter_end_dive_common ; No, discard everything + btfss realdive ; dive longer then one minute + goto ghostwriter_end_dive_common ; NO - discard everything ; In DEBUG compile, keep all simulated dives in logbook, Desat time, nofly, etc... - ifndef __DEBUG - btfsc simulatormode_active ; Are we in simulator mode? - goto ghostwriter_end_dive_common_sim ; Yes, discard everything - endif + ifndef __DEBUG + btfsc simulatormode_active ; are we in simulator mode? + goto ghostwriter_end_dive_common_sim ; YES - discard everything + endif - btfsc FLAG_apnoe_mode ; In Apnoe mode? - goto ghostwriter_end_dive_common ; Yes, discard everything + btfsc FLAG_apnoe_mode ; in Apnoe mode? + goto ghostwriter_end_dive_common ; YES - discard everything - ; Dive finished (and longer then one minute) + ; Dive finished (and longer than one minute) - btfsc FLAG_apnoe_mode ; Calc max. depth (again) for very short apnoe dives + btfsc FLAG_apnoe_mode ; calc max. depth (again) for very short apnoe dives call apnoe_calc_maxdepth ; calculate desaturation time - movff last_surfpressure_30min+0,int_I_pres_surface+0 ; Pass surface to desat routine ! + movff last_surfpressure_30min+0,int_I_pres_surface+0 ; pass surface to desat routine ! movff last_surfpressure_30min+1,int_I_pres_surface+1 call deco_calc_dive_interval_1min ; calculate deco in surface mode call deco_calc_desaturation_time ; calculate desaturation time banksel common ; select ram bank 1 - movlw 0xFD ; .... End-of-Profile Bytes - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + movlw 0xFD ; .... End-of-Profile bytes + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw 0xFD - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. Flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movff ext_flash_address+0,ext_flash_log_pointer+0 movff ext_flash_address+1,ext_flash_log_pointer+1 - movff ext_flash_address+2,ext_flash_log_pointer+2 ; Save end-of-profile pointer to store in header + movff ext_flash_address+2,ext_flash_log_pointer+2 ; save end-of-profile pointer to store in header ; Set to first address again to store dive length ext_flash_dive_counter:3 - rcall ghostwriter_load_pointer ; Load ext_flash_address:3 from EEPROM .4-.6 + rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 - incf_ext_flash_address_0x20 d'6' ; Skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header + incf_ext_flash_address_0x20 d'6' ; skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header ; Store dive length movf ext_flash_dive_counter+0,W - call write_byte_ext_flash_plus_nodel ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page + call write_byte_ext_flash_plus_nodel ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page movf ext_flash_dive_counter+1,W - call write_byte_ext_flash_plus_nodel ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page + call write_byte_ext_flash_plus_nodel ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page movf ext_flash_dive_counter+2,W - call write_byte_ext_flash_plus_nodel ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page + call write_byte_ext_flash_plus_nodel ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page -; profile recording done. +; profile recording done ; Load total number of dives read_int_eeprom .2 @@ -471,66 +478,67 @@ ; Now, write header - movlw 0xFA ; Header start - rcall ghostwrite_byte_header ; (This call will also delete the 4kB TOC entry first) + movlw 0xFA ; header start + rcall ghostwrite_byte_header ; (this call will also delete the 4kB TOC entry first) movlw 0xFA - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; store pointer to begin of dive profile read_int_eeprom .4 movf EEDATA,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash read_int_eeprom .5 movf EEDATA,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash read_int_eeprom .6 movf EEDATA,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; store pointer to end of dive profile movf ext_flash_log_pointer+0,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movf ext_flash_log_pointer+1,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movf ext_flash_log_pointer+2,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; write rest of header - movlw logbook_profile_version ; Defined in hwos.inc - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + movlw logbook_profile_version ; defined in hwos.inc + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; Store dive length movf ext_flash_dive_counter+0,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movf ext_flash_dive_counter+1,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movf ext_flash_dive_counter+2,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash - movff start_year,WREG ; Date - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff start_month,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff start_day,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff start_hours,WREG ; Start of dive time - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff start_mins,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + lfsr FSR0,start_year ; load base address of start-of-dive data + movf POSTINC0,W ; year + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; month + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; day + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; hour + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; minute + rcall ghostwrite_byte_header ; WREG -> header in ext. flash - btfss FLAG_apnoe_mode ; Store apnoe max or normal max (Which is only max from the last descent) - bra end_dive1 ; Store normal depth + btfss FLAG_apnoe_mode ; store apnoe max or normal max (which is only max from the last descent) + bra end_dive1 ; store normal depth movff apnoe_max_pressure+0,lo movff apnoe_max_pressure+1,hi call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] movff lo,apnoe_max_pressure+0 movff hi,apnoe_max_pressure+1 - - movf apnoe_max_pressure+0,W ; Max. depth - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movf apnoe_max_pressure+1,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + + movf lo,W ; max. depth, low byte + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf hi,W ; max. depth, high byte + rcall ghostwrite_byte_header ; WREG -> header in ext. flash bra end_dive2 ; skip normal max. depth end_dive1: @@ -540,133 +548,81 @@ movff lo,max_pressure+0 movff hi,max_pressure+1 - movff max_pressure+0,WREG ; Max. depth - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff max_pressure+1,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + movf lo,W ; max. depth, low byte + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf hi,W ; max. depth, high byte + rcall ghostwrite_byte_header ; WREG -> header in ext. flash end_dive2: movf divemins+0,W ; dive time minutes - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movf divemins+1,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movf divesecs,W ; dive time seconds - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff minimum_temperature+0,WREG ; minimum temperature - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff minimum_temperature+1,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff last_surfpressure_30min+0,WREG ; air pressure before dive - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff last_surfpressure_30min+1,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff int_O_desaturation_time+0,WREG ; desaturation time in minutes - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff int_O_desaturation_time+1,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash - btfss FLAG_ccr_mode ; In CCR mode... - bra end_dive_oc_gaslist ; No, write OC gases - ; Write Diluents... - movff opt_dil_O2_ratio+0,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_dil_He_ratio+0,WREG - rcall ghostwrite_byte_header ; %He - movff char_I_dil_change+0,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_dil_type+0,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2=Normal + btfsc FLAG_ccr_mode ; in CCR mode? + bra end_dive_dil_gaslist ; YES - write diluent gas list + btfsc FLAG_pscr_mode ; in pSCR mode? + bra end_dive_dil_gaslist ; YES - write diluent gas list - movff opt_dil_O2_ratio+1,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_dil_He_ratio+1,WREG - rcall ghostwrite_byte_header ; %He - movff char_I_dil_change+1,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_dil_type+1,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2=Normal +end_dive_oc_gaslist: ; write OC gases + lfsr FSR0,opt_gas_O2_ratio-.1 ; set base address to (opt_gas_O2_ratio - 1) because of pre-increment statement + bra end_dive_gaslist ; write all 5 OC gases - movff opt_dil_O2_ratio+2,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_dil_He_ratio+2,WREG - rcall ghostwrite_byte_header ; %He - movff char_I_dil_change+2,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_dil_type+2,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2=Normal - - movff opt_dil_O2_ratio+3,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_dil_He_ratio+3,WREG - rcall ghostwrite_byte_header ; %He - movff char_I_dil_change+3,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_dil_type+3,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2=Normal +end_dive_dil_gaslist: ; write diluents + lfsr FSR0,opt_dil_O2_ratio-.1 ; set base address to (opt_dil_O2_ratio - 1) because of pre-increment statement + ;bra end_dive_gaslist ; write all 5 diluents - movff opt_dil_O2_ratio+4,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_dil_He_ratio+4,WREG - rcall ghostwrite_byte_header ; %He - movff char_I_dil_change+4,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_dil_type+4,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2=Normal - bra end_dive_oc_cc_common - -end_dive_oc_gaslist: ; OC Gases... - movff opt_gas_O2_ratio+0,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_gas_He_ratio+0,WREG - rcall ghostwrite_byte_header ; %He - movff opt_OC_bail_gas_change+0,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_gas_type+0,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2= Travel, 3= Deco - - movff opt_gas_O2_ratio+1,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_gas_He_ratio+1,WREG - rcall ghostwrite_byte_header ; %He - movff opt_OC_bail_gas_change+1,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_gas_type+1,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2= Travel, 3= Deco - - movff opt_gas_O2_ratio+2,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_gas_He_ratio+2,WREG - rcall ghostwrite_byte_header ; %He - movff opt_OC_bail_gas_change+2,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_gas_type+2,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2= Travel, 3= Deco - - movff opt_gas_O2_ratio+3,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_gas_He_ratio+3,WREG - rcall ghostwrite_byte_header ; %He - movff opt_OC_bail_gas_change+3,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_gas_type+3,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2= Travel, 3= Deco - - movff opt_gas_O2_ratio+4,WREG - rcall ghostwrite_byte_header ; %O2 - movff opt_gas_He_ratio+4,WREG - rcall ghostwrite_byte_header ; %He - movff opt_OC_bail_gas_change+4,WREG - rcall ghostwrite_byte_header ; Configured change depth in m - movff opt_gas_type+4,WREG - rcall ghostwrite_byte_header ; 0=Disabled, 1=First, 2= Travel, 3= Deco -; bra end_dive_oc_cc_common +end_dive_gaslist: ; helper function for writing gas list entries +; +; Memory Map: +; ------------------------- +; opt_gas_O2_ratio res 5 +; opt_dil_O2_ratio res 5 +; opt_gas_He_ratio res 5 +; opt_dil_He_ratio res 5 +; opt_gas_type res 5 +; opt_dil_type res 5 +; opt_gas_change res 5 +; opt_dil_change res 5 +; + movlw .5 ; 5 gases to store + movwf lo ; use lo as counter +end_dive_gaslist_loop: + movf PREINC0,W ; increment base address and get O2 ratio into WREG + rcall ghostwrite_byte_header ; store data + movlw .10 ; offset for H2 ratios + movf PLUSW0,W ; get H2 ratio into WREG + rcall ghostwrite_byte_header ; store data + movlw .30 ; offset for change depths + movf PLUSW0,W ; get change depth into WREG + rcall ghostwrite_byte_header ; store data + movlw .20 ; offset for types + movf PLUSW0,W ; get type into WREG + rcall ghostwrite_byte_header ; store data + decfsz lo ; decrement counter, did it became 0 ? + bra end_dive_gaslist_loop ; NO - loop + ;bra end_dive_oc_cc_common ; YES - done end_dive_oc_cc_common: - movlw softwareversion_x ; Firmware version + movlw softwareversion_x ; firmware version rcall ghostwrite_byte_header movlw softwareversion_y rcall ghostwrite_byte_header - movf batt_voltage+0,W ; Battery voltage + movf batt_voltage+0,W ; battery voltage rcall ghostwrite_byte_header movf batt_voltage+1,W rcall ghostwrite_byte_header @@ -674,92 +630,85 @@ movf samplingrate,W ; Sampling rate btfsc FLAG_apnoe_mode ; Apnoe mode? movlw samplingrate_apnoe ; Apnoe sampling rate - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; CNS at beginning of dive movff CNS_start+0,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff CNS_start+1,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; Gradient factor movff GF_start,WREG - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff int_O_gradient_factor+0,WREG ; value limited to 255, only lower byte in use - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; Logbook offset call do_logoffset_common_read ; Read into lo:hi movf lo,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movf hi,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; Battery info at Byte 59 movf batt_percent,W ; 0-100 - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - ; Store 5 Setpoints - movff char_I_setpoint_cbar+0,WREG - rcall ghostwrite_byte_header ; Setpoint in cbar - movff char_I_setpoint_change+0,WREG - rcall ghostwrite_byte_header ; Change depth - movff char_I_setpoint_cbar+1,WREG - rcall ghostwrite_byte_header ; Setpoint in cbar - movff char_I_setpoint_change+1,WREG - rcall ghostwrite_byte_header ; Change depth - movff char_I_setpoint_cbar+2,WREG - rcall ghostwrite_byte_header ; Setpoint in cbar - movff char_I_setpoint_change+2,WREG - rcall ghostwrite_byte_header ; Change depth - movff char_I_setpoint_cbar+3,WREG - rcall ghostwrite_byte_header ; Setpoint in cbar - movff char_I_setpoint_change+3,WREG - rcall ghostwrite_byte_header ; Change depth - movff char_I_setpoint_cbar+4,WREG - rcall ghostwrite_byte_header ; Setpoint in cbar - movff char_I_setpoint_change+4,WREG - rcall ghostwrite_byte_header ; Change depth + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + + ; Store the setpoints + lfsr FSR0,char_I_setpoint_cbar ; base address of ppO2 values + lfsr FSR1,char_I_setpoint_change ; base address of change depths + movlw .5 ; 5 setpoints to store + movwf lo ; use lo as counter +end_dive_sp_loop: + movf POSTINC0,W ; get ppO2 value + rcall ghostwrite_byte_header ; store ppO2 value + movf POSTINC1,W ; get change depth + rcall ghostwrite_byte_header ; store change depth + decfsz lo ; decrement counter, did it became 0 ? + bra end_dive_sp_loop ; NO - loop - movff opt_salinity,WREG ; Salinity (0-4%) - rcall ghostwrite_byte_header ; Store Salinity to Dive - - movff int_O_CNS_fraction+0,WREG ; copy into bank1 - rcall ghostwrite_byte_header ; Stores CNS% - movff int_O_CNS_fraction+1,WREG ; copy into bank1 - bcf WREG,int_warning_flag ; clear warning flag - bcf WREG,int_attention_flag ; clear attention flag - rcall ghostwrite_byte_header ; Stores CNS% + ; Store further data + movff opt_salinity,WREG ; salinity (0-4%) + rcall ghostwrite_byte_header ; store salinity - movff avg_rel_pressure_total+0,WREG ; Average Depth - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff avg_rel_pressure_total+1,WREG ; Average Depth - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + movff int_O_CNS_fraction+0,WREG ; CNS value, low byte + rcall ghostwrite_byte_header ; store CNS% + movff int_O_CNS_fraction+1,WREG ; CNS value, high byte + bcf WREG,int_warning_flag ; clear warning flag + bcf WREG,int_attention_flag ; clear attention flag + rcall ghostwrite_byte_header ; store CNS% - movff total_divetime_seconds+0,WREG ; Total dive time (Regardless of start_dive_threshold) - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff total_divetime_seconds+1,WREG ; Total dive time (Regardless of start_dive_threshold) - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + movff avg_rel_pressure_total+0,WREG ; average depth + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movff avg_rel_pressure_total+1,WREG ; average depth + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + + movff total_divetime_seconds+0,WREG ; total dive time (regardless of start_dive_threshold) + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movff total_divetime_seconds+1,WREG ; total dive time (regardless of start_dive_threshold) + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff char_I_GF_Low_percentage,WREG ; GF_lo movff char_I_deco_model,lo decfsz lo,F ; jump over next line if char_I_deco_model == 1 - movff char_I_saturation_multiplier,WREG ; Saturation Multiplier - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + movff char_I_saturation_multiplier,WREG ; saturation multiplier + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff char_I_GF_High_percentage,WREG ; GF_hi movff char_I_deco_model,lo decfsz lo,F ; jump over next line if char_I_deco_model == 1 - movff char_I_desaturation_multiplier,WREG ; Desaturation Multiplier - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + movff char_I_desaturation_multiplier,WREG ; desaturation multiplier + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff char_I_deco_model,WREG ; 0 = ZH-L16, 1 = ZH-L16-GF rcall ghostwrite_byte_header ; writes byte and increases address (no banking) read_int_eeprom .2 movf EEDATA,W - rcall ghostwrite_byte_header ; Total dive counter, low + rcall ghostwrite_byte_header ; total dive counter, low read_int_eeprom .3 movf EEDATA,W - rcall ghostwrite_byte_header ; Total dive counter, high + rcall ghostwrite_byte_header ; total dive counter, high movff opt_dive_mode,WREG rcall ghostwrite_byte_header ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR @@ -771,18 +720,18 @@ end_dive_store_tissues_N2: movf POSTINC1,W bcf WREG,7 ; clear flag bit for ongassing/offgassing - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash decfsz lo,F - bra end_dive_store_tissues_N2 ; No + bra end_dive_store_tissues_N2 ; NO movlw .64 movwf lo - lfsr FSR1,0x700 ; pres_tissue_N2+0 ; 16*4Byte Float = 64Bytes + lfsr FSR1,0x700 ; pres_tissue_N2+0 ; 16*4 Byte Float = 64 Bytes end_dive_store_tissues_N2_2: movf POSTINC1,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash decfsz lo,F - bra end_dive_store_tissues_N2_2 ; No + bra end_dive_store_tissues_N2_2 ; NO movlw .16 movwf lo @@ -790,57 +739,58 @@ end_dive_store_tissues_He: movf POSTINC1,W bcf WREG,7 ; clear flag bit for ongassing/offgassing - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash decfsz lo,F - bra end_dive_store_tissues_He ; No + bra end_dive_store_tissues_He ; NO movlw .64 movwf lo - lfsr FSR1,0x740 ; pres_tissue_He+0 ; 16*4Byte Float = 64Bytes + lfsr FSR1,0x740 ; pres_tissue_He+0 ; 16*4 Byte Float = 64 Bytes end_dive_store_tissues_He_2: movf POSTINC1,W - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash decfsz lo,F - bra end_dive_store_tissues_He_2 ; No + bra end_dive_store_tissues_He_2 ; NO ; Some deco stuff movff char_I_depth_last_deco,WREG ; last stop [m] - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movff char_I_deco_distance,WREG ; assumed distance to shown stop - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; Last HUD data - movff hud_battery_mv+0,WREG ; Last HUD battery value - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff hud_battery_mv+1,WREG ; Last HUD battery value - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff hud_status_byte,WREG ; Last HUD status - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + movff hud_battery_mv+0,WREG ; last HUD battery value + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movff hud_battery_mv+1,WREG ; last HUD battery value + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movff hud_status_byte,WREG ; last HUD status + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; Battery gauge registers [nAs] - movff battery_gauge+0,WREG ; Battery gauge register - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff battery_gauge+1,WREG ; Battery gauge register - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff battery_gauge+2,WREG ; Battery gauge register - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff battery_gauge+3,WREG ; Battery gauge register - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff battery_gauge+4,WREG ; Battery gauge register - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash - movff battery_gauge+5,WREG ; Battery gauge register - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + lfsr FSR0,battery_gauge ; load base address of battery gauge register + movf POSTINC0,W ; get byte 0 + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; get byte 1 + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; get byte 2 + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; get byte 3 + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; get byte 4 + rcall ghostwrite_byte_header ; WREG -> header in ext. flash + movf POSTINC0,W ; get byte 5 + rcall ghostwrite_byte_header ; WREG -> header in ext. flash ; Header stop movlw 0xFB - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash movlw 0xFB - rcall ghostwrite_byte_header ; WREG -> Header in ext. flash + rcall ghostwrite_byte_header ; WREG -> header in ext. flash - call divemode_store_statistics ; Store/update statistics for this unit + call divemode_store_statistics ; store/update statistics for this unit clrf surface_interval+0 - clrf surface_interval+1 ; Clear surface interval timer + clrf surface_interval+1 ; clear surface interval timer ghostwriter_end_dive_common: ; Update ext_flash_log_pointer into EEPROM @@ -855,31 +805,31 @@ bcf simulatormode_active ; if we were in simulator mode ; In DEBUG compile, keep all simulated dives in logbook, Desat time, nofly, etc... - ifndef __DEBUG - extern deco_pull_tissues_from_vault - btfsc restore_deco_data ; Restore decodata? - call deco_pull_tissues_from_vault - banksel common ; Bank1 - endif + ifndef __DEBUG + btfsc restore_deco_data ; restore decodata? + call deco_pull_tissues_from_vault + banksel common ; bank 1 + endif call update_battery_registers ; update battery registers into EEPROM goto surfloop ; and return to surface loop + ghostwriter_end_dive_common_sim: - tstfsz surface_interval+0 ; Was interval zero? - bra ghostwriter_end_dive_common_sim2 ; No - tstfsz surface_interval+1 ; Was interval zero? - bra ghostwriter_end_dive_common_sim2 ; No - bra ghostwriter_end_dive_common ; Yes, done. - + tstfsz surface_interval+0 ; was interval zero? + bra ghostwriter_end_dive_common_sim2 ; NO + tstfsz surface_interval+1 ; was interval zero? + bra ghostwriter_end_dive_common_sim2 ; NO + bra ghostwriter_end_dive_common ; YES - done ghostwriter_end_dive_common_sim2: movf divemins+0,W addwf surface_interval+0,F movf divemins+1,W - addwfc surface_interval+1 ; Add simulated dive time to surface interval + addwfc surface_interval+1 ; add simulated dive time to surface interval bra ghostwriter_end_dive_common -ghostwriter_load_pointer: ; Load ext_flash_address:3 from EEPROM .4-.6 - clrf EEADRH ; Make sure to select EEPROM bank 0 + +ghostwriter_load_pointer: ; load ext_flash_address:3 from EEPROM .4-.6 + clrf EEADRH ; make sure to select EEPROM bank 0 read_int_eeprom .4 movff EEDATA,ext_flash_address+0 read_int_eeprom .5 @@ -888,44 +838,44 @@ movff EEDATA,ext_flash_address+2 return -ghostwriter_short_header_init: ; Proceed one page forward +ghostwriter_short_header_init: ; proceed one page forward clrf EEDATA - write_int_eeprom .4 ; ext_flash_address+0 = 0 + write_int_eeprom .4 ; ext_flash_address+0 = 0 movlw .16 addwf ext_flash_address+1,F movlw .0 addwfc ext_flash_address+2,F movlw 0x20 - cpfseq ext_flash_address+2 ; at address 0x200000? - bra ghostwriter_short_header_init2 ; No - clrf ext_flash_address+2 ; Yes, rollover to 0x000000 + cpfseq ext_flash_address+2 ; at address 0x200000? + bra ghostwriter_short_header_init2 ; NO + clrf ext_flash_address+2 ; YES - rollover to 0x000000 ghostwriter_short_header_init2: movlw 0xF0 - andwf ext_flash_address+1,F ; keep higher nibble, set lower nibble to 0 + andwf ext_flash_address+1,F ; keep higher nibble, set lower nibble to 0 movff ext_flash_address+1,EEDATA - write_int_eeprom .5 ; Write new pointer + write_int_eeprom .5 ; write new pointer movff ext_flash_address+2,EEDATA - write_int_eeprom .6 ; Write new pointer - bra ghostwriter_short_header2 ; Done. + write_int_eeprom .6 ; write new pointer + bra ghostwriter_short_header2 ; Done global ghostwriter_short_header -ghostwriter_short_header: ; Write short header with dive number into profile memory +ghostwriter_short_header: ; write short header with dive number into profile memory ; load pointer for profile storing into RAM (Updated in EEPROM after the dive) - rcall ghostwriter_load_pointer ; Load ext_flash_address:3 from EEPROM .4-.6 + rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 ; The following code is used to write a clean new dive after the previous hasn't been ; stored correctly. e.g. after a battery fail during the dive - call ext_flash_byte_read_plus_0x20 ; Into ext_flash_rw + call ext_flash_byte_read_plus_0x20 ; into ext_flash_rw incfsz ext_flash_rw,F - bra ghostwriter_short_header_init ; Not 0xFF -> init page - call ext_flash_byte_read_plus_0x20 ; Into ext_flash_rw + bra ghostwriter_short_header_init ; not 0xFF -> init page + call ext_flash_byte_read_plus_0x20 ; into ext_flash_rw incfsz ext_flash_rw,F - bra ghostwriter_short_header_init ; Not 0xFF -> init page + bra ghostwriter_short_header_init ; not 0xFF -> init page ghostwriter_short_header2: ; All ok, reload the pointer and start - rcall ghostwriter_load_pointer ; Load ext_flash_address:3 from EEPROM .4-.6 + rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 ; Clear dive length counter clrf ext_flash_dive_counter+0 @@ -934,20 +884,20 @@ ; Write short header with dive number into profile memory movlw 0xFA - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw 0xFA - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash ; Load total number of dives (low byte only) read_int_eeprom .2 - incf EEDATA,W ;+1 - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + incf EEDATA,W ; +1 + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash read_int_eeprom .3 movf EEDATA,W - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw 0xFA - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw 0xFA - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash ; Keep room for dive length ext_flash_dive_counter:3 (Stored at the end of the dive) ; Writing 0xFF three times here is mandatory @@ -956,82 +906,82 @@ ; - fixes an issue when we are at exactly 0xXXX000 here... movlw 0xFF - call write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) + call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) movlw 0xFF - call write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) + call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) movlw 0xFF - call write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) + call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) - movf samplingrate,W ; Sampling rate - btfsc FLAG_apnoe_mode ; Apnoe mode? - movlw samplingrate_apnoe ; Apnoe sampling rate - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + movf samplingrate,W ; sampling rate + btfsc FLAG_apnoe_mode ; apnoe mode? + movlw samplingrate_apnoe ; apnoe sampling rate + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movlw .7 ; Number of divisors - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + movlw .7 ; number of divisors + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movlw .0 ; Type - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + movlw .0 ; type + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw infolength_temperature - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash - movlw div_temperature ; Divisor temperature - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movlw div_temperature ; divisor temperature + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw .1 ; Type - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw infolength_deco - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash - movlw div_deco ; Divisor deco data - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movlw div_deco ; divisor deco data + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movlw .2 ; Type - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + movlw .2 ; type + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw infolength_gf - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash - movlw div_gf ; Divisor gf - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movlw div_gf ; divisor gf + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movlw .3 ; Type - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + movlw .3 ; type + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw infolength_ppo2_sensors - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash - movlw div_ppo2_sensors ; Divisor ppO2 + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movlw div_ppo2_sensors ; divisor ppO2 btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active - movlw .0 ; No ppO2 data in OC mode - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + movlw .0 ; no ppO2 data in OC mode + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash - movlw .4 ; Type - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + movlw .4 ; type + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw infolength_decoplan - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash - movlw div_decoplan ; Divisor debug - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movlw div_decoplan ; divisor debug + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw .5 ; Type - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw infolength_cns - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash - movlw div_cns ; Divisor CNS - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movlw div_cns ; divisor CNS + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw .6 ; Type - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash movlw infolength_tank - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash - movlw div_tank ; Divisor Tank - rcall ghostwrite_byte_profile ; WREG -> Profile in ext. flash + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash + movlw div_tank ; divisor tank + rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash return -divemode_store_statistics: ; Store/update statistics for this unit +divemode_store_statistics: ; store/update statistics for this unit call vault_decodata_into_eeprom ; update deco data - call do_logoffset_common_read ; Existing logbook offset into lo:hi + call do_logoffset_common_read ; existing logbook offset into lo:hi tstfsz lo ; lo=0? - bra change_logbook_offset1 ; No, adjust offset + bra change_logbook_offset1 ; NO - adjust offset tstfsz hi ; hi=0? - bra change_logbook_offset1 ; No, adjust offset - bra change_logbook_offset2 ; lo=0 and hi=0 -> skip Offset routine + bra change_logbook_offset1 ; NO - adjust offset + bra change_logbook_offset2 ; lo=0 and hi=0 -> skip offset routine change_logbook_offset1: movlw d'1'