// File: mindbeast[P]rnes/sdl.cpp
// Function: Rnes::Sdl::parseInput()
void Sdl::parseInput() {
  SDL_Event event;
  int button;

  while (SDL_PollEvent(&event)) {
    switch (event.type) {
    case SDL_KEYDOWN:
    case SDL_KEYUP:
      switch (event.key.keysym.sym) {
      case SDLK_UP:
      case SDLK_w:
        button = BUTTON_UP;
        break;
      case SDLK_DOWN:
      case SDLK_s:
        button = BUTTON_DOWN;
        break;
      case SDLK_LEFT:
      case SDLK_a:
        button = BUTTON_LEFT;
        break;
      case SDLK_RIGHT:
      case SDLK_d:
        button = BUTTON_RIGHT;
        break;
      case SDLK_RETURN:
      case SDLK_KP_ENTER:
        button = BUTTON_START;
        break;
      case SDLK_RSHIFT:
      case SDLK_LSHIFT:
        button = BUTTON_SELECT;
        break;
      case SDLK_z:
      case SDLK_n:
        button = BUTTON_A;
        break;
      case SDLK_x:
      case SDLK_m:
        button = BUTTON_B;
        break;
      case SDLK_k:
        button = BUTTON_SAVE;
        break;
      case SDLK_l:
        button = BUTTON_RESTORE;
        break;
      default:
        continue;
      }
      if (event.type == SDL_KEYDOWN) {
        buttonState[button] = true;
      } else {
        buttonState[button] = false;
      }
      break;
    case SDL_QUIT:
      exit(1);
      break;
    default:
      break;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xebb0
cmpl $0x0, %eax
je 0x419e0
movl -0x40(%rbp), %eax
movl %eax, -0x54(%rbp)
subl $0x100, %eax            # imm = 0x100
je 0x419cf
jmp 0x41849
movl -0x54(%rbp), %eax
addl $0xfffffd00, %eax       # imm = 0xFFFFFD00
subl $0x1, %eax
ja 0x419d9
jmp 0x4185c
movl -0x2c(%rbp), %eax
movl %eax, -0x58(%rbp)
subl $0xd, %eax
je 0x4196d
jmp 0x4186d
movl -0x58(%rbp), %eax
subl $0x61, %eax
je 0x4195b
jmp 0x4187b
movl -0x58(%rbp), %eax
subl $0x64, %eax
je 0x41964
jmp 0x41889
movl -0x58(%rbp), %eax
subl $0x6b, %eax
je 0x41991
jmp 0x41897
movl -0x58(%rbp), %eax
subl $0x6c, %eax
je 0x4199a
jmp 0x418a5
movl -0x58(%rbp), %eax
subl $0x6d, %eax
je 0x41988
jmp 0x418b3
movl -0x58(%rbp), %eax
subl $0x6e, %eax
je 0x4197f
jmp 0x418c1
movl -0x58(%rbp), %eax
subl $0x73, %eax
je 0x41952
jmp 0x418cf
movl -0x58(%rbp), %eax
subl $0x77, %eax
je 0x41949
jmp 0x418d9
movl -0x58(%rbp), %eax
subl $0x78, %eax
je 0x41988
jmp 0x418e7
movl -0x58(%rbp), %eax
subl $0x7a, %eax
je 0x4197f
jmp 0x418f5
movl -0x58(%rbp), %eax
subl $0x4000004f, %eax       # imm = 0x4000004F
je 0x41964
jmp 0x41901
movl -0x58(%rbp), %eax
subl $0x40000050, %eax       # imm = 0x40000050
je 0x4195b
jmp 0x4190d
movl -0x58(%rbp), %eax
subl $0x40000051, %eax       # imm = 0x40000051
je 0x41952
jmp 0x41919
movl -0x58(%rbp), %eax
subl $0x40000052, %eax       # imm = 0x40000052
je 0x41949
jmp 0x41925
movl -0x58(%rbp), %eax
subl $0x40000058, %eax       # imm = 0x40000058
je 0x4196d
jmp 0x41931
movl -0x58(%rbp), %eax
subl $0x400000e1, %eax       # imm = 0x400000E1
je 0x41976
jmp 0x4193d
movl -0x58(%rbp), %eax
subl $0x400000e5, %eax       # imm = 0x400000E5
je 0x41976
jmp 0x419a3
movl $0x0, -0x44(%rbp)
jmp 0x419a8
movl $0x1, -0x44(%rbp)
jmp 0x419a8
movl $0x2, -0x44(%rbp)
jmp 0x419a8
movl $0x3, -0x44(%rbp)
jmp 0x419a8
movl $0x4, -0x44(%rbp)
jmp 0x419a8
movl $0x5, -0x44(%rbp)
jmp 0x419a8
movl $0x6, -0x44(%rbp)
jmp 0x419a8
movl $0x7, -0x44(%rbp)
jmp 0x419a8
movl $0x8, -0x44(%rbp)
jmp 0x419a8
movl $0x9, -0x44(%rbp)
jmp 0x419a8
jmp 0x41824
cmpl $0x300, -0x40(%rbp)     # imm = 0x300
jne 0x419c0
movq -0x50(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $0x1, 0x28(%rax,%rcx)
jmp 0x419cd
movq -0x50(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $0x0, 0x28(%rax,%rcx)
jmp 0x419db
movl $0x1, %edi
callq 0xe730
jmp 0x419db
jmp 0x41824
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)