// File: /workspace/github_cpp_makefile_star2_O2/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 0x14576d(%rip), %rax    # 0x228f08
movl (%rax), %edx
testl %edx, %edx
je 0xe37b9
leaq 0x242a78(%rip), %rdi    # 0x326220
cmpl $0x1, %edx
jne 0xe37dc
leaq 0x3b781(%rip), %rsi     # 0x11ef35
pushq $0x1
popq %rdx
jmp 0xe37e3
movupd 0x3b78e(%rip), %xmm0    # 0x11ef4f
leaq 0x242a58(%rip), %rax    # 0x326220
movapd %xmm0, (%rax)
movabsq $0x20736e6f697469, %rcx # imm = 0x20736E6F697469
movq %rcx, 0xd(%rax)
jmp 0xe37ea
leaq 0x3b769(%rip), %rsi     # 0x11ef4c
xorl %eax, %eax
callq 0x9060
leaq 0x241bc3(%rip), %rax    # 0x3253b4
movl (%rax), %edx
testl %edx, %edx
je 0xe3847
leaq 0x121a42(%rip), %rax    # 0x205240
movl (%rax), %eax
leaq 0x241ba5(%rip), %rcx    # 0x3253ac
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 0xe3847
leaq 0x121a1e(%rip), %rcx    # 0x205244
movl (%rcx), %ecx
leaq 0x241b81(%rip), %rsi    # 0x3253b0
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 0xe3854
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rsi
movsd 0x25131(%rip), %xmm0    # 0x108990
xorl %ebx, %ebx
movl $0x578, %edi            # imm = 0x578
leaq 0x145743(%rip), %rdx    # 0x228fb0
cmpq $0xcda00, %rdi          # imm = 0xCDA00
je 0xe3905
cmpl $0x0, -0x214(%rdx,%rdi)
je 0xe38f7
movl -0x8(%rdx,%rdi), %r8d
movl (%rdx,%rdi), %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 0xe38f7
movl -0x4(%rdx,%rdi), %r10d
movl %r10d, %r11d
subl %r9d, %r11d
cmpl %r11d, %ecx
setl %r11b
addl %r10d, %r9d
cmpl %r9d, %ecx
setg %r9b
orb %r11b, %r9b
jne 0xe38f7
subl %eax, %r8d
cvtsi2sd %r8d, %xmm1
subl %ecx, %r10d
cvtsi2sd %r10d, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xe38f7
movl %esi, %ebx
movapd %xmm1, %xmm0
addq $0x348, %rdi            # imm = 0x348
incl %esi
jmp 0xe386d
testl %ebx, %ebx
je 0xe39d2
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 0xe3943
movss 0x208(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movl %eax, %r15d
jne 0xe3943
jp 0xe3943
movb $0x20, %r15b
movb 0x210(%r14), %r12b
testb %r12b, %r12b
je 0xe3963
movss 0x20c(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xe3966
jp 0xe3966
movb $0x20, %r12b
cmpl $0x3e9, %ebx            # imm = 0x3E9
je 0xe3a32
cmpl $0x3e8, %ebx            # imm = 0x3E8
jne 0xe3a99
movss 0x20c(%r14), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
pushq $0x8
popq %rax
pushq $0xe
popq %rcx
cmovbl %eax, %ecx
movl %ecx, 0x358390(%rip)    # 0x43bd2c
cvtss2sd 0x208(%r14), %xmm0
movsbl %r15b, %edx
cvtss2sd %xmm1, %xmm1
movsbl %r12b, %ecx
leaq 0x242868(%rip), %rdi    # 0x326220
leaq 0x3b5a5(%rip), %rsi     # 0x11ef64
movb $0x2, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060
leaq 0x2419c7(%rip), %rdx    # 0x3253a0
movl (%rdx), %edx
subl %edx, %eax
cvtsi2sd %eax, %xmm1
leaq 0x2419bc(%rip), %rax    # 0x3253a4
movl (%rax), %eax
subl %eax, %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
callq 0x9050
mulsd 0x11ea1(%rip), %xmm0    # 0xf58a8
divsd 0x11e91(%rip), %xmm0    # 0xf58a0
addsd 0x11f79(%rip), %xmm0    # 0xf5990
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0xe3aab
addsd 0x24783(%rip), %xmm0    # 0x1081b0
jmp 0xe3abd
movss 0x20c(%r14), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
pushq $0x8
popq %rax
pushq $0xe
popq %rcx
cmovbl %eax, %ecx
movl %ecx, 0x3582dc(%rip)    # 0x43bd2c
cvtss2sd 0x208(%r14), %xmm0
movsbl %r15b, %edx
cvtss2sd %xmm1, %xmm1
movsbl %r12b, %ecx
leaq 0x213dd4(%rip), %rax    # 0x2f7840
movsd (%rax), %xmm2
mulsd 0xf5e8(%rip), %xmm2     # 0xf3060
leaq 0x2427a1(%rip), %rdi    # 0x326220
leaq 0x3b4f7(%rip), %rsi     # 0x11ef7d
movb $0x3, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060
cmpb $0x0, 0x1(%r14)
je 0xe3b36
pushq $0x9
jmp 0xe3b3e
ucomisd 0x246fd(%rip), %xmm0    # 0x1081b0
jb 0xe3abd
addsd 0x31f4b(%rip), %xmm0    # 0x115a08
movsd -0x28(%rbp), %xmm2
mulsd %xmm2, %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
leaq 0x2418b2(%rip), %rax    # 0x32538c
movl (%rax), %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
leaq 0x2418af(%rip), %rcx    # 0x325398
subl (%rcx), %eax
sqrtsd %xmm1, %xmm1
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
mulsd 0x32b61(%rip), %xmm1    # 0x116660
addsd 0x11e89(%rip), %xmm1    # 0xf5990
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jb 0xe3847
leaq 0x242704(%rip), %rdi    # 0x326220
leaq 0x3b4a4(%rip), %rsi     # 0x11efc7
movb $0x2, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060
cmpb $0x1, (%r14)
jne 0xe3b92
pushq $0xc
popq %rax
movl %eax, 0x3581e7(%rip)    # 0x43bd2c
movl %ebx, %edi
callq 0xca553
cvtss2sd 0x208(%r14), %xmm0
cvtss2sd 0x20c(%r14), %xmm1
movsbl %r15b, %r8d
movsbl %r12b, %r9d
cvtss2sd 0x20(%r14), %xmm2
leaq 0x2426ad(%rip), %rdi    # 0x326220
leaq 0x3b42a(%rip), %rsi     # 0x11efa4
movq %rax, %rdx
movl %ebx, %ecx
movb $0x3, %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9060
xorl %eax, %eax
cmpl $0x0, 0x218(%r14)
setle %al
leal 0xa(,%rax,4), %eax
jmp 0xe3b3f