// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/tekmsc.c
// Function: newmap
void
newmap(int mapno)
{
     int       sn,p;
     int       savhealth;
     int       savestun;
     int       savereds;
     int       saveblues;
     int       saveaccutrk;
     int       newmap;

     if( option[4] != 0 ) {
          return;
     }
     if( mapno >= TOTALMAPS ) {
          return;
     }

     switch( mapno ) {
     case 0:
     case 1:
     case 2:
     case 3:
          newmap=mapreturn(currentmapno);
          if( newmap != mapno ) {
               crashgame("bad return map");
          }
          break;
     }

     drawscreen(screenpeek,0);
     printext((xdim>>1)-44,(ydim>>1)-32,"LOADING MAP",ALPHABET2,255);
     nextpage();

     initpaletteshifts();
     p=screenpeek;

    #if 0
     switch( currentmapno ) {
     case 0:
     case 1:
     case 2:
     case 3:
          warpretx=posx[p];
          warprety=posy[p];
          warpretz=posz[p];
          warpretang=ang[p];
          warpretsect=cursectnum[p];
          break;
     default:
          break;
     }
    #endif

     savhealth=health[p];
     savestun=stun[p];
     savereds=invredcards[p];
     saveblues=invbluecards[p];
     saveaccutrk=invaccutrak[p];

     newgame(mapnames[mapno]);

     health[p]=savhealth;
     stun[p]=savestun;
     invredcards[p]=savereds;
     invbluecards[p]=saveblues;
     invaccutrak[p]=saveaccutrk;

    #if 0
     switch( mapno ) {
     case 0:
     case 1:
     case 2:
     case 3:
          sn=playersprite[p];
          sprite[sn].x=warpretx;
          sprite[sn].y=warprety;
          sprite[sn].z=warpretz;
          changespritesect(sn,warpretsect);
          posx[p]=sprite[sn].x;
          posy[p]=sprite[sn].y;
          posz[p]=sprite[sn].z;
          ang[p]=((warpretang+1024)&2047);
          cursectnum[p]=sprite[sn].sectnum;
          updatesector(posx[p],posy[p],cursectnum[p]);
          break;
     default:
          break;
     }
    #endif

     switch( mapno ) {
     case 0:
     case 1:
     case 2:
     case 3:
          sn=playersprite[p];

          sprite[sn].x=warpretx;
          sprite[sn].y=warprety;
          sprite[sn].ang=warpretang;
          copybuf(&sprite[sn].x,&osprite[sn].x,3);
          changespritesect(sn,warpretsect);

          posx[p]=sprite[sn].x;
          posy[p]=sprite[sn].y;
          ang[p]=sprite[sn].ang;
          cursectnum[p]=sprite[sn].sectnum;

          //updatesector(posx[p],posy[p],cursectnum[p]);
          //pushmove(&posx[p],&posy[p],&posz[p],&cursectnum[p],128L,4<<8,4<<8,CLIPMASK0);
          break;
     default:
          break;
     }

     vel=0;
     svel=0;
     angvel=0;

     currentmapno=mapno;
     strcpy(tektempbuf, mapnames[mapno]);
     showmessage(Bstrupr(tektempbuf));

     musicfade();
     if( mapno <= 3 ) {
          menusong(1);
     }
     else {
          startmusic(mission);
     }

}

