Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/simulator.asm @ 234:bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
author | JeanDo |
---|---|
date | Thu, 17 Mar 2011 18:32:16 +0100 |
parents | 59c479181724 |
children | 3dbeacf42e9e |
rev | line source |
---|---|
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 | |
49 | 38 call PLED_brightness_full ;max. brightness |
0 | 39 call PLED_ClearScreen |
40 call PLED_simulator_mask | |
41 | |
42 menu_simulator2: | |
43 bcf switch_left | |
44 bcf switch_right | |
45 bcf menubit2 | |
46 bcf menubit3 | |
47 call PLED_simulator_data | |
48 call PLED_menu_cursor | |
49 | |
50 menu_simulator_loop: | |
51 call check_switches_menu | |
52 menu_simulator_loop2: | |
53 btfss onesecupdate | |
54 bra menu_simulator_loop3 | |
55 | |
56 call timeout_surfmode | |
57 call set_dive_modes | |
58 call test_charger ; check if charger IC is active | |
59 call get_battery_voltage ; get battery voltage | |
60 | |
61 bcf onesecupdate ; End of one second tasks | |
62 | |
63 menu_simulator_loop3: | |
64 btfsc menubit2 | |
65 goto menu_simulator_do ; call submenu | |
66 | |
67 btfss menubit | |
35 | 68 goto menu_simulator_exit |
0 | 69 |
70 btfsc sleepmode | |
35 | 71 goto menu_simulator_exit |
0 | 72 |
73 btfsc divemode | |
74 goto restart ; exit menu, restart and enter divemode | |
75 | |
76 bra menu_simulator_loop | |
77 | |
78 menu_simulator_do: ; calls submenu | |
79 dcfsnz menupos,F | |
80 bra simulator_startdive | |
81 dcfsnz menupos,F | |
82 bra simulator_inc_bottomtime | |
83 dcfsnz menupos,F | |
84 bra simulator_inc_maxdepth | |
85 dcfsnz menupos,F | |
86 bra simulator_calc_deco | |
87 dcfsnz menupos,F | |
88 bra simulator_show_decoplan | |
35 | 89 menu_simulator_exit: |
0 | 90 movlw d'4' |
91 movwf menupos | |
92 goto more_menu2 ; exit... | |
93 | |
94 simulator_inc_bottomtime: | |
95 movlw d'2' | |
96 addwf logbook_temp1,F ; Here: Bottomtime in m | |
97 movlw d'199' | |
98 cpfslt logbook_temp1 | |
99 movwf logbook_temp1 | |
100 movlw d'2' | |
101 movwf menupos | |
102 bra menu_simulator2 | |
103 | |
104 simulator_inc_maxdepth: | |
105 movlw d'3' | |
106 addwf logbook_temp2,F ; Here: Maxdepth in m | |
107 movlw d'99' | |
108 cpfslt logbook_temp2 | |
109 movwf logbook_temp2 | |
110 movlw d'3' | |
111 movwf menupos | |
112 bra menu_simulator2 | |
113 | |
114 simulator_startdive: | |
33 | 115 ; Descent to -15m depth |
0 | 116 ; Set standalone_simulator flag (Displays Simulator menu during simulation by pressing ENTER button) |
117 ; Clear standalone_simulator after (any) dive | |
118 bsf simulatormode_active ; normal simulator mode | |
119 bsf standalone_simulator ; Standalone Simulator active | |
120 | |
121 movff logbook_temp2,xA+0 | |
122 clrf xA+1 | |
123 movlw d'100' | |
124 movwf xB+0 | |
125 clrf xB+1 | |
126 call mult16x16 ;xA*xB=xC ; Depth in m*100 | |
127 | |
62 | 128 movlw LOW d'1000' |
0 | 129 addwf xC+0,F |
62 | 130 movlw HIGH d'1000' |
131 addwfc xC+1,F ; add 1000mBar | |
132 | |
133 ; movf amb_pressure+0,W | |
134 ; addwf xC+0,F | |
135 ; movf amb_pressure+1,W | |
136 ; addwfc xC+1,F ; Add ambient pressure | |
137 ; | |
0 | 138 movff xC+0,sim_pressure+0 |
139 movff xC+1,sim_pressure+1 | |
140 | |
141 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values | |
142 movff sim_pressure+1,amb_pressure+1 | |
143 | |
144 bcf menubit2 | |
145 bcf menubit3 | |
146 bcf menubit | |
147 bcf switch_left | |
148 bcf switch_right | |
149 | |
150 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3 | |
151 | |
200 | 152 movlw d'3' ; Begin of deco cycle (reset table). |
153 movff WREG,char_O_deco_status ; Reset Deco module. | |
154 | |
0 | 155 bsf divemode ; Set divemode flag |
156 ostc_debug 'P' ; Sends debug-information to screen if debugmode active | |
157 goto diveloop ; Start Divemode | |
158 | |
159 simulator_show_decoplan: | |
124 | 160 call PLED_ClearScreen |
161 call PLED_simdata_screen | |
162 call divemenu_see_decoplan | |
163 | |
184 | 164 WIN_LEFT .0 |
165 call PLED_standard_color | |
166 | |
124 | 167 ; Display TTS, if any... |
168 | 168 movff int_O_ascenttime+0,lo |
169 movff int_O_ascenttime+1,hi | |
170 movf lo,W | |
171 iorwf hi,W | |
124 | 172 bz simulator_decoplan_notts |
184 | 173 |
124 | 174 WIN_TOP .160 |
184 | 175 lfsr FSR2, letter |
176 OUTPUTTEXT .85 ; TTS (for translation). | |
177 STRCAT ": " | |
178 bsf leftbind | |
179 output_16 | |
180 STRCAT_PRINT "'" | |
181 | |
182 simulator_decoplan_notts: | |
224 | 183 ; Print ambient pressure in DEBUG compile, because if might |
184 ; be usefull to calibrate decompression algorithm. | |
185 #ifdef __DEBUG | |
184 | 186 movff int_I_pres_surface+0,lo |
187 movff int_I_pres_surface+1,hi | |
188 | |
224 | 189 WIN_TOP .190 |
184 | 190 lfsr FSR2, letter |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
191 bsf leftbind |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
192 output_16 |
124 | 193 bcf leftbind |
184 | 194 STRCAT_PRINT " mbar" |
224 | 195 #endif |
124 | 196 |
197 WIN_INVERT .1 ; Init new Wordprocessor | |
198 DISPLAYTEXT .188 ; Sim. Results: | |
199 WIN_INVERT .0 ; Init new Wordprocessor | |
34 | 200 |
64 | 201 simulator_show_decoplan1: |
0 | 202 bcf switch_left |
203 bcf switch_right | |
204 simulator_show_decoplan2: | |
205 btfss onesecupdate | |
206 bra simulator_show_decoplan3 | |
207 | |
208 call timeout_surfmode | |
209 call set_dive_modes | |
210 call test_charger ; check if charger IC is active | |
211 call get_battery_voltage ; get battery voltage | |
212 | |
213 bcf onesecupdate ; End of one second tasks | |
214 | |
215 simulator_show_decoplan3: | |
64 | 216 btfsc switch_right |
0 | 217 bra simulator_show_decoplan4 ; Quit display |
218 | |
64 | 219 btfsc switch_left |
224 | 220 bra simulator_show_decoplan5 ; Next decoplan-page. |
0 | 221 |
222 btfsc sleepmode | |
223 goto more_menu | |
224 | |
225 btfsc divemode | |
226 goto restart ; exit menu, restart and enter divemode | |
227 | |
228 bra simulator_show_decoplan2 | |
229 | |
64 | 230 simulator_show_decoplan5: |
124 | 231 incf decoplan_page,F |
64 | 232 btfsc last_ceiling_gf_shown ; last ceiling shown? |
233 bra simulator_show_decoplan5_0 ; All done, clear and return | |
234 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
235 call PLED_decoplan ; Re-Draw Current page of GF Decoplan |
64 | 236 bra simulator_show_decoplan1 |
237 | |
231
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
238 ;---- In OCR mode, show the gas Usage special page --------------------------- |
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
239 simulator_show_decoplan5_0: |
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
240 btfss display_see_deco ; Already displayed ? |
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
241 bra simulator_show_decoplan4 ; Exit to menu. |
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
242 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
243 bcf display_see_deco ; clear flag |
224 | 244 |
231
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
245 btfsc FLAG_const_ppO2_mode ; In CCR mode ? |
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
246 bra simulator_show_decoplan4 ; YES: finished. |
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
247 |
225 | 248 ; Re-read gas change depth, from the unsorted list. |
249 movlw .27 ; Active flags. | |
250 movwf EEADR | |
251 clrf EEADRH | |
252 call read_eeprom | |
253 movff EEDATA,waitms_temp ; Save activity flags. | |
254 incf EEADR,F ; 28 == Gas#1's change depth. | |
255 | |
256 lfsr FSR2,char_I_deco_gas_change | |
257 movlw 5 | |
258 movwf wait_temp | |
259 | |
260 simulator_show_decoplan5_4: | |
261 call read_eeprom | |
262 incf EEADR,F | |
263 | |
264 rrcf waitms_temp ; Roll acticity to cary. | |
265 btfss STATUS,C | |
266 clrf EEDATA ; If not active, set depth=0 | |
267 | |
268 movff EEDATA,POSTINC2 ; Write that in depth array. | |
269 decfsz wait_temp | |
270 bra simulator_show_decoplan5_4 | |
271 | |
272 ; Compute gas consumption for each tank. | |
224 | 273 call deco_gas_volumes |
274 movlb 1 | |
275 | |
230
9406a5b0ba5e
BUGFIX Clear bottom stops when display gas usage (bug BB23)
JeanDo
parents:
229
diff
changeset
|
276 ; Clear the complete stop result column: |
9406a5b0ba5e
BUGFIX Clear bottom stops when display gas usage (bug BB23)
JeanDo
parents:
229
diff
changeset
|
277 WIN_BOX_BLACK .0, .239, .82, .160 ;top, bottom, left, right |
224 | 278 |
279 movlw d'10' | |
280 movwf waitms_temp ; Row for gas list is .10+.25 | |
281 clrf wait_temp ; Gas counter | |
282 lfsr FSR0,int_O_gas_volumes ; Initialize indexed addressing. | |
283 | |
284 WIN_LEFT .90 ; Set column | |
285 | |
286 simulator_show_decoplan5_loop: | |
287 incf wait_temp,F ; Increment gas # | |
288 | |
289 movlw .25 | |
290 addwf waitms_temp,F ; Increase row position | |
291 movff waitms_temp,win_top ; Set Row | |
292 | |
293 movff POSTINC0,lo ; Read (16bit) result, low first, | |
294 movff POSTINC0,hi ; then high. | |
295 movf lo,W ; Null ? | |
296 iorwf hi,W | |
297 bz simulator_show_decoplan5_1 ; Skip printing. | |
298 | |
299 movf lo,W ; == 65535 (saturated ?) | |
225 | 300 andwf hi,W |
224 | 301 incf WREG |
302 bnz simulator_show_decoplan5_2 | |
303 call PLED_warnings_color | |
304 STRCPY "> " | |
305 bra simulator_show_decoplan5_3 | |
306 | |
307 simulator_show_decoplan5_2: | |
308 call PLED_standard_color | |
309 STRCPY "= " | |
310 | |
311 simulator_show_decoplan5_3: | |
232 | 312 bsf leftbind |
224 | 313 output_16dp .4 ; 1 decimal. |
232 | 314 bcf leftbind |
224 | 315 call word_processor ; No unit: can be bars or litters. |
316 | |
317 ; Loop for all 5 gas | |
318 simulator_show_decoplan5_1: | |
319 movlw d'5' ; list all five gases | |
320 cpfseq wait_temp ; All gases shown? | |
321 bra simulator_show_decoplan5_loop ; No | |
322 | |
323 WIN_INVERT 1 | |
231
f9d42f8ff97b
BUGFIX Don't show (nosense) gas consumption in CCR mode (bug BB20).
JeanDo
parents:
230
diff
changeset
|
324 DISPLAYTEXTH .301 ; OCR Gas Usage: |
224 | 325 WIN_INVERT 0 |
326 | |
327 bra simulator_show_decoplan1 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
328 |
0 | 329 simulator_show_decoplan4: |
330 movlw d'5' | |
331 movwf menupos | |
332 bra menu_simulator1 | |
333 | |
334 | |
335 simulator_calc_deco: | |
336 call diveloop_boot ; configure gases, etc. | |
337 | |
338 bsf simulatormode_active ; normal simulator mode | |
339 bsf standalone_simulator ; Standalone Simulator active | |
340 | |
224 | 341 ; Save dive parameters for gas volume estimation: |
342 movff logbook_temp2,char_I_bottom_depth | |
343 movff logbook_temp1,char_I_bottom_time | |
344 | |
0 | 345 |
197 | 346 movff logbook_temp2,xA+0 ; Bottom depth. |
0 | 347 clrf xA+1 |
348 movlw d'100' | |
349 movwf xB+0 | |
350 clrf xB+1 | |
351 call mult16x16 ;xA*xB=xC ; Depth in m*100 | |
352 | |
62 | 353 movlw LOW d'1000' |
0 | 354 addwf xC+0,F |
62 | 355 movlw HIGH d'1000' |
356 addwfc xC+1,F ; add 1000mBar | |
357 | |
0 | 358 movff xC+0,sim_pressure+0 |
359 movff xC+1,sim_pressure+1 | |
360 | |
361 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values | |
362 movff sim_pressure+1,amb_pressure+1 | |
363 | |
197 | 364 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3 |
0 | 365 |
124 | 366 call PLED_topline_box |
0 | 367 WIN_INVERT .1 |
197 | 368 DISPLAYTEXT .12 ; "Wait..." |
0 | 369 WIN_INVERT .0 |
370 | |
197 | 371 call divemode_check_decogases ; Checks for decogases and sets the gases |
372 call divemode_prepare_flags_for_deco | |
200 | 373 movlw d'3' ; Begin of deco cycle (reset table). |
197 | 374 movff WREG,char_O_deco_status ; Reset Deco module. |
375 | |
0 | 376 simulator_calc_deco_loop1: |
197 | 377 call deco_calc_hauptroutine ; calc_tissue |
378 movlb b'00000001' ; rambank 1 selected | |
32 | 379 |
124 | 380 movff char_O_deco_status,WREG |
381 tstfsz WREG ; deco_status=0 if decompression calculation done | |
197 | 382 bra simulator_calc_deco_loop1 ; Not finished |
0 | 383 |
31 | 384 movlw d'1' |
197 | 385 movff WREG,char_I_step_is_1min ; 1 minute mode |
32 | 386 |
387 simulator_calc_deco_loop2: | |
388 call PLED_simulator_data | |
197 | 389 btg LED_red |
32 | 390 |
197 | 391 call divemode_check_decogases ; Checks for decogases and sets the gases |
0 | 392 call divemode_prepare_flags_for_deco |
393 | |
116 | 394 call deco_calc_hauptroutine ; calc_tissue |
197 | 395 movlb b'00000001' ; rambank 1 selected |
396 ostc_debug 'C' ; Sends debug-information to screen if debugmode active | |
397 | |
398 decfsz logbook_temp1,F ; Decrement bottom time. | |
399 bra simulator_calc_deco_loop2 | |
32 | 400 |
401 movlw d'0' | |
197 | 402 movff WREG,char_I_step_is_1min ; 2 second deco mode |
403 | |
404 simulator_calc_deco2: | |
200 | 405 btg LED_red |
406 | |
197 | 407 call divemode_check_decogases ; Checks for decogases and sets the gases |
408 call divemode_prepare_flags_for_deco | |
32 | 409 |
197 | 410 call deco_calc_hauptroutine ; calc_tissue |
411 movlb b'00000001' ; rambank 1 selected | |
0 | 412 |
197 | 413 movff char_O_deco_status,WREG |
414 tstfsz WREG ; deco_status=0 if decompression calculation done | |
415 bra simulator_calc_deco2 ; Not finished | |
0 | 416 |
197 | 417 ; Finished |
21 | 418 bsf LED_red |
0 | 419 |
420 call simulator_restore_tissue_data ; Restore 32 floats "pre_tissue" from bank3 | |
421 | |
197 | 422 bcf simulatormode_active ; normal simulator mode |
423 bcf standalone_simulator ; Standalone Simulator active | |
0 | 424 |
425 WAITMS d'250' | |
426 WAITMS d'250' | |
197 | 427 WAITMS d'250' ; Wait for Pressure Sensor to get real pressure again... |
0 | 428 |
197 | 429 bcf LED_red |
0 | 430 |
197 | 431 movlw d'5' ; Pre-Set Cursor to "Show Decoplan" |
432 movwf menupos | |
224 | 433 movff char_I_bottom_time,logbook_temp1; restore bottom time. |
197 | 434 bra menu_simulator1 ; Done. |
49 | 435 |
436 simulator_save_tissue_data: | |
437 bsf restore_deco_data ; Set restore flag | |
438 ostc_debug 'S' ; Sends debug-information to screen if debugmode active | |
116 | 439 call deco_push_tissues_to_vault |
49 | 440 movlb 0x01 ; Back to RAM Bank1 |
441 ostc_debug 'T' ; Sends debug-information to screen if debugmode active | |
442 return | |
443 | |
444 simulator_restore_tissue_data: | |
229
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
445 bcf restore_deco_data ; clear restore flag |
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
446 ostc_debug 'S' ; Sends debug-information to screen if debugmode active |
116 | 447 call deco_pull_tissues_from_vault |
49 | 448 movlb 0x01 ; Back to RAM Bank1 |
229
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
449 ostc_debug 'T' ; Sends debug-information to screen if debugmode active |
49 | 450 |
451 ostc_debug 'G' ; Sends debug-information to screen if debugmode active | |
116 | 452 call deco_calc_desaturation_time ; calculate desaturation time |
229
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
453 movlb b'00000001' ; select ram bank 1 |
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
454 |
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
455 ; Note: should not reset nofly-time here: the true value have continued to be decremented |
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
456 ; during simulation, which is the right thing to do... |
49 | 457 ostc_debug 'H' ; Sends debug-information to screen if debugmode active |
458 | |
459 ; Calculate CNS | |
229
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
460 call deco_calc_CNS_fraction ; calculate CNS |
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
461 movlb b'00000001' ; rambank 1 selected |
85ea09d3b9d8
Nofly should not be reset after dive simulation (bug BB18).
JeanDo
parents:
225
diff
changeset
|
462 |
49 | 463 return |