// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: plot_sat_trail(int, int, int, int, float, float, int, int)
void plot_sat_trail(int grid_x,int grid_y, int grid_r,  int prn, float az,float el,  int color, int dots)
{
int x1,y1;
int x2,y2;
int i;
int row;
u08 m;

   // Draw the trail of previous sat positions.  The trail is marked with colored
   // on the hour and black dots otherwise  as time markers.  

   if(map_trails == 0) return;  // trails disabled
   if((prn == SUN_PRN) && (no_sun_moon & 0x01)) return;
   if((prn == MOON_PRN) && (no_sun_moon & 0x02)) return;

   m = 0;
   row = 0;

   // the current location of the sat
   if(az < 0.0F) az += 360.0F;
   if(az >= 360.0F) az -= 360.0F;
   x1 = grid_x + (int) ((el * cos360(az) * grid_r)+0.50);
   y1 = grid_y + (int) ((el * sin360(az) * grid_r)+0.50);
   if(x1 < 0) return;
   if(y1 < 0) return;
   if(x1 >= SCREEN_WIDTH) return;
   if(y1 >= SCREEN_WIDTH) return;

   for(i=0; i<trail_count; i++) { // check the old locations of the sat
      el = (float) sat_trail[prn].el[i];
      az = (float) sat_trail[prn].az[i];
      if((az == 0.0F) && (el == 0.0F)) break;  // end of valid locations
      if((prn == MOON_PRN) || (prn == SUN_PRN)) {  // moon color depends upon elevation
         if(el < 0.0F) color = GREY;  // !!!! this does not work since saved el is always positive
         else color = MOON_COLOR;
//sprintf(debug_text2, "moon: el:%f  moon_el:%f  color:%d", el, moon_el, color);
      }
      if(el < 0.0F) el = 0.0F - el;

      el = (el - 90.0F) / 90.0F;
      az += 90.0F;
      if(az < 0.0F) az += 360.0F;
      if(az >= 360.0F) az -= 360.0F;

      x2 = grid_x + (int) ((el * cos360(az) * grid_r)+0.50);
      y2 = grid_y + (int) ((el * sin360(az) * grid_r)+0.50);
      if(x2 < 0) continue;
      if(y2 < 0) continue;
      if(x2 >= SCREEN_WIDTH) continue;
      if(y2 >= SCREEN_WIDTH) continue;

      if(dots) {  // mark the trail with time markers
         if((sat_trail[prn].mins[i] % TRAIL_MARKER) == 0) {    // it's time to mark the trail
            if(sat_trail[prn].mins[i] != 0) {  // it's not the hour... dot the dot
               draw_circle(x2,y2, 2, color, 0);  // hollow circle
            }
            else {
               draw_circle(x2,y2, 2, color, 1);  // filled circle
            }
         }
      }
      else {   // draw the trail line
         line(x1,y1, x2,y2, color); 
      }

      x1 = x2;
      y1 = y2;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movss %xmm1, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
leaq 0x1298ac(%rip), %rax    # 0x27a5f9
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x150d5a
jmp 0x15120c
cmpl $0x3e8, -0x10(%rbp)     # imm = 0x3E8
jne 0x150d79
leaq 0x7f0de(%rip), %rax     # 0x1cfe48
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x150d79
jmp 0x15120c
cmpl $0x3e9, -0x10(%rbp)     # imm = 0x3E9
jne 0x150d98
leaq 0x7f0bf(%rip), %rax     # 0x1cfe48
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x150d98
jmp 0x15120c
movb $0x0, -0x39(%rbp)
movl $0x0, -0x38(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x14(%rbp), %xmm0
jbe 0x150dbe
movss 0x32550(%rip), %xmm0    # 0x183304
addss -0x14(%rbp), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x14(%rbp), %xmm0
movss 0x32539(%rip), %xmm1    # 0x183304
ucomiss %xmm1, %xmm0
jb 0x150de6
movss -0x14(%rbp), %xmm0
movss 0x32527(%rip), %xmm1    # 0x183304
subss %xmm1, %xmm0
movss %xmm0, -0x14(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x4c(%rbp)
movss -0x18(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x31d29(%rip), %xmm1    # 0x182b30
callq 0x94d0
movsd 0x1e36c(%rip), %xmm1    # 0x16f180
divsd %xmm1, %xmm0
callq 0x96f0
movl -0x4c(%rbp), %eax
movaps %xmm0, %xmm1
movss -0x48(%rbp), %xmm0
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm0
cvtsi2ssl -0xc(%rbp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1e24b(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x44(%rbp)
movss -0x18(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x31cbd(%rip), %xmm1    # 0x182b30
callq 0x94d0
movsd 0x1e300(%rip), %xmm1    # 0x16f180
divsd %xmm1, %xmm0
callq 0x9080
movl -0x44(%rbp), %eax
movaps %xmm0, %xmm1
movss -0x40(%rbp), %xmm0
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm0
cvtsi2ssl -0xc(%rbp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1e1df(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x150ec9
jmp 0x15120c
cmpl $0x0, -0x28(%rbp)
jge 0x150ed4
jmp 0x15120c
movl -0x24(%rbp), %eax
leaq 0x126b02(%rip), %rcx    # 0x2779e0
cmpl (%rcx), %eax
jl 0x150ee7
jmp 0x15120c
movl -0x28(%rbp), %eax
leaq 0x126aef(%rip), %rcx    # 0x2779e0
cmpl (%rcx), %eax
jl 0x150efa
jmp 0x15120c
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x289f46(%rip), %eax    # 0x3dae50
jge 0x15120c
movslq -0x10(%rbp), %rcx
leaq 0x289f45(%rip), %rax    # 0x3dae60
imulq $0x36c, %rcx, %rcx      # imm = 0x36C
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
movss 0x124(%rax,%rcx,4), %xmm0
movss %xmm0, -0x18(%rbp)
movslq -0x10(%rbp), %rcx
leaq 0x289f1e(%rip), %rax    # 0x3dae60
imulq $0x36c, %rcx, %rcx      # imm = 0x36C
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x14(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x150f7d
jp 0x150f7d
movss -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x150f7d
jp 0x150f7d
jmp 0x15120c
cmpl $0x3e9, -0x10(%rbp)     # imm = 0x3E9
je 0x150f8f
cmpl $0x3e8, -0x10(%rbp)     # imm = 0x3E8
jne 0x150faa
xorps %xmm0, %xmm0
ucomiss -0x18(%rbp), %xmm0
jbe 0x150fa1
movl $0x8, -0x1c(%rbp)
jmp 0x150fa8
movl $0xe, -0x1c(%rbp)
jmp 0x150faa
xorps %xmm0, %xmm0
ucomiss -0x18(%rbp), %xmm0
jbe 0x150fc0
xorps %xmm0, %xmm0
subss -0x18(%rbp), %xmm0
movss %xmm0, -0x18(%rbp)
movss -0x18(%rbp), %xmm0
movss 0x20983(%rip), %xmm1    # 0x171950
subss %xmm1, %xmm0
movss 0x20977(%rip), %xmm1    # 0x171950
divss %xmm1, %xmm0
movss %xmm0, -0x18(%rbp)
movss 0x20966(%rip), %xmm0    # 0x171950
addss -0x14(%rbp), %xmm0
movss %xmm0, -0x14(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x14(%rbp), %xmm0
jbe 0x15100f
movss 0x322ff(%rip), %xmm0    # 0x183304
addss -0x14(%rbp), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x14(%rbp), %xmm0
movss 0x322e8(%rip), %xmm1    # 0x183304
ucomiss %xmm1, %xmm0
jb 0x151037
movss -0x14(%rbp), %xmm0
movss 0x322d6(%rip), %xmm1    # 0x183304
subss %xmm1, %xmm0
movss %xmm0, -0x14(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x5c(%rbp)
movss -0x18(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x31ad8(%rip), %xmm1    # 0x182b30
callq 0x94d0
movsd 0x1e11b(%rip), %xmm1    # 0x16f180
divsd %xmm1, %xmm0
callq 0x96f0
movl -0x5c(%rbp), %eax
movaps %xmm0, %xmm1
movss -0x58(%rbp), %xmm0
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm0
cvtsi2ssl -0xc(%rbp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1dffa(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
addl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x54(%rbp)
movss -0x18(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x31a6c(%rip), %xmm1    # 0x182b30
callq 0x94d0
movsd 0x1e0af(%rip), %xmm1    # 0x16f180
divsd %xmm1, %xmm0
callq 0x9080
movl -0x54(%rbp), %eax
movaps %xmm0, %xmm1
movss -0x50(%rbp), %xmm0
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm0
cvtsi2ssl -0xc(%rbp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1df8e(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x15111a
jmp 0x1511fe
cmpl $0x0, -0x30(%rbp)
jge 0x151125
jmp 0x1511fe
movl -0x2c(%rbp), %eax
leaq 0x1268b1(%rip), %rcx    # 0x2779e0
cmpl (%rcx), %eax
jl 0x151138
jmp 0x1511fe
movl -0x30(%rbp), %eax
leaq 0x12689e(%rip), %rcx    # 0x2779e0
cmpl (%rcx), %eax
jl 0x15114b
jmp 0x1511fe
cmpl $0x0, -0x20(%rbp)
je 0x1511da
movslq -0x10(%rbp), %rcx
leaq 0x289d00(%rip), %rax    # 0x3dae60
imulq $0x36c, %rcx, %rcx      # imm = 0x36C
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
movl 0x248(%rax,%rcx,4), %eax
movl $0x1e, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x1511d8
movslq -0x10(%rbp), %rcx
leaq 0x289cd3(%rip), %rax    # 0x3dae60
imulq $0x36c, %rcx, %rcx      # imm = 0x36C
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
cmpl $0x0, 0x248(%rax,%rcx,4)
je 0x1511bd
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x2, %edx
xorl %r8d, %r8d
callq 0x11f00
jmp 0x1511d6
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x2, %edx
movl $0x1, %r8d
callq 0x11f00
jmp 0x1511d8
jmp 0x1511f2
movl -0x24(%rbp), %edi
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x1c(%rbp), %eax
movzbl %al, %r8d
callq 0x109c0
movl -0x2c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x150f01
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)