0
|
1
|
|
2 ; OSTC - diving computer code
|
|
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR
|
|
4
|
|
5 ; This program is free software: you can redistribute it and/or modify
|
|
6 ; it under the terms of the GNU General Public License as published by
|
|
7 ; the Free Software Foundation, either version 3 of the License, or
|
|
8 ; (at your option) any later version.
|
|
9
|
|
10 ; This program is distributed in the hope that it will be useful,
|
|
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ; GNU General Public License for more details.
|
|
14
|
|
15 ; You should have received a copy of the GNU General Public License
|
|
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
|
18
|
|
19 ; menu "Simulator"
|
|
20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
|
|
21 ; written: 081210
|
|
22 ; last updated: 081210
|
|
23 ; known bugs:
|
|
24 ; ToDo:
|
|
25
|
|
26 menu_simulator:
|
|
27 movlw d'1'
|
|
28 movwf logbook_temp1 ; Bottom time
|
|
29 movlw d'15'
|
|
30 movwf logbook_temp2 ; Max. Depth
|
|
31 movlw d'1'
|
|
32 movwf menupos
|
|
33
|
|
34 menu_simulator1:
|
|
35 clrf timeout_counter2
|
|
36 bsf menubit
|
|
37 bsf cursor
|
|
38 call PLED_ClearScreen
|
|
39 call PLED_simulator_mask
|
|
40
|
|
41 menu_simulator2:
|
|
42 bcf switch_left
|
|
43 bcf switch_right
|
|
44 bcf menubit2
|
|
45 bcf menubit3
|
|
46 call PLED_simulator_data
|
|
47 call PLED_menu_cursor
|
|
48
|
|
49 menu_simulator_loop:
|
|
50 call check_switches_menu
|
|
51 menu_simulator_loop2:
|
|
52 btfss onesecupdate
|
|
53 bra menu_simulator_loop3
|
|
54
|
|
55 call timeout_surfmode
|
|
56 call set_dive_modes
|
|
57 call test_charger ; check if charger IC is active
|
|
58 call get_battery_voltage ; get battery voltage
|
|
59
|
|
60 bcf onesecupdate ; End of one second tasks
|
|
61
|
|
62 menu_simulator_loop3:
|
|
63 btfsc menubit2
|
|
64 goto menu_simulator_do ; call submenu
|
|
65
|
|
66 btfss menubit
|
|
67 goto menu ; exit setup menu and return to main menu
|
|
68
|
|
69 btfsc sleepmode
|
|
70 goto more_menu
|
|
71
|
|
72 btfsc divemode
|
|
73 goto restart ; exit menu, restart and enter divemode
|
|
74
|
|
75 bra menu_simulator_loop
|
|
76
|
|
77 menu_simulator_do: ; calls submenu
|
|
78 dcfsnz menupos,F
|
|
79 bra simulator_startdive
|
|
80 dcfsnz menupos,F
|
|
81 bra simulator_inc_bottomtime
|
|
82 dcfsnz menupos,F
|
|
83 bra simulator_inc_maxdepth
|
|
84 dcfsnz menupos,F
|
|
85 bra simulator_calc_deco
|
|
86 dcfsnz menupos,F
|
|
87 bra simulator_show_decoplan
|
|
88 movlw d'4'
|
|
89 movwf menupos
|
|
90 goto more_menu2 ; exit...
|
|
91
|
|
92 simulator_inc_bottomtime:
|
|
93 movlw d'2'
|
|
94 addwf logbook_temp1,F ; Here: Bottomtime in m
|
|
95 movlw d'199'
|
|
96 cpfslt logbook_temp1
|
|
97 movwf logbook_temp1
|
|
98 movlw d'2'
|
|
99 movwf menupos
|
|
100 bra menu_simulator2
|
|
101
|
|
102 simulator_inc_maxdepth:
|
|
103 movlw d'3'
|
|
104 addwf logbook_temp2,F ; Here: Maxdepth in m
|
|
105 movlw d'99'
|
|
106 cpfslt logbook_temp2
|
|
107 movwf logbook_temp2
|
|
108 movlw d'3'
|
|
109 movwf menupos
|
|
110 bra menu_simulator2
|
|
111
|
|
112 simulator_startdive:
|
33
|
113 ; Descent to -15m depth
|
0
|
114 ; Set standalone_simulator flag (Displays Simulator menu during simulation by pressing ENTER button)
|
|
115 ; Clear standalone_simulator after (any) dive
|
|
116 bsf simulatormode_active ; normal simulator mode
|
|
117 bsf standalone_simulator ; Standalone Simulator active
|
|
118
|
|
119 movff logbook_temp2,xA+0
|
|
120 clrf xA+1
|
|
121 movlw d'100'
|
|
122 movwf xB+0
|
|
123 clrf xB+1
|
|
124 call mult16x16 ;xA*xB=xC ; Depth in m*100
|
|
125
|
|
126 movlw LOW d'1000'
|
|
127 addwf xC+0,F
|
|
128 movlw HIGH d'1000'
|
|
129 addwfc xC+1,F ; Add 1000mBar
|
|
130
|
|
131 movff xC+0,sim_pressure+0
|
|
132 movff xC+1,sim_pressure+1
|
|
133
|
|
134 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values
|
|
135 movff sim_pressure+1,amb_pressure+1
|
|
136
|
|
137 bcf menubit2
|
|
138 bcf menubit3
|
|
139 bcf menubit
|
|
140 bcf switch_left
|
|
141 bcf switch_right
|
|
142
|
|
143 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3
|
|
144
|
|
145 bsf divemode ; Set divemode flag
|
|
146 ostc_debug 'P' ; Sends debug-information to screen if debugmode active
|
|
147 goto diveloop ; Start Divemode
|
|
148
|
|
149 simulator_save_tissue_data:
|
|
150 bsf restore_deco_data ; Set restore flag
|
|
151 ostc_debug 'S' ; Sends debug-information to screen if debugmode active
|
|
152 call main_push_tissues_to_vault
|
|
153 movlb 0x01 ; Back to RAM Bank1
|
|
154 ostc_debug 'T' ; Sends debug-information to screen if debugmode active
|
|
155 return
|
|
156
|
|
157 simulator_restore_tissue_data:
|
|
158 bcf restore_deco_data ; clear restore flag
|
|
159 ostc_debug 'S' ; Sends debug-information to screen if debugmode active
|
|
160 call main_pull_tissues_from_vault
|
|
161 movlb 0x01 ; Back to RAM Bank1
|
|
162 ostc_debug 'T' ; Sends debug-information to screen if debugmode active
|
|
163
|
|
164 ostc_debug 'G' ; Sends debug-information to screen if debugmode active
|
|
165 call deco_main_calc_desaturation_time ; calculate desaturation time
|
|
166 movlb b'00000001' ; select ram bank 1
|
|
167 call calculate_noflytime ; Calc NoFly time
|
|
168 ostc_debug 'H' ; Sends debug-information to screen if debugmode active
|
|
169 return
|
|
170
|
|
171 simulator_show_decoplan:
|
|
172 call PLED_ClearScreen
|
|
173 call divemenu_see_decoplan
|
|
174
|
|
175 bcf switch_left
|
|
176 bcf switch_right
|
|
177
|
|
178 simulator_show_decoplan2:
|
|
179 btfss onesecupdate
|
|
180 bra simulator_show_decoplan3
|
|
181
|
|
182 call timeout_surfmode
|
|
183 call set_dive_modes
|
|
184 call test_charger ; check if charger IC is active
|
|
185 call get_battery_voltage ; get battery voltage
|
|
186
|
|
187 bcf onesecupdate ; End of one second tasks
|
|
188
|
|
189 simulator_show_decoplan3:
|
|
190 btfsc switch_left
|
|
191 bra simulator_show_decoplan4 ; Quit display
|
|
192
|
|
193 btfsc switch_right
|
|
194 bra simulator_show_decoplan4 ; Quit display
|
|
195
|
|
196 btfsc sleepmode
|
|
197 goto more_menu
|
|
198
|
|
199 btfsc divemode
|
|
200 goto restart ; exit menu, restart and enter divemode
|
|
201
|
|
202 bra simulator_show_decoplan2
|
|
203
|
|
204 simulator_show_decoplan4:
|
|
205 movlw d'5'
|
|
206 movwf menupos
|
|
207 bra menu_simulator1
|
|
208
|
|
209
|
|
210 simulator_calc_deco:
|
|
211 call diveloop_boot ; configure gases, etc.
|
|
212
|
|
213 bsf simulatormode_active ; normal simulator mode
|
|
214 bsf standalone_simulator ; Standalone Simulator active
|
|
215
|
|
216
|
|
217 movff logbook_temp2,xA+0
|
|
218 clrf xA+1
|
|
219 movlw d'100'
|
|
220 movwf xB+0
|
|
221 clrf xB+1
|
|
222 call mult16x16 ;xA*xB=xC ; Depth in m*100
|
|
223
|
|
224 movlw LOW d'1000'
|
|
225 addwf xC+0,F
|
|
226 movlw HIGH d'1000'
|
|
227 addwfc xC+1,F ; Add 1000mBar
|
|
228
|
|
229 movff xC+0,sim_pressure+0
|
|
230 movff xC+1,sim_pressure+1
|
|
231
|
|
232 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values
|
|
233 movff sim_pressure+1,amb_pressure+1
|
|
234
|
|
235 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3
|
|
236
|
|
237 WIN_INVERT .1
|
|
238 DISPLAYTEXT .12 ;" Wait.."
|
|
239 WIN_INVERT .0
|
|
240
|
|
241 simulator_calc_deco_loop1:
|
32
|
242
|
0
|
243 ; movlw .011
|
|
244 ; call PLED_SetColumn
|
|
245 ; movlw .009
|
|
246 ; call PLED_SetRow
|
|
247 ; lfsr FSR2,letter
|
|
248 ; movff char_O_array_decodepth+0,lo ; Get Depth
|
|
249 ; bsf leftbind
|
|
250 ; output_8
|
|
251 ; bcf leftbind
|
|
252 ; movlw ' '
|
|
253 ; movwf POSTINC2
|
|
254 ;call word_processor
|
|
255
|
33
|
256
|
32
|
257 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
258 call divemode_prepare_flags_for_deco
|
|
259
|
|
260 call deco_main_calc_hauptroutine ; calc_tissue
|
|
261 movlb b'00000001' ; rambank 1 selected
|
|
262
|
|
263 movff char_O_deco_status,deco_status ;
|
|
264 tstfsz deco_status ; deco_status=0 if decompression calculation done
|
|
265 bra simulator_calc_deco_loop1 ; Not finished
|
0
|
266
|
31
|
267 movlw d'1'
|
|
268 movff WREG,char_I_step_is_1min ; 1 minute mode
|
32
|
269
|
|
270 movlw d'255'
|
|
271 movff WREG,char_O_deco_status ; Reset Deco module
|
|
272
|
|
273 simulator_calc_deco_loop2:
|
|
274 call PLED_simulator_data
|
|
275
|
|
276 btg LED_red
|
31
|
277
|
0
|
278 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
279 call divemode_prepare_flags_for_deco
|
|
280
|
|
281 call deco_main_calc_hauptroutine ; calc_tissue
|
|
282 movlb b'00000001' ; rambank 1 selected
|
|
283 ostc_debug 'C' ; Sends debug-information to screen if debugmode active
|
|
284
|
|
285 decfsz logbook_temp1,F
|
32
|
286 bra simulator_calc_deco_loop2
|
|
287
|
|
288 movlw d'0'
|
|
289 movff WREG,char_I_step_is_1min ; 2 second deco mode
|
33
|
290 ; movff WREG,unused_x24B
|
32
|
291
|
|
292 movlw d'255'
|
|
293 movff WREG,char_O_deco_status ; Reset Deco module
|
0
|
294
|
33
|
295 ; movff char_O_deco_status,deco_status ;
|
|
296 ; tstfsz deco_status ; deco_status=0 if decompression calculation done
|
0
|
297 bra simulator_calc_deco2 ; Not finished
|
|
298
|
|
299 simulator_calc_deco3:
|
21
|
300 bsf LED_red
|
0
|
301
|
|
302 call simulator_restore_tissue_data ; Restore 32 floats "pre_tissue" from bank3
|
|
303
|
|
304 bcf simulatormode_active ; normal simulator mode
|
|
305 bcf standalone_simulator ; Standalone Simulator active
|
|
306
|
|
307 WAITMS d'250'
|
|
308 WAITMS d'250'
|
|
309 WAITMS d'250' ; Wait for Pressure Sensor to get real pressure again...
|
|
310
|
21
|
311 bcf LED_red
|
0
|
312
|
|
313 movlw d'1'
|
|
314 movwf logbook_temp1 ; Bottom time>0!
|
|
315
|
|
316 movlw d'5' ; Pre-Set Cursor to "Show Decoplan"
|
|
317 movwf menupos
|
31
|
318
|
0
|
319 bra menu_simulator1 ; Done.
|
|
320
|
|
321 simulator_calc_deco2:
|
|
322 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
323 call divemode_prepare_flags_for_deco
|
|
324
|
|
325 call deco_main_calc_hauptroutine ; calc_tissue
|
|
326 movlb b'00000001' ; rambank 1 selected
|
|
327
|
|
328 movff char_O_deco_status,deco_status ;
|
|
329 tstfsz deco_status ; deco_status=0 if decompression calculation done
|
|
330 bra simulator_calc_deco2 ; Not finished
|
|
331 bra simulator_calc_deco3 ; finished! |