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
|
|
170 return
|
|
171
|
|
172 simulator_show_decoplan:
|
|
173 call PLED_ClearScreen
|
34
|
174 call PLED_simdata_screen
|
0
|
175 call divemenu_see_decoplan
|
|
176
|
34
|
177 WIN_INVERT .1 ; Init new Wordprocessor
|
|
178 DISPLAYTEXT .188 ; Sim. Results:
|
|
179 WIN_INVERT .0 ; Init new Wordprocessor
|
|
180
|
0
|
181 bcf switch_left
|
|
182 bcf switch_right
|
|
183
|
|
184 simulator_show_decoplan2:
|
|
185 btfss onesecupdate
|
|
186 bra simulator_show_decoplan3
|
|
187
|
|
188 call timeout_surfmode
|
|
189 call set_dive_modes
|
|
190 call test_charger ; check if charger IC is active
|
|
191 call get_battery_voltage ; get battery voltage
|
|
192
|
|
193 bcf onesecupdate ; End of one second tasks
|
|
194
|
|
195 simulator_show_decoplan3:
|
|
196 btfsc switch_left
|
|
197 bra simulator_show_decoplan4 ; Quit display
|
|
198
|
|
199 btfsc switch_right
|
|
200 bra simulator_show_decoplan4 ; Quit display
|
|
201
|
|
202 btfsc sleepmode
|
|
203 goto more_menu
|
|
204
|
|
205 btfsc divemode
|
|
206 goto restart ; exit menu, restart and enter divemode
|
|
207
|
|
208 bra simulator_show_decoplan2
|
|
209
|
|
210 simulator_show_decoplan4:
|
|
211 movlw d'5'
|
|
212 movwf menupos
|
|
213 bra menu_simulator1
|
|
214
|
|
215
|
|
216 simulator_calc_deco:
|
|
217 call diveloop_boot ; configure gases, etc.
|
|
218
|
|
219 bsf simulatormode_active ; normal simulator mode
|
|
220 bsf standalone_simulator ; Standalone Simulator active
|
|
221
|
|
222
|
|
223 movff logbook_temp2,xA+0
|
|
224 clrf xA+1
|
|
225 movlw d'100'
|
|
226 movwf xB+0
|
|
227 clrf xB+1
|
|
228 call mult16x16 ;xA*xB=xC ; Depth in m*100
|
|
229
|
|
230 movlw LOW d'1000'
|
|
231 addwf xC+0,F
|
|
232 movlw HIGH d'1000'
|
|
233 addwfc xC+1,F ; Add 1000mBar
|
|
234
|
|
235 movff xC+0,sim_pressure+0
|
|
236 movff xC+1,sim_pressure+1
|
|
237
|
|
238 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values
|
|
239 movff sim_pressure+1,amb_pressure+1
|
|
240
|
|
241 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3
|
|
242
|
|
243 WIN_INVERT .1
|
|
244 DISPLAYTEXT .12 ;" Wait.."
|
|
245 WIN_INVERT .0
|
|
246
|
|
247 simulator_calc_deco_loop1:
|
32
|
248
|
0
|
249 ; movlw .011
|
|
250 ; call PLED_SetColumn
|
|
251 ; movlw .009
|
|
252 ; call PLED_SetRow
|
|
253 ; lfsr FSR2,letter
|
|
254 ; movff char_O_array_decodepth+0,lo ; Get Depth
|
|
255 ; bsf leftbind
|
|
256 ; output_8
|
|
257 ; bcf leftbind
|
|
258 ; movlw ' '
|
|
259 ; movwf POSTINC2
|
|
260 ;call word_processor
|
|
261
|
33
|
262
|
32
|
263 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
264 call divemode_prepare_flags_for_deco
|
|
265
|
|
266 call deco_main_calc_hauptroutine ; calc_tissue
|
|
267 movlb b'00000001' ; rambank 1 selected
|
|
268
|
|
269 movff char_O_deco_status,deco_status ;
|
|
270 tstfsz deco_status ; deco_status=0 if decompression calculation done
|
|
271 bra simulator_calc_deco_loop1 ; Not finished
|
0
|
272
|
31
|
273 movlw d'1'
|
|
274 movff WREG,char_I_step_is_1min ; 1 minute mode
|
32
|
275
|
|
276 movlw d'255'
|
|
277 movff WREG,char_O_deco_status ; Reset Deco module
|
|
278
|
|
279 simulator_calc_deco_loop2:
|
|
280 call PLED_simulator_data
|
|
281
|
|
282 btg LED_red
|
31
|
283
|
0
|
284 call divemode_check_decogases ; Checks for decogases and sets the gases
|
|
285 call divemode_prepare_flags_for_deco
|
|
286
|
|
287 call deco_main_calc_hauptroutine ; calc_tissue
|
|
288 movlb b'00000001' ; rambank 1 selected
|
|
289 ostc_debug 'C' ; Sends debug-information to screen if debugmode active
|
|
290
|
|
291 decfsz logbook_temp1,F
|
32
|
292 bra simulator_calc_deco_loop2
|
|
293
|
|
294 movlw d'0'
|
|
295 movff WREG,char_I_step_is_1min ; 2 second deco mode
|
33
|
296 ; movff WREG,unused_x24B
|
32
|
297
|
|
298 movlw d'255'
|
|
299 movff WREG,char_O_deco_status ; Reset Deco module
|
0
|
300
|
33
|
301 ; movff char_O_deco_status,deco_status ;
|
|
302 ; tstfsz deco_status ; deco_status=0 if decompression calculation done
|
0
|
303 bra simulator_calc_deco2 ; Not finished
|
|
304
|
|
305 simulator_calc_deco3:
|
21
|
306 bsf LED_red
|
0
|
307
|
|
308 call simulator_restore_tissue_data ; Restore 32 floats "pre_tissue" from bank3
|
|
309
|
|
310 bcf simulatormode_active ; normal simulator mode
|
|
311 bcf standalone_simulator ; Standalone Simulator active
|
|
312
|
|
313 WAITMS d'250'
|
|
314 WAITMS d'250'
|
|
315 WAITMS d'250' ; Wait for Pressure Sensor to get real pressure again...
|
|
316
|
21
|
317 bcf LED_red
|
0
|
318
|
|
319 movlw d'1'
|
|
320 movwf logbook_temp1 ; Bottom time>0!
|
|
321
|
|
322 movlw d'5' ; Pre-Set Cursor to "Show Decoplan"
|
|
323 movwf menupos
|
31
|
324
|
0
|
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! |