// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heather.cpp
// Function: plot_entry(long)
void plot_entry(long i)
{
DATA_SIZE x;
DATA_SIZE y;
DATA_SIZE val;
DATA_SIZE data;
double t;
struct PLOT_Q q;
struct PLOT_Q q2;
int col;
int py;
int k;
u16 sat_flags;

   // draw all data points for the next column in the plot

   if(first_key) return;    // plot area is in use for help/warning message
   if(text_mode) return;    // no graphics available in text mode
   if(rcvr_type == NO_RCVR) return;
   if(no_plots) return;
   if(zoom_screen == 'P');
   else if(zoom_screen) return;
   if(queue_interval <= 0) return;  // no queue data to plot

   if(filter_count) {
      q = filter_plot_q(i);   // plot filtered data
      sat_flags = filter_flags; // q.sat_flags;
   }
   else {
      q = get_plot_q(i);      // plot raw data
      sat_flags = q.sat_flags;
   }


   batt_mah += q.data[BATTI] * (DATA_SIZE) (queue_interval*view_interval/(DATA_SIZE) 3600.0);
   batt_mwh += q.data[BATTI] * (DATA_SIZE) q.data[BATTV] * (queue_interval*view_interval/(DATA_SIZE) 3600.0);
   load_mah += q.data[LEDI] * (DATA_SIZE) (queue_interval*view_interval/(DATA_SIZE) 3600.0);
   load_mwh += q.data[LEDI] * (DATA_SIZE) q.data[LEDV] * (queue_interval*view_interval/(DATA_SIZE) 3600.0);

   if(show_mah) {
      sprintf(debug_text, " Battery: Ah=%.3f  Wh=%.3f     LED: Ah=%.3f  Wh=%.3f", batt_mah,batt_mwh, load_mah,load_mwh);
   }


   for(k=0; k<NUM_PLOTS+DERIVED_PLOTS; k++) {     // compensate for linear trend line slope (drift rate)
      t = (double) plot_column*view_interval;
      q.data[k] = remove_trend(k, 0, t, q.data[k]);
   }

   col = PLOT_COL + plot_column;    // where we will be plotting
   if(plot_column <= 0) {           // no data or only one point to plot
      last_plot_col = 0;
      plot_dot = 1;
   }
   else {  // with more than one point available, connect the dots with lines
      last_plot_col = plot_column-plot_mag;
      if(last_plot_col < 0) last_plot_col = 0;
      plot_dot = 0;
   }

   if(sat_flags & TIME_SKIP) {  // flag skips and stutters in the time stamps
      if(plot_skip_data) {        // use small skip markers
         line(col,PLOT_ROW, col,PLOT_ROW+8, SKIP_COLOR);
      }
   }


   if(plot_holdover_data && (sat_flags & HOLDOVER)) {  // flag holdover events
      if(plot_dot) {
         dot(col,PLOT_ROW+0, HOLDOVER_COLOR);
         dot(col,PLOT_ROW+1, HOLDOVER_COLOR);
      }
      else {
         line(PLOT_COL+last_plot_col,PLOT_ROW+0, col,PLOT_ROW+0, HOLDOVER_COLOR);
         line(PLOT_COL+last_plot_col,PLOT_ROW+1, col,PLOT_ROW+1, HOLDOVER_COLOR);
      }
   }

   show_last_mouse_x(GREEN);

   // flag satellite constellation changes
   if(plot_const_changes && (sat_flags & CONST_CHANGE)) {
      line(col,PLOT_ROW+PLOT_HEIGHT, col,PLOT_ROW+PLOT_HEIGHT-8, CONST_COLOR);
//    plot_dot = 1;  // highlights satellite change discontinuites
   }

   if(plot[SAT_PLOT].show_plot) {  // show_sat_plot
      py = (q.sat_flags & SAT_COUNT_MASK) * COUNT_SCALE;
      if(py > PLOT_HEIGHT) py = PLOT_HEIGHT;
      py = (PLOT_ROW+PLOT_HEIGHT) - py;
      if(plot_dot) dot(col,py, COUNT_COLOR);
      else         line(PLOT_COL+last_plot_col,last_count_y, col,py, plot[SAT_PLOT].plot_color);
      last_count_y = py;
   }

   // draw each of the data plots
   for(k=0; k<NUM_PLOTS+DERIVED_PLOTS; k++) {
      if(plot[k].show_plot) {
         data = q.data[k];

         if(plot[k].show_deriv) {  // showing plot derivative
            if(filter_count) q2 = filter_plot_q(i-1);   // plot filtered data
            else             q2 = get_plot_q(i-1);      // plot raw data
            data -= q2.data[k];
         }
         else if(tie_plot(k) && plot[k].show_freq) {
            data = (DATA_SIZE) tie_to_freq(k, data);
         }

         if(k == TEMP) y = (DATA_SIZE) ((scale_temp((double) data / (double) queue_interval) - plot[k].plot_center) * plot[k].ref_scale);  // y = ppt
else if(enviro_mode() && (k == PRESSURE)) y = (DATA_SIZE) ((scale_pressure((double) data / (double) queue_interval) - plot[k].plot_center) * plot[k].ref_scale);
         else if(luxor && (k == TC2)) y = (DATA_SIZE) (((double) scale_temp(data / (double) queue_interval) - plot[k].plot_center) * plot[k].ref_scale);  // y = ppt
         else if(luxor && (k == LUX1)) y = (DATA_SIZE) (((data / queue_interval * lux_scale) - plot[k].plot_center) * plot[k].ref_scale);
         else if(luxor && (k == LUX2)) y = (DATA_SIZE) (((data / queue_interval * lum_scale) - plot[k].plot_center) * plot[k].ref_scale);
         else if(k >= NUM_PLOTS) {  // derived data DERIVED_PLOTS !!!!!
            if(luxor && (k == BATTW)) {        // battery watts
               y = (DATA_SIZE) (((q.data[BATTI]*q.data[BATTV] / queue_interval) - plot[k].plot_center) * plot[k].ref_scale);
            }
            else if(luxor && (k == LEDW)) {   // LED watts
               y = (DATA_SIZE) (((q.data[LEDI]*q.data[LEDV] / queue_interval) - plot[k].plot_center) * plot[k].ref_scale);
            }
            else if(luxor && (k == EFF)) { // driver efficency
               val = q.data[BATTI]*q.data[BATTV];
               if(val) val = q.data[LEDI]*q.data[LEDV] / val;
               val *= (DATA_SIZE) 100.0;
               y = (DATA_SIZE) ((val - plot[k].plot_center) * plot[k].ref_scale);
            }
            else if(luxor && (k == CCT)) { // color temo
               val = (DATA_SIZE) calc_cct(cct_type, 1, (double)q.data[REDHZ]/(double)queue_interval, (double)q.data[GREENHZ]/(double)queue_interval, (double)q.data[BLUEHZ]/(double)queue_interval);
               y = (DATA_SIZE) ((val - plot[k].plot_center) * plot[k].ref_scale);
            }
            else {
//             y = (DATA_SIZE) 0.0;
               y = (DATA_SIZE) (((data / queue_interval) - plot[k].plot_center) * plot[k].ref_scale);  // y = ppt
            }
         }
         else {
            y = (DATA_SIZE) (((data / queue_interval) - plot[k].plot_center) * plot[k].ref_scale);  // y = ppt
         }

         y /= (DATA_SIZE) (plot[k].scale_factor*plot[k].invert_plot);
         if(k != SAT_PLOT) {
            plot[k].last_y = plot_y(y, plot[k].last_y, plot[k].plot_color);
         }
      }

      if(plot[k].show_freq) ;        // can't plot trend line of freq plots
      else if(plot[k].show_deriv) ;  // can't plot trend line of derivative plots
      else if(plot[k].show_trend) {  // draw the trend line plot
         x = view_interval * queue_interval * (DATA_SIZE) plot_column;
         if(plot_mag) x /= (DATA_SIZE) plot_mag;
         y = (DATA_SIZE) (((plot[k].a0 + (plot[k].a1*x)) - plot[k].plot_center) * plot[k].ref_scale);  // y = ppt
         y /= (DATA_SIZE) (plot[k].scale_factor*plot[k].invert_plot);
         plot[k].last_trend_y = plot_y(y, plot[k].last_trend_y, plot[k].plot_color);
      }
   }
}

// Assembly:
cmpl $0x0, 0x226938(%rip)    # 0x23ef58
jne 0x18d19
cmpl $0x0, 0x2001ab(%rip)    # 0x2187d8
jne 0x18d19
cmpq $0x400, 0x200292(%rip) # imm = 0x400
je 0x18d19
cmpl $0x0, 0x32771d(%rip)    # 0x33fd68
jne 0x18d19
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdi, %rbx
movzbl 0x2f4139(%rip), %eax    # 0x30c7a8
cmpl $0x50, %eax
je 0x1867c
testl %eax, %eax
jne 0x18d08
cmpq $0x0, 0x202d14(%rip)    # 0x21b398
jle 0x18d08
cmpq $0x0, 0x202dde(%rip)    # 0x21b470
je 0x186ac
leaq -0x110(%rbp), %rdi
movq %rbx, %rsi
callq 0x11bc7
leaq 0x327bae(%rip), %r14    # 0x340258
jmp 0x186be
leaq -0x110(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x100be
movzwl (%r14), %r12d
movq 0x202cd7(%rip), %rax    # 0x21b3a0
imulq 0x202cc7(%rip), %rax    # 0x21b398
cvtsi2sd %rax, %xmm4
divsd 0xf0932(%rip), %xmm4    # 0x109010
movsd -0xf8(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm3
movapd %xmm1, %xmm0
mulsd %xmm4, %xmm0
addsd 0x2f476a(%rip), %xmm0   # 0x30ce68
movsd %xmm0, 0x2f4762(%rip)   # 0x30ce68
mulsd -0xf0(%rbp), %xmm1
mulsd %xmm4, %xmm1
addsd 0x2f4756(%rip), %xmm1   # 0x30ce70
movapd %xmm3, %xmm2
mulsd %xmm4, %xmm2
addsd 0x2f474e(%rip), %xmm2   # 0x30ce78
mulsd -0xd8(%rbp), %xmm3
movsd %xmm1, 0x2f4736(%rip)   # 0x30ce70
mulsd %xmm4, %xmm3
addsd 0x2f473a(%rip), %xmm3   # 0x30ce80
movsd %xmm2, 0x2f472a(%rip)   # 0x30ce78
movsd %xmm3, 0x2f472a(%rip)   # 0x30ce80
cmpb $0x0, 0x2f4707(%rip)    # 0x30ce64
je 0x18774
leaq 0x32623a(%rip), %rdi    # 0x33e9a0
leaq 0xf241b(%rip), %rsi     # 0x10ab88
movb $0x4, %al
callq 0x9060
leaq -0x1c0(%rbp), %r14
xorl %r15d, %r15d
xorps %xmm1, %xmm1
cvtsi2sdl 0x202c43(%rip), %xmm1 # 0x21b3cc
xorps %xmm0, %xmm0
cvtsi2sdq 0x202c0b(%rip), %xmm0 # 0x21b3a0
mulsd %xmm1, %xmm0
movsd -0x100(%rbp,%r15,8), %xmm1
movl %r15d, %edi
xorl %esi, %esi
callq 0x13cce
movsd %xmm0, -0x100(%rbp,%r15,8)
incq %r15
cmpq $0x14, %r15
jne 0x1877e
movl 0x202c05(%rip), %r15d   # 0x21b3cc
testl %r15d, %r15d
jle 0x187de
movl %r15d, %ecx
subl 0x202bfb(%rip), %ecx    # 0x21b3d0
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
jmp 0x187e2
movb $0x1, %al
xorl %ecx, %ecx
movl %ecx, 0x327d78(%rip)    # 0x340560
movb %al, 0x327d76(%rip)     # 0x340564
addl 0x20008b(%rip), %r15d   # 0x218880
btl $0xa, %r12d
jae 0x1881f
cmpb $0x0, 0x202bdb(%rip)    # 0x21b3de
je 0x1881f
movl 0x200071(%rip), %esi    # 0x21887c
leal 0x8(%rsi), %ecx
movl %r15d, %edi
movl %r15d, %edx
movl $0xc, %r8d
callq 0xe38a
btl $0x8, %r12d
jae 0x188ac
cmpb $0x0, 0x202bae(%rip)    # 0x21b3df
je 0x188ac
cmpb $0x0, 0x327d2a(%rip)    # 0x340564
je 0x18866
movl 0x20003a(%rip), %esi    # 0x21887c
movl %r15d, %edi
movl $0xc, %edx
callq 0xe657
movl 0x200027(%rip), %esi    # 0x21887c
incl %esi
movl %r15d, %edi
movl $0xc, %edx
callq 0xe657
jmp 0x188ac
movl 0x327cf4(%rip), %edi    # 0x340560
addl 0x20000e(%rip), %edi    # 0x218880
movl 0x200004(%rip), %ecx    # 0x21887c
movl %ecx, %esi
movl %r15d, %edx
movl $0xc, %r8d
callq 0xe38a
movl 0x327cd2(%rip), %edi    # 0x340560
addl 0x1fffec(%rip), %edi    # 0x218880
movl 0x1fffe2(%rip), %ecx    # 0x21887c
incl %ecx
movl %ecx, %esi
movl %r15d, %edx
movl $0xc, %r8d
callq 0xe38a
movl $0xa, %edi
callq 0xef35
btl $0xb, %r12d
jae 0x188eb
cmpb $0x0, 0x202b19(%rip)    # 0x21b3dd
je 0x188eb
movl 0x1fffb0(%rip), %eax    # 0x21887c
movl 0x1fffb6(%rip), %ecx    # 0x218888
leal (%rcx,%rax), %esi
addl %eax, %ecx
addl $-0x8, %ecx
movl %r15d, %edi
movl %r15d, %edx
movl $0xb, %r8d
callq 0xe38a
cmpl $0x0, 0x14658e(%rip)    # 0x15ee80
je 0x18961
movzbl -0x110(%rbp), %eax
imull 0x1fffa6(%rip), %eax    # 0x2188a8
movl 0x1fff7f(%rip), %r12d   # 0x218888
cmpl %r12d, %eax
cmovgel %r12d, %eax
addl 0x1fff65(%rip), %r12d   # 0x21887c
subl %eax, %r12d
cmpb $0x0, 0x327c43(%rip)    # 0x340564
je 0x18935
movl %r15d, %edi
movl %r12d, %esi
movl $0xb, %edx
callq 0xe657
jmp 0x1895a
movl 0x327c25(%rip), %edi    # 0x340560
addl 0x1fff3f(%rip), %edi    # 0x218880
movl 0x1fff5d(%rip), %esi    # 0x2188a4
movzbl 0x146539(%rip), %r8d    # 0x15ee88
movl %r15d, %edx
movl %r12d, %ecx
callq 0xe38a
movl %r12d, 0x1fff43(%rip)   # 0x2188a4
decq %rbx
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
mulsd -0xf0(%rbp), %xmm0
mulsd -0xd8(%rbp), %xmm1
movsd %xmm1, -0x50(%rbp)
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpneqsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
mulsd 0xf068f(%rip), %xmm2    # 0x109060
movapd %xmm2, -0x60(%rbp)
leaq 0x145363(%rip), %r13    # 0x15dd40
xorl %r15d, %r15d
leaq -0x1c0(%rbp), %r12
cmpl $0x0, 0x8(%r13)
je 0x18ab7
movsd -0x100(%rbp,%r15,8), %xmm0
cmpl $0x0, 0xbc(%r13)
movsd %xmm0, -0x30(%rbp)
je 0x18a22
cmpq $0x0, 0x202a5d(%rip)    # 0x21b470
je 0x18a4b
movq %r12, %rdi
movq %rbx, %rsi
callq 0x11bc7
jmp 0x18a56
movl %r15d, %edi
callq 0x13c3e
testl %eax, %eax
je 0x18c21
cmpl $0x0, 0xc0(%r13)
movsd -0x30(%rbp), %xmm0
je 0x18a65
movl %r15d, %edi
callq 0xadb42
jmp 0x18a65
movq %r14, %rdi
movq %rbx, %rsi
callq 0x100be
movsd -0x30(%rbp), %xmm0
subsd -0x1b0(%rbp,%r15,8), %xmm0
cmpq $0x3, %r15
jne 0x18b82
xorps %xmm1, %xmm1
cvtsi2sdq 0x20291d(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
callq 0x131c9
subsd 0x18(%r13), %xmm0
mulsd (%r13), %xmm0
movsd 0x28(%r13), %xmm1
mulsd 0x38(%r13), %xmm1
divsd %xmm1, %xmm0
movl 0xb0(%r13), %edi
movl 0x10(%r13), %esi
callq 0x1857b
movl %eax, 0xb0(%r13)
cmpl $0x0, 0xc0(%r13)
jne 0x18b69
cmpl $0x0, 0xbc(%r13)
jne 0x18b69
cmpl $0x0, 0xb8(%r13)
je 0x18b69
movl 0x2028e9(%rip), %eax    # 0x21b3d0
movsd 0xf0581(%rip), %xmm1    # 0x109070
testl %eax, %eax
je 0x18afa
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movq 0x202897(%rip), %rax    # 0x21b398
imulq 0x202897(%rip), %rax    # 0x21b3a0
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
xorps %xmm0, %xmm0
cvtsi2sdl 0x2028b0(%rip), %xmm0 # 0x21b3cc
mulsd %xmm2, %xmm0
divsd %xmm1, %xmm0
mulsd 0x88(%r13), %xmm0
addsd 0x80(%r13), %xmm0
subsd 0x18(%r13), %xmm0
mulsd (%r13), %xmm0
movsd 0x28(%r13), %xmm1
mulsd 0x38(%r13), %xmm1
divsd %xmm1, %xmm0
movl 0xc8(%r13), %edi
movl 0x10(%r13), %esi
callq 0x1857b
movl %eax, 0xc8(%r13)
incq %r15
addq $0xe8, %r13
cmpq $0x14, %r15
jne 0x189e7
jmp 0x18d08
movsd %xmm0, -0x30(%rbp)
callq 0x5f6cb
testl %eax, %eax
sete %al
cmpq $0x10, %r15
setne %cl
orb %al, %cl
jne 0x18bd6
xorps %xmm0, %xmm0
cvtsi2sdq 0x2027f0(%rip), %xmm0 # 0x21b398
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movq 0x2f43f0(%rip), %rax    # 0x30cfa8
cmpb $0x66, (%rax)
movapd %xmm1, %xmm0
mulsd 0xf04f9(%rip), %xmm0    # 0x1090c0
je 0x18a84
movapd %xmm1, %xmm0
jmp 0x18a84
movb 0x226362(%rip), %al     # 0x23ef3e
testb %al, %al
sete %cl
cmpq $0x8, %r15
setne %dl
orb %cl, %dl
movsd -0x30(%rbp), %xmm0
je 0x18a6f
testb %al, %al
sete %cl
testq %r15, %r15
setne %dl
orb %cl, %dl
jne 0x18c2b
xorps %xmm1, %xmm1
cvtsi2sdq 0x202788(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
mulsd 0x1ffc94(%rip), %xmm0   # 0x2188b0
jmp 0x18a84
movsd -0x30(%rbp), %xmm0
jmp 0x18a65
testb %al, %al
sete %cl
cmpq $0x4, %r15
setne %dl
orb %cl, %dl
jne 0x18c58
xorps %xmm1, %xmm1
cvtsi2sdq 0x202751(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
mulsd 0x1ffc65(%rip), %xmm0   # 0x2188b8
jmp 0x18a84
cmpq $0x10, %r15
jb 0x18cf3
testb %al, %al
sete %cl
cmpq $0x10, %r15
setne %dl
orb %cl, %dl
jne 0x18c85
xorps %xmm1, %xmm1
cvtsi2sdq 0x20271a(%rip), %xmm1 # 0x21b398
movsd -0x50(%rbp), %xmm0
jmp 0x18cff
testb %al, %al
sete %cl
cmpq $0x11, %r15
setne %dl
orb %cl, %dl
jne 0x18c9f
movapd -0x60(%rbp), %xmm0
jmp 0x18a84
testb %al, %al
sete %al
cmpq $0x12, %r15
setne %cl
orb %al, %cl
jne 0x18ce9
movzbl 0x2f42b2(%rip), %edi    # 0x30cf68
cvtsi2sdq 0x2026d9(%rip), %xmm3 # 0x21b398
movsd -0x48(%rbp), %xmm0
divsd %xmm3, %xmm0
movsd -0x40(%rbp), %xmm1
divsd %xmm3, %xmm1
movsd -0x38(%rbp), %xmm2
divsd %xmm3, %xmm2
movl $0x1, %esi
callq 0x7aa82
jmp 0x18a84
cmpq $0x13, %r15
je 0x18ab7
xorps %xmm1, %xmm1
cvtsi2sdq 0x202699(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
jmp 0x18a84
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq