// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/tekmsc.c
// Function: domenuinput
void
domenuinput(void)
{
     int c,keystate;
     int  tries;
     struct menu *mptr = 0;

     if (activemenu == 255) {
          return;
     }
     if (activemenu == HELPSCREEN) {
          if (keystatus[1]) {
               keystatus[1]=0;
               playsound( S_BEEP ,0,0,0,ST_IMMEDIATE);
               if (menudirect) {
                    activemenu=255;
                    menudirect=0;
               }
          }
          return;
     }
     if (loctypemode) {
          while (keyfifoplc != keyfifoend) {
               c=keyfifo[keyfifoplc];
               keystate=keyfifo[(keyfifoplc+1)&(KEYFIFOSIZ-1)];
               keyfifoplc=((keyfifoplc+2)&(KEYFIFOSIZ-1));
               if (keystate != 0) {
                    if (c == 0x01) {              // ESC key
                         keystatus[1]=0;
                         locmessagelen=0;
                         loctypemode=0;
                    }
                    if (c == 0x0E) {              // backspace key
                         keystatus[14]=0;
                         if (locmessagelen == 0) {
                              break;
                         }
                         locmessagelen--;
                         lockeybuf[locmessagelen]=0;
                    }
                    if (c == 0x1C || c == 0x9C) { // enter keys
                         keystatus[0x1C]=keystatus[0x9C]=0;
                         if (locmessagelen > 0) {
                              strncpy(loadsavenames[selopt-1],lockeybuf,
                                   MAXLOADSAVESIZE);
                              locmessagelen=0;
                         }
                         loctypemode=0;
                         if( option[4] == 0 ) {
                              savegame(selopt);
                         }
                         activemenu=255;
                         break;
                    }
                    if (locmessagelen < (MAXLOADSAVESIZE-1) && c < 128) {
                         if (keystatus[0x2A] || keystatus[0x36]) {
                              c=scantoascwithshift[c];
                         }
                         else {
                              c=scantoasc[c];
                         }
                         if (c != 0) {
                              if (isalpha(c) || isdigit(c) || c == ' ') {
                                   lockeybuf[locmessagelen++]=toupper(c);
                                   lockeybuf[locmessagelen]=0;
                              }
                         }
                    }
               }
          }
          return;
     }
     mptr=&menu[activemenu][selopt];
     if (keystatus[1]) {
          keystatus[1]=0;
          playsound( S_BEEP ,0,0,0,ST_IMMEDIATE);
          if (menudirect) {
               activemenu=255;
               menudirect=0;
          }
          else {
               activemenu=mptr->backmenu;
          }
          selopt=lastselopt[activemenu];
          if (activemenu == 0) {
               activemenu=255;
          }
     }
     else if (keystatus[keys[0]]) {     // up arrow
          keystatus[keys[0]]=0;
          playsound( S_BOOP ,0,0,0,ST_IMMEDIATE);
          tries=0;
          while (tries < MAXSUBOPTIONS) {
               selopt--;
               if (selopt <= 0) {
                    selopt=5;
               }
               lastselopt[activemenu]=selopt;
               if (menu[activemenu][selopt].label != NULL) {
                    break;
               }
               tries++;
          }
     }
     else if (keystatus[keys[1]]) {     // down arrow
          keystatus[keys[1]]=0;
          playsound( S_BOOP ,0,0,0,ST_IMMEDIATE);
          tries=0;
          while (tries < MAXSUBOPTIONS) {
               selopt++;
               if (selopt > 5) {
                    selopt=1;
               }
               lastselopt[activemenu]=selopt;
               if (menu[activemenu][selopt].label != NULL) {
                    break;
               }
               tries++;
          }
     }
     else if (activemenu == 4) {
          if (keystatus[21] != 0) {                    // "Y" key
               switch (activemenu) {
               case 4:
                    gameover=1;
                    //playsound( ??? ,0,0,0,ST_IMMEDIATE);
                    break;
               case 5:
                    //endgame=1;
                    activemenu=255;
                    break;
               }
          }
          else if (keystatus[49] != 0) {               // "N" key
               activemenu=255;
          }
     }
     else if (keystatus[0x1C] || keystatus[0x9C]) {    // enter key
          keystatus[0x1C]=keystatus[0x9C]=0;
          playsound( S_MENUSOUND2 ,0,0,0,ST_IMMEDIATE);
          if (mptr->tomenu != 0) {
               activemenu=mptr->tomenu;
               selopt=lastselopt[activemenu];
               redrawborders=1;
          }
          else {
               switch (activemenu) {
               case 1:
                    break;
               case 2:
                    difficulty=selopt;
                    newgame(boardfilename);
                    activemenu=255;
                    break;
               case 3:
                    if (selopt == 3) {
                         if (strcmp(headbobstr,"HEAD BOB ON") == 0) {
                              strcpy(headbobstr,"HEAD BOB OFF");
                              headbobon=0;
                         }
                         else {
                              strcpy(headbobstr,"HEAD BOB ON");
                              headbobon=1;
                         }
                    }
                    break;
               case 5:                                 // day/night mission
                    loadnewgame=selopt;
                    break;
               case 6:                                 // load game
                    stopallsounds();
                    if( option[4] == 0 ) {
                         loadgame(selopt);
                    }
                    activemenu=255;
                    break;
               case 7:                                 // save game
                    keystatus[0x1C]=keystatus[0x9C]=0;
                    loctypemode=1;
                    keyfifoplc=keyfifoend;
                    if (strcmp(loadsavenames[selopt-1],"-EMPTY-") != 0) {
                         strncpy(lockeybuf,loadsavenames[selopt-1],
                              MAXLOADSAVESIZE);
                         locmessagelen=(int)strlen(lockeybuf);
                    }
                    else {
                         memset(lockeybuf,0,sizeof(lockeybuf));
                         locmessagelen=0;
                    }
                    break;
               }
          }
     }
     else if (activemenu == 8 || activemenu == 9) {
          if (keystatus[0x4B] || keystatus[0xCB]) {    // left arrow key
               keystatus[0x4B]=keystatus[0xCB]=0;
               switch (selopt) {
               case 1:
                    if (activemenu == 8) {
                         if (soundv > 0) {
                              soundv--;
                              soundmastervolume(soundv<<11);
                         }
                    }
                    else {
                         if (mousesensitivity > 0) {
                              mousesensitivity--;
                         }
                    }
                    break;
               case 2:
                    if (musicv > 0) {
                         musicv--;
                         songmastervolume(musicv<<3);
                    }
                    break;
               }
               playsound( S_MENUSOUND1 ,0,0,0,ST_IMMEDIATE);
          }
          else if (keystatus[0x4D] || keystatus[0xCD]) {    // right arrow key
               keystatus[0x4D]=keystatus[0xCD]=0;
               switch (selopt) {
               case 1:
                    if (activemenu == 8) {
                         if (soundv < 16) {
                              soundv++;
                              soundmastervolume(soundv<<11);
                         }
                    }
                    else {
                         if (mousesensitivity < 16) {
                              mousesensitivity++;
                         }
                    }
                    break;
               case 2:
                    if (musicv < 16) {
                         musicv++;
                         songmastervolume(musicv<<3);
                    }
                    break;
               }
               playsound( S_MENUSOUND1 ,0,0,0,ST_IMMEDIATE);
          }
     }
     else if (keystatus[16]) {
          keystatus[16]=0;
          gameover=1;
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq 0x114bff(%rip), %rax    # 0x12c4f4
cmpq $0xff, %rax
je 0x17cc2
cmpl $0x63, %eax
jne 0x17957
leaq 0x3147f3(%rip), %rax    # 0x32c100
cmpb $0x0, 0x1(%rax)
je 0x17cc2
movb $0x0, 0x1(%rax)
movl $0x36, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c1f1
cmpl $0x0, 0x116514(%rip)    # 0x12de4c
je 0x17cc2
movl $0xff, 0x114bac(%rip)   # 0x12c4f4
movl $0x0, 0x1164fa(%rip)    # 0x12de4c
jmp 0x17cc2
cmpl $0x0, 0x116686(%rip)    # 0x12dfe4
je 0x17aaa
leaq 0x314649(%rip), %rax    # 0x32bfb4
movl (%rax), %ebp
leaq 0x31463c(%rip), %rdx    # 0x32bfb0
movl (%rdx), %r15d
cmpl %ebp, %r15d
je 0x17cc2
movl 0x116679(%rip), %r13d   # 0x12e000
leaq 0x314772(%rip), %rsi    # 0x32c100
movb 0x36(%rsi), %al
orb 0x2a(%rsi), %al
setne 0x7(%rsp)
leaq 0x314620(%rip), %r8     # 0x32bfc0
leaq 0x116641(%rip), %r12    # 0x12dfe8
movslq %r15d, %r15
movslq (%r8,%r15,4), %rax
leal 0x1(%r15), %ecx
andl $0x3f, %ecx
addl $0x2, %r15d
andl $0x3f, %r15d
movl %r15d, (%rdx)
cmpl $0x0, (%r8,%rcx,4)
je 0x17a9c
cmpl $0xe, %eax
je 0x179ec
cmpl $0x1, %eax
jne 0x17a0d
movb $0x0, 0x1(%rsi)
xorl %r13d, %r13d
movl %r13d, 0x11661d(%rip)   # 0x12e000
movl %r13d, 0x1165fa(%rip)   # 0x12dfe4
jmp 0x17a0d
movb $0x0, 0xe(%rsi)
testl %r13d, %r13d
je 0x17cc2
movslq %r13d, %rcx
leaq -0x1(%rcx), %r13
movl %r13d, 0x1165f9(%rip)   # 0x12e000
movb $0x0, -0x1(%rcx,%r12)
movl %eax, %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
cmpl $0x1c, %ecx
je 0x17b9b
cmpl $0xa, %r13d
jg 0x17a9c
cmpl $0x7f, %eax
jg 0x17a9c
leaq 0xb70e0(%rip), %rcx     # 0xceb10
cmpb $0x0, 0x7(%rsp)
je 0x17a3e
leaq 0xb7152(%rip), %rcx     # 0xceb90
movsbl (%rcx,%rax), %ebx
testl %ebx, %ebx
je 0x17a9c
movslq %ebx, %r14
callq 0x81c0
movq (%rax), %rax
movzwl (%rax,%r14,2), %eax
btl $0xa, %eax
jb 0x17a68
cmpb $0x20, %bl
je 0x17a68
andl $0x800, %eax            # imm = 0x800
je 0x17a87
movl %ebx, %edi
callq 0x8260
movslq %r13d, %rcx
leaq 0x1(%rcx), %r13
movl %r13d, 0x116583(%rip)   # 0x12e000
movb %al, (%rcx,%r12)
movb $0x0, 0x1(%rcx,%r12)
leaq 0x314522(%rip), %rdx    # 0x32bfb0
leaq 0x31466b(%rip), %rsi    # 0x32c100
leaq 0x314524(%rip), %r8     # 0x32bfc0
cmpl %ebp, %r15d
jne 0x179a7
jmp 0x17cc2
movslq 0xb7b43(%rip), %rcx     # 0xcf5f4
leaq (%rax,%rax,2), %rdx
shlq $0x6, %rdx
leaq 0xb72b0(%rip), %rbx     # 0xced70
movq %rcx, %r15
shlq $0x5, %r15
addq %rbx, %r15
addq %rdx, %r15
leaq 0x31462c(%rip), %r14    # 0x32c100
cmpb $0x0, 0x1(%r14)
je 0x17b1c
movb $0x0, 0x1(%r14)
movl $0x36, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c1f1
cmpl $0x0, 0x11634f(%rip)    # 0x12de4c
je 0x17c08
movl $0xff, 0x1149e7(%rip)   # 0x12c4f4
movl $0x0, 0x116335(%rip)    # 0x12de4c
jmp 0x17c13
leaq 0xb6e5d(%rip), %rdx     # 0xce980
movslq (%rdx), %rsi
cmpb $0x0, (%r14,%rsi)
je 0x17c42
movb $0x0, (%r14,%rsi)
movl $0x37, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c1f1
movl 0xb7aa2(%rip), %ecx     # 0xcf5f4
movslq 0x11499b(%rip), %rax    # 0x12c4f4
movl $0x5, %edx
leaq (%rax,%rax,2), %rsi
shlq $0x6, %rsi
addq %rsi, %rbx
movl $0x5, %esi
cmpl $0x2, %ecx
leal -0x1(%rcx), %ecx
cmovll %edx, %ecx
movslq %ecx, %r8
shlq $0x5, %r8
subl $0x1, %esi
setb %dil
cmpq $0x0, 0x8(%r8,%rbx)
jne 0x17cb2
testb %dil, %dil
je 0x17b6e
jmp 0x17cb2
xorl %eax, %eax
movb %al, 0x9c(%rsi)
movb %al, 0x1c(%rsi)
cmpl $0x0, 0x116453(%rip)    # 0x12e000
jle 0x17be4
movslq 0xb7a3e(%rip), %rax     # 0xcf5f4
leaq (%rax,%rax,2), %rax
leaq 0x1163df(%rip), %rcx    # 0x12dfa0
leaq (%rcx,%rax,4), %rdi
addq $-0xc, %rdi
leaq 0x116418(%rip), %rsi    # 0x12dfe8
movl $0xc, %edx
callq 0x8210
movl $0x0, 0x11641c(%rip)    # 0x12e000
movl $0x0, 0x1163f6(%rip)    # 0x12dfe4
leaq 0xb6d83(%rip), %rax     # 0xce978
cmpb $0x0, 0x4(%rax)
jne 0x17c33
movl 0xb79f3(%rip), %edi     # 0xcf5f4
callq 0x12ace
jmp 0x17c33
movsbl 0x19(%r15), %eax
movl %eax, 0x1148e1(%rip)    # 0x12c4f4
movslq 0x1148da(%rip), %rax    # 0x12c4f4
leaq 0xb798f(%rip), %rcx     # 0xcf5b0
movl (%rcx,%rax,4), %ecx
movl %ecx, 0xb79ca(%rip)     # 0xcf5f4
testq %rax, %rax
jne 0x17cc2
movl $0xff, 0x1148b7(%rip)   # 0x12c4f4
jmp 0x17cc2
movslq 0x4(%rdx), %rdx
cmpb $0x0, (%r14,%rdx)
je 0x17cd1
movb $0x0, (%r14,%rdx)
movl $0x1, %ebp
movl $0x37, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c1f1
movl 0xb797d(%rip), %ecx     # 0xcf5f4
movslq 0x114876(%rip), %rax    # 0x12c4f4
movl $0x5, %edx
leaq (%rax,%rax,2), %rsi
shlq $0x6, %rsi
addq %rsi, %rbx
cmpl $0x5, %ecx
leal 0x1(%rcx), %ecx
cmovgel %ebp, %ecx
movslq %ecx, %rdi
shlq $0x5, %rdi
subl $0x1, %edx
setb %sil
cmpq $0x0, 0x8(%rdi,%rbx)
jne 0x17cb2
testb %sil, %sil
je 0x17c8e
movl %ecx, 0xb793c(%rip)     # 0xcf5f4
leaq 0xb78f1(%rip), %rdx     # 0xcf5b0
movl %ecx, (%rdx,%rax,4)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4, %eax
jne 0x17cea
cmpb $0x0, 0x15(%r14)
je 0x17da3
movb $0x1, 0x114811(%rip)    # 0x12c4f9
jmp 0x17cc2
movb 0x9c(%r14), %dl
orb 0x1c(%r14), %dl
je 0x17d4b
xorl %eax, %eax
movb %al, 0x9c(%r14)
movb %al, 0x1c(%r14)
movl $0x35, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c1f1
movsbl 0x18(%r15), %eax
testl %eax, %eax
je 0x17dc8
movl %eax, 0x1147c7(%rip)    # 0x12c4f4
cltq
leaq 0xb787a(%rip), %rcx     # 0xcf5b0
movl (%rcx,%rax,4), %eax
movl %eax, 0xb78b5(%rip)     # 0xcf5f4
movb $0x1, 0x116297(%rip)    # 0x12dfdd
jmp 0x17cc2
movl %eax, %edx
andl $-0x2, %edx
cmpl $0x8, %edx
jne 0x17db3
movb 0xcb(%r14), %dl
orb 0x4b(%r14), %dl
je 0x17e07
xorl %edx, %edx
movb %dl, 0xcb(%r14)
movb %dl, 0x4b(%r14)
cmpl $0x2, %ecx
je 0x17e64
cmpl $0x1, %ecx
jne 0x17ff9
cmpl $0x8, %eax
jne 0x17f9a
movl 0xb7868(%rip), %edi     # 0xcf5fc
testl %edi, %edi
jle 0x17ff9
decl %edi
jmp 0x17e51
cmpb $0x0, 0x31(%r14)
jne 0x17c33
jmp 0x17cc2
cmpb $0x0, 0x10(%r14)
je 0x17cc2
movb $0x0, 0x10(%r14)
jmp 0x17ce1
movl 0x114726(%rip), %eax    # 0x12c4f4
addl $-0x2, %eax
cmpl $0x5, %eax
ja 0x17cc2
leaq 0x746f3(%rip), %rcx     # 0x8c4d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0xb7804(%rip), %eax     # 0xcf5f4
movl %eax, 0x11620e(%rip)    # 0x12e004
leaq 0xcaa13(%rip), %rdi     # 0xe2810
callq 0x16f82
jmp 0x17c33
movb 0xcd(%r14), %dl
orb 0x4d(%r14), %dl
je 0x17cc2
xorl %edx, %edx
movb %dl, 0xcd(%r14)
movb %dl, 0x4d(%r14)
cmpl $0x2, %ecx
je 0x17fa8
cmpl $0x1, %ecx
jne 0x17ff9
cmpl $0x8, %eax
jne 0x17fe6
movl 0xb77b6(%rip), %edi     # 0xcf5fc
cmpl $0xf, %edi
jg 0x17ff9
incl %edi
movl %edi, 0xb77a5(%rip)     # 0xcf5fc
shll $0xb, %edi
callq 0x1c5a1
jmp 0x17ff9
movl 0xb778e(%rip), %eax     # 0xcf5f8
testl %eax, %eax
jle 0x17ff9
leal -0x1(%rax), %ecx
movl %ecx, 0xb777d(%rip)     # 0xcf5f8
leal -0x8(,%rax,8), %edi
jmp 0x17fc3
movl 0xb7767(%rip), %eax     # 0xcf5f4
movl %eax, 0x11614d(%rip)    # 0x12dfe0
jmp 0x17cc2
cmpl $0x3, 0xb7755(%rip)     # 0xcf5f4
jne 0x17cc2
movabsq $0x424f422044414548, %rax # imm = 0x424F422044414548
movq 0xb6eaa(%rip), %rcx     # 0xced60
xorq %rax, %rcx
movl 0xb6ea9(%rip), %edx     # 0xced68
xorq $0x4e4f20, %rdx         # imm = 0x4E4F20
orq %rcx, %rdx
je 0x1801d
movq %rax, 0xb6e8a(%rip)     # 0xced60
movl $0x4e4f20, 0xb6e88(%rip) # imm = 0x4E4F20
leaq 0xb79f9(%rip), %rax     # 0xcf8e0
movl $0x1, (%rax)
jmp 0x17cc2
xorl %eax, %eax
callq 0x1c68f
leaq 0xb6a78(%rip), %rax     # 0xce978
cmpb $0x0, 0x4(%rax)
jne 0x17c33
movl 0xb76e4(%rip), %edi     # 0xcf5f4
callq 0x11e3c
jmp 0x17c33
xorl %ebp, %ebp
movb %bpl, 0x9c(%r14)
movb %bpl, 0x1c(%r14)
movl $0x1, 0x1160b3(%rip)    # 0x12dfe4
leaq 0x31407c(%rip), %rax    # 0x32bfb4
movl (%rax), %eax
leaq 0x31406f(%rip), %rcx    # 0x32bfb0
movl %eax, (%rcx)
movslq 0xb76aa(%rip), %rax     # 0xcf5f4
leaq (%rax,%rax,2), %rax
leaq 0x11604b(%rip), %rcx    # 0x12dfa0
leaq (%rcx,%rax,4), %rbx
addq $-0xc, %rbx
leaq 0x74b3b(%rip), %rsi     # 0x8ca9f
movq %rbx, %rdi
callq 0x8c40
testl %eax, %eax
je 0x17fca
leaq 0x116071(%rip), %r14    # 0x12dfe8
movl $0xc, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8210
movq %r14, %rdi
callq 0x85a0
movl %eax, 0x11606b(%rip)    # 0x12e000
jmp 0x17cc2
movl 0x11605c(%rip), %eax    # 0x12dffc
testl %eax, %eax
jle 0x17ff9
decl %eax
jmp 0x17ff3
movl 0xb764a(%rip), %eax     # 0xcf5f8
cmpl $0xf, %eax
jg 0x17ff9
leal 0x1(%rax), %ecx
movl %ecx, 0xb763c(%rip)     # 0xcf5f8
leal 0x8(,%rax,8), %edi
callq 0x1c5a0
jmp 0x17ff9
movl %ebp, 0x116020(%rip)    # 0x12dff0
movq $0x0, 0x11600d(%rip) # 0x12dfe8
movl %ebp, 0x11601f(%rip)    # 0x12e000
jmp 0x17cc2
movl 0x116010(%rip), %eax    # 0x12dffc
cmpl $0xf, %eax
jg 0x17ff9
incl %eax
movl %eax, 0x116003(%rip)    # 0x12dffc
movl $0x34, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1c1f1
movabsq $0x46464f20424f42, %rcx # imm = 0x46464F20424F42
movq %rcx, 0xb6d37(%rip)     # 0xced65
movq %rax, 0xb6d2b(%rip)     # 0xced60
leaq 0xb78a4(%rip), %rax     # 0xcf8e0
movl $0x0, (%rax)
jmp 0x17cc2