// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x146642(%rip), %rax    # 0x23ef08
movl (%rax), %edx
testl %edx, %edx
je 0xf88e6
leaq 0x24394d(%rip), %rdi    # 0x33c220
cmpl $0x1, %edx
jne 0xf8909
leaq 0x3c646(%rip), %rsi     # 0x134f25
movl $0x1, %edx
jmp 0xf8910
movupd 0x3c651(%rip), %xmm0    # 0x134f3f
leaq 0x24392b(%rip), %rax    # 0x33c220
movapd %xmm0, (%rax)
movabsq $0x20736e6f697469, %rcx # imm = 0x20736E6F697469
movq %rcx, 0xd(%rax)
jmp 0xf8917
leaq 0x3c62c(%rip), %rsi     # 0x134f3c
xorl %eax, %eax
callq 0x9060
leaq 0x242a96(%rip), %rax    # 0x33b3b4
movl (%rax), %eax
testl %eax, %eax
je 0xf8976
leaq 0x122915(%rip), %r14    # 0x21b240
movl (%r14), %ecx
leaq 0x242a77(%rip), %rdx    # 0x33b3ac
movl (%rdx), %edx
movl %edx, %esi
subl %eax, %esi
cmpl %esi, %ecx
setl %sil
addl %eax, %edx
cmpl %edx, %ecx
setg %cl
orb %sil, %cl
jne 0xf8976
leaq 0x1228f0(%rip), %r15    # 0x21b244
movl (%r15), %ecx
leaq 0x242a52(%rip), %rdx    # 0x33b3b0
movl (%rdx), %edx
movl %edx, %esi
subl %eax, %esi
cmpl %esi, %ecx
setl %sil
addl %eax, %edx
cmpl %edx, %ecx
setg %al
orb %sil, %al
je 0xf8985
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, -0x38(%rbp)
movsd 0x25fd4(%rip), %xmm2    # 0x11e968
movl $0x578, %r13d           # imm = 0x578
movl $0x1, %ebx
leaq 0x14660a(%rip), %r12    # 0x23efb0
xorpd %xmm3, %xmm3
cmpl $0x0, -0x214(%r12,%r13)
je 0xf8a48
movl (%r14), %eax
movl -0x8(%r12,%r13), %ecx
movl (%r12,%r13), %edx
movl %ecx, %esi
subl %edx, %esi
cmpl %esi, %eax
setl %sil
leal (%rdx,%rcx), %edi
cmpl %edi, %eax
setg %dil
orb %sil, %dil
jne 0xf8a48
movl (%r15), %esi
movl -0x4(%r12,%r13), %edi
movl %edi, %r8d
subl %edx, %r8d
cmpl %r8d, %esi
setl %r8b
addl %edi, %edx
cmpl %edx, %esi
setg %dl
orb %r8b, %dl
jne 0xf8a48
subl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
subl %esi, %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm3, %xmm0
jb 0xf8a28
sqrtsd %xmm0, %xmm0
jmp 0xf8a3b
movsd %xmm2, -0x30(%rbp)
callq 0x9270
xorpd %xmm3, %xmm3
movsd -0x30(%rbp), %xmm2
ucomisd %xmm0, %xmm2
jbe 0xf8a48
movl %ebx, -0x38(%rbp)
movapd %xmm0, %xmm2
addq $0x348, %r13            # imm = 0x348
incl %ebx
cmpq $0xcda00, %r13          # imm = 0xCDA00
jne 0xf89aa
movl -0x38(%rbp), %r13d
testl %r13d, %r13d
je 0xf8b38
movslq %r13d, %rax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq (%r12,%rax), %rbx
movb 0x211(%r12,%rax), %al
movb $0x20, %r14b
testb %al, %al
je 0xf8aa1
movss 0x208(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movl %eax, %r14d
jne 0xf8aa1
jp 0xf8aa1
movb $0x20, %r14b
movb 0x210(%rbx), %r15b
testb %r15b, %r15b
je 0xf8ac0
movss 0x20c(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xf8ac3
jp 0xf8ac3
movb $0x20, %r15b
cmpl $0x3e9, %r13d           # imm = 0x3E9
je 0xf8ba4
cmpl $0x3e8, %r13d           # imm = 0x3E8
jne 0xf8c12
movss 0x20c(%rbx), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
movl $0x8, %eax
movl $0xe, %ecx
cmovbl %eax, %ecx
movl %ecx, 0x35930e(%rip)    # 0x451e0c
xorps %xmm0, %xmm0
cvtss2sd 0x208(%rbx), %xmm0
movsbl %r14b, %edx
cvtss2sd %xmm1, %xmm1
movsbl %r15b, %ecx
leaq 0x243704(%rip), %rdi    # 0x33c220
leaq 0x3c431(%rip), %rsi     # 0x134f54
movb $0x2, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9060
movl (%r14), %eax
leaq 0x24285e(%rip), %rcx    # 0x33b3a0
subl (%rcx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl (%r15), %eax
leaq 0x24284f(%rip), %rcx    # 0x33b3a4
subl (%rcx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd %xmm1, -0x30(%rbp)
callq 0x9050
movapd %xmm0, %xmm2
mulsd 0x12ca7(%rip), %xmm2    # 0x10b820
divsd 0x12c97(%rip), %xmm2    # 0x10b818
addsd 0x12d87(%rip), %xmm2    # 0x10b910
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
jbe 0xf8c97
addsd 0x254f1(%rip), %xmm2    # 0x11e090
jmp 0xf8ca9
movss 0x20c(%rbx), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
movl $0x8, %eax
movl $0xe, %ecx
cmovbl %eax, %ecx
movl %ecx, 0x359247(%rip)    # 0x451e0c
xorps %xmm0, %xmm0
cvtss2sd 0x208(%rbx), %xmm0
movsbl %r14b, %edx
cvtss2sd %xmm1, %xmm1
movsbl %r15b, %ecx
leaq 0x214c5d(%rip), %rax    # 0x30d840
movsd (%rax), %xmm2
mulsd 0x10471(%rip), %xmm2    # 0x109060
leaq 0x24362a(%rip), %rdi    # 0x33c220
leaq 0x3c370(%rip), %rsi     # 0x134f6d
movb $0x3, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9060
movl $0x9, %eax
cmpb $0x0, 0x1(%rbx)
jne 0xf8c3a
movl $0xc, %eax
cmpb $0x1, (%rbx)
je 0xf8c3a
xorl %eax, %eax
cmpl $0x0, 0x218(%rbx)
setle %al
leal 0xa(,%rax,4), %eax
movl %eax, 0x3591cc(%rip)    # 0x451e0c
movl %r13d, %edi
callq 0xdbbf1
xorps %xmm0, %xmm0
cvtss2sd 0x208(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x20c(%rbx), %xmm1
movsbl %r14b, %r8d
movsbl %r15b, %r9d
xorps %xmm2, %xmm2
cvtss2sd 0x20(%rbx), %xmm2
leaq 0x2435ab(%rip), %rdi    # 0x33c220
leaq 0x3c318(%rip), %rsi     # 0x134f94
movq %rax, %rdx
movl %r13d, %ecx
movb $0x3, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9060
ucomisd 0x253f1(%rip), %xmm2    # 0x11e090
jb 0xf8ca9
addsd 0x32d3f(%rip), %xmm2    # 0x12b9e8
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
jb 0xf8cd2
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0xf8ce9
movsd %xmm2, -0x30(%rbp)
callq 0x9270
xorpd %xmm3, %xmm3
movsd -0x30(%rbp), %xmm2
movapd %xmm0, %xmm1
leaq 0x24269c(%rip), %rax    # 0x33b38c
movl (%rax), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
leaq 0x242696(%rip), %rax    # 0x33b398
subl (%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm1
mulsd 0x12c79(%rip), %xmm1    # 0x10b990
addsd 0x12bf1(%rip), %xmm1    # 0x10b910
ucomisd %xmm3, %xmm1
jb 0xf8976
leaq 0x2434f0(%rip), %rdi    # 0x33c220
leaq 0x3c280(%rip), %rsi     # 0x134fb7
movapd %xmm2, %xmm0
movb $0x2, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9060