// File: /workspace/github_cpp_makefile_star2_O2/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, 0x2113f6(%rip)    # 0x228f58
jne 0x18244
cmpl $0x0, 0x1eac69(%rip)    # 0x2027d8
jne 0x18244
cmpq $0x400, 0x1ead50(%rip) # imm = 0x400
je 0x18244
cmpl $0x0, 0x3121db(%rip)    # 0x329d68
jne 0x18244
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdi, %rbx
movzbl 0x2debf7(%rip), %eax    # 0x2f67a8
cmpl $0x50, %eax
je 0x17bbe
testl %eax, %eax
jne 0x18233
cmpq $0x0, 0x1ed7d2(%rip)    # 0x205398
jle 0x18233
cmpq $0x0, 0x1ed89c(%rip)    # 0x205470
je 0x17bee
leaq -0x110(%rbp), %rdi
movq %rbx, %rsi
callq 0x11478
leaq 0x31266c(%rip), %r14    # 0x32a258
jmp 0x17c00
leaq -0x110(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xf9c7
movzwl (%r14), %r13d
movq 0x1ed795(%rip), %rax    # 0x2053a0
imulq 0x1ed785(%rip), %rax    # 0x205398
cvtsi2sd %rax, %xmm4
divsd 0xdb3f0(%rip), %xmm4    # 0xf3010
movsd -0xf8(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm3
movapd %xmm1, %xmm0
mulsd %xmm4, %xmm0
addsd 0x2df228(%rip), %xmm0   # 0x2f6e68
movsd %xmm0, 0x2df220(%rip)   # 0x2f6e68
mulsd -0xf0(%rbp), %xmm1
mulsd %xmm4, %xmm1
addsd 0x2df214(%rip), %xmm1   # 0x2f6e70
movapd %xmm3, %xmm2
mulsd %xmm4, %xmm2
addsd 0x2df20c(%rip), %xmm2   # 0x2f6e78
mulsd -0xd8(%rbp), %xmm3
movsd %xmm1, 0x2df1f4(%rip)   # 0x2f6e70
mulsd %xmm4, %xmm3
addsd 0x2df1f8(%rip), %xmm3   # 0x2f6e80
movsd %xmm2, 0x2df1e8(%rip)   # 0x2f6e78
movsd %xmm3, 0x2df1e8(%rip)   # 0x2f6e80
cmpb $0x0, 0x2df1c5(%rip)    # 0x2f6e64
je 0x17cb6
leaq 0x310cf8(%rip), %rdi    # 0x3289a0
leaq 0xdcf54(%rip), %rsi     # 0xf4c03
movb $0x4, %al
callq 0x9060
leaq -0x1c0(%rbp), %r14
xorl %r15d, %r15d
cmpq $0x14, %r15
je 0x17cfe
cvtsi2sdl 0x1ed6fe(%rip), %xmm1 # 0x2053cc
cvtsi2sdq 0x1ed6c9(%rip), %xmm0 # 0x2053a0
mulsd %xmm1, %xmm0
movsd -0x100(%rbp,%r15,8), %xmm1
movl %r15d, %edi
xorl %esi, %esi
callq 0x133fc
movsd %xmm0, -0x100(%rbp,%r15,8)
incq %r15
jmp 0x17cc0
movl 0x1ed6c7(%rip), %r15d   # 0x2053cc
testl %r15d, %r15d
jle 0x17d1c
movl %r15d, %ecx
subl 0x1ed6bd(%rip), %ecx    # 0x2053d0
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
jmp 0x17d20
movb $0x1, %al
xorl %ecx, %ecx
movl %ecx, 0x31283a(%rip)    # 0x32a560
movb %al, 0x312838(%rip)     # 0x32a564
addl 0x1eab4d(%rip), %r15d   # 0x202880
btl $0xa, %r13d
jae 0x17d5b
cmpb $0x0, 0x1ed69d(%rip)    # 0x2053de
je 0x17d5b
movl 0x1eab33(%rip), %esi    # 0x20287c
leal 0x8(%rsi), %ecx
pushq $0xc
popq %r8
movl %r15d, %edi
movl %r15d, %edx
callq 0xdedf
btl $0x8, %r13d
jae 0x17de6
cmpb $0x0, 0x1ed672(%rip)    # 0x2053df
je 0x17de6
cmpb $0x0, 0x3127ee(%rip)    # 0x32a564
je 0x17da2
movl 0x1eaafe(%rip), %esi    # 0x20287c
pushq $0xc
popq %r12
movl %r15d, %edi
movl %r12d, %edx
callq 0xe1a7
movl 0x1eaae9(%rip), %esi    # 0x20287c
incl %esi
movl %r15d, %edi
movl %r12d, %edx
callq 0xe1a7
jmp 0x17de6
movl 0x3127b8(%rip), %edi    # 0x32a560
addl 0x1eaad2(%rip), %edi    # 0x202880
movl 0x1eaac8(%rip), %ecx    # 0x20287c
pushq $0xc
popq %r12
movl %ecx, %esi
movl %r15d, %edx
movl %r12d, %r8d
callq 0xdedf
movl 0x312795(%rip), %edi    # 0x32a560
addl 0x1eaaaf(%rip), %edi    # 0x202880
movl 0x1eaaa5(%rip), %ecx    # 0x20287c
incl %ecx
movl %ecx, %esi
movl %r15d, %edx
movl %r12d, %r8d
callq 0xdedf
pushq $0xa
popq %rdi
callq 0xe9f6
btl $0xb, %r13d
jae 0x17e21
cmpb $0x0, 0x1ed5e1(%rip)    # 0x2053dd
je 0x17e21
movl 0x1eaa78(%rip), %eax    # 0x20287c
movl 0x1eaa7e(%rip), %ecx    # 0x202888
leal (%rcx,%rax), %esi
addl %eax, %ecx
addl $-0x8, %ecx
pushq $0xb
popq %r8
movl %r15d, %edi
movl %r15d, %edx
callq 0xdedf
cmpl $0x0, 0x131058(%rip)    # 0x148e80
je 0x17e95
movzbl -0x110(%rbp), %eax
imull 0x1eaa70(%rip), %eax    # 0x2028a8
movl 0x1eaa49(%rip), %r12d   # 0x202888
cmpl %r12d, %eax
cmovgel %r12d, %eax
addl 0x1eaa2f(%rip), %r12d   # 0x20287c
subl %eax, %r12d
cmpb $0x0, 0x31270d(%rip)    # 0x32a564
je 0x17e69
pushq $0xb
popq %rdx
movl %r15d, %edi
movl %r12d, %esi
callq 0xe1a7
jmp 0x17e8e
movl 0x3126f1(%rip), %edi    # 0x32a560
addl 0x1eaa0b(%rip), %edi    # 0x202880
movl 0x1eaa29(%rip), %esi    # 0x2028a4
movzbl 0x131005(%rip), %r8d    # 0x148e88
movl %r15d, %edx
movl %r12d, %ecx
callq 0xdedf
movl %r12d, 0x1eaa0f(%rip)   # 0x2028a4
decq %rbx
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
mulsd -0xf0(%rbp), %xmm0
mulsd -0xd8(%rbp), %xmm1
movsd -0xb8(%rbp), %xmm2
movsd %xmm2, -0x38(%rbp)
movsd %xmm1, -0x50(%rbp)
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpneqsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
mulsd 0xdb15b(%rip), %xmm2    # 0xf3060
movapd %xmm2, -0x60(%rbp)
leaq 0x12fe2f(%rip), %r12    # 0x147d40
xorl %r15d, %r15d
leaq -0x1c0(%rbp), %r13
cmpq $0x14, %r15
je 0x18233
cmpl $0x0, 0x8(%r12)
je 0x17ffb
movsd -0x100(%rbp,%r15,8), %xmm0
cmpl $0x0, 0xbc(%r12)
movsd %xmm0, -0x30(%rbp)
je 0x17f62
cmpq $0x0, 0x1ed51d(%rip)    # 0x205470
je 0x17f8c
movq %r13, %rdi
movq %rbx, %rsi
callq 0x11478
jmp 0x17f97
movl %r15d, %edi
callq 0x13376
testl %eax, %eax
je 0x18157
cmpl $0x0, 0xc0(%r12)
movsd -0x30(%rbp), %xmm0
je 0x17fa6
movl %r15d, %edi
callq 0x9daff
jmp 0x17fa6
movq %r14, %rdi
movq %rbx, %rsi
callq 0xf9c7
movsd -0x30(%rbp), %xmm0
subsd -0x1b0(%rbp,%r15,8), %xmm0
cmpq $0x3, %r15
jne 0x180be
cvtsi2sdq 0x1ed3df(%rip), %xmm1 # 0x205398
divsd %xmm1, %xmm0
callq 0x12952
subsd 0x18(%r12), %xmm0
mulsd (%r12), %xmm0
movsd 0x28(%r12), %xmm1
mulsd 0x38(%r12), %xmm1
divsd %xmm1, %xmm0
movl 0xb0(%r12), %edi
movl 0x10(%r12), %esi
callq 0x17abd
movl %eax, 0xb0(%r12)
cmpl $0x0, 0xc0(%r12)
jne 0x180af
cmpl $0x0, 0xbc(%r12)
jne 0x180af
cmpl $0x0, 0xb8(%r12)
je 0x180af
movl 0x1ed3a2(%rip), %eax    # 0x2053d0
movsd 0xdb03a(%rip), %xmm1    # 0xf3070
testl %eax, %eax
je 0x1803e
cvtsi2sd %eax, %xmm1
movq 0x1ed353(%rip), %rax    # 0x205398
imulq 0x1ed353(%rip), %rax    # 0x2053a0
cvtsi2sd %rax, %xmm2
cvtsi2sdl 0x1ed372(%rip), %xmm0 # 0x2053cc
mulsd %xmm2, %xmm0
divsd %xmm1, %xmm0
mulsd 0x88(%r12), %xmm0
addsd 0x80(%r12), %xmm0
subsd 0x18(%r12), %xmm0
mulsd (%r12), %xmm0
movsd 0x28(%r12), %xmm1
mulsd 0x38(%r12), %xmm1
divsd %xmm1, %xmm0
movl 0xc8(%r12), %edi
movl 0x10(%r12), %esi
callq 0x17abd
movl %eax, 0xc8(%r12)
incq %r15
addq $0xe8, %r12
jmp 0x17f1b
movsd %xmm0, -0x30(%rbp)
callq 0x57eca
testl %eax, %eax
sete %al
cmpq $0x10, %r15
setne %cl
orb %al, %cl
jne 0x1810f
cvtsi2sdq 0x1ed2b7(%rip), %xmm0 # 0x205398
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movq 0x2deeb7(%rip), %rax    # 0x2f6fa8
cmpb $0x66, (%rax)
movapd %xmm1, %xmm0
mulsd 0xdafc0(%rip), %xmm0    # 0xf30c0
je 0x17fc2
movapd %xmm1, %xmm0
jmp 0x17fc2
movb 0x210e29(%rip), %al     # 0x228f3e
testb %al, %al
sete %cl
cmpq $0x8, %r15
setne %dl
orb %cl, %dl
movsd -0x30(%rbp), %xmm0
je 0x17fb0
testb %al, %al
sete %cl
testq %r15, %r15
setne %dl
orb %cl, %dl
jne 0x18161
cvtsi2sdq 0x1ed252(%rip), %xmm1 # 0x205398
divsd %xmm1, %xmm0
mulsd 0x1ea75e(%rip), %xmm0   # 0x2028b0
jmp 0x17fc2
movsd -0x30(%rbp), %xmm0
jmp 0x17fa6
testb %al, %al
sete %cl
cmpq $0x4, %r15
setne %dl
orb %cl, %dl
jne 0x1818b
cvtsi2sdq 0x1ed21e(%rip), %xmm1 # 0x205398
divsd %xmm1, %xmm0
mulsd 0x1ea732(%rip), %xmm0   # 0x2028b8
jmp 0x17fc2
cmpq $0x10, %r15
jb 0x18221
testb %al, %al
sete %cl
cmpq $0x10, %r15
setne %dl
orb %cl, %dl
jne 0x181b5
cvtsi2sdq 0x1ed1ea(%rip), %xmm1 # 0x205398
movsd -0x50(%rbp), %xmm0
jmp 0x1822a
testb %al, %al
sete %cl
cmpq $0x11, %r15
setne %dl
orb %cl, %dl
jne 0x181cf
movapd -0x60(%rbp), %xmm0
jmp 0x17fc2
testb %al, %al
sete %al
cmpq $0x12, %r15
setne %cl
orb %al, %cl
jne 0x18217
movzbl 0x2ded82(%rip), %edi    # 0x2f6f68
cvtsi2sdq 0x1ed1a9(%rip), %xmm3 # 0x205398
movsd -0x48(%rbp), %xmm0
divsd %xmm3, %xmm0
movsd -0x40(%rbp), %xmm1
divsd %xmm3, %xmm1
movsd -0x38(%rbp), %xmm2
divsd %xmm3, %xmm2
pushq $0x1
popq %rsi
callq 0x702c1
jmp 0x17fc2
cmpq $0x13, %r15
je 0x17ffb
cvtsi2sdq 0x1ed16e(%rip), %xmm1 # 0x205398
divsd %xmm1, %xmm0
jmp 0x17fc2
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq