// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: reload_adev_queue(int)
void reload_adev_queue(int reset_phase)
{
long i;
long counter;
long max_count;
struct PLOT_Q q;
int dump_size;
int have_cha_tie, have_chb_tie, have_chc_tie, have_chd_tie;
double cha_tie, chb_tie, chc_tie, chd_tie;
int have_cha_ofs, have_chb_ofs, have_chc_ofs, have_chd_ofs;
double cha_ofs, chb_ofs, chc_ofs, chd_ofs;
double old_cha_ofs, old_chb_ofs, old_chc_ofs, old_chd_ofs;
double cha_tick, chb_tick, chc_tick, chd_tick;
OFS_SIZE old_pps_offset, old_osc_offset;
int old_have_pps_offset, old_have_osc_offset;
long pcount;

   have_cha_tie = have_chb_tie = have_chc_tie = have_chd_tie = 0;
   have_cha_ofs = have_chb_ofs = have_chc_ofs = have_chd_ofs = 0;

   old_have_pps_offset = have_pps_offset;  // receiver derived adev related values
   old_have_osc_offset = have_osc_offset;

   if(reset_phase) dont_reset_phase = 0;
   else            dont_reset_phase = 1;
   if(rcvr_type == TICC_RCVR) {
      if(mtie_q_count[CHA_MTIE]) have_cha_tie = 1;
      if(mtie_q_count[CHB_MTIE]) have_chb_tie = 1;
      if(mtie_q_count[CHC_MTIE]) have_chc_tie = 1;
      if(mtie_q_count[CHD_MTIE]) have_chd_tie = 1;
      reset_queues(RESET_MTIE_Q, 1101);
   }

   if(pps_adev_q_count) have_cha_ofs = 1;
   if(osc_adev_q_count) have_chb_ofs = 1;
   if(chc_adev_q_count) have_chc_ofs = 1;
   if(chd_adev_q_count) have_chd_ofs = 1;


   reset_queues(RESET_ADEV_Q, 1102);   // clear the adev queue
   dont_reset_phase = 0;
////   pause_data = 1;

   max_count = view_interval * (long) PLOT_WIDTH;
   max_count /= (long) plot_mag;
   counter = 0;

   dump_size = 'p';
   if(dump_size == 'p') i = plot_q_col0;  // reloading from the displayed plot area
   else                 i = plot_q_out;   // reloading from the full queue

   if(queue_interval == 0) return;

   cha_tick = pps_adev_period; //  / (double) queue_interval;
   chb_tick = osc_adev_period; //  / (double) queue_interval;
   chc_tick = chc_adev_period; //  / (double) queue_interval;
   chd_tick = chd_adev_period; //  / (double) queue_interval;

   pcount = plot_q_size;
   while(pcount) {
      --pcount;
      q = get_plot_q(i);

      old_cha_ofs = pps_phase;
      old_chb_ofs = osc_phase;
      old_chc_ofs = chc_phase;
      old_chd_ofs = chd_phase;
      old_osc_offset = osc_offset;
      old_pps_offset = pps_offset;

      cha_ofs = cha_tie = 0.0;
      chb_ofs = chb_tie = 0.0;
      chc_ofs = chc_tie = 0.0;
      chd_ofs = chd_tie = 0.0;

      if(queue_interval) {
         cha_ofs = cha_tie = (OFS_SIZE) q.data[PPS] / (OFS_SIZE) queue_interval;
         chb_ofs = chb_tie = (OFS_SIZE) q.data[OSC] / (OFS_SIZE) queue_interval;
         chc_ofs = chc_tie = (OFS_SIZE) q.data[CHC] / (OFS_SIZE) queue_interval;
         chd_ofs = chd_tie = (OFS_SIZE) q.data[CHD] / (OFS_SIZE) queue_interval;
      }

      if(rcvr_type == TICC_RCVR) {  // MTIE data
         --cha_tick;
         --chb_tick;
         --chc_tick;
         --chd_tick;

         if(have_cha_tie && (cha_tick <= 0.0)) add_mtie_point(CHA_MTIE, cha_tie); 
         if(have_chb_tie && (chb_tick <= 0.0)) add_mtie_point(CHB_MTIE, chb_tie); 
         if(have_chc_tie && (chc_tick <= 0.0)) add_mtie_point(CHC_MTIE, chc_tie); 
         if(have_chd_tie && (chd_tick <= 0.0)) add_mtie_point(CHD_MTIE, chd_tie);

         cha_ofs = (OFS_SIZE) q.data[ONE] / (OFS_SIZE) queue_interval;
         chb_ofs = (OFS_SIZE) q.data[TWO] / (OFS_SIZE) queue_interval;
         chc_ofs = (OFS_SIZE) q.data[THREE] / (OFS_SIZE) queue_interval;
         chd_ofs = (OFS_SIZE) q.data[FOUR] / (OFS_SIZE) queue_interval;

         if(have_cha_ofs && (cha_tick <= 0.0)) add_pps_adev_point(cha_ofs, 1);   // adev values
         if(have_chb_ofs && (chb_tick <= 0.0)) add_osc_adev_point(chb_ofs, 1); 
         if(have_chc_ofs && (chc_tick <= 0.0)) add_chc_adev_point(chc_ofs, 1); 
         if(have_chd_ofs && (chd_tick <= 0.0)) add_chd_adev_point(chd_ofs, 1);  

         if(cha_tick <= 0.0) cha_tick = pps_adev_period; // / (double) queue_interval;
         if(cha_tick <= 0.0) chb_tick = osc_adev_period; // / (double) queue_interval;
         if(cha_tick <= 0.0) chc_tick = chc_adev_period; // / (double) queue_interval;
         if(cha_tick <= 0.0) chd_tick = chd_adev_period; // / (double) queue_interval;
      }
      else {  // adevs from receiver data or external TICC
         pps_offset = cha_ofs;
         osc_offset = chb_ofs;
         have_pps_offset = have_cha_ofs;
         have_osc_offset = have_chb_ofs;

         add_rcvr_adev_point(1);

         pps_offset = old_pps_offset;
         osc_offset = old_osc_offset;
         have_pps_offset = old_have_pps_offset;
         have_osc_offset = old_have_osc_offset;
      }

      ++counter;
      if((counter % LOG_GPS_CHECK) == 0) {   // keep serial data from overruning
         get_pending_gps(30);  //!!!! possible recursion
      }
//    if((counter % 1000L) == 1L) {
      if((counter % LOG_SCREEN_RFSH) == 1L) {
         sprintf(out, "Line %ld", counter-1L);
         vidstr(PLOT_TEXT_ROW+4+2, PLOT_TEXT_COL, PROMPT_COLOR, out);
         refresh_page();
      }

      if(dump_size == 'p') {  // reloading from the displayed plot area
         if(counter >= max_count) break;
      }
      if(++i >= plot_q_size) i = 0;  // queue pointer wrapped
   }

   if(rcvr_type == TICC_RCVR) {
      find_global_max();
   }

   force_adev_redraw(11);
   redraw_screen();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movl %edi, -0x4(%rbp)
movl $0x0, -0xe4(%rbp)
movl $0x0, -0xe0(%rbp)
movl $0x0, -0xdc(%rbp)
movl $0x0, -0xd8(%rbp)
movl $0x0, -0x118(%rbp)
movl $0x0, -0x114(%rbp)
movl $0x0, -0x110(%rbp)
movl $0x0, -0x10c(%rbp)
leaq 0x209113(%rip), %rax    # 0x36c418
movl (%rax), %eax
movl %eax, -0x18c(%rbp)
leaq 0x209100(%rip), %rax    # 0x36c414
movl (%rax), %eax
movl %eax, -0x190(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0x163331
leaq 0x6cb1b(%rip), %rax     # 0x1cfe44
movl $0x0, (%rax)
jmp 0x16333e
leaq 0x6cb0c(%rip), %rax     # 0x1cfe44
movl $0x1, (%rax)
leaq 0x11476b(%rip), %rax    # 0x277ab0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x1633a9
cmpl $0x0, 0x350fab(%rip)    # 0x4b4300
je 0x163361
movl $0x1, -0xd8(%rbp)
cmpl $0x0, 0x350f9c(%rip)    # 0x4b4304
je 0x163374
movl $0x1, -0xdc(%rbp)
cmpl $0x0, 0x350f8d(%rip)    # 0x4b4308
je 0x163387
movl $0x1, -0xe0(%rbp)
cmpl $0x0, 0x350f7e(%rip)    # 0x4b430c
je 0x16339a
movl $0x1, -0xe4(%rbp)
movl $0x4, %edi
movl $0x44d, %esi            # imm = 0x44D
callq 0x144c0
leaq 0x138968(%rip), %rax    # 0x29bd18
cmpq $0x0, (%rax)
je 0x1633c0
movl $0x1, -0x10c(%rbp)
leaq 0x1389a1(%rip), %rax    # 0x29bd68
cmpq $0x0, (%rax)
je 0x1633d7
movl $0x1, -0x110(%rbp)
leaq 0x1389da(%rip), %rax    # 0x29bdb8
cmpq $0x0, (%rax)
je 0x1633ee
movl $0x1, -0x114(%rbp)
leaq 0x138a13(%rip), %rax    # 0x29be08
cmpq $0x0, (%rax)
je 0x163405
movl $0x1, -0x118(%rbp)
movl $0x1, %edi
movl $0x44e, %esi            # imm = 0x44E
callq 0x144c0
leaq 0x6ca29(%rip), %rax     # 0x1cfe44
movl $0x0, (%rax)
leaq 0x117158(%rip), %rax    # 0x27a580
movq (%rax), %rax
leaq 0x114632(%rip), %rcx    # 0x277a64
movslq (%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0x20(%rbp)
leaq 0x11716c(%rip), %rax    # 0x27a5b0
movslq (%rax), %rcx
movq -0x20(%rbp), %rax
cqto
idivq %rcx
movq %rax, -0x20(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x70, -0xd4(%rbp)
cmpl $0x70, -0xd4(%rbp)
jne 0x16347f
leaq 0x116fd2(%rip), %rax    # 0x27a448
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x16348d
leaq 0x11708a(%rip), %rax    # 0x27a510
movq (%rax), %rax
movq %rax, -0x10(%rbp)
leaq 0x1170e4(%rip), %rax    # 0x27a578
cmpq $0x0, (%rax)
jne 0x16349f
jmp 0x163aea
leaq 0x138a3a(%rip), %rax    # 0x29bee0
movsd (%rax), %xmm0
movsd %xmm0, -0x160(%rbp)
leaq 0x138a2f(%rip), %rax    # 0x29bee8
movsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
leaq 0x138a24(%rip), %rax    # 0x29bef0
movsd (%rax), %xmm0
movsd %xmm0, -0x170(%rbp)
leaq 0x138a19(%rip), %rax    # 0x29bef8
movsd (%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
leaq 0x11700e(%rip), %rax    # 0x27a500
movq (%rax), %rax
movq %rax, -0x198(%rbp)
cmpq $0x0, -0x198(%rbp)
je 0x163ac6
movq -0x198(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x198(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x248(%rbp), %rdi
callq 0x133f0
leaq -0xd0(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
leaq 0x20848d(%rip), %rax    # 0x36b9d8
movsd (%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
leaq 0x208482(%rip), %rax    # 0x36b9e0
movsd (%rax), %xmm0
movsd %xmm0, -0x148(%rbp)
leaq 0x208487(%rip), %rax    # 0x36b9f8
movsd (%rax), %xmm0
movsd %xmm0, -0x150(%rbp)
leaq 0x20847c(%rip), %rax    # 0x36ba00
movsd (%rax), %xmm0
movsd %xmm0, -0x158(%rbp)
leaq 0x208409(%rip), %rax    # 0x36b9a0
movsd (%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
leaq 0x2083ee(%rip), %rax    # 0x36b998
movsd (%rax), %xmm0
movsd %xmm0, -0x180(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xf0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x120(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xf8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x128(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x100(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x130(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x108(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x138(%rbp)
leaq 0x116f63(%rip), %rax    # 0x27a578
cmpq $0x0, (%rax)
je 0x1636b9
movsd -0xc0(%rbp), %xmm0
leaq 0x116f4a(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd %xmm0, -0x120(%rbp)
movsd -0xb8(%rbp), %xmm0
leaq 0x116f22(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd %xmm0, -0x128(%rbp)
movsd -0x70(%rbp), %xmm0
leaq 0x116efd(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
movsd %xmm0, -0x130(%rbp)
movsd -0x68(%rbp), %xmm0
leaq 0x116ed8(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x108(%rbp)
movsd %xmm0, -0x138(%rbp)
leaq 0x1143f0(%rip), %rax    # 0x277ab0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x16396f
movsd 0xba43(%rip), %xmm0     # 0x16f118
addsd -0x160(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
movsd 0xba2b(%rip), %xmm0     # 0x16f118
addsd -0x168(%rbp), %xmm0
movsd %xmm0, -0x168(%rbp)
movsd 0xba13(%rip), %xmm0     # 0x16f118
addsd -0x170(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
movsd 0xb9fb(%rip), %xmm0     # 0x16f118
addsd -0x178(%rbp), %xmm0
movsd %xmm0, -0x178(%rbp)
cmpl $0x0, -0xd8(%rbp)
je 0x163752
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jb 0x163752
movsd -0xf0(%rbp), %xmm0
xorl %edi, %edi
callq 0x126f90
cmpl $0x0, -0xdc(%rbp)
je 0x16377a
xorps %xmm0, %xmm0
ucomisd -0x168(%rbp), %xmm0
jb 0x16377a
movsd -0xf8(%rbp), %xmm0
movl $0x1, %edi
callq 0x126f90
cmpl $0x0, -0xe0(%rbp)
je 0x1637a2
xorps %xmm0, %xmm0
ucomisd -0x170(%rbp), %xmm0
jb 0x1637a2
movsd -0x100(%rbp), %xmm0
movl $0x2, %edi
callq 0x126f90
cmpl $0x0, -0xe4(%rbp)
je 0x1637ca
xorps %xmm0, %xmm0
ucomisd -0x178(%rbp), %xmm0
jb 0x1637ca
movsd -0x108(%rbp), %xmm0
movl $0x3, %edi
callq 0x126f90
movsd -0xa0(%rbp), %xmm0
leaq 0x116d9f(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x120(%rbp)
movsd -0x98(%rbp), %xmm0
leaq 0x116d7f(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x90(%rbp), %xmm0
leaq 0x116d5f(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x130(%rbp)
movsd -0x88(%rbp), %xmm0
leaq 0x116d3f(%rip), %rax    # 0x27a578
cvtsi2sdq (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x138(%rbp)
cmpl $0x0, -0x10c(%rbp)
je 0x163872
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jb 0x163872
movsd -0x120(%rbp), %xmm0
movl $0x1, %edi
callq 0x161540
cmpl $0x0, -0x110(%rbp)
je 0x16389a
xorps %xmm0, %xmm0
ucomisd -0x168(%rbp), %xmm0
jb 0x16389a
movsd -0x128(%rbp), %xmm0
movl $0x1, %edi
callq 0x161c60
cmpl $0x0, -0x114(%rbp)
je 0x1638c2
xorps %xmm0, %xmm0
ucomisd -0x170(%rbp), %xmm0
jb 0x1638c2
movsd -0x130(%rbp), %xmm0
movl $0x1, %edi
callq 0x161f00
cmpl $0x0, -0x118(%rbp)
je 0x1638ea
xorps %xmm0, %xmm0
ucomisd -0x178(%rbp), %xmm0
jb 0x1638ea
movsd -0x138(%rbp), %xmm0
movl $0x1, %edi
callq 0x1621b0
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jb 0x16390a
leaq 0x1385e2(%rip), %rax    # 0x29bee0
movsd (%rax), %xmm0
movsd %xmm0, -0x160(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jb 0x16392a
leaq 0x1385ca(%rip), %rax    # 0x29bee8
movsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jb 0x16394a
leaq 0x1385b2(%rip), %rax    # 0x29bef0
movsd (%rax), %xmm0
movsd %xmm0, -0x170(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jb 0x16396a
leaq 0x13859a(%rip), %rax    # 0x29bef8
movsd (%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
jmp 0x163a01
movsd -0x120(%rbp), %xmm0
leaq 0x20801a(%rip), %rax    # 0x36b998
movsd %xmm0, (%rax)
movsd -0x128(%rbp), %xmm0
leaq 0x20800f(%rip), %rax    # 0x36b9a0
movsd %xmm0, (%rax)
movl -0x10c(%rbp), %ecx
leaq 0x208a76(%rip), %rax    # 0x36c418
movl %ecx, (%rax)
movl -0x110(%rbp), %ecx
leaq 0x208a63(%rip), %rax    # 0x36c414
movl %ecx, (%rax)
movl $0x1, %edi
callq 0xa4ab0
movsd -0x180(%rbp), %xmm0
leaq 0x207fcc(%rip), %rax    # 0x36b998
movsd %xmm0, (%rax)
movsd -0x188(%rbp), %xmm0
leaq 0x207fc1(%rip), %rax    # 0x36b9a0
movsd %xmm0, (%rax)
movl -0x18c(%rbp), %ecx
leaq 0x208a28(%rip), %rax    # 0x36c418
movl %ecx, (%rax)
movl -0x190(%rbp), %ecx
leaq 0x208a15(%rip), %rax    # 0x36c414
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x1388, %ecx           # imm = 0x1388
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x163a2b
movl $0x1e, %edi
callq 0x29240
movq -0x18(%rbp), %rax
movl $0x2710, %ecx           # imm = 0x2710
cqto
idivq %rcx
cmpq $0x1, %rdx
jne 0x163a8a
movq -0x18(%rbp), %rdx
subq $0x1, %rdx
leaq 0x2379b2(%rip), %rdi    # 0x39b400
leaq 0x310ed(%rip), %rsi     # 0x194b42
movb $0x0, %al
callq 0x9060
leaq 0x11400d(%rip), %rax    # 0x277a70
movl (%rax), %edi
addl $0x4, %edi
addl $0x2, %edi
leaq 0x113ffa(%rip), %rax    # 0x277a6c
movl (%rax), %esi
movl $0xb, %edx
leaq 0x237980(%rip), %rcx    # 0x39b400
callq 0x10ee0
callq 0xb0d0
cmpl $0x70, -0xd4(%rbp)
jne 0x163aa1
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0x163a9f
jmp 0x163ac6
jmp 0x163aa1
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
leaq 0x116a4c(%rip), %rcx    # 0x27a500
cmpq (%rcx), %rax
jl 0x163ac1
movq $0x0, -0x10(%rbp)
jmp 0x1634fc
leaq 0x113fe3(%rip), %rax    # 0x277ab0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x163adb
callq 0x127650
movl $0xb, %edi
callq 0x127cf0
callq 0x12ae0
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nopw %cs:(%rax,%rax)