// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x40, %rsp
leaq 0x8(%rsp), %rdi
callq 0x3160
testl %eax, %eax
jle 0xfa4f
movq 0x2c047(%rip), %rdi     # 0x3b728
callq 0x32c0
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
movl %eax, %edx
xorl $0x300, %edx            # imm = 0x300
movl %ecx, %esi
xorl $0x70, %esi
orl %edx, %esi
jne 0xf737
leaq 0x6de2(%rip), %rbx      # 0x164e8
xorb $0x1, (%rbx)
movq 0x68c0(%rip), %rdi      # 0x15fd0
leaq 0x14e9(%rip), %rsi      # 0x10c00
callq 0x3260
movzbl (%rbx), %esi
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
callq 0x3130
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
movl %eax, %edx
xorl $0x300, %edx            # imm = 0x300
movl %ecx, %esi
xorl $0xd, %esi
movl %edx, %edi
orl %esi, %edi
jne 0xf75e
leaq 0x6e07(%rip), %rax      # 0x16558
movb $0x1, (%rax)
movl $0x300, %eax            # imm = 0x300
jmp 0xfa41
movl %eax, %edi
xorl $0x301, %edi            # imm = 0x301
orl %esi, %edi
jne 0xf77e
leaq 0x6de7(%rip), %rax      # 0x16558
movb $0x0, (%rax)
movl $0x301, %eax            # imm = 0x301
jmp 0xfa41
movl %ecx, %esi
xorl $0x40000039, %esi       # imm = 0x40000039
orl %esi, %edx
jne 0xf7b7
movq 0x683f(%rip), %rdi      # 0x15fd0
leaq 0x1471(%rip), %rsi      # 0x10c09
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6dae(%rip), %rax      # 0x1655a
movb $0x1, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0xf7f3
cmpl $0x40000039, %ecx       # imm = 0x40000039
jne 0xf7f3
movq 0x6803(%rip), %rdi      # 0x15fd0
leaq 0x143d(%rip), %rsi      # 0x10c11
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6d72(%rip), %rax      # 0x1655a
movb $0x0, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0xf82c
cmpl $0x61, %ecx
jne 0xf82c
movq 0x67ca(%rip), %rdi      # 0x15fd0
leaq 0x140a(%rip), %rsi      # 0x10c17
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6d38(%rip), %rax      # 0x16559
movb $0x1, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0xf865
cmpl $0x61, %ecx
jne 0xf865
movq 0x6791(%rip), %rdi      # 0x15fd0
leaq 0x13db(%rip), %rsi      # 0x10c21
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6cff(%rip), %rax      # 0x16559
movb $0x0, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0xf8a1
cmpl $0x40000050, %ecx       # imm = 0x40000050
jne 0xf8a1
movq 0x6755(%rip), %rdi      # 0x15fd0
leaq 0x13a7(%rip), %rsi      # 0x10c29
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6cc6(%rip), %rax      # 0x1655c
movb $0x1, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0xf8dd
cmpl $0x40000050, %ecx       # imm = 0x40000050
jne 0xf8dd
movq 0x6719(%rip), %rdi      # 0x15fd0
leaq 0x1378(%rip), %rsi      # 0x10c36
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6c8a(%rip), %rax      # 0x1655c
movb $0x0, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0xf919
cmpl $0x4000004f, %ecx       # imm = 0x4000004F
jne 0xf919
movq 0x66dd(%rip), %rdi      # 0x15fd0
leaq 0x1347(%rip), %rsi      # 0x10c41
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6c4d(%rip), %rax      # 0x1655b
movb $0x1, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0xf955
cmpl $0x4000004f, %ecx       # imm = 0x4000004F
jne 0xf955
movq 0x66a1(%rip), %rdi      # 0x15fd0
leaq 0x131d(%rip), %rsi      # 0x10c53
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6c11(%rip), %rax      # 0x1655b
movb $0x0, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0xf991
cmpl $0x40000052, %ecx       # imm = 0x40000052
jne 0xf991
movq 0x6665(%rip), %rdi      # 0x15fd0
leaq 0x12f1(%rip), %rsi      # 0x10c63
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6bd7(%rip), %rax      # 0x1655d
movb $0x1, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0xf9cd
cmpl $0x40000052, %ecx       # imm = 0x40000052
jne 0xf9cd
movq 0x6629(%rip), %rdi      # 0x15fd0
leaq 0x12c4(%rip), %rsi      # 0x10c72
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6b9b(%rip), %rax      # 0x1655d
movb $0x0, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x300, %eax            # imm = 0x300
jne 0xfa09
cmpl $0x40000051, %ecx       # imm = 0x40000051
jne 0xfa09
movq 0x65ed(%rip), %rdi      # 0x15fd0
leaq 0x1295(%rip), %rsi      # 0x10c7f
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6b60(%rip), %rax      # 0x1655e
movb $0x1, (%rax)
movl 0x8(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl $0x301, %eax            # imm = 0x301
jne 0xfa41
cmpl $0x40000051, %ecx       # imm = 0x40000051
jne 0xfa41
movq 0x65b1(%rip), %rdi      # 0x15fd0
leaq 0x126a(%rip), %rsi      # 0x10c90
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x6b24(%rip), %rax      # 0x1655e
movb $0x0, (%rax)
movl 0x8(%rsp), %eax
cmpl $0x200, %eax            # imm = 0x200
jne 0xfa4f
cmpb $0xe, 0x14(%rsp)
je 0xfa55
addq $0x40, %rsp
popq %rbx
retq
xorl %edi, %edi
callq 0x32d0