// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, -0x4c(%rbp)
movl %esi, -0x44(%rbp)
movl %edi, -0x48(%rbp)
leaq 0x125c71(%rip), %rax    # 0x205419
cmpb $0x0, (%rax)
je 0xdfb06
movl %r8d, %r12d
movl %edx, %ebx
cmpl $0x3e9, %ecx            # imm = 0x3E9
je 0xdf7d7
cmpl $0x3e8, %ecx            # imm = 0x3E8
jne 0xdf7e7
leaq 0x7b49b(%rip), %rax     # 0x15ac68
testb $0x1, (%rax)
je 0xdf7e7
jmp 0xdfb06
leaq 0x7b48a(%rip), %rax     # 0x15ac68
testb $0x2, (%rax)
jne 0xdfb06
movss 0x291b5(%rip), %xmm4    # 0x1089a4
movaps %xmm0, %xmm5
addss %xmm4, %xmm5
xorps %xmm2, %xmm2
movss %xmm1, -0x30(%rbp)
movaps %xmm0, %xmm3
cmpltss %xmm2, %xmm3
andps %xmm3, %xmm5
andnps %xmm0, %xmm3
orps %xmm5, %xmm3
movaps %xmm4, %xmm0
cmpnless %xmm3, %xmm0
movaps %xmm3, %xmm1
addss 0x36ee2(%rip), %xmm1    # 0x116704
movaps %xmm0, %xmm2
andps %xmm3, %xmm2
andnps %xmm1, %xmm0
orps %xmm2, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x28971(%rip), %xmm1    # 0x1081b0
movl %ecx, %r14d
callq 0x94d0
divsd 0x13911(%rip), %xmm0    # 0xf3160
callq 0x9710
cvtsd2ss %xmm0, %xmm0
cvtsi2ss %ebx, %xmm1
movss %xmm1, -0x34(%rbp)
mulss -0x30(%rbp), %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x137f2(%rip), %xmm0    # 0xf3068
cvttsd2si %xmm0, %r15d
movsd -0x40(%rbp), %xmm0
movsd 0x28928(%rip), %xmm1    # 0x1081b0
callq 0x94d0
divsd 0x138cb(%rip), %xmm0    # 0xf3160
callq 0x9080
movss -0x30(%rbp), %xmm3
movsd 0x137c1(%rip), %xmm2    # 0xf3068
movss -0x34(%rbp), %xmm1
addl -0x48(%rbp), %r15d
js 0xdfb06
cvtsd2ss %xmm0, %xmm0
mulss %xmm3, %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %esi
addl -0x44(%rbp), %esi
js 0xdfb06
leaq 0x122f22(%rip), %rax    # 0x202800
movl (%rax), %eax
cmpl %eax, %r15d
jge 0xdfb06
cmpl %eax, %esi
jge 0xdfb06
movl %r14d, %ecx
movslq %r14d, %rax
imulq $0x36c, %rax, %rax      # imm = 0x36C
leaq 0x285f6b(%rip), %rdx    # 0x365870
addq %rax, %rdx
movq %rdx, -0x58(%rbp)
andl $-0x2, %ecx
xorl %r14d, %r14d
xorps %xmm4, %xmm4
movslq 0x285f44(%rip), %rax    # 0x365860
cmpq %rax, %r14
jge 0xdfb06
movq -0x58(%rbp), %rax
movss (%rax,%r14,4), %xmm0
movss 0x124(%rax,%r14,4), %xmm2
ucomiss %xmm4, %xmm0
jne 0xdf94b
jp 0xdf94b
ucomiss %xmm4, %xmm2
jne 0xdf94b
jnp 0xdfb06
movl %esi, -0x2c(%rbp)
ucomiss %xmm2, %xmm4
pushq $0xe
popq %rax
pushq $0x8
popq %rdx
cmoval %edx, %eax
jbe 0xdf966
xorps %xmm1, %xmm1
subss %xmm2, %xmm1
movaps %xmm1, %xmm2
movl %ecx, %r13d
cmpl $0x3e8, %ecx            # imm = 0x3E8
cmovel %eax, %r12d
movl %r12d, -0x40(%rbp)
addss 0x29021(%rip), %xmm2    # 0x1089a0
movss 0x1777d(%rip), %xmm1    # 0xf7104
divss %xmm1, %xmm2
movss %xmm2, -0x30(%rbp)
addss %xmm1, %xmm0
movaps %xmm0, %xmm1
movss 0x29005(%rip), %xmm3    # 0x1089a4
addss %xmm3, %xmm1
movaps %xmm0, %xmm2
cmpltss %xmm4, %xmm2
andps %xmm2, %xmm1
andnps %xmm0, %xmm2
orps %xmm1, %xmm2
movaps %xmm3, %xmm0
cmpnless %xmm2, %xmm0
movaps %xmm0, %xmm1
andps %xmm2, %xmm1
addss 0x36d3a(%rip), %xmm2    # 0x116704
andnps %xmm2, %xmm0
orps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x287cf(%rip), %xmm1    # 0x1081b0
callq 0x94d0
movsd 0x13772(%rip), %xmm1    # 0xf3160
divsd %xmm1, %xmm0
callq 0x9710
cvtsd2ss %xmm0, %xmm0
mulss -0x30(%rbp), %xmm0
mulss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x13657(%rip), %xmm1    # 0xf3068
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebx
movsd -0x60(%rbp), %xmm0
movsd 0x2878a(%rip), %xmm1    # 0x1081b0
callq 0x94d0
divsd 0x1372d(%rip), %xmm0    # 0xf3160
callq 0x9080
addl -0x48(%rbp), %ebx
js 0xdfaae
cvtsd2ss %xmm0, %xmm0
movss -0x30(%rbp), %xmm1
mulss %xmm0, %xmm1
movss -0x34(%rbp), %xmm2
mulss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm0
addsd 0x13609(%rip), %xmm0    # 0xf3068
cvttsd2si %xmm0, %r12d
addl -0x44(%rbp), %r12d
movl %r13d, %ecx
xorps %xmm4, %xmm4
js 0xdfaa5
leaq 0x122d89(%rip), %rax    # 0x202800
movl (%rax), %eax
cmpl %eax, %ebx
jge 0xdfaa5
cmpl %eax, %r12d
jge 0xdfaa5
cmpl $0x0, -0x4c(%rbp)
je 0xdfab7
movq -0x58(%rbp), %rax
movl 0x248(%rax,%r14,4), %ecx
movl %ecx, %eax
cltd
pushq $0x1e
popq %rsi
idivl %esi
testl %edx, %edx
je 0xdface
movl %r13d, %ecx
jmp 0xdfaf4
movl -0x2c(%rbp), %r12d
movl %r15d, %ebx
jmp 0xdfaf4
movl -0x2c(%rbp), %r12d
movl %r15d, %ebx
jmp 0xdfaee
movzbl -0x40(%rbp), %r8d
movl %r15d, %edi
movl -0x2c(%rbp), %esi
movl %ebx, %edx
movl %r12d, %ecx
callq 0xdedf
jmp 0xdfaee
movl %ebx, %edi
movl %r12d, %esi
pushq $0x2
popq %rdx
testl %ecx, %ecx
je 0xdfae2
movl -0x40(%rbp), %ecx
xorl %r8d, %r8d
jmp 0xdfae9
movl -0x40(%rbp), %ecx
pushq $0x1
popq %r8
callq 0xec2f
movl %r13d, %ecx
xorps %xmm4, %xmm4
incq %r14
movl %r12d, %esi
movl %ebx, %r15d
movl -0x40(%rbp), %r12d
jmp 0xdf915
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq