// File: /workspace/github_c_makefile_star2_O2/jrrk[P]cbzone/c_graphics.c
// Function: joystick
void joystick (position, sens, pl)
     int* position;
     Genericp pl;
     Bool sens;
{
  static float sscale[] = {0.06, 0.03};
  static float rscale[] = {0.00013, 0.000065};
  static int destorigin[] = {845, 550};
  static short stick[8] = {0};
  static Bool first = True;
  static Bool draw = True;
  int ind;
  float scrot, sctot, scale, xl, yl, tl, xoff, yoff;

  if (sens)
    ind = 0;
  else
    ind = 1;
  pl->speed = -(position[1] - 355.0) * sscale[ind];
  pl->rotate = (position[0] - 500.0) * rscale[ind];
  if (fabs(pl->speed) > 10.0)
    pl->speed = sign(10.0, pl->speed);
  if (fabs(pl->rotate) > 0.030)
    pl->rotate = sign(0.030, pl->rotate);
  scrot = pl->rotate * 10.0 / 0.030;
  sctot = sqrt(pl->speed*pl->speed + scrot*scrot);
  if (sctot > 10.0) {
    scale = 10.0 / sctot;
    pl->speed *= scale;
    pl->rotate *= scale;
  }
  if (draw) {
    gprsetclippingactive(False);
    if (!first) {
      gprsetdrawvalue(opt->cpi[COLOR_BG]);
      removepixmap(1, destorigin);
      multiline(stick, 2);
    }
    else
      first = False;
    destorigin[0] =  35.0 * (pl->rotate / 0.03) + 845.0;
    destorigin[1] = -35.0 * (pl->speed  / 10.0)  + 550.0;
    putpixmap(1, destorigin);
    xl = pl->rotate / 0.030;
    yl = pl->speed / 10.0;
    tl = sqrt(xl*xl + yl*yl);
    if (tl > 0.05) {
      yoff = xl / tl * 9.0;
      xoff = yl / tl * 9.0;
    }
    else {
      yoff = 0.0;
      xoff = 0.0;
    }
    stick[0] = stick[4] = 855;
    stick[2] = destorigin[0] + 10 + xoff / 2;
    stick[6] = destorigin[0] + 10 - xoff / 2;
    stick[1] = stick[5] = 560;
    stick[3] = destorigin[1] + 10 + yoff / 2;;
    stick[7] = destorigin[1] + 10 - yoff / 2;
    gprsetdrawvalue(opt->cpi[COLOR_JOYSTICK]);
    multiline(stick, 2);
    gprsetclippingactive(True);
  }
  draw = !draw;
  pl->rotate = -pl->rotate;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
xorl %eax, %eax
testl %esi, %esi
sete %al
cvtsi2sdl 0x4(%rdi), %xmm0
addsd 0x5aeb(%rip), %xmm0     # 0xd598
xorpd 0x5b5b(%rip), %xmm0     # 0xd610
shll $0x2, %eax
leaq 0x5b49(%rip), %rcx      # 0xd608
movss (%rax,%rcx), %xmm1
leaq 0x5b35(%rip), %rcx      # 0xd600
movss (%rax,%rcx), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtsi2sdl (%rdi), %xmm1
addsd 0x5ac1(%rip), %xmm1     # 0xd5a0
cvtps2pd %xmm2, %xmm2
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd %xmm0, %xmm2
cvtpd2ps %xmm2, %xmm0
movq %rdx, %rbx
movlpd %xmm0, 0x2c(%rdx)
movapd 0x5552(%rip), %xmm1     # 0xd050
andpd %xmm0, %xmm1
ucomiss 0x54fb(%rip), %xmm1     # 0xd004
movapd %xmm0, %xmm1
jbe 0x7b2c
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomiss %xmm0, %xmm1
seta %al
leaq 0x5a86(%rip), %rcx      # 0xd5a8
movss (%rcx,%rax,4), %xmm1
movss %xmm1, 0x2c(%rbx)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, %xmm2
andps 0x5516(%rip), %xmm2     # 0xd050
cvtss2sd %xmm2, %xmm2
ucomisd 0x5a6a(%rip), %xmm2     # 0xd5b0
jbe 0x7b64
xorps %xmm2, %xmm2
xorl %eax, %eax
ucomiss %xmm0, %xmm2
seta %al
leaq 0x5a5e(%rip), %rcx      # 0xd5b8
movss (%rcx,%rax,4), %xmm0
movss %xmm0, 0x30(%rbx)
cvtss2sd %xmm0, %xmm2
mulsd 0x5a50(%rip), %xmm2     # 0xd5c0
divsd 0x5a38(%rip), %xmm2     # 0xd5b0
cvtsd2ss %xmm2, %xmm2
mulss %xmm2, %xmm2
movapd %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
sqrtss %xmm3, %xmm2
ucomiss 0x546d(%rip), %xmm2     # 0xd004
jbe 0x7bb7
movss 0x5463(%rip), %xmm3     # 0xd004
divss %xmm2, %xmm3
mulss %xmm3, %xmm1
movss %xmm1, 0x2c(%rbx)
mulss %xmm3, %xmm0
movss %xmm0, 0x30(%rbx)
cmpl $0x0, 0xb7d2(%rip)      # 0x13390
je 0x7c0d
xorl %edi, %edi
xorl %eax, %eax
callq 0x6cb6
cmpb $0x1, 0xbbc0(%rip)      # 0x13790
jne 0x7c15
leaq 0xb9b7(%rip), %rax      # 0x13590
movq (%rax), %rax
movl 0xf0(%rax), %edi
xorl %eax, %eax
callq 0x7092
leaq 0xb798(%rip), %rsi      # 0x13388
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x7335
leaq 0xbb7f(%rip), %rdi      # 0x13780
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x6abd
jmp 0x7c1c
pushq $0x1
popq %rax
jmp 0x7d4f
movb $0x1, 0xbb74(%rip)      # 0x13790
cvtps2pd 0x2c(%rbx), %xmm0
divpd 0x59f8(%rip), %xmm0     # 0xd620
mulpd 0x5a00(%rip), %xmm0     # 0xd630
addpd 0x5a08(%rip), %xmm0     # 0xd640
cvttpd2dq %xmm0, %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0xb73f(%rip)     # 0x13388
leaq 0xb738(%rip), %rsi      # 0x13388
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x72c1
cvtss2sd 0x30(%rbx), %xmm0
divsd 0x5949(%rip), %xmm0     # 0xd5b0
cvtsd2ss %xmm0, %xmm2
movss 0x2c(%rbx), %xmm0
divss 0x538c(%rip), %xmm0     # 0xd004
movaps %xmm0, %xmm1
mulss %xmm0, %xmm1
movaps %xmm2, %xmm3
mulss %xmm2, %xmm3
addss %xmm1, %xmm3
sqrtss %xmm3, %xmm3
cvtss2sd %xmm3, %xmm4
xorps %xmm1, %xmm1
ucomisd 0x592b(%rip), %xmm4     # 0xd5c8
jbe 0x7cba
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
shufps $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
divps %xmm3, %xmm0
mulps 0x59a0(%rip), %xmm0     # 0xd650
mulps 0x59a9(%rip), %xmm0     # 0xd660
movaps %xmm0, %xmm1
movl $0x2300357, %eax        # imm = 0x2300357
movl %eax, 0xbac3(%rip)      # 0x13788
leaq 0xbab4(%rip), %r14      # 0x13780
movl %eax, 0xbaae(%rip)      # 0x13780
movq 0xb6ae(%rip), %xmm0     # 0x13388
paddd 0x598e(%rip), %xmm0     # 0xd670
cvtdq2ps %xmm0, %xmm0
movaps %xmm1, %xmm2
addps %xmm0, %xmm2
cvttps2dq %xmm2, %xmm2
pshuflw $0xe8, %xmm2, %xmm2     # xmm2 = xmm2[0,2,2,3,4,5,6,7]
movd %xmm2, 0xba88(%rip)     # 0x13784
subps %xmm1, %xmm0
cvttps2dq %xmm0, %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, 0xba7c(%rip)     # 0x1378c
leaq 0xb879(%rip), %rax      # 0x13590
movq (%rax), %rax
movl 0x118(%rax), %edi
xorl %eax, %eax
callq 0x7092
pushq $0x2
popq %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x6abd
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x6cb6
movss 0x30(%rbx), %xmm0
xorl %eax, %eax
cmpl $0x0, 0xb644(%rip)      # 0x13390
sete %al
movl %eax, 0xb63b(%rip)      # 0x13390
xorps 0x52b4(%rip), %xmm0     # 0xd010
movss %xmm0, 0x30(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq