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
|
35
|
67 goto menu_simulator_exit
|
0
|
68
|
|
69 btfsc sleepmode
|
35
|
70 goto menu_simulator_exit
|
0
|
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
|
35
|
88 menu_simulator_exit:
|
0
|
89 movlw d'4'
|
|
90 movwf menupos
|
|
91 goto more_menu2 ; exit...
|
|
92
|
|
93 simulator_inc_bottomtime:
|
|
94 movlw d'2'
|
|
95 addwf logbook_temp1,F ; Here: Bottomtime in m
|
|
96 movlw d'199'
|
|
97 cpfslt logbook_temp1
|
|
98 movwf logbook_temp1
|
|
99 movlw d'2'
|
|
100 movwf menupos
|
|
101 bra menu_simulator2
|
|
102
|
|
103 simulator_inc_maxdepth:
|
|
104 movlw d'3'
|
|
105 addwf logbook_temp2,F ; Here: Maxdepth in m
|
|
106 movlw d'99'
|
|
107 cpfslt logbook_temp2
|
|
108 movwf logbook_temp2
|
|
109 movlw d'3'
|
|
110 movwf menupos
|
|
111 bra menu_simulator2
|
|
112
|
|
113 simulator_startdive:
|
33
|
114 ; Descent to -15m depth
|
0
|
115 ; Set standalone_simulator flag (Displays Simulator menu during simulation by pressing ENTER button)
|
|
116 ; Clear standalone_simulator after (any) dive
|
|
117 bsf simulatormode_active ; normal simulator mode
|
|
118 bsf standalone_simulator ; Standalone Simulator active
|
|
119
|
|
120 movff logbook_temp2,xA+0
|
|
121 clrf xA+1
|
|
122 movlw d'100'
|
|
123 movwf xB+0
|
|
124 clrf xB+1
|
|
125 call mult16x16 ;xA*xB=xC ; Depth in m*100
|
|
126
|
|
127 movlw LOW d'1000'
|
|
128 addwf xC+0,F
|
|
129 movlw HIGH d'1000'
|
|
130 addwfc xC+1,F ; Add 1000mBar
|
|
131
|
|
132 movff xC+0,sim_pressure+0
|
|
133 movff xC+1,sim_pressure+1
|
|
134
|
|
135 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values
|
|
136 movff sim_pressure+1,amb_pressure+1
|
|
137
|
|
138 bcf menubit2
|
|
139 bcf menubit3
|
|
140 bcf menubit
|
|
141 bcf switch_left
|
|
142 bcf switch_right
|
|
143
|
|
144 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3
|
|
145
|
|
146 bsf divemode ; Set divemode flag
|
|
147 ostc_debug 'P' ; Sends debug-information to screen if debugmode active
|
|
148 goto diveloop ; Start Divemode
|
|
149
|
|
150 simulator_save_tissue_data:
|
|
151 bsf restore_deco_data ; Set restore flag
|
|
152 ostc_debug 'S' ; Sends debug-information to screen if debugmode active
|
|
153 call main_push_tissues_to_vault
|
|
154 movlb 0x01 ; Back to RAM Bank1
|
|
155 ostc_debug 'T' ; Sends debug-information to screen if debugmode active
|
|
156 return
|
|
157
|
|
158 simulator_restore_tissue_data:
|
|
159 bcf restore_deco_data ; clear restore flag
|
|
160 ostc_debug 'S' ; Sends debug-information to screen if debugmode active
|
|
161 call main_pull_tissues_from_vault
|
|
162 movlb 0x01 ; Back to RAM Bank1
|
|
163 ostc_debug 'T' ; Sends debug-information to screen if debugmode active
|
|
164
|
|
165 ostc_debug 'G' ; Sends debug-information to screen if debugmode active
|
|
166 call deco_main_calc_desaturation_time ; calculate desaturation time
|
|
167 movlb b'00000001' ; select ram bank 1
|
|
168 call calculate_noflytime ; Calc NoFly time
|
|
169 ostc_debug 'H' ; Sends debug-information to screen if debugmode active
|
47
|
170
|
|
171 ; Calculate CNS
|
|
172 call main_calc_CNS_fraction ; calculate CNS
|
|
173 movlb b'00000001' ; rambank 1 selected
|
0
|
174 return
|
|
175
|
|
176 simulator_show_decoplan:
|
|
177 call PLED_ClearScreen
|
34
|
178 call PLED_simdata_screen
|
0
|
179 call divemenu_see_decoplan
|
|
180
|
34
|
181 WIN_INVERT .1 ; Init new Wordprocessor
|
|
182 DISPLAYTEXT .188 ; Sim. Results:
|
|
183 WIN_INVERT .0 ; Init new Wordprocessor
|
|
184
|
0
|
185 bcf switch_left
|
|
186 bcf switch_right
|
|
187
|
|
188 simulator_show_decoplan2:
|
|
189 btfss onesecupdate
|
|
190 bra simulator_show_decoplan3
|
|
191
|
|
192 call timeout_surfmode
|
|
193 call set_dive_modes
|
|
194 call test_charger ; check if charger IC is active
|
|
195 call get_battery_voltage ; get battery voltage
|
|
196
|
|
197 bcf onesecupdate ; End of one second tasks
|
|
198
|
|
199 simulator_show_decoplan3:
|
|
200 btfsc switch_left
|
|
201 bra simulator_show_decoplan4 ; Quit display
|
|
202
|
|
203 btfsc switch_right
|
|
204 bra simulator_show_decoplan4 ; Quit display
|
|
205
|
|
206 btfsc sleepmode
|
|
207 goto more_menu
|
|
208
|
|
209 btfsc divemode
|
|
210 goto restart ; exit menu, restart and enter divemode
|
|
211
|
|
212 bra simulator_show_decoplan2
|
|
213
|
|
214 simulator_show_decoplan4:
|
|
215 movlw d'5'
|
|
216 movwf menupos
|
|
217 bra menu_simulator1
|
|
218
|
|
219
|
|
220 simulator_calc_deco:
|
|
221 call diveloop_boot ; configure gases, etc.
|
|
222
|
|
223 bsf simulatormode_active ; normal simulator mode
|
|
224 bsf standalone_simulator ; Standalone Simulator active
|
|
225
|
|
226
|
|
227 movff logbook_temp2,xA+0
|
|
228 clrf xA+1
|
|
229 movlw d'100'
|
|
230 movwf xB+0
|
|
231 clrf xB+1
|
|
232 call mult16x16 ;xA*xB=xC ; Depth in m*100
|
|
233
|
|
234 movlw LOW d'1000'
|
|
235 addwf xC+0,F
|
|
236 movlw HIGH d'1000'
|
|
237 addwfc xC+1,F ; Add 1000mBar
|
|
238
|
|
239 movff xC+0,sim_pressure+0
|
|
240 movff xC+1,sim_pressure+1
|
|
241
|
|
242 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values
|
|
243 movff sim_pressure+1,amb_pressure+1
|
|
244
|
|
245 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3
|
|
246
|
|
247 WIN_INVERT .1
|
|
248 DISPLAYTEXT .12 ;" Wait.."
|
|
249 WIN_INVERT .0
|
|
250
|
|
251 simulator_calc_deco_loop1:
|
32
|
252
|
0
|
253 ; movlw .011
|
|
254 ; call PLED_SetColumn
|
|
255 ; movlw .009
|
|
256 ; call PLED_SetRow
|
|
257 ; lfsr FSR2,letter
|
|
258 ; movff char_O_array_decodepth+0,lo ; Get Depth
|
|
259 ; bsf leftbind
|
|
260 ; output_8
|
|
261 ; bcf leftbind
|
|
262 ; movlw ' '
|
|
263 ; movwf POSTINC2
|
|
264 ;call word_processor
|
|
265
|
33
|
266
|
32
|
267 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
268 call divemode_prepare_flags_for_deco
|
|
269
|
|
270 call deco_main_calc_hauptroutine ; calc_tissue
|
|
271 movlb b'00000001' ; rambank 1 selected
|
|
272
|
|
273 movff char_O_deco_status,deco_status ;
|
|
274 tstfsz deco_status ; deco_status=0 if decompression calculation done
|
|
275 bra simulator_calc_deco_loop1 ; Not finished
|
0
|
276
|
31
|
277 movlw d'1'
|
|
278 movff WREG,char_I_step_is_1min ; 1 minute mode
|
32
|
279
|
|
280 movlw d'255'
|
|
281 movff WREG,char_O_deco_status ; Reset Deco module
|
|
282
|
|
283 simulator_calc_deco_loop2:
|
|
284 call PLED_simulator_data
|
|
285
|
|
286 btg LED_red
|
31
|
287
|
0
|
288 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
289 call divemode_prepare_flags_for_deco
|
|
290
|
|
291 call deco_main_calc_hauptroutine ; calc_tissue
|
|
292 movlb b'00000001' ; rambank 1 selected
|
|
293 ostc_debug 'C' ; Sends debug-information to screen if debugmode active
|
|
294
|
|
295 decfsz logbook_temp1,F
|
32
|
296 bra simulator_calc_deco_loop2
|
|
297
|
|
298 movlw d'0'
|
|
299 movff WREG,char_I_step_is_1min ; 2 second deco mode
|
|
300
|
|
301 movlw d'255'
|
|
302 movff WREG,char_O_deco_status ; Reset Deco module
|
0
|
303
|
|
304 bra simulator_calc_deco2 ; Not finished
|
|
305
|
|
306 simulator_calc_deco3:
|
21
|
307 bsf LED_red
|
0
|
308
|
|
309 call simulator_restore_tissue_data ; Restore 32 floats "pre_tissue" from bank3
|
|
310
|
|
311 bcf simulatormode_active ; normal simulator mode
|
|
312 bcf standalone_simulator ; Standalone Simulator active
|
|
313
|
|
314 WAITMS d'250'
|
|
315 WAITMS d'250'
|
|
316 WAITMS d'250' ; Wait for Pressure Sensor to get real pressure again...
|
|
317
|
21
|
318 bcf LED_red
|
0
|
319
|
|
320 movlw d'1'
|
|
321 movwf logbook_temp1 ; Bottom time>0!
|
|
322
|
|
323 movlw d'5' ; Pre-Set Cursor to "Show Decoplan"
|
|
324 movwf menupos
|
|
325 bra menu_simulator1 ; Done.
|
|
326
|
|
327 simulator_calc_deco2:
|
|
328 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
329 call divemode_prepare_flags_for_deco
|
|
330
|
|
331 call deco_main_calc_hauptroutine ; calc_tissue
|
|
332 movlb b'00000001' ; rambank 1 selected
|
|
333
|
|
334 movff char_O_deco_status,deco_status ;
|
|
335 tstfsz deco_status ; deco_status=0 if decompression calculation done
|
|
336 bra simulator_calc_deco2 ; Not finished
|
|
337 bra simulator_calc_deco3 ; finished! |