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