// File: /workspace/github_cpp_makefile_star2_O1/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 0x1270e
movq 0x2b55d(%rip), %rdi     # 0x3d748
callq 0x32f0
cmpl $0x300, (%rsp)          # imm = 0x300
jne 0x1225c
cmpl $0x70, 0x14(%rsp)
jne 0x1225c
leaq 0x6301(%rip), %r14      # 0x18508
xorb $0x1, (%r14)
movq 0x5dbe(%rip), %rbx      # 0x17fd0
leaq 0x19e7(%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
xorl %esi, %esi
cmpl $0xd, %ecx
sete %sil
cmpl $0x301, %eax            # imm = 0x301
sete %dl
andb %sil, %dl
cmpl $0x300, %eax            # imm = 0x300
movzbl %dl, %edi
cmovnel %edi, %esi
cmpb $0x1, %sil
jne 0x12294
xorb $0x1, %dl
leaq 0x62e6(%rip), %rsi      # 0x18578
movb %dl, (%rsi)
xorl $0x300, %eax            # imm = 0x300
xorl $0x40000039, %ecx       # imm = 0x40000039
orl %eax, %ecx
jne 0x122ef
movq 0x5d26(%rip), %rbx      # 0x17fd0
leaq 0x1958(%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 0x628e(%rip), %rax      # 0x1857a
movb $0x1, (%rax)
cmpl $0x301, (%rsp)          # imm = 0x301
jne 0x1234e
cmpl $0x40000039, 0x14(%rsp) # imm = 0x40000039
jne 0x1234e
movq 0x5cc7(%rip), %rbx      # 0x17fd0
leaq 0x1901(%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 0x622f(%rip), %rax      # 0x1857a
movb $0x0, (%rax)
cmpl $0x300, (%rsp)          # imm = 0x300
jne 0x123aa
cmpl $0x61, 0x14(%rsp)
jne 0x123aa
movq 0x5c6b(%rip), %rbx      # 0x17fd0
leaq 0x18ab(%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 0x61d2(%rip), %rax      # 0x18579
movb $0x1, (%rax)
cmpl $0x301, (%rsp)          # imm = 0x301
jne 0x12406
cmpl $0x61, 0x14(%rsp)
jne 0x12406
movq 0x5c0f(%rip), %rbx      # 0x17fd0
leaq 0x1859(%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 0x6176(%rip), %rax      # 0x18579
movb $0x0, (%rax)
cmpl $0x300, (%rsp)          # imm = 0x300
jne 0x12465
cmpl $0x40000050, 0x14(%rsp) # imm = 0x40000050
jne 0x12465
movq 0x5bb0(%rip), %rbx      # 0x17fd0
leaq 0x1802(%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 0x611a(%rip), %rax      # 0x1857c
movb $0x1, (%rax)
cmpl $0x301, (%rsp)          # imm = 0x301
jne 0x124c4
cmpl $0x40000050, 0x14(%rsp) # imm = 0x40000050
jne 0x124c4
movq 0x5b51(%rip), %rbx      # 0x17fd0
leaq 0x17b0(%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 0x60bb(%rip), %rax      # 0x1857c
movb $0x0, (%rax)
cmpl $0x300, (%rsp)          # imm = 0x300
jne 0x12523
cmpl $0x4000004f, 0x14(%rsp) # imm = 0x4000004F
jne 0x12523
movq 0x5af2(%rip), %rbx      # 0x17fd0
leaq 0x175c(%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 0x605b(%rip), %rax      # 0x1857b
movb $0x1, (%rax)
cmpl $0x301, (%rsp)          # imm = 0x301
jne 0x12582
cmpl $0x4000004f, 0x14(%rsp) # imm = 0x4000004F
jne 0x12582
movq 0x5a93(%rip), %rbx      # 0x17fd0
leaq 0x170f(%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 0x5ffc(%rip), %rax      # 0x1857b
movb $0x0, (%rax)
cmpl $0x300, (%rsp)          # imm = 0x300
jne 0x125e1
cmpl $0x40000052, 0x14(%rsp) # imm = 0x40000052
jne 0x125e1
movq 0x5a34(%rip), %rbx      # 0x17fd0
leaq 0x16c0(%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 0x5f9f(%rip), %rax      # 0x1857d
movb $0x1, (%rax)
cmpl $0x301, (%rsp)          # imm = 0x301
jne 0x12640
cmpl $0x40000052, 0x14(%rsp) # imm = 0x40000052
jne 0x12640
movq 0x59d5(%rip), %rbx      # 0x17fd0
leaq 0x1670(%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 0x5f40(%rip), %rax      # 0x1857d
movb $0x0, (%rax)
cmpl $0x300, (%rsp)          # imm = 0x300
jne 0x1269f
cmpl $0x40000051, 0x14(%rsp) # imm = 0x40000051
jne 0x1269f
movq 0x5976(%rip), %rbx      # 0x17fd0
leaq 0x161e(%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 0x5ee2(%rip), %rax      # 0x1857e
movb $0x1, (%rax)
cmpl $0x301, (%rsp)          # imm = 0x301
jne 0x126fe
cmpl $0x40000051, 0x14(%rsp) # imm = 0x40000051
jne 0x126fe
movq 0x5917(%rip), %rbx      # 0x17fd0
leaq 0x15d0(%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 0x5e83(%rip), %rax      # 0x1857e
movb $0x0, (%rax)
cmpl $0x200, (%rsp)          # imm = 0x200
jne 0x1270e
cmpb $0xe, 0xc(%rsp)
je 0x12716
addq $0x38, %rsp
popq %rbx
popq %r14
retq
xorl %edi, %edi
callq 0x3310