// File: 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
subq $0x40, %rsp
leaq 0x147399(%rip), %rax    # 0x29e0e8
cmpl $0x1, (%rax)
jne 0x156d74
leaq 0x14738d(%rip), %rax    # 0x29e0e8
movl (%rax), %edx
leaq 0x24469c(%rip), %rdi    # 0x39b400
leaq 0x40e3c(%rip), %rsi     # 0x197ba7
movb $0x0, %al
callq 0x9060
jmp 0x156db7
leaq 0x14736d(%rip), %rax    # 0x29e0e8
cmpl $0x0, (%rax)
je 0x156da0
leaq 0x147361(%rip), %rax    # 0x29e0e8
movl (%rax), %edx
leaq 0x244670(%rip), %rdi    # 0x39b400
leaq 0x40e27(%rip), %rsi     # 0x197bbe
movb $0x0, %al
callq 0x9060
jmp 0x156db5
leaq 0x244659(%rip), %rdi    # 0x39b400
leaq 0x40e13(%rip), %rsi     # 0x197bc1
movb $0x0, %al
callq 0x9060
jmp 0x156db7
leaq 0x2437d6(%rip), %rax    # 0x39a594
cmpl $0x0, (%rax)
jne 0x156dc8
jmp 0x157508
leaq 0x123651(%rip), %rax    # 0x27a420
movl (%rax), %eax
leaq 0x2437b4(%rip), %rcx    # 0x39a58c
movl (%rcx), %ecx
leaq 0x2437b3(%rip), %rdx    # 0x39a594
subl (%rdx), %ecx
cmpl %ecx, %eax
jge 0x156dec
jmp 0x157508
leaq 0x12362d(%rip), %rax    # 0x27a420
movl (%rax), %eax
leaq 0x243790(%rip), %rcx    # 0x39a58c
movl (%rcx), %ecx
leaq 0x24378f(%rip), %rdx    # 0x39a594
addl (%rdx), %ecx
cmpl %ecx, %eax
jle 0x156e10
jmp 0x157508
leaq 0x12360d(%rip), %rax    # 0x27a424
movl (%rax), %eax
leaq 0x243770(%rip), %rcx    # 0x39a590
movl (%rcx), %ecx
leaq 0x24376b(%rip), %rdx    # 0x39a594
subl (%rdx), %ecx
cmpl %ecx, %eax
jge 0x156e34
jmp 0x157508
leaq 0x1235e9(%rip), %rax    # 0x27a424
movl (%rax), %eax
leaq 0x24374c(%rip), %rcx    # 0x39a590
movl (%rcx), %ecx
leaq 0x243747(%rip), %rdx    # 0x39a594
addl (%rdx), %ecx
cmpl %ecx, %eax
jle 0x156e58
jmp 0x157508
movl $0x0, -0x8(%rbp)
movsd 0x2c481(%rip), %xmm0    # 0x1832e8
movsd %xmm0, -0x10(%rbp)
movl $0x1, -0x4(%rbp)
cmpl $0x3e9, -0x4(%rbp)      # imm = 0x3E9
jg 0x157070
movslq -0x4(%rbp), %rcx
leaq 0x147305(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jne 0x156ea0
jmp 0x157062
leaq 0x123579(%rip), %rax    # 0x27a420
movl (%rax), %eax
movslq -0x4(%rbp), %rdx
leaq 0x1472dc(%rip), %rcx    # 0x29e190
imulq $0x348, %rdx, %rdx      # imm = 0x348
addq %rdx, %rcx
movl 0x228(%rcx), %ecx
movslq -0x4(%rbp), %rsi
leaq 0x1472c1(%rip), %rdx    # 0x29e190
imulq $0x348, %rsi, %rsi      # imm = 0x348
addq %rsi, %rdx
subl 0x230(%rdx), %ecx
cmpl %ecx, %eax
jge 0x156ee8
jmp 0x157062
leaq 0x123531(%rip), %rax    # 0x27a420
movl (%rax), %eax
movslq -0x4(%rbp), %rdx
leaq 0x147294(%rip), %rcx    # 0x29e190
imulq $0x348, %rdx, %rdx      # imm = 0x348
addq %rdx, %rcx
movl 0x228(%rcx), %ecx
movslq -0x4(%rbp), %rsi
leaq 0x147279(%rip), %rdx    # 0x29e190
imulq $0x348, %rsi, %rsi      # imm = 0x348
addq %rsi, %rdx
addl 0x230(%rdx), %ecx
cmpl %ecx, %eax
jle 0x156f30
jmp 0x157062
leaq 0x1234ed(%rip), %rax    # 0x27a424
movl (%rax), %eax
movslq -0x4(%rbp), %rdx
leaq 0x14724c(%rip), %rcx    # 0x29e190
imulq $0x348, %rdx, %rdx      # imm = 0x348
addq %rdx, %rcx
movl 0x22c(%rcx), %ecx
movslq -0x4(%rbp), %rsi
leaq 0x147231(%rip), %rdx    # 0x29e190
imulq $0x348, %rsi, %rsi      # imm = 0x348
addq %rsi, %rdx
subl 0x230(%rdx), %ecx
cmpl %ecx, %eax
jge 0x156f78
jmp 0x157062
leaq 0x1234a5(%rip), %rax    # 0x27a424
movl (%rax), %eax
movslq -0x4(%rbp), %rdx
leaq 0x147204(%rip), %rcx    # 0x29e190
imulq $0x348, %rdx, %rdx      # imm = 0x348
addq %rdx, %rcx
movl 0x22c(%rcx), %ecx
movslq -0x4(%rbp), %rsi
leaq 0x1471e9(%rip), %rdx    # 0x29e190
imulq $0x348, %rsi, %rsi      # imm = 0x348
addq %rsi, %rdx
addl 0x230(%rdx), %ecx
cmpl %ecx, %eax
jle 0x156fc0
jmp 0x157062
movslq -0x4(%rbp), %rcx
leaq 0x1471c5(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl 0x228(%rax), %eax
leaq 0x12343e(%rip), %rcx    # 0x27a420
subl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x20(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x147198(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl 0x22c(%rax), %eax
leaq 0x123415(%rip), %rcx    # 0x27a424
subl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd -0x28(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x9280
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm1
movsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x157060
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x8(%rbp)
jmp 0x157062
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x156e73
cmpl $0x0, -0x8(%rbp)
je 0x1573b5
movslq -0x8(%rbp), %rcx
leaq 0x14710b(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movb 0x211(%rax), %al
movb %al, -0x39(%rbp)
movsbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0x1570a7
movb $0x20, -0x39(%rbp)
jmp 0x1570d4
movslq -0x8(%rbp), %rcx
leaq 0x1470de(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x208(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1570d2
jp 0x1570d2
movb $0x20, -0x39(%rbp)
jmp 0x1570d4
movslq -0x8(%rbp), %rcx
leaq 0x1470b1(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movb 0x210(%rax), %al
movb %al, -0x3a(%rbp)
movsbl -0x3a(%rbp), %eax
cmpl $0x0, %eax
jne 0x157101
movb $0x20, -0x3a(%rbp)
jmp 0x15712e
movslq -0x8(%rbp), %rcx
leaq 0x147084(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x20c(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x15712c
jp 0x15712c
movb $0x20, -0x3a(%rbp)
jmp 0x15712e
cmpl $0x3e8, -0x8(%rbp)      # imm = 0x3E8
jne 0x1571da
movslq -0x8(%rbp), %rcx
leaq 0x14704a(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x20c(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x15716c
movl $0xe, 0x35a1b2(%rip)    # 0x4b131c
jmp 0x157176
movl $0x8, 0x35a1a6(%rip)    # 0x4b131c
movslq -0x8(%rbp), %rcx
leaq 0x14700f(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x208(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsbl -0x39(%rbp), %edx
movslq -0x8(%rbp), %rcx
leaq 0x146fea(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x20c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movsbl -0x3a(%rbp), %ecx
leaq 0x244239(%rip), %rdi    # 0x39b400
leaq 0x40a08(%rip), %rsi     # 0x197bd6
movb $0x2, %al
callq 0x9060
jmp 0x1573b0
cmpl $0x3e9, -0x8(%rbp)      # imm = 0x3E9
jne 0x157299
movslq -0x8(%rbp), %rcx
leaq 0x146f9e(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x20c(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x157218
movl $0xe, 0x35a106(%rip)    # 0x4b131c
jmp 0x157222
movl $0x8, 0x35a0fa(%rip)    # 0x4b131c
movslq -0x8(%rbp), %rcx
leaq 0x146f63(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x208(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsbl -0x39(%rbp), %edx
movslq -0x8(%rbp), %rcx
leaq 0x146f3e(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x20c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movsbl -0x3a(%rbp), %ecx
movsd 0x17ddc(%rip), %xmm2    # 0x16f050
leaq 0x2157a5(%rip), %rax    # 0x36ca20
mulsd (%rax), %xmm2
leaq 0x24417a(%rip), %rdi    # 0x39b400
leaq 0x40962(%rip), %rsi     # 0x197bef
movb $0x3, %al
callq 0x9060
jmp 0x1573ae
movslq -0x8(%rbp), %rcx
leaq 0x146eec(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cmpb $0x0, 0x1(%rax)
je 0x1572c0
movl $0x9, 0x35a05e(%rip)    # 0x4b131c
jmp 0x157321
movslq -0x8(%rbp), %rcx
leaq 0x146ec5(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x1572e9
movl $0xc, 0x35a035(%rip)    # 0x4b131c
jmp 0x15731f
movslq -0x8(%rbp), %rcx
leaq 0x146e9c(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cmpl $0x0, 0x218(%rax)
jg 0x157313
movl $0xe, 0x35a00b(%rip)    # 0x4b131c
jmp 0x15731d
movl $0xa, 0x359fff(%rip)    # 0x4b131c
jmp 0x15731f
jmp 0x157321
movl -0x8(%rbp), %edi
callq 0x12d3c0
movq %rax, %rdx
movl -0x8(%rbp), %ecx
movslq -0x8(%rbp), %rsi
leaq 0x146e56(%rip), %rax    # 0x29e190
imulq $0x348, %rsi, %rsi      # imm = 0x348
addq %rsi, %rax
movss 0x208(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsbl -0x39(%rbp), %r8d
movslq -0x8(%rbp), %rsi
leaq 0x146e30(%rip), %rax    # 0x29e190
imulq $0x348, %rsi, %rsi      # imm = 0x348
addq %rsi, %rax
movss 0x20c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movsbl -0x3a(%rbp), %r9d
movslq -0x8(%rbp), %rsi
leaq 0x146e0a(%rip), %rax    # 0x29e190
imulq $0x348, %rsi, %rsi      # imm = 0x348
addq %rsi, %rax
movss 0x20(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x244060(%rip), %rdi    # 0x39b400
leaq 0x4086f(%rip), %rsi     # 0x197c16
movb $0x3, %al
callq 0x9060
jmp 0x1573b0
jmp 0x157508
leaq 0x123064(%rip), %rax    # 0x27a420
movl (%rax), %eax
leaq 0x2431bb(%rip), %rcx    # 0x39a580
subl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x12304d(%rip), %rax    # 0x27a424
movl (%rax), %eax
leaq 0x2431a4(%rip), %rcx    # 0x39a584
subl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
callq 0x9050
movaps %xmm0, %xmm1
movsd 0x17c73(%rip), %xmm0    # 0x16f078
mulsd %xmm0, %xmm1
movsd 0x1a1b7(%rip), %xmm0    # 0x1715c8
divsd %xmm0, %xmm1
movsd 0x17c6b(%rip), %xmm0    # 0x16f088
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x157444
movsd 0x2b6f8(%rip), %xmm0    # 0x182b30
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x15746f
movsd -0x30(%rbp), %xmm0
movsd 0x2b6df(%rip), %xmm1    # 0x182b30
ucomisd %xmm1, %xmm0
jb 0x15746d
movsd -0x30(%rbp), %xmm0
movsd 0x2b6cc(%rip), %xmm1    # 0x182b30
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x15746f
movsd -0x20(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd -0x28(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x9280
leaq 0x2430d5(%rip), %rax    # 0x39a56c
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
leaq 0x2430d0(%rip), %rcx    # 0x39a578
subl (%rcx), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd 0x17bbc(%rip), %xmm1    # 0x16f080
mulsd %xmm1, %xmm0
movsd 0x17bb8(%rip), %xmm1    # 0x16f088
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x157506
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
leaq 0x243f08(%rip), %rdi    # 0x39b400
leaq 0x4073a(%rip), %rsi     # 0x197c39
movb $0x2, %al
callq 0x9060
jmp 0x157508
addq $0x40, %rsp
popq %rbp
retq
nop