// Assembly:
cmpl $0x1f, %edi
jg 0x17337
leaq 0xb788f(%rip), %rax     # 0xce978
cmpb $0x0, 0x4(%rax)
jne 0x17337
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
cmpl $0x3, %edi
ja 0x17125
movl 0x1153fe(%rip), %edi    # 0x12c50c
callq 0x17074
cmpl %ebx, %eax
je 0x17125
leaq 0x75966(%rip), %rdi     # 0x8ca84
xorl %eax, %eax
callq 0x2d800
leaq 0xca332(%rip), %r14     # 0xe145e
movswl (%r14), %edi
xorl %esi, %esi
callq 0xb563
leaq 0x59ed0e(%rip), %rax    # 0x5b5e4c
movl (%rax), %edi
sarl %edi
addl $-0x2c, %edi
leaq 0x59ed04(%rip), %rax    # 0x5b5e50
movl (%rax), %esi
sarl %esi
addl $-0x20, %esi
leaq 0x75939(%rip), %rdx     # 0x8ca93
movl $0x15d, %ecx            # imm = 0x15D
movl $0xff, %r8d
callq 0xa13f
callq 0x44e75
callq 0x145ca
movswq (%r14), %r15
leaq 0xca411(%rip), %rax     # 0xe1590
movl (%rax,%r15,4), %ecx
movl %ecx, 0xc(%rsp)
leaq 0xca202(%rip), %rax     # 0xe1390
movl (%rax,%r15,4), %r12d
leaq 0x116be7(%rip), %rax    # 0x12dd80
movl (%rax,%r15,4), %r13d
leaq 0x116c1c(%rip), %rax    # 0x12ddc0
movl (%rax,%r15,4), %r14d
leaq 0x116c51(%rip), %rax    # 0x12de00
movl (%rax,%r15,4), %ebp
movslq %ebx, %rax
leaq 0xb8453(%rip), %rcx     # 0xcf610
movq %rax, 0x10(%rsp)
movq (%rcx,%rax,8), %rdi
callq 0x16f82
movl 0xc(%rsp), %eax
leaq 0xca3ba(%rip), %rcx     # 0xe1590
movl %eax, (%rcx,%r15,4)
leaq 0xca1af(%rip), %rax     # 0xe1390
movl %r12d, (%rax,%r15,4)
leaq 0x116b94(%rip), %rax    # 0x12dd80
movl %r13d, (%rax,%r15,4)
leaq 0x116bc9(%rip), %rax    # 0x12ddc0
movl %r14d, (%rax,%r15,4)
leaq 0x116bfe(%rip), %rax    # 0x12de00
movl %ebp, (%rax,%r15,4)
cmpl $0x3, %ebx
ja 0x172be
leaq 0xcb53a(%rip), %rax     # 0xe2750
movswl (%rax,%r15,2), %eax
movl 0x116d6f(%rip), %ecx    # 0x12df90
movslq %eax, %r14
imulq $0x2c, %r14, %rbp
leaq 0x4138e1(%rip), %r13    # 0x42ab10
movq %r13, %rdi
addq %rbp, %rdi
movl %ecx, (%r13,%rbp)
movl 0x116d54(%rip), %eax    # 0x12df94
movl %eax, 0x4(%r13,%rbp)
movzwl 0x116d4c(%rip), %eax    # 0x12df98
movw %ax, 0x1c(%r13,%rbp)
leaq (%r14,%r14,2), %rsi
shlq $0x2, %rsi
addq 0xb6d57(%rip), %rsi     # 0xcdfb8
movl $0x3, %edx
callq 0x5da55
movswl 0x116d2a(%rip), %esi    # 0x12df9c
movl %r14d, %edi
callq 0x46bb5
movl (%r13,%rbp), %eax
leaq 0xca24a(%rip), %rcx     # 0xe14d0
movl %eax, (%rcx,%r15,4)
movl 0x4(%r13,%rbp), %eax
leaq 0xca27a(%rip), %rcx     # 0xe1510
movl %eax, (%rcx,%r15,4)
movzwl 0x1c(%r13,%rbp), %eax
leaq 0xca209(%rip), %rcx     # 0xe14b0
movw %ax, (%rcx,%r15,2)
movzwl 0x18(%r13,%rbp), %eax
leaq 0xcb467(%rip), %rcx     # 0xe2720
movw %ax, (%rcx,%r15,2)
leaq 0xcb51b(%rip), %rax     # 0xe27e0
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0xcb514(%rip), %rax     # 0xe27e4
movl %ecx, (%rax)
leaq 0xcb50f(%rip), %rax     # 0xe27e8
movl %ecx, (%rax)
movl %ebx, 0x11522b(%rip)    # 0x12c50c
movq 0x10(%rsp), %rax
leaq 0xb8323(%rip), %rcx     # 0xcf610
movq (%rcx,%rax,8), %rsi
leaq 0x116b68(%rip), %r14    # 0x12de60
movq %r14, %rdi
callq 0x85b0
movq %r14, %rdi
callq 0x348be
movq %rax, %rdi
xorl %eax, %eax
callq 0x14b61
xorl %eax, %eax
callq 0x1cc2d
cmpl $0x3, %ebx
leaq 0x18(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jg 0x17338
movl $0x1, %edi
jmp 0x1cc3f
retq
movl 0x1151d2(%rip), %edi    # 0x12c510
jmp 0x1ccc1