comparison src/simulator.asm @ 634:4050675965ea

3.10 stable release
author heinrichsweikamp
date Tue, 28 Apr 2020 17:34:31 +0200
parents 185ba2f91f59
children 9a64914a8fca
comparison
equal deleted inserted replaced
633:690c48db7b5b 634:4050675965ea
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File simulator.asm combined next generation V3.08.8 3 ; File simulator.asm * combined next generation V3.09.5
4 ; 4 ;
5 ; Deco Calculator 5 ; Deco Calculator
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
21 #include "eeprom_rs232.inc" 21 #include "eeprom_rs232.inc"
22 #include "tft_outputs.inc" 22 #include "tft_outputs.inc"
23 #include "gaslist.inc" 23 #include "gaslist.inc"
24 #include "surfmode.inc" 24 #include "surfmode.inc"
25 #include "wait.inc" 25 #include "wait.inc"
26 #include "colorschemes.inc"
26 27
27 28
28 extern deco_push_tissues_to_vault 29 extern deco_push_tissues_to_vault
29 extern deco_calc_dive_interval 30 extern deco_calc_dive_interval
30 extern deco_calc_hauptroutine 31 extern deco_calc_hauptroutine
31 extern deco_pull_tissues_from_vault 32 extern deco_pull_tissues_from_vault
32 extern TFT_decotype_logbook 33 extern do_return_menu_simulator_planner
33 extern do_return_demo_planner
34 extern convert_meter_to_feet 34 extern convert_meter_to_feet
35 extern dive_boot_oc 35 extern dive_boot_oc
36 extern get_first_gas_to_WREG 36 extern get_first_gas_to_WREG
37 37
38 IFDEF _ccr_pscr 38 IFDEF _ccr_pscr
66 ; decoplan_flags,5 ; --- unused 66 ; decoplan_flags,5 ; --- unused
67 ; decoplan_flags,6 ; --- unused 67 ; decoplan_flags,6 ; --- unused
68 ; decoplan_flags,7 ; --- unused 68 ; decoplan_flags,7 ; --- unused
69 69
70 70
71 ;---- Macro for easier Code Writing ------------------------------------------
72
73 ; print a multi-lingual text at position horizontal x, vertical y in tiny font
74 TEXT_SMALL macro x, y, txt
75 WIN_SMALL x,y
76 STRCPY_TEXT_PRINT txt
77 endm
78
79
80 ;=============================================================================
71 simulator CODE 81 simulator CODE
82 ;=============================================================================
83
72 84
73 ;----------------------------------------------------------------------------- 85 ;-----------------------------------------------------------------------------
74 86 ; Entry Point for Deco Calculator
75 ;============================================================================= 87 ;
76 ; Deco Calculator Main Function 88 global demo_planner
77 ; 89 demo_planner:
78 global do_demo_planner
79 do_demo_planner:
80 btfsc FLAG_gauge_mode ; in gauge mode? 90 btfsc FLAG_gauge_mode ; in gauge mode?
81 bra do_demo_planner_exit ; YES - abort 91 bra do_demo_planner_exit ; YES - abort
82 btfsc FLAG_apnoe_mode ; in apnea mode? 92 btfsc FLAG_apnoe_mode ; in apnea mode?
83 bra do_demo_planner_exit ; YES - abort 93 bra do_demo_planner_exit ; YES - abort
84 94
85 clrf decoplan_flags ; clear all local flags 95 clrf decoplan_flags ; clear all local flags
86 bsf simulatormode ; activate simulator mode 96 bsf simulatormode ; activate simulator mode
87 bsf reset_timebase ; request ISR to reset the timebase 97 bsf reset_timebase ; request ISR to reset the timebase
88 ; btfsc reset_timebase ; has the ISR confirmed reset of the timebase? 98
89 ; bra $-2 ; NO - not yet, loop waiting for the ISR
90 call deco_push_tissues_to_vault ; back-up the state of the real tissues (C-code) 99 call deco_push_tissues_to_vault ; back-up the state of the real tissues (C-code)
91 banksel common ; back to bank common 100 banksel common ; back to bank common
92 101
93 MOVII int_O_CNS_current,real_CNS ; memorize real CNS value from before simulated dive 102 MOVII int_O_CNS_current,real_CNS ; memorize real CNS value from before simulated dive
94 103
96 105
97 btfss decoplan_abort ; was the deco plan calculation aborted? 106 btfss decoplan_abort ; was the deco plan calculation aborted?
98 rcall deco_results ; NO - show results 107 rcall deco_results ; NO - show results
99 108
100 movff simulator_time,char_I_dive_interval ; get the deco calculator runtime 109 movff simulator_time,char_I_dive_interval ; get the deco calculator runtime
110
101 call deco_pull_tissues_from_vault ; restore the status of the real tissues (C-code) 111 call deco_pull_tissues_from_vault ; restore the status of the real tissues (C-code)
102 call deco_calc_dive_interval ; catch up with tissue desaturation (C-code) 112 call deco_calc_dive_interval ; catch up with tissue desaturation (C-code)
103 call deco_calc_desaturation_time ; calculate desaturation and no-fly/no-altitude time after catch-up (C-code) 113 call deco_calc_desaturation_time ; calculate desaturation and no-fly/no-altitude time after catch-up (C-code)
104 banksel common ; back to bank common 114 banksel common ; back to bank common
105 115
106 bcf switch_left ; clear left button event (may be left over from abort/exit) 116 bcf switch_left ; clear left button event (may be left over from abort/exit)
107 bcf simulatormode ; terminate simulator mode 117 bcf simulatormode ; terminate simulator mode
108 bsf reset_timebase ; request ISR to reset the timebase 118 bsf reset_timebase ; request ISR to reset the timebase
109 ; btfsc reset_timebase ; has the ISR confirmed reset of timebase?
110 ; bra $-2 ; NO - not yet, loop waiting for the ISR
111 119
112 btfsc divemode ; shall go into dive mode? 120 btfsc divemode ; shall go into dive mode?
113 goto restart ; YES - goto restart which will dispatch further on to dive mode 121 goto restart ; YES - goto restart which will dispatch further on to dive mode
114 122
115 btfss trigger_timeout ; timeout on any button press? 123 btfss trigger_timeout ; timeout on any button press?
117 bcf trigger_timeout ; YES - clear timeout flag 125 bcf trigger_timeout ; YES - clear timeout flag
118 bcf restart_fast ; - set next restart to be done slow, i.e. with logos 126 bcf restart_fast ; - set next restart to be done slow, i.e. with logos
119 goto sleeploop ; - goto sleep mode 127 goto sleeploop ; - goto sleep mode
120 128
121 do_demo_planner_exit: 129 do_demo_planner_exit:
122 goto do_return_demo_planner ; return to simulator menu 130 goto do_return_menu_simulator_planner; return to simulator menu
123 131
124 132
125 ;============================================================================= 133 ;-----------------------------------------------------------------------------
126 ; Calculate the Deco Plan 134 ; Helper Function - Calculate the Deco Plan
127 ; 135 ;
128 deco_calculate: 136 deco_calculate:
129 call request_speed_fastest ; request CPU speed change to fastest speed 137 call request_speed_fastest ; request CPU speed change to fastest speed
130 call TFT_ClearScreen ; clear screen to show that calculator is starting up 138 call TFT_ClearScreen ; clear screen to show that calculator is starting up
139 FONT_COLOR_MEMO ; select default text color
131 140
132 ; initialization of the deco engine 141 ; initialization of the deco engine
133 btfsc update_surface_pressure ; is there a pending surface pressure update? 142 btfsc update_surface_pressure ; is there a pending surface pressure update?
134 bra $-2 ; YES - loop waiting for the ISR to kick in 143 bra $-2 ; YES - loop waiting for the ISR to kick in
135 144
194 call deco_setup_oc_gases ; set-up of gas list for deco calculations 203 call deco_setup_oc_gases ; set-up of gas list for deco calculations
195 bra deco_calculate_0_com ; continue with common part 204 bra deco_calculate_0_com ; continue with common part
196 205
197 deco_calculate_0_error: 206 deco_calculate_0_error:
198 call request_speed_normal ; request switch back to normal speed 207 call request_speed_normal ; request switch back to normal speed
199 WIN_COLOR color_red ; select color for error message 208 FONT_COLOR color_red ; select color for error message
200 TEXT_SMALL .0, .80, tNoBottomGas1 ; print error message, line 1 209 TEXT_SMALL .0, .80, tNoBottomGas1 ; print error message, line 1
201 TEXT_SMALL .0, .105, tNoBottomGas2 ; print error message, line 2 210 TEXT_SMALL .0, .105, tNoBottomGas2 ; print error message, line 2
202 bsf decoplan_abort ; set abort flag 211 bsf decoplan_abort ; set abort flag
203 call wait_1s ; wait up to a full second 212 WAITS .2 ; wait 2 seconds
204 call wait_1s ; wait a full second
205 call wait_1s ; wait another full second
206 bcf switch_left ; clear potential button event 213 bcf switch_left ; clear potential button event
207 return ; return to deco calculator main function 214 return ; return to deco calculator main function
208 215
209 deco_calculate_0_com: 216 deco_calculate_0_com:
210 ; set deco stop settings 217 ; set deco stop settings
270 277
271 call request_speed_fastest ; request CPU speed change to fastest speed (again, if in redo) 278 call request_speed_fastest ; request CPU speed change to fastest speed (again, if in redo)
272 279
273 ; show that the deco calculation is in progress 280 ; show that the deco calculation is in progress
274 call TFT_ClearScreen ; clear screen from last results 281 call TFT_ClearScreen ; clear screen from last results
275 WIN_COLOR color_lightblue ; select color for abort label 282
283 FONT_COLOR color_lightblue ; select color for abort label
276 TEXT_SMALL .1,.215, tAbort ; print abort label 284 TEXT_SMALL .1,.215, tAbort ; print abort label
277 WIN_COLOR color_white ; select color for title and progress outputs 285
286 FONT_COLOR color_white ; select color for title and progress outputs
278 TEXT_SMALL .0, .40, tCalculating ; print "Calculating..." 287 TEXT_SMALL .0, .40, tCalculating ; print "Calculating..."
279 288
280 ; calculate the surface interval 289 ; calculate the surface interval
281 TSTOSS opt_surface_interval ; surface interval > 0 ? 290 TSTOSS opt_surface_interval ; surface interval > 0 ?
282 bra deco_calculate_bottom ; NO - continue with bottom segment 291 bra deco_calculate_bottom ; NO - continue with bottom segment
293 302
294 TEXT_SMALL .20,.100,tCalcBotSeg ; print what we are doing 303 TEXT_SMALL .20,.100,tCalcBotSeg ; print what we are doing
295 304
296 ; invoke the deco engine once to condition the real tissues 305 ; invoke the deco engine once to condition the real tissues
297 ; to their pressure state at the end of the bottom segment 306 ; to their pressure state at the end of the bottom segment
298 call deco_calc_hauptroutine ; (C-code) 307 call deco_calc_hauptroutine ; invoke the deco engine (C-code)
299 banksel common 308 banksel common ; back to bank common
300 309
301 IFDEF _ccr_pscr 310 IFDEF _ccr_pscr
302 ; conditional switch to bailout mode 311 ; conditional switch to bailout mode
303 btfss bailout_mode ; shall calculate a bailout plan? 312 btfss bailout_mode ; shall calculate a bailout plan?
304 bra deco_calculate_ascent ; NO - skip next 313 bra deco_calculate_ascent ; NO - skip next
333 bra deco_calculate_loop_metric ; 0 - use Meters 342 bra deco_calculate_loop_metric ; 0 - use Meters
334 ;bra deco_calculate_loop_imperial ; 1 - use Feet 343 ;bra deco_calculate_loop_imperial ; 1 - use Feet
335 344
336 deco_calculate_loop_imperial: 345 deco_calculate_loop_imperial:
337 call convert_meter_to_feet ; convert value in lo from [m] to [feet] 346 call convert_meter_to_feet ; convert value in lo from [m] to [feet]
338 output_16_3 ; print depth reached 347 output_999 ; print depth reached
339 STRCAT_TEXT tFeets ; print unit (feet) 348 STRCAT_TEXT tFeets ; append unit and dump to screen
340 bra deco_calculate_loop_0 349 bra deco_calculate_loop_0
341 350
342 deco_calculate_loop_metric: 351 deco_calculate_loop_metric:
343 output_8 ; print depth reached (in meters) 352 output_256 ; print depth reached (in meters)
344 STRCAT_TEXT tMeters ; print unit (meters) 353 STRCAT_TEXT tMeters ; append unit and dump to screen
345 ;bra deco_calculate_loop_0 ; continue 354 ;bra deco_calculate_loop_0 ; continue
346 355
347 deco_calculate_loop_0: 356 deco_calculate_loop_0:
348 btg decoplan_toggleflag ; - toggle the toggle flag 357 btg decoplan_toggleflag ; - toggle the toggle flag
349 btfsc decoplan_toggleflag ; - toggle flag set? 358 btfsc decoplan_toggleflag ; - toggle flag set?
364 deco_calculate_finish: 373 deco_calculate_finish:
365 goto request_speed_normal ; request switch back to normal speed and return to deco calculator main function 374 goto request_speed_normal ; request switch back to normal speed and return to deco calculator main function
366 375
367 376
368 ;----------------------------------------------------------------------------- 377 ;-----------------------------------------------------------------------------
369 ; Draw a stop of the deco plan (simulator or dive) 378 ; Helper Function - draw one Stop of the Deco Plan
370 ; Inputs: lo = depth 379 ; Inputs: lo = depth
371 ; hi = minutes 380 ; hi = minutes
372 ; win_top = line to draw on screen. 381 ; win_top = line to draw on screen.
373 ; 382 ;
374 ; Trashed: hi, lo, 383 ; Trashed: hi, lo,
380 lfsr FSR2,char_O_deco_gas ; needed to be initialized here every time because... 389 lfsr FSR2,char_O_deco_gas ; needed to be initialized here every time because...
381 movf decoplan_gindex,W ; ...FSR2 is also used for string operations 390 movf decoplan_gindex,W ; ...FSR2 is also used for string operations
382 movff PLUSW2,WREG ; get current gas and copy it to WREG for color-coding 391 movff PLUSW2,WREG ; get current gas and copy it to WREG for color-coding
383 call TFT_color_code_gas ; set output color dependent on gas (1-5) 392 call TFT_color_code_gas ; set output color dependent on gas (1-5)
384 393
385 lfsr FSR2,buffer ; set up output buffer 394 INIT_BUFFER ; initialize output buffer
386 395
387 TSTOSS opt_units ; 0=Meter, 1=Feet 396 TSTOSS opt_units ; 0=Meter, 1=Feet
388 bra deco_plan_show_nstd_stop_metric ; 0 - do metric 397 bra deco_plan_show_nstd_stop_metric ; 0 - do metric
389 ; 1 - do imperial 398 ; 1 - do imperial
390 movff hi,ul ; back-up hi (minutes) 399 movff hi,ul ; back-up hi (minutes)
391 WIN_LEFT .80 400 WIN_LEFT .80
392 call convert_meter_to_feet ; convert value in lo from meters to feet 401 call convert_meter_to_feet ; convert value in lo from meters to feet
393 output_16_3 ; limit output to 0...999 402 output_999 ; limit output to 0...999
394 STRCAT_PRINT "ft" 403 STRCAT_PRINT "ft"
395 movff ul,hi ; restore hi (minutes) 404 movff ul,hi ; restore hi (minutes)
396 bra deco_plan_show_nstd_stop_common 405 bra deco_plan_show_nstd_stop_common
397 406
398 deco_plan_show_nstd_stop_metric: 407 deco_plan_show_nstd_stop_metric:
399 WIN_LEFT .85 408 WIN_LEFT .85 ; set position
400 output_8 ; outputs into postinc2 409 output_256 ; print depth
401 STRCAT_PRINT "m" 410 PUTC_PRINT "m" ; append unit and dump buffer to screen
402 411
403 deco_plan_show_nstd_stop_common: 412 deco_plan_show_nstd_stop_common:
404
405 ; print duration 413 ; print duration
406 WIN_LEFT .135 414 WIN_LEFT .135 ; set position
407 lfsr FSR2,buffer 415 INIT_BUFFER ; initialize buffer
408 movff hi,lo 416 movff hi,lo ; get stop time
409 output_99dd ; stop entries are 99 minutes at max., prints double dots if duration is zero 417 output_99dd ; stop entries are 99 minutes at max., prints double dots if duration is zero
410 STRCAT_PRINT "'" 418 PUTC_PRINT "'" ; append unit and dump buffer to screen
411 419
412 ; draw the bar graph used for deco stops (lo = minutes) 420 ; draw the bar graph used for deco stops (lo = minutes)
413 incf win_top,F 421 incf win_top,F
414 movlw .19 422 movlw .19
415 movwf win_height 423 movwf win_height
416 movlw .118 424 movlw .118
417 movwf win_leftx2 ; column left (0-159) 425 movwf win_leftx2 ; column left (0-159)
418 MOVLI .16,win_width ; column max width 426 MOVLI .16,win_width ; column max width
419 incf lo,W ; add 1 for a minimum visible active bargraph area 427 incf lo,W ; add 1 for a minimum visible active bargraph area
420 movwf win_bargraph ; set width of the active bargraph area 428 movwf win_bargraph ; set width of the active bargraph area
421 call TFT_box ; draw bargraph 429 BOX ; draw bargraph
422 430
423 ; restore win_top 431 ; restore win_top
424 call TFT_standard_color 432 FONT_COLOR_MEMO ; set font color
425 decf win_top,F ; restore win_top 433 decf win_top,F ; restore win_top
426 return 434 return ; done
427 435
428 436
429 ;----------------------------------------------------------------------------- 437 ;-----------------------------------------------------------------------------
430 ; Display the deco plan (simulator) 438 ; Helper Function - Display the Deco Plan results Page
439 ;
431 ; Inputs: char_O_deco_table (array of stop times, in minutes) 440 ; Inputs: char_O_deco_table (array of stop times, in minutes)
432 ; decoplan_page = page number. 441 ; decoplan_page = page number.
433 ; 442 ;
434 deco_results_page: 443 deco_results_page:
435 bcf win_invert ; reset invert flag 444 FONT_COLOR color_greenish
436 WIN_COLOR color_greenish
437 IFDEF _ccr_pscr 445 IFDEF _ccr_pscr
438 btfss bailout_mode ; bailout results? 446 btfss bailout_mode ; bailout results?
439 bra deco_results_page_1 ; NO 447 bra deco_results_page_1 ; NO
440 TEXT_SMALL .80,.1, tDiveBailout ; YES 448 TEXT_SMALL .80,.1, tDiveBailout ; YES
441 bra deco_results_page_2 449 bra deco_results_page_2
445 deco_results_page_2: 453 deco_results_page_2:
446 movff char_O_deco_info,WREG ; get the deco info vector 454 movff char_O_deco_info,WREG ; get the deco info vector
447 btfsc WREG,deco_stops_norm ; are there deco stops? 455 btfsc WREG,deco_stops_norm ; are there deco stops?
448 bra deco_plan_show_1 ; YES 456 bra deco_plan_show_1 ; YES
449 457
450 ;---- no deco -------------------------------------------------------- 458 ;---- no deco
451 call TFT_standard_color 459 FONT_COLOR_MEMO ; set color
452 TEXT_SMALL .80, .25, tNoDeco 460 TEXT_SMALL .80, .25, tNoDeco ; print "no Deco"
453 461
454 ; output of remaining NDL time 462 ; show remaining NDL time
455 WIN_SMALL .80, .50 ; same line as bottom time 463 WIN_SMALL .80, .50 ; same line as bottom time
456 PUTC "+" 464 PUTC "+" ; print a plus
457 movff int_O_NDL_norm+0,lo ; get NDL time in normal plan 465 movff int_O_NDL_norm+0,lo ; get NDL time in normal plan
458 bsf leftbind 466 bsf leftbind ; align to the left
459 output_8 467 output_256 ; print time (0-255)
460 bcf leftbind 468 PUTC "'" ; append unit
461 PUTC "'" 469 PUTC " " ; append a space
462 PUTC " " 470 STRCAT_TEXT_PRINT tNDLleft ; append "NDL" and dump to screen
463 STRCAT_TEXT_PRINT tNDLleft ; "NDL"
464 471
465 bsf decoplan_last_stop_shown 472 bsf decoplan_last_stop_shown
466 return 473 return
467 474
468 ;---- deco stops --------------------------------------------------------- 475 ;---- deco stops
469 deco_plan_show_1: 476 deco_plan_show_1:
470 lfsr FSR0,char_O_deco_depth ; initialize indexed addressing 477 lfsr FSR0,char_O_deco_depth ; initialize indexed addressing
471 lfsr FSR1,char_O_deco_time ; ... 478 lfsr FSR1,char_O_deco_time ; ...
472 479
473 clrf decoplan_index ; start with index = 0 480 clrf decoplan_index ; start with index = 0
493 movff PLUSW1,hi ; char_O_deco_time [decoplan_gindex] 500 movff PLUSW1,hi ; char_O_deco_time [decoplan_gindex]
494 movf lo,W 501 movf lo,W
495 bz deco_plan_show_99 ; depth == 0 -> done 502 bz deco_plan_show_99 ; depth == 0 -> done
496 503
497 ; display the stop line 504 ; display the stop line
498 rcall deco_plan_show_stop 505 rcall deco_plan_show_stop ; draw one stop of the deco plan
499 506
500 ; next 507 ; next
501 movlw .24 508 movlw .24 ; row: += 24
502 addwf win_top,F ; row: += 24 509 addwf win_top,F ; ...
503 incf decoplan_index,F ; local index += 1 510 incf decoplan_index,F ; local index += 1
504 incf decoplan_gindex,F ; global index += 1 511 incf decoplan_gindex,F ; global index += 1
505 512
506 ; max number of lines/page reached? 513 ; max number of lines/page reached?
507 movlw .8 ; 8 lines/page in deco plan 514 movlw .8 ; 8 lines/page in deco plan
508 cpfseq decoplan_index 515 cpfseq decoplan_index
509 bra deco_plan_show_2 ; NO - loop 516 bra deco_plan_show_2 ; NO - loop
510 517
511 ; check if next stop is end-of-list? 518 ; check if next stop is end-of-list?
512 movf decoplan_gindex,W 519 movf decoplan_gindex,W ; get index
513 movf PLUSW0,W ; char_O_deco_depth[decoplan_gindex] 520 movf PLUSW0,W ; char_O_deco_depth[decoplan_gindex]
514 bz deco_plan_show_99 ; end of list 521 bz deco_plan_show_99 ; end of list
515 522
516 call TFT_standard_color 523 WIN_SMALL .135,.212 ; set output position
517 WIN_SMALL .135,.212 524 FONT_COLOR_MEMO ; set font color
518 STRCAT_PRINT ">>>" 525 STRCAT_PRINT ">>>" ; show cue for next page
519 return 526 return ; done
520 527
521 deco_plan_show_99: 528 deco_plan_show_99:
522 bsf decoplan_last_stop_shown ; nothing more in table to display 529 bsf decoplan_last_stop_shown ; nothing more in table to display
523 call TFT_standard_color 530 FONT_COLOR_MEMO ; set font color
524 return 531 return ; done
525 532
526 ;============================================================================= 533
534 ;-----------------------------------------------------------------------------
527 ; Show Deco Calculation Results 535 ; Show Deco Calculation Results
528 ; 536 ;
529 deco_results: 537 deco_results:
530 call TFT_ClearScreen 538 call TFT_ClearScreen ; clear the screen
531 call TFT_standard_color 539 FONT_COLOR_MEMO ; set font color
532 540
533 ; print interval 541 ; print interval
534 WIN_SMALL .0,.25 542 WIN_SMALL .0,.25 ; set position
535 STRCPY "Int. :" 543 STRCPY "Int. :" ; print label
536 movff opt_surface_interval,lo 544 movff opt_surface_interval,lo ; get value
537 output_8 545 output_256 ; print value
538 STRCAT_PRINT "'" 546 PUTC_PRINT "'" ; append unit and dump buffer to screen
539 547
540 ; print bottom time 548 ; print bottom time
541 WIN_SMALL .0,.50 549 WIN_SMALL .0,.50 ; set position
542 STRCPY_TEXT tBtTm_short 550 STRCPY_TEXT tBtTm_short ; print label
543 movff char_I_bottom_time,lo 551 movff char_I_bottom_time,lo ; get value
544 output_8 552 output_256 ; print value
545 STRCAT_PRINT "'" 553 PUTC_PRINT "'" ; append unit and dump buffer to screen
546 554
547 ; print bottom depth 555 ; print bottom depth
548 WIN_SMALL .0,.75 556 WIN_SMALL .0,.75 ; set position
549 STRCPY_TEXT tDepth 557 STRCPY_TEXT tDepth ; print label
550 PUTC ":" 558 PUTC ":" ; append ":"
551 movff char_I_bottom_depth,lo 559 movff char_I_bottom_depth,lo ; get value
552 560
553 TSTOSS opt_units ; check depth units 561 TSTOSS opt_units ; check depth units
554 bra deco_results_metric ; 0 - use Meters 562 bra deco_results_metric ; 0 - use Meters
555 ;bra deco_results_imperial ; 1 - use Feet 563 ;bra deco_results_imperial ; 1 - use Feet
556 564
557 deco_results_imperial: 565 deco_results_imperial:
558 call convert_meter_to_feet ; convert value in lo from [m] to [feet] 566 call convert_meter_to_feet ; convert value in lo from [m] to [feet]
559 output_16_3 ; print depth reached 567 output_999 ; print depth reached
560 STRCAT_TEXT tFeets ; print unit (feet) 568 STRCAT_TEXT tFeets ; print unit and dump to screen
561 bra deco_results_0 ; continue 569 bra deco_results_0 ; continue
562 570
563 deco_results_metric: 571 deco_results_metric:
564 output_8 ; print depth reached (in meters) 572 output_256 ; print depth reached
565 STRCAT_TEXT tMeters ; print unit (meters) 573 STRCAT_TEXT tMeters ; print unit and dump to screen
566 ;bra deco_results_0 ; continue 574 ;bra deco_results_0 ; continue
567 575
568 deco_results_0: 576 deco_results_0:
569 STRCAT_PRINT "" ; finalize bottom depth output 577 PRINT ; finalize bottom depth output
570 578
571 ; print warnings or sat/dsat factors 579 ; print warnings or sat/dsat factors
572 WIN_SMALL .0,.105 580 WIN_SMALL .0,.105 ; set position for label
573 581
574 ; check for stop table overflow 582 ; check for stop table overflow
575 btfss decoplan_warnings,deco_plan_incomplete ; check if deco plan is incomplete 583 btfss decoplan_warnings,deco_plan_incomplete ; check if deco plan is incomplete
576 bra deco_results_0a ; NO - skip 584 bra deco_results_0a ; NO - skip
577 585
578 ; display overflow warning 586 ; display overflow warning
579 call TFT_warning_color ; YES - show overflow warning 587 FONT_COLOR_WARNING ; select warning color
580 STRCAT_PRINT "incomplete" ; max 10 characters 588 STRCAT_PRINT "incomplete" ; show warning (max 10 characters)
581 bra deco_results_m1 ; skip displaying sat/dsat factors 589 bra deco_results_m1 ; skip displaying sat/dsat factors
582 590
583 deco_results_0a: 591 deco_results_0a:
584
585 IFDEF _helium 592 IFDEF _helium
586 ; check for IBCD warning 593 ; check for IBCD warning
587 btfss decoplan_warnings,IBCD_warning_lock ; check if we have a locked IBCD warning 594 btfss decoplan_warnings,IBCD_warning_lock ; check if we have a locked IBCD warning
588 bra deco_results_2b ; NO - skip 595 bra deco_results_2b ; NO - skip
589 596
590 ; display IBCD warning 597 ; display IBCD warning
591 call TFT_attention_color ; YES - show IBCD warning 598 FONT_COLOR_ATTENTION ; select attention color
592 STRCAT_PRINT "IBCD!" ; max 10 characters 599 STRCAT_PRINT "IBCD!" ; max 10 characters
593 bra deco_results_m1 ; skip displaying sat/dsat factors 600 bra deco_results_m1 ; skip displaying sat/dsat factors
594 ENDIF 601 ENDIF
595 602
596 deco_results_2b: 603 deco_results_2b:
597
598 ; display Sat/Desat factors --> omitted if there were warnings 604 ; display Sat/Desat factors --> omitted if there were warnings
599 STRCAT_PRINT "SD:" 605 STRCAT_PRINT "SD:" ; print label
600 WIN_SMALL .25,.105 606 WIN_SMALL .25,.105 ; set position for values
601 movff char_I_saturation_multiplier,lo 607 movff char_I_saturation_multiplier,lo ; get 1st value
602 output_8 608 output_256 ; print 1st value
603 STRCAT "/" 609 STRCAT "/" ; print "/"
604 movff char_I_desaturation_multiplier,lo 610 movff char_I_desaturation_multiplier,lo ; get 2nd value
605 output_8 611 output_256 ; print 2nd value
606 STRCAT_PRINT "" 612 PRINT ; dump to screen
607 613
608 deco_results_m1: 614 deco_results_m1:
609 615 FONT_COLOR_MEMO ; revert font color
610 call TFT_standard_color ; clean-up from warnings
611 616
612 ; get model 617 ; get model
613 movff char_I_model,WREG ; 0: straight Buhlmann, 1: with GF 618 movff char_I_model,WREG ; 0: straight Buhlmann, 1: with GF
614 iorwf WREG ; GF factors in use? 619 iorwf WREG ; GF factors in use?
615 bz deco_results_m2 ; NO 620 bz deco_results_m2 ; NO
616 621
617 ; display GF low/high factors 622 ; display GF low/high factors
618 WIN_SMALL .0,.130 623 WIN_SMALL .0,.130 ; set position for label
619 STRCAT_PRINT "GF:" 624 STRCAT_PRINT "GF:" ; print label
620 WIN_SMALL .25,.130 625 WIN_SMALL .25,.130 ; set position for values
621 movff char_I_GF_Low_percentage,lo 626 movff char_I_GF_Low_percentage,lo ; get 1st value
622 output_8 627 output_256 ; print 1st value
623 STRCAT "/" 628 STRCAT "/" ; print "/"
624 movff char_I_GF_High_percentage,lo 629 movff char_I_GF_High_percentage,lo ; get 2nd value
625 output_8 630 output_256 ; print value
626 STRCAT_PRINT "" 631 PRINT ; dump to screen
627 632
628 deco_results_m2: 633 deco_results_m2:
629
630 ; display deco mode 634 ; display deco mode
631 WIN_SMALL .0,.155 635 WIN_SMALL .0,.155 ; set position
632 lfsr FSR2,buffer 636 INIT_BUFFER ; load buffer base address
633 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR 637 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR
634 call TFT_decotype_logbook 638 call TFT_print_decotype ; print deco type (OC, CCR)
635 639
636 IFDEF _ccr_pscr 640 IFDEF _ccr_pscr
637 btfss FLAG_ccr_mode ; current dive mode = CCR ? 641 btfss FLAG_ccr_mode ; current dive mode = CCR ?
638 bra deco_results_2c ; NO - skip 642 bra deco_results_2c ; NO - skip
639 WIN_SMALL .25,.155 643 WIN_SMALL .25,.155 ; YES - set position
640 STRCPY "SP:" ; output setpoint used for calculation 644 STRCPY "SP:" ; - print label
641 movff opt_sim_setpoint_number,lo 645 movff opt_sim_setpoint_number,lo ; - get setpoint used for calculation
642 bsf leftbind 646 output_9 ; - print setpoint number (0-9)
643 output_8 647 PRINT ; - dump to screen
644 bcf leftbind
645 STRCAT_PRINT ""
646 ENDIF 648 ENDIF
647 649
648 deco_results_2c: 650 deco_results_2c:
649
650 btfss FLAG_oc_mode ; current dive mode = OC ? 651 btfss FLAG_oc_mode ; current dive mode = OC ?
651 bra deco_results_2d ; NO - skip 652 bra deco_results_2d ; NO - skip
652 TSTOSS opt_ext_stops ; YES - extended stops activated? 653 TSTOSS opt_ext_stops ; YES - extended stops activated?
653 bra deco_results_2d ; NO - skip 654 bra deco_results_2d ; NO - skip
654 WIN_SMALL .18,.155 ; YES - set position 655 WIN_SMALL .18,.155 ; YES - set position
655 STRCAT_PRINT "ext.Stop" ; - print notice 656 STRCAT_PRINT "ext.Stop" ; - print notice
656 657
657 deco_results_2d: 658 deco_results_2d:
658 659
659 ; display TTS result 660 ; display TTS result
660 WIN_SMALL .0,.180 661 WIN_SMALL .0,.180 ; position
661 STRCPY_TEXT tTTS 662 STRCPY_TEXT tTTS ; print label
662 STRCAT ": " 663 STRCAT ": " ; append ": "
663 MOVII int_O_TTS_norm,mpr 664 MOVII int_O_TTS_norm,mpr ; get TTS value
664 bsf leftbind 665 bsf leftbind ; print left-aligned
665 output_16 666 output_999 ; print TTS (0-999)
666 bcf leftbind 667 PUTC_PRINT "'" ; append unit and dump to screen
667 STRCAT_PRINT "'"
668 668
669 ; display CNS result 669 ; display CNS result
670 WIN_TOP .205 670 WIN_TOP .205 ; position
671 STRCPY_TEXT tCNS2 ; "CNS:" 671 STRCPY_TEXT tCNS2 ; print label
672 MOVII real_CNS,mpr ; recall real CNS from before simulated dive 672 MOVII real_CNS,mpr ; recall real CNS from before simulated dive
673 call TFT_color_code_cns ; color-code CNS output 673 call TFT_color_code_cns ; color-code CNS output
674 bsf leftbind 674 bsf leftbind ; print left-aligned
675 output_16_3 ; limit to 999 and display only (0-999) 675 output_999 ; limit to 999 and display only (0-999)
676 bcf leftbind
677 STRCAT "%\x92" ; "->" 676 STRCAT "%\x92" ; "->"
678 MOVII int_O_CNS_norm,mpr ; get CNS at end of simulated dive in normal plan 677 MOVII int_O_CNS_norm,mpr ; get CNS at end of simulated dive in normal plan
679 call TFT_color_code_cns ; color-code CNS output 678 call TFT_color_code_cns ; color-code CNS output
680 bsf leftbind 679 bsf leftbind ; print left-aligned
681 output_16_3 ; limit to 999 and display only (0-999) 680 output_999 ; limit to 999 and display only (0-999)
682 bcf leftbind 681 PUTC_PRINT "%" ; append unit and print everything to screen
683 STRCAT_PRINT "%" 682 FONT_COLOR_MEMO ; back to standard color
684 call TFT_standard_color
685 683
686 ; loop through deco plan pages 684 ; loop through deco plan pages
687 deco_results_1: 685 deco_results_1:
688 clrf decoplan_page ; start from first page 686 clrf decoplan_page ; start from first page
689 bcf decoplan_pressures_shown ; when showing the gas needs, start with volumes (liter) 687 bcf decoplan_pressures_shown ; when showing the gas needs, start with volumes (liter)
732 deco_results_gas_common: 730 deco_results_gas_common:
733 WIN_BOX_BLACK .0, .239, .80, .159 ; clear the complete right part of the result column (top, bottom, left, right) 731 WIN_BOX_BLACK .0, .239, .80, .159 ; clear the complete right part of the result column (top, bottom, left, right)
734 movlw .25 ; output row is 25 (fixed offset set here) + n*25 (line increment, see below) 732 movlw .25 ; output row is 25 (fixed offset set here) + n*25 (line increment, see below)
735 movwf output_row ; set fixed vertical offset for output row 733 movwf output_row ; set fixed vertical offset for output row
736 WIN_LEFT .80 ; set column 734 WIN_LEFT .80 ; set column
737 call TFT_standard_color
738 clrf gas_index ; initialize gas counter 735 clrf gas_index ; initialize gas counter
739 bcf is_diluent_menu ; working on OC gases 736 bcf is_diluent_menu ; working on OC gases
740 737
741 deco_results_gas_loop: 738 deco_results_gas_loop:
742 movff gas_index,PRODL ; copy gas index to PRODL (interface to gaslist_strcat_gas) 739 movff gas_index,PRODL ; copy gas index to PRODL (interface to gaslist_strcat_gas)
743 incf gas_index,F ; increment gas index 740 incf gas_index,F ; increment gas index
744 741
745 movf gas_index,W ; copy gas index to WREG for color-coding 742 movf gas_index,W ; copy gas index to WREG for color-coding
746 call TFT_color_code_gas ; set output color according to gas (1-5) 743 call TFT_color_code_gas ; set output color according to gas (1-5)
747 744
748 lfsr FSR2,buffer ; set base address of output buffer
749 bsf short_gas_descriptions ; configure gaslist_strcat_gas output format
750 bsf divemode ; configure gaslist_strcat_gas output format
751 call gaslist_strcat_gas ; write "Nxlo", "Txlo/hi", "Air" or "O2" into output buffer
752 bcf divemode ; cleanup above
753
754 movlw .25 ; spacing between outputs 745 movlw .25 ; spacing between outputs
755 addwf output_row,F ; increase row position 746 addwf output_row,F ; increase row position
756 movff output_row,win_top ; set row position 747 movff output_row,win_top ; set row position
757 748
749 INIT_BUFFER ; initialize output buffer
750
751 bsf short_gas_descriptions ; configure gaslist_strcat_gas output format
752 bsf divemode ; configure gaslist_strcat_gas output format
753 call gaslist_strcat_mix_PRODL ; write "Nxlo", "Txlo/hi", "Air" or "O2" into output buffer
754 bcf divemode ; revoke dive mode
755
758 movff POSTINC0,lo ; read gas volume low byte 756 movff POSTINC0,lo ; read gas volume low byte
759 movff POSTINC0,hi ; high byte 757 movff POSTINC0,hi ; high byte
760 758
761 bcf decoplan_overflow ; no overflow in gas needs by default 759 bcf decoplan_overflow ; no overflow in gas needs by default
762 760
763 btfsc decoplan_pressures_shown ; results in bar? 761 btfsc decoplan_pressures_shown ; results in bar?
764 bra deco_results_gas_volumes_1 ; YES 762 bra deco_results_gas_volumes_1 ; YES
765
766 ; output of gas needs in liter
767 movf lo,W ; check if hi:lo = 65535: copy low byte to WREG
768 andwf hi,W ; and do a bitwise AND with the high byte
769 incfsz WREG ; add 1, result zero now?
770 bra deco_results_gas_volumes_2 ; NO - print volume
771 STRCAT_PRINT ">65500" ; YES - print ">65500"
772 bra deco_results_gas_volumes_3 ; - continue checking if all gases are shown
773 763
774 ; output of gas needs in bar 764 ; output of gas needs in bar
775 deco_results_gas_volumes_1: 765 deco_results_gas_volumes_1:
776 btfsc hi,int_high_flag ; overflow in result? 766 btfsc hi,int_high_flag ; overflow in result?
777 bsf decoplan_overflow ; YES - remember it 767 bsf decoplan_overflow ; YES - remember it
783 bcf hi,int_invalid_flag ; clear flag for invalid data 773 bcf hi,int_invalid_flag ; clear flag for invalid data
784 bcf hi,int_is_zero ; clear flag for zero 774 bcf hi,int_is_zero ; clear flag for zero
785 775
786 deco_results_gas_volumes_2: 776 deco_results_gas_volumes_2:
787 PUTC ":" ; print ":" 777 PUTC ":" ; print ":"
788 output_16 ; print 16 bit number 778 output_9999 ; print volume or bar (0-9999)
789 movlw '>' ; load coding of ">" sign into WREG 779 movlw '>' ; load coding of ">" sign into WREG
790 btfsc decoplan_overflow ; overflow in result? 780 btfsc decoplan_overflow ; overflow in pressure value?
791 movff WREG,buffer+.7 ; YES - place ">" before number 781 movff WREG,buffer+.7 ; YES - place ">" in front of pressure value
792 STRCAT_PRINT "" ; finalize output 782 btfsc output_overflow ; overflow in output?
793 bcf win_invert ; back to none-inverse printing 783 movff WREG,buffer+.6 ; YES - place ">" in front of volume value
784 PRINT ; dump to screen
794 785
795 deco_results_gas_volumes_3: 786 deco_results_gas_volumes_3:
796 movlw NUM_GAS ; 5 gases to show 787 movlw NUM_GAS ; 5 gases to show
797 cpfseq gas_index ; all gases shown? 788 cpfseq gas_index ; all gases shown?
798 bra deco_results_gas_loop ; NO - loop 789 bra deco_results_gas_loop ; NO - loop
799 790
800 WIN_COLOR color_greenish ; set color 791 FONT_COLOR color_greenish ; set color
801 TEXT_SMALL .80,.01,tGasUsage ; "Gas Usage" 792 TEXT_SMALL .80,.01,tGasUsage ; "Gas Usage"
802 793
803 btfsc decoplan_pressures_shown ; results shown in bar? 794 btfsc decoplan_pressures_shown ; results shown in bar?
804 bra deco_results_gas_volumes_4 ; YES 795 bra deco_results_gas_volumes_4 ; YES
805 TEXT_SMALL .120,.25,tLiterLong ; NO - in Liter then 796 TEXT_SMALL .120,.25,tLiterLong ; NO - in Liter then
807 798
808 deco_results_gas_volumes_4: 799 deco_results_gas_volumes_4:
809 TEXT_SMALL .120,.25,tbar ; " bar" (with leading space) 800 TEXT_SMALL .120,.25,tbar ; " bar" (with leading space)
810 801
811 deco_results_gas_volumes_5: 802 deco_results_gas_volumes_5:
812 call TFT_standard_color ; revert to standard color
813 call reset_timeout_surfmode ; reset timeout 803 call reset_timeout_surfmode ; reset timeout
814 bcf switch_right ; clear left-over right button event 804 bcf switch_right ; clear left-over right button event
815 bcf switch_left ; clear left-over left button event 805 bcf switch_left ; clear left-over left button event
816 deco_results_gas_volumes_6: 806 deco_results_gas_volumes_6:
817 btfsc switch_right ; right button pressed? 807 btfsc switch_right ; right button pressed?
832 bra deco_results_1 ; YES - show deco stops again 822 bra deco_results_1 ; YES - show deco stops again
833 bsf decoplan_pressures_shown ; NO - but now 823 bsf decoplan_pressures_shown ; NO - but now
834 lfsr FSR0,int_O_gas_need_pres ; - set base address of gas needs in bar 824 lfsr FSR0,int_O_gas_need_pres ; - set base address of gas needs in bar
835 bra deco_results_gas_common ; - re-run gas needs output in pressure mode 825 bra deco_results_gas_common ; - re-run gas needs output in pressure mode
836 826
827 ;-----------------------------------------------------------------------------
837 828
838 END 829 END