// File: /workspace/github_cpp_makefile_star2_O1/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, 0x226948(%rip)    # 0x23ef58
jne 0x18d05
cmpl $0x0, 0x2001bb(%rip)    # 0x2187d8
jne 0x18d05
cmpq $0x400, 0x2002a2(%rip) # imm = 0x400
je 0x18d05
cmpl $0x0, 0x32772d(%rip)    # 0x33fd68
jne 0x18d05
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdi, %rbx
movzbl 0x2f4149(%rip), %eax    # 0x30c7a8
cmpl $0x50, %eax
je 0x1866c
testl %eax, %eax
jne 0x18cf4
cmpq $0x0, 0x202d24(%rip)    # 0x21b398
jle 0x18cf4
cmpq $0x0, 0x202dee(%rip)    # 0x21b470
je 0x1869c
leaq -0x110(%rbp), %rdi
movq %rbx, %rsi
callq 0x11c44
leaq 0x327bbe(%rip), %r14    # 0x340258
jmp 0x186ae
leaq -0x110(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10141
movzwl (%r14), %r12d
movq 0x202ce7(%rip), %rax    # 0x21b3a0
imulq 0x202cd7(%rip), %rax    # 0x21b398
cvtsi2sd %rax, %xmm4
divsd 0xf0942(%rip), %xmm4    # 0x109010
movsd -0xf8(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm3
movapd %xmm1, %xmm0
mulsd %xmm4, %xmm0
addsd 0x2f477a(%rip), %xmm0   # 0x30ce68
movsd %xmm0, 0x2f4772(%rip)   # 0x30ce68
mulsd -0xf0(%rbp), %xmm1
mulsd %xmm4, %xmm1
addsd 0x2f4766(%rip), %xmm1   # 0x30ce70
movapd %xmm3, %xmm2
mulsd %xmm4, %xmm2
addsd 0x2f475e(%rip), %xmm2   # 0x30ce78
mulsd -0xd8(%rbp), %xmm3
movsd %xmm1, 0x2f4746(%rip)   # 0x30ce70
mulsd %xmm4, %xmm3
addsd 0x2f474a(%rip), %xmm3   # 0x30ce80
movsd %xmm2, 0x2f473a(%rip)   # 0x30ce78
movsd %xmm3, 0x2f473a(%rip)   # 0x30ce80
cmpb $0x0, 0x2f4717(%rip)    # 0x30ce64
je 0x18764
leaq 0x32624a(%rip), %rdi    # 0x33e9a0
leaq 0xf241b(%rip), %rsi     # 0x10ab78
movb $0x4, %al
callq 0x9060
leaq -0x1c0(%rbp), %r14
xorl %r15d, %r15d
xorps %xmm1, %xmm1
cvtsi2sdl 0x202c53(%rip), %xmm1 # 0x21b3cc
xorps %xmm0, %xmm0
cvtsi2sdq 0x202c1b(%rip), %xmm0 # 0x21b3a0
mulsd %xmm1, %xmm0
movsd -0x100(%rbp,%r15,8), %xmm1
movl %r15d, %edi
xorl %esi, %esi
callq 0x13d5d
movsd %xmm0, -0x100(%rbp,%r15,8)
incq %r15
cmpq $0x14, %r15
jne 0x1876e
movl 0x202c15(%rip), %r15d   # 0x21b3cc
testl %r15d, %r15d
jle 0x187ce
movl %r15d, %ecx
subl 0x202c0b(%rip), %ecx    # 0x21b3d0
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
jmp 0x187d2
movb $0x1, %al
xorl %ecx, %ecx
movl %ecx, 0x327d88(%rip)    # 0x340560
movb %al, 0x327d86(%rip)     # 0x340564
addl 0x20009b(%rip), %r15d   # 0x218880
btl $0xa, %r12d
jae 0x1880f
cmpb $0x0, 0x202beb(%rip)    # 0x21b3de
je 0x1880f
movl 0x200081(%rip), %esi    # 0x21887c
leal 0x8(%rsi), %ecx
movl %r15d, %edi
movl %r15d, %edx
movl $0xc, %r8d
callq 0xe3c3
btl $0x8, %r12d
jae 0x1889c
cmpb $0x0, 0x202bbe(%rip)    # 0x21b3df
je 0x1889c
cmpb $0x0, 0x327d3a(%rip)    # 0x340564
je 0x18856
movl 0x20004a(%rip), %esi    # 0x21887c
movl %r15d, %edi
movl $0xc, %edx
callq 0xe6a0
movl 0x200037(%rip), %esi    # 0x21887c
incl %esi
movl %r15d, %edi
movl $0xc, %edx
callq 0xe6a0
jmp 0x1889c
movl 0x327d04(%rip), %edi    # 0x340560
addl 0x20001e(%rip), %edi    # 0x218880
movl 0x200014(%rip), %ecx    # 0x21887c
movl %ecx, %esi
movl %r15d, %edx
movl $0xc, %r8d
callq 0xe3c3
movl 0x327ce2(%rip), %edi    # 0x340560
addl 0x1ffffc(%rip), %edi    # 0x218880
movl 0x1ffff2(%rip), %ecx    # 0x21887c
incl %ecx
movl %ecx, %esi
movl %r15d, %edx
movl $0xc, %r8d
callq 0xe3c3
movl $0xa, %edi
callq 0xefb4
btl $0xb, %r12d
jae 0x188db
cmpb $0x0, 0x202b29(%rip)    # 0x21b3dd
je 0x188db
movl 0x1fffc0(%rip), %eax    # 0x21887c
movl 0x1fffc6(%rip), %ecx    # 0x218888
leal (%rcx,%rax), %esi
addl %eax, %ecx
addl $-0x8, %ecx
movl %r15d, %edi
movl %r15d, %edx
movl $0xb, %r8d
callq 0xe3c3
cmpl $0x0, 0x14659e(%rip)    # 0x15ee80
je 0x18951
movzbl -0x110(%rbp), %eax
imull 0x1fffb6(%rip), %eax    # 0x2188a8
movl 0x1fff8f(%rip), %r12d   # 0x218888
cmpl %r12d, %eax
cmovgel %r12d, %eax
addl 0x1fff75(%rip), %r12d   # 0x21887c
subl %eax, %r12d
cmpb $0x0, 0x327c53(%rip)    # 0x340564
je 0x18925
movl %r15d, %edi
movl %r12d, %esi
movl $0xb, %edx
callq 0xe6a0
jmp 0x1894a
movl 0x327c35(%rip), %edi    # 0x340560
addl 0x1fff4f(%rip), %edi    # 0x218880
movl 0x1fff6d(%rip), %esi    # 0x2188a4
movzbl 0x146549(%rip), %r8d    # 0x15ee88
movl %r15d, %edx
movl %r12d, %ecx
callq 0xe3c3
movl %r12d, 0x1fff53(%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 0xf069f(%rip), %xmm2    # 0x109060
movapd %xmm2, -0x60(%rbp)
leaq 0x145373(%rip), %r13    # 0x15dd40
xorl %r15d, %r15d
leaq -0x1c0(%rbp), %r12
cmpl $0x0, 0x8(%r13)
je 0x18aad
movsd -0x100(%rbp,%r15,8), %xmm0
cmpl $0x0, 0xbc(%r13)
movsd %xmm0, -0x30(%rbp)
je 0x18a12
cmpq $0x0, 0x202a6d(%rip)    # 0x21b470
je 0x18a3b
movq %r12, %rdi
movq %rbx, %rsi
callq 0x11c44
jmp 0x18a46
movl %r15d, %edi
callq 0x13ccd
testl %eax, %eax
je 0x18c17
cmpl $0x0, 0xc0(%r13)
movsd -0x30(%rbp), %xmm0
je 0x18a55
movl %r15d, %edi
callq 0xad8a2
jmp 0x18a55
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10141
movsd -0x30(%rbp), %xmm0
subsd -0x1b0(%rbp,%r15,8), %xmm0
cmpq $0x3, %r15
jne 0x18b78
xorps %xmm1, %xmm1
cvtsi2sdq 0x20292d(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
callq 0x1325e
subsd 0x18(%r13), %xmm0
mulsd (%r13), %xmm0
cmpq $0x13, %r15
je 0x18aad
movsd 0x28(%r13), %xmm1
mulsd 0x38(%r13), %xmm1
divsd %xmm1, %xmm0
movl 0xb0(%r13), %edi
movl 0x10(%r13), %esi
callq 0x1856b
movl %eax, 0xb0(%r13)
cmpl $0x0, 0xc0(%r13)
jne 0x18b5f
cmpl $0x0, 0xbc(%r13)
jne 0x18b5f
cmpl $0x0, 0xb8(%r13)
je 0x18b5f
movl 0x2028f3(%rip), %eax    # 0x21b3d0
movsd 0xf058b(%rip), %xmm1    # 0x109070
testl %eax, %eax
je 0x18af0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movq 0x2028a1(%rip), %rax    # 0x21b398
imulq 0x2028a1(%rip), %rax    # 0x21b3a0
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
xorps %xmm0, %xmm0
cvtsi2sdl 0x2028ba(%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 0x1856b
movl %eax, 0xc8(%r13)
incq %r15
addq $0xe8, %r13
cmpq $0x14, %r15
jne 0x189d7
jmp 0x18cf4
movsd %xmm0, -0x30(%rbp)
callq 0x5f743
testl %eax, %eax
sete %al
cmpq $0x10, %r15
setne %cl
orb %al, %cl
jne 0x18bcc
xorps %xmm0, %xmm0
cvtsi2sdq 0x2027fa(%rip), %xmm0 # 0x21b398
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movq 0x2f43fa(%rip), %rax    # 0x30cfa8
cmpb $0x66, (%rax)
movapd %xmm1, %xmm0
mulsd 0xf0503(%rip), %xmm0    # 0x1090c0
je 0x18a74
movapd %xmm1, %xmm0
jmp 0x18a74
movb 0x22636c(%rip), %al     # 0x23ef3e
testb %al, %al
sete %cl
cmpq $0x8, %r15
setne %dl
orb %cl, %dl
movsd -0x30(%rbp), %xmm0
je 0x18a5f
testb %al, %al
sete %cl
testq %r15, %r15
setne %dl
orb %cl, %dl
jne 0x18c21
xorps %xmm1, %xmm1
cvtsi2sdq 0x202792(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
mulsd 0x1ffc9e(%rip), %xmm0   # 0x2188b0
jmp 0x18a74
movsd -0x30(%rbp), %xmm0
jmp 0x18a55
testb %al, %al
sete %cl
cmpq $0x4, %r15
setne %dl
orb %cl, %dl
jne 0x18c4e
xorps %xmm1, %xmm1
cvtsi2sdq 0x20275b(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
mulsd 0x1ffc6f(%rip), %xmm0   # 0x2188b8
jmp 0x18a74
cmpq $0x10, %r15
jb 0x18cdf
testb %al, %al
sete %cl
cmpq $0x10, %r15
setne %dl
orb %cl, %dl
jne 0x18c7b
xorps %xmm1, %xmm1
cvtsi2sdq 0x202724(%rip), %xmm1 # 0x21b398
movsd -0x50(%rbp), %xmm0
jmp 0x18ceb
testb %al, %al
sete %cl
cmpq $0x11, %r15
setne %dl
orb %cl, %dl
jne 0x18c95
movapd -0x60(%rbp), %xmm0
jmp 0x18a74
testb %al, %al
sete %al
cmpq $0x12, %r15
setne %cl
orb %al, %cl
jne 0x18cdf
movzbl 0x2f42bc(%rip), %edi    # 0x30cf68
cvtsi2sdq 0x2026e3(%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 0x7ace4
jmp 0x18a74
xorps %xmm1, %xmm1
cvtsi2sdq 0x2026ad(%rip), %xmm1 # 0x21b398
divsd %xmm1, %xmm0
jmp 0x18a74
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq