Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/divemode.asm @ 33:6e5db85382a2
Speedy simulator! New Deco code test 1
author | heinrichsweikamp |
---|---|
date | Tue, 25 May 2010 17:37:26 +0200 |
parents | 99512945c7a1 |
children | d4f0c097a7fa |
comparison
equal
deleted
inserted
replaced
32:a776039bda63 | 33:6e5db85382a2 |
---|---|
317 | 317 |
318 ; Check for decompression gases if in decomode | 318 ; Check for decompression gases if in decomode |
319 divemode_check_decogases: ; CALLed from Simulator | 319 divemode_check_decogases: ; CALLed from Simulator |
320 btfss dekostop_active | 320 btfss dekostop_active |
321 bra reset_decompression_gases ; While in NDL, do not set deompression gas | 321 bra reset_decompression_gases ; While in NDL, do not set deompression gas |
322 ; 1. Find active gas with deepest change depth < current depth | 322 |
323 ; 2. Set Decogas | 323 ; Copy active gases to char_I_deco_N2_ratio and char_I_deco_He_ratio |
324 | 324 |
325 movff rel_pressure+0,xA+0 | 325 clrf hi ; # of gas (0-4) |
326 movff rel_pressure+1,xA+1 | 326 ; Gas0 is Start gas, do not copy |
327 movlw d'100' | 327 |
328 movwf xB+0 | 328 lfsr FSR1, char_I_deco_He_ratio5 ; most shallow decogas |
329 clrf xB+1 | 329 |
330 call div16x16 ; compute depth in full m -> result in xC+0 | 330 divemode_check_decogases2: |
331 clrf lo ; clear depth for comparison | 331 incf hi,F ; increase |
332 | 332 rcall copy_decogas_info |
333 ; check gas1 | 333 movlw d'4' |
334 cpfseq hi ; 4 Gases copied? | |
335 bra divemode_check_decogases2 ; No, Continue | |
336 | |
337 ; Now, set change depth. Inactive gases get depth=0! | |
338 | |
334 read_int_eeprom d'27' ; read flag register | 339 read_int_eeprom d'27' ; read flag register |
335 btfss EEDATA,0 ; check active flag | 340 movff EEDATA,hi ; temp |
336 bra check_decogas2 ; skip inactive gases! | 341 |
337 read_int_eeprom d'28' ; read gas_change_depth | 342 read_int_eeprom d'28' ; read gas_change_depth Gas1 |
338 movf xC+0,W ; load depth in m into WREG | 343 movlw d'0' |
339 cpfslt EEDATA ; gas_change_depth > current depth? | 344 btfsc hi,1 ; Skip if clear -> Skip if inactive |
340 bra check_decogas2 ; W < EEDATA -> current depth lower then gas_change_depth | 345 movf EEDATA,W |
341 | 346 movff WREG,char_I_deco_gas_change5 |
342 movff EEDATA,lo ; deepest gas_change_depth in lo | 347 |
343 movlw d'1' | 348 read_int_eeprom d'29' ; read gas_change_depth Gas2 |
344 movwf hi ; Decogas # in hi (1-5) | 349 movlw d'0' |
345 | 350 btfsc hi,2 ; Skip if clear -> Skip if inactive |
346 check_decogas2: | 351 movf EEDATA,W |
347 read_int_eeprom d'27' ; read flag register | 352 movff WREG,char_I_deco_gas_change4 |
348 btfss EEDATA,1 ; check active flag | 353 |
349 bra check_decogas3 ; skip inactive gases! | 354 read_int_eeprom d'30' ; read gas_change_depth Gas3 |
350 read_int_eeprom d'29' ; read gas_change_depth | 355 movlw d'0' |
351 movf xC+0,W ; load depth in m into WREG | 356 btfsc hi,3 ; Skip if clear -> Skip if inactive |
352 cpfslt EEDATA ; gas_change_depth > current depth? | 357 movf EEDATA,W |
353 bra check_decogas3 ; W < EEDATA -> current depth lower then gas_change_depth | 358 movff WREG,char_I_deco_gas_change3 |
354 | 359 |
355 read_int_eeprom d'29' ; read gas_change_depth | 360 read_int_eeprom d'31' ; read gas_change_depth Gas1 |
356 movf lo,W ; load current gas_change_depth into WREG | 361 movlw d'0' |
357 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | 362 btfsc hi,4 ; Skip if clear -> Skip if inactive |
358 bra check_decogas3 ; W < lo -> last gas_change_depth > current gas_change_depth | 363 movf EEDATA,W |
359 movff EEDATA,lo ; deepest gas_change_depth in lo | 364 movff WREG,char_I_deco_gas_change2 |
360 movlw d'2' | 365 |
361 movwf hi ; Decogas # in hi (1-5) | 366 return |
362 | 367 |
363 check_decogas3: | 368 copy_decogas_info: |
364 read_int_eeprom d'27' ; read flag register | 369 movf hi,W ; Gas 1-4 |
365 btfss EEDATA,2 ; check active flag | 370 mullw d'4' ; times 4... |
366 bra check_decogas4 ; skip inactive gases! | 371 movf PRODL,W ; |
367 read_int_eeprom d'30' ; read gas_change_depth | 372 addlw d'7' ; +7 = address for He ratio |
368 movf xC+0,W ; load depth in m into WREG | |
369 cpfslt EEDATA ; gas_change_depth > current depth? | |
370 bra check_decogas4 ; W < EEDATA -> current depth lower then gas_change_depth | |
371 | |
372 read_int_eeprom d'30' ; read gas_change_depth | |
373 movf lo,W ; load current gas_change_depth into WREG | |
374 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
375 bra check_decogas4 ; W < lo -> last gas_change_depth > current gas_change_depth | |
376 movff EEDATA,lo ; deepest gas_change_depth in lo | |
377 movlw d'3' | |
378 movwf hi ; Decogas # in hi (1-5) | |
379 | |
380 check_decogas4: | |
381 read_int_eeprom d'27' ; read flag register | |
382 btfss EEDATA,3 ; check active flag | |
383 bra check_decogas5 ; skip inactive gases! | |
384 read_int_eeprom d'31' ; read gas_change_depth | |
385 movf xC+0,W ; load depth in m into WREG | |
386 cpfslt EEDATA ; gas_change_depth > current depth? | |
387 bra check_decogas5 ; W < EEDATA -> current depth lower then gas_change_depth | |
388 | |
389 read_int_eeprom d'31' ; read gas_change_depth | |
390 movf lo,W ; load current gas_change_depth into WREG | |
391 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
392 bra check_decogas5 ; W < lo -> last gas_change_depth > current gas_change_depth | |
393 movff EEDATA,lo ; deepest gas_change_depth in lo | |
394 movlw d'4' | |
395 movwf hi ; Decogas # in hi (1-5) | |
396 | |
397 check_decogas5: | |
398 read_int_eeprom d'27' ; read flag register | |
399 btfss EEDATA,4 ; check active flag | |
400 bra check_decogas_done ; skip inactive gases! | |
401 read_int_eeprom d'32' ; read gas_change_depth | |
402 movf xC+0,W ; load depth in m into WREG | |
403 cpfslt EEDATA ; gas_change_depth > current depth? | |
404 bra check_decogas_done ; W < EEDATA -> current depth lower then gas_change_depth | |
405 | |
406 read_int_eeprom d'32' ; read gas_change_depth | |
407 movf lo,W ; load current gas_change_depth into WREG | |
408 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
409 bra check_decogas_done ; W < lo -> last gas_change_depth > current gas_change_depth | |
410 movff EEDATA,lo ; deepest gas_change_depth in lo | |
411 movlw d'5' | |
412 movwf hi ; Decogas # in hi (1-5) | |
413 | |
414 check_decogas_done: | |
415 ostc_debug 'E' ; Sends debug-information to screen if debugmode active | |
416 | |
417 decf hi,F ; Gas 0-4 | |
418 movff lo, char_I_deco_gas_change ; copy change_depth | |
419 | |
420 movf hi,W ; Gas 0-4 | |
421 mullw d'4' | |
422 movf PRODL,W | |
423 addlw d'7' ; = address for He ratio | |
424 movwf EEADR | 373 movwf EEADR |
425 call read_eeprom ; Read He ratio | 374 call read_eeprom ; Read He ratio |
426 movff EEDATA,char_I_deco_He_ratio ; And copy into hold register | 375 movff EEDATA,INDF1 ; And copy into hold register |
427 | 376 |
428 | 377 movf hi,W ; Gas 1-4 |
429 movf hi,W ; Gas 0-4 | 378 mullw d'4' ; times 4... |
430 mullw d'4' | 379 movf PRODL,W ; |
431 movf PRODL,W | 380 addlw d'6' ; +6 = address for O2 ratio |
432 addlw d'6' ; = address for O2 ratio | |
433 movwf EEADR | 381 movwf EEADR |
434 call read_eeprom ; Read O2 ratio | 382 call read_eeprom ; Read O2 ratio |
435 | 383 ; movff EEDATA, char_I_O2_ratio ; O2 ratio |
436 movff char_I_deco_He_ratio, wait_temp ; copy into bank1 register | 384 movff POSTDEC1, wait_temp ; copy into bank1 register |
437 bsf STATUS,C ; Borrow bit | 385 bsf STATUS,C ; |
438 movlw d'100' ; 100% | 386 movlw d'100' ; 100% |
439 subfwb wait_temp,W ; minus He | 387 subfwb wait_temp,W ; minus He |
440 bsf STATUS,C ; Borrow bit | |
441 subfwb EEDATA,F ; minus O2 | 388 subfwb EEDATA,F ; minus O2 |
442 movff EEDATA, char_I_deco_N2_ratio ; = N2! | 389 movff EEDATA, POSTDEC1 ; = N2! |
443 bra skip_decompression_gases | 390 return |
444 | 391 |
392 ;; 1. Find active gas with deepest change depth < current depth | |
393 ;; 2. Set Decogas | |
394 ; | |
395 ; movff rel_pressure+0,xA+0 | |
396 ; movff rel_pressure+1,xA+1 | |
397 ; movlw d'100' | |
398 ; movwf xB+0 | |
399 ; clrf xB+1 | |
400 ; call div16x16 ; compute depth in full m -> result in xC+0 | |
401 ; clrf lo ; clear depth for comparison | |
402 ; | |
403 ;; check gas1 | |
404 ; read_int_eeprom d'27' ; read flag register | |
405 ; btfss EEDATA,0 ; check active flag | |
406 ; bra check_decogas2 ; skip inactive gases! | |
407 ; read_int_eeprom d'28' ; read gas_change_depth | |
408 ; movf xC+0,W ; load depth in m into WREG | |
409 ; cpfslt EEDATA ; gas_change_depth > current depth? | |
410 ; bra check_decogas2 ; W < EEDATA -> current depth lower then gas_change_depth | |
411 ; | |
412 ; movff EEDATA,lo ; deepest gas_change_depth in lo | |
413 ; movlw d'1' | |
414 ; movwf hi ; Decogas # in hi (1-5) | |
415 ; | |
416 ;check_decogas2: | |
417 ; read_int_eeprom d'27' ; read flag register | |
418 ; btfss EEDATA,1 ; check active flag | |
419 ; bra check_decogas3 ; skip inactive gases! | |
420 ; read_int_eeprom d'29' ; read gas_change_depth | |
421 ; movf xC+0,W ; load depth in m into WREG | |
422 ; cpfslt EEDATA ; gas_change_depth > current depth? | |
423 ; bra check_decogas3 ; W < EEDATA -> current depth lower then gas_change_depth | |
424 ; | |
425 ; read_int_eeprom d'29' ; read gas_change_depth | |
426 ; movf lo,W ; load current gas_change_depth into WREG | |
427 ; cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
428 ; bra check_decogas3 ; W < lo -> last gas_change_depth > current gas_change_depth | |
429 ; movff EEDATA,lo ; deepest gas_change_depth in lo | |
430 ; movlw d'2' | |
431 ; movwf hi ; Decogas # in hi (1-5) | |
432 ; | |
433 ;check_decogas3: | |
434 ; read_int_eeprom d'27' ; read flag register | |
435 ; btfss EEDATA,2 ; check active flag | |
436 ; bra check_decogas4 ; skip inactive gases! | |
437 ; read_int_eeprom d'30' ; read gas_change_depth | |
438 ; movf xC+0,W ; load depth in m into WREG | |
439 ; cpfslt EEDATA ; gas_change_depth > current depth? | |
440 ; bra check_decogas4 ; W < EEDATA -> current depth lower then gas_change_depth | |
441 ; | |
442 ; read_int_eeprom d'30' ; read gas_change_depth | |
443 ; movf lo,W ; load current gas_change_depth into WREG | |
444 ; cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
445 ; bra check_decogas4 ; W < lo -> last gas_change_depth > current gas_change_depth | |
446 ; movff EEDATA,lo ; deepest gas_change_depth in lo | |
447 ; movlw d'3' | |
448 ; movwf hi ; Decogas # in hi (1-5) | |
449 ; | |
450 ;check_decogas4: | |
451 ; read_int_eeprom d'27' ; read flag register | |
452 ; btfss EEDATA,3 ; check active flag | |
453 ; bra check_decogas5 ; skip inactive gases! | |
454 ; read_int_eeprom d'31' ; read gas_change_depth | |
455 ; movf xC+0,W ; load depth in m into WREG | |
456 ; cpfslt EEDATA ; gas_change_depth > current depth? | |
457 ; bra check_decogas5 ; W < EEDATA -> current depth lower then gas_change_depth | |
458 ; | |
459 ; read_int_eeprom d'31' ; read gas_change_depth | |
460 ; movf lo,W ; load current gas_change_depth into WREG | |
461 ; cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
462 ; bra check_decogas5 ; W < lo -> last gas_change_depth > current gas_change_depth | |
463 ; movff EEDATA,lo ; deepest gas_change_depth in lo | |
464 ; movlw d'4' | |
465 ; movwf hi ; Decogas # in hi (1-5) | |
466 ; | |
467 ;check_decogas5: | |
468 ; read_int_eeprom d'27' ; read flag register | |
469 ; btfss EEDATA,4 ; check active flag | |
470 ; bra check_decogas_done ; skip inactive gases! | |
471 ; read_int_eeprom d'32' ; read gas_change_depth | |
472 ; movf xC+0,W ; load depth in m into WREG | |
473 ; cpfslt EEDATA ; gas_change_depth > current depth? | |
474 ; bra check_decogas_done ; W < EEDATA -> current depth lower then gas_change_depth | |
475 ; | |
476 ; read_int_eeprom d'32' ; read gas_change_depth | |
477 ; movf lo,W ; load current gas_change_depth into WREG | |
478 ; cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
479 ; bra check_decogas_done ; W < lo -> last gas_change_depth > current gas_change_depth | |
480 ; movff EEDATA,lo ; deepest gas_change_depth in lo | |
481 ; movlw d'5' | |
482 ; movwf hi ; Decogas # in hi (1-5) | |
483 ; | |
484 ;check_decogas_done: | |
485 ; ostc_debug 'E' ; Sends debug-information to screen if debugmode active | |
486 ; | |
487 ; decf hi,F ; Gas 0-4 | |
488 ; movff lo, char_I_deco_gas_change ; copy change_depth | |
489 ; | |
490 ; movf hi,W ; Gas 0-4 | |
491 ; mullw d'4' | |
492 ; movf PRODL,W | |
493 ; addlw d'7' ; = address for He ratio | |
494 ; movwf EEADR | |
495 ; call read_eeprom ; Read He ratio | |
496 ; movff EEDATA,char_I_deco_He_ratio ; And copy into hold register | |
497 ; | |
498 ; | |
499 ; movf hi,W ; Gas 0-4 | |
500 ; mullw d'4' | |
501 ; movf PRODL,W | |
502 ; addlw d'6' ; = address for O2 ratio | |
503 ; movwf EEADR | |
504 ; call read_eeprom ; Read O2 ratio | |
505 ; | |
506 ; movff char_I_deco_He_ratio, wait_temp ; copy into bank1 register | |
507 ; bsf STATUS,C ; Borrow bit | |
508 ; movlw d'100' ; 100% | |
509 ; subfwb wait_temp,W ; minus He | |
510 ; bsf STATUS,C ; Borrow bit | |
511 ; subfwb EEDATA,F ; minus O2 | |
512 ; movff EEDATA, char_I_deco_N2_ratio ; = N2! | |
513 ; bra skip_decompression_gases | |
514 ; | |
445 reset_decompression_gases: ; reset the deco gas while in NDL | 515 reset_decompression_gases: ; reset the deco gas while in NDL |
446 ostc_debug 'F' ; Sends debug-information to screen if debugmode active | 516 ostc_debug 'F' ; Sends debug-information to screen if debugmode active |
447 clrf lo | 517 clrf lo |
448 movff lo, char_I_deco_gas_change ; clear | 518 movff lo, char_I_deco_gas_change ; clear |
449 movff lo, char_I_deco_N2_ratio ; clear | 519 movff lo, char_I_deco_N2_ratio ; clear |
516 store_dive_data: ; CF20 seconds gone | 586 store_dive_data: ; CF20 seconds gone |
517 bcf store_sample ; update only any CF20 seconds | 587 bcf store_sample ; update only any CF20 seconds |
518 bsf update_divetime ; update divemins every CF20 seconds | 588 bsf update_divetime ; update divemins every CF20 seconds |
519 | 589 |
520 bcf LED_red ; LEDr off (Marker) | 590 bcf LED_red ; LEDr off (Marker) |
591 | |
592 btfsc simulatormode_active ; Are we in simulator mode? | |
593 return ; Yes, discard everything | |
521 | 594 |
522 btfsc header_stored ; Header already stored? | 595 btfsc header_stored ; Header already stored? |
523 bra store_dive_data2 ; Yes, store only profile data | 596 bra store_dive_data2 ; Yes, store only profile data |
524 bsf header_stored ; Store header | 597 bsf header_stored ; Store header |
525 | 598 |
1045 | 1118 |
1046 end_dive: | 1119 end_dive: |
1047 btfss realdive ; dive longer then one minute | 1120 btfss realdive ; dive longer then one minute |
1048 goto end_dive_common ; No, discard everything | 1121 goto end_dive_common ; No, discard everything |
1049 | 1122 |
1123 btfsc simulatormode_active ; Are we in simulator mode? | |
1124 goto end_dive_common ; Yes, discard everything | |
1125 | |
1050 ; Dive finished (and longer then one minute or Apnoe timeout occured) | 1126 ; Dive finished (and longer then one minute or Apnoe timeout occured) |
1051 | 1127 |
1052 btfsc FLAG_apnoe_mode ; Calc max. depth (again) for very short apnoe dives | 1128 btfsc FLAG_apnoe_mode ; Calc max. depth (again) for very short apnoe dives |
1053 rcall apnoe_calc_maxdepth | 1129 rcall apnoe_calc_maxdepth |
1054 | 1130 |
1296 movff hi,EEDATA | 1372 movff hi,EEDATA |
1297 call write_eeprom ; Highbyte | 1373 call write_eeprom ; Highbyte |
1298 | 1374 |
1299 change_logbook_offset2: | 1375 change_logbook_offset2: |
1300 bcf LED_blue | 1376 bcf LED_blue |
1377 | |
1378 end_dive_common: | |
1301 bcf simulatormode_active ; if we were in simulator mode | 1379 bcf simulatormode_active ; if we were in simulator mode |
1302 | 1380 |
1303 end_dive_common: | |
1304 btfsc restore_deco_data ; Restore decodata? | 1381 btfsc restore_deco_data ; Restore decodata? |
1305 call simulator_restore_tissue_data ; Yes! | 1382 call simulator_restore_tissue_data ; Yes! |
1306 | 1383 |
1307 call deco_main_gradient_array | 1384 call deco_main_gradient_array |
1308 movlb b'00000001' ; select ram bank 1 | 1385 movlb b'00000001' ; select ram bank 1 |