comparison code_part1/OSTC_code_asm_part1/simulator.asm @ 292:21a0f7393468

New CNS calculation in decoplan. BUGFIX set current gas in decoplan.
author JeanDo
date Mon, 25 Apr 2011 19:42:44 +0200
parents 4dbff2aa31ee
children d36fe3651d56 2144f19fa1eb
comparison
equal deleted inserted replaced
291:916df3161d52 292:21a0f7393468
167 movff int_O_ascenttime+1,hi 167 movff int_O_ascenttime+1,hi
168 movf lo,W 168 movf lo,W
169 iorwf hi,W 169 iorwf hi,W
170 bz simulator_decoplan_notts 170 bz simulator_decoplan_notts
171 171
172 WIN_TOP .160 172 WIN_TOP .162
173 lfsr FSR2, letter 173 lfsr FSR2, letter
174 OUTPUTTEXT .85 ; TTS 174 OUTPUTTEXT .85 ; TTS
175 STRCAT ": " 175 STRCAT ": "
176 bsf leftbind 176 bsf leftbind
177 output_16 177 output_16
178 STRCAT_PRINT "'" 178 STRCAT_PRINT "'"
179 179
180 simulator_decoplan_notts: 180 simulator_decoplan_notts:
181 ; Print ambient pressure in DEBUG compile, because if might 181 WIN_TOP .190 ; Print calculated CNS before and after dive
182 ; be usefull to calibrate decompression algorithm. 182 STRCPY "CNS:"
183 #ifdef __DEBUG 183 movff char_O_CNS_fraction,lo ; Current CNS, before dive.
184 movff int_I_pres_surface+0,lo 184 output_8
185 movff int_I_pres_surface+1,hi 185
186 186 STRCAT "%\x92" ; Right-arrow
187 WIN_TOP .190 187 movff logbook_temp3,lo ; Get back CNS value.
188 lfsr FSR2, letter 188 output_8 ; CNS after dive.
189 bsf leftbind 189 STRCAT_PRINT "%"
190 output_16
191 bcf leftbind
192 STRCAT_PRINT " mbar"
193 #endif
194 190
195 WIN_INVERT .1 ; Init new Wordprocessor 191 WIN_INVERT .1 ; Init new Wordprocessor
196 DISPLAYTEXT .188 ; Sim. Results: 192 DISPLAYTEXT .188 ; Sim. Results:
197 WIN_INVERT .0 ; Init new Wordprocessor 193 WIN_INVERT .0 ; Init new Wordprocessor
198 194
251 ; Compute gas consumption for each tank. 247 ; Compute gas consumption for each tank.
252 call deco_gas_volumes 248 call deco_gas_volumes
253 movlb 1 249 movlb 1
254 250
255 ; Clear the complete stop result column: 251 ; Clear the complete stop result column:
256 WIN_BOX_BLACK .0, .239, .82, .160 ;top, bottom, left, right 252 WIN_BOX_BLACK .0, .239, .85, .160 ;top, bottom, left, right
257 253
258 movlw d'10' 254 movlw d'10'
259 movwf waitms_temp ; Row for gas list is .10+.25 255 movwf waitms_temp ; Row for gas list is .10+.25
260 clrf wait_temp ; Gas counter 256 clrf wait_temp ; Gas counter
261 lfsr FSR0,int_O_gas_volumes ; Initialize indexed addressing. 257 lfsr FSR0,int_O_gas_volumes ; Initialize indexed addressing.
314 bra menu_simulator1 310 bra menu_simulator1
315 311
316 simulator_calc_deco: 312 simulator_calc_deco:
317 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3 313 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3
318 314
319 bsf simulatormode_active ; normal simulator mode 315 bsf simulatormode_active ; normal simulator mode
320 bsf standalone_simulator ; Standalone Simulator active 316 bsf standalone_simulator ; Standalone Simulator active
321 bsf no_sensor_int ; Disable sensor interrupt 317 bsf no_sensor_int ; Disable sensor interrupt
322 clrf T3CON ; Restart time3 counter, 318 clrf T3CON ; Restart time3 counter,
323 clrf TMR3L ; so the simu won't stop right away. 319 clrf TMR3L ; so the simu won't stop right away.
324 clrf TMR3H 320 clrf TMR3H
325 321
326 call diveloop_boot ; configure gases, etc. 322 call diveloop_boot ; configure gases, etc.
327 323
328 ; Save dive parameters for gas volume estimation: 324 ; Save dive parameters for gas volume estimation:
329 movff logbook_temp2,char_I_bottom_depth 325 movff logbook_temp2,char_I_bottom_depth
330 movff logbook_temp1,char_I_bottom_time 326 movff logbook_temp1,char_I_bottom_time
331 327
332 movff logbook_temp2,xA+0 ; Bottom depth. 328 movff logbook_temp2,xA+0 ; Bottom depth.
333 clrf xA+1 329 clrf xA+1
334 movlw d'100' 330 movlw d'100'
335 movwf xB+0 331 movwf xB+0
336 clrf xB+1 332 clrf xB+1
337 call mult16x16 ;xA*xB=xC ; Depth in m*100 333 call mult16x16 ;xA*xB=xC, Depth in m*100
338 334
339 movlw LOW d'1000' 335 movlw LOW d'1000'
340 addwf xC+0,F 336 addwf xC+0,F
341 movlw HIGH d'1000' 337 movlw HIGH d'1000'
342 addwfc xC+1,F ; add 1000mBar 338 addwfc xC+1,F ; add 1000mBar
343 339
344 movff xC+0,sim_pressure+0 340 movff xC+0,sim_pressure+0
345 movff xC+1,sim_pressure+1 341 movff xC+1,sim_pressure+1
346 342
347 call PLED_topline_box 343 call PLED_topline_box
348 WIN_INVERT .1 344 WIN_INVERT .1
349 DISPLAYTEXT .12 ; "Wait..." 345 DISPLAYTEXT .12 ; "Wait..."
350 WIN_INVERT .0 346 WIN_INVERT .0
351 347
352 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values 348 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values
353 movff sim_pressure+1,amb_pressure+1 349 movff sim_pressure+1,amb_pressure+1
354 350
355 call divemode_check_decogases ; Checks for decogases and sets the gases 351 call divemode_check_decogases ; Checks for decogases and sets the gases
356 call divemode_prepare_flags_for_deco 352 call divemode_prepare_flags_for_deco
353 call set_first_gas ; Set current N2/He/O2 ratios.
354 call set_actual_ppo2 ; Then configure char_I_actual_ppO2
357 355
358 ; First minute is special: init everything. 356 ; First minute is special: init everything.
359 movlw d'3' ; Begin of deco cycle (reset table). 357 movlw d'3' ; Begin of deco cycle (reset table).
360 movff WREG,char_O_deco_status ; Reset Deco module. 358 movff WREG,char_O_deco_status ; Reset Deco module.
361 359
362 movlw d'1' 360 movlw d'1'
363 movff WREG,char_I_step_is_1min ; 1 minute mode. 361 movff WREG,char_I_step_is_1min ; 1 minute mode.
364 362
365 call deco_calc_hauptroutine ; Reset table + sim one minute for descent. 363 call deco_calc_hauptroutine ; Reset table + sim one minute for descent.
364 call deco_calc_CNS_fraction ; Also calculate CNS (in 1min loop)
366 movlb b'00000001' ; rambank 1 selected 365 movlb b'00000001' ; rambank 1 selected
367 366
368 decf logbook_temp1,F ; One minute done. 367 decf logbook_temp1,F ; One minute done.
369 368
370 ; Loop for bottom time duration 369 ; Loop for bottom time duration
371 simulator_calc_deco_loop2: 370 simulator_calc_deco_loop2:
372 call PLED_simulator_data ; Update display of bottom time. 371 call PLED_simulator_data ; Update display of bottom time.
373 372
374 call deco_calc_tissue ; JUST calc tissue (faster). 373 call deco_calc_tissue ; JUST calc tissue (faster).
375 movlb b'00000001' ; rambank 1 selected 374 call deco_calc_CNS_fraction ; Also calculate CNS (in 1min loop)
376 ostc_debug 'C' ; Sends debug-information to screen if debugmode active 375 movlb b'00000001' ; rambank 1 selected
376 ostc_debug 'C' ; Sends debug-information to screen if debugmode active
377 377
378 decfsz logbook_temp1,F ; Decrement bottom time, 378 decfsz logbook_temp1,F ; Decrement bottom time,
379 bra simulator_calc_deco_loop2 ; and loop while not finished. 379 bra simulator_calc_deco_loop2 ; and loop while not finished.
380 380
381 ; No the bottom time is finish, restart a full ascent simulation, 381 ; No the bottom time is finish, restart a full ascent simulation,
397 397
398 movff char_O_deco_status,WREG 398 movff char_O_deco_status,WREG
399 iorwf WREG ; deco_status=0 if decompression calculation done 399 iorwf WREG ; deco_status=0 if decompression calculation done
400 bnz simulator_calc_deco2 ; Not finished 400 bnz simulator_calc_deco2 ; Not finished
401 401
402 ; Finished
402 simulator_calc_deco3: 403 simulator_calc_deco3:
403 ; Finished 404 movff char_O_CNS_fraction,logbook_temp3 ; Save calculated CNS.
404 rcall simulator_restore_tissue_data ; Restore 32 floats "pre_tissue" from bank3 405 rcall simulator_restore_tissue_data ; Restore CNS & 32 floats "pre_tissue" from vault
405 406
406 bcf simulatormode_active ; normal simulator mode 407 bcf simulatormode_active ; normal simulator mode
407 bcf standalone_simulator ; Standalone Simulator active 408 bcf standalone_simulator ; Standalone Simulator active
408 bcf no_sensor_int ; Re-enable sensor interrupt 409 bcf no_sensor_int ; Re-enable sensor interrupt
409 410
426 return 427 return
427 428
428 simulator_restore_tissue_data: 429 simulator_restore_tissue_data:
429 bcf restore_deco_data ; clear restore flag 430 bcf restore_deco_data ; clear restore flag
430 ostc_debug 'S' ; Sends debug-information to screen if debugmode active 431 ostc_debug 'S' ; Sends debug-information to screen if debugmode active
431 call deco_pull_tissues_from_vault 432 call deco_pull_tissues_from_vault ; Restore CNS too...
432 movlb 0x01 ; Back to RAM Bank1 433 movlb 0x01 ; Back to RAM Bank1
433 ostc_debug 'T' ; Sends debug-information to screen if debugmode active 434 ostc_debug 'T' ; Sends debug-information to screen if debugmode active
434 435
435 ostc_debug 'G' ; Sends debug-information to screen if debugmode active 436 ostc_debug 'G' ; Sends debug-information to screen if debugmode active
436 call deco_calc_desaturation_time ; calculate desaturation time 437 call deco_calc_desaturation_time ; calculate desaturation time
438 439
439 ; Note: should not reset nofly-time here: the true value have continued to be decremented 440 ; Note: should not reset nofly-time here: the true value have continued to be decremented
440 ; during simulation, which is the right thing to do... 441 ; during simulation, which is the right thing to do...
441 ostc_debug 'H' ; Sends debug-information to screen if debugmode active 442 ostc_debug 'H' ; Sends debug-information to screen if debugmode active
442 443
443 ; Calculate CNS
444 call deco_calc_CNS_fraction ; calculate CNS
445 movlb b'00000001' ; rambank 1 selected
446
447 return 444 return