// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: plot_lla_point(int, int)
void plot_lla_point(int draw, int color)
{
double x,y;
double xi, yi;
double half_span;
double old_lat, old_lon, old_alt;
double old_ref_lat, old_ref_lon, old_ref_alt;
double old_span, old_scale, old_cos;
double span;

   // add a point to the lat/lon scattergram plot

   if(draw) {
      if(text_mode || (first_key && (SCREEN_HEIGHT < SHORT_SCREEN))) return;
      if(zoom_screen && (zoom_screen != 'L')) return; 
      if(0 && all_adevs && (WIDE_SCREEN == 0)) return;
      if((SCREEN_HEIGHT < SHORT_SCREEN) && (shared_plot == 0)) return;
   }

   old_lat = lat;
   old_lon = lon;
   old_alt = alt;
   old_ref_lat = ref_lat;
   old_ref_lon = ref_lon;
   old_ref_alt = ref_alt;
   old_span = LLA_SPAN;
   old_scale = ANGLE_SCALE;
   old_cos = cos_factor;

   if((rcvr_type == TIDE_RCVR) || show_tides) { // ckckck adjust scale factors for showing lat/lon earth tides
      LLA_SPAN = TIDE_LLA_SPAN;    // !!!!! 10? 15?
      ANGLE_SCALE = 1.0;
      cos_factor = 1.0;
      lat = 0.0 - (lat_tide / RAD_TO_DEG);
      lon = 0.0 - (lon_tide / RAD_TO_DEG);
      alt = alt_tide;
      ref_lat = 0.0;
      ref_lon = 0.0;
      tide_scatter = 1;
   }
   else if(1 && ((lat == 0.0) || (lon == 0.0))) {  // ignore likely invald location
      goto no_lla;
   }
   else {
      if(1 && autoscale_lla && have_valid_lla) {
         span = calc_lla_span(0);
         if(((lla_points < 2) && (span != last_lla_span)) || (span > last_lla_span)) {  // the plot scale has changed
//          autoscale_lla = 0;  // toggle autoscale off
//          change_lla_scale();

            autoscale_lla = 1;        // toggle autoscale back on
            change_lla_scale();

            if(in_rebuild_lla) ;      //llascale - prevent recursion with rebuild_lla_plot()
            else rebuild_lla_plot(0);
            need_redraw = 4321;

            old_ref_lat = ref_lat;
            old_ref_lon = ref_lon;
            old_ref_alt = alt;
            old_cos = cos_factor;
            old_span = LLA_SPAN;
            user_set_ref_lla = 3;
         }
      }
      tide_scatter = 0;
   }


   y = (ref_lat - lat) * RAD_TO_DEG / ANGLE_SCALE;   // x,y = meters (or feet) from center
   x = ((lon - ref_lon) * RAD_TO_DEG / ANGLE_SCALE) * cos_factor;

   half_span = (LLA_SPAN*(double)LLA_DIVISIONS/2.0); // meters each side of center
   if(half_span == 0.0) return;

   if(x > half_span) x = half_span;
   if(x < (-half_span)) x = (-half_span);

   if(y > half_span) y = half_span;
   if(y < (-half_span)) y = (-half_span);

   yi = (y * ((double)lla_width / 2.0)) / half_span;
   xi = (x * ((double)lla_width / 2.0)) / half_span;
   lla_xi = LLA_X + (int) xi;
   lla_yi = LLA_Y + (int) yi;
   if(draw) dot(lla_xi, lla_yi, color);

#ifdef BUFFER_LLA
   // save lla point in the buffer so we can redraw the screen later
   ++lla_points;
   color = (lla_points / (60*60));
   color = (color % 12) + 3;

   xi += ((double) lla_width/2.0);
   yi += ((double) lla_width/2.0);

   xi = ((double) xi * (double) MAX_LLA_SIZE / (double) lla_width);
   yi = ((double) yi * (double) MAX_LLA_SIZE / (double) lla_width);
   if((xi >= 0.0) && (xi < (double) MAX_LLA_SIZE) && (yi >= 0.0) && (yi < (double) MAX_LLA_SIZE)) {
      lla_data[(int)xi][(int)yi] = (u08) color;
   }
#endif

   no_lla:
   lat = old_lat;
   lon = old_lon;
   alt = old_alt;
   ref_lat = old_ref_lat;
   ref_lon = old_ref_lon;
   ref_alt = old_ref_alt;
   LLA_SPAN = old_span;
   ANGLE_SCALE = old_scale;
   cos_factor = old_cos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0x12c288
leaq 0x14b79a(%rip), %rax    # 0x2779b8
cmpl $0x0, (%rax)
jne 0x12c23e
leaq 0x171f0e(%rip), %rax    # 0x29e138
cmpl $0x0, (%rax)
je 0x12c243
leaq 0x14b7ae(%rip), %rax    # 0x2779e4
cmpl $0x258, (%rax)          # imm = 0x258
jge 0x12c243
jmp 0x12c93b
leaq 0x23f73e(%rip), %rax    # 0x36b988
cmpb $0x0, (%rax)
je 0x12c263
leaq 0x23f732(%rip), %rax    # 0x36b988
movzbl (%rax), %eax
cmpl $0x4c, %eax
je 0x12c263
jmp 0x12c93b
leaq 0x14b77a(%rip), %rax    # 0x2779e4
cmpl $0x258, (%rax)          # imm = 0x258
jge 0x12c286
leaq 0x26e34f(%rip), %rax    # 0x39a5c8
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x12c286
jmp 0x12c93b
jmp 0x12c288
leaq 0x23ff21(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x23ff19(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq 0x23ff11(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x26e231(%rip), %rax    # 0x39a4f0
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x26e229(%rip), %rax    # 0x39a4f8
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x26e221(%rip), %rax    # 0x39a500
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x26e181(%rip), %rax    # 0x39a470
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
leaq 0x23fe99(%rip), %rax    # 0x36c198
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq 0x23fe99(%rip), %rax    # 0x36c1a8
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
leaq 0x14b791(%rip), %rax    # 0x277ab0
cmpq $0x800000, (%rax)       # imm = 0x800000
je 0x12c338
leaq 0x23ff31(%rip), %rax    # 0x36c260
cmpl $0x0, (%rax)
je 0x12c407
leaq 0x26e131(%rip), %rax    # 0x39a470
movsd 0x56c01(%rip), %xmm0    # 0x182f48
movsd %xmm0, (%rax)
leaq 0x23fe46(%rip), %rax    # 0x36c198
movsd 0x42d0e(%rip), %xmm0    # 0x16f068
movsd %xmm0, (%rax)
leaq 0x23fe43(%rip), %rax    # 0x36c1a8
movsd 0x42cfb(%rip), %xmm0    # 0x16f068
movsd %xmm0, (%rax)
leaq 0x23feb0(%rip), %rax    # 0x36c228
movsd (%rax), %xmm1
movsd 0x42dfc(%rip), %xmm0    # 0x16f180
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
subsd %xmm1, %xmm0
leaq 0x23fe1a(%rip), %rax    # 0x36c1b0
movsd %xmm0, (%rax)
leaq 0x23fe8f(%rip), %rax    # 0x36c230
movsd (%rax), %xmm1
movsd 0x42dd3(%rip), %xmm0    # 0x16f180
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
subsd %xmm1, %xmm0
leaq 0x23fdf9(%rip), %rax    # 0x36c1b8
movsd %xmm0, (%rax)
leaq 0x23fe6e(%rip), %rax    # 0x36c238
movsd (%rax), %xmm0
leaq 0x23fdeb(%rip), %rax    # 0x36c1c0
movsd %xmm0, (%rax)
leaq 0x26e110(%rip), %rax    # 0x39a4f0
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x26e10a(%rip), %rax    # 0x39a4f8
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x23fe68(%rip), %rax    # 0x36c264
movl $0x1, (%rax)
jmp 0x12c53e
leaq 0x23fda2(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x12c41f
jp 0x12c41f
jmp 0x12c435
leaq 0x23fd92(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x12c43a
jp 0x12c43a
jmp 0x12c8ab
leaq 0x26e053(%rip), %rax    # 0x39a494
cmpl $0x0, (%rax)
je 0x12c52f
leaq 0x240053(%rip), %rax    # 0x36c4a4
cmpl $0x0, (%rax)
je 0x12c52f
xorl %edi, %edi
callq 0x15b350
movsd %xmm0, -0x80(%rbp)
leaq 0x26e05b(%rip), %rax    # 0x39a4c8
cmpl $0x2, (%rax)
jae 0x12c486
movsd -0x80(%rbp), %xmm0
leaq 0x26e01a(%rip), %rax    # 0x39a498
ucomisd (%rax), %xmm0
jne 0x12c49c
jp 0x12c49c
movsd -0x80(%rbp), %xmm0
leaq 0x26e006(%rip), %rax    # 0x39a498
ucomisd (%rax), %xmm0
jbe 0x12c52d
leaq 0x26dff1(%rip), %rax    # 0x39a494
movl $0x1, (%rax)
callq 0x15b5d0
leaq 0x26dff7(%rip), %rax    # 0x39a4ac
cmpl $0x0, (%rax)
je 0x12c4bc
jmp 0x12c4c3
xorl %edi, %edi
callq 0x15b8f0
leaq 0x14b55a(%rip), %rax    # 0x277a24
movl $0x10e1, (%rax)         # imm = 0x10E1
leaq 0x26e019(%rip), %rax    # 0x39a4f0
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x26e011(%rip), %rax    # 0x39a4f8
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x23fcc9(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x23fca1(%rip), %rax    # 0x36c1a8
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
leaq 0x26df59(%rip), %rax    # 0x39a470
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
leaq 0x26dff9(%rip), %rax    # 0x39a520
movl $0x3, (%rax)
jmp 0x12c52f
leaq 0x23fd2e(%rip), %rax    # 0x36c264
movl $0x0, (%rax)
jmp 0x12c53e
leaq 0x26dfab(%rip), %rax    # 0x39a4f0
movsd (%rax), %xmm0
leaq 0x23fc60(%rip), %rax    # 0x36c1b0
subsd (%rax), %xmm0
movsd 0x42c24(%rip), %xmm1    # 0x16f180
mulsd %xmm1, %xmm0
leaq 0x23fc31(%rip), %rax    # 0x36c198
divsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0x23fc41(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
leaq 0x26df76(%rip), %rax    # 0x39a4f8
subsd (%rax), %xmm0
movsd 0x42bf2(%rip), %xmm1    # 0x16f180
mulsd %xmm1, %xmm0
leaq 0x23fbff(%rip), %rax    # 0x36c198
divsd (%rax), %xmm0
leaq 0x23fc04(%rip), %rax    # 0x36c1a8
mulsd (%rax), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x42b0b(%rip), %xmm0    # 0x16f0c0
leaq 0x26deb4(%rip), %rax    # 0x39a470
mulsd (%rax), %xmm0
movsd 0x42b88(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x12c5e6
jp 0x12c5e6
jmp 0x12c93b
movsd -0x10(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x12c5fc
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12c644
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x18(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x12c65a
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12c6a2
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
leaq 0x26ddd6(%rip), %rax    # 0x39a484
cvtsi2sdl (%rax), %xmm1
movsd 0x42a96(%rip), %xmm2    # 0x16f150
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
leaq 0x26ddac(%rip), %rax    # 0x39a484
cvtsi2sdl (%rax), %xmm1
movsd 0x42a6c(%rip), %xmm2    # 0x16f150
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x26dd8f(%rip), %rax    # 0x39a48c
movl (%rax), %eax
movl %eax, -0x88(%rbp)
leaq 0x26dd6c(%rip), %rax    # 0x39a478
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x88(%rbp), %eax
addl %ecx, %eax
subl $0x1, %eax
cvttsd2si -0x20(%rbp), %ecx
addl %ecx, %eax
movl %eax, 0x2ac888(%rip)    # 0x3d8fb8
leaq 0x26dd51(%rip), %rax    # 0x39a488
movl (%rax), %eax
movl %eax, -0x84(%rbp)
leaq 0x26dd32(%rip), %rax    # 0x39a478
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x84(%rbp), %eax
addl %ecx, %eax
subl $0x1, %eax
cvttsd2si -0x28(%rbp), %ecx
addl %ecx, %eax
movl %eax, 0x2ac852(%rip)    # 0x3d8fbc
cmpl $0x0, -0x4(%rbp)
je 0x12c787
movl 0x2ac842(%rip), %edi    # 0x3d8fb8
movl 0x2ac840(%rip), %esi    # 0x3d8fbc
movl -0x8(%rbp), %eax
movzbl %al, %edx
callq 0x10d70
leaq 0x26dd3a(%rip), %rax    # 0x39a4c8
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x26dd2e(%rip), %rax    # 0x39a4c8
movl %ecx, (%rax)
leaq 0x26dd25(%rip), %rax    # 0x39a4c8
movl (%rax), %eax
movl $0xe10, %ecx            # imm = 0xE10
xorl %edx, %edx
divl %ecx
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl $0xc, %ecx
cltd
idivl %ecx
addl $0x3, %edx
movl %edx, -0x8(%rbp)
leaq 0x26dcbb(%rip), %rax    # 0x39a484
cvtsi2sdl (%rax), %xmm0
movsd 0x4297b(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x26dc9a(%rip), %rax    # 0x39a484
cvtsi2sdl (%rax), %xmm0
movsd 0x4295a(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x56604(%rip), %xmm0    # 0x182e10
mulsd -0x20(%rbp), %xmm0
leaq 0x26dc6c(%rip), %rax    # 0x39a484
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd 0x565e3(%rip), %xmm0    # 0x182e10
mulsd -0x28(%rbp), %xmm0
leaq 0x26dc4b(%rip), %rax    # 0x39a484
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x12c8a9
movsd 0x565b4(%rip), %xmm0    # 0x182e10
ucomisd -0x20(%rbp), %xmm0
jbe 0x12c8a9
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x12c8a9
movsd 0x56597(%rip), %xmm0    # 0x182e10
ucomisd -0x28(%rbp), %xmm0
jbe 0x12c8a9
movl -0x8(%rbp), %eax
movb %al, %dl
cvttsd2si -0x20(%rbp), %eax
movslq %eax, %rcx
leaq 0xe6bdc(%rip), %rax     # 0x213470
imulq $0x281, %rcx, %rcx      # imm = 0x281
addq %rcx, %rax
cvttsd2si -0x28(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x12c8ab
movsd -0x38(%rbp), %xmm0
leaq 0x23f8f9(%rip), %rax    # 0x36c1b0
movsd %xmm0, (%rax)
movsd -0x40(%rbp), %xmm0
leaq 0x23f8f1(%rip), %rax    # 0x36c1b8
movsd %xmm0, (%rax)
movsd -0x48(%rbp), %xmm0
leaq 0x23f8e9(%rip), %rax    # 0x36c1c0
movsd %xmm0, (%rax)
movsd -0x50(%rbp), %xmm0
leaq 0x26dc09(%rip), %rax    # 0x39a4f0
movsd %xmm0, (%rax)
movsd -0x58(%rbp), %xmm0
leaq 0x26dc01(%rip), %rax    # 0x39a4f8
movsd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm0
leaq 0x26dbf9(%rip), %rax    # 0x39a500
movsd %xmm0, (%rax)
movsd -0x68(%rbp), %xmm0
leaq 0x26db59(%rip), %rax    # 0x39a470
movsd %xmm0, (%rax)
movsd -0x70(%rbp), %xmm0
leaq 0x23f871(%rip), %rax    # 0x36c198
movsd %xmm0, (%rax)
movsd -0x78(%rbp), %xmm0
leaq 0x23f871(%rip), %rax    # 0x36c1a8
movsd %xmm0, (%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)