// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movslq 0x10ef9b(%rip), %rax    # 0x1254f4
cmpq $0xff, %rax
je 0x16848
cmpl $0x63, %eax
jne 0x165b4
leaq 0x30ebaf(%rip), %rax    # 0x325120
cmpb $0x0, 0x1(%rax)
je 0x16848
movb $0x0, 0x1(%rax)
pushq $0x36
popq %rdi
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1ab2a
cmpl $0x0, 0x1108c4(%rip)    # 0x126e5c
je 0x16848
movl $0xff, 0x10ef4c(%rip)   # 0x1254f4
andl $0x0, 0x1108ad(%rip)    # 0x126e5c
jmp 0x16848
cmpl $0x0, 0x110a49(%rip)    # 0x127004
je 0x16748
leaq 0x30ea0c(%rip), %rax    # 0x324fd4
movl (%rax), %ebp
leaq 0x30e9ff(%rip), %r15    # 0x324fd0
movl (%r15), %r12d
movl 0x110a45(%rip), %r13d   # 0x127020
leaq 0x30eb3e(%rip), %rdx    # 0x325120
movb 0x36(%rdx), %al
orb 0x2a(%rdx), %al
setne %sil
leaq 0x30e9ed(%rip), %r14    # 0x324fe0
leaq 0x110a0e(%rip), %rdi    # 0x127008
leaq 0xb150f(%rip), %r8      # 0xc7b10
leaq 0xb1588(%rip), %r9      # 0xc7b90
cmpl %ebp, %r12d
je 0x16848
movslq %r12d, %rax
movslq (%r14,%rax,4), %rax
leal 0x1(%r12), %ecx
andl $0x3f, %ecx
addl $0x2, %r12d
andl $0x3f, %r12d
movl %r12d, (%r15)
cmpl $0x0, (%r14,%rcx,4)
je 0x16608
cmpl $0xe, %eax
je 0x16653
cmpl $0x1, %eax
jne 0x16675
movb $0x0, 0x1(%rdx)
andl $0x0, 0x1109d9(%rip)    # 0x127020
andl $0x0, 0x1109b6(%rip)    # 0x127004
xorl %r13d, %r13d
jmp 0x16686
movb $0x0, 0xe(%rdx)
testl %r13d, %r13d
je 0x16848
movslq %r13d, %rcx
leaq -0x1(%rcx), %r13
movl %r13d, 0x1109b2(%rip)   # 0x127020
movb $0x0, -0x1(%rcx,%rdi)
jmp 0x16686
movl %eax, %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
cmpl $0x1c, %ecx
je 0x16939
cmpl $0xa, %r13d
jg 0x16608
cmpl $0x7f, %eax
jg 0x16608
movq %r8, %rcx
testb %sil, %sil
je 0x166a4
movq %r9, %rcx
movsbl (%rcx,%rax), %ebx
testl %ebx, %ebx
je 0x16608
movslq %ebx, %rax
movq %rax, 0x10(%rsp)
movb %sil, 0xf(%rsp)
callq 0x81c0
leaq 0xb14c7(%rip), %r9      # 0xc7b90
leaq 0xb1440(%rip), %r8      # 0xc7b10
leaq 0x110931(%rip), %rdi    # 0x127008
movb 0xf(%rsp), %sil
leaq 0x30ea3d(%rip), %rdx    # 0x325120
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
btl $0xa, %eax
jb 0x16705
cmpb $0x20, %bl
je 0x16705
andl $0x800, %eax            # imm = 0x800
je 0x16608
movl %ebx, %edi
callq 0x8260
leaq 0xb147d(%rip), %r9      # 0xc7b90
leaq 0xb13f6(%rip), %r8      # 0xc7b10
leaq 0x1108e7(%rip), %rdi    # 0x127008
movb 0xf(%rsp), %sil
leaq 0x30e9f3(%rip), %rdx    # 0x325120
movslq %r13d, %rcx
leaq 0x1(%rcx), %r13
movl %r13d, 0x1108e5(%rip)   # 0x127020
movb %al, (%rcx,%rdi)
movb $0x0, 0x1(%rcx,%rdi)
jmp 0x16608
movslq 0xb1ea5(%rip), %rcx     # 0xc85f4
imulq $0xc0, %rax, %rdx
leaq 0xb1613(%rip), %r14     # 0xc7d70
movq %rcx, %r15
shlq $0x5, %r15
addq %r14, %r15
addq %rdx, %r15
leaq 0x30e9af(%rip), %rbx    # 0x325120
cmpb $0x0, 0x1(%rbx)
je 0x167a8
movb $0x0, 0x1(%rbx)
pushq $0x36
popq %rdi
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1ab2a
cmpl $0x0, 0x1106c8(%rip)    # 0x126e5c
je 0x1681d
andl $0x0, 0x1106bb(%rip)    # 0x126e5c
movl $0xff, %eax
jmp 0x16822
leaq 0xb11d1(%rip), %rdx     # 0xc7980
movslq (%rdx), %rsi
cmpb $0x0, (%rbx,%rsi)
je 0x16857
movb $0x0, (%rbx,%rsi)
pushq $0x37
popq %rdi
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1ab2a
movl 0xb1e1c(%rip), %edi     # 0xc85f4
movslq 0x10ed15(%rip), %rax    # 0x1254f4
pushq $0x7
popq %rcx
pushq $0x5
popq %rdx
leaq 0xb1dc4(%rip), %rsi     # 0xc85b0
imulq $0xc0, %rax, %r8
addq %r8, %r14
decl %ecx
je 0x16848
cmpl $0x2, %edi
leal -0x1(%rdi), %edi
cmovll %edx, %edi
movl %edi, 0xb1deb(%rip)     # 0xc85f4
movl %edi, (%rsi,%rax,4)
movslq %edi, %r8
shlq $0x5, %r8
cmpq $0x0, 0x8(%r8,%r14)
je 0x167f6
jmp 0x16848
movsbl 0x19(%r15), %eax
movl %eax, 0x10eccc(%rip)    # 0x1254f4
cltq
leaq 0xb1d7f(%rip), %rcx     # 0xc85b0
movl (%rcx,%rax,4), %ecx
movl %ecx, 0xb1dba(%rip)     # 0xc85f4
testl %eax, %eax
jne 0x16848
movl $0xff, 0x10ecac(%rip)   # 0x1254f4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x4(%rdx), %rdx
cmpb $0x0, (%rbx,%rdx)
je 0x168c1
movb $0x0, (%rbx,%rdx)
pushq $0x37
popq %rdi
pushq $0x1
popq %rbx
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl %ebx, %r8d
callq 0x1ab2a
movl 0xb1d75(%rip), %esi     # 0xc85f4
movslq 0x10ec6e(%rip), %rax    # 0x1254f4
pushq $0x7
popq %rcx
leaq 0xb1d20(%rip), %rdx     # 0xc85b0
imulq $0xc0, %rax, %rdi
addq %rdi, %r14
decl %ecx
je 0x16848
cmpl $0x5, %esi
leal 0x1(%rsi), %esi
cmovgel %ebx, %esi
movl %esi, 0xb1d47(%rip)     # 0xc85f4
movl %esi, (%rdx,%rax,4)
movslq %esi, %rdi
shlq $0x5, %rdi
cmpq $0x0, 0x8(%rdi,%r14)
je 0x1689a
jmp 0x16848
cmpl $0x4, %eax
jne 0x168dc
cmpb $0x0, 0x15(%rbx)
je 0x169f5
movb $0x1, 0x10ec22(%rip)    # 0x1254f9
jmp 0x16848
movb 0x9c(%rbx), %dl
orb 0x1c(%rbx), %dl
je 0x169a1
xorl %eax, %eax
movb %al, 0x9c(%rbx)
movb %al, 0x1c(%rbx)
pushq $0x35
popq %rdi
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1ab2a
movsbl 0x18(%r15), %eax
testl %eax, %eax
je 0x16a17
movl %eax, 0x10ebd9(%rip)    # 0x1254f4
cltq
leaq 0xb1c8c(%rip), %rcx     # 0xc85b0
movl (%rcx,%rax,4), %eax
movl %eax, 0xb1cc7(%rip)     # 0xc85f4
movb $0x1, 0x1106c9(%rip)    # 0x126ffd
jmp 0x16848
xorl %eax, %eax
movb %al, 0x9c(%rdx)
movb %al, 0x1c(%rdx)
testl %r13d, %r13d
jle 0x16979
movslq 0xb1ca4(%rip), %rax     # 0xc85f4
imulq $0xc, %rax, %rax
leaq 0x110665(%rip), %rcx    # 0x126fc0
leaq (%rax,%rcx), %rdi
addq $-0xc, %rdi
leaq 0x11069e(%rip), %rsi    # 0x127008
pushq $0xc
popq %rdx
callq 0x8210
andl $0x0, 0x1106a7(%rip)    # 0x127020
andl $0x0, 0x110684(%rip)    # 0x127004
leaq 0xb0ff1(%rip), %rax     # 0xc7978
cmpb $0x0, 0x4(%rax)
jne 0x1683e
movl 0xb1c5d(%rip), %edi     # 0xc85f4
callq 0x11894
jmp 0x1683e
movl %eax, %edx
andl $-0x2, %edx
cmpl $0x8, %edx
jne 0x16a04
movb 0xcb(%rbx), %dl
orb 0x4b(%rbx), %dl
je 0x16a56
xorl %edx, %edx
movb %dl, 0xcb(%rbx)
movb %dl, 0x4b(%rbx)
cmpl $0x2, %ecx
je 0x16aaf
cmpl $0x1, %ecx
jne 0x16c3d
cmpl $0x8, %eax
jne 0x16bdf
movl 0xb1c16(%rip), %edi     # 0xc85fc
testl %edi, %edi
jle 0x16c3d
decl %edi
jmp 0x16a9c
cmpb $0x0, 0x31(%rbx)
jne 0x1683e
jmp 0x16848
cmpb $0x0, 0x10(%rbx)
je 0x16848
movb $0x0, 0x10(%rbx)
jmp 0x168d0
movl 0x10ead7(%rip), %eax    # 0x1254f4
addl $-0x2, %eax
cmpl $0x5, %eax
ja 0x16848
leaq 0x6aab8(%rip), %rcx     # 0x814e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0xb1bb5(%rip), %eax     # 0xc85f4
movl %eax, 0x1105df(%rip)    # 0x127024
leaq 0xc4dc4(%rip), %rdi     # 0xdb810
callq 0x15bef
jmp 0x1683e
movb 0xcd(%rbx), %dl
orb 0x4d(%rbx), %dl
je 0x16848
xorl %edx, %edx
movb %dl, 0xcd(%rbx)
movb %dl, 0x4d(%rbx)
cmpl $0x2, %ecx
je 0x16bed
cmpl $0x1, %ecx
jne 0x16c3d
cmpl $0x8, %eax
jne 0x16c2a
movl 0xb1b6b(%rip), %edi     # 0xc85fc
cmpl $0xf, %edi
jg 0x16c3d
incl %edi
movl %edi, 0xb1b5a(%rip)     # 0xc85fc
shll $0xb, %edi
callq 0x1aeb4
jmp 0x16c3d
movl 0xb1b43(%rip), %eax     # 0xc85f8
testl %eax, %eax
jle 0x16c3d
leal -0x1(%rax), %ecx
movl %ecx, 0xb1b32(%rip)     # 0xc85f8
leal -0x8(,%rax,8), %edi
jmp 0x16c08
movl 0xb1b1c(%rip), %eax     # 0xc85f4
movl %eax, 0x110522(%rip)    # 0x127000
jmp 0x16848
cmpl $0x3, 0xb1b0a(%rip)     # 0xc85f4
jne 0x16848
leaq 0xb1269(%rip), %rdi     # 0xc7d60
leaq 0x6b02d(%rip), %rsi     # 0x81b2b
pushq $0xc
popq %rdx
callq 0x89f0
testl %eax, %eax
je 0x16c5d
movabsq $0x424f422044414548, %rax # imm = 0x424F422044414548
movq %rax, 0xb1241(%rip)     # 0xc7d60
movl $0x4e4f20, 0xb123f(%rip) # imm = 0x4E4F20
leaq 0xb1db0(%rip), %rax     # 0xc88e0
movl $0x1, (%rax)
jmp 0x16848
xorl %eax, %eax
callq 0x1afa5
leaq 0xb0e2f(%rip), %rax     # 0xc7978
cmpb $0x0, 0x4(%rax)
jne 0x1683e
movl 0xb1a9b(%rip), %edi     # 0xc85f4
callq 0x10cbc
jmp 0x1683e
xorl %eax, %eax
movb %al, 0x9c(%rbx)
movb %al, 0x1c(%rbx)
movl $0x1, 0x11048c(%rip)    # 0x127004
leaq 0x30e455(%rip), %rax    # 0x324fd4
movl (%rax), %eax
leaq 0x30e448(%rip), %rcx    # 0x324fd0
movl %eax, (%rcx)
movslq 0xb1a63(%rip), %rax     # 0xc85f4
imulq $0xc, %rax, %rax
leaq 0x110424(%rip), %rcx    # 0x126fc0
leaq (%rax,%rcx), %rbx
addq $-0xc, %rbx
leaq 0x6af78(%rip), %rsi     # 0x81b23
movq %rbx, %rdi
callq 0x8c40
testl %eax, %eax
je 0x16c0f
leaq 0x11044a(%rip), %r14    # 0x127008
pushq $0xc
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8210
movq %r14, %rdi
callq 0x85a0
movl %eax, 0x110446(%rip)    # 0x127020
jmp 0x16848
movl 0x110437(%rip), %eax    # 0x12701c
testl %eax, %eax
jle 0x16c3d
decl %eax
jmp 0x16c37
movl 0xb1a05(%rip), %eax     # 0xc85f8
cmpl $0xf, %eax
jg 0x16c3d
leal 0x1(%rax), %ecx
movl %ecx, 0xb19f7(%rip)     # 0xc85f8
leal 0x8(,%rax,8), %edi
callq 0x1aeb3
jmp 0x16c3d
andl $0x0, 0x1103fa(%rip)    # 0x127010
andq $0x0, 0x1103ea(%rip)    # 0x127008
andl $0x0, 0x1103fb(%rip)    # 0x127020
jmp 0x16848
movl 0x1103ec(%rip), %eax    # 0x12701c
cmpl $0xf, %eax
jg 0x16c3d
incl %eax
movl %eax, 0x1103df(%rip)    # 0x12701c
pushq $0x34
popq %rdi
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1ab2a
movabsq $0x46464f20424f42, %rax # imm = 0x46464F20424F42
movq %rax, 0xb10f7(%rip)     # 0xc7d65
movabsq $0x424f422044414548, %rax # imm = 0x424F422044414548
movq %rax, 0xb10e1(%rip)     # 0xc7d60
leaq 0xb1c5a(%rip), %rax     # 0xc88e0
andl $0x0, (%rax)
jmp 0x16848