// File: /workspace/github_cpp_makefile_star2_O3/rockytriton[P]dreamsys_emu_gb/src/ui.cpp
// Function: dsemu::ui::handleEvents()
void handleEvents() {

    //io::startDown = true;

    SDL_Event e;
    if (SDL_PollEvent(&e) > 0)
    {
        SDL_UpdateWindowSurface(sdlWindow);

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_p) {
            cpu::paused = !cpu::paused;
            cout << "Paused: " << cpu::paused << endl;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_RETURN) {
            //cout << "KEYDOWN" << endl;
            io::startDown = true;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_RETURN) {
            //cout << "KEYUP" << endl;
            io::startDown = false;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_CAPSLOCK) {
            cout << "KEYDOWN" << endl;
            io::selectDown = true;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_CAPSLOCK) {
            cout << "KEYUP" << endl;
            io::selectDown = false;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_a) {
            cout << "KEYDOWN a" << endl;
            io::aDown = true;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_a) {
            cout << "KEYUP a" << endl;
            io::aDown = false;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_LEFT) {
            cout << "KEYDOWN Left" << endl;
            io::leftDown = true;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_LEFT) {
            cout << "KEYUP Left" << endl;
            io::leftDown = false;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_RIGHT) {
            cout << "KEYDOWN rightDown" << endl;
            io::rightDown = true;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_RIGHT) {
            cout << "KEYUP rightDown" << endl;
            io::rightDown = false;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_UP) {
            cout << "KEYDOWN upDown" << endl;
            io::upDown = true;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_UP) {
            cout << "KEYUP upDown" << endl;
            io::upDown = false;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_DOWN) {
            cout << "KEYDOWN downDown" << endl;
            io::downDown = true;
            //sleepMs(1000);
        }

        if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_DOWN) {
            cout << "KEYUP downDown" << endl;
            io::downDown = false;
            //sleepMs(1000);
        }

        if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_CLOSE) {
            exit(0);
        }
    }
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rsp, %rdi
callq 0x3180
testl %eax, %eax
jle 0x12073
movq 0x2b785(%rip), %rdi     # 0x3d748
callq 0x32f0
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
movl %eax, %edx
xorl $0x300, %edx            # imm = 0x300
movl %ecx, %esi
xorl $0x70, %esi
orl %edx, %esi
jne 0x12043
leaq 0x6521(%rip), %r14      # 0x18508
xorb $0x1, (%r14)
movq 0x5fde(%rip), %rbx      # 0x17fd0
leaq 0x1c07(%rip), %rsi      # 0x13c00
movl $0x8, %edx
movq %rbx, %rdi
callq 0x3300
movzbl (%r14), %esi
movq %rbx, %rdi
callq 0x33e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
movl %eax, %edx
xorl $0x300, %edx            # imm = 0x300
movl %ecx, %edi
xorl $0xd, %edi
movb $0x1, %sil
movl %edx, %r8d
orl %edi, %r8d
je 0x12069
movl %eax, %esi
xorl $0x301, %esi            # imm = 0x301
orl %edi, %esi
jne 0x1207b
xorl %esi, %esi
leaq 0x6508(%rip), %rax      # 0x18578
movb %sil, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r14
retq
movl %ecx, %esi
xorl $0x40000039, %esi       # imm = 0x40000039
orl %esi, %edx
jne 0x120da
movq 0x5f42(%rip), %rbx      # 0x17fd0
leaq 0x1b74(%rip), %rsi      # 0x13c09
movl $0x7, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x64aa(%rip), %rax      # 0x1857a
movb $0x1, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0x1213c
cmpl $0x40000039, %ecx       # imm = 0x40000039
jne 0x1213c
movq 0x5ee0(%rip), %rbx      # 0x17fd0
leaq 0x1b1a(%rip), %rsi      # 0x13c11
movl $0x5, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x6448(%rip), %rax      # 0x1857a
movb $0x0, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0x1219b
cmpl $0x61, %ecx
jne 0x1219b
movq 0x5e81(%rip), %rbx      # 0x17fd0
leaq 0x1ac1(%rip), %rsi      # 0x13c17
movl $0x9, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x63e8(%rip), %rax      # 0x18579
movb $0x1, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0x121fa
cmpl $0x61, %ecx
jne 0x121fa
movq 0x5e22(%rip), %rbx      # 0x17fd0
leaq 0x1a6c(%rip), %rsi      # 0x13c21
movl $0x7, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x6389(%rip), %rax      # 0x18579
movb $0x0, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0x1225c
cmpl $0x40000050, %ecx       # imm = 0x40000050
jne 0x1225c
movq 0x5dc0(%rip), %rbx      # 0x17fd0
leaq 0x1a12(%rip), %rsi      # 0x13c29
movl $0xc, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x632a(%rip), %rax      # 0x1857c
movb $0x1, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0x122be
cmpl $0x40000050, %ecx       # imm = 0x40000050
jne 0x122be
movq 0x5d5e(%rip), %rbx      # 0x17fd0
leaq 0x19bd(%rip), %rsi      # 0x13c36
movl $0xa, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x62c8(%rip), %rax      # 0x1857c
movb $0x0, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0x12320
cmpl $0x4000004f, %ecx       # imm = 0x4000004F
jne 0x12320
movq 0x5cfc(%rip), %rbx      # 0x17fd0
leaq 0x1966(%rip), %rsi      # 0x13c41
movl $0x11, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x6265(%rip), %rax      # 0x1857b
movb $0x1, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0x12382
cmpl $0x4000004f, %ecx       # imm = 0x4000004F
jne 0x12382
movq 0x5c9a(%rip), %rbx      # 0x17fd0
leaq 0x1916(%rip), %rsi      # 0x13c53
movl $0xf, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x6203(%rip), %rax      # 0x1857b
movb $0x0, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0x123e4
cmpl $0x40000052, %ecx       # imm = 0x40000052
jne 0x123e4
movq 0x5c38(%rip), %rbx      # 0x17fd0
leaq 0x18c4(%rip), %rsi      # 0x13c63
movl $0xe, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x61a3(%rip), %rax      # 0x1857d
movb $0x1, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0x12446
cmpl $0x40000052, %ecx       # imm = 0x40000052
jne 0x12446
movq 0x5bd6(%rip), %rbx      # 0x17fd0
leaq 0x1871(%rip), %rsi      # 0x13c72
movl $0xc, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x6141(%rip), %rax      # 0x1857d
movb $0x0, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0x124a8
cmpl $0x40000051, %ecx       # imm = 0x40000051
jne 0x124a8
movq 0x5b74(%rip), %rbx      # 0x17fd0
leaq 0x181c(%rip), %rsi      # 0x13c7f
movl $0x10, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x60e0(%rip), %rax      # 0x1857e
movb $0x1, (%rax)
movl (%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0x12506
cmpl $0x40000051, %ecx       # imm = 0x40000051
jne 0x12506
movq 0x5b12(%rip), %rbx      # 0x17fd0
leaq 0x17cb(%rip), %rsi      # 0x13c90
movl $0xe, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x607e(%rip), %rax      # 0x1857e
movb $0x0, (%rax)
movl (%rsp), %eax
cmpl $0x200, %eax            # imm = 0x200
jne 0x12073
cmpb $0xe, 0xc(%rsp)
jne 0x12073
xorl %edi, %edi
callq 0x3310