// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: find_cursor_sat()
void find_cursor_sat()
{
int prn;
int close_prn;
double close_dist;
double dist;
double dx, dy;
double az, el;
char az_dir;
char el_dir;

   // show info of the satellite the mouse cursor is over in the sat map

   if(drawn_sats == 1) sprintf(out, "%d Satellite Position ", drawn_sats);
   else if(drawn_sats) sprintf(out, "%d Satellite Positions ", drawn_sats);
   else                sprintf(out, "Satellite Positions ");

   if(map_r == 0) return;

   if(mouse_x < map_x-map_r) return;
   if(mouse_x > map_x+map_r) return;
   if(mouse_y < map_y-map_r) return;
   if(mouse_y > map_y+map_r) return;

   close_prn = 0;
   close_dist = 1E10;
   for(prn=1; prn<=MOON_PRN; prn++) {
//if(prn == SUN_PRN) ;
//else if(prn == MOON_PRN) ;
      if(sat[prn].level_msg == 0) continue;

      if(mouse_x < sat[prn].plot_x - sat[prn].plot_r) continue;
      if(mouse_x > sat[prn].plot_x + sat[prn].plot_r) continue;
      if(mouse_y < sat[prn].plot_y - sat[prn].plot_r) continue;
      if(mouse_y > sat[prn].plot_y + sat[prn].plot_r) continue;

      dx = (double) (sat[prn].plot_x - mouse_x);
      dy = (double) (sat[prn].plot_y - mouse_y);
      dist = sqrt(dx*dx + dy*dy);
      if(dist < close_dist) {
         close_dist = dist;
         close_prn = prn;
      }
   }

   if(close_prn) {  // show info of the sat at the mouse cursor
      az_dir = (char) sat[close_prn].az_dir;
      if(az_dir == 0) az_dir = ' ';
      else if(sat[close_prn].azimuth == 0.0F) az_dir = ' ';
      el_dir = (char) sat[close_prn].el_dir;
      if(el_dir == 0) el_dir = ' ';
      else if(sat[close_prn].elevation == 0.0F) el_dir = ' ';

      if(close_prn == SUN_PRN) {
         if(sat[close_prn].elevation >= 0) cursor_sat_color = YELLOW;
         else                              cursor_sat_color = GREY;
         sprintf(out, "SUN: az:%.2f%c el:%.2f%c", sat[close_prn].azimuth,az_dir,  sat[close_prn].elevation,el_dir);
      }
      else if(close_prn == MOON_PRN) {
         if(sat[close_prn].elevation >= 0) cursor_sat_color = YELLOW;
         else                              cursor_sat_color = GREY;
         sprintf(out, "MOON: az:%.0f%c el:%.0f%c phase:%.0f%%", sat[close_prn].azimuth,az_dir, sat[close_prn].elevation,el_dir,MoonPhase*100.0);
      }
      else {
         if     (sat[close_prn].disabled)         cursor_sat_color = BLUE;
         else if(sat[close_prn].health_flag == 1) cursor_sat_color = RED;
         else if(sat[close_prn].tracking <= 0)    cursor_sat_color = YELLOW;
         else                                     cursor_sat_color = GREEN;
         sprintf(out, "%s:%d az:%.0f%c el:%.0f%c sig:%.0f", gnss_id(close_prn),close_prn, sat[close_prn].azimuth,az_dir, sat[close_prn].elevation,el_dir,sat[close_prn].sig_level);
      }
//    cursor_sat_color = sat[close_prn].plot_color;
//    center_sat = 0;
   }
   else {   // show az/el at the mouse cursor
      dx = mouse_x - AZEL_X;
      dy = mouse_y - AZEL_Y;
      az = 90.0 + atan2(dy,dx) * 180.0/PI;
      if(az < 0.0) az += 360.0;
      else if(az >= 360.0) az -= 360.0;

      el = sqrt(dx*dx+dy*dy) / AZEL_RADIUS;
      el = 90.0 - (90.0 * el);
      if(el >= 0.0) {
         sprintf(out, "az:%.0f  el:%.0f", az,el);
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
leaq 0x145eba(%rip), %rax    # 0x23ef08
movl (%rax), %edx
testl %edx, %edx
je 0xf906e
leaq 0x2431c5(%rip), %rdi    # 0x33c220
cmpl $0x1, %edx
jne 0xf9091
leaq 0x3bfae(%rip), %rsi     # 0x135015
movl $0x1, %edx
jmp 0xf9098
movupd 0x3bfb9(%rip), %xmm0    # 0x13502f
leaq 0x2431a3(%rip), %rax    # 0x33c220
movapd %xmm0, (%rax)
movabsq $0x20736e6f697469, %rcx # imm = 0x20736E6F697469
movq %rcx, 0xd(%rax)
jmp 0xf909f
leaq 0x3bf94(%rip), %rsi     # 0x13502c
xorl %eax, %eax
callq 0x9060
leaq 0x24230e(%rip), %rax    # 0x33b3b4
movl (%rax), %edx
testl %edx, %edx
je 0xf90fc
leaq 0x12218d(%rip), %rax    # 0x21b240
movl (%rax), %eax
leaq 0x2422f0(%rip), %rcx    # 0x33b3ac
movl (%rcx), %ecx
movl %ecx, %esi
subl %edx, %esi
cmpl %esi, %eax
setl %sil
addl %edx, %ecx
cmpl %ecx, %eax
setg %cl
orb %sil, %cl
jne 0xf90fc
leaq 0x122169(%rip), %rcx    # 0x21b244
movl (%rcx), %ecx
leaq 0x2422cc(%rip), %rsi    # 0x33b3b0
movl (%rsi), %esi
movl %esi, %edi
subl %edx, %edi
cmpl %edi, %ecx
setl %dil
addl %edx, %esi
cmpl %esi, %ecx
setg %dl
orb %dil, %dl
je 0xf9109
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
movsd 0x25905(%rip), %xmm0    # 0x11ea18
movl $0x578, %esi            # imm = 0x578
movl $0x1, %edi
leaq 0x145e8c(%rip), %rdx    # 0x23efb0
cmpl $0x0, -0x214(%rdx,%rsi)
je 0xf91a7
movl -0x8(%rdx,%rsi), %r8d
movl (%rdx,%rsi), %r9d
movl %r8d, %r10d
subl %r9d, %r10d
cmpl %r10d, %eax
setl %r10b
leal (%r9,%r8), %r11d
cmpl %r11d, %eax
setg %r11b
orb %r10b, %r11b
jne 0xf91a7
movl -0x4(%rdx,%rsi), %r10d
movl %r10d, %r11d
subl %r9d, %r11d
cmpl %r11d, %ecx
setl %r11b
addl %r10d, %r9d
cmpl %r9d, %ecx
setg %r9b
orb %r11b, %r9b
jne 0xf91a7
subl %eax, %r8d
xorps %xmm1, %xmm1
cvtsi2sd %r8d, %xmm1
subl %ecx, %r10d
xorps %xmm2, %xmm2
cvtsi2sd %r10d, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xf91a7
movl %edi, %ebx
movapd %xmm1, %xmm0
addq $0x348, %rsi            # imm = 0x348
incl %edi
cmpq $0xcda00, %rsi          # imm = 0xCDA00
jne 0xf9124
testl %ebx, %ebx
je 0xf9291
movslq %ebx, %rax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq (%rdx,%rax), %r14
movb 0x211(%rdx,%rax), %al
movb $0x20, %r15b
testb %al, %al
je 0xf91fb
movss 0x208(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movl %eax, %r15d
jne 0xf91fb
jp 0xf91fb
movb $0x20, %r15b
movb 0x210(%r14), %r12b
testb %r12b, %r12b
je 0xf921b
movss 0x20c(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xf921e
jp 0xf921e
movb $0x20, %r12b
cmpl $0x3e9, %ebx            # imm = 0x3E9
je 0xf92f7
cmpl $0x3e8, %ebx            # imm = 0x3E8
jne 0xf9365
movss 0x20c(%r14), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
movl $0x8, %eax
movl $0xe, %ecx
cmovbl %eax, %ecx
movl %ecx, 0x358ad4(%rip)    # 0x451d2c
xorps %xmm0, %xmm0
cvtss2sd 0x208(%r14), %xmm0
movsbl %r15b, %edx
cvtss2sd %xmm1, %xmm1
movsbl %r12b, %ecx
leaq 0x242fa9(%rip), %rdi    # 0x33c220
leaq 0x3bdc6(%rip), %rsi     # 0x135044
movb $0x2, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060
leaq 0x242108(%rip), %rdx    # 0x33b3a0
movl (%rdx), %edx
subl %edx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
leaq 0x2420fa(%rip), %rax    # 0x33b3a4
movl (%rax), %eax
subl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
callq 0x9050
mulsd 0x12564(%rip), %xmm0    # 0x10b830
divsd 0x12554(%rip), %xmm0    # 0x10b828
addsd 0x1263c(%rip), %xmm0    # 0x10b918
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0xf93ec
addsd 0x24e46(%rip), %xmm0    # 0x11e138
jmp 0xf93fe
movss 0x20c(%r14), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
movl $0x8, %eax
movl $0xe, %ecx
cmovbl %eax, %ecx
movl %ecx, 0x358a13(%rip)    # 0x451d2c
xorps %xmm0, %xmm0
cvtss2sd 0x208(%r14), %xmm0
movsbl %r15b, %edx
cvtss2sd %xmm1, %xmm1
movsbl %r12b, %ecx
leaq 0x214508(%rip), %rax    # 0x30d840
movsd (%rax), %xmm2
mulsd 0xfd1c(%rip), %xmm2     # 0x109060
leaq 0x242ed5(%rip), %rdi    # 0x33c220
leaq 0x3bd0b(%rip), %rsi     # 0x13505d
movb $0x3, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060
movl $0x9, %eax
cmpb $0x0, 0x1(%r14)
jne 0xf9390
movl $0xc, %eax
cmpb $0x1, (%r14)
je 0xf9390
xorl %eax, %eax
cmpl $0x0, 0x218(%r14)
setle %al
leal 0xa(,%rax,4), %eax
movl %eax, 0x358996(%rip)    # 0x451d2c
movl %ebx, %edi
callq 0xdc25a
xorps %xmm0, %xmm0
cvtss2sd 0x208(%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x20c(%r14), %xmm1
movsbl %r15b, %r8d
movsbl %r12b, %r9d
xorps %xmm2, %xmm2
cvtss2sd 0x20(%r14), %xmm2
leaq 0x242e53(%rip), %rdi    # 0x33c220
leaq 0x3bcb0(%rip), %rsi     # 0x135084
movq %rax, %rdx
movl %ebx, %ecx
movb $0x3, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060
ucomisd 0x24d44(%rip), %xmm0    # 0x11e138
jb 0xf93fe
addsd 0x326ca(%rip), %xmm0    # 0x12bac8
movsd -0x28(%rbp), %xmm2
mulsd %xmm2, %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
leaq 0x241f71(%rip), %rax    # 0x33b38c
movl (%rax), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
leaq 0x241f6b(%rip), %rax    # 0x33b398
subl (%rax), %ecx
sqrtsd %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
divsd %xmm2, %xmm1
mulsd 0x332fa(%rip), %xmm1    # 0x12c740
addsd 0x124ca(%rip), %xmm1    # 0x10b918
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jb 0xf90fc
leaq 0x242dbd(%rip), %rdi    # 0x33c220
leaq 0x3bc3d(%rip), %rsi     # 0x1350a7
movb $0x2, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060