// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/src/tekgame.c
// Function: getpackets
void
getpackets()
{
     int i, j, k, l;
     int other, tempbufleng;

     if (option[4] == 0) return;

     while ((tempbufleng = getpacket(&other,tempbuf)) > 0)
     {
          switch(tempbuf[0])
          {
               case 0:  //[0] (receive master sync buffer)
                    j = ((numplayers+1)>>1)+1; k = (1<<3);
                    for(i=connecthead;i>=0;i=connectpoint2[i])
                    {
                         l = (tempbuf[k>>3]>>(k&7));
                         if (l&1) fsyncvel[i] = tempbuf[j++];
//** Les START - 09/27/95
                         if (l&2) {
                              fsyncsvel[i]=tempbuf[j++];
                              fsyncsvel[i]|=(tempbuf[j++]<<8);
                         }
                         if (l&4) {
                              fsyncangvel[i]=tempbuf[j++];
                              fsyncangvel[i]|=(tempbuf[j++]<<8);
                         }
//** Les END   - 09/27/95
                         if (l&8)
                         {
                              fsyncbits[i] = ((short)tempbuf[j])+(((short)tempbuf[j+1])<<8);
                              j += 2;
                         }
                         k += 4;
                    }
#if 0
                    while (j != tempbufleng)
                    {
                         othersyncval[othersyncvalend] = ((int)tempbuf[j]);
                         othersyncval[othersyncvalend] += (((int)tempbuf[j+1])<<8);
                         j += 2;
                         othersyncvalend = ((othersyncvalend+1)&(MOVEFIFOSIZ-1));
                    }

                    i = 0;
                    while (syncvalplc != syncvalend)
                    {
                         if (othersyncvalcnt > syncvalcnt)
                         {
                              if (i == 0) syncstat = 0, i = 1;
                              syncstat |= (syncval[syncvalplc]^othersyncval[syncvalplc]);
                         }
                         syncvalplc = ((syncvalplc+1)&(MOVEFIFOSIZ-1));
                         syncvalcnt++;
                    }
                    while (othersyncvalplc != othersyncvalend)
                    {
                         if (syncvalcnt > othersyncvalcnt)
                         {
                              if (i == 0) syncstat = 0, i = 1;
                              syncstat |= (syncval[othersyncvalplc]^othersyncval[othersyncvalplc]);
                         }
                         othersyncvalplc = ((othersyncvalplc+1)&(MOVEFIFOSIZ-1));
                         othersyncvalcnt++;
                    }
#endif

                movethings();        //Move all players and sprites
                    break;
               case 1:  //[1] (receive slave sync buffer)
                    j = 2; k = tempbuf[1];
                    if (k&1) fsyncvel[other] = tempbuf[j++];
//** Les START - 09/27/95
                     if (k&2) {
                         fsyncsvel[other]=tempbuf[j++];
                         fsyncsvel[other]|=(tempbuf[j++]<<8);
                     }
                     if (k&4) {
                         fsyncangvel[other]=tempbuf[j++];
                         fsyncangvel[other]|=(tempbuf[j++]<<8);
                     }
//** Les END   - 09/27/95
                    if (k&8) fsyncbits[other] = ((fsyncbits[other]&0xff00)|((short)tempbuf[j++]));
                    if (k&16) fsyncbits[other] = ((fsyncbits[other]&0x00ff)|(((short)tempbuf[j++])<<8));
                    break;
               case 2:
                    getmessageleng = tempbufleng-1;
                    for(j=getmessageleng-1;j>=0;j--) getmessage[j] = tempbuf[j+1];
                    getmessagetimeoff = totalclock+360+(getmessageleng<<4);
                    break;
               case 3:
                    break;
              #ifdef NETNAMES
               case 8:
                    memcpy(netnames[tempbuf[1]],&tempbuf[2],10);
                    netnames[tempbuf[1]][10]=0;
                    break;
              #endif
               case 5:
                    playerreadyflag[other] = tempbuf[1];
                    if ((other == connecthead) && (tempbuf[1] == 2))
                         sendpacket(connecthead,tempbuf,2);
                    break;
               case 255:  //[255] (logout)
                    deletesprite(playersprite[other]);
                    sprintf(tektempbuf,"%2d %8s HAS QUIT", other,netnames[other]);
                    showmessage(tektempbuf);
                    break;
          }
     }
}

