// File: /workspace/github_c_makefile_star2_O2/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 0x15f96
leaq 0xb1c29(%rip), %rax     # 0xc7978
cmpb $0x0, 0x4(%rax)
jne 0x15f96
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
cmpl $0x3, %edi
ja 0x15d8b
movl 0x10f798(%rip), %edi    # 0x12550c
callq 0x15cdc
cmpl %ebx, %eax
je 0x15d8b
leaq 0x6bd84(%rip), %rdi     # 0x81b08
xorl %eax, %eax
callq 0x2acb8
leaq 0xc46cc(%rip), %r14     # 0xda45e
movswl (%r14), %edi
xorl %esi, %esi
callq 0xa81a
leaq 0x5990c8(%rip), %rax    # 0x5aee6c
movl (%rax), %edi
sarl %edi
addl $-0x2c, %edi
leaq 0x5990be(%rip), %rax    # 0x5aee70
movl (%rax), %esi
sarl %esi
addl $-0x20, %esi
leaq 0x6bd57(%rip), %rdx     # 0x81b17
movl $0x15d, %ecx            # imm = 0x15D
movl $0xff, %r8d
callq 0x9558
callq 0x422ff
callq 0x1322e
movswq (%r14), %r15
leaq 0xc47ab(%rip), %rax     # 0xda590
movl (%rax,%r15,4), %ecx
movl %ecx, 0xc(%rsp)
leaq 0xc459c(%rip), %rax     # 0xda390
movl (%rax,%r15,4), %r12d
leaq 0x110f91(%rip), %rax    # 0x126d90
movl (%rax,%r15,4), %r13d
leaq 0x110fc6(%rip), %rax    # 0x126dd0
movl (%rax,%r15,4), %r14d
leaq 0x110ffb(%rip), %rax    # 0x126e10
movl (%rax,%r15,4), %ebp
movslq %ebx, %rax
leaq 0xb27ed(%rip), %rcx     # 0xc8610
movq %rax, 0x10(%rsp)
movq (%rcx,%rax,8), %rdi
callq 0x15bef
movl 0xc(%rsp), %eax
leaq 0xc4754(%rip), %rcx     # 0xda590
movl %eax, (%rcx,%r15,4)
leaq 0xc4549(%rip), %rax     # 0xda390
movl %r12d, (%rax,%r15,4)
leaq 0x110f3e(%rip), %rax    # 0x126d90
movl %r13d, (%rax,%r15,4)
leaq 0x110f73(%rip), %rax    # 0x126dd0
movl %r14d, (%rax,%r15,4)
leaq 0x110fa8(%rip), %rax    # 0x126e10
movl %ebp, (%rax,%r15,4)
cmpl $0x3, %ebx
ja 0x15f1e
leaq 0xc58d4(%rip), %rax     # 0xdb750
movswl (%rax,%r15,2), %eax
movl 0x11111d(%rip), %ecx    # 0x126fa4
movslq %eax, %r14
imulq $0x2c, %r14, %rbp
leaq 0x40dc9b(%rip), %r13    # 0x423b30
movq %r13, %rdi
addq %rbp, %rdi
movl %ecx, (%r13,%rbp)
movl 0x111102(%rip), %eax    # 0x126fa8
movl %eax, 0x4(%r13,%rbp)
movzwl 0x1110fa(%rip), %eax    # 0x126fac
movw %ax, 0x1c(%r13,%rbp)
imulq $0xc, %r14, %rsi
addq 0xb10f5(%rip), %rsi     # 0xc6fb8
pushq $0x3
popq %rdx
callq 0x56a36
movswl 0x1110de(%rip), %esi    # 0x126fb0
movl %r14d, %edi
callq 0x43fe1
movl (%r13,%rbp), %eax
leaq 0xc45ea(%rip), %rcx     # 0xda4d0
movl %eax, (%rcx,%r15,4)
movl 0x4(%r13,%rbp), %eax
leaq 0xc461a(%rip), %rcx     # 0xda510
movl %eax, (%rcx,%r15,4)
movzwl 0x1c(%r13,%rbp), %eax
leaq 0xc45a9(%rip), %rcx     # 0xda4b0
movw %ax, (%rcx,%r15,2)
movzwl 0x18(%r13,%rbp), %eax
leaq 0xc5807(%rip), %rcx     # 0xdb720
movw %ax, (%rcx,%r15,2)
leaq 0xc58bb(%rip), %rax     # 0xdb7e0
andl $0x0, (%rax)
leaq 0xc58b5(%rip), %rax     # 0xdb7e4
andl $0x0, (%rax)
leaq 0xc58af(%rip), %rax     # 0xdb7e8
andl $0x0, (%rax)
movl %ebx, 0x10f5ca(%rip)    # 0x12550c
movq 0x10(%rsp), %rax
leaq 0xb26c2(%rip), %rcx     # 0xc8610
movq (%rcx,%rax,8), %rsi
leaq 0x110f17(%rip), %r14    # 0x126e70
movq %r14, %rdi
callq 0x85b0
movq %r14, %rdi
callq 0x31b92
movq %rax, %rdi
xorl %eax, %eax
callq 0x1373a
xorl %eax, %eax
callq 0x1b523
cmpl $0x3, %ebx
leaq 0x18(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jg 0x15f97
pushq $0x1
popq %rdi
jmp 0x1b532
retq
movl 0x10f573(%rip), %edi    # 0x125510
jmp 0x1b5a3