// File: Dalgona[P]mine/mine.cpp
// Function: name_input(score_t&)
void name_input(score_t &score)
{
  int pos = 0;
  int ch;

  curs_set(0);
  WINDOW *nameWin;
  auto drawForm = [&]()
  {
    clear();
    refresh();
    nameWin = newwin(13, 39, scr->getRows() / 2 - 6, scr->getCols() / 2 - 19);
    wattron(nameWin, A_BOLD);
    NIC(18, mvwprintw(nameWin, 0, 5, "C O N G R A T U L A T I O N S"););
    NIC(19, mvwprintw(nameWin, 2, 4, "A   N E W   H I G H   S C O R E"););
    wattroff(nameWin, A_BOLD);
    NIC(11, mvwprintw(nameWin, 4, 0, "What is your name?");
           mvwprintw(nameWin, 8, 0, "Accepted Characters: A-Z, 0-9 and SPACE"););
    NIC(23, mvwprintw(nameWin, 12, 5, "BkSp: ERASE     Enter: DECIDE"););
  };
  drawForm();

  while (true)
  {
    for (int i = 0; i < pos; i++)
      NIC(31, mvwprintw(nameWin, 6, 4 * i, " %c ", score.name[i]););
    for (int i = pos; i < 10; i++)
      NIC(30, mvwprintw(nameWin, 6, 4 * i, " %c ", score.name[i]););
    wrefresh(nameWin);
    ch = getch();
    if ((ch >= 'A' && ch <= 'Z')
        || (ch >= '0' && ch <= '9')
        || ch == ' ')
    { if (pos < 10) score.name[pos++] = ch; }
    else if (ch >= 'a' && ch <= 'z')
    { if (pos < 10) score.name[pos++] = ch - 32; }
    else if (ch == 8 || ch == KEY_BACKSPACE)
    { if (pos != 0) score.name[--pos] = ' '; }
    else if (ch == KEY_RESIZE)
    { scr->updateMaxYX(); delwin(nameWin); drawForm(); }
    else if (ch == 10)
      break;
  }

  delwin(nameWin);
  curs_set(1);
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movl $0x0, 0xcc(%rsp)
xorl %edi, %edi
callq 0x21c0
leaq 0xc0(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x4240
movl $0x0, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jge 0x3cb8
movq 0x16664(%rip), %rax     # 0x1a268
movq %rax, 0x18(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0xb4(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x78(%rsp), %rsi
callq 0x4510
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rcx
movl $0x1f, %edx
callq 0x11400
jmp 0x3c75
leaq 0x90(%rsp), %rdi
callq 0x8c90
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x3be9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x8c90
jmp 0x3efd
movl 0xcc(%rsp), %eax
movl %eax, 0x68(%rsp)
cmpl $0xa, 0x68(%rsp)
jge 0x3d6f
movq 0x16593(%rip), %rax     # 0x1a268
movq %rax, (%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x10(%rsp)
leaq 0x30(%rsp), %rsi
callq 0x45c0
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
movl $0x1e, %edx
callq 0x11400
jmp 0x3d38
leaq 0x48(%rsp), %rdi
callq 0x8c90
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x3cc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x8c90
jmp 0x3efd
movq 0xc0(%rsp), %rdi
callq 0x22b0
movq 0x16255(%rip), %rax     # 0x19fd8
movq (%rax), %rdi
callq 0x20f0
movl %eax, 0xc8(%rsp)
cmpl $0x41, 0xc8(%rsp)
jl 0x3da6
cmpl $0x5a, 0xc8(%rsp)
jle 0x3dc4
cmpl $0x30, 0xc8(%rsp)
jl 0x3dba
cmpl $0x39, 0xc8(%rsp)
jle 0x3dc4
cmpl $0x20, 0xc8(%rsp)
jne 0x3dfd
cmpl $0xa, 0xcc(%rsp)
jge 0x3df8
movl 0xc8(%rsp), %eax
movb %al, %dl
movq 0xd0(%rsp), %rax
movl 0xcc(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0xcc(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x3ed9
cmpl $0x61, 0xc8(%rsp)
jl 0x3e4d
cmpl $0x7a, 0xc8(%rsp)
jg 0x3e4d
cmpl $0xa, 0xcc(%rsp)
jge 0x3e48
movl 0xc8(%rsp), %eax
subl $0x20, %eax
movb %al, %dl
movq 0xd0(%rsp), %rax
movl 0xcc(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0xcc(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x3ed7
cmpl $0x8, 0xc8(%rsp)
je 0x3e64
cmpl $0x107, 0xc8(%rsp) # imm = 0x107
jne 0x3e90
cmpl $0x0, 0xcc(%rsp)
je 0x3e8e
movq 0xd0(%rsp), %rax
movl 0xcc(%rsp), %ecx
addl $-0x1, %ecx
movl %ecx, 0xcc(%rsp)
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
jmp 0x3ed5
cmpl $0x19a, 0xc8(%rsp) # imm = 0x19A
jne 0x3ec5
movq 0x163c4(%rip), %rdi     # 0x1a268
callq 0x11080
movq 0xc0(%rsp), %rdi
callq 0x2060
leaq 0xb8(%rsp), %rdi
callq 0x4240
jmp 0x3ed3
cmpl $0xa, 0xc8(%rsp)
jne 0x3ed1
jmp 0x3ede
jmp 0x3ed3
jmp 0x3ed5
jmp 0x3ed7
jmp 0x3ed9
jmp 0x3bde
movq 0xc0(%rsp), %rdi
callq 0x2060
movl $0x1, %edi
callq 0x21c0
addq $0xd8, %rsp
retq
movq 0x70(%rsp), %rdi
callq 0x2400
nopw (%rax,%rax)