// Assembly:
cmpb $0x0, 0xb9add(%rip)     # 0xc797c
je 0xe179
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0xcc739(%rip), %rbx     # 0xda5f0
leaq 0x72f8a(%rip), %r14     # 0x80e48
leaq 0x78dc6b(%rip), %r12    # 0x79bb30
leaq 0x78dc74(%rip), %rbp    # 0x79bb40
leaq 0xcd76d(%rip), %r15     # 0xdb640
leaq 0xcdcd6(%rip), %r13     # 0xdbbb0
leaq 0x4(%rsp), %rdi
movq %rbx, %rsi
callq 0x5486a
testl %eax, %eax
jle 0xe16b
movzbl 0xcc6fa(%rip), %ecx     # 0xda5f0
cmpq $0x8, %rcx
ja 0xdfb7
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
jmpq *%rcx
leaq 0x78dc1c(%rip), %rax    # 0x79bb2c
movl (%rax), %eax
incl %eax
sarl %eax
incl %eax
pushq $0x8
popq %rdx
movq %r12, %rsi
leaq 0xcd6db(%rip), %r9      # 0xdb600
leaq 0xcd674(%rip), %r10     # 0xdb5a0
leaq 0xcd61d(%rip), %r11     # 0xdb550
movslq (%rsi), %rsi
testq %rsi, %rsi
js 0xe161
movl %edx, %ecx
shrl $0x3, %ecx
movzbl (%rcx,%rbx), %r8d
movl %edx, %ecx
andb $0x4, %cl
movl %r8d, %edi
shrl %cl, %edi
movl %edx, %ecx
andl $0x4, %ecx
btl %ecx, %r8d
jae 0xdf6a
movslq %eax, %rcx
incl %eax
movb (%rcx,%rbx), %cl
movb %cl, (%rsi,%r11)
testb $0x2, %dil
je 0xdf7f
movslq %eax, %rcx
leal 0x2(%rcx), %eax
movzwl (%rcx,%rbx), %ecx
movw %cx, (%r10,%rsi,2)
testb $0x4, %dil
je 0xdf94
movslq %eax, %rcx
leal 0x2(%rcx), %eax
movzwl (%rcx,%rbx), %ecx
movw %cx, (%r9,%rsi,2)
testb $0x8, %dil
je 0xdfa8
cltq
movzwl (%rax,%rbx), %ecx
movw %cx, (%r15,%rsi,2)
addl $0x2, %eax
addl $0x4, %edx
shlq $0x2, %rsi
addq %rbp, %rsi
jmp 0xdf33
cmpl $0xff, %ecx
jne 0xdeda
movslq 0x4(%rsp), %rax
leaq 0xcd781(%rip), %rcx     # 0xdb750
movswl (%rcx,%rax,2), %edi
callq 0x442fc
movslq 0x4(%rsp), %rdx
imulq $0xb, %rdx, %rcx
leaq 0xcd688(%rip), %rax     # 0xdb670
addq %rax, %rcx
movq %r12, %r15
movq %r14, %r12
leaq 0x118e78(%rip), %r14    # 0x126e70
movq %r14, %rdi
leaq 0x7332f(%rip), %rsi     # 0x81331
xorl %eax, %eax
callq 0x8f20
movq %r14, %rdi
movq %r12, %r14
movq %r15, %r12
leaq 0xcd627(%rip), %r15     # 0xdb640
xorl %eax, %eax
callq 0x1373a
jmp 0xdeda
movzbl 0xcc5c5(%rip), %eax     # 0xda5f1
imulq $0xb, %rax, %rax
movzwl 0xcc5c3(%rip), %ecx     # 0xda5fa
leaq 0xcd632(%rip), %rdx     # 0xdb670
movw %cx, 0x8(%rax,%rdx)
movq 0xcc5a8(%rip), %rcx     # 0xda5f2
movq %rcx, (%rax,%rdx)
movb $0x0, 0xa(%rax,%rdx)
jmp 0xdeda
decb %al
movb %al, 0xcdb46(%rip)      # 0xdbba6
movsbl %al, %eax
movq %rax, %rcx
testl %ecx, %ecx
jle 0xe077
movb (%rcx,%rbx), %dl
movb %dl, -0x1(%rcx,%r13)
decq %rcx
jmp 0xe066
leaq 0x5452ea(%rip), %rcx    # 0x553368
movl (%rcx), %ecx
shll $0x4, %eax
addl %ecx, %eax
addl $0x168, %eax            # imm = 0x168
movl %eax, 0xcdbc4(%rip)     # 0xdbc54
jmp 0xdeda
movb 0xcc556(%rip), %al      # 0xda5f1
movslq 0x4(%rsp), %rdi
leaq 0x1153f9(%rip), %rcx    # 0x1234a0
movb %al, (%rdi,%rcx)
cmpl (%r12), %edi
sete %cl
cmpb $0x2, %al
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0xdeda
movq %rbx, %rsi
pushq $0x2
popq %rdx
callq 0x54ffd
jmp 0xdeda
movzbl 0xcc51a(%rip), %eax     # 0xda5f1
pushq $0x2
popq %rcx
testb $0x1, %al
leaq 0xcd46d(%rip), %rsi     # 0xdb550
je 0xe0f6
movb 0xcc507(%rip), %cl      # 0xda5f2
movslq 0x4(%rsp), %rdx
movb %cl, (%rdx,%rsi)
pushq $0x3
popq %rcx
testb $0x2, %al
leaq 0xcd4a1(%rip), %rdi     # 0xdb5a0
je 0xe113
movl %ecx, %edx
movslq 0x4(%rsp), %rsi
addl $0x2, %ecx
movzwl (%rdx,%rbx), %edx
movw %dx, (%rdi,%rsi,2)
leaq 0xcd4e6(%rip), %rdi     # 0xdb600
testb $0x4, %al
je 0xe130
movl %ecx, %edx
movslq 0x4(%rsp), %rsi
addl $0x2, %ecx
movzwl (%rdx,%rbx), %edx
movw %dx, (%rdi,%rsi,2)
testb $0x8, %al
je 0xe145
movslq 0x4(%rsp), %rdx
movl %ecx, %esi
incl %ecx
movb (%rsi,%rbx), %sil
movb %sil, (%r15,%rdx,2)
testb $0x10, %al
je 0xdeda
movslq 0x4(%rsp), %rax
movl %ecx, %ecx
movb (%rcx,%rbx), %cl
movb %cl, 0x1(%r15,%rax,2)
jmp 0xdeda
callq 0xc3d8
jmp 0xdeda
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq