// File: 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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq -0x38(%rbp), %rdi
callq 0x3190
cmpl $0x0, %eax
jle 0x237e4
movq 0x31397(%rip), %rdi     # 0x547e8
callq 0x3370
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x234b5
cmpl $0x70, -0x24(%rbp)
jne 0x234b5
leaq 0xc13c(%rip), %rax      # 0x2f5a8
movb (%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
leaq 0xc12d(%rip), %rax      # 0x2f5a8
movb %cl, (%rax)
movq 0xbb4c(%rip), %rdi      # 0x2efd0
leaq 0x1781(%rip), %rsi      # 0x24c0c
callq 0x32c0
movq %rax, %rdi
leaq 0xc10e(%rip), %rax      # 0x2f5a8
movb (%rax), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x34d0
movq %rax, %rdi
movq 0xbb00(%rip), %rsi      # 0x2efb0
callq 0x3310
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x234ce
cmpl $0xd, -0x24(%rbp)
jne 0x234ce
leaq 0xc14d(%rip), %rax      # 0x2f618
movb $0x1, (%rax)
cmpl $0x301, -0x38(%rbp)     # imm = 0x301
jne 0x234e7
cmpl $0xd, -0x24(%rbp)
jne 0x234e7
leaq 0xc134(%rip), %rax      # 0x2f618
movb $0x0, (%rax)
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x23525
cmpl $0x40000039, -0x24(%rbp) # imm = 0x40000039
jne 0x23525
movq 0xbad0(%rip), %rdi      # 0x2efd0
leaq 0x170e(%rip), %rsi      # 0x24c15
callq 0x32c0
movq %rax, %rdi
movq 0xba9a(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xc0f8(%rip), %rax      # 0x2f61a
movb $0x1, (%rax)
cmpl $0x301, -0x38(%rbp)     # imm = 0x301
jne 0x23563
cmpl $0x40000039, -0x24(%rbp) # imm = 0x40000039
jne 0x23563
movq 0xba92(%rip), %rdi      # 0x2efd0
leaq 0x16d8(%rip), %rsi      # 0x24c1d
callq 0x32c0
movq %rax, %rdi
movq 0xba5c(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xc0ba(%rip), %rax      # 0x2f61a
movb $0x0, (%rax)
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x2359e
cmpl $0x61, -0x24(%rbp)
jne 0x2359e
movq 0xba57(%rip), %rdi      # 0x2efd0
leaq 0x16a3(%rip), %rsi      # 0x24c23
callq 0x32c0
movq %rax, %rdi
movq 0xba21(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xc07e(%rip), %rax      # 0x2f619
movb $0x1, (%rax)
cmpl $0x301, -0x38(%rbp)     # imm = 0x301
jne 0x235d9
cmpl $0x61, -0x24(%rbp)
jne 0x235d9
movq 0xba1c(%rip), %rdi      # 0x2efd0
leaq 0x1672(%rip), %rsi      # 0x24c2d
callq 0x32c0
movq %rax, %rdi
movq 0xb9e6(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xc043(%rip), %rax      # 0x2f619
movb $0x0, (%rax)
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x23617
cmpl $0x40000050, -0x24(%rbp) # imm = 0x40000050
jne 0x23617
movq 0xb9de(%rip), %rdi      # 0x2efd0
leaq 0x163c(%rip), %rsi      # 0x24c35
callq 0x32c0
movq %rax, %rdi
movq 0xb9a8(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xc008(%rip), %rax      # 0x2f61c
movb $0x1, (%rax)
cmpl $0x301, -0x38(%rbp)     # imm = 0x301
jne 0x23655
cmpl $0x40000050, -0x24(%rbp) # imm = 0x40000050
jne 0x23655
movq 0xb9a0(%rip), %rdi      # 0x2efd0
leaq 0x160b(%rip), %rsi      # 0x24c42
callq 0x32c0
movq %rax, %rdi
movq 0xb96a(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xbfca(%rip), %rax      # 0x2f61c
movb $0x0, (%rax)
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x23693
cmpl $0x4000004f, -0x24(%rbp) # imm = 0x4000004F
jne 0x23693
movq 0xb962(%rip), %rdi      # 0x2efd0
leaq 0x15d8(%rip), %rsi      # 0x24c4d
callq 0x32c0
movq %rax, %rdi
movq 0xb92c(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xbf8b(%rip), %rax      # 0x2f61b
movb $0x1, (%rax)
cmpl $0x301, -0x38(%rbp)     # imm = 0x301
jne 0x236d1
cmpl $0x4000004f, -0x24(%rbp) # imm = 0x4000004F
jne 0x236d1
movq 0xb924(%rip), %rdi      # 0x2efd0
leaq 0x15ac(%rip), %rsi      # 0x24c5f
callq 0x32c0
movq %rax, %rdi
movq 0xb8ee(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xbf4d(%rip), %rax      # 0x2f61b
movb $0x0, (%rax)
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x2370f
cmpl $0x40000052, -0x24(%rbp) # imm = 0x40000052
jne 0x2370f
movq 0xb8e6(%rip), %rdi      # 0x2efd0
leaq 0x157e(%rip), %rsi      # 0x24c6f
callq 0x32c0
movq %rax, %rdi
movq 0xb8b0(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xbf11(%rip), %rax      # 0x2f61d
movb $0x1, (%rax)
cmpl $0x301, -0x38(%rbp)     # imm = 0x301
jne 0x2374d
cmpl $0x40000052, -0x24(%rbp) # imm = 0x40000052
jne 0x2374d
movq 0xb8a8(%rip), %rdi      # 0x2efd0
leaq 0x154f(%rip), %rsi      # 0x24c7e
callq 0x32c0
movq %rax, %rdi
movq 0xb872(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xbed3(%rip), %rax      # 0x2f61d
movb $0x0, (%rax)
cmpl $0x300, -0x38(%rbp)     # imm = 0x300
jne 0x2378b
cmpl $0x40000051, -0x24(%rbp) # imm = 0x40000051
jne 0x2378b
movq 0xb86a(%rip), %rdi      # 0x2efd0
leaq 0x151e(%rip), %rsi      # 0x24c8b
callq 0x32c0
movq %rax, %rdi
movq 0xb834(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xbe96(%rip), %rax      # 0x2f61e
movb $0x1, (%rax)
cmpl $0x301, -0x38(%rbp)     # imm = 0x301
jne 0x237c9
cmpl $0x40000051, -0x24(%rbp) # imm = 0x40000051
jne 0x237c9
movq 0xb82c(%rip), %rdi      # 0x2efd0
leaq 0x14f1(%rip), %rsi      # 0x24c9c
callq 0x32c0
movq %rax, %rdi
movq 0xb7f6(%rip), %rsi      # 0x2efb0
callq 0x3310
leaq 0xbe58(%rip), %rax      # 0x2f61e
movb $0x0, (%rax)
cmpl $0x200, -0x38(%rbp)     # imm = 0x200
jne 0x237e2
movzbl -0x2c(%rbp), %eax
cmpl $0xe, %eax
jne 0x237e2
xorl %edi, %edi
callq 0x3390
jmp 0x237e4
addq $0x40, %rsp
popq %rbp
retq